Commit 4f8a066b authored by Kevin Wolf's avatar Kevin Wolf
Browse files

blockdev: Remove IF_* check for read-only blockdev_init



IF_NONE allows read-only, which makes forbidding it in this place
for other types pretty much pointless.

Instead, make sure that all devices for which the check would have
errored out check in their init function that they don't get a read-only
BlockDriverState. This catches even cases where IF_NONE and -device is
used.

Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
Reviewed-by: default avatarEric Blake <eblake@redhat.com>
parent 394c7d4d
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -528,12 +528,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
    if (media == MEDIA_CDROM) {
        /* CDROM is fine for any interface, don't check.  */
        ro = 1;
    } else if (ro == 1) {
        if (type != IF_SCSI && type != IF_VIRTIO && type != IF_FLOPPY &&
            type != IF_NONE && type != IF_PFLASH) {
            error_report("read-only not supported by this bus type");
            goto err;
        }
    }

    bdrv_flags |= ro ? 0 : BDRV_O_RDWR;
+5 −0
Original line number Diff line number Diff line
@@ -624,6 +624,11 @@ static int m25p80_init(SSISlave *ss)
    if (dinfo && dinfo->bdrv) {
        DB_PRINT_L(0, "Binding to IF_MTD drive\n");
        s->bdrv = dinfo->bdrv;
        if (bdrv_is_read_only(s->bdrv)) {
            fprintf(stderr, "Can't use a read-only drive");
            return 1;
        }

        /* FIXME: Move to late init */
        if (bdrv_read(s->bdrv, 0, s->storage, DIV_ROUND_UP(s->size,
                                                    BDRV_SECTOR_SIZE))) {
+5 −0
Original line number Diff line number Diff line
@@ -830,6 +830,11 @@ static int blk_connect(struct XenDevice *xendev)
        /* setup via qemu cmdline -> already setup for us */
        xen_be_printf(&blkdev->xendev, 2, "get configured bdrv (cmdline setup)\n");
        blkdev->bs = blkdev->dinfo->bdrv;
        if (bdrv_is_read_only(blkdev->bs) && !readonly) {
            xen_be_printf(&blkdev->xendev, 0, "Unexpected read-only drive");
            blkdev->bs = NULL;
            return -1;
        }
        /* blkdev->bs is not create by us, we get a reference
         * so we can bdrv_unref() unconditionally */
        bdrv_ref(blkdev->bs);
+4 −0
Original line number Diff line number Diff line
@@ -255,6 +255,10 @@ static int milkymist_memcard_init(SysBusDevice *dev)

    dinfo = drive_get_next(IF_SD);
    s->card = sd_init(dinfo ? dinfo->bdrv : NULL, false);
    if (s->card == NULL) {
        return -1;
    }

    s->enabled = dinfo ? bdrv_is_inserted(dinfo->bdrv) : 0;

    memory_region_init_io(&s->regs_region, OBJECT(s), &memcard_mmio_ops, s,
+6 −0
Original line number Diff line number Diff line
@@ -593,6 +593,9 @@ struct omap_mmc_s *omap_mmc_init(hwaddr base,

    /* Instantiate the storage */
    s->card = sd_init(bd, false);
    if (s->card == NULL) {
        exit(1);
    }

    return s;
}
@@ -618,6 +621,9 @@ struct omap_mmc_s *omap2_mmc_init(struct omap_target_agent_s *ta,

    /* Instantiate the storage */
    s->card = sd_init(bd, false);
    if (s->card == NULL) {
        exit(1);
    }

    s->cdet = qemu_allocate_irqs(omap_mmc_cover_cb, s, 1)[0];
    sd_set_cb(s->card, NULL, s->cdet);
Loading