Blame view
fs/gfs2/sys.c
17.5 KB
7336d0e65 treewide: Replace... |
1 |
// SPDX-License-Identifier: GPL-2.0-only |
b3b94faa5 [GFS2] The core o... |
2 3 |
/* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
3a8a9a103 [GFS2] Update cop... |
4 |
* Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. |
b3b94faa5 [GFS2] The core o... |
5 |
*/ |
d77d1b58a GFS2: Use pr_<lev... |
6 |
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
b3b94faa5 [GFS2] The core o... |
7 |
#include <linux/sched.h> |
5b825c3af sched/headers: Pr... |
8 |
#include <linux/cred.h> |
b3b94faa5 [GFS2] The core o... |
9 10 11 12 13 |
#include <linux/spinlock.h> #include <linux/completion.h> #include <linux/buffer_head.h> #include <linux/module.h> #include <linux/kobject.h> |
7c0f6ba68 Replace <asm/uacc... |
14 |
#include <linux/uaccess.h> |
f057f6cdf GFS2: Merge lock_... |
15 |
#include <linux/gfs2_ondisk.h> |
31e54b01f GFS2: Add sysfs l... |
16 |
#include <linux/genhd.h> |
b3b94faa5 [GFS2] The core o... |
17 18 |
#include "gfs2.h" |
5c676f6d3 [GFS2] Macros rem... |
19 |
#include "incore.h" |
b3b94faa5 [GFS2] The core o... |
20 21 22 23 |
#include "sys.h" #include "super.h" #include "glock.h" #include "quota.h" |
5c676f6d3 [GFS2] Macros rem... |
24 |
#include "util.h" |
64d576ba2 GFS2: Add a "demo... |
25 |
#include "glops.h" |
6ecd7c2dd gfs2: use workque... |
26 |
#include "recovery.h" |
b3b94faa5 [GFS2] The core o... |
27 |
|
48c2b6136 GFS2: Add commit=... |
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
struct gfs2_attr { struct attribute attr; ssize_t (*show)(struct gfs2_sbd *, char *); ssize_t (*store)(struct gfs2_sbd *, const char *, size_t); }; static ssize_t gfs2_attr_show(struct kobject *kobj, struct attribute *attr, char *buf) { struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj); struct gfs2_attr *a = container_of(attr, struct gfs2_attr, attr); return a->show ? a->show(sdp, buf) : 0; } static ssize_t gfs2_attr_store(struct kobject *kobj, struct attribute *attr, const char *buf, size_t len) { struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj); struct gfs2_attr *a = container_of(attr, struct gfs2_attr, attr); return a->store ? a->store(sdp, buf, len) : len; } |
52cf25d0a Driver core: Cons... |
49 |
static const struct sysfs_ops gfs2_attr_ops = { |
48c2b6136 GFS2: Add commit=... |
50 51 52 53 54 55 |
.show = gfs2_attr_show, .store = gfs2_attr_store, }; static struct kset *gfs2_kset; |
b3b94faa5 [GFS2] The core o... |
56 57 |
static ssize_t id_show(struct gfs2_sbd *sdp, char *buf) { |
c7227e464 [GFS2] Given devi... |
58 59 60 |
return snprintf(buf, PAGE_SIZE, "%u:%u ", MAJOR(sdp->sd_vfs->s_dev), MINOR(sdp->sd_vfs->s_dev)); |
b3b94faa5 [GFS2] The core o... |
61 62 63 64 |
} static ssize_t fsname_show(struct gfs2_sbd *sdp, char *buf) { |
3204a6c05 [GFS2] use snprin... |
65 66 |
return snprintf(buf, PAGE_SIZE, "%s ", sdp->sd_fsname); |
b3b94faa5 [GFS2] The core o... |
67 |
} |
02e3cc70e GFS2: Expose UUID... |
68 69 |
static ssize_t uuid_show(struct gfs2_sbd *sdp, char *buf) { |
32e471ef1 GFS2: Use UUID fi... |
70 |
struct super_block *s = sdp->sd_vfs; |
85787090a fs: switch ->s_uu... |
71 |
|
02e3cc70e GFS2: Expose UUID... |
72 |
buf[0] = '\0'; |
85787090a fs: switch ->s_uu... |
73 |
if (uuid_is_null(&s->s_uuid)) |
02e3cc70e GFS2: Expose UUID... |
74 |
return 0; |
85787090a fs: switch ->s_uu... |
75 76 |
return snprintf(buf, PAGE_SIZE, "%pUB ", &s->s_uuid); |
02e3cc70e GFS2: Expose UUID... |
77 |
} |
b3b94faa5 [GFS2] The core o... |
78 79 |
static ssize_t freeze_show(struct gfs2_sbd *sdp, char *buf) { |
d564053f0 GFS2: Clean up fr... |
80 81 |
struct super_block *sb = sdp->sd_vfs; int frozen = (sb->s_writers.frozen == SB_UNFROZEN) ? 0 : 1; |
b3b94faa5 [GFS2] The core o... |
82 |
|
3566c9647 GFS2: fix sprintf... |
83 84 |
return snprintf(buf, PAGE_SIZE, "%d ", frozen); |
b3b94faa5 [GFS2] The core o... |
85 86 87 88 |
} static ssize_t freeze_store(struct gfs2_sbd *sdp, const char *buf, size_t len) { |
e50ead480 gfs2: convert sim... |
89 90 91 92 93 |
int error, n; error = kstrtoint(buf, 0, &n); if (error) return error; |
b3b94faa5 [GFS2] The core o... |
94 95 |
if (!capable(CAP_SYS_ADMIN)) |
417358187 fs: change return... |
96 |
return -EPERM; |
b3b94faa5 [GFS2] The core o... |
97 98 99 |
switch (n) { case 0: |
d564053f0 GFS2: Clean up fr... |
100 |
error = thaw_super(sdp->sd_vfs); |
b3b94faa5 [GFS2] The core o... |
101 102 |
break; case 1: |
d564053f0 GFS2: Clean up fr... |
103 |
error = freeze_super(sdp->sd_vfs); |
b3b94faa5 [GFS2] The core o... |
104 105 |
break; default: |
d564053f0 GFS2: Clean up fr... |
106 |
return -EINVAL; |
b3b94faa5 [GFS2] The core o... |
107 |
} |
d564053f0 GFS2: Clean up fr... |
108 |
if (error) { |
af38816e4 gfs2: Add a few m... |
109 110 |
fs_warn(sdp, "freeze %d error %d ", n, error); |
d564053f0 GFS2: Clean up fr... |
111 112 |
return error; } |
b3b94faa5 [GFS2] The core o... |
113 |
|
d564053f0 GFS2: Clean up fr... |
114 |
return len; |
b3b94faa5 [GFS2] The core o... |
115 116 117 118 |
} static ssize_t withdraw_show(struct gfs2_sbd *sdp, char *buf) { |
eb43e660c gfs2: Introduce f... |
119 |
unsigned int b = gfs2_withdrawn(sdp); |
3204a6c05 [GFS2] use snprin... |
120 121 |
return snprintf(buf, PAGE_SIZE, "%u ", b); |
b3b94faa5 [GFS2] The core o... |
122 123 124 125 |
} static ssize_t withdraw_store(struct gfs2_sbd *sdp, const char *buf, size_t len) { |
e50ead480 gfs2: convert sim... |
126 |
int error, val; |
b3b94faa5 [GFS2] The core o... |
127 |
if (!capable(CAP_SYS_ADMIN)) |
417358187 fs: change return... |
128 |
return -EPERM; |
b3b94faa5 [GFS2] The core o... |
129 |
|
e50ead480 gfs2: convert sim... |
130 131 132 133 134 |
error = kstrtoint(buf, 0, &val); if (error) return error; if (val != 1) |
b3b94faa5 [GFS2] The core o... |
135 |
return -EINVAL; |
badb55ec2 gfs2: Split gfs2_... |
136 137 138 |
gfs2_lm(sdp, "withdrawing from cluster at user's request "); gfs2_withdraw(sdp); |
cb94eb066 GFS2: Convert gfs... |
139 |
|
b3b94faa5 [GFS2] The core o... |
140 141 142 143 144 145 |
return len; } static ssize_t statfs_sync_store(struct gfs2_sbd *sdp, const char *buf, size_t len) { |
e50ead480 gfs2: convert sim... |
146 |
int error, val; |
b3b94faa5 [GFS2] The core o... |
147 |
if (!capable(CAP_SYS_ADMIN)) |
417358187 fs: change return... |
148 |
return -EPERM; |
b3b94faa5 [GFS2] The core o... |
149 |
|
e50ead480 gfs2: convert sim... |
150 151 152 153 154 |
error = kstrtoint(buf, 0, &val); if (error) return error; if (val != 1) |
b3b94faa5 [GFS2] The core o... |
155 |
return -EINVAL; |
8c42d637f GFS2: Alter argum... |
156 |
gfs2_statfs_sync(sdp->sd_vfs, 0); |
b3b94faa5 [GFS2] The core o... |
157 158 |
return len; } |
b3b94faa5 [GFS2] The core o... |
159 160 161 |
static ssize_t quota_sync_store(struct gfs2_sbd *sdp, const char *buf, size_t len) { |
e50ead480 gfs2: convert sim... |
162 |
int error, val; |
b3b94faa5 [GFS2] The core o... |
163 |
if (!capable(CAP_SYS_ADMIN)) |
417358187 fs: change return... |
164 |
return -EPERM; |
b3b94faa5 [GFS2] The core o... |
165 |
|
e50ead480 gfs2: convert sim... |
166 167 168 169 170 |
error = kstrtoint(buf, 0, &val); if (error) return error; if (val != 1) |
b3b94faa5 [GFS2] The core o... |
171 |
return -EINVAL; |
ceed17236 quota: Split dquo... |
172 |
gfs2_quota_sync(sdp->sd_vfs, 0); |
b3b94faa5 [GFS2] The core o... |
173 174 175 176 177 178 |
return len; } static ssize_t quota_refresh_user_store(struct gfs2_sbd *sdp, const char *buf, size_t len) { |
ed87dabcc gfs2: Convert gfs... |
179 |
struct kqid qid; |
ea7623385 GFS2: Add proper ... |
180 |
int error; |
cd915493f [GFS2] Change all... |
181 |
u32 id; |
b3b94faa5 [GFS2] The core o... |
182 183 |
if (!capable(CAP_SYS_ADMIN)) |
417358187 fs: change return... |
184 |
return -EPERM; |
b3b94faa5 [GFS2] The core o... |
185 |
|
e50ead480 gfs2: convert sim... |
186 187 188 |
error = kstrtou32(buf, 0, &id); if (error) return error; |
b3b94faa5 [GFS2] The core o... |
189 |
|
ed87dabcc gfs2: Convert gfs... |
190 191 192 193 194 |
qid = make_kqid(current_user_ns(), USRQUOTA, id); if (!qid_valid(qid)) return -EINVAL; error = gfs2_quota_refresh(sdp, qid); |
ea7623385 GFS2: Add proper ... |
195 |
return error ? error : len; |
b3b94faa5 [GFS2] The core o... |
196 197 198 199 200 |
} static ssize_t quota_refresh_group_store(struct gfs2_sbd *sdp, const char *buf, size_t len) { |
ed87dabcc gfs2: Convert gfs... |
201 |
struct kqid qid; |
ea7623385 GFS2: Add proper ... |
202 |
int error; |
cd915493f [GFS2] Change all... |
203 |
u32 id; |
b3b94faa5 [GFS2] The core o... |
204 205 |
if (!capable(CAP_SYS_ADMIN)) |
417358187 fs: change return... |
206 |
return -EPERM; |
b3b94faa5 [GFS2] The core o... |
207 |
|
e50ead480 gfs2: convert sim... |
208 209 210 |
error = kstrtou32(buf, 0, &id); if (error) return error; |
b3b94faa5 [GFS2] The core o... |
211 |
|
ed87dabcc gfs2: Convert gfs... |
212 213 214 215 216 |
qid = make_kqid(current_user_ns(), GRPQUOTA, id); if (!qid_valid(qid)) return -EINVAL; error = gfs2_quota_refresh(sdp, qid); |
ea7623385 GFS2: Add proper ... |
217 |
return error ? error : len; |
b3b94faa5 [GFS2] The core o... |
218 |
} |
64d576ba2 GFS2: Add a "demo... |
219 220 221 222 223 224 225 226 227 228 229 |
static ssize_t demote_rq_store(struct gfs2_sbd *sdp, const char *buf, size_t len) { struct gfs2_glock *gl; const struct gfs2_glock_operations *glops; unsigned int glmode; unsigned int gltype; unsigned long long glnum; char mode[16]; int rv; if (!capable(CAP_SYS_ADMIN)) |
417358187 fs: change return... |
230 |
return -EPERM; |
64d576ba2 GFS2: Add a "demo... |
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
rv = sscanf(buf, "%u:%llu %15s", &gltype, &glnum, mode); if (rv != 3) return -EINVAL; if (strcmp(mode, "EX") == 0) glmode = LM_ST_UNLOCKED; else if ((strcmp(mode, "CW") == 0) || (strcmp(mode, "DF") == 0)) glmode = LM_ST_DEFERRED; else if ((strcmp(mode, "PR") == 0) || (strcmp(mode, "SH") == 0)) glmode = LM_ST_SHARED; else return -EINVAL; if (gltype > LM_TYPE_JOURNAL) return -EINVAL; |
24972557b GFS2: remove tran... |
248 249 |
if (gltype == LM_TYPE_NONDISK && glnum == GFS2_FREEZE_LOCK) glops = &gfs2_freeze_glops; |
134669854 GFS2: Fix type ma... |
250 251 |
else glops = gfs2_glops_list[gltype]; |
64d576ba2 GFS2: Add a "demo... |
252 253 |
if (glops == NULL) return -EINVAL; |
6a99be5d7 GFS2: Fix typo |
254 |
if (!test_and_set_bit(SDF_DEMOTE, &sdp->sd_flags)) |
913a71d25 GFS2: Add some us... |
255 256 |
fs_info(sdp, "demote interface used "); |
64d576ba2 GFS2: Add a "demo... |
257 258 259 260 261 262 263 |
rv = gfs2_glock_get(sdp, glnum, glops, 0, &gl); if (rv) return rv; gfs2_glock_cb(gl, glmode); gfs2_glock_put(gl); return len; } |
b3b94faa5 [GFS2] The core o... |
264 265 266 267 268 269 |
#define GFS2_ATTR(name, mode, show, store) \ static struct gfs2_attr gfs2_attr_##name = __ATTR(name, mode, show, store) GFS2_ATTR(id, 0444, id_show, NULL); GFS2_ATTR(fsname, 0444, fsname_show, NULL); |
02e3cc70e GFS2: Expose UUID... |
270 |
GFS2_ATTR(uuid, 0444, uuid_show, NULL); |
b3b94faa5 [GFS2] The core o... |
271 |
GFS2_ATTR(freeze, 0644, freeze_show, freeze_store); |
b3b94faa5 [GFS2] The core o... |
272 273 274 275 276 |
GFS2_ATTR(withdraw, 0644, withdraw_show, withdraw_store); GFS2_ATTR(statfs_sync, 0200, NULL, statfs_sync_store); GFS2_ATTR(quota_sync, 0200, NULL, quota_sync_store); GFS2_ATTR(quota_refresh_user, 0200, NULL, quota_refresh_user_store); GFS2_ATTR(quota_refresh_group, 0200, NULL, quota_refresh_group_store); |
64d576ba2 GFS2: Add a "demo... |
277 |
GFS2_ATTR(demote_rq, 0200, NULL, demote_rq_store); |
b3b94faa5 [GFS2] The core o... |
278 279 280 281 |
static struct attribute *gfs2_attrs[] = { &gfs2_attr_id.attr, &gfs2_attr_fsname.attr, |
02e3cc70e GFS2: Expose UUID... |
282 |
&gfs2_attr_uuid.attr, |
b3b94faa5 [GFS2] The core o... |
283 |
&gfs2_attr_freeze.attr, |
b3b94faa5 [GFS2] The core o... |
284 285 286 287 288 |
&gfs2_attr_withdraw.attr, &gfs2_attr_statfs_sync.attr, &gfs2_attr_quota_sync.attr, &gfs2_attr_quota_refresh_user.attr, &gfs2_attr_quota_refresh_group.attr, |
64d576ba2 GFS2: Add a "demo... |
289 |
&gfs2_attr_demote_rq.attr, |
b3b94faa5 [GFS2] The core o... |
290 291 |
NULL, }; |
ef254d13f gfs2: replace kty... |
292 |
ATTRIBUTE_GROUPS(gfs2); |
b3b94faa5 [GFS2] The core o... |
293 |
|
0d515210b GFS2: Add kobject... |
294 295 296 |
static void gfs2_sbd_release(struct kobject *kobj) { struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj); |
2a27b755e gfs2: Clean up fr... |
297 |
free_sbd(sdp); |
0d515210b GFS2: Add kobject... |
298 |
} |
b3b94faa5 [GFS2] The core o... |
299 |
static struct kobj_type gfs2_ktype = { |
0d515210b GFS2: Add kobject... |
300 |
.release = gfs2_sbd_release, |
ef254d13f gfs2: replace kty... |
301 |
.default_groups = gfs2_groups, |
b3b94faa5 [GFS2] The core o... |
302 303 |
.sysfs_ops = &gfs2_attr_ops, }; |
f057f6cdf GFS2: Merge lock_... |
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
/* * lock_module. Originally from lock_dlm */ static ssize_t proto_name_show(struct gfs2_sbd *sdp, char *buf) { const struct lm_lockops *ops = sdp->sd_lockstruct.ls_ops; return sprintf(buf, "%s ", ops->lm_proto_name); } static ssize_t block_show(struct gfs2_sbd *sdp, char *buf) { struct lm_lockstruct *ls = &sdp->sd_lockstruct; ssize_t ret; int val = 0; |
e0c2a9aa1 GFS2: dlm based r... |
321 |
if (test_bit(DFL_BLOCK_LOCKS, &ls->ls_recover_flags)) |
f057f6cdf GFS2: Merge lock_... |
322 323 324 325 326 327 328 329 330 |
val = 1; ret = sprintf(buf, "%d ", val); return ret; } static ssize_t block_store(struct gfs2_sbd *sdp, const char *buf, size_t len) { struct lm_lockstruct *ls = &sdp->sd_lockstruct; |
e50ead480 gfs2: convert sim... |
331 |
int ret, val; |
f057f6cdf GFS2: Merge lock_... |
332 |
|
e50ead480 gfs2: convert sim... |
333 334 335 |
ret = kstrtoint(buf, 0, &val); if (ret) return ret; |
f057f6cdf GFS2: Merge lock_... |
336 337 |
if (val == 1) |
e0c2a9aa1 GFS2: dlm based r... |
338 |
set_bit(DFL_BLOCK_LOCKS, &ls->ls_recover_flags); |
f057f6cdf GFS2: Merge lock_... |
339 |
else if (val == 0) { |
e0c2a9aa1 GFS2: dlm based r... |
340 |
clear_bit(DFL_BLOCK_LOCKS, &ls->ls_recover_flags); |
4e857c58e arch: Mass conver... |
341 |
smp_mb__after_atomic(); |
f057f6cdf GFS2: Merge lock_... |
342 343 |
gfs2_glock_thaw(sdp); } else { |
e50ead480 gfs2: convert sim... |
344 |
return -EINVAL; |
f057f6cdf GFS2: Merge lock_... |
345 |
} |
e50ead480 gfs2: convert sim... |
346 |
return len; |
f057f6cdf GFS2: Merge lock_... |
347 |
} |
fd95e81cb GFS2: Reinstate w... |
348 349 350 351 352 353 354 355 356 357 |
static ssize_t wdack_show(struct gfs2_sbd *sdp, char *buf) { int val = completion_done(&sdp->sd_wdack) ? 1 : 0; return sprintf(buf, "%d ", val); } static ssize_t wdack_store(struct gfs2_sbd *sdp, const char *buf, size_t len) { |
e50ead480 gfs2: convert sim... |
358 |
int ret, val; |
fd95e81cb GFS2: Reinstate w... |
359 |
|
e50ead480 gfs2: convert sim... |
360 361 362 |
ret = kstrtoint(buf, 0, &val); if (ret) return ret; |
fd95e81cb GFS2: Reinstate w... |
363 364 365 366 367 |
if ((val == 1) && !strcmp(sdp->sd_lockstruct.ls_ops->lm_proto_name, "lock_dlm")) complete(&sdp->sd_wdack); else |
e50ead480 gfs2: convert sim... |
368 369 |
return -EINVAL; return len; |
fd95e81cb GFS2: Reinstate w... |
370 |
} |
f057f6cdf GFS2: Merge lock_... |
371 372 373 374 375 376 |
static ssize_t lkfirst_show(struct gfs2_sbd *sdp, char *buf) { struct lm_lockstruct *ls = &sdp->sd_lockstruct; return sprintf(buf, "%d ", ls->ls_first); } |
ba6e93645 GFS2: Wait for jo... |
377 378 379 380 381 382 383 384 |
static ssize_t lkfirst_store(struct gfs2_sbd *sdp, const char *buf, size_t len) { unsigned first; int rv; rv = sscanf(buf, "%u", &first); if (rv != 1 || first > 1) return -EINVAL; |
3942ae531 GFS2: Fix race du... |
385 386 387 |
rv = wait_for_completion_killable(&sdp->sd_locking_init); if (rv) return rv; |
ba6e93645 GFS2: Wait for jo... |
388 389 390 391 392 393 394 395 396 |
spin_lock(&sdp->sd_jindex_spin); rv = -EBUSY; if (test_bit(SDF_NOJOURNALID, &sdp->sd_flags) == 0) goto out; rv = -EINVAL; if (sdp->sd_args.ar_spectator) goto out; if (sdp->sd_lockstruct.ls_ops->lm_mount == NULL) goto out; |
e0c2a9aa1 GFS2: dlm based r... |
397 398 |
sdp->sd_lockstruct.ls_first = first; rv = 0; |
ba6e93645 GFS2: Wait for jo... |
399 400 401 402 |
out: spin_unlock(&sdp->sd_jindex_spin); return rv ? rv : len; } |
f057f6cdf GFS2: Merge lock_... |
403 404 405 |
static ssize_t first_done_show(struct gfs2_sbd *sdp, char *buf) { struct lm_lockstruct *ls = &sdp->sd_lockstruct; |
e0c2a9aa1 GFS2: dlm based r... |
406 407 |
return sprintf(buf, "%d ", !!test_bit(DFL_FIRST_MOUNT_DONE, &ls->ls_recover_flags)); |
f057f6cdf GFS2: Merge lock_... |
408 |
} |
e0c2a9aa1 GFS2: dlm based r... |
409 |
int gfs2_recover_set(struct gfs2_sbd *sdp, unsigned jid) |
f057f6cdf GFS2: Merge lock_... |
410 411 |
{ struct gfs2_jdesc *jd; |
fe64d517d GFS2: Umount reco... |
412 |
int rv; |
0e48e055a GFS2: Prevent rec... |
413 414 |
/* Wait for our primary journal to be initialized */ wait_for_completion(&sdp->sd_journal_ready); |
f057f6cdf GFS2: Merge lock_... |
415 |
spin_lock(&sdp->sd_jindex_spin); |
fe64d517d GFS2: Umount reco... |
416 |
rv = -EBUSY; |
4a7727725 GFS2: Fix recover... |
417 418 419 420 421 422 423 |
/** * If we're a spectator, we use journal0, but it's not really ours. * So we need to wait for its recovery too. If we skip it we'd never * queue work to the recovery workqueue, and so its completion would * never clear the DFL_BLOCK_LOCKS flag, so all our locks would * permanently stop working. */ |
601ef0d52 gfs2: Force withd... |
424 425 |
if (!sdp->sd_jdesc) goto out; |
4a7727725 GFS2: Fix recover... |
426 |
if (sdp->sd_jdesc->jd_jid == jid && !sdp->sd_args.ar_spectator) |
fe64d517d GFS2: Umount reco... |
427 428 |
goto out; rv = -ENOENT; |
f057f6cdf GFS2: Merge lock_... |
429 |
list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) { |
4a7727725 GFS2: Fix recover... |
430 |
if (jd->jd_jid != jid && !sdp->sd_args.ar_spectator) |
f057f6cdf GFS2: Merge lock_... |
431 |
continue; |
6ecd7c2dd gfs2: use workque... |
432 |
rv = gfs2_recover_journal(jd, false); |
f057f6cdf GFS2: Merge lock_... |
433 434 |
break; } |
fe64d517d GFS2: Umount reco... |
435 |
out: |
f057f6cdf GFS2: Merge lock_... |
436 |
spin_unlock(&sdp->sd_jindex_spin); |
e0c2a9aa1 GFS2: dlm based r... |
437 438 439 440 441 442 443 444 445 446 447 |
return rv; } static ssize_t recover_store(struct gfs2_sbd *sdp, const char *buf, size_t len) { unsigned jid; int rv; rv = sscanf(buf, "%u", &jid); if (rv != 1) return -EINVAL; |
1a058f528 gfs2: fix recover... |
448 449 450 451 |
if (test_bit(SDF_NORECOVERY, &sdp->sd_flags)) { rv = -ESHUTDOWN; goto out; } |
e0c2a9aa1 GFS2: dlm based r... |
452 |
|
1a058f528 gfs2: fix recover... |
453 454 |
rv = gfs2_recover_set(sdp, jid); out: |
fe64d517d GFS2: Umount reco... |
455 |
return rv ? rv : len; |
f057f6cdf GFS2: Merge lock_... |
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 |
} static ssize_t recover_done_show(struct gfs2_sbd *sdp, char *buf) { struct lm_lockstruct *ls = &sdp->sd_lockstruct; return sprintf(buf, "%d ", ls->ls_recover_jid_done); } static ssize_t recover_status_show(struct gfs2_sbd *sdp, char *buf) { struct lm_lockstruct *ls = &sdp->sd_lockstruct; return sprintf(buf, "%d ", ls->ls_recover_jid_status); } |
e1b28aab5 GFS2: Remove lock... |
471 472 |
static ssize_t jid_show(struct gfs2_sbd *sdp, char *buf) { |
feb47ca93 GFS2: Improve jou... |
473 474 |
return sprintf(buf, "%d ", sdp->sd_lockstruct.ls_jid); |
e1b28aab5 GFS2: Remove lock... |
475 |
} |
ba6e93645 GFS2: Wait for jo... |
476 477 |
static ssize_t jid_store(struct gfs2_sbd *sdp, const char *buf, size_t len) { |
feb47ca93 GFS2: Improve jou... |
478 |
int jid; |
ba6e93645 GFS2: Wait for jo... |
479 |
int rv; |
feb47ca93 GFS2: Improve jou... |
480 |
rv = sscanf(buf, "%d", &jid); |
ba6e93645 GFS2: Wait for jo... |
481 482 |
if (rv != 1) return -EINVAL; |
3942ae531 GFS2: Fix race du... |
483 484 485 |
rv = wait_for_completion_killable(&sdp->sd_locking_init); if (rv) return rv; |
ba6e93645 GFS2: Wait for jo... |
486 487 |
spin_lock(&sdp->sd_jindex_spin); rv = -EINVAL; |
ba6e93645 GFS2: Wait for jo... |
488 489 490 |
if (sdp->sd_lockstruct.ls_ops->lm_mount == NULL) goto out; rv = -EBUSY; |
feb47ca93 GFS2: Improve jou... |
491 |
if (test_bit(SDF_NOJOURNALID, &sdp->sd_flags) == 0) |
ba6e93645 GFS2: Wait for jo... |
492 |
goto out; |
feb47ca93 GFS2: Improve jou... |
493 494 495 |
rv = 0; if (sdp->sd_args.ar_spectator && jid > 0) rv = jid = -EINVAL; |
ba6e93645 GFS2: Wait for jo... |
496 |
sdp->sd_lockstruct.ls_jid = jid; |
feb47ca93 GFS2: Improve jou... |
497 |
clear_bit(SDF_NOJOURNALID, &sdp->sd_flags); |
4e857c58e arch: Mass conver... |
498 |
smp_mb__after_atomic(); |
ba6e93645 GFS2: Wait for jo... |
499 |
wake_up_bit(&sdp->sd_flags, SDF_NOJOURNALID); |
ba6e93645 GFS2: Wait for jo... |
500 501 502 503 |
out: spin_unlock(&sdp->sd_jindex_spin); return rv ? rv : len; } |
f057f6cdf GFS2: Merge lock_... |
504 |
#define GDLM_ATTR(_name,_mode,_show,_store) \ |
48c2b6136 GFS2: Add commit=... |
505 |
static struct gfs2_attr gdlm_attr_##_name = __ATTR(_name,_mode,_show,_store) |
f057f6cdf GFS2: Merge lock_... |
506 |
|
d7e623da1 GFS2: Fix permiss... |
507 508 |
GDLM_ATTR(proto_name, 0444, proto_name_show, NULL); GDLM_ATTR(block, 0644, block_show, block_store); |
fd95e81cb GFS2: Reinstate w... |
509 |
GDLM_ATTR(withdraw, 0644, wdack_show, wdack_store); |
ba6e93645 GFS2: Wait for jo... |
510 511 |
GDLM_ATTR(jid, 0644, jid_show, jid_store); GDLM_ATTR(first, 0644, lkfirst_show, lkfirst_store); |
d7e623da1 GFS2: Fix permiss... |
512 513 514 515 |
GDLM_ATTR(first_done, 0444, first_done_show, NULL); GDLM_ATTR(recover, 0600, NULL, recover_store); GDLM_ATTR(recover_done, 0444, recover_done_show, NULL); GDLM_ATTR(recover_status, 0444, recover_status_show, NULL); |
f057f6cdf GFS2: Merge lock_... |
516 517 518 519 520 |
static struct attribute *lock_module_attrs[] = { &gdlm_attr_proto_name.attr, &gdlm_attr_block.attr, &gdlm_attr_withdraw.attr, |
e1b28aab5 GFS2: Remove lock... |
521 |
&gdlm_attr_jid.attr, |
f057f6cdf GFS2: Merge lock_... |
522 523 524 525 526 |
&gdlm_attr_first.attr, &gdlm_attr_first_done.attr, &gdlm_attr_recover.attr, &gdlm_attr_recover_done.attr, &gdlm_attr_recover_status.attr, |
ea67eedb2 [GFS2] Fix end of... |
527 |
NULL, |
b3b94faa5 [GFS2] The core o... |
528 |
}; |
b3b94faa5 [GFS2] The core o... |
529 |
/* |
b3b94faa5 [GFS2] The core o... |
530 531 532 533 534 |
* get and set struct gfs2_tune fields */ static ssize_t quota_scale_show(struct gfs2_sbd *sdp, char *buf) { |
3204a6c05 [GFS2] use snprin... |
535 536 537 538 |
return snprintf(buf, PAGE_SIZE, "%u %u ", sdp->sd_tune.gt_quota_scale_num, sdp->sd_tune.gt_quota_scale_den); |
b3b94faa5 [GFS2] The core o... |
539 540 541 542 543 544 545 546 547 |
} static ssize_t quota_scale_store(struct gfs2_sbd *sdp, const char *buf, size_t len) { struct gfs2_tune *gt = &sdp->sd_tune; unsigned int x, y; if (!capable(CAP_SYS_ADMIN)) |
417358187 fs: change return... |
548 |
return -EPERM; |
b3b94faa5 [GFS2] The core o... |
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 |
if (sscanf(buf, "%u %u", &x, &y) != 2 || !y) return -EINVAL; spin_lock(>->gt_spin); gt->gt_quota_scale_num = x; gt->gt_quota_scale_den = y; spin_unlock(>->gt_spin); return len; } static ssize_t tune_set(struct gfs2_sbd *sdp, unsigned int *field, int check_zero, const char *buf, size_t len) { struct gfs2_tune *gt = &sdp->sd_tune; unsigned int x; |
e50ead480 gfs2: convert sim... |
565 |
int error; |
b3b94faa5 [GFS2] The core o... |
566 567 |
if (!capable(CAP_SYS_ADMIN)) |
417358187 fs: change return... |
568 |
return -EPERM; |
b3b94faa5 [GFS2] The core o... |
569 |
|
e50ead480 gfs2: convert sim... |
570 571 572 |
error = kstrtouint(buf, 0, &x); if (error) return error; |
b3b94faa5 [GFS2] The core o... |
573 574 575 576 577 578 579 580 581 |
if (check_zero && !x) return -EINVAL; spin_lock(>->gt_spin); *field = x; spin_unlock(>->gt_spin); return len; } |
b3b94faa5 [GFS2] The core o... |
582 |
#define TUNE_ATTR_3(name, show, store) \ |
48c2b6136 GFS2: Add commit=... |
583 |
static struct gfs2_attr tune_attr_##name = __ATTR(name, 0644, show, store) |
b3b94faa5 [GFS2] The core o... |
584 585 586 587 |
#define TUNE_ATTR_2(name, store) \ static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \ { \ |
3204a6c05 [GFS2] use snprin... |
588 589 |
return snprintf(buf, PAGE_SIZE, "%u ", sdp->sd_tune.gt_##name); \ |
b3b94faa5 [GFS2] The core o... |
590 591 592 593 594 595 596 597 598 |
} \ TUNE_ATTR_3(name, name##_show, store) #define TUNE_ATTR(name, check_zero) \ static ssize_t name##_store(struct gfs2_sbd *sdp, const char *buf, size_t len)\ { \ return tune_set(sdp, &sdp->sd_tune.gt_##name, check_zero, buf, len); \ } \ TUNE_ATTR_2(name, name##_store) |
b3b94faa5 [GFS2] The core o... |
599 600 |
TUNE_ATTR(quota_warn_period, 0); TUNE_ATTR(quota_quantum, 0); |
b3b94faa5 [GFS2] The core o... |
601 602 |
TUNE_ATTR(max_readahead, 0); TUNE_ATTR(complain_secs, 0); |
b3b94faa5 [GFS2] The core o... |
603 604 |
TUNE_ATTR(statfs_slow, 0); TUNE_ATTR(new_files_jdata, 0); |
b3b94faa5 [GFS2] The core o... |
605 |
TUNE_ATTR(statfs_quantum, 1); |
b3b94faa5 [GFS2] The core o... |
606 607 608 |
TUNE_ATTR_3(quota_scale, quota_scale_show, quota_scale_store); static struct attribute *tune_attrs[] = { |
b3b94faa5 [GFS2] The core o... |
609 610 |
&tune_attr_quota_warn_period.attr, &tune_attr_quota_quantum.attr, |
b3b94faa5 [GFS2] The core o... |
611 612 |
&tune_attr_max_readahead.attr, &tune_attr_complain_secs.attr, |
b3b94faa5 [GFS2] The core o... |
613 |
&tune_attr_statfs_slow.attr, |
b3b94faa5 [GFS2] The core o... |
614 |
&tune_attr_statfs_quantum.attr, |
b3b94faa5 [GFS2] The core o... |
615 616 |
&tune_attr_quota_scale.attr, &tune_attr_new_files_jdata.attr, |
ea67eedb2 [GFS2] Fix end of... |
617 |
NULL, |
b3b94faa5 [GFS2] The core o... |
618 |
}; |
29695254e GFS2: constify at... |
619 |
static const struct attribute_group tune_group = { |
b3b94faa5 [GFS2] The core o... |
620 |
.name = "tune", |
ea67eedb2 [GFS2] Fix end of... |
621 |
.attrs = tune_attrs, |
b3b94faa5 [GFS2] The core o... |
622 |
}; |
29695254e GFS2: constify at... |
623 |
static const struct attribute_group lock_module_group = { |
f057f6cdf GFS2: Merge lock_... |
624 625 626 |
.name = "lock_module", .attrs = lock_module_attrs, }; |
b3b94faa5 [GFS2] The core o... |
627 628 |
int gfs2_sys_fs_add(struct gfs2_sbd *sdp) { |
440d6da20 GFS2: Add some mo... |
629 |
struct super_block *sb = sdp->sd_vfs; |
b3b94faa5 [GFS2] The core o... |
630 |
int error; |
440d6da20 GFS2: Add some mo... |
631 632 633 |
char ro[20]; char spectator[20]; char *envp[] = { ro, spectator, NULL }; |
bc98a42c1 VFS: Convert sb->... |
634 |
sprintf(ro, "RDONLY=%d", sb_rdonly(sb)); |
440d6da20 GFS2: Add some mo... |
635 |
sprintf(spectator, "SPECTATOR=%d", sdp->sd_args.ar_spectator ? 1 : 0); |
b3b94faa5 [GFS2] The core o... |
636 |
|
9bec101a0 kset: convert gfs... |
637 |
sdp->sd_kobj.kset = gfs2_kset; |
901195ed7 Kobject: change G... |
638 639 |
error = kobject_init_and_add(&sdp->sd_kobj, &gfs2_ktype, NULL, "%s", sdp->sd_table_name); |
b3b94faa5 [GFS2] The core o... |
640 |
if (error) |
0d515210b GFS2: Add kobject... |
641 |
goto fail_reg; |
b3b94faa5 [GFS2] The core o... |
642 |
|
b3b94faa5 [GFS2] The core o... |
643 644 |
error = sysfs_create_group(&sdp->sd_kobj, &tune_group); if (error) |
f6eb53498 GFS2: Remove args... |
645 |
goto fail_reg; |
b3b94faa5 [GFS2] The core o... |
646 |
|
f057f6cdf GFS2: Merge lock_... |
647 648 649 |
error = sysfs_create_group(&sdp->sd_kobj, &lock_module_group); if (error) goto fail_tune; |
31e54b01f GFS2: Add sysfs l... |
650 651 652 653 654 |
error = sysfs_create_link(&sdp->sd_kobj, &disk_to_dev(sb->s_bdev->bd_disk)->kobj, "device"); if (error) goto fail_lock_module; |
440d6da20 GFS2: Add some mo... |
655 |
kobject_uevent_env(&sdp->sd_kobj, KOBJ_ADD, envp); |
b3b94faa5 [GFS2] The core o... |
656 |
return 0; |
31e54b01f GFS2: Add sysfs l... |
657 658 |
fail_lock_module: sysfs_remove_group(&sdp->sd_kobj, &lock_module_group); |
f057f6cdf GFS2: Merge lock_... |
659 660 |
fail_tune: sysfs_remove_group(&sdp->sd_kobj, &tune_group); |
a91ea69ff [GFS2] Align all ... |
661 |
fail_reg: |
af38816e4 gfs2: Add a few m... |
662 663 |
fs_err(sdp, "error %d adding sysfs files ", error); |
fbcde197e gfs2: Fix error p... |
664 |
kobject_put(&sdp->sd_kobj); |
0d515210b GFS2: Add kobject... |
665 |
sb->s_fs_info = NULL; |
b3b94faa5 [GFS2] The core o... |
666 667 668 669 670 |
return error; } void gfs2_sys_fs_del(struct gfs2_sbd *sdp) { |
31e54b01f GFS2: Add sysfs l... |
671 |
sysfs_remove_link(&sdp->sd_kobj, "device"); |
b3b94faa5 [GFS2] The core o... |
672 |
sysfs_remove_group(&sdp->sd_kobj, &tune_group); |
f057f6cdf GFS2: Merge lock_... |
673 |
sysfs_remove_group(&sdp->sd_kobj, &lock_module_group); |
197b12d67 Kobject: convert ... |
674 |
kobject_put(&sdp->sd_kobj); |
b3b94faa5 [GFS2] The core o... |
675 |
} |
fdd1062eb GFS2: Send some s... |
676 677 678 679 |
static int gfs2_uevent(struct kset *kset, struct kobject *kobj, struct kobj_uevent_env *env) { struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj); |
32e471ef1 GFS2: Use UUID fi... |
680 |
struct super_block *s = sdp->sd_vfs; |
02e3cc70e GFS2: Expose UUID... |
681 |
|
fdd1062eb GFS2: Send some s... |
682 683 |
add_uevent_var(env, "LOCKTABLE=%s", sdp->sd_table_name); add_uevent_var(env, "LOCKPROTO=%s", sdp->sd_proto_name); |
ba6e93645 GFS2: Wait for jo... |
684 |
if (!test_bit(SDF_NOJOURNALID, &sdp->sd_flags)) |
feb47ca93 GFS2: Improve jou... |
685 |
add_uevent_var(env, "JOURNALID=%d", sdp->sd_lockstruct.ls_jid); |
85787090a fs: switch ->s_uu... |
686 687 |
if (!uuid_is_null(&s->s_uuid)) add_uevent_var(env, "UUID=%pUB", &s->s_uuid); |
fdd1062eb GFS2: Send some s... |
688 689 |
return 0; } |
9cd43611c kobject: Constify... |
690 |
static const struct kset_uevent_ops gfs2_uevent_ops = { |
fdd1062eb GFS2: Send some s... |
691 692 |
.uevent = gfs2_uevent, }; |
b3b94faa5 [GFS2] The core o... |
693 694 |
int gfs2_sys_init(void) { |
fdd1062eb GFS2: Send some s... |
695 |
gfs2_kset = kset_create_and_add("gfs2", &gfs2_uevent_ops, fs_kobj); |
9bec101a0 kset: convert gfs... |
696 697 698 |
if (!gfs2_kset) return -ENOMEM; return 0; |
b3b94faa5 [GFS2] The core o... |
699 700 701 702 |
} void gfs2_sys_uninit(void) { |
9bec101a0 kset: convert gfs... |
703 |
kset_unregister(gfs2_kset); |
b3b94faa5 [GFS2] The core o... |
704 |
} |