summaryrefslogtreecommitdiffstats
path: root/drivers/block/loop/loop_main.c
diff options
context:
space:
mode:
authorManuel Bentele2019-08-07 16:23:19 +0200
committerManuel Bentele2019-08-21 22:03:37 +0200
commit7d72f198cd47536e6c6cdd07b3f8c6a9cd8a624a (patch)
treedf56a9330373da52523bba4fc7e1928bd9e54d63 /drivers/block/loop/loop_main.c
parentblock: loop: file_fmt_qcow: set up L2 cache size correctly (diff)
downloadkernel-qcow2-linux-7d72f198cd47536e6c6cdd07b3f8c6a9cd8a624a.tar.gz
kernel-qcow2-linux-7d72f198cd47536e6c6cdd07b3f8c6a9cd8a624a.tar.xz
kernel-qcow2-linux-7d72f198cd47536e6c6cdd07b3f8c6a9cd8a624a.zip
block: loop: add debugfs support for loop devices
The loop device module is extended by providing debugfs support if debugfs is enabled in kconfig. The provided debugfs root directory is called loop and contains for each loop device a subfolder named after its disk name of the block device. These folders can be used by the different loop file format drivers to export debugging information. This patch contains debugfs entries for the QCOW2 file format driver, too. The read-only 'header' entry provides human readable information of the QCOW header. The 'offset' entry provides interaction with the address calulation engine of the QCOW implementation. One linear address number can be written to the 'offset' entry. Later on, after writing to the entry, the calulated non-linear cluster offset can be read. Signed-off-by: Manuel Bentele <development@manuel-bentele.de>
Diffstat (limited to 'drivers/block/loop/loop_main.c')
-rw-r--r--drivers/block/loop/loop_main.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/drivers/block/loop/loop_main.c b/drivers/block/loop/loop_main.c
index 09f001f0690c..1150956974fb 100644
--- a/drivers/block/loop/loop_main.c
+++ b/drivers/block/loop/loop_main.c
@@ -1667,6 +1667,8 @@ static const struct blk_mq_ops loop_mq_ops = {
.complete = lo_complete_rq,
};
+static struct dentry *loop_dbgfs_dir;
+
static int loop_add(struct loop_device **l, int i)
{
struct loop_device *lo;
@@ -1766,6 +1768,21 @@ static int loop_add(struct loop_device **l, int i)
sprintf(disk->disk_name, "loop%d", i);
add_disk(disk);
*l = lo;
+
+ /* initialize debugfs entries */
+ /* create for each loop device a debugfs directory under 'loop' if
+ * the 'block' directory exists, otherwise create the loop directory in
+ * the root directory */
+#ifdef CONFIG_DEBUG_FS
+ lo->lo_dbgfs_dir = debugfs_create_dir(disk->disk_name, loop_dbgfs_dir);
+
+ if (IS_ERR_OR_NULL(lo->lo_dbgfs_dir)) {
+ err = -ENODEV;
+ lo->lo_dbgfs_dir = NULL;
+ goto out_free_file_fmt;
+ }
+#endif
+
return lo->lo_number;
out_free_file_fmt:
@@ -1785,6 +1802,7 @@ out:
static void loop_remove(struct loop_device *lo)
{
loop_file_fmt_free(lo->lo_fmt);
+ debugfs_remove(lo->lo_dbgfs_dir);
del_gendisk(lo->lo_disk);
blk_cleanup_queue(lo->lo_queue);
blk_mq_free_tag_set(&lo->tag_set);
@@ -1972,6 +1990,14 @@ static int __init loop_init(void)
goto misc_out;
}
+#ifdef CONFIG_DEBUG_FS
+ loop_dbgfs_dir = debugfs_create_dir("loop", NULL);
+ if (IS_ERR_OR_NULL(loop_dbgfs_dir)) {
+ err = -ENODEV;
+ goto misc_out;
+ }
+#endif
+
blk_register_region(MKDEV(LOOP_MAJOR, 0), range,
THIS_MODULE, loop_probe, NULL, NULL);
@@ -2010,6 +2036,10 @@ static void __exit loop_exit(void)
blk_unregister_region(MKDEV(LOOP_MAJOR, 0), range);
unregister_blkdev(LOOP_MAJOR, "loop");
+#ifdef CONFIG_DEBUG_FS
+ debugfs_remove(loop_dbgfs_dir);
+#endif
+
misc_deregister(&loop_misc);
}