diff options
author | NeilBrown <neilb@suse.de> | 2015-04-27 00:12:22 -0400 |
---|---|---|
committer | Jens Axboe <axboe@fb.com> | 2015-04-27 12:27:20 -0400 |
commit | 6cd18e711dd8075da9d78cfc1239f912ff28968a (patch) | |
tree | 4383aaa3187800278a5f0f50e3c4c33cec926952 | |
parent | 393a33970540ac6a2c894b0d6ef3f5d485860884 (diff) |
block: destroy bdi before blockdev is unregistered.
Because of the peculiar way that md devices are created (automatically
when the device node is opened), a new device can be created and
registered immediately after the
blk_unregister_region(disk_devt(disk), disk->minors);
call in del_gendisk().
Therefore it is important that all visible artifacts of the previous
device are removed before this call. In particular, the 'bdi'.
Since:
commit c4db59d31e39ea067c32163ac961e9c80198fd37
Author: Christoph Hellwig <hch@lst.de>
fs: don't reassign dirty inodes to default_backing_dev_info
moved the
device_unregister(bdi->dev);
call from bdi_unregister() to bdi_destroy() it has been quite easy to
lose a race and have a new (e.g.) "md127" be created after the
blk_unregister_region() call and before bdi_destroy() is ultimately
called by the final 'put_disk', which must come after del_gendisk().
The new device finds that the bdi name is already registered in sysfs
and complains
> [ 9627.630029] WARNING: CPU: 18 PID: 3330 at fs/sysfs/dir.c:31 sysfs_warn_dup+0x5a/0x70()
> [ 9627.630032] sysfs: cannot create duplicate filename '/devices/virtual/bdi/9:127'
We can fix this by moving the bdi_destroy() call out of
blk_release_queue() (which can happen very late when a refcount
reaches zero) and into blk_cleanup_queue() - which happens exactly when the md
device driver calls it.
Then it is only necessary for md to call blk_cleanup_queue() before
del_gendisk(). As loop.c devices are also created on demand by
opening the device node, we make the same change there.
Fixes: c4db59d31e39ea067c32163ac961e9c80198fd37
Reported-by: Azat Khuzhin <a3at.mail@gmail.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: stable@vger.kernel.org (v4.0)
Signed-off-by: NeilBrown <neilb@suse.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@fb.com>
-rw-r--r-- | block/blk-core.c | 2 | ||||
-rw-r--r-- | block/blk-sysfs.c | 2 | ||||
-rw-r--r-- | drivers/block/loop.c | 2 | ||||
-rw-r--r-- | drivers/md/md.c | 4 |
4 files changed, 5 insertions, 5 deletions
diff --git a/block/blk-core.c b/block/blk-core.c index fd154b94447a..7871603f0a29 100644 --- a/block/blk-core.c +++ b/block/blk-core.c | |||
@@ -552,6 +552,8 @@ void blk_cleanup_queue(struct request_queue *q) | |||
552 | q->queue_lock = &q->__queue_lock; | 552 | q->queue_lock = &q->__queue_lock; |
553 | spin_unlock_irq(lock); | 553 | spin_unlock_irq(lock); |
554 | 554 | ||
555 | bdi_destroy(&q->backing_dev_info); | ||
556 | |||
555 | /* @q is and will stay empty, shutdown and put */ | 557 | /* @q is and will stay empty, shutdown and put */ |
556 | blk_put_queue(q); | 558 | blk_put_queue(q); |
557 | } | 559 | } |
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index faaf36ade7eb..2b8fd302f677 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c | |||
@@ -522,8 +522,6 @@ static void blk_release_queue(struct kobject *kobj) | |||
522 | 522 | ||
523 | blk_trace_shutdown(q); | 523 | blk_trace_shutdown(q); |
524 | 524 | ||
525 | bdi_destroy(&q->backing_dev_info); | ||
526 | |||
527 | ida_simple_remove(&blk_queue_ida, q->id); | 525 | ida_simple_remove(&blk_queue_ida, q->id); |
528 | call_rcu(&q->rcu_head, blk_free_queue_rcu); | 526 | call_rcu(&q->rcu_head, blk_free_queue_rcu); |
529 | } | 527 | } |
diff --git a/drivers/block/loop.c b/drivers/block/loop.c index ae3fcb4199e9..d7173cb1ea76 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c | |||
@@ -1620,8 +1620,8 @@ out: | |||
1620 | 1620 | ||
1621 | static void loop_remove(struct loop_device *lo) | 1621 | static void loop_remove(struct loop_device *lo) |
1622 | { | 1622 | { |
1623 | del_gendisk(lo->lo_disk); | ||
1624 | blk_cleanup_queue(lo->lo_queue); | 1623 | blk_cleanup_queue(lo->lo_queue); |
1624 | del_gendisk(lo->lo_disk); | ||
1625 | blk_mq_free_tag_set(&lo->tag_set); | 1625 | blk_mq_free_tag_set(&lo->tag_set); |
1626 | put_disk(lo->lo_disk); | 1626 | put_disk(lo->lo_disk); |
1627 | kfree(lo); | 1627 | kfree(lo); |
diff --git a/drivers/md/md.c b/drivers/md/md.c index e6178787ce3d..e47d1dd046da 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c | |||
@@ -4754,12 +4754,12 @@ static void md_free(struct kobject *ko) | |||
4754 | if (mddev->sysfs_state) | 4754 | if (mddev->sysfs_state) |
4755 | sysfs_put(mddev->sysfs_state); | 4755 | sysfs_put(mddev->sysfs_state); |
4756 | 4756 | ||
4757 | if (mddev->queue) | ||
4758 | blk_cleanup_queue(mddev->queue); | ||
4757 | if (mddev->gendisk) { | 4759 | if (mddev->gendisk) { |
4758 | del_gendisk(mddev->gendisk); | 4760 | del_gendisk(mddev->gendisk); |
4759 | put_disk(mddev->gendisk); | 4761 | put_disk(mddev->gendisk); |
4760 | } | 4762 | } |
4761 | if (mddev->queue) | ||
4762 | blk_cleanup_queue(mddev->queue); | ||
4763 | 4763 | ||
4764 | kfree(mddev); | 4764 | kfree(mddev); |
4765 | } | 4765 | } |