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