mirror of https://github.com/proxmox/mirror_qemu
blockdev: Remove 'media' parameter from blockdev_init()
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> Reviewed-by: Eric Blake <eblake@redhat.com>master
parent
a9b43397a9
commit
e34ef04641
40
blockdev.c
40
blockdev.c
|
@ -309,8 +309,7 @@ typedef enum { MEDIA_DISK, MEDIA_CDROM } DriveMediaType;
|
||||||
|
|
||||||
/* Takes the ownership of bs_opts */
|
/* Takes the ownership of bs_opts */
|
||||||
static DriveInfo *blockdev_init(QDict *bs_opts,
|
static DriveInfo *blockdev_init(QDict *bs_opts,
|
||||||
BlockInterfaceType type,
|
BlockInterfaceType type)
|
||||||
DriveMediaType media)
|
|
||||||
{
|
{
|
||||||
const char *buf;
|
const char *buf;
|
||||||
const char *file = NULL;
|
const char *file = NULL;
|
||||||
|
@ -488,22 +487,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
|
||||||
bdrv_set_io_limits(dinfo->bdrv, &cfg);
|
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 (!file || !*file) {
|
||||||
if (has_driver_specific_opts) {
|
if (has_driver_specific_opts) {
|
||||||
file = NULL;
|
file = NULL;
|
||||||
|
@ -525,11 +508,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
|
||||||
bdrv_flags |= BDRV_O_INCOMING;
|
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;
|
bdrv_flags |= ro ? 0 : BDRV_O_RDWR;
|
||||||
|
|
||||||
if (ro && copy_on_read) {
|
if (ro && copy_on_read) {
|
||||||
|
@ -713,6 +691,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
|
||||||
media = MEDIA_DISK;
|
media = MEDIA_DISK;
|
||||||
} else if (!strcmp(value, "cdrom")) {
|
} else if (!strcmp(value, "cdrom")) {
|
||||||
media = MEDIA_CDROM;
|
media = MEDIA_CDROM;
|
||||||
|
qdict_put(bs_opts, "read-only", qstring_from_str("on"));
|
||||||
} else {
|
} else {
|
||||||
error_report("'%s' invalid media", value);
|
error_report("'%s' invalid media", value);
|
||||||
goto fail;
|
goto fail;
|
||||||
|
@ -860,7 +839,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Actual block device init: Functionality shared with blockdev-add */
|
/* 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) {
|
if (dinfo == NULL) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -878,6 +857,17 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
|
||||||
dinfo->unit = unit_id;
|
dinfo->unit = unit_id;
|
||||||
dinfo->devaddr = devaddr;
|
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:
|
fail:
|
||||||
qemu_opts_del(legacy_opts);
|
qemu_opts_del(legacy_opts);
|
||||||
return dinfo;
|
return dinfo;
|
||||||
|
@ -2176,7 +2166,7 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)
|
||||||
|
|
||||||
qdict_flatten(qdict);
|
qdict_flatten(qdict);
|
||||||
|
|
||||||
dinfo = blockdev_init(qdict, IF_NONE, MEDIA_DISK);
|
dinfo = blockdev_init(qdict, IF_NONE);
|
||||||
if (!dinfo) {
|
if (!dinfo) {
|
||||||
error_setg(errp, "Could not open image");
|
error_setg(errp, "Could not open image");
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
Loading…
Reference in New Issue