blob: 7655f5025fec4868e7d00e5790abb5d85394a926 [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"
Steven Whitehouse64d576b2009-02-12 13:31:58 +000027#include "glops.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000028
David Teiglandb3b94fa2006-01-16 16:50:04 +000029static ssize_t id_show(struct gfs2_sbd *sdp, char *buf)
30{
Bob Petersonc7227e42007-11-02 09:37:15 -050031 return snprintf(buf, PAGE_SIZE, "%u:%u\n",
32 MAJOR(sdp->sd_vfs->s_dev), MINOR(sdp->sd_vfs->s_dev));
David Teiglandb3b94fa2006-01-16 16:50:04 +000033}
34
35static ssize_t fsname_show(struct gfs2_sbd *sdp, char *buf)
36{
David Teigland3204a6c2006-09-06 16:57:06 -050037 return snprintf(buf, PAGE_SIZE, "%s\n", sdp->sd_fsname);
David Teiglandb3b94fa2006-01-16 16:50:04 +000038}
39
Steven Whitehouse02e3cc72009-02-10 13:48:30 +000040static int gfs2_uuid_valid(const u8 *uuid)
41{
42 int i;
43
44 for (i = 0; i < 16; i++) {
45 if (uuid[i])
46 return 1;
47 }
48 return 0;
49}
50
51static ssize_t uuid_show(struct gfs2_sbd *sdp, char *buf)
52{
53 const u8 *uuid = sdp->sd_sb.sb_uuid;
54 buf[0] = '\0';
55 if (!gfs2_uuid_valid(uuid))
56 return 0;
57 return snprintf(buf, PAGE_SIZE, "%02X%02X%02X%02X-%02X%02X-"
58 "%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X\n",
59 uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5],
60 uuid[6], uuid[7], uuid[8], uuid[9], uuid[10], uuid[11],
61 uuid[12], uuid[13], uuid[14], uuid[15]);
62}
63
David Teiglandb3b94fa2006-01-16 16:50:04 +000064static ssize_t freeze_show(struct gfs2_sbd *sdp, char *buf)
65{
66 unsigned int count;
67
Steven Whitehousef55ab262006-02-21 12:51:39 +000068 mutex_lock(&sdp->sd_freeze_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +000069 count = sdp->sd_freeze_count;
Steven Whitehousef55ab262006-02-21 12:51:39 +000070 mutex_unlock(&sdp->sd_freeze_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +000071
David Teigland3204a6c2006-09-06 16:57:06 -050072 return snprintf(buf, PAGE_SIZE, "%u\n", count);
David Teiglandb3b94fa2006-01-16 16:50:04 +000073}
74
75static ssize_t freeze_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
76{
77 ssize_t ret = len;
78 int error = 0;
79 int n = simple_strtol(buf, NULL, 0);
80
81 if (!capable(CAP_SYS_ADMIN))
82 return -EACCES;
83
84 switch (n) {
85 case 0:
86 gfs2_unfreeze_fs(sdp);
87 break;
88 case 1:
89 error = gfs2_freeze_fs(sdp);
90 break;
91 default:
92 ret = -EINVAL;
93 }
94
95 if (error)
96 fs_warn(sdp, "freeze %d error %d", n, error);
97
98 return ret;
99}
100
101static ssize_t withdraw_show(struct gfs2_sbd *sdp, char *buf)
102{
103 unsigned int b = test_bit(SDF_SHUTDOWN, &sdp->sd_flags);
David Teigland3204a6c2006-09-06 16:57:06 -0500104 return snprintf(buf, PAGE_SIZE, "%u\n", b);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000105}
106
107static ssize_t withdraw_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
108{
109 if (!capable(CAP_SYS_ADMIN))
110 return -EACCES;
111
112 if (simple_strtol(buf, NULL, 0) != 1)
113 return -EINVAL;
114
115 gfs2_lm_withdraw(sdp,
116 "GFS2: fsid=%s: withdrawing from cluster at user's request\n",
117 sdp->sd_fsname);
118 return len;
119}
120
121static ssize_t statfs_sync_store(struct gfs2_sbd *sdp, const char *buf,
122 size_t len)
123{
124 if (!capable(CAP_SYS_ADMIN))
125 return -EACCES;
126
127 if (simple_strtol(buf, NULL, 0) != 1)
128 return -EINVAL;
129
130 gfs2_statfs_sync(sdp);
131 return len;
132}
133
David Teiglandb3b94fa2006-01-16 16:50:04 +0000134static ssize_t quota_sync_store(struct gfs2_sbd *sdp, const char *buf,
135 size_t len)
136{
137 if (!capable(CAP_SYS_ADMIN))
138 return -EACCES;
139
140 if (simple_strtol(buf, NULL, 0) != 1)
141 return -EINVAL;
142
143 gfs2_quota_sync(sdp);
144 return len;
145}
146
147static ssize_t quota_refresh_user_store(struct gfs2_sbd *sdp, const char *buf,
148 size_t len)
149{
Steven Whitehousecd915492006-09-04 12:49:07 -0400150 u32 id;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000151
152 if (!capable(CAP_SYS_ADMIN))
153 return -EACCES;
154
155 id = simple_strtoul(buf, NULL, 0);
156
157 gfs2_quota_refresh(sdp, 1, id);
158 return len;
159}
160
161static ssize_t quota_refresh_group_store(struct gfs2_sbd *sdp, const char *buf,
162 size_t len)
163{
Steven Whitehousecd915492006-09-04 12:49:07 -0400164 u32 id;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000165
166 if (!capable(CAP_SYS_ADMIN))
167 return -EACCES;
168
169 id = simple_strtoul(buf, NULL, 0);
170
171 gfs2_quota_refresh(sdp, 0, id);
172 return len;
173}
174
Steven Whitehouse64d576b2009-02-12 13:31:58 +0000175static ssize_t demote_rq_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
176{
177 struct gfs2_glock *gl;
178 const struct gfs2_glock_operations *glops;
179 unsigned int glmode;
180 unsigned int gltype;
181 unsigned long long glnum;
182 char mode[16];
183 int rv;
184
185 if (!capable(CAP_SYS_ADMIN))
186 return -EACCES;
187
188 rv = sscanf(buf, "%u:%llu %15s", &gltype, &glnum,
189 mode);
190 if (rv != 3)
191 return -EINVAL;
192
193 if (strcmp(mode, "EX") == 0)
194 glmode = LM_ST_UNLOCKED;
195 else if ((strcmp(mode, "CW") == 0) || (strcmp(mode, "DF") == 0))
196 glmode = LM_ST_DEFERRED;
197 else if ((strcmp(mode, "PR") == 0) || (strcmp(mode, "SH") == 0))
198 glmode = LM_ST_SHARED;
199 else
200 return -EINVAL;
201
202 if (gltype > LM_TYPE_JOURNAL)
203 return -EINVAL;
204 glops = gfs2_glops_list[gltype];
205 if (glops == NULL)
206 return -EINVAL;
207 rv = gfs2_glock_get(sdp, glnum, glops, 0, &gl);
208 if (rv)
209 return rv;
210 gfs2_glock_cb(gl, glmode);
211 gfs2_glock_put(gl);
212 return len;
213}
214
David Teiglandb3b94fa2006-01-16 16:50:04 +0000215struct gfs2_attr {
216 struct attribute attr;
217 ssize_t (*show)(struct gfs2_sbd *, char *);
218 ssize_t (*store)(struct gfs2_sbd *, const char *, size_t);
219};
220
221#define GFS2_ATTR(name, mode, show, store) \
222static struct gfs2_attr gfs2_attr_##name = __ATTR(name, mode, show, store)
223
224GFS2_ATTR(id, 0444, id_show, NULL);
225GFS2_ATTR(fsname, 0444, fsname_show, NULL);
Steven Whitehouse02e3cc72009-02-10 13:48:30 +0000226GFS2_ATTR(uuid, 0444, uuid_show, NULL);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000227GFS2_ATTR(freeze, 0644, freeze_show, freeze_store);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000228GFS2_ATTR(withdraw, 0644, withdraw_show, withdraw_store);
229GFS2_ATTR(statfs_sync, 0200, NULL, statfs_sync_store);
230GFS2_ATTR(quota_sync, 0200, NULL, quota_sync_store);
231GFS2_ATTR(quota_refresh_user, 0200, NULL, quota_refresh_user_store);
232GFS2_ATTR(quota_refresh_group, 0200, NULL, quota_refresh_group_store);
Steven Whitehouse64d576b2009-02-12 13:31:58 +0000233GFS2_ATTR(demote_rq, 0200, NULL, demote_rq_store);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000234
235static struct attribute *gfs2_attrs[] = {
236 &gfs2_attr_id.attr,
237 &gfs2_attr_fsname.attr,
Steven Whitehouse02e3cc72009-02-10 13:48:30 +0000238 &gfs2_attr_uuid.attr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000239 &gfs2_attr_freeze.attr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000240 &gfs2_attr_withdraw.attr,
241 &gfs2_attr_statfs_sync.attr,
242 &gfs2_attr_quota_sync.attr,
243 &gfs2_attr_quota_refresh_user.attr,
244 &gfs2_attr_quota_refresh_group.attr,
Steven Whitehouse64d576b2009-02-12 13:31:58 +0000245 &gfs2_attr_demote_rq.attr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000246 NULL,
247};
248
249static ssize_t gfs2_attr_show(struct kobject *kobj, struct attribute *attr,
250 char *buf)
251{
252 struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj);
253 struct gfs2_attr *a = container_of(attr, struct gfs2_attr, attr);
254 return a->show ? a->show(sdp, buf) : 0;
255}
256
257static ssize_t gfs2_attr_store(struct kobject *kobj, struct attribute *attr,
258 const char *buf, size_t len)
259{
260 struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj);
261 struct gfs2_attr *a = container_of(attr, struct gfs2_attr, attr);
262 return a->store ? a->store(sdp, buf, len) : len;
263}
264
265static struct sysfs_ops gfs2_attr_ops = {
266 .show = gfs2_attr_show,
267 .store = gfs2_attr_store,
268};
269
270static struct kobj_type gfs2_ktype = {
271 .default_attrs = gfs2_attrs,
272 .sysfs_ops = &gfs2_attr_ops,
273};
274
Greg Kroah-Hartman9bec1012007-10-29 20:13:17 +0100275static struct kset *gfs2_kset;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000276
277/*
278 * display struct lm_lockstruct fields
279 */
280
281struct lockstruct_attr {
282 struct attribute attr;
283 ssize_t (*show)(struct gfs2_sbd *, char *);
284};
285
286#define LOCKSTRUCT_ATTR(name, fmt) \
287static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \
288{ \
David Teigland3204a6c2006-09-06 16:57:06 -0500289 return snprintf(buf, PAGE_SIZE, fmt, sdp->sd_lockstruct.ls_##name); \
David Teiglandb3b94fa2006-01-16 16:50:04 +0000290} \
291static struct lockstruct_attr lockstruct_attr_##name = __ATTR_RO(name)
292
293LOCKSTRUCT_ATTR(jid, "%u\n");
294LOCKSTRUCT_ATTR(first, "%u\n");
David Teiglandb3b94fa2006-01-16 16:50:04 +0000295
296static struct attribute *lockstruct_attrs[] = {
297 &lockstruct_attr_jid.attr,
298 &lockstruct_attr_first.attr,
Steven Whitehousef057f6c2009-01-12 10:43:39 +0000299 NULL,
300};
301
302/*
303 * lock_module. Originally from lock_dlm
304 */
305
306static ssize_t proto_name_show(struct gfs2_sbd *sdp, char *buf)
307{
308 const struct lm_lockops *ops = sdp->sd_lockstruct.ls_ops;
309 return sprintf(buf, "%s\n", ops->lm_proto_name);
310}
311
312static ssize_t block_show(struct gfs2_sbd *sdp, char *buf)
313{
314 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
315 ssize_t ret;
316 int val = 0;
317
318 if (test_bit(DFL_BLOCK_LOCKS, &ls->ls_flags))
319 val = 1;
320 ret = sprintf(buf, "%d\n", val);
321 return ret;
322}
323
324static ssize_t block_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
325{
326 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
327 ssize_t ret = len;
328 int val;
329
330 val = simple_strtol(buf, NULL, 0);
331
332 if (val == 1)
333 set_bit(DFL_BLOCK_LOCKS, &ls->ls_flags);
334 else if (val == 0) {
335 clear_bit(DFL_BLOCK_LOCKS, &ls->ls_flags);
336 smp_mb__after_clear_bit();
337 gfs2_glock_thaw(sdp);
338 } else {
339 ret = -EINVAL;
340 }
341 return ret;
342}
343
344static ssize_t lkid_show(struct gfs2_sbd *sdp, char *buf)
345{
346 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
347 return sprintf(buf, "%u\n", ls->ls_id);
348}
349
350static ssize_t lkfirst_show(struct gfs2_sbd *sdp, char *buf)
351{
352 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
353 return sprintf(buf, "%d\n", ls->ls_first);
354}
355
356static ssize_t first_done_show(struct gfs2_sbd *sdp, char *buf)
357{
358 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
359 return sprintf(buf, "%d\n", ls->ls_first_done);
360}
361
362static ssize_t recover_show(struct gfs2_sbd *sdp, char *buf)
363{
364 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
365 return sprintf(buf, "%d\n", ls->ls_recover_jid);
366}
367
368static void gfs2_jdesc_make_dirty(struct gfs2_sbd *sdp, unsigned int jid)
369{
370 struct gfs2_jdesc *jd;
371
372 spin_lock(&sdp->sd_jindex_spin);
373 list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) {
374 if (jd->jd_jid != jid)
375 continue;
376 jd->jd_dirty = 1;
377 break;
378 }
379 spin_unlock(&sdp->sd_jindex_spin);
380}
381
382static ssize_t recover_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
383{
384 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
385 ls->ls_recover_jid = simple_strtol(buf, NULL, 0);
386 gfs2_jdesc_make_dirty(sdp, ls->ls_recover_jid);
387 if (sdp->sd_recoverd_process)
388 wake_up_process(sdp->sd_recoverd_process);
389 return len;
390}
391
392static ssize_t recover_done_show(struct gfs2_sbd *sdp, char *buf)
393{
394 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
395 return sprintf(buf, "%d\n", ls->ls_recover_jid_done);
396}
397
398static ssize_t recover_status_show(struct gfs2_sbd *sdp, char *buf)
399{
400 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
401 return sprintf(buf, "%d\n", ls->ls_recover_jid_status);
402}
403
404struct gdlm_attr {
405 struct attribute attr;
406 ssize_t (*show)(struct gfs2_sbd *sdp, char *);
407 ssize_t (*store)(struct gfs2_sbd *sdp, const char *, size_t);
408};
409
410#define GDLM_ATTR(_name,_mode,_show,_store) \
411static struct gdlm_attr gdlm_attr_##_name = __ATTR(_name,_mode,_show,_store)
412
413GDLM_ATTR(proto_name, 0444, proto_name_show, NULL);
414GDLM_ATTR(block, 0644, block_show, block_store);
415GDLM_ATTR(withdraw, 0644, withdraw_show, withdraw_store);
416GDLM_ATTR(id, 0444, lkid_show, NULL);
417GDLM_ATTR(first, 0444, lkfirst_show, NULL);
418GDLM_ATTR(first_done, 0444, first_done_show, NULL);
419GDLM_ATTR(recover, 0644, recover_show, recover_store);
420GDLM_ATTR(recover_done, 0444, recover_done_show, NULL);
421GDLM_ATTR(recover_status, 0444, recover_status_show, NULL);
422
423static struct attribute *lock_module_attrs[] = {
424 &gdlm_attr_proto_name.attr,
425 &gdlm_attr_block.attr,
426 &gdlm_attr_withdraw.attr,
427 &gdlm_attr_id.attr,
428 &lockstruct_attr_jid.attr,
429 &gdlm_attr_first.attr,
430 &gdlm_attr_first_done.attr,
431 &gdlm_attr_recover.attr,
432 &gdlm_attr_recover_done.attr,
433 &gdlm_attr_recover_status.attr,
Steven Whitehouseea67eed2006-09-05 10:53:09 -0400434 NULL,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000435};
436
437/*
438 * display struct gfs2_args fields
439 */
440
441struct args_attr {
442 struct attribute attr;
443 ssize_t (*show)(struct gfs2_sbd *, char *);
444};
445
446#define ARGS_ATTR(name, fmt) \
447static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \
448{ \
David Teigland3204a6c2006-09-06 16:57:06 -0500449 return snprintf(buf, PAGE_SIZE, fmt, sdp->sd_args.ar_##name); \
David Teiglandb3b94fa2006-01-16 16:50:04 +0000450} \
451static struct args_attr args_attr_##name = __ATTR_RO(name)
452
453ARGS_ATTR(lockproto, "%s\n");
454ARGS_ATTR(locktable, "%s\n");
455ARGS_ATTR(hostdata, "%s\n");
456ARGS_ATTR(spectator, "%d\n");
457ARGS_ATTR(ignore_local_fs, "%d\n");
458ARGS_ATTR(localcaching, "%d\n");
459ARGS_ATTR(localflocks, "%d\n");
460ARGS_ATTR(debug, "%d\n");
461ARGS_ATTR(upgrade, "%d\n");
David Teiglandb3b94fa2006-01-16 16:50:04 +0000462ARGS_ATTR(posix_acl, "%d\n");
463ARGS_ATTR(quota, "%u\n");
464ARGS_ATTR(suiddir, "%d\n");
465ARGS_ATTR(data, "%d\n");
466
David Teiglandb3b94fa2006-01-16 16:50:04 +0000467static struct attribute *args_attrs[] = {
468 &args_attr_lockproto.attr,
469 &args_attr_locktable.attr,
470 &args_attr_hostdata.attr,
471 &args_attr_spectator.attr,
472 &args_attr_ignore_local_fs.attr,
473 &args_attr_localcaching.attr,
474 &args_attr_localflocks.attr,
475 &args_attr_debug.attr,
476 &args_attr_upgrade.attr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000477 &args_attr_posix_acl.attr,
478 &args_attr_quota.attr,
479 &args_attr_suiddir.attr,
480 &args_attr_data.attr,
Steven Whitehouseea67eed2006-09-05 10:53:09 -0400481 NULL,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000482};
483
484/*
David Teiglandb3b94fa2006-01-16 16:50:04 +0000485 * get and set struct gfs2_tune fields
486 */
487
488static ssize_t quota_scale_show(struct gfs2_sbd *sdp, char *buf)
489{
David Teigland3204a6c2006-09-06 16:57:06 -0500490 return snprintf(buf, PAGE_SIZE, "%u %u\n",
491 sdp->sd_tune.gt_quota_scale_num,
492 sdp->sd_tune.gt_quota_scale_den);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000493}
494
495static ssize_t quota_scale_store(struct gfs2_sbd *sdp, const char *buf,
496 size_t len)
497{
498 struct gfs2_tune *gt = &sdp->sd_tune;
499 unsigned int x, y;
500
501 if (!capable(CAP_SYS_ADMIN))
502 return -EACCES;
503
504 if (sscanf(buf, "%u %u", &x, &y) != 2 || !y)
505 return -EINVAL;
506
507 spin_lock(&gt->gt_spin);
508 gt->gt_quota_scale_num = x;
509 gt->gt_quota_scale_den = y;
510 spin_unlock(&gt->gt_spin);
511 return len;
512}
513
514static ssize_t tune_set(struct gfs2_sbd *sdp, unsigned int *field,
515 int check_zero, const char *buf, size_t len)
516{
517 struct gfs2_tune *gt = &sdp->sd_tune;
518 unsigned int x;
519
520 if (!capable(CAP_SYS_ADMIN))
521 return -EACCES;
522
523 x = simple_strtoul(buf, NULL, 0);
524
525 if (check_zero && !x)
526 return -EINVAL;
527
528 spin_lock(&gt->gt_spin);
529 *field = x;
530 spin_unlock(&gt->gt_spin);
531 return len;
532}
533
534struct tune_attr {
535 struct attribute attr;
536 ssize_t (*show)(struct gfs2_sbd *, char *);
537 ssize_t (*store)(struct gfs2_sbd *, const char *, size_t);
538};
539
540#define TUNE_ATTR_3(name, show, store) \
541static struct tune_attr tune_attr_##name = __ATTR(name, 0644, show, store)
542
543#define TUNE_ATTR_2(name, store) \
544static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \
545{ \
David Teigland3204a6c2006-09-06 16:57:06 -0500546 return snprintf(buf, PAGE_SIZE, "%u\n", sdp->sd_tune.gt_##name); \
David Teiglandb3b94fa2006-01-16 16:50:04 +0000547} \
548TUNE_ATTR_3(name, name##_show, store)
549
550#define TUNE_ATTR(name, check_zero) \
551static ssize_t name##_store(struct gfs2_sbd *sdp, const char *buf, size_t len)\
552{ \
553 return tune_set(sdp, &sdp->sd_tune.gt_##name, check_zero, buf, len); \
554} \
555TUNE_ATTR_2(name, name##_store)
556
557#define TUNE_ATTR_DAEMON(name, process) \
558static ssize_t name##_store(struct gfs2_sbd *sdp, const char *buf, size_t len)\
559{ \
560 ssize_t r = tune_set(sdp, &sdp->sd_tune.gt_##name, 1, buf, len); \
561 wake_up_process(sdp->sd_##process); \
562 return r; \
563} \
564TUNE_ATTR_2(name, name##_store)
565
David Teiglandb3b94fa2006-01-16 16:50:04 +0000566TUNE_ATTR(incore_log_blocks, 0);
567TUNE_ATTR(log_flush_secs, 0);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000568TUNE_ATTR(quota_warn_period, 0);
569TUNE_ATTR(quota_quantum, 0);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000570TUNE_ATTR(max_readahead, 0);
571TUNE_ATTR(complain_secs, 0);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000572TUNE_ATTR(statfs_slow, 0);
573TUNE_ATTR(new_files_jdata, 0);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000574TUNE_ATTR(quota_simul_sync, 1);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000575TUNE_ATTR(stall_secs, 1);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000576TUNE_ATTR(statfs_quantum, 1);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000577TUNE_ATTR_DAEMON(recoverd_secs, recoverd_process);
578TUNE_ATTR_DAEMON(logd_secs, logd_process);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000579TUNE_ATTR_3(quota_scale, quota_scale_show, quota_scale_store);
580
581static struct attribute *tune_attrs[] = {
David Teiglandb3b94fa2006-01-16 16:50:04 +0000582 &tune_attr_incore_log_blocks.attr,
583 &tune_attr_log_flush_secs.attr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000584 &tune_attr_quota_warn_period.attr,
585 &tune_attr_quota_quantum.attr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000586 &tune_attr_max_readahead.attr,
587 &tune_attr_complain_secs.attr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000588 &tune_attr_statfs_slow.attr,
589 &tune_attr_quota_simul_sync.attr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000590 &tune_attr_stall_secs.attr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000591 &tune_attr_statfs_quantum.attr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000592 &tune_attr_recoverd_secs.attr,
593 &tune_attr_logd_secs.attr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000594 &tune_attr_quota_scale.attr,
595 &tune_attr_new_files_jdata.attr,
Steven Whitehouseea67eed2006-09-05 10:53:09 -0400596 NULL,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000597};
598
599static struct attribute_group lockstruct_group = {
600 .name = "lockstruct",
Steven Whitehouseea67eed2006-09-05 10:53:09 -0400601 .attrs = lockstruct_attrs,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000602};
603
David Teiglandb3b94fa2006-01-16 16:50:04 +0000604static struct attribute_group args_group = {
605 .name = "args",
Steven Whitehouseea67eed2006-09-05 10:53:09 -0400606 .attrs = args_attrs,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000607};
608
609static struct attribute_group tune_group = {
610 .name = "tune",
Steven Whitehouseea67eed2006-09-05 10:53:09 -0400611 .attrs = tune_attrs,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000612};
613
Steven Whitehousef057f6c2009-01-12 10:43:39 +0000614static struct attribute_group lock_module_group = {
615 .name = "lock_module",
616 .attrs = lock_module_attrs,
617};
618
David Teiglandb3b94fa2006-01-16 16:50:04 +0000619int gfs2_sys_fs_add(struct gfs2_sbd *sdp)
620{
621 int error;
622
Greg Kroah-Hartman9bec1012007-10-29 20:13:17 +0100623 sdp->sd_kobj.kset = gfs2_kset;
Greg Kroah-Hartman901195e2007-12-17 15:54:39 -0400624 error = kobject_init_and_add(&sdp->sd_kobj, &gfs2_ktype, NULL,
625 "%s", sdp->sd_table_name);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000626 if (error)
627 goto fail;
628
629 error = sysfs_create_group(&sdp->sd_kobj, &lockstruct_group);
630 if (error)
631 goto fail_reg;
632
David Teiglandb3b94fa2006-01-16 16:50:04 +0000633 error = sysfs_create_group(&sdp->sd_kobj, &args_group);
634 if (error)
Steven Whitehouse97cc1022008-11-20 13:39:47 +0000635 goto fail_lockstruct;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000636
637 error = sysfs_create_group(&sdp->sd_kobj, &tune_group);
638 if (error)
639 goto fail_args;
640
Steven Whitehousef057f6c2009-01-12 10:43:39 +0000641 error = sysfs_create_group(&sdp->sd_kobj, &lock_module_group);
642 if (error)
643 goto fail_tune;
644
Greg Kroah-Hartman901195e2007-12-17 15:54:39 -0400645 kobject_uevent(&sdp->sd_kobj, KOBJ_ADD);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000646 return 0;
647
Steven Whitehousef057f6c2009-01-12 10:43:39 +0000648fail_tune:
649 sysfs_remove_group(&sdp->sd_kobj, &tune_group);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400650fail_args:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000651 sysfs_remove_group(&sdp->sd_kobj, &args_group);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400652fail_lockstruct:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000653 sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400654fail_reg:
Greg Kroah-Hartman197b12d2007-12-20 08:13:05 -0800655 kobject_put(&sdp->sd_kobj);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400656fail:
David Teigland65952fb2006-09-15 13:09:11 -0500657 fs_err(sdp, "error %d adding sysfs files", error);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000658 return error;
659}
660
661void gfs2_sys_fs_del(struct gfs2_sbd *sdp)
662{
663 sysfs_remove_group(&sdp->sd_kobj, &tune_group);
664 sysfs_remove_group(&sdp->sd_kobj, &args_group);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000665 sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group);
Steven Whitehousef057f6c2009-01-12 10:43:39 +0000666 sysfs_remove_group(&sdp->sd_kobj, &lock_module_group);
Greg Kroah-Hartman197b12d2007-12-20 08:13:05 -0800667 kobject_put(&sdp->sd_kobj);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000668}
669
Steven Whitehouse02e3cc72009-02-10 13:48:30 +0000670
Steven Whitehousefdd10622008-11-26 10:26:38 +0000671static int gfs2_uevent(struct kset *kset, struct kobject *kobj,
672 struct kobj_uevent_env *env)
673{
674 struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj);
Steven Whitehouse02e3cc72009-02-10 13:48:30 +0000675 const u8 *uuid = sdp->sd_sb.sb_uuid;
676
Steven Whitehousefdd10622008-11-26 10:26:38 +0000677 add_uevent_var(env, "LOCKTABLE=%s", sdp->sd_table_name);
678 add_uevent_var(env, "LOCKPROTO=%s", sdp->sd_proto_name);
Steven Whitehouse02e3cc72009-02-10 13:48:30 +0000679 if (gfs2_uuid_valid(uuid)) {
680 add_uevent_var(env, "UUID=%02X%02X%02X%02X-%02X%02X-%02X%02X-"
681 "%02X%02X-%02X%02X%02X%02X%02X%02X",
682 uuid[0], uuid[1], uuid[2], uuid[3], uuid[4],
683 uuid[5], uuid[6], uuid[7], uuid[8], uuid[9],
684 uuid[10], uuid[11], uuid[12], uuid[13],
685 uuid[14], uuid[15]);
686 }
Steven Whitehousefdd10622008-11-26 10:26:38 +0000687 return 0;
688}
689
690static struct kset_uevent_ops gfs2_uevent_ops = {
691 .uevent = gfs2_uevent,
692};
693
694
David Teiglandb3b94fa2006-01-16 16:50:04 +0000695int gfs2_sys_init(void)
696{
Steven Whitehousefdd10622008-11-26 10:26:38 +0000697 gfs2_kset = kset_create_and_add("gfs2", &gfs2_uevent_ops, fs_kobj);
Greg Kroah-Hartman9bec1012007-10-29 20:13:17 +0100698 if (!gfs2_kset)
699 return -ENOMEM;
700 return 0;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000701}
702
703void gfs2_sys_uninit(void)
704{
Greg Kroah-Hartman9bec1012007-10-29 20:13:17 +0100705 kset_unregister(gfs2_kset);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000706}
707