0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "bcache_ondisk.h"
0010 #include "bcache.h"
0011 #include "features.h"
0012
0013 struct feature {
0014 int compat;
0015 unsigned int mask;
0016 const char *string;
0017 };
0018
0019 static struct feature feature_list[] = {
0020 {BCH_FEATURE_INCOMPAT, BCH_FEATURE_INCOMPAT_LOG_LARGE_BUCKET_SIZE,
0021 "large_bucket"},
0022 {0, 0, NULL },
0023 };
0024
0025 #define compose_feature_string(type) \
0026 ({ \
0027 struct feature *f; \
0028 bool first = true; \
0029 \
0030 for (f = &feature_list[0]; f->compat != 0; f++) { \
0031 if (f->compat != BCH_FEATURE_ ## type) \
0032 continue; \
0033 if (BCH_HAS_ ## type ## _FEATURE(&c->cache->sb, f->mask)) { \
0034 if (first) { \
0035 out += snprintf(out, buf + size - out, \
0036 "["); \
0037 } else { \
0038 out += snprintf(out, buf + size - out, \
0039 " ["); \
0040 } \
0041 } else if (!first) { \
0042 out += snprintf(out, buf + size - out, " "); \
0043 } \
0044 \
0045 out += snprintf(out, buf + size - out, "%s", f->string);\
0046 \
0047 if (BCH_HAS_ ## type ## _FEATURE(&c->cache->sb, f->mask)) \
0048 out += snprintf(out, buf + size - out, "]"); \
0049 \
0050 first = false; \
0051 } \
0052 if (!first) \
0053 out += snprintf(out, buf + size - out, "\n"); \
0054 })
0055
0056 int bch_print_cache_set_feature_compat(struct cache_set *c, char *buf, int size)
0057 {
0058 char *out = buf;
0059 compose_feature_string(COMPAT);
0060 return out - buf;
0061 }
0062
0063 int bch_print_cache_set_feature_ro_compat(struct cache_set *c, char *buf, int size)
0064 {
0065 char *out = buf;
0066 compose_feature_string(RO_COMPAT);
0067 return out - buf;
0068 }
0069
0070 int bch_print_cache_set_feature_incompat(struct cache_set *c, char *buf, int size)
0071 {
0072 char *out = buf;
0073 compose_feature_string(INCOMPAT);
0074 return out - buf;
0075 }