All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scsi: ignore Synchronize Cache command failures to keep using drives not supporting it
@ 2019-03-17 17:51 Guido Trentalancia
  2019-03-20 16:44 ` [PATCH v2] " Guido Trentalancia
  0 siblings, 1 reply; 4+ messages in thread
From: Guido Trentalancia @ 2019-03-17 17:51 UTC (permalink / raw)
  To: linux-kernel

Many obsolete hard drives do not support the Synchronize Cache SCSI
command. Such command is generally issued during fsync() calls which
at the moment therefore fail with the ILLEGAL_REQUEST sense key.

Since this failure is currently treated as critical in the kernel SCSI
disk driver, such obsolete hard drives cannot be used anymore (at least
since kernel 4.10, maybe even earlier): they cannot be formatted,
mounted and/or checked using tools such as e2fsprogs.

Because there is nothing which can be done if the drive does not support
such command, such ILLEGAL_REQUEST should be treated as non-critical so
that the underlying operation does not fail and the obsolete hard drive
can be used normally.

Of course, using such hard drives which do not feature the Synchronize
Cache SCSI command implies a very high risk (or maybe even certainty) of
data loss in case of power cuts, USB cable disconnects and so on -
SO YOU HAVE BEEN WARNED - IN DOUBT, UPGRADE TO A NEWER HARD DRIVE !!!

Signed-off-by: Guido Trentalancia <guido@trentalancia.com>
---
 drivers/scsi/sd.c |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)

--- linux-5.0.2-orig/drivers/scsi/sd.c	2019-03-17 18:22:04.822720851 +0100
+++ linux-5.0.2/drivers/scsi/sd.c	2019-03-17 18:47:06.405881720 +0100
@@ -1633,6 +1633,16 @@ static int sd_sync_cache(struct scsi_dis
 	}
 
 	if (res) {
+		/*
+		 * sshdr.sense_key == ILLEGAL_REQUEST means this drive
+		 * doesn't support sync. There's not much to do and
+		 * sync shouldn't fail.
+		 */
+		if (sshdr->sense_key == ILLEGAL_REQUEST && sshdr->asc == 0x20) {
+			sd_printk(KERN_NOTICE, sdkp, "Drive does not support Synchronize Cache(10) command: ignoring.\n");
+			return 0;
+		}
+
 		sd_print_result(sdkp, "Synchronize Cache(10) failed", res);
 
 		if (driver_byte(res) == DRIVER_SENSE)
@@ -2022,6 +2032,13 @@ static int sd_done(struct scsi_cmnd *SCp
 					req->rq_flags |= RQF_QUIET;
 				}
 				break;
+			case SYNCHRONIZE_CACHE:
+				if (sshdr.asc == 0x20) {
+					sd_printk(KERN_NOTICE, sdkp, "Drive does not support Synchronize Cache(10) command: ignoring.\n");
+					SCpnt->result = 0;
+					good_bytes = scsi_bufflen(SCpnt);
+				}
+				break;
 			}
 		}
 		break;

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] scsi: ignore Synchronize Cache command failures to keep using drives not supporting it
  2019-03-17 17:51 [PATCH] scsi: ignore Synchronize Cache command failures to keep using drives not supporting it Guido Trentalancia
@ 2019-03-20 16:44 ` Guido Trentalancia
  0 siblings, 0 replies; 4+ messages in thread
From: Guido Trentalancia @ 2019-03-20 16:44 UTC (permalink / raw)
  To: linux-kernel; +Cc: eric

Many obsolete hard drives do not support the Synchronize Cache SCSI
command. Such command is generally issued during fsync() calls which
at the moment therefore fail with the ILLEGAL_REQUEST sense key.

Since this failure is currently treated as critical in the kernel SCSI
disk driver, such obsolete hard drives cannot be used anymore (at least
since kernel 4.10, maybe even earlier): they cannot be formatted,
mounted and/or checked using tools such as e2fsprogs.

Because there is nothing which can be done if the drive does not support
such command, such ILLEGAL_REQUEST should be treated as non-critical so
that the underlying operation does not fail and the obsolete hard drive
can be used normally.

This second version of the patch (v2) disables the Write Cache feature
as a precaution on hard drives which do not support the Synchronize Cache
command and therefore the cache flushing functionality.

Although the Write Cache is disabled (v2) when using such hard drives
which do not feature the Synchronize Cache SCSI command there is still
some risk of data loss in case of power cuts, USB cable disconnects and
so on: YOU HAVE BEEN WARNED - THE DRIVE MANIFACTURER SHOULD HAVE BEEN
WARNED YOU IN THE FIRST PLACE - IN DOUBT, UPGRADE TO A NEWER HARD DRIVE !!

Signed-off-by: Guido Trentalancia <guido@trentalancia.com>
---
 drivers/scsi/sd.c |   29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff -pru linux-5.0.2-orig/drivers/scsi/sd.c linux-5.0.2/drivers/scsi/sd.c
