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