From nobody Sun May 5 03:11:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1503324743533529.2003479899562; Mon, 21 Aug 2017 07:12:23 -0700 (PDT) Received: from localhost ([::1]:48347 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1djnRG-000496-5y for importer@patchew.org; Mon, 21 Aug 2017 10:12:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54803) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1djnPR-0002tu-62 for qemu-devel@nongnu.org; Mon, 21 Aug 2017 10:10:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1djnPL-0001X6-4n for qemu-devel@nongnu.org; Mon, 21 Aug 2017 10:10:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58828) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1djnPK-0001Ve-Rt for qemu-devel@nongnu.org; Mon, 21 Aug 2017 10:10:23 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D870B7DD09 for ; Mon, 21 Aug 2017 14:10:21 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-62.pek2.redhat.com [10.72.12.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id 328FA6CDB4; Mon, 21 Aug 2017 14:10:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D870B7DD09 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=famz@redhat.com From: Fam Zheng To: qemu-devel@nongnu.org Date: Mon, 21 Aug 2017 22:10:05 +0800 Message-Id: <20170821141008.19383-2-famz@redhat.com> In-Reply-To: <20170821141008.19383-1-famz@redhat.com> References: <20170821141008.19383-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 21 Aug 2017 14:10:22 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 1/4] scsi: Refactor scsi sense interpreting code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" So that it can be reused outside of iscsi.c. Also update MAINTAINERS to include the new files in SCSI section. Signed-off-by: Fam Zheng --- MAINTAINERS | 2 ++ block/iscsi.c | 45 ++++----------------------------------------- include/scsi/scsi.h | 19 +++++++++++++++++++ util/Makefile.objs | 1 + util/scsi.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++= +++ 5 files changed, 78 insertions(+), 41 deletions(-) create mode 100644 include/scsi/scsi.h create mode 100644 util/scsi.c diff --git a/MAINTAINERS b/MAINTAINERS index ccee28b12d..2a4e5036ae 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -969,7 +969,9 @@ SCSI M: Paolo Bonzini S: Supported F: include/hw/scsi/* +F: include/scsi/* F: hw/scsi/* +F: util/scsi* F: tests/virtio-scsi-test.c T: git git://github.com/bonzini/qemu.git scsi-next =20 diff --git a/block/iscsi.c b/block/iscsi.c index d557c99668..4bed63cd6d 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -40,6 +40,7 @@ #include "qmp-commands.h" #include "qapi/qmp/qstring.h" #include "crypto/secret.h" +#include "scsi/scsi.h" =20 #include #include @@ -209,47 +210,9 @@ static inline unsigned exp_random(double mean) =20 static int iscsi_translate_sense(struct scsi_sense *sense) { - int ret; - - switch (sense->key) { - case SCSI_SENSE_NOT_READY: - return -EBUSY; - case SCSI_SENSE_DATA_PROTECTION: - return -EACCES; - case SCSI_SENSE_COMMAND_ABORTED: - return -ECANCELED; - case SCSI_SENSE_ILLEGAL_REQUEST: - /* Parse ASCQ */ - break; - default: - return -EIO; - } - switch (sense->ascq) { - case SCSI_SENSE_ASCQ_PARAMETER_LIST_LENGTH_ERROR: - case SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE: - case SCSI_SENSE_ASCQ_INVALID_FIELD_IN_CDB: - case SCSI_SENSE_ASCQ_INVALID_FIELD_IN_PARAMETER_LIST: - ret =3D -EINVAL; - break; - case SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE: - ret =3D -ENOSPC; - break; - case SCSI_SENSE_ASCQ_LOGICAL_UNIT_NOT_SUPPORTED: - ret =3D -ENOTSUP; - break; - case SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT: - case SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_CLOSED: - case SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_OPEN: - ret =3D -ENOMEDIUM; - break; - case SCSI_SENSE_ASCQ_WRITE_PROTECTED: - ret =3D -EACCES; - break; - default: - ret =3D -EIO; - break; - } - return ret; + return - scsi_sense_to_errno(sense->key, + (sense->ascq & 0xFF00) >> 8, + sense->ascq & 0xFF); } =20 /* Called (via iscsi_service) with QemuMutex held. */ diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h new file mode 100644 index 0000000000..f894ace4bf --- /dev/null +++ b/include/scsi/scsi.h @@ -0,0 +1,19 @@ +/* + * SCSI helpers + * + * Copyright 2017 Red Hat, Inc. + * + * Authors: + * Fam Zheng + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the F= ree + * Software Foundation; either version 2 of the License, or (at your optio= n) + * any later version. + */ +#ifndef QEMU_SCSI_H +#define QEMU_SCSI_H + +int scsi_sense_to_errno(int key, int asc, int ascq); + +#endif diff --git a/util/Makefile.objs b/util/Makefile.objs index 50a55ecc75..c9e6c493d3 100644 --- a/util/Makefile.objs +++ b/util/Makefile.objs @@ -45,3 +45,4 @@ util-obj-y +=3D qht.o util-obj-y +=3D range.o util-obj-y +=3D stats64.o util-obj-y +=3D systemd.o +util-obj-y +=3D scsi.o diff --git a/util/scsi.c b/util/scsi.c new file mode 100644 index 0000000000..a6710799fc --- /dev/null +++ b/util/scsi.c @@ -0,0 +1,52 @@ +/* + * SCSI helpers + * + * Copyright 2017 Red Hat, Inc. + * + * Authors: + * Fam Zheng + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the F= ree + * Software Foundation; either version 2 of the License, or (at your optio= n) + * any later version. + */ + +#include "qemu/osdep.h" +#include "scsi/scsi.h" + +int scsi_sense_to_errno(int key, int asc, int ascq) +{ + switch (key) { + case 0x02: /* NOT READY */ + return EBUSY; + case 0x07: /* DATA PROTECTION */ + return EACCES; + case 0x0b: /* COMMAND ABORTED */ + return ECANCELED; + case 0x05: /* ILLEGAL REQUEST */ + /* Parse ASCQ */ + break; + default: + return EIO; + } + switch ((asc << 8) | ascq) { + case 0x1a00: /* PARAMETER LIST LENGTH ERROR */ + case 0x2000: /* INVALID OPERATION CODE */ + case 0x2400: /* INVALID FIELD IN CDB */ + case 0x2600: /* INVALID FIELD IN PARAMETER LIST */ + return EINVAL; + case 0x2100: /* LBA OUT OF RANGE */ + return ENOSPC; + case 0x2500: /* LOGICAL UNIT NOT SUPPORTED */ + return ENOTSUP; + case 0x3a00: /* MEDIUM NOT PRESENT */ + case 0x3a01: /* MEDIUM NOT PRESENT TRAY CLOSED */ + case 0x3a02: /* MEDIUM NOT PRESENT TRAY OPEN */ + return ENOMEDIUM; + case 0x2700: /* WRITE PROTECTED */ + return EACCES; + default: + return EIO; + } +} --=20 2.13.5 From nobody Sun May 5 03:11:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1503324862769336.5702273476239; Mon, 21 Aug 2017 07:14:22 -0700 (PDT) Received: from localhost ([::1]:48519 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1djnTB-00061k-Ea for importer@patchew.org; Mon, 21 Aug 2017 10:14:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54818) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1djnPS-0002ub-Tx for qemu-devel@nongnu.org; Mon, 21 Aug 2017 10:10:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1djnPN-0001Yv-AO for qemu-devel@nongnu.org; Mon, 21 Aug 2017 10:10:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47394) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1djnPN-0001YZ-48 for qemu-devel@nongnu.org; Mon, 21 Aug 2017 10:10:25 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 37F0D13A9F for ; Mon, 21 Aug 2017 14:10:24 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-62.pek2.redhat.com [10.72.12.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7817D6CDA7; Mon, 21 Aug 2017 14:10:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 37F0D13A9F Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=famz@redhat.com From: Fam Zheng To: qemu-devel@nongnu.org Date: Mon, 21 Aug 2017 22:10:06 +0800 Message-Id: <20170821141008.19383-3-famz@redhat.com> In-Reply-To: <20170821141008.19383-1-famz@redhat.com> References: <20170821141008.19383-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 21 Aug 2017 14:10:24 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 2/4] scsi: Improve scsi_sense_to_errno X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Tweak the errno mapping to return more accurate/appropriate values. Signed-off-by: Fam Zheng --- util/scsi.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/util/scsi.c b/util/scsi.c index a6710799fc..472eb5bea5 100644 --- a/util/scsi.c +++ b/util/scsi.c @@ -18,13 +18,16 @@ int scsi_sense_to_errno(int key, int asc, int ascq) { switch (key) { - case 0x02: /* NOT READY */ - return EBUSY; - case 0x07: /* DATA PROTECTION */ - return EACCES; + case 0x00: /* NO SENSE */ + case 0x01: /* RECOVERED ERROR */ + case 0x06: /* UNIT ATTENTION */ + /* These sense keys are not errors */ + return 0; case 0x0b: /* COMMAND ABORTED */ return ECANCELED; + case 0x02: /* NOT READY */ case 0x05: /* ILLEGAL REQUEST */ + case 0x07: /* DATA PROTECTION */ /* Parse ASCQ */ break; default: @@ -37,6 +40,7 @@ int scsi_sense_to_errno(int key, int asc, int ascq) case 0x2600: /* INVALID FIELD IN PARAMETER LIST */ return EINVAL; case 0x2100: /* LBA OUT OF RANGE */ + case 0x2707: /* SPACE ALLOC FAILED */ return ENOSPC; case 0x2500: /* LOGICAL UNIT NOT SUPPORTED */ return ENOTSUP; @@ -46,6 +50,10 @@ int scsi_sense_to_errno(int key, int asc, int ascq) return ENOMEDIUM; case 0x2700: /* WRITE PROTECTED */ return EACCES; + case 0x0401: /* NOT READY, IN PROGRESS OF BECOMING READY */ + return EAGAIN; + case 0x0402: /* NOT READY, INITIALIZING COMMAND REQUIRED */ + return ENOTCONN; default: return EIO; } --=20 2.13.5 From nobody Sun May 5 03:11:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1503324749489629.7724445591018; Mon, 21 Aug 2017 07:12:29 -0700 (PDT) Received: from localhost ([::1]:48348 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1djnRM-0004GJ-BG for importer@patchew.org; Mon, 21 Aug 2017 10:12:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54832) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1djnPU-0002um-T1 for qemu-devel@nongnu.org; Mon, 21 Aug 2017 10:10:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1djnPQ-0001fq-6r for qemu-devel@nongnu.org; Mon, 21 Aug 2017 10:10:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46514) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1djnPQ-0001dR-17 for qemu-devel@nongnu.org; Mon, 21 Aug 2017 10:10:28 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 17D26C047B82 for ; Mon, 21 Aug 2017 14:10:27 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-62.pek2.redhat.com [10.72.12.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id 06CC26CDBA; Mon, 21 Aug 2017 14:10:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 17D26C047B82 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=famz@redhat.com From: Fam Zheng To: qemu-devel@nongnu.org Date: Mon, 21 Aug 2017 22:10:07 +0800 Message-Id: <20170821141008.19383-4-famz@redhat.com> In-Reply-To: <20170821141008.19383-1-famz@redhat.com> References: <20170821141008.19383-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 21 Aug 2017 14:10:27 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 3/4] scsi: Introduce scsi_sense_buf_to_errno X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This recognizes the "fixed" and "descriptor" format sense data, extracts the sense key/asc/ascq fields then converts them to an errno. Signed-off-by: Fam Zheng --- include/scsi/scsi.h | 1 + util/scsi.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h index f894ace4bf..fe330385d8 100644 --- a/include/scsi/scsi.h +++ b/include/scsi/scsi.h @@ -15,5 +15,6 @@ #define QEMU_SCSI_H =20 int scsi_sense_to_errno(int key, int asc, int ascq); +int scsi_sense_buf_to_errno(const uint8_t *sense, size_t sense_size); =20 #endif diff --git a/util/scsi.c b/util/scsi.c index 472eb5bea5..472293d59b 100644 --- a/util/scsi.c +++ b/util/scsi.c @@ -58,3 +58,33 @@ int scsi_sense_to_errno(int key, int asc, int ascq) return EIO; } } + +int scsi_sense_buf_to_errno(const uint8_t *sense, size_t sense_size) +{ + int key, asc, ascq; + if (sense_size < 1) { + return EIO; + } + switch (sense[0]) { + case 0x70: /* Fixed format sense data. */ + if (sense_size < 14) { + return EIO; + } + key =3D sense[2] & 0xF; + asc =3D sense[12]; + ascq =3D sense[13]; + break; + case 0x72: /* Descriptor format sense data. */ + if (sense_size < 4) { + return EIO; + } + key =3D sense[1] & 0xF; + asc =3D sense[2]; + ascq =3D sense[3]; + break; + default: + return EIO; + break; + } + return scsi_sense_to_errno(key, asc, ascq); +} --=20 2.13.5 From nobody Sun May 5 03:11:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1503324948987775.1974667229405; Mon, 21 Aug 2017 07:15:48 -0700 (PDT) Received: from localhost ([::1]:48615 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1djnUZ-0007Bj-PF for importer@patchew.org; Mon, 21 Aug 2017 10:15:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54866) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1djnPZ-0002zk-QS for qemu-devel@nongnu.org; Mon, 21 Aug 2017 10:10:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1djnPU-0001mO-SA for qemu-devel@nongnu.org; Mon, 21 Aug 2017 10:10:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:4694) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1djnPU-0001kD-JL for qemu-devel@nongnu.org; Mon, 21 Aug 2017 10:10:32 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ABEF65F73C for ; Mon, 21 Aug 2017 14:10:31 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-62.pek2.redhat.com [10.72.12.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id A6E576CDBA; Mon, 21 Aug 2017 14:10:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com ABEF65F73C Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=famz@redhat.com From: Fam Zheng To: qemu-devel@nongnu.org Date: Mon, 21 Aug 2017 22:10:08 +0800 Message-Id: <20170821141008.19383-5-famz@redhat.com> In-Reply-To: <20170821141008.19383-1-famz@redhat.com> References: <20170821141008.19383-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 21 Aug 2017 14:10:31 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 4/4] scsi-block: Support rerror/werror X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This makes the werror/rerror options available on the scsi-block device, to allow user specify error handling policy similar to scsi-hd. Signed-off-by: Fam Zheng --- hw/scsi/scsi-disk.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 5f1e5e8070..cf38f93b9d 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -39,6 +39,7 @@ do { printf("scsi-disk: " fmt , ## __VA_ARGS__); } while = (0) #include "hw/block/block.h" #include "sysemu/dma.h" #include "qemu/cutils.h" +#include "scsi/scsi.h" =20 #ifdef __linux #include @@ -106,7 +107,7 @@ typedef struct SCSIDiskState bool tray_locked; } SCSIDiskState; =20 -static int scsi_handle_rw_error(SCSIDiskReq *r, int error, bool acct_faile= d); +static bool scsi_handle_rw_error(SCSIDiskReq *r, int error, bool acct_fail= ed); =20 static void scsi_free_request(SCSIRequest *req) { @@ -184,19 +185,10 @@ static bool scsi_disk_req_check_error(SCSIDiskReq *r,= int ret, bool acct_failed) return true; } =20 - if (ret < 0) { + if (ret < 0 || (r->status && *r->status)) { return scsi_handle_rw_error(r, -ret, acct_failed); } =20 - if (r->status && *r->status) { - if (acct_failed) { - SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, r->req.dev= ); - block_acct_failed(blk_get_stats(s->qdev.conf.blk), &r->acct); - } - scsi_req_complete(&r->req, *r->status); - return true; - } - return false; } =20 @@ -422,13 +414,13 @@ static void scsi_read_data(SCSIRequest *req) } =20 /* - * scsi_handle_rw_error has two return values. 0 means that the error - * must be ignored, 1 means that the error has been processed and the + * scsi_handle_rw_error has two return values. False means that the error + * must be ignored, true means that the error has been processed and the * caller should not do anything else for this request. Note that * scsi_handle_rw_error always manages its reference counts, independent * of the return value. */ -static int scsi_handle_rw_error(SCSIDiskReq *r, int error, bool acct_faile= d) +static bool scsi_handle_rw_error(SCSIDiskReq *r, int error, bool acct_fail= ed) { bool is_read =3D (r->req.cmd.mode =3D=3D SCSI_XFER_FROM_DEV); SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, r->req.dev); @@ -440,6 +432,11 @@ static int scsi_handle_rw_error(SCSIDiskReq *r, int er= ror, bool acct_failed) block_acct_failed(blk_get_stats(s->qdev.conf.blk), &r->acct); } switch (error) { + case 0: + /* The command has run, no need to fake sense. */ + assert(r->status && *r->status); + scsi_req_complete(&r->req, *r->status); + break; case ENOMEDIUM: scsi_check_condition(r, SENSE_CODE(NO_MEDIUM)); break; @@ -457,6 +454,18 @@ static int scsi_handle_rw_error(SCSIDiskReq *r, int er= ror, bool acct_failed) break; } } + if (!error) { + assert(r->status && *r->status); + error =3D scsi_sense_buf_to_errno(r->req.sense, sizeof(r->req.sens= e)); + + if (error =3D=3D ECANCELED || error =3D=3D EAGAIN || error =3D=3D = ENOTCONN || + error =3D=3D 0) { + /* These errors are handled by guest. */ + scsi_req_complete(&r->req, *r->status); + return true; + } + } + blk_error_action(s->qdev.conf.blk, action, is_read, error); if (action =3D=3D BLOCK_ERROR_ACTION_STOP) { scsi_req_retry(&r->req); @@ -2972,6 +2981,7 @@ static const TypeInfo scsi_cd_info =3D { =20 #ifdef __linux__ static Property scsi_block_properties[] =3D { + DEFINE_BLOCK_ERROR_PROPERTIES(SCSIDiskState, qdev.conf), \ DEFINE_PROP_DRIVE("drive", SCSIDiskState, qdev.conf.blk), DEFINE_PROP_END_OF_LIST(), }; --=20 2.13.5