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