On 02/23/2017 11:31 PM, Eric Blake wrote:
On 02/23/2017 01:14 AM, Zhang Chen wrote:
We can call this qmp command to start/stop replication outside of qemu.
Like Xen colo need this function.

Signed-off-by: Zhang Chen <zhangchen.f...@cn.fujitsu.com>
Signed-off-by: Wen Congyang <wencongy...@gmail.com>
Reviewed-by: Eric Blake <ebl...@redhat.com>
Reviewed-by: Stefano Stabellini <sstabell...@kernel.org>
Reviewed-by: zhanghailiang <zhang.zhanghaili...@huawei.com>

---
@@ -104,6 +106,27 @@ void colo_do_failover(MigrationState *s)
      }
  }
+void qmp_xen_set_replication(bool enable, bool primary,
+                             bool has_failover, bool failover,
+                             Error **errp)
+{
+    ReplicationMode mode = primary ?
+                           REPLICATION_MODE_PRIMARY :
+                           REPLICATION_MODE_SECONDARY;
+
+    if (has_failover && enable) {
+        error_setg(errp, "Parameter 'failover' is only for"
+                   " stopping replication");
+        return;
+    }
+
+    if (enable) {
+        replication_start_all(mode, errp);
+    } else {
+        replication_stop_all(failover, failover ? NULL : errp);
Technically, this is use of failover without first checking
has_failover; it would be safer if you inserted:

if (!has_failover) {
     failover = NULL;
}

OK, I will insert this code in next version.

Thanks
Zhang Chen

earlier in the function to be safe against any callers that don't go
through the QAPI-generated code.  Fortunately, our QAPI generated code
guarantees that failover is NULL when has_failover is false, so my R-b
can stand as-is if there is no other reason for a respin.

--
Thanks
Zhang Chen




Reply via email to