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 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 29 | static ssize_t id_show(struct gfs2_sbd *sdp, char *buf) |
| 30 | { |
Bob Peterson | c7227e46 | 2007-11-02 09:37:15 -0500 | [diff] [blame] | 31 | return snprintf(buf, PAGE_SIZE, "%u:%u\n", |
| 32 | MAJOR(sdp->sd_vfs->s_dev), MINOR(sdp->sd_vfs->s_dev)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | static ssize_t fsname_show(struct gfs2_sbd *sdp, char *buf) |
| 36 | { |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 37 | return snprintf(buf, PAGE_SIZE, "%s\n", sdp->sd_fsname); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | static ssize_t freeze_show(struct gfs2_sbd *sdp, char *buf) |
| 41 | { |
| 42 | unsigned int count; |
| 43 | |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 44 | mutex_lock(&sdp->sd_freeze_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 45 | count = sdp->sd_freeze_count; |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 46 | mutex_unlock(&sdp->sd_freeze_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 47 | |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 48 | return snprintf(buf, PAGE_SIZE, "%u\n", count); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | static ssize_t freeze_store(struct gfs2_sbd *sdp, const char *buf, size_t len) |
| 52 | { |
| 53 | ssize_t ret = len; |
| 54 | int error = 0; |
| 55 | int n = simple_strtol(buf, NULL, 0); |
| 56 | |
| 57 | if (!capable(CAP_SYS_ADMIN)) |
| 58 | return -EACCES; |
| 59 | |
| 60 | switch (n) { |
| 61 | case 0: |
| 62 | gfs2_unfreeze_fs(sdp); |
| 63 | break; |
| 64 | case 1: |
| 65 | error = gfs2_freeze_fs(sdp); |
| 66 | break; |
| 67 | default: |
| 68 | ret = -EINVAL; |
| 69 | } |
| 70 | |
| 71 | if (error) |
| 72 | fs_warn(sdp, "freeze %d error %d", n, error); |
| 73 | |
| 74 | return ret; |
| 75 | } |
| 76 | |
| 77 | static ssize_t withdraw_show(struct gfs2_sbd *sdp, char *buf) |
| 78 | { |
| 79 | unsigned int b = test_bit(SDF_SHUTDOWN, &sdp->sd_flags); |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 80 | return snprintf(buf, PAGE_SIZE, "%u\n", b); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | static ssize_t withdraw_store(struct gfs2_sbd *sdp, const char *buf, size_t len) |
| 84 | { |
| 85 | if (!capable(CAP_SYS_ADMIN)) |
| 86 | return -EACCES; |
| 87 | |
| 88 | if (simple_strtol(buf, NULL, 0) != 1) |
| 89 | return -EINVAL; |
| 90 | |
| 91 | gfs2_lm_withdraw(sdp, |
| 92 | "GFS2: fsid=%s: withdrawing from cluster at user's request\n", |
| 93 | sdp->sd_fsname); |
| 94 | return len; |
| 95 | } |
| 96 | |
| 97 | static ssize_t statfs_sync_store(struct gfs2_sbd *sdp, const char *buf, |
| 98 | size_t len) |
| 99 | { |
| 100 | if (!capable(CAP_SYS_ADMIN)) |
| 101 | return -EACCES; |
| 102 | |
| 103 | if (simple_strtol(buf, NULL, 0) != 1) |
| 104 | return -EINVAL; |
| 105 | |
| 106 | gfs2_statfs_sync(sdp); |
| 107 | return len; |
| 108 | } |
| 109 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 110 | static ssize_t quota_sync_store(struct gfs2_sbd *sdp, const char *buf, |
| 111 | size_t len) |
| 112 | { |
| 113 | if (!capable(CAP_SYS_ADMIN)) |
| 114 | return -EACCES; |
| 115 | |
| 116 | if (simple_strtol(buf, NULL, 0) != 1) |
| 117 | return -EINVAL; |
| 118 | |
| 119 | gfs2_quota_sync(sdp); |
| 120 | return len; |
| 121 | } |
| 122 | |
| 123 | static ssize_t quota_refresh_user_store(struct gfs2_sbd *sdp, const char *buf, |
| 124 | size_t len) |
| 125 | { |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 126 | u32 id; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 127 | |
| 128 | if (!capable(CAP_SYS_ADMIN)) |
| 129 | return -EACCES; |
| 130 | |
| 131 | id = simple_strtoul(buf, NULL, 0); |
| 132 | |
| 133 | gfs2_quota_refresh(sdp, 1, id); |
| 134 | return len; |
| 135 | } |
| 136 | |
| 137 | static ssize_t quota_refresh_group_store(struct gfs2_sbd *sdp, const char *buf, |
| 138 | size_t len) |
| 139 | { |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 140 | u32 id; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 141 | |
| 142 | if (!capable(CAP_SYS_ADMIN)) |
| 143 | return -EACCES; |
| 144 | |
| 145 | id = simple_strtoul(buf, NULL, 0); |
| 146 | |
| 147 | gfs2_quota_refresh(sdp, 0, id); |
| 148 | return len; |
| 149 | } |
| 150 | |
| 151 | struct gfs2_attr { |
| 152 | struct attribute attr; |
| 153 | ssize_t (*show)(struct gfs2_sbd *, char *); |
| 154 | ssize_t (*store)(struct gfs2_sbd *, const char *, size_t); |
| 155 | }; |
| 156 | |
| 157 | #define GFS2_ATTR(name, mode, show, store) \ |
| 158 | static struct gfs2_attr gfs2_attr_##name = __ATTR(name, mode, show, store) |
| 159 | |
| 160 | GFS2_ATTR(id, 0444, id_show, NULL); |
| 161 | GFS2_ATTR(fsname, 0444, fsname_show, NULL); |
| 162 | GFS2_ATTR(freeze, 0644, freeze_show, freeze_store); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 163 | GFS2_ATTR(withdraw, 0644, withdraw_show, withdraw_store); |
| 164 | GFS2_ATTR(statfs_sync, 0200, NULL, statfs_sync_store); |
| 165 | GFS2_ATTR(quota_sync, 0200, NULL, quota_sync_store); |
| 166 | GFS2_ATTR(quota_refresh_user, 0200, NULL, quota_refresh_user_store); |
| 167 | GFS2_ATTR(quota_refresh_group, 0200, NULL, quota_refresh_group_store); |
| 168 | |
| 169 | static struct attribute *gfs2_attrs[] = { |
| 170 | &gfs2_attr_id.attr, |
| 171 | &gfs2_attr_fsname.attr, |
| 172 | &gfs2_attr_freeze.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 173 | &gfs2_attr_withdraw.attr, |
| 174 | &gfs2_attr_statfs_sync.attr, |
| 175 | &gfs2_attr_quota_sync.attr, |
| 176 | &gfs2_attr_quota_refresh_user.attr, |
| 177 | &gfs2_attr_quota_refresh_group.attr, |
| 178 | NULL, |
| 179 | }; |
| 180 | |
| 181 | static ssize_t gfs2_attr_show(struct kobject *kobj, struct attribute *attr, |
| 182 | char *buf) |
| 183 | { |
| 184 | struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj); |
| 185 | struct gfs2_attr *a = container_of(attr, struct gfs2_attr, attr); |
| 186 | return a->show ? a->show(sdp, buf) : 0; |
| 187 | } |
| 188 | |
| 189 | static ssize_t gfs2_attr_store(struct kobject *kobj, struct attribute *attr, |
| 190 | const char *buf, size_t len) |
| 191 | { |
| 192 | struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj); |
| 193 | struct gfs2_attr *a = container_of(attr, struct gfs2_attr, attr); |
| 194 | return a->store ? a->store(sdp, buf, len) : len; |
| 195 | } |
| 196 | |
| 197 | static struct sysfs_ops gfs2_attr_ops = { |
| 198 | .show = gfs2_attr_show, |
| 199 | .store = gfs2_attr_store, |
| 200 | }; |
| 201 | |
| 202 | static struct kobj_type gfs2_ktype = { |
| 203 | .default_attrs = gfs2_attrs, |
| 204 | .sysfs_ops = &gfs2_attr_ops, |
| 205 | }; |
| 206 | |
Greg Kroah-Hartman | 9bec101 | 2007-10-29 20:13:17 +0100 | [diff] [blame] | 207 | static struct kset *gfs2_kset; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 208 | |
| 209 | /* |
| 210 | * display struct lm_lockstruct fields |
| 211 | */ |
| 212 | |
| 213 | struct lockstruct_attr { |
| 214 | struct attribute attr; |
| 215 | ssize_t (*show)(struct gfs2_sbd *, char *); |
| 216 | }; |
| 217 | |
| 218 | #define LOCKSTRUCT_ATTR(name, fmt) \ |
| 219 | static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \ |
| 220 | { \ |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 221 | return snprintf(buf, PAGE_SIZE, fmt, sdp->sd_lockstruct.ls_##name); \ |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 222 | } \ |
| 223 | static struct lockstruct_attr lockstruct_attr_##name = __ATTR_RO(name) |
| 224 | |
| 225 | LOCKSTRUCT_ATTR(jid, "%u\n"); |
| 226 | LOCKSTRUCT_ATTR(first, "%u\n"); |
| 227 | LOCKSTRUCT_ATTR(lvb_size, "%u\n"); |
| 228 | LOCKSTRUCT_ATTR(flags, "%d\n"); |
| 229 | |
| 230 | static struct attribute *lockstruct_attrs[] = { |
| 231 | &lockstruct_attr_jid.attr, |
| 232 | &lockstruct_attr_first.attr, |
| 233 | &lockstruct_attr_lvb_size.attr, |
| 234 | &lockstruct_attr_flags.attr, |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 235 | NULL, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 236 | }; |
| 237 | |
| 238 | /* |
| 239 | * display struct gfs2_args fields |
| 240 | */ |
| 241 | |
| 242 | struct args_attr { |
| 243 | struct attribute attr; |
| 244 | ssize_t (*show)(struct gfs2_sbd *, char *); |
| 245 | }; |
| 246 | |
| 247 | #define ARGS_ATTR(name, fmt) \ |
| 248 | static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \ |
| 249 | { \ |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 250 | return snprintf(buf, PAGE_SIZE, fmt, sdp->sd_args.ar_##name); \ |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 251 | } \ |
| 252 | static struct args_attr args_attr_##name = __ATTR_RO(name) |
| 253 | |
| 254 | ARGS_ATTR(lockproto, "%s\n"); |
| 255 | ARGS_ATTR(locktable, "%s\n"); |
| 256 | ARGS_ATTR(hostdata, "%s\n"); |
| 257 | ARGS_ATTR(spectator, "%d\n"); |
| 258 | ARGS_ATTR(ignore_local_fs, "%d\n"); |
| 259 | ARGS_ATTR(localcaching, "%d\n"); |
| 260 | ARGS_ATTR(localflocks, "%d\n"); |
| 261 | ARGS_ATTR(debug, "%d\n"); |
| 262 | ARGS_ATTR(upgrade, "%d\n"); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 263 | ARGS_ATTR(posix_acl, "%d\n"); |
| 264 | ARGS_ATTR(quota, "%u\n"); |
| 265 | ARGS_ATTR(suiddir, "%d\n"); |
| 266 | ARGS_ATTR(data, "%d\n"); |
| 267 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 268 | static struct attribute *args_attrs[] = { |
| 269 | &args_attr_lockproto.attr, |
| 270 | &args_attr_locktable.attr, |
| 271 | &args_attr_hostdata.attr, |
| 272 | &args_attr_spectator.attr, |
| 273 | &args_attr_ignore_local_fs.attr, |
| 274 | &args_attr_localcaching.attr, |
| 275 | &args_attr_localflocks.attr, |
| 276 | &args_attr_debug.attr, |
| 277 | &args_attr_upgrade.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 278 | &args_attr_posix_acl.attr, |
| 279 | &args_attr_quota.attr, |
| 280 | &args_attr_suiddir.attr, |
| 281 | &args_attr_data.attr, |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 282 | NULL, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 283 | }; |
| 284 | |
| 285 | /* |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 286 | * get and set struct gfs2_tune fields |
| 287 | */ |
| 288 | |
| 289 | static ssize_t quota_scale_show(struct gfs2_sbd *sdp, char *buf) |
| 290 | { |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 291 | return snprintf(buf, PAGE_SIZE, "%u %u\n", |
| 292 | sdp->sd_tune.gt_quota_scale_num, |
| 293 | sdp->sd_tune.gt_quota_scale_den); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | static ssize_t quota_scale_store(struct gfs2_sbd *sdp, const char *buf, |
| 297 | size_t len) |
| 298 | { |
| 299 | struct gfs2_tune *gt = &sdp->sd_tune; |
| 300 | unsigned int x, y; |
| 301 | |
| 302 | if (!capable(CAP_SYS_ADMIN)) |
| 303 | return -EACCES; |
| 304 | |
| 305 | if (sscanf(buf, "%u %u", &x, &y) != 2 || !y) |
| 306 | return -EINVAL; |
| 307 | |
| 308 | spin_lock(>->gt_spin); |
| 309 | gt->gt_quota_scale_num = x; |
| 310 | gt->gt_quota_scale_den = y; |
| 311 | spin_unlock(>->gt_spin); |
| 312 | return len; |
| 313 | } |
| 314 | |
| 315 | static ssize_t tune_set(struct gfs2_sbd *sdp, unsigned int *field, |
| 316 | int check_zero, const char *buf, size_t len) |
| 317 | { |
| 318 | struct gfs2_tune *gt = &sdp->sd_tune; |
| 319 | unsigned int x; |
| 320 | |
| 321 | if (!capable(CAP_SYS_ADMIN)) |
| 322 | return -EACCES; |
| 323 | |
| 324 | x = simple_strtoul(buf, NULL, 0); |
| 325 | |
| 326 | if (check_zero && !x) |
| 327 | return -EINVAL; |
| 328 | |
| 329 | spin_lock(>->gt_spin); |
| 330 | *field = x; |
| 331 | spin_unlock(>->gt_spin); |
| 332 | return len; |
| 333 | } |
| 334 | |
| 335 | struct tune_attr { |
| 336 | struct attribute attr; |
| 337 | ssize_t (*show)(struct gfs2_sbd *, char *); |
| 338 | ssize_t (*store)(struct gfs2_sbd *, const char *, size_t); |
| 339 | }; |
| 340 | |
| 341 | #define TUNE_ATTR_3(name, show, store) \ |
| 342 | static struct tune_attr tune_attr_##name = __ATTR(name, 0644, show, store) |
| 343 | |
| 344 | #define TUNE_ATTR_2(name, store) \ |
| 345 | static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \ |
| 346 | { \ |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 347 | return snprintf(buf, PAGE_SIZE, "%u\n", sdp->sd_tune.gt_##name); \ |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 348 | } \ |
| 349 | TUNE_ATTR_3(name, name##_show, store) |
| 350 | |
| 351 | #define TUNE_ATTR(name, check_zero) \ |
| 352 | static ssize_t name##_store(struct gfs2_sbd *sdp, const char *buf, size_t len)\ |
| 353 | { \ |
| 354 | return tune_set(sdp, &sdp->sd_tune.gt_##name, check_zero, buf, len); \ |
| 355 | } \ |
| 356 | TUNE_ATTR_2(name, name##_store) |
| 357 | |
| 358 | #define TUNE_ATTR_DAEMON(name, process) \ |
| 359 | static ssize_t name##_store(struct gfs2_sbd *sdp, const char *buf, size_t len)\ |
| 360 | { \ |
| 361 | ssize_t r = tune_set(sdp, &sdp->sd_tune.gt_##name, 1, buf, len); \ |
| 362 | wake_up_process(sdp->sd_##process); \ |
| 363 | return r; \ |
| 364 | } \ |
| 365 | TUNE_ATTR_2(name, name##_store) |
| 366 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 367 | TUNE_ATTR(incore_log_blocks, 0); |
| 368 | TUNE_ATTR(log_flush_secs, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 369 | TUNE_ATTR(quota_warn_period, 0); |
| 370 | TUNE_ATTR(quota_quantum, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 371 | TUNE_ATTR(max_readahead, 0); |
| 372 | TUNE_ATTR(complain_secs, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 373 | TUNE_ATTR(statfs_slow, 0); |
| 374 | TUNE_ATTR(new_files_jdata, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 375 | TUNE_ATTR(quota_simul_sync, 1); |
| 376 | TUNE_ATTR(quota_cache_secs, 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 377 | TUNE_ATTR(stall_secs, 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 378 | TUNE_ATTR(statfs_quantum, 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 379 | TUNE_ATTR_DAEMON(recoverd_secs, recoverd_process); |
| 380 | TUNE_ATTR_DAEMON(logd_secs, logd_process); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 381 | TUNE_ATTR_3(quota_scale, quota_scale_show, quota_scale_store); |
| 382 | |
| 383 | static struct attribute *tune_attrs[] = { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 384 | &tune_attr_incore_log_blocks.attr, |
| 385 | &tune_attr_log_flush_secs.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 386 | &tune_attr_quota_warn_period.attr, |
| 387 | &tune_attr_quota_quantum.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 388 | &tune_attr_max_readahead.attr, |
| 389 | &tune_attr_complain_secs.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 390 | &tune_attr_statfs_slow.attr, |
| 391 | &tune_attr_quota_simul_sync.attr, |
| 392 | &tune_attr_quota_cache_secs.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 393 | &tune_attr_stall_secs.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 394 | &tune_attr_statfs_quantum.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 395 | &tune_attr_recoverd_secs.attr, |
| 396 | &tune_attr_logd_secs.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 397 | &tune_attr_quota_scale.attr, |
| 398 | &tune_attr_new_files_jdata.attr, |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 399 | NULL, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 400 | }; |
| 401 | |
| 402 | static struct attribute_group lockstruct_group = { |
| 403 | .name = "lockstruct", |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 404 | .attrs = lockstruct_attrs, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 405 | }; |
| 406 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 407 | static struct attribute_group args_group = { |
| 408 | .name = "args", |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 409 | .attrs = args_attrs, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 410 | }; |
| 411 | |
| 412 | static struct attribute_group tune_group = { |
| 413 | .name = "tune", |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 414 | .attrs = tune_attrs, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 415 | }; |
| 416 | |
| 417 | int gfs2_sys_fs_add(struct gfs2_sbd *sdp) |
| 418 | { |
| 419 | int error; |
| 420 | |
Greg Kroah-Hartman | 9bec101 | 2007-10-29 20:13:17 +0100 | [diff] [blame] | 421 | sdp->sd_kobj.kset = gfs2_kset; |
Greg Kroah-Hartman | 901195e | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 422 | error = kobject_init_and_add(&sdp->sd_kobj, &gfs2_ktype, NULL, |
| 423 | "%s", sdp->sd_table_name); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 424 | if (error) |
| 425 | goto fail; |
| 426 | |
| 427 | error = sysfs_create_group(&sdp->sd_kobj, &lockstruct_group); |
| 428 | if (error) |
| 429 | goto fail_reg; |
| 430 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 431 | error = sysfs_create_group(&sdp->sd_kobj, &args_group); |
| 432 | if (error) |
Steven Whitehouse | 97cc102 | 2008-11-20 13:39:47 +0000 | [diff] [blame] | 433 | goto fail_lockstruct; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 434 | |
| 435 | error = sysfs_create_group(&sdp->sd_kobj, &tune_group); |
| 436 | if (error) |
| 437 | goto fail_args; |
| 438 | |
Greg Kroah-Hartman | 901195e | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 439 | kobject_uevent(&sdp->sd_kobj, KOBJ_ADD); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 440 | return 0; |
| 441 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 442 | fail_args: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 443 | sysfs_remove_group(&sdp->sd_kobj, &args_group); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 444 | fail_lockstruct: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 445 | sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 446 | fail_reg: |
Greg Kroah-Hartman | 197b12d | 2007-12-20 08:13:05 -0800 | [diff] [blame] | 447 | kobject_put(&sdp->sd_kobj); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 448 | fail: |
David Teigland | 65952fb | 2006-09-15 13:09:11 -0500 | [diff] [blame] | 449 | fs_err(sdp, "error %d adding sysfs files", error); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 450 | return error; |
| 451 | } |
| 452 | |
| 453 | void gfs2_sys_fs_del(struct gfs2_sbd *sdp) |
| 454 | { |
| 455 | sysfs_remove_group(&sdp->sd_kobj, &tune_group); |
| 456 | sysfs_remove_group(&sdp->sd_kobj, &args_group); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 457 | sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group); |
Greg Kroah-Hartman | 197b12d | 2007-12-20 08:13:05 -0800 | [diff] [blame] | 458 | kobject_put(&sdp->sd_kobj); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 459 | } |
| 460 | |
Steven Whitehouse | fdd1062 | 2008-11-26 10:26:38 +0000 | [diff] [blame] | 461 | static int gfs2_uevent(struct kset *kset, struct kobject *kobj, |
| 462 | struct kobj_uevent_env *env) |
| 463 | { |
| 464 | struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj); |
| 465 | add_uevent_var(env, "LOCKTABLE=%s", sdp->sd_table_name); |
| 466 | add_uevent_var(env, "LOCKPROTO=%s", sdp->sd_proto_name); |
| 467 | return 0; |
| 468 | } |
| 469 | |
| 470 | static struct kset_uevent_ops gfs2_uevent_ops = { |
| 471 | .uevent = gfs2_uevent, |
| 472 | }; |
| 473 | |
| 474 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 475 | int gfs2_sys_init(void) |
| 476 | { |
Steven Whitehouse | fdd1062 | 2008-11-26 10:26:38 +0000 | [diff] [blame] | 477 | gfs2_kset = kset_create_and_add("gfs2", &gfs2_uevent_ops, fs_kobj); |
Greg Kroah-Hartman | 9bec101 | 2007-10-29 20:13:17 +0100 | [diff] [blame] | 478 | if (!gfs2_kset) |
| 479 | return -ENOMEM; |
| 480 | return 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | void gfs2_sys_uninit(void) |
| 484 | { |
Greg Kroah-Hartman | 9bec101 | 2007-10-29 20:13:17 +0100 | [diff] [blame] | 485 | kset_unregister(gfs2_kset); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 486 | } |
| 487 | |