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