]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: introduce new constants for tracking max block name prefix 14539/head
authorJason Dillaman <dillaman@redhat.com>
Thu, 26 Jan 2017 19:02:11 +0000 (14:02 -0500)
committerNathan Cutler <ncutler@suse.com>
Mon, 3 Jul 2017 10:49:11 +0000 (12:49 +0200)
Fixes: http://tracker.ceph.com/issues/18653
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
(cherry picked from commit 2c08629c99d90aa7676b59263c055c9f1f577039)

src/include/rbd_types.h
src/librbd/Utils.cc
src/librbd/image/CreateRequest.cc

index de7d1c6f35a8beed7f559b879f22493c8fbba20a..a8eac71538e1d6a977d2e08d24b93d12a34d97db 100644 (file)
 #define RBD_MAX_OBJ_NAME_SIZE  96
 #define RBD_MAX_BLOCK_NAME_SIZE 24
 
+/**
+ * Maximum string length of the RBD v2 image id (not including
+ * null termination). This limit was derived from the existing
+ * RBD_MAX_BLOCK_NAME_SIZE limit which needs to hold the "rbd_data."
+ * prefix and null termination.
+ */
+#define RBD_MAX_IMAGE_ID_LENGTH 14
+
+/**
+ * Maximum string length of the RBD block object name prefix (not including
+ * null termination).
+ *
+ * v1 format: rb.<max 8-byte high id>.<max 8-byte low id>.<max 8-byte extra>
+ * v2 format: rbd_data.[<max 19-byte pool id>.]<max 14-byte image id>
+ *
+ * Note: new features might require increasing this maximum prefix length.
+ */
+#define RBD_MAX_BLOCK_NAME_PREFIX_LENGTH 43
+
 #define RBD_COMP_NONE          0
 #define RBD_CRYPT_NONE         0
 
index 1dff4ce4b8f1d5722fdad2d8dcd238b30be2aa12..9dcead61f63ff015a4deb4806d78e7904d751803 100644 (file)
@@ -56,9 +56,8 @@ std::string generate_image_id(librados::IoCtx &ioctx) {
   std::string id = bid_ss.str();
 
   // ensure the image id won't overflow the fixed block name size
-  const size_t max_id_length = RBD_MAX_BLOCK_NAME_SIZE - strlen(RBD_DATA_PREFIX) - 1;
-  if (id.length() > max_id_length) {
-    id = id.substr(id.length() - max_id_length);
+  if (id.length() > RBD_MAX_IMAGE_ID_LENGTH) {
+    id = id.substr(id.length() - RBD_MAX_IMAGE_ID_LENGTH);
   }
 
   return id;
index 2a9dfac2fc1f26cc3a7aad38407b771513c2abf1..2c10092723ede2b9bbb41d24bd041cc21cbfc473 100644 (file)
@@ -443,6 +443,11 @@ void CreateRequest<I>::create_image() {
     oss << stringify(m_ioctx.get_id()) << ".";
   }
   oss << m_image_id;
+  if (oss.str().length() > RBD_MAX_BLOCK_NAME_PREFIX_LENGTH) {
+    lderr(m_cct) << "object prefix '" << oss.str() << "' too large" << dendl;
+    complete(-EINVAL);
+    return;
+  }
 
   librados::ObjectWriteOperation op;
   op.create(true);