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