Skip to contentSkip to conversation

scsi: sd: mark the scsi device in shutdown as deleted

PATCH In review Tomas Henzl 1 participant 2 messages Apr 3, 2023 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: sd: mark the scsi device in shutdown as deleted

Set the state to deleted in sd_shutdown so that the attached LLD doesn't receive new I/O (can happen when in kexec) later after LLD's shutdown function has been called.

---
 drivers/scsi/sd.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/scsi/sd.c +7 -0
index 4f28dd617eca..8095f0302e66 100644
@@ -3694,10 +3694,13 @@ static int sd_start_stop_device(struct scsi_disk *sdkp, int start)
 static void sd_shutdown(struct device *dev)
 {
 	struct scsi_disk *sdkp = dev_get_drvdata(dev);
+	struct scsi_device *sdp;
 
 	if (!sdkp)
 		return;         /* this can happen */
 
+	sdp = sdkp->device;
+
 	if (pm_runtime_suspended(dev))
 		return;
 
@@ -3710,6 +3713,10 @@ static void sd_shutdown(struct device *dev)
 		sd_printk(KERN_NOTICE, sdkp, "Stopping disk\n");
 		sd_start_stop_device(sdkp, 0);
 	}
+
+	mutex_lock(&sdp->state_mutex);
+	scsi_device_set_state(sdp, SDEV_DEL);
+	mutex_unlock(&sdp->state_mutex);
 }
 
 static int sd_suspend_common(struct device *dev, bool ignore_stop_errors)
Signature · 1 line
2.39.2
#1 lore raw

Please drop this one, I've sent it by mistake.

tomash

Quoted 38 lines · Tomas Henzl

Set the state to deleted in sd_shutdown so that the attached LLD doesn't receive new I/O (can happen when in kexec) later after LLD's shutdown function has been called.

---
 drivers/scsi/sd.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/scsi/sd.c +7 -0
index 4f28dd617eca..8095f0302e66 100644
@@ -3694,10 +3694,13 @@ static int sd_start_stop_device(struct scsi_disk *sdkp, int start)
 static void sd_shutdown(struct device *dev)
 {
 	struct scsi_disk *sdkp = dev_get_drvdata(dev);
+	struct scsi_device *sdp;
 
 	if (!sdkp)
 		return;         /* this can happen */
 
+	sdp = sdkp->device;
+
 	if (pm_runtime_suspended(dev))
 		return;
 
@@ -3710,6 +3713,10 @@ static void sd_shutdown(struct device *dev)
 		sd_printk(KERN_NOTICE, sdkp, "Stopping disk\n");
 		sd_start_stop_device(sdkp, 0);
 	}
+
+	mutex_lock(&sdp->state_mutex);
+	scsi_device_set_state(sdp, SDEV_DEL);
+	mutex_unlock(&sdp->state_mutex);
 }
 
 static int sd_suspend_common(struct device *dev, bool ignore_stop_errors)