--- linux-5.0.2-orig/drivers/scsi/sd.c	2019-03-17 18:22:04.822720851 +0100
+++ linux-5.0.2/drivers/scsi/sd.c	2019-03-20 17:41:44.526957307 +0100
@@ -22,6 +22,10 @@
  *	 - Badari Pulavarty <pbadari@us.ibm.com>, Matthew Wilcox 
  *	   <willy@debian.org>, Kurt Garloff <garloff@suse.de>: 
  *	   Support 32k/1M disks.
+ *	 - Guido Trentalancia <guido@trentalancia.com> ignore Synchronize
+ *	   Cache command failures on hard-drives that do not support it
+ *	   and disable the Write Cache functionality on such devices as a
+ *	   precaution: this allows to keep using several obsolete drives.
  *
  *	Logging policy (needs CONFIG_SCSI_LOGGING defined):
  *	 - setting up transfer: SCSI_LOG_HLQUEUE levels 1 and 2
@@ -1633,6 +1637,20 @@ static int sd_sync_cache(struct scsi_dis
 	}
 
 	if (res) {
+		/*
+		 * sshdr.sense_key == ILLEGAL_REQUEST means this drive
+		 * doesn't support sync. There's not much to do and
+		 * sync shouldn't fail.
+		 */
+		if (sshdr->sense_key == ILLEGAL_REQUEST && sshdr->asc == 0x20) {
+			if (sdkp->WCE) {
+				sdkp->WCE = 0;
+				sd_printk(KERN_NOTICE, sdkp, "Drive does not support Synchronize Cache(10) command: disabling write cache.\n");
+				sd_set_flush_flag(sdkp);
+			}
+			return 0;
+		}
+
 		sd_print_result(sdkp, "Synchronize Cache(10) failed", res);
 
 		if (driver_byte(res) == DRIVER_SENSE)
@@ -2022,6 +2040,17 @@ static int sd_done(struct scsi_cmnd *SCp
 					req->rq_flags |= RQF_QUIET;
 				}
 				break;
+			case SYNCHRONIZE_CACHE:
+				if (sshdr.asc == 0x20) {
+					if (sdkp->WCE) {
+						sdkp->WCE = 0;
+						sd_printk(KERN_NOTICE, sdkp, "Drive does not support Synchronize Cache(10) command: disabling write cache.\n");
+						sd_set_flush_flag(sdkp);
+					}
+					SCpnt->result = 0;
+					good_bytes = scsi_bufflen(SCpnt);
+				}
+				break;
 			}
 		}
 		break;

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] scsi: ignore Synchronize Cache command failures to keep using drives not supporting it
  2019-12-09 10:06 Guido Trentalancia
@ 2019-12-09 10:24 ` Guido Trentalancia
  0 siblings, 0 replies; 4+ messages in thread
From: Guido Trentalancia @ 2019-12-09 10:24 UTC (permalink / raw)
  To: linux-scsi

Kernel bug filed here:

https://bugzilla.kernel.org/show_bug.cgi?id=203635

On Mon, 09/12/2019 at 11.06 +0100, Guido Trentalancia wrote:
> Many obsolete hard drives do not support the Synchronize Cache SCSI
> command. Such command is generally issued during fsync() calls which
> at the moment therefore fail with the ILLEGAL_REQUEST sense key.
> 
> Since this failure is currently treated as critical in the kernel
> SCSI
> disk driver, such obsolete hard drives cannot be used anymore (at
> least
> since kernel 4.10, maybe even earlier): they cannot be formatted,
> mounted and/or checked using tools such as e2fsprogs.
> 
> Because there is nothing which can be done if the drive does not
> support
> such command, such ILLEGAL_REQUEST should be treated as non-critical
> so
> that the underlying operation does not fail and the obsolete hard
> drive
> can be used normally.
> 
> This second version of the patch (v2) disables the Write Cache
> feature
> as a precaution on hard drives which do not support the Synchronize
> Cache
> command and therefore the cache flushing functionality.
> 
> Although the Write Cache is disabled (v2) when using such hard drives
> which do not feature the Synchronize Cache SCSI command, there is
> still
> some risk of data loss in case of power cuts, USB cable disconnects
> and
> so on, which depend on the drive itself and not on this patch or the
> rest of the kernel code: YOU HAVE BEEN WARNED - THE DRIVE
> MANIFACTURER
> SHOULD HAVE BEEN WARNED YOU IN THE FIRST PLACE - IN DOUBT, UPGRADE TO
> A
> NEWER HARD DRIVE !!
> 
> Tested on a Maxtor OneTouch USB 200Gb External Hard Drive.
> 
> Signed-off-by: Guido Trentalancia <guido@trentalancia.com>
> ---
>  drivers/scsi/sd.c |   29 +++++++++++++++++++++++++++++
>  1 file changed, 29 insertions(+)
> [...]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] scsi: ignore Synchronize Cache command failures to keep using drives not supporting it
@ 2019-12-09 10:06 Guido Trentalancia
  2019-12-09 10:24 ` Guido Trentalancia
  0 siblings, 1 reply; 4+ messages in thread
