if (r < 0) {
lderr(cct) << "error opening image: "
<< cpp_strerror(r) << dendl;
- delete imctx;
return r;
}
+
librbd::NoOpProgressContext prog_ctx;
r = imctx->operations->flatten(prog_ctx);
if (r < 0) {
return r;
}
}
- imctx->state->close();
+
+ r = imctx->state->close();
+ if (r < 0) {
+ lderr(cct) << "failed to close image: " << cpp_strerror(r) << dendl;
+ return r;
+ }
}
pctx.update_progress(++i, size);
assert(i <= size);
if (r < 0) {
lderr(cct) << "error opening parent image: "
<< cpp_strerror(r) << dendl;
- delete p_imctx;
return r;
}
r = c_imctx->state->open(false);
if (r < 0) {
lderr(cct) << "Error opening new image: " << cpp_strerror(r) << dendl;
- delete c_imctx;
goto err_remove;
}
if (r < 0) {
lderr(ictx->cct) << "error opening source image: " << cpp_strerror(r)
<< dendl;
- delete ictx;
return r;
}
BOOST_SCOPE_EXIT((ictx)) {
dest_md_ctx, false);
r = dest->state->open(false);
if (r < 0) {
- delete dest;
lderr(cct) << "failed to read newly created header" << dendl;
return r;
}
if (r < 0) {
lderr(cct) << "error opening image "<< img_pair.first << ": "
<< cpp_strerror(r) << dendl;
- delete img_ctx;
return r;
}
if (r < 0) {
lderr(cct) << "error opening image id "<< img_id << ": "
<< cpp_strerror(r) << dendl;
- delete img_ctx;
return r;
}
r = mirror_image_disable(img_ctx, false);
+ int close_r = img_ctx->state->close();
if (r < 0) {
lderr(cct) << "error disabling mirroring for image id " << img_id
<< cpp_strerror(r) << dendl;
return r;
- }
-
- r = img_ctx->state->close();
- if (r < 0) {
+ } else if (close_r < 0) {
lderr(cct) << "failed to close image id " << img_id << ": "
- << cpp_strerror(r) << dendl;
- return r;
+ << cpp_strerror(close_r) << dendl;
+ return close_r;
}
}
}
void **ictxp;
bool reopen;
C_OpenComplete(librbd::ImageCtx *ictx, librbd::io::AioCompletion* comp,
- void **ictxp, bool reopen = false)
- : ictx(ictx), comp(comp), ictxp(ictxp), reopen(reopen) {
+ void **ictxp)
+ : ictx(ictx), comp(comp), ictxp(ictxp) {
comp->init_time(ictx, librbd::io::AIO_TYPE_OPEN);
comp->get();
}
void finish(int r) override {
ldout(ictx->cct, 20) << "C_OpenComplete::finish: r=" << r << dendl;
- if (reopen) {
- delete reinterpret_cast<librbd::ImageCtx*>(*ictxp);
- }
if (r < 0) {
*ictxp = nullptr;
comp->fail(r);
void finish(int r) override {
ldout(ictx->cct, 20) << "C_OpenAfterCloseComplete::finish: r=" << r
<< dendl;
- ictx->state->open(false, new C_OpenComplete(ictx, comp, ictxp, true));
+ delete reinterpret_cast<librbd::ImageCtx*>(*ictxp);
+ *ictxp = nullptr;
+
+ ictx->state->open(false, new C_OpenComplete(ictx, comp, ictxp));
}
};
int r = ictx->state->open(false);
if (r < 0) {
- delete ictx;
tracepoint(librbd, open_image_exit, r);
return r;
}
int r = ictx->state->open(false);
if (r < 0) {
- delete ictx;
tracepoint(librbd, open_image_exit, r);
return r;
}
tracepoint(librbd, open_image_enter, ictx, ictx->name.c_str(), ictx->id.c_str(), ictx->snap_name.c_str(), ictx->read_only);
int r = ictx->state->open(false);
- if (r < 0) {
- delete ictx;
- } else {
+ if (r >= 0) {
*image = (rbd_image_t)ictx;
}
tracepoint(librbd, open_image_exit, r);
tracepoint(librbd, open_image_enter, ictx, ictx->name.c_str(), ictx->id.c_str(), ictx->snap_name.c_str(), ictx->read_only);
int r = ictx->state->open(false);
- if (r < 0) {
- delete ictx;
- } else {
+ if (r >= 0) {
*image = (rbd_image_t)ictx;
}
tracepoint(librbd, open_image_exit, r);
librbd::ImageCtx *ictx = new librbd::ImageCtx(image_name, "", "", io_ctx, false);
int r = ictx->state->open(false);
if (r < 0) {
- delete ictx;
tracepoint(librbd, open_image_exit, r);
return r;
}