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>
*/
#include <blkid.h>
+#include <stdbool.h>
#include "mountP.h"
#include "loopdev.h"
struct loopdev_cxt lc;
int rc = 0, lo_flags = 0;
uint64_t offset = 0, sizelimit = 0;
+ bool reuse = FALSE;
assert(cxt);
assert(cxt->fs);
if (loopval) {
rc = -MNT_ERR_LOOPOVERLAP;
goto done;
- } else
+ } else {
+ reuse = TRUE;
goto success;
+ }
}
default: /* error */
goto done;
/* 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.