Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: fdmanana@kernel.org, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] btrfs: simplify dir item location setup in btrfs_insert_xattr_item()
Date: Sat, 26 Sep 2026 08:13:45 +0930	[thread overview]
Message-ID: <d09b9361-af58-42fa-ba3c-45a9f83f8be3@gmx.com> (raw)
In-Reply-To: <8f24a85bf4a14292293a0e43c2522418f80f6a52.1790355077.git.fdmanana@suse.com>



在 2026/9/26 02:22, fdmanana@kernel.org 写道:
> From: Filipe Manana <fdmanana@suse.com>
> 
> The location (a btrfs_disk_key) of a btrfs_dir_item used for a xattr is
> always zeroed and we have a complex setup in btrfs_insert_xattr_item()
> where we declare an on stack btrfs_key, zero it out, convert it into a
> btrfs_disk_key, also declared on stack, and then pass that btrfs_disk_key
> to a btrfs_set_dir_item_key() call.
> 
> We can simplify this, and save stack space (one btrfs_disk_key and one
> btrfs_key), by simply using memzero_extent_buffer().
> 
> Signed-off-by: Filipe Manana <fdmanana@suse.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu

> ---
>   fs/btrfs/dir-item.c | 9 ++++-----
>   1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/btrfs/dir-item.c b/fs/btrfs/dir-item.c
> index 3a90736915af..d39f85035b43 100644
> --- a/fs/btrfs/dir-item.c
> +++ b/fs/btrfs/dir-item.c
> @@ -62,8 +62,7 @@ int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans,
>   	int ret = 0;
>   	struct btrfs_dir_item *dir_item;
>   	unsigned long name_ptr, data_ptr;
> -	struct btrfs_key key, location;
> -	struct btrfs_disk_key disk_key;
> +	struct btrfs_key key;
>   	struct extent_buffer *leaf;
>   	u32 data_size;
>   
> @@ -79,11 +78,11 @@ int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans,
>   					name, name_len);
>   	if (IS_ERR(dir_item))
>   		return PTR_ERR(dir_item);
> -	memset(&location, 0, sizeof(location));
>   
>   	leaf = path->nodes[0];
> -	btrfs_cpu_key_to_disk(&disk_key, &location);
> -	btrfs_set_dir_item_key(leaf, dir_item, &disk_key);
> +	memzero_extent_buffer(leaf, (unsigned long)dir_item +
> +			      offsetof(struct btrfs_dir_item, location),
> +			      sizeof(struct btrfs_disk_key));
>   	btrfs_set_dir_flags(leaf, dir_item, BTRFS_FT_XATTR);
>   	btrfs_set_dir_name_len(leaf, dir_item, name_len);
>   	btrfs_set_dir_transid(leaf, dir_item, trans->transid);


      reply	other threads:[~2026-09-25 22:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-25 16:52 [PATCH] btrfs: simplify dir item location setup in btrfs_insert_xattr_item() fdmanana
2026-09-25 22:43 ` Qu Wenruo [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d09b9361-af58-42fa-ba3c-45a9f83f8be3@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=fdmanana@kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox