From nobody Wed Nov 27 02:26:23 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1701768119; cv=none; d=zohomail.com; s=zohoarc; b=FuvqazoZmcKxSxufS81GTsHxDb7e6QknMSMlnxEQJiIuEQhPUA3TFc3GBWWuEi0EN7E7qcCp2pP3+Nq9qCJYAS70lBWmRflXPcOOzR9RPDtWV6vxFd7H00L5tYOoH/c4w1Iqg2XDJCJuqmHcHp7NO/qobGeApb2oemGMMoKAeLQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701768119; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ZrjIWuVTon5cUmZo726CAd50U+w4Y2gWMhU0w/nYYzM=; b=LZUGgm71bBxeN1h6N2NfEUo9nTenFLKTb+RUuaMQpBAUS1t8OZEEjwQXqNeltCysvLzK4TE6J1a0GaJslB9oMmIHWX9/mD3I02a2AFWR6LlQKc5VNLcNerWv6gi6JV6C+ttZiJ73bzDUcTQQm5xo3EHK6cjTwpvnj5Dre1na+6g= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701768119651664.3678199397729; Tue, 5 Dec 2023 01:21:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rARcK-0007MH-GR; Tue, 05 Dec 2023 04:21:24 -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 1rARcE-0007Ll-33 for qemu-devel@nongnu.org; Tue, 05 Dec 2023 04:21:19 -0500 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rARcB-0002cv-7C for qemu-devel@nongnu.org; Tue, 05 Dec 2023 04:21:17 -0500 Received: by mail-pg1-x52f.google.com with SMTP id 41be03b00d2f7-5c66988c2eeso1825963a12.1 for ; Tue, 05 Dec 2023 01:19:11 -0800 (PST) Received: from tianren.zelin.local ([221.122.98.162]) by smtp.gmail.com with ESMTPSA id e12-20020a170902ed8c00b001d0915435f8sm4052272plj.16.2023.12.05.01.19.07 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Dec 2023 01:19:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1701767950; x=1702372750; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=ZrjIWuVTon5cUmZo726CAd50U+w4Y2gWMhU0w/nYYzM=; b=JWmNGMbnKYjij3Codwg1ftZhaUdqvPvdafdXdO7f+9w9ok1dLHA/6/l5PgVAIDfmG4 dMugA+roTc5/gh1sbvHTc2gF3Oq6cUxFGNbJ80FHN981cQeiRG3UMkXtGeQavKJcfXUx saSF3BRCPQzdlRYMNsZUv/qlKDXp5MAvALXYDnN9TstH0zIJCHhf8vdEwhIqGD2NY8tQ zvR50JpfkNj/WXdmZgqBrlC6kFnJDFrhL+KOuNUx8H+gbohq07VM0XEdoo73Xz031Tuu eWza3fzPuLMEy8mI1iE8zInf74v5NXC+dpht1Krh9JFzqyrF0SwiJy6qHyf/VRrPsXIt YBvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701767950; x=1702372750; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ZrjIWuVTon5cUmZo726CAd50U+w4Y2gWMhU0w/nYYzM=; b=TCnmUXtTW5w0niisq14Q4J1yfhwzhwR2y3gRMIfcC9KxJVx5SdEDLdB3l+1vtZgROJ TrioT6XklRSkWW00sVbxHGca6a+UkZHwXOdS5ivsPPG4euGG2CorfHVqmzMTaJAeQogu uThoqTUSbkZhuFroR9KNK6LdZN0c7umq6FnmUCMWXG9szWydybVPC/6GQfuO1YbprNwk f1sybaqsZkgztLi/RNMtdRQHnu5xbYRsh3j0wuaPR8srMJfFQKYPgYNCHkKYBYkaPcnx QQNByASYtWm/thLSnVsrG4e01ikvzc/vVDCqP8zGX6UVcFeAme90yKvhkw3iqdPvdd0+ VPjA== X-Gm-Message-State: AOJu0Yz8NMni6zPbK4Tq4qmN7MfCx7UoKvPM1h0RGnKePEFr9k4rPCdW lFpfNVTx16xv7J4iQT+MnmM5GZpzKA9CgDLYev/t0AWkOyE= X-Google-Smtp-Source: AGHT+IGOojDKUOHYP9HSd3OHmsPGFh01Zokgs6ygKPewmLNV5QWIwcsUjhlQ4r02akjeLA/wfsI8Ew== X-Received: by 2002:a17:90b:f85:b0:286:99a9:f4d4 with SMTP id ft5-20020a17090b0f8500b0028699a9f4d4mr1197234pjb.9.1701767949667; Tue, 05 Dec 2023 01:19:09 -0800 (PST) From: tianren@smartx.com To: qemu-devel@nongnu.org Cc: berrange@redhat.com, richard.henderson@linaro.org, pbonzini@redhat.com, Tianren Zhang Subject: [PATCH v3] qemu: send stop event after bdrv_flush_all Date: Tue, 5 Dec 2023 04:19:03 -0500 Message-ID: <20231205091903.3640-1-tianren@smartx.com> X-Mailer: git-send-email 2.41.0 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: none client-ip=2607:f8b0:4864:20::52f; envelope-from=tianren@smartx.com; helo=mail-pg1-x52f.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 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 @smartx-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1701768120480100001 Content-Type: text/plain; charset="utf-8" From: Tianren Zhang The stop process is not finished until bdrv_flush_all is done. Some users (e.g., libvirt) detect the STOP event and invokes some lock release logic to revoke the disk lock held by current qemu when such event is emitted. In such case, if the bdrv_flush_all is after the stop event, it's possible that the disk lock is released while the qemu is still waiting for I/O. Therefore, it's better to have the stop event generated after the whole stop process is done, so we can guarantee to users that the stop process is finished when they get the STOP event. Signed-off-by: Tianren Zhang Reviewed-by: Daniel P. Berrang=C3=A9 --- v2: do not call runstate_is_running twice v3: remove irrelevant info from commit msg --- system/cpus.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/system/cpus.c b/system/cpus.c index a444a747f0..49af0f92b5 100644 --- a/system/cpus.c +++ b/system/cpus.c @@ -262,21 +262,24 @@ void cpu_interrupt(CPUState *cpu, int mask) static int do_vm_stop(RunState state, bool send_stop) { int ret =3D 0; + bool do_send_stop =3D false; =20 if (runstate_is_running()) { runstate_set(state); cpu_disable_ticks(); pause_all_vcpus(); vm_state_notify(0, state); - if (send_stop) { - qapi_event_send_stop(); - } + do_send_stop =3D send_stop; } =20 bdrv_drain_all(); ret =3D bdrv_flush_all(); trace_vm_stop_flush_all(ret); =20 + if (do_send_stop) { + qapi_event_send_stop(); + } + return ret; } =20 --=20 2.41.0