From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43217) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VMzIh-0002n6-FR for qemu-devel@nongnu.org; Fri, 20 Sep 2013 07:55:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VMzIb-0008OQ-En for qemu-devel@nongnu.org; Fri, 20 Sep 2013 07:55:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:2938) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VMzIb-0008Lr-60 for qemu-devel@nongnu.org; Fri, 20 Sep 2013 07:55:01 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r8KBt0eW015725 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 20 Sep 2013 07:55:00 -0400 From: Kevin Wolf Date: Fri, 20 Sep 2013 13:54:28 +0200 Message-Id: <1379678070-14346-16-git-send-email-kwolf@redhat.com> In-Reply-To: <1379678070-14346-1-git-send-email-kwolf@redhat.com> References: <1379678070-14346-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 15/17] blockdev: Remove 'media' parameter from blockdev_init() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, armbru@redhat.com, stefanha@redhat.com, mreitz@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 --- blockdev.c | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/blockdev.c b/blockdev.c index ed4ba65..afdeb34 100644 --- a/blockdev.c +++ b/blockdev.c @@ -306,8 +306,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; @@ -489,22 +488,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; @@ -526,11 +509,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) { @@ -714,6 +692,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; @@ -861,7 +840,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; } @@ -879,6 +858,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; @@ -2173,7 +2163,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