Skip to contentSkip to conversation

SCSI: sd_suspend: evaluate lower layers' returns

PATCH New Oliver Neukum 1 participant 1 message Oct 8, 2010 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 SCSI: sd_suspend: evaluate lower layers' returns

Quoted 1 line

From 57262ff8bee869f671f843c81f48c2ed3d6713df Mon Sep 17 00:00:00 2001

From: Oliver Neukum <[email protected]>
Date: Fri, 8 Oct 2010 15:00:16 +0200
Subject: [PATCH 1/2] SCSI: sd_suspend: evaluate lower layers' returns

sd_suspend() sends down commands that may fail. Depending on the reason of failure the failures can be ignored, the suspension retried or aborted. This patch evaluates the error returns from the lower layers to do so.

---
 drivers/scsi/sd.c |   24 ++++++++++++++++++++----
 1 files changed, 20 insertions(+), 4 deletions(-)
drivers/scsi/sd.c +20 -4
index ffa0689..5784c94 100644
@@ -1083,9 +1083,7 @@ static int sd_sync_cache(struct scsi_disk *sdkp)
 			sd_print_sense_hdr(sdkp, &sshdr);
 	}
 
-	if (res)
-		return -EIO;
-	return 0;
+	return res;
 }
 
 static void sd_rescan(struct device *dev)
@@ -2526,7 +2524,25 @@ static int sd_suspend(struct device *dev, pm_message_t mesg)
 
 done:
 	scsi_disk_put(sdkp);
-	return ret;
+
+	if (ret) {
+		/* ??should errors due to medium removal be ignored? */
+		switch (host_byte(ret)) {
+		/* ignore errors due to racing a disconnection */
+		case DID_BAD_TARGET:
+		case DID_NO_CONNECT:	
+			return 0;
+		/* signal the upper layer it might try again */
+		case DID_BUS_BUSY:
+		case DID_ABORT:
+		case DID_RESET:
+			return -EBUSY;
+		default:
+			return -EIO;
+		}
+	} else {
+		return 0;
+	}
 }
 
 static int sd_resume(struct device *dev)
Signature · 1 line
1.7.1