From: Jeff Mahoney <jeffm@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: dsterba@suse.cz, clmason@fusionio.com
Subject: [patch 6/9] btrfs: publish per-super features to sysfs
Date: Mon, 16 Sep 2013 14:19:16 -0400 [thread overview]
Message-ID: <20130916182018.627191537@suse.com> (raw)
In-Reply-To: 20130916181910.799140428@suse.com
This patch publishes information on which features are enabled in the
file system on a per-super basis. At this point, it only publishes
information on features supported by the file system implementation.
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
fs/btrfs/ctree.h | 1
fs/btrfs/sysfs.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
fs/btrfs/sysfs.h | 2 -
3 files changed, 75 insertions(+), 1 deletion(-)
--- a/fs/btrfs/ctree.h 2013-09-16 13:49:28.960465646 -0400
+++ b/fs/btrfs/ctree.h 2013-09-16 13:49:47.688214995 -0400
@@ -1513,6 +1513,7 @@ struct btrfs_fs_info {
int thread_pool_size;
struct kobj_completion super_kc;
+ struct kobj_completion features_kc;
int do_barriers;
int closing;
int log_root_recovering;
--- a/fs/btrfs/sysfs.c 2013-09-16 13:49:28.960465646 -0400
+++ b/fs/btrfs/sysfs.c 2013-09-16 13:49:47.688214995 -0400
@@ -68,6 +68,39 @@ static struct kobj_type btrfs_supp_feat_
.release = kobj_completion_release,
};
+static u64 get_features(struct btrfs_fs_info *fs_info,
+ enum btrfs_feature_set set)
+{
+ struct btrfs_super_block *disk_super = fs_info->super_copy;
+ if (set == FEAT_COMPAT)
+ return btrfs_super_compat_flags(disk_super);
+ else if (set == FEAT_COMPAT_RO)
+ return btrfs_super_compat_ro_flags(disk_super);
+ else
+ return btrfs_super_incompat_flags(disk_super);
+}
+
+#define feat_kobj_to_fs_info(kobj) \
+ container_of(kobj, struct btrfs_fs_info, features_kc.kc_kobj)
+static ssize_t btrfs_feat_show(struct kobject *kobj, struct attribute *attr,
+ char *buf)
+{
+ struct btrfs_fs_info *fs_info = feat_kobj_to_fs_info(kobj);
+ struct btrfs_feature_attr *fa = to_btrfs_feature_attr(attr);
+ u64 features = get_features(fs_info, fa->feature_set);
+
+ return snprintf(buf, PAGE_SIZE, "%u\n", !!(features & fa->feature_bit));
+}
+
+static const struct sysfs_ops btrfs_feat_attr_ops = {
+ .show = btrfs_feat_show,
+};
+
+static struct kobj_type btrfs_feat_ktype = {
+ .sysfs_ops = &btrfs_feat_attr_ops,
+ .release = kobj_completion_release,
+};
+
static struct attribute *btrfs_attrs[] = {
NULL,
};
@@ -105,6 +138,26 @@ static struct kobj_type btrfs_ktype = {
.release = kobj_completion_release,
};
+static int add_per_fs_features(struct btrfs_fs_info *fs_info)
+{
+ int i;
+ for (i = 0; btrfs_supp_feature_attrs[i]; i++) {
+ struct attribute *attr = btrfs_supp_feature_attrs[i];
+ struct btrfs_feature_attr *fa = to_btrfs_feature_attr(attr);
+ u64 features = get_features(fs_info, fa->feature_set);
+ int error;
+
+ if (!(features & fa->feature_bit))
+ continue;
+
+ error = sysfs_create_file(&fs_info->features_kc.kc_kobj,
+ &fa->attr);
+ if (error)
+ return error;
+ }
+ return 0;
+}
+
/* /sys/fs/btrfs/ entry */
static struct kset *btrfs_kset;
@@ -116,12 +169,32 @@ int btrfs_sysfs_add_one(struct btrfs_fs_
fs_info->super_kc.kc_kobj.kset = btrfs_kset;
error = kobject_add(&fs_info->super_kc.kc_kobj, NULL,
"%pU", fs_info->fsid);
+ if (error)
+ return error;
+
+ kobj_completion_init(&fs_info->features_kc, &btrfs_feat_ktype);
+ error = kobject_add(&fs_info->features_kc.kc_kobj,
+ &fs_info->super_kc.kc_kobj, "features");
+ if (error)
+ goto out_super;
+
+ error = add_per_fs_features(fs_info);
+ if (error)
+ goto out_features;
+
+ return 0;
+
+out_features:
+ kobj_completion_del_and_wait(&fs_info->features_kc);
+out_super:
+ kobj_completion_del_and_wait(&fs_info->super_kc);
return error;
}
void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info)
{
+ kobj_completion_del_and_wait(&fs_info->features_kc);
kobj_completion_del_and_wait(&fs_info->super_kc);
}
--- a/fs/btrfs/sysfs.h 2013-09-16 13:49:28.964465592 -0400
+++ b/fs/btrfs/sysfs.h 2013-09-16 13:49:47.688214995 -0400
@@ -28,7 +28,7 @@ static struct btrfs_attr btrfs_attr_##_n
#define BTRFS_ATTR_LIST(_name) (&btrfs_attr_##_name.attr),
struct btrfs_feature_attr {
- struct attribute attr; /* global show, no store */
+ struct attribute attr; /* per-fs/global show, no store */
enum btrfs_feature_set feature_set;
u64 feature_bit;
};
next prev 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 ` [patch 5/9] btrfs: add per-super attributes " Jeff Mahoney
2013-09-16 18:19 ` Jeff Mahoney [this message]
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.627191537@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).