*/
int rados_cluster_stat(rados_t cluster, struct rados_cluster_stat_t *result);
+/**
+ * Get the fsid of the cluster as a hexadecimal string.
+ *
+ * The fsid is a unique id of an entire Ceph cluster.
+ *
+ * @param cluster where to get the fsid
+ * @param buf where to write the fsid
+ * @param len the size of buf in bytes (should be 37)
+ * @returns 0 on success, negative error code on failure
+ * @returns -ERANGE if the buffer is too short to contain the
+ * fsid
+ */
+int rados_cluster_fsid(rados_t cluster, char *buf, size_t len);
/**
* @defgroup librados_h_pools Pools
std::string& category,
std::map<std::string, stats_map>& stats);
int cluster_stat(cluster_stat_t& result);
+ int cluster_fsid(std::string *fsid);
/* pool aio */
static PoolAsyncCompletion *pool_async_create_completion();
return 0;
}
+int librados::RadosClient::get_fsid(std::string *s)
+{
+ if (!s)
+ return -EINVAL;
+ Mutex::Locker l(lock);
+ ostringstream oss;
+ oss << osdmap.get_fsid();
+ *s = oss.str();
+ return 0;
+}
+
int librados::RadosClient::connect()
{
common_init_finish(cct);
int create_ioctx(const char *name, IoCtxImpl **io);
+ int get_fsid(std::string *s);
int64_t lookup_pool(const char *name);
const char *get_pool_name(int64_t pool_id);
int pool_get_auid(uint64_t pool_id, unsigned long long *auid);
return r;
}
+int librados::Rados::cluster_fsid(string *fsid)
+{
+ return client->get_fsid(fsid);
+}
+
librados::PoolAsyncCompletion *librados::Rados::pool_async_create_completion()
{
PoolAsyncCompletionImpl *c = new PoolAsyncCompletionImpl;
return name.length();
}
+extern "C" int rados_cluster_fsid(rados_t cluster, char *buf,
+ size_t maxlen)
+{
+ librados::RadosClient *radosp = (librados::RadosClient *)cluster;
+ std::string fsid;
+ radosp->get_fsid(&fsid);
+ if (fsid.length() >= maxlen)
+ return -ERANGE;
+ strcpy(buf, fsid.c_str());
+ return fsid.length();
+}
+
extern "C" int rados_pool_list(rados_t cluster, char *buf, size_t len)
{
librados::RadosClient *client = (librados::RadosClient *)cluster;
break
return filter(lambda name: name != '', c_names.raw.split('\0'))
+ def get_fsid(self):
+ self.require_state("connected")
+ fsid_len = 36
+ fsid = create_string_buffer(fsid_len + 1)
+ ret = self.librados.rados_cluster_fsid(self.cluster,
+ byref(fsid),
+ fsid_len + 1)
+ if ret < 0:
+ raise make_ex(ret, "error getting cluster fsid")
+ return fsid.value
+
def open_ioctx(self, ioctx_name):
self.require_state("connected")
if not isinstance(ioctx_name, str):
ANONYMOUS_AUID, ADMIN_AUID)
import threading
-class TestPool(object):
+class TestRados(object):
def setUp(self):
self.rados = Rados(conffile='')
eq(set(['a' * 500]), self.list_non_default_pools())
self.rados.delete_pool('a' * 500)
+ def test_get_fsid(self):
+ fsid = self.rados.get_fsid()
+ eq(len(fsid), 36)
+
class TestIoctx(object):
def setUp(self):
Rados::version(&major, &minor, &extra);
}
+TEST(LibRadosMisc, ClusterFSID) {
+ rados_t cluster;
+ std::string pool_name = get_temp_pool_name();
+ ASSERT_EQ("", create_one_pool(pool_name, &cluster));
+
+ char fsid[37];
+ ASSERT_EQ(-ERANGE, rados_cluster_fsid(cluster, fsid, sizeof(fsid) - 1));
+ ASSERT_EQ(sizeof(fsid) - 1,
+ (size_t)rados_cluster_fsid(cluster, fsid, sizeof(fsid)));
+
+ ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
+}
+
static std::string read_key_from_tmap(IoCtx& ioctx, const std::string &obj,
const std::string &key)
{