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