]> git.proxmox.com Git - ceph.git/blob - ceph/src/mds/cephfs_features.cc
import ceph quincy 17.2.6
[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 "notify_session_state",
27 "op_getvxattr",
28 };
29 static_assert(feature_names.size() == CEPHFS_FEATURE_MAX + 1);
30
31 std::string_view cephfs_feature_name(size_t id)
32 {
33 if (id > feature_names.size())
34 return "unknown";
35 return feature_names[id];
36 }
37
38 int cephfs_feature_from_name(std::string_view name)
39 {
40 if (name == "reserved") {
41 return -1;
42 }
43 for (size_t i = 0; i < feature_names.size(); ++i) {
44 if (name == feature_names[i])
45 return i;
46 }
47 return -1;
48 }
49
50 std::string cephfs_stringify_features(const feature_bitset_t& features)
51 {
52 CachedStackStringStream css;
53 bool first = true;
54 *css << "{";
55 for (size_t i = 0; i < feature_names.size(); ++i) {
56 if (!features.test(i))
57 continue;
58 if (!first)
59 *css << ",";
60 *css << i << "=" << cephfs_feature_name(i);
61 first = false;
62 }
63 *css << "}";
64 return css->str();
65 }
66
67 void cephfs_dump_features(ceph::Formatter *f, const feature_bitset_t& features)
68 {
69 for (size_t i = 0; i < feature_names.size(); ++i) {
70 if (!features.test(i))
71 continue;
72 char s[18];
73 snprintf(s, sizeof(s), "feature_%zu", i);
74 f->dump_string(s, cephfs_feature_name(i));
75 }
76 }
77