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 "sys.h" |
| 24 | #include "super.h" |
| 25 | #include "glock.h" |
| 26 | #include "quota.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 27 | #include "util.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 28 | |
| 29 | char *gfs2_sys_margs; |
| 30 | spinlock_t gfs2_sys_margs_lock; |
| 31 | |
| 32 | static ssize_t id_show(struct gfs2_sbd *sdp, char *buf) |
| 33 | { |
Bob Peterson | c7227e4 | 2007-11-02 09:37:15 -0500 | [diff] [blame] | 34 | return snprintf(buf, PAGE_SIZE, "%u:%u\n", |
| 35 | MAJOR(sdp->sd_vfs->s_dev), MINOR(sdp->sd_vfs->s_dev)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | static ssize_t fsname_show(struct gfs2_sbd *sdp, char *buf) |
| 39 | { |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 40 | return snprintf(buf, PAGE_SIZE, "%s\n", sdp->sd_fsname); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | static ssize_t freeze_show(struct gfs2_sbd *sdp, char *buf) |
| 44 | { |
| 45 | unsigned int count; |
| 46 | |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 47 | mutex_lock(&sdp->sd_freeze_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 48 | count = sdp->sd_freeze_count; |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 49 | mutex_unlock(&sdp->sd_freeze_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 50 | |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 51 | return snprintf(buf, PAGE_SIZE, "%u\n", count); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 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); |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 83 | return snprintf(buf, PAGE_SIZE, "%u\n", b); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 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 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 113 | static ssize_t quota_sync_store(struct gfs2_sbd *sdp, const char *buf, |
| 114 | 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_quota_sync(sdp); |
| 123 | return len; |
| 124 | } |
| 125 | |
| 126 | static ssize_t quota_refresh_user_store(struct gfs2_sbd *sdp, const char *buf, |
| 127 | size_t len) |
| 128 | { |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 129 | u32 id; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 130 | |
| 131 | if (!capable(CAP_SYS_ADMIN)) |
| 132 | return -EACCES; |
| 133 | |
| 134 | id = simple_strtoul(buf, NULL, 0); |
| 135 | |
| 136 | gfs2_quota_refresh(sdp, 1, id); |
| 137 | return len; |
| 138 | } |
| 139 | |
| 140 | static ssize_t quota_refresh_group_store(struct gfs2_sbd *sdp, const char *buf, |
| 141 | size_t len) |
| 142 | { |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 143 | u32 id; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 144 | |
| 145 | if (!capable(CAP_SYS_ADMIN)) |
| 146 | return -EACCES; |
| 147 | |
| 148 | id = simple_strtoul(buf, NULL, 0); |
| 149 | |
| 150 | gfs2_quota_refresh(sdp, 0, id); |
| 151 | return len; |
| 152 | } |
| 153 | |
| 154 | struct gfs2_attr { |
| 155 | struct attribute attr; |
| 156 | ssize_t (*show)(struct gfs2_sbd *, char *); |
| 157 | ssize_t (*store)(struct gfs2_sbd *, const char *, size_t); |
| 158 | }; |
| 159 | |
| 160 | #define GFS2_ATTR(name, mode, show, store) \ |
| 161 | static struct gfs2_attr gfs2_attr_##name = __ATTR(name, mode, show, store) |
| 162 | |
| 163 | GFS2_ATTR(id, 0444, id_show, NULL); |
| 164 | GFS2_ATTR(fsname, 0444, fsname_show, NULL); |
| 165 | GFS2_ATTR(freeze, 0644, freeze_show, freeze_store); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 166 | GFS2_ATTR(withdraw, 0644, withdraw_show, withdraw_store); |
| 167 | GFS2_ATTR(statfs_sync, 0200, NULL, statfs_sync_store); |
| 168 | GFS2_ATTR(quota_sync, 0200, NULL, quota_sync_store); |
| 169 | GFS2_ATTR(quota_refresh_user, 0200, NULL, quota_refresh_user_store); |
| 170 | GFS2_ATTR(quota_refresh_group, 0200, NULL, quota_refresh_group_store); |
| 171 | |
| 172 | static struct attribute *gfs2_attrs[] = { |
| 173 | &gfs2_attr_id.attr, |
| 174 | &gfs2_attr_fsname.attr, |
| 175 | &gfs2_attr_freeze.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 176 | &gfs2_attr_withdraw.attr, |
| 177 | &gfs2_attr_statfs_sync.attr, |
| 178 | &gfs2_attr_quota_sync.attr, |
| 179 | &gfs2_attr_quota_refresh_user.attr, |
| 180 | &gfs2_attr_quota_refresh_group.attr, |
| 181 | NULL, |
| 182 | }; |
| 183 | |
| 184 | static ssize_t gfs2_attr_show(struct kobject *kobj, struct attribute *attr, |
| 185 | char *buf) |
| 186 | { |
| 187 | struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj); |
| 188 | struct gfs2_attr *a = container_of(attr, struct gfs2_attr, attr); |
| 189 | return a->show ? a->show(sdp, buf) : 0; |
| 190 | } |
| 191 | |
| 192 | static ssize_t gfs2_attr_store(struct kobject *kobj, struct attribute *attr, |
| 193 | const char *buf, size_t len) |
| 194 | { |
| 195 | struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj); |
| 196 | struct gfs2_attr *a = container_of(attr, struct gfs2_attr, attr); |
| 197 | return a->store ? a->store(sdp, buf, len) : len; |
| 198 | } |
| 199 | |
| 200 | static struct sysfs_ops gfs2_attr_ops = { |
| 201 | .show = gfs2_attr_show, |
| 202 | .store = gfs2_attr_store, |
| 203 | }; |
| 204 | |
| 205 | static struct kobj_type gfs2_ktype = { |
| 206 | .default_attrs = gfs2_attrs, |
| 207 | .sysfs_ops = &gfs2_attr_ops, |
| 208 | }; |
| 209 | |
Greg Kroah-Hartman | 9bec101 | 2007-10-29 20:13:17 +0100 | [diff] [blame] | 210 | static struct kset *gfs2_kset; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 211 | |
| 212 | /* |
| 213 | * display struct lm_lockstruct fields |
| 214 | */ |
| 215 | |
| 216 | struct lockstruct_attr { |
| 217 | struct attribute attr; |
| 218 | ssize_t (*show)(struct gfs2_sbd *, char *); |
| 219 | }; |
| 220 | |
| 221 | #define LOCKSTRUCT_ATTR(name, fmt) \ |
| 222 | static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \ |
| 223 | { \ |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 224 | return snprintf(buf, PAGE_SIZE, fmt, sdp->sd_lockstruct.ls_##name); \ |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 225 | } \ |
| 226 | static struct lockstruct_attr lockstruct_attr_##name = __ATTR_RO(name) |
| 227 | |
| 228 | LOCKSTRUCT_ATTR(jid, "%u\n"); |
| 229 | LOCKSTRUCT_ATTR(first, "%u\n"); |
| 230 | LOCKSTRUCT_ATTR(lvb_size, "%u\n"); |
| 231 | LOCKSTRUCT_ATTR(flags, "%d\n"); |
| 232 | |
| 233 | static struct attribute *lockstruct_attrs[] = { |
| 234 | &lockstruct_attr_jid.attr, |
| 235 | &lockstruct_attr_first.attr, |
| 236 | &lockstruct_attr_lvb_size.attr, |
| 237 | &lockstruct_attr_flags.attr, |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 238 | NULL, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 239 | }; |
| 240 | |
| 241 | /* |
| 242 | * display struct gfs2_args fields |
| 243 | */ |
| 244 | |
| 245 | struct args_attr { |
| 246 | struct attribute attr; |
| 247 | ssize_t (*show)(struct gfs2_sbd *, char *); |
| 248 | }; |
| 249 | |
| 250 | #define ARGS_ATTR(name, fmt) \ |
| 251 | static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \ |
| 252 | { \ |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 253 | return snprintf(buf, PAGE_SIZE, fmt, sdp->sd_args.ar_##name); \ |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 254 | } \ |
| 255 | static struct args_attr args_attr_##name = __ATTR_RO(name) |
| 256 | |
| 257 | ARGS_ATTR(lockproto, "%s\n"); |
| 258 | ARGS_ATTR(locktable, "%s\n"); |
| 259 | ARGS_ATTR(hostdata, "%s\n"); |
| 260 | ARGS_ATTR(spectator, "%d\n"); |
| 261 | ARGS_ATTR(ignore_local_fs, "%d\n"); |
| 262 | ARGS_ATTR(localcaching, "%d\n"); |
| 263 | ARGS_ATTR(localflocks, "%d\n"); |
| 264 | ARGS_ATTR(debug, "%d\n"); |
| 265 | ARGS_ATTR(upgrade, "%d\n"); |
| 266 | ARGS_ATTR(num_glockd, "%u\n"); |
| 267 | ARGS_ATTR(posix_acl, "%d\n"); |
| 268 | ARGS_ATTR(quota, "%u\n"); |
| 269 | ARGS_ATTR(suiddir, "%d\n"); |
| 270 | ARGS_ATTR(data, "%d\n"); |
| 271 | |
| 272 | /* one oddball doesn't fit the macro mold */ |
| 273 | static ssize_t noatime_show(struct gfs2_sbd *sdp, char *buf) |
| 274 | { |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 275 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 276 | !!test_bit(SDF_NOATIME, &sdp->sd_flags)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 277 | } |
| 278 | static struct args_attr args_attr_noatime = __ATTR_RO(noatime); |
| 279 | |
| 280 | static struct attribute *args_attrs[] = { |
| 281 | &args_attr_lockproto.attr, |
| 282 | &args_attr_locktable.attr, |
| 283 | &args_attr_hostdata.attr, |
| 284 | &args_attr_spectator.attr, |
| 285 | &args_attr_ignore_local_fs.attr, |
| 286 | &args_attr_localcaching.attr, |
| 287 | &args_attr_localflocks.attr, |
| 288 | &args_attr_debug.attr, |
| 289 | &args_attr_upgrade.attr, |
| 290 | &args_attr_num_glockd.attr, |
| 291 | &args_attr_posix_acl.attr, |
| 292 | &args_attr_quota.attr, |
| 293 | &args_attr_suiddir.attr, |
| 294 | &args_attr_data.attr, |
| 295 | &args_attr_noatime.attr, |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 296 | NULL, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 297 | }; |
| 298 | |
| 299 | /* |
| 300 | * display counters from superblock |
| 301 | */ |
| 302 | |
| 303 | struct counters_attr { |
| 304 | struct attribute attr; |
| 305 | ssize_t (*show)(struct gfs2_sbd *, char *); |
| 306 | }; |
| 307 | |
David Teigland | 6a6b3d0 | 2006-02-23 10:11:47 +0000 | [diff] [blame] | 308 | #define COUNTERS_ATTR(name, fmt) \ |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 309 | static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \ |
| 310 | { \ |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 311 | return snprintf(buf, PAGE_SIZE, fmt, \ |
| 312 | (unsigned int)atomic_read(&sdp->sd_##name)); \ |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 313 | } \ |
| 314 | static struct counters_attr counters_attr_##name = __ATTR_RO(name) |
| 315 | |
David Teigland | 6a6b3d0 | 2006-02-23 10:11:47 +0000 | [diff] [blame] | 316 | COUNTERS_ATTR(reclaimed, "%u\n"); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 317 | |
| 318 | static struct attribute *counters_attrs[] = { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 319 | &counters_attr_reclaimed.attr, |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 320 | NULL, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 321 | }; |
| 322 | |
| 323 | /* |
| 324 | * get and set struct gfs2_tune fields |
| 325 | */ |
| 326 | |
| 327 | static ssize_t quota_scale_show(struct gfs2_sbd *sdp, char *buf) |
| 328 | { |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 329 | return snprintf(buf, PAGE_SIZE, "%u %u\n", |
| 330 | sdp->sd_tune.gt_quota_scale_num, |
| 331 | sdp->sd_tune.gt_quota_scale_den); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | static ssize_t quota_scale_store(struct gfs2_sbd *sdp, const char *buf, |
| 335 | size_t len) |
| 336 | { |
| 337 | struct gfs2_tune *gt = &sdp->sd_tune; |
| 338 | unsigned int x, y; |
| 339 | |
| 340 | if (!capable(CAP_SYS_ADMIN)) |
| 341 | return -EACCES; |
| 342 | |
| 343 | if (sscanf(buf, "%u %u", &x, &y) != 2 || !y) |
| 344 | return -EINVAL; |
| 345 | |
| 346 | spin_lock(>->gt_spin); |
| 347 | gt->gt_quota_scale_num = x; |
| 348 | gt->gt_quota_scale_den = y; |
| 349 | spin_unlock(>->gt_spin); |
| 350 | return len; |
| 351 | } |
| 352 | |
| 353 | static ssize_t tune_set(struct gfs2_sbd *sdp, unsigned int *field, |
| 354 | int check_zero, const char *buf, size_t len) |
| 355 | { |
| 356 | struct gfs2_tune *gt = &sdp->sd_tune; |
| 357 | unsigned int x; |
| 358 | |
| 359 | if (!capable(CAP_SYS_ADMIN)) |
| 360 | return -EACCES; |
| 361 | |
| 362 | x = simple_strtoul(buf, NULL, 0); |
| 363 | |
| 364 | if (check_zero && !x) |
| 365 | return -EINVAL; |
| 366 | |
| 367 | spin_lock(>->gt_spin); |
| 368 | *field = x; |
| 369 | spin_unlock(>->gt_spin); |
| 370 | return len; |
| 371 | } |
| 372 | |
| 373 | struct tune_attr { |
| 374 | struct attribute attr; |
| 375 | ssize_t (*show)(struct gfs2_sbd *, char *); |
| 376 | ssize_t (*store)(struct gfs2_sbd *, const char *, size_t); |
| 377 | }; |
| 378 | |
| 379 | #define TUNE_ATTR_3(name, show, store) \ |
| 380 | static struct tune_attr tune_attr_##name = __ATTR(name, 0644, show, store) |
| 381 | |
| 382 | #define TUNE_ATTR_2(name, store) \ |
| 383 | static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \ |
| 384 | { \ |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 385 | return snprintf(buf, PAGE_SIZE, "%u\n", sdp->sd_tune.gt_##name); \ |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 386 | } \ |
| 387 | TUNE_ATTR_3(name, name##_show, store) |
| 388 | |
| 389 | #define TUNE_ATTR(name, check_zero) \ |
| 390 | static ssize_t name##_store(struct gfs2_sbd *sdp, const char *buf, size_t len)\ |
| 391 | { \ |
| 392 | return tune_set(sdp, &sdp->sd_tune.gt_##name, check_zero, buf, len); \ |
| 393 | } \ |
| 394 | TUNE_ATTR_2(name, name##_store) |
| 395 | |
| 396 | #define TUNE_ATTR_DAEMON(name, process) \ |
| 397 | static ssize_t name##_store(struct gfs2_sbd *sdp, const char *buf, size_t len)\ |
| 398 | { \ |
| 399 | ssize_t r = tune_set(sdp, &sdp->sd_tune.gt_##name, 1, buf, len); \ |
| 400 | wake_up_process(sdp->sd_##process); \ |
| 401 | return r; \ |
| 402 | } \ |
| 403 | TUNE_ATTR_2(name, name##_store) |
| 404 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 405 | TUNE_ATTR(demote_secs, 0); |
| 406 | TUNE_ATTR(incore_log_blocks, 0); |
| 407 | TUNE_ATTR(log_flush_secs, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 408 | TUNE_ATTR(quota_warn_period, 0); |
| 409 | TUNE_ATTR(quota_quantum, 0); |
| 410 | TUNE_ATTR(atime_quantum, 0); |
| 411 | TUNE_ATTR(max_readahead, 0); |
| 412 | TUNE_ATTR(complain_secs, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 413 | TUNE_ATTR(statfs_slow, 0); |
| 414 | TUNE_ATTR(new_files_jdata, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 415 | TUNE_ATTR(quota_simul_sync, 1); |
| 416 | TUNE_ATTR(quota_cache_secs, 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 417 | TUNE_ATTR(stall_secs, 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 418 | TUNE_ATTR(statfs_quantum, 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 419 | TUNE_ATTR_DAEMON(recoverd_secs, recoverd_process); |
| 420 | TUNE_ATTR_DAEMON(logd_secs, logd_process); |
| 421 | TUNE_ATTR_DAEMON(quotad_secs, quotad_process); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 422 | TUNE_ATTR_3(quota_scale, quota_scale_show, quota_scale_store); |
| 423 | |
| 424 | static struct attribute *tune_attrs[] = { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 425 | &tune_attr_demote_secs.attr, |
| 426 | &tune_attr_incore_log_blocks.attr, |
| 427 | &tune_attr_log_flush_secs.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 428 | &tune_attr_quota_warn_period.attr, |
| 429 | &tune_attr_quota_quantum.attr, |
| 430 | &tune_attr_atime_quantum.attr, |
| 431 | &tune_attr_max_readahead.attr, |
| 432 | &tune_attr_complain_secs.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 433 | &tune_attr_statfs_slow.attr, |
| 434 | &tune_attr_quota_simul_sync.attr, |
| 435 | &tune_attr_quota_cache_secs.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 436 | &tune_attr_stall_secs.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 437 | &tune_attr_statfs_quantum.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 438 | &tune_attr_recoverd_secs.attr, |
| 439 | &tune_attr_logd_secs.attr, |
| 440 | &tune_attr_quotad_secs.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 441 | &tune_attr_quota_scale.attr, |
| 442 | &tune_attr_new_files_jdata.attr, |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 443 | NULL, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 444 | }; |
| 445 | |
| 446 | static struct attribute_group lockstruct_group = { |
| 447 | .name = "lockstruct", |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 448 | .attrs = lockstruct_attrs, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 449 | }; |
| 450 | |
| 451 | static struct attribute_group counters_group = { |
| 452 | .name = "counters", |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 453 | .attrs = counters_attrs, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 454 | }; |
| 455 | |
| 456 | static struct attribute_group args_group = { |
| 457 | .name = "args", |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 458 | .attrs = args_attrs, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 459 | }; |
| 460 | |
| 461 | static struct attribute_group tune_group = { |
| 462 | .name = "tune", |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 463 | .attrs = tune_attrs, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 464 | }; |
| 465 | |
| 466 | int gfs2_sys_fs_add(struct gfs2_sbd *sdp) |
| 467 | { |
| 468 | int error; |
| 469 | |
Greg Kroah-Hartman | 9bec101 | 2007-10-29 20:13:17 +0100 | [diff] [blame] | 470 | sdp->sd_kobj.kset = gfs2_kset; |
Greg Kroah-Hartman | 901195e | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 471 | error = kobject_init_and_add(&sdp->sd_kobj, &gfs2_ktype, NULL, |
| 472 | "%s", sdp->sd_table_name); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 473 | if (error) |
| 474 | goto fail; |
| 475 | |
| 476 | error = sysfs_create_group(&sdp->sd_kobj, &lockstruct_group); |
| 477 | if (error) |
| 478 | goto fail_reg; |
| 479 | |
| 480 | error = sysfs_create_group(&sdp->sd_kobj, &counters_group); |
| 481 | if (error) |
| 482 | goto fail_lockstruct; |
| 483 | |
| 484 | error = sysfs_create_group(&sdp->sd_kobj, &args_group); |
| 485 | if (error) |
| 486 | goto fail_counters; |
| 487 | |
| 488 | error = sysfs_create_group(&sdp->sd_kobj, &tune_group); |
| 489 | if (error) |
| 490 | goto fail_args; |
| 491 | |
Greg Kroah-Hartman | 901195e | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 492 | kobject_uevent(&sdp->sd_kobj, KOBJ_ADD); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 493 | return 0; |
| 494 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 495 | fail_args: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 496 | sysfs_remove_group(&sdp->sd_kobj, &args_group); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 497 | fail_counters: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 498 | sysfs_remove_group(&sdp->sd_kobj, &counters_group); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 499 | fail_lockstruct: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 500 | sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 501 | fail_reg: |
Greg Kroah-Hartman | 197b12d | 2007-12-20 08:13:05 -0800 | [diff] [blame] | 502 | kobject_put(&sdp->sd_kobj); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 503 | fail: |
David Teigland | 65952fb | 2006-09-15 13:09:11 -0500 | [diff] [blame] | 504 | fs_err(sdp, "error %d adding sysfs files", error); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 505 | return error; |
| 506 | } |
| 507 | |
| 508 | void gfs2_sys_fs_del(struct gfs2_sbd *sdp) |
| 509 | { |
| 510 | sysfs_remove_group(&sdp->sd_kobj, &tune_group); |
| 511 | sysfs_remove_group(&sdp->sd_kobj, &args_group); |
| 512 | sysfs_remove_group(&sdp->sd_kobj, &counters_group); |
| 513 | sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group); |
Greg Kroah-Hartman | 197b12d | 2007-12-20 08:13:05 -0800 | [diff] [blame] | 514 | kobject_put(&sdp->sd_kobj); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | int gfs2_sys_init(void) |
| 518 | { |
| 519 | gfs2_sys_margs = NULL; |
| 520 | spin_lock_init(&gfs2_sys_margs_lock); |
Greg Kroah-Hartman | 9bec101 | 2007-10-29 20:13:17 +0100 | [diff] [blame] | 521 | gfs2_kset = kset_create_and_add("gfs2", NULL, fs_kobj); |
| 522 | if (!gfs2_kset) |
| 523 | return -ENOMEM; |
| 524 | return 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | void gfs2_sys_uninit(void) |
| 528 | { |
| 529 | kfree(gfs2_sys_margs); |
Greg Kroah-Hartman | 9bec101 | 2007-10-29 20:13:17 +0100 | [diff] [blame] | 530 | kset_unregister(gfs2_kset); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 531 | } |
| 532 | |