Received: by 2002:ac0:950e:0:0:0:0:0 with SMTP id f14csp1337780imc; Sun, 17 Mar 2019 11:00:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqx7l3o/bjX0q5bDWOaaByIX59RD2HyDBGYUPBAY5L7OwHkLeKIDrShZo9mxoKpHUrt7JPpR X-Received: by 2002:a63:2a86:: with SMTP id q128mr13920822pgq.424.1552845617514; Sun, 17 Mar 2019 11:00:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552845617; cv=none; d=google.com; s=arc-20160816; b=eoOCUjr/tQ3rUVsubudXBCwPce1ogd4suwuGvLdzXYEnr6ST/ItatGktkZO5hweg20 hZfoTZKXIuaRe66TwrvvDiVJKoXqPFN23xz7Uagq1fzN06YshUhJSlZvakMJj1EQWofa kv7/eXcaJj4+M6vfFn69j6p7rDth4M/TU5MJ2vJQYa2K8KTphjYLSUHzkH3QeW7Buxne bmBzEudydpOkwNtr4POu+bH3FMzYB5FTPnqpZzkVUboNbPpeE3E6SFb2YzwhJYPSa1Ry diJ15U5Iz6+C/jiZwM+wNxntIbKekc+4inah6XIpeAQM8GYPfoideTWxFbkTl97mk+R+ g6WQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :date:to:from:subject:message-id; bh=wLoI2F9voAPrJYJNAag/sb3jmV+zvaLeQwYk//QD+TI=; b=ZYuAdnZpTZmUFYJpq1QVYIrIeUfOhFE3LAARaFTn+uxBCBv2xX5cL4idgosYduJRxk 4RPfHf4Cb/yBX1xuKzNOahVv82ejVV15ud0z7K8lg5KrJMVhxBwEebWRyRFSghVjCvLs Jk0xzeXg86O0FH/gRT1TqGHd36xScpmR3txsEgyqhG8PL8n5YMUIUl9CDu/24s3Sbdmr o5LEK1L9qfNmc7Iv/7g6VNpoy7CG0tGkr/fmHHDSvEvl3K57e0rSnNxdpxGyeMVnO01j PzF1C24bwXM36WBsP6h3YtX2ntN4hxaTGL1HRAZzpB/4J5WMekdrL7t72R/uZC9hqHPz ousg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i62si7605098pli.218.2019.03.17.11.00.01; Sun, 17 Mar 2019 11:00:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726744AbfCQR7W (ORCPT + 99 others); Sun, 17 Mar 2019 13:59:22 -0400 Received: from authsmtp23.register.it ([81.88.48.46]:48511 "EHLO authsmtp.register.it" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726115AbfCQR7V (ORCPT ); Sun, 17 Mar 2019 13:59:21 -0400 X-Greylist: delayed 490 seconds by postgrey-1.27 at vger.kernel.org; Sun, 17 Mar 2019 13:59:20 EDT Received: from [192.168.1.1] ([93.41.32.9]) by cmsmtp with ESMTPSA id 5ZwDhWZDYjSal5ZwDhLYg8; Sun, 17 Mar 2019 18:51:09 +0100 X-Rid: guido@trentalancia.com@93.41.32.9 Message-ID: <1552845068.5940.6.camel@trentalancia.com> Subject: [PATCH] scsi: ignore Synchronize Cache command failures to keep using drives not supporting it From: Guido Trentalancia To: linux-kernel@vger.kernel.org Date: Sun, 17 Mar 2019 18:51:08 +0100 X-Priority: 1 Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.26.2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-CMAE-Envelope: MS4wfKlZb5edfOVWOran40zjuv9f15oy+xiWfqgl7B/bI6yqvZpHOArq/t56XlJmtER1iQW0Ib0SiP1AH75UDqCX03vlZ/RvsGU9mGNsShRBnnNNn0nwyl5Y rS1mi0CBwG9kq8CKhR579jDbjSqEr54WfUplx9ptL+sqJJ7iHIxT2N3O Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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;