Skip to content

Commit 092bd54

Browse files
Coly Liaxboe
authored andcommitted
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 <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent ffa4703 commit 092bd54

File tree

4 files changed

+73
-1
lines changed

4 files changed

+73
-1
lines changed

drivers/md/bcache/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ obj-$(CONFIG_BCACHE) += bcache.o
44

55
bcache-y := alloc.o bset.o btree.o closure.o debug.o extents.o\
66
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

drivers/md/bcache/features.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99
#include <linux/bcache.h>
1010
#include "bcache.h"
11+
#include "features.h"
1112

1213
struct feature {
1314
int compat;
@@ -20,3 +21,55 @@ static struct feature feature_list[] = {
2021
"large_bucket"},
2122
{0, 0, 0 },
2223
};
24+
25+
#define compose_feature_string(type) \
26+
({ \
27+
struct feature *f; \
28+
bool first = true; \
29+
\
30+
for (f = &feature_list[0]; f->compat != 0; f++) { \
31+
if (f->compat != BCH_FEATURE_ ## type) \
32+
continue; \
33+
if (BCH_HAS_ ## type ## _FEATURE(&c->sb, f->mask)) { \
34+
if (first) { \
35+
out += snprintf(out, buf + size - out, \
36+
"["); \
37+
} else { \
38+
out += snprintf(out, buf + size - out, \
39+
" ["); \
40+
} \
41+
} else if (!first) { \
42+
out += snprintf(out, buf + size - out, " "); \
43+
} \
44+
\
45+
out += snprintf(out, buf + size - out, "%s", f->string);\
46+
\
47+
if (BCH_HAS_ ## type ## _FEATURE(&c->sb, f->mask)) \
48+
out += snprintf(out, buf + size - out, "]"); \
49+
\
50+
first = false; \
51+
} \
52+
if (!first) \
53+
out += snprintf(out, buf + size - out, "\n"); \
54+
})
55+
56+
int bch_print_cache_set_feature_compat(struct cache_set *c, char *buf, int size)
57+
{
58+
char *out = buf;
59+
compose_feature_string(COMPAT);
60+
return out - buf;
61+
}
62+
63+
int bch_print_cache_set_feature_ro_compat(struct cache_set *c, char *buf, int size)
64+
{
65+
char *out = buf;
66+
compose_feature_string(RO_COMPAT);
67+
return out - buf;
68+
}
69+
70+
int bch_print_cache_set_feature_incompat(struct cache_set *c, char *buf, int size)
71+
{
72+
char *out = buf;
73+
compose_feature_string(INCOMPAT);
74+
return out - buf;
75+
}

drivers/md/bcache/features.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,9 @@ static inline void bch_clear_feature_##name(struct cache_sb *sb) \
7878
}
7979

8080
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+
8186
#endif

drivers/md/bcache/sysfs.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "btree.h"
1212
#include "request.h"
1313
#include "writeback.h"
14+
#include "features.h"
1415

1516
#include <linux/blkdev.h>
1617
#include <linux/sort.h>
@@ -88,6 +89,9 @@ read_attribute(btree_used_percent);
8889
read_attribute(average_key_size);
8990
read_attribute(dirty_data);
9091
read_attribute(bset_tree_stats);
92+
read_attribute(feature_compat);
93+
read_attribute(feature_ro_compat);
94+
read_attribute(feature_incompat);
9195

9296
read_attribute(state);
9397
read_attribute(cache_read_races);
@@ -779,6 +783,13 @@ SHOW(__bch_cache_set)
779783
if (attr == &sysfs_bset_tree_stats)
780784
return bch_bset_print_stats(c, buf);
781785

786+
if (attr == &sysfs_feature_compat)
787+
return bch_print_cache_set_feature_compat(c, buf, PAGE_SIZE);
788+
if (attr == &sysfs_feature_ro_compat)
789+
return bch_print_cache_set_feature_ro_compat(c, buf, PAGE_SIZE);
790+
if (attr == &sysfs_feature_incompat)
791+
return bch_print_cache_set_feature_incompat(c, buf, PAGE_SIZE);
792+
782793
return 0;
783794
}
784795
SHOW_LOCKED(bch_cache_set)
@@ -987,6 +998,9 @@ static struct attribute *bch_cache_set_internal_files[] = {
987998
&sysfs_io_disable,
988999
&sysfs_cutoff_writeback,
9891000
&sysfs_cutoff_writeback_sync,
1001+
&sysfs_feature_compat,
1002+
&sysfs_feature_ro_compat,
1003+
&sysfs_feature_incompat,
9901004
NULL
9911005
};
9921006
KTYPE(bch_cache_set_internal);

0 commit comments

Comments
 (0)