Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2164404iof; Tue, 7 Jun 2022 21:54:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxiFN5QTuxQsaTlqHk/VGmVkIyRzQm+9RW2GLtx9UoBTcpkvCq9sJp29/SJlEm37vjsmeyZ X-Received: by 2002:a62:d045:0:b0:51b:fcf6:3add with SMTP id p66-20020a62d045000000b0051bfcf63addmr19109212pfg.68.1654664047167; Tue, 07 Jun 2022 21:54:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654664047; cv=none; d=google.com; s=arc-20160816; b=OXgPRoeTY1UaTwUXQw+vPpgeV/tFoTNeFfM+DGSY7co8H6iaTk1AcbhpY+B7AD3TYt uoq1fockY++bVTL+ZEU0L4g4R4yDrNC8tlAMDn9Ket+5gqea5HUqsvtiMRFHNEVhgLbJ rCV5Gh3GB5PHuf/vB1lpeP0F4+w708xsl+X5acvb2m6oHUIfagSYhOL8ADKByTgmyLhF KzbpbOEXHHWmh1snvAaqNZaCyBp2lk/bn/oBqssmgy9VHyaCi0umrXhxPeW/fHtLPPef ATMzHPj/RuyDV9ZrygYiTE+w3i8ScLDRc3RioBy4mqKM5BJZzb8JBEtlfm+5G0q5xp7X SpOg== 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=zz0OPpDwz5cUJ+0h4AbhFM+zFEVva5RlEv9v9tS0GqA=; b=eGzXNu7rEBT/DHE/55nHMIKdFBu90Svv6vdgmI6KL543m6FtY2jqASei8Ls3jMeA8K 14Qj9jg+hiezq5bcqO1neKYvLBvdtea441nE8LV/vDA7M3jCq1r1gGECETEBsWoIojEI +SxN04BWaE6JdxIyuq66Y7ooMvg9jNbJg1dPmlR4VoHv3fOWruTSzvGZbNajAUQ0h/Sj OIQlD01leVwpFc38EdRzh77gTaA4GDBtOnyh+m7MiAZkih6JAOnyxlt+T+Phs4bkPXgJ wAUgMmg9A3AFm7RRnnqPs66ADeXcuCsfySoNat3lUYFIpPOAToOFTSIpWKcd3Dn54LTX MkRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RXJ2Vzqc; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id jj20-20020a170903049400b0016403c5eaa2si624340plb.28.2022.06.07.21.54.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 21:54:07 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RXJ2Vzqc; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 5D99027F44D; Tue, 7 Jun 2022 21:23:22 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349877AbiFGSMj (ORCPT + 99 others); Tue, 7 Jun 2022 14:12:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349725AbiFGRvc (ORCPT ); Tue, 7 Jun 2022 13:51:32 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EA3713C4C4; Tue, 7 Jun 2022 10:38:48 -0700 (PDT) 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 B5FB8615F5; Tue, 7 Jun 2022 17:38:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1B0EC385A5; Tue, 7 Jun 2022 17:38:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654623486; bh=N92Elaq3Zey+mrdNun2r6vzaANKK0WHWOAm7kLBzVpM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RXJ2Vzqc9sp684DHL3ylarlL+p6P7BSBGB9XS+BqYc41KG5fvV0YfsSEKQiL/0p8A OcyEqFMMHeeEkvxUqZ5ZsbGApBw0AjhiYeby4hSTpcwzyKOFMDqaW0vEjkEIDpcvom mw+5bq7RnqF5mtG/i5TnqPaElyZFVnDI/7Y+D/tc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Brian Foster , "Darrick J. Wong" , Amir Goldstein Subject: [PATCH 5.10 436/452] xfs: consider shutdown in bmapbt cursor delete assert Date: Tue, 7 Jun 2022 19:04:53 +0200 Message-Id: <20220607164921.552916317@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607164908.521895282@linuxfoundation.org> References: <20220607164908.521895282@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=-3.1 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=unavailable 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: Brian Foster commit 1cd738b13ae9b29e03d6149f0246c61f76e81fcf upstream. The assert in xfs_btree_del_cursor() checks that the bmapbt block allocation field has been handled correctly before the cursor is freed. This field is used for accurate calculation of indirect block reservation requirements (for delayed allocations), for example. generic/019 reproduces a scenario where this assert fails because the filesystem has shutdown while in the middle of a bmbt record insertion. This occurs after a bmbt block has been allocated via the cursor but before the higher level bmap function (i.e. xfs_bmap_add_extent_hole_real()) completes and resets the field. Update the assert to accommodate the transient state if the filesystem has shutdown. While here, clean up the indentation and comments in the function. Signed-off-by: Brian Foster Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Signed-off-by: Amir Goldstein Signed-off-by: Greg Kroah-Hartman --- fs/xfs/libxfs/xfs_btree.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) --- a/fs/xfs/libxfs/xfs_btree.c +++ b/fs/xfs/libxfs/xfs_btree.c @@ -353,20 +353,17 @@ xfs_btree_free_block( */ void xfs_btree_del_cursor( - xfs_btree_cur_t *cur, /* btree cursor */ - int error) /* del because of error */ + struct xfs_btree_cur *cur, /* btree cursor */ + int error) /* del because of error */ { - int i; /* btree level */ + int i; /* btree level */ /* - * Clear the buffer pointers, and release the buffers. - * If we're doing this in the face of an error, we - * need to make sure to inspect all of the entries - * in the bc_bufs array for buffers to be unlocked. - * This is because some of the btree code works from - * level n down to 0, and if we get an error along - * the way we won't have initialized all the entries - * down to 0. + * Clear the buffer pointers and release the buffers. If we're doing + * this because of an error, inspect all of the entries in the bc_bufs + * array for buffers to be unlocked. This is because some of the btree + * code works from level n down to 0, and if we get an error along the + * way we won't have initialized all the entries down to 0. */ for (i = 0; i < cur->bc_nlevels; i++) { if (cur->bc_bufs[i]) @@ -374,17 +371,11 @@ xfs_btree_del_cursor( else if (!error) break; } - /* - * Can't free a bmap cursor without having dealt with the - * allocated indirect blocks' accounting. - */ - ASSERT(cur->bc_btnum != XFS_BTNUM_BMAP || - cur->bc_ino.allocated == 0); - /* - * Free the cursor. - */ + + ASSERT(cur->bc_btnum != XFS_BTNUM_BMAP || cur->bc_ino.allocated == 0 || + XFS_FORCED_SHUTDOWN(cur->bc_mp)); if (unlikely(cur->bc_flags & XFS_BTREE_STAGING)) - kmem_free((void *)cur->bc_ops); + kmem_free(cur->bc_ops); kmem_cache_free(xfs_btree_cur_zone, cur); }