Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bcache: add sysfs file to display feature sets information of cache set

The following three sysfs files are created to display according feature
set information of bcache:
/sys/fs/bcache/<cache set UUID>/internal/feature_compat
/sys/fs/bcache/<cache set UUID>/internal/feature_ro_compat
/sys/fs/bcache/<cache set UUID>/internal/feature_incompat
is added by this patch, to display feature sets information of the cache
set.

Now only an incompat feature 'large_bucket' added in bcache, the sysfs
file content is:
[large_bucket]
string large_bucket means the running bcache drive supports incompat
feature 'large_bucket', the wrapping [] means the 'large_bucket' feature
is currently enabled on this cache set.

This patch is ready to display compat and ro_compat features, in future
once bcache code implements such feature sets, the according feature
strings will be displayed in their sysfs files too.

Signed-off-by: Coly Li <colyli@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Coly Li and committed by
Jens Axboe
092bd54d ffa47032

+73 -1
+1 -1
drivers/md/bcache/Makefile
··· 4 4 5 5 bcache-y := alloc.o bset.o btree.o closure.o debug.o extents.o\ 6 6 io.o journal.o movinggc.o request.o stats.o super.o sysfs.o trace.o\ 7 - util.o writeback.o 7 + util.o writeback.o features.o
+53
drivers/md/bcache/features.c
··· 8 8 */ 9 9 #include <linux/bcache.h> 10 10 #include "bcache.h" 11 + #include "features.h" 11 12 12 13 struct feature { 13 14 int compat; ··· 21 20 "large_bucket"}, 22 21 {0, 0, 0 }, 23 22 }; 23 + 24 + #define compose_feature_string(type) \ 25 + ({ \ 26 + struct feature *f; \ 27 + bool first = true; \ 28 + \ 29 + for (f = &feature_list[0]; f->compat != 0; f++) { \ 30 + if (f->compat != BCH_FEATURE_ ## type) \ 31 + continue; \ 32 + if (BCH_HAS_ ## type ## _FEATURE(&c->sb, f->mask)) { \ 33 + if (first) { \ 34 + out += snprintf(out, buf + size - out, \ 35 + "["); \ 36 + } else { \ 37 + out += snprintf(out, buf + size - out, \ 38 + " ["); \ 39 + } \ 40 + } else if (!first) { \ 41 + out += snprintf(out, buf + size - out, " "); \ 42 + } \ 43 + \ 44 + out += snprintf(out, buf + size - out, "%s", f->string);\ 45 + \ 46 + if (BCH_HAS_ ## type ## _FEATURE(&c->sb, f->mask)) \ 47 + out += snprintf(out, buf + size - out, "]"); \ 48 + \ 49 + first = false; \ 50 + } \ 51 + if (!first) \ 52 + out += snprintf(out, buf + size - out, "\n"); \ 53 + }) 54 + 55 + int bch_print_cache_set_feature_compat(struct cache_set *c, char *buf, int size) 56 + { 57 + char *out = buf; 58 + compose_feature_string(COMPAT); 59 + return out - buf; 60 + } 61 + 62 + int bch_print_cache_set_feature_ro_compat(struct cache_set *c, char *buf, int size) 63 + { 64 + char *out = buf; 65 + compose_feature_string(RO_COMPAT); 66 + return out - buf; 67 + } 68 + 69 + int bch_print_cache_set_feature_incompat(struct cache_set *c, char *buf, int size) 70 + { 71 + char *out = buf; 72 + compose_feature_string(INCOMPAT); 73 + return out - buf; 74 + }
+5
drivers/md/bcache/features.h
··· 78 78 } 79 79 80 80 BCH_FEATURE_INCOMPAT_FUNCS(large_bucket, LARGE_BUCKET); 81 + 82 + int bch_print_cache_set_feature_compat(struct cache_set *c, char *buf, int size); 83 + int bch_print_cache_set_feature_ro_compat(struct cache_set *c, char *buf, int size); 84 + int bch_print_cache_set_feature_incompat(struct cache_set *c, char *buf, int size); 85 + 81 86 #endif
+14
drivers/md/bcache/sysfs.c
··· 11 11 #include "btree.h" 12 12 #include "request.h" 13 13 #include "writeback.h" 14 + #include "features.h" 14 15 15 16 #include <linux/blkdev.h> 16 17 #include <linux/sort.h> ··· 89 88 read_attribute(average_key_size); 90 89 read_attribute(dirty_data); 91 90 read_attribute(bset_tree_stats); 91 + read_attribute(feature_compat); 92 + read_attribute(feature_ro_compat); 93 + read_attribute(feature_incompat); 92 94 93 95 read_attribute(state); 94 96 read_attribute(cache_read_races); ··· 783 779 if (attr == &sysfs_bset_tree_stats) 784 780 return bch_bset_print_stats(c, buf); 785 781 782 + if (attr == &sysfs_feature_compat) 783 + return bch_print_cache_set_feature_compat(c, buf, PAGE_SIZE); 784 + if (attr == &sysfs_feature_ro_compat) 785 + return bch_print_cache_set_feature_ro_compat(c, buf, PAGE_SIZE); 786 + if (attr == &sysfs_feature_incompat) 787 + return bch_print_cache_set_feature_incompat(c, buf, PAGE_SIZE); 788 + 786 789 return 0; 787 790 } 788 791 SHOW_LOCKED(bch_cache_set) ··· 998 987 &sysfs_io_disable, 999 988 &sysfs_cutoff_writeback, 1000 989 &sysfs_cutoff_writeback_sync, 990 + &sysfs_feature_compat, 991 + &sysfs_feature_ro_compat, 992 + &sysfs_feature_incompat, 1001 993 NULL 1002 994 }; 1003 995 KTYPE(bch_cache_set_internal);