From: Zhiqiang Wang Date: Fri, 20 Mar 2015 08:26:29 +0000 (+0800) Subject: rbd: move the detection of destination image ealier in rename op X-Git-Tag: v9.0.0~82^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F4113%2Fhead;p=ceph.git 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 --- diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc index 714c3b3ef38..2f1d8ca8094 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);