summaryrefslogtreecommitdiffstats
path: root/lib/loopdev.c
diff options
context:
space:
mode:
authorKarel Zak2016-08-17 12:28:33 +0200
committerKarel Zak2016-08-17 12:28:33 +0200
commit9a94b634a343e83bfa2a9d311074e3e520abdddd (patch)
treeb1118ead3294be824b9fdbbf01449bb822aad4cf /lib/loopdev.c
parenttests: keep 'hppa' in fdisk/bsd test too (diff)
downloadkernel-qcow2-util-linux-9a94b634a343e83bfa2a9d311074e3e520abdddd.tar.gz
kernel-qcow2-util-linux-9a94b634a343e83bfa2a9d311074e3e520abdddd.tar.xz
kernel-qcow2-util-linux-9a94b634a343e83bfa2a9d311074e3e520abdddd.zip
losetup: add --nooverlap options
This patch introduces overlap detections and loop devices re-use for losetup(8). We already support this feature for mount(8) where it's enabled by default (because we mount filesystems and it's always mistake to share the same filesystem between more loop devices). Stanislav has suggested to enable this feature also for losetup by default. I'm not sure about it, IMHO it's better to keep losetup(8) simple and stupid by default, and inform users about possible problems and solutions in the man page. The feature forces losetup to scan all loop devices always when new one is requested. This maybe disadvantage (especially when we use control-loop to avoid /sys or /dev scans) on system with huge number of loop devices. Co-Author: Stanislav Brabec <sbrabec@suse.cz> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib/loopdev.c')
-rw-r--r--lib/loopdev.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/loopdev.c b/lib/loopdev.c
index 21c8f4366..8bbde0425 100644
--- a/lib/loopdev.c
+++ b/lib/loopdev.c
@@ -353,10 +353,8 @@ int loopcxt_deinit_iterator(struct loopdev_cxt *lc)
fclose(iter->proc);
if (iter->sysblock)
closedir(iter->sysblock);
- iter->minors = NULL;
- iter->proc = NULL;
- iter->sysblock = NULL;
- iter->done = 1;
+
+ memset(iter, 0, sizeof(*iter));
return 0;
}
@@ -1426,8 +1424,11 @@ int loopcxt_find_unused(struct loopdev_cxt *lc)
DBG(CXT, ul_debugobj(lc, "find_unused requested"));
if (lc->flags & LOOPDEV_FL_CONTROL) {
- int ctl = open(_PATH_DEV_LOOPCTL, O_RDWR|O_CLOEXEC);
+ int ctl;
+
+ DBG(CXT, ul_debugobj(lc, "using loop-control"));
+ ctl = open(_PATH_DEV_LOOPCTL, O_RDWR|O_CLOEXEC);
if (ctl >= 0)
rc = ioctl(ctl, LOOP_CTL_GET_FREE);
if (rc >= 0) {
@@ -1443,6 +1444,7 @@ int loopcxt_find_unused(struct loopdev_cxt *lc)
}
if (rc < 0) {
+ DBG(CXT, ul_debugobj(lc, "using loop scan"));
rc = loopcxt_init_iterator(lc, LOOPITER_FL_FREE);
if (rc)
return rc;
@@ -1577,6 +1579,7 @@ int loopcxt_find_overlap(struct loopdev_cxt *lc, const char *filename,
if (!filename)
return -EINVAL;
+ DBG(CXT, ul_debugobj(lc, "find_overlap requested"));
hasst = !stat(filename, &st);
rc = loopcxt_init_iterator(lc, LOOPITER_FL_USED);
@@ -1633,6 +1636,7 @@ int loopcxt_find_overlap(struct loopdev_cxt *lc, const char *filename,
rc = 0; /* not found */
found:
loopcxt_deinit_iterator(lc);
+ DBG(CXT, ul_debugobj(lc, "find_overlap done [rc=%d]", rc));
return rc;
}