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: clmason@fusionio.com, dsterba@suse.cz
Subject: [patch 7/7] btrfs: use feature attribute names to print better error messages
Date: Tue, 10 Sep 2013 00:24:15 -0400	[thread overview]
Message-ID: <20130910043008.468612870@suse.com> (raw)
In-Reply-To: 20130910042408.335071038@suse.com

Now that we have the feature name strings available in the kernel via
the sysfs attributes, we can use them for printing better failure
messages from the ioctl path.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/ioctl.c |   35 ++++++++++++++++++++++++++++++-----
 fs/btrfs/sysfs.c |   25 +++++++++++++++++++++++++
 fs/btrfs/sysfs.h |    3 +++
 3 files changed, 58 insertions(+), 5 deletions(-)

--- a/fs/btrfs/ioctl.c	2013-09-09 23:23:34.794883859 -0400
+++ b/fs/btrfs/ioctl.c	2013-09-09 23:24:03.019073609 -0400
@@ -56,6 +56,7 @@
 #include "rcu-string.h"
 #include "send.h"
 #include "dev-replace.h"
+#include "sysfs.h"
 
 /* Mask out flags that are inappropriate for the given type of inode. */
 static inline __u32 btrfs_mask_flags(umode_t mode, __u32 flags)
@@ -4143,17 +4144,27 @@ static int btrfs_ioctl_get_features(stru
 	return 0;
 }
 
-static int check_feature_bits(struct btrfs_root *root, const char *type,
+static int check_feature_bits(struct btrfs_root *root,
+			      enum btrfs_feature_set set,
 			      u64 change_mask, u64 flags, u64 supported_flags,
 			      u64 safe_set, u64 safe_clear)
 {
+	const char *type = btrfs_feature_set_names[set];
+	char *names;
 	u64 disallowed, unsupported;
 	u64 set_mask = flags & change_mask;
 	u64 clear_mask = ~flags & change_mask;
 
 	unsupported = set_mask & ~supported_flags;
 	if (unsupported) {
-		btrfs_warn(root->fs_info,
+		names = btrfs_printable_features(set, unsupported);
+		if (names) {
+			btrfs_warn(root->fs_info,
+			   "this kernel does not support the %s feature bit%s",
+			   names, strchr(names, ',') ? "s" : "");
+			kfree(names);
+		} else
+			btrfs_warn(root->fs_info,
 			   "this kernel does not support %s bits 0x%llx",
 			   type, unsupported);
 		return -EOPNOTSUPP;
@@ -4161,7 +4172,14 @@ static int check_feature_bits(struct btr
 
 	disallowed = set_mask & ~safe_set;
 	if (disallowed) {
-		btrfs_warn(root->fs_info,
+		names = btrfs_printable_features(set, disallowed);
+		if (names) {
+			btrfs_warn(root->fs_info,
+			   "can't set the %s feature bit%s while mounted",
+			   names, strchr(names, ',') ? "s" : "");
+			kfree(names);
+		} else
+			btrfs_warn(root->fs_info,
 			   "can't set %s bits 0x%llx while mounted",
 			   type, disallowed);
 		return -EPERM;
@@ -4169,7 +4187,14 @@ static int check_feature_bits(struct btr
 
 	disallowed = clear_mask & ~safe_clear;
 	if (disallowed) {
-		btrfs_warn(root->fs_info,
+		names = btrfs_printable_features(set, disallowed);
+		if (names) {
+			btrfs_warn(root->fs_info,
+			   "can't clear the %s feature bit%s while mounted",
+			   names, strchr(names, ',') ? "s" : "");
+			kfree(names);
+		} else
+			btrfs_warn(root->fs_info,
 			   "can't clear %s bits 0x%llx while mounted",
 			   type, disallowed);
 		return -EPERM;
@@ -4179,7 +4204,7 @@ static int check_feature_bits(struct btr
 }
 
 #define check_feature(root, change_mask, flags, mask_base)	\
-check_feature_bits(root, # mask_base, change_mask, flags,	\
+check_feature_bits(root, FEAT_##mask_base, change_mask, flags,	\
 		   BTRFS_FEATURE_ ## mask_base ## _SUPP,	\
 		   BTRFS_FEATURE_ ## mask_base ## _SAFE_SET,	\
 		   BTRFS_FEATURE_ ## mask_base ## _SAFE_CLEAR)
--- a/fs/btrfs/sysfs.c	2013-09-09 23:24:02.991073420 -0400
+++ b/fs/btrfs/sysfs.c	2013-09-09 23:24:03.019073609 -0400
@@ -65,6 +65,31 @@ const char *btrfs_feature_set_names[FEAT
 static char btrfs_feature_names[FEAT_MAX][64][13];
 static struct btrfs_feature_attr btrfs_feature_attrs[FEAT_MAX][64];
 
+char *btrfs_printable_features(enum btrfs_feature_set set, u64 flags)
+{
+	size_t bufsize = 4096; /* safe max, 64 names * 64 bytes */
+	int len = 0;
+	int i;
+	char *str;
+
+	str = kmalloc(bufsize, GFP_KERNEL);
+	if (!str)
+		return str;
+
+	for (i = 0; i < ARRAY_SIZE(btrfs_feature_attrs[set]); i++) {
+		if (!(flags & (1ULL << i)))
+			continue;
+
+		flags &= ~(1ULL << i);
+
+		len += snprintf(str + len, bufsize - len,
+				"%s%s", len ? "," : "",
+				btrfs_feature_attrs[set][i].attr.name);
+	}
+
+	return str;
+}
+
 static void init_feature_set_attrs(enum btrfs_feature_set set)
 {
 	int i;
--- a/fs/btrfs/sysfs.h	2013-09-09 23:23:34.794883859 -0400
+++ b/fs/btrfs/sysfs.h	2013-09-09 23:24:03.019073609 -0400
@@ -53,4 +53,7 @@ static struct btrfs_feature_attr btrfs_a
 #define to_btrfs_feature_attr(a) \
 			container_of(a, struct btrfs_feature_attr, attr)
 
+char *btrfs_printable_features(enum btrfs_feature_set set, u64 flags);
+extern const char *btrfs_feature_set_names[FEAT_MAX];
+
 #endif /* _BTRFS_SYSFS_H_ */



      parent reply	other threads:[~2013-09-10  4:30 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-10  4:24 [patch 0/7] btrfs: Add ability to query/modify feature bits while mounted Jeff Mahoney
2013-09-10  4:24 ` [patch 1/7] [PATCH] btrfs: add ability to query/change feature bits online Jeff Mahoney
2013-09-16 17:26   ` David Sterba
2013-09-16 18:13     ` Jeff Mahoney
2013-09-10  4:24 ` [patch 2/7] btrfs: export supported featured to sysfs Jeff Mahoney
2013-09-10  4:24 ` [patch 3/7] btrfs: Add per-super attributes " Jeff Mahoney
2013-10-26 19:00   ` Alex Lyakas
2013-10-26 19:24     ` Jeff Mahoney
2013-09-10  4:24 ` [patch 4/7] btrfs: publish per-super features " Jeff Mahoney
2013-09-10  4:24 ` [patch 5/7] btrfs: Add publishing of unknown features in sysfs Jeff Mahoney
2013-09-10  4:24 ` [patch 6/7] btrfs: Add ability to change features via sysfs Jeff Mahoney
2013-09-10  4:24 ` Jeff Mahoney [this message]

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=20130910043008.468612870@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).