ocfs2: Create stack glue sysfs files.
authorJoel Becker <joel.becker@oracle.com>
Fri, 1 Feb 2008 07:56:17 +0000 (23:56 -0800)
committerMark Fasheh <mfasheh@suse.com>
Fri, 18 Apr 2008 15:56:05 +0000 (08:56 -0700)
Introduce a set of sysfs files that describe the current stack glue
state.  The files live under /sys/fs/ocfs2.  The locking_protocol file
displays the version of ocfs2's locking code.  The
loaded_cluster_plugins file displays all of the currently loaded stack
plugins.  When filesystems are mounted, the active_cluster_plugin file
will display the plugin in use.

Signed-off-by: Joel Becker <joel.becker@oracle.com>
Signed-off-by: Mark Fasheh <mfasheh@suse.com>
fs/ocfs2/stackglue.c

index 1978c9cff0e9c6910bf260233aec2c4ec32c4807..76ae4fcebcbdea9564e3d07f9b960f6735edce96 100644 (file)
@@ -23,6 +23,9 @@
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/kmod.h>
+#include <linux/fs.h>
+#include <linux/kobject.h>
+#include <linux/sysfs.h>
 
 #include "stackglue.h"
 
@@ -335,14 +338,130 @@ int ocfs2_cluster_this_node(unsigned int *node)
 EXPORT_SYMBOL_GPL(ocfs2_cluster_this_node);
 
 
-static int __init ocfs2_stack_glue_init(void)
+/*
+ * Sysfs bits
+ */
+
+static ssize_t ocfs2_max_locking_protocol_show(struct kobject *kobj,
+                                              struct kobj_attribute *attr,
+                                              char *buf)
+{
+       ssize_t ret = 0;
+
+       spin_lock(&ocfs2_stack_lock);
+       if (lproto)
+               ret = snprintf(buf, PAGE_SIZE, "%u.%u\n",
+                              lproto->lp_max_version.pv_major,
+                              lproto->lp_max_version.pv_minor);
+       spin_unlock(&ocfs2_stack_lock);
+
+       return ret;
+}
+
+static struct kobj_attribute ocfs2_attr_max_locking_protocol =
+       __ATTR(max_locking_protocol, S_IFREG | S_IRUGO,
+              ocfs2_max_locking_protocol_show, NULL);
+
+static ssize_t ocfs2_loaded_cluster_plugins_show(struct kobject *kobj,
+                                                struct kobj_attribute *attr,
+                                                char *buf)
 {
+       ssize_t ret = 0, total = 0, remain = PAGE_SIZE;
+       struct ocfs2_stack_plugin *p;
+
+       spin_lock(&ocfs2_stack_lock);
+       list_for_each_entry(p, &ocfs2_stack_list, sp_list) {
+               ret = snprintf(buf, remain, "%s\n",
+                              p->sp_name);
+               if (ret < 0) {
+                       total = ret;
+                       break;
+               }
+               if (ret == remain) {
+                       /* snprintf() didn't fit */
+                       total = -E2BIG;
+                       break;
+               }
+               total += ret;
+               remain -= ret;
+       }
+       spin_unlock(&ocfs2_stack_lock);
+
+       return total;
+}
+
+static struct kobj_attribute ocfs2_attr_loaded_cluster_plugins =
+       __ATTR(loaded_cluster_plugins, S_IFREG | S_IRUGO,
+              ocfs2_loaded_cluster_plugins_show, NULL);
+
+static ssize_t ocfs2_active_cluster_plugin_show(struct kobject *kobj,
+                                               struct kobj_attribute *attr,
+                                               char *buf)
+{
+       ssize_t ret = 0;
+
+       spin_lock(&ocfs2_stack_lock);
+       if (active_stack) {
+               ret = snprintf(buf, PAGE_SIZE, "%s\n",
+                              active_stack->sp_name);
+               if (ret == PAGE_SIZE)
+                       ret = -E2BIG;
+       }
+       spin_unlock(&ocfs2_stack_lock);
+
+       return ret;
+}
+
+static struct kobj_attribute ocfs2_attr_active_cluster_plugin =
+       __ATTR(active_cluster_plugin, S_IFREG | S_IRUGO,
+              ocfs2_active_cluster_plugin_show, NULL);
+
+static struct attribute *ocfs2_attrs[] = {
+       &ocfs2_attr_max_locking_protocol.attr,
+       &ocfs2_attr_loaded_cluster_plugins.attr,
+       &ocfs2_attr_active_cluster_plugin.attr,
+       NULL,
+};
+
+static struct attribute_group ocfs2_attr_group = {
+       .attrs = ocfs2_attrs,
+};
+
+static struct kset *ocfs2_kset;
+
+static void ocfs2_sysfs_exit(void)
+{
+       kset_unregister(ocfs2_kset);
+}
+
+static int ocfs2_sysfs_init(void)
+{
+       int ret;
+
+       ocfs2_kset = kset_create_and_add("ocfs2", NULL, fs_kobj);
+       if (!ocfs2_kset)
+               return -ENOMEM;
+
+       ret = sysfs_create_group(&ocfs2_kset->kobj, &ocfs2_attr_group);
+       if (ret)
+               goto error;
+
        return 0;
+
+error:
+       kset_unregister(ocfs2_kset);
+       return ret;
+}
+
+static int __init ocfs2_stack_glue_init(void)
+{
+       return ocfs2_sysfs_init();
 }
 
 static void __exit ocfs2_stack_glue_exit(void)
 {
        lproto = NULL;
+       ocfs2_sysfs_exit();
 }
 
 MODULE_AUTHOR("Oracle");