summaryrefslogtreecommitdiff
path: root/src/dissect
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2022-05-18 13:35:21 +0200
committerLuca Boccassi <luca.boccassi@gmail.com>2022-05-23 18:15:16 +0100
commit75d7e04eb4662a814c26010d447eed8a862f5ec1 (patch)
tree620412705b319ece346db079f27f56057d4038c2 /src/dissect
parentaf7211541272823b1ef4fef8c36d10dc1027733e (diff)
downloadsystemd-75d7e04eb4662a814c26010d447eed8a862f5ec1.tar.gz
dissect-image: Explicitly remove partitions when done with image
When closing a loop device, the kernel will asynchronously remove the probed partitions. This can lead to race conditions where we try to reuse a partition device that still needs to be removed by the kernel. To avoid such issues, let's explicitly try to remove any partitions using BLKPG_DEL_PARTITION when we're done with an image. To make sure we don't try to remove partitions when we want them to remain (e.g. systemd-dissect --mount), we add dissected_image_relinquish() in a similar vein to loop_device_relinquish() and decrypted_image_relinquish().
Diffstat (limited to 'src/dissect')
-rw-r--r--src/dissect/dissect.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/dissect/dissect.c b/src/dissect/dissect.c
index bd94a755db..0239d9b394 100644
--- a/src/dissect/dissect.c
+++ b/src/dissect/dissect.c
@@ -648,6 +648,7 @@ static int action_mount(DissectedImage *m, LoopDevice *d) {
return log_error_errno(r, "Failed to relinquish DM devices: %m");
}
+ dissected_image_relinquish(m);
loop_device_relinquish(d);
return 0;
}
@@ -700,6 +701,7 @@ static int action_copy(DissectedImage *m, LoopDevice *d) {
return log_error_errno(r, "Failed to relinquish DM devices: %m");
}
+ dissected_image_relinquish(m);
loop_device_relinquish(d);
if (arg_action == ACTION_COPY_FROM) {