]> git.proxmox.com Git - ceph.git/blob - ceph/src/mds/cephfs_features.cc
3709ca8b9b4aff61359c8cb3ecfa3b82b77bc2d3
[ceph.git] / ceph / src / mds / cephfs_features.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #include <array>
5 #include "cephfs_features.h"
6 #include "mdstypes.h"
7
8 static const std::array feature_names
9 {
10 "reserved",
11 "reserved",
12 "reserved",
13 "reserved",
14 "reserved",
15 "jewel",
16 "kraken",
17 "luminous",
18 "mimic",
19 "reply_encoding",
20 "reclaim_client",
21 "lazy_caps_wanted",
22 "multi_reconnect",
23 "deleg_ino",
24 "metric_collect",
25 "alternate_name",
26 };
27 static_assert(feature_names.size() == CEPHFS_FEATURE_MAX + 1);
28
29 std::string_view cephfs_feature_name(size_t id)
30 {
31 if (id > feature_names.size())
32 return "unknown";
33 return feature_names[id];
34 }
35
36 int cephfs_feature_from_name(std::string_view name)
37 {
38 if (name == "reserved") {
39 return -1;
40 }
41 for (size_t i = 0; i < feature_names.size(); ++i) {
42 if (name == feature_names[i])
43 return i;
44 }
45 return -1;
46 }
47
48 std::string cephfs_stringify_features(const feature_bitset_t& features)
49 {
50 CachedStackStringStream css;
51 bool first = true;
52 *css << "{";
53 for (size_t i = 0; i < feature_names.size(); ++i) {
54 if (!features.test(i))
55 continue;
56 if (!first)
57 *css << ",";
58 *css << i << "=" << cephfs_feature_name(i);
59 first = false;
60 }
61 *css << "}";
62 return css->str();
63 }
64
65 void cephfs_dump_features(ceph::Formatter *f, const feature_bitset_t& features)
66 {
67 for (size_t i = 0; i < feature_names.size(); ++i) {
68 if (!features.test(i))
69 continue;
70 char s[18];
71 snprintf(s, sizeof(s), "feature_%zu", i);
72 f->dump_string(s, cephfs_feature_name(i));
73 }
74 }
75