From f67f62abab2816e87a8526ed5c726920fac5d641 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 28 Mar 2013 21:53:30 -0700 Subject: [PATCH] rbd: prevent import-diff if start snapshot is not already present Signed-off-by: Sage Weil --- qa/workunits/rbd/diff.sh | 5 +++++ src/rbd.cc | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/qa/workunits/rbd/diff.sh b/qa/workunits/rbd/diff.sh index 8218ae28dab53..48ab5bb223230 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 23d9d045d9f03..988af06963055 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 -- 2.39.5