From patchwork Tue Dec 5 06:53:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 844608 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yrXnF4Phcz9sBZ for ; Tue, 5 Dec 2017 18:05:05 +1100 (AEDT) Received: from localhost ([::1]:46886 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eM7Hq-0002Mo-88 for incoming@patchwork.ozlabs.org; Tue, 05 Dec 2017 02:05:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51714) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eM781-0000jH-An for qemu-devel@nongnu.org; Tue, 05 Dec 2017 01:54:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eM780-00042S-D5 for qemu-devel@nongnu.org; Tue, 05 Dec 2017 01:54:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52666) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eM780-000421-4B for qemu-devel@nongnu.org; Tue, 05 Dec 2017 01:54:52 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 41F055D68C; Tue, 5 Dec 2017 06:54:51 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-111.nay.redhat.com [10.66.14.111]) by smtp.corp.redhat.com (Postfix) with ESMTP id DFE0862461; Tue, 5 Dec 2017 06:54:48 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 5 Dec 2017 14:53:05 +0800 Message-Id: <20171205065307.21853-27-peterx@redhat.com> In-Reply-To: <20171205065307.21853-1-peterx@redhat.com> References: <20171205065307.21853-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 05 Dec 2017 06:54:51 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 26/28] migration: allow migrate_cancel to pause postcopy X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrea Arcangeli , Juan Quintela , Alexey Perevalov , peterx@redhat.com, "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" It was allowed in the past to even cancel a postcopy migration, but it does not really make sense, and no one should be using it, since cancelling a migration during postcopy means crashing the VM at no time. Let's just use re-use this command as a way to pause the postcopy migration when we detected that we are in postcopy migration. This can be used when we want to trigger the postcopy recovery manually. Signed-off-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert --- hmp-commands.hx | 8 ++++++-- migration/migration.c | 18 +++++++++++++++++- qapi/migration.json | 3 ++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/hmp-commands.hx b/hmp-commands.hx index ffcdc34652..32fdd52212 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -952,14 +952,18 @@ ETEXI .name = "migrate_cancel", .args_type = "", .params = "", - .help = "cancel the current VM migration", + .help = "cancel the current VM precopy migration, or " + "pause the migration if it's in postcopy state, " + "so that a postcopy recovery can be carried out later.", .cmd = hmp_migrate_cancel, }, STEXI @item migrate_cancel @findex migrate_cancel -Cancel the current VM migration. +If during a precopy, this command cancels the migration. If during +postcopy, this command pauses the migration (so that a postcopy +recovery can be carried out afterward). ETEXI { diff --git a/migration/migration.c b/migration/migration.c index 8762fad9be..0c1a783df2 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1535,7 +1535,23 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk, void qmp_migrate_cancel(Error **errp) { - migrate_fd_cancel(migrate_get_current()); + MigrationState *ms = migrate_get_current(); + int ret; + + if (ms->state == MIGRATION_STATUS_POSTCOPY_ACTIVE) { + /* + * Cancelling a postcopy migration does not really make sense. + * Here instead we pause the migration only, so another + * recovery can take place if needed. + */ + ret = qemu_file_shutdown(ms->to_dst_file); + if (ret) { + error_setg(errp, "Failed to pause migration stream."); + } + return; + } + + migrate_fd_cancel(ms); } void qmp_migrate_continue(MigrationStatus state, Error **errp) diff --git a/qapi/migration.json b/qapi/migration.json index 5dfac0681d..e15bb516cd 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -881,7 +881,8 @@ ## # @migrate_cancel: # -# Cancel the current executing migration process. +# Cancel the current executing migration process for precopy. For +# postcopy, it'll pause the migration instead. # # Returns: nothing on success #