All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, kraxel@redhat.com
Subject: [Qemu-devel] [PATCH 12/13] blockdev: Factor option value parsers out of drive_init()
Date: Wed,  2 Jun 2010 18:55:28 +0200	[thread overview]
Message-ID: <1275497729-13120-13-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1275497729-13120-1-git-send-email-armbru@redhat.com>

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 <armbru@redhat.com>
---
 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;
         }
     }
-- 
1.6.6.1

  parent reply	other threads:[~2010-06-02 16:55 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-02 16:55 [Qemu-devel] [PATCH 00/13] New -blockdev to define a host block device Markus Armbruster
2010-06-02 16:55 ` [Qemu-devel] [PATCH 01/13] block: Move error actions from DriveInfo to BlockDriverState Markus Armbruster
2010-06-02 16:55 ` [Qemu-devel] [PATCH 02/13] block: Decouple block device "commit all" from DriveInfo Markus Armbruster
2010-06-02 16:55 ` [Qemu-devel] [PATCH 03/13] monitor: Make "commit FOO" complain when FOO doesn't exist Markus Armbruster
2010-06-02 16:55 ` [Qemu-devel] [PATCH 04/13] block: New bdrv_next() Markus Armbruster
2010-06-02 16:55 ` [Qemu-devel] [PATCH 05/13] block: Decouple savevm from DriveInfo Markus Armbruster
2010-06-02 16:55 ` [Qemu-devel] [PATCH 06/13] blockdev: Give drives internal linkage Markus Armbruster
2010-06-02 16:55 ` [Qemu-devel] [PATCH 07/13] blockdev: Means to destroy blockdev only if made with drive_init() Markus Armbruster
2010-06-10 14:19   ` [Qemu-devel] " Kevin Wolf
2010-06-10 16:00     ` Markus Armbruster
2010-06-02 16:55 ` [Qemu-devel] [PATCH 08/13] qdev: Decouple qdev_prop_drive from DriveInfo Markus Armbruster
2010-06-02 19:28   ` [Qemu-devel] " Gerd Hoffmann
2010-06-04  8:22     ` Markus Armbruster
2010-06-02 16:55 ` [Qemu-devel] [PATCH 09/13] blockdev: drive_get_by_id() is no longer used, remove Markus Armbruster
2010-06-02 16:55 ` [Qemu-devel] [PATCH 10/13] qemu-option: New qemu_opts_reset() Markus Armbruster
2010-06-02 16:55 ` [Qemu-devel] [PATCH 11/13] qemu-option: New qemu_opt_next(), qemu_opt_name() Markus Armbruster
2010-06-02 16:55 ` Markus Armbruster [this message]
2010-06-02 16:55 ` [Qemu-devel] [PATCH 13/13] blockdev: New -blockdev to define a host block device Markus Armbruster
2010-06-03  8:00   ` Christoph Hellwig
2010-06-04  8:23     ` Markus Armbruster
2010-06-10 15:32   ` [Qemu-devel] " Paolo Bonzini
2010-06-10 16:32     ` Markus Armbruster
2010-06-10 17:03       ` Paolo Bonzini
2010-06-14 14:46   ` [Qemu-devel] " Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1275497729-13120-13-git-send-email-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.