Skip to content

Commit e34ef04

Browse files
committed
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 <[email protected]> Reviewed-by: Max Reitz <[email protected]> Reviewed-by: Eric Blake <[email protected]>
1 parent a9b4339 commit e34ef04

File tree

1 file changed

+15
-25
lines changed

1 file changed

+15
-25
lines changed

blockdev.c

+15-25
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,7 @@ typedef enum { MEDIA_DISK, MEDIA_CDROM } DriveMediaType;
309309

310310
/* Takes the ownership of bs_opts */
311311
static DriveInfo *blockdev_init(QDict *bs_opts,
312-
BlockInterfaceType type,
313-
DriveMediaType media)
312+
BlockInterfaceType type)
314313
{
315314
const char *buf;
316315
const char *file = NULL;
@@ -488,22 +487,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
488487
bdrv_set_io_limits(dinfo->bdrv, &cfg);
489488
}
490489

491-
switch(type) {
492-
case IF_IDE:
493-
case IF_SCSI:
494-
case IF_XEN:
495-
case IF_NONE:
496-
dinfo->media_cd = media == MEDIA_CDROM;
497-
break;
498-
case IF_SD:
499-
case IF_FLOPPY:
500-
case IF_PFLASH:
501-
case IF_MTD:
502-
case IF_VIRTIO:
503-
break;
504-
default:
505-
abort();
506-
}
507490
if (!file || !*file) {
508491
if (has_driver_specific_opts) {
509492
file = NULL;
@@ -525,11 +508,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
525508
bdrv_flags |= BDRV_O_INCOMING;
526509
}
527510

528-
if (media == MEDIA_CDROM) {
529-
/* CDROM is fine for any interface, don't check. */
530-
ro = 1;
531-
}
532-
533511
bdrv_flags |= ro ? 0 : BDRV_O_RDWR;
534512

535513
if (ro && copy_on_read) {
@@ -713,6 +691,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
713691
media = MEDIA_DISK;
714692
} else if (!strcmp(value, "cdrom")) {
715693
media = MEDIA_CDROM;
694+
qdict_put(bs_opts, "read-only", qstring_from_str("on"));
716695
} else {
717696
error_report("'%s' invalid media", value);
718697
goto fail;
@@ -860,7 +839,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
860839
}
861840

862841
/* Actual block device init: Functionality shared with blockdev-add */
863-
dinfo = blockdev_init(bs_opts, type, media);
842+
dinfo = blockdev_init(bs_opts, type);
864843
if (dinfo == NULL) {
865844
goto fail;
866845
}
@@ -878,6 +857,17 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
878857
dinfo->unit = unit_id;
879858
dinfo->devaddr = devaddr;
880859

860+
switch(type) {
861+
case IF_IDE:
862+
case IF_SCSI:
863+
case IF_XEN:
864+
case IF_NONE:
865+
dinfo->media_cd = media == MEDIA_CDROM;
866+
break;
867+
default:
868+
break;
869+
}
870+
881871
fail:
882872
qemu_opts_del(legacy_opts);
883873
return dinfo;
@@ -2176,7 +2166,7 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)
21762166

21772167
qdict_flatten(qdict);
21782168

2179-
dinfo = blockdev_init(qdict, IF_NONE, MEDIA_DISK);
2169+
dinfo = blockdev_init(qdict, IF_NONE);
21802170
if (!dinfo) {
21812171
error_setg(errp, "Could not open image");
21822172
goto fail;

0 commit comments

Comments
 (0)