block: Move bdi_unregister() to del_gendisk()
authorJan Kara <jack@suse.cz>
Wed, 8 Feb 2017 07:05:56 +0000 (08:05 +0100)
committerJens Axboe <axboe@fb.com>
Thu, 2 Mar 2017 23:08:35 +0000 (16:08 -0700)
commit31b3d522128843b20fc19b89e66a80d50daf44a7
tree844b4541dcc7edd35feac79dfda0c25312d51ade
parent8ed41e482b45ff5d74266626d0ae6c629b6b8882
block: Move bdi_unregister() to del_gendisk()

Commit 5273269310b2 "block: destroy bdi before blockdev is
unregistered." moved bdi unregistration (at that time through
bdi_destroy()) from blk_release_queue() to blk_cleanup_queue() because
it needs to happen before blk_unregister_region() call in del_gendisk()
for MD. SCSI though will free up the device number from sd_remove()
called through a maze of callbacks from device_del() in
__scsi_remove_device() before blk_cleanup_queue() and thus similar races
as described in 5273269310b2 can happen for SCSI as well as reported by
Omar [1].

Moving bdi_unregister() to del_gendisk() works for MD and fixes the
problem for SCSI since del_gendisk() gets called from sd_remove() before
freeing the device number.

This also makes device_add_disk() (calling bdi_register_owner()) more
symmetric with del_gendisk().

[1] http://marc.info/?l=linux-block&m=148554717109098&w=2

Tested-by: Lekshmi Pillai <lekshmicpillai@in.ibm.com>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jan Kara <jack@suse.cz>
Tested-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
block/blk-core.c
block/genhd.c