From nobody Sat Apr 11 14:13:59 2026 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 C7C2DC25B0E for ; Fri, 12 Aug 2022 14:43:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237029AbiHLOnA (ORCPT ); Fri, 12 Aug 2022 10:43:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238760AbiHLOmw (ORCPT ); Fri, 12 Aug 2022 10:42:52 -0400 Received: from synology.com (mail.synology.com [211.23.38.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B5CDAB1BA; Fri, 12 Aug 2022 07:42:51 -0700 (PDT) Received: from localhost.localdomain (unknown [10.17.41.204]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by synology.com (Postfix) with ESMTPSA id C6A0C2D0446AA; Fri, 12 Aug 2022 22:42:49 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synology.com; s=123; t=1660315369; bh=NlLH4gcwbWn1WqzYcqKyY79CAKssO+sDk1ZOyNCFY/M=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hXqJCZfssdFUGLDyh6h0u0gn6sp5aA9MEcng00HsRE7g6VjVDfq2IHG4PMYJcWVih viv/LE0t+8gqHzjyLvzEkFjAu2IveZZ/kkB8wT4TgTK9yn8o5d08ZIJqgzrMXBYYSV 8fTZT5uzPzP1LJQqEWIFon6pCOGT/Q5BuTWdzOGk= From: bingjingc To: fdmanana@kernel.org, josef@toxicpanda.com, dsterba@suse.com, clm@fb.com, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: bingjingc@synology.com, robbieko@synology.com, bxxxjxxg@gmail.com Subject: [PATCH v3 1/2] btrfs: send: refactor get_inode_info() Date: Fri, 12 Aug 2022 22:42:32 +0800 Message-Id: <20220812144233.132960-2-bingjingc@synology.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220812144233.132960-1-bingjingc@synology.com> References: <20220812144233.132960-1-bingjingc@synology.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Synology-MCP-Status: no X-Synology-Spam-Flag: no X-Synology-Spam-Status: score=0, required 6, WHITELIST_FROM_ADDRESS 0 X-Synology-Virus-Status: no Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: BingJing Chang Refactor get_inode_info() to populate all wanted fields on an output structure. Besides, also introduce a helper function called get_inode_gen(), which is majorly used. Reviewed-by: Robbie Ko Signed-off-by: BingJing Chang Reviewed-by: Filipe Manana --- fs/btrfs/send.c | 154 +++++++++++++++++++++++++----------------------- 1 file changed, 79 insertions(+), 75 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index e7671afcee4f..f8d77a33b9b7 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -842,17 +842,31 @@ static int send_rmdir(struct send_ctx *sctx, struct f= s_path *path) return ret; } =20 +struct btrfs_inode_info { + u64 size; + u64 gen; + u64 mode; + u64 uid; + u64 gid; + u64 rdev; + u64 attr; +}; + /* * Helper function to retrieve some fields from an inode item. */ -static int __get_inode_info(struct btrfs_root *root, struct btrfs_path *pa= th, - u64 ino, u64 *size, u64 *gen, u64 *mode, u64 *uid, - u64 *gid, u64 *rdev, u64 *fileattr) +static int get_inode_info(struct btrfs_root *root, u64 ino, + struct btrfs_inode_info *info) { int ret; + struct btrfs_path *path; struct btrfs_inode_item *ii; struct btrfs_key key; =20 + path =3D alloc_path_for_send(); + if (!path) + return -ENOMEM; + key.objectid =3D ino; key.type =3D BTRFS_INODE_ITEM_KEY; key.offset =3D 0; @@ -860,47 +874,42 @@ static int __get_inode_info(struct btrfs_root *root, = struct btrfs_path *path, if (ret) { if (ret > 0) ret =3D -ENOENT; - return ret; + goto out; } =20 + if (!info) + goto out; + ii =3D btrfs_item_ptr(path->nodes[0], path->slots[0], struct btrfs_inode_item); - if (size) - *size =3D btrfs_inode_size(path->nodes[0], ii); - if (gen) - *gen =3D btrfs_inode_generation(path->nodes[0], ii); - if (mode) - *mode =3D btrfs_inode_mode(path->nodes[0], ii); - if (uid) - *uid =3D btrfs_inode_uid(path->nodes[0], ii); - if (gid) - *gid =3D btrfs_inode_gid(path->nodes[0], ii); - if (rdev) - *rdev =3D btrfs_inode_rdev(path->nodes[0], ii); + info->size =3D btrfs_inode_size(path->nodes[0], ii); + info->gen =3D btrfs_inode_generation(path->nodes[0], ii); + info->mode =3D btrfs_inode_mode(path->nodes[0], ii); + info->uid =3D btrfs_inode_uid(path->nodes[0], ii); + info->gid =3D btrfs_inode_gid(path->nodes[0], ii); + info->rdev =3D btrfs_inode_rdev(path->nodes[0], ii); /* * Transfer the unchanged u64 value of btrfs_inode_item::flags, that's * otherwise logically split to 32/32 parts. */ - if (fileattr) - *fileattr =3D btrfs_inode_flags(path->nodes[0], ii); + info->attr =3D btrfs_inode_flags(path->nodes[0], ii); =20 +out: + btrfs_free_path(path); return ret; } =20 -static int get_inode_info(struct btrfs_root *root, - u64 ino, u64 *size, u64 *gen, - u64 *mode, u64 *uid, u64 *gid, - u64 *rdev, u64 *fileattr) +static int get_inode_gen(struct btrfs_root *root, u64 ino, u64 *gen) { - struct btrfs_path *path; int ret; + struct btrfs_inode_info info; =20 - path =3D alloc_path_for_send(); - if (!path) - return -ENOMEM; - ret =3D __get_inode_info(root, path, ino, size, gen, mode, uid, gid, - rdev, fileattr); - btrfs_free_path(path); + if (!gen) + return -EPERM; + + ret =3D get_inode_info(root, ino, &info); + if (!ret) + *gen =3D info.gen; return ret; } =20 @@ -1644,8 +1653,7 @@ static int get_cur_inode_state(struct send_ctx *sctx,= u64 ino, u64 gen) u64 left_gen; u64 right_gen; =20 - ret =3D get_inode_info(sctx->send_root, ino, NULL, &left_gen, NULL, NULL, - NULL, NULL, NULL); + ret =3D get_inode_gen(sctx->send_root, ino, &left_gen); if (ret < 0 && ret !=3D -ENOENT) goto out; left_ret =3D ret; @@ -1653,8 +1661,7 @@ static int get_cur_inode_state(struct send_ctx *sctx,= u64 ino, u64 gen) if (!sctx->parent_root) { right_ret =3D -ENOENT; } else { - ret =3D get_inode_info(sctx->parent_root, ino, NULL, &right_gen, - NULL, NULL, NULL, NULL, NULL); + ret =3D get_inode_gen(sctx->parent_root, ino, &right_gen); if (ret < 0 && ret !=3D -ENOENT) goto out; right_ret =3D ret; @@ -1816,8 +1823,7 @@ static int get_first_ref(struct btrfs_root *root, u64= ino, btrfs_release_path(path); =20 if (dir_gen) { - ret =3D get_inode_info(root, parent_dir, NULL, dir_gen, NULL, - NULL, NULL, NULL, NULL); + ret =3D get_inode_gen(root, parent_dir, dir_gen); if (ret < 0) goto out; } @@ -1874,6 +1880,7 @@ static int will_overwrite_ref(struct send_ctx *sctx, = u64 dir, u64 dir_gen, int ret =3D 0; u64 gen; u64 other_inode =3D 0; + struct btrfs_inode_info info; =20 if (!sctx->parent_root) goto out; @@ -1888,8 +1895,7 @@ static int will_overwrite_ref(struct send_ctx *sctx, = u64 dir, u64 dir_gen, * and we can just unlink this entry. */ if (sctx->parent_root && dir !=3D BTRFS_FIRST_FREE_OBJECTID) { - ret =3D get_inode_info(sctx->parent_root, dir, NULL, &gen, NULL, - NULL, NULL, NULL, NULL); + ret =3D get_inode_gen(sctx->parent_root, dir, &gen); if (ret < 0 && ret !=3D -ENOENT) goto out; if (ret) { @@ -1916,13 +1922,14 @@ static int will_overwrite_ref(struct send_ctx *sctx= , u64 dir, u64 dir_gen, */ if (other_inode > sctx->send_progress || is_waiting_for_move(sctx, other_inode)) { - ret =3D get_inode_info(sctx->parent_root, other_inode, NULL, - who_gen, who_mode, NULL, NULL, NULL, NULL); + ret =3D get_inode_info(sctx->parent_root, other_inode, &info); if (ret < 0) goto out; =20 ret =3D 1; *who_ino =3D other_inode; + *who_gen =3D info.gen; + *who_mode =3D info.mode; } else { ret =3D 0; } @@ -1955,8 +1962,7 @@ static int did_overwrite_ref(struct send_ctx *sctx, goto out; =20 if (dir !=3D BTRFS_FIRST_FREE_OBJECTID) { - ret =3D get_inode_info(sctx->send_root, dir, NULL, &gen, NULL, - NULL, NULL, NULL, NULL); + ret =3D get_inode_gen(sctx->send_root, dir, &gen); if (ret < 0 && ret !=3D -ENOENT) goto out; if (ret) { @@ -1978,8 +1984,7 @@ static int did_overwrite_ref(struct send_ctx *sctx, goto out; } =20 - ret =3D get_inode_info(sctx->send_root, ow_inode, NULL, &gen, NULL, NULL, - NULL, NULL, NULL); + ret =3D get_inode_gen(sctx->send_root, ow_inode, &gen); if (ret < 0) goto out; =20 @@ -2645,6 +2650,7 @@ static int send_create_inode(struct send_ctx *sctx, u= 64 ino) int ret =3D 0; struct fs_path *p; int cmd; + struct btrfs_inode_info info; u64 gen; u64 mode; u64 rdev; @@ -2656,10 +2662,12 @@ static int send_create_inode(struct send_ctx *sctx,= u64 ino) return -ENOMEM; =20 if (ino !=3D sctx->cur_ino) { - ret =3D get_inode_info(sctx->send_root, ino, NULL, &gen, &mode, - NULL, NULL, &rdev, NULL); + ret =3D get_inode_info(sctx->send_root, ino, &info); if (ret < 0) goto out; + gen =3D info.gen; + mode =3D info.mode; + rdev =3D info.rdev; } else { gen =3D sctx->cur_inode_gen; mode =3D sctx->cur_inode_mode; @@ -3359,8 +3367,7 @@ static int apply_dir_move(struct send_ctx *sctx, stru= ct pending_dir_move *pm) /* * The parent inode might have been deleted in the send snapshot */ - ret =3D get_inode_info(sctx->send_root, cur->dir, NULL, - NULL, NULL, NULL, NULL, NULL, NULL); + ret =3D get_inode_info(sctx->send_root, cur->dir, NULL); if (ret =3D=3D -ENOENT) { ret =3D 0; continue; @@ -3534,12 +3541,10 @@ static int wait_for_dest_dir_move(struct send_ctx *= sctx, goto out; } =20 - ret =3D get_inode_info(sctx->parent_root, di_key.objectid, NULL, - &left_gen, NULL, NULL, NULL, NULL, NULL); + ret =3D get_inode_gen(sctx->parent_root, di_key.objectid, &left_gen); if (ret < 0) goto out; - ret =3D get_inode_info(sctx->send_root, di_key.objectid, NULL, - &right_gen, NULL, NULL, NULL, NULL, NULL); + ret =3D get_inode_gen(sctx->send_root, di_key.objectid, &right_gen); if (ret < 0) { if (ret =3D=3D -ENOENT) ret =3D 0; @@ -3669,8 +3674,7 @@ static int is_ancestor(struct btrfs_root *root, cur_offset =3D item_size; } =20 - ret =3D get_inode_info(root, parent, NULL, &parent_gen, - NULL, NULL, NULL, NULL, NULL); + ret =3D get_inode_gen(root, parent, &parent_gen); if (ret < 0) goto out; ret =3D check_ino_in_path(root, ino1, ino1_gen, @@ -3760,9 +3764,8 @@ static int wait_for_parent_move(struct send_ctx *sctx, memcmp(path_before->start, path_after->start, len1))) { u64 parent_ino_gen; =20 - ret =3D get_inode_info(sctx->parent_root, ino, NULL, - &parent_ino_gen, NULL, NULL, NULL, - NULL, NULL); + ret =3D get_inode_gen(sctx->parent_root, ino, + &parent_ino_gen); if (ret < 0) goto out; if (ino_gen =3D=3D parent_ino_gen) { @@ -4441,8 +4444,7 @@ static int record_new_ref_if_needed(int num, u64 dir,= int index, struct recorded_ref *ref; u64 dir_gen; =20 - ret =3D get_inode_info(sctx->send_root, dir, NULL, &dir_gen, NULL, - NULL, NULL, NULL, NULL); + ret =3D get_inode_gen(sctx->send_root, dir, &dir_gen); if (ret < 0) goto out; =20 @@ -4472,8 +4474,7 @@ static int record_deleted_ref_if_needed(int num, u64 = dir, int index, struct recorded_ref *ref; u64 dir_gen; =20 - ret =3D get_inode_info(sctx->parent_root, dir, NULL, &dir_gen, NULL, - NULL, NULL, NULL, NULL); + ret =3D get_inode_gen(sctx->parent_root, dir, &dir_gen); if (ret < 0) goto out; =20 @@ -5056,8 +5057,7 @@ static int send_clone(struct send_ctx *sctx, TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, p); =20 if (clone_root->root =3D=3D sctx->send_root) { - ret =3D get_inode_info(sctx->send_root, clone_root->ino, NULL, - &gen, NULL, NULL, NULL, NULL, NULL); + ret =3D get_inode_gen(sctx->send_root, clone_root->ino, &gen); if (ret < 0) goto out; ret =3D get_cur_path(sctx, clone_root->ino, gen, p); @@ -5536,6 +5536,7 @@ static int clone_range(struct send_ctx *sctx, struct = btrfs_path *dst_path, struct btrfs_path *path; struct btrfs_key key; int ret; + struct btrfs_inode_info info; u64 clone_src_i_size =3D 0; =20 /* @@ -5565,12 +5566,11 @@ static int clone_range(struct send_ctx *sctx, struc= t btrfs_path *dst_path, * There are inodes that have extents that lie behind its i_size. Don't * accept clones from these extents. */ - ret =3D __get_inode_info(clone_root->root, path, clone_root->ino, - &clone_src_i_size, NULL, NULL, NULL, NULL, NULL, - NULL); + ret =3D get_inode_info(clone_root->root, clone_root->ino, &info); btrfs_release_path(path); if (ret < 0) goto out; + clone_src_i_size =3D info.size; =20 /* * We can't send a clone operation for the entire range if we find @@ -6259,6 +6259,7 @@ static int process_recorded_refs_if_needed(struct sen= d_ctx *sctx, int at_end, static int finish_inode_if_needed(struct send_ctx *sctx, int at_end) { int ret =3D 0; + struct btrfs_inode_info info; u64 left_mode; u64 left_uid; u64 left_gid; @@ -6301,11 +6302,13 @@ static int finish_inode_if_needed(struct send_ctx *= sctx, int at_end) goto out; if (!at_end && sctx->cmp_key->objectid =3D=3D sctx->cur_ino) goto out; - - ret =3D get_inode_info(sctx->send_root, sctx->cur_ino, NULL, NULL, - &left_mode, &left_uid, &left_gid, NULL, &left_fileattr); + ret =3D get_inode_info(sctx->send_root, sctx->cur_ino, &info); if (ret < 0) goto out; + left_mode =3D info.mode; + left_uid =3D info.uid; + left_gid =3D info.gid; + left_fileattr =3D info.attr; =20 if (!sctx->parent_root || sctx->cur_inode_new) { need_chown =3D 1; @@ -6316,11 +6319,14 @@ static int finish_inode_if_needed(struct send_ctx *= sctx, int at_end) } else { u64 old_size; =20 - ret =3D get_inode_info(sctx->parent_root, sctx->cur_ino, - &old_size, NULL, &right_mode, &right_uid, - &right_gid, NULL, &right_fileattr); + ret =3D get_inode_info(sctx->parent_root, sctx->cur_ino, &info); if (ret < 0) goto out; + old_size =3D info.size; + right_mode =3D info.mode; + right_uid =3D info.uid; + right_gid =3D info.gid; + right_fileattr =3D info.attr; =20 if (left_uid !=3D right_uid || left_gid !=3D right_gid) need_chown =3D 1; @@ -6790,13 +6796,11 @@ static int dir_changed(struct send_ctx *sctx, u64 d= ir) u64 orig_gen, new_gen; int ret; =20 - ret =3D get_inode_info(sctx->send_root, dir, NULL, &new_gen, NULL, NULL, - NULL, NULL, NULL); + ret =3D get_inode_gen(sctx->send_root, dir, &new_gen); if (ret) return ret; =20 - ret =3D get_inode_info(sctx->parent_root, dir, NULL, &orig_gen, NULL, - NULL, NULL, NULL, NULL); + ret =3D get_inode_gen(sctx->parent_root, dir, &orig_gen); if (ret) return ret; =20 --=20 2.37.1