diff options
author | David Sterba <dsterba@suse.cz> | 2014-02-05 09:36:18 -0500 |
---|---|---|
committer | Josef Bacik <jbacik@fb.com> | 2014-03-10 15:15:51 -0400 |
commit | 1bae30982bc86ab66d61ccb6e22792593b45d44d (patch) | |
tree | 55363ac60e0ab2a95a4f52e9dbc5b64f44d81104 | |
parent | ace0105076a493c04e6d5e91e6a19f222d6b3875 (diff) |
btrfs: add simple debugfs interface
Help during debugging to export various interesting infromation and
tunables without the need of extra mount options or ioctls.
Usage:
* declare your variable in sysfs.h, and include where you need it
* define the variable in sysfs.c and make it visible via
debugfs_create_TYPE
Depends on CONFIG_DEBUG_FS.
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Josef Bacik <jbacik@fb.com>
-rw-r--r-- | fs/btrfs/sysfs.c | 33 | ||||
-rw-r--r-- | fs/btrfs/sysfs.h | 5 |
2 files changed, 32 insertions, 6 deletions
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 865f4cf9a769..c5eb2143dc66 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <linux/kobject.h> | 24 | #include <linux/kobject.h> |
25 | #include <linux/bug.h> | 25 | #include <linux/bug.h> |
26 | #include <linux/genhd.h> | 26 | #include <linux/genhd.h> |
27 | #include <linux/debugfs.h> | ||
27 | 28 | ||
28 | #include "ctree.h" | 29 | #include "ctree.h" |
29 | #include "disk-io.h" | 30 | #include "disk-io.h" |
@@ -599,6 +600,12 @@ static int add_device_membership(struct btrfs_fs_info *fs_info) | |||
599 | /* /sys/fs/btrfs/ entry */ | 600 | /* /sys/fs/btrfs/ entry */ |
600 | static struct kset *btrfs_kset; | 601 | static struct kset *btrfs_kset; |
601 | 602 | ||
603 | /* /sys/kernel/debug/btrfs */ | ||
604 | static struct dentry *btrfs_debugfs_root_dentry; | ||
605 | |||
606 | /* Debugging tunables and exported data */ | ||
607 | u64 btrfs_debugfs_test; | ||
608 | |||
602 | int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info) | 609 | int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info) |
603 | { | 610 | { |
604 | int error; | 611 | int error; |
@@ -642,27 +649,41 @@ failure: | |||
642 | return error; | 649 | return error; |
643 | } | 650 | } |
644 | 651 | ||
652 | static int btrfs_init_debugfs(void) | ||
653 | { | ||
654 | #ifdef CONFIG_DEBUG_FS | ||
655 | btrfs_debugfs_root_dentry = debugfs_create_dir("btrfs", NULL); | ||
656 | if (!btrfs_debugfs_root_dentry) | ||
657 | return -ENOMEM; | ||
658 | |||
659 | debugfs_create_u64("test", S_IRUGO | S_IWUGO, btrfs_debugfs_root_dentry, | ||
660 | &btrfs_debugfs_test); | ||
661 | #endif | ||
662 | return 0; | ||
663 | } | ||
664 | |||
645 | int btrfs_init_sysfs(void) | 665 | int btrfs_init_sysfs(void) |
646 | { | 666 | { |
647 | int ret; | 667 | int ret; |
668 | |||
648 | btrfs_kset = kset_create_and_add("btrfs", NULL, fs_kobj); | 669 | btrfs_kset = kset_create_and_add("btrfs", NULL, fs_kobj); |
649 | if (!btrfs_kset) | 670 | if (!btrfs_kset) |
650 | return -ENOMEM; | 671 | return -ENOMEM; |
651 | 672 | ||
652 | init_feature_attrs(); | 673 | ret = btrfs_init_debugfs(); |
674 | if (ret) | ||
675 | return ret; | ||
653 | 676 | ||
677 | init_feature_attrs(); | ||
654 | ret = sysfs_create_group(&btrfs_kset->kobj, &btrfs_feature_attr_group); | 678 | ret = sysfs_create_group(&btrfs_kset->kobj, &btrfs_feature_attr_group); |
655 | if (ret) { | ||
656 | kset_unregister(btrfs_kset); | ||
657 | return ret; | ||
658 | } | ||
659 | 679 | ||
660 | return 0; | 680 | return ret; |
661 | } | 681 | } |
662 | 682 | ||
663 | void btrfs_exit_sysfs(void) | 683 | void btrfs_exit_sysfs(void) |
664 | { | 684 | { |
665 | sysfs_remove_group(&btrfs_kset->kobj, &btrfs_feature_attr_group); | 685 | sysfs_remove_group(&btrfs_kset->kobj, &btrfs_feature_attr_group); |
666 | kset_unregister(btrfs_kset); | 686 | kset_unregister(btrfs_kset); |
687 | debugfs_remove_recursive(btrfs_debugfs_root_dentry); | ||
667 | } | 688 | } |
668 | 689 | ||
diff --git a/fs/btrfs/sysfs.h b/fs/btrfs/sysfs.h index f3cea3710d44..9ab576318a84 100644 --- a/fs/btrfs/sysfs.h +++ b/fs/btrfs/sysfs.h | |||
@@ -1,6 +1,11 @@ | |||
1 | #ifndef _BTRFS_SYSFS_H_ | 1 | #ifndef _BTRFS_SYSFS_H_ |
2 | #define _BTRFS_SYSFS_H_ | 2 | #define _BTRFS_SYSFS_H_ |
3 | 3 | ||
4 | /* | ||
5 | * Data exported through sysfs | ||
6 | */ | ||
7 | extern u64 btrfs_debugfs_test; | ||
8 | |||
4 | enum btrfs_feature_set { | 9 | enum btrfs_feature_set { |
5 | FEAT_COMPAT, | 10 | FEAT_COMPAT, |
6 | FEAT_COMPAT_RO, | 11 | FEAT_COMPAT_RO, |