bdi: avoid oops on device removal
authorJan Kara <jack@suse.cz>
Thu, 3 Apr 2014 21:46:23 +0000 (14:46 -0700)
committer黄涛 <huangtao@rock-chips.com>
Thu, 22 May 2014 13:11:01 +0000 (21:11 +0800)
commitf51667e9c759dba07cd970830d4b83be9e5c4d04
tree8baf81745fdaf82dc5fa65dd8563fd9dfa135c57
parenta66396333f93ac7be706094e39e304f5be3995c5
bdi: avoid oops on device removal

commit 5acda9d12dcf1ad0d9a5a2a7c646de3472fa7555 upstream.

After commit 839a8e8660b6 ("writeback: replace custom worker pool
implementation with unbound workqueue") when device is removed while we
are writing to it we crash in bdi_writeback_workfn() ->
set_worker_desc() because bdi->dev is NULL.

This can happen because even though bdi_unregister() cancels all pending
flushing work, nothing really prevents new ones from being queued from
balance_dirty_pages() or other places.

Fix the problem by clearing BDI_registered bit in bdi_unregister() and
checking it before scheduling of any flushing work.

Fixes: 839a8e8660b6777e7fe4e80af1a048aebe2b5977
Reviewed-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jan Kara <jack@suse.cz>
Cc: Derek Basehore <dbasehore@chromium.org>
Cc: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit bf0972039ddc483a9cb79edae73076c635876568)
fs/fs-writeback.c
include/linux/backing-dev.h
mm/backing-dev.c