mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hongbo Li <lihongbo22@huawei.com>
To: Gao Xiang <hsiangkao@linux.alibaba.com>, <linux-erofs@lists.ozlabs.org>
Cc: LKML <linux-kernel@vger.kernel.org>, <oliver.yang@linux.alibaba.com>
Subject: Re: [PATCH] erofs: clean up erofs_ishare_fill_inode()
Date: Mon, 15 Jun 2026 09:26:14 +0800	[thread overview]
Message-ID: <51c13a05-a4f5-4bbe-ad1a-ba167fa2e76c@huawei.com> (raw)
In-Reply-To: <20260607172132.2695176-1-hsiangkao@linux.alibaba.com>



On 2026/6/8 1:21, Gao Xiang wrote:
>   - Use the shorthand `si` to replace the overly long `sharedinode`;
> 
>   - Introduce erofs_warn() and get rid of barely-used _erofs_printk();
> 
>   - Get rid of the variable `hash`;
> 
>   - Simplify error paths.
> 
> Cc: Hongbo Li <lihongbo22@huawei.com>
> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>

Reviewed-by: Hongbo Li <lihongbo22@huawei.com>

Thanks,
Hongbo

> ---
>   fs/erofs/internal.h |  2 ++
>   fs/erofs/ishare.c   | 45 +++++++++++++++++++--------------------------
>   2 files changed, 21 insertions(+), 26 deletions(-)
> 
> diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
> index 4792490161ec..9e2ae7b61977 100644
> --- a/fs/erofs/internal.h
> +++ b/fs/erofs/internal.h
> @@ -23,6 +23,8 @@
>   __printf(2, 3) void _erofs_printk(struct super_block *sb, const char *fmt, ...);
>   #define erofs_err(sb, fmt, ...)	\
>   	_erofs_printk(sb, KERN_ERR fmt "\n", ##__VA_ARGS__)
> +#define erofs_warn(sb, fmt, ...) \
> +	_erofs_printk(sb, KERN_WARNING fmt "\n", ##__VA_ARGS__)
>   #define erofs_info(sb, fmt, ...) \
>   	_erofs_printk(sb, KERN_INFO fmt "\n", ##__VA_ARGS__)
>   
> diff --git a/fs/erofs/ishare.c b/fs/erofs/ishare.c
> index 6ed66b17359b..35cbd0bc04d7 100644
> --- a/fs/erofs/ishare.c
> +++ b/fs/erofs/ishare.c
> @@ -40,49 +40,42 @@ static int erofs_ishare_iget5_set(struct inode *inode, void *data)
>   bool erofs_ishare_fill_inode(struct inode *inode)
>   {
>   	struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb);
> -	struct erofs_inode *vi = EROFS_I(inode);
>   	const struct address_space_operations *aops;
> +	struct erofs_inode *vi = EROFS_I(inode);
>   	struct erofs_inode_fingerprint fp;
> -	struct inode *sharedinode;
> -	unsigned long hash;
> +	struct inode *si;
>   
>   	aops = erofs_get_aops(inode, true);
>   	if (IS_ERR(aops))
>   		return false;
>   	if (erofs_xattr_fill_inode_fingerprint(&fp, inode, sbi->domain_id))
>   		return false;
> -	hash = xxh32(fp.opaque, fp.size, 0);
> -	sharedinode = iget5_locked(erofs_ishare_mnt->mnt_sb, hash,
> -				   erofs_ishare_iget5_eq, erofs_ishare_iget5_set,
> -				   &fp);
> -	if (!sharedinode) {
> -		kfree(fp.opaque);
> -		return false;
> -	}
>   
> -	if (inode_state_read_once(sharedinode) & I_NEW) {
> -		sharedinode->i_mapping->a_ops = aops;
> -		sharedinode->i_size = vi->vfs_inode.i_size;
> -		unlock_new_inode(sharedinode);
> +	si = iget5_locked(erofs_ishare_mnt->mnt_sb,
> +			  xxh32(fp.opaque, fp.size, 0),
> +			  erofs_ishare_iget5_eq, erofs_ishare_iget5_set, &fp);
> +	if (si && (inode_state_read_once(si) & I_NEW)) {
> +		si->i_mapping->a_ops = aops;
> +		si->i_size = inode->i_size;
> +		unlock_new_inode(si);
>   	} else {
>   		kfree(fp.opaque);
> -		if (aops != sharedinode->i_mapping->a_ops) {
> -			iput(sharedinode);
> +		if (!si || aops != si->i_mapping->a_ops) {
> +			iput(si);
>   			return false;
>   		}
> -		if (sharedinode->i_size != vi->vfs_inode.i_size) {
> -			_erofs_printk(inode->i_sb, KERN_WARNING
> -				"size(%lld:%lld) not matches for the same fingerprint\n",
> -				vi->vfs_inode.i_size, sharedinode->i_size);
> -			iput(sharedinode);
> +		if (si->i_size != inode->i_size) {
> +			erofs_warn(inode->i_sb, "i_size mismatch (%lld != %lld) for the same fingerprint",
> +				   inode->i_size, si->i_size);
> +			iput(si);
>   			return false;
>   		}
>   	}
> -	vi->sharedinode = sharedinode;
> +	vi->sharedinode = si;
>   	INIT_LIST_HEAD(&vi->ishare_list);
> -	spin_lock(&EROFS_I(sharedinode)->ishare_lock);
> -	list_add(&vi->ishare_list, &EROFS_I(sharedinode)->ishare_list);
> -	spin_unlock(&EROFS_I(sharedinode)->ishare_lock);
> +	spin_lock(&EROFS_I(si)->ishare_lock);
> +	list_add(&vi->ishare_list, &EROFS_I(si)->ishare_list);
> +	spin_unlock(&EROFS_I(si)->ishare_lock);
>   	return true;
>   }
>   

  reply	other threads:[~2026-06-15  1:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-07 17:21 Gao Xiang
2026-06-15  1:26 ` Hongbo Li [this message]
2026-06-16 11:32 ` Chao Yu

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=51c13a05-a4f5-4bbe-ad1a-ba167fa2e76c@huawei.com \
    --to=lihongbo22@huawei.com \
    --cc=hsiangkao@linux.alibaba.com \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oliver.yang@linux.alibaba.com \
    /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

all inboxes | Powered by JetHome®