summaryrefslogtreecommitdiffstats
path: root/src/mds/cephfs_features.cc
blob: 3c7949c5ed7f8abd22f2ba5c51e232f47dbd4587 (plain)
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
77
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#include <array>
#include "cephfs_features.h"
#include "mdstypes.h"

static const std::array feature_names
{
  "reserved",
  "reserved",
  "reserved",
  "reserved",
  "reserved",
  "jewel",
  "kraken",
  "luminous",
  "mimic",
  "reply_encoding",
  "reclaim_client",
  "lazy_caps_wanted",
  "multi_reconnect",
  "deleg_ino",
  "metric_collect",
  "alternate_name",
  "notify_session_state",
  "op_getvxattr",
};
static_assert(feature_names.size() == CEPHFS_FEATURE_MAX + 1);

std::string_view cephfs_feature_name(size_t id)
{
  if (id > feature_names.size())
    return "unknown"sv;
  return feature_names[id];
}

int cephfs_feature_from_name(std::string_view name)
{
  if (name == "reserved"sv) {
    return -1;
  }
  for (size_t i = 0; i < feature_names.size(); ++i) {
    if (name == feature_names[i])
      return i;
  }
  return -1;
}

std::string cephfs_stringify_features(const feature_bitset_t& features)
{
  CachedStackStringStream css;
  bool first = true;
  *css << "{";
  for (size_t i = 0; i < feature_names.size(); ++i) {
    if (!features.test(i))
      continue;
    if (!first)
      *css << ",";
    *css << i << "=" << cephfs_feature_name(i);
    first = false;
  }
  *css << "}";
  return css->str();
}

void cephfs_dump_features(ceph::Formatter *f, const feature_bitset_t& features)
{
  for (size_t i = 0; i < feature_names.size(); ++i) {
    if (!features.test(i))
      continue;
    char s[18];
    snprintf(s, sizeof(s), "feature_%lu", i);
    f->dump_string(s, cephfs_feature_name(i));
  }
}