From: Sage Weil Date: Fri, 29 Mar 2013 04:53:30 +0000 (-0700) Subject: rbd: prevent import-diff if start snapshot is not already present X-Git-Tag: v0.62~118^2~21 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f67f62abab2816e87a8526ed5c726920fac5d641;p=ceph.git rbd: prevent import-diff if start snapshot is not already present Signed-off-by: Sage Weil --- diff --git a/qa/workunits/rbd/diff.sh b/qa/workunits/rbd/diff.sh index 8218ae28dab5..48ab5bb22323 100755 --- a/qa/workunits/rbd/diff.sh +++ b/qa/workunits/rbd/diff.sh @@ -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 diff --git a/src/rbd.cc b/src/rbd.cc index 23d9d045d9f0..988af0696305 100644 --- a/src/rbd.cc +++ b/src/rbd.cc @@ -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