librbd: added group image remove by id to API

Signed-off-by: Ricardo Dias <rdias@suse.com>
This commit is contained in:
Ricardo Dias 2017-04-10 14:26:21 +01:00
parent 0a25ea0036
commit 9438ee9353
No known key found for this signature in database
GPG Key ID: 74390C579BD37B68
6 changed files with 100 additions and 11 deletions

View File

@ -827,6 +827,9 @@ CEPH_RBD_API int rbd_group_image_add(
CEPH_RBD_API int rbd_group_image_remove(
rados_ioctx_t group_p, const char *group_name,
rados_ioctx_t image_p, const char *image_name);
CEPH_RBD_API int rbd_group_image_remove_by_id(
rados_ioctx_t group_p, const char *group_name,
rados_ioctx_t image_p, const char *image_id);
CEPH_RBD_API int rbd_group_image_list(
rados_ioctx_t group_p, const char *group_name,
rbd_group_image_status_t *images,

View File

@ -193,6 +193,8 @@ public:
IoCtx& image_io_ctx, const char *image_name);
int group_image_remove(IoCtx& io_ctx, const char *group_name,
IoCtx& image_io_ctx, const char *image_name);
int group_image_remove_by_id(IoCtx& io_ctx, const char *group_name,
IoCtx& image_io_ctx, const char *image_id);
int group_image_list(IoCtx& io_ctx, const char *group_name,
std::vector<group_image_status_t> *images);

View File

@ -235,6 +235,30 @@ int Group<I>::image_remove(librados::IoCtx& group_ioctx, const char *group_name,
<< " group name " << group_name << " image "
<< &image_ioctx << " name " << image_name << dendl;
string image_id;
int r = cls_client::dir_get_id(&image_ioctx, RBD_DIRECTORY, image_name,
&image_id);
if (r < 0) {
lderr(cct) << "error reading image id object: "
<< cpp_strerror(-r) << dendl;
return r;
}
return Group<I>::image_remove_by_id(group_ioctx, group_name, image_ioctx,
image_id.c_str());
}
template <typename I>
int Group<I>::image_remove_by_id(librados::IoCtx& group_ioctx,
const char *group_name,
librados::IoCtx& image_ioctx,
const char *image_id)
{
CephContext *cct = (CephContext *)group_ioctx.cct();
ldout(cct, 20) << "group_remove_image_by_id " << &group_ioctx
<< " group name " << group_name << " image "
<< &image_ioctx << " id " << image_id << dendl;
string group_id;
int r = cls_client::dir_get_id(&group_ioctx, RBD_GROUP_DIRECTORY, group_name,
@ -250,19 +274,9 @@ int Group<I>::image_remove(librados::IoCtx& group_ioctx, const char *group_name,
ldout(cct, 20) << "adding image to group name " << group_name
<< " group id " << group_header_oid << dendl;
string image_id;
r = cls_client::dir_get_id(&image_ioctx, RBD_DIRECTORY, image_name,
&image_id);
if (r < 0) {
lderr(cct) << "error reading image id object: "
<< cpp_strerror(-r) << dendl;
return r;
}
string image_header_oid = util::header_name(image_id);
ldout(cct, 20) << "removing image " << image_name
<< " image id " << image_header_oid << dendl;
ldout(cct, 20) << "removing " << " image id " << image_header_oid << dendl;
cls::rbd::GroupSpec group_spec(group_id, group_ioctx.get_id());

View File

@ -27,6 +27,10 @@ struct Group {
librados::IoCtx& image_ioctx, const char *image_name);
static int image_remove(librados::IoCtx& group_ioctx, const char *group_name,
librados::IoCtx& image_ioctx, const char *image_name);
static int image_remove_by_id(librados::IoCtx& group_ioctx,
const char *group_name,
librados::IoCtx& image_ioctx,
const char *image_id);
static int image_list(librados::IoCtx& group_ioctx, const char *group_name,
std::vector<group_image_status_t> *images);

View File

@ -723,6 +723,21 @@ namespace librbd {
return r;
}
int RBD::group_image_remove_by_id(IoCtx& group_ioctx, const char *group_name,
IoCtx& image_ioctx, const char *image_id)
{
TracepointProvider::initialize<tracepoint_traits>(get_cct(group_ioctx));
tracepoint(librbd, group_image_remove_by_id_enter,
group_ioctx.get_pool_name().c_str(),
group_ioctx.get_id(), group_name,
image_ioctx.get_pool_name().c_str(),
image_ioctx.get_id(), image_id);
int r = librbd::api::Group<>::image_remove_by_id(group_ioctx, group_name,
image_ioctx, image_id);
tracepoint(librbd, group_image_remove_by_id_exit, r);
return r;
}
int RBD::group_image_list(IoCtx& group_ioctx, const char *group_name,
std::vector<group_image_status_t> *images)
{
@ -4037,6 +4052,31 @@ extern "C" int rbd_group_image_remove(
return r;
}
extern "C" int rbd_group_image_remove_by_id(rados_ioctx_t group_p,
const char *group_name,
rados_ioctx_t image_p,
const char *image_id)
{
librados::IoCtx group_ioctx;
librados::IoCtx image_ioctx;
librados::IoCtx::from_rados_ioctx_t(group_p, group_ioctx);
librados::IoCtx::from_rados_ioctx_t(image_p, image_ioctx);
TracepointProvider::initialize<tracepoint_traits>(get_cct(group_ioctx));
tracepoint(librbd, group_image_remove_by_id_enter,
group_ioctx.get_pool_name().c_str(),
group_ioctx.get_id(), group_name,
image_ioctx.get_pool_name().c_str(),
image_ioctx.get_id(), image_id);
int r = librbd::api::Group<>::image_remove_by_id(group_ioctx, group_name,
image_ioctx, image_id);
tracepoint(librbd, group_image_remove_by_id_exit, r);
return r;
}
extern "C" int rbd_group_image_list(rados_ioctx_t group_p,
const char *group_name,
rbd_group_image_status_t *images,

View File

@ -2350,6 +2350,32 @@ TRACEPOINT_EVENT(librbd, group_image_remove_exit,
)
)
TRACEPOINT_EVENT(librbd, group_image_remove_by_id_enter,
TP_ARGS(
const char*, pool_name,
int64_t, id,
const char*, group_name,
const char*, image_pool_name,
int64_t, image_ioctx_id,
const char*, image_id),
TP_FIELDS(
ctf_string(pool_name, pool_name)
ctf_integer(int64_t, id, id)
ctf_string(group_name, group_name)
ctf_string(image_pool_name, image_pool_name)
ctf_integer(int64_t, image_ioctx_id, image_ioctx_id)
ctf_string(image_id, image_id)
)
)
TRACEPOINT_EVENT(librbd, group_image_remove_by_id_exit,
TP_ARGS(
int, retval),
TP_FIELDS(
ctf_integer(int, retval, retval)
)
)
TRACEPOINT_EVENT(librbd, group_image_list_enter,
TP_ARGS(
const char*, pool_name,