]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/loopdev: improve debug messages
authorKarel Zak <kzak@redhat.com>
Wed, 17 Oct 2012 09:42:21 +0000 (11:42 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 17 Oct 2012 09:42:21 +0000 (11:42 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
lib/loopdev.c
sys-utils/losetup.c

index 77d91ec3ae4a744b86cb50ffe41d0a75488fc33f..a552fb7556e16fc7f67db15783f7b71eb387c069 100644 (file)
@@ -87,8 +87,10 @@ int loopcxt_set_device(struct loopdev_cxt *lc, const char *device)
        if (!lc)
                return -EINVAL;
 
-       if (lc->fd >= 0)
+       if (lc->fd >= 0) {
                close(lc->fd);
+               DBG(lc, loopdev_debug("closing old open fd"));
+       }
        lc->fd = -1;
        lc->mode = 0;
        lc->has_info = 0;
@@ -158,19 +160,26 @@ int loopcxt_init(struct loopdev_cxt *lc, int flags)
        memcpy(lc, &dummy, sizeof(dummy));
        lc->flags = flags;
 
+       if (getenv("LOOPDEV_DEBUG"))
+               loopcxt_enable_debug(lc, TRUE);
+
        rc = loopcxt_set_device(lc, NULL);
        if (rc)
                return rc;
 
        if (!(lc->flags & LOOPDEV_FL_NOSYSFS) &&
-           get_linux_version() >= KERNEL_VERSION(2,6,37))
+           get_linux_version() >= KERNEL_VERSION(2,6,37)) {
                /*
                 * Use only sysfs for basic information about loop devices
                 */
                lc->flags |= LOOPDEV_FL_NOIOCTL;
+               DBG(lc, loopdev_debug("init: ignore ioctls"));
+       }
 
-       if (!(lc->flags & LOOPDEV_FL_CONTROL) && !stat(_PATH_DEV_LOOPCTL, &st))
+       if (!(lc->flags & LOOPDEV_FL_CONTROL) && !stat(_PATH_DEV_LOOPCTL, &st)) {
                lc->flags |= LOOPDEV_FL_CONTROL;
+               DBG(lc, loopdev_debug("init: loop-control detected "));
+       }
 
        return 0;
 }
@@ -272,7 +281,9 @@ int loopcxt_get_fd(struct loopdev_cxt *lc)
        if (lc->fd < 0) {
                lc->mode = lc->flags & LOOPDEV_FL_RDWR ? O_RDWR : O_RDONLY;
                lc->fd = open(lc->device, lc->mode);
-               DBG(lc, loopdev_debug("open %s", lc->fd < 0 ? "failed" : "ok"));
+               DBG(lc, loopdev_debug("open %s [%s]: %s", lc->device,
+                               lc->flags & LOOPDEV_FL_RDWR ? "rw" : "ro",
+                               lc->fd < 0 ? "failed" : "ok"));
        }
        return lc->fd;
 }
@@ -576,6 +587,7 @@ int loopcxt_next(struct loopdev_cxt *lc)
         *    of loop devices). This is enough for 99% of all cases.
         */
        if (iter->default_check) {
+               DBG(lc, loopdev_debug("iter: next: default check"));
                for (++iter->ncur; iter->ncur < LOOPDEV_DEFAULT_NNODES;
                                                        iter->ncur++) {
                        char name[16];
@@ -590,6 +602,7 @@ int loopcxt_next(struct loopdev_cxt *lc)
        /* C) the worst possibility, scan whole /dev or /dev/loop/<N>
         */
        if (!iter->minors) {
+               DBG(lc, loopdev_debug("iter: next: scan /dev"));
                iter->nminors = (lc->flags & LOOPDEV_FL_DEVSUBDIR) ?
                        loop_scandir(_PATH_DEV_LOOP, &iter->minors, 0) :
                        loop_scandir(_PATH_DEV, &iter->minors, 1);
@@ -1094,6 +1107,7 @@ int loopcxt_setup_device(struct loopdev_cxt *lc)
        DBG(lc, loopdev_debug("setup: backing file open: OK"));
 
        if (lc->fd != -1 && lc->mode != mode) {
+               DBG(lc, loopdev_debug("closing already open device (mode mismatch)"));
                close(lc->fd);
                lc->fd = -1;
                lc->mode = 0;
index 38ccc7d08459e4ea3636537cd4093988cfe90911..bd0f16118deb0b0700ea6b1ce70bcefd5430a833 100644 (file)
@@ -247,8 +247,6 @@ int main(int argc, char **argv)
        if (loopcxt_init(&lc, 0))
                err(EXIT_FAILURE, _("failed to initialize loopcxt"));
 
-       loopcxt_enable_debug(&lc, getenv("LOOPDEV_DEBUG") ? TRUE : FALSE);
-
        while ((c = getopt_long(argc, argv, "ac:d:De:E:fhj:o:p:PrvV",
                                longopts, NULL)) != -1) {