USB: drivers/usb/misc/sisusbvga/sisusb.c: kill two unused variables
[linux-2.6/next.git] / fs / gfs2 / locking / dlm / sysfs.c
blobd9fe3ca40e1859ec8420c7e512bda40bfba486e6
1 /*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
8 */
10 #include <linux/ctype.h>
11 #include <linux/stat.h>
13 #include "lock_dlm.h"
15 extern struct lm_lockops gdlm_ops;
17 static ssize_t proto_name_show(struct gdlm_ls *ls, char *buf)
19 return sprintf(buf, "%s\n", gdlm_ops.lm_proto_name);
22 static ssize_t block_show(struct gdlm_ls *ls, char *buf)
24 ssize_t ret;
25 int val = 0;
27 if (test_bit(DFL_BLOCK_LOCKS, &ls->flags))
28 val = 1;
29 ret = sprintf(buf, "%d\n", val);
30 return ret;
33 static ssize_t block_store(struct gdlm_ls *ls, const char *buf, size_t len)
35 ssize_t ret = len;
36 int val;
38 val = simple_strtol(buf, NULL, 0);
40 if (val == 1)
41 set_bit(DFL_BLOCK_LOCKS, &ls->flags);
42 else if (val == 0) {
43 clear_bit(DFL_BLOCK_LOCKS, &ls->flags);
44 gdlm_submit_delayed(ls);
45 } else {
46 ret = -EINVAL;
48 return ret;
51 static ssize_t withdraw_show(struct gdlm_ls *ls, char *buf)
53 ssize_t ret;
54 int val = 0;
56 if (test_bit(DFL_WITHDRAW, &ls->flags))
57 val = 1;
58 ret = sprintf(buf, "%d\n", val);
59 return ret;
62 static ssize_t withdraw_store(struct gdlm_ls *ls, const char *buf, size_t len)
64 ssize_t ret = len;
65 int val;
67 val = simple_strtol(buf, NULL, 0);
69 if (val == 1)
70 set_bit(DFL_WITHDRAW, &ls->flags);
71 else
72 ret = -EINVAL;
73 wake_up(&ls->wait_control);
74 return ret;
77 static ssize_t id_show(struct gdlm_ls *ls, char *buf)
79 return sprintf(buf, "%u\n", ls->id);
82 static ssize_t jid_show(struct gdlm_ls *ls, char *buf)
84 return sprintf(buf, "%d\n", ls->jid);
87 static ssize_t first_show(struct gdlm_ls *ls, char *buf)
89 return sprintf(buf, "%d\n", ls->first);
92 static ssize_t first_done_show(struct gdlm_ls *ls, char *buf)
94 return sprintf(buf, "%d\n", ls->first_done);
97 static ssize_t recover_show(struct gdlm_ls *ls, char *buf)
99 return sprintf(buf, "%d\n", ls->recover_jid);
102 static ssize_t recover_store(struct gdlm_ls *ls, const char *buf, size_t len)
104 ls->recover_jid = simple_strtol(buf, NULL, 0);
105 ls->fscb(ls->sdp, LM_CB_NEED_RECOVERY, &ls->recover_jid);
106 return len;
109 static ssize_t recover_done_show(struct gdlm_ls *ls, char *buf)
111 return sprintf(buf, "%d\n", ls->recover_jid_done);
114 static ssize_t recover_status_show(struct gdlm_ls *ls, char *buf)
116 return sprintf(buf, "%d\n", ls->recover_jid_status);
119 static ssize_t drop_count_show(struct gdlm_ls *ls, char *buf)
121 return sprintf(buf, "%d\n", ls->drop_locks_count);
124 static ssize_t drop_count_store(struct gdlm_ls *ls, const char *buf, size_t len)
126 ls->drop_locks_count = simple_strtol(buf, NULL, 0);
127 return len;
130 struct gdlm_attr {
131 struct attribute attr;
132 ssize_t (*show)(struct gdlm_ls *, char *);
133 ssize_t (*store)(struct gdlm_ls *, const char *, size_t);
136 #define GDLM_ATTR(_name,_mode,_show,_store) \
137 static struct gdlm_attr gdlm_attr_##_name = __ATTR(_name,_mode,_show,_store)
139 GDLM_ATTR(proto_name, 0444, proto_name_show, NULL);
140 GDLM_ATTR(block, 0644, block_show, block_store);
141 GDLM_ATTR(withdraw, 0644, withdraw_show, withdraw_store);
142 GDLM_ATTR(id, 0444, id_show, NULL);
143 GDLM_ATTR(jid, 0444, jid_show, NULL);
144 GDLM_ATTR(first, 0444, first_show, NULL);
145 GDLM_ATTR(first_done, 0444, first_done_show, NULL);
146 GDLM_ATTR(recover, 0644, recover_show, recover_store);
147 GDLM_ATTR(recover_done, 0444, recover_done_show, NULL);
148 GDLM_ATTR(recover_status, 0444, recover_status_show, NULL);
149 GDLM_ATTR(drop_count, 0644, drop_count_show, drop_count_store);
151 static struct attribute *gdlm_attrs[] = {
152 &gdlm_attr_proto_name.attr,
153 &gdlm_attr_block.attr,
154 &gdlm_attr_withdraw.attr,
155 &gdlm_attr_id.attr,
156 &gdlm_attr_jid.attr,
157 &gdlm_attr_first.attr,
158 &gdlm_attr_first_done.attr,
159 &gdlm_attr_recover.attr,
160 &gdlm_attr_recover_done.attr,
161 &gdlm_attr_recover_status.attr,
162 &gdlm_attr_drop_count.attr,
163 NULL,
166 static ssize_t gdlm_attr_show(struct kobject *kobj, struct attribute *attr,
167 char *buf)
169 struct gdlm_ls *ls = container_of(kobj, struct gdlm_ls, kobj);
170 struct gdlm_attr *a = container_of(attr, struct gdlm_attr, attr);
171 return a->show ? a->show(ls, buf) : 0;
174 static ssize_t gdlm_attr_store(struct kobject *kobj, struct attribute *attr,
175 const char *buf, size_t len)
177 struct gdlm_ls *ls = container_of(kobj, struct gdlm_ls, kobj);
178 struct gdlm_attr *a = container_of(attr, struct gdlm_attr, attr);
179 return a->store ? a->store(ls, buf, len) : len;
182 static struct sysfs_ops gdlm_attr_ops = {
183 .show = gdlm_attr_show,
184 .store = gdlm_attr_store,
187 static struct kobj_type gdlm_ktype = {
188 .default_attrs = gdlm_attrs,
189 .sysfs_ops = &gdlm_attr_ops,
192 static struct kset gdlm_kset = {
193 .kobj = {.name = "lock_dlm",},
194 .ktype = &gdlm_ktype,
197 int gdlm_kobject_setup(struct gdlm_ls *ls, struct kobject *fskobj)
199 int error;
201 error = kobject_set_name(&ls->kobj, "%s", "lock_module");
202 if (error) {
203 log_error("can't set kobj name %d", error);
204 return error;
207 ls->kobj.kset = &gdlm_kset;
208 ls->kobj.ktype = &gdlm_ktype;
209 ls->kobj.parent = fskobj;
211 error = kobject_register(&ls->kobj);
212 if (error)
213 log_error("can't register kobj %d", error);
215 return error;
218 void gdlm_kobject_release(struct gdlm_ls *ls)
220 kobject_unregister(&ls->kobj);
223 int gdlm_sysfs_init(void)
225 int error;
227 kobj_set_kset_s(&gdlm_kset, kernel_subsys);
228 error = kset_register(&gdlm_kset);
229 if (error)
230 printk("lock_dlm: cannot register kset %d\n", error);
232 return error;
235 void gdlm_sysfs_exit(void)
237 kset_unregister(&gdlm_kset);