forked from andreatomassetti/bcache-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
features.c
76 lines (68 loc) · 1.74 KB
/
features.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// SPDX-License-Identifier: GPL-2.0
/*
* Author: Coly Li <[email protected]>
*
* Inspired by e2fsprogs features compat/incompat/ro_compat
* related code.
*/
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/types.h>
#include <string.h>
#include "bcache.h"
struct feature {
int compat;
unsigned int mask;
const char *string;
};
static struct feature feature_list[] = {
{BCH_FEATURE_INCOMPAT, BCH_FEATURE_INCOMPAT_OBSO_LARGE_BUCKET,
"obso_large_bucket"},
{BCH_FEATURE_INCOMPAT, BCH_FEATURE_INCOMPAT_LOG_LARGE_BUCKET_SIZE,
"large_bucket"},
{0, 0, 0 },
};
#define compose_feature_string(type, header) \
({ \
struct feature *f; \
bool first = true; \
\
for (f = &feature_list[0]; f->compat != 0; f++) { \
if (f->compat != BCH_FEATURE_ ## type) \
continue; \
if (!(BCH_HAS_ ## type ## _FEATURE(sb, f->mask))) \
continue; \
\
if (first) { \
out += snprintf(out, buf + size - out, \
"%s:\t", (header)); \
first = false; \
} else { \
out += snprintf(out, buf + size - out, " "); \
} \
\
out += snprintf(out, buf + size - out, "%s", f->string);\
\
} \
if (!first) \
out += snprintf(out, buf + size - out, "\n"); \
})
void print_cache_set_supported_feature_sets(struct cache_sb *sb)
{
char buf[4096];
char *out;
int size = sizeof(buf) - 1;
out = buf;
memset(buf, 0, sizeof(buf));
compose_feature_string(COMPAT, "sb.feature_compat");
printf("%s", buf);
out = buf;
memset(buf, 0, sizeof(buf));
compose_feature_string(RO_COMPAT, "sb.feature_ro_compat");
printf("%s", buf);
out = buf;
memset(buf, 0, sizeof(buf));
compose_feature_string(INCOMPAT, "sb.feature_incompat");
printf("%s", buf);
}