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 v.2.
10 #include <linux/ctype.h>
11 #include <linux/stat.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)
27 if (test_bit(DFL_BLOCK_LOCKS, &ls->flags))
29 ret = sprintf(buf, "%d\n", val);
33 static ssize_t block_store(struct gdlm_ls *ls, const char *buf, size_t len)
38 val = simple_strtol(buf, NULL, 0);
41 set_bit(DFL_BLOCK_LOCKS, &ls->flags);
43 clear_bit(DFL_BLOCK_LOCKS, &ls->flags);
44 gdlm_submit_delayed(ls);
50 static ssize_t withdraw_show(struct gdlm_ls *ls, char *buf)
55 if (test_bit(DFL_WITHDRAW, &ls->flags))
57 ret = sprintf(buf, "%d\n", val);
61 static ssize_t withdraw_store(struct gdlm_ls *ls, const char *buf, size_t len)
66 val = simple_strtol(buf, NULL, 0);
69 set_bit(DFL_WITHDRAW, &ls->flags);
72 wake_up(&ls->wait_control);
76 static ssize_t id_show(struct gdlm_ls *ls, char *buf)
78 return sprintf(buf, "%u\n", ls->id);
81 static ssize_t jid_show(struct gdlm_ls *ls, char *buf)
83 return sprintf(buf, "%d\n", ls->jid);
86 static ssize_t first_show(struct gdlm_ls *ls, char *buf)
88 return sprintf(buf, "%d\n", ls->first);
91 static ssize_t first_done_show(struct gdlm_ls *ls, char *buf)
93 return sprintf(buf, "%d\n", ls->first_done);
96 static ssize_t recover_show(struct gdlm_ls *ls, char *buf)
98 return sprintf(buf, "%d\n", ls->recover_jid);
101 static ssize_t recover_store(struct gdlm_ls *ls, const char *buf, size_t len)
103 ls->recover_jid = simple_strtol(buf, NULL, 0);
104 ls->fscb(ls->fsdata, LM_CB_NEED_RECOVERY, &ls->recover_jid);
108 static ssize_t recover_done_show(struct gdlm_ls *ls, char *buf)
110 return sprintf(buf, "%d\n", ls->recover_jid_done);
114 struct attribute attr;
115 ssize_t (*show)(struct gdlm_ls *, char *);
116 ssize_t (*store)(struct gdlm_ls *, const char *, size_t);
119 #define GDLM_ATTR(_name,_mode,_show,_store) \
120 static struct gdlm_attr gdlm_attr_##_name = __ATTR(_name,_mode,_show,_store)
122 GDLM_ATTR(proto_name, 0444, proto_name_show, NULL);
123 GDLM_ATTR(block, 0644, block_show, block_store);
124 GDLM_ATTR(withdraw, 0644, withdraw_show, withdraw_store);
125 GDLM_ATTR(id, 0444, id_show, NULL);
126 GDLM_ATTR(jid, 0444, jid_show, NULL);
127 GDLM_ATTR(first, 0444, first_show, NULL);
128 GDLM_ATTR(first_done, 0444, first_done_show, NULL);
129 GDLM_ATTR(recover, 0644, recover_show, recover_store);
130 GDLM_ATTR(recover_done, 0444, recover_done_show, NULL);
132 static struct attribute *gdlm_attrs[] = {
133 &gdlm_attr_proto_name.attr,
134 &gdlm_attr_block.attr,
135 &gdlm_attr_withdraw.attr,
138 &gdlm_attr_first.attr,
139 &gdlm_attr_first_done.attr,
140 &gdlm_attr_recover.attr,
141 &gdlm_attr_recover_done.attr,
145 static ssize_t gdlm_attr_show(struct kobject *kobj, struct attribute *attr,
148 struct gdlm_ls *ls = container_of(kobj, struct gdlm_ls, kobj);
149 struct gdlm_attr *a = container_of(attr, struct gdlm_attr, attr);
150 return a->show ? a->show(ls, buf) : 0;
153 static ssize_t gdlm_attr_store(struct kobject *kobj, struct attribute *attr,
154 const char *buf, size_t len)
156 struct gdlm_ls *ls = container_of(kobj, struct gdlm_ls, kobj);
157 struct gdlm_attr *a = container_of(attr, struct gdlm_attr, attr);
158 return a->store ? a->store(ls, buf, len) : len;
161 static struct sysfs_ops gdlm_attr_ops = {
162 .show = gdlm_attr_show,
163 .store = gdlm_attr_store,
166 static struct kobj_type gdlm_ktype = {
167 .default_attrs = gdlm_attrs,
168 .sysfs_ops = &gdlm_attr_ops,
171 static struct kset gdlm_kset = {
172 .subsys = &kernel_subsys,
173 .kobj = {.name = "lock_dlm",},
174 .ktype = &gdlm_ktype,
177 int gdlm_kobject_setup(struct gdlm_ls *ls, struct kobject *fskobj)
181 error = kobject_set_name(&ls->kobj, "%s", "lock_module");
183 log_error("can't set kobj name %d", error);
187 ls->kobj.kset = &gdlm_kset;
188 ls->kobj.ktype = &gdlm_ktype;
189 ls->kobj.parent = fskobj;
191 error = kobject_register(&ls->kobj);
193 log_error("can't register kobj %d", error);
198 void gdlm_kobject_release(struct gdlm_ls *ls)
200 kobject_unregister(&ls->kobj);
203 int gdlm_sysfs_init(void)
207 error = kset_register(&gdlm_kset);
209 printk("lock_dlm: cannot register kset %d\n", error);
214 void gdlm_sysfs_exit(void)
216 kset_unregister(&gdlm_kset);