Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758774Ab1ENTKI (ORCPT ); Sat, 14 May 2011 15:10:08 -0400 Received: from smtp-out002.kontent.com ([81.88.40.216]:50586 "EHLO smtp-out002.kontent.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753963Ab1ENTKG convert rfc822-to-8bit (ORCPT ); Sat, 14 May 2011 15:10:06 -0400 From: Oliver Neukum To: James Bottomley , hare@suse.de Subject: Re: [PATCH] scsi/sd: fix suspend with USB-connected Android phone (one line) Date: Sat, 14 May 2011 21:11:52 +0200 User-Agent: KMail/1.13.5 (Linux/2.6.39-rc4-12-desktop+; KDE/4.4.4; x86_64; ; ) Cc: "Rafael J. Wysocki" , Charles Hannum , linux-kernel@vger.kernel.org, "Greg Kroah-Hartman" , Alan Stern , "linux-scsi" , linux-usb@vger.kernel.org References: <201105122203.13671.rjw@sisk.pl> <1305232563.2575.85.camel@mulgrave.site> In-Reply-To: <1305232563.2575.85.camel@mulgrave.site> MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: 8BIT Message-Id: <201105142111.53266.oliver@neukum.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2736 Lines: 90 Am Donnerstag, 12. Mai 2011, 22:36:03 schrieb James Bottomley: > Instinct tells me the correct set of fixes is to add a sync cache from > release (so we automatically sync on last close, which is usually when > an ordered remove happens), keep the one on shutdown, just in case the > system goes down with stuff still mounted and print a nasty message on > suspend for a write back device that's been removed. > > I also think we shouldn't abort the suspend if the disk doesn't respond > correctly to start/stop ... the power is going to be disconnected > anyway, so it's no issue if the disk spins for a second or so longer. > > The problem this is going to cause is double sync on shutdown (once when > final unmount closes the device and once on shutdown) ... do people > agree that's a price worth paying? > > Something like this? Hi, it seems to me that the error codes should really be evaluated a bit better. How about this? Regards Oliver >From 2ab03ae46d6dc126a51ee9cd38206fbdc8bf6a34 Mon Sep 17 00:00:00 2001 From: Oliver Neukum Date: Mon, 25 Oct 2010 12:25:26 +0200 Subject: [PATCH 2/5] SCSI:sd:error handling in sd_sync_cache() The SCSI commands sd_sync_cache() uses may fail. These errors needs to be evaluated to return correct error codes. This fixes system suspension while a device removal is being handled. Signed-off-by: Oliver NEukum --- drivers/scsi/sd.c | 28 ++++++++++++++++++++++++---- 1 files changed, 24 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index fcba7d2..5ed75bf 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -1104,11 +1104,31 @@ static int sd_sync_cache(struct scsi_disk *sdkp) sd_print_result(sdkp, res); if (driver_byte(res) & DRIVER_SENSE) sd_print_sense_hdr(sdkp, &sshdr); - } - if (res) - return -EIO; - return 0; + /* we need to evaluate the error return */ + if ((scsi_sense_valid(&sshdr) && + /* 0x3a is medium not present */ + sshdr.asc == 0x3a)) + /* this is no error here */ + return 0; + + switch (host_byte(res)) { + /* 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_IMM_RETRY: + case DID_REQUEUE: + case DID_SOFT_ERROR: + return -EBUSY; + default: + return -EIO; + } + } else { + return 0; + } } static void sd_rescan(struct device *dev) -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/