summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorKarel Zak2018-05-15 13:43:29 +0200
committerKarel Zak2018-06-21 13:07:46 +0200
commitbcf445fd688692fd4cbfde03cda60be4281ac28b (patch)
tree0a805ce19b8b7bb2cf204320eb9cf24b455c9e63 /lib
parentlib/loopdev: remove obsolete macro (diff)
downloadkernel-qcow2-util-linux-bcf445fd688692fd4cbfde03cda60be4281ac28b.tar.gz
kernel-qcow2-util-linux-bcf445fd688692fd4cbfde03cda60be4281ac28b.tar.xz
kernel-qcow2-util-linux-bcf445fd688692fd4cbfde03cda60be4281ac28b.zip
lib/path lib/sysfs: add debug
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/path.c38
-rw-r--r--lib/sysfs.c38
2 files changed, 74 insertions, 2 deletions
diff --git a/lib/path.c b/lib/path.c
index d6cfe1453..998dce5bb 100644
--- a/lib/path.c
+++ b/lib/path.c
@@ -18,6 +18,29 @@
#include "fileutils.h"
#include "all-io.h"
#include "path.h"
+#include "debug.h"
+
+/*
+ * Debug stuff (based on include/debug.h)
+ */
+static UL_DEBUG_DEFINE_MASK(ulpath);
+UL_DEBUG_DEFINE_MASKNAMES(ulpath) = UL_DEBUG_EMPTY_MASKNAMES;
+
+#define ULPATH_DEBUG_INIT (1 << 1)
+#define ULPATH_DEBUG_CXT (1 << 2)
+
+#define DBG(m, x) __UL_DBG(ulpath, ULPATH_DEBUG_, m, x)
+#define ON_DBG(m, x) __UL_DBG_CALL(ulpath, ULPATH_DEBUG_, m, x)
+
+#define UL_DEBUG_CURRENT_MASK UL_DEBUG_MASK(ulpath)
+#include "debugobj.h"
+
+void ul_path_init_debug(void)
+{
+ if (ulpath_debug_mask)
+ return;
+ __UL_INIT_DEBUG_FROM_ENV(ulpath, ULPATH_DEBUG_, 0, ULPATH_DEBUG);
+}
struct path_cxt *ul_new_path(const char *dir)
{
@@ -26,6 +49,8 @@ struct path_cxt *ul_new_path(const char *dir)
if (!pc)
return NULL;
+ DBG(CXT, ul_debugobj(pc, "alloc"));
+
pc->refcount = 1;
pc->dir_fd = -1;
@@ -54,6 +79,7 @@ void ul_unref_path(struct path_cxt *pc)
pc->refcount--;
if (pc->refcount <= 0) {
+ DBG(CXT, ul_debugobj(pc, "dealloc"));
if (pc->dialect)
pc->free_dialect(pc);
if (pc->dir_fd >= 0)
@@ -78,6 +104,7 @@ int ul_path_set_prefix(struct path_cxt *pc, const char *prefix)
free(pc->prefix);
pc->prefix = p;
+ DBG(CXT, ul_debugobj(pc, "new prefix: '%s'", p));
return 0;
}
@@ -103,6 +130,7 @@ int ul_path_set_dir(struct path_cxt *pc, const char *dir)
free(pc->dir_path);
pc->dir_path = p;
+ DBG(CXT, ul_debugobj(pc, "new dir: '%s'", p));
return 0;
}
@@ -115,6 +143,7 @@ int ul_path_set_dialect(struct path_cxt *pc, void *data, void free_data(struct p
{
pc->dialect = data;
pc->free_dialect = free_data;
+ DBG(CXT, ul_debugobj(pc, "new dialect"));
return 0;
}
@@ -157,6 +186,8 @@ int ul_path_get_dirfd(struct path_cxt *pc)
const char *path = get_absdir(pc);
if (!path)
return -errno;
+
+ DBG(CXT, ul_debugobj(pc, "opening dir: '%s'", path));
pc->dir_fd = open(path, O_RDONLY|O_CLOEXEC);
}
@@ -223,6 +254,7 @@ int ul_path_open(struct path_cxt *pc, int flags, const char *path)
&& pc->redirect_on_enoent(pc, path, &dir) == 0)
fd = openat(dir, path, flags);
+ DBG(CXT, ul_debugobj(pc, "opening '%s'", path));
return fd;
}
@@ -327,8 +359,10 @@ DIR *ul_path_opendir(struct path_cxt *pc, const char *path)
if (path)
fd = ul_path_open(pc, O_RDONLY|O_CLOEXEC, path);
- else if (pc->dir_path)
+ else if (pc->dir_path) {
+ DBG(CXT, ul_debugobj(pc, "duplicate dir path"));
fd = dup_fd_cloexec(ul_path_get_dirfd(pc), STDERR_FILENO + 1);
+ }
if (fd < 0)
return NULL;
@@ -895,6 +929,8 @@ int main(int argc, char *argv[])
errx(EXIT_FAILURE, "<dir> not defined");
dir = argv[optind++];
+ ul_path_init_debug();
+
pc = ul_new_path(dir);
if (!pc)
err(EXIT_FAILURE, "failed to initialize path context");
diff --git a/lib/sysfs.c b/lib/sysfs.c
index b6f20ee19..3fe771449 100644
--- a/lib/sysfs.c
+++ b/lib/sysfs.c
@@ -15,11 +15,34 @@
#include "sysfs.h"
#include "fileutils.h"
#include "all-io.h"
+#include "debug.h"
static void sysfs_blkdev_deinit_path(struct path_cxt *pc);
static int sysfs_blkdev_enoent_redirect(struct path_cxt *pc, const char *path, int *dirfd);
static dev_t __sysfs_devname_to_devno(const char *prefix, const char *name, const char *parent);
+/*
+ * Debug stuff (based on include/debug.h)
+ */
+static UL_DEBUG_DEFINE_MASK(ulsysfs);
+UL_DEBUG_DEFINE_MASKNAMES(ulsysfs) = UL_DEBUG_EMPTY_MASKNAMES;
+
+#define ULSYSFS_DEBUG_INIT (1 << 1)
+#define ULSYSFS_DEBUG_CXT (1 << 2)
+
+#define DBG(m, x) __UL_DBG(ulsysfs, ULSYSFS_DEBUG_, m, x)
+#define ON_DBG(m, x) __UL_DBG_CALL(ulsysfs, ULSYSFS_DEBUG_, m, x)
+
+#define UL_DEBUG_CURRENT_MASK UL_DEBUG_MASK(ulsysfs)
+#include "debugobj.h"
+
+void ul_sysfs_init_debug(void)
+{
+ if (ulsysfs_debug_mask)
+ return;
+ __UL_INIT_DEBUG_FROM_ENV(ulsysfs, ULSYSFS_DEBUG_, 0, ULSYSFS_DEBUG);
+}
+
struct path_cxt *ul_new_sysfs_path(dev_t devno, struct path_cxt *parent, const char *prefix)
{
struct path_cxt *pc = ul_new_path(NULL);
@@ -34,6 +57,7 @@ struct path_cxt *ul_new_sysfs_path(dev_t devno, struct path_cxt *parent, const c
return NULL;
}
+ DBG(CXT, ul_debugobj(pc, "alloc"));
return pc;
}
@@ -65,12 +89,15 @@ int sysfs_blkdev_init_path(struct path_cxt *pc, dev_t devno, struct path_cxt *pa
if (!blk)
return -ENOMEM;
+ DBG(CXT, ul_debugobj(pc, "init for sysfs"));
+
blk->devno = devno;
ul_path_set_dialect(pc, blk, sysfs_blkdev_deinit_path);
sysfs_blkdev_set_parent(pc, parent);
ul_path_set_enoent_redirect(pc, sysfs_blkdev_enoent_redirect);
+
return 0;
}
@@ -80,6 +107,9 @@ static void sysfs_blkdev_deinit_path(struct path_cxt *pc)
if (!pc)
return;
+
+ DBG(CXT, ul_debugobj(pc, "deinit"));
+
blk = ul_path_get_dialect(pc);
if (!blk)
return;
@@ -106,6 +136,7 @@ int sysfs_blkdev_set_parent(struct path_cxt *pc, struct path_cxt *parent)
} else
blk->parent = NULL;
+ DBG(CXT, ul_debugobj(pc, "new parent"));
return 0;
}
@@ -122,8 +153,10 @@ static int sysfs_blkdev_enoent_redirect(struct path_cxt *pc, const char *path, i
if (blk && blk->parent && strncmp(path, "queue/", 6) == 0) {
*dirfd = ul_path_get_dirfd(blk->parent);
- if (*dirfd >= 0)
+ if (*dirfd >= 0) {
+ DBG(CXT, ul_debugobj(pc, "%s redirected to parent", path));
return 0;
+ }
}
return 1; /* no redirect */
}
@@ -261,6 +294,7 @@ dev_t sysfs_blkdev_partno_to_devno(struct path_cxt *pc, int partno)
}
closedir(dir);
+ DBG(CXT, ul_debugobj(pc, "partno (%d) -> devno (%d)", (int) partno, (int) devno));
return devno;
}
@@ -970,6 +1004,8 @@ int main(int argc, char *argv[])
if (argc != 2)
errx(EXIT_FAILURE, "usage: %s <devname>", argv[0]);
+ ul_sysfs_init_debug();
+
devname = argv[1];
devno = sysfs_devname_to_devno(devname);