diff options
author | Stanislav Brabec | 2016-08-17 12:54:40 +0200 |
---|---|---|
committer | Karel Zak | 2016-08-17 12:58:12 +0200 |
commit | f27d989c67eb0d85b3bfc54807e626ff16e71f56 (patch) | |
tree | 3650f08eebe0e4caad26045bcd1c2d8627ee1b60 /sys-utils/losetup.c | |
parent | loopdev: Implememt loopcxt_set_status() (diff) | |
download | kernel-qcow2-util-linux-f27d989c67eb0d85b3bfc54807e626ff16e71f56.tar.gz kernel-qcow2-util-linux-f27d989c67eb0d85b3bfc54807e626ff16e71f56.tar.xz kernel-qcow2-util-linux-f27d989c67eb0d85b3bfc54807e626ff16e71f56.zip |
losetup: Prevent AUTOCLEAR detach race
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>
Diffstat (limited to 'sys-utils/losetup.c')
-rw-r--r-- | sys-utils/losetup.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/sys-utils/losetup.c b/sys-utils/losetup.c index ba1363de3..606789c42 100644 --- a/sys-utils/losetup.c +++ b/sys-utils/losetup.c @@ -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 */ |