Map releases to client features (and back again).
Signed-off-by: Sage Weil <sage@redhat.com>
* Ceph string constants
*/
#include "include/types.h"
+#include "include/ceph_features.h"
const char *ceph_entity_type_name(int type)
{
if (!s) {
return -1;
}
+ if (strcmp(s, "mimic") == 0) {
+ return CEPH_RELEASE_MIMIC;
+ }
if (strcmp(s, "luminous") == 0) {
return CEPH_RELEASE_LUMINOUS;
}
return -1;
}
+uint64_t ceph_release_features(int r)
+{
+ uint64_t req = 0;
+
+ req |= CEPH_FEATURE_CRUSH_TUNABLES;
+ if (r <= CEPH_RELEASE_CUTTLEFISH)
+ return req;
+
+ req |= CEPH_FEATURE_CRUSH_TUNABLES2 |
+ CEPH_FEATURE_OSDHASHPSPOOL;
+ if (r <= CEPH_RELEASE_EMPEROR)
+ return req;
+
+ req |= CEPH_FEATURE_CRUSH_TUNABLES3 |
+ CEPH_FEATURE_OSD_PRIMARY_AFFINITY |
+ CEPH_FEATURE_OSD_CACHEPOOL;
+ if (r <= CEPH_RELEASE_GIANT)
+ return req;
+
+ req |= CEPH_FEATURE_CRUSH_V4;
+ if (r <= CEPH_RELEASE_INFERNALIS)
+ return req;
+
+ req |= CEPH_FEATURE_CRUSH_TUNABLES5;
+ if (r <= CEPH_RELEASE_JEWEL)
+ return req;
+
+ req |= CEPH_FEATURE_MSG_ADDR2;
+ if (r <= CEPH_RELEASE_KRAKEN)
+ return req;
+
+ req |= CEPH_FEATUREMASK_CRUSH_CHOOSE_ARGS; // and overlaps
+ if (r <= CEPH_RELEASE_LUMINOUS)
+ return req;
+
+ return req;
+}
+
+/* return oldest/first release that supports these features */
+int ceph_release_from_features(uint64_t features)
+{
+ int r = 1;
+ while (true) {
+ uint64_t need = ceph_release_features(r);
+ if ((need & features) != need ||
+ r == CEPH_RELEASE_MAX) {
+ r--;
+ need = ceph_release_features(r);
+ /* we want the first release that looks like this */
+ while (r > 1 && ceph_release_features(r - 1) == need) {
+ r--;
+ }
+ break;
+ }
+ ++r;
+ }
+ return r;
+}
+
const char *ceph_osd_watch_op_name(int o)
{
switch (o) {
#define CEPH_RELEASE_KRAKEN 11
#define CEPH_RELEASE_LUMINOUS 12
#define CEPH_RELEASE_MIMIC 13
+#define CEPH_RELEASE_MAX 14 /* highest + 1 */
extern const char *ceph_release_name(int r);
extern int ceph_release_from_name(const char *s);
+extern uint64_t ceph_release_features(int r);
+extern int ceph_release_from_features(uint64_t features);
/*
* The error code to return when an OSD can't handle a write
for (auto& q : p.second) {
f->open_object_section("group");
f->dump_unsigned("features", q.first);
+ f->dump_string("release", ceph_release_name(
+ ceph_release_from_features(q.first)));
f->dump_unsigned("num", q.second);
f->close_section();
}
add_ceph_unittest(unittest_mempool ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittest_mempool)
target_link_libraries(unittest_mempool global)
+# unittest_features
+add_executable(unittest_features
+ test_features.cc
+ )
+add_ceph_unittest(unittest_features ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittest_features)
+target_link_libraries(unittest_features global)
+
# unittest_crypto
add_executable(unittest_crypto
crypto.cc
--- /dev/null
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+#include <stdio.h>
+
+#include "global/global_init.h"
+#include "common/ceph_argparse.h"
+#include "global/global_context.h"
+#include "gtest/gtest.h"
+#include "include/ceph_features.h"
+#include "include/rados.h"
+
+
+TEST(features, release_features)
+{
+ for (int r = 1; r < CEPH_RELEASE_MAX; ++r) {
+ const char *name = ceph_release_name(r);
+ ASSERT_NE(string("unknown"), name);
+ ASSERT_EQ(r, ceph_release_from_name(name));
+ uint64_t features = ceph_release_features(r);
+ int rr = ceph_release_from_features(features);
+ cout << r << " " << name << " features 0x" << std::hex << features
+ << std::dec << " looks like " << ceph_release_name(rr) << std::endl;
+ EXPECT_LE(rr, r);
+ }
+}
+
+TEST(features, release_from_features) {
+ ASSERT_EQ(CEPH_RELEASE_JEWEL, ceph_release_from_features(575862587619852283));
+ ASSERT_EQ(CEPH_RELEASE_LUMINOUS,
+ ceph_release_from_features(1152323339925389307));
+}
+
+int main(int argc, char **argv)
+{
+ vector<const char*> args;
+ argv_to_vec(argc, (const char **)argv, args);
+
+ auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT,
+ CODE_ENVIRONMENT_UTILITY, 0);
+ common_init_finish(g_ceph_context);
+
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}