1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
|
/******************************************************************************
*******************************************************************************
**
** Copyright (C) 2005 Red Hat, Inc. All rights reserved.
**
** This copyrighted material is made available to anyone wishing to use,
** modify, copy, or redistribute it subject to the terms and conditions
** of the GNU General Public License v.2.
**
*******************************************************************************
******************************************************************************/
#include <linux/ctype.h>
#include <linux/stat.h>
#include "lock_dlm.h"
static ssize_t gdlm_block_show(struct gdlm_ls *ls, char *buf)
{
ssize_t ret;
int val = 0;
if (test_bit(DFL_BLOCK_LOCKS, &ls->flags))
val = 1;
ret = sprintf(buf, "%d\n", val);
return ret;
}
static ssize_t gdlm_block_store(struct gdlm_ls *ls, const char *buf, size_t len)
{
ssize_t ret = len;
int val;
val = simple_strtol(buf, NULL, 0);
if (val == 1)
set_bit(DFL_BLOCK_LOCKS, &ls->flags);
else if (val == 0) {
clear_bit(DFL_BLOCK_LOCKS, &ls->flags);
gdlm_submit_delayed(ls);
} else
ret = -EINVAL;
return ret;
}
static ssize_t gdlm_mounted_show(struct gdlm_ls *ls, char *buf)
{
ssize_t ret;
int val = -2;
if (test_bit(DFL_TERMINATE, &ls->flags))
val = -1;
else if (test_bit(DFL_LEAVE_DONE, &ls->flags))
val = 0;
else if (test_bit(DFL_JOIN_DONE, &ls->flags))
val = 1;
ret = sprintf(buf, "%d\n", val);
return ret;
}
static ssize_t gdlm_mounted_store(struct gdlm_ls *ls, const char *buf, size_t len)
{
ssize_t ret = len;
int val;
val = simple_strtol(buf, NULL, 0);
if (val == 1)
set_bit(DFL_JOIN_DONE, &ls->flags);
else if (val == 0)
set_bit(DFL_LEAVE_DONE, &ls->flags);
else if (val == -1) {
set_bit(DFL_TERMINATE, &ls->flags);
set_bit(DFL_JOIN_DONE, &ls->flags);
set_bit(DFL_LEAVE_DONE, &ls->flags);
} else
ret = -EINVAL;
wake_up(&ls->wait_control);
return ret;
}
static ssize_t gdlm_withdraw_show(struct gdlm_ls *ls, char *buf)
{
ssize_t ret;
int val = 0;
if (test_bit(DFL_WITHDRAW, &ls->flags))
val = 1;
ret = sprintf(buf, "%d\n", val);
return ret;
}
static ssize_t gdlm_withdraw_store(struct gdlm_ls *ls, const char *buf, size_t len)
{
ssize_t ret = len;
int val;
val = simple_strtol(buf, NULL, 0);
if (val == 1)
set_bit(DFL_WITHDRAW, &ls->flags);
else
ret = -EINVAL;
wake_up(&ls->wait_control);
return ret;
}
static ssize_t gdlm_jid_show(struct gdlm_ls *ls, char *buf)
{
return sprintf(buf, "%u\n", ls->jid);
}
static ssize_t gdlm_jid_store(struct gdlm_ls *ls, const char *buf, size_t len)
{
ls->jid = simple_strtol(buf, NULL, 0);
return len;
}
static ssize_t gdlm_first_show(struct gdlm_ls *ls, char *buf)
{
return sprintf(buf, "%u\n", ls->first);
}
static ssize_t gdlm_first_store(struct gdlm_ls *ls, const char *buf, size_t len)
{
ls->first = simple_strtol(buf, NULL, 0);
return len;
}
static ssize_t gdlm_first_done_show(struct gdlm_ls *ls, char *buf)
{
return sprintf(buf, "%d\n", ls->first_done);
}
static ssize_t gdlm_recover_show(struct gdlm_ls *ls, char *buf)
{
return sprintf(buf, "%u\n", ls->recover_jid);
}
static ssize_t gdlm_recover_store(struct gdlm_ls *ls, const char *buf, size_t len)
{
ls->recover_jid = simple_strtol(buf, NULL, 0);
ls->fscb(ls->fsdata, LM_CB_NEED_RECOVERY, &ls->recover_jid);
return len;
}
static ssize_t gdlm_recover_done_show(struct gdlm_ls *ls, char *buf)
{
ssize_t ret;
ret = sprintf(buf, "%d\n", ls->recover_done);
return ret;
}
static ssize_t gdlm_cluster_show(struct gdlm_ls *ls, char *buf)
{
ssize_t ret;
ret = sprintf(buf, "%s\n", ls->clustername);
return ret;
}
static ssize_t gdlm_options_show(struct gdlm_ls *ls, char *buf)
{
ssize_t ret = 0;
if (ls->fsflags & LM_MFLAG_SPECTATOR)
ret += sprintf(buf, "spectator ");
return ret;
}
struct gdlm_attr {
struct attribute attr;
ssize_t (*show)(struct gdlm_ls *, char *);
ssize_t (*store)(struct gdlm_ls *, const char *, size_t);
};
static struct gdlm_attr gdlm_attr_block = {
.attr = {.name = "block", .mode = S_IRUGO | S_IWUSR},
.show = gdlm_block_show,
.store = gdlm_block_store
};
static struct gdlm_attr gdlm_attr_mounted = {
.attr = {.name = "mounted", .mode = S_IRUGO | S_IWUSR},
.show = gdlm_mounted_show,
.store = gdlm_mounted_store
};
static struct gdlm_attr gdlm_attr_withdraw = {
.attr = {.name = "withdraw", .mode = S_IRUGO | S_IWUSR},
.show = gdlm_withdraw_show,
.store = gdlm_withdraw_store
};
static struct gdlm_attr gdlm_attr_jid = {
.attr = {.name = "jid", .mode = S_IRUGO | S_IWUSR},
.show = gdlm_jid_show,
.store = gdlm_jid_store
};
static struct gdlm_attr gdlm_attr_first = {
.attr = {.name = "first", .mode = S_IRUGO | S_IWUSR},
.show = gdlm_first_show,
.store = gdlm_first_store
};
static struct gdlm_attr gdlm_attr_first_done = {
.attr = {.name = "first_done", .mode = S_IRUGO},
.show = gdlm_first_done_show,
};
static struct gdlm_attr gdlm_attr_recover = {
.attr = {.name = "recover", .mode = S_IRUGO | S_IWUSR},
.show = gdlm_recover_show,
.store = gdlm_recover_store
};
static struct gdlm_attr gdlm_attr_recover_done = {
.attr = {.name = "recover_done", .mode = S_IRUGO | S_IWUSR},
.show = gdlm_recover_done_show,
};
static struct gdlm_attr gdlm_attr_cluster = {
.attr = {.name = "cluster", .mode = S_IRUGO | S_IWUSR},
.show = gdlm_cluster_show,
};
static struct gdlm_attr gdlm_attr_options = {
.attr = {.name = "options", .mode = S_IRUGO | S_IWUSR},
.show = gdlm_options_show,
};
static struct attribute *gdlm_attrs[] = {
&gdlm_attr_block.attr,
&gdlm_attr_mounted.attr,
&gdlm_attr_withdraw.attr,
&gdlm_attr_jid.attr,
&gdlm_attr_first.attr,
&gdlm_attr_first_done.attr,
&gdlm_attr_recover.attr,
&gdlm_attr_recover_done.attr,
&gdlm_attr_cluster.attr,
&gdlm_attr_options.attr,
NULL,
};
static ssize_t gdlm_attr_show(struct kobject *kobj, struct attribute *attr,
char *buf)
{
struct gdlm_ls *ls = container_of(kobj, struct gdlm_ls, kobj);
struct gdlm_attr *a = container_of(attr, struct gdlm_attr, attr);
return a->show ? a->show(ls, buf) : 0;
}
static ssize_t gdlm_attr_store(struct kobject *kobj, struct attribute *attr,
const char *buf, size_t len)
{
struct gdlm_ls *ls = container_of(kobj, struct gdlm_ls, kobj);
struct gdlm_attr *a = container_of(attr, struct gdlm_attr, attr);
return a->store ? a->store(ls, buf, len) : len;
}
static struct sysfs_ops gdlm_attr_ops = {
.show = gdlm_attr_show,
.store = gdlm_attr_store,
};
static struct kobj_type gdlm_ktype = {
.default_attrs = gdlm_attrs,
.sysfs_ops = &gdlm_attr_ops,
};
static struct kset gdlm_kset = {
.subsys = &kernel_subsys,
.kobj = {.name = "lock_dlm",},
.ktype = &gdlm_ktype,
};
int gdlm_kobject_setup(struct gdlm_ls *ls)
{
int error;
error = kobject_set_name(&ls->kobj, "%s", ls->fsname);
if (error)
return error;
ls->kobj.kset = &gdlm_kset;
ls->kobj.ktype = &gdlm_ktype;
error = kobject_register(&ls->kobj);
return 0;
}
void gdlm_kobject_release(struct gdlm_ls *ls)
{
kobject_unregister(&ls->kobj);
}
int gdlm_sysfs_init(void)
{
int error;
error = kset_register(&gdlm_kset);
if (error)
printk("lock_dlm: cannot register kset %d\n", error);
return error;
}
void gdlm_sysfs_exit(void)
{
kset_unregister(&gdlm_kset);
}
|