diff mbox

[2/2] ext4: Provide separate operations for sysfs feature files

Message ID 1410262340-13713-2-git-send-email-lczerner@redhat.com
State Accepted, archived
Headers show

Commit Message

Lukas Czerner Sept. 9, 2014, 11:32 a.m. UTC
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>
---
 fs/ext4/super.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

Comments

Theodore Ts'o Sept. 11, 2014, 3:28 p.m. UTC | #1
On Tue, Sep 09, 2014 at 01:32:20PM +0200, Lukas Czerner wrote:
> 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>

Applied, thanks.

					- Ted
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 8e55ae1..2eff922 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -2754,9 +2754,25 @@  static void ext4_feat_release(struct kobject *kobj)
 	complete(&ext4_feat->f_kobj_unregister);
 }
 
+static ssize_t ext4_feat_show(struct kobject *kobj,
+			      struct attribute *attr, char *buf)
+{
+	return snprintf(buf, PAGE_SIZE, "supported\n");
+}
+
+/*
+ * We can not use ext4_attr_show/store because it relies on the kobject
+ * being embedded in the ext4_sb_info structure which is definitely not
+ * true in this case.
+ */
+static const struct sysfs_ops ext4_feat_ops = {
+	.show	= ext4_feat_show,
+	.store	= NULL,
+};
+
 static struct kobj_type ext4_feat_ktype = {
 	.default_attrs	= ext4_feat_attrs,
-	.sysfs_ops	= &ext4_attr_ops,
+	.sysfs_ops	= &ext4_feat_ops,
 	.release	= ext4_feat_release,
 };