const char *namespace_name);
CEPH_RBD_API int rbd_namespace_list(rados_ioctx_t io, char *namespace_names,
size_t *size);
+CEPH_RBD_API int rbd_namespace_exists(rados_ioctx_t io, const char *namespace_name,
+ bool *exists);
#ifdef __cplusplus
}
int namespace_create(IoCtx& ioctx, const char *namespace_name);
int namespace_remove(IoCtx& ioctx, const char *namespace_name);
int namespace_list(IoCtx& io_ctx, std::vector<std::string>* namespace_names);
+ int namespace_exists(IoCtx& io_ctx, const char *namespace_name, bool *exists);
private:
/* We don't allow assignment or copying */
return 0;
}
+template <typename I>
+int Namespace<I>::exists(librados::IoCtx& io_ctx, const std::string& name, bool *exists)
+{
+ CephContext *cct = (CephContext *)io_ctx.cct();
+ ldout(cct, 5) << "name=" << name << dendl;
+
+ if (name.empty()) {
+ return -EINVAL;
+ }
+
+ librados::IoCtx ns_ctx;
+ ns_ctx.dup(io_ctx);
+ ns_ctx.set_namespace(name);
+
+ int r = librbd::cls_client::dir_state_assert(&ns_ctx, RBD_DIRECTORY,
+ cls::rbd::DIRECTORY_STATE_READY);
+ if (r == 0) {
+ *exists = true;
+ } else if (r == -ENOENT) {
+ *exists = false;
+ } else {
+ lderr(cct) << "error asserting namespace: " << cpp_strerror(r) << dendl;
+ return r;
+ }
+
+ return 0;
+}
+
} // namespace api
} // namespace librbd
static int create(librados::IoCtx& io_ctx, const std::string& name);
static int remove(librados::IoCtx& io_ctx, const std::string& name);
static int list(librados::IoCtx& io_ctx, std::vector<std::string>* names);
+ static int exists(librados::IoCtx& io_ctx, const std::string& name, bool *exists);
};
return librbd::api::Namespace<>::list(io_ctx, namespace_names);
}
+ int RBD::namespace_exists(IoCtx& io_ctx, const char *namespace_name,
+ bool *exists) {
+ return librbd::api::Namespace<>::exists(io_ctx, namespace_name, exists);
+ }
+
int RBD::list(IoCtx& io_ctx, vector<string>& names)
{
TracepointProvider::initialize<tracepoint_traits>(get_cct(io_ctx));
return (int)expected_size;
}
+extern "C" int rbd_namespace_exists(rados_ioctx_t io,
+ const char *namespace_name,
+ bool *exists) {
+ librados::IoCtx io_ctx;
+ librados::IoCtx::from_rados_ioctx_t(io, io_ctx);
+
+ return librbd::api::Namespace<>::exists(io_ctx, namespace_name, exists);
+}
+
extern "C" int rbd_copy(rbd_image_t image, rados_ioctx_t dest_p,
const char *destname)
{
ASSERT_EQ(2U, cpp_names.size());
ASSERT_EQ("name1", cpp_names[0]);
ASSERT_EQ("name3", cpp_names[1]);
+ bool exists;
+ ASSERT_EQ(0, rbd_namespace_exists(ioctx, "name2", &exists));
+ ASSERT_FALSE(exists);
+ ASSERT_EQ(0, rbd_namespace_exists(ioctx, "name3", &exists));
+ ASSERT_TRUE(exists);
rados_ioctx_destroy(ioctx);
}
ASSERT_EQ(2U, names.size());
ASSERT_EQ("name1", names[0]);
ASSERT_EQ("name3", names[1]);
+ bool exists;
+ ASSERT_EQ(0, rbd.namespace_exists(ioctx, "name2", &exists));
+ ASSERT_FALSE(exists);
+ ASSERT_EQ(0, rbd.namespace_exists(ioctx, "name3", &exists));
+ ASSERT_TRUE(exists);
librados::IoCtx ns_io_ctx;
ns_io_ctx.dup(ioctx);