Message ID | 9c9d150a93e91a5a648840ef77240e81b70ff769.1690495785.git.boris@bur.io (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | btrfs: simple quotas | expand |
On Thu, Jul 27, 2023 at 03:12:50PM -0700, Boris Burkov wrote: > Add a new sysfs file > /sys/fs/btrfs/<uuid>/qgroups/mode > which prints out the mode qgroups is running in. The possible modes are > disabled, qgroup, and squota > > Signed-off-by: Boris Burkov <boris@bur.io> Reviewed-by: Josef Bacik <josef@toxicpanda.com> Thanks, Josef
On Thu, Jul 27, 2023 at 03:12:50PM -0700, Boris Burkov wrote: > Add a new sysfs file > /sys/fs/btrfs/<uuid>/qgroups/mode > which prints out the mode qgroups is running in. The possible modes are > disabled, qgroup, and squota Can you get the 'disabled' at all? Because when the quotas are disabled by ioctl the whole sysfs directory is gone, see btrfs_free_qgroup_config(). > Signed-off-by: Boris Burkov <boris@bur.io> > --- > fs/btrfs/sysfs.c | 26 ++++++++++++++++++++++++++ > 1 file changed, 26 insertions(+) > > diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c > index b1d1ac25237b..e53614753391 100644 > --- a/fs/btrfs/sysfs.c > +++ b/fs/btrfs/sysfs.c > @@ -2086,6 +2086,31 @@ static ssize_t qgroup_enabled_show(struct kobject *qgroups_kobj, > } > BTRFS_ATTR(qgroups, enabled, qgroup_enabled_show); > > +static ssize_t qgroup_mode_show(struct kobject *qgroups_kobj, > + struct kobj_attribute *a, > + char *buf) > +{ > + struct btrfs_fs_info *fs_info = to_fs_info(qgroups_kobj->parent); > + char *mode = ""; > + > + spin_lock(&fs_info->qgroup_lock); > + switch (btrfs_qgroup_mode(fs_info)) { > + case BTRFS_QGROUP_MODE_DISABLED: > + mode = "disabled"; > + break; > + case BTRFS_QGROUP_MODE_FULL: > + mode = "qgroup"; > + break; > + case BTRFS_QGROUP_MODE_SIMPLE: > + mode = "squota"; You can do lock; switch (mode) { case FULL: sysfs_emit(buf, "qgroup\n"); break; case SIMPLE: sysfs_emit(buf, "simple\n"); break; } unlock; return 7; or track the return value from sysfs_emit so it's not so hacky. > + break; > + } > + spin_unlock(&fs_info->qgroup_lock); > + > + return sysfs_emit(buf, "%s\n", mode); > +} > +BTRFS_ATTR(qgroups, mode, qgroup_mode_show); > + > static ssize_t qgroup_inconsistent_show(struct kobject *qgroups_kobj, > struct kobj_attribute *a, > char *buf) > @@ -2148,6 +2173,7 @@ static struct attribute *qgroups_attrs[] = { > BTRFS_ATTR_PTR(qgroups, enabled), > BTRFS_ATTR_PTR(qgroups, inconsistent), > BTRFS_ATTR_PTR(qgroups, drop_subtree_threshold), > + BTRFS_ATTR_PTR(qgroups, mode), > NULL > }; > ATTRIBUTE_GROUPS(qgroups); > -- > 2.41.0
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index b1d1ac25237b..e53614753391 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -2086,6 +2086,31 @@ static ssize_t qgroup_enabled_show(struct kobject *qgroups_kobj, } BTRFS_ATTR(qgroups, enabled, qgroup_enabled_show); +static ssize_t qgroup_mode_show(struct kobject *qgroups_kobj, + struct kobj_attribute *a, + char *buf) +{ + struct btrfs_fs_info *fs_info = to_fs_info(qgroups_kobj->parent); + char *mode = ""; + + spin_lock(&fs_info->qgroup_lock); + switch (btrfs_qgroup_mode(fs_info)) { + case BTRFS_QGROUP_MODE_DISABLED: + mode = "disabled"; + break; + case BTRFS_QGROUP_MODE_FULL: + mode = "qgroup"; + break; + case BTRFS_QGROUP_MODE_SIMPLE: + mode = "squota"; + break; + } + spin_unlock(&fs_info->qgroup_lock); + + return sysfs_emit(buf, "%s\n", mode); +} +BTRFS_ATTR(qgroups, mode, qgroup_mode_show); + static ssize_t qgroup_inconsistent_show(struct kobject *qgroups_kobj, struct kobj_attribute *a, char *buf) @@ -2148,6 +2173,7 @@ static struct attribute *qgroups_attrs[] = { BTRFS_ATTR_PTR(qgroups, enabled), BTRFS_ATTR_PTR(qgroups, inconsistent), BTRFS_ATTR_PTR(qgroups, drop_subtree_threshold), + BTRFS_ATTR_PTR(qgroups, mode), NULL }; ATTRIBUTE_GROUPS(qgroups);
Add a new sysfs file /sys/fs/btrfs/<uuid>/qgroups/mode which prints out the mode qgroups is running in. The possible modes are disabled, qgroup, and squota Signed-off-by: Boris Burkov <boris@bur.io> --- fs/btrfs/sysfs.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)