Skip to content

Commit c7f7254

Browse files
Lukas Czernertytso
authored andcommitted
ext4: provide separate operations for sysfs feature files
Currently sysfs feature files uses ext4_attr_ops as the file operations to show/store data. However the feature files is not supposed to contain any data at all, the sole existence of the file means that the module support the feature. Moreover, none of the sysfs feature attributes actually register show/store functions so that would not be a problem. However if a sysfs feature attribute register a show or store function we might be in trouble because the kobject in this case is _not_ embedded in the ext4_sb_info structure as ext4_attr_show/store expect. So just to be safe, provide separate empty sysfs_ops to use in ext4_feat_ktype. This might safe us from potential problems in the future. As a bonus we can "store" something more descriptive than nothing in the files, so let it contain "enabled" to make it clear that the feature is really present in the module. Signed-off-by: Lukas Czerner <lczerner@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent 52c198c commit c7f7254

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

‎fs/ext4/super.c‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2754,9 +2754,25 @@ static void ext4_feat_release(struct kobject *kobj)
27542754
complete(&ext4_feat->f_kobj_unregister);
27552755
}
27562756

2757+
static ssize_t ext4_feat_show(struct kobject *kobj,
2758+
struct attribute *attr, char *buf)
2759+
{
2760+
return snprintf(buf, PAGE_SIZE, "supported\n");
2761+
}
2762+
2763+
/*
2764+
* We can not use ext4_attr_show/store because it relies on the kobject
2765+
* being embedded in the ext4_sb_info structure which is definitely not
2766+
* true in this case.
2767+
*/
2768+
static const struct sysfs_ops ext4_feat_ops = {
2769+
.show = ext4_feat_show,
2770+
.store = NULL,
2771+
};
2772+
27572773
static struct kobj_type ext4_feat_ktype = {
27582774
.default_attrs = ext4_feat_attrs,
2759-
.sysfs_ops = &ext4_attr_ops,
2775+
.sysfs_ops = &ext4_feat_ops,
27602776
.release = ext4_feat_release,
27612777
};
27622778

0 commit comments

Comments
 (0)