Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux...
[linux-2.6] / fs / gfs2 / sys.c
1 /*
2  * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
3  * Copyright (C) 2004-2006 Red Hat, Inc.  All rights reserved.
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
7  * of the GNU General Public License version 2.
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>
17 #include <asm/uaccess.h>
18 #include <linux/gfs2_ondisk.h>
19
20 #include "gfs2.h"
21 #include "incore.h"
22 #include "sys.h"
23 #include "super.h"
24 #include "glock.h"
25 #include "quota.h"
26 #include "util.h"
27 #include "glops.h"
28
29 static ssize_t id_show(struct gfs2_sbd *sdp, char *buf)
30 {
31         return snprintf(buf, PAGE_SIZE, "%u:%u\n",
32                         MAJOR(sdp->sd_vfs->s_dev), MINOR(sdp->sd_vfs->s_dev));
33 }
34
35 static ssize_t fsname_show(struct gfs2_sbd *sdp, char *buf)
36 {
37         return snprintf(buf, PAGE_SIZE, "%s\n", sdp->sd_fsname);
38 }
39
40 static 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
51 static 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
64 static ssize_t freeze_show(struct gfs2_sbd *sdp, char *buf)
65 {
66         unsigned int count;
67
68         mutex_lock(&sdp->sd_freeze_lock);
69         count = sdp->sd_freeze_count;
70         mutex_unlock(&sdp->sd_freeze_lock);
71
72         return snprintf(buf, PAGE_SIZE, "%u\n", count);
73 }
74
75 static 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
101 static ssize_t withdraw_show(struct gfs2_sbd *sdp, char *buf)
102 {
103         unsigned int b = test_bit(SDF_SHUTDOWN, &sdp->sd_flags);
104         return snprintf(buf, PAGE_SIZE, "%u\n", b);
105 }
106
107 static 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
121 static 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
134 static 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
147 static ssize_t quota_refresh_user_store(struct gfs2_sbd *sdp, const char *buf,
148                                         size_t len)
149 {
150         u32 id;
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
161 static ssize_t quota_refresh_group_store(struct gfs2_sbd *sdp, const char *buf,
162                                          size_t len)
163 {
164         u32 id;
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
175 static 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
215 struct 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) \
222 static struct gfs2_attr gfs2_attr_##name = __ATTR(name, mode, show, store)
223
224 GFS2_ATTR(id,                  0444, id_show,       NULL);
225 GFS2_ATTR(fsname,              0444, fsname_show,   NULL);
226 GFS2_ATTR(uuid,                0444, uuid_show,     NULL);
227 GFS2_ATTR(freeze,              0644, freeze_show,   freeze_store);
228 GFS2_ATTR(withdraw,            0644, withdraw_show, withdraw_store);
229 GFS2_ATTR(statfs_sync,         0200, NULL,          statfs_sync_store);
230 GFS2_ATTR(quota_sync,          0200, NULL,          quota_sync_store);
231 GFS2_ATTR(quota_refresh_user,  0200, NULL,          quota_refresh_user_store);
232 GFS2_ATTR(quota_refresh_group, 0200, NULL,          quota_refresh_group_store);
233 GFS2_ATTR(demote_rq,           0200, NULL,          demote_rq_store);
234
235 static struct attribute *gfs2_attrs[] = {
236         &gfs2_attr_id.attr,
237         &gfs2_attr_fsname.attr,
238         &gfs2_attr_uuid.attr,
239         &gfs2_attr_freeze.attr,
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,
245         &gfs2_attr_demote_rq.attr,
246         NULL,
247 };
248
249 static 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
257 static 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
265 static struct sysfs_ops gfs2_attr_ops = {
266         .show  = gfs2_attr_show,
267         .store = gfs2_attr_store,
268 };
269
270 static struct kobj_type gfs2_ktype = {
271         .default_attrs = gfs2_attrs,
272         .sysfs_ops     = &gfs2_attr_ops,
273 };
274
275 static struct kset *gfs2_kset;
276
277 /*
278  * display struct lm_lockstruct fields
279  */
280
281 struct lockstruct_attr {
282         struct attribute attr;
283         ssize_t (*show)(struct gfs2_sbd *, char *);
284 };
285
286 #define LOCKSTRUCT_ATTR(name, fmt)                                          \
287 static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf)                 \
288 {                                                                           \
289         return snprintf(buf, PAGE_SIZE, fmt, sdp->sd_lockstruct.ls_##name); \
290 }                                                                           \
291 static struct lockstruct_attr lockstruct_attr_##name = __ATTR_RO(name)
292
293 LOCKSTRUCT_ATTR(jid,      "%u\n");
294 LOCKSTRUCT_ATTR(first,    "%u\n");
295
296 static struct attribute *lockstruct_attrs[] = {
297         &lockstruct_attr_jid.attr,
298         &lockstruct_attr_first.attr,
299         NULL,
300 };
301
302 /*
303  * lock_module. Originally from lock_dlm
304  */
305
306 static 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
312 static 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
324 static 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
344 static 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
350 static 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
356 static 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
362 static 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
368 static 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
382 static 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
392 static 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
398 static 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
404 struct 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) \
411 static struct gdlm_attr gdlm_attr_##_name = __ATTR(_name,_mode,_show,_store)
412
413 GDLM_ATTR(proto_name,     0444, proto_name_show,     NULL);
414 GDLM_ATTR(block,          0644, block_show,          block_store);
415 GDLM_ATTR(withdraw,       0644, withdraw_show,       withdraw_store);
416 GDLM_ATTR(id,             0444, lkid_show,           NULL);
417 GDLM_ATTR(first,          0444, lkfirst_show,        NULL);
418 GDLM_ATTR(first_done,     0444, first_done_show,     NULL);
419 GDLM_ATTR(recover,        0644, recover_show,        recover_store);
420 GDLM_ATTR(recover_done,   0444, recover_done_show,   NULL);
421 GDLM_ATTR(recover_status, 0444, recover_status_show, NULL);
422
423 static 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,
434         NULL,
435 };
436
437 /*
438  * display struct gfs2_args fields
439  */
440
441 struct args_attr {
442         struct attribute attr;
443         ssize_t (*show)(struct gfs2_sbd *, char *);
444 };
445
446 #define ARGS_ATTR(name, fmt)                                                \
447 static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf)                 \
448 {                                                                           \
449         return snprintf(buf, PAGE_SIZE, fmt, sdp->sd_args.ar_##name);       \
450 }                                                                           \
451 static struct args_attr args_attr_##name = __ATTR_RO(name)
452
453 ARGS_ATTR(lockproto,       "%s\n");
454 ARGS_ATTR(locktable,       "%s\n");
455 ARGS_ATTR(hostdata,        "%s\n");
456 ARGS_ATTR(spectator,       "%d\n");
457 ARGS_ATTR(ignore_local_fs, "%d\n");
458 ARGS_ATTR(localcaching,    "%d\n");
459 ARGS_ATTR(localflocks,     "%d\n");
460 ARGS_ATTR(debug,           "%d\n");
461 ARGS_ATTR(upgrade,         "%d\n");
462 ARGS_ATTR(posix_acl,       "%d\n");
463 ARGS_ATTR(quota,           "%u\n");
464 ARGS_ATTR(suiddir,         "%d\n");
465 ARGS_ATTR(data,            "%d\n");
466
467 static 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,
477         &args_attr_posix_acl.attr,
478         &args_attr_quota.attr,
479         &args_attr_suiddir.attr,
480         &args_attr_data.attr,
481         NULL,
482 };
483
484 /*
485  * get and set struct gfs2_tune fields
486  */
487
488 static ssize_t quota_scale_show(struct gfs2_sbd *sdp, char *buf)
489 {
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);
493 }
494
495 static 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
514 static 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
534 struct 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)                                        \
541 static struct tune_attr tune_attr_##name = __ATTR(name, 0644, show, store)
542
543 #define TUNE_ATTR_2(name, store)                                              \
544 static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf)                   \
545 {                                                                             \
546         return snprintf(buf, PAGE_SIZE, "%u\n", sdp->sd_tune.gt_##name);      \
547 }                                                                             \
548 TUNE_ATTR_3(name, name##_show, store)
549
550 #define TUNE_ATTR(name, check_zero)                                           \
551 static 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 }                                                                             \
555 TUNE_ATTR_2(name, name##_store)
556
557 #define TUNE_ATTR_DAEMON(name, process)                                       \
558 static 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 }                                                                             \
564 TUNE_ATTR_2(name, name##_store)
565
566 TUNE_ATTR(incore_log_blocks, 0);
567 TUNE_ATTR(log_flush_secs, 0);
568 TUNE_ATTR(quota_warn_period, 0);
569 TUNE_ATTR(quota_quantum, 0);
570 TUNE_ATTR(max_readahead, 0);
571 TUNE_ATTR(complain_secs, 0);
572 TUNE_ATTR(statfs_slow, 0);
573 TUNE_ATTR(new_files_jdata, 0);
574 TUNE_ATTR(quota_simul_sync, 1);
575 TUNE_ATTR(stall_secs, 1);
576 TUNE_ATTR(statfs_quantum, 1);
577 TUNE_ATTR_DAEMON(recoverd_secs, recoverd_process);
578 TUNE_ATTR_DAEMON(logd_secs, logd_process);
579 TUNE_ATTR_3(quota_scale, quota_scale_show, quota_scale_store);
580
581 static struct attribute *tune_attrs[] = {
582         &tune_attr_incore_log_blocks.attr,
583         &tune_attr_log_flush_secs.attr,
584         &tune_attr_quota_warn_period.attr,
585         &tune_attr_quota_quantum.attr,
586         &tune_attr_max_readahead.attr,
587         &tune_attr_complain_secs.attr,
588         &tune_attr_statfs_slow.attr,
589         &tune_attr_quota_simul_sync.attr,
590         &tune_attr_stall_secs.attr,
591         &tune_attr_statfs_quantum.attr,
592         &tune_attr_recoverd_secs.attr,
593         &tune_attr_logd_secs.attr,
594         &tune_attr_quota_scale.attr,
595         &tune_attr_new_files_jdata.attr,
596         NULL,
597 };
598
599 static struct attribute_group lockstruct_group = {
600         .name = "lockstruct",
601         .attrs = lockstruct_attrs,
602 };
603
604 static struct attribute_group args_group = {
605         .name = "args",
606         .attrs = args_attrs,
607 };
608
609 static struct attribute_group tune_group = {
610         .name = "tune",
611         .attrs = tune_attrs,
612 };
613
614 static struct attribute_group lock_module_group = {
615         .name = "lock_module",
616         .attrs = lock_module_attrs,
617 };
618
619 int gfs2_sys_fs_add(struct gfs2_sbd *sdp)
620 {
621         int error;
622
623         sdp->sd_kobj.kset = gfs2_kset;
624         error = kobject_init_and_add(&sdp->sd_kobj, &gfs2_ktype, NULL,
625                                      "%s", sdp->sd_table_name);
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
633         error = sysfs_create_group(&sdp->sd_kobj, &args_group);
634         if (error)
635                 goto fail_lockstruct;
636
637         error = sysfs_create_group(&sdp->sd_kobj, &tune_group);
638         if (error)
639                 goto fail_args;
640
641         error = sysfs_create_group(&sdp->sd_kobj, &lock_module_group);
642         if (error)
643                 goto fail_tune;
644
645         kobject_uevent(&sdp->sd_kobj, KOBJ_ADD);
646         return 0;
647
648 fail_tune:
649         sysfs_remove_group(&sdp->sd_kobj, &tune_group);
650 fail_args:
651         sysfs_remove_group(&sdp->sd_kobj, &args_group);
652 fail_lockstruct:
653         sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group);
654 fail_reg:
655         kobject_put(&sdp->sd_kobj);
656 fail:
657         fs_err(sdp, "error %d adding sysfs files", error);
658         return error;
659 }
660
661 void 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);
665         sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group);
666         sysfs_remove_group(&sdp->sd_kobj, &lock_module_group);
667         kobject_put(&sdp->sd_kobj);
668 }
669
670
671 static 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);
675         const u8 *uuid = sdp->sd_sb.sb_uuid;
676
677         add_uevent_var(env, "LOCKTABLE=%s", sdp->sd_table_name);
678         add_uevent_var(env, "LOCKPROTO=%s", sdp->sd_proto_name);
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         }
687         return 0;
688 }
689
690 static struct kset_uevent_ops gfs2_uevent_ops = {
691         .uevent = gfs2_uevent,
692 };
693
694
695 int gfs2_sys_init(void)
696 {
697         gfs2_kset = kset_create_and_add("gfs2", &gfs2_uevent_ops, fs_kobj);
698         if (!gfs2_kset)
699                 return -ENOMEM;
700         return 0;
701 }
702
703 void gfs2_sys_uninit(void)
704 {
705         kset_unregister(gfs2_kset);
706 }
707