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, benoit.canet@irqsave.net, armbru@redhat.com,
	mreitz@redhat.com, stefanha@redhat.com,
	xiawenc@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH v2 15/17] blockdev: Remove 'media' parameter from blockdev_init()
Date: Tue,  1 Oct 2013 15:20:17 +0200	[thread overview]
Message-ID: <1380633619-12213-16-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1380633619-12213-1-git-send-email-kwolf@redhat.com>

The remaining users shouldn't be there with blockdev-add and are easy to
move to drive_init().

Bonus bug fix: As a side effect, CD-ROM drives can now use block drivers
on the read-only whitelist without explicitly specifying read-only=on,
even if a format is explicitly specified.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
---
 blockdev.c | 40 +++++++++++++++-------------------------
 1 file changed, 15 insertions(+), 25 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index c465dff..bb6a1d5 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -309,8 +309,7 @@ typedef enum { MEDIA_DISK, MEDIA_CDROM } DriveMediaType;
 
 /* Takes the ownership of bs_opts */
 static DriveInfo *blockdev_init(QDict *bs_opts,
-                                BlockInterfaceType type,
-                                DriveMediaType media)
+                                BlockInterfaceType type)
 {
     const char *buf;
     const char *file = NULL;
@@ -492,22 +491,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
         bdrv_set_io_limits(dinfo->bdrv, &cfg);
     }
 
-    switch(type) {
-    case IF_IDE:
-    case IF_SCSI:
-    case IF_XEN:
-    case IF_NONE:
-        dinfo->media_cd = media == MEDIA_CDROM;
-        break;
-    case IF_SD:
-    case IF_FLOPPY:
-    case IF_PFLASH:
-    case IF_MTD:
-    case IF_VIRTIO:
-        break;
-    default:
-        abort();
-    }
     if (!file || !*file) {
         if (has_driver_specific_opts) {
             file = NULL;
@@ -529,11 +512,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
         bdrv_flags |= BDRV_O_INCOMING;
     }
 
-    if (media == MEDIA_CDROM) {
-        /* CDROM is fine for any interface, don't check.  */
-        ro = 1;
-    }
-
     bdrv_flags |= ro ? 0 : BDRV_O_RDWR;
 
     if (ro && copy_on_read) {
@@ -717,6 +695,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
             media = MEDIA_DISK;
         } else if (!strcmp(value, "cdrom")) {
             media = MEDIA_CDROM;
+            qdict_put(bs_opts, "read-only", qstring_from_str("on"));
         } else {
             error_report("'%s' invalid media", value);
             goto fail;
@@ -864,7 +843,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
     }
 
     /* Actual block device init: Functionality shared with blockdev-add */
-    dinfo = blockdev_init(bs_opts, type, media);
+    dinfo = blockdev_init(bs_opts, type);
     if (dinfo == NULL) {
         goto fail;
     }
@@ -882,6 +861,17 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
     dinfo->unit = unit_id;
     dinfo->devaddr = devaddr;
 
+    switch(type) {
+    case IF_IDE:
+    case IF_SCSI:
+    case IF_XEN:
+    case IF_NONE:
+        dinfo->media_cd = media == MEDIA_CDROM;
+        break;
+    default:
+        break;
+    }
+
 fail:
     qemu_opts_del(legacy_opts);
     return dinfo;
@@ -2176,7 +2166,7 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)
 
     qdict_flatten(qdict);
 
