aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/sysfs.c
diff options
context:
space:
mode:
authorJeff Mahoney <jeffm@suse.com>2013-11-01 13:07:02 -0400
committerChris Mason <clm@fb.com>2014-01-28 16:19:28 -0500
commit3b02a68a636400590dd6831a5fc046f0a7909a77 (patch)
tree4768baefa0c5ed4e76e215c444e100680c992746 /fs/btrfs/sysfs.c
parentba631941ef09c10e229661219dbd1707e56131d8 (diff)
btrfs: use feature attribute names to print better error messages
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> Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Chris Mason <clm@fb.com>
Diffstat (limited to 'fs/btrfs/sysfs.c')
-rw-r--r--fs/btrfs/sysfs.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 7d340f352b77..562e346994d9 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -254,6 +254,31 @@ const char * const btrfs_feature_set_names[3] = {
254static char btrfs_unknown_feature_names[3][NUM_FEATURE_BITS][13]; 254static char btrfs_unknown_feature_names[3][NUM_FEATURE_BITS][13];
255static struct btrfs_feature_attr btrfs_feature_attrs[3][NUM_FEATURE_BITS]; 255static struct btrfs_feature_attr btrfs_feature_attrs[3][NUM_FEATURE_BITS];
256 256
257char *btrfs_printable_features(enum btrfs_feature_set set, u64 flags)
258{
259 size_t bufsize = 4096; /* safe max, 64 names * 64 bytes */
260 int len = 0;
261 int i;
262 char *str;
263
264 str = kmalloc(bufsize, GFP_KERNEL);
265 if (!str)
266 return str;
267
268 for (i = 0; i < ARRAY_SIZE(btrfs_feature_attrs[set]); i++) {
269 const char *name;
270
271 if (!(flags & (1ULL << i)))
272 continue;
273
274 name = btrfs_feature_attrs[set][i].kobj_attr.attr.name;
275 len += snprintf(str + len, bufsize - len, "%s%s",
276 len ? "," : "", name);
277 }
278
279 return str;
280}
281
257static void init_feature_attrs(void) 282static void init_feature_attrs(void)
258{ 283{
259 struct btrfs_feature_attr *fa; 284 struct btrfs_feature_attr *fa;
@@ -264,11 +289,17 @@ static void init_feature_attrs(void)
264 BUILD_BUG_ON(ARRAY_SIZE(btrfs_unknown_feature_names[0]) != 289 BUILD_BUG_ON(ARRAY_SIZE(btrfs_unknown_feature_names[0]) !=
265 ARRAY_SIZE(btrfs_feature_attrs[0])); 290 ARRAY_SIZE(btrfs_feature_attrs[0]));
266 291
292 memset(btrfs_feature_attrs, 0, sizeof(btrfs_feature_attrs));
293 memset(btrfs_unknown_feature_names, 0,
294 sizeof(btrfs_unknown_feature_names));
295
267 for (i = 0; btrfs_supported_feature_attrs[i]; i++) { 296 for (i = 0; btrfs_supported_feature_attrs[i]; i++) {
268 struct btrfs_feature_attr *sfa; 297 struct btrfs_feature_attr *sfa;
269 struct attribute *a = btrfs_supported_feature_attrs[i]; 298 struct attribute *a = btrfs_supported_feature_attrs[i];
299 int bit;
270 sfa = attr_to_btrfs_feature_attr(a); 300 sfa = attr_to_btrfs_feature_attr(a);
271 fa = &btrfs_feature_attrs[sfa->feature_set][sfa->feature_bit]; 301 bit = ilog2(sfa->feature_bit);
302 fa = &btrfs_feature_attrs[sfa->feature_set][bit];
272 303
273 fa->kobj_attr.attr.name = sfa->kobj_attr.attr.name; 304 fa->kobj_attr.attr.name = sfa->kobj_attr.attr.name;
274 } 305 }