Skip to content

Commit

Permalink
rbd: move the detection of destination image ealier in rename op
Browse files Browse the repository at this point in the history
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 <zhiqiang.wang@intel.com>
  • Loading branch information
wonzhq committed Mar 23, 2015
1 parent ada7ec8 commit 27120d7
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/librbd/internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,17 @@ namespace librbd {
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 =
Expand Down Expand Up @@ -1250,17 +1261,6 @@ namespace librbd {
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);
Expand Down

0 comments on commit 27120d7

Please sign in to comment.