diff options
author | Stanislav Brabec | 2017-01-12 15:45:42 +0100 |
---|---|---|
committer | Karel Zak | 2017-01-16 12:25:45 +0100 |
commit | 7b46647df4d7d568de91fa8da1c2342acd960e8e (patch) | |
tree | ccb04ec479807ef4e3ba80feb31c4b3c70444f01 /libmount/src/context_loopdev.c | |
parent | libmount: fix mount -oloop=/dev/loopX regression (diff) | |
download | kernel-qcow2-util-linux-7b46647df4d7d568de91fa8da1c2342acd960e8e.tar.gz kernel-qcow2-util-linux-7b46647df4d7d568de91fa8da1c2342acd960e8e.tar.xz kernel-qcow2-util-linux-7b46647df4d7d568de91fa8da1c2342acd960e8e.zip |
libmount: Fix incorrect detach of reused loop device
If -oloop is used and the loop device is reused, the loop device is detached
after umount. It is incorrect as it could break the another task using the loop
device.
This is caused by mnt_context_enable_loopdel(,TRUE) that is called from
mnt_context_prepare_umount() whenever "loop" option is used, independently on
AUTOCLEAR flag.
Remove the "loop" option for reused devices to prevent detaching of reused loop
device.
Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
Diffstat (limited to 'libmount/src/context_loopdev.c')
-rw-r--r-- | libmount/src/context_loopdev.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/libmount/src/context_loopdev.c b/libmount/src/context_loopdev.c index 18eb2cc56..ab80bd110 100644 --- a/libmount/src/context_loopdev.c +++ b/libmount/src/context_loopdev.c @@ -10,6 +10,7 @@ */ #include <blkid.h> +#include <stdbool.h> #include "mountP.h" #include "loopdev.h" @@ -142,6 +143,7 @@ int mnt_context_setup_loopdev(struct libmnt_context *cxt) struct loopdev_cxt lc; int rc = 0, lo_flags = 0; uint64_t offset = 0, sizelimit = 0; + bool reuse = FALSE; assert(cxt); assert(cxt->fs); @@ -263,8 +265,10 @@ int mnt_context_setup_loopdev(struct libmnt_context *cxt) if (loopval) { rc = -MNT_ERR_LOOPOVERLAP; goto done; - } else + } else { + reuse = TRUE; goto success; + } } default: /* error */ goto done; @@ -339,8 +343,8 @@ success: /* success */ cxt->flags |= MNT_FL_LOOPDEV_READY; - if ((cxt->user_mountflags & MNT_MS_LOOP) && - loopcxt_is_autoclear(&lc)) { + if (reuse || ( (cxt->user_mountflags & MNT_MS_LOOP) && + loopcxt_is_autoclear(&lc))) { /* * autoclear flag accepted by the kernel, don't store * the "loop=" option to mtab. |