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