]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: prevent import-diff if start snapshot is not already present
authorSage Weil <sage@inktank.com>
Fri, 29 Mar 2013 04:53:30 +0000 (21:53 -0700)
committerJosh Durgin <josh.durgin@inktank.com>
Mon, 1 Apr 2013 06:32:41 +0000 (23:32 -0700)
Signed-off-by: Sage Weil <sage@inktank.com>
qa/workunits/rbd/diff.sh
src/rbd.cc

index 8218ae28dab5311a053aa7042ad5bf9d94ee4582..48ab5bb223230754da5fdd4a439eca52c1ff8771 100755 (executable)
@@ -5,6 +5,8 @@ function cleanup() {
     rbd rm foo || :
     rbd snap purge foo.copy || :
     rbd rm foo.copy || :
+    rbd snap purge foo.copy2 || :
+    rbd rm foo.copy2 || :
     rm -f foo.diff foo.out
 }
 
@@ -30,6 +32,9 @@ rbd import-diff foo.diff foo.copy
 rbd import-diff foo.diff foo.copy && exit 1 || true   # this should fail with EEXIST on the end snap
 rbd snap ls foo.copy | grep three
 
+rbd create foo.copy2 --size 1000
+rbd import-diff foo.diff foo.copy2 && exit 1 || true   # this should fail bc the start snap dne
+
 rbd export foo foo.out
 orig=`md5sum foo.out | awk '{print $1}'`
 rm foo.out
index 23d9d045d9f03276ba06e29d020776ba631b06c3..988af06963055e244cee1adb38420408ed69433e 100644 (file)
@@ -1418,6 +1418,12 @@ static int do_import_diff(librbd::Image &image, const char *path)
       if (r < 0)
        goto done;
       dout(2) << " from snap " << from << dendl;
+
+      if (!image.snap_exists(from.c_str())) {
+       cerr << "start snapshot '" << from << "' does not exist in the image, aborting" << std::endl;
+       r = -EINVAL;
+       goto done;
+      }
     }
     else if (tag == 't') {
       r = read_string(fd, 4096, &to);   // 4k limit to make sure we don't get a garbage string