loop-util: make clearer how LoopDevice objects that do not encapsulate an actual loopback device are set up

This commit is contained in:
Lennart Poettering
2022-09-01 22:06:19 +02:00
parent 4c1d50e65c
commit 7cb349f0ca
2 changed files with 6 additions and 3 deletions
+2 -2
View File
@@ -719,7 +719,7 @@ LoopDevice* loop_device_unref(LoopDevice *d) {
/* Let's open the control device early, and lock it, so that we can release our block device and
* delete it in a synchronized fashion, and allocators won't needlessly see the block device as free
* while we are about to delete it. */
if (d->nr >= 0 && !d->relinquished) {
if (!LOOP_DEVICE_IS_FOREIGN(d) && !d->relinquished) {
control = open("/dev/loop-control", O_RDWR|O_CLOEXEC|O_NOCTTY|O_NONBLOCK);
if (control < 0)
log_debug_errno(errno, "Failed to open loop control device, cannot remove loop device '%s', ignoring: %m", strna(d->node));
@@ -733,7 +733,7 @@ LoopDevice* loop_device_unref(LoopDevice *d) {
if (fsync(d->fd) < 0)
log_debug_errno(errno, "Failed to sync loop block device, ignoring: %m");
if (d->nr >= 0 && !d->relinquished) {
if (!LOOP_DEVICE_IS_FOREIGN(d) && !d->relinquished) {
/* We are supposed to clear the loopback device. Let's do this synchronously: lock
* the device, manually remove all partitions and then clear it. This should ensure
* udev doesn't concurrently access the devices, and we can be reasonably sure that