From nobody Tue Dec 16 20:11:34 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 5B7A6C10DC3 for ; Tue, 5 Dec 2023 05:59:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344281AbjLEF7b (ORCPT ); Tue, 5 Dec 2023 00:59:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231695AbjLEF73 (ORCPT ); Tue, 5 Dec 2023 00:59:29 -0500 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8E57AA for ; Mon, 4 Dec 2023 21:59:35 -0800 (PST) Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-5c1a75a4b6cso1762402a12.2 for ; Mon, 04 Dec 2023 21:59:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1701755975; x=1702360775; 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=XSezztPpzbnoN5Gm9WnigSfdiZPls8znLUzzdIBA48c=; b=Wl2jk2W6B7HPT6M6mVcvffSkk0T4RcgcDfxY3YbOHs1nrAhEsNnO2GyTyd114+MPPJ vq+dXaAescZgq+ikkfC+dBuhduJNcYVcKb/tF4X6vJKQm4n47i+ZyG3vN1TSC4iFiaZn gjKHhow90OLn2SiFPUA9PYCmqCEXWG3mqKQsBX7D9Yz+FZsWZTkY3TDFErDDbP54eT4L OdydVgdP+Yo2wgyp3i/J+lwEEUuLkYz4YAacMgenQnUOomddyfLFNtChqov2jRG5c9bX IJZRbpydGHklaNCObbCwhptnryowAbnzi7zutGpifksjd/y0f2JzErPHbxhheQhYzE3r LKxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701755975; x=1702360775; 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=XSezztPpzbnoN5Gm9WnigSfdiZPls8znLUzzdIBA48c=; b=svjKiulTsQMu+QuIOuQ+eryvJqLHVPC2hf6b6618q/3sW6fXifR3wfoOANDWjTjKVg h5yRGt4OGk+/6Zq2ZiBkOE/bACsErq+qVqXFfJ2Yw4DYP9Obpo2smKhyz8deq8nP2ss+ d950fHU68fiLCDlV5k9xjP5VuuwJnpnJXEHA2jYnYt1RlrB1Jkc+Luj6uLvIdBw6kjp4 jeUG7R9cVWzuq+VMaF4rNsEzCFo6+1KDTYbmbg5jJUnzMYx7dqlo1YSXzqSzBA+LRhd2 ct34kBXkbx9FauPq9FXg3grZCmXlZFbVBtESyElKtOKxnNpx/50jAr/iHPr0pNDJz5BH OAiw== X-Gm-Message-State: AOJu0YyKC6HIGyt7iSHSzJQgJHLiu3MpOJkAqItaQuA5KTWbh7MMH07l XKKt1XtDnCADNM8pzFeF8KQsL19Z3mjZn6+AD0jgc7D+ X-Google-Smtp-Source: AGHT+IEiW1htDnrqBUR2CJ+H2GvnE37UjdNxvSFQjEJkVfXtex4MbpDKgKKk/LPhOcqJuCZ68bU30g== X-Received: by 2002:a17:902:8b85:b0:1d0:6ffd:ae0e with SMTP id ay5-20020a1709028b8500b001d06ffdae0emr2561663plb.117.1701755975368; Mon, 04 Dec 2023 21:59:35 -0800 (PST) Received: from localhost.localdomain ([61.213.176.5]) by smtp.gmail.com with ESMTPSA id jb7-20020a170903258700b001d05bb77b43sm7111605plb.19.2023.12.04.21.59.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 21:59:35 -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 v4 3/3] xfs: extract xfs_da_buf_copy() helper function Date: Tue, 5 Dec 2023 13:59:00 +0800 Message-Id: <20231205055900.62855-4-zhangjiachen.jaycee@bytedance.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20231205055900.62855-1-zhangjiachen.jaycee@bytedance.com> References: <20231205055900.62855-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 | 74 ++++++++++++++--------------------- fs/xfs/libxfs/xfs_da_btree.h | 2 + 3 files changed, 36 insertions(+), 52 deletions(-) diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c index 2580ae47209a..654e17e6610d 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 282c7cf032f4..5457188bb4de 100644 --- a/fs/xfs/libxfs/xfs_da_btree.c +++ b/fs/xfs/libxfs/xfs_da_btree.c @@ -421,6 +421,25 @@ xfs_da3_node_read_mapped( return xfs_da3_node_set_type(tp, *bpp); } =20 +/* + * Copy src directory/attr leaf/node buffer to the dst. + * For v5 file systems make sure the right blkno is stamped in. + */ +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)); +} + /*=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D * Routines used for growing the Btree. *=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D*/ @@ -690,12 +709,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 +720,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 +1219,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 can drop the child buffer. + */ error =3D xfs_da_shrink_inode(args, child, bp); return error; } @@ -2316,14 +2308,8 @@ xfs_da3_swap_lastblock( return error; /* * Copy the last block into the dead buffer and log it. - * On CRC-enabled file systems, also update the stamped in blkno. */ - 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