CEPH_RBD_API int rbd_group_snap_remove(rados_ioctx_t group_p,
const char *group_name,
const char *snap_name);
+CEPH_RBD_API int rbd_group_snap_rename(rados_ioctx_t group_p,
+ const char *group_name,
+ const char *old_snap_name,
+ const char *new_snap_name);
CEPH_RBD_API int rbd_group_snap_list(rados_ioctx_t group_p,
const char *group_name,
rbd_group_snap_spec_t *snaps,
const char *snap_name);
int group_snap_remove(IoCtx& io_ctx, const char *group_name,
const char *snap_name);
+ int group_snap_rename(IoCtx& group_ioctx, const char *group_name,
+ const char *old_snap_name, const char *new_snap_name);
int group_snap_list(IoCtx& group_ioctx, const char *group_name,
std::vector<group_snap_spec_t> *snaps);
<< dendl;
return r;
}
+
std::vector<cls::rbd::GroupSnapshot> snaps;
r = group_snap_list(group_ioctx, group_name, &snaps);
if (r < 0) {
return r;
}
+template <typename I>
+int Group<I>::snap_rename(librados::IoCtx& group_ioctx, const char *group_name,
+ const char *old_snap_name,
+ const char *new_snap_name) {
+ CephContext *cct = (CephContext *)group_ioctx.cct();
+
+ std::string group_id;
+ int r = cls_client::dir_get_id(&group_ioctx, RBD_GROUP_DIRECTORY,
+ group_name, &group_id);
+ if (r == -ENOENT) {
+ return r;
+ } else if (r < 0) {
+ lderr(cct) << "error reading group id object: " << cpp_strerror(r) << dendl;
+ return r;
+ }
+
+ std::vector<cls::rbd::GroupSnapshot> group_snaps;
+ r = group_snap_list(group_ioctx, group_name, &group_snaps);
+ if (r < 0) {
+ return r;
+ }
+
+ cls::rbd::GroupSnapshot group_snap;
+ for (auto &snap : group_snaps) {
+ if (snap.name == old_snap_name) {
+ group_snap = snap;
+ break;
+ }
+ }
+
+ if (group_snap.id.empty()) {
+ return -ENOENT;
+ }
+
+ std::string group_header_oid = util::group_header_name(group_id);
+ group_snap.name = new_snap_name;
+ r = cls_client::group_snap_set(&group_ioctx, group_header_oid, group_snap);
+ if (r < 0) {
+ return r;
+ }
+
+ return 0;
+}
+
template <typename I>
int Group<I>::snap_list(librados::IoCtx& group_ioctx, const char *group_name,
std::vector<group_snap_spec_t> *snaps)
static int image_get_group(ImageCtxT *ictx, group_spec_t *group_spec);
static int snap_create(librados::IoCtx& group_ioctx,
- const char *group_name, const char *snap_name);
+ const char *group_name, const char *snap_name);
static int snap_remove(librados::IoCtx& group_ioctx,
- const char *group_name, const char *snap_name);
+ const char *group_name, const char *snap_name);
+ static int snap_rename(librados::IoCtx& group_ioctx, const char *group_name,
+ const char *old_snap_name, const char *new_snap_name);
static int snap_list(librados::IoCtx& group_ioctx, const char *group_name,
- std::vector<group_snap_spec_t> *snaps);
+ std::vector<group_snap_spec_t> *snaps);
};
return r;
}
+ int RBD::group_snap_rename(IoCtx& group_ioctx, const char *group_name,
+ const char *old_snap_name,
+ const char *new_snap_name)
+ {
+ TracepointProvider::initialize<tracepoint_traits>(get_cct(group_ioctx));
+ tracepoint(librbd, group_snap_rename_enter,
+ group_ioctx.get_pool_name().c_str(), group_ioctx.get_id(),
+ group_name, old_snap_name, new_snap_name);
+ int r = librbd::api::Group<>::snap_rename(group_ioctx, group_name,
+ old_snap_name, new_snap_name);
+ tracepoint(librbd, group_snap_list_exit, r);
+ return r;
+ }
+
RBD::AioCompletion::AioCompletion(void *cb_arg, callback_t complete_cb)
{
return r;
}
+extern "C" int rbd_group_snap_rename(rados_ioctx_t group_p,
+ const char *group_name,
+ const char *old_snap_name,
+ const char *new_snap_name)
+{
+ librados::IoCtx group_ioctx;
+ librados::IoCtx::from_rados_ioctx_t(group_p, group_ioctx);
+
+ TracepointProvider::initialize<tracepoint_traits>(get_cct(group_ioctx));
+ tracepoint(librbd, group_snap_rename_enter,
+ group_ioctx.get_pool_name().c_str(), group_ioctx.get_id(),
+ group_name, old_snap_name, new_snap_name);
+
+ int r = librbd::api::Group<>::snap_rename(group_ioctx, group_name,
+ old_snap_name, new_snap_name);
+
+ tracepoint(librbd, group_snap_list_exit, r);
+ return r;
+}
+
extern "C" int rbd_group_snap_list(rados_ioctx_t group_p, const char *group_name,
rbd_group_snap_spec_t *snaps, size_t *snaps_size)
{
int rbd_group_snap_remove(rados_ioctx_t group_p, const char *group_name,
const char *snap_name)
+ int rbd_group_snap_rename(rados_ioctx_t group_p, const char *group_name,
+ const char *old_snap_name,
+ const char *new_snap_name)
+
int rbd_group_snap_list(rados_ioctx_t group_p,
const char *group_name,
rbd_group_snap_spec_t *snaps,
if ret != 0:
raise make_ex(ret, 'error removing group snapshot', group_errno_to_exception)
+ def rename_snap(self, old_snap_name, new_snap_name):
+ """
+ Rename group's snapshot.
+
+ :raises: :class:`ObjectNotFound`
+ :raises: :class:`ObjectExists`
+ :raises: :class:`InvalidArgument`
+ :raises: :class:`FunctionNotSupported`
+ """
+
+ old_snap_name = cstr(old_snap_name, 'old_snap_name')
+ new_snap_name = cstr(new_snap_name, 'new_snap_name')
+ cdef:
+ char *_old_snap_name = old_snap_name
+ char *_new_snap_name = new_snap_name
+ with nogil:
+ ret = rbd_group_snap_rename(self._ioctx, self._name, _old_snap_name,
+ _new_snap_name)
+ if ret != 0:
+ raise make_ex(ret, 'error removing group snapshot',
+ group_errno_to_exception)
+
def list_snaps(self):
"""
Iterate over the images of a group.
self.group.remove_snap(snap_name)
eq([], list(self.group.list_snaps()))
+ def test_group_snap_rename(self):
+ global snap_name
+ new_snap_name = "new" + snap_name
+
+ eq([], list(self.group.list_snaps()))
+ self.group.create_snap(snap_name)
+ eq([snap_name], [snap['name'] for snap in self.group.list_snaps()])
+ self.group.rename_snap(snap_name, new_snap_name)
+ eq([new_snap_name], [snap['name'] for snap in self.group.list_snaps()])
+
@with_setup(create_image, remove_image)
def test_rename():
rbd = RBD()
)
)
+TRACEPOINT_EVENT(librbd, group_snap_rename_enter,
+ TP_ARGS(
+ const char*, pool_name,
+ int64_t, id,
+ const char*, group_name,
+ const char*, old_snap_name,
+ const char*, new_snap_name),
+ TP_FIELDS(
+ ctf_string(pool_name, pool_name)
+ ctf_integer(int64_t, id, id)
+ ctf_string(group_name, group_name)
+ ctf_string(old_snap_name, old_snap_name)
+ ctf_string(new_snap_name, new_snap_name)
+ )
+)
+
+TRACEPOINT_EVENT(librbd, group_snap_rename_exit,
+ TP_ARGS(
+ int, retval),
+ TP_FIELDS(
+ ctf_integer(int, retval, retval)
+ )
+)
+
TRACEPOINT_EVENT(librbd, group_snap_list_enter,
TP_ARGS(
const char*, pool_name,