]> 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, 31 Oct 2012 12:52:34 +0000 (13:52 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
lib/loopdev.c
sys-utils/losetup.c

index a9f6df2203d61f1d7700daf86e3a639633cf6d2a..0e6033a255f132270fae36fd3cf6a69026326f13 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);
@@ -1150,6 +1163,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 fdcc0beeb51ca7a3adf9c137089165f3c7b3ce71..a8381a8433f20d2ab44f803db96911485f945191 100644 (file)
@@ -250,8 +250,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) {