features.c (4b4193256c8d3bc3a5397b5cd9494c2ad386317d) features.c (b16671e8f493e3df40b1fb0dff4078f391c5099a)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Feature set bits and string conversion.
4 * Inspired by ext4's features compat/incompat/ro_compat related code.
5 *
6 * Copyright 2020 Coly Li <colyli@suse.de>
7 *
8 */
9#include <linux/bcache.h>
10#include "bcache.h"
11#include "features.h"
12
13struct feature {
14 int compat;
15 unsigned int mask;
16 const char *string;
17};
18
19static struct feature feature_list[] = {
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Feature set bits and string conversion.
4 * Inspired by ext4's features compat/incompat/ro_compat related code.
5 *
6 * Copyright 2020 Coly Li <colyli@suse.de>
7 *
8 */
9#include <linux/bcache.h>
10#include "bcache.h"
11#include "features.h"
12
13struct feature {
14 int compat;
15 unsigned int mask;
16 const char *string;
17};
18
19static struct feature feature_list[] = {
20 {BCH_FEATURE_INCOMPAT, BCH_FEATURE_INCOMPAT_LARGE_BUCKET,
20 {BCH_FEATURE_INCOMPAT, BCH_FEATURE_INCOMPAT_LOG_LARGE_BUCKET_SIZE,
21 "large_bucket"},
22 {0, 0, 0 },
23};
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; \
21 "large_bucket"},
22 {0, 0, 0 },
23};
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)) { \
33 if (BCH_HAS_ ## type ## _FEATURE(&c->cache->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 \
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)) \
47 if (BCH_HAS_ ## type ## _FEATURE(&c->cache->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

--- 20 unchanged lines hidden ---
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

--- 20 unchanged lines hidden ---