Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1645910pxb; Wed, 9 Feb 2022 01:04:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJwsCNzCxxvsrweUEa4cEQfGSRKl6YtaF7dxRnlSqL5ZnOlp1NYf3a7One1ghsL4rIlx9N+E X-Received: by 2002:a17:902:e80f:: with SMTP id u15mr1157474plg.98.1644397442095; Wed, 09 Feb 2022 01:04:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644397442; cv=none; d=google.com; s=arc-20160816; b=KT/78luiV0xxVA1hXofnZX8M96LfJAx6vJzuo12FbcFKB0MdCS4bLiTnaxLYiYTfub 8Rm3mT+NYnA/adjCmezb+EuK4SPIR4zUWY384L//ZSFWbCwIa71f1ToUO2tSoUYuu3kG gxmOKYa7adtVGoqEv79fxdh72u2MCfQAIBm9QK5+m9sEaKHQORU++qkTvhzmtcQEbNHw 7f5E1a9Mjt9wC/9Pz7bpfjR1twL+tXWqRcLiiahXKqZt93HaV2j5OMvPWyesrYR4ho3K sH7kdppH19um1kcMAQafGKuYAx+DLW3J6Wwbr3w3dj9vBJHVv6a4xHDq94xVsr+DxWYF KK0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=u25G8STVUfYEve8ryyvANmUDiW/RfC9S9jwu+JmhSQ0=; b=uswUxQSvlBz9D3F6ojZ2CGpjohPEGOq4PW8rbN2BCkLaScftfxMPvv7sRqumyOljS5 HJ2Rjlw1WgT1ek36+OMr/JJplSOVgQPW0WFQUhLIrSr+ufevQaSl2JyGgJQCtYuVvn2e feycMKEWGVBa6YVcnNuk6hTAIG+DjMvJXHvt6aDmIG1XVw45I5xuvRxRV9zhbK7Fopl3 Nfyi89NTvpj9+3RK5bShQp9bV+q6LbKOTHlRR0uwhx/sz7cpGKRpW02TB5kQFn/rmAZO SBRKUiedGSaSSTn884wdlhVsgBM7Si/gaZWErJgDZkyiWEk4kp+0hqkOR8BsV+VDw+7p Qrew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EKJkgPv5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id b14si10758003pll.71.2022.02.09.01.04.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 01:04:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EKJkgPv5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 19169E0186E5; Wed, 9 Feb 2022 00:50:02 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1388184AbiBGLnJ (ORCPT + 99 others); Mon, 7 Feb 2022 06:43:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1385570AbiBGLb7 (ORCPT ); Mon, 7 Feb 2022 06:31:59 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 273C1C03E96B; Mon, 7 Feb 2022 03:30:56 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id AA7DB60AB0; Mon, 7 Feb 2022 11:30:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 81337C004E1; Mon, 7 Feb 2022 11:30:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644233455; bh=n9gapmnR3BmvRHyNXNq14LqFhx8NlinKmjcEoRr3GL8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EKJkgPv5zgFw4nyGZJDLXHTWyZPy5hNgyOi1azjp/yx1NwXslqOnJI1jwFVYRHOl3 z49EtoNQ5OkCWHSBkPN+1yptfMKLHr3ymrBEE+bp4j5zh6UmT+Qk1Vmbs43GoNfGXg QVuBUEjQJlS5QCrQc2PKpVmLO++d8o6RsHbX8Jqs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qu Wenruo , David Sterba Subject: [PATCH 5.16 018/126] btrfs: dont start transaction for scrub if the fs is mounted read-only Date: Mon, 7 Feb 2022 12:05:49 +0100 Message-Id: <20220207103804.695325273@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220207103804.053675072@linuxfoundation.org> References: <20220207103804.053675072@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Qu Wenruo commit 2d192fc4c1abeb0d04d1c8cd54405ff4a0b0255b upstream. [BUG] The following super simple script would crash btrfs at unmount time, if CONFIG_BTRFS_ASSERT() is set. mkfs.btrfs -f $dev mount $dev $mnt xfs_io -f -c "pwrite 0 4k" $mnt/file umount $mnt mount -r ro $dev $mnt btrfs scrub start -Br $mnt umount $mnt This will trigger the following ASSERT() introduced by commit 0a31daa4b602 ("btrfs: add assertion for empty list of transactions at late stage of umount"). That patch is definitely not the cause, it just makes enough noise for developers. [CAUSE] We will start transaction for the following call chain during scrub: scrub_enumerate_chunks() |- btrfs_inc_block_group_ro() |- btrfs_join_transaction() However for RO mount, there is no running transaction at all, thus btrfs_join_transaction() will start a new transaction. Furthermore, since it's read-only mount, btrfs_sync_fs() will not call btrfs_commit_super() to commit the new but empty transaction. And leads to the ASSERT(). The bug has been there for a long time. Only the new ASSERT() makes it noisy enough to be noticed. [FIX] For read-only scrub on read-only mount, there is no need to start a transaction nor to allocate new chunks in btrfs_inc_block_group_ro(). Just do extra read-only mount check in btrfs_inc_block_group_ro(), and if it's read-only, skip all chunk allocation and go inc_block_group_ro() directly. CC: stable@vger.kernel.org # 5.4+ Signed-off-by: Qu Wenruo Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/block-group.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -2547,6 +2547,19 @@ int btrfs_inc_block_group_ro(struct btrf int ret; bool dirty_bg_running; + /* + * This can only happen when we are doing read-only scrub on read-only + * mount. + * In that case we should not start a new transaction on read-only fs. + * Thus here we skip all chunk allocations. + */ + if (sb_rdonly(fs_info->sb)) { + mutex_lock(&fs_info->ro_block_group_mutex); + ret = inc_block_group_ro(cache, 0); + mutex_unlock(&fs_info->ro_block_group_mutex); + return ret; + } + do { trans = btrfs_join_transaction(fs_info->extent_root); if (IS_ERR(trans))