From 10bebfcac0af4c770c7e08206e63b5e37073b0c0 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Tue, 7 May 2019 12:49:02 -0400 Subject: [PATCH] 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 --- src/librbd/ImageCtx.cc | 4 +--- src/librbd/Utils.h | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/librbd/ImageCtx.cc b/src/librbd/ImageCtx.cc index a20069c6e16..5a8bf337745 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 c0b68b9f873..0f9ebe3a82d 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 -- 2.39.5