add patch provide-separate-oeprations-for-sysfs-feature-files
[ext4-patch-queue.git] / provide-separate-oeprations-for-sysfs-feature-files
blobe71ce65686722e3e963c43f8724ed2c2a3785417
1 ext4: provide separate operations for sysfs feature files
3 From: Lukas Czerner <lczerner@redhat.com>
5 Currently sysfs feature files uses ext4_attr_ops as the file operations
6 to show/store data. However the feature files is not supposed to contain
7 any data at all, the sole existence of the file means that the module
8 support the feature. Moreover, none of the sysfs feature attributes
9 actually register show/store functions so that would not be a problem.
11 However if a sysfs feature attribute register a show or store function
12 we might be in trouble because the kobject in this case is _not_ embedded
13 in the ext4_sb_info structure as ext4_attr_show/store expect.
15 So just to be safe, provide separate empty sysfs_ops to use in
16 ext4_feat_ktype. This might safe us from potential problems in the
17 future. As a bonus we can "store" something more descriptive than
18 nothing in the files, so let it contain "enabled" to make it clear that
19 the feature is really present in the module.
21 Signed-off-by: Lukas Czerner <lczerner@redhat.com>
22 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
23 ---
24  fs/ext4/super.c | 18 +++++++++++++++++-
25  1 file changed, 17 insertions(+), 1 deletion(-)
27 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
28 index 8e55ae1..2eff922 100644
29 --- a/fs/ext4/super.c
30 +++ b/fs/ext4/super.c
31 @@ -2754,9 +2754,25 @@ static void ext4_feat_release(struct kobject *kobj)
32         complete(&ext4_feat->f_kobj_unregister);
33  }
35 +static ssize_t ext4_feat_show(struct kobject *kobj,
36 +                             struct attribute *attr, char *buf)
38 +       return snprintf(buf, PAGE_SIZE, "supported\n");
41 +/*
42 + * We can not use ext4_attr_show/store because it relies on the kobject
43 + * being embedded in the ext4_sb_info structure which is definitely not
44 + * true in this case.
45 + */
46 +static const struct sysfs_ops ext4_feat_ops = {
47 +       .show   = ext4_feat_show,
48 +       .store  = NULL,
49 +};
51  static struct kobj_type ext4_feat_ktype = {
52         .default_attrs  = ext4_feat_attrs,
53 -       .sysfs_ops      = &ext4_attr_ops,
54 +       .sysfs_ops      = &ext4_feat_ops,
55         .release        = ext4_feat_release,
56  };