[RFC 4/8] Helper functions and attributes for super block's sysfs entries

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Goldwyn Rodrigues <rgoldwyn@xxxxxxxx>

Introduces super_block_attribute as helper attribute which
encompasses store() and show() fucntions.

Also includes the macros to define attributes.

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@xxxxxxxx>
---
 fs/super.c         | 38 ++++++++++++++++++++++++++++++++++++++
 include/linux/fs.h | 26 ++++++++++++++++++++++++++
 2 files changed, 64 insertions(+)

diff --git a/fs/super.c b/fs/super.c
index c6b8801..d6d4d05 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -1396,3 +1396,41 @@ out:
 	return 0;
 }
 EXPORT_SYMBOL(thaw_super);
+
+static ssize_t super_block_attribute_show(struct kobject *kobj,
+		struct attribute *attr, char *buf)
+{
+	struct super_block_attribute *sattr =
+		container_of(attr, struct super_block_attribute, attr);
+	struct super_block *sb = container_of(kobj, struct super_block, s_kobj);
+	if (!sattr->show)
+		return -EIO;
+
+	return sattr->show(sb, sattr, buf);
+}
+
+static ssize_t super_block_attribute_store(struct kobject *kobj,
+		struct attribute *attr, const char *buf, size_t count)
+{
+	struct super_block_attribute *sattr =
+		container_of(attr, struct super_block_attribute, attr);
+	struct super_block *sb = container_of(kobj, struct super_block, s_kobj);
+	if (!sattr->store)
+		return -EIO;
+
+	return sattr->store(sb, sattr, buf, count);
+}
+
+const struct sysfs_ops super_block_sysfs_ops = {
+	.show = super_block_attribute_show,
+	.store = super_block_attribute_store,
+};
+
+EXPORT_SYMBOL(super_block_sysfs_ops);
+
+void super_block_release(struct kobject *kobj)
+{
+	struct super_block *sb = container_of(kobj, struct super_block, s_kobj);
+	complete(&sb->s_kobj_del);
+}
+EXPORT_SYMBOL(super_block_release);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 1cf2e011..117d641 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1423,6 +1423,32 @@ struct super_block {
 	struct completion	s_kobj_del; /* Wait for kobjects deletion */
 };
 
+struct super_block_attribute {
+	struct attribute attr;
+	ssize_t (*show)(struct super_block *sb, struct super_block_attribute *,
+			char *buf);
+	ssize_t (*store)(struct super_block *sb, struct super_block_attribute *,
+			const char *buf, size_t count);
+};
+
+#define SB_ATTR(_name, _mode)                  		\
+	struct super_block_attribute sb_attr_##_name = {\
+		.attr = {.name = __stringify(_name),    \
+			.mode = _mode},                 \
+		.show = _name##_show,                   \
+		.store = _name##_store,                 \
+	}
+
+#define SB_ATTR_RO(_name)                      		\
+	struct super_block_attribute sb_attr_##_name = {\
+		.attr = {.name = __stringify(_name),    \
+			.mode = S_IRUGO},               \
+		.show = _name##_show,                   \
+	}
+
+extern const struct sysfs_ops super_block_sysfs_ops;
+void super_block_release(struct kobject *kobj);
+
 extern struct timespec current_fs_time(struct super_block *sb);
 
 /*
-- 
2.6.6

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



[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux