Commit 2f51ade9 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jaegeuk Kim

f2fs: f2fs_do_map_lock

Split f2fs_do_map_lock into a lock and unlock helper to make the code
using it easier to read.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarChao Yu <chao@kernel.org>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent cf342d3b
...@@ -1451,19 +1451,20 @@ static int __allocate_data_block(struct dnode_of_data *dn, int seg_type) ...@@ -1451,19 +1451,20 @@ static int __allocate_data_block(struct dnode_of_data *dn, int seg_type)
return 0; return 0;
} }
static void f2fs_do_map_lock(struct f2fs_sb_info *sbi, int flag, bool lock) static void f2fs_map_lock(struct f2fs_sb_info *sbi, int flag)
{ {
if (flag == F2FS_GET_BLOCK_PRE_AIO) { if (flag == F2FS_GET_BLOCK_PRE_AIO)
if (lock) f2fs_down_read(&sbi->node_change);
f2fs_down_read(&sbi->node_change); else
else f2fs_lock_op(sbi);
f2fs_up_read(&sbi->node_change); }
} else {
if (lock) static void f2fs_map_unlock(struct f2fs_sb_info *sbi, int flag)
f2fs_lock_op(sbi); {
else if (flag == F2FS_GET_BLOCK_PRE_AIO)
f2fs_unlock_op(sbi); f2fs_up_read(&sbi->node_change);
} else
f2fs_unlock_op(sbi);
} }
int f2fs_get_block_locked(struct dnode_of_data *dn, pgoff_t index) int f2fs_get_block_locked(struct dnode_of_data *dn, pgoff_t index)
...@@ -1471,9 +1472,9 @@ int f2fs_get_block_locked(struct dnode_of_data *dn, pgoff_t index) ...@@ -1471,9 +1472,9 @@ int f2fs_get_block_locked(struct dnode_of_data *dn, pgoff_t index)
struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode); struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode);
int err; int err;
f2fs_do_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO, true); f2fs_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO);
err = f2fs_get_block(dn, index); err = f2fs_get_block(dn, index);
f2fs_do_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO, false); f2fs_map_unlock(sbi, F2FS_GET_BLOCK_PRE_AIO);
return err; return err;
} }
...@@ -1548,7 +1549,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, ...@@ -1548,7 +1549,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
next_dnode: next_dnode:
if (map->m_may_create) if (map->m_may_create)
f2fs_do_map_lock(sbi, flag, true); f2fs_map_lock(sbi, flag);
/* When reading holes, we need its node page */ /* When reading holes, we need its node page */
set_new_dnode(&dn, inode, NULL, NULL, 0); set_new_dnode(&dn, inode, NULL, NULL, 0);
...@@ -1732,7 +1733,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, ...@@ -1732,7 +1733,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
f2fs_put_dnode(&dn); f2fs_put_dnode(&dn);
if (map->m_may_create) { if (map->m_may_create) {
f2fs_do_map_lock(sbi, flag, false); f2fs_map_unlock(sbi, flag);
f2fs_balance_fs(sbi, dn.node_changed); f2fs_balance_fs(sbi, dn.node_changed);
} }
goto next_dnode; goto next_dnode;
...@@ -1778,7 +1779,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, ...@@ -1778,7 +1779,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
f2fs_put_dnode(&dn); f2fs_put_dnode(&dn);
unlock_out: unlock_out:
if (map->m_may_create) { if (map->m_may_create) {
f2fs_do_map_lock(sbi, flag, false); f2fs_map_unlock(sbi, flag);
f2fs_balance_fs(sbi, dn.node_changed); f2fs_balance_fs(sbi, dn.node_changed);
} }
out: out:
...@@ -3350,7 +3351,7 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi, ...@@ -3350,7 +3351,7 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi,
if (f2fs_has_inline_data(inode) || if (f2fs_has_inline_data(inode) ||
(pos & PAGE_MASK) >= i_size_read(inode)) { (pos & PAGE_MASK) >= i_size_read(inode)) {
f2fs_do_map_lock(sbi, flag, true); f2fs_map_lock(sbi, flag);
locked = true; locked = true;
} }
...@@ -3385,7 +3386,7 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi, ...@@ -3385,7 +3386,7 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi,
err = f2fs_get_dnode_of_data(&dn, index, LOOKUP_NODE); err = f2fs_get_dnode_of_data(&dn, index, LOOKUP_NODE);
if (err || dn.data_blkaddr == NULL_ADDR) { if (err || dn.data_blkaddr == NULL_ADDR) {
f2fs_put_dnode(&dn); f2fs_put_dnode(&dn);
f2fs_do_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO, true); f2fs_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO);
WARN_ON(flag != F2FS_GET_BLOCK_PRE_AIO); WARN_ON(flag != F2FS_GET_BLOCK_PRE_AIO);
locked = true; locked = true;
goto restart; goto restart;
...@@ -3399,7 +3400,7 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi, ...@@ -3399,7 +3400,7 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi,
f2fs_put_dnode(&dn); f2fs_put_dnode(&dn);
unlock_out: unlock_out:
if (locked) if (locked)
f2fs_do_map_lock(sbi, flag, false); f2fs_map_unlock(sbi, flag);
return err; return err;
} }
...@@ -3438,7 +3439,7 @@ static int __reserve_data_block(struct inode *inode, pgoff_t index, ...@@ -3438,7 +3439,7 @@ static int __reserve_data_block(struct inode *inode, pgoff_t index,
struct page *ipage; struct page *ipage;
int err = 0; int err = 0;
f2fs_do_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO, true); f2fs_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO);
ipage = f2fs_get_node_page(sbi, inode->i_ino); ipage = f2fs_get_node_page(sbi, inode->i_ino);
if (IS_ERR(ipage)) { if (IS_ERR(ipage)) {
...@@ -3454,7 +3455,7 @@ static int __reserve_data_block(struct inode *inode, pgoff_t index, ...@@ -3454,7 +3455,7 @@ static int __reserve_data_block(struct inode *inode, pgoff_t index,
f2fs_put_dnode(&dn); f2fs_put_dnode(&dn);
unlock_out: unlock_out:
f2fs_do_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO, false); f2fs_map_unlock(sbi, F2FS_GET_BLOCK_PRE_AIO);
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment