#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
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;
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);