]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
loop-util: explicitly close loopback block device before sleeping
authorLennart Poettering <lennart@poettering.net>
Tue, 5 Apr 2022 21:34:44 +0000 (23:34 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 7 Apr 2022 16:55:58 +0000 (18:55 +0200)
attach_empty() file takes a BSD file lock on the device, and we really
should release that before going to sleep. hence explicitly close the
block device before the sleep instead of relying on _cleanup_ to close
it after the sleep.

src/shared/loop-util.c

index 257af7340f0bbba35eeae6edd0237993e7001355..073755fb9e2cd6958a32b2d93b84c0b6cb37831f 100644 (file)
@@ -561,6 +561,9 @@ static int loop_device_make_internal(
                 if (++n_attempts >= 64) /* Give up eventually */
                         return -EBUSY;
 
+                /* Now close the loop device explicitly. This will release any lock acquired by
+                 * attach_empty_file() or similar, while we sleep below. */
+                loop = safe_close(loop);
                 loopdev = mfree(loopdev);
 
                 /* Wait some random time, to make collision less likely. Let's pick a random time in the