From 084f22ce15eb200e859ba03a76636bf78d9eeba3 Mon Sep 17 00:00:00 2001 From: xiexingguo Date: Sat, 19 Dec 2015 14:53:47 +0800 Subject: [PATCH] tools: replace snap_exists with a new safer version Signed-off-by: xie xingguo --- src/tools/rbd/action/ImportDiff.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/tools/rbd/action/ImportDiff.cc b/src/tools/rbd/action/ImportDiff.cc index 9f600f8285d8d..21a817cbbe652 100644 --- a/src/tools/rbd/action/ImportDiff.cc +++ b/src/tools/rbd/action/ImportDiff.cc @@ -74,7 +74,12 @@ static int do_import_diff(librbd::Image &image, const char *path, goto done; dout(2) << " from snap " << from << dendl; - if (!image.snap_exists(from.c_str())) { + bool exists; + r = image.snap_exists2(from.c_str(), &exists); + if (r < 0) + goto done; + + if (!exists) { std::cerr << "start snapshot '" << from << "' does not exist in the image, aborting" << std::endl; r = -EINVAL; @@ -88,7 +93,12 @@ static int do_import_diff(librbd::Image &image, const char *path, dout(2) << " to snap " << to << dendl; // verify this snap isn't already present - if (image.snap_exists(to.c_str())) { + bool exists; + r = image.snap_exists2(to.c_str(), &exists); + if (r < 0) + goto done; + + if (exists) { std::cerr << "end snapshot '" << to << "' already exists, aborting" << std::endl; r = -EEXIST; -- 2.39.5