bool up;
} rbd_mirror_image_status_t;
-typedef enum {
- GROUP_IMAGE_STATE_ATTACHED,
- GROUP_IMAGE_STATE_INCOMPLETE
-} rbd_group_image_state_t;
-
-typedef struct {
- char *name;
- int64_t pool;
-} rbd_group_image_spec_t;
-
-typedef struct {
- rbd_group_image_spec_t spec;
- rbd_group_image_state_t state;
-} rbd_group_image_status_t;
-
-typedef struct {
- char *name;
- int64_t pool;
-} rbd_group_spec_t;
-
typedef enum {
RBD_LOCK_MODE_EXCLUSIVE = 0,
RBD_LOCK_MODE_SHARED = 1,
rbd_mirror_image_status_t *mirror_image_status,
size_t status_size);
-// RBD consistency groups support functions
-CEPH_RBD_API int rbd_group_create(rados_ioctx_t p, const char *name);
-CEPH_RBD_API int rbd_group_remove(rados_ioctx_t p, const char *name);
-CEPH_RBD_API int rbd_group_list(rados_ioctx_t p, char *names, size_t *size);
-
/**
* Register an image metadata change watcher.
*
*/
CEPH_RBD_API int rbd_update_unwatch(rbd_image_t image, uint64_t handle);
-
-CEPH_RBD_API int rbd_group_image_add(
- 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(
- 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_list(
- rados_ioctx_t group_p, const char *group_name,
- rbd_group_image_status_t *images,
- size_t *image_size);
-CEPH_RBD_API int rbd_image_get_group(rados_ioctx_t image_p,
- const char *image_name,
- rbd_group_spec_t *group_spec);
-CEPH_RBD_API void rbd_group_spec_cleanup(rbd_group_spec_t *group_spec);
-CEPH_RBD_API void rbd_group_image_status_cleanup(
- rbd_group_image_status_t *image
- );
-CEPH_RBD_API void rbd_group_image_status_list_cleanup(
- rbd_group_image_status_t *images,
- size_t len);
#ifdef __cplusplus
}
#endif
bool up;
} mirror_image_status_t;
- typedef rbd_group_image_state_t group_image_state_t;
-
- typedef struct {
- std::string name;
- int64_t pool;
- group_image_state_t state;
- } group_image_status_t;
-
- typedef struct {
- std::string name;
- int64_t pool;
- } group_spec_t;
-
typedef rbd_image_info_t image_info_t;
class CEPH_RBD_API ProgressContext
int mirror_image_status_summary(IoCtx& io_ctx,
std::map<mirror_image_status_state_t, int> *states);
- // RBD consistency groups support functions
- int group_create(IoCtx& io_ctx, const char *group_name);
- int group_remove(IoCtx& io_ctx, const char *group_name);
- int group_list(IoCtx& io_ctx, std::vector<std::string> *names);
-
- int group_image_add(IoCtx& io_ctx, const char *group_name,
- 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_list(IoCtx& io_ctx, const char *group_name,
- std::vector<group_image_status_t> *images);
-
private:
/* We don't allow assignment or copying */
RBD(const RBD& rhs);
std::string *parent_snapname);
int old_format(uint8_t *old);
int size(uint64_t *size);
- int get_group(group_spec_t *group_spec);
int features(uint64_t *features);
int update_features(uint64_t features, bool enabled);
int overlap(uint64_t *overlap);
namespace librbd {
+typedef enum {
+ GROUP_IMAGE_STATE_ATTACHED,
+ GROUP_IMAGE_STATE_INCOMPLETE
+} group_image_state_t;
+
+typedef struct {
+ std::string name;
+ int64_t pool;
+ group_image_state_t state;
+} group_image_status_t;
+
+typedef struct {
+ std::string name;
+ int64_t pool;
+} group_spec_t;
+
// Consistency groups functions
int group_create(librados::IoCtx& io_ctx, const char *imgname);
int group_remove(librados::IoCtx& io_ctx, const char *group_name);
}
};
-void group_image_status_cpp_to_c(const librbd::group_image_status_t &cpp_status,
- rbd_group_image_status_t *c_status) {
- c_status->spec.name = strdup(cpp_status.name.c_str());
- c_status->spec.pool = cpp_status.pool;
- c_status->state = cpp_status.state;
-}
-
-void group_spec_cpp_to_c(const librbd::group_spec_t &cpp_spec,
- rbd_group_spec_t *c_spec) {
- c_spec->name = strdup(cpp_spec.name.c_str());
- c_spec->pool = cpp_spec.pool;
-}
-
void mirror_image_info_cpp_to_c(const librbd::mirror_image_info_t &cpp_info,
rbd_mirror_image_info_t *c_info) {
c_info->global_id = strdup(cpp_info.global_id.c_str());
return librbd::mirror_image_status_summary(io_ctx, states);
}
- int RBD::group_create(IoCtx& io_ctx, const char *group_name)
- {
- TracepointProvider::initialize<tracepoint_traits>(get_cct(io_ctx));
- tracepoint(librbd, group_create_enter, io_ctx.get_pool_name().c_str(),
- io_ctx.get_id(), group_name);
- int r = librbd::group_create(io_ctx, group_name);
- tracepoint(librbd, group_create_exit, r);
- return r;
- }
-
- int RBD::group_remove(IoCtx& io_ctx, const char *group_name)
- {
- TracepointProvider::initialize<tracepoint_traits>(get_cct(io_ctx));
- tracepoint(librbd, group_remove_enter, io_ctx.get_pool_name().c_str(),
- io_ctx.get_id(), group_name);
- int r = librbd::group_remove(io_ctx, group_name);
- tracepoint(librbd, group_remove_exit, r);
- return r;
- }
-
- int RBD::group_list(IoCtx& io_ctx, vector<string> *names)
- {
- TracepointProvider::initialize<tracepoint_traits>(get_cct(io_ctx));
- tracepoint(librbd, group_list_enter, io_ctx.get_pool_name().c_str(),
- io_ctx.get_id());
-
- int r = librbd::group_list(io_ctx, names);
- if (r >= 0) {
- for (auto itr : *names) {
- tracepoint(librbd, group_list_entry, itr.c_str());
- }
- }
- tracepoint(librbd, group_list_exit, r);
- return r;
- }
-
- int RBD::group_image_add(IoCtx& group_ioctx, const char *group_name,
- IoCtx& image_ioctx, const char *image_name)
- {
- TracepointProvider::initialize<tracepoint_traits>(get_cct(group_ioctx));
- tracepoint(librbd, group_image_add_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_name);
- int r = librbd::group_image_add(group_ioctx, group_name, image_ioctx, image_name);
- tracepoint(librbd, group_image_add_exit, r);
- return r;
- }
-
- int RBD::group_image_remove(IoCtx& group_ioctx, const char *group_name,
- IoCtx& image_ioctx, const char *image_name)
- {
- TracepointProvider::initialize<tracepoint_traits>(get_cct(group_ioctx));
- tracepoint(librbd, group_image_remove_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_name);
- int r = librbd::group_image_remove(group_ioctx, group_name, image_ioctx, image_name);
- tracepoint(librbd, group_image_remove_exit, r);
- return r;
- }
-
- int RBD::group_image_list(IoCtx& group_ioctx, const char *group_name,
- std::vector<group_image_status_t> *images)
- {
- TracepointProvider::initialize<tracepoint_traits>(get_cct(group_ioctx));
- tracepoint(librbd, group_image_list_enter, group_ioctx.get_pool_name().c_str(),
- group_ioctx.get_id(), group_name);
- int r = librbd::group_image_list(group_ioctx, group_name, images);
- tracepoint(librbd, group_image_list_exit, r);
- return r;
- }
-
-
RBD::AioCompletion::AioCompletion(void *cb_arg, callback_t complete_cb)
{
pc = reinterpret_cast<void*>(librbd::AioCompletion::create(
return r;
}
- int Image::get_group(group_spec_t *group_spec)
- {
- ImageCtx *ictx = (ImageCtx *)ctx;
- tracepoint(librbd, image_get_group_enter, ictx->name.c_str());
- int r = librbd::image_get_group(ictx, group_spec);
- tracepoint(librbd, image_get_group_exit, r);
- return r;
- }
-
int Image::features(uint64_t *features)
{
ImageCtx *ictx = (ImageCtx *)ctx;
comp->release();
}
-extern "C" int rbd_group_create(rados_ioctx_t p, const char *name)
-{
- librados::IoCtx io_ctx;
- librados::IoCtx::from_rados_ioctx_t(p, io_ctx);
- TracepointProvider::initialize<tracepoint_traits>(get_cct(io_ctx));
- tracepoint(librbd, group_create_enter, io_ctx.get_pool_name().c_str(),
- io_ctx.get_id(), name);
- int r = librbd::group_create(io_ctx, name);
- tracepoint(librbd, group_create_exit, r);
- return r;
-}
-
-extern "C" int rbd_group_remove(rados_ioctx_t p, const char *name)
-{
- librados::IoCtx io_ctx;
- librados::IoCtx::from_rados_ioctx_t(p, io_ctx);
- TracepointProvider::initialize<tracepoint_traits>(get_cct(io_ctx));
- tracepoint(librbd, group_remove_enter, io_ctx.get_pool_name().c_str(),
- io_ctx.get_id(), name);
- int r = librbd::group_remove(io_ctx, name);
- tracepoint(librbd, group_remove_exit, r);
- return r;
-}
-
-extern "C" int rbd_group_list(rados_ioctx_t p, char *names, size_t *size)
-{
- librados::IoCtx io_ctx;
- librados::IoCtx::from_rados_ioctx_t(p, io_ctx);
- TracepointProvider::initialize<tracepoint_traits>(get_cct(io_ctx));
- tracepoint(librbd, group_list_enter, io_ctx.get_pool_name().c_str(),
- io_ctx.get_id());
-
- vector<string> cpp_names;
- int r = librbd::list(io_ctx, cpp_names);
-
- if (r == -ENOENT) {
- *size = 0;
- *names = '\0';
- tracepoint(librbd, group_list_exit, 0);
- return 0;
- }
-
- if (r < 0) {
- tracepoint(librbd, group_list_exit, r);
- return r;
- }
-
- size_t expected_size = 0;
-
- for (size_t i = 0; i < cpp_names.size(); i++) {
- expected_size += cpp_names[i].size() + 1;
- }
- if (*size < expected_size) {
- *size = expected_size;
- tracepoint(librbd, group_list_exit, -ERANGE);
- return -ERANGE;
- }
-
- if (!names)
- return -EINVAL;
-
- names[expected_size] = '\0';
- for (int i = 0; i < (int)cpp_names.size(); i++) {
- const char* name = cpp_names[i].c_str();
- tracepoint(librbd, group_list_entry, name);
- strcpy(names, name);
- names += strlen(names) + 1;
- }
- tracepoint(librbd, group_list_exit, (int)expected_size);
- return (int)expected_size;
-}
-
-extern "C" int rbd_group_image_add(
- rados_ioctx_t group_p, const char *group_name,
- rados_ioctx_t image_p, const char *image_name)
-{
- 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_add_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_name);
-
- int r = librbd::group_image_add(group_ioctx, group_name, image_ioctx, image_name);
-
- tracepoint(librbd, group_image_add_exit, r);
- return r;
-}
-
-extern "C" int rbd_group_image_remove(
- rados_ioctx_t group_p, const char *group_name,
- rados_ioctx_t image_p, const char *image_name)
-{
- 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_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_name);
-
- int r = librbd::group_image_remove(group_ioctx, group_name, image_ioctx, image_name);
-
- tracepoint(librbd, group_image_remove_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,
- size_t *image_size)
-{
- 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_image_list_enter, group_ioctx.get_pool_name().c_str(),
- group_ioctx.get_id(), group_name);
-
- std::vector<librbd::group_image_status_t> cpp_images;
- int r = librbd::group_image_list(group_ioctx, group_name, &cpp_images);
-
- if (r == -ENOENT) {
- tracepoint(librbd, group_image_list_exit, 0);
- return 0;
- }
-
- if (r < 0) {
- tracepoint(librbd, group_image_list_exit, r);
- return r;
- }
-
- if (*image_size < cpp_images.size()) {
- tracepoint(librbd, group_image_list_exit, -ERANGE);
- return -ERANGE;
- }
-
- for (size_t i = 0; i < cpp_images.size(); ++i) {
- group_image_status_cpp_to_c(cpp_images[i], &images[i]);
- }
-
- tracepoint(librbd, group_image_list_exit, r);
- return r;
-}
-
-extern "C" int rbd_image_get_group(rados_ioctx_t image_p,
- const char *image_name,
- rbd_group_spec_t *c_group_spec)
-{
- librados::IoCtx io_ctx;
- librados::IoCtx::from_rados_ioctx_t(image_p, io_ctx);
-
- librbd::ImageCtx *ictx = new librbd::ImageCtx(image_name, "", "", io_ctx, false);
- int r = ictx->state->open();
- if (r < 0) {
- delete ictx;
- tracepoint(librbd, open_image_exit, r);
- return r;
- }
-
- tracepoint(librbd, image_get_group_enter, ictx->name.c_str());
- librbd::group_spec_t group_spec;
- r = librbd::image_get_group(ictx, &group_spec);
- group_spec_cpp_to_c(group_spec, c_group_spec);
- tracepoint(librbd, image_get_group_exit, r);
- ictx->state->close();
- return r;
-}
-
-extern "C" void rbd_group_spec_cleanup(rbd_group_spec_t *group_spec) {
- free(group_spec->name);
-}
-
-extern "C" void rbd_group_image_status_cleanup(
- rbd_group_image_status_t *image) {
- free(image->spec.name);
-}
-
-extern "C" void rbd_group_image_status_list_cleanup(
- rbd_group_image_status_t *images,
- size_t len) {
- for (size_t i = 0; i < len; ++i) {
- rbd_group_image_status_cleanup(&images[i]);
- }
-}
feature enable Enable the specified image feature.
flatten Fill clone with parent data (make it
independent).
- group create Create a consistency group.
- group image add Add an image to a consistency group.
- group image list List images in a consistency group.
- group image remove Remove an image from a consistency group.
- group list (group ls) List rbd consistency groups.
- group remove (group rm) Delete a consistency group.
image-meta get Image metadata get the value associated with
the key.
image-meta list Image metadata list keys with values.
--image arg image name
--no-progress disable progress output
- rbd help group create
- usage: rbd group create [--pool <pool>] [--group <group>]
- <group-spec>
-
- Create a consistency group.
-
- Positional arguments
- <group-spec> group specification
- (example: [<pool-name>/]<group-name>)
-
- Optional arguments
- -p [ --pool ] arg pool name
- --group arg group name
-
- rbd help group image add
- usage: rbd group image add [--group-pool <group-pool>] [--group <group>]
- [--image-pool <image-pool>] [--image <image>]
- [--pool <pool>]
- <group-spec> <image-spec>
-
- Add an image to a consistency group.
-
- Positional arguments
- <group-spec> group specification
- (example: [<pool-name>/]<group-name>)
- <image-spec> image specification
- (example: [<pool-name>/]<image-name>)
-
- Optional arguments
- --group-pool arg group pool name
- --group arg group name
- --image-pool arg image pool name
- --image arg image name
- -p [ --pool ] arg pool name unless overridden
-
- rbd help group image list
- usage: rbd group image list [--format <format>] [--pretty-format]
- [--pool <pool>] [--group <group>]
- <group-spec>
-
- List images in a consistency group.
-
- Positional arguments
- <group-spec> group specification
- (example: [<pool-name>/]<group-name>)
-
- Optional arguments
- --format arg output format [plain, json, or xml]
- --pretty-format pretty formatting (json and xml)
- -p [ --pool ] arg pool name
- --group arg group name
-
- rbd help group image remove
- usage: rbd group image remove [--group-pool <group-pool>] [--group <group>]
- [--image-pool <image-pool>] [--image <image>]
- [--pool <pool>]
- <group-spec> <image-spec>
-
- Remove an image from a consistency group.
-
- Positional arguments
- <group-spec> group specification
- (example: [<pool-name>/]<group-name>)
- <image-spec> image specification
- (example: [<pool-name>/]<image-name>)
-
- Optional arguments
- --group-pool arg group pool name
- --group arg group name
- --image-pool arg image pool name
- --image arg image name
- -p [ --pool ] arg pool name unless overridden
-
- rbd help group list
- usage: rbd group list [--pool <pool>] [--format <format>] [--pretty-format]
-
- List rbd consistency groups.
-
- Optional arguments
- -p [ --pool ] arg pool name
- --format arg output format [plain, json, or xml]
- --pretty-format pretty formatting (json and xml)
-
- rbd help group remove
- usage: rbd group remove [--pool <pool>] [--group <group>]
- <group-spec>
-
- Delete a consistency group.
-
- Positional arguments
- <group-spec> group specification
- (example: [<pool-name>/]<group-name>)
-
- Optional arguments
- -p [ --pool ] arg pool name
- --group arg group name
-
rbd help image-meta get
usage: rbd image-meta get [--pool <pool>] [--image <image>]
<image-spec> <key>
# doesn't use add_ceph_test because it is called by run-rbd-unit-tests.sh
set(unittest_librbd_srcs
test_BlockGuard.cc
- test_ConsistencyGroups.cc
test_main.cc
test_mock_fixture.cc
test_mock_AioImageRequest.cc
+++ /dev/null
-// -*- mode:C; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
-// vim: ts=8 sw=2 smarttab
-#include "test/librbd/test_fixture.h"
-#include "test/librbd/test_support.h"
-#include "include/int_types.h"
-#include "include/stringify.h"
-#include "include/rados/librados.h"
-#include "include/rbd/librbd.hpp"
-#include "common/Cond.h"
-#include "common/errno.h"
-#include "common/Mutex.h"
-#include "common/RWLock.h"
-#include "cls/lock/cls_lock_client.h"
-#include "cls/lock/cls_lock_types.h"
-#include "librbd/AioCompletion.h"
-#include "librbd/AioImageRequestWQ.h"
-#include "librbd/internal.h"
-#include "librbd/ImageCtx.h"
-#include "librbd/ImageWatcher.h"
-#include "librbd/WatchNotifyTypes.h"
-#include "test/librados/test.h"
-#include "gtest/gtest.h"
-#include <boost/assign/std/set.hpp>
-#include <boost/assign/std/map.hpp>
-#include <boost/bind.hpp>
-#include <boost/scope_exit.hpp>
-#include <boost/thread/thread.hpp>
-#include <iostream>
-#include <map>
-#include <set>
-#include <sstream>
-#include <vector>
-
-using namespace ceph;
-using namespace boost::assign;
-using namespace librbd::watch_notify;
-
-void register_test_consistency_groups() {
-}
-
-class TestLibCG : public TestFixture {
-
-};
-
-TEST_F(TestLibCG, group_create)
-{
- librados::IoCtx ioctx;
- ASSERT_EQ(0, _rados.ioctx_create(_pool_name.c_str(), ioctx));
-
- librbd::RBD rbd;
- ASSERT_EQ(0, rbd.group_create(ioctx, "mygroup"));
-
- vector<string> groups;
- ASSERT_EQ(0, rbd.group_list(ioctx, &groups));
- ASSERT_EQ(1U, groups.size());
- ASSERT_EQ("mygroup", groups[0]);
-
- ASSERT_EQ(0, rbd.group_remove(ioctx, "mygroup"));
-
- groups.clear();
- ASSERT_EQ(0, rbd.group_list(ioctx, &groups));
- ASSERT_EQ(0U, groups.size());
-}
-
-TEST_F(TestLibCG, add_image)
-{
- librados::IoCtx ioctx;
- ASSERT_EQ(0, _rados.ioctx_create(_pool_name.c_str(), ioctx));
-
- const char *group_name = "mycg";
- const char *image_name = "myimage";
- librbd::RBD rbd;
- ASSERT_EQ(0, rbd.group_create(ioctx, group_name));
- int order = 14;
- ASSERT_EQ(0, rbd.create2(ioctx, image_name, 65535,
- RBD_FEATURE_LAYERING, &order)); // Specified features make image of new format.
-
- ASSERT_EQ(0, rbd.group_image_add(ioctx, group_name, ioctx, image_name));
-
- vector<librbd::group_image_status_t> images;
- ASSERT_EQ(0, rbd.group_image_list(ioctx, group_name, &images));
- ASSERT_EQ(1U, images.size());
- ASSERT_EQ("myimage", images[0].name);
- ASSERT_EQ(ioctx.get_id(), images[0].pool);
-
- ASSERT_EQ(0, rbd.group_image_remove(ioctx, group_name, ioctx, image_name));
-
- images.clear();
- ASSERT_EQ(0, rbd.group_image_list(ioctx, group_name, &images));
- ASSERT_EQ(0U, images.size());
-}
extern void register_test_operations();
extern void register_test_mirroring();
extern void register_test_mirroring_watcher();
-extern void register_test_consistency_groups();
#endif // TEST_LIBRBD_INTERNALS
int main(int argc, char **argv)
register_test_operations();
register_test_mirroring();
register_test_mirroring_watcher();
- register_test_consistency_groups();
#endif // TEST_LIBRBD_INTERNALS
::testing::InitGoogleTest(&argc, argv);
action/ExportDiff.cc
action/Feature.cc
action/Flatten.cc
- action/Group.cc
action/ImageMeta.cc
action/Import.cc
action/ImportDiff.cc
+++ /dev/null
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
-// vim: ts=8 sw=2 smarttab
-
-#include <iostream>
-
-#include "tools/rbd/ArgumentTypes.h"
-#include "tools/rbd/Shell.h"
-#include "tools/rbd/Utils.h"
-#include "include/rbd_types.h"
-#include "cls/rbd/cls_rbd_types.h"
-#include "common/errno.h"
-#include "common/Formatter.h"
-
-namespace rbd {
-namespace action {
-namespace consgrp {
-
-namespace at = argument_types;
-namespace po = boost::program_options;
-
-int execute_create(const po::variables_map &vm) {
- size_t arg_index = 0;
-
- std::string group_name;
- std::string pool_name;
-
- int r = utils::get_pool_group_names(vm, at::ARGUMENT_MODIFIER_NONE,
- &arg_index, &pool_name, &group_name);
- if (r < 0) {
- return r;
- }
-
- librados::Rados rados;
- librados::IoCtx io_ctx;
-
- r = utils::init(pool_name, &rados, &io_ctx);
- if (r < 0) {
- return r;
- }
- librbd::RBD rbd;
- r = rbd.group_create(io_ctx, group_name.c_str());
- if (r < 0) {
- std::cerr << "rbd: create error: " << cpp_strerror(r) << std::endl;
- return r;
- }
-
- return 0;
-}
-
-int execute_list(const po::variables_map &vm) {
-
- size_t arg_index = 0;
- std::string pool_name = utils::get_pool_name(vm, &arg_index);
-
- at::Format::Formatter formatter;
- int r = utils::get_formatter(vm, &formatter);
- if (r < 0) {
- return r;
- }
- Formatter *f = formatter.get();
-
- librados::Rados rados;
- librados::IoCtx io_ctx;
- r = utils::init(pool_name, &rados, &io_ctx);
- if (r < 0) {
- return r;
- }
-
- librbd::RBD rbd;
- std::vector<std::string> names;
- r = rbd.group_list(io_ctx, &names);
-
- if (r == -ENOENT)
- r = 0;
- if (r < 0)
- return r;
-
- if (f)
- f->open_array_section("consistency_groups");
- for (auto i : names) {
- if (f)
- f->dump_string("name", i);
- else
- std::cout << i << std::endl;
- }
- if (f) {
- f->close_section();
- f->flush(std::cout);
- }
-
- return 0;
-}
-
-int execute_remove(const po::variables_map &vm) {
- size_t arg_index = 0;
-
- std::string group_name;
- std::string pool_name;
-
- int r = utils::get_pool_group_names(vm, at::ARGUMENT_MODIFIER_NONE,
- &arg_index, &pool_name, &group_name);
- if (r < 0) {
- return r;
- }
-
- librados::Rados rados;
- librados::IoCtx io_ctx;
-
- r = utils::init(pool_name, &rados, &io_ctx);
- if (r < 0) {
- return r;
- }
- librbd::RBD rbd;
-
- r = rbd.group_remove(io_ctx, group_name.c_str());
- if (r < 0) {
- std::cerr << "rbd: remove error: " << cpp_strerror(r) << std::endl;
- return r;
- }
-
- return 0;
-}
-
-int execute_add(const po::variables_map &vm) {
- size_t arg_index = 0;
- // Parse group data.
- std::string group_name;
- std::string group_pool_name;
-
- int r = utils::get_special_pool_group_names(vm, &arg_index,
- &group_pool_name,
- &group_name);
- if (r < 0) {
- std::cerr << "rbd: image add error: " << cpp_strerror(r) << std::endl;
- return r;
- }
-
- std::string image_name;
- std::string image_pool_name;
-
- r = utils::get_special_pool_image_names(vm, &arg_index,
- &image_pool_name,
- &image_name);
-
- if (r < 0) {
- std::cerr << "rbd: image add error: " << cpp_strerror(r) << std::endl;
- return r;
- }
-
- librados::Rados rados;
-
- librados::IoCtx cg_io_ctx;
- r = utils::init(group_pool_name, &rados, &cg_io_ctx);
- if (r < 0) {
- return r;
- }
-
- librados::IoCtx image_io_ctx;
- r = utils::init(image_pool_name, &rados, &image_io_ctx);
- if (r < 0) {
- return r;
- }
-
- librbd::RBD rbd;
- r = rbd.group_image_add(cg_io_ctx, group_name.c_str(),
- image_io_ctx, image_name.c_str());
- if (r < 0) {
- std::cerr << "rbd: add image error: " << cpp_strerror(r) << std::endl;
- return r;
- }
-
- return 0;
-}
-
-int execute_remove_image(const po::variables_map &vm) {
- size_t arg_index = 0;
-
- std::string group_name;
- std::string group_pool_name;
-
- int r = utils::get_special_pool_group_names(vm, &arg_index,
- &group_pool_name,
- &group_name);
- if (r < 0) {
- std::cerr << "rbd: image remove error: " << cpp_strerror(r) << std::endl;
- return r;
- }
-
- std::string image_name;
- std::string image_pool_name;
-
- r = utils::get_special_pool_image_names(vm, &arg_index,
- &image_pool_name,
- &image_name);
-
- if (r < 0) {
- std::cerr << "rbd: image remove error: " << cpp_strerror(r) << std::endl;
- return r;
- }
-
- librados::Rados rados;
-
- librados::IoCtx cg_io_ctx;
- r = utils::init(group_pool_name, &rados, &cg_io_ctx);
- if (r < 0) {
- return r;
- }
-
- librados::IoCtx image_io_ctx;
- r = utils::init(image_pool_name, &rados, &image_io_ctx);
- if (r < 0) {
- return r;
- }
-
- librbd::RBD rbd;
- r = rbd.group_image_remove(cg_io_ctx, group_name.c_str(),
- image_io_ctx, image_name.c_str());
- if (r < 0) {
- std::cerr << "rbd: remove image error: " << cpp_strerror(r) << std::endl;
- return r;
- }
-
- return 0;
-}
-
-int execute_list_images(const po::variables_map &vm) {
- size_t arg_index = 0;
- std::string group_name;
- std::string pool_name;
-
- int r = utils::get_pool_group_names(vm, at::ARGUMENT_MODIFIER_NONE,
- &arg_index, &pool_name, &group_name);
- if (r < 0) {
- return r;
- }
-
- if (group_name.empty()) {
- std::cerr << "rbd: "
- << "consistency group name was not specified" << std::endl;
- return -EINVAL;
- }
-
- at::Format::Formatter formatter;
- r = utils::get_formatter(vm, &formatter);
- if (r < 0) {
- return r;
- }
- Formatter *f = formatter.get();
-
- librados::Rados rados;
- librados::IoCtx io_ctx;
- r = utils::init(pool_name, &rados, &io_ctx);
- if (r < 0) {
- return r;
- }
-
- librbd::RBD rbd;
- std::vector<librbd::group_image_status_t> images;
-
- r = rbd.group_image_list(io_ctx, group_name.c_str(), &images);
-
- if (r == -ENOENT)
- r = 0;
- if (r < 0)
- return r;
-
- if (f)
- f->open_array_section("consistency_groups");
- for (auto i : images) {
- std::string image_name = i.name;
- int64_t pool_id = i.pool;
- int state = i.state;
- std::string state_string;
- if (cls::rbd::GROUP_IMAGE_LINK_STATE_INCOMPLETE == state) {
- state_string = "incomplete";
- }
- if (r < 0)
- return r;
- if (f) {
- f->dump_string("image name", image_name);
- f->dump_int("pool id", pool_id);
- f->dump_int("state", state);
- } else
- std::cout << pool_id << "." << image_name << " " << state_string << std::endl;
- }
- if (f) {
- f->close_section();
- f->flush(std::cout);
- }
-
- return 0;
-}
-
-void get_create_arguments(po::options_description *positional,
- po::options_description *options) {
- at::add_group_spec_options(positional, options, at::ARGUMENT_MODIFIER_NONE);
-}
-
-void get_remove_arguments(po::options_description *positional,
- po::options_description *options) {
- at::add_group_spec_options(positional, options, at::ARGUMENT_MODIFIER_NONE);
-}
-
-void get_list_arguments(po::options_description *positional,
- po::options_description *options) {
- add_pool_option(options, at::ARGUMENT_MODIFIER_NONE);
- at::add_format_options(options);
-}
-
-void get_add_arguments(po::options_description *positional,
- po::options_description *options) {
- positional->add_options()
- (at::GROUP_SPEC.c_str(),
- "group specification\n"
- "(example: [<pool-name>/]<group-name>)");
-
- at::add_special_pool_option(options, "group");
- at::add_group_option(options, at::ARGUMENT_MODIFIER_NONE);
-
- positional->add_options()
- (at::IMAGE_SPEC.c_str(),
- "image specification\n"
- "(example: [<pool-name>/]<image-name>)");
-
- at::add_special_pool_option(options, "image");
- at::add_image_option(options, at::ARGUMENT_MODIFIER_NONE);
-
- at::add_pool_option(options, at::ARGUMENT_MODIFIER_NONE,
- " unless overridden");
-}
-
-void get_remove_image_arguments(po::options_description *positional,
- po::options_description *options) {
- positional->add_options()
- (at::GROUP_SPEC.c_str(),
- "group specification\n"
- "(example: [<pool-name>/]<group-name>)");
-
- at::add_special_pool_option(options, "group");
- at::add_group_option(options, at::ARGUMENT_MODIFIER_NONE);
-
- positional->add_options()
- (at::IMAGE_SPEC.c_str(),
- "image specification\n"
- "(example: [<pool-name>/]<image-name>)");
-
- at::add_special_pool_option(options, "image");
- at::add_image_option(options, at::ARGUMENT_MODIFIER_NONE);
-
- at::add_pool_option(options, at::ARGUMENT_MODIFIER_NONE,
- " unless overridden");
-}
-
-void get_list_images_arguments(po::options_description *positional,
- po::options_description *options) {
- at::add_format_options(options);
- at::add_group_spec_options(positional, options, at::ARGUMENT_MODIFIER_NONE);
-}
-
-Shell::Action action_create(
- {"group", "create"}, {}, "Create a consistency group.",
- "", &get_create_arguments, &execute_create);
-Shell::Action action_remove(
- {"group", "remove"}, {"group", "rm"}, "Delete a consistency group.",
- "", &get_remove_arguments, &execute_remove);
-Shell::Action action_list(
- {"group", "list"}, {"group", "ls"}, "List rbd consistency groups.",
- "", &get_list_arguments, &execute_list);
-Shell::Action action_add(
- {"group", "image", "add"}, {}, "Add an image to a consistency group.",
- "", &get_add_arguments, &execute_add);
-Shell::Action action_remove_image(
- {"group", "image", "remove"}, {}, "Remove an image from a consistency group.",
- "", &get_remove_image_arguments, &execute_remove_image);
-Shell::Action action_list_images(
- {"group", "image", "list"}, {}, "List images in a consistency group.",
- "", &get_list_images_arguments, &execute_list_images);
-} // namespace snap
-} // namespace action
-} // namespace rbd
std::string prefix = image.get_block_name_prefix();
- librbd::group_spec_t group_spec;
- r = image.get_group(&group_spec);
- if (r < 0) {
- return r;
- }
-
- std::string group_string = "";
- if (-1 != group_spec.pool)
- group_string = stringify(group_spec.pool) + "." + group_spec.name;
-
if (f) {
f->open_object_section("image");
f->dump_string("name", imgname);
format_flags(f, flags);
}
- if (!group_string.empty()) {
- if (f) {
- f->dump_string("group", group_string);
- } else {
- std::cout << "\tconsistency group: " << group_string
- << std::endl;
- }
- }
-
// snapshot info, if present
if (snapname) {
if (f) {
<< "it crashed. Try again after closing/unmapping it or "
<< "waiting 30s for the crashed client to timeout."
<< std::endl;
- } else if (r == -EMLINK) {
- librbd::Image image;
- int image_r = utils::open_image(io_ctx, image_name, true, &image);
- librbd::group_spec_t group_spec;
- if (image_r == 0) {
- image_r = image.get_group(&group_spec);
- }
- if (image_r == 0)
- std::cerr << "rbd: error: image belongs to a consistency group "
- << group_spec.pool << "." << group_spec.name;
- else
- std::cerr << "rbd: error: image belongs to a consistency group";
-
- std::cerr << std::endl
- << "Remove the image from the consistency group and try again."
- << std::endl;
- image.close();
} else {
std::cerr << "rbd: delete error: " << cpp_strerror(r) << std::endl;
}
)
)
-TRACEPOINT_EVENT(librbd, group_create_enter,
- TP_ARGS(
- const char*, pool_name,
- int64_t, id,
- const char*, groupname),
- TP_FIELDS(
- ctf_string(pool_name, pool_name)
- ctf_integer(int64_t, id, id)
- ctf_string(groupname, groupname)
- )
-)
-
-TRACEPOINT_EVENT(librbd, group_create_exit,
- TP_ARGS(
- int, retval),
- TP_FIELDS(
- ctf_integer(int, retval, retval)
- )
-)
-
-TRACEPOINT_EVENT(librbd, group_remove_enter,
- TP_ARGS(
- const char*, pool_name,
- int64_t, id,
- const char*, groupname),
- TP_FIELDS(
- ctf_string(pool_name, pool_name)
- ctf_integer(int64_t, id, id)
- ctf_string(groupname, groupname)
- )
-)
-
-TRACEPOINT_EVENT(librbd, group_remove_exit,
- TP_ARGS(
- int, retval),
- TP_FIELDS(
- ctf_integer(int, retval, retval)
- )
-)
-
-TRACEPOINT_EVENT(librbd, group_list_enter,
- TP_ARGS(
- const char*, pool_name,
- int64_t, id),
- TP_FIELDS(
- ctf_string(pool_name, pool_name)
- ctf_integer(int64_t, id, id)
- )
-)
-
-TRACEPOINT_EVENT(librbd, group_list_entry,
- TP_ARGS(
- const char*, name),
- TP_FIELDS(
- ctf_string(name, name)
- )
-)
-
-TRACEPOINT_EVENT(librbd, group_list_exit,
- TP_ARGS(
- int, retval),
- TP_FIELDS(
- ctf_integer(int, retval, retval)
- )
-)
-
TRACEPOINT_EVENT(librbd, update_watch_enter,
TP_ARGS(
void*, imagectx,
ctf_integer(int, retval, retval)
)
)
-
-TRACEPOINT_EVENT(librbd, group_image_add_enter,
- TP_ARGS(
- const char*, pool_name,
- int64_t, id,
- const char*, group_name,
- const char*, image_pool_name,
- int64_t, image_id,
- const char*, image_name),
- 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_id, image_id)
- ctf_string(image_name, image_name)
- )
-)
-
-TRACEPOINT_EVENT(librbd, group_image_add_exit,
- TP_ARGS(
- int, retval),
- TP_FIELDS(
- ctf_integer(int, retval, retval)
- )
-)
-
-TRACEPOINT_EVENT(librbd, group_image_remove_enter,
- TP_ARGS(
- const char*, pool_name,
- int64_t, id,
- const char*, group_name,
- const char*, image_pool_name,
- int64_t, image_id,
- const char*, image_name),
- 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_id, image_id)
- ctf_string(image_name, image_name)
- )
-)
-
-TRACEPOINT_EVENT(librbd, group_image_remove_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,
- int64_t, id,
- const char*, group_name),
- TP_FIELDS(
- ctf_string(pool_name, pool_name)
- ctf_integer(int64_t, id, id)
- ctf_string(group_name, group_name)
- )
-)
-
-TRACEPOINT_EVENT(librbd, group_image_list_exit,
- TP_ARGS(
- int, retval),
- TP_FIELDS(
- ctf_integer(int, retval, retval)
- )
-)
-
-TRACEPOINT_EVENT(librbd, image_get_group_enter,
- TP_ARGS(
- const char*, image_name),
- TP_FIELDS(
- ctf_string(image_name, image_name)
- )
-)
-
-TRACEPOINT_EVENT(librbd, image_get_group_exit,
- TP_ARGS(
- int, retval),
- TP_FIELDS(
- ctf_integer(int, retval, retval)
- )
-)