Skip to content

Commit

Permalink
f2fs: introduce f2fs_base_attr for global sysfs entries
Browse files Browse the repository at this point in the history
[ Upstream commit 21925ed ]

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>
  • Loading branch information
Jaegeuk Kim authored and Greg Kroah-Hartman committed Jun 4, 2025
1 parent 9af429f commit 6fed5e2
Showing 1 changed file with 52 additions and 22 deletions.
74 changes: 52 additions & 22 deletions fs/f2fs/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ struct f2fs_attr {
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,
struct f2fs_sb_info *sbi, char *buf);

Expand Down Expand Up @@ -791,6 +797,25 @@ static void f2fs_sb_release(struct kobject *kobj)
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:
* 1) /sys/fs/f2fs/features
Expand All @@ -809,14 +834,13 @@ static void f2fs_sb_release(struct kobject *kobj)
* please add new on-disk feature in this list only.
* - ref. F2FS_SB_FEATURE_RO_ATTR()
*/
static ssize_t f2fs_feature_show(struct f2fs_attr *a,
struct f2fs_sb_info *sbi, char *buf)
static ssize_t f2fs_feature_show(struct f2fs_base_attr *a, char *buf)
{
return sysfs_emit(buf, "supported\n");
}

#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 }, \
.show = f2fs_feature_show, \
}
Expand Down Expand Up @@ -1166,37 +1190,38 @@ static struct attribute *f2fs_attrs[] = {
};
ATTRIBUTE_GROUPS(f2fs);

#define BASE_ATTR_LIST(name) (&f2fs_base_attr_##name.attr)
static struct attribute *f2fs_feat_attrs[] = {
#ifdef CONFIG_FS_ENCRYPTION
ATTR_LIST(encryption),
ATTR_LIST(test_dummy_encryption_v2),
BASE_ATTR_LIST(encryption),
BASE_ATTR_LIST(test_dummy_encryption_v2),
#if IS_ENABLED(CONFIG_UNICODE)
ATTR_LIST(encrypted_casefold),
BASE_ATTR_LIST(encrypted_casefold),
#endif
#endif /* CONFIG_FS_ENCRYPTION */
#ifdef CONFIG_BLK_DEV_ZONED
ATTR_LIST(block_zoned),
BASE_ATTR_LIST(block_zoned),
#endif
ATTR_LIST(atomic_write),
ATTR_LIST(extra_attr),
ATTR_LIST(project_quota),
ATTR_LIST(inode_checksum),
ATTR_LIST(flexible_inline_xattr),
ATTR_LIST(quota_ino),
ATTR_LIST(inode_crtime),
ATTR_LIST(lost_found),
BASE_ATTR_LIST(atomic_write),
BASE_ATTR_LIST(extra_attr),
BASE_ATTR_LIST(project_quota),
BASE_ATTR_LIST(inode_checksum),
BASE_ATTR_LIST(flexible_inline_xattr),
BASE_ATTR_LIST(quota_ino),
BASE_ATTR_LIST(inode_crtime),
BASE_ATTR_LIST(lost_found),
#ifdef CONFIG_FS_VERITY
ATTR_LIST(verity),
BASE_ATTR_LIST(verity),
#endif
ATTR_LIST(sb_checksum),
BASE_ATTR_LIST(sb_checksum),
#if IS_ENABLED(CONFIG_UNICODE)
ATTR_LIST(casefold),
BASE_ATTR_LIST(casefold),
#endif
ATTR_LIST(readonly),
BASE_ATTR_LIST(readonly),
#ifdef CONFIG_F2FS_FS_COMPRESSION
ATTR_LIST(compression),
BASE_ATTR_LIST(compression),
#endif
ATTR_LIST(pin_file),
BASE_ATTR_LIST(pin_file),
NULL,
};
ATTRIBUTE_GROUPS(f2fs_feat);
Expand Down Expand Up @@ -1263,9 +1288,14 @@ static struct kset f2fs_kset = {
.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 = {
.default_groups = f2fs_feat_groups,
.sysfs_ops = &f2fs_attr_ops,
.sysfs_ops = &f2fs_feat_attr_ops,
};

static struct kobject f2fs_feat = {
Expand Down

0 comments on commit 6fed5e2

Please sign in to comment.