From: Jason Dillaman Date: Tue, 30 Oct 2018 18:11:22 +0000 (-0400) Subject: rbd: support namespaces for image migration X-Git-Tag: v14.1.0~1014^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f10ef69bd27136c3d23aab39f2442c07b3cd6c15;p=ceph.git rbd: support namespaces for image migration Fixes: http://tracker.ceph.com/issues/26951 Signed-off-by: Jason Dillaman --- diff --git a/src/cls/rbd/cls_rbd_types.cc b/src/cls/rbd/cls_rbd_types.cc index 0c779a812d82..1d7f932e9709 100644 --- a/src/cls/rbd/cls_rbd_types.cc +++ b/src/cls/rbd/cls_rbd_types.cc @@ -812,6 +812,7 @@ void MigrationSpec::encode(bufferlist& bl) const { ENCODE_START(1, 1, bl); encode(header_type, bl); encode(pool_id, bl); + encode(pool_namespace, bl); encode(image_name, bl); encode(image_id, bl); encode(snap_seqs, bl); @@ -827,6 +828,7 @@ void MigrationSpec::decode(bufferlist::const_iterator& bl) { DECODE_START(1, bl); decode(header_type, bl); decode(pool_id, bl); + decode(pool_namespace, bl); decode(image_name, bl); decode(image_id, bl); decode(snap_seqs, bl); @@ -853,6 +855,7 @@ std::ostream& operator<<(std::ostream& os, void MigrationSpec::dump(Formatter *f) const { f->dump_stream("header_type") << header_type; f->dump_int("pool_id", pool_id); + f->dump_string("pool_namespace", pool_namespace); f->dump_string("image_name", image_name); f->dump_string("image_id", image_id); f->dump_stream("snap_seqs") << snap_seqs; @@ -862,9 +865,9 @@ void MigrationSpec::dump(Formatter *f) const { void MigrationSpec::generate_test_instances(std::list &o) { o.push_back(new MigrationSpec()); - o.push_back(new MigrationSpec(MIGRATION_HEADER_TYPE_SRC, 1, "image_name", - "image_id", {{1, 2}}, 123, true, true, - MIGRATION_STATE_PREPARED, "description")); + o.push_back(new MigrationSpec(MIGRATION_HEADER_TYPE_SRC, 1, "ns", + "image_name", "image_id", {{1, 2}}, 123, true, + true, MIGRATION_STATE_PREPARED, "description")); } std::ostream& operator<<(std::ostream& os, @@ -872,6 +875,7 @@ std::ostream& operator<<(std::ostream& os, os << "[" << "header_type=" << migration_spec.header_type << ", " << "pool_id=" << migration_spec.pool_id << ", " + << "pool_namespace=" << migration_spec.pool_namespace << ", " << "image_name=" << migration_spec.image_name << ", " << "image_id=" << migration_spec.image_id << ", " << "snap_seqs=" << migration_spec.snap_seqs << ", " diff --git a/src/cls/rbd/cls_rbd_types.h b/src/cls/rbd/cls_rbd_types.h index ac914081ed9f..18a9eeff01d1 100644 --- a/src/cls/rbd/cls_rbd_types.h +++ b/src/cls/rbd/cls_rbd_types.h @@ -716,6 +716,7 @@ std::ostream& operator<<(std::ostream& os, struct MigrationSpec { MigrationHeaderType header_type = MIGRATION_HEADER_TYPE_SRC; int64_t pool_id = -1; + std::string pool_namespace; std::string image_name; std::string image_id; std::map snap_seqs; @@ -728,11 +729,13 @@ struct MigrationSpec { MigrationSpec() { } MigrationSpec(MigrationHeaderType header_type, int64_t pool_id, + const std::string& pool_namespace, const std::string &image_name, const std::string &image_id, const std::map &snap_seqs, uint64_t overlap, bool mirroring, bool flatten, MigrationState state, const std::string &state_description) - : header_type(header_type), pool_id(pool_id), image_name(image_name), + : header_type(header_type), pool_id(pool_id), + pool_namespace(pool_namespace), image_name(image_name), image_id(image_id), snap_seqs(snap_seqs), overlap(overlap), flatten(flatten), mirroring(mirroring), state(state), state_description(state_description) { @@ -746,9 +749,10 @@ struct MigrationSpec { inline bool operator==(const MigrationSpec& ms) const { return header_type == ms.header_type && pool_id == ms.pool_id && - image_name == ms.image_name && image_id == ms.image_id && - snap_seqs == ms.snap_seqs && overlap == ms.overlap && - flatten == ms.flatten && mirroring == ms.mirroring && state == ms.state && + pool_namespace == ms.pool_namespace && image_name == ms.image_name && + image_id == ms.image_id && snap_seqs == ms.snap_seqs && + overlap == ms.overlap && flatten == ms.flatten && + mirroring == ms.mirroring && state == ms.state && state_description == ms.state_description; } }; diff --git a/src/include/rbd/librbd.h b/src/include/rbd/librbd.h index 4c381614533c..741012161068 100644 --- a/src/include/rbd/librbd.h +++ b/src/include/rbd/librbd.h @@ -241,9 +241,11 @@ typedef enum { typedef struct { int64_t source_pool_id; + char *source_pool_namespace; char *source_image_name; char *source_image_id; int64_t dest_pool_id; + char *dest_pool_namespace; char *dest_image_name; char *dest_image_id; rbd_image_migration_state_t state; diff --git a/src/include/rbd/librbd.hpp b/src/include/rbd/librbd.hpp index 1447484a7e72..380fc4d4ece1 100644 --- a/src/include/rbd/librbd.hpp +++ b/src/include/rbd/librbd.hpp @@ -132,9 +132,11 @@ namespace librbd { typedef struct { int64_t source_pool_id; + std::string source_pool_namespace; std::string source_image_name; std::string source_image_id; int64_t dest_pool_id; + std::string dest_pool_namespace; std::string dest_image_name; std::string dest_image_id; image_migration_state_t state; diff --git a/src/librbd/Types.h b/src/librbd/Types.h index 5b9f17937144..3f1104478ebc 100644 --- a/src/librbd/Types.h +++ b/src/librbd/Types.h @@ -96,6 +96,7 @@ enum { struct MigrationInfo { int64_t pool_id = -1; + std::string pool_namespace; std::string image_name; std::string image_id; deep_copy::SnapMap snap_map; @@ -104,11 +105,13 @@ struct MigrationInfo { MigrationInfo() { } - MigrationInfo(int64_t pool_id, std::string image_name, std::string image_id, + MigrationInfo(int64_t pool_id, const std::string& pool_namespace, + const std::string& image_name, const std::string& image_id, const deep_copy::SnapMap &snap_map, uint64_t overlap, bool flatten) - : pool_id(pool_id), image_name(image_name), image_id(image_id), - snap_map(snap_map), overlap(overlap), flatten(flatten) { + : pool_id(pool_id), pool_namespace(pool_namespace), image_name(image_name), + image_id(image_id), snap_map(snap_map), overlap(overlap), + flatten(flatten) { } bool empty() const { diff --git a/src/librbd/api/Migration.cc b/src/librbd/api/Migration.cc index 8561ba075006..32c13df3786d 100644 --- a/src/librbd/api/Migration.cc +++ b/src/librbd/api/Migration.cc @@ -235,15 +235,10 @@ int open_source_image(librados::IoCtx& io_ctx, const std::string &image_name, return r; } - // TODO support namespaces - if (io_ctx.get_id() == migration_spec.pool_id) { - src_io_ctx.dup(io_ctx); - } else { - r = util::create_ioctx(io_ctx, "source image", migration_spec.pool_id, - {}, &src_io_ctx); - if (r < 0) { - return r; - } + r = util::create_ioctx(io_ctx, "source image", migration_spec.pool_id, + migration_spec.pool_namespace, &src_io_ctx); + if (r < 0) { + return r; } src_image_name = migration_spec.image_name; @@ -306,15 +301,11 @@ int open_source_image(librados::IoCtx& io_ctx, const std::string &image_name, ldout(cct, 20) << "migration spec: " << migration_spec << dendl; } - // TODO support namespaces - if (image_ctx->md_ctx.get_id() == migration_spec.pool_id) { - dst_io_ctx->dup(io_ctx); - } else { - r = util::create_ioctx(image_ctx->md_ctx, "source image", - migration_spec.pool_id, {}, dst_io_ctx); - if (r < 0) { - return r; - } + r = util::create_ioctx(image_ctx->md_ctx, "source image", + migration_spec.pool_id, migration_spec.pool_namespace, + dst_io_ctx); + if (r < 0) { + return r; } *src_image_ctx = image_ctx; @@ -635,13 +626,14 @@ Migration::Migration(I *src_image_ctx, librados::IoCtx& dst_io_ctx, m_dst_header_oid(util::header_name(m_dst_image_id)), m_image_options(opts), m_flatten(flatten), m_mirroring(mirroring), m_prog_ctx(prog_ctx), m_src_migration_spec(cls::rbd::MIGRATION_HEADER_TYPE_SRC, - m_dst_io_ctx.get_id(), m_dst_image_name, - m_dst_image_id, {}, 0, flatten, mirroring, state, - state_description), + m_dst_io_ctx.get_id(), m_dst_io_ctx.get_namespace(), + m_dst_image_name, m_dst_image_id, {}, 0, flatten, + mirroring, state, state_description), m_dst_migration_spec(cls::rbd::MIGRATION_HEADER_TYPE_DST, - src_image_ctx->md_ctx.get_id(), m_src_image_ctx->name, - m_src_image_ctx->id, {}, 0, flatten, mirroring, state, - state_description) { + src_image_ctx->md_ctx.get_id(), + src_image_ctx->md_ctx.get_namespace(), + m_src_image_ctx->name, m_src_image_ctx->id, {}, 0, + flatten, mirroring, state, state_description) { m_src_io_ctx.dup(src_image_ctx->md_ctx); } @@ -906,9 +898,11 @@ int Migration::status(image_migration_status_t *status) { ldout(m_cct, 10) << dendl; status->source_pool_id = m_dst_migration_spec.pool_id; + status->source_pool_namespace = m_dst_migration_spec.pool_namespace; status->source_image_name = m_dst_migration_spec.image_name; status->source_image_id = m_dst_migration_spec.image_id; status->dest_pool_id = m_src_migration_spec.pool_id; + status->dest_pool_namespace = m_src_migration_spec.pool_namespace; status->dest_image_name = m_src_migration_spec.image_name; status->dest_image_id = m_src_migration_spec.image_id; @@ -1232,9 +1226,10 @@ int Migration::create_dst_image() { } m_dst_migration_spec = {cls::rbd::MIGRATION_HEADER_TYPE_DST, - m_src_io_ctx.get_id(), m_src_image_name, - m_src_image_id, snap_seqs, size, m_flatten, - m_mirroring, cls::rbd::MIGRATION_STATE_PREPARING, ""}; + m_src_io_ctx.get_id(), m_src_io_ctx.get_namespace(), + m_src_image_name, m_src_image_id, snap_seqs, size, + m_flatten, m_mirroring, + cls::rbd::MIGRATION_STATE_PREPARING, ""}; r = cls_client::migration_set(&m_dst_io_ctx, m_dst_header_oid, m_dst_migration_spec); diff --git a/src/librbd/image/RefreshRequest.cc b/src/librbd/image/RefreshRequest.cc index 082cdd305500..ec290a957ec5 100644 --- a/src/librbd/image/RefreshRequest.cc +++ b/src/librbd/image/RefreshRequest.cc @@ -1455,6 +1455,7 @@ bool RefreshRequest::get_migration_info(ParentImageInfo *parent_md, } parent_md->spec.pool_id = m_migration_spec.pool_id; + parent_md->spec.pool_namespace = m_migration_spec.pool_namespace; parent_md->spec.image_id = m_migration_spec.image_id; parent_md->spec.snap_id = CEPH_NOSNAP; parent_md->overlap = std::min(m_size, m_migration_spec.overlap); @@ -1484,9 +1485,9 @@ bool RefreshRequest::get_migration_info(ParentImageInfo *parent_md, } } - *migration_info = {m_migration_spec.pool_id, m_migration_spec.image_name, - m_migration_spec.image_id, {}, overlap, - m_migration_spec.flatten}; + *migration_info = {m_migration_spec.pool_id, m_migration_spec.pool_namespace, + m_migration_spec.image_name, m_migration_spec.image_id, {}, + overlap, m_migration_spec.flatten}; deep_copy::util::compute_snap_map(0, CEPH_NOSNAP, snap_seqs, &migration_info->snap_map); diff --git a/src/librbd/librbd.cc b/src/librbd/librbd.cc index 6e409babc295..7db9b78a5b61 100644 --- a/src/librbd/librbd.cc +++ b/src/librbd/librbd.cc @@ -3300,9 +3300,13 @@ extern "C" int rbd_migration_status(rados_ioctx_t p, const char *image_name, int r = librbd::api::Migration<>::status(io_ctx, image_name, &cpp_status); if (r >= 0) { status->source_pool_id = cpp_status.source_pool_id; + status->source_pool_namespace = + strdup(cpp_status.source_pool_namespace.c_str()); status->source_image_name = strdup(cpp_status.source_image_name.c_str()); status->source_image_id = strdup(cpp_status.source_image_id.c_str()); status->dest_pool_id = cpp_status.dest_pool_id; + status->dest_pool_namespace = + strdup(cpp_status.dest_pool_namespace.c_str()); status->dest_image_name = strdup(cpp_status.dest_image_name.c_str()); status->dest_image_id = strdup(cpp_status.dest_image_id.c_str()); status->state = cpp_status.state; @@ -3315,8 +3319,10 @@ extern "C" int rbd_migration_status(rados_ioctx_t p, const char *image_name, extern "C" void rbd_migration_status_cleanup(rbd_image_migration_status_t *s) { + free(s->source_pool_namespace); free(s->source_image_name); free(s->source_image_id); + free(s->dest_pool_namespace); free(s->dest_image_name); free(s->dest_image_id); free(s->state_description); diff --git a/src/pybind/rbd/rbd.pyx b/src/pybind/rbd/rbd.pyx index b300edd0d1a3..871345dfe2f6 100644 --- a/src/pybind/rbd/rbd.pyx +++ b/src/pybind/rbd/rbd.pyx @@ -208,9 +208,11 @@ cdef extern from "rbd/librbd.h" nogil: ctypedef struct rbd_image_migration_status_t: int64_t source_pool_id + char *source_pool_namespace char *source_image_name char *source_image_id int64_t dest_pool_id + char *dest_pool_namespace char *dest_image_name char *dest_image_id rbd_image_migration_state_t state @@ -1385,12 +1387,16 @@ class RBD(object): * ``source_pool_id`` (int) - source image pool id + * ``source_pool_namespace`` (str) - source image pool namespace + * ``source_image_name`` (str) - source image name * ``source_image_id`` (str) - source image id * ``dest_pool_id`` (int) - destination image pool id + * ``dest_pool_namespace`` (str) - destination image pool namespace + * ``dest_image_name`` (str) - destination image name * ``dest_image_id`` (str) - destination image id @@ -1413,14 +1419,16 @@ class RBD(object): raise make_ex(ret, 'error getting migration status') status = { - 'source_pool_id' : c_status.source_pool_id, - 'source_image_name' : decode_cstr(c_status.source_image_name), - 'source_image_id' : decode_cstr(c_status.source_image_id), - 'dest_pool_id' : c_status.source_pool_id, - 'dest_image_name' : decode_cstr(c_status.dest_image_name), - 'dest_image_id' : decode_cstr(c_status.dest_image_id), - 'state' : c_status.state, - 'state_description' : decode_cstr(c_status.state_description) + 'source_pool_id' : c_status.source_pool_id, + 'source_pool_namespace' : decode_cstr(c_status.source_pool_namespace), + 'source_image_name' : decode_cstr(c_status.source_image_name), + 'source_image_id' : decode_cstr(c_status.source_image_id), + 'dest_pool_id' : c_status.source_pool_id, + 'dest_pool_namespace' : decode_cstr(c_status.dest_pool_namespace), + 'dest_image_name' : decode_cstr(c_status.dest_image_name), + 'dest_image_id' : decode_cstr(c_status.dest_image_id), + 'state' : c_status.state, + 'state_description' : decode_cstr(c_status.state_description) } rbd_migration_status_cleanup(&c_status) diff --git a/src/test/cls_rbd/test_cls_rbd.cc b/src/test/cls_rbd/test_cls_rbd.cc index 99a0a55b9816..726c29eab494 100644 --- a/src/test/cls_rbd/test_cls_rbd.cc +++ b/src/test/cls_rbd/test_cls_rbd.cc @@ -2810,7 +2810,8 @@ TEST_F(TestClsRbd, migration) ASSERT_EQ(0, create_image(&ioctx, oid, 0, 22, 0, oid, -1)); cls::rbd::MigrationSpec migration_spec(cls::rbd::MIGRATION_HEADER_TYPE_DST, 1, - "name", "id", {}, 0, false, false, + "name", "ns", "id", {}, 0, false, + false, cls::rbd::MIGRATION_STATE_PREPARING, "123"); cls::rbd::MigrationSpec read_migration_spec; @@ -2879,7 +2880,8 @@ TEST_F(TestClsRbd, migration_v1) ASSERT_EQ(0, ioctx.write(oid, header, header.length(), 0)); cls::rbd::MigrationSpec migration_spec(cls::rbd::MIGRATION_HEADER_TYPE_DST, 1, - "name", "id", {}, 0, false, false, + "name", "ns", "id", {}, 0, false, + false, cls::rbd::MIGRATION_STATE_PREPARING, "123"); cls::rbd::MigrationSpec read_migration_spec; diff --git a/src/test/librbd/test_Migration.cc b/src/test/librbd/test_Migration.cc index a42e201634fa..b9e0791b234f 100644 --- a/src/test/librbd/test_Migration.cc +++ b/src/test/librbd/test_Migration.cc @@ -213,9 +213,11 @@ struct TestMigration : public TestFixture { EXPECT_EQ(0, librbd::api::Migration<>::status(m_ioctx, m_image_name, &status)); EXPECT_EQ(status.source_pool_id, m_ioctx.get_id()); + EXPECT_EQ(status.source_pool_namespace, m_ioctx.get_namespace()); EXPECT_EQ(status.source_image_name, m_image_name); EXPECT_EQ(status.source_image_id, m_image_id); EXPECT_EQ(status.dest_pool_id, m_ictx->md_ctx.get_id()); + EXPECT_EQ(status.dest_pool_namespace, m_ictx->md_ctx.get_namespace()); EXPECT_EQ(status.dest_image_name, m_ictx->name); EXPECT_EQ(status.dest_image_id, m_ictx->id); EXPECT_EQ(status.state, state); diff --git a/src/tools/rbd/action/Status.cc b/src/tools/rbd/action/Status.cc index 253f9508f304..75afdd774311 100644 --- a/src/tools/rbd/action/Status.cc +++ b/src/tools/rbd/action/Status.cc @@ -101,9 +101,13 @@ static int do_show_status(librados::IoCtx& io_ctx, const std::string &image_name if (!migration_state.empty()) { f->open_object_section("migration"); f->dump_string("source_pool_name", source_pool_name); + f->dump_string("source_pool_namespace", + migration_status.source_pool_namespace); f->dump_string("source_image_name", migration_status.source_image_name); f->dump_string("source_image_id", migration_status.source_image_id); f->dump_string("dest_pool_name", dest_pool_name); + f->dump_string("dest_pool_namespace", + migration_status.dest_pool_namespace); f->dump_string("dest_image_name", migration_status.dest_image_name); f->dump_string("dest_image_id", migration_status.dest_image_id); f->dump_string("state", migration_state); @@ -121,6 +125,13 @@ static int do_show_status(librados::IoCtx& io_ctx, const std::string &image_name std::cout << "Watchers: none" << std::endl; } if (!migration_state.empty()) { + if (!migration_status.source_pool_namespace.empty()) { + source_pool_name += ("/" + migration_status.source_pool_namespace); + } + if (!migration_status.dest_pool_namespace.empty()) { + dest_pool_name += ("/" + migration_status.dest_pool_namespace); + } + std::cout << "Migration:" << std::endl; std::cout << "\tsource: " << source_pool_name << "/" << migration_status.source_image_name;