blob: 4d284d14980b8ef4641ce78ba291dfb30a4298f7 [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
Steven Whitehouse02e3cc72009-02-10 13:48:30 +000039static int gfs2_uuid_valid(const u8 *uuid)
40{
41 int i;
42
43 for (i = 0; i < 16; i++) {
44 if (uuid[i])
45 return 1;
46 }
47 return 0;
48}
49
50static ssize_t uuid_show(struct gfs2_sbd *sdp, char *buf)
51{
52 const u8 *uuid = sdp->sd_sb.sb_uuid;
53 buf[0] = '\0';
54 if (!gfs2_uuid_valid(uuid))
55 return 0;
56 return snprintf(buf, PAGE_SIZE, "%02X%02X%02X%02X-%02X%02X-"
57 "%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X\n",
58 uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5],
59 uuid[6], uuid[7], uuid[8], uuid[9], uuid[10], uuid[11],
60 uuid[12], uuid[13], uuid[14], uuid[15]);
61}
62
David Teiglandb3b94fa2006-01-16 16:50:04 +000063static ssize_t freeze_show(struct gfs2_sbd *sdp, char *buf)
64{
65 unsigned int count;
66
Steven Whitehousef55ab262006-02-21 12:51:39 +000067 mutex_lock(&sdp->sd_freeze_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +000068 count = sdp->sd_freeze_count;
Steven Whitehousef55ab262006-02-21 12:51:39 +000069 mutex_unlock(&sdp->sd_freeze_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +000070
David Teigland3204a6c2006-09-06 16:57:06 -050071 return snprintf(buf, PAGE_SIZE, "%u\n", count);
David Teiglandb3b94fa2006-01-16 16:50:04 +000072}
73
74static ssize_t freeze_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
75{
76 ssize_t ret = len;
77 int error = 0;
78 int n = simple_strtol(buf, NULL, 0);
79
80 if (!capable(CAP_SYS_ADMIN))
81 return -EACCES;
82
83 switch (n) {
84 case 0:
85 gfs2_unfreeze_fs(sdp);
86 break;
87 case 1:
88 error = gfs2_freeze_fs(sdp);
89 break;
90 default:
91 ret = -EINVAL;
92 }
93
94 if (error)
95 fs_warn(sdp, "freeze %d error %d", n, error);
96
97 return ret;
98}
99
100static ssize_t withdraw_show(struct gfs2_sbd *sdp, char *buf)
101{
102 unsigned int b = test_bit(SDF_SHUTDOWN, &sdp->sd_flags);
David Teigland3204a6c2006-09-06 16:57:06 -0500103 return snprintf(buf, PAGE_SIZE, "%u\n", b);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000104}
105
106static ssize_t withdraw_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
107{
108 if (!capable(CAP_SYS_ADMIN))
109 return -EACCES;
110
111 if (simple_strtol(buf, NULL, 0) != 1)
112 return -EINVAL;
113
114 gfs2_lm_withdraw(sdp,
115 "GFS2: fsid=%s: withdrawing from cluster at user's request\n",
116 sdp->sd_fsname);
117 return len;
118}
119
120static ssize_t statfs_sync_store(struct gfs2_sbd *sdp, const char *buf,
121 size_t len)
122{
123 if (!capable(CAP_SYS_ADMIN))
124 return -EACCES;
125
126 if (simple_strtol(buf, NULL, 0) != 1)
127 return -EINVAL;
128
129 gfs2_statfs_sync(sdp);
130 return len;
131}
132
David Teiglandb3b94fa2006-01-16 16:50:04 +0000133static ssize_t quota_sync_store(struct gfs2_sbd *sdp, const char *buf,
134 size_t len)
135{
136 if (!capable(CAP_SYS_ADMIN))
137 return -EACCES;
138
139 if (simple_strtol(buf, NULL, 0) != 1)
140 return -EINVAL;
141
142 gfs2_quota_sync(sdp);
143 return len;
144}
145
146static ssize_t quota_refresh_user_store(struct gfs2_sbd *sdp, const char *buf,
147 size_t len)
148{
Steven Whitehousecd915492006-09-04 12:49:07 -0400149 u32 id;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000150
151 if (!capable(CAP_SYS_ADMIN))
152 return -EACCES;
153
154 id = simple_strtoul(buf, NULL, 0);
155
156 gfs2_quota_refresh(sdp, 1, id);
157 return len;
158}
159
160static ssize_t quota_refresh_group_store(struct gfs2_sbd *sdp, const char *buf,
161 size_t len)
162{
Steven Whitehousecd915492006-09-04 12:49:07 -0400163 u32 id;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000164
165 if (!capable(CAP_SYS_ADMIN))
166 return -EACCES;
167
168 id = simple_strtoul(buf, NULL, 0);
169
170 gfs2_quota_refresh(sdp, 0, id);
171 return len;
172}
173
174struct gfs2_attr {
175 struct attribute attr;
176 ssize_t (*show)(struct gfs2_sbd *, char *);
177 ssize_t (*store)(struct gfs2_sbd *, const char *, size_t);
178};
179
180#define GFS2_ATTR(name, mode, show, store) \
181static struct gfs2_attr gfs2_attr_##name = __ATTR(name, mode, show, store)
182
183GFS2_ATTR(id, 0444, id_show, NULL);
184GFS2_ATTR(fsname, 0444, fsname_show, NULL);
Steven Whitehouse02e3cc72009-02-10 13:48:30 +0000185GFS2_ATTR(uuid, 0444, uuid_show, NULL);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000186GFS2_ATTR(freeze, 0644, freeze_show, freeze_store);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000187GFS2_ATTR(withdraw, 0644, withdraw_show, withdraw_store);
188GFS2_ATTR(statfs_sync, 0200, NULL, statfs_sync_store);
189GFS2_ATTR(quota_sync, 0200, NULL, quota_sync_store);
190GFS2_ATTR(quota_refresh_user, 0200, NULL, quota_refresh_user_store);
191GFS2_ATTR(quota_refresh_group, 0200, NULL, quota_refresh_group_store);
192
193static struct attribute *gfs2_attrs[] = {
194 &gfs2_attr_id.attr,
195 &gfs2_attr_fsname.attr,
Steven Whitehouse02e3cc72009-02-10 13:48:30 +0000196 &gfs2_attr_uuid.attr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000197 &gfs2_attr_freeze.attr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000198 &gfs2_attr_withdraw.attr,
199 &gfs2_attr_statfs_sync.attr,
200 &gfs2_attr_quota_sync.attr,
201 &gfs2_attr_quota_refresh_user.attr,
202 &gfs2_attr_quota_refresh_group.attr,
203 NULL,
204};
205
206static ssize_t gfs2_attr_show(struct kobject *kobj, struct attribute *attr,
207 char *buf)
208{
209 struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj);
210 struct gfs2_attr *a = container_of(attr, struct gfs2_attr, attr);
211 return a->show ? a->show(sdp, buf) : 0;
212}
213
214static ssize_t gfs2_attr_store(struct kobject *kobj, struct attribute *attr,
215 const char *buf, size_t len)
216{
217 struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj);
218 struct gfs2_attr *a = container_of(attr, struct gfs2_attr, attr);
219 return a->store ? a->store(sdp, buf, len) : len;
220}
221
222static struct sysfs_ops gfs2_attr_ops = {
223 .show = gfs2_attr_show,
224 .store = gfs2_attr_store,
225};
226
227static struct kobj_type gfs2_ktype = {
228 .default_attrs = gfs2_attrs,
229 .sysfs_ops = &gfs2_attr_ops,
230};
231
Greg Kroah-Hartman9bec1012007-10-29 20:13:17 +0100232static struct kset *gfs2_kset;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000233
234/*
235 * display struct lm_lockstruct fields
236 */
237
238struct lockstruct_attr {
239 struct attribute attr;
240 ssize_t (*show)(struct gfs2_sbd *, char *);
241};
242
243#define LOCKSTRUCT_ATTR(name, fmt) \
244static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \
245{ \
David Teigland3204a6c2006-09-06 16:57:06 -0500246 return snprintf(buf, PAGE_SIZE, fmt, sdp->sd_lockstruct.ls_##name); \
David Teiglandb3b94fa2006-01-16 16:50:04 +0000247} \
248static struct lockstruct_attr lockstruct_attr_##name = __ATTR_RO(name)
249
250LOCKSTRUCT_ATTR(jid, "%u\n");
251LOCKSTRUCT_ATTR(first, "%u\n");
David Teiglandb3b94fa2006-01-16 16:50:04 +0000252
253static struct attribute *lockstruct_attrs[] = {
254 &lockstruct_attr_jid.attr,
255 &lockstruct_attr_first.attr,
Steven Whitehousef057f6c2009-01-12 10:43:39 +0000256 NULL,
257};
258
259/*
260 * lock_module. Originally from lock_dlm
261 */
262
263static ssize_t proto_name_show(struct gfs2_sbd *sdp, char *buf)
264{
265 const struct lm_lockops *ops = sdp->sd_lockstruct.ls_ops;
266 return sprintf(buf, "%s\n", ops->lm_proto_name);
267}
268
269static ssize_t block_show(struct gfs2_sbd *sdp, char *buf)
270{
271 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
272 ssize_t ret;
273 int val = 0;
274
275 if (test_bit(DFL_BLOCK_LOCKS, &ls->ls_flags))
276 val = 1;
277 ret = sprintf(buf, "%d\n", val);
278 return ret;
279}
280
281static ssize_t block_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
282{
283 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
284 ssize_t ret = len;
285 int val;
286
287 val = simple_strtol(buf, NULL, 0);
288
289 if (val == 1)
290 set_bit(DFL_BLOCK_LOCKS, &ls->ls_flags);
291 else if (val == 0) {
292 clear_bit(DFL_BLOCK_LOCKS, &ls->ls_flags);
293 smp_mb__after_clear_bit();
294 gfs2_glock_thaw(sdp);
295 } else {
296 ret = -EINVAL;
297 }
298 return ret;
299}
300
301static ssize_t lkid_show(struct gfs2_sbd *sdp, char *buf)
302{
303 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
304 return sprintf(buf, "%u\n", ls->ls_id);
305}
306
307static ssize_t lkfirst_show(struct gfs2_sbd *sdp, char *buf)
308{
309 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
310 return sprintf(buf, "%d\n", ls->ls_first);
311}
312
313static ssize_t first_done_show(struct gfs2_sbd *sdp, char *buf)
314{
315 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
316 return sprintf(buf, "%d\n", ls->ls_first_done);
317}
318
319static ssize_t recover_show(struct gfs2_sbd *sdp, char *buf)
320{
321 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
322 return sprintf(buf, "%d\n", ls->ls_recover_jid);
323}
324
325static void gfs2_jdesc_make_dirty(struct gfs2_sbd *sdp, unsigned int jid)
326{
327 struct gfs2_jdesc *jd;
328
329 spin_lock(&sdp->sd_jindex_spin);
330 list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) {
331 if (jd->jd_jid != jid)
332 continue;
333 jd->jd_dirty = 1;
334 break;
335 }
336 spin_unlock(&sdp->sd_jindex_spin);
337}
338
339static ssize_t recover_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
340{
341 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
342 ls->ls_recover_jid = simple_strtol(buf, NULL, 0);
343 gfs2_jdesc_make_dirty(sdp, ls->ls_recover_jid);
344 if (sdp->sd_recoverd_process)
345 wake_up_process(sdp->sd_recoverd_process);
346 return len;
347}
348
349static ssize_t recover_done_show(struct gfs2_sbd *sdp, char *buf)
350{
351 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
352 return sprintf(buf, "%d\n", ls->ls_recover_jid_done);
353}
354
355static ssize_t recover_status_show(struct gfs2_sbd *sdp, char *buf)
356{
357 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
358 return sprintf(buf, "%d\n", ls->ls_recover_jid_status);
359}
360
361struct gdlm_attr {
362 struct attribute attr;
363 ssize_t (*show)(struct gfs2_sbd *sdp, char *);
364 ssize_t (*store)(struct gfs2_sbd *sdp, const char *, size_t);
365};
366
367#define GDLM_ATTR(_name,_mode,_show,_store) \
368static struct gdlm_attr gdlm_attr_##_name = __ATTR(_name,_mode,_show,_store)
369
370GDLM_ATTR(proto_name, 0444, proto_name_show, NULL);
371GDLM_ATTR(block, 0644, block_show, block_store);
372GDLM_ATTR(withdraw, 0644, withdraw_show, withdraw_store);
373GDLM_ATTR(id, 0444, lkid_show, NULL);
374GDLM_ATTR(first, 0444, lkfirst_show, NULL);
375GDLM_ATTR(first_done, 0444, first_done_show, NULL);
376GDLM_ATTR(recover, 0644, recover_show, recover_store);
377GDLM_ATTR(recover_done, 0444, recover_done_show, NULL);
378GDLM_ATTR(recover_status, 0444, recover_status_show, NULL);
379
380static struct attribute *lock_module_attrs[] = {
381 &gdlm_attr_proto_name.attr,
382 &gdlm_attr_block.attr,
383 &gdlm_attr_withdraw.attr,
384 &gdlm_attr_id.attr,
385 &lockstruct_attr_jid.attr,
386 &gdlm_attr_first.attr,
387 &gdlm_attr_first_done.attr,
388 &gdlm_attr_recover.attr,
389 &gdlm_attr_recover_done.attr,
390 &gdlm_attr_recover_status.attr,
Steven Whitehouseea67eed2006-09-05 10:53:09 -0400391 NULL,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000392};
393
394/*
395 * display struct gfs2_args fields
396 */
397
398struct args_attr {
399 struct attribute attr;
400 ssize_t (*show)(struct gfs2_sbd *, char *);
401};
402
403#define ARGS_ATTR(name, fmt) \
404static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \
405{ \
David Teigland3204a6c2006-09-06 16:57:06 -0500406 return snprintf(buf, PAGE_SIZE, fmt, sdp->sd_args.ar_##name); \
David Teiglandb3b94fa2006-01-16 16:50:04 +0000407} \
408static struct args_attr args_attr_##name = __ATTR_RO(name)
409
410ARGS_ATTR(lockproto, "%s\n");
411ARGS_ATTR(locktable, "%s\n");
412ARGS_ATTR(hostdata, "%s\n");
413ARGS_ATTR(spectator, "%d\n");
414ARGS_ATTR(ignore_local_fs, "%d\n");
415ARGS_ATTR(localcaching, "%d\n");
416ARGS_ATTR(localflocks, "%d\n");
417ARGS_ATTR(debug, "%d\n");
418ARGS_ATTR(upgrade, "%d\n");
David Teiglandb3b94fa2006-01-16 16:50:04 +0000419ARGS_ATTR(posix_acl, "%d\n");
420ARGS_ATTR(quota, "%u\n");
421ARGS_ATTR(suiddir, "%d\n");
422ARGS_ATTR(data, "%d\n");
423
David Teiglandb3b94fa2006-01-16 16:50:04 +0000424static struct attribute *args_attrs[] = {
425 &args_attr_lockproto.attr,
426 &args_attr_locktable.attr,
427 &args_attr_hostdata.attr,
428 &args_attr_spectator.attr,
429 &args_attr_ignore_local_fs.attr,
430 &args_attr_localcaching.attr,
431 &args_attr_localflocks.attr,
432 &args_attr_debug.attr,
433 &args_attr_upgrade.attr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000434 &args_attr_posix_acl.attr,
435 &args_attr_quota.attr,
436 &args_attr_suiddir.attr,
437 &args_attr_data.attr,
Steven Whitehouseea67eed2006-09-05 10:53:09 -0400438 NULL,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000439};
440
441/*
David Teiglandb3b94fa2006-01-16 16:50:04 +0000442 * get and set struct gfs2_tune fields
443 */
444
445static ssize_t quota_scale_show(struct gfs2_sbd *sdp, char *buf)
446{
David Teigland3204a6c2006-09-06 16:57:06 -0500447 return snprintf(buf, PAGE_SIZE, "%u %u\n",
448 sdp->sd_tune.gt_quota_scale_num,
449 sdp->sd_tune.gt_quota_scale_den);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000450}
451
452static ssize_t quota_scale_store(struct gfs2_sbd *sdp, const char *buf,
453 size_t len)
454{
455 struct gfs2_tune *gt = &sdp->sd_tune;
456 unsigned int x, y;
457
458 if (!capable(CAP_SYS_ADMIN))
459 return -EACCES;
460
461 if (sscanf(buf, "%u %u", &x, &y) != 2 || !y)
462 return -EINVAL;
463
464 spin_lock(&gt->gt_spin);
465 gt->gt_quota_scale_num = x;
466 gt->gt_quota_scale_den = y;
467 spin_unlock(&gt->gt_spin);
468 return len;
469}
470
471static ssize_t tune_set(struct gfs2_sbd *sdp, unsigned int *field,
472 int check_zero, const char *buf, size_t len)
473{
474 struct gfs2_tune *gt = &sdp->sd_tune;
475 unsigned int x;
476
477 if (!capable(CAP_SYS_ADMIN))
478 return -EACCES;
479
480 x = simple_strtoul(buf, NULL, 0);
481
482 if (check_zero && !x)
483 return -EINVAL;
484
485 spin_lock(&gt->gt_spin);
486 *field = x;
487 spin_unlock(&gt->gt_spin);
488 return len;
489}
490
491struct tune_attr {
492 struct attribute attr;
493 ssize_t (*show)(struct gfs2_sbd *, char *);
494 ssize_t (*store)(struct gfs2_sbd *, const char *, size_t);
495};
496
497#define TUNE_ATTR_3(name, show, store) \
498static struct tune_attr tune_attr_##name = __ATTR(name, 0644, show, store)
499
500#define TUNE_ATTR_2(name, store) \
501static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \
502{ \
David Teigland3204a6c2006-09-06 16:57:06 -0500503 return snprintf(buf, PAGE_SIZE, "%u\n", sdp->sd_tune.gt_##name); \
David Teiglandb3b94fa2006-01-16 16:50:04 +0000504} \
505TUNE_ATTR_3(name, name##_show, store)
506
507#define TUNE_ATTR(name, check_zero) \
508static ssize_t name##_store(struct gfs2_sbd *sdp, const char *buf, size_t len)\
509{ \
510 return tune_set(sdp, &sdp->sd_tune.gt_##name, check_zero, buf, len); \
511} \
512TUNE_ATTR_2(name, name##_store)
513
514#define TUNE_ATTR_DAEMON(name, process) \
515static ssize_t name##_store(struct gfs2_sbd *sdp, const char *buf, size_t len)\
516{ \
517 ssize_t r = tune_set(sdp, &sdp->sd_tune.gt_##name, 1, buf, len); \
518 wake_up_process(sdp->sd_##process); \
519 return r; \
520} \
521TUNE_ATTR_2(name, name##_store)
522
David Teiglandb3b94fa2006-01-16 16:50:04 +0000523TUNE_ATTR(incore_log_blocks, 0);
524TUNE_ATTR(log_flush_secs, 0);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000525TUNE_ATTR(quota_warn_period, 0);
526TUNE_ATTR(quota_quantum, 0);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000527TUNE_ATTR(max_readahead, 0);
528TUNE_ATTR(complain_secs, 0);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000529TUNE_ATTR(statfs_slow, 0);
530TUNE_ATTR(new_files_jdata, 0);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000531TUNE_ATTR(quota_simul_sync, 1);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000532TUNE_ATTR(stall_secs, 1);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000533TUNE_ATTR(statfs_quantum, 1);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000534TUNE_ATTR_DAEMON(recoverd_secs, recoverd_process);
535TUNE_ATTR_DAEMON(logd_secs, logd_process);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000536TUNE_ATTR_3(quota_scale, quota_scale_show, quota_scale_store);
537
538static struct attribute *tune_attrs[] = {
David Teiglandb3b94fa2006-01-16 16:50:04 +0000539 &tune_attr_incore_log_blocks.attr,
540 &tune_attr_log_flush_secs.attr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000541 &tune_attr_quota_warn_period.attr,
542 &tune_attr_quota_quantum.attr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000543 &tune_attr_max_readahead.attr,
544 &tune_attr_complain_secs.attr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000545 &tune_attr_statfs_slow.attr,
546 &tune_attr_quota_simul_sync.attr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000547 &tune_attr_stall_secs.attr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000548 &tune_attr_statfs_quantum.attr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000549 &tune_attr_recoverd_secs.attr,
550 &tune_attr_logd_secs.attr,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000551 &tune_attr_quota_scale.attr,
552 &tune_attr_new_files_jdata.attr,
Steven Whitehouseea67eed2006-09-05 10:53:09 -0400553 NULL,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000554};
555
556static struct attribute_group lockstruct_group = {
557 .name = "lockstruct",
Steven Whitehouseea67eed2006-09-05 10:53:09 -0400558 .attrs = lockstruct_attrs,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000559};
560
David Teiglandb3b94fa2006-01-16 16:50:04 +0000561static struct attribute_group args_group = {
562 .name = "args",
Steven Whitehouseea67eed2006-09-05 10:53:09 -0400563 .attrs = args_attrs,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000564};
565
566static struct attribute_group tune_group = {
567 .name = "tune",
Steven Whitehouseea67eed2006-09-05 10:53:09 -0400568 .attrs = tune_attrs,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000569};
570
Steven Whitehousef057f6c2009-01-12 10:43:39 +0000571static struct attribute_group lock_module_group = {
572 .name = "lock_module",
573 .attrs = lock_module_attrs,
574};
575
David Teiglandb3b94fa2006-01-16 16:50:04 +0000576int gfs2_sys_fs_add(struct gfs2_sbd *sdp)
577{
578 int error;
579
Greg Kroah-Hartman9bec1012007-10-29 20:13:17 +0100580 sdp->sd_kobj.kset = gfs2_kset;
Greg Kroah-Hartman901195e2007-12-17 15:54:39 -0400581 error = kobject_init_and_add(&sdp->sd_kobj, &gfs2_ktype, NULL,
582 "%s", sdp->sd_table_name);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000583 if (error)
584 goto fail;
585
586 error = sysfs_create_group(&sdp->sd_kobj, &lockstruct_group);
587 if (error)
588 goto fail_reg;
589
David Teiglandb3b94fa2006-01-16 16:50:04 +0000590 error = sysfs_create_group(&sdp->sd_kobj, &args_group);
591 if (error)
Steven Whitehouse97cc10252008-11-20 13:39:47 +0000592 goto fail_lockstruct;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000593
594 error = sysfs_create_group(&sdp->sd_kobj, &tune_group);
595 if (error)
596 goto fail_args;
597
Steven Whitehousef057f6c2009-01-12 10:43:39 +0000598 error = sysfs_create_group(&sdp->sd_kobj, &lock_module_group);
599 if (error)
600 goto fail_tune;
601
Greg Kroah-Hartman901195e2007-12-17 15:54:39 -0400602 kobject_uevent(&sdp->sd_kobj, KOBJ_ADD);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000603 return 0;
604
Steven Whitehousef057f6c2009-01-12 10:43:39 +0000605fail_tune:
606 sysfs_remove_group(&sdp->sd_kobj, &tune_group);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400607fail_args:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000608 sysfs_remove_group(&sdp->sd_kobj, &args_group);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400609fail_lockstruct:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000610 sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400611fail_reg:
Greg Kroah-Hartman197b12d2007-12-20 08:13:05 -0800612 kobject_put(&sdp->sd_kobj);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400613fail:
David Teigland65952fb2006-09-15 13:09:11 -0500614 fs_err(sdp, "error %d adding sysfs files", error);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000615 return error;
616}
617
618void gfs2_sys_fs_del(struct gfs2_sbd *sdp)
619{
620 sysfs_remove_group(&sdp->sd_kobj, &tune_group);
621 sysfs_remove_group(&sdp->sd_kobj, &args_group);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000622 sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group);
Steven Whitehousef057f6c2009-01-12 10:43:39 +0000623 sysfs_remove_group(&sdp->sd_kobj, &lock_module_group);
Greg Kroah-Hartman197b12d2007-12-20 08:13:05 -0800624 kobject_put(&sdp->sd_kobj);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000625}
626
Steven Whitehouse02e3cc72009-02-10 13:48:30 +0000627
Steven Whitehousefdd1062e2008-11-26 10:26:38 +0000628static int gfs2_uevent(struct kset *kset, struct kobject *kobj,
629 struct kobj_uevent_env *env)
630{
631 struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj);
Steven Whitehouse02e3cc72009-02-10 13:48:30 +0000632 const u8 *uuid = sdp->sd_sb.sb_uuid;
633
Steven Whitehousefdd1062e2008-11-26 10:26:38 +0000634 add_uevent_var(env, "LOCKTABLE=%s", sdp->sd_table_name);
635 add_uevent_var(env, "LOCKPROTO=%s", sdp->sd_proto_name);
Steven Whitehouse02e3cc72009-02-10 13:48:30 +0000636 if (gfs2_uuid_valid(uuid)) {
637 add_uevent_var(env, "UUID=%02X%02X%02X%02X-%02X%02X-%02X%02X-"
638 "%02X%02X-%02X%02X%02X%02X%02X%02X",
639 uuid[0], uuid[1], uuid[2], uuid[3], uuid[4],
640 uuid[5], uuid[6], uuid[7], uuid[8], uuid[9],
641 uuid[10], uuid[11], uuid[12], uuid[13],
642 uuid[14], uuid[15]);
643 }
Steven Whitehousefdd1062e2008-11-26 10:26:38 +0000644 return 0;
645}
646
647static struct kset_uevent_ops gfs2_uevent_ops = {
648 .uevent = gfs2_uevent,
649};
650
651
David Teiglandb3b94fa2006-01-16 16:50:04 +0000652int gfs2_sys_init(void)
653{
Steven Whitehousefdd1062e2008-11-26 10:26:38 +0000654 gfs2_kset = kset_create_and_add("gfs2", &gfs2_uevent_ops, fs_kobj);
Greg Kroah-Hartman9bec1012007-10-29 20:13:17 +0100655 if (!gfs2_kset)
656 return -ENOMEM;
657 return 0;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000658}
659
660void gfs2_sys_uninit(void)
661{
Greg Kroah-Hartman9bec1012007-10-29 20:13:17 +0100662 kset_unregister(gfs2_kset);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000663}
664