commit 4a04f88cba7a0cb788b127050a82e819aaf00e8e
Author: Yiannis Pericleous <[EMAIL PROTECTED]>
Date: Wed Mar 28 18:47:35 2007 -0400
made the configfs attributes code more flexible and added a 'help' attribute
diff --git a/fs/unionfs/config.c b/fs/unionfs/config.c
index 03b6dea..5875b12 100644
--- a/fs/unionfs/config.c
+++ b/fs/unionfs/config.c
@@ -45,55 +45,95 @@ int unionfs_config_init(void) {return 0;};
struct unionfs_config_attr {
struct configfs_attribute attr;
struct unionfs_attribute *unionfs_attr;
+ ssize_t (*show)(struct unionfs_attribute *, char *);
+ ssize_t (*store)(struct unionfs_attribute *, const char *, size_t);
};
+/* reads a number */
+static ssize_t unionfs_read_num(struct unionfs_attribute *attr, char *page)
+{
+ return sprintf(page, "%d\n", attr->val);
+}
+
+/* prints out information about the variables */
+static ssize_t unionfs_read_help(struct unionfs_attribute *attr, char *page)
+{
+ return sprintf(page, "\n%s",
+ TIMEOUT ": " TIMEOUT_INFO "\n\n"
+ THRESH_B ": " THRESH_B_INFO "\n\n"
+ THRESH_I ": " THRESH_I_INFO "\n\n"
+ );
+}
+
+/* writes numbers within a range */
+static ssize_t unionfs_write_num(struct unionfs_attribute *attr,
+ const char *page, size_t count)
+{
+ unsigned long tmp;
+ char *p = (char *) page;
+ tmp = simple_strtoul(p, &p, 10);
+
+ if (!p || (*p && (*p != '\n')))
+ return -EINVAL;
+
+ if (tmp > attr->max || tmp < attr->min) {
+ printk("unionfs: attribute out of range (%d - %d)\n",
+ attr->min, attr->max);
+ return -ERANGE;
+ }
+
+ attr->val = tmp;
+ return count;
+}
+
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,
+ .show = unionfs_read_num,
+ .store = unionfs_write_num,
};
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,
+ .show = unionfs_read_num,
+ .store = unionfs_write_num,
};
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,
+ .show = unionfs_read_num,
+ .store = unionfs_write_num,
};
-/* reads a number */
+static struct unionfs_config_attr unionfs_config_help = {
+ .attr = { .ca_owner = THIS_MODULE, .ca_name = HELP_NAME, .ca_mode =
S_IRUGO | S_IWUSR },
+ .unionfs_attr = &unionfs_attr_thresh_i,
+ .show = unionfs_read_help,
+};
+
+
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_config_attr,
attr)->unionfs_attr;
- return sprintf(page, "%d\n", unionfs_attr->val);
+ struct unionfs_config_attr *config_attr =
+ container_of(attr, struct unionfs_config_attr, attr);
+ if (config_attr->show)
+ return config_attr->show(config_attr->unionfs_attr, page);
+ return 0;
}
-/* 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_config_attr,
attr)->unionfs_attr;
- unsigned long tmp;
- char *p = (char *) page;
- tmp = simple_strtoul(p, &p, 10);
-
- if (!p || (*p && (*p != '\n')))
- return -EINVAL;
-
- if (tmp > unionfs_attr->max || tmp < unionfs_attr->min) {
- printk("unionfs: attribute out of range (%d - %d)\n",
- unionfs_attr->min, unionfs_attr->max);
- return -ERANGE;
- }
-
- unionfs_attr->val = tmp;
- return count;
+ struct unionfs_config_attr *config_attr =
+ container_of(attr, struct unionfs_config_attr, attr);
+ if (config_attr->store)
+ return config_attr->store(config_attr->unionfs_attr, page,
count);
+ return -EINVAL;
}
/* what we want to be visible at /config/unionfs */
@@ -101,6 +141,7 @@ static struct configfs_attribute *unionfs_global_attrs[] = {
&unionfs_config_timeout.attr,
&unionfs_config_thresh_b.attr,
&unionfs_config_thresh_i.attr,
+ &unionfs_config_help.attr,
NULL,
};
diff --git a/fs/unionfs/config.h b/fs/unionfs/config.h
index 5760a72..c733eff 100644
--- a/fs/unionfs/config.h
+++ b/fs/unionfs/config.h
@@ -5,14 +5,22 @@
#define TIMEOUT_MIN 1
#define TIMEOUT_MAX 100000
#define TIMEOUT_DEF 30
+#define TIMEOUT_INFO "defaults to 30 seconds. Controls the interval when the
ODF\n" \
+ "cleanup thread will wake up."
#define THRESH_B "block_thresh"
#define THRESH_B_MIN 1
#define THRESH_B_MAX 99
#define THRESH_B_DEF 80
+#define THRESH_B_INFO "defaults to 80%. The threshold of consumed disk blocks
in\n" \
+ "/odf, above which we begin cleaning, to bring the system below
this\n" \
+ "threshold."
#define THRESH_I "inode_thresh"
#define THRESH_I_MIN 1
#define THRESH_I_MAX 99
#define THRESH_I_DEF 80
+#define THRESH_I_INFO " defaults to 80%. The threshold of consumed inodes in
/odf,\n" \
+ "above which we begin cleaning, to bring the system below this
threshold."
+#define HELP_NAME "help"
struct unionfs_attribute {
int val;
_______________________________________________
unionfs-cvs mailing list: http://unionfs.filesystems.org/
[email protected]
http://www.fsl.cs.sunysb.edu/mailman/listinfo/unionfs-cvs