Commit fa64a003 authored by Chao Yu's avatar Chao Yu Committed by Jaegeuk Kim

f2fs: prevent waiter encountering incorrect discard states

In f2fs_submit_discard_endio, we will wake up waiter before setting
discard command states, so waiter may use incorrect states. Change
the order between complete() and states setting to fix this issue.
Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent d431413f
...@@ -717,9 +717,9 @@ static void f2fs_submit_discard_endio(struct bio *bio) ...@@ -717,9 +717,9 @@ static void f2fs_submit_discard_endio(struct bio *bio)
{ {
struct discard_cmd *dc = (struct discard_cmd *)bio->bi_private; struct discard_cmd *dc = (struct discard_cmd *)bio->bi_private;
complete(&dc->wait);
dc->error = bio->bi_error; dc->error = bio->bi_error;
dc->state = D_DONE; dc->state = D_DONE;
complete(&dc->wait);
bio_put(bio); bio_put(bio);
} }
...@@ -807,8 +807,7 @@ void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr) ...@@ -807,8 +807,7 @@ void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr)
list_for_each_entry_safe(dc, tmp, wait_list, list) { list_for_each_entry_safe(dc, tmp, wait_list, list) {
if (dc->lstart <= blkaddr && blkaddr < dc->lstart + dc->len) { if (dc->lstart <= blkaddr && blkaddr < dc->lstart + dc->len) {
if (dc->state == D_SUBMIT) wait_for_completion_io(&dc->wait);
wait_for_completion_io(&dc->wait);
__punch_discard_cmd(sbi, dc, blkaddr); __punch_discard_cmd(sbi, dc, blkaddr);
} }
} }
...@@ -868,8 +867,10 @@ static int issue_discard_thread(void *data) ...@@ -868,8 +867,10 @@ static int issue_discard_thread(void *data)
} }
list_for_each_entry_safe(dc, tmp, wait_list, list) { list_for_each_entry_safe(dc, tmp, wait_list, list) {
if (dc->state == D_DONE) if (dc->state == D_DONE) {
wait_for_completion_io(&dc->wait);
__remove_discard_cmd(sbi, dc); __remove_discard_cmd(sbi, dc);
}
} }
mutex_unlock(&dcc->cmd_lock); mutex_unlock(&dcc->cmd_lock);
......
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