David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
Steven Whitehouse | 3a8a9a1 | 2006-05-18 15:09:15 -0400 | [diff] [blame] | 3 | * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 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 |
Steven Whitehouse | e9fc2aa | 2006-09-01 11:05:15 -0400 | [diff] [blame] | 7 | * of the GNU General Public License version 2. |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 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> |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 17 | #include <linux/gfs2_ondisk.h> |
Fabio Massimo Di Nitto | 7d30859 | 2006-09-19 07:56:29 +0200 | [diff] [blame] | 18 | #include <linux/lm_interface.h> |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 19 | #include <asm/uaccess.h> |
| 20 | |
| 21 | #include "gfs2.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 22 | #include "incore.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 23 | #include "lm.h" |
| 24 | #include "sys.h" |
| 25 | #include "super.h" |
| 26 | #include "glock.h" |
| 27 | #include "quota.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 28 | #include "util.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 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 | { |
Bob Peterson | c7227e46 | 2007-11-02 09:37:15 -0500 | [diff] [blame] | 35 | return snprintf(buf, PAGE_SIZE, "%u:%u\n", |
| 36 | MAJOR(sdp->sd_vfs->s_dev), MINOR(sdp->sd_vfs->s_dev)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | static ssize_t fsname_show(struct gfs2_sbd *sdp, char *buf) |
| 40 | { |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 41 | return snprintf(buf, PAGE_SIZE, "%s\n", sdp->sd_fsname); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | static ssize_t freeze_show(struct gfs2_sbd *sdp, char *buf) |
| 45 | { |
| 46 | unsigned int count; |
| 47 | |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 48 | mutex_lock(&sdp->sd_freeze_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 49 | count = sdp->sd_freeze_count; |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 50 | mutex_unlock(&sdp->sd_freeze_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 51 | |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 52 | return snprintf(buf, PAGE_SIZE, "%u\n", count); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | static ssize_t freeze_store(struct gfs2_sbd *sdp, const char *buf, size_t len) |
| 56 | { |
| 57 | ssize_t ret = len; |
| 58 | int error = 0; |
| 59 | int n = simple_strtol(buf, NULL, 0); |
| 60 | |
| 61 | if (!capable(CAP_SYS_ADMIN)) |
| 62 | return -EACCES; |
| 63 | |
| 64 | switch (n) { |
| 65 | case 0: |
| 66 | gfs2_unfreeze_fs(sdp); |
| 67 | break; |
| 68 | case 1: |
| 69 | error = gfs2_freeze_fs(sdp); |
| 70 | break; |
| 71 | default: |
| 72 | ret = -EINVAL; |
| 73 | } |
| 74 | |
| 75 | if (error) |
| 76 | fs_warn(sdp, "freeze %d error %d", n, error); |
| 77 | |
| 78 | return ret; |
| 79 | } |
| 80 | |
| 81 | static ssize_t withdraw_show(struct gfs2_sbd *sdp, char *buf) |
| 82 | { |
| 83 | unsigned int b = test_bit(SDF_SHUTDOWN, &sdp->sd_flags); |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 84 | return snprintf(buf, PAGE_SIZE, "%u\n", b); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | static ssize_t withdraw_store(struct gfs2_sbd *sdp, const char *buf, size_t len) |
| 88 | { |
| 89 | if (!capable(CAP_SYS_ADMIN)) |
| 90 | return -EACCES; |
| 91 | |
| 92 | if (simple_strtol(buf, NULL, 0) != 1) |
| 93 | return -EINVAL; |
| 94 | |
| 95 | gfs2_lm_withdraw(sdp, |
| 96 | "GFS2: fsid=%s: withdrawing from cluster at user's request\n", |
| 97 | sdp->sd_fsname); |
| 98 | return len; |
| 99 | } |
| 100 | |
| 101 | static ssize_t statfs_sync_store(struct gfs2_sbd *sdp, const char *buf, |
| 102 | size_t len) |
| 103 | { |
| 104 | if (!capable(CAP_SYS_ADMIN)) |
| 105 | return -EACCES; |
| 106 | |
| 107 | if (simple_strtol(buf, NULL, 0) != 1) |
| 108 | return -EINVAL; |
| 109 | |
| 110 | gfs2_statfs_sync(sdp); |
| 111 | return len; |
| 112 | } |
| 113 | |
| 114 | static ssize_t shrink_store(struct gfs2_sbd *sdp, const char *buf, size_t len) |
| 115 | { |
| 116 | if (!capable(CAP_SYS_ADMIN)) |
| 117 | return -EACCES; |
| 118 | |
| 119 | if (simple_strtol(buf, NULL, 0) != 1) |
| 120 | return -EINVAL; |
| 121 | |
| 122 | gfs2_gl_hash_clear(sdp, NO_WAIT); |
| 123 | return len; |
| 124 | } |
| 125 | |
| 126 | static ssize_t quota_sync_store(struct gfs2_sbd *sdp, const char *buf, |
| 127 | size_t len) |
| 128 | { |
| 129 | if (!capable(CAP_SYS_ADMIN)) |
| 130 | return -EACCES; |
| 131 | |
| 132 | if (simple_strtol(buf, NULL, 0) != 1) |
| 133 | return -EINVAL; |
| 134 | |
| 135 | gfs2_quota_sync(sdp); |
| 136 | return len; |
| 137 | } |
| 138 | |
| 139 | static ssize_t quota_refresh_user_store(struct gfs2_sbd *sdp, const char *buf, |
| 140 | size_t len) |
| 141 | { |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 142 | u32 id; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 143 | |
| 144 | if (!capable(CAP_SYS_ADMIN)) |
| 145 | return -EACCES; |
| 146 | |
| 147 | id = simple_strtoul(buf, NULL, 0); |
| 148 | |
| 149 | gfs2_quota_refresh(sdp, 1, id); |
| 150 | return len; |
| 151 | } |
| 152 | |
| 153 | static ssize_t quota_refresh_group_store(struct gfs2_sbd *sdp, const char *buf, |
| 154 | size_t len) |
| 155 | { |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 156 | u32 id; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 157 | |
| 158 | if (!capable(CAP_SYS_ADMIN)) |
| 159 | return -EACCES; |
| 160 | |
| 161 | id = simple_strtoul(buf, NULL, 0); |
| 162 | |
| 163 | gfs2_quota_refresh(sdp, 0, id); |
| 164 | return len; |
| 165 | } |
| 166 | |
| 167 | struct gfs2_attr { |
| 168 | struct attribute attr; |
| 169 | ssize_t (*show)(struct gfs2_sbd *, char *); |
| 170 | ssize_t (*store)(struct gfs2_sbd *, const char *, size_t); |
| 171 | }; |
| 172 | |
| 173 | #define GFS2_ATTR(name, mode, show, store) \ |
| 174 | static struct gfs2_attr gfs2_attr_##name = __ATTR(name, mode, show, store) |
| 175 | |
| 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); |
| 185 | |
| 186 | static struct attribute *gfs2_attrs[] = { |
| 187 | &gfs2_attr_id.attr, |
| 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, |
| 196 | NULL, |
| 197 | }; |
| 198 | |
| 199 | static ssize_t gfs2_attr_show(struct kobject *kobj, struct attribute *attr, |
| 200 | char *buf) |
| 201 | { |
| 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; |
| 205 | } |
| 206 | |
| 207 | static ssize_t gfs2_attr_store(struct kobject *kobj, struct attribute *attr, |
| 208 | const char *buf, size_t len) |
| 209 | { |
| 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; |
| 213 | } |
| 214 | |
| 215 | static struct sysfs_ops gfs2_attr_ops = { |
| 216 | .show = gfs2_attr_show, |
| 217 | .store = gfs2_attr_store, |
| 218 | }; |
| 219 | |
| 220 | static struct kobj_type gfs2_ktype = { |
| 221 | .default_attrs = gfs2_attrs, |
| 222 | .sysfs_ops = &gfs2_attr_ops, |
| 223 | }; |
| 224 | |
Greg Kroah-Hartman | 9bec101 | 2007-10-29 20:13:17 +0100 | [diff] [blame] | 225 | static struct kset *gfs2_kset; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 226 | |
| 227 | /* |
| 228 | * display struct lm_lockstruct fields |
| 229 | */ |
| 230 | |
| 231 | struct lockstruct_attr { |
| 232 | struct attribute attr; |
| 233 | ssize_t (*show)(struct gfs2_sbd *, char *); |
| 234 | }; |
| 235 | |
| 236 | #define LOCKSTRUCT_ATTR(name, fmt) \ |
| 237 | static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \ |
| 238 | { \ |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 239 | return snprintf(buf, PAGE_SIZE, fmt, sdp->sd_lockstruct.ls_##name); \ |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 240 | } \ |
| 241 | static struct lockstruct_attr lockstruct_attr_##name = __ATTR_RO(name) |
| 242 | |
| 243 | LOCKSTRUCT_ATTR(jid, "%u\n"); |
| 244 | LOCKSTRUCT_ATTR(first, "%u\n"); |
| 245 | LOCKSTRUCT_ATTR(lvb_size, "%u\n"); |
| 246 | LOCKSTRUCT_ATTR(flags, "%d\n"); |
| 247 | |
| 248 | static struct attribute *lockstruct_attrs[] = { |
| 249 | &lockstruct_attr_jid.attr, |
| 250 | &lockstruct_attr_first.attr, |
| 251 | &lockstruct_attr_lvb_size.attr, |
| 252 | &lockstruct_attr_flags.attr, |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 253 | NULL, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 254 | }; |
| 255 | |
| 256 | /* |
| 257 | * display struct gfs2_args fields |
| 258 | */ |
| 259 | |
| 260 | struct args_attr { |
| 261 | struct attribute attr; |
| 262 | ssize_t (*show)(struct gfs2_sbd *, char *); |
| 263 | }; |
| 264 | |
| 265 | #define ARGS_ATTR(name, fmt) \ |
| 266 | static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \ |
| 267 | { \ |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 268 | return snprintf(buf, PAGE_SIZE, fmt, sdp->sd_args.ar_##name); \ |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 269 | } \ |
| 270 | static struct args_attr args_attr_##name = __ATTR_RO(name) |
| 271 | |
| 272 | ARGS_ATTR(lockproto, "%s\n"); |
| 273 | ARGS_ATTR(locktable, "%s\n"); |
| 274 | ARGS_ATTR(hostdata, "%s\n"); |
| 275 | ARGS_ATTR(spectator, "%d\n"); |
| 276 | ARGS_ATTR(ignore_local_fs, "%d\n"); |
| 277 | ARGS_ATTR(localcaching, "%d\n"); |
| 278 | ARGS_ATTR(localflocks, "%d\n"); |
| 279 | ARGS_ATTR(debug, "%d\n"); |
| 280 | ARGS_ATTR(upgrade, "%d\n"); |
| 281 | ARGS_ATTR(num_glockd, "%u\n"); |
| 282 | ARGS_ATTR(posix_acl, "%d\n"); |
| 283 | ARGS_ATTR(quota, "%u\n"); |
| 284 | ARGS_ATTR(suiddir, "%d\n"); |
| 285 | ARGS_ATTR(data, "%d\n"); |
| 286 | |
| 287 | /* one oddball doesn't fit the macro mold */ |
| 288 | static ssize_t noatime_show(struct gfs2_sbd *sdp, char *buf) |
| 289 | { |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 290 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 291 | !!test_bit(SDF_NOATIME, &sdp->sd_flags)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 292 | } |
| 293 | static struct args_attr args_attr_noatime = __ATTR_RO(noatime); |
| 294 | |
| 295 | static struct attribute *args_attrs[] = { |
| 296 | &args_attr_lockproto.attr, |
| 297 | &args_attr_locktable.attr, |
| 298 | &args_attr_hostdata.attr, |
| 299 | &args_attr_spectator.attr, |
| 300 | &args_attr_ignore_local_fs.attr, |
| 301 | &args_attr_localcaching.attr, |
| 302 | &args_attr_localflocks.attr, |
| 303 | &args_attr_debug.attr, |
| 304 | &args_attr_upgrade.attr, |
| 305 | &args_attr_num_glockd.attr, |
| 306 | &args_attr_posix_acl.attr, |
| 307 | &args_attr_quota.attr, |
| 308 | &args_attr_suiddir.attr, |
| 309 | &args_attr_data.attr, |
| 310 | &args_attr_noatime.attr, |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 311 | NULL, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 312 | }; |
| 313 | |
| 314 | /* |
| 315 | * display counters from superblock |
| 316 | */ |
| 317 | |
| 318 | struct counters_attr { |
| 319 | struct attribute attr; |
| 320 | ssize_t (*show)(struct gfs2_sbd *, char *); |
| 321 | }; |
| 322 | |
David Teigland | 6a6b3d0 | 2006-02-23 10:11:47 +0000 | [diff] [blame] | 323 | #define COUNTERS_ATTR(name, fmt) \ |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 324 | static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \ |
| 325 | { \ |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 326 | return snprintf(buf, PAGE_SIZE, fmt, \ |
| 327 | (unsigned int)atomic_read(&sdp->sd_##name)); \ |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 328 | } \ |
| 329 | static struct counters_attr counters_attr_##name = __ATTR_RO(name) |
| 330 | |
David Teigland | 6a6b3d0 | 2006-02-23 10:11:47 +0000 | [diff] [blame] | 331 | COUNTERS_ATTR(glock_count, "%u\n"); |
| 332 | COUNTERS_ATTR(glock_held_count, "%u\n"); |
| 333 | COUNTERS_ATTR(inode_count, "%u\n"); |
| 334 | COUNTERS_ATTR(reclaimed, "%u\n"); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 335 | |
| 336 | static struct attribute *counters_attrs[] = { |
| 337 | &counters_attr_glock_count.attr, |
| 338 | &counters_attr_glock_held_count.attr, |
| 339 | &counters_attr_inode_count.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 340 | &counters_attr_reclaimed.attr, |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 341 | NULL, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 342 | }; |
| 343 | |
| 344 | /* |
| 345 | * get and set struct gfs2_tune fields |
| 346 | */ |
| 347 | |
| 348 | static ssize_t quota_scale_show(struct gfs2_sbd *sdp, char *buf) |
| 349 | { |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 350 | return snprintf(buf, PAGE_SIZE, "%u %u\n", |
| 351 | sdp->sd_tune.gt_quota_scale_num, |
| 352 | sdp->sd_tune.gt_quota_scale_den); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | static ssize_t quota_scale_store(struct gfs2_sbd *sdp, const char *buf, |
| 356 | size_t len) |
| 357 | { |
| 358 | struct gfs2_tune *gt = &sdp->sd_tune; |
| 359 | unsigned int x, y; |
| 360 | |
| 361 | if (!capable(CAP_SYS_ADMIN)) |
| 362 | return -EACCES; |
| 363 | |
| 364 | if (sscanf(buf, "%u %u", &x, &y) != 2 || !y) |
| 365 | return -EINVAL; |
| 366 | |
| 367 | spin_lock(>->gt_spin); |
| 368 | gt->gt_quota_scale_num = x; |
| 369 | gt->gt_quota_scale_den = y; |
| 370 | spin_unlock(>->gt_spin); |
| 371 | return len; |
| 372 | } |
| 373 | |
| 374 | static ssize_t tune_set(struct gfs2_sbd *sdp, unsigned int *field, |
| 375 | int check_zero, const char *buf, size_t len) |
| 376 | { |
| 377 | struct gfs2_tune *gt = &sdp->sd_tune; |
| 378 | unsigned int x; |
| 379 | |
| 380 | if (!capable(CAP_SYS_ADMIN)) |
| 381 | return -EACCES; |
| 382 | |
| 383 | x = simple_strtoul(buf, NULL, 0); |
| 384 | |
| 385 | if (check_zero && !x) |
| 386 | return -EINVAL; |
| 387 | |
| 388 | spin_lock(>->gt_spin); |
| 389 | *field = x; |
| 390 | spin_unlock(>->gt_spin); |
| 391 | return len; |
| 392 | } |
| 393 | |
| 394 | struct tune_attr { |
| 395 | struct attribute attr; |
| 396 | ssize_t (*show)(struct gfs2_sbd *, char *); |
| 397 | ssize_t (*store)(struct gfs2_sbd *, const char *, size_t); |
| 398 | }; |
| 399 | |
| 400 | #define TUNE_ATTR_3(name, show, store) \ |
| 401 | static struct tune_attr tune_attr_##name = __ATTR(name, 0644, show, store) |
| 402 | |
| 403 | #define TUNE_ATTR_2(name, store) \ |
| 404 | static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \ |
| 405 | { \ |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 406 | return snprintf(buf, PAGE_SIZE, "%u\n", sdp->sd_tune.gt_##name); \ |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 407 | } \ |
| 408 | TUNE_ATTR_3(name, name##_show, store) |
| 409 | |
| 410 | #define TUNE_ATTR(name, check_zero) \ |
| 411 | static ssize_t name##_store(struct gfs2_sbd *sdp, const char *buf, size_t len)\ |
| 412 | { \ |
| 413 | return tune_set(sdp, &sdp->sd_tune.gt_##name, check_zero, buf, len); \ |
| 414 | } \ |
| 415 | TUNE_ATTR_2(name, name##_store) |
| 416 | |
| 417 | #define TUNE_ATTR_DAEMON(name, process) \ |
| 418 | static ssize_t name##_store(struct gfs2_sbd *sdp, const char *buf, size_t len)\ |
| 419 | { \ |
| 420 | ssize_t r = tune_set(sdp, &sdp->sd_tune.gt_##name, 1, buf, len); \ |
| 421 | wake_up_process(sdp->sd_##process); \ |
| 422 | return r; \ |
| 423 | } \ |
| 424 | TUNE_ATTR_2(name, name##_store) |
| 425 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 426 | TUNE_ATTR(demote_secs, 0); |
| 427 | TUNE_ATTR(incore_log_blocks, 0); |
| 428 | TUNE_ATTR(log_flush_secs, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 429 | TUNE_ATTR(quota_warn_period, 0); |
| 430 | TUNE_ATTR(quota_quantum, 0); |
| 431 | TUNE_ATTR(atime_quantum, 0); |
| 432 | TUNE_ATTR(max_readahead, 0); |
| 433 | TUNE_ATTR(complain_secs, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 434 | TUNE_ATTR(statfs_slow, 0); |
| 435 | TUNE_ATTR(new_files_jdata, 0); |
| 436 | TUNE_ATTR(new_files_directio, 0); |
| 437 | TUNE_ATTR(quota_simul_sync, 1); |
| 438 | TUNE_ATTR(quota_cache_secs, 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 439 | TUNE_ATTR(stall_secs, 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 440 | TUNE_ATTR(statfs_quantum, 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 441 | TUNE_ATTR_DAEMON(recoverd_secs, recoverd_process); |
| 442 | TUNE_ATTR_DAEMON(logd_secs, logd_process); |
| 443 | TUNE_ATTR_DAEMON(quotad_secs, quotad_process); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 444 | TUNE_ATTR_3(quota_scale, quota_scale_show, quota_scale_store); |
| 445 | |
| 446 | static struct attribute *tune_attrs[] = { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 447 | &tune_attr_demote_secs.attr, |
| 448 | &tune_attr_incore_log_blocks.attr, |
| 449 | &tune_attr_log_flush_secs.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 450 | &tune_attr_quota_warn_period.attr, |
| 451 | &tune_attr_quota_quantum.attr, |
| 452 | &tune_attr_atime_quantum.attr, |
| 453 | &tune_attr_max_readahead.attr, |
| 454 | &tune_attr_complain_secs.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 455 | &tune_attr_statfs_slow.attr, |
| 456 | &tune_attr_quota_simul_sync.attr, |
| 457 | &tune_attr_quota_cache_secs.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 458 | &tune_attr_stall_secs.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 459 | &tune_attr_statfs_quantum.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 460 | &tune_attr_recoverd_secs.attr, |
| 461 | &tune_attr_logd_secs.attr, |
| 462 | &tune_attr_quotad_secs.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 463 | &tune_attr_quota_scale.attr, |
| 464 | &tune_attr_new_files_jdata.attr, |
| 465 | &tune_attr_new_files_directio.attr, |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 466 | NULL, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 467 | }; |
| 468 | |
| 469 | static struct attribute_group lockstruct_group = { |
| 470 | .name = "lockstruct", |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 471 | .attrs = lockstruct_attrs, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 472 | }; |
| 473 | |
| 474 | static struct attribute_group counters_group = { |
| 475 | .name = "counters", |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 476 | .attrs = counters_attrs, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 477 | }; |
| 478 | |
| 479 | static struct attribute_group args_group = { |
| 480 | .name = "args", |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 481 | .attrs = args_attrs, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 482 | }; |
| 483 | |
| 484 | static struct attribute_group tune_group = { |
| 485 | .name = "tune", |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 486 | .attrs = tune_attrs, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 487 | }; |
| 488 | |
| 489 | int gfs2_sys_fs_add(struct gfs2_sbd *sdp) |
| 490 | { |
| 491 | int error; |
| 492 | |
Greg Kroah-Hartman | 9bec101 | 2007-10-29 20:13:17 +0100 | [diff] [blame] | 493 | sdp->sd_kobj.kset = gfs2_kset; |
Greg Kroah-Hartman | 901195e | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 494 | error = kobject_init_and_add(&sdp->sd_kobj, &gfs2_ktype, NULL, |
| 495 | "%s", sdp->sd_table_name); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 496 | if (error) |
| 497 | goto fail; |
| 498 | |
| 499 | error = sysfs_create_group(&sdp->sd_kobj, &lockstruct_group); |
| 500 | if (error) |
| 501 | goto fail_reg; |
| 502 | |
| 503 | error = sysfs_create_group(&sdp->sd_kobj, &counters_group); |
| 504 | if (error) |
| 505 | goto fail_lockstruct; |
| 506 | |
| 507 | error = sysfs_create_group(&sdp->sd_kobj, &args_group); |
| 508 | if (error) |
| 509 | goto fail_counters; |
| 510 | |
| 511 | error = sysfs_create_group(&sdp->sd_kobj, &tune_group); |
| 512 | if (error) |
| 513 | goto fail_args; |
| 514 | |
Greg Kroah-Hartman | 901195e | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 515 | kobject_uevent(&sdp->sd_kobj, KOBJ_ADD); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 516 | return 0; |
| 517 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 518 | fail_args: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 519 | sysfs_remove_group(&sdp->sd_kobj, &args_group); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 520 | fail_counters: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 521 | sysfs_remove_group(&sdp->sd_kobj, &counters_group); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 522 | fail_lockstruct: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 523 | sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 524 | fail_reg: |
Greg Kroah-Hartman | 197b12d | 2007-12-20 08:13:05 -0800 | [diff] [blame] | 525 | kobject_put(&sdp->sd_kobj); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 526 | fail: |
David Teigland | 65952fb | 2006-09-15 13:09:11 -0500 | [diff] [blame] | 527 | fs_err(sdp, "error %d adding sysfs files", error); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 528 | return error; |
| 529 | } |
| 530 | |
| 531 | void gfs2_sys_fs_del(struct gfs2_sbd *sdp) |
| 532 | { |
| 533 | sysfs_remove_group(&sdp->sd_kobj, &tune_group); |
| 534 | sysfs_remove_group(&sdp->sd_kobj, &args_group); |
| 535 | sysfs_remove_group(&sdp->sd_kobj, &counters_group); |
| 536 | sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group); |
Greg Kroah-Hartman | 197b12d | 2007-12-20 08:13:05 -0800 | [diff] [blame] | 537 | kobject_put(&sdp->sd_kobj); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | int gfs2_sys_init(void) |
| 541 | { |
| 542 | gfs2_sys_margs = NULL; |
| 543 | spin_lock_init(&gfs2_sys_margs_lock); |
Greg Kroah-Hartman | 9bec101 | 2007-10-29 20:13:17 +0100 | [diff] [blame] | 544 | gfs2_kset = kset_create_and_add("gfs2", NULL, fs_kobj); |
| 545 | if (!gfs2_kset) |
| 546 | return -ENOMEM; |
| 547 | return 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | void gfs2_sys_uninit(void) |
| 551 | { |
| 552 | kfree(gfs2_sys_margs); |
Greg Kroah-Hartman | 9bec101 | 2007-10-29 20:13:17 +0100 | [diff] [blame] | 553 | kset_unregister(gfs2_kset); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 554 | } |
| 555 | |