From nobody Tue Dec 16 11:42:58 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8878FC4167B for ; Thu, 30 Nov 2023 04:06:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344435AbjK3EGA (ORCPT ); Wed, 29 Nov 2023 23:06:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344424AbjK3EFy (ORCPT ); Wed, 29 Nov 2023 23:05:54 -0500 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9832110C6 for ; Wed, 29 Nov 2023 20:05:35 -0800 (PST) Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-5c6001ec920so460053a12.0 for ; Wed, 29 Nov 2023 20:05:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1701317135; x=1701921935; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HifOguLosmCp1hqOD7nW4Pzhg3FPPc3H1eWRpxejRrY=; b=ACwPBuMIkvHS0zI/LN+NB+3jM4e1sTKu4c2au+Vi5mF75iopDUbsItmrOA90zcllOG 5pV5rA9aEwGZSL9VqrupURkA9ixJK6o5z1dHaVzZgI2DoxYSnu3HJqa03pQSl5jAfzrV BiHCKg4+dD3vP1p2e/zaqIuUOJWGO+fMKQTA3K0eSB1E+E80/PbvooMmHuduAhd8PiMV 15lP2N77qsDXosPYD3WDTJQIUk8Fuxu1SpbtKIDmFiT5KHTFdJ6VYDiQstHTdSm372Bn P3E+OrQ/CLcjnUPNcvr4tIpvPSL5zhDXgVyLCe+LevjeLVbueRnZ07TAmIDLe245uAuF Ky0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701317135; x=1701921935; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HifOguLosmCp1hqOD7nW4Pzhg3FPPc3H1eWRpxejRrY=; b=RwgvZF2Ad0iDJUM2+D/vD0Q+7h6FrQ/OB+8n2QhPRJmFEq/jW6RGzLCtjghHYgGSYN DNlKziC8oXy1i8OpyiHk7zXhgWy2COAKjY8g2ww0HsbUxFwisCUAE7tU0432yFR7q9TI tH514TMOyfcOZKpc6ODDiklYCo4+dtjJLmR/nhAsBuN0N6u5xz7KWHzymWmHhBKZpAE+ WMOQYTx4aDjVnezlT46asH8o7Qfw7k0Hj36ez+rXNdv3i61grsa2NJop+Gz9FpUPgXQj 2W/gpAIkbDyMNnlHDYpGP07xaPMYQms2mcfTQBj71XK0aJPZa+I5uf8RAZYR4Dh+BpxA XB4w== X-Gm-Message-State: AOJu0YzCTKGd5PF4u43OosnXmmrN5yTiOBtAKBWj8AKXnnUSR4bEKVNJ 2tCDV92vhoQSdxAB0MP7yrkLeQ== X-Google-Smtp-Source: AGHT+IH9PSQT+1rspy2juwmb1zQ+1+xmcZ4tuw74DHRM5bQB/lfp8qpMQb3zzbKumW4BYP3Z9DzDug== X-Received: by 2002:a05:6a20:548e:b0:18c:8d0f:a794 with SMTP id i14-20020a056a20548e00b0018c8d0fa794mr14103759pzk.19.1701317134959; Wed, 29 Nov 2023 20:05:34 -0800 (PST) Received: from localhost.localdomain ([61.213.176.7]) by smtp.gmail.com with ESMTPSA id u6-20020a170903124600b001d01c970119sm174181plh.275.2023.11.29.20.05.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 20:05:34 -0800 (PST) From: Jiachen Zhang To: Chandan Babu R , "Darrick J. Wong" Cc: Dave Chinner , Allison Henderson , Zhang Tianci , Brian Foster , linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, xieyongji@bytedance.com, me@jcix.top, Jiachen Zhang , Christoph Hellwig Subject: [PATCH v3 1/3] xfs: ensure logflagsp is initialized in xfs_bmap_del_extent_real Date: Thu, 30 Nov 2023 12:05:14 +0800 Message-Id: <20231130040516.35677-2-zhangjiachen.jaycee@bytedance.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20231130040516.35677-1-zhangjiachen.jaycee@bytedance.com> References: <20231130040516.35677-1-zhangjiachen.jaycee@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In the case of returning -ENOSPC, ensure logflagsp is initialized by 0. Otherwise the caller __xfs_bunmapi will set uninitialized illegal tmp_logflags value into xfs log, which might cause unpredictable error in the log recovery procedure. Also, remove the flags variable and set the *logflagsp directly, so that the code should be more robust in the long run. Fixes: 1b24b633aafe ("xfs: move some more code into xfs_bmap_del_extent_rea= l") Signed-off-by: Jiachen Zhang Reviewed-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_bmap.c | 73 +++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 42 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index be62acffad6c..eacd7f43c952 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -5010,7 +5010,6 @@ xfs_bmap_del_extent_real( xfs_fileoff_t del_endoff; /* first offset past del */ int do_fx; /* free extent at end of routine */ int error; /* error return value */ - int flags =3D 0;/* inode logging flags */ struct xfs_bmbt_irec got; /* current extent entry */ xfs_fileoff_t got_endoff; /* first offset past got */ int i; /* temp state */ @@ -5023,6 +5022,8 @@ xfs_bmap_del_extent_real( uint32_t state =3D xfs_bmap_fork_to_state(whichfork); struct xfs_bmbt_irec old; =20 + *logflagsp =3D 0; + mp =3D ip->i_mount; XFS_STATS_INC(mp, xs_del_exlist); =20 @@ -5035,7 +5036,6 @@ xfs_bmap_del_extent_real( ASSERT(got_endoff >=3D del_endoff); ASSERT(!isnullstartblock(got.br_startblock)); qfield =3D 0; - error =3D 0; =20 /* * If it's the case where the directory code is running with no block @@ -5051,13 +5051,13 @@ xfs_bmap_del_extent_real( del->br_startoff > got.br_startoff && del_endoff < got_endoff) return -ENOSPC; =20 - flags =3D XFS_ILOG_CORE; + *logflagsp =3D XFS_ILOG_CORE; if (whichfork =3D=3D XFS_DATA_FORK && XFS_IS_REALTIME_INODE(ip)) { if (!(bflags & XFS_BMAPI_REMAP)) { error =3D xfs_rtfree_blocks(tp, del->br_startblock, del->br_blockcount); if (error) - goto done; + return error; } =20 do_fx =3D 0; @@ -5072,11 +5072,9 @@ xfs_bmap_del_extent_real( if (cur) { error =3D xfs_bmbt_lookup_eq(cur, &got, &i); if (error) - goto done; - if (XFS_IS_CORRUPT(mp, i !=3D 1)) { - error =3D -EFSCORRUPTED; - goto done; - } + return error; + if (XFS_IS_CORRUPT(mp, i !=3D 1)) + return -EFSCORRUPTED; } =20 if (got.br_startoff =3D=3D del->br_startoff) @@ -5093,17 +5091,15 @@ xfs_bmap_del_extent_real( xfs_iext_prev(ifp, icur); ifp->if_nextents--; =20 - flags |=3D XFS_ILOG_CORE; + *logflagsp |=3D XFS_ILOG_CORE; if (!cur) { - flags |=3D xfs_ilog_fext(whichfork); + *logflagsp |=3D xfs_ilog_fext(whichfork); break; } if ((error =3D xfs_btree_delete(cur, &i))) - goto done; - if (XFS_IS_CORRUPT(mp, i !=3D 1)) { - error =3D -EFSCORRUPTED; - goto done; - } + return error; + if (XFS_IS_CORRUPT(mp, i !=3D 1)) + return -EFSCORRUPTED; break; case BMAP_LEFT_FILLING: /* @@ -5114,12 +5110,12 @@ xfs_bmap_del_extent_real( got.br_blockcount -=3D del->br_blockcount; xfs_iext_update_extent(ip, state, icur, &got); if (!cur) { - flags |=3D xfs_ilog_fext(whichfork); + *logflagsp |=3D xfs_ilog_fext(whichfork); break; } error =3D xfs_bmbt_update(cur, &got); if (error) - goto done; + return error; break; case BMAP_RIGHT_FILLING: /* @@ -5128,12 +5124,12 @@ xfs_bmap_del_extent_real( got.br_blockcount -=3D del->br_blockcount; xfs_iext_update_extent(ip, state, icur, &got); if (!cur) { - flags |=3D xfs_ilog_fext(whichfork); + *logflagsp |=3D xfs_ilog_fext(whichfork); break; } error =3D xfs_bmbt_update(cur, &got); if (error) - goto done; + return error; break; case 0: /* @@ -5150,18 +5146,18 @@ xfs_bmap_del_extent_real( new.br_state =3D got.br_state; new.br_startblock =3D del_endblock; =20 - flags |=3D XFS_ILOG_CORE; + *logflagsp |=3D XFS_ILOG_CORE; if (cur) { error =3D xfs_bmbt_update(cur, &got); if (error) - goto done; + return error; error =3D xfs_btree_increment(cur, 0, &i); if (error) - goto done; + return error; cur->bc_rec.b =3D new; error =3D xfs_btree_insert(cur, &i); if (error && error !=3D -ENOSPC) - goto done; + return error; /* * If get no-space back from btree insert, it tried a * split, and we have a zero block reservation. Fix up @@ -5174,33 +5170,28 @@ xfs_bmap_del_extent_real( */ error =3D xfs_bmbt_lookup_eq(cur, &got, &i); if (error) - goto done; - if (XFS_IS_CORRUPT(mp, i !=3D 1)) { - error =3D -EFSCORRUPTED; - goto done; - } + return error; + if (XFS_IS_CORRUPT(mp, i !=3D 1)) + return -EFSCORRUPTED; /* * Update the btree record back * to the original value. */ error =3D xfs_bmbt_update(cur, &old); if (error) - goto done; + return error; /* * Reset the extent record back * to the original value. */ xfs_iext_update_extent(ip, state, icur, &old); - flags =3D 0; - error =3D -ENOSPC; - goto done; - } - if (XFS_IS_CORRUPT(mp, i !=3D 1)) { - error =3D -EFSCORRUPTED; - goto done; + *logflagsp =3D 0; + return -ENOSPC; } + if (XFS_IS_CORRUPT(mp, i !=3D 1)) + return -EFSCORRUPTED; } else - flags |=3D xfs_ilog_fext(whichfork); + *logflagsp |=3D xfs_ilog_fext(whichfork); =20 ifp->if_nextents++; xfs_iext_next(ifp, icur); @@ -5224,7 +5215,7 @@ xfs_bmap_del_extent_real( ((bflags & XFS_BMAPI_NODISCARD) || del->br_state =3D=3D XFS_EXT_UNWRITTEN)); if (error) - goto done; + return error; } } =20 @@ -5239,9 +5230,7 @@ xfs_bmap_del_extent_real( if (qfield && !(bflags & XFS_BMAPI_REMAP)) xfs_trans_mod_dquot_byino(tp, ip, qfield, (long)-nblks); =20 -done: - *logflagsp =3D flags; - return error; + return 0; } =20 /* --=20 2.20.1 From nobody Tue Dec 16 11:42:58 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04FAFC4167B for ; Thu, 30 Nov 2023 04:05:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344397AbjK3EFl (ORCPT ); Wed, 29 Nov 2023 23:05:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234966AbjK3EFg (ORCPT ); Wed, 29 Nov 2023 23:05:36 -0500 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CBF710DF for ; Wed, 29 Nov 2023 20:05:42 -0800 (PST) Received: by mail-pj1-x1030.google.com with SMTP id 98e67ed59e1d1-285636785ddso584188a91.3 for ; Wed, 29 Nov 2023 20:05:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1701317141; x=1701921941; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xzZ48eJfLHHMlCtm8iE2OIqQ5CTleeJ/lIhizaNpWbg=; b=UJHPcnR3IAmJ6BxYQcXs7BT0KpYQYFtB/3DXw8JWcNb7fSZ8IRsEXMwkCdiQ8HdeVO CwzuFiUDBemxBQElnHO7aGUMkApPCPUahx87zMrLqmp7fCSl2tyYA7MgOWgU0cXyoBh5 YMb0H62WuMO8EJqVlA5yO5E624R6AC6/VLMM6UEZnZ/vCYrmBnGD5zKG5hUVoRxfUomX U7AS8n3KzT93bvXas47dqpCCID49mN5djQx/cFUH4xF2+Dc41RhNAvQu2/n5ywgDDkdO 2z1kvP48MKjlbkKdPgnk46k/32CqphqTNvOkHDBpGcVLKJr3I+rCU5i9pSU11Y0ldU95 Hd5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701317141; x=1701921941; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xzZ48eJfLHHMlCtm8iE2OIqQ5CTleeJ/lIhizaNpWbg=; b=dPbQeqIe5OHM4Gf/oIK6XwKPPQjtttikZGCHFkcPay+DIWURe0fpPBzh1BcN+RxBw9 9oSgR5AMpKRplb82Aqvu3bDJUT11J6thQaxouUkk0oGR59XVhkbg5mbH8UngsT8267Lc M7i2WkUqn8T43PuoCfQPYs/NAV3bQprBOolIxuHE08au/jIJsEY1yf5RUuFuOeVGz+Lc HNChQjj2xOmRVgXsiQdk3vyOadpf4fUkGkf4cUmCkKoUrtTalhBYgQYSjvkNutDsNC1G i6OK1ol4o2NxSLU4TcGkdedH+DSQ/jCCus+CNDzIMeDVwn4vU9eTSomHyF6lcdJY7AFC Y+Iw== X-Gm-Message-State: AOJu0YyWTeA4FWTMv8zmighrSP8/gtD+4YfIH4JI1HJGo8sXFmyQrdC4 5j8qAbKT8cJ6hhK9PjBMm6dkTw== X-Google-Smtp-Source: AGHT+IFQrYsOQuWo3n6G/FFjxEVrJeW/vdVp9n45XlrFZpjEuQm/fsiX77YwpQo1mKZTf5I7LaOZgQ== X-Received: by 2002:a17:90b:3a8c:b0:285:d720:b568 with SMTP id om12-20020a17090b3a8c00b00285d720b568mr11942054pjb.27.1701317141432; Wed, 29 Nov 2023 20:05:41 -0800 (PST) Received: from localhost.localdomain ([61.213.176.7]) by smtp.gmail.com with ESMTPSA id u6-20020a170903124600b001d01c970119sm174181plh.275.2023.11.29.20.05.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 20:05:40 -0800 (PST) From: Jiachen Zhang To: Chandan Babu R , "Darrick J. Wong" Cc: Dave Chinner , Allison Henderson , Zhang Tianci , Brian Foster , linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, xieyongji@bytedance.com, me@jcix.top, Dave Chinner Subject: [PATCH v3 2/3] xfs: update dir3 leaf block metadata after swap Date: Thu, 30 Nov 2023 12:05:15 +0800 Message-Id: <20231130040516.35677-3-zhangjiachen.jaycee@bytedance.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20231130040516.35677-1-zhangjiachen.jaycee@bytedance.com> References: <20231130040516.35677-1-zhangjiachen.jaycee@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 !=3D 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/0xe= 0 [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 ......= ..=3D....... 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...d= DA..`.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/x= fs/xfs_buf.c. Return address =3D 00000000c0ff63c1 XFS (dm-0): Corruption of in-memory data detected. Shutting down filesys= tem 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 rec= ord its blkno is 0x1a0. Fixes: 24df33b45ecf ("xfs: add CRC checking to dir2 leaf blocks") Signed-off-by: Zhang Tianci Suggested-by: Dave Chinner Reviewed-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_da_btree.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/xfs/libxfs/xfs_da_btree.c b/fs/xfs/libxfs/xfs_da_btree.c index e576560b46e9..f3f987a65bc1 100644 --- a/fs/xfs/libxfs/xfs_da_btree.c +++ b/fs/xfs/libxfs/xfs_da_btree.c @@ -2316,10 +2316,18 @@ xfs_da3_swap_lastblock( return error; /* * Copy the last block into the dead buffer and log it. + * If xfs enable crc, the node/leaf block records its blkno, we + * must update it. */ memcpy(dead_buf->b_addr, last_buf->b_addr, args->geo->blksize); + if (xfs_has_crc(mp)) { + struct xfs_da3_blkinfo *da3 =3D dead_buf->b_addr; + + da3->blkno =3D cpu_to_be64(xfs_buf_daddr(dead_buf)); + } xfs_trans_log_buf(tp, dead_buf, 0, args->geo->blksize - 1); dead_info =3D dead_buf->b_addr; + /* * Get values from the moved block. */ --=20 2.20.1 From nobody Tue Dec 16 11:42:58 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 074C0C4167B for ; Thu, 30 Nov 2023 04:06:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344448AbjK3EGM (ORCPT ); Wed, 29 Nov 2023 23:06:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344444AbjK3EGG (ORCPT ); Wed, 29 Nov 2023 23:06:06 -0500 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3BD3D66 for ; Wed, 29 Nov 2023 20:05:47 -0800 (PST) Received: by mail-pg1-x533.google.com with SMTP id 41be03b00d2f7-53fbf2c42bfso462468a12.3 for ; Wed, 29 Nov 2023 20:05:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1701317147; x=1701921947; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1ONsjeizIjE5OlaayHFlorAVbCZUs0JfCPupP+En1ic=; b=HqEFLVg2G2Y+zfn9p4Z4gs6nj37fo+/kmf39nwa4Cj5TOS0q4Jp4rfQWrBudZzARYF tF3IRb9q+438mbMT69Jqo6Nt6w5pNCAhCBlJW+UDJeiMVjiXrnuSWNX++b/NHhMTRtYW 58ruXgWALCWXaUd0bTW/1CJz73Gg2Xd+c6ZmiNy36g89zU5Q5Z8TwjcElR0FID4u6t8M 6vXY62UOdlzPKVwFVMIruKS9RvlR3UR55V1rGxDSgowx0+FTg2e4U/ozmqLa9+8ipEr6 SPDJteF3I2CbjFu3fh/e0wk+3nfz4KuSjk8z8FwMMgJyytFa1mRTCbfYJ4HRyzhH/xOP 0Wyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701317147; x=1701921947; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1ONsjeizIjE5OlaayHFlorAVbCZUs0JfCPupP+En1ic=; b=F3+YxiCzJjUDzVyRiPgal+AkM9g5Jq/hOpI8lMwOpJhiFTj4CD3Ax7dzvwZidY5Wiv PI9MWGOTc4sGHgUXXnmD3GEN74qbxgOAHOYIwsexYFmtMmCagKpIYNb6Q3QQNzGHebmy CFSik8J4esWq9SdWeqMKd7gycXUe0lycFmyWkPZCIut78U9o7EdH1fSat8DSPd3blT5P 4edTo48eCOdhWWXpnXAwYB9Z7VrtvzuzF1wc0yF6lso3+UZk+yXIPUJHYL4WV/Bgsar6 B3W1+PC2WR7d+mbKtQZWrwULrdLzkpudGQhtN+NFT2vI3nKwCiVa1xbrjCq9lg7RZ1AE C4cw== X-Gm-Message-State: AOJu0YypQd1wGg4Zd3C5o3LuU13lE2h2X/x7NxtP2wQxec2x8sTPKklc 3DvGN/9jI7igKqbEESbCU8Db0A== X-Google-Smtp-Source: AGHT+IGENlU2AnU0zafhpFrp1eBhMj0i2EcTlAUrNuqi2YPkll+KdKJHDo4eBv671KSFRb0Hw5Qu7Q== X-Received: by 2002:a05:6a20:914b:b0:18c:548d:3d23 with SMTP id x11-20020a056a20914b00b0018c548d3d23mr19929964pzc.59.1701317147305; Wed, 29 Nov 2023 20:05:47 -0800 (PST) Received: from localhost.localdomain ([61.213.176.7]) by smtp.gmail.com with ESMTPSA id u6-20020a170903124600b001d01c970119sm174181plh.275.2023.11.29.20.05.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 20:05:46 -0800 (PST) From: Jiachen Zhang To: Chandan Babu R , "Darrick J. Wong" Cc: Dave Chinner , Allison Henderson , Zhang Tianci , Brian Foster , linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, xieyongji@bytedance.com, me@jcix.top, Christoph Hellwig Subject: [PATCH v3 3/3] xfs: extract xfs_da_buf_copy() helper function Date: Thu, 30 Nov 2023 12:05:16 +0800 Message-Id: <20231130040516.35677-4-zhangjiachen.jaycee@bytedance.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20231130040516.35677-1-zhangjiachen.jaycee@bytedance.com> References: <20231130040516.35677-1-zhangjiachen.jaycee@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Zhang Tianci This patch does not modify logic. xfs_da_buf_copy() will copy one block from src xfs_buf to dst xfs_buf, and update the block metadata in dst directly. Signed-off-by: Zhang Tianci Suggested-by: Christoph Hellwig Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_attr_leaf.c | 12 ++---- fs/xfs/libxfs/xfs_da_btree.c | 76 ++++++++++++++--------------------- fs/xfs/libxfs/xfs_da_btree.h | 2 + 3 files changed, 37 insertions(+), 53 deletions(-) diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c index 2580ae47209a..628dcd2d971e 100644 --- a/fs/xfs/libxfs/xfs_attr_leaf.c +++ b/fs/xfs/libxfs/xfs_attr_leaf.c @@ -1244,14 +1244,10 @@ xfs_attr3_leaf_to_node( if (error) goto out; =20 - /* copy leaf to new buffer, update identifiers */ - xfs_trans_buf_set_type(args->trans, bp2, XFS_BLFT_ATTR_LEAF_BUF); - bp2->b_ops =3D bp1->b_ops; - memcpy(bp2->b_addr, bp1->b_addr, args->geo->blksize); - if (xfs_has_crc(mp)) { - struct xfs_da3_blkinfo *hdr3 =3D bp2->b_addr; - hdr3->blkno =3D cpu_to_be64(xfs_buf_daddr(bp2)); - } + /* + * copy leaf to new buffer and log it. + */ + xfs_da_buf_copy(bp2, bp1, args->geo->blksize); xfs_trans_log_buf(args->trans, bp2, 0, args->geo->blksize - 1); =20 /* diff --git a/fs/xfs/libxfs/xfs_da_btree.c b/fs/xfs/libxfs/xfs_da_btree.c index f3f987a65bc1..d39d6ad0f97b 100644 --- a/fs/xfs/libxfs/xfs_da_btree.c +++ b/fs/xfs/libxfs/xfs_da_btree.c @@ -690,12 +690,6 @@ xfs_da3_root_split( btree =3D icnodehdr.btree; size =3D (int)((char *)&btree[icnodehdr.count] - (char *)oldroot); level =3D icnodehdr.level; - - /* - * we are about to copy oldroot to bp, so set up the type - * of bp while we know exactly what it will be. - */ - xfs_trans_buf_set_type(tp, bp, XFS_BLFT_DA_NODE_BUF); } else { struct xfs_dir3_icleaf_hdr leafhdr; =20 @@ -707,31 +701,17 @@ xfs_da3_root_split( size =3D (int)((char *)&leafhdr.ents[leafhdr.count] - (char *)leaf); level =3D 0; - - /* - * we are about to copy oldroot to bp, so set up the type - * of bp while we know exactly what it will be. - */ - xfs_trans_buf_set_type(tp, bp, XFS_BLFT_DIR_LEAFN_BUF); } =20 /* - * we can copy most of the information in the node from one block to - * another, but for CRC enabled headers we have to make sure that the - * block specific identifiers are kept intact. We update the buffer - * directly for this. + * Copy old root to new buffer and log it. */ - memcpy(node, oldroot, size); - if (oldroot->hdr.info.magic =3D=3D cpu_to_be16(XFS_DA3_NODE_MAGIC) || - oldroot->hdr.info.magic =3D=3D cpu_to_be16(XFS_DIR3_LEAFN_MAGIC)) { - struct xfs_da3_intnode *node3 =3D (struct xfs_da3_intnode *)node; - - node3->hdr.info.blkno =3D cpu_to_be64(xfs_buf_daddr(bp)); - } + xfs_da_buf_copy(bp, blk1->bp, size); xfs_trans_log_buf(tp, bp, 0, size - 1); =20 - bp->b_ops =3D blk1->bp->b_ops; - xfs_trans_buf_copy_type(bp, blk1->bp); + /* + * Update blk1 to point to new buffer. + */ blk1->bp =3D bp; blk1->blkno =3D blkno; =20 @@ -1220,21 +1200,14 @@ xfs_da3_root_join( xfs_da_blkinfo_onlychild_validate(bp->b_addr, oldroothdr.level); =20 /* - * This could be copying a leaf back into the root block in the case of - * there only being a single leaf block left in the tree. Hence we have - * to update the b_ops pointer as well to match the buffer type change - * that could occur. For dir3 blocks we also need to update the block - * number in the buffer header. + * Copy child to root buffer and log it. */ - memcpy(root_blk->bp->b_addr, bp->b_addr, args->geo->blksize); - root_blk->bp->b_ops =3D bp->b_ops; - xfs_trans_buf_copy_type(root_blk->bp, bp); - if (oldroothdr.magic =3D=3D XFS_DA3_NODE_MAGIC) { - struct xfs_da3_blkinfo *da3 =3D root_blk->bp->b_addr; - da3->blkno =3D cpu_to_be64(xfs_buf_daddr(root_blk->bp)); - } + xfs_da_buf_copy(root_blk->bp, bp, args->geo->blksize); xfs_trans_log_buf(args->trans, root_blk->bp, 0, args->geo->blksize - 1); + /* + * Now we could drop the child buffer. + */ error =3D xfs_da_shrink_inode(args, child, bp); return error; } @@ -2252,6 +2225,26 @@ xfs_da_grow_inode( return error; } =20 +/* + * Copy src directory/xattribute leaf/node buffer to the dst. + * If xfs enables crc(IOW, xfs' on-disk format is v5), we have to + * make sure that the block specific identifiers are kept intact. + */ +void +xfs_da_buf_copy( + struct xfs_buf *dst, + struct xfs_buf *src, + size_t size) +{ + struct xfs_da3_blkinfo *da3 =3D dst->b_addr; + + memcpy(dst->b_addr, src->b_addr, size); + dst->b_ops =3D src->b_ops; + xfs_trans_buf_copy_type(dst, src); + if (xfs_has_crc(dst->b_mount)) + da3->blkno =3D cpu_to_be64(xfs_buf_daddr(dst)); +} + /* * Ick. We need to always be able to remove a btree block, even * if there's no space reservation because the filesystem is full. @@ -2316,15 +2309,8 @@ xfs_da3_swap_lastblock( return error; /* * Copy the last block into the dead buffer and log it. - * If xfs enable crc, the node/leaf block records its blkno, we - * must update it. */ - memcpy(dead_buf->b_addr, last_buf->b_addr, args->geo->blksize); - if (xfs_has_crc(mp)) { - struct xfs_da3_blkinfo *da3 =3D dead_buf->b_addr; - - da3->blkno =3D cpu_to_be64(xfs_buf_daddr(dead_buf)); - } + xfs_da_buf_copy(dead_buf, last_buf, args->geo->blksize); xfs_trans_log_buf(tp, dead_buf, 0, args->geo->blksize - 1); dead_info =3D dead_buf->b_addr; =20 diff --git a/fs/xfs/libxfs/xfs_da_btree.h b/fs/xfs/libxfs/xfs_da_btree.h index ffa3df5b2893..706baf36e175 100644 --- a/fs/xfs/libxfs/xfs_da_btree.h +++ b/fs/xfs/libxfs/xfs_da_btree.h @@ -219,6 +219,8 @@ int xfs_da_reada_buf(struct xfs_inode *dp, xfs_dablk_t = bno, const struct xfs_buf_ops *ops); int xfs_da_shrink_inode(xfs_da_args_t *args, xfs_dablk_t dead_blkno, struct xfs_buf *dead_buf); +void xfs_da_buf_copy(struct xfs_buf *dst, struct xfs_buf *src, + size_t size); =20 uint xfs_da_hashname(const uint8_t *name_string, int name_length); enum xfs_dacmp xfs_da_compname(struct xfs_da_args *args, --=20 2.20.1