From patchwork Fri Aug 18 14:15:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 9909205 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 261FC602C8 for ; Fri, 18 Aug 2017 14:22:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0FC1728CCB for ; Fri, 18 Aug 2017 14:22:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 04CA528CDC; Fri, 18 Aug 2017 14:22:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 868CC28CCB for ; Fri, 18 Aug 2017 14:22:18 +0000 (UTC) Received: from localhost ([::1]:57093 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diiAD-0003GF-6d for patchwork-qemu-devel@patchwork.kernel.org; Fri, 18 Aug 2017 10:22:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54808) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dii3b-0006CC-6p for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:15:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dii3Z-0005xE-VR for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:15:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60184) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dii3Z-0005uv-LH for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:15:25 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8D874461D2 for ; Fri, 18 Aug 2017 14:15:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8D874461D2 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 Received: from lemon.redhat.com (ovpn-12-120.pek2.redhat.com [10.72.12.120]) by smtp.corp.redhat.com (Postfix) with ESMTP id 64A186364D; Fri, 18 Aug 2017 14:15:23 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 22:15:12 +0800 Message-Id: <20170818141512.15205-4-famz@redhat.com> In-Reply-To: <20170818141512.15205-1-famz@redhat.com> References: <20170818141512.15205-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 18 Aug 2017 14:15: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 v3 3/3] 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 | 54 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 5f1e5e8070..ec7dbe4a2d 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" #ifdef __linux #include @@ -106,7 +107,7 @@ typedef struct SCSIDiskState bool tray_locked; } SCSIDiskState; -static int scsi_handle_rw_error(SCSIDiskReq *r, int error, bool acct_failed); +static bool scsi_handle_rw_error(SCSIDiskReq *r, int error, bool acct_failed); 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; } - if (ret < 0) { + if (ret < 0 || (r->status && *r->status)) { return scsi_handle_rw_error(r, -ret, acct_failed); } - if (r->status && *r->status) { - if (acct_failed) { - SCSIDiskState *s = 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; } @@ -422,13 +414,13 @@ static void scsi_read_data(SCSIRequest *req) } /* - * 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_failed) +static bool scsi_handle_rw_error(SCSIDiskReq *r, int error, bool acct_failed) { bool is_read = (r->req.cmd.mode == SCSI_XFER_FROM_DEV); SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev); @@ -440,6 +432,11 @@ static int scsi_handle_rw_error(SCSIDiskReq *r, int error, 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,34 @@ static int scsi_handle_rw_error(SCSIDiskReq *r, int error, bool acct_failed) break; } } + if (!error) { + int key, asc, ascq; + assert(r->status && *r->status); + switch (r->req.sense[0]) { + case 0x70: /* Fixed format sense data. */ + key = r->req.sense[2] & 0xF; + asc = r->req.sense[12]; + ascq = r->req.sense[13]; + error = scsi_sense_to_errno(key, asc, ascq); + break; + case 0x72: /* Descriptor format sense data. */ + key = r->req.sense[1] & 0xF; + asc = r->req.sense[2]; + ascq = r->req.sense[3]; + error = scsi_sense_to_errno(key, asc, ascq); + break; + default: + error = EIO; + break; + } + + if (error == ECANCELED) { + /* Command aborted shouldn't stop the VM. */ + scsi_req_complete(&r->req, *r->status); + return true; + } + } + blk_error_action(s->qdev.conf.blk, action, is_read, error); if (action == BLOCK_ERROR_ACTION_STOP) { scsi_req_retry(&r->req); @@ -2972,6 +2997,7 @@ static const TypeInfo scsi_cd_info = { #ifdef __linux__ static Property scsi_block_properties[] = { + DEFINE_BLOCK_ERROR_PROPERTIES(SCSIDiskState, qdev.conf), \ DEFINE_PROP_DRIVE("drive", SCSIDiskState, qdev.conf.blk), DEFINE_PROP_END_OF_LIST(), };