From: Jason Dillaman Date: Tue, 7 May 2019 16:49:02 +0000 (-0400) Subject: librbd: helper method to generate data object OIDs on-demand X-Git-Tag: v15.1.0~2664^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=10bebfcac0af4c770c7e08206e63b5e37073b0c0;p=ceph.git librbd: helper method to generate data object OIDs on-demand The new generator avoids multiple string length and copy operations that are currently required in the Striper. Signed-off-by: Jason Dillaman --- diff --git a/src/librbd/ImageCtx.cc b/src/librbd/ImageCtx.cc index a20069c6e163..5a8bf337745a 100644 --- a/src/librbd/ImageCtx.cc +++ b/src/librbd/ImageCtx.cc @@ -409,9 +409,7 @@ public: } string ImageCtx::get_object_name(uint64_t num) const { - char buf[object_prefix.length() + 32]; - snprintf(buf, sizeof(buf), format_string, num); - return string(buf); + return util::data_object_name(this, num); } uint64_t ImageCtx::get_stripe_unit() const diff --git a/src/librbd/Utils.h b/src/librbd/Utils.h index c0b68b9f873a..0f9ebe3a82db 100644 --- a/src/librbd/Utils.h +++ b/src/librbd/Utils.h @@ -6,11 +6,13 @@ #include "include/rados/librados.hpp" #include "include/rbd_types.h" +#include "include/ceph_assert.h" #include "include/Context.h" #include "common/zipkin_trace.h" #include #include +#include namespace librbd { @@ -107,6 +109,19 @@ const std::string header_name(const std::string &image_id); const std::string old_header_name(const std::string &image_name); std::string unique_lock_name(const std::string &name, void *address); +template +std::string data_object_name(I* image_ctx, uint64_t object_no) { + char buf[RBD_MAX_OBJ_NAME_SIZE]; + size_t length = snprintf(buf, RBD_MAX_OBJ_NAME_SIZE, + image_ctx->format_string, object_no); + ceph_assert(length < RBD_MAX_OBJ_NAME_SIZE); + + std::string oid; + oid.reserve(RBD_MAX_OBJ_NAME_SIZE); + oid.append(buf, length); + return oid; +} + librados::AioCompletion *create_rados_callback(Context *on_finish); template