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