yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-blockdev-Remove-IF_-check-for-read-only-blockdev_ini.patch

218e99
From 6048f02ce5388f14c0ff1a77122d26be9dffcac0 Mon Sep 17 00:00:00 2001
218e99
From: Kevin Wolf <kwolf@redhat.com>
218e99
Date: Thu, 7 Nov 2013 12:41:46 +0100
218e99
Subject: [PATCH 57/87] blockdev: Remove IF_* check for read-only blockdev_init
218e99
218e99
RH-Author: Kevin Wolf <kwolf@redhat.com>
218e99
Message-id: <1383660558-32096-17-git-send-email-kwolf@redhat.com>
218e99
Patchwork-id: 55395
218e99
O-Subject: [RHEL-7.0 qemu-kvm PATCH 16/24] blockdev: Remove IF_* check for read-only blockdev_init
218e99
Bugzilla: 978402
218e99
RH-Acked-by: Fam Zheng <famz@redhat.com>
218e99
RH-Acked-by: Max Reitz <mreitz@redhat.com>
218e99
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
218e99
218e99
IF_NONE allows read-only, which makes forbidding it in this place
218e99
for other types pretty much pointless.
218e99
218e99
Instead, make sure that all devices for which the check would have
218e99
errored out check in their init function that they don't get a read-only
218e99
BlockDriverState. This catches even cases where IF_NONE and -device is
218e99
used.
218e99
218e99
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
218e99
Reviewed-by: Eric Blake <eblake@redhat.com>
218e99
(cherry picked from commit 4f8a066b5fc254eeaabbbde56ba4f5b29cc68fdf)
218e99
218e99
Conflicts:
218e99
	hw/block/xen_disk.c
218e99
	hw/sd/milkymist-memcard.c
218e99
	hw/sd/omap_mmc.c
218e99
	hw/sd/pl181.c
218e99
	hw/sd/pxa2xx_mmci.c
218e99
	hw/sd/sdhci.c
218e99
	hw/sd/ssi-sd.c
218e99
218e99
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
218e99
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
---
218e99
 blockdev.c                 |    6 ------
218e99
 hw/block/m25p80.c          |    5 +++++
218e99
 hw/block/xen_disk.c        |    5 +++++
218e99
 hw/sd/milkymist-memcard.c  |    4 ++++
218e99
 hw/sd/omap_mmc.c           |    6 ++++++
218e99
 hw/sd/pl181.c              |    4 ++++
218e99
 hw/sd/pxa2xx_mmci.c        |    3 +++
218e99
 hw/sd/sd.c                 |    5 +++++
218e99
 hw/sd/sdhci.c              |    3 +++
218e99
 hw/sd/ssi-sd.c             |    3 +++
218e99
 tests/qemu-iotests/051.out |    5 ++++-
218e99
 11 files changed, 42 insertions(+), 7 deletions(-)
218e99
218e99
diff --git a/blockdev.c b/blockdev.c
218e99
index 14b357a..680ba22 100644
218e99
--- a/blockdev.c
218e99
+++ b/blockdev.c
218e99
@@ -529,12 +529,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
218e99
     if (media == MEDIA_CDROM) {
218e99
         /* CDROM is fine for any interface, don't check.  */
218e99
         ro = 1;
218e99
-    } else if (ro == 1) {
218e99
-        if (type != IF_SCSI && type != IF_VIRTIO && type != IF_FLOPPY &&
218e99
-            type != IF_NONE && type != IF_PFLASH) {
218e99
-            error_report("read-only not supported by this bus type");
218e99
-            goto err;
218e99
-        }
218e99
     }
218e99
 
218e99
     bdrv_flags |= ro ? 0 : BDRV_O_RDWR;
