Skip to content

Commit bf2cf3b

Browse files
Bart Van AsscheJames Bottomley
authored andcommitted
scsi: Fix a bdi reregistration race
Unregister and reregister BDI devices in the proper order. This patch avoids that the following kernel warning can get triggered: WARNING: CPU: 7 PID: 203 at fs/sysfs/dir.c:31 sysfs_warn_dup+0x68/0x80() sysfs: cannot create duplicate filename '/devices/virtual/bdi/8:32' Workqueue: events_unbound async_run_entry_fn Call Trace: [<ffffffff814ff5a4>] dump_stack+0x4c/0x65 [<ffffffff810746ba>] warn_slowpath_common+0x8a/0xc0 [<ffffffff81074736>] warn_slowpath_fmt+0x46/0x50 [<ffffffff81237ca8>] sysfs_warn_dup+0x68/0x80 [<ffffffff81237d8e>] sysfs_create_dir_ns+0x7e/0x90 [<ffffffff81291f58>] kobject_add_internal+0xa8/0x320 [<ffffffff812923a0>] kobject_add+0x60/0xb0 [<ffffffff8138c937>] device_add+0x107/0x5e0 [<ffffffff8138d018>] device_create_groups_vargs+0xd8/0x100 [<ffffffff8138d05c>] device_create_vargs+0x1c/0x20 [<ffffffff8117f233>] bdi_register+0x63/0x2a0 [<ffffffff8117f497>] bdi_register_dev+0x27/0x30 [<ffffffff81281549>] add_disk+0x1a9/0x4e0 [<ffffffffa00c5739>] sd_probe_async+0x119/0x1d0 [sd_mod] [<ffffffff8109a81a>] async_run_entry_fn+0x4a/0x140 [<ffffffff81091078>] process_one_work+0x1d8/0x7c0 [<ffffffff81091774>] worker_thread+0x114/0x460 [<ffffffff81097878>] kthread+0xf8/0x110 [<ffffffff8150801f>] ret_from_fork+0x3f/0x70 See also patch "block: destroy bdi before blockdev is unregistered" (commit ID 6cd18e7). Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com> Reviewed-by: Hannes Reinecke <hare@suse.de> Cc: <stable@vger.kernel.org> Signed-off-by: James Bottomley <JBottomley@Odin.com>
1 parent cd9d715 commit bf2cf3b

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

drivers/scsi/scsi_sysfs.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,9 +1084,7 @@ void __scsi_remove_device(struct scsi_device *sdev)
10841084
device_unregister(&sdev->sdev_dev);
10851085
transport_remove_device(dev);
10861086
scsi_dh_remove_device(sdev);
1087-
device_del(dev);
1088-
} else
1089-
put_device(&sdev->sdev_dev);
1087+
}
10901088

10911089
/*
10921090
* Stop accepting new requests and wait until all queuecommand() and
@@ -1097,6 +1095,16 @@ void __scsi_remove_device(struct scsi_device *sdev)
10971095
blk_cleanup_queue(sdev->request_queue);
10981096
cancel_work_sync(&sdev->requeue_work);
10991097

1098+
/*
1099+
* Remove the device after blk_cleanup_queue() has been called such
1100+
* a possible bdi_register() call with the same name occurs after
1101+
* blk_cleanup_queue() has called bdi_destroy().
1102+
*/
1103+
if (sdev->is_visible)
1104+
device_del(dev);
1105+
else
1106+
put_device(&sdev->sdev_dev);
1107+
11001108
if (sdev->host->hostt->slave_destroy)
11011109
sdev->host->hostt->slave_destroy(sdev);
11021110
transport_destroy_device(dev);

0 commit comments

Comments
 (0)