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 5/9] btrfs: add per-super attributes to sysfs
Date: Mon, 16 Sep 2013 14:19:15 -0400	[thread overview]
Message-ID: <20130916182018.459541510@suse.com> (raw)
In-Reply-To: 20130916181910.799140428@suse.com

This patch adds per-super attributes to sysfs.

It doesn't publish any attributes yet, but does the proper lifetime
handling as well as the basic infrastructure to add new attributes.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/ctree.h |    2 +
 fs/btrfs/super.c |   13 +++++++++++-
 fs/btrfs/sysfs.c |   56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/btrfs/sysfs.h |   20 +++++++++++++++++++
 4 files changed, 90 insertions(+), 1 deletion(-)

--- a/fs/btrfs/ctree.h	2013-09-16 13:49:06.656768298 -0400
+++ b/fs/btrfs/ctree.h	2013-09-16 13:49:25.464512784 -0400
@@ -3694,6 +3694,8 @@ int btrfs_defrag_leaves(struct btrfs_tra
 /* sysfs.c */
 int btrfs_init_sysfs(void);
 void btrfs_exit_sysfs(void);
+int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info);
+void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info);
 
 /* xattr.c */
 ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
--- a/fs/btrfs/super.c	2013-09-16 13:49:06.660768245 -0400
+++ b/fs/btrfs/super.c	2013-09-16 13:49:25.464512784 -0400
@@ -301,6 +301,8 @@ void __btrfs_panic(struct btrfs_fs_info
 
 static void btrfs_put_super(struct super_block *sb)
 {
+	btrfs_sysfs_remove_one(btrfs_sb(sb));
+
 	(void)close_ctree(btrfs_sb(sb)->tree_root);
 	/* FIXME: need to fix VFS to return error? */
 	/* AV: return it _where_?  ->put_super() can be triggered by any number
@@ -1143,8 +1145,17 @@ static struct dentry *btrfs_mount(struct
 	}
 
 	root = !error ? get_default_root(s, subvol_objectid) : ERR_PTR(error);
-	if (IS_ERR(root))
+	if (IS_ERR(root)) {
 		deactivate_locked_super(s);
+		return root;
+	}
+
+	error = btrfs_sysfs_add_one(fs_info);
+	if (error) {
+		dput(root);
+		deactivate_locked_super(s);
+		return ERR_PTR(error);
+	}
 
 	return root;
 
--- a/fs/btrfs/sysfs.c	2013-09-16 13:49:06.668768135 -0400
+++ b/fs/btrfs/sysfs.c	2013-09-16 13:49:25.464512784 -0400
@@ -27,6 +27,7 @@
 #include "ctree.h"
 #include "disk-io.h"
 #include "transaction.h"
+#include "sysfs.h"
 
 BTRFS_FEAT_ATTR_INCOMPAT(mixed_backref, MIXED_BACKREF);
 BTRFS_FEAT_ATTR_INCOMPAT(default_subvol, DEFAULT_SUBVOL);
@@ -67,8 +68,63 @@ static struct kobj_type btrfs_supp_feat_
 	.release	= kobj_completion_release,
 };
 
+static struct attribute *btrfs_attrs[] = {
+	NULL,
+};
+
+#define super_kobj_to_fs_info(kobj) \
+	container_of(kobj, struct btrfs_fs_info, super_kc.kc_kobj)
+
+static ssize_t btrfs_attr_show(struct kobject *kobj,
+			       struct attribute *attr, char *buf)
+{
+	struct btrfs_attr *a = container_of(attr, struct btrfs_attr, attr);
+	struct btrfs_fs_info *fs_info = super_kobj_to_fs_info(kobj);
+
+	return a->show ? a->show(a, fs_info, buf) : 0;
+}
+
+static ssize_t btrfs_attr_store(struct kobject *kobj,
+				struct attribute *attr,
+				const char *buf, size_t len)
+{
+	struct btrfs_attr *a = container_of(attr, struct btrfs_attr, attr);
+	struct btrfs_fs_info *fs_info = super_kobj_to_fs_info(kobj);
+
+	return a->store ? a->store(a, fs_info, buf, len) : 0;
+}
+
+static const struct sysfs_ops btrfs_attr_ops = {
+	.show = btrfs_attr_show,
+	.store = btrfs_attr_store,
+};
+
+static struct kobj_type btrfs_ktype = {
+	.default_attrs	= btrfs_attrs,
+	.sysfs_ops	= &btrfs_attr_ops,
+	.release	= kobj_completion_release,
+};
+
 /* /sys/fs/btrfs/ entry */
 static struct kset *btrfs_kset;
+
+int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info)
+{
+	int error;
+
+	kobj_completion_init(&fs_info->super_kc, &btrfs_ktype);
+	fs_info->super_kc.kc_kobj.kset = btrfs_kset;
+	error = kobject_add(&fs_info->super_kc.kc_kobj, NULL,
+			    "%pU", fs_info->fsid);
+
+	return error;
+}
+
+void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info)
+{
+	kobj_completion_del_and_wait(&fs_info->super_kc);
+}
+
 static struct kobj_completion btrfs_features;
 
 int btrfs_init_sysfs(void)
--- a/fs/btrfs/sysfs.h	2013-09-16 13:49:06.668768135 -0400
+++ b/fs/btrfs/sysfs.h	2013-09-16 13:49:25.464512784 -0400
@@ -8,6 +8,25 @@ enum btrfs_feature_set {
 	FEAT_MAX
 };
 
+struct btrfs_attr {
+	struct attribute attr;
+	ssize_t (*show)(struct btrfs_attr *, struct btrfs_fs_info *, char *);
+	ssize_t (*store)(struct btrfs_attr *, struct btrfs_fs_info *,
+			 const char *, size_t);
+};
+
+#define __INIT_BTRFS_ATTR(_name, _mode, _show, _store)			\
+{									\
+	.attr	= { .name = __stringify(_name), .mode = _mode },	\
+	.show	= _show,						\
+	.store	= _store,						\
+}
+
+#define BTRFS_ATTR(_name, _mode, _show, _store)				\
+static struct btrfs_attr btrfs_attr_##_name =				\
+			__INIT_BTRFS_ATTR(_name, _mode, _show, _store)
+#define BTRFS_ATTR_LIST(_name)    (&btrfs_attr_##_name.attr),
+
 struct btrfs_feature_attr {
 	struct attribute attr;			/* global show, no store */
 	enum btrfs_feature_set feature_set;
@@ -30,6 +49,7 @@ static struct btrfs_feature_attr btrfs_a
 	BTRFS_FEAT_ATTR(name, FEAT_INCOMPAT, BTRFS_FEATURE_INCOMPAT, feature)
 
 /* convert from attribute */
+#define to_btrfs_attr(a) container_of(a, struct btrfs_attr, attr)
 #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 ` [patch 4/9] btrfs: export supported featured to sysfs Jeff Mahoney
2013-09-16 18:19 ` Jeff Mahoney [this message]
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.459541510@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).