From 0551029242aa6cdac91165e390eb3e85fbb8d0ea Mon Sep 17 00:00:00 2001 From: songweibin Date: Thu, 18 Jan 2018 10:56:19 +0800 Subject: [PATCH] rbd: add deep cp CLI method Signed-off-by: songweibin --- doc/man/8/rbd.rst | 4 + qa/workunits/rbd/cli_generic.sh | 11 ++- qa/workunits/rbd/journal.sh | 24 ++++++ src/common/options.cc | 2 +- src/librbd/deep_copy/ObjectCopyRequest.cc | 2 +- src/librbd/deep_copy/SnapshotCopyRequest.cc | 4 +- src/test/cli/rbd/help.t | 48 ++++++++++++ src/test/cli/rbd/invalid-snap-usage.t | 6 ++ src/test/cli/rbd/not-enough-args.t | 9 +++ src/tools/rbd/action/Copy.cc | 81 +++++++++++++++++++++ 10 files changed, 187 insertions(+), 4 deletions(-) diff --git a/doc/man/8/rbd.rst b/doc/man/8/rbd.rst index edf09fdea43a9..3096d234e70f7 100644 --- a/doc/man/8/rbd.rst +++ b/doc/man/8/rbd.rst @@ -201,6 +201,10 @@ Commands Will create a new rbd image. You must also specify the size via --size. The --stripe-unit and --stripe-count arguments are optional, but must be used together. +:command:`deep cp` (*src-image-spec* | *src-snap-spec*) *dest-image-spec* + Deep copy the content of a src-image into the newly created dest-image. + Dest-image will have the same size, object size, image format, and snapshots as src-image. + :command:`diff` [--from-snap *snap-name*] [--whole-object] *image-spec* | *snap-spec* Dump a list of byte extents in the image that have changed since the specified start snapshot, or since the image was created. Each output line includes the starting offset diff --git a/qa/workunits/rbd/cli_generic.sh b/qa/workunits/rbd/cli_generic.sh index 5318f507c15c7..23fdbcbadcbb0 100755 --- a/qa/workunits/rbd/cli_generic.sh +++ b/qa/workunits/rbd/cli_generic.sh @@ -3,7 +3,7 @@ # make sure rbd pool is EMPTY.. this is a test script!! rbd ls | wc -l | grep -v '^0$' && echo "nonempty rbd pool, aborting! run this script on an empty test cluster only." && exit 1 -IMGS="testimg1 testimg2 testimg3 testimg-diff1 testimg-diff2 testimg-diff3 foo foo2 bar bar2 test1 test2 test3 clone2" +IMGS="testimg1 testimg2 testimg3 testimg4 testimg5 testimg6 testimg-diff1 testimg-diff2 testimg-diff3 foo foo2 bar bar2 test1 test2 test3 clone2" tiered=0 if ceph osd dump | grep ^pool | grep "'rbd'" | grep tier; then @@ -73,6 +73,14 @@ test_others() { rbd info testimg-diff2 | grep 'size 256 MB' rbd info testimg-diff3 | grep 'size 128 MB' + # deep copies + rbd deep copy testimg1 testimg4 + rbd deep copy testimg1 --snap=snap1 testimg5 + rbd info testimg4 | grep 'size 128 MB' + rbd info testimg5 | grep 'size 256 MB' + rbd snap ls testimg4 | grep -v 'SNAPID' | wc -l | grep 1 + rbd snap ls testimg4 | grep '.*snap1.*' + rbd export testimg1 /tmp/img1.new rbd export testimg2 /tmp/img2.new rbd export testimg3 /tmp/img3.new @@ -100,6 +108,7 @@ test_others() { rbd rm testimg3 rbd create testimg2 -s 0 rbd cp testimg2 testimg3 + rbd deep cp testimg2 testimg6 # remove snapshots rbd snap rm --snap=snap1 testimg1 diff --git a/qa/workunits/rbd/journal.sh b/qa/workunits/rbd/journal.sh index 02a8ebd8c13fc..157e7ad8af57c 100755 --- a/qa/workunits/rbd/journal.sh +++ b/qa/workunits/rbd/journal.sh @@ -172,6 +172,30 @@ test_rbd_copy() rbd remove ${image} } +test_rbd_deep_copy() +{ + local src=testrbdcopys$$ + rbd create --size 256 ${src} + rbd snap create ${src}@snap1 + + local dest=testrbdcopy$$ + rbd deep copy --image-feature exclusive-lock --image-feature journaling \ + --journal-pool rbd \ + --journal-object-size 20M \ + --journal-splay-width 6 \ + ${src} ${dest} + + rbd snap purge ${src} + rbd remove ${src} + + rbd_assert_eq ${dest} 'journal info' '//journal/order' 25 + rbd_assert_eq ${dest} 'journal info' '//journal/splay_width' 6 + rbd_assert_eq ${dest} 'journal info' '//journal/object_pool' rbd + + rbd snap purge ${dest} + rbd remove ${dest} +} + test_rbd_clone() { local parent=testrbdclonep$$ diff --git a/src/common/options.cc b/src/common/options.cc index 505cf277e7fae..2d8eccc73e3ce 100644 --- a/src/common/options.cc +++ b/src/common/options.cc @@ -5956,7 +5956,7 @@ static std::vector