]> err.no Git - linux-2.6/blob - fs/gfs2/locking/dlm/sysfs.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/jk/spufs
[linux-2.6] / fs / gfs2 / locking / dlm / sysfs.c
1 /*
2  * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
3  * Copyright (C) 2004-2005 Red Hat, Inc.  All rights reserved.
4  *
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  */
9
10 #include <linux/ctype.h>
11 #include <linux/stat.h>
12
13 #include "lock_dlm.h"
14
15 static ssize_t proto_name_show(struct gdlm_ls *ls, char *buf)
16 {
17         return sprintf(buf, "%s\n", gdlm_ops.lm_proto_name);
18 }
19
20 static ssize_t block_show(struct gdlm_ls *ls, char *buf)
21 {
22         ssize_t ret;
23         int val = 0;
24
25         if (test_bit(DFL_BLOCK_LOCKS, &ls->flags))
26                 val = 1;
27         ret = sprintf(buf, "%d\n", val);
28         return ret;
29 }
30
31 static ssize_t block_store(struct gdlm_ls *ls, const char *buf, size_t len)
32 {
33         ssize_t ret = len;
34         int val;
35
36         val = simple_strtol(buf, NULL, 0);
37
38         if (val == 1)
39                 set_bit(DFL_BLOCK_LOCKS, &ls->flags);
40         else if (val == 0) {
41                 clear_bit(DFL_BLOCK_LOCKS, &ls->flags);
42                 gdlm_submit_delayed(ls);
43         } else {
44                 ret = -EINVAL;
45         }
46         return ret;
47 }
48
49 static ssize_t withdraw_show(struct gdlm_ls *ls, char *buf)
50 {
51         ssize_t ret;
52         int val = 0;
53
54         if (test_bit(DFL_WITHDRAW, &ls->flags))
55                 val = 1;
56         ret = sprintf(buf, "%d\n", val);
57         return ret;
58 }
59
60 static ssize_t withdraw_store(struct gdlm_ls *ls, const char *buf, size_t len)
61 {
62         ssize_t ret = len;
63         int val;
64
65         val = simple_strtol(buf, NULL, 0);
66
67         if (val == 1)
68                 set_bit(DFL_WITHDRAW, &ls->flags);
69         else
70                 ret = -EINVAL;
71         wake_up(&ls->wait_control);
72         return ret;
73 }
74
75 static ssize_t id_show(struct gdlm_ls *ls, char *buf)
76 {
77         return sprintf(buf, "%u\n", ls->id);
78 }
79
80 static ssize_t jid_show(struct gdlm_ls *ls, char *buf)
81 {
82         return sprintf(buf, "%d\n", ls->jid);
83 }
84
85 static ssize_t first_show(struct gdlm_ls *ls, char *buf)
86 {
87         return sprintf(buf, "%d\n", ls->first);
88 }
89
90 static ssize_t first_done_show(struct gdlm_ls *ls, char *buf)
91 {
92         return sprintf(buf, "%d\n", ls->first_done);
93 }
94
95 static ssize_t recover_show(struct gdlm_ls *ls, char *buf)
96 {
97         return sprintf(buf, "%d\n", ls->recover_jid);
98 }
99
100 static ssize_t recover_store(struct gdlm_ls *ls, const char *buf, size_t len)
101 {
102         ls->recover_jid = simple_strtol(buf, NULL, 0);
103         ls->fscb(ls->sdp, LM_CB_NEED_RECOVERY, &ls->recover_jid);
104         return len;
105 }
106
107 static ssize_t recover_done_show(struct gdlm_ls *ls, char *buf)
108 {
109         return sprintf(buf, "%d\n", ls->recover_jid_done);
110 }
111
112 static ssize_t recover_status_show(struct gdlm_ls *ls, char *buf)
113 {
114         return sprintf(buf, "%d\n", ls->recover_jid_status);
115 }
116
117 static ssize_t drop_count_show(struct gdlm_ls *ls, char *buf)
118 {
119         return sprintf(buf, "%d\n", ls->drop_locks_count);
120 }
121
122 static ssize_t drop_count_store(struct gdlm_ls *ls, const char *buf, size_t len)
123 {
124         ls->drop_locks_count = simple_strtol(buf, NULL, 0);
125         return len;
126 }
127
128 struct gdlm_attr {
129         struct attribute attr;
130         ssize_t (*show)(struct gdlm_ls *, char *);
131         ssize_t (*store)(struct gdlm_ls *, const char *, size_t);
132 };
133
134 #define GDLM_ATTR(_name,_mode,_show,_store) \
135 static struct gdlm_attr gdlm_attr_##_name = __ATTR(_name,_mode,_show,_store)
136
137 GDLM_ATTR(proto_name,     0444, proto_name_show,     NULL);
138 GDLM_ATTR(block,          0644, block_show,          block_store);
139 GDLM_ATTR(withdraw,       0644, withdraw_show,       withdraw_store);
140 GDLM_ATTR(id,             0444, id_show,             NULL);
141 GDLM_ATTR(jid,            0444, jid_show,            NULL);
142 GDLM_ATTR(first,          0444, first_show,          NULL);
143 GDLM_ATTR(first_done,     0444, first_done_show,     NULL);
144 GDLM_ATTR(recover,        0644, recover_show,        recover_store);
145 GDLM_ATTR(recover_done,   0444, recover_done_show,   NULL);
146 GDLM_ATTR(recover_status, 0444, recover_status_show, NULL);
147 GDLM_ATTR(drop_count,     0644, drop_count_show,     drop_count_store);
148
149 static struct attribute *gdlm_attrs[] = {
150         &gdlm_attr_proto_name.attr,
151         &gdlm_attr_block.attr,
152         &gdlm_attr_withdraw.attr,
153         &gdlm_attr_id.attr,
154         &gdlm_attr_jid.attr,
155         &gdlm_attr_first.attr,
156         &gdlm_attr_first_done.attr,
157         &gdlm_attr_recover.attr,
158         &gdlm_attr_recover_done.attr,
159         &gdlm_attr_recover_status.attr,
160         &gdlm_attr_drop_count.attr,
161         NULL,
162 };
163
164 static ssize_t gdlm_attr_show(struct kobject *kobj, struct attribute *attr,
165                               char *buf)
166 {
167         struct gdlm_ls *ls = container_of(kobj, struct gdlm_ls, kobj);
168         struct gdlm_attr *a = container_of(attr, struct gdlm_attr, attr);
169         return a->show ? a->show(ls, buf) : 0;
170 }
171
172 static ssize_t gdlm_attr_store(struct kobject *kobj, struct attribute *attr,
173                                const char *buf, size_t len)
174 {
175         struct gdlm_ls *ls = container_of(kobj, struct gdlm_ls, kobj);
176         struct gdlm_attr *a = container_of(attr, struct gdlm_attr, attr);
177         return a->store ? a->store(ls, buf, len) : len;
178 }
179
180 static struct sysfs_ops gdlm_attr_ops = {
181         .show  = gdlm_attr_show,
182         .store = gdlm_attr_store,
183 };
184
185 static struct kobj_type gdlm_ktype = {
186         .default_attrs = gdlm_attrs,
187         .sysfs_ops     = &gdlm_attr_ops,
188 };
189
190 static struct kset *gdlm_kset;
191
192 int gdlm_kobject_setup(struct gdlm_ls *ls, struct kobject *fskobj)
193 {
194         int error;
195
196         ls->kobj.kset = gdlm_kset;
197         error = kobject_init_and_add(&ls->kobj, &gdlm_ktype, fskobj,
198                                      "lock_module");
199         if (error)
200                 log_error("can't register kobj %d", error);
201         kobject_uevent(&ls->kobj, KOBJ_ADD);
202
203         return error;
204 }
205
206 void gdlm_kobject_release(struct gdlm_ls *ls)
207 {
208         kobject_put(&ls->kobj);
209 }
210
211 int gdlm_sysfs_init(void)
212 {
213         gdlm_kset = kset_create_and_add("lock_dlm", NULL, kernel_kobj);
214         if (!gdlm_kset) {
215                 printk(KERN_WARNING "%s: can not create kset\n", __FUNCTION__);
216                 return -ENOMEM;
217         }
218         return 0;
219 }
220
221 void gdlm_sysfs_exit(void)
222 {
223         kset_unregister(gdlm_kset);
224 }
225