From: Radoslaw Zarzynski Date: Thu, 4 Feb 2021 17:33:13 +0000 (+0000) Subject: librados: introduce rados_nobjects_list_next2(). X-Git-Tag: v16.2.0~116^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=fa5c44a309ffae853598a804b7b3be3440f4d58c;p=ceph.git librados: introduce rados_nobjects_list_next2(). 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 (cherry picked from commit 9d268b0dd72324347ce74408b9a7a2a95c37ad0f) --- diff --git a/src/include/rados/librados.h b/src/include/rados/librados.h index 17fa5b7ce2d..5df8f99fe11 100644 --- a/src/include/rados/librados.h +++ b/src/include/rados/librados.h @@ -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. * diff --git a/src/librados/librados_c.cc b/src/librados/librados_c.cc index 6f9871127fd..76014beee71 100644 --- a/src/librados/librados_c.cc +++ b/src/librados/librados_c.cc @@ -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); /* diff --git a/src/tracing/librados.tp b/src/tracing/librados.tp index 5cfde1750a4..80bb79f9ce4 100644 --- a/src/tracing/librados.tp +++ b/src/tracing/librados.tp @@ -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),