2007-11-02 17:16:34

by Latchesar Ionkov

[permalink] [raw]
Subject: [PATCH] 9p: basic sysfs support

This patch implements the basic sysfs support for 9p. If CONFIG_NET_9P_DEBUG
is defined, allows reading and modifying the debug level via
/sysfs/fs/9p/debuglevel.

Signed-off-by: Latchesar Ionkov <[email protected]>

---
include/net/9p/9p.h | 1 +
net/9p/mod.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/include/net/9p/9p.h b/include/net/9p/9p.h
index 686425a..9ace484 100644
--- a/include/net/9p/9p.h
+++ b/include/net/9p/9p.h
@@ -377,6 +377,7 @@ struct p9_fcall {
};

struct p9_idpool;
+extern struct kset p9_subsys;

int p9_deserialize_stat(void *buf, u32 buflen, struct p9_stat *stat,
int dotu);
diff --git a/net/9p/mod.c b/net/9p/mod.c
index 41d70f4..8205c4b 100644
--- a/net/9p/mod.c
+++ b/net/9p/mod.c
@@ -29,6 +29,7 @@
#include <net/9p/9p.h>
#include <linux/fs.h>
#include <linux/parser.h>
+#include <linux/fs.h>
#include <net/9p/transport.h>
#include <linux/list.h>

@@ -37,8 +38,17 @@ unsigned int p9_debug_level = 0; /* feature-rific global debug level */
EXPORT_SYMBOL(p9_debug_level);
module_param_named(debug, p9_debug_level, uint, 0);
MODULE_PARM_DESC(debug, "9P debugging level");
+
+static ssize_t p9_debug_show(struct kset *, char *);
+static ssize_t p9_debug_store(struct kset *, const char *, size_t);
+
+static struct subsys_attribute p9_debug_attr = __ATTR(debuglevel, 0644,
+ p9_debug_show, p9_debug_store);
#endif

+decl_subsys_name(p9, 9p, NULL, NULL);
+EXPORT_SYMBOL(p9_subsys);
+
extern int p9_mux_global_init(void);
extern void p9_mux_global_exit(void);

@@ -99,6 +109,27 @@ struct p9_trans_module *v9fs_default_trans(void)
}
EXPORT_SYMBOL(v9fs_default_trans);

+#ifdef CONFIG_NET_9P_DEBUG
+
+static ssize_t p9_debug_show(struct kset *k, char *buf)
+{
+ return snprintf(buf, PAGE_SIZE, "%d\n", p9_debug_level);
+}
+
+static ssize_t p9_debug_store(struct kset *k, const char *buf, size_t buflen)
+{
+ int n;
+ char *p;
+
+ n = simple_strtol(buf, &p, 0);
+ if (*p != '\n' && *p != '\0')
+ return EINVAL;
+
+ p9_debug_level = n;
+ return buflen;
+}
+
+#endif

/**
* v9fs_init - Initialize module
@@ -109,6 +140,19 @@ static int __init init_p9(void)
int ret;

p9_error_init();
+ kobj_set_kset_s(&p9_subsys, fs_subsys);
+ ret = subsystem_register(&p9_subsys);
+ if (ret)
+ return ret;
+
+#ifdef CONFIG_NET_9P_DEBUG
+ ret = subsys_create_file(&p9_subsys, &p9_debug_attr);
+ if (ret) {
+ subsystem_unregister(&p9_subsys);
+ return ret;
+ }
+#endif
+
printk(KERN_INFO "Installing 9P2000 support\n");
ret = p9_mux_global_init();
if (ret) {
@@ -127,6 +171,7 @@ static int __init init_p9(void)
static void __exit exit_p9(void)
{
p9_mux_global_exit();
+ subsystem_unregister(&p9_subsys);
}

module_init(init_p9)


2007-11-02 18:31:08

by Greg KH

[permalink] [raw]
Subject: Re: [PATCH] 9p: basic sysfs support

On Fri, Nov 02, 2007 at 10:53:31AM -0600, Latchesar Ionkov wrote:
> This patch implements the basic sysfs support for 9p. If CONFIG_NET_9P_DEBUG
> is defined, allows reading and modifying the debug level via
> /sysfs/fs/9p/debuglevel.

Since this is a debug-only type file, why not just put it in debugfs
instead?

And I have a huge patch-series pending that will make adding files like
this to sysfs much easier in the future. But nice job, it looks like
you got it all correct, which is pretty hard to do first time these days
due to the complexity of the current interface :)

thanks,

greg k-h

2007-11-02 19:14:19

by Latchesar Ionkov

[permalink] [raw]
Subject: Re: [PATCH] 9p: basic sysfs support

This patch adds only the basic 9p functionality, we use the sysfs
interface extensively for configuring the 9p in-kernel servers (patch
7 in the series). The v9fs filesyste will probably add some more
subdirectories for authenticating users and mapping user names to
uids...

Thanks,
Lucho

On 11/2/07, Greg KH <[email protected]> wrote:
> On Fri, Nov 02, 2007 at 10:53:31AM -0600, Latchesar Ionkov wrote:
> > This patch implements the basic sysfs support for 9p. If CONFIG_NET_9P_DEBUG
> > is defined, allows reading and modifying the debug level via
> > /sysfs/fs/9p/debuglevel.
>
> Since this is a debug-only type file, why not just put it in debugfs
> instead?
>
> And I have a huge patch-series pending that will make adding files like
> this to sysfs much easier in the future. But nice job, it looks like
> you got it all correct, which is pretty hard to do first time these days
> due to the complexity of the current interface :)
>
> thanks,
>
> greg k-h
>

2007-11-03 00:22:22

by Greg KH

[permalink] [raw]
Subject: Re: [PATCH] 9p: basic sysfs support

On Fri, Nov 02, 2007 at 01:14:05PM -0600, Latchesar Ionkov wrote:
> This patch adds only the basic 9p functionality, we use the sysfs
> interface extensively for configuring the 9p in-kernel servers (patch
> 7 in the series). The v9fs filesyste will probably add some more
> subdirectories for authenticating users and mapping user names to
> uids...

Ah, ok. I don't know your projected time frame for this patch series,
but if it's for 2.6.25, you might want to look at the set of patches I
just sent to lkml to help make files like this easier to create thanks
to the great work from Kay Sievers.

thanks,

greg k-h