erofs: use inode_set_cached_link()
PATCH 1/1 erofs: use inode_set_cached_link()
Symlink lengths are now cached in in-memory inodes directly so that readlink can be sped up.
Signed-off-by Gao Xiang <[email protected]>
--- fs/erofs/inode.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)
fs/erofs/inode.c +15 -13
@@ -8,21 +8,23 @@#include <linux/compat.h> #include <trace/events/erofs.h> -static int erofs_fill_symlink (struct inode *inode,void *kaddr, -unsigned int m_pofs) +static int erofs_fill_symlink (struct inode *inode,void *bptr,unsigned int ofs) {struct erofs_inode *vi =EROFS_I (inode); -loff_t off; - - m_pofs += vi->xattr_isize; -/* check if it cannot be handled with fast symlink scheme */ -if (vi->datalayout !=EROFS_INODE_FLAT_INLINE || -check_add_overflow (m_pofs, inode->i_size, &off) || - off >i_blocksize (inode)) -return 0 ; - - inode->i_link =kmemdup_nul (kaddr + m_pofs, inode->i_size,GFP_KERNEL ); -return inode->i_link ?0 : -ENOMEM ; +char *link; +loff_t end; + + ofs += vi->xattr_isize; +/* check whether the symlink data is small enough to be inlined */ +if (vi->datalayout ==EROFS_INODE_FLAT_INLINE && + !check_add_overflow (ofs, inode->i_size, &end) && + end <=i_blocksize (inode)) { + link =kmemdup_nul (bptr + ofs, inode->i_size,GFP_KERNEL ); +if (!link) +return -ENOMEM ; +inode_set_cached_link (inode, link, inode->i_size); + } +return 0 ; }static int erofs_read_inode (struct inode *inode)
Signature · 1 line
2.43.5
Quoted 4 lines · Gao Xiang
Symlink lengths are now cached in in-memory inodes directly so that readlink can be sped up.
Signed-off-by Gao Xiang <[email protected]>
Reviewed-by Hongbo Li <[email protected]>
Thanks,
Hongbo
Quoted 45 lines
--- fs/erofs/inode.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)fs/erofs/inode.c +15
-13@@ -8,21 +8,23 @@#include <linux/compat.h> #include <trace/events/erofs.h> -static int erofs_fill_symlink (struct inode *inode,void *kaddr, -unsigned int m_pofs) +static int erofs_fill_symlink (struct inode *inode,void *bptr,unsigned int ofs) {struct erofs_inode *vi =EROFS_I (inode); -loff_t off; - - m_pofs += vi->xattr_isize; -/* check if it cannot be handled with fast symlink scheme */ -if (vi->datalayout !=EROFS_INODE_FLAT_INLINE || -check_add_overflow (m_pofs, inode->i_size, &off) || - off >i_blocksize (inode)) -return 0 ; - - inode->i_link =kmemdup_nul (kaddr + m_pofs, inode->i_size,GFP_KERNEL ); -return inode->i_link ?0 : -ENOMEM ; +char *link; +loff_t end; + + ofs += vi->xattr_isize; +/* check whether the symlink data is small enough to be inlined */ +if (vi->datalayout ==EROFS_INODE_FLAT_INLINE && + !check_add_overflow (ofs, inode->i_size, &end) && + end <=i_blocksize (inode)) { + link =kmemdup_nul (bptr + ofs, inode->i_size,GFP_KERNEL ); +if (!link) +return -ENOMEM ; +inode_set_cached_link (inode, link, inode->i_size); + } +return 0 ; }static int erofs_read_inode (struct inode *inode)
PATCH v2 1/1 erofs: use inode_set_cached_link()
In reply to Gao XiangSymlink lengths are now cached in in-memory inodes directly so that readlink can be sped up.
Signed-off-by Gao Xiang <[email protected]>
---
v2:
- fix syzbot reports:
https://syzkaller.appspot.com/bug?extid=c2dd47dc153320cc4692
fs/erofs/inode.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-)
fs/erofs/inode.c +21 -13
@@ -8,21 +8,29 @@#include <linux/compat.h> #include <trace/events/erofs.h> -static int erofs_fill_symlink (struct inode *inode,void *kaddr, -unsigned int m_pofs) +static int erofs_fill_symlink (struct inode *inode,void *bptr,unsigned int ofs) {struct erofs_inode *vi =EROFS_I (inode); -loff_t off; - - m_pofs += vi->xattr_isize; -/* check if it cannot be handled with fast symlink scheme */ -if (vi->datalayout !=EROFS_INODE_FLAT_INLINE || -check_add_overflow (m_pofs, inode->i_size, &off) || - off >i_blocksize (inode)) -return 0 ; - - inode->i_link =kmemdup_nul (kaddr + m_pofs, inode->i_size,GFP_KERNEL ); -return inode->i_link ?0 : -ENOMEM ; +char *link; +loff_t end; + + ofs += vi->xattr_isize; +/* check whether the symlink data is small enough to be inlined */ +if (vi->datalayout ==EROFS_INODE_FLAT_INLINE && + !check_add_overflow (ofs, inode->i_size, &end) && + end <=i_blocksize (inode)) { + link =kmemdup_nul (bptr + ofs, inode->i_size,GFP_KERNEL ); +if (!link) +return -ENOMEM ; +if (unlikely (!inode->i_size ||strlen (link) != inode->i_size)) { +erofs_err (inode->i_sb,"invalid fast symlink size %llu @ nid %llu" , + inode->i_size |0ULL , vi->nid); +kfree (link); +return -EFSCORRUPTED ; + } +inode_set_cached_link (inode, link, inode->i_size); + } +return 0 ; }static int erofs_read_inode (struct inode *inode)
Signature · 1 line
2.43.5