|
@@ -719,7 +719,7 @@ static ssize_t
|
|
store_state_field(struct device *dev, struct device_attribute *attr,
|
|
store_state_field(struct device *dev, struct device_attribute *attr,
|
|
const char *buf, size_t count)
|
|
const char *buf, size_t count)
|
|
{
|
|
{
|
|
- int i;
|
|
|
|
|
|
+ int i, ret;
|
|
struct scsi_device *sdev = to_scsi_device(dev);
|
|
struct scsi_device *sdev = to_scsi_device(dev);
|
|
enum scsi_device_state state = 0;
|
|
enum scsi_device_state state = 0;
|
|
|
|
|
|
@@ -734,9 +734,11 @@ store_state_field(struct device *dev, struct device_attribute *attr,
|
|
if (!state)
|
|
if (!state)
|
|
return -EINVAL;
|
|
return -EINVAL;
|
|
|
|
|
|
- if (scsi_device_set_state(sdev, state))
|
|
|
|
- return -EINVAL;
|
|
|
|
- return count;
|
|
|
|
|
|
+ mutex_lock(&sdev->state_mutex);
|
|
|
|
+ ret = scsi_device_set_state(sdev, state);
|
|
|
|
+ mutex_unlock(&sdev->state_mutex);
|
|
|
|
+
|
|
|
|
+ return ret == 0 ? count : -EINVAL;
|
|
}
|
|
}
|
|
|
|
|
|
static ssize_t
|
|
static ssize_t
|
|
@@ -1272,6 +1274,7 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev)
|
|
void __scsi_remove_device(struct scsi_device *sdev)
|
|
void __scsi_remove_device(struct scsi_device *sdev)
|
|
{
|
|
{
|
|
struct device *dev = &sdev->sdev_gendev;
|
|
struct device *dev = &sdev->sdev_gendev;
|
|
|
|
+ int res;
|
|
|
|
|
|
/*
|
|
/*
|
|
* This cleanup path is not reentrant and while it is impossible
|
|
* This cleanup path is not reentrant and while it is impossible
|
|
@@ -1282,7 +1285,15 @@ void __scsi_remove_device(struct scsi_device *sdev)
|
|
return;
|
|
return;
|
|
|
|
|
|
if (sdev->is_visible) {
|
|
if (sdev->is_visible) {
|
|
- if (scsi_device_set_state(sdev, SDEV_CANCEL) != 0)
|
|
|
|
|
|
+ /*
|
|
|
|
+ * If scsi_internal_target_block() is running concurrently,
|
|
|
|
+ * wait until it has finished before changing the device state.
|
|
|
|
+ */
|
|
|
|
+ mutex_lock(&sdev->state_mutex);
|
|
|
|
+ res = scsi_device_set_state(sdev, SDEV_CANCEL);
|
|
|
|
+ mutex_unlock(&sdev->state_mutex);
|
|
|
|
+
|
|
|
|
+ if (res != 0)
|
|
return;
|
|
return;
|
|
|
|
|
|
bsg_unregister_queue(sdev->request_queue);
|
|
bsg_unregister_queue(sdev->request_queue);
|
|
@@ -1298,7 +1309,10 @@ void __scsi_remove_device(struct scsi_device *sdev)
|
|
* scsi_run_queue() invocations have finished before tearing down the
|
|
* scsi_run_queue() invocations have finished before tearing down the
|
|
* device.
|
|
* device.
|
|
*/
|
|
*/
|
|
|
|
+ mutex_lock(&sdev->state_mutex);
|
|
scsi_device_set_state(sdev, SDEV_DEL);
|
|
scsi_device_set_state(sdev, SDEV_DEL);
|
|
|
|
+ mutex_unlock(&sdev->state_mutex);
|
|
|
|
+
|
|
blk_cleanup_queue(sdev->request_queue);
|
|
blk_cleanup_queue(sdev->request_queue);
|
|
cancel_work_sync(&sdev->requeue_work);
|
|
cancel_work_sync(&sdev->requeue_work);
|
|
|
|
|