diff options
| author | Chao Yu <yuchao0@huawei.com> | 2017-04-05 18:26:26 +0800 |
|---|---|---|
| committer | Moyster <oysterized@gmail.com> | 2017-05-21 18:40:23 +0200 |
| commit | aff30ee33ced32408a989a0b845c322a1bef8889 (patch) | |
| tree | 7b268b33d2ae69f2496a697ef86d16c1db7b3a27 /fs | |
| parent | 76da35a30b148c093ce3ef72b9ebbe90118cb3b5 (diff) | |
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: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Conflicts:
fs/f2fs/segment.c
Diffstat (limited to 'fs')
| -rw-r--r-- | fs/f2fs/segment.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index d59aadf50..f201cbaa1 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -776,9 +776,9 @@ static void f2fs_submit_discard_endio(struct bio *bio, int err) { struct discard_cmd *dc = (struct discard_cmd *)bio->bi_private; - complete(&dc->wait); dc->error = err; dc->state = D_DONE; + complete(&dc->wait); bio_put(bio); } @@ -945,8 +945,7 @@ void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr) list_for_each_entry_safe(dc, tmp, wait_list, list) { 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); } } @@ -1006,8 +1005,10 @@ repeat: } 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); + } } mutex_unlock(&dcc->cmd_lock); |
