From aa017678a73aede1b4f64eb18d9c45d06a87e7d3 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Tue, 23 Jan 2018 14:35:25 -0500 Subject: [PATCH] librados: getter for min compatible client versions Signed-off-by: Jason Dillaman --- src/include/rados/librados.h | 14 ++++++++++++++ src/include/rados/librados.hpp | 3 +++ src/librados/RadosClient.cc | 16 ++++++++++++++++ src/librados/RadosClient.h | 3 +++ src/librados/librados.cc | 16 ++++++++++++++++ src/test/librados/misc.cc | 26 ++++++++++++++++++++++++++ 6 files changed, 78 insertions(+) diff --git a/src/include/rados/librados.h b/src/include/rados/librados.h index 452c3ac573f..8ef08360026 100644 --- a/src/include/rados/librados.h +++ b/src/include/rados/librados.h @@ -706,6 +706,20 @@ CEPH_RADOS_API rados_config_t rados_cct(rados_t cluster); */ CEPH_RADOS_API uint64_t rados_get_instance_id(rados_t cluster); +/** + * Gets the minimum compatible client version + * + * @param cluster cluster handle + * @param[out] min_compat_client minimum compatible client version + * based upon the current features + * @param[out] require_min_compat_client required minimum client version + * based upon explicit setting + * @returns 0 on sucess, negative error code on failure + */ +CEPH_RADOS_API int rados_get_min_compatible_client(rados_t cluster, + int8_t* min_compat_client, + int8_t* require_min_compat_client); + /** * Create an io context * diff --git a/src/include/rados/librados.hpp b/src/include/rados/librados.hpp index cd3c5e1d60c..5c7befc49e4 100644 --- a/src/include/rados/librados.hpp +++ b/src/include/rados/librados.hpp @@ -1337,6 +1337,9 @@ namespace librados uint64_t get_instance_id(); + int get_min_compatible_client(int8_t* min_compat_client, + int8_t* require_min_compat_client); + int mon_command(std::string cmd, const bufferlist& inbl, bufferlist *outbl, std::string *outs); int mgr_command(std::string cmd, const bufferlist& inbl, diff --git a/src/librados/RadosClient.cc b/src/librados/RadosClient.cc index 17c4bfcd7a1..3fcd2523daf 100644 --- a/src/librados/RadosClient.cc +++ b/src/librados/RadosClient.cc @@ -441,6 +441,22 @@ uint64_t librados::RadosClient::get_instance_id() return instance_id; } +int librados::RadosClient::get_min_compatible_client(int8_t* min_compat_client, + int8_t* require_min_compat_client) +{ + int r = wait_for_osdmap(); + if (r < 0) { + return r; + } + + objecter->with_osdmap( + [min_compat_client, require_min_compat_client](const OSDMap& o) { + *min_compat_client = o.get_min_compat_client(); + *require_min_compat_client = o.get_require_min_compat_client(); + }); + return 0; +} + librados::RadosClient::~RadosClient() { if (messenger) diff --git a/src/librados/RadosClient.h b/src/librados/RadosClient.h index 324458e07e8..66016b10061 100644 --- a/src/librados/RadosClient.h +++ b/src/librados/RadosClient.h @@ -99,6 +99,9 @@ public: uint64_t get_instance_id(); + int get_min_compatible_client(int8_t* min_compat_client, + int8_t* require_min_compat_client); + int wait_for_latest_osdmap(); int create_ioctx(const char *name, IoCtxImpl **io); diff --git a/src/librados/librados.cc b/src/librados/librados.cc index a0e3abe5abc..a3143973e2a 100644 --- a/src/librados/librados.cc +++ b/src/librados/librados.cc @@ -2323,6 +2323,13 @@ uint64_t librados::Rados::get_instance_id() return client->get_instance_id(); } +int librados::Rados::get_min_compatible_client(int8_t* min_compat_client, + int8_t* require_min_compat_client) +{ + return client->get_min_compatible_client(min_compat_client, + require_min_compat_client); +} + int librados::Rados::conf_read_file(const char * const path) const { return rados_conf_read_file((rados_t)client, path); @@ -2888,6 +2895,15 @@ extern "C" uint64_t rados_get_instance_id(rados_t cluster) return retval; } +extern "C" int rados_get_min_compatible_client(rados_t cluster, + int8_t* min_compat_client, + int8_t* require_min_compat_client) +{ + librados::RadosClient *client = (librados::RadosClient *)cluster; + return client->get_min_compatible_client(min_compat_client, + require_min_compat_client); +} + extern "C" void rados_version(int *major, int *minor, int *extra) { tracepoint(librados, rados_version_enter, major, minor, extra); diff --git a/src/test/librados/misc.cc b/src/test/librados/misc.cc index e3101e23c37..93ac62ddca9 100644 --- a/src/test/librados/misc.cc +++ b/src/test/librados/misc.cc @@ -6,6 +6,7 @@ #include "include/err.h" #include "include/buffer.h" #include "include/rbd_types.h" +#include "include/rados.h" #include "include/rados/librados.h" #include "include/rados/librados.hpp" #include "include/stringify.h" @@ -1379,3 +1380,28 @@ TEST_F(LibRadosMiscECPP, CompareExtentRange) { read2.cmpext(2097152, bl3, nullptr); ASSERT_EQ(0, ioctx.operate("foo", &read2, nullptr)); } + +TEST_F(LibRadosMisc, MinCompatClient) { + int8_t min_compat_client; + int8_t require_min_compat_client; + ASSERT_EQ(0, rados_get_min_compatible_client(cluster, + &min_compat_client, + &require_min_compat_client)); + ASSERT_LE(-1, min_compat_client); + ASSERT_GT(CEPH_RELEASE_MAX, min_compat_client); + + ASSERT_LE(-1, require_min_compat_client); + ASSERT_GT(CEPH_RELEASE_MAX, require_min_compat_client); +} + +TEST_F(LibRadosMiscPP, MinCompatClient) { + int8_t min_compat_client; + int8_t require_min_compat_client; + ASSERT_EQ(0, cluster.get_min_compatible_client(&min_compat_client, + &require_min_compat_client)); + ASSERT_LE(-1, min_compat_client); + ASSERT_GT(CEPH_RELEASE_MAX, min_compat_client); + + ASSERT_LE(-1, require_min_compat_client); + ASSERT_GT(CEPH_RELEASE_MAX, require_min_compat_client); +}