From 27120d703051371068e7e1bcdcb49c52d78d6789 Mon Sep 17 00:00:00 2001 From: Zhiqiang Wang Date: Fri, 20 Mar 2015 16:26:29 +0800 Subject: [PATCH] rbd: move the detection of destination image ealier in rename op Return earlier to avoid extra work of reading image data and omap if the detection fails or the destination image already exists. Signed-off-by: Zhiqiang Wang --- src/librbd/internal.cc | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc index 714c3b3ef381..2f1d8ca80943 100644 --- a/src/librbd/internal.cc +++ b/src/librbd/internal.cc @@ -1212,6 +1212,17 @@ reprotect_and_return_err: return r; } + r = detect_format(io_ctx, dstname, NULL, NULL); + if (r < 0 && r != -ENOENT) { + lderr(cct) << "error checking for existing image called " + << dstname << ":" << cpp_strerror(r) << dendl; + return r; + } + if (r == 0) { + lderr(cct) << "rbd image " << dstname << " already exists" << dendl; + return -EEXIST; + } + string src_oid = old_format ? old_header_name(srcname) : id_obj_name(srcname); string dst_oid = @@ -1250,17 +1261,6 @@ reprotect_and_return_err: last_read = outbl.rbegin()->first; } while (r == MAX_READ); - r = detect_format(io_ctx, dstname, NULL, NULL); - if (r < 0 && r != -ENOENT) { - lderr(cct) << "error checking for existing image called " - << dstname << ":" << cpp_strerror(r) << dendl; - return r; - } - if (r == 0) { - lderr(cct) << "rbd image " << dstname << " already exists" << dendl; - return -EEXIST; - } - librados::ObjectWriteOperation op; op.create(true); op.write_full(databl); -- 2.47.3