Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JRqr8-0002OI-EJ for qemu-devel@nongnu.org; Wed, 20 Feb 2008 10:27:34 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JRqr4-0002I5-Fq for qemu-devel@nongnu.org; Wed, 20 Feb 2008 10:27:34 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JRqr4-0002Hm-9t for qemu-devel@nongnu.org; Wed, 20 Feb 2008 10:27:30 -0500 Received: from smtp02.citrix.com ([66.165.176.63]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JRqr2-0008PM-9C for qemu-devel@nongnu.org; Wed, 20 Feb 2008 10:27:30 -0500 Received: from mariner.uk.xensource.com (mariner.uk.xensource.com [172.31.17.38]) by smtp01.ad.xensource.com (8.13.1/8.13.1) with ESMTP id m1KFQhEA010629 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Wed, 20 Feb 2008 07:26:45 -0800 Received: from iwj by mariner.uk.xensource.com with local (Exim 4.63) (envelope-from ) id 1JRqqH-0008Kv-TL for qemu-devel@nongnu.org; Wed, 20 Feb 2008 15:26:41 +0000 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="ugAAyJjsGE" Content-Transfer-Encoding: 7bit Message-ID: <18364.18097.675405.220217@mariner.uk.xensource.com> Date: Wed, 20 Feb 2008 15:26:41 +0000 From: Ian Jackson Subject: [Qemu-devel] [PATCH] ide.c error checking Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org --ugAAyJjsGE Content-Type: text/plain; charset=us-ascii Content-Description: message body text Content-Transfer-Encoding: 7bit The attached patch makes the ide emulation actually take notice of error returns from bdrv_write and bdrv_aio_{read,write}. Ian. --ugAAyJjsGE Content-Type: text/plain Content-Description: check errors from various IDE operations Content-Disposition: inline; filename="qemu-ide-errorcheck.patch" Content-Transfer-Encoding: 7bit diff --git a/block.c b/block.c diff --git a/hw/ide.c b/hw/ide.c index 25f5b9f..370a412 100644 --- a/hw/ide.c +++ b/hw/ide.c @@ -792,6 +792,11 @@ static void ide_set_sector(IDEState *s, int64_t sector_num) } } +static void ide_rw_error(IDEState *s) { + ide_abort_command(s); + ide_set_irq(s); +} + static void ide_sector_read(IDEState *s) { int64_t sector_num; @@ -811,6 +816,10 @@ static void ide_sector_read(IDEState *s) if (n > s->req_nb_sectors) n = s->req_nb_sectors; ret = bdrv_read(s->bs, sector_num, s->io_buffer, n); + if (ret != 0) { + ide_rw_error(s); + return; + } ide_transfer_start(s, s->io_buffer, 512 * n, ide_sector_read); ide_set_irq(s); ide_set_sector(s, sector_num + n); @@ -818,6 +827,14 @@ static void ide_sector_read(IDEState *s) } } +static void ide_dma_error(IDEState *s) +{ + ide_transfer_stop(s); + s->error = ABRT_ERR; + s->status = READY_STAT | ERR_STAT; + ide_set_irq(s); +} + /* return 0 if buffer completed */ static int dma_buf_rw(BMDMAState *bm, int is_write) { @@ -866,7 +883,6 @@ static int dma_buf_rw(BMDMAState *bm, int is_write) return 1; } -/* XXX: handle errors */ static void ide_read_dma_cb(void *opaque, int ret) { BMDMAState *bm = opaque; @@ -874,6 +890,11 @@ static void ide_read_dma_cb(void *opaque, int ret) int n; int64_t sector_num; + if (ret < 0) { + ide_dma_error(s); + return; + } + n = s->io_buffer_size >> 9; sector_num = ide_get_sector(s); if (n > 0) { @@ -938,6 +959,11 @@ static void ide_sector_write(IDEState *s) if (n > s->req_nb_sectors) n = s->req_nb_sectors; ret = bdrv_write(s->bs, sector_num, s->io_buffer, n); + if (ret != 0) { + ide_rw_error(s); + return; + } + s->nsector -= n; if (s->nsector == 0) { /* no more sectors to write */ @@ -967,7 +993,6 @@ static void ide_sector_write(IDEState *s) } } -/* XXX: handle errors */ static void ide_write_dma_cb(void *opaque, int ret) { BMDMAState *bm = opaque; @@ -975,6 +1000,11 @@ static void ide_write_dma_cb(void *opaque, int ret) int n; int64_t sector_num; + if (ret < 0) { + ide_dma_error(s); + return; + } + n = s->io_buffer_size >> 9; sector_num = ide_get_sector(s); if (n > 0) { --ugAAyJjsGE--