[Ocfs2-commits] mfasheh commits r2615 - trunk/fs/ocfs2/cluster
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Fri Sep 23 20:19:26 CDT 2005
Author: mfasheh
Signed-off-by: jlbec
Date: 2005-09-23 20:19:24 -0500 (Fri, 23 Sep 2005)
New Revision: 2615
Added:
trunk/fs/ocfs2/cluster/sys.c
trunk/fs/ocfs2/cluster/sys.h
Modified:
trunk/fs/ocfs2/cluster/Makefile
trunk/fs/ocfs2/cluster/masklog.c
trunk/fs/ocfs2/cluster/masklog.h
trunk/fs/ocfs2/cluster/nodemanager.c
Log:
* move the interface_revision proc item to sysfs
* move the masklog items to sysfs
Signed-off-by: jlbec
Modified: trunk/fs/ocfs2/cluster/Makefile
===================================================================
--- trunk/fs/ocfs2/cluster/Makefile 2005-09-24 01:18:44 UTC (rev 2614)
+++ trunk/fs/ocfs2/cluster/Makefile 2005-09-24 01:19:24 UTC (rev 2615)
@@ -28,6 +28,7 @@
masklog.c \
nodemanager.c \
quorum.c \
+ sys.c \
tcp.c \
ver.c
@@ -39,6 +40,7 @@
ocfs2_heartbeat.h \
ocfs2_nodemanager.h \
quorum.h \
+ sys.h \
tcp.h \
tcp_internal.h \
ver.h
Modified: trunk/fs/ocfs2/cluster/masklog.c
===================================================================
--- trunk/fs/ocfs2/cluster/masklog.c 2005-09-24 01:18:44 UTC (rev 2614)
+++ trunk/fs/ocfs2/cluster/masklog.c 2005-09-24 01:19:24 UTC (rev 2615)
@@ -33,195 +33,134 @@
struct mlog_bits mlog_not_bits = MLOG_BITS_RHS(MLOG_INITIAL_NOT_MASK);
EXPORT_SYMBOL_GPL(mlog_not_bits);
-static char *mlog_bit_names[MLOG_MAX_BITS];
-
-static void *mlog_name_from_pos(loff_t *caller_pos)
+static ssize_t mlog_mask_show(u64 mask, char *buf)
{
- loff_t pos = *caller_pos;
- while (pos < ARRAY_SIZE(mlog_bit_names) && mlog_bit_names[pos] == NULL)
- pos++;
-
- if (pos >= ARRAY_SIZE(mlog_bit_names))
- return NULL;
-
- *caller_pos = pos;
- return &mlog_bit_names[pos];
-}
-
-static void *mlog_seq_start(struct seq_file *seq, loff_t *pos)
-{
- return mlog_name_from_pos(pos);
-}
-
-static void *mlog_seq_next(struct seq_file *seq, void *v, loff_t *pos)
-{
- (*pos)++;
- return mlog_name_from_pos(pos);
-}
-
-static int mlog_seq_show(struct seq_file *seq, void *v)
-{
- char **name = v;
- int bit = name - mlog_bit_names;
char *state;
- if (__mlog_test_u64((u64)1 << bit, mlog_and_bits))
+ if (__mlog_test_u64(mask, mlog_and_bits))
state = "allow";
- else if (__mlog_test_u64((u64)1 << bit, mlog_not_bits))
+ else if (__mlog_test_u64(mask, mlog_not_bits))
state = "deny";
else
state = "off";
- seq_printf(seq, "%s %s\n", *name, state);
- return 0;
+ return snprintf(buf, PAGE_SIZE, "%s\n", state);
}
-static void mlog_seq_stop(struct seq_file *p, void *v)
+static ssize_t mlog_mask_store(u64 mask, const char *buf, size_t count)
{
+ if (!strnicmp(buf, "allow", 5)) {
+ __mlog_set_u64(mask, mlog_and_bits);
+ __mlog_clear_u64(mask, mlog_not_bits);
+ } else if (!strnicmp(buf, "deny", 4)) {
+ __mlog_set_u64(mask, mlog_not_bits);
+ __mlog_clear_u64(mask, mlog_and_bits);
+ } else if (!strnicmp(buf, "off", 3)) {
+ __mlog_clear_u64(mask, mlog_not_bits);
+ __mlog_clear_u64(mask, mlog_and_bits);
+ } else
+ return -EINVAL;
+
+ return count;
}
-static struct seq_operations mlog_seq_ops = {
- .start = mlog_seq_start,
- .next = mlog_seq_next,
- .stop = mlog_seq_stop,
- .show = mlog_seq_show,
+struct mlog_attribute {
+ struct attribute attr;
+ u64 mask;
};
-static int mlog_fop_open(struct inode *inode, struct file *file)
-{
- return seq_open(file, &mlog_seq_ops);
+#define to_mlog_attr(_attr) container_of(_attr, struct mlog_attribute, attr)
+
+#define define_mask(_name) { \
+ .attr = { \
+ .name = #_name, \
+ .mode = S_IRUGO | S_IWUSR, \
+ }, \
+ .mask = ML_##_name, \
}
-static ssize_t mlog_fop_write(struct file *filp, const char __user *buf,
- size_t count, loff_t *pos)
-{
- char *name;
- char str[32], *mask, *val;
- unsigned i, masklen, namelen;
+static struct mlog_attribute mlog_attrs[MLOG_MAX_BITS] = {
+ define_mask(ENTRY),
+ define_mask(EXIT),
+ define_mask(TCP),
+ define_mask(MSG),
+ define_mask(SOCKET),
+ define_mask(HEARTBEAT),
+ define_mask(HB_BIO),
+ define_mask(DLMFS),
+ define_mask(DLM),
+ define_mask(DLM_DOMAIN),
+ define_mask(DLM_THREAD),
+ define_mask(DLM_MASTER),
+ define_mask(DLM_RECOVERY),
+ define_mask(AIO),
+ define_mask(JOURNAL),
+ define_mask(DISK_ALLOC),
+ define_mask(SUPER),
+ define_mask(FILE_IO),
+ define_mask(EXTENT_MAP),
+ define_mask(DLM_GLUE),
+ define_mask(BH_IO),
+ define_mask(UPTODATE),
+ define_mask(NAMEI),
+ define_mask(INODE),
+ define_mask(VOTE),
+ define_mask(DCACHE),
+ define_mask(CONN),
+ define_mask(QUORUM),
+ define_mask(EXPORT),
+ define_mask(ERROR),
+ define_mask(NOTICE),
+ define_mask(KTHREAD),
+};
- if (count == 0)
- return 0;
+static struct attribute *mlog_attr_ptrs[MLOG_MAX_BITS] = {NULL, };
- /* count at least mask + space + 3 for "off" */
- if (*pos != 0 || count < 5 || count >= sizeof(str))
- return -EINVAL;
+static ssize_t mlog_show(struct kobject *obj, struct attribute *attr,
+ char *buf)
+{
+ struct mlog_attribute *mlog_attr = to_mlog_attr(attr);
- if (copy_from_user(str, buf, count))
- return -EFAULT;
+ return mlog_mask_show(mlog_attr->mask, buf);
+}
- str[count] = '\0';
+static ssize_t mlog_store(struct kobject *obj, struct attribute *attr,
+ const char *buf, size_t count)
+{
+ struct mlog_attribute *mlog_attr = to_mlog_attr(attr);
- mask = str;
- val = strchr(str, ' ');
- if (val == NULL)
- return -EINVAL;
- *val = '\0';
- val++;
+ return mlog_mask_store(mlog_attr->mask, buf, count);
+}
- if (strlen(val) == 0)
- return -EINVAL;
+static struct sysfs_ops mlog_attr_ops = {
+ .show = mlog_show,
+ .store = mlog_store,
+};
- masklen = strlen(mask);
+static struct kobj_type mlog_ktype = {
+ .default_attrs = mlog_attr_ptrs,
+ .sysfs_ops = &mlog_attr_ops,
+};
- for (i = 0; i < ARRAY_SIZE(mlog_bit_names); i++) {
- name = mlog_bit_names[i];
+static struct kset mlog_kset = {
+ .kobj = {.name = "logmask", .ktype = &mlog_ktype},
+};
- if (name == NULL)
- continue;
+int mlog_sys_init(struct subsystem *o2cb_subsys)
+{
+ int i = 0;
- namelen = strlen(name);
-
- if (namelen != masklen
- || strnicmp(mask, name, namelen))
- continue;
- break;
+ while (mlog_attrs[i].attr.mode) {
+ mlog_attr_ptrs[i] = &mlog_attrs[i].attr;
+ i++;
}
- if (i == ARRAY_SIZE(mlog_bit_names))
- return -EINVAL;
+ mlog_attr_ptrs[i] = NULL;
- if (!strnicmp(val, "allow", 5)) {
- __mlog_set_u64((u64)1 << i, mlog_and_bits);
- __mlog_clear_u64((u64)1 << i, mlog_not_bits);
- } else if (!strnicmp(val, "deny", 4)) {
- __mlog_set_u64((u64)1 << i, mlog_not_bits);
- __mlog_clear_u64((u64)1 << i, mlog_and_bits);
- } else if (!strnicmp(val, "off", 3)) {
- __mlog_clear_u64((u64)1 << i, mlog_not_bits);
- __mlog_clear_u64((u64)1 << i, mlog_and_bits);
- } else
- return -EINVAL;
-
- *pos += count;
- return count;
+ mlog_kset.subsys = o2cb_subsys;
+ return kset_register(&mlog_kset);
}
-static struct file_operations mlog_seq_fops = {
- .owner = THIS_MODULE,
- .open = mlog_fop_open,
- .read = seq_read,
- .write = mlog_fop_write,
- .llseek = seq_lseek,
- .release = seq_release,
-};
-
-#define set_a_string(which) do { \
- struct mlog_bits _bits = {{0,}, }; \
- int _bit; \
- __mlog_set_u64(ML_##which, _bits); \
- _bit = find_first_bit(_bits.words, MLOG_MAX_BITS); \
- mlog_bit_names[_bit] = #which; \
-} while (0)
-
-#define LOGMASK_PROC_NAME "log_mask"
-
-void mlog_remove_proc(struct proc_dir_entry *parent)
+void mlog_sys_shutdown(void)
{
- remove_proc_entry(LOGMASK_PROC_NAME, parent);
+ kset_unregister(&mlog_kset);
}
-
-int mlog_init_proc(struct proc_dir_entry *parent)
-{
- struct proc_dir_entry *p;
-
- set_a_string(ENTRY);
- set_a_string(EXIT);
- set_a_string(TCP);
- set_a_string(MSG);
- set_a_string(SOCKET);
- set_a_string(HEARTBEAT);
- set_a_string(HB_BIO);
- set_a_string(DLMFS);
- set_a_string(DLM);
- set_a_string(DLM_DOMAIN);
- set_a_string(DLM_THREAD);
- set_a_string(DLM_MASTER);
- set_a_string(DLM_RECOVERY);
- set_a_string(AIO);
- set_a_string(JOURNAL);
- set_a_string(DISK_ALLOC);
- set_a_string(SUPER);
- set_a_string(FILE_IO);
- set_a_string(EXTENT_MAP);
- set_a_string(DLM_GLUE);
- set_a_string(BH_IO);
- set_a_string(UPTODATE);
- set_a_string(NAMEI);
- set_a_string(INODE);
- set_a_string(VOTE);
- set_a_string(DCACHE);
- set_a_string(CONN);
- set_a_string(QUORUM);
- set_a_string(EXPORT);
- set_a_string(ERROR);
- set_a_string(NOTICE);
- set_a_string(KTHREAD);
-
- p = create_proc_entry(LOGMASK_PROC_NAME, S_IRUGO, parent);
- if (p == NULL)
- return -ENOMEM;
-
- p->proc_fops = &mlog_seq_fops;
-
- return 0;
-}
-EXPORT_SYMBOL_GPL(mlog_init_proc);
Modified: trunk/fs/ocfs2/cluster/masklog.h
===================================================================
--- trunk/fs/ocfs2/cluster/masklog.h 2005-09-24 01:18:44 UTC (rev 2614)
+++ trunk/fs/ocfs2/cluster/masklog.h 2005-09-24 01:19:24 UTC (rev 2615)
@@ -265,8 +265,9 @@
#define MLFx64 "lx"
#endif
-#include <linux/proc_fs.h>
-int mlog_init_proc(struct proc_dir_entry *parent);
-void mlog_remove_proc(struct proc_dir_entry *parent);
+#include <linux/kobject.h>
+#include <linux/sysfs.h>
+int mlog_sys_init(struct subsystem *o2cb_subsys);
+void mlog_sys_shutdown(void);
#endif /* O2CLUSTER_MASKLOG_H */
Modified: trunk/fs/ocfs2/cluster/nodemanager.c
===================================================================
--- trunk/fs/ocfs2/cluster/nodemanager.c 2005-09-24 01:18:44 UTC (rev 2614)
+++ trunk/fs/ocfs2/cluster/nodemanager.c 2005-09-24 01:19:24 UTC (rev 2615)
@@ -22,7 +22,6 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/sysctl.h>
-#include <linux/proc_fs.h>
#include <linux/configfs.h>
#include "endian.h"
@@ -30,6 +29,7 @@
#include "nodemanager.h"
#include "heartbeat.h"
#include "masklog.h"
+#include "sys.h"
#include "ver.h"
/* for now we operate under the assertion that there can be only one
@@ -730,16 +730,6 @@
},
};
-#define O2NM_PROC_PATH "fs/ocfs2_nodemanager"
-static struct proc_dir_entry *o2nm_proc;
-
-#define O2NM_VERSION_PROC_NAME "interface_revision"
-
-static void o2nm_remove_proc(struct proc_dir_entry *parent)
-{
- remove_proc_entry(O2NM_VERSION_PROC_NAME, parent);
-}
-
static void __exit exit_o2nm(void)
{
if (ocfs2_table_header)
@@ -748,60 +738,11 @@
/* XXX sync with hb callbacks and shut down hb? */
o2net_unregister_hb_callbacks();
configfs_unregister_subsystem(&o2nm_cluster_group.cs_subsys);
- o2nm_remove_proc(o2nm_proc);
- mlog_remove_proc(o2nm_proc);
- remove_proc_entry(O2NM_PROC_PATH, NULL);
+ o2cb_sys_shutdown();
o2net_exit();
}
-static int o2nm_proc_read_uint(char *page, char **start, off_t off,
- int count, int *eof, unsigned int data)
-{
- int len;
-
- len = sprintf(page, "%u\n", data);
- if (len < 0)
- return len;
-
- if (len <= off + count)
- *eof = 1;
-
- *start = page + off;
-
- len -= off;
-
- if (len > count)
- len = count;
-
- if (len < 0)
- len = 0;
-
- return len;
-}
-
-static int o2nm_proc_version(char *page, char **start, off_t off,
- int count, int *eof, void *data)
-{
- return o2nm_proc_read_uint(page, start, off, count, eof,
- O2NM_API_VERSION);
-}
-
-static int o2nm_init_proc(struct proc_dir_entry *parent)
-{
- struct proc_dir_entry *p;
-
- p = create_proc_read_entry(O2NM_VERSION_PROC_NAME,
- S_IFREG | S_IRUGO,
- parent,
- o2nm_proc_version,
- NULL);
- if (!p)
- return -ENOMEM;
-
- return 0;
-}
-
static int __init init_o2nm(void)
{
int ret = -1;
@@ -830,24 +771,10 @@
goto out_callbacks;
}
- o2nm_proc = proc_mkdir(O2NM_PROC_PATH, NULL);
- if (o2nm_proc == NULL) {
- ret = -ENOMEM; /* shrug */
- goto out_subsys;
- }
-
- ret = mlog_init_proc(o2nm_proc);
- if (ret)
- goto out_remove;
-
- ret = o2nm_init_proc(o2nm_proc);
- if (ret == 0)
+ ret = o2cb_sys_init();
+ if (!ret)
goto out;
- mlog_remove_proc(o2nm_proc);
-out_remove:
- remove_proc_entry(O2NM_PROC_PATH, NULL);
-out_subsys:
configfs_unregister_subsystem(&o2nm_cluster_group.cs_subsys);
out_callbacks:
o2net_unregister_hb_callbacks();
Added: trunk/fs/ocfs2/cluster/sys.c
===================================================================
--- trunk/fs/ocfs2/cluster/sys.c 2005-09-24 01:18:44 UTC (rev 2614)
+++ trunk/fs/ocfs2/cluster/sys.c 2005-09-24 01:19:24 UTC (rev 2615)
@@ -0,0 +1,123 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * sys.c
+ *
+ * OCFS2 cluster sysfs interface
+ *
+ * Copyright (C) 2005 Oracle. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation,
+ * version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/kobject.h>
+#include <linux/sysfs.h>
+
+#include "ocfs2_nodemanager.h"
+#include "masklog.h"
+
+struct o2cb_attribute {
+ struct attribute attr;
+ ssize_t (*show)(char *buf);
+ ssize_t (*store)(const char *buf, size_t count);
+};
+
+#define O2CB_ATTR(_name, _mode, _show, _store) \
+struct o2cb_attribute o2cb_attr_##_name = __ATTR(_name, _mode, _show, _store)
+
+#define to_o2cb_subsys(k) container_of(to_kset(k), struct subsystem, kset)
+#define to_o2cb_attr(_attr) container_of(_attr, struct o2cb_attribute, attr)
+
+static ssize_t o2cb_interface_revision_show(char *buf)
+{
+ return snprintf(buf, PAGE_SIZE, "%u\n", O2NM_API_VERSION);
+}
+
+O2CB_ATTR(interface_revision, S_IFREG | S_IRUGO, o2cb_interface_revision_show, NULL);
+
+static struct attribute *o2cb_attrs[] = {
+ &o2cb_attr_interface_revision.attr,
+ NULL,
+};
+
+static ssize_t
+o2cb_show(struct kobject * kobj, struct attribute * attr, char * buffer);
+static ssize_t
+o2cb_store(struct kobject * kobj, struct attribute * attr,
+ const char * buffer, size_t count);
+static struct sysfs_ops o2cb_sysfs_ops = {
+ .show = o2cb_show,
+ .store = o2cb_store,
+};
+
+struct kobj_type o2cb_subsys_type = {
+ .default_attrs = o2cb_attrs,
+ .sysfs_ops = &o2cb_sysfs_ops,
+};
+
+/* gives us o2cb_subsys */
+decl_subsys(o2cb, NULL, NULL);
+
+static ssize_t
+o2cb_show(struct kobject * kobj, struct attribute * attr, char * buffer)
+{
+ struct o2cb_attribute *o2cb_attr = to_o2cb_attr(attr);
+ struct subsystem *sbs = to_o2cb_subsys(kobj);
+
+ BUG_ON(sbs != &o2cb_subsys);
+
+ if (o2cb_attr->show)
+ return o2cb_attr->show(buffer);
+ return -EIO;
+}
+
+static ssize_t
+o2cb_store(struct kobject * kobj, struct attribute * attr,
+ const char * buffer, size_t count)
+{
+ struct o2cb_attribute *o2cb_attr = to_o2cb_attr(attr);
+ struct subsystem *sbs = to_o2cb_subsys(kobj);
+
+ BUG_ON(sbs != &o2cb_subsys);
+
+ if (o2cb_attr->store)
+ return o2cb_attr->store(buffer, count);
+ return -EIO;
+}
+
+void o2cb_sys_shutdown(void)
+{
+ mlog_sys_shutdown();
+ subsystem_unregister(&o2cb_subsys);
+}
+
+int o2cb_sys_init(void)
+{
+ int ret;
+
+ o2cb_subsys.kset.kobj.ktype = &o2cb_subsys_type;
+ ret = subsystem_register(&o2cb_subsys);
+ if (ret)
+ return ret;
+
+ ret = mlog_sys_init(&o2cb_subsys);
+ if (ret)
+ subsystem_unregister(&o2cb_subsys);
+ return ret;
+}
Added: trunk/fs/ocfs2/cluster/sys.h
===================================================================
--- trunk/fs/ocfs2/cluster/sys.h 2005-09-24 01:18:44 UTC (rev 2614)
+++ trunk/fs/ocfs2/cluster/sys.h 2005-09-24 01:19:24 UTC (rev 2615)
@@ -0,0 +1,33 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * sys.h
+ *
+ * Function prototypes for o2cb sysfs interface
+ *
+ * Copyright (C) 2005 Oracle. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation,
+ * version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ *
+ */
+
+#ifndef O2CLUSTER_SYS_H
+#define O2CLUSTER_SYS_H
+
+void o2cb_sys_shutdown(void);
+int o2cb_sys_init(void);
+
+#endif /* O2CLUSTER_SYS_H */
More information about the Ocfs2-commits
mailing list