From nobody Sun Sep 28 17:06:28 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1757520214; cv=none; d=zohomail.com; s=zohoarc; b=cuv6gLziP/MpGmr1eWUxuhBQzTuTrwPSxI7p5xsMcXDgmqSHUN3E6U2xAsQbv55grfaLwD087d5M0vBqSXlMlPNPWfuXSIoZbS2TdBqDxC9CB1ompmiqv1cOXJU6aHn+tsFTTUwdv2Y8373QGwI9dhimVpn4whqSJwr7CUHSjgo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757520214; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8p45ZSRefEV6HYOFhbXSS9og5rhg3/fjfKNb+/N5nuk=; b=TZRVaKXFwc6F7SFzdgptdoxmAufoTgfGLlDu+0Yo9iJR1cEJx6mMPkfkv/hMTdzIqTThmK6J48WCfFmm/lN0MGwBjeQKbpGfgY1fc/q4A4sxAIUFUSeKUmjqOOnH+LDZLbCMk+mKM84sLbKX89ig6OKDcweD666j9SWgDcb0OZU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1757520214355984.1360660468057; Wed, 10 Sep 2025 09:03:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwNHD-0003VK-Mo; Wed, 10 Sep 2025 12:02:31 -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 1uwNGr-0003AO-Nj for qemu-devel@nongnu.org; Wed, 10 Sep 2025 12:02:15 -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 1uwNGp-0004Vc-2w for qemu-devel@nongnu.org; Wed, 10 Sep 2025 12:02:09 -0400 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-2-1EeEGBzkPLqts47_5pHr8Q-1; Wed, 10 Sep 2025 12:02:01 -0400 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-7fff4abc97cso1772649985a.1 for ; Wed, 10 Sep 2025 09:02:01 -0700 (PDT) Received: from x1.com ([174.89.135.121]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4b61bbe0a85sm26655281cf.42.2025.09.10.09.01.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Sep 2025 09:01:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757520123; 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: in-reply-to:in-reply-to:references:references; bh=8p45ZSRefEV6HYOFhbXSS9og5rhg3/fjfKNb+/N5nuk=; b=ddM4K+0e3x7quWbroo5TyWEBD/IpyL5cDSWCzMuwfGkb5AYper1N9pT7tRN8rgDgozbqEV 03Ufwn7dEL44FGQp5XVLDizd8L4tHrPwqNzFkNCksdpoG1cJfpeG8nqmCVNsSeJ0BUYApR OG/EBGdBw4DTQp0RezJPH6JpCjWSkX4= X-MC-Unique: 1EeEGBzkPLqts47_5pHr8Q-1 X-Mimecast-MFC-AGG-ID: 1EeEGBzkPLqts47_5pHr8Q_1757520121 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757520120; x=1758124920; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8p45ZSRefEV6HYOFhbXSS9og5rhg3/fjfKNb+/N5nuk=; b=uJ/Vu5MyEL+h8AcmV8duV/abWSEi1jFJ9ivAeEPtmwB7wgQkTL/MClgzMTnGYNgtPG JYIDAg1DLY/ZosDF7sqZkZGu+BYQXwd2DW/Q9ytPpW3Pdbap64lbsVDR/bQysfqm53sM laXUovdlzTkJrYPIVRTZCiLr9JpsMD8JTIRLc4mgh4nzbnPNUJWWQ74RBfFE2wKY/Hrz ZWj5njNZqSLkaL368/dJt/mSefk+PQkILVQVDVyjQh6CLIfeYlilKPMo33rafUcpxd4U 8RICv7Z4Gd2YfDhB/m2PNqbrw792IIrczHlXiTaxc/zOBrvHUxik0eugiYPgLZfFdsEt HW3Q== X-Gm-Message-State: AOJu0YzR6zi94IDd8Ig+/FCY5MDz6EV7GCgcY3QdK9Al0epm4qiNgsQ4 gfBZEcdeS8lFyH9y4SivdskORA6KaPFH0cNDoSkzlCXbOnklr97NNr5Gg6/DYJhY+41ZJwMsFwl bNtDJynq4FiSPy2mKKGdNI9u6S3ohditfCXoAqS4GebDwUExCBaRMeZE2OsUtV2Elp77R0v/14t 5yIIY0mSwUAfJ0OVKgz1zmALCMVGGdWUgIe9KSjA== X-Gm-Gg: ASbGncv+umYukGBxLfx+LjSBM3dt6aHinKJIiCqyXyXej7zUfQ6XVfOM6kubSwqyB9f PTUhMAej1vKcSDkieIQ53cIN5gStr8raYptM5q13qal22T40z1Dg0jsfn4t8+XSdGlcnI/5NGkJ /JmTey0iQc55dJnhWqnbI5C5xU2kc1JOFExU1jq6OqVke/K9rRJi/UJd9LtcWo4LVq8HaPzY6ta YJUjiraCnU9eMit21HSCgj4VHRpth8mmvOzBQkftAckRTR1lDvSEmQJ2P1fAzdbwGR5m4kxxCvK 26kSZWfRwUyqeLqQDXvhA1JQmR/gpQ== X-Received: by 2002:a05:620a:319c:b0:81f:f2aa:70ee with SMTP id af79cd13be357-81ff2ab173fmr16118385a.76.1757520120007; Wed, 10 Sep 2025 09:02:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGAY6gOHFyMYhlvAF6R9jjrSu6CnVNrLrTw5GRFwXnhj/qWNhZGXiqGlfdaVoBvgTDD39rbgA== X-Received: by 2002:a05:620a:319c:b0:81f:f2aa:70ee with SMTP id af79cd13be357-81ff2ab173fmr16108085a.76.1757520118869; Wed, 10 Sep 2025 09:01:58 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Juraj Marcin , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Fabiano Rosas , Xiaohui Li Subject: [PATCH 1/3] migration/tls: Gracefully shutdown main and preempt channels Date: Wed, 10 Sep 2025 12:01:42 -0400 Message-ID: <20250910160144.1762894-2-peterx@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250910160144.1762894-1-peterx@redhat.com> References: <20250910160144.1762894-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1757520215221116600 Content-Type: text/plain; charset="utf-8" QEMU supported graceful shutdowns for multifd channels starting from commit 48796f6b44 ("migration/multifd: Terminate the TLS connection"). Then error check was enabled for premature TLS terminations. Now if we run the preempt TLS unit test, the test would pass, but there will be a warning reported: qemu-system-x86_64: Cannot read from TLS channel: The TLS connection was no= n-properly terminated. ok 1 /x86_64/migration/postcopy/preempt/tls/psk To fix it, make the rest channels to be gracefully terminated too when it's a TLS channel. One note is that the qemufile helper needs to be in migration.c not qemu-file.c, because qemu-file.c will be linked in unit tests, which will not link channel.c unfortunately. Reported-by: Xiaohui Li Signed-off-by: Peter Xu --- migration/channel.h | 3 +++ migration/migration.h | 2 ++ migration/channel.c | 13 +++++++++++++ migration/migration.c | 24 +++++++++++++++++++++++- 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/migration/channel.h b/migration/channel.h index 5bdb8208a7..0b25dd7c5b 100644 --- a/migration/channel.h +++ b/migration/channel.h @@ -29,4 +29,7 @@ int migration_channel_read_peek(QIOChannel *ioc, const char *buf, const size_t buflen, Error **errp); + +bool migration_channel_shutdown_gracefully(QIOChannel *c, Error **errp); + #endif diff --git a/migration/migration.h b/migration/migration.h index 01329bf824..b5763af057 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -594,4 +594,6 @@ void migration_bitmap_sync_precopy(bool last_stage); void dirty_bitmap_mig_init(void); bool should_send_vmdesc(void); =20 +bool qemu_file_shutdown_gracefully(QEMUFile *f, Error **errp); + #endif diff --git a/migration/channel.c b/migration/channel.c index a547b1fbfe..1ae839e5fe 100644 --- a/migration/channel.c +++ b/migration/channel.c @@ -145,3 +145,16 @@ int migration_channel_read_peek(QIOChannel *ioc, =20 return 0; } + +/* + * This is only needed for a successful migration, no-op for non-TLS + * channels. For unexpected interruptions, use qio_channel_shutdown(). + */ +bool migration_channel_shutdown_gracefully(QIOChannel *c, Error **errp) +{ + if (object_dynamic_cast((Object *)c, TYPE_QIO_CHANNEL_TLS)) { + qio_channel_tls_bye(QIO_CHANNEL_TLS(c), errp); + } + + return *errp =3D=3D NULL; +} diff --git a/migration/migration.c b/migration/migration.c index 10c216d25d..7015c2b5e0 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -113,6 +113,27 @@ static bool close_return_path_on_source(MigrationState= *s); static void migration_completion_end(MigrationState *s); static void migrate_hup_delete(MigrationState *s); =20 +/* + * See migration_channel_shutdown_gracefully(). The "graceful" versions + * are only needed if migration succeeded. + */ +bool qemu_file_shutdown_gracefully(QEMUFile *f, Error **errp) +{ + int ret; + + if (!migration_channel_shutdown_gracefully(qemu_file_get_ioc(f), errp)= ) { + return false; + } + + ret =3D qemu_file_shutdown(f); + if (ret) { + error_setg_errno(errp, -ret, "qemu_file_shutdown() failed"); + return false; + } + + return true; +} + static void migration_downtime_start(MigrationState *s) { trace_vmstate_downtime_checkpoint("src-downtime-start"); @@ -2473,11 +2494,12 @@ static void migration_release_dst_files(MigrationSt= ate *ms) */ if (ms->postcopy_qemufile_src) { migration_ioc_unregister_yank_from_file(ms->postcopy_qemufile_src); - qemu_file_shutdown(ms->postcopy_qemufile_src); + qemu_file_shutdown_gracefully(ms->postcopy_qemufile_src, &error_wa= rn); qemu_fclose(ms->postcopy_qemufile_src); ms->postcopy_qemufile_src =3D NULL; } =20 + qemu_file_shutdown_gracefully(file, &error_warn); qemu_fclose(file); } =20 --=20 2.50.1 From nobody Sun Sep 28 17:06:28 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1757520206; cv=none; d=zohomail.com; s=zohoarc; b=PuO/2Cya2o8NylC3pbjQwiXYjj/FhR9fYFqg6Sgn7psHR19iQWS4hU5/h9Nr5EnrJOUtaOmbJ4VqtaOpfgt3ljGDTHYMDc3+aac2AFEjZEfZVywsZFfIXxds+ZmEhnI8RUGFlxHLpBknIPhgQrjqZX1V10om7LQ4BlJTk81/c+w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757520206; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Pk2p/fZ62GE+HVK96dUx6wUZhpLCmZYAlpZ+g5YJz3U=; b=HbYK4jYmZmwy1luTVHVGnYkf6b0Lk0JdgNRTsK6yfr/Uq+dGDF6IQyXwgD6QKAQBmoIWgSCo58KAqmDcNUkVNEw+D73GJoo1VDq0cLolh3P5PU32UEnZpPc5LE2Z00ygWR/6MHXvAGM+EfxmicQWS1WdiQOb6FMu2AKb3moi3Ac= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1757520206332398.57133014219016; Wed, 10 Sep 2025 09:03:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwNHD-0003VO-SS; Wed, 10 Sep 2025 12:02:31 -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 1uwNGr-0003AL-DG for qemu-devel@nongnu.org; Wed, 10 Sep 2025 12:02:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uwNGo-0004Vs-6B for qemu-devel@nongnu.org; Wed, 10 Sep 2025 12:02:09 -0400 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-681-qt1OKEMJOa6zm2FYoEVGSg-1; Wed, 10 Sep 2025 12:02:03 -0400 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-7ff94e5c251so225352385a.1 for ; Wed, 10 Sep 2025 09:02:03 -0700 (PDT) Received: from x1.com ([174.89.135.121]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4b61bbe0a85sm26655281cf.42.2025.09.10.09.01.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Sep 2025 09:01:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757520125; 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: in-reply-to:in-reply-to:references:references; bh=Pk2p/fZ62GE+HVK96dUx6wUZhpLCmZYAlpZ+g5YJz3U=; b=iXQ+jE+CAAaH8qRrVcZnGiyIFkTM+mQzPwXDT+cyw0QuiILrlqKfMo+tAg93hdEuqB6SSr l3Ej6nCw0+rJkS1Mam2Rc8xVx0bCJoLLO8S0INUiPWl9EHovwZl8wt0fSSkeCZW/f1f6hB DvuYA2PL5t2buLCkOZzwntcmf1NCoKo= X-MC-Unique: qt1OKEMJOa6zm2FYoEVGSg-1 X-Mimecast-MFC-AGG-ID: qt1OKEMJOa6zm2FYoEVGSg_1757520122 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757520122; x=1758124922; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Pk2p/fZ62GE+HVK96dUx6wUZhpLCmZYAlpZ+g5YJz3U=; b=ZeCpm9JUnQrGxgSFNKg3UDTXor3EDbWKkcIXAXkNI/pRigHzCODuT2XFUf//vUecnk vlwqaVfVUQGrT8PBUP4HY+sGR8ZomhBIqF7zflcUT7y4xs7XG73hT9P5LhlQRnzxj6L2 Rqsa5tmA7uUza8OIrB1hU3YZYTHUFTt/34zeNnF1cG46hZSWCXiUv+cRwnwxb7UyPLaV xPPei2uZL0K17uJcThdZsCJ2lSGRmqpwVjxUCN6RFIY6/iJtkqSYxwvj5h/URjpvv0KZ QsRYwvbhsx7UDdY6P1/mA9xV37oqmmuHVepov4Mg80M0NDRA0OyMnsbxHd5CMwBNOVdt HPug== X-Gm-Message-State: AOJu0Yy8k5z/SxgtUBUQKc1la0wPoHIGclesm47tsPbY7Xvx8OB1smCp bt2Tx8vIX7x3ndHmVNJpVPOZ+OBEtslQbh/o3evfhomla4xI/DMLMNh+aU4n/2uzGng9PwjxM8h LypwjUMHz2JqCYLUo7mSDrm+bo1Rp5pRMpCd/8+VVHPhjXVOoJmZ/pqUA7OVHoI6MT96uFiRTfp z+RZFkOs0GKzj1D00jYuOpKVtFN7HYFKFEXQ+P0w== X-Gm-Gg: ASbGncuZLgXNceO/i7IKFQXIQkI4iR6Rh5BdzBeNrD17z2udoeR/T8TOwtLLfgt9U8S Bckq4YYwLuGg5g1WkrTZS5GvIttIMpjwcG6e3wuWtREIkhRWgb99zjt6gqvGPo4rv8DPmazKRpc K2xhsFFbKB5VUtsPI4as76Rbq1hNxWhmx2IR4jgAaE8yt+iAJsZzv/OhtU4i8xxp6AxHK3jZzXn 0fVmjD82WLeJoN5EyfUGul/8KDhBYmEJQT0IQadIn1TNG1f5Fwx+MOehja0DgUlPi529qtacmKD odkebe6XzKokX6d5R30nhM/Oh7HDmA== X-Received: by 2002:a05:620a:414f:b0:7e8:8f35:1d2b with SMTP id af79cd13be357-81ff181374emr16849285a.2.1757520122065; Wed, 10 Sep 2025 09:02:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEQx2xOVSmqUjrjn0K0j5L7e36/Uc3be7+P8Puidgf2AUD9TXTqBozLNygj0SCKXPJhPx9Veg== X-Received: by 2002:a05:620a:414f:b0:7e8:8f35:1d2b with SMTP id af79cd13be357-81ff181374emr16832185a.2.1757520119930; Wed, 10 Sep 2025 09:01:59 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Juraj Marcin , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Fabiano Rosas Subject: [PATCH 2/3] migration: Make migration_has_failed() work even for CANCELLING Date: Wed, 10 Sep 2025 12:01:43 -0400 Message-ID: <20250910160144.1762894-3-peterx@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250910160144.1762894-1-peterx@redhat.com> References: <20250910160144.1762894-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1757520207095116601 Content-Type: text/plain; charset="utf-8" We set CANCELLED very late, it means migration_has_failed() may not work correctly if it's invoked before updating CANCELLING to CANCELLED. Allow that state will make migration_has_failed() working as expected even if it's invoked slightly earlier. One current user is the multifd code for the TLS graceful termination, where it's before updating to CANCELLED. Signed-off-by: Peter Xu --- migration/migration.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/migration/migration.c b/migration/migration.c index 7015c2b5e0..397917b1b3 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1723,7 +1723,8 @@ int migration_call_notifiers(MigrationState *s, Migra= tionEventType type, =20 bool migration_has_failed(MigrationState *s) { - return (s->state =3D=3D MIGRATION_STATUS_CANCELLED || + return (s->state =3D=3D MIGRATION_STATUS_CANCELLING || + s->state =3D=3D MIGRATION_STATUS_CANCELLED || s->state =3D=3D MIGRATION_STATUS_FAILED); } =20 --=20 2.50.1 From nobody Sun Sep 28 17:06:28 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1757522361; cv=none; d=zohomail.com; s=zohoarc; b=C7mgFTRE7WFmItu554StWxz3zPLeqbwpgZjMhYaJ1rI3qbdjk1lq/dIxNAQKsYTJT10cfRwGf5YhAKULI2lDQLqLwMxquF6OQdKLk83PR+Hub/wQzs/2RX0B9IZVpPsWYsIc3gANuw8AneTWG1H+LwYhSqfY1kWVuTOBpPEHjjs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757522361; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=jsJ6uWuRVz9mme6Px6mGxd6bZciJc7GE+WQ3P+OnGj4=; b=ljY/bVI5Mer8uNyNYZ07mRQe39aGeyNNPPC6/szSLDrMGJ4CRFLXEQoPtKVh1LrYMjUjNC80ugW+vN2yMZ6p5yeU55/peNxDecDbV4uafgmhOT1kya3BE0X9oLRRnrxH821ap0HhfZcCqri3pVvan031uJwHGo5V/5wGURv//lA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 175752236175077.65284165880792; Wed, 10 Sep 2025 09:39:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwNHI-0003bM-8U; Wed, 10 Sep 2025 12:02:36 -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 1uwNGs-0003AY-0a for qemu-devel@nongnu.org; Wed, 10 Sep 2025 12:02:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uwNGp-0004Vz-VQ for qemu-devel@nongnu.org; Wed, 10 Sep 2025 12:02:09 -0400 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-549-hxh20QKjM_alN2jffMYnyQ-1; Wed, 10 Sep 2025 12:02:05 -0400 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-4b47b4d296eso169645701cf.1 for ; Wed, 10 Sep 2025 09:02:05 -0700 (PDT) Received: from x1.com ([174.89.135.121]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4b61bbe0a85sm26655281cf.42.2025.09.10.09.02.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Sep 2025 09:02:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757520126; 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: in-reply-to:in-reply-to:references:references; bh=jsJ6uWuRVz9mme6Px6mGxd6bZciJc7GE+WQ3P+OnGj4=; b=Oz7tl68GBNbwZmHZcvsGMcyHbToLgLP1neIM8xEhNm0JK9fBIY/J3PeAL3lhDkjbCe7BLW 58DI2dd2JyLebu+x8XlnDZVi+yhkDGDJ8q0XjqxGRGeWqpTiz/uu1iWSYlKSxDTL9Wq+DH z8DGugSKlcscTOUEPP0zZUUSXLImp2M= X-MC-Unique: hxh20QKjM_alN2jffMYnyQ-1 X-Mimecast-MFC-AGG-ID: hxh20QKjM_alN2jffMYnyQ_1757520125 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757520124; x=1758124924; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jsJ6uWuRVz9mme6Px6mGxd6bZciJc7GE+WQ3P+OnGj4=; b=SiGTszDgo0gApfp0nkFnPGRNerU1kAoylUPQjeR7/Kkd6pn3lH/CrdqR3A1wFcj8vi IsiSqWSYs073fc5PoBb6Ogk8198QWpWgjJoNwddnqyWcuWfs8deCsWqaEU8/DQlMbcme GxwMAqpQY2KnNwUy76jCc1yuJXygzSHUq+Kn2XaffxwqgOCpwDvvT+vcvkl+wX3v0rmo +Di/ADWU/MWb0xhb2HYNRxpkd3ttP4HFHceIR+jkSQqDDa1MgnBvcwce2MagcPaHDEZC mcpNseGt1J9s1AgOYAKamFD6qOUkiKO4WQ9a6KU2UVgtXG3Lx8Y8B1654AEm+vaT7xLn rJGQ== X-Gm-Message-State: AOJu0Yyw6zITtxHJcMWE/R+1HJmMotd0gmRpS9Vyb01py3Ibttk4iLy/ WTTZ89SJ8hnQ+t20icqviLJxhm1q8iezl1TcgZYsZeMIZs5taxfH2mP+7jYL06Aaby7YfOx/f2o nMbJmwfC0Gku4yIoxtuC7dullMhGThW9Gz1aNn0HIkSrFbjf07eINa5ob4oMBpg93m9+Ghx08NW PzBTwB3X84Dufemg34kgPdO5itNX/51rmZ32OjWw== X-Gm-Gg: ASbGnctNnwDOeb2hJ1EmyWcKqUEH5YRYii9lDkln2vBuXF8gwbvlfMLezzCmDD5VHhv W2WUmeAJVfybqhvOYBJLObopz61Oy7Co9xtLbozHid/F9ZPn8ZWZOdnQyGgxKMJsy5spdiyosM8 McnEKQg24XhQefATrI1TFiksAyrpY4D+9ZQyajf5Qi/ZKceI0+PTSULJbgRAQ3mxdOEAWL4KudZ 9sEc0idriprp0NCeYuFQRYqeOSvj64e3XmvEeKwILdkri+xBxDeIUm4Mmkj8sWnHueMtzVnxCf0 wFxajVvEb0Jd7Vnpkvo/CBzK0FtwDg== X-Received: by 2002:a05:622a:5e0e:b0:4b6:144:faf3 with SMTP id d75a77b69052e-4b60144fc88mr98421271cf.30.1757520124049; Wed, 10 Sep 2025 09:02:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG5R2jBx42YgW4YgzFXkBFBkE3E17Jp840MW0gjhmmebGf2ZG0Jp9VZPOeQNkn4E37F0QmiOA== X-Received: by 2002:a05:622a:5e0e:b0:4b6:144:faf3 with SMTP id d75a77b69052e-4b60144fc88mr98420631cf.30.1757520123086; Wed, 10 Sep 2025 09:02:03 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Juraj Marcin , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Fabiano Rosas Subject: [PATCH 3/3] migration/multifd: Use the new graceful termination helper Date: Wed, 10 Sep 2025 12:01:44 -0400 Message-ID: <20250910160144.1762894-4-peterx@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250910160144.1762894-1-peterx@redhat.com> References: <20250910160144.1762894-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1757522363798116600 Content-Type: text/plain; charset="utf-8" Multifd has a separate loop to do TLS terminations gracefully. Meanwhile, it depends on two variables which records thread creations. It works perfectly before, however relying on "whether some threads are created" flag might be not as straightforward to decide a graceful shutdown. Since we'll need to dynamically identify TLS channels anyway with the new helper (which is needed for main and postcopy channels), use the same simple API for multifd channels too. Also, we only need graceful shutdown on success of migrations. With that, we can remove the loop and drop migration_tls_channel_end(). The comment there is still a good explanation, move it over to the new helper instead. Signed-off-by: Peter Xu --- migration/tls.h | 1 - migration/channel.c | 7 +++++++ migration/multifd.c | 40 +++++++--------------------------------- migration/tls.c | 5 ----- 4 files changed, 14 insertions(+), 39 deletions(-) diff --git a/migration/tls.h b/migration/tls.h index 58b25e1228..75c918e156 100644 --- a/migration/tls.h +++ b/migration/tls.h @@ -36,7 +36,6 @@ void migration_tls_channel_connect(MigrationState *s, QIOChannel *ioc, const char *hostname, Error **errp); -void migration_tls_channel_end(QIOChannel *ioc, Error **errp); /* Whether the QIO channel requires further TLS handshake? */ bool migrate_channel_requires_tls_upgrade(QIOChannel *ioc); =20 diff --git a/migration/channel.c b/migration/channel.c index 1ae839e5fe..a481b45eae 100644 --- a/migration/channel.c +++ b/migration/channel.c @@ -153,6 +153,13 @@ int migration_channel_read_peek(QIOChannel *ioc, bool migration_channel_shutdown_gracefully(QIOChannel *c, Error **errp) { if (object_dynamic_cast((Object *)c, TYPE_QIO_CHANNEL_TLS)) { + /* + * The destination expects the TLS session to always be properly + * terminated. This helps to detect a premature termination in the + * middle of the stream. Note that older QEMUs always break the + * connection on the source and the destination always sees + * GNUTLS_E_PREMATURE_TERMINATION. + */ qio_channel_tls_bye(QIO_CHANNEL_TLS(c), errp); } =20 diff --git a/migration/multifd.c b/migration/multifd.c index b255778855..cb0262076b 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -439,7 +439,7 @@ static void multifd_send_set_error(Error *err) } } =20 -static void multifd_send_terminate_threads(void) +static void multifd_send_terminate_threads(bool succeeded) { int i; =20 @@ -460,6 +460,9 @@ static void multifd_send_terminate_threads(void) =20 qemu_sem_post(&p->sem); if (p->c) { + if (succeeded) { + migration_channel_shutdown_gracefully(p->c, &error_warn); + } qio_channel_shutdown(p->c, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); } } @@ -541,50 +544,21 @@ static void multifd_send_cleanup_state(void) =20 void multifd_send_shutdown(void) { + MigrationState *s =3D migrate_get_current(); int i; =20 if (!migrate_multifd()) { return; } =20 - for (i =3D 0; i < migrate_multifd_channels(); i++) { - MultiFDSendParams *p =3D &multifd_send_state->params[i]; - - /* thread_created implies the TLS handshake has succeeded */ - if (p->tls_thread_created && p->thread_created) { - Error *local_err =3D NULL; - /* - * The destination expects the TLS session to always be - * properly terminated. This helps to detect a premature - * termination in the middle of the stream. Note that - * older QEMUs always break the connection on the source - * and the destination always sees - * GNUTLS_E_PREMATURE_TERMINATION. - */ - migration_tls_channel_end(p->c, &local_err); - - /* - * The above can return an error in case the migration has - * already failed. If the migration succeeded, errors are - * not expected but there's no need to kill the source. - */ - if (local_err && !migration_has_failed(migrate_get_current()))= { - warn_report( - "multifd_send_%d: Failed to terminate TLS connection: = %s", - p->id, error_get_pretty(local_err)); - break; - } - } - } - - multifd_send_terminate_threads(); + multifd_send_terminate_threads(!migration_has_failed(s)); =20 for (i =3D 0; i < migrate_multifd_channels(); i++) { MultiFDSendParams *p =3D &multifd_send_state->params[i]; Error *local_err =3D NULL; =20 if (!multifd_send_cleanup_channel(p, &local_err)) { - migrate_set_error(migrate_get_current(), local_err); + migrate_set_error(s, local_err); error_free(local_err); } } diff --git a/migration/tls.c b/migration/tls.c index 284a6194b2..ca1595e05d 100644 --- a/migration/tls.c +++ b/migration/tls.c @@ -165,11 +165,6 @@ void migration_tls_channel_connect(MigrationState *s, NULL); } =20 -void migration_tls_channel_end(QIOChannel *ioc, Error **errp) -{ - qio_channel_tls_bye(QIO_CHANNEL_TLS(ioc), errp); -} - bool migrate_channel_requires_tls_upgrade(QIOChannel *ioc) { if (!migrate_tls()) { --=20 2.50.1