erofs: use meta buffers for inode operations

Get rid of old erofs_get_meta_page() within inode operations by
using on-stack meta buffers in order to prepare subpage and folio
features.

Link: https://lore.kernel.org/r/20220102040017.51352-3-hsiangkao@linux.alibaba.com
Reviewed-by: Yue Hu <huyue2@yulong.com>
Reviewed-by: Liu Bo <bo.liu@linux.alibaba.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
This commit is contained in:
Gao Xiang 2022-01-02 12:00:14 +08:00
Родитель fdf80a4793
Коммит c521e3ad6c
2 изменённых файлов: 35 добавлений и 36 удалений

Просмотреть файл

@ -13,8 +13,8 @@
* the inode payload page if it's an extended inode) in order to fill * the inode payload page if it's an extended inode) in order to fill
* inline data if possible. * inline data if possible.
*/ */
static struct page *erofs_read_inode(struct inode *inode, static void *erofs_read_inode(struct erofs_buf *buf,
unsigned int *ofs) struct inode *inode, unsigned int *ofs)
{ {
struct super_block *sb = inode->i_sb; struct super_block *sb = inode->i_sb;
struct erofs_sb_info *sbi = EROFS_SB(sb); struct erofs_sb_info *sbi = EROFS_SB(sb);
@ -22,7 +22,7 @@ static struct page *erofs_read_inode(struct inode *inode,
const erofs_off_t inode_loc = iloc(sbi, vi->nid); const erofs_off_t inode_loc = iloc(sbi, vi->nid);
erofs_blk_t blkaddr, nblks = 0; erofs_blk_t blkaddr, nblks = 0;
struct page *page; void *kaddr;
struct erofs_inode_compact *dic; struct erofs_inode_compact *dic;
struct erofs_inode_extended *die, *copied = NULL; struct erofs_inode_extended *die, *copied = NULL;
unsigned int ifmt; unsigned int ifmt;
@ -34,14 +34,14 @@ static struct page *erofs_read_inode(struct inode *inode,
erofs_dbg("%s, reading inode nid %llu at %u of blkaddr %u", erofs_dbg("%s, reading inode nid %llu at %u of blkaddr %u",
__func__, vi->nid, *ofs, blkaddr); __func__, vi->nid, *ofs, blkaddr);
page = erofs_get_meta_page(sb, blkaddr); kaddr = erofs_read_metabuf(buf, sb, blkaddr, EROFS_KMAP);
if (IS_ERR(page)) { if (IS_ERR(kaddr)) {
erofs_err(sb, "failed to get inode (nid: %llu) page, err %ld", erofs_err(sb, "failed to get inode (nid: %llu) page, err %ld",
vi->nid, PTR_ERR(page)); vi->nid, PTR_ERR(kaddr));
return page; return kaddr;
} }
dic = page_address(page) + *ofs; dic = kaddr + *ofs;
ifmt = le16_to_cpu(dic->i_format); ifmt = le16_to_cpu(dic->i_format);
if (ifmt & ~EROFS_I_ALL) { if (ifmt & ~EROFS_I_ALL) {
@ -62,12 +62,12 @@ static struct page *erofs_read_inode(struct inode *inode,
switch (erofs_inode_version(ifmt)) { switch (erofs_inode_version(ifmt)) {
case EROFS_INODE_LAYOUT_EXTENDED: case EROFS_INODE_LAYOUT_EXTENDED:
vi->inode_isize = sizeof(struct erofs_inode_extended); vi->inode_isize = sizeof(struct erofs_inode_extended);
/* check if the inode acrosses page boundary */ /* check if the extended inode acrosses block boundary */
if (*ofs + vi->inode_isize <= PAGE_SIZE) { if (*ofs + vi->inode_isize <= EROFS_BLKSIZ) {
*ofs += vi->inode_isize; *ofs += vi->inode_isize;
die = (struct erofs_inode_extended *)dic; die = (struct erofs_inode_extended *)dic;
} else { } else {
const unsigned int gotten = PAGE_SIZE - *ofs; const unsigned int gotten = EROFS_BLKSIZ - *ofs;
copied = kmalloc(vi->inode_isize, GFP_NOFS); copied = kmalloc(vi->inode_isize, GFP_NOFS);
if (!copied) { if (!copied) {
@ -75,18 +75,16 @@ static struct page *erofs_read_inode(struct inode *inode,
goto err_out; goto err_out;
} }
memcpy(copied, dic, gotten); memcpy(copied, dic, gotten);
unlock_page(page); kaddr = erofs_read_metabuf(buf, sb, blkaddr + 1,
put_page(page); EROFS_KMAP);
if (IS_ERR(kaddr)) {
page = erofs_get_meta_page(sb, blkaddr + 1); erofs_err(sb, "failed to get inode payload block (nid: %llu), err %ld",
if (IS_ERR(page)) { vi->nid, PTR_ERR(kaddr));
erofs_err(sb, "failed to get inode payload page (nid: %llu), err %ld",
vi->nid, PTR_ERR(page));
kfree(copied); kfree(copied);
return page; return kaddr;
} }
*ofs = vi->inode_isize - gotten; *ofs = vi->inode_isize - gotten;
memcpy((u8 *)copied + gotten, page_address(page), *ofs); memcpy((u8 *)copied + gotten, kaddr, *ofs);
die = copied; die = copied;
} }
vi->xattr_isize = erofs_xattr_ibody_size(die->i_xattr_icount); vi->xattr_isize = erofs_xattr_ibody_size(die->i_xattr_icount);
@ -200,7 +198,7 @@ static struct page *erofs_read_inode(struct inode *inode,
inode->i_blocks = roundup(inode->i_size, EROFS_BLKSIZ) >> 9; inode->i_blocks = roundup(inode->i_size, EROFS_BLKSIZ) >> 9;
else else
inode->i_blocks = nblks << LOG_SECTORS_PER_BLOCK; inode->i_blocks = nblks << LOG_SECTORS_PER_BLOCK;
return page; return kaddr;
bogusimode: bogusimode:
erofs_err(inode->i_sb, "bogus i_mode (%o) @ nid %llu", erofs_err(inode->i_sb, "bogus i_mode (%o) @ nid %llu",
@ -209,12 +207,11 @@ bogusimode:
err_out: err_out:
DBG_BUGON(1); DBG_BUGON(1);
kfree(copied); kfree(copied);
unlock_page(page); erofs_put_metabuf(buf);
put_page(page);
return ERR_PTR(err); return ERR_PTR(err);
} }
static int erofs_fill_symlink(struct inode *inode, void *data, static int erofs_fill_symlink(struct inode *inode, void *kaddr,
unsigned int m_pofs) unsigned int m_pofs)
{ {
struct erofs_inode *vi = EROFS_I(inode); struct erofs_inode *vi = EROFS_I(inode);
@ -222,7 +219,7 @@ static int erofs_fill_symlink(struct inode *inode, void *data,
/* if it cannot be handled with fast symlink scheme */ /* if it cannot be handled with fast symlink scheme */
if (vi->datalayout != EROFS_INODE_FLAT_INLINE || if (vi->datalayout != EROFS_INODE_FLAT_INLINE ||
inode->i_size >= PAGE_SIZE) { inode->i_size >= EROFS_BLKSIZ) {
inode->i_op = &erofs_symlink_iops; inode->i_op = &erofs_symlink_iops;
return 0; return 0;
} }
@ -232,8 +229,8 @@ static int erofs_fill_symlink(struct inode *inode, void *data,
return -ENOMEM; return -ENOMEM;
m_pofs += vi->xattr_isize; m_pofs += vi->xattr_isize;
/* inline symlink data shouldn't cross page boundary as well */ /* inline symlink data shouldn't cross block boundary */
if (m_pofs + inode->i_size > PAGE_SIZE) { if (m_pofs + inode->i_size > EROFS_BLKSIZ) {
kfree(lnk); kfree(lnk);
erofs_err(inode->i_sb, erofs_err(inode->i_sb,
"inline data cross block boundary @ nid %llu", "inline data cross block boundary @ nid %llu",
@ -241,8 +238,7 @@ static int erofs_fill_symlink(struct inode *inode, void *data,
DBG_BUGON(1); DBG_BUGON(1);
return -EFSCORRUPTED; return -EFSCORRUPTED;
} }
memcpy(lnk, kaddr + m_pofs, inode->i_size);
memcpy(lnk, data + m_pofs, inode->i_size);
lnk[inode->i_size] = '\0'; lnk[inode->i_size] = '\0';
inode->i_link = lnk; inode->i_link = lnk;
@ -253,16 +249,17 @@ static int erofs_fill_symlink(struct inode *inode, void *data,
static int erofs_fill_inode(struct inode *inode, int isdir) static int erofs_fill_inode(struct inode *inode, int isdir)
{ {
struct erofs_inode *vi = EROFS_I(inode); struct erofs_inode *vi = EROFS_I(inode);
struct page *page; struct erofs_buf buf = __EROFS_BUF_INITIALIZER;
void *kaddr;
unsigned int ofs; unsigned int ofs;
int err = 0; int err = 0;
trace_erofs_fill_inode(inode, isdir); trace_erofs_fill_inode(inode, isdir);
/* read inode base data from disk */ /* read inode base data from disk */
page = erofs_read_inode(inode, &ofs); kaddr = erofs_read_inode(&buf, inode, &ofs);
if (IS_ERR(page)) if (IS_ERR(kaddr))
return PTR_ERR(page); return PTR_ERR(kaddr);
/* setup the new inode */ /* setup the new inode */
switch (inode->i_mode & S_IFMT) { switch (inode->i_mode & S_IFMT) {
@ -278,7 +275,7 @@ static int erofs_fill_inode(struct inode *inode, int isdir)
inode->i_fop = &erofs_dir_fops; inode->i_fop = &erofs_dir_fops;
break; break;
case S_IFLNK: case S_IFLNK:
err = erofs_fill_symlink(inode, page_address(page), ofs); err = erofs_fill_symlink(inode, kaddr, ofs);
if (err) if (err)
goto out_unlock; goto out_unlock;
inode_nohighmem(inode); inode_nohighmem(inode);
@ -302,8 +299,7 @@ static int erofs_fill_inode(struct inode *inode, int isdir)
inode->i_mapping->a_ops = &erofs_raw_access_aops; inode->i_mapping->a_ops = &erofs_raw_access_aops;
out_unlock: out_unlock:
unlock_page(page); erofs_put_metabuf(&buf);
put_page(page);
return err; return err;
} }

Просмотреть файл

@ -475,6 +475,9 @@ struct erofs_map_dev {
/* data.c */ /* data.c */
extern const struct file_operations erofs_file_fops; extern const struct file_operations erofs_file_fops;
struct page *erofs_get_meta_page(struct super_block *sb, erofs_blk_t blkaddr); struct page *erofs_get_meta_page(struct super_block *sb, erofs_blk_t blkaddr);
void erofs_put_metabuf(struct erofs_buf *buf);
void *erofs_read_metabuf(struct erofs_buf *buf, struct super_block *sb,
erofs_blk_t blkaddr, enum erofs_kmap_type type);
int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *dev); int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *dev);
int erofs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, int erofs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
u64 start, u64 len); u64 start, u64 len);