Commit 01f9cf6d authored by Chao Yu's avatar Chao Yu Committed by Jaegeuk Kim

f2fs: fix to correct return value of f2fs_trim_fs

We should account trimmed block number from __wait_all_discard_cmd
in __issue_discard_cmd_range, otherwise trimmed blocks returned
by f2fs_trim_fs will be wrong, this patch fixes it.
Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent c77ec61c
...@@ -1320,21 +1320,22 @@ static unsigned int __wait_discard_cmd_range(struct f2fs_sb_info *sbi, ...@@ -1320,21 +1320,22 @@ static unsigned int __wait_discard_cmd_range(struct f2fs_sb_info *sbi,
return trimmed; return trimmed;
} }
static void __wait_all_discard_cmd(struct f2fs_sb_info *sbi, static unsigned int __wait_all_discard_cmd(struct f2fs_sb_info *sbi,
struct discard_policy *dpolicy) struct discard_policy *dpolicy)
{ {
struct discard_policy dp; struct discard_policy dp;
unsigned int discard_blks;
if (dpolicy) { if (dpolicy)
__wait_discard_cmd_range(sbi, dpolicy, 0, UINT_MAX); return __wait_discard_cmd_range(sbi, dpolicy, 0, UINT_MAX);
return;
}
/* wait all */ /* wait all */
__init_discard_policy(sbi, &dp, DPOLICY_FSTRIM, 1); __init_discard_policy(sbi, &dp, DPOLICY_FSTRIM, 1);
__wait_discard_cmd_range(sbi, &dp, 0, UINT_MAX); discard_blks = __wait_discard_cmd_range(sbi, &dp, 0, UINT_MAX);
__init_discard_policy(sbi, &dp, DPOLICY_UMOUNT, 1); __init_discard_policy(sbi, &dp, DPOLICY_UMOUNT, 1);
__wait_discard_cmd_range(sbi, &dp, 0, UINT_MAX); discard_blks += __wait_discard_cmd_range(sbi, &dp, 0, UINT_MAX);
return discard_blks;
} }
/* This should be covered by global mutex, &sit_i->sentry_lock */ /* This should be covered by global mutex, &sit_i->sentry_lock */
...@@ -2368,7 +2369,7 @@ bool f2fs_exist_trim_candidates(struct f2fs_sb_info *sbi, ...@@ -2368,7 +2369,7 @@ bool f2fs_exist_trim_candidates(struct f2fs_sb_info *sbi,
return has_candidate; return has_candidate;
} }
static void __issue_discard_cmd_range(struct f2fs_sb_info *sbi, static unsigned int __issue_discard_cmd_range(struct f2fs_sb_info *sbi,
struct discard_policy *dpolicy, struct discard_policy *dpolicy,
unsigned int start, unsigned int end) unsigned int start, unsigned int end)
{ {
...@@ -2378,6 +2379,7 @@ static void __issue_discard_cmd_range(struct f2fs_sb_info *sbi, ...@@ -2378,6 +2379,7 @@ static void __issue_discard_cmd_range(struct f2fs_sb_info *sbi,
struct discard_cmd *dc; struct discard_cmd *dc;
struct blk_plug plug; struct blk_plug plug;
int issued; int issued;
unsigned int trimmed = 0;
next: next:
issued = 0; issued = 0;
...@@ -2415,7 +2417,7 @@ static void __issue_discard_cmd_range(struct f2fs_sb_info *sbi, ...@@ -2415,7 +2417,7 @@ static void __issue_discard_cmd_range(struct f2fs_sb_info *sbi,
blk_finish_plug(&plug); blk_finish_plug(&plug);
mutex_unlock(&dcc->cmd_lock); mutex_unlock(&dcc->cmd_lock);
__wait_all_discard_cmd(sbi, NULL); trimmed += __wait_all_discard_cmd(sbi, NULL);
congestion_wait(BLK_RW_ASYNC, HZ/50); congestion_wait(BLK_RW_ASYNC, HZ/50);
goto next; goto next;
} }
...@@ -2429,6 +2431,8 @@ static void __issue_discard_cmd_range(struct f2fs_sb_info *sbi, ...@@ -2429,6 +2431,8 @@ static void __issue_discard_cmd_range(struct f2fs_sb_info *sbi,
blk_finish_plug(&plug); blk_finish_plug(&plug);
mutex_unlock(&dcc->cmd_lock); mutex_unlock(&dcc->cmd_lock);
return trimmed;
} }
int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range) int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range)
...@@ -2486,9 +2490,10 @@ int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range) ...@@ -2486,9 +2490,10 @@ int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range)
end_block = START_BLOCK(sbi, end_segno + 1); end_block = START_BLOCK(sbi, end_segno + 1);
__init_discard_policy(sbi, &dpolicy, DPOLICY_FSTRIM, cpc.trim_minlen); __init_discard_policy(sbi, &dpolicy, DPOLICY_FSTRIM, cpc.trim_minlen);
__issue_discard_cmd_range(sbi, &dpolicy, start_block, end_block); trimmed = __issue_discard_cmd_range(sbi, &dpolicy,
start_block, end_block);
trimmed = __wait_discard_cmd_range(sbi, &dpolicy, trimmed += __wait_discard_cmd_range(sbi, &dpolicy,
start_block, end_block); start_block, end_block);
range->len = F2FS_BLK_TO_BYTES(trimmed); range->len = F2FS_BLK_TO_BYTES(trimmed);
out: out:
......
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