diff options
author | James Bottomley <James.Bottomley@suse.de> | 2009-11-19 17:48:29 -0500 |
---|---|---|
committer | James Bottomley <James.Bottomley@suse.de> | 2009-11-26 10:43:39 -0500 |
commit | 860dc73608a091e0b325218acc2701709d5f221a (patch) | |
tree | 2527b226e1991c459ac02de4a6ba5c98a4639add /drivers/scsi/scsi_scan.c | |
parent | 3bf3583b6a49c318f7ed350862d7a217b500e71c (diff) |
[SCSI] fix async scan add/remove race resulting in an oops
Async scanning introduced a very wide window where the SCSI device is
up and running but has not yet been added to sysfs. We delay the
adding until all scans have completed to retain the same ordering as
sync scanning.
This delay in visibility causes an oops if a device is removed before
we make it visible because the SCSI removal routines have an inbuilt
assumption that if a device is in SDEV_RUNNING state, it must be
visible (which is not necessarily true in the async scanning case).
Fix this by introducing an additional is_visible flag which we can use
to condition the tear down so we do the right thing for running but
not yet made visible.
Reported-by: Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
Diffstat (limited to 'drivers/scsi/scsi_scan.c')
-rw-r--r-- | drivers/scsi/scsi_scan.c | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c index 0547a7f44d4..47291bcff0d 100644 --- a/drivers/scsi/scsi_scan.c +++ b/drivers/scsi/scsi_scan.c | |||
@@ -952,16 +952,6 @@ static int scsi_add_lun(struct scsi_device *sdev, unsigned char *inq_result, | |||
952 | return SCSI_SCAN_LUN_PRESENT; | 952 | return SCSI_SCAN_LUN_PRESENT; |
953 | } | 953 | } |
954 | 954 | ||
955 | static inline void scsi_destroy_sdev(struct scsi_device *sdev) | ||
956 | { | ||
957 | scsi_device_set_state(sdev, SDEV_DEL); | ||
958 | if (sdev->host->hostt->slave_destroy) | ||
959 | sdev->host->hostt->slave_destroy(sdev); | ||
960 | transport_destroy_device(&sdev->sdev_gendev); | ||
961 | put_device(&sdev->sdev_dev); | ||
962 | put_device(&sdev->sdev_gendev); | ||
963 | } | ||
964 | |||
965 | #ifdef CONFIG_SCSI_LOGGING | 955 | #ifdef CONFIG_SCSI_LOGGING |
966 | /** | 956 | /** |
967 | * scsi_inq_str - print INQUIRY data from min to max index, strip trailing whitespace | 957 | * scsi_inq_str - print INQUIRY data from min to max index, strip trailing whitespace |
@@ -1139,7 +1129,7 @@ static int scsi_probe_and_add_lun(struct scsi_target *starget, | |||
1139 | } | 1129 | } |
1140 | } | 1130 | } |
1141 | } else | 1131 | } else |
1142 | scsi_destroy_sdev(sdev); | 1132 | __scsi_remove_device(sdev); |
1143 | out: | 1133 | out: |
1144 | return res; | 1134 | return res; |
1145 | } | 1135 | } |
@@ -1500,7 +1490,7 @@ static int scsi_report_lun_scan(struct scsi_target *starget, int bflags, | |||
1500 | /* | 1490 | /* |
1501 | * the sdev we used didn't appear in the report luns scan | 1491 | * the sdev we used didn't appear in the report luns scan |
1502 | */ | 1492 | */ |
1503 | scsi_destroy_sdev(sdev); | 1493 | __scsi_remove_device(sdev); |
1504 | return ret; | 1494 | return ret; |
1505 | } | 1495 | } |
1506 | 1496 | ||
@@ -1710,7 +1700,7 @@ static void scsi_sysfs_add_devices(struct Scsi_Host *shost) | |||
1710 | shost_for_each_device(sdev, shost) { | 1700 | shost_for_each_device(sdev, shost) { |
1711 | if (!scsi_host_scan_allowed(shost) || | 1701 | if (!scsi_host_scan_allowed(shost) || |
1712 | scsi_sysfs_add_sdev(sdev) != 0) | 1702 | scsi_sysfs_add_sdev(sdev) != 0) |
1713 | scsi_destroy_sdev(sdev); | 1703 | __scsi_remove_device(sdev); |
1714 | } | 1704 | } |
1715 | } | 1705 | } |
1716 | 1706 | ||
@@ -1943,7 +1933,7 @@ void scsi_free_host_dev(struct scsi_device *sdev) | |||
1943 | { | 1933 | { |
1944 | BUG_ON(sdev->id != sdev->host->this_id); | 1934 | BUG_ON(sdev->id != sdev->host->this_id); |
1945 | 1935 | ||
1946 | scsi_destroy_sdev(sdev); | 1936 | __scsi_remove_device(sdev); |
1947 | } | 1937 | } |
1948 | EXPORT_SYMBOL(scsi_free_host_dev); | 1938 | EXPORT_SYMBOL(scsi_free_host_dev); |
1949 | 1939 | ||