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> |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 17 | #include <asm/uaccess.h> |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 18 | #include <linux/gfs2_ondisk.h> |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 19 | |
| 20 | #include "gfs2.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 21 | #include "incore.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 22 | #include "sys.h" |
| 23 | #include "super.h" |
| 24 | #include "glock.h" |
| 25 | #include "quota.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 26 | #include "util.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 27 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 28 | static ssize_t id_show(struct gfs2_sbd *sdp, char *buf) |
| 29 | { |
Bob Peterson | c7227e46 | 2007-11-02 09:37:15 -0500 | [diff] [blame] | 30 | return snprintf(buf, PAGE_SIZE, "%u:%u\n", |
| 31 | MAJOR(sdp->sd_vfs->s_dev), MINOR(sdp->sd_vfs->s_dev)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | static ssize_t fsname_show(struct gfs2_sbd *sdp, char *buf) |
| 35 | { |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 36 | return snprintf(buf, PAGE_SIZE, "%s\n", sdp->sd_fsname); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 37 | } |
| 38 | |
Steven Whitehouse | 02e3cc7 | 2009-02-10 13:48:30 +0000 | [diff] [blame^] | 39 | static int gfs2_uuid_valid(const u8 *uuid) |
| 40 | { |
| 41 | int i; |
| 42 | |
| 43 | for (i = 0; i < 16; i++) { |
| 44 | if (uuid[i]) |
| 45 | return 1; |
| 46 | } |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | static ssize_t uuid_show(struct gfs2_sbd *sdp, char *buf) |
| 51 | { |
| 52 | const u8 *uuid = sdp->sd_sb.sb_uuid; |
| 53 | buf[0] = '\0'; |
| 54 | if (!gfs2_uuid_valid(uuid)) |
| 55 | return 0; |
| 56 | return snprintf(buf, PAGE_SIZE, "%02X%02X%02X%02X-%02X%02X-" |
| 57 | "%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X\n", |
| 58 | uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], |
| 59 | uuid[6], uuid[7], uuid[8], uuid[9], uuid[10], uuid[11], |
| 60 | uuid[12], uuid[13], uuid[14], uuid[15]); |
| 61 | } |
| 62 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 63 | static ssize_t freeze_show(struct gfs2_sbd *sdp, char *buf) |
| 64 | { |
| 65 | unsigned int count; |
| 66 | |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 67 | mutex_lock(&sdp->sd_freeze_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 68 | count = sdp->sd_freeze_count; |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 69 | mutex_unlock(&sdp->sd_freeze_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 70 | |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 71 | return snprintf(buf, PAGE_SIZE, "%u\n", count); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | static ssize_t freeze_store(struct gfs2_sbd *sdp, const char *buf, size_t len) |
| 75 | { |
| 76 | ssize_t ret = len; |
| 77 | int error = 0; |
| 78 | int n = simple_strtol(buf, NULL, 0); |
| 79 | |
| 80 | if (!capable(CAP_SYS_ADMIN)) |
| 81 | return -EACCES; |
| 82 | |
| 83 | switch (n) { |
| 84 | case 0: |
| 85 | gfs2_unfreeze_fs(sdp); |
| 86 | break; |
| 87 | case 1: |
| 88 | error = gfs2_freeze_fs(sdp); |
| 89 | break; |
| 90 | default: |
| 91 | ret = -EINVAL; |
| 92 | } |
| 93 | |
| 94 | if (error) |
| 95 | fs_warn(sdp, "freeze %d error %d", n, error); |
| 96 | |
| 97 | return ret; |
| 98 | } |
| 99 | |
| 100 | static ssize_t withdraw_show(struct gfs2_sbd *sdp, char *buf) |
| 101 | { |
| 102 | unsigned int b = test_bit(SDF_SHUTDOWN, &sdp->sd_flags); |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 103 | return snprintf(buf, PAGE_SIZE, "%u\n", b); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | static ssize_t withdraw_store(struct gfs2_sbd *sdp, const char *buf, size_t len) |
| 107 | { |
| 108 | if (!capable(CAP_SYS_ADMIN)) |
| 109 | return -EACCES; |
| 110 | |
| 111 | if (simple_strtol(buf, NULL, 0) != 1) |
| 112 | return -EINVAL; |
| 113 | |
| 114 | gfs2_lm_withdraw(sdp, |
| 115 | "GFS2: fsid=%s: withdrawing from cluster at user's request\n", |
| 116 | sdp->sd_fsname); |
| 117 | return len; |
| 118 | } |
| 119 | |
| 120 | static ssize_t statfs_sync_store(struct gfs2_sbd *sdp, const char *buf, |
| 121 | size_t len) |
| 122 | { |
| 123 | if (!capable(CAP_SYS_ADMIN)) |
| 124 | return -EACCES; |
| 125 | |
| 126 | if (simple_strtol(buf, NULL, 0) != 1) |
| 127 | return -EINVAL; |
| 128 | |
| 129 | gfs2_statfs_sync(sdp); |
| 130 | return len; |
| 131 | } |
| 132 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 133 | static ssize_t quota_sync_store(struct gfs2_sbd *sdp, const char *buf, |
| 134 | size_t len) |
| 135 | { |
| 136 | if (!capable(CAP_SYS_ADMIN)) |
| 137 | return -EACCES; |
| 138 | |
| 139 | if (simple_strtol(buf, NULL, 0) != 1) |
| 140 | return -EINVAL; |
| 141 | |
| 142 | gfs2_quota_sync(sdp); |
| 143 | return len; |
| 144 | } |
| 145 | |
| 146 | static ssize_t quota_refresh_user_store(struct gfs2_sbd *sdp, const char *buf, |
| 147 | size_t len) |
| 148 | { |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 149 | u32 id; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 150 | |
| 151 | if (!capable(CAP_SYS_ADMIN)) |
| 152 | return -EACCES; |
| 153 | |
| 154 | id = simple_strtoul(buf, NULL, 0); |
| 155 | |
| 156 | gfs2_quota_refresh(sdp, 1, id); |
| 157 | return len; |
| 158 | } |
| 159 | |
| 160 | static ssize_t quota_refresh_group_store(struct gfs2_sbd *sdp, const char *buf, |
| 161 | size_t len) |
| 162 | { |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 163 | u32 id; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 164 | |
| 165 | if (!capable(CAP_SYS_ADMIN)) |
| 166 | return -EACCES; |
| 167 | |
| 168 | id = simple_strtoul(buf, NULL, 0); |
| 169 | |
| 170 | gfs2_quota_refresh(sdp, 0, id); |
| 171 | return len; |
| 172 | } |
| 173 | |
| 174 | struct gfs2_attr { |
| 175 | struct attribute attr; |
| 176 | ssize_t (*show)(struct gfs2_sbd *, char *); |
| 177 | ssize_t (*store)(struct gfs2_sbd *, const char *, size_t); |
| 178 | }; |
| 179 | |
| 180 | #define GFS2_ATTR(name, mode, show, store) \ |
| 181 | static struct gfs2_attr gfs2_attr_##name = __ATTR(name, mode, show, store) |
| 182 | |
| 183 | GFS2_ATTR(id, 0444, id_show, NULL); |
| 184 | GFS2_ATTR(fsname, 0444, fsname_show, NULL); |
Steven Whitehouse | 02e3cc7 | 2009-02-10 13:48:30 +0000 | [diff] [blame^] | 185 | GFS2_ATTR(uuid, 0444, uuid_show, NULL); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 186 | GFS2_ATTR(freeze, 0644, freeze_show, freeze_store); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 187 | GFS2_ATTR(withdraw, 0644, withdraw_show, withdraw_store); |
| 188 | GFS2_ATTR(statfs_sync, 0200, NULL, statfs_sync_store); |
| 189 | GFS2_ATTR(quota_sync, 0200, NULL, quota_sync_store); |
| 190 | GFS2_ATTR(quota_refresh_user, 0200, NULL, quota_refresh_user_store); |
| 191 | GFS2_ATTR(quota_refresh_group, 0200, NULL, quota_refresh_group_store); |
| 192 | |
| 193 | static struct attribute *gfs2_attrs[] = { |
| 194 | &gfs2_attr_id.attr, |
| 195 | &gfs2_attr_fsname.attr, |
Steven Whitehouse | 02e3cc7 | 2009-02-10 13:48:30 +0000 | [diff] [blame^] | 196 | &gfs2_attr_uuid.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 197 | &gfs2_attr_freeze.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 198 | &gfs2_attr_withdraw.attr, |
| 199 | &gfs2_attr_statfs_sync.attr, |
| 200 | &gfs2_attr_quota_sync.attr, |
| 201 | &gfs2_attr_quota_refresh_user.attr, |
| 202 | &gfs2_attr_quota_refresh_group.attr, |
| 203 | NULL, |
| 204 | }; |
| 205 | |
| 206 | static ssize_t gfs2_attr_show(struct kobject *kobj, struct attribute *attr, |
| 207 | char *buf) |
| 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->show ? a->show(sdp, buf) : 0; |
| 212 | } |
| 213 | |
| 214 | static ssize_t gfs2_attr_store(struct kobject *kobj, struct attribute *attr, |
| 215 | const char *buf, size_t len) |
| 216 | { |
| 217 | struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj); |
| 218 | struct gfs2_attr *a = container_of(attr, struct gfs2_attr, attr); |
| 219 | return a->store ? a->store(sdp, buf, len) : len; |
| 220 | } |
| 221 | |
| 222 | static struct sysfs_ops gfs2_attr_ops = { |
| 223 | .show = gfs2_attr_show, |
| 224 | .store = gfs2_attr_store, |
| 225 | }; |
| 226 | |
| 227 | static struct kobj_type gfs2_ktype = { |
| 228 | .default_attrs = gfs2_attrs, |
| 229 | .sysfs_ops = &gfs2_attr_ops, |
| 230 | }; |
| 231 | |
Greg Kroah-Hartman | 9bec101 | 2007-10-29 20:13:17 +0100 | [diff] [blame] | 232 | static struct kset *gfs2_kset; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 233 | |
| 234 | /* |
| 235 | * display struct lm_lockstruct fields |
| 236 | */ |
| 237 | |
| 238 | struct lockstruct_attr { |
| 239 | struct attribute attr; |
| 240 | ssize_t (*show)(struct gfs2_sbd *, char *); |
| 241 | }; |
| 242 | |
| 243 | #define LOCKSTRUCT_ATTR(name, fmt) \ |
| 244 | static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \ |
| 245 | { \ |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 246 | return snprintf(buf, PAGE_SIZE, fmt, sdp->sd_lockstruct.ls_##name); \ |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 247 | } \ |
| 248 | static struct lockstruct_attr lockstruct_attr_##name = __ATTR_RO(name) |
| 249 | |
| 250 | LOCKSTRUCT_ATTR(jid, "%u\n"); |
| 251 | LOCKSTRUCT_ATTR(first, "%u\n"); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 252 | |
| 253 | static struct attribute *lockstruct_attrs[] = { |
| 254 | &lockstruct_attr_jid.attr, |
| 255 | &lockstruct_attr_first.attr, |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 256 | NULL, |
| 257 | }; |
| 258 | |
| 259 | /* |
| 260 | * lock_module. Originally from lock_dlm |
| 261 | */ |
| 262 | |
| 263 | static ssize_t proto_name_show(struct gfs2_sbd *sdp, char *buf) |
| 264 | { |
| 265 | const struct lm_lockops *ops = sdp->sd_lockstruct.ls_ops; |
| 266 | return sprintf(buf, "%s\n", ops->lm_proto_name); |
| 267 | } |
| 268 | |
| 269 | static ssize_t block_show(struct gfs2_sbd *sdp, char *buf) |
| 270 | { |
| 271 | struct lm_lockstruct *ls = &sdp->sd_lockstruct; |
| 272 | ssize_t ret; |
| 273 | int val = 0; |
| 274 | |
| 275 | if (test_bit(DFL_BLOCK_LOCKS, &ls->ls_flags)) |
| 276 | val = 1; |
| 277 | ret = sprintf(buf, "%d\n", val); |
| 278 | return ret; |
| 279 | } |
| 280 | |
| 281 | static ssize_t block_store(struct gfs2_sbd *sdp, const char *buf, size_t len) |
| 282 | { |
| 283 | struct lm_lockstruct *ls = &sdp->sd_lockstruct; |
| 284 | ssize_t ret = len; |
| 285 | int val; |
| 286 | |
| 287 | val = simple_strtol(buf, NULL, 0); |
| 288 | |
| 289 | if (val == 1) |
| 290 | set_bit(DFL_BLOCK_LOCKS, &ls->ls_flags); |
| 291 | else if (val == 0) { |
| 292 | clear_bit(DFL_BLOCK_LOCKS, &ls->ls_flags); |
| 293 | smp_mb__after_clear_bit(); |
| 294 | gfs2_glock_thaw(sdp); |
| 295 | } else { |
| 296 | ret = -EINVAL; |
| 297 | } |
| 298 | return ret; |
| 299 | } |
| 300 | |
| 301 | static ssize_t lkid_show(struct gfs2_sbd *sdp, char *buf) |
| 302 | { |
| 303 | struct lm_lockstruct *ls = &sdp->sd_lockstruct; |
| 304 | return sprintf(buf, "%u\n", ls->ls_id); |
| 305 | } |
| 306 | |
| 307 | static ssize_t lkfirst_show(struct gfs2_sbd *sdp, char *buf) |
| 308 | { |
| 309 | struct lm_lockstruct *ls = &sdp->sd_lockstruct; |
| 310 | return sprintf(buf, "%d\n", ls->ls_first); |
| 311 | } |
| 312 | |
| 313 | static ssize_t first_done_show(struct gfs2_sbd *sdp, char *buf) |
| 314 | { |
| 315 | struct lm_lockstruct *ls = &sdp->sd_lockstruct; |
| 316 | return sprintf(buf, "%d\n", ls->ls_first_done); |
| 317 | } |
| 318 | |
| 319 | static ssize_t recover_show(struct gfs2_sbd *sdp, char *buf) |
| 320 | { |
| 321 | struct lm_lockstruct *ls = &sdp->sd_lockstruct; |
| 322 | return sprintf(buf, "%d\n", ls->ls_recover_jid); |
| 323 | } |
| 324 | |
| 325 | static void gfs2_jdesc_make_dirty(struct gfs2_sbd *sdp, unsigned int jid) |
| 326 | { |
| 327 | struct gfs2_jdesc *jd; |
| 328 | |
| 329 | spin_lock(&sdp->sd_jindex_spin); |
| 330 | list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) { |
| 331 | if (jd->jd_jid != jid) |
| 332 | continue; |
| 333 | jd->jd_dirty = 1; |
| 334 | break; |
| 335 | } |
| 336 | spin_unlock(&sdp->sd_jindex_spin); |
| 337 | } |
| 338 | |
| 339 | static ssize_t recover_store(struct gfs2_sbd *sdp, const char *buf, size_t len) |
| 340 | { |
| 341 | struct lm_lockstruct *ls = &sdp->sd_lockstruct; |
| 342 | ls->ls_recover_jid = simple_strtol(buf, NULL, 0); |
| 343 | gfs2_jdesc_make_dirty(sdp, ls->ls_recover_jid); |
| 344 | if (sdp->sd_recoverd_process) |
| 345 | wake_up_process(sdp->sd_recoverd_process); |
| 346 | return len; |
| 347 | } |
| 348 | |
| 349 | static ssize_t recover_done_show(struct gfs2_sbd *sdp, char *buf) |
| 350 | { |
| 351 | struct lm_lockstruct *ls = &sdp->sd_lockstruct; |
| 352 | return sprintf(buf, "%d\n", ls->ls_recover_jid_done); |
| 353 | } |
| 354 | |
| 355 | static ssize_t recover_status_show(struct gfs2_sbd *sdp, char *buf) |
| 356 | { |
| 357 | struct lm_lockstruct *ls = &sdp->sd_lockstruct; |
| 358 | return sprintf(buf, "%d\n", ls->ls_recover_jid_status); |
| 359 | } |
| 360 | |
| 361 | struct gdlm_attr { |
| 362 | struct attribute attr; |
| 363 | ssize_t (*show)(struct gfs2_sbd *sdp, char *); |
| 364 | ssize_t (*store)(struct gfs2_sbd *sdp, const char *, size_t); |
| 365 | }; |
| 366 | |
| 367 | #define GDLM_ATTR(_name,_mode,_show,_store) \ |
| 368 | static struct gdlm_attr gdlm_attr_##_name = __ATTR(_name,_mode,_show,_store) |
| 369 | |
| 370 | GDLM_ATTR(proto_name, 0444, proto_name_show, NULL); |
| 371 | GDLM_ATTR(block, 0644, block_show, block_store); |
| 372 | GDLM_ATTR(withdraw, 0644, withdraw_show, withdraw_store); |
| 373 | GDLM_ATTR(id, 0444, lkid_show, NULL); |
| 374 | GDLM_ATTR(first, 0444, lkfirst_show, NULL); |
| 375 | GDLM_ATTR(first_done, 0444, first_done_show, NULL); |
| 376 | GDLM_ATTR(recover, 0644, recover_show, recover_store); |
| 377 | GDLM_ATTR(recover_done, 0444, recover_done_show, NULL); |
| 378 | GDLM_ATTR(recover_status, 0444, recover_status_show, NULL); |
| 379 | |
| 380 | static struct attribute *lock_module_attrs[] = { |
| 381 | &gdlm_attr_proto_name.attr, |
| 382 | &gdlm_attr_block.attr, |
| 383 | &gdlm_attr_withdraw.attr, |
| 384 | &gdlm_attr_id.attr, |
| 385 | &lockstruct_attr_jid.attr, |
| 386 | &gdlm_attr_first.attr, |
| 387 | &gdlm_attr_first_done.attr, |
| 388 | &gdlm_attr_recover.attr, |
| 389 | &gdlm_attr_recover_done.attr, |
| 390 | &gdlm_attr_recover_status.attr, |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 391 | NULL, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 392 | }; |
| 393 | |
| 394 | /* |
| 395 | * display struct gfs2_args fields |
| 396 | */ |
| 397 | |
| 398 | struct args_attr { |
| 399 | struct attribute attr; |
| 400 | ssize_t (*show)(struct gfs2_sbd *, char *); |
| 401 | }; |
| 402 | |
| 403 | #define ARGS_ATTR(name, fmt) \ |
| 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, fmt, sdp->sd_args.ar_##name); \ |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 407 | } \ |
| 408 | static struct args_attr args_attr_##name = __ATTR_RO(name) |
| 409 | |
| 410 | ARGS_ATTR(lockproto, "%s\n"); |
| 411 | ARGS_ATTR(locktable, "%s\n"); |
| 412 | ARGS_ATTR(hostdata, "%s\n"); |
| 413 | ARGS_ATTR(spectator, "%d\n"); |
| 414 | ARGS_ATTR(ignore_local_fs, "%d\n"); |
| 415 | ARGS_ATTR(localcaching, "%d\n"); |
| 416 | ARGS_ATTR(localflocks, "%d\n"); |
| 417 | ARGS_ATTR(debug, "%d\n"); |
| 418 | ARGS_ATTR(upgrade, "%d\n"); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 419 | ARGS_ATTR(posix_acl, "%d\n"); |
| 420 | ARGS_ATTR(quota, "%u\n"); |
| 421 | ARGS_ATTR(suiddir, "%d\n"); |
| 422 | ARGS_ATTR(data, "%d\n"); |
| 423 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 424 | static struct attribute *args_attrs[] = { |
| 425 | &args_attr_lockproto.attr, |
| 426 | &args_attr_locktable.attr, |
| 427 | &args_attr_hostdata.attr, |
| 428 | &args_attr_spectator.attr, |
| 429 | &args_attr_ignore_local_fs.attr, |
| 430 | &args_attr_localcaching.attr, |
| 431 | &args_attr_localflocks.attr, |
| 432 | &args_attr_debug.attr, |
| 433 | &args_attr_upgrade.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 434 | &args_attr_posix_acl.attr, |
| 435 | &args_attr_quota.attr, |
| 436 | &args_attr_suiddir.attr, |
| 437 | &args_attr_data.attr, |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 438 | NULL, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 439 | }; |
| 440 | |
| 441 | /* |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 442 | * get and set struct gfs2_tune fields |
| 443 | */ |
| 444 | |
| 445 | static ssize_t quota_scale_show(struct gfs2_sbd *sdp, char *buf) |
| 446 | { |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 447 | return snprintf(buf, PAGE_SIZE, "%u %u\n", |
| 448 | sdp->sd_tune.gt_quota_scale_num, |
| 449 | sdp->sd_tune.gt_quota_scale_den); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | static ssize_t quota_scale_store(struct gfs2_sbd *sdp, const char *buf, |
| 453 | size_t len) |
| 454 | { |
| 455 | struct gfs2_tune *gt = &sdp->sd_tune; |
| 456 | unsigned int x, y; |
| 457 | |
| 458 | if (!capable(CAP_SYS_ADMIN)) |
| 459 | return -EACCES; |
| 460 | |
| 461 | if (sscanf(buf, "%u %u", &x, &y) != 2 || !y) |
| 462 | return -EINVAL; |
| 463 | |
| 464 | spin_lock(>->gt_spin); |
| 465 | gt->gt_quota_scale_num = x; |
| 466 | gt->gt_quota_scale_den = y; |
| 467 | spin_unlock(>->gt_spin); |
| 468 | return len; |
| 469 | } |
| 470 | |
| 471 | static ssize_t tune_set(struct gfs2_sbd *sdp, unsigned int *field, |
| 472 | int check_zero, const char *buf, size_t len) |
| 473 | { |
| 474 | struct gfs2_tune *gt = &sdp->sd_tune; |
| 475 | unsigned int x; |
| 476 | |
| 477 | if (!capable(CAP_SYS_ADMIN)) |
| 478 | return -EACCES; |
| 479 | |
| 480 | x = simple_strtoul(buf, NULL, 0); |
| 481 | |
| 482 | if (check_zero && !x) |
| 483 | return -EINVAL; |
| 484 | |
| 485 | spin_lock(>->gt_spin); |
| 486 | *field = x; |
| 487 | spin_unlock(>->gt_spin); |
| 488 | return len; |
| 489 | } |
| 490 | |
| 491 | struct tune_attr { |
| 492 | struct attribute attr; |
| 493 | ssize_t (*show)(struct gfs2_sbd *, char *); |
| 494 | ssize_t (*store)(struct gfs2_sbd *, const char *, size_t); |
| 495 | }; |
| 496 | |
| 497 | #define TUNE_ATTR_3(name, show, store) \ |
| 498 | static struct tune_attr tune_attr_##name = __ATTR(name, 0644, show, store) |
| 499 | |
| 500 | #define TUNE_ATTR_2(name, store) \ |
| 501 | static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \ |
| 502 | { \ |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 503 | return snprintf(buf, PAGE_SIZE, "%u\n", sdp->sd_tune.gt_##name); \ |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 504 | } \ |
| 505 | TUNE_ATTR_3(name, name##_show, store) |
| 506 | |
| 507 | #define TUNE_ATTR(name, check_zero) \ |
| 508 | static ssize_t name##_store(struct gfs2_sbd *sdp, const char *buf, size_t len)\ |
| 509 | { \ |
| 510 | return tune_set(sdp, &sdp->sd_tune.gt_##name, check_zero, buf, len); \ |
| 511 | } \ |
| 512 | TUNE_ATTR_2(name, name##_store) |
| 513 | |
| 514 | #define TUNE_ATTR_DAEMON(name, process) \ |
| 515 | static ssize_t name##_store(struct gfs2_sbd *sdp, const char *buf, size_t len)\ |
| 516 | { \ |
| 517 | ssize_t r = tune_set(sdp, &sdp->sd_tune.gt_##name, 1, buf, len); \ |
| 518 | wake_up_process(sdp->sd_##process); \ |
| 519 | return r; \ |
| 520 | } \ |
| 521 | TUNE_ATTR_2(name, name##_store) |
| 522 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 523 | TUNE_ATTR(incore_log_blocks, 0); |
| 524 | TUNE_ATTR(log_flush_secs, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 525 | TUNE_ATTR(quota_warn_period, 0); |
| 526 | TUNE_ATTR(quota_quantum, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 527 | TUNE_ATTR(max_readahead, 0); |
| 528 | TUNE_ATTR(complain_secs, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 529 | TUNE_ATTR(statfs_slow, 0); |
| 530 | TUNE_ATTR(new_files_jdata, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 531 | TUNE_ATTR(quota_simul_sync, 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 532 | TUNE_ATTR(stall_secs, 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 533 | TUNE_ATTR(statfs_quantum, 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 534 | TUNE_ATTR_DAEMON(recoverd_secs, recoverd_process); |
| 535 | TUNE_ATTR_DAEMON(logd_secs, logd_process); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 536 | TUNE_ATTR_3(quota_scale, quota_scale_show, quota_scale_store); |
| 537 | |
| 538 | static struct attribute *tune_attrs[] = { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 539 | &tune_attr_incore_log_blocks.attr, |
| 540 | &tune_attr_log_flush_secs.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 541 | &tune_attr_quota_warn_period.attr, |
| 542 | &tune_attr_quota_quantum.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 543 | &tune_attr_max_readahead.attr, |
| 544 | &tune_attr_complain_secs.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 545 | &tune_attr_statfs_slow.attr, |
| 546 | &tune_attr_quota_simul_sync.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 547 | &tune_attr_stall_secs.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 548 | &tune_attr_statfs_quantum.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 549 | &tune_attr_recoverd_secs.attr, |
| 550 | &tune_attr_logd_secs.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 551 | &tune_attr_quota_scale.attr, |
| 552 | &tune_attr_new_files_jdata.attr, |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 553 | NULL, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 554 | }; |
| 555 | |
| 556 | static struct attribute_group lockstruct_group = { |
| 557 | .name = "lockstruct", |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 558 | .attrs = lockstruct_attrs, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 559 | }; |
| 560 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 561 | static struct attribute_group args_group = { |
| 562 | .name = "args", |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 563 | .attrs = args_attrs, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 564 | }; |
| 565 | |
| 566 | static struct attribute_group tune_group = { |
| 567 | .name = "tune", |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 568 | .attrs = tune_attrs, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 569 | }; |
| 570 | |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 571 | static struct attribute_group lock_module_group = { |
| 572 | .name = "lock_module", |
| 573 | .attrs = lock_module_attrs, |
| 574 | }; |
| 575 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 576 | int gfs2_sys_fs_add(struct gfs2_sbd *sdp) |
| 577 | { |
| 578 | int error; |
| 579 | |
Greg Kroah-Hartman | 9bec101 | 2007-10-29 20:13:17 +0100 | [diff] [blame] | 580 | sdp->sd_kobj.kset = gfs2_kset; |
Greg Kroah-Hartman | 901195e | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 581 | error = kobject_init_and_add(&sdp->sd_kobj, &gfs2_ktype, NULL, |
| 582 | "%s", sdp->sd_table_name); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 583 | if (error) |
| 584 | goto fail; |
| 585 | |
| 586 | error = sysfs_create_group(&sdp->sd_kobj, &lockstruct_group); |
| 587 | if (error) |
| 588 | goto fail_reg; |
| 589 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 590 | error = sysfs_create_group(&sdp->sd_kobj, &args_group); |
| 591 | if (error) |
Steven Whitehouse | 97cc1025 | 2008-11-20 13:39:47 +0000 | [diff] [blame] | 592 | goto fail_lockstruct; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 593 | |
| 594 | error = sysfs_create_group(&sdp->sd_kobj, &tune_group); |
| 595 | if (error) |
| 596 | goto fail_args; |
| 597 | |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 598 | error = sysfs_create_group(&sdp->sd_kobj, &lock_module_group); |
| 599 | if (error) |
| 600 | goto fail_tune; |
| 601 | |
Greg Kroah-Hartman | 901195e | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 602 | kobject_uevent(&sdp->sd_kobj, KOBJ_ADD); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 603 | return 0; |
| 604 | |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 605 | fail_tune: |
| 606 | sysfs_remove_group(&sdp->sd_kobj, &tune_group); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 607 | fail_args: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 608 | sysfs_remove_group(&sdp->sd_kobj, &args_group); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 609 | fail_lockstruct: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 610 | sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 611 | fail_reg: |
Greg Kroah-Hartman | 197b12d | 2007-12-20 08:13:05 -0800 | [diff] [blame] | 612 | kobject_put(&sdp->sd_kobj); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 613 | fail: |
David Teigland | 65952fb | 2006-09-15 13:09:11 -0500 | [diff] [blame] | 614 | fs_err(sdp, "error %d adding sysfs files", error); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 615 | return error; |
| 616 | } |
| 617 | |
| 618 | void gfs2_sys_fs_del(struct gfs2_sbd *sdp) |
| 619 | { |
| 620 | sysfs_remove_group(&sdp->sd_kobj, &tune_group); |
| 621 | sysfs_remove_group(&sdp->sd_kobj, &args_group); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 622 | sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group); |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 623 | sysfs_remove_group(&sdp->sd_kobj, &lock_module_group); |
Greg Kroah-Hartman | 197b12d | 2007-12-20 08:13:05 -0800 | [diff] [blame] | 624 | kobject_put(&sdp->sd_kobj); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 625 | } |
| 626 | |
Steven Whitehouse | 02e3cc7 | 2009-02-10 13:48:30 +0000 | [diff] [blame^] | 627 | |
Steven Whitehouse | fdd1062e | 2008-11-26 10:26:38 +0000 | [diff] [blame] | 628 | static int gfs2_uevent(struct kset *kset, struct kobject *kobj, |
| 629 | struct kobj_uevent_env *env) |
| 630 | { |
| 631 | struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj); |
Steven Whitehouse | 02e3cc7 | 2009-02-10 13:48:30 +0000 | [diff] [blame^] | 632 | const u8 *uuid = sdp->sd_sb.sb_uuid; |
| 633 | |
Steven Whitehouse | fdd1062e | 2008-11-26 10:26:38 +0000 | [diff] [blame] | 634 | add_uevent_var(env, "LOCKTABLE=%s", sdp->sd_table_name); |
| 635 | add_uevent_var(env, "LOCKPROTO=%s", sdp->sd_proto_name); |
Steven Whitehouse | 02e3cc7 | 2009-02-10 13:48:30 +0000 | [diff] [blame^] | 636 | if (gfs2_uuid_valid(uuid)) { |
| 637 | add_uevent_var(env, "UUID=%02X%02X%02X%02X-%02X%02X-%02X%02X-" |
| 638 | "%02X%02X-%02X%02X%02X%02X%02X%02X", |
| 639 | uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], |
| 640 | uuid[5], uuid[6], uuid[7], uuid[8], uuid[9], |
| 641 | uuid[10], uuid[11], uuid[12], uuid[13], |
| 642 | uuid[14], uuid[15]); |
| 643 | } |
Steven Whitehouse | fdd1062e | 2008-11-26 10:26:38 +0000 | [diff] [blame] | 644 | return 0; |
| 645 | } |
| 646 | |
| 647 | static struct kset_uevent_ops gfs2_uevent_ops = { |
| 648 | .uevent = gfs2_uevent, |
| 649 | }; |
| 650 | |
| 651 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 652 | int gfs2_sys_init(void) |
| 653 | { |
Steven Whitehouse | fdd1062e | 2008-11-26 10:26:38 +0000 | [diff] [blame] | 654 | 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] | 655 | if (!gfs2_kset) |
| 656 | return -ENOMEM; |
| 657 | return 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | void gfs2_sys_uninit(void) |
| 661 | { |
Greg Kroah-Hartman | 9bec101 | 2007-10-29 20:13:17 +0100 | [diff] [blame] | 662 | kset_unregister(gfs2_kset); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 663 | } |
| 664 | |