From: Jeff Mahoney <jeffm@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: dsterba@suse.cz, clmason@fusionio.com
Subject: [patch 7/9] btrfs: add publishing of unknown features in sysfs
Date: Mon, 16 Sep 2013 14:19:17 -0400 [thread overview]
Message-ID: <20130916182018.796022700@suse.com> (raw)
In-Reply-To: 20130916181910.799140428@suse.com
With the compat and compat-ro bits, it's possible for file systems to
exist that have features that aren't supported by the kernel's file system
implementation yet still be mountable.
This patch publishes read-only info on those features using a prefix:number
format, where the number is the bit number rather than the shifted value.
e.g. "compat:12"
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
fs/btrfs/sysfs.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 71 insertions(+), 4 deletions(-)
--- a/fs/btrfs/sysfs.c 2013-09-10 15:58:32.209384497 -0400
+++ b/fs/btrfs/sysfs.c 2013-09-10 15:58:32.645377839 -0400
@@ -68,6 +68,58 @@ static struct kobj_type btrfs_supp_feat_
.release = kobj_completion_release,
};
+const char * const btrfs_feature_set_names[FEAT_MAX] = {
+ [FEAT_COMPAT] = "compat",
+ [FEAT_COMPAT_RO] = "compat_ro",
+ [FEAT_INCOMPAT] = "incompat",
+};
+
+static char btrfs_feature_names[FEAT_MAX][64][13];
+static struct btrfs_feature_attr btrfs_feature_attrs[FEAT_MAX][64];
+
+static void init_feature_set_attrs(enum btrfs_feature_set set)
+{
+ int i;
+ int len = strlen(btrfs_feature_set_names[set]) + 4;
+
+ for (i = 0; i < 64; i++) {
+ char *name = btrfs_feature_names[set][i];
+ struct btrfs_feature_attr *fa;
+
+ snprintf(name, len, "%s:%u", btrfs_feature_set_names[set], i);
+
+ fa = &btrfs_feature_attrs[set][i];
+ fa->attr.name = name;
+ fa->attr.mode = S_IRUGO;
+ fa->feature_set = set;
+ fa->feature_bit = (1ULL << i);
+ }
+}
+
+static void init_feature_attrs(void)
+{
+ int i;
+
+ init_feature_set_attrs(FEAT_COMPAT);
+ init_feature_set_attrs(FEAT_COMPAT_RO);
+ init_feature_set_attrs(FEAT_INCOMPAT);
+
+ /* Copy the names over for supported features */
+ for (i = 0; btrfs_supp_feature_attrs[i]; i++) {
+ struct btrfs_feature_attr *fa;
+ struct attribute *attr;
+ int n;
+
+ fa = to_btrfs_feature_attr(btrfs_supp_feature_attrs[i]);
+ n = ilog2(fa->feature_bit);
+
+ attr = &btrfs_feature_attrs[fa->feature_set][n].attr;
+ attr->name = fa->attr.name;
+
+ btrfs_feature_names[fa->feature_set][n][0] = '\0';
+ }
+}
+
static u64 get_features(struct btrfs_fs_info *fs_info,
enum btrfs_feature_set set)
{
@@ -138,12 +190,12 @@ static struct kobj_type btrfs_ktype = {
.release = kobj_completion_release,
};
-static int add_per_fs_features(struct btrfs_fs_info *fs_info)
+static int add_per_fs_feature_set(struct btrfs_fs_info *fs_info,
+ enum btrfs_feature_set set)
{
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);
+ for (i = 0; i < ARRAY_SIZE(btrfs_feature_attrs[0]); i++) {
+ struct btrfs_feature_attr *fa = &btrfs_feature_attrs[set][i];
u64 features = get_features(fs_info, fa->feature_set);
int error;
@@ -158,6 +210,20 @@ static int add_per_fs_features(struct bt
return 0;
}
+static int add_per_fs_features(struct btrfs_fs_info *fs_info)
+{
+ enum btrfs_feature_set set;
+ int error;
+
+ for (set = FEAT_COMPAT; set < FEAT_MAX; set++) {
+ error = add_per_fs_feature_set(fs_info, set);
+ if (error)
+ return error;
+ }
+
+ return 0;
+}
+
/* /sys/fs/btrfs/ entry */
static struct kset *btrfs_kset;
@@ -207,6 +273,7 @@ int btrfs_init_sysfs(void)
if (!btrfs_kset)
return -ENOMEM;
+ init_feature_attrs();
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");
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 ` [patch 6/9] btrfs: publish per-super features " Jeff Mahoney
2013-09-16 18:19 ` Jeff Mahoney [this message]
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.796022700@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).