From: songweibin Date: Thu, 3 Jan 2019 07:38:54 +0000 (+0800) Subject: librbd: disallow migrating a parent image X-Git-Tag: v14.1.0~428^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d02c1f5e3ee97f77f91569e9267cf756b2f7e19f;p=ceph.git librbd: disallow migrating a parent image 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 --- diff --git a/src/librbd/api/Migration.cc b/src/librbd/api/Migration.cc index aad7c7394f1..b5cf4a06347 100644 --- a/src/librbd/api/Migration.cc +++ b/src/librbd/api/Migration.cc @@ -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::list_snaps(std::vector *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 child_images; + r = api::Image::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; + } } }