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().
This commit is contained in:
Daan De Meyer
2022-05-23 18:15:16 +01:00
committed by Luca Boccassi
parent af72115412
commit 75d7e04eb4
6 changed files with 75 additions and 5 deletions
+1
View File
@@ -2426,6 +2426,7 @@ int setup_namespace(
}
}
dissected_image_relinquish(dissected_image);
loop_device_relinquish(loop_device);
} else if (root_directory) {