diff mbox

[4/9] btrfs: export supported featured to sysfs

Message ID 20130916182018.291611624@suse.com
State New, archived
Headers show

Commit Message

Jeff Mahoney Sept. 16, 2013, 6:19 p.m. UTC
This patch adds the ability to publish supported features to sysfs under
/sys/fs/btrfs/features.

The files are module-wide and export which features the kernel supports.

The content, for now, is just "0\n".

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/ctree.h   |    4 ++--
 fs/btrfs/disk-io.c |    1 -
 fs/btrfs/sysfs.c   |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/btrfs/sysfs.h   |   35 +++++++++++++++++++++++++++++++++++
 4 files changed, 89 insertions(+), 3 deletions(-)



--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" 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

--- a/fs/btrfs/ctree.h	2013-09-16 13:46:30.875025162 -0400
+++ b/fs/btrfs/ctree.h	2013-09-16 13:48:53.252952421 -0400
@@ -32,6 +32,7 @@ 
 #include <asm/kmap_types.h>
 #include <linux/pagemap.h>
 #include <linux/btrfs.h>
+#include <linux/kobj_completion.h>
 #include "extent_io.h"
 #include "extent_map.h"
 #include "async-thread.h"
@@ -1511,8 +1512,7 @@  struct btrfs_fs_info {
 	struct task_struct *cleaner_kthread;
 	int thread_pool_size;
 
-	struct kobject super_kobj;
-	struct completion kobj_unregister;
+	struct kobj_completion super_kc;
 	int do_barriers;
 	int closing;
 	int log_root_recovering;
--- a/fs/btrfs/disk-io.c	2013-09-16 13:46:30.875025162 -0400
+++ b/fs/btrfs/disk-io.c	2013-09-16 13:46:32.970992936 -0400
@@ -2163,7 +2163,6 @@  int open_ctree(struct super_block *sb,
 	mutex_init(&fs_info->reloc_mutex);
 	seqlock_init(&fs_info->profiles_lock);
 
-	init_completion(&fs_info->kobj_unregister);
 	INIT_LIST_HEAD(&fs_info->dirty_cowonly_roots);
 	INIT_LIST_HEAD(&fs_info->space_info);
 	INIT_LIST_HEAD(&fs_info->tree_mod_seq_list);
--- a/fs/btrfs/sysfs.c	2013-09-16 13:46:30.875025162 -0400
+++ b/fs/btrfs/sysfs.c	2013-09-16 13:48:53.252952421 -0400
@@ -22,24 +22,76 @@ 
 #include <linux/completion.h>
 #include <linux/buffer_head.h>
 #include <linux/kobject.h>
+#include <linux/kobj_completion.h>
 
 #include "ctree.h"
 #include "disk-io.h"
 #include "transaction.h"
 
+BTRFS_FEAT_ATTR_INCOMPAT(mixed_backref, MIXED_BACKREF);
+BTRFS_FEAT_ATTR_INCOMPAT(default_subvol, DEFAULT_SUBVOL);
+BTRFS_FEAT_ATTR_INCOMPAT(mixed_groups, MIXED_GROUPS);
+BTRFS_FEAT_ATTR_INCOMPAT(compress_lzo, COMPRESS_LZO);
+BTRFS_FEAT_ATTR_INCOMPAT(compress_lzov2, COMPRESS_LZOv2);
+BTRFS_FEAT_ATTR_INCOMPAT(big_metadata, BIG_METADATA);
+BTRFS_FEAT_ATTR_INCOMPAT(extended_iref, EXTENDED_IREF);
+BTRFS_FEAT_ATTR_INCOMPAT(raid56, RAID56);
+BTRFS_FEAT_ATTR_INCOMPAT(skinny_metadata, SKINNY_METADATA);
+
+static struct attribute *btrfs_supp_feature_attrs[] = {
+	BTRFS_FEAT_ATTR_LIST(mixed_backref)
+	BTRFS_FEAT_ATTR_LIST(default_subvol)
+	BTRFS_FEAT_ATTR_LIST(mixed_groups)
+	BTRFS_FEAT_ATTR_LIST(compress_lzo)
+	BTRFS_FEAT_ATTR_LIST(compress_lzov2)
+	BTRFS_FEAT_ATTR_LIST(big_metadata)
+	BTRFS_FEAT_ATTR_LIST(extended_iref)
+	BTRFS_FEAT_ATTR_LIST(raid56)
+	BTRFS_FEAT_ATTR_LIST(skinny_metadata)
+	NULL
+};
+
+static ssize_t btrfs_supp_attr_show(struct kobject *kobj, struct attribute *a,
+				    char *buf)
+{
+	return snprintf(buf, PAGE_SIZE, "0\n");
+}
+
+static const struct sysfs_ops btrfs_supp_attr_ops = {
+	.show = btrfs_supp_attr_show,
+};
+
+static struct kobj_type btrfs_supp_feat_ktype = {
+	.default_attrs	= btrfs_supp_feature_attrs,
+	.sysfs_ops	= &btrfs_supp_attr_ops,
+	.release	= kobj_completion_release,
+};
+
 /* /sys/fs/btrfs/ entry */
 static struct kset *btrfs_kset;
+static struct kobj_completion btrfs_features;
 
 int btrfs_init_sysfs(void)
 {
+	int ret;
 	btrfs_kset = kset_create_and_add("btrfs", NULL, fs_kobj);
 	if (!btrfs_kset)
 		return -ENOMEM;
+
+	kobj_completion_init(&btrfs_features, &btrfs_supp_feat_ktype);
+	btrfs_features.kc_kobj.kset = btrfs_kset;
+	ret = kobject_add(&btrfs_features.kc_kobj, NULL, "features");
+	if (ret) {
+		kset_unregister(btrfs_kset);
+		return ret;
+	}
+
 	return 0;
 }
 
 void btrfs_exit_sysfs(void)
 {
+	kobj_completion_del_and_wait(&btrfs_features);
 	kset_unregister(btrfs_kset);
 }
 
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ b/fs/btrfs/sysfs.h	2013-09-16 13:49:01.064844933 -0400
@@ -0,0 +1,35 @@ 
+#ifndef _BTRFS_SYSFS_H_
+#define _BTRFS_SYSFS_H_
+
+enum btrfs_feature_set {
+	FEAT_COMPAT,
+	FEAT_COMPAT_RO,
+	FEAT_INCOMPAT,
+	FEAT_MAX
+};
+
+struct btrfs_feature_attr {
+	struct attribute attr;			/* global show, no store */
+	enum btrfs_feature_set feature_set;
+	u64 feature_bit;
+};
+
+#define BTRFS_FEAT_ATTR(_name, _feature_set, _prefix, _feature_bit)	     \
+static struct btrfs_feature_attr btrfs_attr_##_name = {			     \
+	.attr		= { .name = __stringify(_name), .mode = S_IRUGO, },  \
+	.feature_set	= _feature_set,					     \
+	.feature_bit	= _prefix ##_## _feature_bit,			     \
+}
+#define BTRFS_FEAT_ATTR_LIST(_name)    (&btrfs_attr_##_name.attr),
+
+#define BTRFS_FEAT_ATTR_COMPAT(name, feature) \
+	BTRFS_FEAT_ATTR(name, FEAT_COMPAT, BTRFS_FEATURE_COMPAT, feature)
+#define BTRFS_FEAT_ATTR_COMPAT_RO(name, feature) \
+	BTRFS_FEAT_ATTR(name, FEAT_COMPAT_RO, BTRFS_FEATURE_COMPAT, feature)
+#define BTRFS_FEAT_ATTR_INCOMPAT(name, feature) \
+	BTRFS_FEAT_ATTR(name, FEAT_INCOMPAT, BTRFS_FEATURE_INCOMPAT, feature)
+
+/* convert from attribute */
+#define to_btrfs_feature_attr(a) \
+			container_of(a, struct btrfs_feature_attr, attr)
+#endif /* _BTRFS_SYSFS_H_ */