diff options
Diffstat (limited to 'fs/gfs2/sys.c')
-rw-r--r-- | fs/gfs2/sys.c | 583 |
1 files changed, 583 insertions, 0 deletions
diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c new file mode 100644 index 000000000000..0e0ec988f731 --- /dev/null +++ b/fs/gfs2/sys.c | |||
@@ -0,0 +1,583 @@ | |||
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 <linux/gfs2_ondisk.h> | ||
18 | #include <linux/lm_interface.h> | ||
19 | #include <asm/uaccess.h> | ||
20 | |||
21 | #include "gfs2.h" | ||
22 | #include "incore.h" | ||
23 | #include "lm.h" | ||
24 | #include "sys.h" | ||
25 | #include "super.h" | ||
26 | #include "glock.h" | ||
27 | #include "quota.h" | ||
28 | #include "util.h" | ||
29 | |||
30 | char *gfs2_sys_margs; | ||
31 | spinlock_t gfs2_sys_margs_lock; | ||
32 | |||
33 | static ssize_t id_show(struct gfs2_sbd *sdp, char *buf) | ||
34 | { | ||
35 | return snprintf(buf, PAGE_SIZE, "%s\n", sdp->sd_vfs->s_id); | ||
36 | } | ||
37 | |||
38 | static ssize_t fsname_show(struct gfs2_sbd *sdp, char *buf) | ||
39 | { | ||
40 | return snprintf(buf, PAGE_SIZE, "%s\n", sdp->sd_fsname); | ||
41 | } | ||
42 | |||
43 | static ssize_t freeze_show(struct gfs2_sbd *sdp, char *buf) | ||
44 | { | ||
45 | unsigned int count; | ||
46 | |||
47 | mutex_lock(&sdp->sd_freeze_lock); | ||
48 | count = sdp->sd_freeze_count; | ||
49 | mutex_unlock(&sdp->sd_freeze_lock); | ||
50 | |||
51 | return snprintf(buf, PAGE_SIZE, "%u\n", count); | ||
52 | } | ||
53 | |||
54 | static ssize_t freeze_store(struct gfs2_sbd *sdp, const char *buf, size_t len) | ||
55 | { | ||
56 | ssize_t ret = len; | ||
57 | int error = 0; | ||
58 | int n = simple_strtol(buf, NULL, 0); | ||
59 | |||
60 | if (!capable(CAP_SYS_ADMIN)) | ||
61 | return -EACCES; | ||
62 | |||
63 | switch (n) { | ||
64 | case 0: | ||
65 | gfs2_unfreeze_fs(sdp); | ||
66 | break; | ||
67 | case 1: | ||
68 | error = gfs2_freeze_fs(sdp); | ||
69 | break; | ||
70 | default: | ||
71 | ret = -EINVAL; | ||
72 | } | ||
73 | |||
74 | if (error) | ||
75 | fs_warn(sdp, "freeze %d error %d", n, error); | ||
76 | |||
77 | return ret; | ||
78 | } | ||
79 | |||
80 | static ssize_t withdraw_show(struct gfs2_sbd *sdp, char *buf) | ||
81 | { | ||
82 | unsigned int b = test_bit(SDF_SHUTDOWN, &sdp->sd_flags); | ||
83 | return snprintf(buf, PAGE_SIZE, "%u\n", b); | ||
84 | } | ||
85 | |||
86 | static ssize_t withdraw_store(struct gfs2_sbd *sdp, const char *buf, size_t len) | ||
87 | { | ||
88 | if (!capable(CAP_SYS_ADMIN)) | ||
89 | return -EACCES; | ||
90 | |||
91 | if (simple_strtol(buf, NULL, 0) != 1) | ||
92 | return -EINVAL; | ||
93 | |||
94 | gfs2_lm_withdraw(sdp, | ||
95 | "GFS2: fsid=%s: withdrawing from cluster at user's request\n", | ||
96 | sdp->sd_fsname); | ||
97 | return len; | ||
98 | } | ||
99 | |||
100 | static ssize_t statfs_sync_store(struct gfs2_sbd *sdp, const char *buf, | ||
101 | size_t len) | ||
102 | { | ||
103 | if (!capable(CAP_SYS_ADMIN)) | ||
104 | return -EACCES; | ||
105 | |||
106 | if (simple_strtol(buf, NULL, 0) != 1) | ||
107 | return -EINVAL; | ||
108 | |||
109 | gfs2_statfs_sync(sdp); | ||
110 | return len; | ||
111 | } | ||
112 | |||
113 | static ssize_t shrink_store(struct gfs2_sbd *sdp, const char *buf, size_t len) | ||
114 | { | ||
115 | if (!capable(CAP_SYS_ADMIN)) | ||
116 | return -EACCES; | ||
117 | |||
118 | if (simple_strtol(buf, NULL, 0) != 1) | ||
119 | return -EINVAL; | ||
120 | |||
121 | gfs2_gl_hash_clear(sdp, NO_WAIT); | ||
122 | return len; | ||
123 | } | ||
124 | |||
125 | static ssize_t quota_sync_store(struct gfs2_sbd *sdp, const char *buf, | ||
126 | size_t len) | ||
127 | { | ||
128 | if (!capable(CAP_SYS_ADMIN)) | ||
129 | return -EACCES; | ||
130 | |||
131 | if (simple_strtol(buf, NULL, 0) != 1) | ||
132 | return -EINVAL; | ||
133 | |||
134 | gfs2_quota_sync(sdp); | ||
135 | return len; | ||
136 | } | ||
137 | |||
138 | static ssize_t quota_refresh_user_store(struct gfs2_sbd *sdp, const char *buf, | ||
139 | size_t len) | ||
140 | { | ||
141 | u32 id; | ||
142 | |||
143 | if (!capable(CAP_SYS_ADMIN)) | ||
144 | return -EACCES; | ||
145 | |||
146 | id = simple_strtoul(buf, NULL, 0); | ||
147 | |||
148 | gfs2_quota_refresh(sdp, 1, id); | ||
149 | return len; | ||
150 | } | ||
151 | |||
152 | static ssize_t quota_refresh_group_store(struct gfs2_sbd *sdp, const char *buf, | ||
153 | size_t len) | ||
154 | { | ||
155 | u32 id; | ||
156 | |||
157 | if (!capable(CAP_SYS_ADMIN)) | ||
158 | return -EACCES; | ||
159 | |||
160 | id = simple_strtoul(buf, NULL, 0); | ||
161 | |||
162 | gfs2_quota_refresh(sdp, 0, id); | ||
163 | return len; | ||
164 | } | ||
165 | |||
166 | struct gfs2_attr { | ||
167 | struct attribute attr; | ||
168 | ssize_t (*show)(struct gfs2_sbd *, char *); | ||
169 | ssize_t (*store)(struct gfs2_sbd *, const char *, size_t); | ||
170 | }; | ||
171 | |||
172 | #define GFS2_ATTR(name, mode, show, store) \ | ||
173 | static struct gfs2_attr gfs2_attr_##name = __ATTR(name, mode, show, store) | ||
174 | |||
175 | GFS2_ATTR(id, 0444, id_show, NULL); | ||
176 | GFS2_ATTR(fsname, 0444, fsname_show, NULL); | ||
177 | GFS2_ATTR(freeze, 0644, freeze_show, freeze_store); | ||
178 | GFS2_ATTR(shrink, 0200, NULL, shrink_store); | ||
179 | GFS2_ATTR(withdraw, 0644, withdraw_show, withdraw_store); | ||
180 | GFS2_ATTR(statfs_sync, 0200, NULL, statfs_sync_store); | ||
181 | GFS2_ATTR(quota_sync, 0200, NULL, quota_sync_store); | ||
182 | GFS2_ATTR(quota_refresh_user, 0200, NULL, quota_refresh_user_store); | ||
183 | GFS2_ATTR(quota_refresh_group, 0200, NULL, quota_refresh_group_store); | ||
184 | |||
185 | static struct attribute *gfs2_attrs[] = { | ||
186 | &gfs2_attr_id.attr, | ||
187 | &gfs2_attr_fsname.attr, | ||
188 | &gfs2_attr_freeze.attr, | ||
189 | &gfs2_attr_shrink.attr, | ||
190 | &gfs2_attr_withdraw.attr, | ||
191 | &gfs2_attr_statfs_sync.attr, | ||
192 | &gfs2_attr_quota_sync.attr, | ||
193 | &gfs2_attr_quota_refresh_user.attr, | ||
194 | &gfs2_attr_quota_refresh_group.attr, | ||
195 | NULL, | ||
196 | }; | ||
197 | |||
198 | static ssize_t gfs2_attr_show(struct kobject *kobj, struct attribute *attr, | ||
199 | char *buf) | ||
200 | { | ||
201 | struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj); | ||
202 | struct gfs2_attr *a = container_of(attr, struct gfs2_attr, attr); | ||
203 | return a->show ? a->show(sdp, buf) : 0; | ||
204 | } | ||
205 | |||
206 | static ssize_t gfs2_attr_store(struct kobject *kobj, struct attribute *attr, | ||
207 | const char *buf, size_t len) | ||
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->store ? a->store(sdp, buf, len) : len; | ||
212 | } | ||
213 | |||
214 | static struct sysfs_ops gfs2_attr_ops = { | ||
215 | .show = gfs2_attr_show, | ||
216 | .store = gfs2_attr_store, | ||
217 | }; | ||
218 | |||
219 | static struct kobj_type gfs2_ktype = { | ||
220 | .default_attrs = gfs2_attrs, | ||
221 | .sysfs_ops = &gfs2_attr_ops, | ||
222 | }; | ||
223 | |||
224 | static struct kset gfs2_kset = { | ||
225 | .subsys = &fs_subsys, | ||
226 | .kobj = {.name = "gfs2"}, | ||
227 | .ktype = &gfs2_ktype, | ||
228 | }; | ||
229 | |||
230 | /* | ||
231 | * display struct lm_lockstruct fields | ||
232 | */ | ||
233 | |||
234 | struct lockstruct_attr { | ||
235 | struct attribute attr; | ||
236 | ssize_t (*show)(struct gfs2_sbd *, char *); | ||
237 | }; | ||
238 | |||
239 | #define LOCKSTRUCT_ATTR(name, fmt) \ | ||
240 | static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \ | ||
241 | { \ | ||
242 | return snprintf(buf, PAGE_SIZE, fmt, sdp->sd_lockstruct.ls_##name); \ | ||
243 | } \ | ||
244 | static struct lockstruct_attr lockstruct_attr_##name = __ATTR_RO(name) | ||
245 | |||
246 | LOCKSTRUCT_ATTR(jid, "%u\n"); | ||
247 | LOCKSTRUCT_ATTR(first, "%u\n"); | ||
248 | LOCKSTRUCT_ATTR(lvb_size, "%u\n"); | ||
249 | LOCKSTRUCT_ATTR(flags, "%d\n"); | ||
250 | |||
251 | static struct attribute *lockstruct_attrs[] = { | ||
252 | &lockstruct_attr_jid.attr, | ||
253 | &lockstruct_attr_first.attr, | ||
254 | &lockstruct_attr_lvb_size.attr, | ||
255 | &lockstruct_attr_flags.attr, | ||
256 | NULL, | ||
257 | }; | ||
258 | |||
259 | /* | ||
260 | * display struct gfs2_args fields | ||
261 | */ | ||
262 | |||
263 | struct args_attr { | ||
264 | struct attribute attr; | ||
265 | ssize_t (*show)(struct gfs2_sbd *, char *); | ||
266 | }; | ||
267 | |||
268 | #define ARGS_ATTR(name, fmt) \ | ||
269 | static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \ | ||
270 | { \ | ||
271 | return snprintf(buf, PAGE_SIZE, fmt, sdp->sd_args.ar_##name); \ | ||
272 | } \ | ||
273 | static struct args_attr args_attr_##name = __ATTR_RO(name) | ||
274 | |||
275 | ARGS_ATTR(lockproto, "%s\n"); | ||
276 | ARGS_ATTR(locktable, "%s\n"); | ||
277 | ARGS_ATTR(hostdata, "%s\n"); | ||
278 | ARGS_ATTR(spectator, "%d\n"); | ||
279 | ARGS_ATTR(ignore_local_fs, "%d\n"); | ||
280 | ARGS_ATTR(localcaching, "%d\n"); | ||
281 | ARGS_ATTR(localflocks, "%d\n"); | ||
282 | ARGS_ATTR(debug, "%d\n"); | ||
283 | ARGS_ATTR(upgrade, "%d\n"); | ||
284 | ARGS_ATTR(num_glockd, "%u\n"); | ||
285 | ARGS_ATTR(posix_acl, "%d\n"); | ||
286 | ARGS_ATTR(quota, "%u\n"); | ||
287 | ARGS_ATTR(suiddir, "%d\n"); | ||
288 | ARGS_ATTR(data, "%d\n"); | ||
289 | |||
290 | /* one oddball doesn't fit the macro mold */ | ||
291 | static ssize_t noatime_show(struct gfs2_sbd *sdp, char *buf) | ||
292 | { | ||
293 | return snprintf(buf, PAGE_SIZE, "%d\n", | ||
294 | !!test_bit(SDF_NOATIME, &sdp->sd_flags)); | ||
295 | } | ||
296 | static struct args_attr args_attr_noatime = __ATTR_RO(noatime); | ||
297 | |||
298 | static struct attribute *args_attrs[] = { | ||
299 | &args_attr_lockproto.attr, | ||
300 | &args_attr_locktable.attr, | ||
301 | &args_attr_hostdata.attr, | ||
302 | &args_attr_spectator.attr, | ||
303 | &args_attr_ignore_local_fs.attr, | ||
304 | &args_attr_localcaching.attr, | ||
305 | &args_attr_localflocks.attr, | ||
306 | &args_attr_debug.attr, | ||
307 | &args_attr_upgrade.attr, | ||
308 | &args_attr_num_glockd.attr, | ||
309 | &args_attr_posix_acl.attr, | ||
310 | &args_attr_quota.attr, | ||
311 | &args_attr_suiddir.attr, | ||
312 | &args_attr_data.attr, | ||
313 | &args_attr_noatime.attr, | ||
314 | NULL, | ||
315 | }; | ||
316 | |||
317 | /* | ||
318 | * display counters from superblock | ||
319 | */ | ||
320 | |||
321 | struct counters_attr { | ||
322 | struct attribute attr; | ||
323 | ssize_t (*show)(struct gfs2_sbd *, char *); | ||
324 | }; | ||
325 | |||
326 | #define COUNTERS_ATTR(name, fmt) \ | ||
327 | static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \ | ||
328 | { \ | ||
329 | return snprintf(buf, PAGE_SIZE, fmt, \ | ||
330 | (unsigned int)atomic_read(&sdp->sd_##name)); \ | ||
331 | } \ | ||
332 | static struct counters_attr counters_attr_##name = __ATTR_RO(name) | ||
333 | |||
334 | COUNTERS_ATTR(glock_count, "%u\n"); | ||
335 | COUNTERS_ATTR(glock_held_count, "%u\n"); | ||
336 | COUNTERS_ATTR(inode_count, "%u\n"); | ||
337 | COUNTERS_ATTR(reclaimed, "%u\n"); | ||
338 | |||
339 | static struct attribute *counters_attrs[] = { | ||
340 | &counters_attr_glock_count.attr, | ||
341 | &counters_attr_glock_held_count.attr, | ||
342 | &counters_attr_inode_count.attr, | ||
343 | &counters_attr_reclaimed.attr, | ||
344 | NULL, | ||
345 | }; | ||
346 | |||
347 | /* | ||
348 | * get and set struct gfs2_tune fields | ||
349 | */ | ||
350 | |||
351 | static ssize_t quota_scale_show(struct gfs2_sbd *sdp, char *buf) | ||
352 | { | ||
353 | return snprintf(buf, PAGE_SIZE, "%u %u\n", | ||
354 | sdp->sd_tune.gt_quota_scale_num, | ||
355 | sdp->sd_tune.gt_quota_scale_den); | ||
356 | } | ||
357 | |||
358 | static ssize_t quota_scale_store(struct gfs2_sbd *sdp, const char *buf, | ||
359 | size_t len) | ||
360 | { | ||
361 | struct gfs2_tune *gt = &sdp->sd_tune; | ||
362 | unsigned int x, y; | ||
363 | |||
364 | if (!capable(CAP_SYS_ADMIN)) | ||
365 | return -EACCES; | ||
366 | |||
367 | if (sscanf(buf, "%u %u", &x, &y) != 2 || !y) | ||
368 | return -EINVAL; | ||
369 | |||
370 | spin_lock(>->gt_spin); | ||
371 | gt->gt_quota_scale_num = x; | ||
372 | gt->gt_quota_scale_den = y; | ||
373 | spin_unlock(>->gt_spin); | ||
374 | return len; | ||
375 | } | ||
376 | |||
377 | static ssize_t tune_set(struct gfs2_sbd *sdp, unsigned int *field, | ||
378 | int check_zero, const char *buf, size_t len) | ||
379 | { | ||
380 | struct gfs2_tune *gt = &sdp->sd_tune; | ||
381 | unsigned int x; | ||
382 | |||
383 | if (!capable(CAP_SYS_ADMIN)) | ||
384 | return -EACCES; | ||
385 | |||
386 | x = simple_strtoul(buf, NULL, 0); | ||
387 | |||
388 | if (check_zero && !x) | ||
389 | return -EINVAL; | ||
390 | |||
391 | spin_lock(>->gt_spin); | ||
392 | *field = x; | ||
393 | spin_unlock(>->gt_spin); | ||
394 | return len; | ||
395 | } | ||
396 | |||
397 | struct tune_attr { | ||
398 | struct attribute attr; | ||
399 | ssize_t (*show)(struct gfs2_sbd *, char *); | ||
400 | ssize_t (*store)(struct gfs2_sbd *, const char *, size_t); | ||
401 | }; | ||
402 | |||
403 | #define TUNE_ATTR_3(name, show, store) \ | ||
404 | static struct tune_attr tune_attr_##name = __ATTR(name, 0644, show, store) | ||
405 | |||
406 | #define TUNE_ATTR_2(name, store) \ | ||
407 | static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \ | ||
408 | { \ | ||
409 | return snprintf(buf, PAGE_SIZE, "%u\n", sdp->sd_tune.gt_##name); \ | ||
410 | } \ | ||
411 | TUNE_ATTR_3(name, name##_show, store) | ||
412 | |||
413 | #define TUNE_ATTR(name, check_zero) \ | ||
414 | static ssize_t name##_store(struct gfs2_sbd *sdp, const char *buf, size_t len)\ | ||
415 | { \ | ||
416 | return tune_set(sdp, &sdp->sd_tune.gt_##name, check_zero, buf, len); \ | ||
417 | } \ | ||
418 | TUNE_ATTR_2(name, name##_store) | ||
419 | |||
420 | #define TUNE_ATTR_DAEMON(name, process) \ | ||
421 | static ssize_t name##_store(struct gfs2_sbd *sdp, const char *buf, size_t len)\ | ||
422 | { \ | ||
423 | ssize_t r = tune_set(sdp, &sdp->sd_tune.gt_##name, 1, buf, len); \ | ||
424 | wake_up_process(sdp->sd_##process); \ | ||
425 | return r; \ | ||
426 | } \ | ||
427 | TUNE_ATTR_2(name, name##_store) | ||
428 | |||
429 | TUNE_ATTR(ilimit, 0); | ||
430 | TUNE_ATTR(ilimit_tries, 0); | ||
431 | TUNE_ATTR(ilimit_min, 0); | ||
432 | TUNE_ATTR(demote_secs, 0); | ||
433 | TUNE_ATTR(incore_log_blocks, 0); | ||
434 | TUNE_ATTR(log_flush_secs, 0); | ||
435 | TUNE_ATTR(jindex_refresh_secs, 0); | ||
436 | TUNE_ATTR(quota_warn_period, 0); | ||
437 | TUNE_ATTR(quota_quantum, 0); | ||
438 | TUNE_ATTR(atime_quantum, 0); | ||
439 | TUNE_ATTR(max_readahead, 0); | ||
440 | TUNE_ATTR(complain_secs, 0); | ||
441 | TUNE_ATTR(reclaim_limit, 0); | ||
442 | TUNE_ATTR(prefetch_secs, 0); | ||
443 | TUNE_ATTR(statfs_slow, 0); | ||
444 | TUNE_ATTR(new_files_jdata, 0); | ||
445 | TUNE_ATTR(new_files_directio, 0); | ||
446 | TUNE_ATTR(quota_simul_sync, 1); | ||
447 | TUNE_ATTR(quota_cache_secs, 1); | ||
448 | TUNE_ATTR(max_atomic_write, 1); | ||
449 | TUNE_ATTR(stall_secs, 1); | ||
450 | TUNE_ATTR(entries_per_readdir, 1); | ||
451 | TUNE_ATTR(greedy_default, 1); | ||
452 | TUNE_ATTR(greedy_quantum, 1); | ||
453 | TUNE_ATTR(greedy_max, 1); | ||
454 | TUNE_ATTR(statfs_quantum, 1); | ||
455 | TUNE_ATTR_DAEMON(scand_secs, scand_process); | ||
456 | TUNE_ATTR_DAEMON(recoverd_secs, recoverd_process); | ||
457 | TUNE_ATTR_DAEMON(logd_secs, logd_process); | ||
458 | TUNE_ATTR_DAEMON(quotad_secs, quotad_process); | ||
459 | TUNE_ATTR_3(quota_scale, quota_scale_show, quota_scale_store); | ||
460 | |||
461 | static struct attribute *tune_attrs[] = { | ||
462 | &tune_attr_ilimit.attr, | ||
463 | &tune_attr_ilimit_tries.attr, | ||
464 | &tune_attr_ilimit_min.attr, | ||
465 | &tune_attr_demote_secs.attr, | ||
466 | &tune_attr_incore_log_blocks.attr, | ||
467 | &tune_attr_log_flush_secs.attr, | ||
468 | &tune_attr_jindex_refresh_secs.attr, | ||
469 | &tune_attr_quota_warn_period.attr, | ||
470 | &tune_attr_quota_quantum.attr, | ||
471 | &tune_attr_atime_quantum.attr, | ||
472 | &tune_attr_max_readahead.attr, | ||
473 | &tune_attr_complain_secs.attr, | ||
474 | &tune_attr_reclaim_limit.attr, | ||
475 | &tune_attr_prefetch_secs.attr, | ||
476 | &tune_attr_statfs_slow.attr, | ||
477 | &tune_attr_quota_simul_sync.attr, | ||
478 | &tune_attr_quota_cache_secs.attr, | ||
479 | &tune_attr_max_atomic_write.attr, | ||
480 | &tune_attr_stall_secs.attr, | ||
481 | &tune_attr_entries_per_readdir.attr, | ||
482 | &tune_attr_greedy_default.attr, | ||
483 | &tune_attr_greedy_quantum.attr, | ||
484 | &tune_attr_greedy_max.attr, | ||
485 | &tune_attr_statfs_quantum.attr, | ||
486 | &tune_attr_scand_secs.attr, | ||
487 | &tune_attr_recoverd_secs.attr, | ||
488 | &tune_attr_logd_secs.attr, | ||
489 | &tune_attr_quotad_secs.attr, | ||
490 | &tune_attr_quota_scale.attr, | ||
491 | &tune_attr_new_files_jdata.attr, | ||
492 | &tune_attr_new_files_directio.attr, | ||
493 | NULL, | ||
494 | }; | ||
495 | |||
496 | static struct attribute_group lockstruct_group = { | ||
497 | .name = "lockstruct", | ||
498 | .attrs = lockstruct_attrs, | ||
499 | }; | ||
500 | |||
501 | static struct attribute_group counters_group = { | ||
502 | .name = "counters", | ||
503 | .attrs = counters_attrs, | ||
504 | }; | ||
505 | |||
506 | static struct attribute_group args_group = { | ||
507 | .name = "args", | ||
508 | .attrs = args_attrs, | ||
509 | }; | ||
510 | |||
511 | static struct attribute_group tune_group = { | ||
512 | .name = "tune", | ||
513 | .attrs = tune_attrs, | ||
514 | }; | ||
515 | |||
516 | int gfs2_sys_fs_add(struct gfs2_sbd *sdp) | ||
517 | { | ||
518 | int error; | ||
519 | |||
520 | sdp->sd_kobj.kset = &gfs2_kset; | ||
521 | sdp->sd_kobj.ktype = &gfs2_ktype; | ||
522 | |||
523 | error = kobject_set_name(&sdp->sd_kobj, "%s", sdp->sd_table_name); | ||
524 | if (error) | ||
525 | goto fail; | ||
526 | |||
527 | error = kobject_register(&sdp->sd_kobj); | ||
528 | if (error) | ||
529 | goto fail; | ||
530 | |||
531 | error = sysfs_create_group(&sdp->sd_kobj, &lockstruct_group); | ||
532 | if (error) | ||
533 | goto fail_reg; | ||
534 | |||
535 | error = sysfs_create_group(&sdp->sd_kobj, &counters_group); | ||
536 | if (error) | ||
537 | goto fail_lockstruct; | ||
538 | |||
539 | error = sysfs_create_group(&sdp->sd_kobj, &args_group); | ||
540 | if (error) | ||
541 | goto fail_counters; | ||
542 | |||
543 | error = sysfs_create_group(&sdp->sd_kobj, &tune_group); | ||
544 | if (error) | ||
545 | goto fail_args; | ||
546 | |||
547 | return 0; | ||
548 | |||
549 | fail_args: | ||
550 | sysfs_remove_group(&sdp->sd_kobj, &args_group); | ||
551 | fail_counters: | ||
552 | sysfs_remove_group(&sdp->sd_kobj, &counters_group); | ||
553 | fail_lockstruct: | ||
554 | sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group); | ||
555 | fail_reg: | ||
556 | kobject_unregister(&sdp->sd_kobj); | ||
557 | fail: | ||
558 | fs_err(sdp, "error %d adding sysfs files", error); | ||
559 | return error; | ||
560 | } | ||
561 | |||
562 | void gfs2_sys_fs_del(struct gfs2_sbd *sdp) | ||
563 | { | ||
564 | sysfs_remove_group(&sdp->sd_kobj, &tune_group); | ||
565 | sysfs_remove_group(&sdp->sd_kobj, &args_group); | ||
566 | sysfs_remove_group(&sdp->sd_kobj, &counters_group); | ||
567 | sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group); | ||
568 | kobject_unregister(&sdp->sd_kobj); | ||
569 | } | ||
570 | |||
571 | int gfs2_sys_init(void) | ||
572 | { | ||
573 | gfs2_sys_margs = NULL; | ||
574 | spin_lock_init(&gfs2_sys_margs_lock); | ||
575 | return kset_register(&gfs2_kset); | ||
576 | } | ||
577 | |||
578 | void gfs2_sys_uninit(void) | ||
579 | { | ||
580 | kfree(gfs2_sys_margs); | ||
581 | kset_unregister(&gfs2_kset); | ||
582 | } | ||
583 | |||