Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4377680rdh; Tue, 28 Nov 2023 22:34:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IEBCSTN+T3qpXQ9Hv1gS1FBQw2wSofsuyMIPMqsZsY6QEcJm1mgTJxlFSdSr06K9ip1VpVG X-Received: by 2002:a05:6a20:394f:b0:187:5a4d:7061 with SMTP id r15-20020a056a20394f00b001875a4d7061mr21708526pzg.44.1701239689749; Tue, 28 Nov 2023 22:34:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701239689; cv=none; d=google.com; s=arc-20160816; b=msaXUlMDUN33cOpwlR7AWcL7LxsfSi4vtPoom5E0ESySENa1HnrYtEVUEBsJKOWNdA 4W29lPV4GN4ipJtNA+d2lZGApEXbg1ej1rZavWNlTxB0dht35tsaFuSQXbd1q9Y2O/rJ r9DuTStOeD9JaVSRGXathcTWNPo8pTXmNIC6q6PE0gEDVF18rWMFvepZM9UrYB2cxSnV F+gPolx4pegM19F+9p+uHGon8XGYV32ID04RlDi+YjTgwZyrSZhLhUxBt3Q14l6oOUbs o7yADqR2AIwTEbEpYV5I5blYEYeWF6+hRithz/Dk4f9UonH1rumMR4OeG5KQNF7MXcnc gi0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=wcQuzzO+KMN/HmEnKHu10begarBG0t4Z9ZGnvbVfVlg=; fh=9WvzaIUXtRiGUu+oEmbr1XD6yy5bNfHcZT9yhptS1p0=; b=mlqiIwu0XQSZp91X605wfvaosv2x5L7fSHfJo+WiPicZA8uMfvn2AwDYI4hvJ/JI7U 17+/Gg4d9tyAKPyyJU1fvvSz8cV5r4OtT/2Z+XAKbBY1ihdnZH4v62cWiW4tz/uKTV3a zIcK/A5XqBwOQ+lID9vSyAo588Qn3yGk9qFFEZe2DbJ3snoz2P4R4WhUDrljCSvKQiRL NImAl7i0XvLcolbt/hGd/tja8v6vwVRwviLtXDEt0KeURc5aa6HRyQPlIbP2MSxyX7ek kGwgcF3hAysqC+NCqXPnhqzyo1q8+8enHoJIYDDe9ZP6Wu7ZTT5493/VolmrnSYgkOMD gRaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NoFywrii; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id g4-20020a170902934400b001cc2853bfe6si13353706plp.192.2023.11.28.22.34.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 22:34:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NoFywrii; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 9864F804B3BB; Tue, 28 Nov 2023 22:34:46 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344925AbjK2Ge3 (ORCPT + 99 others); Wed, 29 Nov 2023 01:34:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231393AbjK2Ge2 (ORCPT ); Wed, 29 Nov 2023 01:34:28 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 840D01735 for ; Tue, 28 Nov 2023 22:34:34 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 15D5AC433C7; Wed, 29 Nov 2023 06:34:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701239674; bh=gi+butBnjxFbdfipltyeJ8FK1caOXBc4/I7P659ZPfE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=NoFywriiasU8itLSU9EpPZQ/kSoZlfUodkVhK0ezxHYU1qjnO7ONdm1WVcn0qzqmq ezxl9xTLIigFrWTlpl7ELkU2HSm7ZOjFDoEt69qE2WE1UQA8v/QpZkozfkKjf/Dc/e eTCEjpmHSO3h2Zd0Q0D0kF6zOVg1OCTXB8vppEPSR/jHFXijMHYTHGN+ftg2FIHf5J 5KZ/xorJsEHKNBl5rdiqVD94/BWuoFPtaqttStoABr2Or7XTyaRUzrZjTHAxl9IoWd 3s4MnEHtkxZF14X52rc0+3Uq91+AGWo1Ukie8vUPaxo8bQJxovocf+zb0wWTznT5ox gU+bIb0LvpJOQ== Date: Tue, 28 Nov 2023 22:34:33 -0800 From: "Darrick J. Wong" To: Dave Chinner Cc: Jiachen Zhang , Chandan Babu R , Dave Chinner , Allison Henderson , Zhang Tianci , Brian Foster , Ben Myers , linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, xieyongji@bytedance.com, me@jcix.top Subject: Re: [PATCH 2/2] xfs: update dir3 leaf block metadata after swap Message-ID: <20231129063433.GD361584@frogsfrogsfrogs> References: <20231128053202.29007-1-zhangjiachen.jaycee@bytedance.com> <20231128053202.29007-3-zhangjiachen.jaycee@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,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 pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Tue, 28 Nov 2023 22:34:46 -0800 (PST) On Wed, Nov 29, 2023 at 10:15:52AM +1100, Dave Chinner wrote: > On Tue, Nov 28, 2023 at 01:32:02PM +0800, Jiachen Zhang wrote: > > From: Zhang Tianci > > > > xfs_da3_swap_lastblock() copy the last block content to the dead block, > > but do not update the metadata in it. We need update some metadata > > for some kinds of type block, such as dir3 leafn block records its > > blkno, we shall update it to the dead block blkno. Otherwise, > > before write the xfs_buf to disk, the verify_write() will fail in > > blk_hdr->blkno != xfs_buf->b_bn, then xfs will be shutdown. > > > > We will get this warning: > > > > XFS (dm-0): Metadata corruption detected at xfs_dir3_leaf_verify+0xa8/0xe0 [xfs], xfs_dir3_leafn block 0x178 > > XFS (dm-0): Unmount and run xfs_repair > > XFS (dm-0): First 128 bytes of corrupted metadata buffer: > > 00000000e80f1917: 00 80 00 0b 00 80 00 07 3d ff 00 00 00 00 00 00 ........=....... > > 000000009604c005: 00 00 00 00 00 00 01 a0 00 00 00 00 00 00 00 00 ................ > > 000000006b6fb2bf: e4 44 e3 97 b5 64 44 41 8b 84 60 0e 50 43 d9 bf .D...dDA..`.PC.. > > 00000000678978a2: 00 00 00 00 00 00 00 83 01 73 00 93 00 00 00 00 .........s...... > > 00000000b28b247c: 99 29 1d 38 00 00 00 00 99 29 1d 40 00 00 00 00 .).8.....).@.... > > 000000002b2a662c: 99 29 1d 48 00 00 00 00 99 49 11 00 00 00 00 00 .).H.....I...... > > 00000000ea2ffbb8: 99 49 11 08 00 00 45 25 99 49 11 10 00 00 48 fe .I....E%.I....H. > > 0000000069e86440: 99 49 11 18 00 00 4c 6b 99 49 11 20 00 00 4d 97 .I....Lk.I. ..M. > > XFS (dm-0): xfs_do_force_shutdown(0x8) called from line 1423 of file fs/xfs/xfs_buf.c. Return address = 00000000c0ff63c1 > > XFS (dm-0): Corruption of in-memory data detected. Shutting down filesystem > > XFS (dm-0): Please umount the filesystem and rectify the problem(s) > > > > From the log above, we know xfs_buf->b_no is 0x178, but the block's hdr record > > its blkno is 0x1a0. > > > > Fixes: 24df33b45ecf ("xfs: add CRC checking to dir2 leaf blocks") > > Signed-off-by: Zhang Tianci > > --- > > fs/xfs/libxfs/xfs_da_btree.c | 12 +++++++++++- > > 1 file changed, 11 insertions(+), 1 deletion(-) > > > > diff --git a/fs/xfs/libxfs/xfs_da_btree.c b/fs/xfs/libxfs/xfs_da_btree.c > > index e576560b46e9..35f70e4c6447 100644 > > --- a/fs/xfs/libxfs/xfs_da_btree.c > > +++ b/fs/xfs/libxfs/xfs_da_btree.c > > @@ -2318,8 +2318,18 @@ xfs_da3_swap_lastblock( > > * Copy the last block into the dead buffer and log it. > > */ > > memcpy(dead_buf->b_addr, last_buf->b_addr, args->geo->blksize); > > - xfs_trans_log_buf(tp, dead_buf, 0, args->geo->blksize - 1); > > dead_info = dead_buf->b_addr; > > + /* > > + * Update the moved block's blkno if it's a dir3 leaf block > > + */ > > + if (dead_info->magic == cpu_to_be16(XFS_DIR3_LEAF1_MAGIC) || > > + dead_info->magic == cpu_to_be16(XFS_DIR3_LEAFN_MAGIC) || > > + dead_info->magic == cpu_to_be16(XFS_ATTR3_LEAF_MAGIC)) { On second thought, does this code have to handle XFS_DA3_NODE_MAGIC as well? > > a.k.a. > > if (xfs_has_crc(mp)) { > > i.e. this is not specific to the buffer type being processed, it's > specific to v4 vs v5 on-disk format. Hence it's a fs-feature check, > not a block magic number check. in which case Dave's comment is correct, yes? --D > Cheers, > > Dave. > -- > Dave Chinner > david@fromorbit.com >