提交 2163d198 编写于 作者: G Gu Zheng 提交者: Jaegeuk Kim

f2fs: introduce help function {create,destroy}_flush_cmd_control

Introduce help function {create,destroy}_flush_cmd_control to clean up
the create/destory flush merge operation.
Signed-off-by: NGu Zheng <guz.fnst@cn.fujitsu.com>
Signed-off-by: NJaegeuk Kim <jaegeuk.kim@samsung.com>
上级 a688b9d9
...@@ -1184,8 +1184,9 @@ void destroy_node_manager_caches(void); ...@@ -1184,8 +1184,9 @@ void destroy_node_manager_caches(void);
*/ */
void f2fs_balance_fs(struct f2fs_sb_info *); void f2fs_balance_fs(struct f2fs_sb_info *);
void f2fs_balance_fs_bg(struct f2fs_sb_info *); void f2fs_balance_fs_bg(struct f2fs_sb_info *);
int issue_flush_thread(void *);
int f2fs_issue_flush(struct f2fs_sb_info *); int f2fs_issue_flush(struct f2fs_sb_info *);
int create_flush_cmd_control(struct f2fs_sb_info *);
void destroy_flush_cmd_control(struct f2fs_sb_info *);
void invalidate_blocks(struct f2fs_sb_info *, block_t); void invalidate_blocks(struct f2fs_sb_info *, block_t);
void refresh_sit_entry(struct f2fs_sb_info *, block_t, block_t); void refresh_sit_entry(struct f2fs_sb_info *, block_t, block_t);
void clear_prefree_segments(struct f2fs_sb_info *); void clear_prefree_segments(struct f2fs_sb_info *);
......
...@@ -197,7 +197,7 @@ void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi) ...@@ -197,7 +197,7 @@ void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi)
f2fs_sync_fs(sbi->sb, true); f2fs_sync_fs(sbi->sb, true);
} }
int issue_flush_thread(void *data) static int issue_flush_thread(void *data)
{ {
struct f2fs_sb_info *sbi = data; struct f2fs_sb_info *sbi = data;
struct flush_cmd_control *fcc = SM_I(sbi)->cmd_control_info; struct flush_cmd_control *fcc = SM_I(sbi)->cmd_control_info;
...@@ -264,6 +264,40 @@ int f2fs_issue_flush(struct f2fs_sb_info *sbi) ...@@ -264,6 +264,40 @@ int f2fs_issue_flush(struct f2fs_sb_info *sbi)
return ret; return ret;
} }
int create_flush_cmd_control(struct f2fs_sb_info *sbi)
{
dev_t dev = sbi->sb->s_bdev->bd_dev;
struct flush_cmd_control *fcc;
int err = 0;
fcc = kzalloc(sizeof(struct flush_cmd_control), GFP_KERNEL);
if (!fcc)
return -ENOMEM;
spin_lock_init(&fcc->issue_lock);
init_waitqueue_head(&fcc->flush_wait_queue);
fcc->f2fs_issue_flush = kthread_run(issue_flush_thread, sbi,
"f2fs_flush-%u:%u", MAJOR(dev), MINOR(dev));
if (IS_ERR(fcc->f2fs_issue_flush)) {
err = PTR_ERR(fcc->f2fs_issue_flush);
kfree(fcc);
return err;
}
sbi->sm_info->cmd_control_info = fcc;
return err;
}
void destroy_flush_cmd_control(struct f2fs_sb_info *sbi)
{
struct flush_cmd_control *fcc =
sbi->sm_info->cmd_control_info;
if (fcc && fcc->f2fs_issue_flush)
kthread_stop(fcc->f2fs_issue_flush);
kfree(fcc);
sbi->sm_info->cmd_control_info = NULL;
}
static void __locate_dirty_segment(struct f2fs_sb_info *sbi, unsigned int segno, static void __locate_dirty_segment(struct f2fs_sb_info *sbi, unsigned int segno,
enum dirty_type dirty_type) enum dirty_type dirty_type)
{ {
...@@ -1845,7 +1879,6 @@ int build_segment_manager(struct f2fs_sb_info *sbi) ...@@ -1845,7 +1879,6 @@ int build_segment_manager(struct f2fs_sb_info *sbi)
{ {
struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
dev_t dev = sbi->sb->s_bdev->bd_dev;
struct f2fs_sm_info *sm_info; struct f2fs_sm_info *sm_info;
int err; int err;
...@@ -1874,22 +1907,9 @@ int build_segment_manager(struct f2fs_sb_info *sbi) ...@@ -1874,22 +1907,9 @@ int build_segment_manager(struct f2fs_sb_info *sbi)
sm_info->max_discards = 0; sm_info->max_discards = 0;
if (test_opt(sbi, FLUSH_MERGE) && !f2fs_readonly(sbi->sb)) { if (test_opt(sbi, FLUSH_MERGE) && !f2fs_readonly(sbi->sb)) {
struct flush_cmd_control *fcc = err = create_flush_cmd_control(sbi);
kzalloc(sizeof(struct flush_cmd_control), GFP_KERNEL); if (err)
if (!fcc)
return -ENOMEM;
spin_lock_init(&fcc->issue_lock);
init_waitqueue_head(&fcc->flush_wait_queue);
fcc->f2fs_issue_flush = kthread_run(issue_flush_thread, sbi,
"f2fs_flush-%u:%u", MAJOR(dev), MINOR(dev));
if (IS_ERR(fcc->f2fs_issue_flush)) {
err = PTR_ERR(fcc->f2fs_issue_flush);
kfree(fcc);
return err; return err;
}
sm_info->cmd_control_info = fcc;
} }
err = build_sit_info(sbi); err = build_sit_info(sbi);
...@@ -1998,14 +2018,10 @@ static void destroy_sit_info(struct f2fs_sb_info *sbi) ...@@ -1998,14 +2018,10 @@ static void destroy_sit_info(struct f2fs_sb_info *sbi)
void destroy_segment_manager(struct f2fs_sb_info *sbi) void destroy_segment_manager(struct f2fs_sb_info *sbi)
{ {
struct f2fs_sm_info *sm_info = SM_I(sbi); struct f2fs_sm_info *sm_info = SM_I(sbi);
struct flush_cmd_control *fcc;
if (!sm_info) if (!sm_info)
return; return;
fcc = sm_info->cmd_control_info; destroy_flush_cmd_control(sbi);
if (fcc && fcc->f2fs_issue_flush)
kthread_stop(fcc->f2fs_issue_flush);
kfree(fcc);
destroy_dirty_segmap(sbi); destroy_dirty_segmap(sbi);
destroy_curseg(sbi); destroy_curseg(sbi);
destroy_free_segmap(sbi); destroy_free_segmap(sbi);
......
...@@ -641,33 +641,12 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data) ...@@ -641,33 +641,12 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
* or if flush_merge is not passed in mount option. * or if flush_merge is not passed in mount option.
*/ */
if ((*flags & MS_RDONLY) || !test_opt(sbi, FLUSH_MERGE)) { if ((*flags & MS_RDONLY) || !test_opt(sbi, FLUSH_MERGE)) {
struct flush_cmd_control *fcc = destroy_flush_cmd_control(sbi);
sbi->sm_info->cmd_control_info;
if (fcc && fcc->f2fs_issue_flush)
kthread_stop(fcc->f2fs_issue_flush);
kfree(fcc);
sbi->sm_info->cmd_control_info = NULL;
} else if (test_opt(sbi, FLUSH_MERGE) && } else if (test_opt(sbi, FLUSH_MERGE) &&
!sbi->sm_info->cmd_control_info) { !sbi->sm_info->cmd_control_info) {
dev_t dev = sbi->sb->s_bdev->bd_dev; err = create_flush_cmd_control(sbi);
struct flush_cmd_control *fcc = if (err)
kzalloc(sizeof(struct flush_cmd_control), GFP_KERNEL);
if (!fcc) {
err = -ENOMEM;
goto restore_gc;
}
spin_lock_init(&fcc->issue_lock);
init_waitqueue_head(&fcc->flush_wait_queue);
fcc->f2fs_issue_flush = kthread_run(issue_flush_thread, sbi,
"f2fs_flush-%u:%u", MAJOR(dev), MINOR(dev));
if (IS_ERR(fcc->f2fs_issue_flush)) {
err = PTR_ERR(fcc->f2fs_issue_flush);
kfree(fcc);
goto restore_gc; goto restore_gc;
}
sbi->sm_info->cmd_control_info = fcc;
} }
skip: skip:
/* Update the POSIXACL Flag */ /* Update the POSIXACL Flag */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册