commit 44406961587c22fb020aca9e9e593d9deef4cf33
Author: Yiannis Pericleous <[EMAIL PROTECTED]>
Date: Wed Mar 28 17:42:22 2007 -0400
separated configfs code and ifdefd it
diff --git a/fs/unionfs/config.c b/fs/unionfs/config.c
index a734e43..03b6dea 100644
--- a/fs/unionfs/config.c
+++ b/fs/unionfs/config.c
@@ -1,41 +1,26 @@
#include <linux/module.h>
#include "config.h"
-
-#define TIMEOUT "timeout"
-#define TIMEOUT_MIN 1
-#define TIMEOUT_MAX 1000
-#define TIMEOUT_DEF 30
-#define THRESH_B "block_thresh"
-#define THRESH_B_MIN 1
-#define THRESH_B_MAX 99
-#define THRESH_B_DEF 80
-#define THRESH_I "inode_thresh"
-#define THRESH_I_MIN 1
-#define THRESH_I_MAX 99
-#define THRESH_I_DEF 80
-
+/* our configurable variables */
static struct unionfs_attribute unionfs_attr_timeout = {
- .attr = { .ca_owner = THIS_MODULE, .ca_name = TIMEOUT, .ca_mode =
S_IRUGO | S_IWUSR },
.min = TIMEOUT_MIN,
.max = TIMEOUT_MAX,
.val = TIMEOUT_DEF,
};
static struct unionfs_attribute unionfs_attr_thresh_b = {
- .attr = { .ca_owner = THIS_MODULE, .ca_name = THRESH_B, .ca_mode =
S_IRUGO | S_IWUSR },
.min = THRESH_B_MIN,
.max = THRESH_B_MAX,
.val = THRESH_B_DEF,
};
static struct unionfs_attribute unionfs_attr_thresh_i = {
- .attr = { .ca_owner = THIS_MODULE, .ca_name = THRESH_I, .ca_mode =
S_IRUGO | S_IWUSR },
.min = THRESH_I_MIN,
.max = THRESH_I_MAX,
.val = THRESH_I_DEF,
};
+/* group them for easy acces by all unionfs mounts */
static struct unionfs_attributes unionfs_attributes = {
.timeout = &unionfs_attr_timeout,
.thresh_b = &unionfs_attr_thresh_b,
@@ -47,21 +32,53 @@ extern struct unionfs_attributes *get_attributes()
return &unionfs_attributes;
}
+
+#ifndef CONFIG_CONFIGFS_FS
+
+void unionfs_config_exit(void) {};
+int unionfs_config_init(void) {return 0;};
+
+#else /* configfs specific code starts here */
+
+#include <linux/configfs.h>
+
+struct unionfs_config_attr {
+ struct configfs_attribute attr;
+ struct unionfs_attribute *unionfs_attr;
+};
+
+static struct unionfs_config_attr unionfs_config_timeout = {
+ .attr = { .ca_owner = THIS_MODULE, .ca_name = TIMEOUT, .ca_mode =
S_IRUGO | S_IWUSR },
+ .unionfs_attr = &unionfs_attr_timeout,
+};
+
+static struct unionfs_config_attr unionfs_config_thresh_b = {
+ .attr = { .ca_owner = THIS_MODULE, .ca_name = THRESH_B, .ca_mode =
S_IRUGO | S_IWUSR },
+ .unionfs_attr = &unionfs_attr_thresh_b,
+};
+
+static struct unionfs_config_attr unionfs_config_thresh_i = {
+ .attr = { .ca_owner = THIS_MODULE, .ca_name = THRESH_I, .ca_mode =
S_IRUGO | S_IWUSR },
+ .unionfs_attr = &unionfs_attr_thresh_i,
+};
+
+/* reads a number */
static ssize_t unionfs_attr_show(struct config_item *item,
struct configfs_attribute *attr,
char *page)
{
struct unionfs_attribute *unionfs_attr =
- container_of(attr, struct unionfs_attribute, attr);
+ container_of(attr, struct unionfs_config_attr,
attr)->unionfs_attr;
return sprintf(page, "%d\n", unionfs_attr->val);
}
+/* writes numbers within a range */
static ssize_t unionfs_attr_store(struct config_item *item,
struct configfs_attribute *attr,
const char *page, size_t count)
{
struct unionfs_attribute *unionfs_attr =
- container_of(attr, struct unionfs_attribute, attr);
+ container_of(attr, struct unionfs_config_attr,
attr)->unionfs_attr;
unsigned long tmp;
char *p = (char *) page;
tmp = simple_strtoul(p, &p, 10);
@@ -79,13 +96,15 @@ static ssize_t unionfs_attr_store(struct config_item *item,
return count;
}
+/* what we want to be visible at /config/unionfs */
static struct configfs_attribute *unionfs_global_attrs[] = {
- &unionfs_attr_timeout.attr,
- &unionfs_attr_thresh_b.attr,
- &unionfs_attr_thresh_i.attr,
+ &unionfs_config_timeout.attr,
+ &unionfs_config_thresh_b.attr,
+ &unionfs_config_thresh_i.attr,
NULL,
};
+/* only allow show and store, no group/item creation */
static struct configfs_item_operations unionfs_global_item_ops = {
.show_attribute = unionfs_attr_show,
.store_attribute = unionfs_attr_store,
@@ -106,31 +125,32 @@ static struct configfs_subsystem unionfs_subsys = {
},
};
+/* register the unionfs subsystem */
int unionfs_config_init(void)
{
int ret;
- struct configfs_subsystem *subsys;
- subsys = &unionfs_subsys;
-
- config_group_init(&subsys->su_group);
- init_MUTEX(&subsys->su_sem);
- ret = configfs_register_subsystem(subsys);
+ config_group_init(&unionfs_subsys.su_group);
+ init_MUTEX(&unionfs_subsys.su_sem);
+ ret = configfs_register_subsystem(&unionfs_subsys);
if (ret) {
printk(KERN_ERR "Error %d while registering subsystem %s\n",
ret,
- subsys->su_group.cg_item.ci_namebuf);
+ unionfs_subsys.su_group.cg_item.ci_namebuf);
goto out_unregister;
}
return 0;
out_unregister:
- configfs_unregister_subsystem(subsys);
+ configfs_unregister_subsystem(&unionfs_subsys);
return ret;
}
+/* unregister the unionfs subsystem */
void unionfs_config_exit(void)
{
configfs_unregister_subsystem(&unionfs_subsys);
}
+
+#endif /*CONFIG_CONFIGFS_FS*/
diff --git a/fs/unionfs/config.h b/fs/unionfs/config.h
index 5a10c77..5760a72 100644
--- a/fs/unionfs/config.h
+++ b/fs/unionfs/config.h
@@ -1,11 +1,21 @@
-#ifndef __CONFIG_H__
-#define __CONFIG_H__
+#ifndef _CONFIG_H__
+#define _CONFIG_H__
-#include <linux/configfs.h>
+#define TIMEOUT "timeout"
+#define TIMEOUT_MIN 1
+#define TIMEOUT_MAX 100000
+#define TIMEOUT_DEF 30
+#define THRESH_B "block_thresh"
+#define THRESH_B_MIN 1
+#define THRESH_B_MAX 99
+#define THRESH_B_DEF 80
+#define THRESH_I "inode_thresh"
+#define THRESH_I_MIN 1
+#define THRESH_I_MAX 99
+#define THRESH_I_DEF 80
struct unionfs_attribute {
- struct configfs_attribute attr;
- int val;
+ int val;
int min;
int max;
};
@@ -15,6 +25,7 @@ struct unionfs_attributes {
struct unionfs_attribute *thresh_b;
struct unionfs_attribute *thresh_i;
};
+
extern void unionfs_config_exit(void);
extern int unionfs_config_init(void);
_______________________________________________
unionfs-cvs mailing list: http://unionfs.filesystems.org/
[email protected]
http://www.fsl.cs.sunysb.edu/mailman/listinfo/unionfs-cvs