]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: helper method to generate data object OIDs on-demand
authorJason Dillaman <dillaman@redhat.com>
Tue, 7 May 2019 16:49:02 +0000 (12:49 -0400)
committerJason Dillaman <dillaman@redhat.com>
Mon, 13 May 2019 17:07:04 +0000 (13:07 -0400)
The new generator avoids multiple string length and copy operations
that are currently required in the Striper.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/ImageCtx.cc
src/librbd/Utils.h

index a20069c6e163122eb0bf12c44ab66127fa50e802..5a8bf337745a7954f1d6bb8d27e530b87de23d47 100644 (file)
@@ -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
index c0b68b9f873a145a198447efd70850a1277ee37f..0f9ebe3a82db672c3c763cdf83a56fe15aaa0308 100644 (file)
@@ -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 <atomic>
 #include <type_traits>
+#include <stdio.h>
 
 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 <typename I>
+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 <typename T>