From patchwork Wed Jun 2 16:55:28 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 54395 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 052E3B7D4C for ; Thu, 3 Jun 2010 03:13:57 +1000 (EST) Received: from localhost ([127.0.0.1]:60742 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OJrVp-0001dU-VX for incoming@patchwork.ozlabs.org; Wed, 02 Jun 2010 13:13:54 -0400 Received: from [140.186.70.92] (port=40081 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OJrEK-0007R7-HI for qemu-devel@nongnu.org; Wed, 02 Jun 2010 12:55:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OJrE4-0005hb-NW for qemu-devel@nongnu.org; Wed, 02 Jun 2010 12:55:44 -0400 Received: from oxygen.pond.sub.org ([213.239.205.148]:35287) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OJrE4-0005gi-Em for qemu-devel@nongnu.org; Wed, 02 Jun 2010 12:55:32 -0400 Received: from blackfin.pond.sub.org (pD9E39C24.dip.t-dialin.net [217.227.156.36]) by oxygen.pond.sub.org (Postfix) with ESMTPA id E8E5E2E2B25 for ; Wed, 2 Jun 2010 18:55:30 +0200 (CEST) Received: by blackfin.pond.sub.org (Postfix, from userid 500) id D09D63FC; Wed, 2 Jun 2010 18:55:29 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Wed, 2 Jun 2010 18:55:28 +0200 Message-Id: <1275497729-13120-13-git-send-email-armbru@redhat.com> X-Mailer: git-send-email 1.6.6.1 In-Reply-To: <1275497729-13120-1-git-send-email-armbru@redhat.com> References: <1275497729-13120-1-git-send-email-armbru@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) Cc: kwolf@redhat.com, kraxel@redhat.com Subject: [Qemu-devel] [PATCH 12/13] blockdev: Factor option value parsers out of drive_init() 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 The new functions use qerror_report() to make them usable from QMP-enabled monitor commands. They'll appear in a future patch series. Signed-off-by: Markus Armbruster --- blockdev.c | 130 +++++++++++++++++++++++++++++++++++++++-------------------- 1 files changed, 86 insertions(+), 44 deletions(-) diff --git a/blockdev.c b/blockdev.c index 8c51e6e..a1e6394 100644 --- a/blockdev.c +++ b/blockdev.c @@ -21,6 +21,83 @@ static QTAILQ_HEAD(drivelist, DriveInfo) drives = QTAILQ_HEAD_INITIALIZER(drives); +static BlockDriver *parse_block_format(const char *val) +{ + BlockDriver *drv = bdrv_find_whitelisted_format(val); + if (!drv) { + qerror_report(QERR_INVALID_PARAMETER_VALUE, + "format", "a block driver name"); + return NULL; + } + return drv; +} + +static int parse_block_error_action(const char *val, int is_read) +{ + if (!val) { + return is_read ? BLOCK_ERR_REPORT : BLOCK_ERR_STOP_ENOSPC; + } else if (!strcmp(val, "ignore")) { + return BLOCK_ERR_IGNORE; + } else if (!is_read && !strcmp(val, "enospc")) { + return BLOCK_ERR_STOP_ENOSPC; + } else if (!strcmp(val, "stop")) { + return BLOCK_ERR_STOP_ANY; + } else if (!strcmp(val, "report")) { + return BLOCK_ERR_REPORT; + } else { + if (is_read) { + qerror_report(QERR_INVALID_PARAMETER_VALUE, "rerror", + "ignore, report, stop"); + } else { + qerror_report(QERR_INVALID_PARAMETER_VALUE, "werror", + "enospc, ignore, stop or report"); + } + return -1; + } +} + +static int parse_block_cache(const char *val) +{ + if (!val) { + return 0; + } else if (!strcmp(val, "off") || !strcmp(val, "none")) { + return BDRV_O_NOCACHE; + } else if (!strcmp(val, "writeback")) { + return BDRV_O_CACHE_WB; + } else if (!strcmp(val, "unsafe")) { + return BDRV_O_CACHE_WB; + return BDRV_O_NO_FLUSH; + } else if (!strcmp(val, "writethrough")) { + return 0; + } else { + qerror_report(QERR_INVALID_PARAMETER_VALUE, "cache", + "none, unsafe, writeback or writethrough"); + return -1; + } +} + +static int parse_block_aio(const char *val) +{ + if (!val) { + return 0; +#ifdef CONFIG_LINUX_AIO + } else if (!strcmp(val, "native")) { + return BDRV_O_NATIVE_AIO; +#endif + } else if (!strcmp(val, "threads")) { + return 0; + } else { + qerror_report(QERR_INVALID_PARAMETER_VALUE, "aio", +#ifdef CONFIG_LINUX_AIO + "native or threads" +#else + "threads" +#endif + ); + return -1; + } +} + static int blockdev_del_dinfo(BlockDriverState *bs) { DriveInfo *dinfo, *next_dinfo; @@ -126,23 +203,6 @@ 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, int default_to_scsi, int *fatal_error) { const char *buf; @@ -280,34 +340,17 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error) } } - if ((buf = qemu_opt_get(opts, "cache")) != NULL) { - if (!strcmp(buf, "off") || !strcmp(buf, "none")) { - bdrv_flags |= BDRV_O_NOCACHE; - } else if (!strcmp(buf, "writeback")) { - bdrv_flags |= BDRV_O_CACHE_WB; - } else if (!strcmp(buf, "unsafe")) { - bdrv_flags |= BDRV_O_CACHE_WB; - bdrv_flags |= BDRV_O_NO_FLUSH; - } else if (!strcmp(buf, "writethrough")) { - /* this is the default */ - } else { - fprintf(stderr, "qemu: invalid cache option\n"); - return NULL; - } + ret = parse_block_cache(qemu_opt_get(opts, "cache")); + if (ret < 0) { + return NULL; } + bdrv_flags |= ret; -#ifdef CONFIG_LINUX_AIO - if ((buf = qemu_opt_get(opts, "aio")) != NULL) { - if (!strcmp(buf, "native")) { - bdrv_flags |= BDRV_O_NATIVE_AIO; - } else if (!strcmp(buf, "threads")) { - /* this is the default */ - } else { - fprintf(stderr, "qemu: invalid aio option\n"); - return NULL; - } + ret = parse_block_aio(qemu_opt_get(opts, "aio")); + if (ret < 0) { + return NULL; } -#endif + bdrv_flags |= ret; if ((buf = qemu_opt_get(opts, "format")) != NULL) { if (strcmp(buf, "?") == 0) { @@ -316,9 +359,8 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error) fprintf(stderr, "\n"); return NULL; } - drv = bdrv_find_whitelisted_format(buf); + drv = parse_block_format(buf); if (!drv) { - fprintf(stderr, "qemu: '%s' invalid format\n", buf); return NULL; } }