From patchwork Thu Jan 16 09:36:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 11336425 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 54011921 for ; Thu, 16 Jan 2020 09:37:53 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 25B952075B for ; Thu, 16 Jan 2020 09:37:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="MpydKly0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 25B952075B Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1is1Zz-0006l8-Vx; Thu, 16 Jan 2020 09:36:43 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1is1Zz-0006kj-3B for xen-devel@lists.xenproject.org; Thu, 16 Jan 2020 09:36:43 +0000 X-Inumbo-ID: b1e1e786-3843-11ea-86d6-12813bfff9fa Received: from smtp-fw-33001.amazon.com (unknown [207.171.190.10]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b1e1e786-3843-11ea-86d6-12813bfff9fa; Thu, 16 Jan 2020 09:36:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1579167399; x=1610703399; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WlL6CEyevqCFHw9lFQaXcJPihFEM4SPg5uZQkHPtqrM=; b=MpydKly0uGXMHiLbLYtYtB5Yi9lzfUzi1I48v2j5IHfsgcayLhlFbfes eWeCi6DKkCOrxqvtcTA7ucef2t5TS2qitxnUbEFNzjpb3SczFwXxCco5+ Vbv3WKqh/2K2ikv3Ogr0HvlIU9Ls5B2eVu94Qm8cngQpZM0C/hkVosW4n Q=; IronPort-SDR: Bg4/Xo2A+Fb8n9qk4fxe5qCxQOGWo0/78eG5tzVpWjwXhfVLCXXOXcso/cXb4drIh3VbkdwZGY PLkaga5PptLw== X-IronPort-AV: E=Sophos;i="5.70,325,1574121600"; d="scan'208";a="20426712" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2b-5bdc5131.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 16 Jan 2020 09:36:39 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2b-5bdc5131.us-west-2.amazon.com (Postfix) with ESMTPS id 1E263A28C9; Thu, 16 Jan 2020 09:36:38 +0000 (UTC) Received: from EX13D32EUC002.ant.amazon.com (10.43.164.94) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Thu, 16 Jan 2020 09:36:26 +0000 Received: from EX13MTAUWA001.ant.amazon.com (10.43.160.58) by EX13D32EUC002.ant.amazon.com (10.43.164.94) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Thu, 16 Jan 2020 09:36:24 +0000 Received: from u2f063a87eabd5f.cbg10.amazon.com (10.125.106.135) by mail-relay.amazon.com (10.43.160.118) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Thu, 16 Jan 2020 09:36:22 +0000 From: Paul Durrant To: Date: Thu, 16 Jan 2020 09:36:02 +0000 Message-ID: <20200116093602.4203-7-pdurrant@amazon.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200116093602.4203-1-pdurrant@amazon.com> References: <20200116093602.4203-1-pdurrant@amazon.com> MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH v3 6/6] xl: allow domid to be preserved on save/restore or migrate X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Paul Durrant , Ian Jackson , Wei Liu Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" This patch adds a '-D' command line option to save and migrate to allow the domain id to be incorporated into the saved domain configuration and hence be preserved. Signed-off-by: Paul Durrant --- Cc: Ian Jackson Cc: Wei Liu v2: - Heavily re-worked based on new libxl_domain_create_info --- docs/man/xl.1.pod.in | 14 ++++++++++++++ tools/xl/xl.h | 1 + tools/xl/xl_cmdtable.c | 6 ++++-- tools/xl/xl_migrate.c | 15 ++++++++++----- tools/xl/xl_saverestore.c | 19 ++++++++++++++----- tools/xl/xl_vmcontrol.c | 3 ++- 6 files changed, 45 insertions(+), 13 deletions(-) diff --git a/docs/man/xl.1.pod.in b/docs/man/xl.1.pod.in index d4b5e8e362..937eda690f 100644 --- a/docs/man/xl.1.pod.in +++ b/docs/man/xl.1.pod.in @@ -490,6 +490,13 @@ Display huge (!) amount of debug information during the migration process. Leave the domain on the receive side paused after migration. +=item B<-D> + +Preserve the B in the domain coniguration that is transferred +such that it will be identical on the destination host, unless that +configuration is overridden using the B<-C> option. Note that it is not +possible to use this option for a 'localhost' migration. + =back =item B [I] I I @@ -692,6 +699,13 @@ Leave the domain running after creating the snapshot. Leave the domain paused after creating the snapshot. +=item B<-D> + +Preserve the B in the domain coniguration that is embedded in +the state file such that it will be identical when the domain is restored, +unless that configuration is overridden. (See the B operation +above). + =back =item B [I] diff --git a/tools/xl/xl.h b/tools/xl/xl.h index 2b4709efb2..06569c6c4a 100644 --- a/tools/xl/xl.h +++ b/tools/xl/xl.h @@ -99,6 +99,7 @@ struct save_file_header { #define SAVEFILE_BYTEORDER_VALUE ((uint32_t)0x01020304UL) void save_domain_core_begin(uint32_t domid, + int preserve_domid, const char *override_config_file, uint8_t **config_data_r, int *config_len_r); diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c index 3b302b2f20..08335394e5 100644 --- a/tools/xl/xl_cmdtable.c +++ b/tools/xl/xl_cmdtable.c @@ -153,7 +153,8 @@ struct cmd_spec cmd_table[] = { "[options] []", "-h Print this help.\n" "-c Leave domain running after creating the snapshot.\n" - "-p Leave domain paused after creating the snapshot." + "-p Leave domain paused after creating the snapshot.\n" + "-D Store the domain id in the configration." }, { "migrate", &main_migrate, 0, 1, @@ -167,7 +168,8 @@ struct cmd_spec cmd_table[] = { "-e Do not wait in the background (on ) for the death\n" " of the domain.\n" "--debug Print huge (!) amount of debug during the migration process.\n" - "-p Do not unpause domain after migrating it." + "-p Do not unpause domain after migrating it.\n" + "-D Preserve the domain id" }, { "restore", &main_restore, 0, 1, diff --git a/tools/xl/xl_migrate.c b/tools/xl/xl_migrate.c index 22f0429b84..0813beb801 100644 --- a/tools/xl/xl_migrate.c +++ b/tools/xl/xl_migrate.c @@ -176,7 +176,8 @@ static void migrate_do_preamble(int send_fd, int recv_fd, pid_t child, } -static void migrate_domain(uint32_t domid, const char *rune, int debug, +static void migrate_domain(uint32_t domid, int preserve_domid, + const char *rune, int debug, const char *override_config_file) { pid_t child = -1; @@ -187,7 +188,7 @@ static void migrate_domain(uint32_t domid, const char *rune, int debug, uint8_t *config_data; int config_len, flags = LIBXL_SUSPEND_LIVE; - save_domain_core_begin(domid, override_config_file, + save_domain_core_begin(domid, preserve_domid, override_config_file, &config_data, &config_len); if (!config_len) { @@ -537,13 +538,14 @@ int main_migrate(int argc, char **argv) char *rune = NULL; char *host; int opt, daemonize = 1, monitor = 1, debug = 0, pause_after_migration = 0; + int preserve_domid = 0; static struct option opts[] = { {"debug", 0, 0, 0x100}, {"live", 0, 0, 0x200}, COMMON_LONG_OPTS }; - SWITCH_FOREACH_OPT(opt, "FC:s:ep", opts, "migrate", 2) { + SWITCH_FOREACH_OPT(opt, "FC:s:epD", opts, "migrate", 2) { case 'C': config_filename = optarg; break; @@ -560,6 +562,9 @@ int main_migrate(int argc, char **argv) case 'p': pause_after_migration = 1; break; + case 'D': + preserve_domid = 1; + break; case 0x100: /* --debug */ debug = 1; break; @@ -596,7 +601,7 @@ int main_migrate(int argc, char **argv) pause_after_migration ? " -p" : ""); } - migrate_domain(domid, rune, debug, config_filename); + migrate_domain(domid, preserve_domid, rune, debug, config_filename); return EXIT_SUCCESS; } @@ -716,7 +721,7 @@ int main_remus(int argc, char **argv) } } - save_domain_core_begin(domid, NULL, &config_data, &config_len); + save_domain_core_begin(domid, 0, NULL, &config_data, &config_len); if (!config_len) { fprintf(stderr, "No config file stored for running domain and " diff --git a/tools/xl/xl_saverestore.c b/tools/xl/xl_saverestore.c index 9be033fe65..953d791d1a 100644 --- a/tools/xl/xl_saverestore.c +++ b/tools/xl/xl_saverestore.c @@ -32,6 +32,7 @@ #ifndef LIBXL_HAVE_NO_SUSPEND_RESUME void save_domain_core_begin(uint32_t domid, + int preserve_domid, const char *override_config_file, uint8_t **config_data_r, int *config_len_r) @@ -62,6 +63,8 @@ void save_domain_core_begin(uint32_t domid, fprintf(stderr, "unable to retrieve domain configuration\n"); exit(EXIT_FAILURE); } + + d_config.c_info.domid = preserve_domid ? domid : 0; } config_c = libxl_domain_config_to_json(ctx, &d_config); @@ -120,14 +123,15 @@ void save_domain_core_writeconfig(int fd, const char *source, hdr.optional_data_len); } -static int save_domain(uint32_t domid, const char *filename, int checkpoint, - int leavepaused, const char *override_config_file) +static int save_domain(uint32_t domid, int preserve_domid, + const char *filename, int checkpoint, + int leavepaused, const char *override_config_file) { int fd; uint8_t *config_data; int config_len; - save_domain_core_begin(domid, override_config_file, + save_domain_core_begin(domid, preserve_domid, override_config_file, &config_data, &config_len); if (!config_len) { @@ -236,15 +240,19 @@ int main_save(int argc, char **argv) const char *config_filename = NULL; int checkpoint = 0; int leavepaused = 0; + int preserve_domid = 0; int opt; - SWITCH_FOREACH_OPT(opt, "cp", NULL, "save", 2) { + SWITCH_FOREACH_OPT(opt, "cpD", NULL, "save", 2) { case 'c': checkpoint = 1; break; case 'p': leavepaused = 1; break; + case 'D': + preserve_domid = 1; + break; } if (argc-optind > 3) { @@ -257,7 +265,8 @@ int main_save(int argc, char **argv) if ( argc - optind >= 3 ) config_filename = argv[optind + 2]; - save_domain(domid, filename, checkpoint, leavepaused, config_filename); + save_domain(domid, preserve_domid, filename, checkpoint, leavepaused, + config_filename); return EXIT_SUCCESS; } diff --git a/tools/xl/xl_vmcontrol.c b/tools/xl/xl_vmcontrol.c index 39292acfe6..2e2d427492 100644 --- a/tools/xl/xl_vmcontrol.c +++ b/tools/xl/xl_vmcontrol.c @@ -899,7 +899,8 @@ start: autoconnect_console_how = 0; } - d_config.c_info.domid = domid_policy; + if (!libxl_domid_valid_guest(d_config.c_info.domid)) + d_config.c_info.domid = domid_policy; if ( restoring ) { libxl_domain_restore_params params;