GFS2: Add a "demote a glock" interface to sysfs
[deliverable/linux.git] / fs / gfs2 / sys.c
CommitLineData
b3b94faa
DT
1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3a8a9a10 3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
b3b94faa
DT
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
e9fc2aa0 7 * of the GNU General Public License version 2.
b3b94faa
DT
8 */
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>
b3b94faa 17#include <asm/uaccess.h>
f057f6cd 18#include <linux/gfs2_ondisk.h>
b3b94faa
DT
19
20#include "gfs2.h"
5c676f6d 21#include "incore.h"
b3b94faa
DT
22#include "sys.h"
23#include "super.h"
24#include "glock.h"
25#include "quota.h"
5c676f6d 26#include "util.h"
64d576ba 27#include "glops.h"
b3b94faa 28
b3b94faa
DT
29static ssize_t id_show(struct gfs2_sbd *sdp, char *buf)
30{
c7227e46
BP
31 return snprintf(buf, PAGE_SIZE, "%u:%u\n",
32 MAJOR(sdp->sd_vfs->s_dev), MINOR(sdp->sd_vfs->s_dev));
b3b94faa
DT
33}
34
35static ssize_t fsname_show(struct gfs2_sbd *sdp, char *buf)
36{
3204a6c0 37 return snprintf(buf, PAGE_SIZE, "%s\n", sdp->sd_fsname);
b3b94faa
DT
38}
39
02e3cc70
SW
40static 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
b3b94faa
DT
64static ssize_t freeze_show(struct gfs2_sbd *sdp, char *buf)
65{
66 unsigned int count;
67
f55ab26a 68 mutex_lock(&sdp->sd_freeze_lock);
b3b94faa 69 count = sdp->sd_freeze_count;
f55ab26a 70 mutex_unlock(&sdp->sd_freeze_lock);
b3b94faa 71
3204a6c0 72 return snprintf(buf, PAGE_SIZE, "%u\n", count);
b3b94faa
DT
73}
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);
3204a6c0 104 return snprintf(buf, PAGE_SIZE, "%u\n", b);
b3b94faa
DT
105}
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
b3b94faa
DT
134static 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{
cd915493 150 u32 id;
b3b94faa
DT
151
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{
cd915493 164 u32 id;
b3b94faa
DT
165
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
64d576ba
SW
175static 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
b3b94faa
DT
215struct 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);
02e3cc70 226GFS2_ATTR(uuid, 0444, uuid_show, NULL);
b3b94faa 227GFS2_ATTR(freeze, 0644, freeze_show, freeze_store);
b3b94faa
DT
228GFS2_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);
64d576ba 233GFS2_ATTR(demote_rq, 0200, NULL, demote_rq_store);
b3b94faa
DT
234
235static struct attribute *gfs2_attrs[] = {
236 &gfs2_attr_id.attr,
237 &gfs2_attr_fsname.attr,
02e3cc70 238 &gfs2_attr_uuid.attr,
b3b94faa 239 &gfs2_attr_freeze.attr,
b3b94faa
DT
240 &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,
64d576ba 245 &gfs2_attr_demote_rq.attr,
b3b94faa
DT
246 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
9bec101a 275static struct kset *gfs2_kset;
b3b94faa
DT
276
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{ \
3204a6c0 289 return snprintf(buf, PAGE_SIZE, fmt, sdp->sd_lockstruct.ls_##name); \
b3b94faa
DT
290} \
291static struct lockstruct_attr lockstruct_attr_##name = __ATTR_RO(name)
292
293LOCKSTRUCT_ATTR(jid, "%u\n");
294LOCKSTRUCT_ATTR(first, "%u\n");
b3b94faa
DT
295
296static struct attribute *lockstruct_attrs[] = {
297 &lockstruct_attr_jid.attr,
298 &lockstruct_attr_first.attr,
f057f6cd
SW
299 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,
ea67eedb 434 NULL,
b3b94faa
DT
435};
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{ \
3204a6c0 449 return snprintf(buf, PAGE_SIZE, fmt, sdp->sd_args.ar_##name); \
b3b94faa
DT
450} \
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");
b3b94faa
DT
462ARGS_ATTR(posix_acl, "%d\n");
463ARGS_ATTR(quota, "%u\n");
464ARGS_ATTR(suiddir, "%d\n");
465ARGS_ATTR(data, "%d\n");
466
b3b94faa
DT
467static 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,
b3b94faa
DT
477 &args_attr_posix_acl.attr,
478 &args_attr_quota.attr,
479 &args_attr_suiddir.attr,
480 &args_attr_data.attr,
ea67eedb 481 NULL,
b3b94faa
DT
482};
483
b3b94faa
DT
484/*
485 * get and set struct gfs2_tune fields
486 */
487
488static ssize_t quota_scale_show(struct gfs2_sbd *sdp, char *buf)
489{
3204a6c0
DT
490 return snprintf(buf, PAGE_SIZE, "%u %u\n",
491 sdp->sd_tune.gt_quota_scale_num,
492 sdp->sd_tune.gt_quota_scale_den);
b3b94faa
DT
493}
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{ \
3204a6c0 546 return snprintf(buf, PAGE_SIZE, "%u\n", sdp->sd_tune.gt_##name); \
b3b94faa
DT
547} \
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
b3b94faa
DT
566TUNE_ATTR(incore_log_blocks, 0);
567TUNE_ATTR(log_flush_secs, 0);
b3b94faa
DT
568TUNE_ATTR(quota_warn_period, 0);
569TUNE_ATTR(quota_quantum, 0);
b3b94faa
DT
570TUNE_ATTR(max_readahead, 0);
571TUNE_ATTR(complain_secs, 0);
b3b94faa
DT
572TUNE_ATTR(statfs_slow, 0);
573TUNE_ATTR(new_files_jdata, 0);
b3b94faa 574TUNE_ATTR(quota_simul_sync, 1);
b3b94faa 575TUNE_ATTR(stall_secs, 1);
b3b94faa 576TUNE_ATTR(statfs_quantum, 1);
b3b94faa
DT
577TUNE_ATTR_DAEMON(recoverd_secs, recoverd_process);
578TUNE_ATTR_DAEMON(logd_secs, logd_process);
b3b94faa
DT
579TUNE_ATTR_3(quota_scale, quota_scale_show, quota_scale_store);
580
581static struct attribute *tune_attrs[] = {
b3b94faa
DT
582 &tune_attr_incore_log_blocks.attr,
583 &tune_attr_log_flush_secs.attr,
b3b94faa
DT
584 &tune_attr_quota_warn_period.attr,
585 &tune_attr_quota_quantum.attr,
b3b94faa
DT
586 &tune_attr_max_readahead.attr,
587 &tune_attr_complain_secs.attr,
b3b94faa
DT
588 &tune_attr_statfs_slow.attr,
589 &tune_attr_quota_simul_sync.attr,
b3b94faa 590 &tune_attr_stall_secs.attr,
b3b94faa 591 &tune_attr_statfs_quantum.attr,
b3b94faa
DT
592 &tune_attr_recoverd_secs.attr,
593 &tune_attr_logd_secs.attr,
b3b94faa
DT
594 &tune_attr_quota_scale.attr,
595 &tune_attr_new_files_jdata.attr,
ea67eedb 596 NULL,
b3b94faa
DT
597};
598
599static struct attribute_group lockstruct_group = {
600 .name = "lockstruct",
ea67eedb 601 .attrs = lockstruct_attrs,
b3b94faa
DT
602};
603
b3b94faa
DT
604static struct attribute_group args_group = {
605 .name = "args",
ea67eedb 606 .attrs = args_attrs,
b3b94faa
DT
607};
608
609static struct attribute_group tune_group = {
610 .name = "tune",
ea67eedb 611 .attrs = tune_attrs,
b3b94faa
DT
612};
613
f057f6cd
SW
614static struct attribute_group lock_module_group = {
615 .name = "lock_module",
616 .attrs = lock_module_attrs,
617};
618
b3b94faa
DT
619int gfs2_sys_fs_add(struct gfs2_sbd *sdp)
620{
621 int error;
622
9bec101a 623 sdp->sd_kobj.kset = gfs2_kset;
901195ed
GKH
624 error = kobject_init_and_add(&sdp->sd_kobj, &gfs2_ktype, NULL,
625 "%s", sdp->sd_table_name);
b3b94faa
DT
626 if (error)
627 goto fail;
628
629 error = sysfs_create_group(&sdp->sd_kobj, &lockstruct_group);
630 if (error)
631 goto fail_reg;
632
b3b94faa
DT
633 error = sysfs_create_group(&sdp->sd_kobj, &args_group);
634 if (error)
97cc1025 635 goto fail_lockstruct;
b3b94faa
DT
636
637 error = sysfs_create_group(&sdp->sd_kobj, &tune_group);
638 if (error)
639 goto fail_args;
640
f057f6cd
SW
641 error = sysfs_create_group(&sdp->sd_kobj, &lock_module_group);
642 if (error)
643 goto fail_tune;
644
901195ed 645 kobject_uevent(&sdp->sd_kobj, KOBJ_ADD);
b3b94faa
DT
646 return 0;
647
f057f6cd
SW
648fail_tune:
649 sysfs_remove_group(&sdp->sd_kobj, &tune_group);
a91ea69f 650fail_args:
b3b94faa 651 sysfs_remove_group(&sdp->sd_kobj, &args_group);
a91ea69f 652fail_lockstruct:
b3b94faa 653 sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group);
a91ea69f 654fail_reg:
197b12d6 655 kobject_put(&sdp->sd_kobj);
a91ea69f 656fail:
65952fb4 657 fs_err(sdp, "error %d adding sysfs files", error);
b3b94faa
DT
658 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);
b3b94faa 665 sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group);
f057f6cd 666 sysfs_remove_group(&sdp->sd_kobj, &lock_module_group);
197b12d6 667 kobject_put(&sdp->sd_kobj);
b3b94faa
DT
668}
669
02e3cc70 670
fdd1062e
SW
671static 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);
02e3cc70
SW
675 const u8 *uuid = sdp->sd_sb.sb_uuid;
676
fdd1062e
SW
677 add_uevent_var(env, "LOCKTABLE=%s", sdp->sd_table_name);
678 add_uevent_var(env, "LOCKPROTO=%s", sdp->sd_proto_name);
02e3cc70
SW
679 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 }
fdd1062e
SW
687 return 0;
688}
689
690static struct kset_uevent_ops gfs2_uevent_ops = {
691 .uevent = gfs2_uevent,
692};
693
694
b3b94faa
DT
695int gfs2_sys_init(void)
696{
fdd1062e 697 gfs2_kset = kset_create_and_add("gfs2", &gfs2_uevent_ops, fs_kobj);
9bec101a
GKH
698 if (!gfs2_kset)
699 return -ENOMEM;
700 return 0;
b3b94faa
DT
701}
702
703void gfs2_sys_uninit(void)
704{
9bec101a 705 kset_unregister(gfs2_kset);
b3b94faa
DT
706}
707
This page took 0.387458 seconds and 5 git commands to generate.