2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
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.
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>
31 spinlock_t gfs2_sys_margs_lock
;
33 static ssize_t
id_show(struct gfs2_sbd
*sdp
, char *buf
)
35 return snprintf(buf
, PAGE_SIZE
, "%u:%u\n",
36 MAJOR(sdp
->sd_vfs
->s_dev
), MINOR(sdp
->sd_vfs
->s_dev
));
39 static ssize_t
fsname_show(struct gfs2_sbd
*sdp
, char *buf
)
41 return snprintf(buf
, PAGE_SIZE
, "%s\n", sdp
->sd_fsname
);
44 static ssize_t
freeze_show(struct gfs2_sbd
*sdp
, char *buf
)
48 mutex_lock(&sdp
->sd_freeze_lock
);
49 count
= sdp
->sd_freeze_count
;
50 mutex_unlock(&sdp
->sd_freeze_lock
);
52 return snprintf(buf
, PAGE_SIZE
, "%u\n", count
);
55 static ssize_t
freeze_store(struct gfs2_sbd
*sdp
, const char *buf
, size_t len
)
59 int n
= simple_strtol(buf
, NULL
, 0);
61 if (!capable(CAP_SYS_ADMIN
))
66 gfs2_unfreeze_fs(sdp
);
69 error
= gfs2_freeze_fs(sdp
);
76 fs_warn(sdp
, "freeze %d error %d", n
, error
);
81 static ssize_t
withdraw_show(struct gfs2_sbd
*sdp
, char *buf
)
83 unsigned int b
= test_bit(SDF_SHUTDOWN
, &sdp
->sd_flags
);
84 return snprintf(buf
, PAGE_SIZE
, "%u\n", b
);
87 static ssize_t
withdraw_store(struct gfs2_sbd
*sdp
, const char *buf
, size_t len
)
89 if (!capable(CAP_SYS_ADMIN
))
92 if (simple_strtol(buf
, NULL
, 0) != 1)
96 "GFS2: fsid=%s: withdrawing from cluster at user's request\n",
101 static ssize_t
statfs_sync_store(struct gfs2_sbd
*sdp
, const char *buf
,
104 if (!capable(CAP_SYS_ADMIN
))
107 if (simple_strtol(buf
, NULL
, 0) != 1)
110 gfs2_statfs_sync(sdp
);
114 static ssize_t
shrink_store(struct gfs2_sbd
*sdp
, const char *buf
, size_t len
)
116 if (!capable(CAP_SYS_ADMIN
))
119 if (simple_strtol(buf
, NULL
, 0) != 1)
122 gfs2_gl_hash_clear(sdp
, NO_WAIT
);
126 static ssize_t
quota_sync_store(struct gfs2_sbd
*sdp
, const char *buf
,
129 if (!capable(CAP_SYS_ADMIN
))
132 if (simple_strtol(buf
, NULL
, 0) != 1)
135 gfs2_quota_sync(sdp
);
139 static ssize_t
quota_refresh_user_store(struct gfs2_sbd
*sdp
, const char *buf
,
144 if (!capable(CAP_SYS_ADMIN
))
147 id
= simple_strtoul(buf
, NULL
, 0);
149 gfs2_quota_refresh(sdp
, 1, id
);
153 static ssize_t
quota_refresh_group_store(struct gfs2_sbd
*sdp
, const char *buf
,
158 if (!capable(CAP_SYS_ADMIN
))
161 id
= simple_strtoul(buf
, NULL
, 0);
163 gfs2_quota_refresh(sdp
, 0, id
);
168 struct attribute attr
;
169 ssize_t (*show
)(struct gfs2_sbd
*, char *);
170 ssize_t (*store
)(struct gfs2_sbd
*, const char *, size_t);
173 #define GFS2_ATTR(name, mode, show, store) \
174 static struct gfs2_attr gfs2_attr_##name = __ATTR(name, mode, show, store)
176 GFS2_ATTR(id
, 0444, id_show
, NULL
);
177 GFS2_ATTR(fsname
, 0444, fsname_show
, NULL
);
178 GFS2_ATTR(freeze
, 0644, freeze_show
, freeze_store
);
179 GFS2_ATTR(shrink
, 0200, NULL
, shrink_store
);
180 GFS2_ATTR(withdraw
, 0644, withdraw_show
, withdraw_store
);
181 GFS2_ATTR(statfs_sync
, 0200, NULL
, statfs_sync_store
);
182 GFS2_ATTR(quota_sync
, 0200, NULL
, quota_sync_store
);
183 GFS2_ATTR(quota_refresh_user
, 0200, NULL
, quota_refresh_user_store
);
184 GFS2_ATTR(quota_refresh_group
, 0200, NULL
, quota_refresh_group_store
);
186 static struct attribute
*gfs2_attrs
[] = {
188 &gfs2_attr_fsname
.attr
,
189 &gfs2_attr_freeze
.attr
,
190 &gfs2_attr_shrink
.attr
,
191 &gfs2_attr_withdraw
.attr
,
192 &gfs2_attr_statfs_sync
.attr
,
193 &gfs2_attr_quota_sync
.attr
,
194 &gfs2_attr_quota_refresh_user
.attr
,
195 &gfs2_attr_quota_refresh_group
.attr
,
199 static ssize_t
gfs2_attr_show(struct kobject
*kobj
, struct attribute
*attr
,
202 struct gfs2_sbd
*sdp
= container_of(kobj
, struct gfs2_sbd
, sd_kobj
);
203 struct gfs2_attr
*a
= container_of(attr
, struct gfs2_attr
, attr
);
204 return a
->show
? a
->show(sdp
, buf
) : 0;
207 static ssize_t
gfs2_attr_store(struct kobject
*kobj
, struct attribute
*attr
,
208 const char *buf
, size_t len
)
210 struct gfs2_sbd
*sdp
= container_of(kobj
, struct gfs2_sbd
, sd_kobj
);
211 struct gfs2_attr
*a
= container_of(attr
, struct gfs2_attr
, attr
);
212 return a
->store
? a
->store(sdp
, buf
, len
) : len
;
215 static struct sysfs_ops gfs2_attr_ops
= {
216 .show
= gfs2_attr_show
,
217 .store
= gfs2_attr_store
,
220 static struct kobj_type gfs2_ktype
= {
221 .default_attrs
= gfs2_attrs
,
222 .sysfs_ops
= &gfs2_attr_ops
,
225 static struct kset gfs2_kset
= {
226 .ktype
= &gfs2_ktype
,
230 * display struct lm_lockstruct fields
233 struct lockstruct_attr
{
234 struct attribute attr
;
235 ssize_t (*show
)(struct gfs2_sbd
*, char *);
238 #define LOCKSTRUCT_ATTR(name, fmt) \
239 static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \
241 return snprintf(buf, PAGE_SIZE, fmt, sdp->sd_lockstruct.ls_##name); \
243 static struct lockstruct_attr lockstruct_attr_##name = __ATTR_RO(name)
245 LOCKSTRUCT_ATTR(jid
, "%u\n");
246 LOCKSTRUCT_ATTR(first
, "%u\n");
247 LOCKSTRUCT_ATTR(lvb_size
, "%u\n");
248 LOCKSTRUCT_ATTR(flags
, "%d\n");
250 static struct attribute
*lockstruct_attrs
[] = {
251 &lockstruct_attr_jid
.attr
,
252 &lockstruct_attr_first
.attr
,
253 &lockstruct_attr_lvb_size
.attr
,
254 &lockstruct_attr_flags
.attr
,
259 * display struct gfs2_args fields
263 struct attribute attr
;
264 ssize_t (*show
)(struct gfs2_sbd
*, char *);
267 #define ARGS_ATTR(name, fmt) \
268 static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \
270 return snprintf(buf, PAGE_SIZE, fmt, sdp->sd_args.ar_##name); \
272 static struct args_attr args_attr_##name = __ATTR_RO(name)
274 ARGS_ATTR(lockproto
, "%s\n");
275 ARGS_ATTR(locktable
, "%s\n");
276 ARGS_ATTR(hostdata
, "%s\n");
277 ARGS_ATTR(spectator
, "%d\n");
278 ARGS_ATTR(ignore_local_fs
, "%d\n");
279 ARGS_ATTR(localcaching
, "%d\n");
280 ARGS_ATTR(localflocks
, "%d\n");
281 ARGS_ATTR(debug
, "%d\n");
282 ARGS_ATTR(upgrade
, "%d\n");
283 ARGS_ATTR(num_glockd
, "%u\n");
284 ARGS_ATTR(posix_acl
, "%d\n");
285 ARGS_ATTR(quota
, "%u\n");
286 ARGS_ATTR(suiddir
, "%d\n");
287 ARGS_ATTR(data
, "%d\n");
289 /* one oddball doesn't fit the macro mold */
290 static ssize_t
noatime_show(struct gfs2_sbd
*sdp
, char *buf
)
292 return snprintf(buf
, PAGE_SIZE
, "%d\n",
293 !!test_bit(SDF_NOATIME
, &sdp
->sd_flags
));
295 static struct args_attr args_attr_noatime
= __ATTR_RO(noatime
);
297 static struct attribute
*args_attrs
[] = {
298 &args_attr_lockproto
.attr
,
299 &args_attr_locktable
.attr
,
300 &args_attr_hostdata
.attr
,
301 &args_attr_spectator
.attr
,
302 &args_attr_ignore_local_fs
.attr
,
303 &args_attr_localcaching
.attr
,
304 &args_attr_localflocks
.attr
,
305 &args_attr_debug
.attr
,
306 &args_attr_upgrade
.attr
,
307 &args_attr_num_glockd
.attr
,
308 &args_attr_posix_acl
.attr
,
309 &args_attr_quota
.attr
,
310 &args_attr_suiddir
.attr
,
311 &args_attr_data
.attr
,
312 &args_attr_noatime
.attr
,
317 * display counters from superblock
320 struct counters_attr
{
321 struct attribute attr
;
322 ssize_t (*show
)(struct gfs2_sbd
*, char *);
325 #define COUNTERS_ATTR(name, fmt) \
326 static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \
328 return snprintf(buf, PAGE_SIZE, fmt, \
329 (unsigned int)atomic_read(&sdp->sd_##name)); \
331 static struct counters_attr counters_attr_##name = __ATTR_RO(name)
333 COUNTERS_ATTR(glock_count
, "%u\n");
334 COUNTERS_ATTR(glock_held_count
, "%u\n");
335 COUNTERS_ATTR(inode_count
, "%u\n");
336 COUNTERS_ATTR(reclaimed
, "%u\n");
338 static struct attribute
*counters_attrs
[] = {
339 &counters_attr_glock_count
.attr
,
340 &counters_attr_glock_held_count
.attr
,
341 &counters_attr_inode_count
.attr
,
342 &counters_attr_reclaimed
.attr
,
347 * get and set struct gfs2_tune fields
350 static ssize_t
quota_scale_show(struct gfs2_sbd
*sdp
, char *buf
)
352 return snprintf(buf
, PAGE_SIZE
, "%u %u\n",
353 sdp
->sd_tune
.gt_quota_scale_num
,
354 sdp
->sd_tune
.gt_quota_scale_den
);
357 static ssize_t
quota_scale_store(struct gfs2_sbd
*sdp
, const char *buf
,
360 struct gfs2_tune
*gt
= &sdp
->sd_tune
;
363 if (!capable(CAP_SYS_ADMIN
))
366 if (sscanf(buf
, "%u %u", &x
, &y
) != 2 || !y
)
369 spin_lock(>
->gt_spin
);
370 gt
->gt_quota_scale_num
= x
;
371 gt
->gt_quota_scale_den
= y
;
372 spin_unlock(>
->gt_spin
);
376 static ssize_t
tune_set(struct gfs2_sbd
*sdp
, unsigned int *field
,
377 int check_zero
, const char *buf
, size_t len
)
379 struct gfs2_tune
*gt
= &sdp
->sd_tune
;
382 if (!capable(CAP_SYS_ADMIN
))
385 x
= simple_strtoul(buf
, NULL
, 0);
387 if (check_zero
&& !x
)
390 spin_lock(>
->gt_spin
);
392 spin_unlock(>
->gt_spin
);
397 struct attribute attr
;
398 ssize_t (*show
)(struct gfs2_sbd
*, char *);
399 ssize_t (*store
)(struct gfs2_sbd
*, const char *, size_t);
402 #define TUNE_ATTR_3(name, show, store) \
403 static struct tune_attr tune_attr_##name = __ATTR(name, 0644, show, store)
405 #define TUNE_ATTR_2(name, store) \
406 static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \
408 return snprintf(buf, PAGE_SIZE, "%u\n", sdp->sd_tune.gt_##name); \
410 TUNE_ATTR_3(name, name##_show, store)
412 #define TUNE_ATTR(name, check_zero) \
413 static ssize_t name##_store(struct gfs2_sbd *sdp, const char *buf, size_t len)\
415 return tune_set(sdp, &sdp->sd_tune.gt_##name, check_zero, buf, len); \
417 TUNE_ATTR_2(name, name##_store)
419 #define TUNE_ATTR_DAEMON(name, process) \
420 static ssize_t name##_store(struct gfs2_sbd *sdp, const char *buf, size_t len)\
422 ssize_t r = tune_set(sdp, &sdp->sd_tune.gt_##name, 1, buf, len); \
423 wake_up_process(sdp->sd_##process); \
426 TUNE_ATTR_2(name, name##_store)
428 TUNE_ATTR(demote_secs
, 0);
429 TUNE_ATTR(incore_log_blocks
, 0);
430 TUNE_ATTR(log_flush_secs
, 0);
431 TUNE_ATTR(jindex_refresh_secs
, 0);
432 TUNE_ATTR(quota_warn_period
, 0);
433 TUNE_ATTR(quota_quantum
, 0);
434 TUNE_ATTR(atime_quantum
, 0);
435 TUNE_ATTR(max_readahead
, 0);
436 TUNE_ATTR(complain_secs
, 0);
437 TUNE_ATTR(statfs_slow
, 0);
438 TUNE_ATTR(new_files_jdata
, 0);
439 TUNE_ATTR(new_files_directio
, 0);
440 TUNE_ATTR(quota_simul_sync
, 1);
441 TUNE_ATTR(quota_cache_secs
, 1);
442 TUNE_ATTR(stall_secs
, 1);
443 TUNE_ATTR(statfs_quantum
, 1);
444 TUNE_ATTR_DAEMON(recoverd_secs
, recoverd_process
);
445 TUNE_ATTR_DAEMON(logd_secs
, logd_process
);
446 TUNE_ATTR_DAEMON(quotad_secs
, quotad_process
);
447 TUNE_ATTR_3(quota_scale
, quota_scale_show
, quota_scale_store
);
449 static struct attribute
*tune_attrs
[] = {
450 &tune_attr_demote_secs
.attr
,
451 &tune_attr_incore_log_blocks
.attr
,
452 &tune_attr_log_flush_secs
.attr
,
453 &tune_attr_jindex_refresh_secs
.attr
,
454 &tune_attr_quota_warn_period
.attr
,
455 &tune_attr_quota_quantum
.attr
,
456 &tune_attr_atime_quantum
.attr
,
457 &tune_attr_max_readahead
.attr
,
458 &tune_attr_complain_secs
.attr
,
459 &tune_attr_statfs_slow
.attr
,
460 &tune_attr_quota_simul_sync
.attr
,
461 &tune_attr_quota_cache_secs
.attr
,
462 &tune_attr_stall_secs
.attr
,
463 &tune_attr_statfs_quantum
.attr
,
464 &tune_attr_recoverd_secs
.attr
,
465 &tune_attr_logd_secs
.attr
,
466 &tune_attr_quotad_secs
.attr
,
467 &tune_attr_quota_scale
.attr
,
468 &tune_attr_new_files_jdata
.attr
,
469 &tune_attr_new_files_directio
.attr
,
473 static struct attribute_group lockstruct_group
= {
474 .name
= "lockstruct",
475 .attrs
= lockstruct_attrs
,
478 static struct attribute_group counters_group
= {
480 .attrs
= counters_attrs
,
483 static struct attribute_group args_group
= {
488 static struct attribute_group tune_group
= {
493 int gfs2_sys_fs_add(struct gfs2_sbd
*sdp
)
497 sdp
->sd_kobj
.kset
= &gfs2_kset
;
498 sdp
->sd_kobj
.ktype
= &gfs2_ktype
;
500 error
= kobject_set_name(&sdp
->sd_kobj
, "%s", sdp
->sd_table_name
);
504 error
= kobject_register(&sdp
->sd_kobj
);
508 error
= sysfs_create_group(&sdp
->sd_kobj
, &lockstruct_group
);
512 error
= sysfs_create_group(&sdp
->sd_kobj
, &counters_group
);
514 goto fail_lockstruct
;
516 error
= sysfs_create_group(&sdp
->sd_kobj
, &args_group
);
520 error
= sysfs_create_group(&sdp
->sd_kobj
, &tune_group
);
527 sysfs_remove_group(&sdp
->sd_kobj
, &args_group
);
529 sysfs_remove_group(&sdp
->sd_kobj
, &counters_group
);
531 sysfs_remove_group(&sdp
->sd_kobj
, &lockstruct_group
);
533 kobject_unregister(&sdp
->sd_kobj
);
535 fs_err(sdp
, "error %d adding sysfs files", error
);
539 void gfs2_sys_fs_del(struct gfs2_sbd
*sdp
)
541 sysfs_remove_group(&sdp
->sd_kobj
, &tune_group
);
542 sysfs_remove_group(&sdp
->sd_kobj
, &args_group
);
543 sysfs_remove_group(&sdp
->sd_kobj
, &counters_group
);
544 sysfs_remove_group(&sdp
->sd_kobj
, &lockstruct_group
);
545 kobject_unregister(&sdp
->sd_kobj
);
548 int gfs2_sys_init(void)
550 gfs2_sys_margs
= NULL
;
551 spin_lock_init(&gfs2_sys_margs_lock
);
552 kobject_set_name(&gfs2_kset
.kobj
, "gfs2");
553 kobj_set_kset_s(&gfs2_kset
, fs_subsys
);
554 return kset_register(&gfs2_kset
);
557 void gfs2_sys_uninit(void)
559 kfree(gfs2_sys_margs
);
560 kset_unregister(&gfs2_kset
);