From patchwork Wed Mar 23 08:06:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Changlong Xie X-Patchwork-Id: 8647631 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 8779FC0553 for ; Wed, 23 Mar 2016 08:06:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8489B203A5 for ; Wed, 23 Mar 2016 08:06:31 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6C2B12038D for ; Wed, 23 Mar 2016 08:06:30 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1aidmZ-0002BQ-00; Wed, 23 Mar 2016 08:04:47 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1aidmX-0001u5-D4 for xen-devel@lists.xen.org; Wed, 23 Mar 2016 08:04:45 +0000 Received: from [193.109.254.147] by server-3.bemta-14.messagelabs.com id 5C/B7-03304-D1E42F65; Wed, 23 Mar 2016 08:04:45 +0000 X-Env-Sender: xiecl.fnst@cn.fujitsu.com X-Msg-Ref: server-5.tower-27.messagelabs.com!1458720265!33319081!10 X-Originating-IP: [59.151.112.132] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.11; banners=-,-,- X-VirusChecked: Checked Received: (qmail 54207 invoked from network); 23 Mar 2016 08:04:44 -0000 Received: from cn.fujitsu.com (HELO heian.cn.fujitsu.com) (59.151.112.132) by server-5.tower-27.messagelabs.com with SMTP; 23 Mar 2016 08:04:44 -0000 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="4882448" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 23 Mar 2016 16:04:39 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id A5B6C408D264; Wed, 23 Mar 2016 16:04:38 +0800 (CST) Received: from changlox.g08.fujitsu.local (10.167.225.55) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.279.2; Wed, 23 Mar 2016 16:04:38 +0800 From: Changlong Xie To: xen devel , Konrad Rzeszutek Wilk , Andrew Cooper , Ian Campbell , Ian Jackson , Wei Liu Date: Wed, 23 Mar 2016 16:06:32 +0800 Message-ID: <1458720400-4699-19-git-send-email-xiecl.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1458720400-4699-1-git-send-email-xiecl.fnst@cn.fujitsu.com> References: <1458720400-4699-1-git-send-email-xiecl.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.225.55] X-yoursite-MailScanner-ID: A5B6C408D264.A1CF5 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xiecl.fnst@cn.fujitsu.com X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Cc: Lars Kurth , Changlong Xie , Wen Congyang , Li Zhijian , Gui Jianfeng , Jiang Yunhong , Dong Eddie , Anthony Perard , Shriram Rajagopalan , Yang Hongyang Subject: [Xen-devel] [PATCH v12 18/26] COLO: introduce new API to prepare/start/do/get_error/stop replication X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Wen Congyang 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 e4b237f..d6ca232 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1771,6 +1771,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 c0bdfcb..3eb279a 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) {