]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/cls/rbd/cls_rbd_types.cc
import ceph quincy 17.2.4
[ceph.git] / ceph / src / cls / rbd / cls_rbd_types.cc
index 5f3c40b049f2f312a8d6b6696ef295b88958be70..e47f227777b8f76c67c3efff6ddec0ba0337ebb4 100644 (file)
@@ -8,6 +8,13 @@
 namespace cls {
 namespace rbd {
 
+using std::istringstream;
+using std::ostringstream;
+using std::string;
+
+using ceph::bufferlist;
+using ceph::Formatter;
+
 std::ostream& operator<<(std::ostream& os,
                          MirrorPeerDirection mirror_peer_direction) {
   switch (mirror_peer_direction) {
@@ -994,12 +1001,16 @@ std::ostream& operator<<(std::ostream& os, const MirrorSnapshotNamespace& ns) {
   os << "[" << SNAPSHOT_NAMESPACE_TYPE_MIRROR << " "
      << "state=" << ns.state << ", "
      << "complete=" << ns.complete << ", "
-     << "mirror_peer_uuids=" << ns.mirror_peer_uuids << ", "
-     << "primary_mirror_uuid=" << ns.primary_mirror_uuid << ", "
-     << "primary_snap_id=" << ns.primary_snap_id << ", "
-     << "last_copied_object_number=" << ns.last_copied_object_number << ", "
-     << "snap_seqs=" << ns.snap_seqs
-     << "]";
+     << "mirror_peer_uuids=" << ns.mirror_peer_uuids << ", ";
+  if (ns.is_primary()) {
+     os << "clean_since_snap_id=" << ns.clean_since_snap_id;
+  } else {
+     os << "primary_mirror_uuid=" << ns.primary_mirror_uuid << ", "
+        << "primary_snap_id=" << ns.primary_snap_id << ", "
+        << "last_copied_object_number=" << ns.last_copied_object_number << ", "
+        << "snap_seqs=" << ns.snap_seqs;
+  }
+  os << "]";
   return os;
 }
 
@@ -1201,6 +1212,9 @@ std::ostream& operator<<(std::ostream& os,
   case MIGRATION_STATE_EXECUTED:
     os << "executed";
     break;
+  case MIGRATION_STATE_ABORTING:
+    os << "aborting";
+    break;
   default:
     os << "unknown (" << static_cast<uint32_t>(migration_state) << ")";
     break;
@@ -1209,7 +1223,12 @@ std::ostream& operator<<(std::ostream& os,
 }
 
 void MigrationSpec::encode(bufferlist& bl) const {
-  ENCODE_START(2, 1, bl);
+  uint8_t min_version = 1;
+  if (!source_spec.empty()) {
+    min_version = 3;
+  }
+
+  ENCODE_START(3, min_version, bl);
   encode(header_type, bl);
   encode(pool_id, bl);
   encode(pool_namespace, bl);
@@ -1222,11 +1241,12 @@ void MigrationSpec::encode(bufferlist& bl) const {
   encode(state, bl);
   encode(state_description, bl);
   encode(static_cast<uint8_t>(mirror_image_mode), bl);
+  encode(source_spec, bl);
   ENCODE_FINISH(bl);
 }
 
 void MigrationSpec::decode(bufferlist::const_iterator& bl) {
-  DECODE_START(2, bl);
+  DECODE_START(3, bl);
   decode(header_type, bl);
   decode(pool_id, bl);
   decode(pool_namespace, bl);
@@ -1243,7 +1263,10 @@ void MigrationSpec::decode(bufferlist::const_iterator& bl) {
     decode(int_mode, bl);
     mirror_image_mode = static_cast<MirrorImageMode>(int_mode);
   }
- DECODE_FINISH(bl);
+  if (struct_v >= 3) {
+    decode(source_spec, bl);
+  }
+  DECODE_FINISH(bl);
 }
 
 std::ostream& operator<<(std::ostream& os,
@@ -1260,10 +1283,15 @@ 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);
+  if (header_type == MIGRATION_HEADER_TYPE_SRC ||
+      source_spec.empty()) {
+    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);
+  } else {
+    f->dump_string("source_spec", source_spec);
+  }
   f->dump_stream("snap_seqs") << snap_seqs;
   f->dump_unsigned("overlap", overlap);
   f->dump_bool("mirroring", mirroring);
@@ -1273,20 +1301,29 @@ 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, "ns",
-                                "image_name", "image_id", {{1, 2}}, 123, true,
-                                MIRROR_IMAGE_MODE_SNAPSHOT, true,
+                                "image_name", "image_id", "", {{1, 2}}, 123,
+                                true, MIRROR_IMAGE_MODE_SNAPSHOT, true,
+                                MIGRATION_STATE_PREPARED, "description"));
+  o.push_back(new MigrationSpec(MIGRATION_HEADER_TYPE_DST, -1, "", "", "",
+                                "{\"format\": \"raw\"}", {{1, 2}}, 123,
+                                true, MIRROR_IMAGE_MODE_SNAPSHOT, true,
                                 MIGRATION_STATE_PREPARED, "description"));
 }
 
 std::ostream& operator<<(std::ostream& os,
                          const MigrationSpec& migration_spec) {
   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 << ", "
+     << "header_type=" << migration_spec.header_type << ", ";
+  if (migration_spec.header_type == MIGRATION_HEADER_TYPE_SRC ||
+      migration_spec.source_spec.empty()) {
+    os << "pool_id=" << migration_spec.pool_id << ", "
+       << "pool_namespace=" << migration_spec.pool_namespace << ", "
+       << "image_name=" << migration_spec.image_name << ", "
+       << "image_id=" << migration_spec.image_id << ", ";
+  } else {
+     os << "source_spec=" << migration_spec.source_spec << ", ";
+  }
+  os << "snap_seqs=" << migration_spec.snap_seqs << ", "
      << "overlap=" << migration_spec.overlap << ", "
      << "flatten=" << migration_spec.flatten << ", "
      << "mirroring=" << migration_spec.mirroring << ", "