From nobody Thu Dec 18 22:24:45 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1733273635; cv=none; d=zohomail.com; s=zohoarc; b=f5tvJ5WeL3dvWxvQ5MK30EQ09ywe/th42acgcvA2gCs8BewvL6DK0MrDrjI4nJiQO9sHkRm+yWhyLTFishFNcwRdC8p3XtGAaMpbFMQR+Gr3CHCKKvdoBYx1zgida1ArzJidWCmggp20XnLwYKOMMmBIOLy1Qhxetk9OmPKYnGw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733273635; 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=YeSfgc7Jyo9nB/kprDl4lAEUoTylMcAzUPDJAOUL/0Y=; b=CqLsfUYu/UZtijatCCMOOVh3+FHtb5VlZxpVR2K1RxcEeNYHqueK9gkLQw1pE4laIiq6WjyFnSMWHBt9yyS+WXgTatIpaLmRzPwyzZ3+CDsNdpvhOuKqP/MAmZRle43aj6YAUb/7DAXFyD2K8BvBwuJ/L8DXXYUQ4VWnesOvdfI= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1733273635435879.8834427683504; Tue, 3 Dec 2024 16:53:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIdcP-00039i-RW; Tue, 03 Dec 2024 19:51:55 -0500 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 1tIdcK-000396-Qe for qemu-devel@nongnu.org; Tue, 03 Dec 2024 19:51:50 -0500 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 1tIdcI-0005L5-2E for qemu-devel@nongnu.org; Tue, 03 Dec 2024 19:51:48 -0500 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-635-bup9oWohPPOAhpAQUte5KA-1; Tue, 03 Dec 2024 19:51:44 -0500 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-7b66a5121efso754671785a.0 for ; Tue, 03 Dec 2024 16:51:44 -0800 (PST) Received: from x1n.redhat.com (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b68492cb81sm559974785a.34.2024.12.03.16.51.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 16:51:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733273505; 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=YeSfgc7Jyo9nB/kprDl4lAEUoTylMcAzUPDJAOUL/0Y=; b=hdT9J/uyFeQRtXEHGR+DDIvcCJ7239fnKK0GZjXln1emKe5+EimshQTjHx7sUiIc22434N gDKReAf7VGooMhyR7DgmBQT63LIXGIA+Hw3cSQ325QxFvxZ0m3/lQQtmjXRwzpb+Yyj9fB /V6ijZ8udaouTBwIKq9Gb/pJ4sbHlsc= X-MC-Unique: bup9oWohPPOAhpAQUte5KA-1 X-Mimecast-MFC-AGG-ID: bup9oWohPPOAhpAQUte5KA X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733273503; x=1733878303; 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=YeSfgc7Jyo9nB/kprDl4lAEUoTylMcAzUPDJAOUL/0Y=; b=dYrvH2187VRxFsu0VwEu7vxNucHhJDX1RWy/+Hp3y4K25kgGpPu189BlM4cPZd9loV Vz2rgKkLN9jzW9q/kmOl4QVdEvye8xMaWLCQ5HlePxbc66H+UUEnPxr4eIgbmjpVkFsV OxJj7VT5uszJrDiST9bMQ4JbklaSYFJQgV1no6Fr7IDpCPLJP2K0Fk/5jRTVZwSmD/22 48FAUIDO0bz22k5WaL/OmzaJCMsTvBmWZTO8DWixsv74AxnP4ywQcyTnk4zIHXIwxg1C k6LuFhIxQNxWNVS3OoNJ5Gr/DdVzrIR7PpeFdhUnp38WrxUcN8mED5gi8/92Gg1kahsn GKew== X-Gm-Message-State: AOJu0Yzbc2R2MrhNruuDXfE3kNOCWgMjsAsIjcAcpL1PJQowSS89CmMo KDnFz3VQ6E8gYVic38a5EEvei8pwURxm/TabDjsUS3j4RbWxU1kUoRLNkTSUkZ5PjL/6pfj0qYn DyvxLE+8aw0wS8GDPIK26YSxsTIDjiEUdJ9+OC9iyKK3LOkhQ03QsreCdBP4OlStXAu1Bgp5RTo c7Egg4xR1VGfLW5Vmn2yJG3ZoNErEqUlntcg== X-Gm-Gg: ASbGncvcf0zv3MFx/KBOmNo8YuPpbOzRqcHk5D79XH8V6maHh4EEYom5i91Voekw78h 0fV7iiavn3kBQtK2Ysj+BiEukG3qi0GarEACS8k2S5JYckFkcot4PBbBEKeU30nWWvwbUbg8+Fk gm61fOVNDFsx0Z/IwYk4zbSrPNaVJc4DJ2HbAr/yb7CyWrskI1hPMYrpu43MRBWBortFjgbjjn1 /+uixiNpHR+dH2lB1ihE95T3z5U5KlDOK27eYlwBBbK3nONp1tg4t1IwV6o1A1jBsJF4SaWTq6i fOmTeTadYtOM47cIpojIeE/IXQ== X-Received: by 2002:a05:620a:248f:b0:7b6:6add:4a3c with SMTP id af79cd13be357-7b6a5d3a035mr624332285a.21.1733273503263; Tue, 03 Dec 2024 16:51:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IHcApxcf2wNJvtEwRWGFfA1Km44uCXjtDUDtamN8kBwMkDJRh1L+c+at2kpfbDQBdZ5+y5kjA== X-Received: by 2002:a05:620a:248f:b0:7b6:6add:4a3c with SMTP id af79cd13be357-7b6a5d3a035mr624328885a.21.1733273502774; Tue, 03 Dec 2024 16:51:42 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Fabiano Rosas , "Dr . David Alan Gilbert" , Eric Blake , Kevin Wolf , Vladimir Sementsov-Ogievskiy , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Andrey Drobyshev , peterx@redhat.com, Stefan Hajnoczi Subject: [PATCH RFC 01/11] migration: Add helper to get target runstate Date: Tue, 3 Dec 2024 19:51:28 -0500 Message-ID: <20241204005138.702289-2-peterx@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241204005138.702289-1-peterx@redhat.com> References: <20241204005138.702289-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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: 1733273635875116600 Content-Type: text/plain; charset="utf-8" In 99% cases, after QEMU migrates to dest host, it tries to detect the target VM runstate using global_state_get_runstate(). There's one outlier so far which is Xen that won't send global state. That's the major reason why global_state_received() check was always there together with global_state_get_runstate(). However it's utterly confusing why global_state_received() has anything to do with "let's start VM or not". Provide a helper to explain it, then we have an unified entry for getting the target dest QEMU runstate after migration. Suggested-by: Fabiano Rosas Signed-off-by: Peter Xu --- migration/migration.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 8c5bd0a75c..d2a6b939cf 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -135,6 +135,21 @@ static bool migration_needs_multiple_sockets(void) return migrate_multifd() || migrate_postcopy_preempt(); } =20 +static RunState migration_get_target_runstate(void) +{ + /* + * When the global state is not migrated, it means we don't know the + * runstate of the src QEMU. We don't have much choice but assuming + * the VM is running. NOTE: this is pretty rare case, so far only Xen + * uses it. + */ + if (!global_state_received()) { + return RUN_STATE_RUNNING; + } + + return global_state_get_runstate(); +} + static bool transport_supports_multi_channels(MigrationAddress *addr) { if (addr->transport =3D=3D MIGRATION_ADDRESS_TYPE_SOCKET) { @@ -735,8 +750,7 @@ static void process_incoming_migration_bh(void *opaque) * unless we really are starting the VM. */ if (!migrate_late_block_activate() || - (autostart && (!global_state_received() || - runstate_is_live(global_state_get_runstate())))) { + (autostart && runstate_is_live(migration_get_target_runstate()))) { /* Make sure all file formats throw away their mutable metadata. * If we get an error here, just don't restart the VM yet. */ bdrv_activate_all(&local_err); @@ -759,8 +773,7 @@ static void process_incoming_migration_bh(void *opaque) =20 dirty_bitmap_mig_before_vm_start(); =20 - if (!global_state_received() || - runstate_is_live(global_state_get_runstate())) { + if (runstate_is_live(migration_get_target_runstate())) { if (autostart) { vm_start(); } else { --=20 2.47.0 From nobody Thu Dec 18 22:24:45 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1733273614; cv=none; d=zohomail.com; s=zohoarc; b=hvTWQs8lfxseTerH24NDCFIy9YtOBKc8ynTyfzm9zOR8blOtRDMScox2Yr2nyI7G48b6R3cHTI3/j/HihExlN993arzBR5JHTwKaLc9/ImYZcUxl2sXX8VXEPUgkjvzdqWJTMmu7+e71qnLLQG40Hi46tvqUuYYlI9kRXrC0msA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733273614; 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=bj8MGswrXWKOgEfQ2x9IDB2aXSksN2FVHW5jduhyU+Q=; b=BnYTKMxVhMWbqXG0OfxYlu+k2Md8TYjS0Oz0/4qyAkM7Fi/a9XtAUIakY4tSFt4j7Jc7Fev1FHhp2ygigSDvor8Y6IUYE/OuUKBPjCO8JsM39J36/J9HxZ+t6BFkqx85pHoOw1YzYCYtOjMurZG6oo8gxk28IxAMQSM/nOeeUQo= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1733273614692796.5101246908075; Tue, 3 Dec 2024 16:53:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIdcT-0003Bv-MK; Tue, 03 Dec 2024 19:51:57 -0500 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 1tIdcQ-0003AX-Iz for qemu-devel@nongnu.org; Tue, 03 Dec 2024 19:51:55 -0500 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 1tIdcO-0005Sg-B3 for qemu-devel@nongnu.org; Tue, 03 Dec 2024 19:51:53 -0500 Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-607-H3vZ0emfMpypT23YOmEWyA-1; Tue, 03 Dec 2024 19:51:46 -0500 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-7b674755f8eso973388385a.2 for ; Tue, 03 Dec 2024 16:51:46 -0800 (PST) Received: from x1n.redhat.com (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b68492cb81sm559974785a.34.2024.12.03.16.51.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 16:51:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733273510; 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=bj8MGswrXWKOgEfQ2x9IDB2aXSksN2FVHW5jduhyU+Q=; b=LHtzQ7QONTVi9BPotbwkR4wGa2iw7iyHWCSF4wzkk3EqmWZ4YiVAi3uuVp1IFk3jJzbRWm DIxcFbaGR7+qhUqfpNCVJhr5kDUShMeT5lycBuC99XitcGdI4MQK2CsgP6G8+7eOY2zjo9 hHDWfGTwQOAv5Rf89XSNZfczd6jVyhw= X-MC-Unique: H3vZ0emfMpypT23YOmEWyA-1 X-Mimecast-MFC-AGG-ID: H3vZ0emfMpypT23YOmEWyA X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733273505; x=1733878305; 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=bj8MGswrXWKOgEfQ2x9IDB2aXSksN2FVHW5jduhyU+Q=; b=ZOt9jZfEhoG+MOka6BBcKLDj1w2Wh6boOw8KFIYZ/F1Xg0nW/tMqcgbzRepc4/l8FB cvB0Qro+llF308i2xjuOfpCpkoy6ChsIAg//dGMJYLczsAIS1LpYT4cjOrR1n5FB/C96 Au78yWp+rl7UeiCHTEs3sZlG53tlYyxpD/d8T7C2UhC3R6H+RZRjelF2Ly1auQCqu7vD hJjEeviOLzn2WJ+x/anBW9mId/PRY2RXZgh5FmALCIdXBZ8GXBFaxzE+5QQiXpS/oAAt kOZE2OMJQUsxQm8FPqfUKCfMKxts1EYm1E9lqjOETkt+fGCugTF8jyXKdNVJ7hJnf1YN NlgA== X-Gm-Message-State: AOJu0Yz0KJLyGfwGZnilqHmaq5i5qY9E1fgVzNUkadXJ7j1GZ7AR5rYb T70Wy6sKUAAG/WcQqRhCSEs6e7YkU5g86lrT6W8lC5B9RWsaiY3Ve1LxJQysn6ki0VNxPP7LD+X jbM86CHwurRdkfGM0ZTRGpIJTC065h1L7qtnnPrD9tzjNOI0d0tQw8p9aJw/vez2FXHZYOngvBK 5Bzw+Ra3rzGAIbUWoHQRj22KQ2JxfTc7X14g== X-Gm-Gg: ASbGncv+Xdk5lARTcSJndsZZoh3bthxn/byd8G8jeImjkyjmWaU07Jy2FEim2ihUGv9 W02+Dr/blTvzpEegQ+RC1nX/J6aAz8+xzGstIRBriryNEVXciveMspG05nGCEhj0lIki2W99RPD +LswVwYL3caOKiLCo2JHliTsx8peWO75vZ3/nMrIMXHFlFXgLOmA7UHI4/2SH8Or57DhIZorZ9z sgcTvpNE5OJpyuosywM7+4e4VPJSbGB2dKEIAocMYLS6wZTsBlUEJ8df26Skh6nvo9CRFdo4qV0 2MYx+8YAPfFSMF4isIvC+Isceg== X-Received: by 2002:a05:620a:4089:b0:7b6:773f:4bd3 with SMTP id af79cd13be357-7b6a619aa85mr512943585a.41.1733273505181; Tue, 03 Dec 2024 16:51:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IFA9ZLwy+VY7F5c8FJAvgQAzm9ryKvqIDEYug7Ue8bxh4rdmsvy1gpAYngRmZWIWcgPCgeBeA== X-Received: by 2002:a05:620a:4089:b0:7b6:773f:4bd3 with SMTP id af79cd13be357-7b6a619aa85mr512939985a.41.1733273504711; Tue, 03 Dec 2024 16:51:44 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Fabiano Rosas , "Dr . David Alan Gilbert" , Eric Blake , Kevin Wolf , Vladimir Sementsov-Ogievskiy , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Andrey Drobyshev , peterx@redhat.com, Stefan Hajnoczi Subject: [PATCH RFC 02/11] migration/block: Make late-block-active the default Date: Tue, 3 Dec 2024 19:51:29 -0500 Message-ID: <20241204005138.702289-3-peterx@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241204005138.702289-1-peterx@redhat.com> References: <20241204005138.702289-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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: 1733273615614116600 Content-Type: text/plain; charset="utf-8" Migration capability 'late-block-active' controls when the block drives will be activated. If enabled, block drives will only be activated until VM starts, either src runstate was "live" (RUNNING, or SUSPENDED), or it'll be postponed until qmp_cont(). Let's do this unconditionally. There's no harm to delay activation of block drives. Meanwhile there's no ABI breakage if dest does it, because src QEMU has nothing to do with it, so it's no concern on ABI breakage. IIUC we could avoid introducing this cap when introducing it before, but now it's still not too late to just always do it. Cap now prone to removal, but it'll be for later patches. Signed-off-by: Peter Xu --- migration/migration.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index d2a6b939cf..e6db9cfc50 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -743,24 +743,6 @@ static void process_incoming_migration_bh(void *opaque) =20 trace_vmstate_downtime_checkpoint("dst-precopy-bh-enter"); =20 - /* If capability late_block_activate is set: - * Only fire up the block code now if we're going to restart the - * VM, else 'cont' will do it. - * This causes file locking to happen; so we don't want it to happen - * unless we really are starting the VM. - */ - if (!migrate_late_block_activate() || - (autostart && runstate_is_live(migration_get_target_runstate()))) { - /* Make sure all file formats throw away their mutable metadata. - * If we get an error here, just don't restart the VM yet. */ - bdrv_activate_all(&local_err); - if (local_err) { - error_report_err(local_err); - local_err =3D NULL; - autostart =3D false; - } - } - /* * This must happen after all error conditions are dealt with and * we're sure the VM is going to be running on this host. @@ -775,7 +757,25 @@ static void process_incoming_migration_bh(void *opaque) =20 if (runstate_is_live(migration_get_target_runstate())) { if (autostart) { - vm_start(); + /* + * Block activation is always delayed until VM starts, either + * here (which means we need to start the dest VM right now..), + * or until qmp_cont() later. + * + * We used to have cap 'late-block-activate' but now we do this + * unconditionally, as it has no harm but only benefit. E.g., + * it's not part of migration ABI on the time of disk activati= on. + * + * Make sure all file formats throw away their mutable + * metadata. If error, don't restart the VM yet. + */ + bdrv_activate_all(&local_err); + if (local_err) { + error_report_err(local_err); + local_err =3D NULL; + } else { + vm_start(); + } } else { runstate_set(RUN_STATE_PAUSED); } --=20 2.47.0 From nobody Thu Dec 18 22:24:45 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1733273638; cv=none; d=zohomail.com; s=zohoarc; b=Y8xoCFwr8wDYGBUDcbsunBQrWRBAGG9pJ+ipjvDIC3h13mfJmUzaOhW/TXFZgoPl+bd7/W8hnadzeKA/StCBUBdnS3W5IRYAIjgCsmKgklh15J6nbCisTE8NwUud/iJlv28vYvkH0bvEWpE8FixhEefEgojzYu47kG6fsHwgfYM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733273638; 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=9eO5MPkyUkZyqcYRHcQpN0Gixuc0Ku87NoiXHCs64ME=; b=jGyD2pRnwvklNhXO1aDhfIhWrfuAocrB4g+lVffQMoFDCEGzcfLq+AqiLvpOJyny2s1IQwXUBKcgiZAQw6lZTVJAU7I+fpEuSD/l3y/tigggsZM/NGIK/XLwaoQ1+zdSOKh1n79KYWRWdttfwixdx7N19BUxQRBO7y8bktBMjTE= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1733273638355878.2579382236872; Tue, 3 Dec 2024 16:53:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIdcT-0003Bx-Of; Tue, 03 Dec 2024 19:51:57 -0500 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 1tIdcO-00039n-IN for qemu-devel@nongnu.org; Tue, 03 Dec 2024 19:51:53 -0500 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 1tIdcM-0005SU-0c for qemu-devel@nongnu.org; Tue, 03 Dec 2024 19:51:51 -0500 Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-626-CnKCJla8OHq70XaYlIhYlg-1; Tue, 03 Dec 2024 19:51:48 -0500 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-7b677151a03so749213985a.3 for ; Tue, 03 Dec 2024 16:51:48 -0800 (PST) Received: from x1n.redhat.com (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b68492cb81sm559974785a.34.2024.12.03.16.51.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 16:51:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733273509; 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=9eO5MPkyUkZyqcYRHcQpN0Gixuc0Ku87NoiXHCs64ME=; b=iltn93Gu5jIxo0TwHzgaT9jWoiuRpkWn4ldozmllCknrWi2KwDoQ3tSIoFnDDCFqkVZ91u BhvYHTLwsTc7LzTxf7rekpvlKzYjPJEVBIIPz03+tD2C5I4btFbgccmL4aAEa9xPwaWxdr hwshsRZdcabEJkQEiPcuZfm1/Nbds50= X-MC-Unique: CnKCJla8OHq70XaYlIhYlg-1 X-Mimecast-MFC-AGG-ID: CnKCJla8OHq70XaYlIhYlg X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733273507; x=1733878307; 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=9eO5MPkyUkZyqcYRHcQpN0Gixuc0Ku87NoiXHCs64ME=; b=o2dyUyA/YkJQIUGTiDQDY/K7Du3FzqPuTt5uNPX/Ax0k57krUgYhXlAmP+6pkl9xGS TYZ/Uu6zPhennVqS/tX4m45VgBq730y6IdqRSPBEkwTqmTTC7DMfDS7gsxC3xDKp7M9b WW+AgbA2jR/y2y+9PXMCQ0rPA96LWJA1Z0PhoCis3sV+BiVY1/Zp5F7yVDNbuKZFH83e RNm9Ch8RibjbxGUyenZbLW2SaSd4z+BnyHOFoL+QQzX/mYPHU/g3zb7l0T+K7vzaZEh4 Peecrh499TlncBY3BFMdVOmhMuWhwoFavKUqqZFTS1EZW5pkQQVPID7H9pNCPt9x0kHl bqcw== X-Gm-Message-State: AOJu0YziMHI1Z+L+knxuWCR/85aQOdAIMIdqLw5MFSk7quApD6U5hNVl vfOLCtIVE5OA4njb0bj3NadPsEAotY1ojOljTkfZOcUCms91Zwbi3qUa3CM84Yw1LpD8Lmc7vuo qmiTviII7Fv6dfd+cWgapw1enIjMhshvvRBHuivPgjU3SJczE7PsWocgAvV7dsHelPfC4vf8qW8 K+9cNEhMdcchBxaopikoOi4nRyX9m1lP6JVQ== X-Gm-Gg: ASbGncsCmYOd7SEaMWIORGFUu0Ffhfgey9D154bZOvHpbA5BlXQyRKfWCyt9sGNSxfA iD9l9sdhhcArZyQEfpOCvOu0Gq7rg9WOjOgKfQiUO0a9x1VOs2Zf9VOESStcyQlXsYQ7+YfiTRF vD9FZdjCTPv3igF+4lmMvWHxDwvK9USWfF2JzcDjAUnWx13twOrY0BA+iVz1H1Iqr+ziOkaHVBF szmGaCPuUE2e+e01x+Rvm6sOkV1kHgVh90UumURZn+2hKJ48IMy0RTxZ5OhTaGL1jWDf1OgSBLB MTgjzNIJfO1Rlw0dzLGTeRxUNw== X-Received: by 2002:a05:620a:1a9e:b0:7af:cfc0:7822 with SMTP id af79cd13be357-7b6a61a70d1mr404977685a.33.1733273507118; Tue, 03 Dec 2024 16:51:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IHg7yUx65HgLNiULxwoxOsjqoo1vP731Ts1QmtCkUb8n+BsSydYEEwKAKA54EEupxWWV13QUQ== X-Received: by 2002:a05:620a:1a9e:b0:7af:cfc0:7822 with SMTP id af79cd13be357-7b6a61a70d1mr404975285a.33.1733273506763; Tue, 03 Dec 2024 16:51:46 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Fabiano Rosas , "Dr . David Alan Gilbert" , Eric Blake , Kevin Wolf , Vladimir Sementsov-Ogievskiy , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Andrey Drobyshev , peterx@redhat.com, Stefan Hajnoczi Subject: [PATCH RFC 03/11] migration/block: Apply late-block-active behavior to postcopy Date: Tue, 3 Dec 2024 19:51:30 -0500 Message-ID: <20241204005138.702289-4-peterx@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241204005138.702289-1-peterx@redhat.com> References: <20241204005138.702289-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1733273639857116600 Content-Type: text/plain; charset="utf-8" Postcopy never cared about late-block-active. However there's no mention in the capability that it doesn't apply to postcopy. Considering that we _assumed_ late activation is always good, do that too for postcopy unconditionally, just like precopy. After this patch, we should have unified the behavior across all. Signed-off-by: Peter Xu --- migration/savevm.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/migration/savevm.c b/migration/savevm.c index 98821c8120..0d52fe522c 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2137,22 +2137,19 @@ static void loadvm_postcopy_handle_run_bh(void *opa= que) =20 trace_vmstate_downtime_checkpoint("dst-postcopy-bh-announced"); =20 - /* Make sure all file formats throw away their mutable metadata. - * If we get an error here, just don't restart the VM yet. */ - bdrv_activate_all(&local_err); - if (local_err) { - error_report_err(local_err); - local_err =3D NULL; - autostart =3D false; - } - - trace_vmstate_downtime_checkpoint("dst-postcopy-bh-cache-invalidated"); - dirty_bitmap_mig_before_vm_start(); =20 if (autostart) { - /* Hold onto your hats, starting the CPU */ - vm_start(); + /* Make sure all file formats throw away their mutable metadata. + * If we get an error here, just don't restart the VM yet. */ + bdrv_activate_all(&local_err); + trace_vmstate_downtime_checkpoint("dst-postcopy-bh-cache-invalidat= ed"); + if (local_err) { + error_report_err(local_err); + local_err =3D NULL; + } else { + vm_start(); + } } else { /* leave it paused and let management decide when to start the CPU= */ runstate_set(RUN_STATE_PAUSED); --=20 2.47.0 From nobody Thu Dec 18 22:24:46 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1733273613; cv=none; d=zohomail.com; s=zohoarc; b=HoDiBl+C8czuO0MHzvH+dBAw7SMN9O+TIwpy4J7U/Ewo1xoshCtZb7mGSOiKp0AEHp2y3rghUxsfvGhPW8WdSjt/0xb3XvmokST0BIQSWT1wVRxgaobKsOkmRebnMlv2JHVjxhJbp26ILFUjyLnnlo7HrdzrtwBeb5y2/4y8Hl8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733273613; 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=ZntSzqNWuBb17WbCKGc0zhRMJFYOiINDmC++y1Vats0=; b=LVLNXTmbnI69xvLKasj3XNnzoNevzRsZZA4ft991sNZa1fFD4z++ljMkekK8UYCD/1lgDa0YJnBWD7p5w3BBpZ9pNzu10rpTKgF9t/egdmSJuk9ghOaWuEhBXiLPN1h0bxE3o9ynFP88S9JeZRR7mxqzkrtgudzMMTbzSt0dOLE= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 173327361340252.488339475790326; Tue, 3 Dec 2024 16:53:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIdcb-0003Fc-Sa; Tue, 03 Dec 2024 19:52:05 -0500 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 1tIdcV-0003D2-6F for qemu-devel@nongnu.org; Tue, 03 Dec 2024 19:52:01 -0500 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 1tIdcT-0005g8-LD for qemu-devel@nongnu.org; Tue, 03 Dec 2024 19:51:58 -0500 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-43-rGZQarT0Pw2_7qXoitjgnw-1; Tue, 03 Dec 2024 19:51:52 -0500 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-7b665521dabso93631585a.0 for ; Tue, 03 Dec 2024 16:51:52 -0800 (PST) Received: from x1n.redhat.com (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b68492cb81sm559974785a.34.2024.12.03.16.51.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 16:51:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733273517; 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=ZntSzqNWuBb17WbCKGc0zhRMJFYOiINDmC++y1Vats0=; b=gdSIGiWNW0ITT3E3TZfK4Wl+uHw5Z/btfpvcQw7n0v3i5Agd+2RF6fORKITh3sZpzPJZFC pOzIknN8qo2FcZJ31OhO7Rltg5/7BuRulcbOaOf6D9SIEOM1cKl25LD0B4neNhktirqDCB GmkM/daf+xxkWhiAS+XuaE9u2jgmhmY= X-MC-Unique: rGZQarT0Pw2_7qXoitjgnw-1 X-Mimecast-MFC-AGG-ID: rGZQarT0Pw2_7qXoitjgnw X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733273511; x=1733878311; 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=ZntSzqNWuBb17WbCKGc0zhRMJFYOiINDmC++y1Vats0=; b=uhByttN+Pp5X1pxr+tTijZDy3dFuvfU7bjg7mncfh9q25OAAVB/Z7MizPnQfs0hRul e6THOLotpx5me0bHWW/5Bkh8bN8ZddCln6Om6Hge0t7lw40RpW3LUb8yLBnKTm1CHtnV HN61yRxi1YqAKWcsXMmipQ3hcQhyCoA8L+QPUg+/1jJC7x6z7AEmKhTa1n6dlZAQlVf4 UUYatopu/4r7FcFAJ6HwtjeTkZ3+d4U5y/uma5udubf2SkxZtRQUGbxOVw2s5TI9Zyln QxvL2MCq/3Yl1lsPrgt0eLdBvprxfVaQRK6W9+QhWyTEao33iqPF38gdQO7iRcF3Vt0c HN1w== X-Gm-Message-State: AOJu0YyY5cvBhVtoxRLoNk8HlugOx6KE6mwV3SPsM1Y37ezKy3Kb9MTg xPLuE+yn406BMygVJKJcxGEAmJAICmTR2rry4MND23mkCvksEac5E1sroU5vEwx6QDsnzaJ+WWs eeiHeIObAi3i9/fUbgwpwdtoOdCLwm8IaRvubrf50IQlcfIDPtnk4Xw27Row6q+DLHtKW4xrIyF lv/IGLZCx+lokPDSv/3y/S6N8sb4QX2C5dCQ== X-Gm-Gg: ASbGncu75uRlUURL2ckMnHp3K0lW58ZhVjmQK55wRFbr1UPV0aLWOldGmk7vJ55D0lT gOIQgjhwCa5sG4iO8c6VYqCg4n2QEcfcbYDT+EEZGMmSgG5X/nEs42WjXCH+OsUUyOj5JiFWQ4q KxuXNPNCeEBxtOh9KJposljLC7iwzlxjxaOMvSMhpXDvX5id+k4euojMJyQSMvlU23rCzSIKLUI N+9XdAXuQN3Q1sjBvcUX1GKfAq2Qd8LIAIeLsvI075Das+gvADFRj+k1GOTnjbTzGWdhNMMloy4 Er1RzlGd21RdmS+0ypNRqDvIEQ== X-Received: by 2002:a05:620a:170f:b0:7b1:3c0e:3289 with SMTP id af79cd13be357-7b6a671f8a2mr603590685a.22.1733273511248; Tue, 03 Dec 2024 16:51:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IH8P6MkeCNieGQeIuDha8vXOKH5080KvlShL6IdO4CYNP6LAXEbiBdBrreI+UpJm6UvqEIBrQ== X-Received: by 2002:a05:620a:170f:b0:7b1:3c0e:3289 with SMTP id af79cd13be357-7b6a671f8a2mr603572285a.22.1733273508150; Tue, 03 Dec 2024 16:51:48 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Fabiano Rosas , "Dr . David Alan Gilbert" , Eric Blake , Kevin Wolf , Vladimir Sementsov-Ogievskiy , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Andrey Drobyshev , peterx@redhat.com, Stefan Hajnoczi Subject: [PATCH RFC 04/11] migration/block: Fix possible race with block_inactive Date: Tue, 3 Dec 2024 19:51:31 -0500 Message-ID: <20241204005138.702289-5-peterx@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241204005138.702289-1-peterx@redhat.com> References: <20241204005138.702289-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1733273613831116600 Content-Type: text/plain; charset="utf-8" Src QEMU sets block_inactive=3Dtrue very early before the invalidation takes place. It means if something wrong happened during setting the flag but before reaching qemu_savevm_state_complete_precopy_non_iterable() where it did the invalidation work, it'll make block_inactive flag inconsistent. For example, think about when qemu_savevm_state_complete_precopy_iterable() can fail: it will have block_inactive set to true even if all block drives are active. Fix that by only update the flag after the invalidation is done. No Fixes for any commit, because it's not an issue if bdrv_activate_all() is re-entrant upon all-active disks - false positive block_inactive can bring nothing more than "trying to active the blocks but they're already active". However let's still do it right to avoid the inconsistent flag v.s. reality. Signed-off-by: Peter Xu --- migration/migration.c | 9 +++------ migration/savevm.c | 2 ++ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index e6db9cfc50..ba5deec5bc 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2749,14 +2749,11 @@ static int migration_completion_precopy(MigrationSt= ate *s, goto out_unlock; } =20 - /* - * Inactivate disks except in COLO, and track that we have done so in = order - * to remember to reactivate them if migration fails or is cancelled. - */ - s->block_inactive =3D !migrate_colo(); migration_rate_set(RATE_LIMIT_DISABLED); + + /* Inactivate disks except in COLO */ ret =3D qemu_savevm_state_complete_precopy(s->to_dst_file, false, - s->block_inactive); + !migrate_colo()); out_unlock: bql_unlock(); return ret; diff --git a/migration/savevm.c b/migration/savevm.c index 0d52fe522c..3c75257318 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1558,6 +1558,8 @@ int qemu_savevm_state_complete_precopy_non_iterable(Q= EMUFile *f, qemu_file_set_error(f, ret); return ret; } + /* Remember that we did this */ + s->block_inactive =3D true; } if (!in_postcopy) { /* Postcopy stream will still be going */ --=20 2.47.0 From nobody Thu Dec 18 22:24:46 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1733273655; cv=none; d=zohomail.com; s=zohoarc; b=g2VRIpRZPm4+p2o/Cn0NX8dASmqYpwu6pXjtwdguwuctqDgARU7sdfEn3Sc7fouQJHHLX9UFfsvPJMxEwzN4vZwjC73HYda47WjoWqGFN/bDL/zauKwLjjHWigmtAXp0n074KaVgPIOZBNzbq8mHw6DRkld9GgTWoh685NaBFMY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733273655; 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=KsL66nlHuV4JdK6/kM+Un3Nz5nHzQSMy63MxFVqZCT8=; b=Boa0+oLmrXpnQVjgRvro1Hvd6x5I5who/XrWhPr9uv3ZzqyImj7NdJREcwXjIaX4L/aNNZ0aZlIf45AwEP0Uor56TdSFFi/jC3+eCBcZznszY+gg1g+ljwY3NS4msOUW8XvvHi/FKb/VE0TYpLUe00F0NcnEUlUekE5Ortt5l8c= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1733273655558585.3590908984128; Tue, 3 Dec 2024 16:54:15 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIdca-0003EN-9A; Tue, 03 Dec 2024 19:52:04 -0500 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 1tIdcU-0003Cc-Jy for qemu-devel@nongnu.org; Tue, 03 Dec 2024 19:51:58 -0500 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 1tIdcQ-0005YR-Ne for qemu-devel@nongnu.org; Tue, 03 Dec 2024 19:51:57 -0500 Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-37-lEzTh7FRPZCCmJq1n0UVWg-1; Tue, 03 Dec 2024 19:51:51 -0500 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-7b69c165661so346450485a.2 for ; Tue, 03 Dec 2024 16:51:51 -0800 (PST) Received: from x1n.redhat.com (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b68492cb81sm559974785a.34.2024.12.03.16.51.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 16:51:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733273514; 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=KsL66nlHuV4JdK6/kM+Un3Nz5nHzQSMy63MxFVqZCT8=; b=d7VQLfTsVeUw4vY8GnDRRCi5xqKjv74biPh20hNcrBtWGnOoJD7j/+KY6rCS++cw312++r LzsQR87yeHX9McE+GyPa4rKI3oa7yTGkrwS5Cw2W9aCh49AWvyb9Z6JVEe8sXNxYNkSR8Z cESHKe1daTsl6HIac5I48w767IbkrX4= X-MC-Unique: lEzTh7FRPZCCmJq1n0UVWg-1 X-Mimecast-MFC-AGG-ID: lEzTh7FRPZCCmJq1n0UVWg X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733273510; x=1733878310; 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=KsL66nlHuV4JdK6/kM+Un3Nz5nHzQSMy63MxFVqZCT8=; b=V+FhkvUQnHANptF5NpzJdKCMZC3kxQXclwghqXa277qRJAjdDx8rSq3074fpkT9iy1 05xsh7aarQpMv+qcMcevojSXa05lkuPK1DzJuMTlnMjGnn/6Wj8A2fdLQOMz+jzVa3El fQDdsYTWavul48RL5tUVdqSNNglL8gH0f/8kyDitNuq/eCYsiyN5JEODseebbNn7oF0B plPWdoTvmbGoXHzflV0iViyktHy1F+vdkh1okfRCexS83rlDu9vKGCbNDo1Y6PO2qws6 /xc/oYGT6cnvdCgpqndSwPjnLEivz/77a5j//YEJrGQn898nSKFHZvPbLWNfzanuckxF Exlw== X-Gm-Message-State: AOJu0Ywne04BEBfWYZXJDcR1/z02MRxuMZhXC3rg8K3SAqL6J62MduHW Qts4a7kMkMNQIlsxA2sz98TEEJR9mhW++2NAWTg6Q6lcZzy6+8R69RCkOUGITiNEbHHPK0MeCwo zMItQJ3aD0QYPezD5/xcjlIvcu7ybGeyPRJRe7/ccTy5bHbh89/mXo8s5phbfk4Cfd+3Tav8nMh 0BzE3GiifKtMMOPGxQXvrfrTfFR2sXyasp/A== X-Gm-Gg: ASbGncsKP7cvSAjXl9xFlM2aW98Xg056q2NO2eacNUH3ogvJnOKBWNkcORE4SIi97Tz dO+hJcP/dG43hDfLiyivAKFP2INbNQKiNuWXXxXjxD755+7yKRw04AmkORSwNQGcxXK2a0lNWxx srbOECqtm56PsIVBHEHftclwce1JjIyLAgRQlJn5EW23OrT5SA5DKu5KlB7NF7NhKqyl/yVt0Vl UCNwYXODb0T8i+jiZR7kS1igLx3Ya3QZwGYTAPU9uFzxX1OJ6Sxvqmt/iOJ1CPxInql284m6q8I G06gnlZMi4K8OyPcwLLRfENVEg== X-Received: by 2002:a05:620a:1a26:b0:7b1:3ada:dc58 with SMTP id af79cd13be357-7b6a617eb13mr315585585a.34.1733273510585; Tue, 03 Dec 2024 16:51:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IETa/ngM/QBjIo9R9p1IezBqU7QRnSiGjlvAPsNLl/yP1dNntAjKwWUJq5x9BSoMB7RedN3oQ== X-Received: by 2002:a05:620a:1a26:b0:7b1:3ada:dc58 with SMTP id af79cd13be357-7b6a617eb13mr315583285a.34.1733273510157; Tue, 03 Dec 2024 16:51:50 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Fabiano Rosas , "Dr . David Alan Gilbert" , Eric Blake , Kevin Wolf , Vladimir Sementsov-Ogievskiy , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Andrey Drobyshev , peterx@redhat.com, Stefan Hajnoczi Subject: [PATCH RFC 05/11] migration/block: Merge block reactivations for fail/cancel Date: Tue, 3 Dec 2024 19:51:32 -0500 Message-ID: <20241204005138.702289-6-peterx@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241204005138.702289-1-peterx@redhat.com> References: <20241204005138.702289-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1733273657125116600 Content-Type: text/plain; charset="utf-8" When migration is either cancelled or failed during switchover, especially when after the disks are inactivated, QEMU needs to remember re-activate the disks again before vm starts. It used to be done separately in two paths: one in qmp_migrate_cancel(), the other one in the failure path of migration_completion(). It used to be fixed in different commits, all over the places in QEMU. So these are the ones I see at least: - In 2016, commit fe904ea824 ("migration: regain control of images when migration fails to complete") - In 2017, commit 1d2acc3162 ("migration: re-active images while migration been canceled after inactive them") - In 2023, commit 6dab4c93ec ("migration: Attempt disk reactivation in more failure scenarios") We could have done better on trying to solve this once and for all. Now it might be a good chance because we have a better whole picture now. Put both of the error cases together now into migration_iteration_finish(), which will be invoked for either of the scenario. At the meantime, cleanup block_inactive in a few ways: - Rename it to block_active, which is easier to follow.. - Maintain the flag for the whole lifecycle of QEMU. Otherwise it's not clear on when the flag is valid or not. - Put it together with the operations, rather than updating the flag separately. Now we set the flag to TRUE from the start, showing block ownership of a fresh started QEMU (but so far only used in migration module). Then it can be modified by migration switchover code if invalidation happened. With that, the flag always reflects the correct block ownership. NOTE: it can always be racy if there's concurrent operation to change the block activation status (e.g., qmp_cont() right after migration failure but right before block re-activate happens), but that's not avoidable even before this patch, so it's not part of the goal that this patch would like to achieve, so put aside as of now. Signed-off-by: Peter Xu --- migration/migration.h | 20 +++++++++- migration/migration.c | 86 +++++++++++++++++++++++++------------------ migration/savevm.c | 11 ++---- 3 files changed, 72 insertions(+), 45 deletions(-) diff --git a/migration/migration.h b/migration/migration.h index 3857905c0e..b71c062ad2 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -370,8 +370,20 @@ struct MigrationState { /* Flag set once the migration thread is running (and needs joining) */ bool migration_thread_running; =20 - /* Flag set once the migration thread called bdrv_inactivate_all */ - bool block_inactive; + /* + * Migration-only cache to remember the block layer activation status. + * Protected by BQL. + * + * We need this because.. + * + * - Migration can fail after block devices are invalidated (during + * switchover phase). When that happens, we need to be able to + * recover the block drive status by re-activating them. + * + * For freshly started QEMU, block_active is initialized to TRUE + * reflecting the scenario where QEMU owns block device ownerships. + */ + bool block_active; =20 /* Migration is waiting for guest to unplug device */ QemuSemaphore wait_unplug_sem; @@ -556,4 +568,8 @@ void migration_bitmap_sync_precopy(bool last_stage); /* migration/block-dirty-bitmap.c */ void dirty_bitmap_mig_init(void); =20 +/* Wrapper for block active/inactive operations */ +bool migration_block_activate(MigrationState *s); +bool migration_block_inactivate(MigrationState *s); + #endif diff --git a/migration/migration.c b/migration/migration.c index ba5deec5bc..8f7d09ca84 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -130,6 +130,47 @@ static void migration_downtime_end(MigrationState *s) trace_vmstate_downtime_checkpoint("src-downtime-end"); } =20 +bool migration_block_activate(MigrationState *s) +{ + Error *local_err =3D NULL; + + assert(bql_locked()); + + if (s->block_active) { + return true; + } + + bdrv_activate_all(&local_err); + if (local_err) { + error_report_err(local_err); + return false; + } + + s->block_active =3D true; + return true; +} + +bool migration_block_inactivate(MigrationState *s) +{ + int ret; + + assert(bql_locked()); + + if (!s->block_active) { + return true; + } + + ret =3D bdrv_inactivate_all(); + if (ret) { + error_report("%s: bdrv_inactivate_all() failed: %d\n", + __func__, ret); + return false; + } + + s->block_active =3D false; + return true; +} + static bool migration_needs_multiple_sockets(void) { return migrate_multifd() || migrate_postcopy_preempt(); @@ -1552,16 +1593,6 @@ static void migrate_fd_cancel(MigrationState *s) } } } - if (s->state =3D=3D MIGRATION_STATUS_CANCELLING && s->block_inactive) { - Error *local_err =3D NULL; - - bdrv_activate_all(&local_err); - if (local_err) { - error_report_err(local_err); - } else { - s->block_inactive =3D false; - } - } } =20 void migration_add_notifier_mode(NotifierWithReturn *notify, @@ -2778,31 +2809,6 @@ static void migration_completion_postcopy(MigrationS= tate *s) trace_migration_completion_postcopy_end_after_complete(); } =20 -static void migration_completion_failed(MigrationState *s, - int current_active_state) -{ - if (s->block_inactive && (s->state =3D=3D MIGRATION_STATUS_ACTIVE || - s->state =3D=3D MIGRATION_STATUS_DEVICE)) { - /* - * If not doing postcopy, vm_start() will be called: let's - * regain control on images. - */ - Error *local_err =3D NULL; - - bql_lock(); - bdrv_activate_all(&local_err); - if (local_err) { - error_report_err(local_err); - } else { - s->block_inactive =3D false; - } - bql_unlock(); - } - - migrate_set_state(&s->state, current_active_state, - MIGRATION_STATUS_FAILED); -} - /** * migration_completion: Used by migration_thread when there's not much le= ft. * The caller 'breaks' the loop when this returns. @@ -2856,7 +2862,8 @@ fail: error_free(local_err); } =20 - migration_completion_failed(s, current_active_state); + migrate_set_state(&s->state, current_active_state, + MIGRATION_STATUS_FAILED); } =20 /** @@ -3286,6 +3293,11 @@ static void migration_iteration_finish(MigrationStat= e *s) case MIGRATION_STATUS_FAILED: case MIGRATION_STATUS_CANCELLED: case MIGRATION_STATUS_CANCELLING: + /* + * Re-activate the block drives if they're inactivated. Note, COLO + * shouldn't use block_active at all, so it should be no-op there. + */ + migration_block_activate(s); if (runstate_is_live(s->vm_old_state)) { if (!runstate_check(RUN_STATE_SHUTDOWN)) { vm_start(); @@ -3858,6 +3870,8 @@ static void migration_instance_init(Object *obj) ms->state =3D MIGRATION_STATUS_NONE; ms->mbps =3D -1; ms->pages_per_second =3D -1; + /* Freshly started QEMU owns all the block devices */ + ms->block_active =3D true; qemu_sem_init(&ms->pause_sem, 0); qemu_mutex_init(&ms->error_mutex); =20 diff --git a/migration/savevm.c b/migration/savevm.c index 3c75257318..a335344c75 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1549,17 +1549,14 @@ int qemu_savevm_state_complete_precopy_non_iterable= (QEMUFile *f, if (inactivate_disks) { /* Inactivate before sending QEMU_VM_EOF so that the * bdrv_activate_all() on the other end won't fail. */ - ret =3D bdrv_inactivate_all(); - if (ret) { - error_setg(&local_err, "%s: bdrv_inactivate_all() failed (%d)", - __func__, ret); + if (!migration_block_inactivate(ms)) { + error_setg(&local_err, "%s: bdrv_inactivate_all() failed", + __func__); migrate_set_error(ms, local_err); error_report_err(local_err); - qemu_file_set_error(f, ret); + qemu_file_set_error(f, -EFAULT); return ret; } - /* Remember that we did this */ - s->block_inactive =3D true; } if (!in_postcopy) { /* Postcopy stream will still be going */ --=20 2.47.0 From nobody Thu Dec 18 22:24:46 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1733273607; cv=none; d=zohomail.com; s=zohoarc; b=NifNQPezczc2gi+ESOgmivhiroURSnmiO5lKKjdOVe128oTJYflD5/VlkzzegK4sG4Zv+n4e3+DZas/VyU4+lsfeBXNk+O97x6WIUlxfmJBBUBadB2O56lORE7jdnPiMm0mESc0tPLxEXdP+Uy49UpdyxR5MnEV1IS7RbPNqk5g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733273607; 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=41KR4Z+XrJCKzJDc/n7PJZw1zpTfNlrkS9eZ0Nhk9Yk=; b=Wq0IcbmuMSNcFqyHn7oLzSWuctXNlMjwEVsSQIbhuVpgtHi7E869OaRQGx8bYiItp4hSgYRm3HmIGiWyykoXmo5p67t2cfIdpMeJEW2QSDY0hQRp4YTeyYA4IyJhO4KLgxX6wNmEfzU7bk4NUg/wLcOIZJKUuSGAN1wxM7ZmdIU= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1733273606917865.5325883443496; Tue, 3 Dec 2024 16:53:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIdcZ-0003EJ-Tg; Tue, 03 Dec 2024 19:52:04 -0500 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 1tIdcV-0003D5-9r for qemu-devel@nongnu.org; Tue, 03 Dec 2024 19:52:01 -0500 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 1tIdcS-0005fv-VO for qemu-devel@nongnu.org; Tue, 03 Dec 2024 19:51:59 -0500 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-513-YBC6GVfXO_u10_-yLIYm_Q-1; Tue, 03 Dec 2024 19:51:54 -0500 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-7b6732101a6so959239885a.2 for ; Tue, 03 Dec 2024 16:51:53 -0800 (PST) Received: from x1n.redhat.com (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b68492cb81sm559974785a.34.2024.12.03.16.51.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 16:51:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733273516; 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=41KR4Z+XrJCKzJDc/n7PJZw1zpTfNlrkS9eZ0Nhk9Yk=; b=WODDdwBVJl+da3kQiWS3VieJ2yhDxGR5186O02Di4jKhsCSJ+SREDC+pP9LI2hM7xjOpCd lP57OaIGW5OymvnxTkeU5Z64Arw1Q0PYEI1Ja6J+g3TBRuyqlnAV+AJksuxSlxS2wWnvik 9K8WkjPU17fpjndqL6GXl/++snDyEZ8= X-MC-Unique: YBC6GVfXO_u10_-yLIYm_Q-1 X-Mimecast-MFC-AGG-ID: YBC6GVfXO_u10_-yLIYm_Q X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733273513; x=1733878313; 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=41KR4Z+XrJCKzJDc/n7PJZw1zpTfNlrkS9eZ0Nhk9Yk=; b=d0p0DSdvKVlNctheioq/VWlq6vFSpTBZ68bNfpsctg0bZM+MNAHdm7vzmVfReRTZLz EKMmP4gvN26u/t5PMYJeKXoDwmT6KC72/FCoJ76Dto1uFWR5NPAhlu4lWXA4Oo2eG+t1 ywoYSMyDsgLwitHzFqeJIGMwZxEF+RGoW/fGc3WnKlW6ZfcmXrB7B9dvtNLJsdbRBn5G dBWDzWV0vsgC/BiRlIWJK6IiU46mjXX///701zjpN8gvhtKlbl49tpOigpM9G5giDyTj wP28W4UkbJPclYsFssKK8UWCQ+qiZjHrho7L0LrnD0f1eekZhyPa7Uq71leQ97zoaVCC xfNw== X-Gm-Message-State: AOJu0Yw9DSMoDGpdRth8FqHUr3knc24miRQyE/QmG5+5L83amqyFcktO 68Qwh/2oRPZflQmJbYihY3YWKajoRdo1wUbj3GGkCrLHWKSKT98IxQIA/HlBI2MA6CzeBVoBDFF 9RA/hVcaJTBzmUPQGeo5EEC0n/nPeSSoQLYbzROon6YKUpMKDDN7z+VVgLZOcKEEr1drUIngezw k0F6TkNIGUo8auHqoHJSRkExahE6EbQvK3sQ== X-Gm-Gg: ASbGncu5svT5pKxZi4M4lAq59HTsfiOvJdwYh+rwcMoYGCfuVLAhlHKXeXVWdv5/yJo ixRCL6ABbYDDWu3E+fN0/NMaQoqatzyeWvABnztH4toFgUo80tIaTc3+DIiTzMSWzbNfJAmLlcd oVZHSwLdPaxc2xktignnmnhyaOGX3Uw83cUsJlt++9szcMSiE7XQcEU7TyAyXxSmj9qitN6h0EP fKX8yirRHN87dEm6qAbFOeJs6ct0G7fN4DYeJ4Nd8YsDSgORq+TROrm+8Cq4s1gY+52hK0quJYf JZOfpiygLZUIrawCqwwCbEjw1w== X-Received: by 2002:a05:620a:4486:b0:7b1:3f88:48ef with SMTP id af79cd13be357-7b6a617f631mr566394785a.46.1733273512783; Tue, 03 Dec 2024 16:51:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IFOMMP8VoVIvOp3DPzYl64JgJ8DjxMRQ2g3iFH8huNDueUrBW2ZvODw/qIwsDbap+5r5Va0tA== X-Received: by 2002:a05:620a:4486:b0:7b1:3f88:48ef with SMTP id af79cd13be357-7b6a617f631mr566390185a.46.1733273512324; Tue, 03 Dec 2024 16:51:52 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Fabiano Rosas , "Dr . David Alan Gilbert" , Eric Blake , Kevin Wolf , Vladimir Sementsov-Ogievskiy , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Andrey Drobyshev , peterx@redhat.com, Stefan Hajnoczi Subject: [PATCH RFC 06/11] migration/block: Extend the migration_block_* API to dest side Date: Tue, 3 Dec 2024 19:51:33 -0500 Message-ID: <20241204005138.702289-7-peterx@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241204005138.702289-1-peterx@redhat.com> References: <20241204005138.702289-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1733273608118116600 Content-Type: text/plain; charset="utf-8" Extend the usage of such API to the receiver side, because such status maintenance is also necessary there. It's needed to avoid bdrv_inactivate_all() not being invoked when the drives are already inactive. When invoked, it can crash QEMU. See the issue link for more information. So it means we need to start remember the block activation status not only on src, but also on dest. One thing tricky here is, when we need to consider incoming QEMU, we need to also consider its initial status as incoming side. Due to the fact that before switchover the incoming QEMU doesn't own the disks, we need to set initial state to FALSE for a incoming QEMU. In this case, postcopy recover doesn't count. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2395 Signed-off-by: Peter Xu --- migration/migration.h | 13 +++++++++++++ migration/migration.c | 13 +++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/migration/migration.h b/migration/migration.h index b71c062ad2..f477494c5d 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -380,8 +380,21 @@ struct MigrationState { * switchover phase). When that happens, we need to be able to * recover the block drive status by re-activating them. * + * - Currently bdrv_inactivate_all() is not safe to be invoked on top + * of invalidated drives (even if bdrv_activate_all() is actually + * safe to be called any time!). It means remembering this could + * help migration to make sure it won't invalidate twice in a row, + * crashing QEMU. It can happen when we migrate a PAUSED VM from + * host1 to host2, then migrate again to host3 without starting it. + * TODO: a cleaner solution is to allow safe invoke of + * bdrv_inactivate_all() at anytime, like bdrv_activate_all(). + * * For freshly started QEMU, block_active is initialized to TRUE * reflecting the scenario where QEMU owns block device ownerships. + * + * For incoming QEMU taking a migration stream, block_active is set to + * FALSE reflecting that the incoming side doesn't own the block + * devices, not until switchover happens. */ bool block_active; =20 diff --git a/migration/migration.c b/migration/migration.c index 8f7d09ca84..e01264168f 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -701,6 +701,12 @@ migration_incoming_state_setup(MigrationIncomingState = *mis, Error **errp) return false; } =20 + /* + * Newly setup QEMU, prepared for incoming migration. Mark the block + * active state to reflect that the src currently owns the disks. + */ + migrate_get_current()->block_active =3D false; + migrate_set_state(&mis->state, current, MIGRATION_STATUS_SETUP); return true; } @@ -779,7 +785,6 @@ static void qemu_start_incoming_migration(const char *u= ri, bool has_channels, =20 static void process_incoming_migration_bh(void *opaque) { - Error *local_err =3D NULL; MigrationIncomingState *mis =3D opaque; =20 trace_vmstate_downtime_checkpoint("dst-precopy-bh-enter"); @@ -810,11 +815,7 @@ static void process_incoming_migration_bh(void *opaque) * Make sure all file formats throw away their mutable * metadata. If error, don't restart the VM yet. */ - bdrv_activate_all(&local_err); - if (local_err) { - error_report_err(local_err); - local_err =3D NULL; - } else { + if (migration_block_activate(migrate_get_current())) { vm_start(); } } else { --=20 2.47.0 From nobody Thu Dec 18 22:24:46 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1733273607; cv=none; d=zohomail.com; s=zohoarc; b=fABQFS6FVUAo2hfNxO4othkY/nZH55cLvv9v2zvcLc5jFuXWpaM8Mn4brIQ1MS16i71pkOm9HFHbPLPAEzeFK47nm+woQWH84uInFhsUXLK01Jn3npnmNWMxxmtYGygKF/MCAwn1Bihfpif8kntabhkpUVuz4czsfu7+Yhp+pR8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733273607; 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=2o9Ay7I+xylCE7OLCz2N3wxn74Ig5CUQWEe8c1yR3tA=; b=dmMoVNtioeqWicFdGQDWUfFjz49+HW5qjzPppWb3+IKVmdM7sVpyMghTeIQ4opNYKgMIx+LChEUWFTYfD/EYKWtZFJoylYSQAt2buzovVimITAG3E84Fphl9Ff8pMLf5d3YyOeg4EQQXMi37OA9B6i0GOYmPrAU9QumEVQHbLVc= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1733273606996412.9894145577654; Tue, 3 Dec 2024 16:53:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIdcr-0003IU-PR; Tue, 03 Dec 2024 19:52:21 -0500 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 1tIdca-0003EX-2b for qemu-devel@nongnu.org; Tue, 03 Dec 2024 19:52:04 -0500 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 1tIdcX-0005jg-8x for qemu-devel@nongnu.org; Tue, 03 Dec 2024 19:52:03 -0500 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-589-KAHrG_rzOdOUT933QscutA-1; Tue, 03 Dec 2024 19:51:58 -0500 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-6d8860ab00dso73556976d6.0 for ; Tue, 03 Dec 2024 16:51:58 -0800 (PST) Received: from x1n.redhat.com (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b68492cb81sm559974785a.34.2024.12.03.16.51.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 16:51:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733273519; 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=2o9Ay7I+xylCE7OLCz2N3wxn74Ig5CUQWEe8c1yR3tA=; b=S+R4U5DKPnNNztDp09EwjkwQwaOscF1xNuKy21d3xj7rs5kJT/UNPrYZXffVE/U5L5kfKC /pdVxaLhxDFvNGS9atwQzEwDYtKDD5ZR+BsfDZCXYpHpEMfi+x8uupWhz1955rowc1GWJ5 tixJAR9XOEEhiVuSpUdnqj0zH3vIF2k= X-MC-Unique: KAHrG_rzOdOUT933QscutA-1 X-Mimecast-MFC-AGG-ID: KAHrG_rzOdOUT933QscutA X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733273517; x=1733878317; 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=2o9Ay7I+xylCE7OLCz2N3wxn74Ig5CUQWEe8c1yR3tA=; b=gTVdZ70sIcOdnlVEFSwgrV5qq6lvEe4RG/2dkr20V7uV9rzbnD56h8HG0aextkm17k m1zX9YTrOIQNvLBqKu33SkeATLLRKFAqk8IWfOGDRi3i2dNY/PegxB1AGtlzgUYu4nbf FewfGNaEQrJgmsDVLD7cB+J6XfBrZTOSnUDOzZ5imJocJl+2ryaSvAHQ6xitXEqgXwhF Y5XIo4Qs72Bhc3FFVdQQnvvsXcw7FiKl3U+qGTBOLshcPTX2FB9Kur/SjPGlMaAvISmX NnTWEjTY2rYMC9DsZZOQrwR8Dse1YWQXPTs92W5FDdHokqKZvlCjVgpD7WVA86TgUdZ4 cnRw== X-Gm-Message-State: AOJu0YwKE4TFE7OkZfk+8PqAQ3gptGky9XZKDIuqNK6xOeBSFEpNfe+E BE4PKDLwpIVz2weQDBmfdCS5mMprIHyzlbahimSwXU8T3PuNsCsAur18ktFAMdlYNtOoZMxs2RE TeKSW02Qj1kmogySPksCWQox4MCg2kwO+vUdoA/HYFTpe2CAAgfmZABAisyPDgjDWaihnbRVK8y 2HPpC/1CoeU8YmZyOBJ28VO9WoEiSIUIf+OA== X-Gm-Gg: ASbGncu/zWt40junuKqoKif1JdnhDVufWRwTRaeqoOg02DbunEFjdx81a5JTTRWLqxS sxD2zo5GvlXVHCz4CNFMpLjfClPshLiFHmsVMiI+zaHipVaBmEzJcahCQpu94KtACC1M9Y6yhhn OLBpz1Tb1I59pgzbx1X5OYOLjmMV3MsF65PP9hCOtYN25hfvRMvyUu62MfofEpqz/KJmYiWyQX9 4feo7P6p4CY07VLPomBGIHJnO7QxeaM72kUa7YWRfgvtgk8C1DhVbHkZqzJwtJ4jCuImJpd10q8 d3cuZrKckO3/w+et7LC84iQSKQ== X-Received: by 2002:a05:6214:c85:b0:6d8:9124:8799 with SMTP id 6a1803df08f44-6d8b72f1f6dmr77855936d6.5.1733273516406; Tue, 03 Dec 2024 16:51:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IFSCNQw8j7E14VNPjP3P6I4wf6VCAZ9mSIt9xG51R5aX1oKUj8/MP/VArfso8yNho0pXXHkbQ== X-Received: by 2002:a05:6214:c85:b0:6d8:9124:8799 with SMTP id 6a1803df08f44-6d8b72f1f6dmr77854586d6.5.1733273514563; Tue, 03 Dec 2024 16:51:54 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Fabiano Rosas , "Dr . David Alan Gilbert" , Eric Blake , Kevin Wolf , Vladimir Sementsov-Ogievskiy , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Andrey Drobyshev , peterx@redhat.com, Stefan Hajnoczi Subject: [PATCH RFC 07/11] migration/block: Apply the migration_block_* API to postcopy Date: Tue, 3 Dec 2024 19:51:34 -0500 Message-ID: <20241204005138.702289-8-peterx@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241204005138.702289-1-peterx@redhat.com> References: <20241204005138.702289-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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: 1733273608111116600 Content-Type: text/plain; charset="utf-8" Postcopy also has similar error handling for re-activation of block devices. Use the same API as precopy to do the re-activation, for both src & dst sides. Signed-off-by: Peter Xu --- migration/migration.c | 22 +++------------------- migration/savevm.c | 10 ++++------ 2 files changed, 7 insertions(+), 25 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index e01264168f..1a1c570c5b 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2544,7 +2544,6 @@ static int postcopy_start(MigrationState *ms, Error *= *errp) QIOChannelBuffer *bioc; QEMUFile *fb; uint64_t bandwidth =3D migrate_max_postcopy_bandwidth(); - bool restart_block =3D false; int cur_state =3D MIGRATION_STATUS_ACTIVE; =20 if (migrate_postcopy_preempt()) { @@ -2580,13 +2579,10 @@ static int postcopy_start(MigrationState *ms, Error= **errp) goto fail; } =20 - ret =3D bdrv_inactivate_all(); - if (ret < 0) { - error_setg_errno(errp, -ret, "%s: Failed in bdrv_inactivate_all()", - __func__); + if (!migration_block_inactivate(ms)) { + error_setg(errp, "%s: Failed in bdrv_inactivate_all()", __func__); goto fail; } - restart_block =3D true; =20 /* * Cause any non-postcopiable, but iterative devices to @@ -2656,8 +2652,6 @@ static int postcopy_start(MigrationState *ms, Error *= *errp) goto fail_closefb; } =20 - restart_block =3D false; - /* Now send that blob */ if (qemu_savevm_send_packaged(ms->to_dst_file, bioc->data, bioc->usage= )) { error_setg(errp, "%s: Failed to send packaged data", __func__); @@ -2702,17 +2696,7 @@ fail_closefb: fail: migrate_set_state(&ms->state, MIGRATION_STATUS_POSTCOPY_ACTIVE, MIGRATION_STATUS_FAILED); - if (restart_block) { - /* A failure happened early enough that we know the destination ha= sn't - * accessed block devices, so we're safe to recover. - */ - Error *local_err =3D NULL; - - bdrv_activate_all(&local_err); - if (local_err) { - error_report_err(local_err); - } - } + migration_block_activate(ms); migration_call_notifiers(ms, MIG_EVENT_PRECOPY_FAILED, NULL); bql_unlock(); return -1; diff --git a/migration/savevm.c b/migration/savevm.c index a335344c75..2ce5064efc 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2120,7 +2120,6 @@ static int loadvm_postcopy_handle_listen(MigrationInc= omingState *mis) =20 static void loadvm_postcopy_handle_run_bh(void *opaque) { - Error *local_err =3D NULL; MigrationIncomingState *mis =3D opaque; =20 trace_vmstate_downtime_checkpoint("dst-postcopy-bh-enter"); @@ -2141,12 +2140,11 @@ static void loadvm_postcopy_handle_run_bh(void *opa= que) if (autostart) { /* Make sure all file formats throw away their mutable metadata. * If we get an error here, just don't restart the VM yet. */ - bdrv_activate_all(&local_err); + bool success =3D migration_block_activate(migrate_get_current()); + trace_vmstate_downtime_checkpoint("dst-postcopy-bh-cache-invalidat= ed"); - if (local_err) { - error_report_err(local_err); - local_err =3D NULL; - } else { + + if (success) { vm_start(); } } else { --=20 2.47.0 From nobody Thu Dec 18 22:24:46 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1733273607; cv=none; d=zohomail.com; s=zohoarc; b=WO066zaikz6gdSKhW/cxvGkdlygFvqU5FCKpG9g2A/70BlxUSixJOU9NWWEbusootcjB+vOSheTGFQc+if7qzrMKFhadtZRwiTk9s6OSaY9IyixLyI9sIDu32QdRTriDDemWAe6TKz8UiyB2i44JeV3mi0lt/36oFpadjcIIlgw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733273607; 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=FO857v8PXpejg9RDiLcW7mg3vTpTDPgqvs32Ru5PZEU=; b=hmqTST6MoxdYlpFl7ajycnPGDVC0Upmp3d2P/taw13lu5MU6jvdjMI+bt/w5qYsenuTxox+36nIjxod6S4fnhy0TY4wrYifOFSCXITWQfJpjGjNudBzCCouUbuNAWg9uevV4MkTk8zobbx4PzRskqSYfFeqzU8gtsfG+VdVOdnk= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1733273607466956.5636596700605; Tue, 3 Dec 2024 16:53:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIdcd-0003GP-82; Tue, 03 Dec 2024 19:52:07 -0500 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 1tIdca-0003EW-2S for qemu-devel@nongnu.org; Tue, 03 Dec 2024 19:52:04 -0500 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 1tIdcX-0005mR-Bp for qemu-devel@nongnu.org; Tue, 03 Dec 2024 19:52:03 -0500 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-439-vnQLAfvnNgKX0kpvKATMgQ-1; Tue, 03 Dec 2024 19:51:58 -0500 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-7b674755f8eso973410185a.2 for ; Tue, 03 Dec 2024 16:51:58 -0800 (PST) Received: from x1n.redhat.com (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b68492cb81sm559974785a.34.2024.12.03.16.51.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 16:51:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733273520; 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=FO857v8PXpejg9RDiLcW7mg3vTpTDPgqvs32Ru5PZEU=; b=cgsSaEKFm/jRc71xrQh3fpTmo3h2QCbA59L8Ryed5tgz6y8tIsYjVhsk7rfwSJF6FWiiPY 6JTDdUJBrvbjTqFfe9DiF49DEasidp6u3PLPsZy0371JioSjZgbLGnR6kezRaIUpt3Rjt6 7hy+i/wFP0JfrNfB2akCDtJXvWKjqEM= X-MC-Unique: vnQLAfvnNgKX0kpvKATMgQ-1 X-Mimecast-MFC-AGG-ID: vnQLAfvnNgKX0kpvKATMgQ X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733273517; x=1733878317; 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=FO857v8PXpejg9RDiLcW7mg3vTpTDPgqvs32Ru5PZEU=; b=I2bu++OonTWgtHmP65KJocWMDePR/a3pzjIcUozgLNck9e5MZCzSV6mU18lJYKYHOZ RIp9iiR2NpcLFFLxO1p+d5C3rB1pmK6TZJx7lpiEosswnCt9syPp8gU8fmIp2ud9N/Dj b0SSc5HFLPLSk/ppYV23uQBQBCUjB6WXSipCRtYIveasWU+E5lHcywXcnsomyPaQWd20 OaRQV4r01+mfqAOsUYh8l/NSSRO6I5fWlhxu0jmUZ0nQmLeFzkff2CgoTJyX3BiEoj1X tpRYxTYxXfEOUqBZdhGsxGfVCk0UadFsF6SdcYoVCR7Mj+NCGI28vn28AvMWjsL5fbxX V8kg== X-Gm-Message-State: AOJu0Yx7MBvd/7AWC5qZVlcJzZIEQruGK9fxJbbwCNFC+BvLrh+IIgDA eaoSYBWMp4fHjf9IFsqE8F43qW/P57XUcPSXbuaOANVwzGTEzYia4r6rI0x9ZtVIj1j8cYlkLG1 3FpOpCJpD2jVG6znSU6fN5K/grcjaQ1pO2jsEsUL8sWJuEHlHSBj1GoBPwxP00XvlQs5MH7fVxF cyJUGGeHTb4n+h6WOHL7GxIGztw5G740HJlA== X-Gm-Gg: ASbGncvloFhhusYeBB1DEd4245PZZZ8p3J61+x6I7OsY/m03+UyukErrGqxjlGx99dd zYIn6heB1XdgSUBbqqM83AbhfXolFsYuo3S7XAc24iFySif97BCJA978778kL4SF/g8yXt4nUpQ JwdoSl5TJw0+6ndOE7/4pNJvDHMiFnACpuzRP69jPsp6XyNBVBzeuwfss4hiIZSthho8SiLnIlv rCon8TY3YYfwBvpk8EAYO7JT1UsTs1xd+CPZ6vYkWWA0gE+XgVCXL16vjY6AyWzQM804UIhS6H+ TbEF4lSp3z+YnnZ0D1J63Cn9qg== X-Received: by 2002:a05:620a:4055:b0:7b1:49f7:90ba with SMTP id af79cd13be357-7b6a5d2aaeemr445151785a.8.1733273517145; Tue, 03 Dec 2024 16:51:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IE9rF+JJXp5CLxVWRXQlAO86ovXcvfXhQo2/q858VposVDTqkI5X6HSAIkJIvy6d+u5ez8+zw== X-Received: by 2002:a05:620a:4055:b0:7b1:49f7:90ba with SMTP id af79cd13be357-7b6a5d2aaeemr445147985a.8.1733273516606; Tue, 03 Dec 2024 16:51:56 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Fabiano Rosas , "Dr . David Alan Gilbert" , Eric Blake , Kevin Wolf , Vladimir Sementsov-Ogievskiy , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Andrey Drobyshev , peterx@redhat.com, Stefan Hajnoczi Subject: [PATCH RFC 08/11] tests/qtest/migration: Move more code under only_target Date: Tue, 3 Dec 2024 19:51:35 -0500 Message-ID: <20241204005138.702289-9-peterx@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241204005138.702289-1-peterx@redhat.com> References: <20241204005138.702289-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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: 1733273609668116600 Content-Type: text/plain; charset="utf-8" From: Fabiano Rosas The only_target option's purpose is to make sure only the destination QTestState machine is initialized. This allows the test code to retain an already initialized source machine (e.g. for doing ping pong migration). We have drifted from that a bit when adding new code, so move some lines under only_target to restore the functionality. Signed-off-by: Fabiano Rosas Link: https://lore.kernel.org/r/20241125144612.16194-2-farosas@suse.de Signed-off-by: Peter Xu --- tests/qtest/migration-test.c | 44 ++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index 74d3000198..eafc2da806 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -717,7 +717,6 @@ static int test_migrate_start(QTestState **from, QTestS= tate **to, g_autofree gchar *arch_target =3D NULL; /* options for source and target */ g_autofree gchar *arch_opts =3D NULL; - g_autofree gchar *cmd_source =3D NULL; g_autofree gchar *cmd_target =3D NULL; const gchar *ignore_stderr; g_autofree char *shmem_opts =3D NULL; @@ -735,10 +734,7 @@ static int test_migrate_start(QTestState **from, QTest= State **to, } } =20 - dst_state =3D (QTestMigrationState) { }; - src_state =3D (QTestMigrationState) { }; bootfile_create(tmpfs, args->suspend_me); - src_state.suspend_me =3D args->suspend_me; =20 if (strcmp(arch, "i386") =3D=3D 0 || strcmp(arch, "x86_64") =3D=3D 0) { memory_size =3D "150M"; @@ -817,27 +813,35 @@ static int test_migrate_start(QTestState **from, QTes= tState **to, =20 g_test_message("Using machine type: %s", machine); =20 - cmd_source =3D g_strdup_printf("-accel kvm%s -accel tcg " - "-machine %s,%s " - "-name source,debug-threads=3Don " - "-m %s " - "-serial file:%s/src_serial " - "%s %s %s %s %s", - kvm_opts ? kvm_opts : "", - machine, machine_opts, - memory_size, tmpfs, - arch_opts ? arch_opts : "", - arch_source ? arch_source : "", - shmem_opts ? shmem_opts : "", - args->opts_source ? args->opts_source : "= ", - ignore_stderr); if (!args->only_target) { + g_autofree gchar *cmd_source =3D NULL; + + src_state =3D (QTestMigrationState) { }; + src_state.suspend_me =3D args->suspend_me; + + cmd_source =3D g_strdup_printf("-accel kvm%s -accel tcg " + "-machine %s,%s " + "-name source,debug-threads=3Don " + "-m %s " + "-serial file:%s/src_serial " + "%s %s %s %s %s", + kvm_opts ? kvm_opts : "", + machine, machine_opts, + memory_size, tmpfs, + arch_opts ? arch_opts : "", + arch_source ? arch_source : "", + shmem_opts ? shmem_opts : "", + args->opts_source ? args->opts_source= : "", + ignore_stderr); + *from =3D qtest_init_with_env(QEMU_ENV_SRC, cmd_source); qtest_qmp_set_event_callback(*from, migrate_watch_for_events, &src_state); } =20 + dst_state =3D (QTestMigrationState) { }; + cmd_target =3D g_strdup_printf("-accel kvm%s -accel tcg " "-machine %s,%s " "-name target,debug-threads=3Don " @@ -870,7 +874,9 @@ static int test_migrate_start(QTestState **from, QTestS= tate **to, * Always enable migration events. Libvirt always uses it, let's try * to mimic as closer as that. */ - migrate_set_capability(*from, "events", true); + if (!args->only_target) { + migrate_set_capability(*from, "events", true); + } migrate_set_capability(*to, "events", true); =20 return 0; --=20 2.47.0 From nobody Thu Dec 18 22:24:46 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1733273607; cv=none; d=zohomail.com; s=zohoarc; b=iHT1h2q44b2txm2/glMqKte5kTNJ6dycl/iY28ptkjBN5OEErDKLWHa5d56ByigJ5HpHxPne77T0hU6m93+KqQ/5SsIQc1QKhs7zu8ZoKzZbld03025kJr+s8WTOOxCZmnzYLtXEIaGbDUdbay1s2Ce0JPzGVUd+6GzpjB7ldS8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733273607; 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=Lm/P/jIwMwruD4XzBa8oclsmE6F53aZByJkttYW/WWw=; b=d8eDvX1uoypRm7/OWboECz3o6Kwlj/PDli7nK/JMuMwiaMfE0U5dA5lz3FM87Gs+f9JLGD14nbXNQ0dqMsLRkS6Tq5Q3ZKe+euURxCxjcueO4cDdCaGnKpuNPuilIiM+U71KwybZnRErogguoA2TGi18qCcTWrRuGrU1TvXcW5A= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1733273607080765.8130371973707; Tue, 3 Dec 2024 16:53:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIdcz-0003KZ-3t; Tue, 03 Dec 2024 19:52:29 -0500 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 1tIdcc-0003G5-M0 for qemu-devel@nongnu.org; Tue, 03 Dec 2024 19:52:06 -0500 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 1tIdca-0005r8-Im for qemu-devel@nongnu.org; Tue, 03 Dec 2024 19:52:06 -0500 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-661-YIuoHBM3Nv6sHeFW8imlqw-1; Tue, 03 Dec 2024 19:52:02 -0500 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-7b66724f242so822266185a.2 for ; Tue, 03 Dec 2024 16:52:01 -0800 (PST) Received: from x1n.redhat.com (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b68492cb81sm559974785a.34.2024.12.03.16.51.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 16:51:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733273523; 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=Lm/P/jIwMwruD4XzBa8oclsmE6F53aZByJkttYW/WWw=; b=CudD6YNavcgUin+Co1LDKeJguuXrz51e2Lq12tnKFZMgyENJA3PJdLjnXEhbao45tJHlYs ndsXf7nZcC/k3ymCb/G0jYCxeuv3Mpqc7CjZwlTsiQcXKRDe1F5GCFOHqcfgRMLoBAcH0C MuHACCjQh3sLnvxpwVT08UbYOd0vWqk= X-MC-Unique: YIuoHBM3Nv6sHeFW8imlqw-1 X-Mimecast-MFC-AGG-ID: YIuoHBM3Nv6sHeFW8imlqw X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733273520; x=1733878320; 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=Lm/P/jIwMwruD4XzBa8oclsmE6F53aZByJkttYW/WWw=; b=CqeqIp9sCgYXJsKrsxKav5Bo40wdwWkFQY/LPIqMoWybvlmL6VFEtrqCFD1PQR0SGP FA1om7jYy1OX4FSc2BQh3ZUpuguwikAsasLoF3E28o3+hHcC/wCa4jFy7AA0RrMAXRe9 IJqbZ9DYev3Ki9x9kUfrGTV2o7ZVOkkcFbKQIArpliBfCV2hjEhWgflT8yHNF1toctit g+9WUHRMKxM+/T2yfJzj/vv19aTUno5KdVjStaPhLyjFgcXBgqyXLIKn63AZcu29fFfD QR30qqe6LbB6kivZu7uaFlimQqNoJUlqfiyW1hBGoSjZdjhZ1VDxwiZZEHK0Tzw2t0OP u7YQ== X-Gm-Message-State: AOJu0YygxlTme90vBwFOuObscDeOu42wLtx2tUcw0fvHhDMzxylTAzSs qr5qe/GWFjm1t9ENTfOXM2ZNMtJCbHyyZrgZuLKjsBWCgVxUhtCzGjgbIpbp1J0n0WcY6+YUwyP KvP3oWglLjrVI8jSw0Ervj4R06nZQF6UOohGo/2RPVEsdnCg6ieXJTHY0k1sVKHgWJ4OiesMlKC opLuxRrU4fSLh5XWYN9Uk68bZGBB0DvsuXBg== X-Gm-Gg: ASbGncv8zGYhSDx/Y1+nSuv0MExktuE60urM5ysjl2wDqd4FvSQbrse/HbrkQ5lz/Vq 5JFgnPjyhpusfPKASqhbemSjjNQ26j8Aa/USJBNIsUd66JIRLO+ICe5UhOtASoGy6Ga3e+a1KPB mzBP6clgCK/TRhDbVEXrsX41eGaoGtwSs2+PovAcAxiUpB9XPfFCIsHNjmyrf1Pnl66ErFijdq0 dMEXD8rljsho2A9SAO5taGOSK9GWpocQSsbRnspNKM1u9UqvmZE5uquGWEhNa5A1o9ECeT+pMRZ aE5s4M6m9vEAh6rNId09wYFt1Q== X-Received: by 2002:a05:620a:2408:b0:7b6:6365:1b72 with SMTP id af79cd13be357-7b6a5d2073emr613217985a.3.1733273519901; Tue, 03 Dec 2024 16:51:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IE3ehHw+bMA4K4ztxLeKi6Ucp6THmJxt72TbRS5NcTYNqQyu7e332g7IaAHGL4zeTDyoJ21Cw== X-Received: by 2002:a05:620a:2408:b0:7b6:6365:1b72 with SMTP id af79cd13be357-7b6a5d2073emr613213785a.3.1733273519486; Tue, 03 Dec 2024 16:51:59 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Fabiano Rosas , "Dr . David Alan Gilbert" , Eric Blake , Kevin Wolf , Vladimir Sementsov-Ogievskiy , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Andrey Drobyshev , peterx@redhat.com, Stefan Hajnoczi Subject: [PATCH RFC 09/11] tests/qtest/migration: Don't use hardcoded strings for -serial Date: Tue, 3 Dec 2024 19:51:36 -0500 Message-ID: <20241204005138.702289-10-peterx@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241204005138.702289-1-peterx@redhat.com> References: <20241204005138.702289-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1733273608308116600 Content-Type: text/plain; charset="utf-8" From: Fabiano Rosas Stop using hardcoded strings for -serial so we can in the next patches perform more than one migration in a row. Having the serial path hardcoded means we cannot reuse the code when dst becomes the new src. Signed-off-by: Fabiano Rosas Link: https://lore.kernel.org/r/20241125144612.16194-3-farosas@suse.de Signed-off-by: Peter Xu --- tests/qtest/migration-helpers.h | 2 + tests/qtest/migration-helpers.c | 8 ++++ tests/qtest/migration-test.c | 68 ++++++++++++++++++--------------- 3 files changed, 48 insertions(+), 30 deletions(-) diff --git a/tests/qtest/migration-helpers.h b/tests/qtest/migration-helper= s.h index 72dba369fb..c7a36a33d6 100644 --- a/tests/qtest/migration-helpers.h +++ b/tests/qtest/migration-helpers.h @@ -20,6 +20,7 @@ typedef struct QTestMigrationState { bool resume_seen; bool suspend_seen; bool suspend_me; + char *serial; } QTestMigrationState; =20 bool migrate_watch_for_events(QTestState *who, const char *name, @@ -64,5 +65,6 @@ static inline bool probe_o_direct_support(const char *tmp= fs) #endif void migration_test_add(const char *path, void (*fn)(void)); void migration_event_wait(QTestState *s, const char *target); +char *migrate_get_unique_serial(const char *tmpfs); =20 #endif /* MIGRATION_HELPERS_H */ diff --git a/tests/qtest/migration-helpers.c b/tests/qtest/migration-helper= s.c index 3f8ba7fa8e..7c0b54ce0e 100644 --- a/tests/qtest/migration-helpers.c +++ b/tests/qtest/migration-helpers.c @@ -528,3 +528,11 @@ void migration_event_wait(QTestState *s, const char *t= arget) qobject_unref(response); } while (!found); } + +char *migrate_get_unique_serial(const char *tmpfs) +{ + static int i; + + assert(i < INT_MAX); + return g_strdup_printf("%s/serial_%d", tmpfs, i++); +} diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index eafc2da806..1452778c81 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -192,9 +192,8 @@ static void bootfile_create(char *dir, bool suspend_me) * we get an 'A' followed by an endless string of 'B's * but on the destination we won't have the A (unless we enabled suspend/r= esume) */ -static void wait_for_serial(const char *side) +static void wait_for_serial(const char *serialpath) { - g_autofree char *serialpath =3D g_strdup_printf("%s/%s", tmpfs, side); FILE *serialfile =3D fopen(serialpath, "r"); =20 do { @@ -216,7 +215,7 @@ static void wait_for_serial(const char *side) break; =20 default: - fprintf(stderr, "Unexpected %d on %s serial\n", readvalue, sid= e); + fprintf(stderr, "Unexpected %d on %s\n", readvalue, serialpath= ); g_assert_not_reached(); } } while (true); @@ -818,16 +817,17 @@ static int test_migrate_start(QTestState **from, QTes= tState **to, =20 src_state =3D (QTestMigrationState) { }; src_state.suspend_me =3D args->suspend_me; + src_state.serial =3D migrate_get_unique_serial(tmpfs); =20 cmd_source =3D g_strdup_printf("-accel kvm%s -accel tcg " "-machine %s,%s " "-name source,debug-threads=3Don " "-m %s " - "-serial file:%s/src_serial " + "-serial file:%s " "%s %s %s %s %s", kvm_opts ? kvm_opts : "", machine, machine_opts, - memory_size, tmpfs, + memory_size, src_state.serial, arch_opts ? arch_opts : "", arch_source ? arch_source : "", shmem_opts ? shmem_opts : "", @@ -841,17 +841,18 @@ static int test_migrate_start(QTestState **from, QTes= tState **to, } =20 dst_state =3D (QTestMigrationState) { }; + dst_state.serial =3D migrate_get_unique_serial(tmpfs); =20 cmd_target =3D g_strdup_printf("-accel kvm%s -accel tcg " "-machine %s,%s " "-name target,debug-threads=3Don " "-m %s " - "-serial file:%s/dest_serial " + "-serial file:%s " "-incoming %s " "%s %s %s %s %s", kvm_opts ? kvm_opts : "", machine, machine_opts, - memory_size, tmpfs, uri, + memory_size, dst_state.serial, uri, arch_opts ? arch_opts : "", arch_target ? arch_target : "", shmem_opts ? shmem_opts : "", @@ -911,8 +912,10 @@ static void test_migrate_end(QTestState *from, QTestSt= ate *to, bool test_dest) qtest_quit(to); =20 cleanup("migsocket"); - cleanup("src_serial"); - cleanup("dest_serial"); + unlink(src_state.serial); + g_free(src_state.serial); + unlink(dst_state.serial); + g_free(dst_state.serial); cleanup(FILE_TEST_FILENAME); } =20 @@ -1290,7 +1293,7 @@ static int migrate_postcopy_prepare(QTestState **from= _ptr, " 'port': '0' } } ] } }"); =20 /* Wait for the first serial output from the source */ - wait_for_serial("src_serial"); + wait_for_serial(src_state.serial); wait_for_suspend(from, &src_state); =20 migrate_qmp(from, to, NULL, NULL, "{}"); @@ -1314,7 +1317,7 @@ static void migrate_postcopy_complete(QTestState *fro= m, QTestState *to, } =20 /* Make sure we get at least one "B" on destination */ - wait_for_serial("dest_serial"); + wait_for_serial(dst_state.serial); =20 if (uffd_feature_thread_id) { read_blocktime(to); @@ -1719,7 +1722,7 @@ static void test_precopy_common(MigrateCommon *args) =20 /* Wait for the first serial output from the source */ if (args->result =3D=3D MIG_TEST_SUCCEED) { - wait_for_serial("src_serial"); + wait_for_serial(src_state.serial); wait_for_suspend(from, &src_state); } =20 @@ -1796,7 +1799,7 @@ static void test_precopy_common(MigrateCommon *args) qtest_qmp_assert_success(to, "{'execute': 'system_wakeup'}"); } =20 - wait_for_serial("dest_serial"); + wait_for_serial(dst_state.serial); } =20 finish: @@ -1871,7 +1874,7 @@ static void test_file_common(MigrateCommon *args, boo= l stop_src) } =20 migrate_ensure_converge(from); - wait_for_serial("src_serial"); + wait_for_serial(src_state.serial); =20 if (stop_src) { qtest_qmp_assert_success(from, "{ 'execute' : 'stop'}"); @@ -1898,7 +1901,7 @@ static void test_file_common(MigrateCommon *args, boo= l stop_src) } wait_for_resume(to, &dst_state); =20 - wait_for_serial("dest_serial"); + wait_for_serial(dst_state.serial); =20 if (check_offset) { file_check_offset_region(); @@ -2041,7 +2044,7 @@ static void test_ignore_shared(void) migrate_set_capability(to, "x-ignore-shared", true); =20 /* Wait for the first serial output from the source */ - wait_for_serial("src_serial"); + wait_for_serial(src_state.serial); =20 migrate_qmp(from, to, uri, NULL, "{}"); =20 @@ -2051,7 +2054,7 @@ static void test_ignore_shared(void) =20 qtest_qmp_eventwait(to, "RESUME"); =20 - wait_for_serial("dest_serial"); + wait_for_serial(dst_state.serial); wait_for_migration_complete(from); =20 /* Check whether shared RAM has been really skipped */ @@ -2669,7 +2672,7 @@ static void do_test_validate_uuid(MigrateStart *args,= bool should_fail) migrate_set_capability(from, "validate-uuid", true); =20 /* Wait for the first serial output from the source */ - wait_for_serial("src_serial"); + wait_for_serial(src_state.serial); =20 migrate_qmp(from, to, uri, NULL, "{}"); =20 @@ -2733,7 +2736,7 @@ static void do_test_validate_uri_channel(MigrateCommo= n *args) } =20 /* Wait for the first serial output from the source */ - wait_for_serial("src_serial"); + wait_for_serial(src_state.serial); =20 /* * 'uri' and 'channels' validation is checked even before the migration @@ -2823,7 +2826,7 @@ static void test_migrate_auto_converge(void) migrate_set_capability(from, "pause-before-switchover", true); =20 /* Wait for the first serial output from the source */ - wait_for_serial("src_serial"); + wait_for_serial(src_state.serial); =20 migrate_qmp(from, to, uri, NULL, "{}"); =20 @@ -2885,7 +2888,7 @@ static void test_migrate_auto_converge(void) =20 qtest_qmp_eventwait(to, "RESUME"); =20 - wait_for_serial("dest_serial"); + wait_for_serial(dst_state.serial); wait_for_migration_complete(from); =20 test_migrate_end(from, to, true); @@ -3296,7 +3299,7 @@ static void test_multifd_tcp_cancel(void) migrate_incoming_qmp(to, "tcp:127.0.0.1:0", "{}"); =20 /* Wait for the first serial output from the source */ - wait_for_serial("src_serial"); + wait_for_serial(src_state.serial); =20 migrate_qmp(from, to, NULL, NULL, "{}"); =20 @@ -3307,7 +3310,8 @@ static void test_multifd_tcp_cancel(void) /* Make sure QEMU process "to" exited */ qtest_set_expected_status(to, EXIT_FAILURE); qtest_wait_qemu(to); - qtest_quit(to); + unlink(dst_state.serial); + g_free(dst_state.serial); =20 /* * Ensure the source QEMU finishes its cancellation process before we @@ -3345,7 +3349,7 @@ static void test_multifd_tcp_cancel(void) wait_for_stop(from, &src_state); qtest_qmp_eventwait(to2, "RESUME"); =20 - wait_for_serial("dest_serial"); + wait_for_serial(dst_state.serial); wait_for_migration_complete(from); test_migrate_end(from, to2, true); } @@ -3488,13 +3492,16 @@ static QTestState *dirtylimit_start_vm(void) QTestState *vm =3D NULL; g_autofree gchar *cmd =3D NULL; =20 + src_state =3D (QTestMigrationState) { }; + src_state.serial =3D migrate_get_unique_serial(tmpfs); + bootfile_create(tmpfs, false); cmd =3D g_strdup_printf("-accel kvm,dirty-ring-size=3D4096 " "-name dirtylimit-test,debug-threads=3Don " "-m 150M -smp 1 " - "-serial file:%s/vm_serial " + "-serial file:%s " "-drive file=3D%s,format=3Draw ", - tmpfs, bootpath); + src_state.serial, bootpath); =20 vm =3D qtest_init(cmd); return vm; @@ -3503,7 +3510,8 @@ static QTestState *dirtylimit_start_vm(void) static void dirtylimit_stop_vm(QTestState *vm) { qtest_quit(vm); - cleanup("vm_serial"); + unlink(src_state.serial); + g_free(src_state.serial); } =20 static void test_vcpu_dirty_limit(void) @@ -3519,7 +3527,7 @@ static void test_vcpu_dirty_limit(void) vm =3D dirtylimit_start_vm(); =20 /* Wait for the first serial output from the vm*/ - wait_for_serial("vm_serial"); + wait_for_serial(src_state.serial); =20 /* Do dirtyrate measurement with calc time equals 1s */ calc_dirty_rate(vm, 1); @@ -3612,7 +3620,7 @@ static void migrate_dirty_limit_wait_showup(QTestStat= e *from, migrate_set_capability(from, "pause-before-switchover", true); =20 /* Wait for the serial output from the source */ - wait_for_serial("src_serial"); + wait_for_serial(src_state.serial); } =20 /* @@ -3751,7 +3759,7 @@ static void test_migrate_dirty_limit(void) =20 qtest_qmp_eventwait(to, "RESUME"); =20 - wait_for_serial("dest_serial"); + wait_for_serial(dst_state.serial); wait_for_migration_complete(from); =20 test_migrate_end(from, to, true); --=20 2.47.0 From nobody Thu Dec 18 22:24:46 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1733273647; cv=none; d=zohomail.com; s=zohoarc; b=CoYtSx6k/MtE5v05ZpUxA6STFqOfFMvBni57MBmKOejwRuKd6xri1mnm0147uQnuGJ2MKJfKHemQsskARArhf4yhTjuMKrCXLxtgHZ7M4XrSTK97Nh1OVi1bqslnsF+YTOx+143zFeDjSHJ0Ir6TI0m3fCz8ngw6UL7dltTCt6o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733273647; 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=d/1lUrwSbtWDIYxhFmJMUTG/9ArL3F+YVTSB3vhHZLQ=; b=Ft0HwGHQCsa2SjdO59sBCFKbg/vxWSQRGbycZWDGMd640lBp/3nFxEYOfb3972w1JhZe47VZNis3NrOAe3sbM1PJPsilbMv7apiAhyvu11zKvn8Ms5mB6EaSVcNN1TNkRw7bZfIxhtZSyoZsWIfwQGrKOMjeg5zJW1ua5SKeH+w= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1733273647404487.6167171562844; Tue, 3 Dec 2024 16:54:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIdcy-0003KG-Cl; Tue, 03 Dec 2024 19:52:28 -0500 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 1tIdcc-0003Fz-EM for qemu-devel@nongnu.org; Tue, 03 Dec 2024 19:52:06 -0500 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 1tIdca-0005rC-Ju for qemu-devel@nongnu.org; Tue, 03 Dec 2024 19:52:06 -0500 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-158-LeBMOdLJNkCcjtIHbCNGvw-1; Tue, 03 Dec 2024 19:52:03 -0500 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-6d8b3173b5bso26845296d6.3 for ; Tue, 03 Dec 2024 16:52:02 -0800 (PST) Received: from x1n.redhat.com (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b68492cb81sm559974785a.34.2024.12.03.16.51.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 16:52:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733273524; 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=d/1lUrwSbtWDIYxhFmJMUTG/9ArL3F+YVTSB3vhHZLQ=; b=imZrSrf7nZ/KRKFIvcsLqrNxcewZKwYsBRnhtBxt+P12u43eiwcMPHg7jy8JmXwcHu4x6j q1l9DlCbVRFpVYTb20cYfN1lU7SKsW52JdDOMFeevdsmBex/qvIC/kyDJLx/hol5ckr9hL K3SzwdKrxjKHBZ0eR85WEmf6A3jT6S0= X-MC-Unique: LeBMOdLJNkCcjtIHbCNGvw-1 X-Mimecast-MFC-AGG-ID: LeBMOdLJNkCcjtIHbCNGvw X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733273522; x=1733878322; 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=d/1lUrwSbtWDIYxhFmJMUTG/9ArL3F+YVTSB3vhHZLQ=; b=A4arnGj4iDekgGaoaEU0qJSGx9T1ASwbsXWkFhUpjVkLXhP/PHKTiHL4b/tPAsWtqA ONwGGDrxsj9d9AEF770ngSiEktxxW+8Z5IJrZr1Wi6idGvf83hMzPpbtc31i+mE+Soob jc7a4bLkLGrBmwny1RxdY8oiA48VpNM/0zJw2g4SVxzZiRkF8c0/E3mEnXu4IQfxxVE0 0hYQG3/GBSUDXYz5BHM5Tqc+JstSxJMVoPnXeHFgq4Lvm5HSRRNccHE0I+1o7/yVCeRp rEA+fi8nCO3+495IkD+U2xPDJqLFlMKZOql+WthLOo8UWU2//xee/wQbFo8q3Jxu424X CHhw== X-Gm-Message-State: AOJu0YxebkEyYXvUuIKANeq+VcUqYfEghMf+LSx2F9w88KIkF4Yy0of/ lPQdRofA0O+E0X2gqd/zlPvyZsDs/GGpfs5aUp7EPHzFbpISIIexshWwGvDK9ZQ3a/LZHdDt2K2 xWOuRg4Rp2CiDi8pYFBn5TfJs6a1drEnDWiL68VVGIiH8szTk+agFfuWhiXECxzk2yF/Tbmo84R oSBSo5ZgmBA2rUcSjKPteUhE6wlkbgylPQ5w== X-Gm-Gg: ASbGnctHu7AUU96C2zfekZH912sJ5vBoYt7DyJhO5mIaa5f7me7pswiBGuubEHoJ7Sn C+sEF5cEH6PfOLWyUZQLVtfmcJP30t7yS/3xSPlTb+0S+UbaUoDAERj6Yn/4SZsnwdp+/OTIdFa Blk8Er6BcrdtiHxE2VIYw3pPnwMeiU283xVwnHDYb3pudL6lKg+l5gNF5dhJqxgdARYpzcOiJ+L Aah0fe1PWzWDYhNPmbRGdS7I8EmWlZ4E6SmAU94kb0QCpII2lBt/6A/T71yIOfDvTiCgtMu8rrk uLuQ6l/tlzUdrRH3OtSmBosYCQ== X-Received: by 2002:ad4:5c46:0:b0:6d8:b189:541d with SMTP id 6a1803df08f44-6d8b7331a75mr94271686d6.6.1733273522024; Tue, 03 Dec 2024 16:52:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IE1lURGF+S355GWNV3rC+kOlmDmuNHXuiDQjcsKHwFOEYtHioiyra4eiKmdimAaOvMIs5j85A== X-Received: by 2002:ad4:5c46:0:b0:6d8:b189:541d with SMTP id 6a1803df08f44-6d8b7331a75mr94271216d6.6.1733273521673; Tue, 03 Dec 2024 16:52:01 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Fabiano Rosas , "Dr . David Alan Gilbert" , Eric Blake , Kevin Wolf , Vladimir Sementsov-Ogievskiy , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Andrey Drobyshev , peterx@redhat.com, Stefan Hajnoczi Subject: [PATCH RFC 10/11] tests/qtest/migration: Support cleaning up only one side of migration Date: Tue, 3 Dec 2024 19:51:37 -0500 Message-ID: <20241204005138.702289-11-peterx@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241204005138.702289-1-peterx@redhat.com> References: <20241204005138.702289-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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: 1733273647708116600 Content-Type: text/plain; charset="utf-8" From: Fabiano Rosas We don't always want to cleanup both VMs at the same time. One example is the multifd cancel test, where there's a second migration reusing the source VM. The next patches will add another instance, keeping the destination VM instead. Extract the cleanup routine from test_migrate_end() into another function so it can be reused. Signed-off-by: Fabiano Rosas Link: https://lore.kernel.org/r/20241125144612.16194-4-farosas@suse.de Signed-off-by: Peter Xu --- tests/qtest/migration-test.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index 1452778c81..74645f749c 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -883,13 +883,29 @@ static int test_migrate_start(QTestState **from, QTes= tState **to, return 0; } =20 +static void migrate_cleanup(QTestState *from, QTestState *to) +{ + if (from) { + qtest_quit(from); + unlink(src_state.serial); + g_free(src_state.serial); + } + + if (to) { + qtest_quit(to); + unlink(dst_state.serial); + g_free(dst_state.serial); + } + + cleanup("migsocket"); + cleanup(FILE_TEST_FILENAME); +} + static void test_migrate_end(QTestState *from, QTestState *to, bool test_d= est) { unsigned char dest_byte_a, dest_byte_b, dest_byte_c, dest_byte_d; =20 - qtest_quit(from); - - if (test_dest) { + if (to && test_dest) { qtest_memread(to, start_address, &dest_byte_a, 1); =20 /* Destination still running, wait for a byte to change */ @@ -909,14 +925,7 @@ static void test_migrate_end(QTestState *from, QTestSt= ate *to, bool test_dest) check_guests_ram(to); } =20 - qtest_quit(to); - - cleanup("migsocket"); - unlink(src_state.serial); - g_free(src_state.serial); - unlink(dst_state.serial); - g_free(dst_state.serial); - cleanup(FILE_TEST_FILENAME); + migrate_cleanup(from, to); } =20 #ifdef CONFIG_GNUTLS @@ -3309,9 +3318,7 @@ static void test_multifd_tcp_cancel(void) =20 /* Make sure QEMU process "to" exited */ qtest_set_expected_status(to, EXIT_FAILURE); - qtest_wait_qemu(to); - unlink(dst_state.serial); - g_free(dst_state.serial); + migrate_cleanup(NULL, to); =20 /* * Ensure the source QEMU finishes its cancellation process before we --=20 2.47.0 From nobody Thu Dec 18 22:24:46 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1733273637; cv=none; d=zohomail.com; s=zohoarc; b=XAvc7/kai4nXSeXXq/W+0l5jqnKPmCH7UkXuQNzRkIAhGiGw44bMF3LaV0qSv+velGWxLLccwQ1kD+IA0orAFEZs7wOBp9XUc2WKvj32DKfmdMhMXC9pPdlJ/Nj9eHvTrNku4HV2t3rH7sB1aafWdOgJWfBshVM3asWPnErJvr8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733273637; 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=j6HNcsiqaXHAtCR81Tet2C9VNDCVc5sLauFrWeUoMuc=; b=RYOqC69+iK4aL3TP3fcHjy6X9Lav8e6K3wqLLJ177HVWWV9kkQ3nKbD3nGFn2RKeJMXCXYgPRDvnBAWi6STWTWaYdBCLDmTW9BQDKqfH9CA2BmQt3qKv0niZ/6nxCJihjeI3l05cPbXdyVBFEUrMwI6rYwDdgwgBdM57kS0S7+o= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1733273637413100.58493213705958; Tue, 3 Dec 2024 16:53:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIdd0-0003Kg-RY; Tue, 03 Dec 2024 19:52:30 -0500 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 1tIdce-0003H6-VK for qemu-devel@nongnu.org; Tue, 03 Dec 2024 19:52:09 -0500 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 1tIdcc-0005rr-Hn for qemu-devel@nongnu.org; Tue, 03 Dec 2024 19:52:08 -0500 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-314-1oLbw1FLPT2Dzv8CQWcGQQ-1; Tue, 03 Dec 2024 19:52:05 -0500 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-6d89309de06so65801636d6.2 for ; Tue, 03 Dec 2024 16:52:05 -0800 (PST) Received: from x1n.redhat.com (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b68492cb81sm559974785a.34.2024.12.03.16.52.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 16:52:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733273525; 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=j6HNcsiqaXHAtCR81Tet2C9VNDCVc5sLauFrWeUoMuc=; b=Jr9tD5747O8Ttn00HIKsXd6XD0iVnL4mau1iOFHfarPLzhRx2B92mRGovUyhH/FXMPIzOc zZ7NWVaOZKEUBaR2ZHT+yYU1PW3irdPTR0rpALYH8PZ77NQnDqJiQrKabPyFJhLT7QGv2k haL3vwCLYGJz3oEUcbIJ0yQqt3FWHZk= X-MC-Unique: 1oLbw1FLPT2Dzv8CQWcGQQ-1 X-Mimecast-MFC-AGG-ID: 1oLbw1FLPT2Dzv8CQWcGQQ X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733273524; x=1733878324; 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=j6HNcsiqaXHAtCR81Tet2C9VNDCVc5sLauFrWeUoMuc=; b=L9imlWnylOzpw4DQfBQp30c0or2QbEtvHm86QyoLf0PdNtz5LI5zlyXeNEg7FJHcpd /9P+qOBcsvToTAK6uso4ptVcxOk8t9nUFIvrcRCboBvWoCewN8rBKXaVkG5McG3le+4d vxxfO7EF0/8mcO8Qe+R04+u3xPxHpmK/5vqWW7MtONCESw/acTdDRLo4NYFbX8a/xEXQ UnoxXW6cHQm97SPygNJQVVx9vBkN46OKylkvt45lt2Pmh3+A3ea+qezkc2v7CiTi9cSq q6oHZOI7Zk18woohZ3AwmQxnkgnmCnwbHIkNl1Qej8zB2v+xtoqS4W2AunIWPK7OV+qY nbsQ== X-Gm-Message-State: AOJu0YwnYrGsW7QCwZlT/jdYqSNJY0Z9/Zm78g0FwS823hAAXiL9rIcs KNDj8KyYETsulmyylIbNUo4i478vEv4dDV7QtfddYi9C3+y44fdw5isALQwjxQCEq92Vh6BOYdY fUYOh2rsxKhLZg8dXjGKXqREFKMSfBerubpf1HscRRYDVF7yEYpQY57yTTSWDdP7hMlEO1Nei2R 5f9EDuQjeO1YFjePzfVX4FueYhjQ3VGOg0oQ== X-Gm-Gg: ASbGncuAAcyrTRt/moSUUVJLOU/4WPrb+zLbriH+0dPyXCxyVw2HThUs4tldzu2yNiI QJSioP39TonsDH/b6beh2KY/bKVdbUF3GEHhLd/04PK/dxASKEEP5FtQBEnowGdOVgFuQ60zuyQ RJcBt5gcowmS/ptSzjcAIk0hiViQ//fvH/4qHtmeURdvw9pbsUizTOWeNehslBZZKBn6yCx1dMN rKx42FhfnnHF/FfMX6gDkmo0cpnRnInM1fByHU5tC49J7WN8iADRshHk2Yr6yJTHQEqasdlCITg 3E2JL1DBgNu7wpTfSOSwMWqpLQ== X-Received: by 2002:ad4:5f4e:0:b0:6d8:8165:ef21 with SMTP id 6a1803df08f44-6d8c46ecd45mr39271026d6.49.1733273524304; Tue, 03 Dec 2024 16:52:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IG9P/+ortXg3b41Bp+raqm8Nws9cdGRStoTLCdCOjTlHhezJ7S3s4bwJECw66qbfByvuDPnfQ== X-Received: by 2002:ad4:5f4e:0:b0:6d8:8165:ef21 with SMTP id 6a1803df08f44-6d8c46ecd45mr39270656d6.49.1733273523859; Tue, 03 Dec 2024 16:52:03 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Fabiano Rosas , "Dr . David Alan Gilbert" , Eric Blake , Kevin Wolf , Vladimir Sementsov-Ogievskiy , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Andrey Drobyshev , peterx@redhat.com, Stefan Hajnoczi Subject: [PATCH RFC 11/11] tests/qtest/migration: Test successive migrations Date: Tue, 3 Dec 2024 19:51:38 -0500 Message-ID: <20241204005138.702289-12-peterx@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241204005138.702289-1-peterx@redhat.com> References: <20241204005138.702289-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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: 1733273637754116600 Content-Type: text/plain; charset="utf-8" From: Fabiano Rosas Add a framework for running migrations back and forth between two guests (aka ping-pong migration). We have seen a couple of bugs that only reproduce when a guest is migrated and the destination machine is used as the source of a new migration. Add a simple test that does 2 migrations and another test that uses the late-block-activate capability, which is one area where a bug has been found. Note that this does not reuse any of the existing tests (e.g. test_precopy_common), because there is too much ambiguity regarding how to handle the hooks, args->result, stop/continue, etc. Signed-off-by: Fabiano Rosas Link: https://lore.kernel.org/r/20241125144612.16194-6-farosas@suse.de Signed-off-by: Peter Xu --- tests/qtest/migration-test.c | 121 +++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index 74645f749c..4955b3b9eb 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -1819,6 +1819,104 @@ finish: test_migrate_end(from, to, args->result =3D=3D MIG_TEST_SUCCEED); } =20 +static void migrate_dst_becomes_src(QTestState **from, QTestState **to, + QTestMigrationState *src_state, + QTestMigrationState *dst_state) +{ + *from =3D *to; + + *src_state =3D (QTestMigrationState) { }; + src_state->serial =3D dst_state->serial; + qtest_qmp_set_event_callback(*from, migrate_watch_for_events, src_stat= e); + + src_state->stop_seen =3D dst_state->stop_seen; +} + +static void test_precopy_ping_pong_common(MigrateCommon *args, int n, + bool late_block_activate) +{ + QTestState *from, *to; + bool keep_paused =3D false; + + g_assert(!args->live); + + g_test_message("Migrating back and forth %d times", n); + + for (int i =3D 0; i < n; i++) { + g_test_message("%s (%d/%d)", i % 2 ? "pong" : "ping", i + 1, n); + + if (test_migrate_start(&from, &to, args->listen_uri, &args->start)= ) { + return; + } + + if (late_block_activate) { + migrate_set_capability(from, "late-block-activate", true); + migrate_set_capability(to, "late-block-activate", true); + + /* + * The late-block-activate capability expects that the + * management layer will issue a qmp_continue command on + * the destination once the migration finishes. In order + * to test the capability properly, make sure the test is + * not issuing spurious continue commands. + */ + keep_paused =3D true; + } + + if (!src_state.stop_seen) { + wait_for_serial(src_state.serial); + } + + /* because of !args->live */ + qtest_qmp_assert_success(from, "{ 'execute' : 'stop'}"); + wait_for_stop(from, &src_state); + + migrate_ensure_converge(from); + migrate_qmp(from, to, args->connect_uri, args->connect_channels, "= {}"); + + wait_for_migration_complete(from); + wait_for_migration_complete(to); + + /* note check_guests_ram() requires a stopped guest */ + check_guests_ram(to); + + if (keep_paused) { + /* + * Nothing issued continue on the destination, reflect + * that the guest is paused in the dst_state. + */ + dst_state.stop_seen =3D true; + } else { + qtest_qmp_assert_success(to, "{ 'execute' : 'cont'}"); + wait_for_serial(dst_state.serial); + dst_state.stop_seen =3D false; + } + + /* + * Last iteration, let the guest run to make sure there's no + * memory corruption. The test_migrate_end() below will check + * the memory one last time. + */ + if (i =3D=3D n - 1) { + qtest_qmp_assert_success(to, "{ 'execute' : 'cont'}"); + wait_for_serial(dst_state.serial); + dst_state.stop_seen =3D false; + break; + } + + /* + * Prepare for migrating back: clear the original source and + * switch source & destination. + */ + migrate_cleanup(from, NULL); + migrate_dst_becomes_src(&from, &to, &src_state, &dst_state); + + args->start.only_target =3D true; + } + + test_migrate_end(from, to, true); +} + static void file_dirty_offset_region(void) { g_autofree char *path =3D g_strdup_printf("%s/%s", tmpfs, FILE_TEST_FI= LENAME); @@ -3772,6 +3870,24 @@ static void test_migrate_dirty_limit(void) test_migrate_end(from, to, true); } =20 +static void test_precopy_ping_pong(void) +{ + MigrateCommon args =3D { + .listen_uri =3D "tcp:127.0.0.1:0", + }; + + test_precopy_ping_pong_common(&args, 2, false); +} + +static void test_precopy_ping_pong_late_block(void) +{ + MigrateCommon args =3D { + .listen_uri =3D "tcp:127.0.0.1:0", + }; + + test_precopy_ping_pong_common(&args, 2, true); +} + static bool kvm_dirty_ring_supported(void) { #if defined(__linux__) && defined(HOST_X86_64) @@ -4055,6 +4171,11 @@ int main(int argc, char **argv) } } =20 + migration_test_add("/migration/precopy/ping-pong/plain", + test_precopy_ping_pong); + migration_test_add("/migration/precopy/ping-pong/late-block-activate", + test_precopy_ping_pong_late_block); + ret =3D g_test_run(); =20 g_assert_cmpint(ret, =3D=3D, 0); --=20 2.47.0