From: Guido Trentalancia @ 2019-12-09 10:06 UTC (permalink / raw)
  To: linux-scsi; +Cc: drew, linux-kernel

Many obsolete hard drives do not support the Synchronize Cache SCSI
command. Such command is generally issued during fsync() calls which
at the moment therefore fail with the ILLEGAL_REQUEST sense key.

Since this failure is currently treated as critical in the kernel SCSI
disk driver, such obsolete hard drives cannot be used anymore (at least
since kernel 4.10, maybe even earlier): they cannot be formatted,
mounted and/or checked using tools such as e2fsprogs.

Because there is nothing which can be done if the drive does not support
such command, such ILLEGAL_REQUEST should be treated as non-critical so
that the underlying operation does not fail and the obsolete hard drive
can be used normally.

This second version of the patch (v2) disables the Write Cache feature
as a precaution on hard drives which do not support the Synchronize Cache
command and therefore the cache flushing functionality.

Although the Write Cache is disabled (v2) when using such hard drives
which do not feature the Synchronize Cache SCSI command, there is still
some risk of data loss in case of power cuts, USB cable disconnects and
so on, which depend on the drive itself and not on this patch or the
rest of the kernel code: YOU HAVE BEEN WARNED - THE DRIVE MANIFACTURER
SHOULD HAVE BEEN WARNED YOU IN THE FIRST PLACE - IN DOUBT, UPGRADE TO A
NEWER HARD DRIVE !!

Tested on a Maxtor OneTouch USB 200Gb External Hard Drive.

Signed-off-by: Guido Trentalancia <guido@trentalancia.com>
---
 drivers/scsi/sd.c |   29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff -pru a/drivers/scsi/sd.c b/drivers/scsi/sd.c
--- a/drivers/scsi/sd.c	2019-03-17 18:22:04.822720851 +0100
+++ b/drivers/scsi/sd.c	2019-03-20 17:41:44.526957307 +0100
@@ -22,6 +22,10 @@
  *	 - Badari Pulavarty <pbadari@us.ibm.com>, Matthew Wilcox 
  *	   <willy@debian.org>, Kurt Garloff <garloff@suse.de>: 
  *	   Support 32k/1M disks.
+ *	 - Guido Trentalancia <guido@trentalancia.com> ignore Synchronize
+ *	   Cache command failures on hard-drives that do not support it
+ *	   and disable the Write Cache functionality on such devices as a
+ *	   precaution: this allows to keep using several obsolete drives.
  *
  *	Logging policy (needs CONFIG_SCSI_LOGGING defined):
  *	 - setting up transfer: SCSI_LOG_HLQUEUE levels 1 and 2
@@ -1633,6 +1637,20 @@ static int sd_sync_cache(struct scsi_dis
 	}
 
 	if (res) {
+		/*
+		 * sshdr.sense_key == ILLEGAL_REQUEST means this drive
+		 * doesn't support sync. There's not much to do and
+		 * sync shouldn't fail.
+		 */
+		if (sshdr->sense_key == ILLEGAL_REQUEST && sshdr->asc == 0x20) {
+			if (sdkp->WCE) {
+				sdkp->WCE = 0;
+				sd_printk(KERN_NOTICE, sdkp, "Drive does not support Synchronize Cache(10) command: disabling write cache.\n");
+				sd_set_flush_flag(sdkp);
+			}
+			return 0;
+		}
+
 		sd_print_result(sdkp, "Synchronize Cache(10) failed", res);
 
 		if (driver_byte(res) == DRIVER_SENSE)
@@ -2022,6 +2040,17 @@ static int sd_done(struct scsi_cmnd *SCp
 					req->rq_flags |= RQF_QUIET;
 				}
 				break;
+			case SYNCHRONIZE_CACHE:
+				if (sshdr.asc == 0x20) {
+					if (sdkp->WCE) {
+						sdkp->WCE = 0;
+						sd_printk(KERN_NOTICE, sdkp, "Drive does not support Synchronize Cache(10) command: disabling write cache.\n");
+						sd_set_flush_flag(sdkp);
+					}
+					SCpnt->result = 0;
+					good_bytes = scsi_bufflen(SCpnt);
+				}
+				break;
 			}
 		}
 		break;

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-12-09 10:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-17 17:51 [PATCH] scsi: ignore Synchronize Cache command failures to keep using drives not supporting it Guido Trentalancia
2019-03-20 16:44 ` [PATCH v2] " Guido Trentalancia
2019-12-09 10:06 Guido Trentalancia
2019-12-09 10:24 ` Guido Trentalancia

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.