linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff Mahoney <jeffm@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: dsterba@suse.cz, clmason@fusionio.com
Subject: [patch 4/9] btrfs: export supported featured to sysfs
Date: Mon, 16 Sep 2013 14:19:14 -0400	[thread overview]
Message-ID: <20130916182018.291611624@suse.com> (raw)
In-Reply-To: 20130916181910.799140428@suse.com

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(-)

--- 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_ */



  parent reply	other threads:[~2013-09-16 18:22 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-16 18:19 [patch 0/9 v3] add ability to query/change feature bits online Jeff Mahoney
2013-09-16 18:19 ` [patch 1/9] btrfs: add ioctls " Jeff Mahoney
2013-09-18 14:05   ` David Sterba
2013-09-18 14:14   ` David Sterba
2013-09-18 14:29     ` Jeff Mahoney
2013-09-16 18:19 ` [patch 2/9] btrfs: use btrfs_commit_transaction when setting fslabel Jeff Mahoney
2013-09-16 18:19 ` [patch 3/9] kobject: introduce kobj_completion Jeff Mahoney
2013-09-16 18:19 ` Jeff Mahoney [this message]
2013-09-16 18:19 ` [patch 5/9] btrfs: add per-super attributes to sysfs Jeff Mahoney
2013-09-16 18:19 ` [patch 6/9] btrfs: publish per-super features " Jeff Mahoney
2013-09-16 18:19 ` [patch 7/9] btrfs: add publishing of unknown features in sysfs Jeff Mahoney
2013-09-16 18:19 ` [patch 8/9] btrfs: add ability to change features via sysfs Jeff Mahoney
2013-09-16 18:19 ` [patch 9/9] btrfs: use feature attribute names to print better error messages Jeff Mahoney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130916182018.291611624@suse.com \
    --to=jeffm@suse.com \
    --cc=clmason@fusionio.com \
    --cc=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).