From ed37ef1f91c20f0ab162ce60f8c38400b917fa64 Mon Sep 17 00:00:00 2001 From: Wen Congyang Date: Wed, 17 Feb 2016 14:28:32 +0800 Subject: [PATCH] COLO: introduce new API to prepare/start/do/get_error/stop replication We will use qemu block replication, and qemu provides some qmp commands to prepare replication, start replication, get replication error, and stop replication. Introduce new API to execute these qmp commands. Signed-off-by: Wen Congyang Signed-off-by: Changlong Xie Acked-by: Wei Liu --- tools/libxl/libxl_internal.h | 24 +++++++++ tools/libxl/libxl_qmp.c | 96 ++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+) diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index b3bb479dc8..148df055bf 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1774,6 +1774,30 @@ _hidden int libxl__qmp_set_global_dirty_log(libxl__gc *gc, int domid, bool enabl _hidden int libxl__qmp_insert_cdrom(libxl__gc *gc, int domid, const libxl_device_disk *disk); /* Add a virtual CPU */ _hidden int libxl__qmp_cpu_add(libxl__gc *gc, int domid, int index); +/* Start NBD server */ +_hidden int libxl__qmp_nbd_server_start(libxl__gc *gc, int domid, + const char *host, const char *port); +/* Add a disk to NBD server */ +_hidden int libxl__qmp_nbd_server_add(libxl__gc *gc, int domid, + const char *disk); +/* Start replication */ +_hidden int libxl__qmp_start_replication(libxl__gc *gc, int domid, + bool primary); +/* Get replication error that occurs when the vm is running */ +_hidden int libxl__qmp_get_replication_error(libxl__gc *gc, int domid); +/* Do checkpoint */ +_hidden int libxl__qmp_do_checkpoint(libxl__gc *gc, int domid); +/* Stop replication */ +_hidden int libxl__qmp_stop_replication(libxl__gc *gc, int domid, + bool primary); +/* Stop NBD server */ +_hidden int libxl__qmp_nbd_server_stop(libxl__gc *gc, int domid); +/* Add or remove a child to/from quorum */ +_hidden int libxl__qmp_x_blockdev_change(libxl__gc *gc, int domid, + const char *parant, + const char *child, const char *node); +/* run a hmp command in qmp mode */ +_hidden int libxl__qmp_hmp(libxl__gc *gc, int domid, const char *command_line); /* close and free the QMP handler */ _hidden void libxl__qmp_close(libxl__qmp_handler *qmp); /* remove the socket file, if the file has already been removed, diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c index c0bdfcb83a..3eb279aacc 100644 --- a/tools/libxl/libxl_qmp.c +++ b/tools/libxl/libxl_qmp.c @@ -979,6 +979,102 @@ int libxl__qmp_cpu_add(libxl__gc *gc, int domid, int idx) return qmp_run_command(gc, domid, "cpu-add", args, NULL, NULL); } +int libxl__qmp_nbd_server_start(libxl__gc *gc, int domid, + const char *host, const char *port) +{ + libxl__json_object *args = NULL; + libxl__json_object *addr = NULL; + libxl__json_object *data = NULL; + + /* 'addr': { + * 'type': 'inet', + * 'data': { + * 'host': '$nbd_host', + * 'port': '$nbd_port' + * } + * } + */ + qmp_parameters_add_string(gc, &data, "host", host); + qmp_parameters_add_string(gc, &data, "port", port); + + qmp_parameters_add_string(gc, &addr, "type", "inet"); + qmp_parameters_common_add(gc, &addr, "data", data); + + qmp_parameters_common_add(gc, &args, "addr", addr); + + return qmp_run_command(gc, domid, "nbd-server-start", args, NULL, NULL); +} + +int libxl__qmp_nbd_server_add(libxl__gc *gc, int domid, const char *disk) +{ + libxl__json_object *args = NULL; + + qmp_parameters_add_string(gc, &args, "device", disk); + qmp_parameters_add_bool(gc, &args, "writable", true); + + return qmp_run_command(gc, domid, "nbd-server-add", args, NULL, NULL); +} + +int libxl__qmp_start_replication(libxl__gc *gc, int domid, bool primary) +{ + libxl__json_object *args = NULL; + + qmp_parameters_add_bool(gc, &args, "enable", true); + qmp_parameters_add_bool(gc, &args, "primary", primary); + + return qmp_run_command(gc, domid, "xen-set-replication", args, NULL, NULL); +} + +int libxl__qmp_get_replication_error(libxl__gc *gc, int domid) +{ + return qmp_run_command(gc, domid, "xen-get-replication-error", NULL, + NULL, NULL); +} + +int libxl__qmp_do_checkpoint(libxl__gc *gc, int domid) +{ + return qmp_run_command(gc, domid, "xen-do-checkpoint", NULL, NULL, NULL); +} + +int libxl__qmp_stop_replication(libxl__gc *gc, int domid, bool primary) +{ + libxl__json_object *args = NULL; + + qmp_parameters_add_bool(gc, &args, "enable", false); + qmp_parameters_add_bool(gc, &args, "primary", primary); + + return qmp_run_command(gc, domid, "xen-set-replication", args, NULL, NULL); +} + +int libxl__qmp_nbd_server_stop(libxl__gc *gc, int domid) +{ + return qmp_run_command(gc, domid, "nbd-server-stop", NULL, NULL, NULL); +} + +int libxl__qmp_x_blockdev_change(libxl__gc *gc, int domid, const char *parent, + const char *child, const char *node) +{ + libxl__json_object *args = NULL; + + qmp_parameters_add_string(gc, &args, "parent", parent); + if (child) + qmp_parameters_add_string(gc, &args, "child", child); + if (node) + qmp_parameters_add_string(gc, &args, "node", node); + + return qmp_run_command(gc, domid, "x-blockdev-change", args, NULL, NULL); +} + +int libxl__qmp_hmp(libxl__gc *gc, int domid, const char *command_line) +{ + libxl__json_object *args = NULL; + + qmp_parameters_add_string(gc, &args, "command-line", command_line); + + return qmp_run_command(gc, domid, "human-monitor-command", args, + NULL, NULL); +} + int libxl__qmp_initializations(libxl__gc *gc, uint32_t domid, const libxl_domain_config *guest_config) { -- 2.30.2