Skip to content

Commit ed2e35d

Browse files
adam900710kdave
authored andcommitted
btrfs: sysfs: introduce global qgroup attribute group
Although we already have info kobject for each qgroup, we don't have global qgroup info attributes to show things like enabled or inconsistent status flags. Add this qgroups attribute groups, and the first member is qgroup_flags, which is a read-only attribute to show human readable qgroup flags. The path is: /sys/fs/btrfs/<uuid>/qgroups/enabled /sys/fs/btrfs/<uuid>/qgroups/inconsistent The output is simple, just 1 or 0. Signed-off-by: Qu Wenruo <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent ac3c0d3 commit ed2e35d

File tree

1 file changed

+61
-4
lines changed

1 file changed

+61
-4
lines changed

fs/btrfs/sysfs.c

+61-4
Original file line numberDiff line numberDiff line change
@@ -2015,6 +2015,59 @@ int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info)
20152015
return error;
20162016
}
20172017

2018+
static ssize_t qgroup_enabled_show(struct kobject *qgroups_kobj,
2019+
struct kobj_attribute *a,
2020+
char *buf)
2021+
{
2022+
struct btrfs_fs_info *fs_info = to_fs_info(qgroups_kobj->parent);
2023+
bool enabled;
2024+
2025+
spin_lock(&fs_info->qgroup_lock);
2026+
enabled = fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_ON;
2027+
spin_unlock(&fs_info->qgroup_lock);
2028+
2029+
return sysfs_emit(buf, "%d\n", enabled);
2030+
}
2031+
BTRFS_ATTR(qgroups, enabled, qgroup_enabled_show);
2032+
2033+
static ssize_t qgroup_inconsistent_show(struct kobject *qgroups_kobj,
2034+
struct kobj_attribute *a,
2035+
char *buf)
2036+
{
2037+
struct btrfs_fs_info *fs_info = to_fs_info(qgroups_kobj->parent);
2038+
bool inconsistent;
2039+
2040+
spin_lock(&fs_info->qgroup_lock);
2041+
inconsistent = (fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT);
2042+
spin_unlock(&fs_info->qgroup_lock);
2043+
2044+
return sysfs_emit(buf, "%d\n", inconsistent);
2045+
}
2046+
BTRFS_ATTR(qgroups, inconsistent, qgroup_inconsistent_show);
2047+
2048+
/*
2049+
* Qgroups global info
2050+
*
2051+
* Path: /sys/fs/btrfs/<uuid>/qgroups/
2052+
*/
2053+
static struct attribute *qgroups_attrs[] = {
2054+
BTRFS_ATTR_PTR(qgroups, enabled),
2055+
BTRFS_ATTR_PTR(qgroups, inconsistent),
2056+
NULL
2057+
};
2058+
ATTRIBUTE_GROUPS(qgroups);
2059+
2060+
static void qgroups_release(struct kobject *kobj)
2061+
{
2062+
kfree(kobj);
2063+
}
2064+
2065+
static struct kobj_type qgroups_ktype = {
2066+
.sysfs_ops = &kobj_sysfs_ops,
2067+
.default_groups = qgroups_groups,
2068+
.release = qgroups_release,
2069+
};
2070+
20182071
static inline struct btrfs_fs_info *qgroup_kobj_to_fs_info(struct kobject *kobj)
20192072
{
20202073
return to_fs_info(kobj->parent->parent);
@@ -2140,11 +2193,15 @@ int btrfs_sysfs_add_qgroups(struct btrfs_fs_info *fs_info)
21402193
if (fs_info->qgroups_kobj)
21412194
return 0;
21422195

2143-
fs_info->qgroups_kobj = kobject_create_and_add("qgroups", fsid_kobj);
2144-
if (!fs_info->qgroups_kobj) {
2145-
ret = -ENOMEM;
2196+
fs_info->qgroups_kobj = kzalloc(sizeof(struct kobject), GFP_KERNEL);
2197+
if (!fs_info->qgroups_kobj)
2198+
return -ENOMEM;
2199+
2200+
ret = kobject_init_and_add(fs_info->qgroups_kobj, &qgroups_ktype,
2201+
fsid_kobj, "qgroups");
2202+
if (ret < 0)
21462203
goto out;
2147-
}
2204+
21482205
rbtree_postorder_for_each_entry_safe(qgroup, next,
21492206
&fs_info->qgroup_tree, node) {
21502207
ret = btrfs_sysfs_add_one_qgroup(fs_info, qgroup);

0 commit comments

Comments
 (0)