]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librados: introduce rados_nobjects_list_next2().
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Thu, 4 Feb 2021 17:33:13 +0000 (17:33 +0000)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Tue, 9 Mar 2021 17:04:45 +0000 (17:04 +0000)
It's needed to properly list an object with the NUL
character in the name. Such names can appear mostly
as a consequence of bugs in clients.

Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
(cherry picked from commit 9d268b0dd72324347ce74408b9a7a2a95c37ad0f)

src/include/rados/librados.h
src/librados/librados_c.cc
src/tracing/librados.tp

index 17fa5b7ce2dcdb30ce98b3494200ff7537ebd863..5df8f99fe111fc859b95f104af26052d8443c1a7 100644 (file)
@@ -222,7 +222,7 @@ typedef void *rados_ioctx_t;
  *
  * An iterator for listing the objects in a pool.
  * Used with rados_nobjects_list_open(),
- * rados_nobjects_list_next(), and
+ * rados_nobjects_list_next(), rados_nobjects_list_next2(), and
  * rados_nobjects_list_close().
  */
 typedef void *rados_list_ctx_t;
@@ -1137,6 +1137,32 @@ CEPH_RADOS_API int rados_nobjects_list_next(rados_list_ctx_t ctx,
                                            const char **key,
                                             const char **nspace);
 
+/**
+ * Get the next object name, locator and their sizes in the pool
+ *
+ * The sizes allow to list objects with \0 (the NUL character)
+ * in .e.g *entry. Is is unusual see such object names but a bug
+ * in a client has risen the need to handle them as well.
+ * *entry and *key are valid until next call to rados_nobjects_list_*
+ *
+ * @param ctx iterator marking where you are in the listing
+ * @param entry where to store the name of the entry
+ * @param key where to store the object locator (set to NULL to ignore)
+ * @param nspace where to store the object namespace (set to NULL to ignore)
+ * @param entry_size where to store the size of name of the entry
+ * @param key_size where to store the size of object locator (set to NULL to ignore)
+ * @param nspace_size where to store the size of object namespace (set to NULL to ignore)
+ * @returns 0 on success, negative error code on failure
+ * @returns -ENOENT when there are no more objects to list
+ */
+CEPH_RADOS_API int rados_nobjects_list_next2(rados_list_ctx_t ctx,
+                                             const char **entry,
+                                             const char **key,
+                                             const char **nspace,
+                                             size_t *entry_size,
+                                             size_t *key_size,
+                                             size_t *nspace_size);
+
 /**
  * Close the object listing handle.
  *
index 6f9871127fd74d27b3dc0deb214cac4e0fb89e6c..76014beee715ec9cfda2da3901eb9c5768ec93ec 100644 (file)
@@ -2410,6 +2410,22 @@ extern "C" int LIBRADOS_C_API_DEFAULT_F(rados_nobjects_list_next)(
   const char **nspace)
 {
   tracepoint(librados, rados_nobjects_list_next_enter, listctx);
+  uint32_t retval = rados_nobjects_list_next2(listctx, entry, key, nspace, NULL, NULL, NULL);
+  tracepoint(librados, rados_nobjects_list_next_exit, 0, *entry, key, nspace);
+  return retval;
+}
+LIBRADOS_C_API_BASE_DEFAULT(rados_nobjects_list_next);
+
+extern "C" int LIBRADOS_C_API_DEFAULT_F(rados_nobjects_list_next2)(
+  rados_list_ctx_t listctx,
+  const char **entry,
+  const char **key,
+  const char **nspace,
+  size_t *entry_size,
+  size_t *key_size,
+  size_t *nspace_size)
+{
+  tracepoint(librados, rados_nobjects_list_next2_enter, listctx);
   librados::ObjListCtx *lh = (librados::ObjListCtx *)listctx;
   Objecter::NListContext *h = lh->nlc;
 
@@ -2421,11 +2437,11 @@ extern "C" int LIBRADOS_C_API_DEFAULT_F(rados_nobjects_list_next)(
   if (h->list.empty()) {
     int ret = lh->ctx->nlist(lh->nlc, RADOS_LIST_MAX_ENTRIES);
     if (ret < 0) {
-      tracepoint(librados, rados_nobjects_list_next_exit, ret, NULL, NULL, NULL);
+      tracepoint(librados, rados_nobjects_list_next2_exit, ret, NULL, NULL, NULL, NULL, NULL, NULL);
       return ret;
     }
     if (h->list.empty()) {
-      tracepoint(librados, rados_nobjects_list_next_exit, -ENOENT, NULL, NULL, NULL);
+      tracepoint(librados, rados_nobjects_list_next2_exit, -ENOENT, NULL, NULL, NULL, NULL, NULL, NULL);
       return -ENOENT;
     }
   }
@@ -2440,10 +2456,19 @@ extern "C" int LIBRADOS_C_API_DEFAULT_F(rados_nobjects_list_next)(
   }
   if (nspace)
     *nspace = h->list.front().nspace.c_str();
-  tracepoint(librados, rados_nobjects_list_next_exit, 0, *entry, key, nspace);
+
+  if (entry_size)
+    *entry_size = h->list.front().oid.size();
+  if (key_size)
+    *key_size = h->list.front().locator.size();
+  if (nspace_size)
+    *nspace_size = h->list.front().nspace.size();
+
+  tracepoint(librados, rados_nobjects_list_next2_exit, 0, entry, key, nspace,
+             entry_size, key_size, nspace_size);
   return 0;
 }
-LIBRADOS_C_API_BASE_DEFAULT(rados_nobjects_list_next);
+LIBRADOS_C_API_BASE_DEFAULT(rados_nobjects_list_next2);
 
 
 /*
index 5cfde1750a498758b45cb8adeb59b75863c0bb13..80bb79f9ce43e55293e79ca58838ffd2e345ba88 100644 (file)
@@ -1884,6 +1884,32 @@ TRACEPOINT_EVENT(librados, rados_nobjects_list_next_exit,
     )
 )
 
+TRACEPOINT_EVENT(librados, rados_nobjects_list_next2_enter,
+    TP_ARGS(
+        rados_list_ctx_t, listctx),
+    TP_FIELDS(
+        ctf_integer_hex(rados_list_ctx_t, listctx, listctx)
+    )
+)
+
+TRACEPOINT_EVENT(librados, rados_nobjects_list_next2_exit,
+    TP_ARGS(
+        int, retval,
+        const char* const*, entry,
+        const char* const*, key,
+        const char* const*, nspace,
+        const size_t*, entry_size,
+        const size_t*, key_size,
+        const size_t*, nspace_size),
+    TP_FIELDS(
+        ctf_integer(int, retval, retval)
+        ceph_ctf_sequencep(char, entry, entry, size_t, entry_size)
+        ceph_ctf_sequencep(char, key, key, size_t, key_size)
+        ceph_ctf_sequencep(char, nspace, nspace, size_t, nspace_size)
+    )
+)
+
+
 TRACEPOINT_EVENT(librados, rados_objects_list_open_enter,
     TP_ARGS(
         rados_ioctx_t, ioctx),