blob: a78997ea50373c13a0c0870c276f70d4e6602e26 [file] [log] [blame]
David Teiglandb3b94fa2006-01-16 16:50:04 +00001/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
Steven Whitehouse3a8a9a12006-05-18 15:09:15 -04003 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
David Teiglandb3b94fa2006-01-16 16:50:04 +00004 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
Steven Whitehousee9fc2aa2006-09-01 11:05:15 -04007 * of the GNU General Public License version 2.
David Teiglandb3b94fa2006-01-16 16:50:04 +00008 */
9
10#include <linux/sched.h>
11#include <linux/slab.h>
12#include <linux/spinlock.h>
13#include <linux/completion.h>
14#include <linux/buffer_head.h>
15#include <linux/module.h>
16#include <linux/kobject.h>
David Teiglandb3b94fa2006-01-16 16:50:04 +000017#include <asm/uaccess.h>
Steven Whitehousef057f6c2009-01-12 10:43:39 +000018#include <linux/gfs2_ondisk.h>
David Teiglandb3b94fa2006-01-16 16:50:04 +000019
20#include "gfs2.h"
Steven Whitehouse5c676f62006-02-27 17:23:27 -050021#include "incore.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000022#include "sys.h"
23#include "super.h"
24#include "glock.h"
25#include "quota.h"
Steven Whitehouse5c676f62006-02-27 17:23:27 -050026#include "util.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000027
David Teiglandb3b94fa2006-01-16 16:50:04 +000028static ssize_t id_show(struct gfs2_sbd *sdp, char *buf)
29{
Bob Petersonc7227e462007-11-02 09:37:15 -050030 return snprintf(buf, PAGE_SIZE, "%u:%u\n",
31 MAJOR(sdp->sd_vfs->s_dev), MINOR(sdp->sd_vfs->s_dev));
David Teiglandb3b94fa2006-01-16 16:50:04 +000032}
33
34static ssize_t fsname_show(struct gfs2_sbd *sdp, char *buf)
35{
David Teigland3204a6c2006-09-06 16:57:06 -050036 return snprintf(buf, PAGE_SIZE, "%s\n", sdp->sd_fsname);
David Teiglandb3b94fa2006-01-16 16:50:04 +000037}
38
39static ssize_t freeze_show(struct gfs2_sbd *sdp, char *buf)
40{
41 unsigned int count;
42
Steven Whitehousef55ab262006-02-21 12:51:39 +000043 mutex_lock(&sdp->sd_freeze_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +000044 count = sdp->sd_freeze_count;
Steven Whitehousef55ab262006-02-21 12:51:39 +000045 mutex_unlock(&sdp->sd_freeze_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +000046
David Teigland3204a6c2006-09-06 16:57:06 -050047 return snprintf(buf, PAGE_SIZE, "%u\n", count);
David Teiglandb3b94fa2006-01-16 16:50:04 +000048}
49
50static ssize_t freeze_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
51{
52 ssize_t ret = len;
53 int error = 0;
54 int n = simple_strtol(buf, NULL, 0);
55
56 if (!capable(CAP_SYS_ADMIN))
57 return -EACCES;
58
59 switch (n) {
60 case 0:
61 gfs2_unfreeze_fs(sdp);
62 break;
63 case 1:
64 error = gfs2_freeze_fs(sdp);
65 break;
66 default:
67 ret = -EINVAL;
68 }
69
70 if (error)
71 fs_warn(sdp, "freeze %d error %d", n, error);
72
73 return ret;
74}
75
76static ssize_t withdraw_show(struct gfs2_sbd *sdp, char *buf)
77{
78 unsigned int b = test_bit(SDF_SHUTDOWN, &sdp->sd_flags);
David Teigland3204a6c2006-09-06 16:57:06 -050079 return snprintf(buf, PAGE_SIZE, "%u\n", b);
David Teiglandb3b94fa2006-01-16 16:50:04 +000080}
81
82static ssize_t withdraw_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
83{
84 if (!capable(CAP_SYS_ADMIN))
85 return -EACCES;
86
87 if (simple_strtol(buf, NULL, 0) != 1)
88 return -EINVAL;
89
90 gfs2_lm_withdraw(sdp,
91 "GFS2: fsid=%s: withdrawing from cluster at user's request\n",
92 sdp->sd_fsname);
93 return len;
94}
95
96static ssize_t statfs_sync_store(struct gfs2_sbd *sdp, const char *buf,
97 size_t len)
98{
99 if (!capable(CAP_SYS_ADMIN))
100 return -EACCES;
101
102 if (simple_strtol(buf, NULL, 0) != 1)
103 return -EINVAL;
104
105 gfs2_statfs_sync(sdp);
106 return len;
107}
108
David Teiglandb3b94fa2006-01-16 16:50:04 +0000109static ssize_t quota_sync_store(struct gfs2_sbd *sdp, const char *buf,
110 size_t len)
111{
112 if (!capable(CAP_SYS_ADMIN))
113 return -EACCES;
114
115 if (simple_strtol(buf, NULL, 0) != 1)
116 return -EINVAL;
117
118 gfs2_quota_sync(sdp);
119 return len;
120}
121
122static ssize_t quota_refresh_user_store(struct gfs2_sbd *sdp, const char *buf,
123 size_t len)
124{
Steven Whitehousecd915492006-09-04 12:49:07 -0400125 u32 id;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000126
127 if (!capable(CAP_SYS_ADMIN))
128 return -EACCES;
129
130 id = simple_strtoul(buf, NULL, 0);
131
132 gfs2_quota_refresh(sdp, 1, id);
133 return len;
134}
135
136static ssize_t quota_refresh_group_store(struct gfs2_sbd *sdp, const char *buf,
137 size_t len)
138{
Steven Whitehousecd915492006-09-04 12:49:07 -0400139 u32 id;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000140
141 if (!capable(CAP_SYS_ADMIN))
142 return -EACCES;
143
144 id = simple_strtoul(buf, NULL, 0);
145
146 gfs2_quota_refresh(sdp, 0, id);
147 return len;
148}
149
150struct gfs2_attr {
151 struct attribute attr;
152 ssize_t (*show)(struct gfs2_sbd *, char *);
153 ssize_t (*store)(struct gfs2_sbd *, const char *, size_t);
154};
155
156#define GFS2_ATTR(name, mode, show, store) \
157static struct gfs2_attr gfs2_attr_##name = __ATTR(name, mode, show, store)
158
159GFS2_ATTR(id, 0444, id_show, NULL);
160GFS2_ATTR(fsname, 0444, fsname_show, NULL);
161GFS2_ATTR(freeze, 0644, freeze_show, freeze_store);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000162GFS2_ATTR(withdraw, 0644, withdraw_show, withdraw_store);
163GFS2_ATTR(statfs_sync, 0200, NULL, statfs_sync_store);
164GFS2_ATTR(quota_sync, 0200, NULL, quota_sync_store);
165GFS2_ATTR(quota_refresh_user, 0200, NULL, quota_refresh_user_store);
166GFS2_ATTR(quota_refresh_group, 0200, NULL, quota_refresh_group_store);
167
168static struct attribute *gfs2_attrs[] = {
169 &gfs2_attr_id.attr,
170 &gfs2_attr_fsname.attr,
171 &gfs2_attr_freeze.attr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000172 &gfs2_attr_withdraw.attr,
173 &gfs2_attr_statfs_sync.attr,
174 &gfs2_attr_quota_sync.attr,
175 &gfs2_attr_quota_refresh_user.attr,
176 &gfs2_attr_quota_refresh_group.attr,
177 NULL,
178};
179
180static ssize_t gfs2_attr_show(struct kobject *kobj, struct attribute *attr,
181 char *buf)
182{
183 struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj);
184 struct gfs2_attr *a = container_of(attr, struct gfs2_attr, attr);
185 return a->show ? a->show(sdp, buf) : 0;
186}
187
188static ssize_t gfs2_attr_store(struct kobject *kobj, struct attribute *attr,
189 const char *buf, size_t len)
190{
191 struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj);
192 struct gfs2_attr *a = container_of(attr, struct gfs2_attr, attr);
193 return a->store ? a->store(sdp, buf, len) : len;
194}
195
196static struct sysfs_ops gfs2_attr_ops = {
197 .show = gfs2_attr_show,
198 .store = gfs2_attr_store,
199};
200
201static struct kobj_type gfs2_ktype = {
202 .default_attrs = gfs2_attrs,
203 .sysfs_ops = &gfs2_attr_ops,
204};
205
Greg Kroah-Hartman9bec1012007-10-29 20:13:17 +0100206static struct kset *gfs2_kset;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000207
208/*
209 * display struct lm_lockstruct fields
210 */
211
212struct lockstruct_attr {
213 struct attribute attr;
214 ssize_t (*show)(struct gfs2_sbd *, char *);
215};
216
217#define LOCKSTRUCT_ATTR(name, fmt) \
218static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \
219{ \
David Teigland3204a6c2006-09-06 16:57:06 -0500220 return snprintf(buf, PAGE_SIZE, fmt, sdp->sd_lockstruct.ls_##name); \
David Teiglandb3b94fa2006-01-16 16:50:04 +0000221} \
222static struct lockstruct_attr lockstruct_attr_##name = __ATTR_RO(name)
223
224LOCKSTRUCT_ATTR(jid, "%u\n");
225LOCKSTRUCT_ATTR(first, "%u\n");
David Teiglandb3b94fa2006-01-16 16:50:04 +0000226
227static struct attribute *lockstruct_attrs[] = {
228 &lockstruct_attr_jid.attr,
229 &lockstruct_attr_first.attr,
Steven Whitehousef057f6c2009-01-12 10:43:39 +0000230 NULL,
231};
232
233/*
234 * lock_module. Originally from lock_dlm
235 */
236
237static ssize_t proto_name_show(struct gfs2_sbd *sdp, char *buf)
238{
239 const struct lm_lockops *ops = sdp->sd_lockstruct.ls_ops;
240 return sprintf(buf, "%s\n", ops->lm_proto_name);
241}
242
243static ssize_t block_show(struct gfs2_sbd *sdp, char *buf)
244{
245 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
246 ssize_t ret;
247 int val = 0;
248
249 if (test_bit(DFL_BLOCK_LOCKS, &ls->ls_flags))
250 val = 1;
251 ret = sprintf(buf, "%d\n", val);
252 return ret;
253}
254
255static ssize_t block_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
256{
257 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
258 ssize_t ret = len;
259 int val;
260
261 val = simple_strtol(buf, NULL, 0);
262
263 if (val == 1)
264 set_bit(DFL_BLOCK_LOCKS, &ls->ls_flags);
265 else if (val == 0) {
266 clear_bit(DFL_BLOCK_LOCKS, &ls->ls_flags);
267 smp_mb__after_clear_bit();
268 gfs2_glock_thaw(sdp);
269 } else {
270 ret = -EINVAL;
271 }
272 return ret;
273}
274
275static ssize_t lkid_show(struct gfs2_sbd *sdp, char *buf)
276{
277 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
278 return sprintf(buf, "%u\n", ls->ls_id);
279}
280
281static ssize_t lkfirst_show(struct gfs2_sbd *sdp, char *buf)
282{
283 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
284 return sprintf(buf, "%d\n", ls->ls_first);
285}
286
287static ssize_t first_done_show(struct gfs2_sbd *sdp, char *buf)
288{
289 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
290 return sprintf(buf, "%d\n", ls->ls_first_done);
291}
292
293static ssize_t recover_show(struct gfs2_sbd *sdp, char *buf)
294{
295 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
296 return sprintf(buf, "%d\n", ls->ls_recover_jid);
297}
298
299static void gfs2_jdesc_make_dirty(struct gfs2_sbd *sdp, unsigned int jid)
300{
301 struct gfs2_jdesc *jd;
302
303 spin_lock(&sdp->sd_jindex_spin);
304 list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) {
305 if (jd->jd_jid != jid)
306 continue;
307 jd->jd_dirty = 1;
308 break;
309 }
310 spin_unlock(&sdp->sd_jindex_spin);
311}
312
313static ssize_t recover_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
314{
315 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
316 ls->ls_recover_jid = simple_strtol(buf, NULL, 0);
317 gfs2_jdesc_make_dirty(sdp, ls->ls_recover_jid);
318 if (sdp->sd_recoverd_process)
319 wake_up_process(sdp->sd_recoverd_process);
320 return len;
321}
322
323static ssize_t recover_done_show(struct gfs2_sbd *sdp, char *buf)
324{
325 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
326 return sprintf(buf, "%d\n", ls->ls_recover_jid_done);
327}
328
329static ssize_t recover_status_show(struct gfs2_sbd *sdp, char *buf)
330{
331 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
332 return sprintf(buf, "%d\n", ls->ls_recover_jid_status);
333}
334
335struct gdlm_attr {
336 struct attribute attr;
337 ssize_t (*show)(struct gfs2_sbd *sdp, char *);
338 ssize_t (*store)(struct gfs2_sbd *sdp, const char *, size_t);
339};
340
341#define GDLM_ATTR(_name,_mode,_show,_store) \
342static struct gdlm_attr gdlm_attr_##_name = __ATTR(_name,_mode,_show,_store)
343
344GDLM_ATTR(proto_name, 0444, proto_name_show, NULL);
345GDLM_ATTR(block, 0644, block_show, block_store);
346GDLM_ATTR(withdraw, 0644, withdraw_show, withdraw_store);
347GDLM_ATTR(id, 0444, lkid_show, NULL);
348GDLM_ATTR(first, 0444, lkfirst_show, NULL);
349GDLM_ATTR(first_done, 0444, first_done_show, NULL);
350GDLM_ATTR(recover, 0644, recover_show, recover_store);
351GDLM_ATTR(recover_done, 0444, recover_done_show, NULL);
352GDLM_ATTR(recover_status, 0444, recover_status_show, NULL);
353
354static struct attribute *lock_module_attrs[] = {
355 &gdlm_attr_proto_name.attr,
356 &gdlm_attr_block.attr,
357 &gdlm_attr_withdraw.attr,
358 &gdlm_attr_id.attr,
359 &lockstruct_attr_jid.attr,
360 &gdlm_attr_first.attr,
361 &gdlm_attr_first_done.attr,
362 &gdlm_attr_recover.attr,
363 &gdlm_attr_recover_done.attr,
364 &gdlm_attr_recover_status.attr,
Steven Whitehouseea67eed2006-09-05 10:53:09 -0400365 NULL,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000366};
367
368/*
369 * display struct gfs2_args fields
370 */
371
372struct args_attr {
373 struct attribute attr;
374 ssize_t (*show)(struct gfs2_sbd *, char *);
375};
376
377#define ARGS_ATTR(name, fmt) \
378static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \
379{ \
David Teigland3204a6c2006-09-06 16:57:06 -0500380 return snprintf(buf, PAGE_SIZE, fmt, sdp->sd_args.ar_##name); \
David Teiglandb3b94fa2006-01-16 16:50:04 +0000381} \
382static struct args_attr args_attr_##name = __ATTR_RO(name)
383
384ARGS_ATTR(lockproto, "%s\n");
385ARGS_ATTR(locktable, "%s\n");
386ARGS_ATTR(hostdata, "%s\n");
387ARGS_ATTR(spectator, "%d\n");
388ARGS_ATTR(ignore_local_fs, "%d\n");
389ARGS_ATTR(localcaching, "%d\n");
390ARGS_ATTR(localflocks, "%d\n");
391ARGS_ATTR(debug, "%d\n");
392ARGS_ATTR(upgrade, "%d\n");
David Teiglandb3b94fa2006-01-16 16:50:04 +0000393ARGS_ATTR(posix_acl, "%d\n");
394ARGS_ATTR(quota, "%u\n");
395ARGS_ATTR(suiddir, "%d\n");
396ARGS_ATTR(data, "%d\n");
397
David Teiglandb3b94fa2006-01-16 16:50:04 +0000398static struct attribute *args_attrs[] = {
399 &args_attr_lockproto.attr,
400 &args_attr_locktable.attr,
401 &args_attr_hostdata.attr,
402 &args_attr_spectator.attr,
403 &args_attr_ignore_local_fs.attr,
404 &args_attr_localcaching.attr,
405 &args_attr_localflocks.attr,
406 &args_attr_debug.attr,
407 &args_attr_upgrade.attr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000408 &args_attr_posix_acl.attr,
409 &args_attr_quota.attr,
410 &args_attr_suiddir.attr,
411 &args_attr_data.attr,
Steven Whitehouseea67eed2006-09-05 10:53:09 -0400412 NULL,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000413};
414
415/*
David Teiglandb3b94fa2006-01-16 16:50:04 +0000416 * get and set struct gfs2_tune fields
417 */
418
419static ssize_t quota_scale_show(struct gfs2_sbd *sdp, char *buf)
420{
David Teigland3204a6c2006-09-06 16:57:06 -0500421 return snprintf(buf, PAGE_SIZE, "%u %u\n",
422 sdp->sd_tune.gt_quota_scale_num,
423 sdp->sd_tune.gt_quota_scale_den);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000424}
425
426static ssize_t quota_scale_store(struct gfs2_sbd *sdp, const char *buf,
427 size_t len)
428{
429 struct gfs2_tune *gt = &sdp->sd_tune;
430 unsigned int x, y;
431
432 if (!capable(CAP_SYS_ADMIN))
433 return -EACCES;
434
435 if (sscanf(buf, "%u %u", &x, &y) != 2 || !y)
436 return -EINVAL;
437
438 spin_lock(&gt->gt_spin);
439 gt->gt_quota_scale_num = x;
440 gt->gt_quota_scale_den = y;
441 spin_unlock(&gt->gt_spin);
442 return len;
443}
444
445static ssize_t tune_set(struct gfs2_sbd *sdp, unsigned int *field,
446 int check_zero, const char *buf, size_t len)
447{
448 struct gfs2_tune *gt = &sdp->sd_tune;
449 unsigned int x;
450
451 if (!capable(CAP_SYS_ADMIN))
452 return -EACCES;
453
454 x = simple_strtoul(buf, NULL, 0);
455
456 if (check_zero && !x)
457 return -EINVAL;
458
459 spin_lock(&gt->gt_spin);
460 *field = x;
461 spin_unlock(&gt->gt_spin);
462 return len;
463}
464
465struct tune_attr {
466 struct attribute attr;
467 ssize_t (*show)(struct gfs2_sbd *, char *);
468 ssize_t (*store)(struct gfs2_sbd *, const char *, size_t);
469};
470
471#define TUNE_ATTR_3(name, show, store) \
472static struct tune_attr tune_attr_##name = __ATTR(name, 0644, show, store)
473
474#define TUNE_ATTR_2(name, store) \
475static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \
476{ \
David Teigland3204a6c2006-09-06 16:57:06 -0500477 return snprintf(buf, PAGE_SIZE, "%u\n", sdp->sd_tune.gt_##name); \
David Teiglandb3b94fa2006-01-16 16:50:04 +0000478} \
479TUNE_ATTR_3(name, name##_show, store)
480
481#define TUNE_ATTR(name, check_zero) \
482static ssize_t name##_store(struct gfs2_sbd *sdp, const char *buf, size_t len)\
483{ \
484 return tune_set(sdp, &sdp->sd_tune.gt_##name, check_zero, buf, len); \
485} \
486TUNE_ATTR_2(name, name##_store)
487
488#define TUNE_ATTR_DAEMON(name, process) \
489static ssize_t name##_store(struct gfs2_sbd *sdp, const char *buf, size_t len)\
490{ \
491 ssize_t r = tune_set(sdp, &sdp->sd_tune.gt_##name, 1, buf, len); \
492 wake_up_process(sdp->sd_##process); \
493 return r; \
494} \
495TUNE_ATTR_2(name, name##_store)
496
David Teiglandb3b94fa2006-01-16 16:50:04 +0000497TUNE_ATTR(incore_log_blocks, 0);
498TUNE_ATTR(log_flush_secs, 0);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000499TUNE_ATTR(quota_warn_period, 0);
500TUNE_ATTR(quota_quantum, 0);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000501TUNE_ATTR(max_readahead, 0);
502TUNE_ATTR(complain_secs, 0);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000503TUNE_ATTR(statfs_slow, 0);
504TUNE_ATTR(new_files_jdata, 0);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000505TUNE_ATTR(quota_simul_sync, 1);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000506TUNE_ATTR(stall_secs, 1);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000507TUNE_ATTR(statfs_quantum, 1);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000508TUNE_ATTR_DAEMON(recoverd_secs, recoverd_process);
509TUNE_ATTR_DAEMON(logd_secs, logd_process);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000510TUNE_ATTR_3(quota_scale, quota_scale_show, quota_scale_store);
511
512static struct attribute *tune_attrs[] = {
David Teiglandb3b94fa2006-01-16 16:50:04 +0000513 &tune_attr_incore_log_blocks.attr,
514 &tune_attr_log_flush_secs.attr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000515 &tune_attr_quota_warn_period.attr,
516 &tune_attr_quota_quantum.attr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000517 &tune_attr_max_readahead.attr,
518 &tune_attr_complain_secs.attr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000519 &tune_attr_statfs_slow.attr,
520 &tune_attr_quota_simul_sync.attr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000521 &tune_attr_stall_secs.attr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000522 &tune_attr_statfs_quantum.attr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000523 &tune_attr_recoverd_secs.attr,
524 &tune_attr_logd_secs.attr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000525 &tune_attr_quota_scale.attr,
526 &tune_attr_new_files_jdata.attr,
Steven Whitehouseea67eed2006-09-05 10:53:09 -0400527 NULL,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000528};
529
530static struct attribute_group lockstruct_group = {
531 .name = "lockstruct",
Steven Whitehouseea67eed2006-09-05 10:53:09 -0400532 .attrs = lockstruct_attrs,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000533};
534
David Teiglandb3b94fa2006-01-16 16:50:04 +0000535static struct attribute_group args_group = {
536 .name = "args",
Steven Whitehouseea67eed2006-09-05 10:53:09 -0400537 .attrs = args_attrs,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000538};
539
540static struct attribute_group tune_group = {
541 .name = "tune",
Steven Whitehouseea67eed2006-09-05 10:53:09 -0400542 .attrs = tune_attrs,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000543};
544
Steven Whitehousef057f6c2009-01-12 10:43:39 +0000545static struct attribute_group lock_module_group = {
546 .name = "lock_module",
547 .attrs = lock_module_attrs,
548};
549
David Teiglandb3b94fa2006-01-16 16:50:04 +0000550int gfs2_sys_fs_add(struct gfs2_sbd *sdp)
551{
552 int error;
553
Greg Kroah-Hartman9bec1012007-10-29 20:13:17 +0100554 sdp->sd_kobj.kset = gfs2_kset;
Greg Kroah-Hartman901195e2007-12-17 15:54:39 -0400555 error = kobject_init_and_add(&sdp->sd_kobj, &gfs2_ktype, NULL,
556 "%s", sdp->sd_table_name);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000557 if (error)
558 goto fail;
559
560 error = sysfs_create_group(&sdp->sd_kobj, &lockstruct_group);
561 if (error)
562 goto fail_reg;
563
David Teiglandb3b94fa2006-01-16 16:50:04 +0000564 error = sysfs_create_group(&sdp->sd_kobj, &args_group);
565 if (error)
Steven Whitehouse97cc10252008-11-20 13:39:47 +0000566 goto fail_lockstruct;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000567
568 error = sysfs_create_group(&sdp->sd_kobj, &tune_group);
569 if (error)
570 goto fail_args;
571
Steven Whitehousef057f6c2009-01-12 10:43:39 +0000572 error = sysfs_create_group(&sdp->sd_kobj, &lock_module_group);
573 if (error)
574 goto fail_tune;
575
Greg Kroah-Hartman901195e2007-12-17 15:54:39 -0400576 kobject_uevent(&sdp->sd_kobj, KOBJ_ADD);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000577 return 0;
578
Steven Whitehousef057f6c2009-01-12 10:43:39 +0000579fail_tune:
580 sysfs_remove_group(&sdp->sd_kobj, &tune_group);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400581fail_args:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000582 sysfs_remove_group(&sdp->sd_kobj, &args_group);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400583fail_lockstruct:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000584 sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400585fail_reg:
Greg Kroah-Hartman197b12d2007-12-20 08:13:05 -0800586 kobject_put(&sdp->sd_kobj);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400587fail:
David Teigland65952fb2006-09-15 13:09:11 -0500588 fs_err(sdp, "error %d adding sysfs files", error);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000589 return error;
590}
591
592void gfs2_sys_fs_del(struct gfs2_sbd *sdp)
593{
594 sysfs_remove_group(&sdp->sd_kobj, &tune_group);
595 sysfs_remove_group(&sdp->sd_kobj, &args_group);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000596 sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group);
Steven Whitehousef057f6c2009-01-12 10:43:39 +0000597 sysfs_remove_group(&sdp->sd_kobj, &lock_module_group);
Greg Kroah-Hartman197b12d2007-12-20 08:13:05 -0800598 kobject_put(&sdp->sd_kobj);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000599}
600
Steven Whitehousefdd1062e2008-11-26 10:26:38 +0000601static int gfs2_uevent(struct kset *kset, struct kobject *kobj,
602 struct kobj_uevent_env *env)
603{
604 struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj);
605 add_uevent_var(env, "LOCKTABLE=%s", sdp->sd_table_name);
606 add_uevent_var(env, "LOCKPROTO=%s", sdp->sd_proto_name);
607 return 0;
608}
609
610static struct kset_uevent_ops gfs2_uevent_ops = {
611 .uevent = gfs2_uevent,
612};
613
614
David Teiglandb3b94fa2006-01-16 16:50:04 +0000615int gfs2_sys_init(void)
616{
Steven Whitehousefdd1062e2008-11-26 10:26:38 +0000617 gfs2_kset = kset_create_and_add("gfs2", &gfs2_uevent_ops, fs_kobj);
Greg Kroah-Hartman9bec1012007-10-29 20:13:17 +0100618 if (!gfs2_kset)
619 return -ENOMEM;
620 return 0;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000621}
622
623void gfs2_sys_uninit(void)
624{
Greg Kroah-Hartman9bec1012007-10-29 20:13:17 +0100625 kset_unregister(gfs2_kset);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000626}
627