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 | |
Joe Perches | d77d1b5 | 2014-03-06 12:10:45 -0800 | [diff] [blame] | 10 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 11 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 12 | #include <linux/sched.h> |
Ingo Molnar | 5b825c3 | 2017-02-02 17:54:15 +0100 | [diff] [blame] | 13 | #include <linux/cred.h> |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 14 | #include <linux/spinlock.h> |
| 15 | #include <linux/completion.h> |
| 16 | #include <linux/buffer_head.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/kobject.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 19 | #include <linux/uaccess.h> |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 20 | #include <linux/gfs2_ondisk.h> |
Steven Whitehouse | 31e54b0 | 2009-08-13 12:18:08 +0100 | [diff] [blame] | 21 | #include <linux/genhd.h> |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 22 | |
| 23 | #include "gfs2.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 24 | #include "incore.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 25 | #include "sys.h" |
| 26 | #include "super.h" |
| 27 | #include "glock.h" |
| 28 | #include "quota.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 29 | #include "util.h" |
Steven Whitehouse | 64d576b | 2009-02-12 13:31:58 +0000 | [diff] [blame] | 30 | #include "glops.h" |
Tejun Heo | 6ecd7c2 | 2010-07-20 22:09:02 +0200 | [diff] [blame] | 31 | #include "recovery.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 32 | |
Steven Whitehouse | 48c2b61 | 2009-05-13 14:49:48 +0100 | [diff] [blame] | 33 | struct gfs2_attr { |
| 34 | struct attribute attr; |
| 35 | ssize_t (*show)(struct gfs2_sbd *, char *); |
| 36 | ssize_t (*store)(struct gfs2_sbd *, const char *, size_t); |
| 37 | }; |
| 38 | |
| 39 | static ssize_t gfs2_attr_show(struct kobject *kobj, struct attribute *attr, |
| 40 | char *buf) |
| 41 | { |
| 42 | struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj); |
| 43 | struct gfs2_attr *a = container_of(attr, struct gfs2_attr, attr); |
| 44 | return a->show ? a->show(sdp, buf) : 0; |
| 45 | } |
| 46 | |
| 47 | static ssize_t gfs2_attr_store(struct kobject *kobj, struct attribute *attr, |
| 48 | const char *buf, size_t len) |
| 49 | { |
| 50 | struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj); |
| 51 | struct gfs2_attr *a = container_of(attr, struct gfs2_attr, attr); |
| 52 | return a->store ? a->store(sdp, buf, len) : len; |
| 53 | } |
| 54 | |
Emese Revfy | 52cf25d | 2010-01-19 02:58:23 +0100 | [diff] [blame] | 55 | static const struct sysfs_ops gfs2_attr_ops = { |
Steven Whitehouse | 48c2b61 | 2009-05-13 14:49:48 +0100 | [diff] [blame] | 56 | .show = gfs2_attr_show, |
| 57 | .store = gfs2_attr_store, |
| 58 | }; |
| 59 | |
| 60 | |
| 61 | static struct kset *gfs2_kset; |
| 62 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 63 | static ssize_t id_show(struct gfs2_sbd *sdp, char *buf) |
| 64 | { |
Bob Peterson | c7227e46 | 2007-11-02 09:37:15 -0500 | [diff] [blame] | 65 | return snprintf(buf, PAGE_SIZE, "%u:%u\n", |
| 66 | MAJOR(sdp->sd_vfs->s_dev), MINOR(sdp->sd_vfs->s_dev)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | static ssize_t fsname_show(struct gfs2_sbd *sdp, char *buf) |
| 70 | { |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 71 | return snprintf(buf, PAGE_SIZE, "%s\n", sdp->sd_fsname); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Steven Whitehouse | 02e3cc7 | 2009-02-10 13:48:30 +0000 | [diff] [blame] | 74 | static int gfs2_uuid_valid(const u8 *uuid) |
| 75 | { |
| 76 | int i; |
| 77 | |
| 78 | for (i = 0; i < 16; i++) { |
| 79 | if (uuid[i]) |
| 80 | return 1; |
| 81 | } |
| 82 | return 0; |
| 83 | } |
| 84 | |
| 85 | static ssize_t uuid_show(struct gfs2_sbd *sdp, char *buf) |
| 86 | { |
Steven Whitehouse | 32e471e | 2011-05-10 15:01:59 +0100 | [diff] [blame] | 87 | struct super_block *s = sdp->sd_vfs; |
| 88 | const u8 *uuid = s->s_uuid; |
Steven Whitehouse | 02e3cc7 | 2009-02-10 13:48:30 +0000 | [diff] [blame] | 89 | buf[0] = '\0'; |
| 90 | if (!gfs2_uuid_valid(uuid)) |
| 91 | return 0; |
Joe Perches | f0b34ae | 2009-12-14 18:01:13 -0800 | [diff] [blame] | 92 | return snprintf(buf, PAGE_SIZE, "%pUB\n", uuid); |
Steven Whitehouse | 02e3cc7 | 2009-02-10 13:48:30 +0000 | [diff] [blame] | 93 | } |
| 94 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 95 | static ssize_t freeze_show(struct gfs2_sbd *sdp, char *buf) |
| 96 | { |
Steven Whitehouse | d564053f | 2013-01-11 10:49:34 +0000 | [diff] [blame] | 97 | struct super_block *sb = sdp->sd_vfs; |
| 98 | int frozen = (sb->s_writers.frozen == SB_UNFROZEN) ? 0 : 1; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 99 | |
alex chen | 3566c96 | 2015-01-12 19:01:03 +0800 | [diff] [blame] | 100 | return snprintf(buf, PAGE_SIZE, "%d\n", frozen); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | static ssize_t freeze_store(struct gfs2_sbd *sdp, const char *buf, size_t len) |
| 104 | { |
Fabian Frederick | e50ead4 | 2015-05-05 13:23:22 -0500 | [diff] [blame] | 105 | int error, n; |
| 106 | |
| 107 | error = kstrtoint(buf, 0, &n); |
| 108 | if (error) |
| 109 | return error; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 110 | |
| 111 | if (!capable(CAP_SYS_ADMIN)) |
Zhao Hongjiang | 4173581 | 2013-02-20 13:13:55 +1100 | [diff] [blame] | 112 | return -EPERM; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 113 | |
| 114 | switch (n) { |
| 115 | case 0: |
Steven Whitehouse | d564053f | 2013-01-11 10:49:34 +0000 | [diff] [blame] | 116 | error = thaw_super(sdp->sd_vfs); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 117 | break; |
| 118 | case 1: |
Steven Whitehouse | d564053f | 2013-01-11 10:49:34 +0000 | [diff] [blame] | 119 | error = freeze_super(sdp->sd_vfs); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 120 | break; |
| 121 | default: |
Steven Whitehouse | d564053f | 2013-01-11 10:49:34 +0000 | [diff] [blame] | 122 | return -EINVAL; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Steven Whitehouse | d564053f | 2013-01-11 10:49:34 +0000 | [diff] [blame] | 125 | if (error) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 126 | fs_warn(sdp, "freeze %d error %d", n, error); |
Steven Whitehouse | d564053f | 2013-01-11 10:49:34 +0000 | [diff] [blame] | 127 | return error; |
| 128 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 129 | |
Steven Whitehouse | d564053f | 2013-01-11 10:49:34 +0000 | [diff] [blame] | 130 | return len; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | static ssize_t withdraw_show(struct gfs2_sbd *sdp, char *buf) |
| 134 | { |
| 135 | unsigned int b = test_bit(SDF_SHUTDOWN, &sdp->sd_flags); |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 136 | return snprintf(buf, PAGE_SIZE, "%u\n", b); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | static ssize_t withdraw_store(struct gfs2_sbd *sdp, const char *buf, size_t len) |
| 140 | { |
Fabian Frederick | e50ead4 | 2015-05-05 13:23:22 -0500 | [diff] [blame] | 141 | int error, val; |
| 142 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 143 | if (!capable(CAP_SYS_ADMIN)) |
Zhao Hongjiang | 4173581 | 2013-02-20 13:13:55 +1100 | [diff] [blame] | 144 | return -EPERM; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 145 | |
Fabian Frederick | e50ead4 | 2015-05-05 13:23:22 -0500 | [diff] [blame] | 146 | error = kstrtoint(buf, 0, &val); |
| 147 | if (error) |
| 148 | return error; |
| 149 | |
| 150 | if (val != 1) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 151 | return -EINVAL; |
| 152 | |
Joe Perches | cb94eb0 | 2014-03-06 12:17:21 -0800 | [diff] [blame] | 153 | gfs2_lm_withdraw(sdp, "withdrawing from cluster at user's request\n"); |
| 154 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 155 | return len; |
| 156 | } |
| 157 | |
| 158 | static ssize_t statfs_sync_store(struct gfs2_sbd *sdp, const char *buf, |
| 159 | size_t len) |
| 160 | { |
Fabian Frederick | e50ead4 | 2015-05-05 13:23:22 -0500 | [diff] [blame] | 161 | int error, val; |
| 162 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 163 | if (!capable(CAP_SYS_ADMIN)) |
Zhao Hongjiang | 4173581 | 2013-02-20 13:13:55 +1100 | [diff] [blame] | 164 | return -EPERM; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 165 | |
Fabian Frederick | e50ead4 | 2015-05-05 13:23:22 -0500 | [diff] [blame] | 166 | error = kstrtoint(buf, 0, &val); |
| 167 | if (error) |
| 168 | return error; |
| 169 | |
| 170 | if (val != 1) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 171 | return -EINVAL; |
| 172 | |
Steven Whitehouse | 8c42d63 | 2009-09-11 14:36:44 +0100 | [diff] [blame] | 173 | gfs2_statfs_sync(sdp->sd_vfs, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 174 | return len; |
| 175 | } |
| 176 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 177 | static ssize_t quota_sync_store(struct gfs2_sbd *sdp, const char *buf, |
| 178 | size_t len) |
| 179 | { |
Fabian Frederick | e50ead4 | 2015-05-05 13:23:22 -0500 | [diff] [blame] | 180 | int error, val; |
| 181 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 182 | if (!capable(CAP_SYS_ADMIN)) |
Zhao Hongjiang | 4173581 | 2013-02-20 13:13:55 +1100 | [diff] [blame] | 183 | return -EPERM; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 184 | |
Fabian Frederick | e50ead4 | 2015-05-05 13:23:22 -0500 | [diff] [blame] | 185 | error = kstrtoint(buf, 0, &val); |
| 186 | if (error) |
| 187 | return error; |
| 188 | |
| 189 | if (val != 1) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 190 | return -EINVAL; |
| 191 | |
Jan Kara | ceed172 | 2012-07-03 16:45:28 +0200 | [diff] [blame] | 192 | gfs2_quota_sync(sdp->sd_vfs, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 193 | return len; |
| 194 | } |
| 195 | |
| 196 | static ssize_t quota_refresh_user_store(struct gfs2_sbd *sdp, const char *buf, |
| 197 | size_t len) |
| 198 | { |
Eric W. Biederman | ed87dab | 2013-01-31 19:42:40 -0800 | [diff] [blame] | 199 | struct kqid qid; |
Steven Whitehouse | ea76233 | 2009-09-15 16:20:30 +0100 | [diff] [blame] | 200 | int error; |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 201 | u32 id; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 202 | |
| 203 | if (!capable(CAP_SYS_ADMIN)) |
Zhao Hongjiang | 4173581 | 2013-02-20 13:13:55 +1100 | [diff] [blame] | 204 | return -EPERM; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 205 | |
Fabian Frederick | e50ead4 | 2015-05-05 13:23:22 -0500 | [diff] [blame] | 206 | error = kstrtou32(buf, 0, &id); |
| 207 | if (error) |
| 208 | return error; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 209 | |
Eric W. Biederman | ed87dab | 2013-01-31 19:42:40 -0800 | [diff] [blame] | 210 | qid = make_kqid(current_user_ns(), USRQUOTA, id); |
| 211 | if (!qid_valid(qid)) |
| 212 | return -EINVAL; |
| 213 | |
| 214 | error = gfs2_quota_refresh(sdp, qid); |
Steven Whitehouse | ea76233 | 2009-09-15 16:20:30 +0100 | [diff] [blame] | 215 | return error ? error : len; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | static ssize_t quota_refresh_group_store(struct gfs2_sbd *sdp, const char *buf, |
| 219 | size_t len) |
| 220 | { |
Eric W. Biederman | ed87dab | 2013-01-31 19:42:40 -0800 | [diff] [blame] | 221 | struct kqid qid; |
Steven Whitehouse | ea76233 | 2009-09-15 16:20:30 +0100 | [diff] [blame] | 222 | int error; |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 223 | u32 id; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 224 | |
| 225 | if (!capable(CAP_SYS_ADMIN)) |
Zhao Hongjiang | 4173581 | 2013-02-20 13:13:55 +1100 | [diff] [blame] | 226 | return -EPERM; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 227 | |
Fabian Frederick | e50ead4 | 2015-05-05 13:23:22 -0500 | [diff] [blame] | 228 | error = kstrtou32(buf, 0, &id); |
| 229 | if (error) |
| 230 | return error; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 231 | |
Eric W. Biederman | ed87dab | 2013-01-31 19:42:40 -0800 | [diff] [blame] | 232 | qid = make_kqid(current_user_ns(), GRPQUOTA, id); |
| 233 | if (!qid_valid(qid)) |
| 234 | return -EINVAL; |
| 235 | |
| 236 | error = gfs2_quota_refresh(sdp, qid); |
Steven Whitehouse | ea76233 | 2009-09-15 16:20:30 +0100 | [diff] [blame] | 237 | return error ? error : len; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 238 | } |
| 239 | |
Steven Whitehouse | 64d576b | 2009-02-12 13:31:58 +0000 | [diff] [blame] | 240 | static ssize_t demote_rq_store(struct gfs2_sbd *sdp, const char *buf, size_t len) |
| 241 | { |
| 242 | struct gfs2_glock *gl; |
| 243 | const struct gfs2_glock_operations *glops; |
| 244 | unsigned int glmode; |
| 245 | unsigned int gltype; |
| 246 | unsigned long long glnum; |
| 247 | char mode[16]; |
| 248 | int rv; |
| 249 | |
| 250 | if (!capable(CAP_SYS_ADMIN)) |
Zhao Hongjiang | 4173581 | 2013-02-20 13:13:55 +1100 | [diff] [blame] | 251 | return -EPERM; |
Steven Whitehouse | 64d576b | 2009-02-12 13:31:58 +0000 | [diff] [blame] | 252 | |
| 253 | rv = sscanf(buf, "%u:%llu %15s", &gltype, &glnum, |
| 254 | mode); |
| 255 | if (rv != 3) |
| 256 | return -EINVAL; |
| 257 | |
| 258 | if (strcmp(mode, "EX") == 0) |
| 259 | glmode = LM_ST_UNLOCKED; |
| 260 | else if ((strcmp(mode, "CW") == 0) || (strcmp(mode, "DF") == 0)) |
| 261 | glmode = LM_ST_DEFERRED; |
| 262 | else if ((strcmp(mode, "PR") == 0) || (strcmp(mode, "SH") == 0)) |
| 263 | glmode = LM_ST_SHARED; |
| 264 | else |
| 265 | return -EINVAL; |
| 266 | |
| 267 | if (gltype > LM_TYPE_JOURNAL) |
| 268 | return -EINVAL; |
Benjamin Marzinski | 2497255 | 2014-05-01 22:26:55 -0500 | [diff] [blame] | 269 | if (gltype == LM_TYPE_NONDISK && glnum == GFS2_FREEZE_LOCK) |
| 270 | glops = &gfs2_freeze_glops; |
Steven Whitehouse | 1346698 | 2010-10-06 09:58:44 +0100 | [diff] [blame] | 271 | else |
| 272 | glops = gfs2_glops_list[gltype]; |
Steven Whitehouse | 64d576b | 2009-02-12 13:31:58 +0000 | [diff] [blame] | 273 | if (glops == NULL) |
| 274 | return -EINVAL; |
Steven Whitehouse | 6a99be5 | 2010-05-14 14:05:51 +0100 | [diff] [blame] | 275 | if (!test_and_set_bit(SDF_DEMOTE, &sdp->sd_flags)) |
Steven Whitehouse | 913a71d | 2010-05-06 11:03:29 +0100 | [diff] [blame] | 276 | fs_info(sdp, "demote interface used\n"); |
Steven Whitehouse | 64d576b | 2009-02-12 13:31:58 +0000 | [diff] [blame] | 277 | rv = gfs2_glock_get(sdp, glnum, glops, 0, &gl); |
| 278 | if (rv) |
| 279 | return rv; |
| 280 | gfs2_glock_cb(gl, glmode); |
| 281 | gfs2_glock_put(gl); |
| 282 | return len; |
| 283 | } |
| 284 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 285 | |
| 286 | #define GFS2_ATTR(name, mode, show, store) \ |
| 287 | static struct gfs2_attr gfs2_attr_##name = __ATTR(name, mode, show, store) |
| 288 | |
| 289 | GFS2_ATTR(id, 0444, id_show, NULL); |
| 290 | GFS2_ATTR(fsname, 0444, fsname_show, NULL); |
Steven Whitehouse | 02e3cc7 | 2009-02-10 13:48:30 +0000 | [diff] [blame] | 291 | GFS2_ATTR(uuid, 0444, uuid_show, NULL); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 292 | GFS2_ATTR(freeze, 0644, freeze_show, freeze_store); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 293 | GFS2_ATTR(withdraw, 0644, withdraw_show, withdraw_store); |
| 294 | GFS2_ATTR(statfs_sync, 0200, NULL, statfs_sync_store); |
| 295 | GFS2_ATTR(quota_sync, 0200, NULL, quota_sync_store); |
| 296 | GFS2_ATTR(quota_refresh_user, 0200, NULL, quota_refresh_user_store); |
| 297 | GFS2_ATTR(quota_refresh_group, 0200, NULL, quota_refresh_group_store); |
Steven Whitehouse | 64d576b | 2009-02-12 13:31:58 +0000 | [diff] [blame] | 298 | GFS2_ATTR(demote_rq, 0200, NULL, demote_rq_store); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 299 | |
| 300 | static struct attribute *gfs2_attrs[] = { |
| 301 | &gfs2_attr_id.attr, |
| 302 | &gfs2_attr_fsname.attr, |
Steven Whitehouse | 02e3cc7 | 2009-02-10 13:48:30 +0000 | [diff] [blame] | 303 | &gfs2_attr_uuid.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 304 | &gfs2_attr_freeze.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 305 | &gfs2_attr_withdraw.attr, |
| 306 | &gfs2_attr_statfs_sync.attr, |
| 307 | &gfs2_attr_quota_sync.attr, |
| 308 | &gfs2_attr_quota_refresh_user.attr, |
| 309 | &gfs2_attr_quota_refresh_group.attr, |
Steven Whitehouse | 64d576b | 2009-02-12 13:31:58 +0000 | [diff] [blame] | 310 | &gfs2_attr_demote_rq.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 311 | NULL, |
| 312 | }; |
| 313 | |
Bob Peterson | 0d51521 | 2012-06-13 10:27:41 -0400 | [diff] [blame] | 314 | static void gfs2_sbd_release(struct kobject *kobj) |
| 315 | { |
| 316 | struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj); |
| 317 | |
| 318 | kfree(sdp); |
| 319 | } |
| 320 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 321 | static struct kobj_type gfs2_ktype = { |
Bob Peterson | 0d51521 | 2012-06-13 10:27:41 -0400 | [diff] [blame] | 322 | .release = gfs2_sbd_release, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 323 | .default_attrs = gfs2_attrs, |
| 324 | .sysfs_ops = &gfs2_attr_ops, |
| 325 | }; |
| 326 | |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 327 | |
| 328 | /* |
| 329 | * lock_module. Originally from lock_dlm |
| 330 | */ |
| 331 | |
| 332 | static ssize_t proto_name_show(struct gfs2_sbd *sdp, char *buf) |
| 333 | { |
| 334 | const struct lm_lockops *ops = sdp->sd_lockstruct.ls_ops; |
| 335 | return sprintf(buf, "%s\n", ops->lm_proto_name); |
| 336 | } |
| 337 | |
| 338 | static ssize_t block_show(struct gfs2_sbd *sdp, char *buf) |
| 339 | { |
| 340 | struct lm_lockstruct *ls = &sdp->sd_lockstruct; |
| 341 | ssize_t ret; |
| 342 | int val = 0; |
| 343 | |
David Teigland | e0c2a9a | 2012-01-09 17:18:05 -0500 | [diff] [blame] | 344 | if (test_bit(DFL_BLOCK_LOCKS, &ls->ls_recover_flags)) |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 345 | val = 1; |
| 346 | ret = sprintf(buf, "%d\n", val); |
| 347 | return ret; |
| 348 | } |
| 349 | |
| 350 | static ssize_t block_store(struct gfs2_sbd *sdp, const char *buf, size_t len) |
| 351 | { |
| 352 | struct lm_lockstruct *ls = &sdp->sd_lockstruct; |
Fabian Frederick | e50ead4 | 2015-05-05 13:23:22 -0500 | [diff] [blame] | 353 | int ret, val; |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 354 | |
Fabian Frederick | e50ead4 | 2015-05-05 13:23:22 -0500 | [diff] [blame] | 355 | ret = kstrtoint(buf, 0, &val); |
| 356 | if (ret) |
| 357 | return ret; |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 358 | |
| 359 | if (val == 1) |
David Teigland | e0c2a9a | 2012-01-09 17:18:05 -0500 | [diff] [blame] | 360 | set_bit(DFL_BLOCK_LOCKS, &ls->ls_recover_flags); |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 361 | else if (val == 0) { |
David Teigland | e0c2a9a | 2012-01-09 17:18:05 -0500 | [diff] [blame] | 362 | clear_bit(DFL_BLOCK_LOCKS, &ls->ls_recover_flags); |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 363 | smp_mb__after_atomic(); |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 364 | gfs2_glock_thaw(sdp); |
| 365 | } else { |
Fabian Frederick | e50ead4 | 2015-05-05 13:23:22 -0500 | [diff] [blame] | 366 | return -EINVAL; |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 367 | } |
Fabian Frederick | e50ead4 | 2015-05-05 13:23:22 -0500 | [diff] [blame] | 368 | return len; |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 369 | } |
| 370 | |
Steven Whitehouse | fd95e81 | 2013-02-13 12:21:40 +0000 | [diff] [blame] | 371 | static ssize_t wdack_show(struct gfs2_sbd *sdp, char *buf) |
| 372 | { |
| 373 | int val = completion_done(&sdp->sd_wdack) ? 1 : 0; |
| 374 | |
| 375 | return sprintf(buf, "%d\n", val); |
| 376 | } |
| 377 | |
| 378 | static ssize_t wdack_store(struct gfs2_sbd *sdp, const char *buf, size_t len) |
| 379 | { |
Fabian Frederick | e50ead4 | 2015-05-05 13:23:22 -0500 | [diff] [blame] | 380 | int ret, val; |
Steven Whitehouse | fd95e81 | 2013-02-13 12:21:40 +0000 | [diff] [blame] | 381 | |
Fabian Frederick | e50ead4 | 2015-05-05 13:23:22 -0500 | [diff] [blame] | 382 | ret = kstrtoint(buf, 0, &val); |
| 383 | if (ret) |
| 384 | return ret; |
Steven Whitehouse | fd95e81 | 2013-02-13 12:21:40 +0000 | [diff] [blame] | 385 | |
| 386 | if ((val == 1) && |
| 387 | !strcmp(sdp->sd_lockstruct.ls_ops->lm_proto_name, "lock_dlm")) |
| 388 | complete(&sdp->sd_wdack); |
| 389 | else |
Fabian Frederick | e50ead4 | 2015-05-05 13:23:22 -0500 | [diff] [blame] | 390 | return -EINVAL; |
| 391 | return len; |
Steven Whitehouse | fd95e81 | 2013-02-13 12:21:40 +0000 | [diff] [blame] | 392 | } |
| 393 | |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 394 | static ssize_t lkfirst_show(struct gfs2_sbd *sdp, char *buf) |
| 395 | { |
| 396 | struct lm_lockstruct *ls = &sdp->sd_lockstruct; |
| 397 | return sprintf(buf, "%d\n", ls->ls_first); |
| 398 | } |
| 399 | |
Steven Whitehouse | ba6e936 | 2010-06-14 10:01:30 +0100 | [diff] [blame] | 400 | static ssize_t lkfirst_store(struct gfs2_sbd *sdp, const char *buf, size_t len) |
| 401 | { |
| 402 | unsigned first; |
| 403 | int rv; |
| 404 | |
| 405 | rv = sscanf(buf, "%u", &first); |
| 406 | if (rv != 1 || first > 1) |
| 407 | return -EINVAL; |
Steven Whitehouse | 3942ae5 | 2011-07-11 08:53:30 +0100 | [diff] [blame] | 408 | rv = wait_for_completion_killable(&sdp->sd_locking_init); |
| 409 | if (rv) |
| 410 | return rv; |
Steven Whitehouse | ba6e936 | 2010-06-14 10:01:30 +0100 | [diff] [blame] | 411 | spin_lock(&sdp->sd_jindex_spin); |
| 412 | rv = -EBUSY; |
| 413 | if (test_bit(SDF_NOJOURNALID, &sdp->sd_flags) == 0) |
| 414 | goto out; |
| 415 | rv = -EINVAL; |
| 416 | if (sdp->sd_args.ar_spectator) |
| 417 | goto out; |
| 418 | if (sdp->sd_lockstruct.ls_ops->lm_mount == NULL) |
| 419 | goto out; |
David Teigland | e0c2a9a | 2012-01-09 17:18:05 -0500 | [diff] [blame] | 420 | sdp->sd_lockstruct.ls_first = first; |
| 421 | rv = 0; |
Steven Whitehouse | ba6e936 | 2010-06-14 10:01:30 +0100 | [diff] [blame] | 422 | out: |
| 423 | spin_unlock(&sdp->sd_jindex_spin); |
| 424 | return rv ? rv : len; |
| 425 | } |
| 426 | |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 427 | static ssize_t first_done_show(struct gfs2_sbd *sdp, char *buf) |
| 428 | { |
| 429 | struct lm_lockstruct *ls = &sdp->sd_lockstruct; |
David Teigland | e0c2a9a | 2012-01-09 17:18:05 -0500 | [diff] [blame] | 430 | return sprintf(buf, "%d\n", !!test_bit(DFL_FIRST_MOUNT_DONE, &ls->ls_recover_flags)); |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 431 | } |
| 432 | |
David Teigland | e0c2a9a | 2012-01-09 17:18:05 -0500 | [diff] [blame] | 433 | int gfs2_recover_set(struct gfs2_sbd *sdp, unsigned jid) |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 434 | { |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 435 | struct gfs2_jdesc *jd; |
Steven Whitehouse | fe64d51 | 2009-05-19 10:01:18 +0100 | [diff] [blame] | 436 | int rv; |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 437 | |
Bob Peterson | 0e48e055 | 2014-06-02 09:40:25 -0400 | [diff] [blame] | 438 | /* Wait for our primary journal to be initialized */ |
| 439 | wait_for_completion(&sdp->sd_journal_ready); |
| 440 | |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 441 | spin_lock(&sdp->sd_jindex_spin); |
Steven Whitehouse | fe64d51 | 2009-05-19 10:01:18 +0100 | [diff] [blame] | 442 | rv = -EBUSY; |
| 443 | if (sdp->sd_jdesc->jd_jid == jid) |
| 444 | goto out; |
| 445 | rv = -ENOENT; |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 446 | list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) { |
| 447 | if (jd->jd_jid != jid) |
| 448 | continue; |
Tejun Heo | 6ecd7c2 | 2010-07-20 22:09:02 +0200 | [diff] [blame] | 449 | rv = gfs2_recover_journal(jd, false); |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 450 | break; |
| 451 | } |
Steven Whitehouse | fe64d51 | 2009-05-19 10:01:18 +0100 | [diff] [blame] | 452 | out: |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 453 | spin_unlock(&sdp->sd_jindex_spin); |
David Teigland | e0c2a9a | 2012-01-09 17:18:05 -0500 | [diff] [blame] | 454 | return rv; |
| 455 | } |
| 456 | |
| 457 | static ssize_t recover_store(struct gfs2_sbd *sdp, const char *buf, size_t len) |
| 458 | { |
| 459 | unsigned jid; |
| 460 | int rv; |
| 461 | |
| 462 | rv = sscanf(buf, "%u", &jid); |
| 463 | if (rv != 1) |
| 464 | return -EINVAL; |
| 465 | |
David Teigland | 1a058f5 | 2012-05-01 15:50:48 -0500 | [diff] [blame] | 466 | if (test_bit(SDF_NORECOVERY, &sdp->sd_flags)) { |
| 467 | rv = -ESHUTDOWN; |
| 468 | goto out; |
| 469 | } |
David Teigland | e0c2a9a | 2012-01-09 17:18:05 -0500 | [diff] [blame] | 470 | |
David Teigland | 1a058f5 | 2012-05-01 15:50:48 -0500 | [diff] [blame] | 471 | rv = gfs2_recover_set(sdp, jid); |
| 472 | out: |
Steven Whitehouse | fe64d51 | 2009-05-19 10:01:18 +0100 | [diff] [blame] | 473 | return rv ? rv : len; |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | static ssize_t recover_done_show(struct gfs2_sbd *sdp, char *buf) |
| 477 | { |
| 478 | struct lm_lockstruct *ls = &sdp->sd_lockstruct; |
| 479 | return sprintf(buf, "%d\n", ls->ls_recover_jid_done); |
| 480 | } |
| 481 | |
| 482 | static ssize_t recover_status_show(struct gfs2_sbd *sdp, char *buf) |
| 483 | { |
| 484 | struct lm_lockstruct *ls = &sdp->sd_lockstruct; |
| 485 | return sprintf(buf, "%d\n", ls->ls_recover_jid_status); |
| 486 | } |
| 487 | |
Steven Whitehouse | e1b28aa | 2009-05-26 15:41:27 +0100 | [diff] [blame] | 488 | static ssize_t jid_show(struct gfs2_sbd *sdp, char *buf) |
| 489 | { |
Steven Whitehouse | feb47ca9 | 2010-09-29 15:04:18 +0100 | [diff] [blame] | 490 | return sprintf(buf, "%d\n", sdp->sd_lockstruct.ls_jid); |
Steven Whitehouse | e1b28aa | 2009-05-26 15:41:27 +0100 | [diff] [blame] | 491 | } |
| 492 | |
Steven Whitehouse | ba6e936 | 2010-06-14 10:01:30 +0100 | [diff] [blame] | 493 | static ssize_t jid_store(struct gfs2_sbd *sdp, const char *buf, size_t len) |
| 494 | { |
Steven Whitehouse | feb47ca9 | 2010-09-29 15:04:18 +0100 | [diff] [blame] | 495 | int jid; |
Steven Whitehouse | ba6e936 | 2010-06-14 10:01:30 +0100 | [diff] [blame] | 496 | int rv; |
| 497 | |
Steven Whitehouse | feb47ca9 | 2010-09-29 15:04:18 +0100 | [diff] [blame] | 498 | rv = sscanf(buf, "%d", &jid); |
Steven Whitehouse | ba6e936 | 2010-06-14 10:01:30 +0100 | [diff] [blame] | 499 | if (rv != 1) |
| 500 | return -EINVAL; |
Steven Whitehouse | 3942ae5 | 2011-07-11 08:53:30 +0100 | [diff] [blame] | 501 | rv = wait_for_completion_killable(&sdp->sd_locking_init); |
| 502 | if (rv) |
| 503 | return rv; |
Steven Whitehouse | ba6e936 | 2010-06-14 10:01:30 +0100 | [diff] [blame] | 504 | spin_lock(&sdp->sd_jindex_spin); |
| 505 | rv = -EINVAL; |
Steven Whitehouse | ba6e936 | 2010-06-14 10:01:30 +0100 | [diff] [blame] | 506 | if (sdp->sd_lockstruct.ls_ops->lm_mount == NULL) |
| 507 | goto out; |
| 508 | rv = -EBUSY; |
Steven Whitehouse | feb47ca9 | 2010-09-29 15:04:18 +0100 | [diff] [blame] | 509 | if (test_bit(SDF_NOJOURNALID, &sdp->sd_flags) == 0) |
Steven Whitehouse | ba6e936 | 2010-06-14 10:01:30 +0100 | [diff] [blame] | 510 | goto out; |
Steven Whitehouse | feb47ca9 | 2010-09-29 15:04:18 +0100 | [diff] [blame] | 511 | rv = 0; |
| 512 | if (sdp->sd_args.ar_spectator && jid > 0) |
| 513 | rv = jid = -EINVAL; |
Steven Whitehouse | ba6e936 | 2010-06-14 10:01:30 +0100 | [diff] [blame] | 514 | sdp->sd_lockstruct.ls_jid = jid; |
Steven Whitehouse | feb47ca9 | 2010-09-29 15:04:18 +0100 | [diff] [blame] | 515 | clear_bit(SDF_NOJOURNALID, &sdp->sd_flags); |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 516 | smp_mb__after_atomic(); |
Steven Whitehouse | ba6e936 | 2010-06-14 10:01:30 +0100 | [diff] [blame] | 517 | wake_up_bit(&sdp->sd_flags, SDF_NOJOURNALID); |
Steven Whitehouse | ba6e936 | 2010-06-14 10:01:30 +0100 | [diff] [blame] | 518 | out: |
| 519 | spin_unlock(&sdp->sd_jindex_spin); |
| 520 | return rv ? rv : len; |
| 521 | } |
| 522 | |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 523 | #define GDLM_ATTR(_name,_mode,_show,_store) \ |
Steven Whitehouse | 48c2b61 | 2009-05-13 14:49:48 +0100 | [diff] [blame] | 524 | static struct gfs2_attr gdlm_attr_##_name = __ATTR(_name,_mode,_show,_store) |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 525 | |
Steven Whitehouse | d7e623d | 2009-08-11 11:20:11 +0100 | [diff] [blame] | 526 | GDLM_ATTR(proto_name, 0444, proto_name_show, NULL); |
| 527 | GDLM_ATTR(block, 0644, block_show, block_store); |
Steven Whitehouse | fd95e81 | 2013-02-13 12:21:40 +0000 | [diff] [blame] | 528 | GDLM_ATTR(withdraw, 0644, wdack_show, wdack_store); |
Steven Whitehouse | ba6e936 | 2010-06-14 10:01:30 +0100 | [diff] [blame] | 529 | GDLM_ATTR(jid, 0644, jid_show, jid_store); |
| 530 | GDLM_ATTR(first, 0644, lkfirst_show, lkfirst_store); |
Steven Whitehouse | d7e623d | 2009-08-11 11:20:11 +0100 | [diff] [blame] | 531 | GDLM_ATTR(first_done, 0444, first_done_show, NULL); |
| 532 | GDLM_ATTR(recover, 0600, NULL, recover_store); |
| 533 | GDLM_ATTR(recover_done, 0444, recover_done_show, NULL); |
| 534 | GDLM_ATTR(recover_status, 0444, recover_status_show, NULL); |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 535 | |
| 536 | static struct attribute *lock_module_attrs[] = { |
| 537 | &gdlm_attr_proto_name.attr, |
| 538 | &gdlm_attr_block.attr, |
| 539 | &gdlm_attr_withdraw.attr, |
Steven Whitehouse | e1b28aa | 2009-05-26 15:41:27 +0100 | [diff] [blame] | 540 | &gdlm_attr_jid.attr, |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 541 | &gdlm_attr_first.attr, |
| 542 | &gdlm_attr_first_done.attr, |
| 543 | &gdlm_attr_recover.attr, |
| 544 | &gdlm_attr_recover_done.attr, |
| 545 | &gdlm_attr_recover_status.attr, |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 546 | NULL, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 547 | }; |
| 548 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 549 | /* |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 550 | * get and set struct gfs2_tune fields |
| 551 | */ |
| 552 | |
| 553 | static ssize_t quota_scale_show(struct gfs2_sbd *sdp, char *buf) |
| 554 | { |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 555 | return snprintf(buf, PAGE_SIZE, "%u %u\n", |
| 556 | sdp->sd_tune.gt_quota_scale_num, |
| 557 | sdp->sd_tune.gt_quota_scale_den); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | static ssize_t quota_scale_store(struct gfs2_sbd *sdp, const char *buf, |
| 561 | size_t len) |
| 562 | { |
| 563 | struct gfs2_tune *gt = &sdp->sd_tune; |
| 564 | unsigned int x, y; |
| 565 | |
| 566 | if (!capable(CAP_SYS_ADMIN)) |
Zhao Hongjiang | 4173581 | 2013-02-20 13:13:55 +1100 | [diff] [blame] | 567 | return -EPERM; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 568 | |
| 569 | if (sscanf(buf, "%u %u", &x, &y) != 2 || !y) |
| 570 | return -EINVAL; |
| 571 | |
| 572 | spin_lock(>->gt_spin); |
| 573 | gt->gt_quota_scale_num = x; |
| 574 | gt->gt_quota_scale_den = y; |
| 575 | spin_unlock(>->gt_spin); |
| 576 | return len; |
| 577 | } |
| 578 | |
| 579 | static ssize_t tune_set(struct gfs2_sbd *sdp, unsigned int *field, |
| 580 | int check_zero, const char *buf, size_t len) |
| 581 | { |
| 582 | struct gfs2_tune *gt = &sdp->sd_tune; |
| 583 | unsigned int x; |
Fabian Frederick | e50ead4 | 2015-05-05 13:23:22 -0500 | [diff] [blame] | 584 | int error; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 585 | |
| 586 | if (!capable(CAP_SYS_ADMIN)) |
Zhao Hongjiang | 4173581 | 2013-02-20 13:13:55 +1100 | [diff] [blame] | 587 | return -EPERM; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 588 | |
Fabian Frederick | e50ead4 | 2015-05-05 13:23:22 -0500 | [diff] [blame] | 589 | error = kstrtouint(buf, 0, &x); |
| 590 | if (error) |
| 591 | return error; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 592 | |
| 593 | if (check_zero && !x) |
| 594 | return -EINVAL; |
| 595 | |
| 596 | spin_lock(>->gt_spin); |
| 597 | *field = x; |
| 598 | spin_unlock(>->gt_spin); |
| 599 | return len; |
| 600 | } |
| 601 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 602 | #define TUNE_ATTR_3(name, show, store) \ |
Steven Whitehouse | 48c2b61 | 2009-05-13 14:49:48 +0100 | [diff] [blame] | 603 | static struct gfs2_attr tune_attr_##name = __ATTR(name, 0644, show, store) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 604 | |
| 605 | #define TUNE_ATTR_2(name, store) \ |
| 606 | static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \ |
| 607 | { \ |
David Teigland | 3204a6c | 2006-09-06 16:57:06 -0500 | [diff] [blame] | 608 | return snprintf(buf, PAGE_SIZE, "%u\n", sdp->sd_tune.gt_##name); \ |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 609 | } \ |
| 610 | TUNE_ATTR_3(name, name##_show, store) |
| 611 | |
| 612 | #define TUNE_ATTR(name, check_zero) \ |
| 613 | static ssize_t name##_store(struct gfs2_sbd *sdp, const char *buf, size_t len)\ |
| 614 | { \ |
| 615 | return tune_set(sdp, &sdp->sd_tune.gt_##name, check_zero, buf, len); \ |
| 616 | } \ |
| 617 | TUNE_ATTR_2(name, name##_store) |
| 618 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 619 | TUNE_ATTR(quota_warn_period, 0); |
| 620 | TUNE_ATTR(quota_quantum, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 621 | TUNE_ATTR(max_readahead, 0); |
| 622 | TUNE_ATTR(complain_secs, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 623 | TUNE_ATTR(statfs_slow, 0); |
| 624 | TUNE_ATTR(new_files_jdata, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 625 | TUNE_ATTR(statfs_quantum, 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 626 | TUNE_ATTR_3(quota_scale, quota_scale_show, quota_scale_store); |
| 627 | |
| 628 | static struct attribute *tune_attrs[] = { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 629 | &tune_attr_quota_warn_period.attr, |
| 630 | &tune_attr_quota_quantum.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 631 | &tune_attr_max_readahead.attr, |
| 632 | &tune_attr_complain_secs.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 633 | &tune_attr_statfs_slow.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 634 | &tune_attr_statfs_quantum.attr, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 635 | &tune_attr_quota_scale.attr, |
| 636 | &tune_attr_new_files_jdata.attr, |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 637 | NULL, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 638 | }; |
| 639 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 640 | static struct attribute_group tune_group = { |
| 641 | .name = "tune", |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 642 | .attrs = tune_attrs, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 643 | }; |
| 644 | |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 645 | static struct attribute_group lock_module_group = { |
| 646 | .name = "lock_module", |
| 647 | .attrs = lock_module_attrs, |
| 648 | }; |
| 649 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 650 | int gfs2_sys_fs_add(struct gfs2_sbd *sdp) |
| 651 | { |
Steven Whitehouse | 440d6da | 2009-07-31 12:16:25 +0100 | [diff] [blame] | 652 | struct super_block *sb = sdp->sd_vfs; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 653 | int error; |
Steven Whitehouse | 440d6da | 2009-07-31 12:16:25 +0100 | [diff] [blame] | 654 | char ro[20]; |
| 655 | char spectator[20]; |
| 656 | char *envp[] = { ro, spectator, NULL }; |
Bob Peterson | 0d51521 | 2012-06-13 10:27:41 -0400 | [diff] [blame] | 657 | int sysfs_frees_sdp = 0; |
Steven Whitehouse | 440d6da | 2009-07-31 12:16:25 +0100 | [diff] [blame] | 658 | |
| 659 | sprintf(ro, "RDONLY=%d", (sb->s_flags & MS_RDONLY) ? 1 : 0); |
| 660 | sprintf(spectator, "SPECTATOR=%d", sdp->sd_args.ar_spectator ? 1 : 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 661 | |
Greg Kroah-Hartman | 9bec101 | 2007-10-29 20:13:17 +0100 | [diff] [blame] | 662 | sdp->sd_kobj.kset = gfs2_kset; |
Greg Kroah-Hartman | 901195e | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 663 | error = kobject_init_and_add(&sdp->sd_kobj, &gfs2_ktype, NULL, |
| 664 | "%s", sdp->sd_table_name); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 665 | if (error) |
Bob Peterson | 0d51521 | 2012-06-13 10:27:41 -0400 | [diff] [blame] | 666 | goto fail_reg; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 667 | |
Bob Peterson | 0d51521 | 2012-06-13 10:27:41 -0400 | [diff] [blame] | 668 | sysfs_frees_sdp = 1; /* Freeing sdp is now done by sysfs calling |
| 669 | function gfs2_sbd_release. */ |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 670 | error = sysfs_create_group(&sdp->sd_kobj, &tune_group); |
| 671 | if (error) |
Steven Whitehouse | f6eb534 | 2009-05-26 15:50:25 +0100 | [diff] [blame] | 672 | goto fail_reg; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 673 | |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 674 | error = sysfs_create_group(&sdp->sd_kobj, &lock_module_group); |
| 675 | if (error) |
| 676 | goto fail_tune; |
| 677 | |
Steven Whitehouse | 31e54b0 | 2009-08-13 12:18:08 +0100 | [diff] [blame] | 678 | error = sysfs_create_link(&sdp->sd_kobj, |
| 679 | &disk_to_dev(sb->s_bdev->bd_disk)->kobj, |
| 680 | "device"); |
| 681 | if (error) |
| 682 | goto fail_lock_module; |
| 683 | |
Steven Whitehouse | 440d6da | 2009-07-31 12:16:25 +0100 | [diff] [blame] | 684 | kobject_uevent_env(&sdp->sd_kobj, KOBJ_ADD, envp); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 685 | return 0; |
| 686 | |
Steven Whitehouse | 31e54b0 | 2009-08-13 12:18:08 +0100 | [diff] [blame] | 687 | fail_lock_module: |
| 688 | sysfs_remove_group(&sdp->sd_kobj, &lock_module_group); |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 689 | fail_tune: |
| 690 | sysfs_remove_group(&sdp->sd_kobj, &tune_group); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 691 | fail_reg: |
Bob Peterson | 0d51521 | 2012-06-13 10:27:41 -0400 | [diff] [blame] | 692 | free_percpu(sdp->sd_lkstats); |
David Teigland | 65952fb | 2006-09-15 13:09:11 -0500 | [diff] [blame] | 693 | fs_err(sdp, "error %d adding sysfs files", error); |
Bob Peterson | 0d51521 | 2012-06-13 10:27:41 -0400 | [diff] [blame] | 694 | if (sysfs_frees_sdp) |
| 695 | kobject_put(&sdp->sd_kobj); |
| 696 | else |
| 697 | kfree(sdp); |
| 698 | sb->s_fs_info = NULL; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 699 | return error; |
| 700 | } |
| 701 | |
| 702 | void gfs2_sys_fs_del(struct gfs2_sbd *sdp) |
| 703 | { |
Steven Whitehouse | 31e54b0 | 2009-08-13 12:18:08 +0100 | [diff] [blame] | 704 | sysfs_remove_link(&sdp->sd_kobj, "device"); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 705 | sysfs_remove_group(&sdp->sd_kobj, &tune_group); |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 706 | sysfs_remove_group(&sdp->sd_kobj, &lock_module_group); |
Greg Kroah-Hartman | 197b12d | 2007-12-20 08:13:05 -0800 | [diff] [blame] | 707 | kobject_put(&sdp->sd_kobj); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 708 | } |
| 709 | |
Steven Whitehouse | fdd1062 | 2008-11-26 10:26:38 +0000 | [diff] [blame] | 710 | static int gfs2_uevent(struct kset *kset, struct kobject *kobj, |
| 711 | struct kobj_uevent_env *env) |
| 712 | { |
| 713 | struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj); |
Steven Whitehouse | 32e471e | 2011-05-10 15:01:59 +0100 | [diff] [blame] | 714 | struct super_block *s = sdp->sd_vfs; |
| 715 | const u8 *uuid = s->s_uuid; |
Steven Whitehouse | 02e3cc7 | 2009-02-10 13:48:30 +0000 | [diff] [blame] | 716 | |
Steven Whitehouse | fdd1062 | 2008-11-26 10:26:38 +0000 | [diff] [blame] | 717 | add_uevent_var(env, "LOCKTABLE=%s", sdp->sd_table_name); |
| 718 | add_uevent_var(env, "LOCKPROTO=%s", sdp->sd_proto_name); |
Steven Whitehouse | ba6e936 | 2010-06-14 10:01:30 +0100 | [diff] [blame] | 719 | if (!test_bit(SDF_NOJOURNALID, &sdp->sd_flags)) |
Steven Whitehouse | feb47ca9 | 2010-09-29 15:04:18 +0100 | [diff] [blame] | 720 | add_uevent_var(env, "JOURNALID=%d", sdp->sd_lockstruct.ls_jid); |
Joe Perches | f0b34ae | 2009-12-14 18:01:13 -0800 | [diff] [blame] | 721 | if (gfs2_uuid_valid(uuid)) |
| 722 | add_uevent_var(env, "UUID=%pUB", uuid); |
Steven Whitehouse | fdd1062 | 2008-11-26 10:26:38 +0000 | [diff] [blame] | 723 | return 0; |
| 724 | } |
| 725 | |
Emese Revfy | 9cd4361 | 2009-12-31 14:52:51 +0100 | [diff] [blame] | 726 | static const struct kset_uevent_ops gfs2_uevent_ops = { |
Steven Whitehouse | fdd1062 | 2008-11-26 10:26:38 +0000 | [diff] [blame] | 727 | .uevent = gfs2_uevent, |
| 728 | }; |
| 729 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 730 | int gfs2_sys_init(void) |
| 731 | { |
Steven Whitehouse | fdd1062 | 2008-11-26 10:26:38 +0000 | [diff] [blame] | 732 | 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] | 733 | if (!gfs2_kset) |
| 734 | return -ENOMEM; |
| 735 | return 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | void gfs2_sys_uninit(void) |
| 739 | { |
Greg Kroah-Hartman | 9bec101 | 2007-10-29 20:13:17 +0100 | [diff] [blame] | 740 | kset_unregister(gfs2_kset); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 741 | } |
| 742 | |