mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-11 12:28:41 +08:00
f2fs: add a f2fs_lookup_extent_cache_block helper
All but three callers of f2fs_lookup_extent_cache just want the block address. Add a small helper to simplify them. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
parent
bc29835a9d
commit
04a91ab016
@ -1214,14 +1214,9 @@ int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index)
|
|||||||
|
|
||||||
int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index)
|
int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index)
|
||||||
{
|
{
|
||||||
struct extent_info ei = {0, };
|
if (f2fs_lookup_read_extent_cache_block(dn->inode, index,
|
||||||
struct inode *inode = dn->inode;
|
&dn->data_blkaddr))
|
||||||
|
|
||||||
if (f2fs_lookup_read_extent_cache(inode, index, &ei)) {
|
|
||||||
dn->data_blkaddr = ei.blk + index - ei.fofs;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
return f2fs_reserve_block(dn, index);
|
return f2fs_reserve_block(dn, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1232,15 +1227,14 @@ struct page *f2fs_get_read_data_page(struct inode *inode, pgoff_t index,
|
|||||||
struct address_space *mapping = inode->i_mapping;
|
struct address_space *mapping = inode->i_mapping;
|
||||||
struct dnode_of_data dn;
|
struct dnode_of_data dn;
|
||||||
struct page *page;
|
struct page *page;
|
||||||
struct extent_info ei = {0, };
|
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
page = f2fs_grab_cache_page(mapping, index, for_write);
|
page = f2fs_grab_cache_page(mapping, index, for_write);
|
||||||
if (!page)
|
if (!page)
|
||||||
return ERR_PTR(-ENOMEM);
|
return ERR_PTR(-ENOMEM);
|
||||||
|
|
||||||
if (f2fs_lookup_read_extent_cache(inode, index, &ei)) {
|
if (f2fs_lookup_read_extent_cache_block(inode, index,
|
||||||
dn.data_blkaddr = ei.blk + index - ei.fofs;
|
&dn.data_blkaddr)) {
|
||||||
if (!f2fs_is_valid_blkaddr(F2FS_I_SB(inode), dn.data_blkaddr,
|
if (!f2fs_is_valid_blkaddr(F2FS_I_SB(inode), dn.data_blkaddr,
|
||||||
DATA_GENERIC_ENHANCE_READ)) {
|
DATA_GENERIC_ENHANCE_READ)) {
|
||||||
err = -EFSCORRUPTED;
|
err = -EFSCORRUPTED;
|
||||||
@ -2641,7 +2635,6 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
|
|||||||
struct page *page = fio->page;
|
struct page *page = fio->page;
|
||||||
struct inode *inode = page->mapping->host;
|
struct inode *inode = page->mapping->host;
|
||||||
struct dnode_of_data dn;
|
struct dnode_of_data dn;
|
||||||
struct extent_info ei = {0, };
|
|
||||||
struct node_info ni;
|
struct node_info ni;
|
||||||
bool ipu_force = false;
|
bool ipu_force = false;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
@ -2653,9 +2646,8 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
|
|||||||
set_new_dnode(&dn, inode, NULL, NULL, 0);
|
set_new_dnode(&dn, inode, NULL, NULL, 0);
|
||||||
|
|
||||||
if (need_inplace_update(fio) &&
|
if (need_inplace_update(fio) &&
|
||||||
f2fs_lookup_read_extent_cache(inode, page->index, &ei)) {
|
f2fs_lookup_read_extent_cache_block(inode, page->index,
|
||||||
fio->old_blkaddr = ei.blk + page->index - ei.fofs;
|
&fio->old_blkaddr)) {
|
||||||
|
|
||||||
if (!f2fs_is_valid_blkaddr(fio->sbi, fio->old_blkaddr,
|
if (!f2fs_is_valid_blkaddr(fio->sbi, fio->old_blkaddr,
|
||||||
DATA_GENERIC_ENHANCE)) {
|
DATA_GENERIC_ENHANCE)) {
|
||||||
f2fs_handle_error(fio->sbi,
|
f2fs_handle_error(fio->sbi,
|
||||||
@ -3328,7 +3320,6 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi,
|
|||||||
struct dnode_of_data dn;
|
struct dnode_of_data dn;
|
||||||
struct page *ipage;
|
struct page *ipage;
|
||||||
bool locked = false;
|
bool locked = false;
|
||||||
struct extent_info ei = {0, };
|
|
||||||
int err = 0;
|
int err = 0;
|
||||||
int flag;
|
int flag;
|
||||||
|
|
||||||
@ -3376,20 +3367,16 @@ restart:
|
|||||||
}
|
}
|
||||||
} else if (locked) {
|
} else if (locked) {
|
||||||
err = f2fs_get_block(&dn, index);
|
err = f2fs_get_block(&dn, index);
|
||||||
} else {
|
} else if (!f2fs_lookup_read_extent_cache_block(inode, index,
|
||||||
if (f2fs_lookup_read_extent_cache(inode, index, &ei)) {
|
&dn.data_blkaddr)) {
|
||||||
dn.data_blkaddr = ei.blk + index - ei.fofs;
|
/* hole case */
|
||||||
} else {
|
err = f2fs_get_dnode_of_data(&dn, index, LOOKUP_NODE);
|
||||||
/* hole case */
|
if (err || dn.data_blkaddr == NULL_ADDR) {
|
||||||
err = f2fs_get_dnode_of_data(&dn, index, LOOKUP_NODE);
|
f2fs_put_dnode(&dn);
|
||||||
if (err || dn.data_blkaddr == NULL_ADDR) {
|
f2fs_do_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO, true);
|
||||||
f2fs_put_dnode(&dn);
|
WARN_ON(flag != F2FS_GET_BLOCK_PRE_AIO);
|
||||||
f2fs_do_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO,
|
locked = true;
|
||||||
true);
|
goto restart;
|
||||||
WARN_ON(flag != F2FS_GET_BLOCK_PRE_AIO);
|
|
||||||
locked = true;
|
|
||||||
goto restart;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3409,7 +3396,6 @@ static int __find_data_block(struct inode *inode, pgoff_t index,
|
|||||||
{
|
{
|
||||||
struct dnode_of_data dn;
|
struct dnode_of_data dn;
|
||||||
struct page *ipage;
|
struct page *ipage;
|
||||||
struct extent_info ei = {0, };
|
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
ipage = f2fs_get_node_page(F2FS_I_SB(inode), inode->i_ino);
|
ipage = f2fs_get_node_page(F2FS_I_SB(inode), inode->i_ino);
|
||||||
@ -3418,9 +3404,8 @@ static int __find_data_block(struct inode *inode, pgoff_t index,
|
|||||||
|
|
||||||
set_new_dnode(&dn, inode, ipage, ipage, 0);
|
set_new_dnode(&dn, inode, ipage, ipage, 0);
|
||||||
|
|
||||||
if (f2fs_lookup_read_extent_cache(inode, index, &ei)) {
|
if (!f2fs_lookup_read_extent_cache_block(inode, index,
|
||||||
dn.data_blkaddr = ei.blk + index - ei.fofs;
|
&dn.data_blkaddr)) {
|
||||||
} else {
|
|
||||||
/* hole case */
|
/* hole case */
|
||||||
err = f2fs_get_dnode_of_data(&dn, index, LOOKUP_NODE);
|
err = f2fs_get_dnode_of_data(&dn, index, LOOKUP_NODE);
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -1047,6 +1047,17 @@ bool f2fs_lookup_read_extent_cache(struct inode *inode, pgoff_t pgofs,
|
|||||||
return __lookup_extent_tree(inode, pgofs, ei, EX_READ);
|
return __lookup_extent_tree(inode, pgofs, ei, EX_READ);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool f2fs_lookup_read_extent_cache_block(struct inode *inode, pgoff_t index,
|
||||||
|
block_t *blkaddr)
|
||||||
|
{
|
||||||
|
struct extent_info ei = {};
|
||||||
|
|
||||||
|
if (!f2fs_lookup_read_extent_cache(inode, index, &ei))
|
||||||
|
return false;
|
||||||
|
*blkaddr = ei.blk + index - ei.fofs;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void f2fs_update_read_extent_cache(struct dnode_of_data *dn)
|
void f2fs_update_read_extent_cache(struct dnode_of_data *dn)
|
||||||
{
|
{
|
||||||
return __update_extent_cache(dn, EX_READ);
|
return __update_extent_cache(dn, EX_READ);
|
||||||
|
@ -4182,6 +4182,8 @@ void f2fs_destroy_extent_cache(void);
|
|||||||
void f2fs_init_read_extent_tree(struct inode *inode, struct page *ipage);
|
void f2fs_init_read_extent_tree(struct inode *inode, struct page *ipage);
|
||||||
bool f2fs_lookup_read_extent_cache(struct inode *inode, pgoff_t pgofs,
|
bool f2fs_lookup_read_extent_cache(struct inode *inode, pgoff_t pgofs,
|
||||||
struct extent_info *ei);
|
struct extent_info *ei);
|
||||||
|
bool f2fs_lookup_read_extent_cache_block(struct inode *inode, pgoff_t index,
|
||||||
|
block_t *blkaddr);
|
||||||
void f2fs_update_read_extent_cache(struct dnode_of_data *dn);
|
void f2fs_update_read_extent_cache(struct dnode_of_data *dn);
|
||||||
void f2fs_update_read_extent_cache_range(struct dnode_of_data *dn,
|
void f2fs_update_read_extent_cache_range(struct dnode_of_data *dn,
|
||||||
pgoff_t fofs, block_t blkaddr, unsigned int len);
|
pgoff_t fofs, block_t blkaddr, unsigned int len);
|
||||||
|
@ -1150,7 +1150,6 @@ static int ra_data_block(struct inode *inode, pgoff_t index)
|
|||||||
struct address_space *mapping = inode->i_mapping;
|
struct address_space *mapping = inode->i_mapping;
|
||||||
struct dnode_of_data dn;
|
struct dnode_of_data dn;
|
||||||
struct page *page;
|
struct page *page;
|
||||||
struct extent_info ei = {0, };
|
|
||||||
struct f2fs_io_info fio = {
|
struct f2fs_io_info fio = {
|
||||||
.sbi = sbi,
|
.sbi = sbi,
|
||||||
.ino = inode->i_ino,
|
.ino = inode->i_ino,
|
||||||
@ -1168,8 +1167,8 @@ static int ra_data_block(struct inode *inode, pgoff_t index)
|
|||||||
if (!page)
|
if (!page)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
if (f2fs_lookup_read_extent_cache(inode, index, &ei)) {
|
if (f2fs_lookup_read_extent_cache_block(inode, index,
|
||||||
dn.data_blkaddr = ei.blk + index - ei.fofs;
|
&dn.data_blkaddr)) {
|
||||||
if (unlikely(!f2fs_is_valid_blkaddr(sbi, dn.data_blkaddr,
|
if (unlikely(!f2fs_is_valid_blkaddr(sbi, dn.data_blkaddr,
|
||||||
DATA_GENERIC_ENHANCE_READ))) {
|
DATA_GENERIC_ENHANCE_READ))) {
|
||||||
err = -EFSCORRUPTED;
|
err = -EFSCORRUPTED;
|
||||||
|
Loading…
Reference in New Issue
Block a user