f2fs: introduce f2fs_base_attr for global sysfs entries

[ Upstream commit 21925ede449e038ed6f9efdfe0e79f15bddc34bc ]

In /sys/fs/f2fs/features, there's no f2fs_sb_info, so let's avoid to get
the pointer.

Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
Jaegeuk Kim
2025-01-30 05:06:07 +00:00
committed by Greg Kroah-Hartman
parent 9af429febf
commit 6fed5e23d2

View File

@@ -61,6 +61,12 @@ struct f2fs_attr {
int id; int id;
}; };
struct f2fs_base_attr {
struct attribute attr;
ssize_t (*show)(struct f2fs_base_attr *a, char *buf);
ssize_t (*store)(struct f2fs_base_attr *a, const char *buf, size_t len);
};
static ssize_t f2fs_sbi_show(struct f2fs_attr *a, static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
struct f2fs_sb_info *sbi, char *buf); struct f2fs_sb_info *sbi, char *buf);
@@ -791,6 +797,25 @@ static void f2fs_sb_release(struct kobject *kobj)
complete(&sbi->s_kobj_unregister); complete(&sbi->s_kobj_unregister);
} }
static ssize_t f2fs_base_attr_show(struct kobject *kobj,
struct attribute *attr, char *buf)
{
struct f2fs_base_attr *a = container_of(attr,
struct f2fs_base_attr, attr);
return a->show ? a->show(a, buf) : 0;
}
static ssize_t f2fs_base_attr_store(struct kobject *kobj,
struct attribute *attr,
const char *buf, size_t len)
{
struct f2fs_base_attr *a = container_of(attr,
struct f2fs_base_attr, attr);
return a->store ? a->store(a, buf, len) : 0;
}
/* /*
* Note that there are three feature list entries: * Note that there are three feature list entries:
* 1) /sys/fs/f2fs/features * 1) /sys/fs/f2fs/features
@@ -809,14 +834,13 @@ static void f2fs_sb_release(struct kobject *kobj)
* please add new on-disk feature in this list only. * please add new on-disk feature in this list only.
* - ref. F2FS_SB_FEATURE_RO_ATTR() * - ref. F2FS_SB_FEATURE_RO_ATTR()
*/ */
static ssize_t f2fs_feature_show(struct f2fs_attr *a, static ssize_t f2fs_feature_show(struct f2fs_base_attr *a, char *buf)
struct f2fs_sb_info *sbi, char *buf)
{ {
return sysfs_emit(buf, "supported\n"); return sysfs_emit(buf, "supported\n");
} }
#define F2FS_FEATURE_RO_ATTR(_name) \ #define F2FS_FEATURE_RO_ATTR(_name) \
static struct f2fs_attr f2fs_attr_##_name = { \ static struct f2fs_base_attr f2fs_base_attr_##_name = { \
.attr = {.name = __stringify(_name), .mode = 0444 }, \ .attr = {.name = __stringify(_name), .mode = 0444 }, \
.show = f2fs_feature_show, \ .show = f2fs_feature_show, \
} }
@@ -1166,37 +1190,38 @@ static struct attribute *f2fs_attrs[] = {
}; };
ATTRIBUTE_GROUPS(f2fs); ATTRIBUTE_GROUPS(f2fs);
#define BASE_ATTR_LIST(name) (&f2fs_base_attr_##name.attr)
static struct attribute *f2fs_feat_attrs[] = { static struct attribute *f2fs_feat_attrs[] = {
#ifdef CONFIG_FS_ENCRYPTION #ifdef CONFIG_FS_ENCRYPTION
ATTR_LIST(encryption), BASE_ATTR_LIST(encryption),
ATTR_LIST(test_dummy_encryption_v2), BASE_ATTR_LIST(test_dummy_encryption_v2),
#if IS_ENABLED(CONFIG_UNICODE) #if IS_ENABLED(CONFIG_UNICODE)
ATTR_LIST(encrypted_casefold), BASE_ATTR_LIST(encrypted_casefold),
#endif #endif
#endif /* CONFIG_FS_ENCRYPTION */ #endif /* CONFIG_FS_ENCRYPTION */
#ifdef CONFIG_BLK_DEV_ZONED #ifdef CONFIG_BLK_DEV_ZONED
ATTR_LIST(block_zoned), BASE_ATTR_LIST(block_zoned),
#endif #endif
ATTR_LIST(atomic_write), BASE_ATTR_LIST(atomic_write),
ATTR_LIST(extra_attr), BASE_ATTR_LIST(extra_attr),
ATTR_LIST(project_quota), BASE_ATTR_LIST(project_quota),
ATTR_LIST(inode_checksum), BASE_ATTR_LIST(inode_checksum),
ATTR_LIST(flexible_inline_xattr), BASE_ATTR_LIST(flexible_inline_xattr),
ATTR_LIST(quota_ino), BASE_ATTR_LIST(quota_ino),
ATTR_LIST(inode_crtime), BASE_ATTR_LIST(inode_crtime),
ATTR_LIST(lost_found), BASE_ATTR_LIST(lost_found),
#ifdef CONFIG_FS_VERITY #ifdef CONFIG_FS_VERITY
ATTR_LIST(verity), BASE_ATTR_LIST(verity),
#endif #endif
ATTR_LIST(sb_checksum), BASE_ATTR_LIST(sb_checksum),
#if IS_ENABLED(CONFIG_UNICODE) #if IS_ENABLED(CONFIG_UNICODE)
ATTR_LIST(casefold), BASE_ATTR_LIST(casefold),
#endif #endif
ATTR_LIST(readonly), BASE_ATTR_LIST(readonly),
#ifdef CONFIG_F2FS_FS_COMPRESSION #ifdef CONFIG_F2FS_FS_COMPRESSION
ATTR_LIST(compression), BASE_ATTR_LIST(compression),
#endif #endif
ATTR_LIST(pin_file), BASE_ATTR_LIST(pin_file),
NULL, NULL,
}; };
ATTRIBUTE_GROUPS(f2fs_feat); ATTRIBUTE_GROUPS(f2fs_feat);
@@ -1263,9 +1288,14 @@ static struct kset f2fs_kset = {
.kobj = {.ktype = &f2fs_ktype}, .kobj = {.ktype = &f2fs_ktype},
}; };
static const struct sysfs_ops f2fs_feat_attr_ops = {
.show = f2fs_base_attr_show,
.store = f2fs_base_attr_store,
};
static const struct kobj_type f2fs_feat_ktype = { static const struct kobj_type f2fs_feat_ktype = {
.default_groups = f2fs_feat_groups, .default_groups = f2fs_feat_groups,
.sysfs_ops = &f2fs_attr_ops, .sysfs_ops = &f2fs_feat_attr_ops,
}; };
static struct kobject f2fs_feat = { static struct kobject f2fs_feat = {