-    dinfo = blockdev_init(qdict, IF_NONE, MEDIA_DISK);
+    dinfo = blockdev_init(qdict, IF_NONE);
     if (!dinfo) {
         error_setg(errp, "Could not open image");
         goto fail;
-- 
1.8.1.4

  parent reply	other threads:[~2013-10-01 13:21 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-01 13:20 [Qemu-devel] [PATCH v2 00/17] blockdev-add QMP command Kevin Wolf
2013-10-01 13:20 ` [Qemu-devel] [PATCH v2 01/17] qapi-types/visit.py: Pass whole expr dict for structs Kevin Wolf
2013-10-01 13:20 ` [Qemu-devel] [PATCH v2 02/17] qapi-types/visit.py: Inheritance " Kevin Wolf
2013-10-01 15:21   ` Eric Blake
2013-10-01 13:20 ` [Qemu-devel] [PATCH v2 03/17] blockdev: Introduce DriveInfo.enable_auto_del Kevin Wolf
2013-10-01 13:20 ` [Qemu-devel] [PATCH v2 04/17] blockdev: 'blockdev-add' QMP command Kevin Wolf
2013-10-01 14:00   ` Benoît Canet
2013-10-01 15:41   ` Eric Blake
2013-10-01 13:20 ` [Qemu-devel] [PATCH v2 05/17] blockdev: Separate ID generation from DriveInfo creation Kevin Wolf
2013-10-01 13:20 ` [Qemu-devel] [PATCH v2 06/17] blockdev: Pass QDict to blockdev_init() Kevin Wolf
2013-10-01 15:53   ` Eric Blake
2013-10-01 13:20 ` [Qemu-devel] [PATCH v2 07/17] blockdev: Move parsing of 'media' option to drive_init Kevin Wolf
2013-10-01 15:57   ` Eric Blake
2013-10-01 13:20 ` [Qemu-devel] [PATCH v2 08/17] blockdev: Move parsing of 'if' " Kevin Wolf
2013-10-01 14:44   ` Benoît Canet
2013-10-01 16:01   ` Eric Blake
2013-10-01 13:20 ` [Qemu-devel] [PATCH v2 09/17] blockdev: Moving parsing of geometry options " Kevin Wolf
2013-10-01 16:09   ` Eric Blake
2013-10-01 13:20 ` [Qemu-devel] [PATCH v2 10/17] blockdev: Move parsing of 'boot' option " Kevin Wolf
2013-10-01 16:19   ` Eric Blake
2013-10-01 13:20 ` [Qemu-devel] [PATCH v2 11/17] blockdev: Move bus/unit/index processing " Kevin Wolf
2013-10-01 16:25   ` Eric Blake
2013-10-01 13:20 ` [Qemu-devel] [PATCH v2 12/17] blockdev: Move virtio-blk device creation " Kevin Wolf
2013-10-01 16:34   ` Eric Blake
2013-10-01 13:20 ` [Qemu-devel] [PATCH v2 13/17] blockdev: Remove IF_* check for read-only blockdev_init Kevin Wolf
2013-10-01 16:51   ` Eric Blake
2013-10-01 13:20 ` [Qemu-devel] [PATCH v2 14/17] qemu-iotests: Check autodel behaviour for device_del Kevin Wolf
2013-10-01 17:06   ` Eric Blake
2013-10-08  9:44     ` Kevin Wolf
2013-10-01 13:20 ` Kevin Wolf [this message]
2013-10-01 17:07   ` [Qemu-devel] [PATCH v2 15/17] blockdev: Remove 'media' parameter from blockdev_init() Eric Blake
2013-10-01 13:20 ` [Qemu-devel] [PATCH v2 16/17] blockdev: Don't disable COR automatically with blockdev-add Kevin Wolf
2013-10-01 17:09   ` Eric Blake
2013-10-01 13:20 ` [Qemu-devel] [PATCH v2 17/17] blockdev: blockdev_init() error conversion Kevin Wolf
2013-10-01 17:11   ` Eric Blake
2013-10-01 15:41 ` [Qemu-devel] [PATCH v2 00/17] blockdev-add QMP command Eric Blake
2013-10-01 15:50   ` Kevin Wolf
2013-10-01 15:54     ` Eric Blake

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=1380633619-12213-16-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=armbru@redhat.com \
    --cc=benoit.canet@irqsave.net \
    --cc=mreitz@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=xiawenc@linux.vnet.ibm.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).