From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C3C98CA0FE9 for ; Tue, 26 Aug 2025 11:53:09 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uqsDw-0007iF-Rl; Tue, 26 Aug 2025 07:52:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uqsDu-0007ho-JH for qemu-devel@nongnu.org; Tue, 26 Aug 2025 07:52:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uqsDn-0003c2-Gw for qemu-devel@nongnu.org; Tue, 26 Aug 2025 07:52:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1756209129; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=02ZPVdKLPGjLdOoH53kzE+YabXZCibh9LvP7UVsLn7c=; b=Me3TnjzzZvbcGX42Ac/+FcBY5XmRNZTEGk6KwkhUHA4kvmdponpkoi6vSeOrzO6IOz1mJY CI7AVgWnY6u1S7JMkRwy7uVC2OFYcqITjkO0JQh99rmzB3foeYTj/pfn4g60HLyigGKvPa exy29grecVClR45u+7s+uuTabPKLkv8= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-606-fPl32wrXPpyGWafcYM0aWw-1; Tue, 26 Aug 2025 07:52:03 -0400 X-MC-Unique: fPl32wrXPpyGWafcYM0aWw-1 X-Mimecast-MFC-AGG-ID: fPl32wrXPpyGWafcYM0aWw_1756209122 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 37C3A1955F28; Tue, 26 Aug 2025 11:52:02 +0000 (UTC) Received: from fedora (unknown [10.43.3.60]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 050E130001A2; Tue, 26 Aug 2025 11:51:59 +0000 (UTC) From: Juraj Marcin To: qemu-devel@nongnu.org Cc: Juraj Marcin , Fabiano Rosas , Peter Xu , qemu-stable@nongnu.org Subject: [PATCH] migration: Fix state transition in postcopy_start() error handling Date: Tue, 26 Aug 2025 13:51:40 +0200 Message-ID: <20250826115145.871272-1-jmarcin@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass client-ip=170.10.133.124; envelope-from=jmarcin@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Juraj Marcin Commit 48814111366b ("migration: Always set DEVICE state") introduced DEVICE state to postcopy, which moved the actual state transition that leads to POSTCOPY_ACTIVE. However, the error handling part of the postcopy_start() function still expects the state POSTCOPY_ACTIVE, but depending on where an error happens, now the state can be either ACTIVE, DEVICE or CANCELLING, but never POSTCOPY_ACTIVE, as this transition now happens just before a successful return from the function. Instead, accept any state except CANCELLING when transitioning to FAILED state. Cc: qemu-stable@nongnu.org Fixes: 48814111366b ("migration: Always set DEVICE state") Signed-off-by: Juraj Marcin --- In the RFC[1] where this patch was discussed, there was also a suggestion for a helper function migrate_set_failure() that would check if the state is not CANCELLING and then set migration error and FAILED state. I discussed the implementation with Peter, and we came to a conclusion that instead of patching such clean-up on top of the current error handling code, it might be more useful to do a larger refactor and clean-up of all error handling in the migration code. Such clean-up should reduce the number of places where we need to explicitly transition to a FAILED state (ideally to one, or only a couple of places), and instead only set an appropriate migration error using migrate_set_error(). Additionally, it would also refactor inappropriate uses of QEMUFile errors where the error is not really an error of the underlying channel and migrate_set_error() should be used instead. [1]: https://lore.kernel.org/all/20250807114922.1013286-3-jmarcin@redhat.com/ --- migration/migration.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 10c216d25d..32b8ce5613 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2872,8 +2872,9 @@ static int postcopy_start(MigrationState *ms, Error **errp) fail_closefb: qemu_fclose(fb); fail: - migrate_set_state(&ms->state, MIGRATION_STATUS_POSTCOPY_ACTIVE, - MIGRATION_STATUS_FAILED); + if (ms->state != MIGRATION_STATUS_CANCELLING) { + migrate_set_state(&ms->state, ms->state, MIGRATION_STATUS_FAILED); + } migration_block_activate(NULL); migration_call_notifiers(ms, MIG_EVENT_PRECOPY_FAILED, NULL); bql_unlock(); -- 2.50.1