]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: disallow migrating a parent image 25765/head
authorsongweibin <song.weibin@zte.com.cn>
Thu, 3 Jan 2019 07:38:54 +0000 (15:38 +0800)
committersongweibin <song.weibin@zte.com.cn>
Thu, 3 Jan 2019 08:41:35 +0000 (16:41 +0800)
Fixes:
```
[swb@ ~/ceph/ceph-dev/build]$ rbd snap create img2@snap1
[swb@ ~/ceph/ceph-dev/build]$ rbd clone img2@snap1 clone1 --rbd-default-clone-format 2
[swb@ ~/ceph/ceph-dev/build]$ rbd migration prepare img2 m2
[swb@ ~/ceph/ceph-dev/build]$ rbd migration execute m2
Image migration: 100% complete...done.
[swb@ ~/ceph/ceph-dev/build]$ rbd migration commit m2
2019-01-03 09:55:39.914 7fa5e177a040 -1 librbd::image::RemoveRequest: 0x560084be6e30 check_image_snaps: image has snapshots - not removing
2019-01-03 09:55:39.989 7fa5e177a040 -1 librbd::Migration: remove_src_image: failed removing source image: (39) Directory not empty
Commit image migration: 0% complete...failed.
rbd: committing migration failed: (39) Directory not empty
```

Signed-off-by: songweibin <song.weibin@zte.com.cn>
src/librbd/api/Migration.cc

index aad7c7394f15e64abe1217862c3714d85eb97d25..b5cf4a063476d8a7aa0f185032efb0dd7aac146b 100644 (file)
@@ -14,6 +14,7 @@
 #include "librbd/Utils.h"
 #include "librbd/api/Config.h"
 #include "librbd/api/Group.h"
+#include "librbd/api/Image.h"
 #include "librbd/api/Snapshot.h"
 #include "librbd/api/Trash.h"
 #include "librbd/deep_copy/MetadataCopyRequest.h"
@@ -994,6 +995,25 @@ int Migration<I>::list_snaps(std::vector<librbd::snap_info_t> *snapsptr) {
                      << dendl;
         return -EBUSY;
       }
+
+      RWLock::RLocker l(m_src_image_ctx->snap_lock);
+      cls::rbd::ParentImageSpec parent_spec{m_src_image_ctx->md_ctx.get_id(),
+                                            m_src_image_ctx->md_ctx.get_namespace(),
+                                            m_src_image_ctx->id, snap.id};
+      std::vector<librbd::linked_image_spec_t> child_images;
+      r = api::Image<I>::list_children(m_src_image_ctx, parent_spec, &child_images);
+      if (r < 0) {
+        lderr(m_cct) << "failed listing children: " << cpp_strerror(r)
+                     << dendl;
+        return r;
+      }
+
+      size_t size = child_images.size();
+      if (size > 0) {
+        lderr(m_cct) << "image has snapshot '" << snap.name << "' with linked clones"
+                     << dendl;
+        return -EBUSY;
+      }
     }
   }