]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: introduce new constants for tracking max block name prefix 13141/head
authorJason Dillaman <dillaman@redhat.com>
Thu, 26 Jan 2017 19:02:11 +0000 (14:02 -0500)
committerJason Dillaman <dillaman@redhat.com>
Mon, 30 Jan 2017 20:25:23 +0000 (15:25 -0500)
Fixes: http://tracker.ceph.com/issues/18653
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/include/rbd_types.h
src/librbd/Utils.cc
src/librbd/image/CreateRequest.cc

index b564e0fbfd1f2d5bb1701a5d47d451f01709a923..a641b32dca38f63d41b0fc8b1ae1cd372551cc7f 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 6d077ae641f51f9370222c1650e15c4264a763a6..63d9a06fa64d5962bc121ae05f1594bcc3d875ee 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);