From patchwork Thu Jan 9 11:48:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 11325513 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 D9A92921 for ; Thu, 9 Jan 2020 11:50:02 +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 A9EF52072A for ; Thu, 9 Jan 2020 11:50:02 +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="kFaGD3f3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A9EF52072A 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 1ipWIt-0000J8-W8; Thu, 09 Jan 2020 11:48:43 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ipWIt-0000Ir-Al for xen-devel@lists.xenproject.org; Thu, 09 Jan 2020 11:48:43 +0000 X-Inumbo-ID: fb254460-32d5-11ea-a2eb-bc764e2007e4 Received: from smtp-fw-2101.amazon.com (unknown [72.21.196.25]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id fb254460-32d5-11ea-a2eb-bc764e2007e4; Thu, 09 Jan 2020 11:48:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1578570521; x=1610106521; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WlL6CEyevqCFHw9lFQaXcJPihFEM4SPg5uZQkHPtqrM=; b=kFaGD3f3UTfmRx0YrMuMMyUqKBEgBBUyOIbHmS74ynSGmUfyQsDsLY5/ tMRlUzrClQqbxTNGZqcncVEFR94nFbyT94t6eJOnpH3xFEkMeosgKMAIY J0sw0Z49Fe4ihYWV/AXaS3uMJOrBr+qoicv5fr5kqPbdVNboJV0Eb7+43 c=; IronPort-SDR: 6nFZDSwNz2srjnlzpFxzpvb5Ubnf/gI8mwuhtMpZ0wdE9ajq1O4N6hkSqbuy4FYHmEigqWJZ1o ilcAxLX2bWPg== X-IronPort-AV: E=Sophos;i="5.69,413,1571702400"; d="scan'208";a="11662437" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-1a-715bee71.us-east-1.amazon.com) ([10.43.8.2]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP; 09 Jan 2020 11:48:40 +0000 Received: from EX13MTAUEA001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1a-715bee71.us-east-1.amazon.com (Postfix) with ESMTPS id 5E95DA25DF; Thu, 9 Jan 2020 11:48:39 +0000 (UTC) Received: from EX13D32EUC003.ant.amazon.com (10.43.164.24) by EX13MTAUEA001.ant.amazon.com (10.43.61.243) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Thu, 9 Jan 2020 11:48:38 +0000 Received: from EX13MTAUWC001.ant.amazon.com (10.43.162.135) by EX13D32EUC003.ant.amazon.com (10.43.164.24) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Thu, 9 Jan 2020 11:48:37 +0000 Received: from u2f063a87eabd5f.cbg10.amazon.com (10.125.106.135) by mail-relay.amazon.com (10.43.162.232) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Thu, 9 Jan 2020 11:48:35 +0000 From: Paul Durrant To: Date: Thu, 9 Jan 2020 11:48:16 +0000 Message-ID: <20200109114816.2293-7-pdurrant@amazon.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200109114816.2293-1-pdurrant@amazon.com> References: <20200109114816.2293-1-pdurrant@amazon.com> MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH v2 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;