]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: support namespaces for image migration 24836/head
authorJason Dillaman <dillaman@redhat.com>
Tue, 30 Oct 2018 18:11:22 +0000 (14:11 -0400)
committerJason Dillaman <dillaman@redhat.com>
Thu, 1 Nov 2018 14:11:51 +0000 (10:11 -0400)
Fixes: http://tracker.ceph.com/issues/26951
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
12 files changed:
src/cls/rbd/cls_rbd_types.cc
src/cls/rbd/cls_rbd_types.h
src/include/rbd/librbd.h
src/include/rbd/librbd.hpp
src/librbd/Types.h
src/librbd/api/Migration.cc
src/librbd/image/RefreshRequest.cc
src/librbd/librbd.cc
src/pybind/rbd/rbd.pyx
src/test/cls_rbd/test_cls_rbd.cc
src/test/librbd/test_Migration.cc
src/tools/rbd/action/Status.cc

index 0c779a812d827a2d6377ef93c33c661a78df77c0..1d7f932e9709ca706480c45eb8b33fdffa194b7c 100644 (file)
@@ -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<MigrationSpec*> &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 << ", "
index ac914081ed9f36b3f3d0ff45f4a839326d9f1cd5..18a9eeff01d169ed8ec4dc3e02ff45917869c162 100644 (file)
@@ -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<uint64_t, uint64_t> 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<uint64_t, uint64_t> &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;
   }
 };
index 4c381614533c176ba6d5fcb3a27d8ee2851a2faa..74101216106894d2aee6651d903580498272030a 100644 (file)
@@ -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;
index 1447484a7e72aacf4020fb2befbbb8af8bce05a4..380fc4d4ece1e71fb7ec80a6a8e23ad0bd9a77b0 100644 (file)
@@ -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;
index 5b9f1793714461a46f87302abb201437c04ccd2b..3f1104478ebcea505d3debe7e30cc212f0e8a193 100644 (file)
@@ -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 {
index 8561ba075006d2bc5c393bea142c58eb78d950fa..32c13df3786d9a52dfd4b1a916f41625b3f95246 100644 (file)
@@ -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<I>::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<I>::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<I>::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);
index 082cdd305500c29ccbad3454c429620f25949821..ec290a957ec547363b2442629a75fee93bf7a6e0 100644 (file)
@@ -1455,6 +1455,7 @@ bool RefreshRequest<I>::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<I>::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);
index 6e409babc295b501889f372de73a5fdeff869397..7db9b78a5b612671fce08a8b8a7df424fe5546b4 100644 (file)
@@ -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);
index b300edd0d1a38793b80466c02c5c16fec0cbf011..871345dfe2f6b3a275f282ed602004f59fd6779a 100644 (file)
@@ -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)
index 99a0a55b9816e9473c4e273cd4f8d9e69d865bd6..726c29eab494c001f516451db986bf1ef103f2b8 100644 (file)
@@ -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;
index a42e201634faed9ef99d5cc3caaf698248a0869a..b9e0791b234faea315ee4aa4a855e4f6970b4ae2 100644 (file)
@@ -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);
index 253f9508f30427dca13f19e27aeba357df2457bb..75afdd7743117558a82457fbc8598e8cdc1b3b0b 100644 (file)
@@ -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;