218e99
diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c
218e99
index 759c84d..ccec5ab 100644
218e99
--- a/hw/block/m25p80.c
218e99
+++ b/hw/block/m25p80.c
218e99
@@ -619,6 +619,11 @@ static int m25p80_init(SSISlave *ss)
218e99
     if (dinfo && dinfo->bdrv) {
218e99
         DB_PRINT_L(0, "Binding to IF_MTD drive\n");
218e99
         s->bdrv = dinfo->bdrv;
218e99
+        if (bdrv_is_read_only(s->bdrv)) {
218e99
+            fprintf(stderr, "Can't use a read-only drive");
218e99
+            return 1;
218e99
+        }
218e99
+
218e99
         /* FIXME: Move to late init */
218e99
         if (bdrv_read(s->bdrv, 0, s->storage, DIV_ROUND_UP(s->size,
218e99
                                                     BDRV_SECTOR_SIZE))) {
218e99
diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c
218e99
index 2d4d263..498f2e9 100644
218e99
--- a/hw/block/xen_disk.c
218e99
+++ b/hw/block/xen_disk.c
218e99
@@ -817,6 +817,11 @@ static int blk_connect(struct XenDevice *xendev)
218e99
         /* setup via qemu cmdline -> already setup for us */
218e99
         xen_be_printf(&blkdev->xendev, 2, "get configured bdrv (cmdline setup)\n");
218e99
         blkdev->bs = blkdev->dinfo->bdrv;
218e99
+        if (bdrv_is_read_only(blkdev->bs) && !readonly) {
218e99
+            xen_be_printf(&blkdev->xendev, 0, "Unexpected read-only drive");
218e99
+            blkdev->bs = NULL;
218e99
+            return -1;
218e99
+        }
218e99
     }
218e99
     bdrv_attach_dev_nofail(blkdev->bs, blkdev);
218e99
     blkdev->file_size = bdrv_getlength(blkdev->bs);
218e99
diff --git a/hw/sd/milkymist-memcard.c b/hw/sd/milkymist-memcard.c
218e99
index d5944bc..a7dfbff 100644
218e99
--- a/hw/sd/milkymist-memcard.c
218e99
+++ b/hw/sd/milkymist-memcard.c
218e99
@@ -251,6 +251,10 @@ static int milkymist_memcard_init(SysBusDevice *dev)
218e99
 
218e99
     dinfo = drive_get_next(IF_SD);
218e99
     s->card = sd_init(dinfo ? dinfo->bdrv : NULL, 0);
218e99
+    if (s->card == NULL) {
218e99
+        return -1;
218e99
+    }
218e99
+
218e99
     s->enabled = dinfo ? bdrv_is_inserted(dinfo->bdrv) : 0;
218e99
 
218e99
     memory_region_init_io(&s->regs_region, &memcard_mmio_ops, s,
218e99
diff --git a/hw/sd/omap_mmc.c b/hw/sd/omap_mmc.c
218e99
index d4079cd..aefdc3e 100644
218e99
--- a/hw/sd/omap_mmc.c
218e99
+++ b/hw/sd/omap_mmc.c
218e99
@@ -593,6 +593,9 @@ struct omap_mmc_s *omap_mmc_init(hwaddr base,
218e99
 
218e99
     /* Instantiate the storage */
218e99
     s->card = sd_init(bd, 0);
218e99
+    if (s->card == NULL) {
218e99
+        exit(1);
218e99
+    }
218e99
 
218e99
     return s;
218e99
 }
218e99
@@ -618,6 +621,9 @@ struct omap_mmc_s *omap2_mmc_init(struct omap_target_agent_s *ta,
218e99
 
218e99
     /* Instantiate the storage */
218e99
     s->card = sd_init(bd, 0);
218e99
+    if (s->card == NULL) {
218e99
+        exit(1);
218e99
+    }
218e99
 
218e99
     s->cdet = qemu_allocate_irqs(omap_mmc_cover_cb, s, 1)[0];
218e99
     sd_set_cb(s->card, NULL, s->cdet);
218e99
diff --git a/hw/sd/pl181.c b/hw/sd/pl181.c
218e99
index c5ad890..a7f85b8 100644
218e99
--- a/hw/sd/pl181.c
218e99
+++ b/hw/sd/pl181.c
218e99
@@ -486,6 +486,10 @@ static int pl181_init(SysBusDevice *dev)
218e99
     qdev_init_gpio_out(&s->busdev.qdev, s->cardstatus, 2);
218e99
     dinfo = drive_get_next(IF_SD);
218e99
     s->card = sd_init(dinfo ? dinfo->bdrv : NULL, 0);
218e99
+    if (s->card == NULL) {
218e99
+        return -1;
218e99
+    }
218e99
+
218e99
     return 0;
218e99
 }
218e99
 
218e99
diff --git a/hw/sd/pxa2xx_mmci.c b/hw/sd/pxa2xx_mmci.c
218e99
index 2db1cab..066d523 100644
218e99
--- a/hw/sd/pxa2xx_mmci.c
218e99
+++ b/hw/sd/pxa2xx_mmci.c
218e99
@@ -539,6 +539,9 @@ PXA2xxMMCIState *pxa2xx_mmci_init(MemoryRegion *sysmem,
218e99
 
218e99
     /* Instantiate the actual storage */
218e99
     s->card = sd_init(bd, 0);
218e99
+    if (s->card == NULL) {
218e99
+        exit(1);
218e99
+    }
218e99
 
218e99
     register_savevm(NULL, "pxa2xx_mmci", 0, 0,
218e99
                     pxa2xx_mmci_save, pxa2xx_mmci_load, s);
218e99
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
218e99
index 2e0ef3e..e816c78 100644
218e99
--- a/hw/sd/sd.c
218e99
+++ b/hw/sd/sd.c
218e99
@@ -492,6 +492,11 @@ SDState *sd_init(BlockDriverState *bs, bool is_spi)
218e99
 {
218e99
     SDState *sd;
218e99
 
218e99
+    if (bdrv_is_read_only(bs)) {
218e99
+        fprintf(stderr, "sd_init: Cannot use read-only drive\n");
218e99
+        return NULL;
218e99
+    }
218e99
+
218e99
     sd = (SDState *) g_malloc0(sizeof(SDState));
218e99
     sd->buf = qemu_blockalign(bs, 512);
218e99
     sd->spi = is_spi;
218e99
diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
218e99
index 91dc9b0..d8a4987 100644
218e99
--- a/hw/sd/sdhci.c
218e99
+++ b/hw/sd/sdhci.c
218e99
@@ -1166,6 +1166,9 @@ static void sdhci_initfn(Object *obj)
218e99
 
218e99
     di = drive_get_next(IF_SD);
218e99
     s->card = sd_init(di ? di->bdrv : NULL, 0);
218e99
+    if (s->card == NULL) {
218e99
+        exit(1);
218e99
+    }
218e99
     s->eject_cb = qemu_allocate_irqs(sdhci_insert_eject_cb, s, 1)[0];
218e99
     s->ro_cb = qemu_allocate_irqs(sdhci_card_readonly_cb, s, 1)[0];
218e99
     sd_set_cb(s->card, s->ro_cb, s->eject_cb);
218e99
diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c
218e99
index 4d3c4f6..79ec51a 100644
218e99
--- a/hw/sd/ssi-sd.c
218e99
+++ b/hw/sd/ssi-sd.c
218e99
@@ -246,6 +246,9 @@ static int ssi_sd_init(SSISlave *dev)
218e99
     s->mode = SSI_SD_CMD;
218e99
     dinfo = drive_get_next(IF_SD);
218e99
     s->sd = sd_init(dinfo ? dinfo->bdrv : NULL, 1);
218e99
+    if (s->sd == NULL) {
218e99
+        return -1;
218e99
+    }
218e99
     register_savevm(&dev->qdev, "ssi_sd", -1, 1, ssi_sd_save, ssi_sd_load, s);
218e99
     return 0;
218e99
 }
218e99
diff --git a/tests/qemu-iotests/051.out b/tests/qemu-iotests/051.out
218e99
index 54a6b3a..4fca1ca 100644
218e99
--- a/tests/qemu-iotests/051.out
218e99
+++ b/tests/qemu-iotests/051.out
218e99
@@ -98,7 +98,10 @@ QEMU X.Y.Z monitor - type 'help' for more information
218e99
 (qemu) q?[K?[Dqu?[K?[D?[Dqui?[K?[D?[D?[Dquit?[K
218e99
 
218e99
 Testing: -drive file=TEST_DIR/t.qcow2,if=ide,readonly=on
218e99
-QEMU_PROG: -drive file=TEST_DIR/t.qcow2,if=ide,readonly=on: read-only not supported by this bus type
218e99
+QEMU X.Y.Z monitor - type 'help' for more information
218e99
+(qemu) QEMU_PROG: Can't use a read-only drive
218e99
+QEMU_PROG: Device initialization failed.
218e99
+QEMU_PROG: Initialization of device ide-hd failed
218e99
 
218e99
 Testing: -drive file=TEST_DIR/t.qcow2,if=virtio,readonly=on
218e99
 QEMU X.Y.Z monitor - type 'help' for more information
218e99
-- 
218e99
1.7.1
218e99