From patchwork Wed May 12 07:49:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Zhang, Chen" X-Patchwork-Id: 12252977 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97DDCC433ED for ; Wed, 12 May 2021 07:57:54 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F218B611BF for ; Wed, 12 May 2021 07:57:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F218B611BF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:38626 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lgjke-0007Jf-Ru for qemu-devel@archiver.kernel.org; Wed, 12 May 2021 03:57:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58394) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgjjb-0006QR-G6; Wed, 12 May 2021 03:56:48 -0400 Received: from mga06.intel.com ([134.134.136.31]:10029) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgjjY-0000o7-4y; Wed, 12 May 2021 03:56:46 -0400 IronPort-SDR: gHfXWQ6K5toM3zoQIAMUQ/LM+hIur96c21hn2V+chq3Kq4vIc58bkE16OA8e9nH7Xuy7Jbbnwj v9Ymik+VS8Uw== X-IronPort-AV: E=McAfee;i="6200,9189,9981"; a="260896502" X-IronPort-AV: E=Sophos;i="5.82,293,1613462400"; d="scan'208";a="260896502" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 May 2021 00:56:37 -0700 IronPort-SDR: GAu5cFX586Z6un9oIR5Y/8apmA66pah3ixsFJcP+adTM0yDjHH2Uhxg4E/k2Mazeqs2mq+Fp7c eYINWM8Fc/Jw== X-IronPort-AV: E=Sophos;i="5.82,293,1613462400"; d="scan'208";a="622210758" Received: from unknown (HELO localhost.localdomain) ([10.239.13.19]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 May 2021 00:56:34 -0700 From: Zhang Chen To: Kevin Wolf , Max Reitz , Stefan Hajnoczi , Fam Zheng , qemu-dev , qemu-block Subject: [RFC PATCH] block/io.c: Flush parent for quorum in generic code Date: Wed, 12 May 2021 15:49:57 +0800 Message-Id: <20210512074957.763711-1-chen.zhang@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Received-SPF: pass client-ip=134.134.136.31; envelope-from=chen.zhang@intel.com; helo=mga06.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhang Chen , Minghao Yuan , Zhang Chen Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Fix the issue from this patch: [PATCH] block: Flush all children in generic code From 883833e29cb800b4d92b5d4736252f4004885191 Quorum driver do not have the primary child. It will caused guest block flush issue when use quorum and NBD. The vm guest flushes failed,and then guest filesystem is shutdown. Signed-off-by: Zhang Chen Reported-by: Minghao Yuan --- block/io.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/block/io.c b/block/io.c index 35b6c56efc..4dc1873cb9 100644 --- a/block/io.c +++ b/block/io.c @@ -2849,6 +2849,13 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs) BdrvChild *child; int current_gen; int ret = 0; + bool no_primary_child = false; + + /* Quorum drivers do not have the primary child. */ + if (!primary_child) { + primary_child = bs->file; + no_primary_child = true; + } bdrv_inc_in_flight(bs); @@ -2886,12 +2893,12 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs) /* But don't actually force it to the disk with cache=unsafe */ if (bs->open_flags & BDRV_O_NO_FLUSH) { - goto flush_children; + goto flush_data; } /* Check if we really need to flush anything */ if (bs->flushed_gen == current_gen) { - goto flush_children; + goto flush_data; } BLKDBG_EVENT(primary_child, BLKDBG_FLUSH_TO_DISK); @@ -2938,13 +2945,19 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs) /* Now flush the underlying protocol. It will also have BDRV_O_NO_FLUSH * in the case of cache=unsafe, so there are no useless flushes. */ -flush_children: - ret = 0; - QLIST_FOREACH(child, &bs->children, next) { - if (child->perm & (BLK_PERM_WRITE | BLK_PERM_WRITE_UNCHANGED)) { - int this_child_ret = bdrv_co_flush(child->bs); - if (!ret) { - ret = this_child_ret; +flush_data: + if (no_primary_child) { + /* Flush parent */ + ret = bs->file ? bdrv_co_flush(bs->file->bs) : 0; + } else { + /* Flush childrens */ + ret = 0; + QLIST_FOREACH(child, &bs->children, next) { + if (child->perm & (BLK_PERM_WRITE | BLK_PERM_WRITE_UNCHANGED)) { + int this_child_ret = bdrv_co_flush(child->bs); + if (!ret) { + ret = this_child_ret; + } } } }