]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librados: add namespace getter to IoCtx API
authorJason Dillaman <dillaman@redhat.com>
Wed, 20 Jun 2018 18:16:03 +0000 (14:16 -0400)
committerJason Dillaman <dillaman@redhat.com>
Thu, 21 Jun 2018 12:33:17 +0000 (08:33 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/include/rados/librados.h
src/include/rados/librados.hpp
src/librados/librados.cc
src/test/librados/list.cc
src/tracing/librados.tp

index ac4a1b1bfce2de89ae42572a0c94a0cf2f498f08..03ad017464dca182ba54cabd1ba74aa6df1969cb 100644 (file)
@@ -998,6 +998,18 @@ CEPH_RADOS_API void rados_ioctx_locator_set_key(rados_ioctx_t io,
  */
 CEPH_RADOS_API void rados_ioctx_set_namespace(rados_ioctx_t io,
                                               const char *nspace);
+
+/**
+ * Get the namespace for objects within the io context
+ *
+ * @param io the io context to query
+ * @param buf pointer to buffer where name will be stored
+ * @param maxlen size of buffer where name will be stored
+ * @returns length of string stored, or -ERANGE if buffer too small
+ */
+CEPH_RADOS_API int rados_ioctx_get_namespace(rados_ioctx_t io, char *buf,
+                                             unsigned maxlen);
+
 /** @} obj_loc */
 
 /**
index a7aad81c9e430bf06c44e34e59cf111574556142..85257dde4f882eb9e0fc20b08bfc4b6551454601 100644 (file)
@@ -1242,6 +1242,7 @@ namespace librados
 
     void locator_set_key(const std::string& key);
     void set_namespace(const std::string& nspace);
+    std::string get_namespace() const;
 
     int64_t get_id();
 
index 08c4379c4a63cec1c4e1fdfccc3a0656565cf73d..4b1432632dfafb1158a792e7627e2d81420de509 100644 (file)
@@ -2215,6 +2215,11 @@ void librados::IoCtx::set_namespace(const string& nspace)
   io_ctx_impl->oloc.nspace = nspace;
 }
 
+std::string librados::IoCtx::get_namespace() const
+{
+  return io_ctx_impl->oloc.nspace;
+}
+
 int64_t librados::IoCtx::get_id()
 {
   return io_ctx_impl->get_id();
@@ -4033,6 +4038,22 @@ extern "C" void rados_ioctx_set_namespace(rados_ioctx_t io, const char *nspace)
   tracepoint(librados, rados_ioctx_set_namespace_exit);
 }
 
+extern "C" int rados_ioctx_get_namespace(rados_ioctx_t io, char *s,
+                                         unsigned maxlen)
+{
+  tracepoint(librados, rados_ioctx_get_namespace_enter, io, maxlen);
+  librados::IoCtxImpl *ctx = (librados::IoCtxImpl *)io;
+  auto length = ctx->oloc.nspace.length();
+  if (length >= maxlen) {
+    tracepoint(librados, rados_ioctx_get_namespace_exit, -ERANGE, "");
+    return -ERANGE;
+  }
+  strcpy(s, ctx->oloc.nspace.c_str());
+  int retval = (int)length;
+  tracepoint(librados, rados_ioctx_get_namespace_exit, retval, s);
+  return retval;
+}
+
 extern "C" rados_t rados_ioctx_get_cluster(rados_ioctx_t io)
 {
   tracepoint(librados, rados_ioctx_get_cluster_enter, io);
index 74000ac2da5dda39fcb0a37d1aa7195dd06b6360..097bab5d532966b2a7ec948debb2de46c7934cd8 100644 (file)
@@ -183,6 +183,11 @@ TEST_F(LibRadosList, ListObjectsNS) {
   ASSERT_EQ(0, rados_write(ioctx, "foo6", buf, sizeof(buf), 0));
   ASSERT_EQ(0, rados_write(ioctx, "foo7", buf, sizeof(buf), 0));
 
+  char nspace[4];
+  ASSERT_EQ(-ERANGE, rados_ioctx_get_namespace(ioctx, nspace, 3));
+  ASSERT_EQ(0, rados_ioctx_get_namespace(ioctx, nspace, sizeof(nspace)));
+  ASSERT_EQ(0, strcmp("ns2", nspace));
+
   std::set<std::string> def, ns1, ns2, all;
   def.insert(std::string("foo1"));
   def.insert(std::string("foo2"));
@@ -271,6 +276,7 @@ TEST_F(LibRadosListPP, ListObjectsPPNS) {
   ioctx.set_namespace("ns2");
   ASSERT_EQ(0, ioctx.write("foo6", bl1, sizeof(buf), 0));
   ASSERT_EQ(0, ioctx.write("foo7", bl1, sizeof(buf), 0));
+  ASSERT_EQ(std::string("ns2"), ioctx.get_namespace());
 
   std::set<std::string> def, ns1, ns2, all;
   def.insert(std::string("foo1"));
index f84e078a8098247e20d293c2ebbd1b880042da9e..98462ce04838bde1ec51b24aaaee9198263aa504 100644 (file)
@@ -1263,6 +1263,26 @@ TRACEPOINT_EVENT(librados, rados_ioctx_set_namespace_exit,
     TP_FIELDS()
 )
 
+TRACEPOINT_EVENT(librados, rados_ioctx_get_namespace_enter,
+    TP_ARGS(
+        rados_ioctx_t, ioctx,
+        unsigned, maxlen),
+    TP_FIELDS(
+        ctf_integer_hex(rados_ioctx_t, ioctx, ioctx)
+        ctf_integer(unsigned, maxlen, maxlen)
+    )
+)
+
+TRACEPOINT_EVENT(librados, rados_ioctx_get_namespace_exit,
+    TP_ARGS(
+        int, retval,
+        const char*, name),
+    TP_FIELDS(
+        ctf_integer(int, retval, retval)
+        ctf_string(name, name)
+    )
+)
+
 TRACEPOINT_EVENT(librados, rados_ioctx_get_cluster_enter,
     TP_ARGS(
         rados_ioctx_t, ioctx),