* [PATCH] erofs: clean up erofs_ishare_fill_inode()
@ 2026-06-07 17:21 Gao Xiang
2026-06-15 1:26 ` Hongbo Li
2026-06-16 11:32 ` Chao Yu
0 siblings, 2 replies; 3+ messages in thread
From: Gao Xiang @ 2026-06-07 17:21 UTC (permalink / raw)
To: linux-erofs; +Cc: LKML, oliver.yang, Gao Xiang, Hongbo Li
- 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>
---
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;
}
--
2.43.5
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] erofs: clean up erofs_ishare_fill_inode()
2026-06-07 17:21 [PATCH] erofs: clean up erofs_ishare_fill_inode() Gao Xiang
@ 2026-06-15 1:26 ` Hongbo Li
2026-06-16 11:32 ` Chao Yu
1 sibling, 0 replies; 3+ messages in thread
From: Hongbo Li @ 2026-06-15 1:26 UTC (permalink / raw)
To: Gao Xiang, linux-erofs; +Cc: LKML, oliver.yang
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;
> }
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] erofs: clean up erofs_ishare_fill_inode()
2026-06-07 17:21 [PATCH] erofs: clean up erofs_ishare_fill_inode() Gao Xiang
2026-06-15 1:26 ` Hongbo Li
@ 2026-06-16 11:32 ` Chao Yu
1 sibling, 0 replies; 3+ messages in thread
From: Chao Yu @ 2026-06-16 11:32 UTC (permalink / raw)
To: Gao Xiang, linux-erofs; +Cc: chao, LKML, oliver.yang, Hongbo Li
On 6/7/26 17: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: Chao Yu <chao@kernel.org>
Thanks,
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-06-16 11:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-07 17:21 [PATCH] erofs: clean up erofs_ishare_fill_inode() Gao Xiang
2026-06-15 1:26 ` Hongbo Li
2026-06-16 11:32 ` Chao Yu
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®