]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
losetup: Prevent AUTOCLEAR detach race
authorStanislav Brabec <sbrabec@suse.cz>
Wed, 17 Aug 2016 10:54:40 +0000 (12:54 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 17 Aug 2016 10:58:12 +0000 (12:58 +0200)
Kernel needs some time to delete a device after losetup --detach. If
the losetup --find --nooverlay is called just after losetup --delete,
it can sometimes attempt to recycle the device that is just being
released.  To prevent this race, clear the AUTOCLEAR flag of the
device.

[kzak@redhat.com: - rebase to the new version of the code]

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/losetup.c

index ba1363de3b9399af35215d19255f905220217fbe..606789c42742b64065a5a977a40703a88b948cea 100644 (file)
@@ -481,6 +481,12 @@ static int create_loop(struct loopdev_cxt *lc,
                                loopcxt_deinit(lc);
                                errx(EXIT_FAILURE, _("%s: overlapping encrypted loop device exists"), file);
                        }
+
+                       lc->info.lo_flags &= !LO_FLAGS_AUTOCLEAR;
+                       if (loopcxt_set_status(lc)) {
+                               loopcxt_deinit(lc);
+                               errx(EXIT_FAILURE, _("%s: failed to re-use loop device"), file);
+                       }
                        return 0;       /* success, re-use */
                }
                default: /* error */