qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, armbru@redhat.com, stefanha@redhat.com
Subject: [Qemu-devel] [PATCH 6/7] block: Support driver specific options in drive_init()
Date: Fri,  1 Mar 2013 21:13:40 +0100	[thread overview]
Message-ID: <1362168821-25668-7-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1362168821-25668-1-git-send-email-kwolf@redhat.com>

Any non-default -drive options are now passed down to the block drivers.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 blockdev.c | 45 ++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 40 insertions(+), 5 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index d679174..1f896ca 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -22,6 +22,7 @@
 #include "sysemu/arch_init.h"
 
 static QTAILQ_HEAD(drivelist, DriveInfo) drives = QTAILQ_HEAD_INITIALIZER(drives);
+extern QemuOptsList qemu_common_drive_opts;
 
 static const char *const if_name[IF_COUNT] = {
     [IF_NONE] = "none",
@@ -287,7 +288,7 @@ static bool do_check_io_limits(BlockIOLimit *io_limits, Error **errp)
     return true;
 }
 
-DriveInfo *drive_init(QemuOpts *opts, BlockInterfaceType block_default_type)
+DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
 {
     const char *buf;
     const char *file = NULL;
@@ -310,10 +311,25 @@ DriveInfo *drive_init(QemuOpts *opts, BlockInterfaceType block_default_type)
     bool copy_on_read;
     int ret;
     Error *error = NULL;
+    QemuOpts *opts;
+    QDict *bs_opts;
 
     translation = BIOS_ATA_TRANSLATION_AUTO;
     media = MEDIA_DISK;
 
+    /* Check common options by copying from all_opts to opts, all other options
+     * are stored in bs_opts. */
+    opts = qemu_opts_create_nofail(&qemu_common_drive_opts);
+
+    bs_opts = qdict_new();
+    qemu_opts_to_qdict(all_opts, bs_opts);
+    qemu_opts_absorb_qdict(opts, bs_opts, &error);
+    if (error_is_set(&error)) {
+        qerror_report_err(error);
+        error_free(error);
+        return NULL;
+    }
+
     /* extract parameters */
     bus_id  = qemu_opt_get_number(opts, "bus", 0);
     unit_id = qemu_opt_get_number(opts, "unit", -1);
@@ -564,7 +580,7 @@ DriveInfo *drive_init(QemuOpts *opts, BlockInterfaceType block_default_type)
     dinfo->heads = heads;
     dinfo->secs = secs;
     dinfo->trans = translation;
-    dinfo->opts = opts;
+    dinfo->opts = all_opts;
     dinfo->refcount = 1;
     dinfo->serial = serial;
     QTAILQ_INSERT_TAIL(&drives, dinfo, next);
@@ -635,7 +651,9 @@ DriveInfo *drive_init(QemuOpts *opts, BlockInterfaceType block_default_type)
         error_report("warning: disabling copy_on_read on readonly drive");
     }
 
-    ret = bdrv_open(dinfo->bdrv, file, NULL, bdrv_flags, drv);
+    ret = bdrv_open(dinfo->bdrv, file, bs_opts, bdrv_flags, drv);
+    bs_opts = NULL;
+
     if (ret < 0) {
         if (ret == -EMEDIUMTYPE) {
             error_report("could not open disk image %s: not in %s format",
@@ -649,9 +667,14 @@ DriveInfo *drive_init(QemuOpts *opts, BlockInterfaceType block_default_type)
 
     if (bdrv_key_required(dinfo->bdrv))
         autostart = 0;
+
+    qemu_opts_del(opts);
+
     return dinfo;
 
 err:
+    qemu_opts_del(opts);
+    QDECREF(bs_opts);
     bdrv_delete(dinfo->bdrv);
     g_free(dinfo->id);
     QTAILQ_REMOVE(&drives, dinfo, next);
@@ -1461,9 +1484,9 @@ BlockJobInfoList *qmp_query_block_jobs(Error **errp)
     return dummy.next;
 }
 
-QemuOptsList qemu_drive_opts = {
+QemuOptsList qemu_common_drive_opts = {
     .name = "drive",
-    .head = QTAILQ_HEAD_INITIALIZER(qemu_drive_opts.head),
+    .head = QTAILQ_HEAD_INITIALIZER(qemu_common_drive_opts.head),
     .desc = {
         {
             .name = "bus",
@@ -1582,3 +1605,15 @@ QemuOptsList qemu_drive_opts = {
         { /* end of list */ }
     },
 };
+
+QemuOptsList qemu_drive_opts = {
+    .name = "drive",
+    .head = QTAILQ_HEAD_INITIALIZER(qemu_drive_opts.head),
+    .desc = {
+        /*
+         * no elements => accept any params
+         * validation will happen later
+         */
+        { /* end of list */ }
+    },
+};
-- 
1.8.1.2

  parent reply	other threads:[~2013-03-01 20:14 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-01 20:13 [Qemu-devel] [PATCH 0/7] block: Add driver specific options Kevin Wolf
2013-03-01 20:13 ` [Qemu-devel] [PATCH 1/7] block: Add options QDict to .bdrv_open() Kevin Wolf
2013-03-01 21:15   ` Eric Blake
2013-03-01 20:13 ` [Qemu-devel] [PATCH 2/7] block: Add options QDict to bdrv_open() prototype Kevin Wolf
2013-03-01 21:53   ` Eric Blake
2013-03-01 20:13 ` [Qemu-devel] [PATCH 3/7] Add qdict_clone_shallow() Kevin Wolf
2013-03-01 21:55   ` Eric Blake
2013-03-01 20:13 ` [Qemu-devel] [PATCH 4/7] block: Add options QDict to bdrv_open_common() Kevin Wolf
2013-03-01 22:01   ` Eric Blake
2013-03-04  9:28   ` Stefan Hajnoczi
2013-03-01 20:13 ` [Qemu-devel] [PATCH 5/7] qemu-option: Add qemu_opts_absorb_qdict() Kevin Wolf
2013-03-01 22:14   ` Eric Blake
2013-03-01 20:13 ` Kevin Wolf [this message]
2013-03-01 22:26   ` [Qemu-devel] [PATCH 6/7] block: Support driver specific options in drive_init() Eric Blake
2013-03-01 20:13 ` [Qemu-devel] [PATCH 7/7] qcow2: Allow lazy refcounts to be enabled on the command line Kevin Wolf
2013-03-01 22:28   ` Eric Blake
2013-03-04  9:29 ` [Qemu-devel] [PATCH 0/7] block: Add driver specific options Stefan Hajnoczi

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=1362168821-25668-7-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=armbru@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).