* [PATCH] btrfs: add simple debugfs interface
@ 2014-01-16 1:25 David Sterba
2014-01-28 15:50 ` Josef Bacik
0 siblings, 1 reply; 2+ messages in thread
From: David Sterba @ 2014-01-16 1:25 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
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>
---
fs/btrfs/sysfs.c | 23 +++++++++++++++++++++++
1 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index ba94b277e98d..d0023196e996 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -24,6 +24,7 @@
#include <linux/kobject.h>
#include <linux/bug.h>
#include <linux/genhd.h>
+#include <linux/debugfs.h>
#include "ctree.h"
#include "disk-io.h"
@@ -593,6 +594,12 @@ static int add_device_membership(struct btrfs_fs_info *fs_info)
/* /sys/fs/btrfs/ entry */
static struct kset *btrfs_kset;
+/* /sys/kernel/debug/btrfs */
+static struct dentry *btrfs_debugfs_root_dentry;
+
+/* Debugging tunables and exported data */
+u64 btrfs_debugfs_test;
+
int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info)
{
int error;
@@ -636,6 +643,18 @@ failure:
return error;
}
+static int btrfs_init_debugfs(void)
+{
+#ifdef CONFIG_DEBUG_FS
+ btrfs_debugfs_root_dentry = debugfs_create_dir("btrfs", NULL);
+ if (!btrfs_debugfs_root_dentry)
+ return -ENOMEM;
+
+ debugfs_create_u64("test", S_IRUGO | S_IWUGO, btrfs_debugfs_root_dentry,
+ &btrfs_debugfs_test);
+#endif
+}
+
int btrfs_init_sysfs(void)
{
int ret;
@@ -643,6 +662,7 @@ int btrfs_init_sysfs(void)
if (!btrfs_kset)
return -ENOMEM;
+ btrfs_init_debugfs();
init_feature_attrs();
ret = sysfs_create_group(&btrfs_kset->kobj, &btrfs_feature_attr_group);
@@ -658,5 +678,8 @@ void btrfs_exit_sysfs(void)
{
sysfs_remove_group(&btrfs_kset->kobj, &btrfs_feature_attr_group);
kset_unregister(btrfs_kset);
+#ifdef CONFIG_DEBUG_FS
+ debugfs_remove_recursive(btrfs_debugfs_root_dentry);
+#endif
}
--
1.7.9
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] btrfs: add simple debugfs interface
2014-01-16 1:25 [PATCH] btrfs: add simple debugfs interface David Sterba
@ 2014-01-28 15:50 ` Josef Bacik
0 siblings, 0 replies; 2+ messages in thread
From: Josef Bacik @ 2014-01-28 15:50 UTC (permalink / raw)
To: David Sterba, linux-btrfs
On 01/15/2014 08:25 PM, David Sterba wrote:
> 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>
> ---
> fs/btrfs/sysfs.c | 23 +++++++++++++++++++++++
> 1 files changed, 23 insertions(+), 0 deletions(-)
>
> diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
> index ba94b277e98d..d0023196e996 100644
> --- a/fs/btrfs/sysfs.c
> +++ b/fs/btrfs/sysfs.c
> @@ -24,6 +24,7 @@
> #include <linux/kobject.h>
> #include <linux/bug.h>
> #include <linux/genhd.h>
> +#include <linux/debugfs.h>
>
> #include "ctree.h"
> #include "disk-io.h"
> @@ -593,6 +594,12 @@ static int add_device_membership(struct btrfs_fs_info *fs_info)
> /* /sys/fs/btrfs/ entry */
> static struct kset *btrfs_kset;
>
> +/* /sys/kernel/debug/btrfs */
> +static struct dentry *btrfs_debugfs_root_dentry;
> +
> +/* Debugging tunables and exported data */
> +u64 btrfs_debugfs_test;
> +
> int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info)
> {
> int error;
> @@ -636,6 +643,18 @@ failure:
> return error;
> }
>
> +static int btrfs_init_debugfs(void)
> +{
> +#ifdef CONFIG_DEBUG_FS
> + btrfs_debugfs_root_dentry = debugfs_create_dir("btrfs", NULL);
> + if (!btrfs_debugfs_root_dentry)
> + return -ENOMEM;
> +
> + debugfs_create_u64("test", S_IRUGO | S_IWUGO, btrfs_debugfs_root_dentry,
> + &btrfs_debugfs_test);
> +#endif
Need to return a value.
Josef
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-01-28 15:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-16 1:25 [PATCH] btrfs: add simple debugfs interface David Sterba
2014-01-28 15:50 ` Josef Bacik
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).