Re: [PATCH 5/5] jffs2: Allow selection of compression mode via a sysfs attribute

2007-04-25 Thread David Woodhouse
On Wed, 2007-02-28 at 19:13 +, Richard Purdie wrote:
> Allow selection of the compression mode for jffs2 via a sysfs 
> attribute. This establishes a sysfs presence for jffs2 through
> which other compression options could easily be exported too. 

And other options like GC threshold and other allocation things. So
perhaps put the sysfs subsystem_register() and other core bits into a
generic (and Linux-specific) file?

-- 
dwmw2

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 5/5] jffs2: Allow selection of compression mode via a sysfs attribute

2007-02-28 Thread Richard Purdie
On Wed, 2007-02-28 at 21:39 +0200, Artem Bityutskiy wrote:
> On Wed, 2007-02-28 at 19:13 +, Richard Purdie wrote:
> > +/* gives us jffs2_subsys */
> > +static decl_subsys(jffs2, NULL, NULL);
> 
> There is actually a file-system subsys - look up for fs_subsys. It is
> declared at fs/namespace.c.

Further down the patch you'll see:

+   kset_set_kset_s(&jffs2_subsys, fs_subsys);

There was a reason for doing that instead using fs_subsys in the above
although I can't remember why offhand. I did try it and it didn't work
as expected...

Regards,

Richard

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 5/5] jffs2: Allow selection of compression mode via a sysfs attribute

2007-02-28 Thread Artem Bityutskiy
Hi Richard,

On Wed, 2007-02-28 at 19:13 +, Richard Purdie wrote:
> +/* gives us jffs2_subsys */
> +static decl_subsys(jffs2, NULL, NULL);

There is actually a file-system subsys - look up for fs_subsys. It is
declared at fs/namespace.c.

-- 
Best regards,
Artem Bityutskiy (Битюцкий Артём)

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 5/5] jffs2: Allow selection of compression mode via a sysfs attribute

2007-02-28 Thread Richard Purdie
Allow selection of the compression mode for jffs2 via a sysfs 
attribute. This establishes a sysfs presence for jffs2 through
which other compression options could easily be exported too.

Signed-off-by: Richard Purdie <[EMAIL PROTECTED]>

---
 fs/jffs2/compr.c |  131 +++
 1 file changed, 94 insertions(+), 37 deletions(-)

Index: linux/fs/jffs2/compr.c
===
--- linux.orig/fs/jffs2/compr.c 2007-02-28 18:12:33.0 +
+++ linux/fs/jffs2/compr.c  2007-02-28 18:12:33.0 +
@@ -13,6 +13,7 @@
  *
  */
 
+#include 
 #include "compr.h"
 
 static DEFINE_SPINLOCK(jffs2_compressor_list_lock);
@@ -298,6 +299,43 @@ int jffs2_unregister_compressor(struct j
 return 0;
 }
 
+char *jffs2_get_compression_mode_name(void)
+{
+switch (jffs2_compression_mode) {
+case JFFS2_COMPR_MODE_NONE:
+return "none";
+case JFFS2_COMPR_MODE_PRIORITY:
+return "priority";
+case JFFS2_COMPR_MODE_SIZE:
+return "size";
+   case JFFS2_COMPR_MODE_FAVOURLZO:
+   return "favourlzo";
+}
+return "unkown";
+}
+
+int jffs2_set_compression_mode_name(const char *name)
+{
+if (!strncmp("none", name, 4)) {
+jffs2_compression_mode = JFFS2_COMPR_MODE_NONE;
+return 0;
+}
+if (!strncmp("priority", name, 8)) {
+jffs2_compression_mode = JFFS2_COMPR_MODE_PRIORITY;
+return 0;
+}
+if (!strncmp("size", name, 4)) {
+jffs2_compression_mode = JFFS2_COMPR_MODE_SIZE;
+return 0;
+}
+   if (!strncmp("favourlzo", name, 9)) {
+   jffs2_compression_mode = JFFS2_COMPR_MODE_FAVOURLZO;
+   return 0;
+   }
+return -EINVAL;
+}
+
+
 #ifdef CONFIG_JFFS2_PROC
 
 #define JFFS2_STAT_BUF_SIZE 16000
@@ -347,42 +385,6 @@ char *jffs2_stats(void)
 return buf;
 }
 
-char *jffs2_get_compression_mode_name(void)
-{
-switch (jffs2_compression_mode) {
-case JFFS2_COMPR_MODE_NONE:
-return "none";
-case JFFS2_COMPR_MODE_PRIORITY:
-return "priority";
-case JFFS2_COMPR_MODE_SIZE:
-return "size";
-case JFFS2_COMPR_MODE_FAVOURLZO:
-return "favourlzo";
-}
-return "unkown";
-}
-
-int jffs2_set_compression_mode_name(const char *name)
-{
-if (!strcmp("none",name)) {
-jffs2_compression_mode = JFFS2_COMPR_MODE_NONE;
-return 0;
-}
-if (!strcmp("priority",name)) {
-jffs2_compression_mode = JFFS2_COMPR_MODE_PRIORITY;
-return 0;
-}
-if (!strcmp("size",name)) {
-jffs2_compression_mode = JFFS2_COMPR_MODE_SIZE;
-return 0;
-}
-if (!strncmp("favourlzo", name, 9)) {
-jffs2_compression_mode = JFFS2_COMPR_MODE_FAVOURLZO;
-return 0;
-}
-return 1;
-}
-
 static int jffs2_compressor_Xable(const char *name, int disabled)
 {
 struct jffs2_compressor *this;
@@ -448,8 +450,54 @@ void jffs2_free_comprbuf(unsigned char *
 kfree(comprbuf);
 }
 
+static struct attribute jffs2_attr_mode = {
+   .name = "mode",
+   .mode = S_IRUGO | S_IWUSR,
+};
+
+static struct attribute *jffs2_attrs[] = {
+   &jffs2_attr_mode,
+   NULL,
+};
+
+static ssize_t jffs2_attr_show(struct kobject *kobj, struct attribute *attr,
+   char *page)
+{
+   if (!strcmp("mode", attr->name))
+   return sprintf(page, "%s\n", jffs2_get_compression_mode_name());
+   return 0;
+}
+
+static ssize_t jffs2_attr_store(struct kobject *kobj, struct attribute *attr,
+   const char *page, size_t count)
+{
+   int ret = -EINVAL;
+
+   if (!strcmp("mode", attr->name)) {
+   ret = jffs2_set_compression_mode_name(page);
+   if (ret >= 0)
+   return count;
+   }
+   return ret;
+}
+
+static struct sysfs_ops jffs2_sysfs_ops = {
+   .show   =   jffs2_attr_show,
+   .store  =   jffs2_attr_store,
+};
+
+static struct kobj_type jffs2_subsys_type = {
+   .default_attrs  = jffs2_attrs,
+   .sysfs_ops  = &jffs2_sysfs_ops,
+};
+
+/* gives us jffs2_subsys */
+static decl_subsys(jffs2, NULL, NULL);
+
 int __init jffs2_compressors_init(void)
 {
+   int ret;
+
 /* Registering compressors */
 #ifdef CONFIG_JFFS2_ZLIB
 jffs2_zlib_init();
@@ -481,12 +529,21 @@ int __init jffs2_compressors_init(void)
 #endif
 #endif
 #endif
+   /* Errors here are not fatal */
+   kset_set_kset_s(&jffs2_subsys, fs_subsys);
+   jffs2_subsys.kset.kobj.ktype = &jffs2_subsys_type;
+   ret = subsystem_register(&jffs2_subsys);
+   if (ret)
+   printk(KERN_WA