err_close_child:
c_imctx->state->close();
err_remove:
- partial_r = remove(c_ioctx, c_name, no_op);
+ partial_r = remove(c_ioctx, c_name, "", no_op);
if (partial_r < 0) {
lderr(cct) << "Error removing failed clone: "
<< cpp_strerror(partial_r) << dendl;
return 0;
}
- int remove(IoCtx& io_ctx, const char *imgname, ProgressContext& prog_ctx,
+ int remove(IoCtx& io_ctx, const std::string &image_name,
+ const std::string &image_id, ProgressContext& prog_ctx,
bool force)
{
CephContext *cct((CephContext *)io_ctx.cct());
- ldout(cct, 20) << "remove " << &io_ctx << " " << imgname << dendl;
+ ldout(cct, 20) << "remove " << &io_ctx << " "
+ << (image_id.empty() ? image_name : image_id) << dendl;
- string id;
+ std::string name(image_name);
+ std::string id(image_id);
bool old_format = false;
bool unknown_format = true;
- ImageCtx *ictx = new ImageCtx(imgname, "", NULL, io_ctx, false);
+ ImageCtx *ictx = new ImageCtx(
+ (id.empty() ? name : std::string()), id, nullptr, io_ctx, false);
int r = ictx->state->open();
if (r < 0) {
ldout(cct, 2) << "error opening image: " << cpp_strerror(-r) << dendl;
string header_oid = ictx->header_oid;
old_format = ictx->old_format;
unknown_format = false;
+ name = ictx->name;
id = ictx->id;
ictx->owner_lock.get_read();
if (old_format || unknown_format) {
ldout(cct, 2) << "removing rbd image from v1 directory..." << dendl;
- r = tmap_rm(io_ctx, imgname);
+ r = tmap_rm(io_ctx, name);
old_format = (r == 0);
if (r < 0 && !unknown_format) {
if (r != -ENOENT) {
if (!old_format) {
if (id.empty()) {
ldout(cct, 5) << "attempting to determine image id" << dendl;
- r = cls_client::dir_get_id(&io_ctx, RBD_DIRECTORY, imgname, &id);
+ r = cls_client::dir_get_id(&io_ctx, RBD_DIRECTORY, name, &id);
if (r < 0 && r != -ENOENT) {
lderr(cct) << "error getting id of image" << dendl;
return r;
}
+ } else if (name.empty()) {
+ ldout(cct, 5) << "attempting to determine image name" << dendl;
+ r = cls_client::dir_get_name(&io_ctx, RBD_DIRECTORY, id, &name);
+ if (r < 0 && r != -ENOENT) {
+ lderr(cct) << "error getting name of image" << dendl;
+ return r;
+ }
}
+
if (!id.empty()) {
ldout(cct, 10) << "removing journal..." << dendl;
r = Journal<>::remove(io_ctx, id);
}
ldout(cct, 2) << "removing id object..." << dendl;
- r = io_ctx.remove(util::id_obj_name(imgname));
+ r = io_ctx.remove(util::id_obj_name(name));
if (r < 0 && r != -ENOENT) {
lderr(cct) << "error removing id object: " << cpp_strerror(r)
<< dendl;
}
ldout(cct, 2) << "removing rbd image from v2 directory..." << dendl;
- r = cls_client::dir_remove_image(&io_ctx, RBD_DIRECTORY, imgname, id);
+ r = cls_client::dir_remove_image(&io_ctx, RBD_DIRECTORY, name, id);
if (r < 0) {
if (r != -ENOENT) {
lderr(cct) << "error removing image from v2 directory: "
int set_image_notification(ImageCtx *ictx, int fd, int type);
int is_exclusive_lock_owner(ImageCtx *ictx, bool *is_owner);
- int remove(librados::IoCtx& io_ctx, const char *imgname,
- ProgressContext& prog_ctx, bool force=false);
+ int remove(librados::IoCtx& io_ctx, const std::string &image_name,
+ const std::string &image_id, ProgressContext& prog_ctx,
+ bool force=false);
int snap_list(ImageCtx *ictx, std::vector<snap_info_t>& snaps);
int snap_exists(ImageCtx *ictx, const char *snap_name, bool *exists);
int snap_get_limit(ImageCtx *ictx, uint64_t *limit);
TracepointProvider::initialize<tracepoint_traits>(get_cct(io_ctx));
tracepoint(librbd, remove_enter, io_ctx.get_pool_name().c_str(), io_ctx.get_id(), name);
librbd::NoOpProgressContext prog_ctx;
- int r = librbd::remove(io_ctx, name, prog_ctx);
+ int r = librbd::remove(io_ctx, name, "", prog_ctx);
tracepoint(librbd, remove_exit, r);
return r;
}
{
TracepointProvider::initialize<tracepoint_traits>(get_cct(io_ctx));
tracepoint(librbd, remove_enter, io_ctx.get_pool_name().c_str(), io_ctx.get_id(), name);
- int r = librbd::remove(io_ctx, name, pctx);
+ int r = librbd::remove(io_ctx, name, "", pctx);
tracepoint(librbd, remove_exit, r);
return r;
}
TracepointProvider::initialize<tracepoint_traits>(get_cct(io_ctx));
tracepoint(librbd, remove_enter, io_ctx.get_pool_name().c_str(), io_ctx.get_id(), name);
librbd::NoOpProgressContext prog_ctx;
- int r = librbd::remove(io_ctx, name, prog_ctx);
+ int r = librbd::remove(io_ctx, name, "", prog_ctx);
tracepoint(librbd, remove_exit, r);
return r;
}
TracepointProvider::initialize<tracepoint_traits>(get_cct(io_ctx));
tracepoint(librbd, remove_enter, io_ctx.get_pool_name().c_str(), io_ctx.get_id(), name);
librbd::CProgressContext prog_ctx(cb, cbdata);
- int r = librbd::remove(io_ctx, name, prog_ctx);
+ int r = librbd::remove(io_ctx, name, "", prog_ctx);
tracepoint(librbd, remove_exit, r);
return r;
}
}
librbd::NoOpProgressContext no_op;
- ASSERT_EQ(0, librbd::remove(m_ioctx, clone_name.c_str(), no_op));
+ ASSERT_EQ(0, librbd::remove(m_ioctx, clone_name, "", no_op));
ASSERT_EQ(0, ictx->operations->snap_unprotect("snap"));
};
parent->unlock_image();
}
librbd::NoOpProgressContext no_op;
- ASSERT_EQ(0, librbd::remove(m_ioctx, clone_name.c_str(), no_op));
+ ASSERT_EQ(0, librbd::remove(m_ioctx, clone_name, "", no_op));
} BOOST_SCOPE_EXIT_END;
ASSERT_EQ(0, open_image(clone_name, &ictx2));
}
librbd::NoOpProgressContext remove_no_op;
- ASSERT_EQ(0, librbd::remove(m_ioctx, clone_name.c_str(), remove_no_op));
+ ASSERT_EQ(0, librbd::remove(m_ioctx, clone_name, "", remove_no_op));
} BOOST_SCOPE_EXIT_END;
ASSERT_EQ(0, open_image(clone_name, &ictx2));
read_bl.c_str(), 0));
ASSERT_TRUE(bl.contents_equal(read_bl));
}
+
+TEST_F(TestInternal, RemoveById) {
+ REQUIRE_FEATURE(RBD_FEATURE_LAYERING);
+
+ librbd::ImageCtx *ictx;
+ ASSERT_EQ(0, open_image(m_image_name, &ictx));
+
+ std::string image_id = ictx->id;
+ close_image(ictx);
+
+ librbd::NoOpProgressContext remove_no_op;
+ ASSERT_EQ(0, librbd::remove(m_ioctx, "", image_id, remove_no_op));
+}
promote_image();
}
NoOpProgressContext ctx;
- int r = remove(m_local_io_ctx, m_image_name.c_str(), ctx, force);
+ int r = remove(m_local_io_ctx, m_image_name, "", ctx, force);
EXPECT_EQ(1, r == 0 || r == -ENOENT);
}
}
librbd::NoOpProgressContext ctx;
- r = librbd::remove(ioctx, m_active_delete->local_image_name.c_str(), ctx,
- true);
+ r = librbd::remove(ioctx, "", m_active_delete->local_image_id, ctx, true);
if (r < 0 && r != -ENOENT) {
derr << "error removing image " << m_active_delete->local_image_name
<< " from local pool: " << cpp_strerror(r) << dendl;