From patchwork Fri Nov 27 12:25:38 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 39626 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B2C8E1007D1 for ; Fri, 27 Nov 2009 23:36:36 +1100 (EST) Received: from localhost ([127.0.0.1]:40665 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NE03t-0004Cm-9k for incoming@patchwork.ozlabs.org; Fri, 27 Nov 2009 07:36:33 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NDzuc-0007yE-NL for qemu-devel@nongnu.org; Fri, 27 Nov 2009 07:26:58 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NDzuX-0007tT-CA for qemu-devel@nongnu.org; Fri, 27 Nov 2009 07:26:57 -0500 Received: from [199.232.76.173] (port=41467 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDzuX-0007tO-6e for qemu-devel@nongnu.org; Fri, 27 Nov 2009 07:26:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:6195) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NDzuW-0007Ku-MQ for qemu-devel@nongnu.org; Fri, 27 Nov 2009 07:26:52 -0500 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nARCQqMU012567 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 27 Nov 2009 07:26:52 -0500 Received: from localhost.localdomain (vpn2-8-149.ams2.redhat.com [10.36.8.149]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nARCQin6002824; Fri, 27 Nov 2009 07:26:50 -0500 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Fri, 27 Nov 2009 13:25:38 +0100 Message-Id: <1259324739-6805-4-git-send-email-kwolf@redhat.com> In-Reply-To: <1259324739-6805-1-git-send-email-kwolf@redhat.com> References: <1259324739-6805-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Kevin Wolf Subject: [Qemu-devel] [PATCH 3/4] ide: Implement rerror option X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Kevin Wolf --- hw/ide/core.c | 54 ++++++++++++++++++++++++++++++++++++---------------- hw/ide/internal.h | 1 + vl.c | 2 +- 3 files changed, 39 insertions(+), 18 deletions(-) diff --git a/hw/ide/core.c b/hw/ide/core.c index 49bbdcd..a5b00ae 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -61,8 +61,9 @@ static inline int media_is_cd(IDEState *s) } static void ide_dma_start(IDEState *s, BlockDriverCompletionFunc *dma_cb); -static void ide_dma_restart(IDEState *s); +static void ide_dma_restart(IDEState *s, int is_read); static void ide_atapi_cmd_read_dma_cb(void *opaque, int ret); +static int ide_handle_rw_error(IDEState *s, int error, int op); static void padstr(char *str, const char *src, int len) { @@ -407,8 +408,11 @@ static void ide_sector_read(IDEState *s) n = s->req_nb_sectors; ret = bdrv_read(s->bs, sector_num, s->io_buffer, n); if (ret != 0) { - ide_rw_error(s); - return; + if (ide_handle_rw_error(s, -ret, + BM_STATUS_PIO_RETRY | BM_STATUS_RETRY_READ)) + { + return; + } } ide_transfer_start(s, s->io_buffer, 512 * n, ide_sector_read); ide_set_irq(s->bus); @@ -471,9 +475,10 @@ void ide_dma_error(IDEState *s) ide_set_irq(s->bus); } -static int ide_handle_write_error(IDEState *s, int error, int op) +static int ide_handle_rw_error(IDEState *s, int error, int op) { - BlockInterfaceErrorAction action = drive_get_on_error(s->bs, 0); + int is_read = (op & BM_STATUS_RETRY_READ); + BlockInterfaceErrorAction action = drive_get_on_error(s->bs, is_read); if (action == BLOCK_ERR_IGNORE) return 0; @@ -484,7 +489,7 @@ static int ide_handle_write_error(IDEState *s, int error, int op) s->bus->bmdma->status |= op; vm_stop(0); } else { - if (op == BM_STATUS_DMA_RETRY) { + if (op & BM_STATUS_DMA_RETRY) { dma_buf_commit(s, 0); ide_dma_error(s); } else { @@ -551,9 +556,11 @@ static void ide_read_dma_cb(void *opaque, int ret) int64_t sector_num; if (ret < 0) { - dma_buf_commit(s, 1); - ide_dma_error(s); - return; + if (ide_handle_rw_error(s, -ret, + BM_STATUS_DMA_RETRY | BM_STATUS_RETRY_READ)) + { + return; + } } n = s->io_buffer_size >> 9; @@ -622,7 +629,7 @@ static void ide_sector_write(IDEState *s) ret = bdrv_write(s->bs, sector_num, s->io_buffer, n); if (ret != 0) { - if (ide_handle_write_error(s, -ret, BM_STATUS_PIO_RETRY)) + if (ide_handle_rw_error(s, -ret, BM_STATUS_PIO_RETRY)) return; } @@ -658,16 +665,23 @@ static void ide_sector_write(IDEState *s) static void ide_dma_restart_bh(void *opaque) { BMDMAState *bm = opaque; + int is_read; qemu_bh_delete(bm->bh); bm->bh = NULL; + is_read = !!(bm->status & BM_STATUS_RETRY_READ); + if (bm->status & BM_STATUS_DMA_RETRY) { - bm->status &= ~BM_STATUS_DMA_RETRY; - ide_dma_restart(bmdma_active_if(bm)); + bm->status &= ~(BM_STATUS_DMA_RETRY | BM_STATUS_RETRY_READ); + ide_dma_restart(bmdma_active_if(bm), is_read); } else if (bm->status & BM_STATUS_PIO_RETRY) { - bm->status &= ~BM_STATUS_PIO_RETRY; - ide_sector_write(bmdma_active_if(bm)); + bm->status &= ~(BM_STATUS_PIO_RETRY | BM_STATUS_RETRY_READ); + if (is_read) { + ide_sector_read(bmdma_active_if(bm)); + } else { + ide_sector_write(bmdma_active_if(bm)); + } } } @@ -692,7 +706,7 @@ static void ide_write_dma_cb(void *opaque, int ret) int64_t sector_num; if (ret < 0) { - if (ide_handle_write_error(s, -ret, BM_STATUS_DMA_RETRY)) + if (ide_handle_rw_error(s, -ret, BM_STATUS_DMA_RETRY)) return; } @@ -2715,7 +2729,7 @@ static void ide_dma_start(IDEState *s, BlockDriverCompletionFunc *dma_cb) } } -static void ide_dma_restart(IDEState *s) +static void ide_dma_restart(IDEState *s, int is_read) { BMDMAState *bm = s->bus->bmdma; ide_set_sector(s, bm->sector_num); @@ -2723,7 +2737,13 @@ static void ide_dma_restart(IDEState *s) s->io_buffer_size = 0; s->nsector = bm->nsector; bm->cur_addr = bm->addr; - bm->dma_cb = ide_write_dma_cb; + + if (is_read) { + bm->dma_cb = ide_read_dma_cb; + } else { + bm->dma_cb = ide_write_dma_cb; + } + ide_dma_start(s, bm->dma_cb); } diff --git a/hw/ide/internal.h b/hw/ide/internal.h index 567616e..f937daa 100644 --- a/hw/ide/internal.h +++ b/hw/ide/internal.h @@ -464,6 +464,7 @@ struct IDEDeviceInfo { #define BM_STATUS_INT 0x04 #define BM_STATUS_DMA_RETRY 0x08 #define BM_STATUS_PIO_RETRY 0x10 +#define BM_STATUS_RETRY_READ 0x20 #define BM_CMD_START 0x01 #define BM_CMD_READ 0x08 diff --git a/vl.c b/vl.c index 5b5dc60..0136d16 100644 --- a/vl.c +++ b/vl.c @@ -2199,7 +2199,7 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque, on_read_error = BLOCK_ERR_REPORT; if ((buf = qemu_opt_get(opts, "rerror")) != NULL) { - if (1) { + if (type != IF_IDE) { fprintf(stderr, "rerror is no supported by this format\n"); return NULL; }