1 /******************************************************************************
2 *******************************************************************************
4 ** Copyright (C) 2005 Red Hat, Inc. All rights reserved.
6 ** This copyrighted material is made available to anyone wishing to use,
7 ** modify, copy, or redistribute it subject to the terms and conditions
8 ** of the GNU General Public License v.2.
10 *******************************************************************************
11 ******************************************************************************/
13 #include <linux/ctype.h>
14 #include <linux/stat.h>
18 static ssize_t gdlm_block_show(struct gdlm_ls *ls, char *buf)
23 if (test_bit(DFL_BLOCK_LOCKS, &ls->flags))
25 ret = sprintf(buf, "%d\n", val);
29 static ssize_t gdlm_block_store(struct gdlm_ls *ls, const char *buf, size_t len)
34 val = simple_strtol(buf, NULL, 0);
37 set_bit(DFL_BLOCK_LOCKS, &ls->flags);
39 clear_bit(DFL_BLOCK_LOCKS, &ls->flags);
40 gdlm_submit_delayed(ls);
46 static ssize_t gdlm_mounted_show(struct gdlm_ls *ls, char *buf)
51 if (test_bit(DFL_TERMINATE, &ls->flags))
53 else if (test_bit(DFL_LEAVE_DONE, &ls->flags))
55 else if (test_bit(DFL_JOIN_DONE, &ls->flags))
57 ret = sprintf(buf, "%d\n", val);
61 static ssize_t gdlm_mounted_store(struct gdlm_ls *ls, const char *buf, size_t len)
66 val = simple_strtol(buf, NULL, 0);
69 set_bit(DFL_JOIN_DONE, &ls->flags);
71 set_bit(DFL_LEAVE_DONE, &ls->flags);
73 set_bit(DFL_TERMINATE, &ls->flags);
74 set_bit(DFL_JOIN_DONE, &ls->flags);
75 set_bit(DFL_LEAVE_DONE, &ls->flags);
78 wake_up(&ls->wait_control);
82 static ssize_t gdlm_withdraw_show(struct gdlm_ls *ls, char *buf)
87 if (test_bit(DFL_WITHDRAW, &ls->flags))
89 ret = sprintf(buf, "%d\n", val);
93 static ssize_t gdlm_withdraw_store(struct gdlm_ls *ls, const char *buf, size_t len)
98 val = simple_strtol(buf, NULL, 0);
101 set_bit(DFL_WITHDRAW, &ls->flags);
104 wake_up(&ls->wait_control);
108 static ssize_t gdlm_jid_show(struct gdlm_ls *ls, char *buf)
110 return sprintf(buf, "%u\n", ls->jid);
113 static ssize_t gdlm_jid_store(struct gdlm_ls *ls, const char *buf, size_t len)
115 ls->jid = simple_strtol(buf, NULL, 0);
119 static ssize_t gdlm_first_show(struct gdlm_ls *ls, char *buf)
121 return sprintf(buf, "%u\n", ls->first);
124 static ssize_t gdlm_first_store(struct gdlm_ls *ls, const char *buf, size_t len)
126 ls->first = simple_strtol(buf, NULL, 0);
130 static ssize_t gdlm_first_done_show(struct gdlm_ls *ls, char *buf)
132 return sprintf(buf, "%d\n", ls->first_done);
135 static ssize_t gdlm_recover_show(struct gdlm_ls *ls, char *buf)
137 return sprintf(buf, "%u\n", ls->recover_jid);
140 static ssize_t gdlm_recover_store(struct gdlm_ls *ls, const char *buf, size_t len)
142 ls->recover_jid = simple_strtol(buf, NULL, 0);
143 ls->fscb(ls->fsdata, LM_CB_NEED_RECOVERY, &ls->recover_jid);
147 static ssize_t gdlm_recover_done_show(struct gdlm_ls *ls, char *buf)
150 ret = sprintf(buf, "%d\n", ls->recover_done);
154 static ssize_t gdlm_cluster_show(struct gdlm_ls *ls, char *buf)
157 ret = sprintf(buf, "%s\n", ls->clustername);
161 static ssize_t gdlm_options_show(struct gdlm_ls *ls, char *buf)
165 if (ls->fsflags & LM_MFLAG_SPECTATOR)
166 ret += sprintf(buf, "spectator ");
172 struct attribute attr;
173 ssize_t (*show)(struct gdlm_ls *, char *);
174 ssize_t (*store)(struct gdlm_ls *, const char *, size_t);
177 static struct gdlm_attr gdlm_attr_block = {
178 .attr = {.name = "block", .mode = S_IRUGO | S_IWUSR},
179 .show = gdlm_block_show,
180 .store = gdlm_block_store
183 static struct gdlm_attr gdlm_attr_mounted = {
184 .attr = {.name = "mounted", .mode = S_IRUGO | S_IWUSR},
185 .show = gdlm_mounted_show,
186 .store = gdlm_mounted_store
189 static struct gdlm_attr gdlm_attr_withdraw = {
190 .attr = {.name = "withdraw", .mode = S_IRUGO | S_IWUSR},
191 .show = gdlm_withdraw_show,
192 .store = gdlm_withdraw_store
195 static struct gdlm_attr gdlm_attr_jid = {
196 .attr = {.name = "jid", .mode = S_IRUGO | S_IWUSR},
197 .show = gdlm_jid_show,
198 .store = gdlm_jid_store
201 static struct gdlm_attr gdlm_attr_first = {
202 .attr = {.name = "first", .mode = S_IRUGO | S_IWUSR},
203 .show = gdlm_first_show,
204 .store = gdlm_first_store
207 static struct gdlm_attr gdlm_attr_first_done = {
208 .attr = {.name = "first_done", .mode = S_IRUGO},
209 .show = gdlm_first_done_show,
212 static struct gdlm_attr gdlm_attr_recover = {
213 .attr = {.name = "recover", .mode = S_IRUGO | S_IWUSR},
214 .show = gdlm_recover_show,
215 .store = gdlm_recover_store
218 static struct gdlm_attr gdlm_attr_recover_done = {
219 .attr = {.name = "recover_done", .mode = S_IRUGO | S_IWUSR},
220 .show = gdlm_recover_done_show,
223 static struct gdlm_attr gdlm_attr_cluster = {
224 .attr = {.name = "cluster", .mode = S_IRUGO | S_IWUSR},
225 .show = gdlm_cluster_show,
228 static struct gdlm_attr gdlm_attr_options = {
229 .attr = {.name = "options", .mode = S_IRUGO | S_IWUSR},
230 .show = gdlm_options_show,
233 static struct attribute *gdlm_attrs[] = {
234 &gdlm_attr_block.attr,
235 &gdlm_attr_mounted.attr,
236 &gdlm_attr_withdraw.attr,
238 &gdlm_attr_first.attr,
239 &gdlm_attr_first_done.attr,
240 &gdlm_attr_recover.attr,
241 &gdlm_attr_recover_done.attr,
242 &gdlm_attr_cluster.attr,
243 &gdlm_attr_options.attr,
247 static ssize_t gdlm_attr_show(struct kobject *kobj, struct attribute *attr,
250 struct gdlm_ls *ls = container_of(kobj, struct gdlm_ls, kobj);
251 struct gdlm_attr *a = container_of(attr, struct gdlm_attr, attr);
252 return a->show ? a->show(ls, buf) : 0;
255 static ssize_t gdlm_attr_store(struct kobject *kobj, struct attribute *attr,
256 const char *buf, size_t len)
258 struct gdlm_ls *ls = container_of(kobj, struct gdlm_ls, kobj);
259 struct gdlm_attr *a = container_of(attr, struct gdlm_attr, attr);
260 return a->store ? a->store(ls, buf, len) : len;
263 static struct sysfs_ops gdlm_attr_ops = {
264 .show = gdlm_attr_show,
265 .store = gdlm_attr_store,
268 static struct kobj_type gdlm_ktype = {
269 .default_attrs = gdlm_attrs,
270 .sysfs_ops = &gdlm_attr_ops,
273 static struct kset gdlm_kset = {
274 .subsys = &kernel_subsys,
275 .kobj = {.name = "lock_dlm",},
276 .ktype = &gdlm_ktype,
279 int gdlm_kobject_setup(struct gdlm_ls *ls)
283 error = kobject_set_name(&ls->kobj, "%s", ls->fsname);
287 ls->kobj.kset = &gdlm_kset;
288 ls->kobj.ktype = &gdlm_ktype;
290 error = kobject_register(&ls->kobj);
295 void gdlm_kobject_release(struct gdlm_ls *ls)
297 kobject_unregister(&ls->kobj);
300 int gdlm_sysfs_init(void)
304 error = kset_register(&gdlm_kset);
306 printk("lock_dlm: cannot register kset %d\n", error);
311 void gdlm_sysfs_exit(void)
313 kset_unregister(&gdlm_kset);