]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: add the validate of the format and clone_format
authorjunxiang Mu <1948535941@qq.com>
Fri, 21 Jun 2024 02:10:21 +0000 (10:10 +0800)
committerIlya Dryomov <idryomov@gmail.com>
Thu, 27 Jun 2024 11:59:59 +0000 (13:59 +0200)
[ idryomov: squash test_unsupported_clone_format() into
  test_clone_format() ]

Fixes: https://tracker.ceph.com/issues/65744
Signed-off-by: junxiang Mu <1948535941@qq.com>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
src/librbd/api/Image.cc
src/librbd/image/CloneRequest.cc
src/librbd/internal.cc
src/test/pybind/test_rbd.py

index 19dc5aa68bd4e684efc76e4f0e19e8378bdf603d..d813242f5f4704a0c507bddd587e5c0f1aa71dbe 100644 (file)
@@ -570,8 +570,8 @@ int Image<I>::deep_copy(I *src, librados::IoCtx& dest_md_ctx,
   if (opts.get(RBD_IMAGE_OPTION_FORMAT, &format) != 0) {
     opts.set(RBD_IMAGE_OPTION_FORMAT, format);
   }
-  if (format == 1) {
-    lderr(cct) << "old format not supported for destination image" << dendl;
+  if (format != 2) {
+    lderr(cct) << "unsupported destination image format: " << format << dendl;
     return -EINVAL;
   }
   uint64_t stripe_unit = src->stripe_unit;
index 700bd24587649d5b781aa6860acae6e69ae8bc9c..d2e2547507cb272be6cefd1013575271ee921a61 100644 (file)
@@ -87,8 +87,8 @@ void CloneRequest<I>::validate_options() {
 
   uint64_t format = 0;
   m_opts.get(RBD_IMAGE_OPTION_FORMAT, &format);
-  if (format < 2) {
-    lderr(m_cct) << "format 2 or later required for clone" << dendl;
+  if (format != 2) {
+    lderr(m_cct) << "unsupported format for clone: " << format << dendl;
     complete(-EINVAL);
     return;
   }
@@ -124,6 +124,12 @@ void CloneRequest<I>::validate_options() {
     }
   }
 
+  if (m_clone_format < 1 || m_clone_format > 2) {
+    lderr(m_cct) << "unsupported clone format: " << m_clone_format << dendl;
+    complete(-EINVAL);
+    return;
+  }
+
   if (m_clone_format == 1 &&
       m_parent_io_ctx.get_namespace() != m_ioctx.get_namespace()) {
     ldout(m_cct, 1) << "clone v2 required for cross-namespace clones" << dendl;
index dd674f3a9497c19a83d0274fd1e217157f76d14d..c550053666995397c6852c74b6d5143f4b1ed545 100644 (file)
@@ -638,6 +638,11 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) {
     uint64_t format;
     if (opts.get(RBD_IMAGE_OPTION_FORMAT, &format) != 0)
       format = cct->_conf.get_val<uint64_t>("rbd_default_format");
+
+    if (format < 1 || format > 2) {
+      lderr(cct) << "unsupported format: " << format << dendl;
+      return -EINVAL;
+    }
     bool old_format = format == 1;
 
     // make sure it doesn't already exist, in either format
index 5f52888f8eca0af3ff6775efd04c5f819dfe0787..47421cc4906a198b4535ff2f394cbc5398d62907 100644 (file)
@@ -1730,6 +1730,11 @@ class TestClone(object):
 
     def test_clone_format(self):
         clone_name2 = get_temp_image_name()
+        assert_raises(InvalidArgument, self.rbd.clone, ioctx, image_name,
+                       'snap1', ioctx, clone_name2, features, clone_format=0)
+        assert_raises(InvalidArgument, self.rbd.clone, ioctx, image_name,
+                       'snap1', ioctx, clone_name2, features, clone_format=3)
+
         self.rbd.clone(ioctx, image_name, 'snap1', ioctx, clone_name2,
                        features, clone_format=1)
         with Image(ioctx, clone_name2) as clone2: