librados: getter for min compatible client versions

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
This commit is contained in:
Jason Dillaman 2018-01-23 14:35:25 -05:00
parent c553f00c5f
commit aa017678a7
6 changed files with 78 additions and 0 deletions

View File

@ -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
*

View File

@ -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,

View File

@ -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)

View File

@ -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);

View File

@ -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);

View File

@ -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);
}