From patchwork Fri Nov 27 12:25:37 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 39625 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 1A5271007D1 for ; Fri, 27 Nov 2009 23:33:22 +1100 (EST) Received: from localhost ([127.0.0.1]:39598 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NE00k-0002R4-MI for incoming@patchwork.ozlabs.org; Fri, 27 Nov 2009 07:33:18 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NDzua-0007ws-Ew for qemu-devel@nongnu.org; Fri, 27 Nov 2009 07:26:56 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NDzuV-0007qa-OE for qemu-devel@nongnu.org; Fri, 27 Nov 2009 07:26:55 -0500 Received: from [199.232.76.173] (port=41466 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDzuV-0007qJ-EC for qemu-devel@nongnu.org; Fri, 27 Nov 2009 07:26:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:11471) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NDzuU-0007Ki-Vp for qemu-devel@nongnu.org; Fri, 27 Nov 2009 07:26:51 -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 nARCQoAr018924 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 27 Nov 2009 07:26:50 -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 nARCQin5002824; Fri, 27 Nov 2009 07:26:48 -0500 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Fri, 27 Nov 2009 13:25:37 +0100 Message-Id: <1259324739-6805-3-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 2/4] Introduce rerror option for drives 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 rerror controls the action to be taken when an error occurs while accessing the guest image file. It corresponds to werror which already controls the action take for write errors. This purely introduces parsing rerror command line option into the right structures, real support for it in the device emulation is added in the following patches. Signed-off-by: Kevin Wolf --- qemu-config.c | 3 ++ sysemu.h | 1 + vl.c | 59 ++++++++++++++++++++++++++++++++++++++------------------ 3 files changed, 44 insertions(+), 19 deletions(-) diff --git a/qemu-config.c b/qemu-config.c index 590fc05..92b5363 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -65,6 +65,9 @@ QemuOptsList qemu_drive_opts = { .name = "serial", .type = QEMU_OPT_STRING, },{ + .name = "rerror", + .type = QEMU_OPT_STRING, + },{ .name = "werror", .type = QEMU_OPT_STRING, },{ diff --git a/sysemu.h b/sysemu.h index 522d9af..629d7e5 100644 --- a/sysemu.h +++ b/sysemu.h @@ -172,6 +172,7 @@ typedef struct DriveInfo { int bus; int unit; QemuOpts *opts; + BlockInterfaceErrorAction on_read_error; BlockInterfaceErrorAction on_write_error; char serial[BLOCK_SERIAL_STRLEN + 1]; QTAILQ_ENTRY(DriveInfo) next; diff --git a/vl.c b/vl.c index ecfecb3..5b5dc60 100644 --- a/vl.c +++ b/vl.c @@ -1965,16 +1965,12 @@ BlockInterfaceErrorAction drive_get_on_error( { DriveInfo *dinfo; - if (is_read) { - return BLOCK_ERR_REPORT; - } - QTAILQ_FOREACH(dinfo, &drives, next) { if (dinfo->bdrv == bdrv) - return dinfo->on_write_error; + return is_read ? dinfo->on_read_error : dinfo->on_write_error; } - return BLOCK_ERR_STOP_ENOSPC; + return is_read ? BLOCK_ERR_REPORT : BLOCK_ERR_STOP_ENOSPC; } static void bdrv_format_print(void *opaque, const char *name) @@ -1990,6 +1986,23 @@ void drive_uninit(DriveInfo *dinfo) qemu_free(dinfo); } +static int parse_block_error_action(const char *buf, int is_read) +{ + if (!strcmp(buf, "ignore")) { + return BLOCK_ERR_IGNORE; + } else if (!is_read && !strcmp(buf, "enospc")) { + return BLOCK_ERR_STOP_ENOSPC; + } else if (!strcmp(buf, "stop")) { + return BLOCK_ERR_STOP_ANY; + } else if (!strcmp(buf, "report")) { + return BLOCK_ERR_REPORT; + } else { + fprintf(stderr, "qemu: '%s' invalid %s error action\n", + buf, is_read ? "read" : "write"); + return -1; + } +} + DriveInfo *drive_init(QemuOpts *opts, void *opaque, int *fatal_error) { @@ -2009,7 +2022,8 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque, int cache; int aio = 0; int ro = 0; - int bdrv_flags, onerror; + int bdrv_flags; + int on_read_error, on_write_error; const char *devaddr; DriveInfo *dinfo; int snapshot = 0; @@ -2170,22 +2184,28 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque, } } - onerror = BLOCK_ERR_STOP_ENOSPC; + on_write_error = BLOCK_ERR_STOP_ENOSPC; if ((buf = qemu_opt_get(opts, "werror")) != NULL) { if (type != IF_IDE && type != IF_SCSI && type != IF_VIRTIO) { fprintf(stderr, "werror is no supported by this format\n"); return NULL; } - if (!strcmp(buf, "ignore")) - onerror = BLOCK_ERR_IGNORE; - else if (!strcmp(buf, "enospc")) - onerror = BLOCK_ERR_STOP_ENOSPC; - else if (!strcmp(buf, "stop")) - onerror = BLOCK_ERR_STOP_ANY; - else if (!strcmp(buf, "report")) - onerror = BLOCK_ERR_REPORT; - else { - fprintf(stderr, "qemu: '%s' invalid write error action\n", buf); + + on_write_error = parse_block_error_action(buf, 0); + if (on_write_error < 0) { + return NULL; + } + } + + on_read_error = BLOCK_ERR_REPORT; + if ((buf = qemu_opt_get(opts, "rerror")) != NULL) { + if (1) { + fprintf(stderr, "rerror is no supported by this format\n"); + return NULL; + } + + on_read_error = parse_block_error_action(buf, 1); + if (on_read_error < 0) { return NULL; } } @@ -2269,7 +2289,8 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque, dinfo->type = type; dinfo->bus = bus_id; dinfo->unit = unit_id; - dinfo->on_write_error = onerror; + dinfo->on_read_error = on_read_error; + dinfo->on_write_error = on_write_error; dinfo->opts = opts; if (serial) strncpy(dinfo->serial, serial, sizeof(serial));