thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-blockdev-Don-t-disable-COR-automatically-with-blockd.patch

9ae3a8
From f511f5b093b500474168bb0c7e95b1a48a0d5d42 Mon Sep 17 00:00:00 2001
9ae3a8
From: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Date: Tue, 5 Nov 2013 14:09:13 +0100
9ae3a8
Subject: [PATCH 60/87] blockdev: Don't disable COR automatically with blockdev-add
9ae3a8
9ae3a8
RH-Author: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Message-id: <1383660558-32096-20-git-send-email-kwolf@redhat.com>
9ae3a8
Patchwork-id: 55398
9ae3a8
O-Subject: [RHEL-7.0 qemu-kvm PATCH 19/24] blockdev: Don't disable COR automatically with blockdev-add
9ae3a8
Bugzilla: 978402
9ae3a8
RH-Acked-by: Fam Zheng <famz@redhat.com>
9ae3a8
RH-Acked-by: Max Reitz <mreitz@redhat.com>
9ae3a8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
9ae3a8
If a read-only device is configured with copy-on-read=on, the old code
9ae3a8
only prints a warning and automatically disables copy on read. Make it
9ae3a8
a real error for blockdev-add.
9ae3a8
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Reviewed-by: Max Reitz <mreitz@redhat.com>
9ae3a8
Reviewed-by: Eric Blake <eblake@redhat.com>
9ae3a8
(cherry picked from commit 0ebd24e0a203cf2852c310b59fbe050190dc6c8c)
9ae3a8
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
---
9ae3a8
 block.c    |  9 +++++++--
9ae3a8
 blockdev.c | 31 +++++++++++++++++++++++++++----
9ae3a8
 2 files changed, 34 insertions(+), 6 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 block.c    |    9 +++++++--
9ae3a8
 blockdev.c |   31 +++++++++++++++++++++++++++----
9ae3a8
 2 files changed, 34 insertions(+), 6 deletions(-)
9ae3a8
9ae3a8
diff --git a/block.c b/block.c
9ae3a8
index c2b6930..d11661a 100644
9ae3a8
--- a/block.c
9ae3a8
+++ b/block.c
9ae3a8
@@ -746,8 +746,13 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file,
9ae3a8
     }
9ae3a8
 
9ae3a8
     assert(bs->copy_on_read == 0); /* bdrv_new() and bdrv_close() make it so */
9ae3a8
-    if (!bs->read_only && (flags & BDRV_O_COPY_ON_READ)) {
9ae3a8
-        bdrv_enable_copy_on_read(bs);
9ae3a8
+    if (flags & BDRV_O_COPY_ON_READ) {
9ae3a8
+        if (!bs->read_only) {
9ae3a8
+            bdrv_enable_copy_on_read(bs);
9ae3a8
+        } else {
9ae3a8
+            error_setg(errp, "Can't use copy-on-read on read-only device");
9ae3a8
+            return -EINVAL;
9ae3a8
+        }
9ae3a8
     }
9ae3a8
 
9ae3a8
     if (filename != NULL) {
9ae3a8
diff --git a/blockdev.c b/blockdev.c
9ae3a8
index d4b18c5..cbf01eb 100644
9ae3a8
--- a/blockdev.c
9ae3a8
+++ b/blockdev.c
9ae3a8
@@ -511,10 +511,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
9ae3a8
 
9ae3a8
     bdrv_flags |= ro ? 0 : BDRV_O_RDWR;
9ae3a8
 
9ae3a8
-    if (ro && copy_on_read) {
9ae3a8
-        error_report("warning: disabling copy_on_read on read-only drive");
9ae3a8
-    }
9ae3a8
-
9ae3a8
     QINCREF(bs_opts);
9ae3a8
     ret = bdrv_open(dinfo->bdrv, file, bs_opts, bdrv_flags, drv, &error);
9ae3a8
 
9ae3a8
@@ -602,6 +598,18 @@ QemuOptsList qemu_legacy_drive_opts = {
9ae3a8
             .type = QEMU_OPT_STRING,
9ae3a8
             .help = "pci address (virtio only)",
9ae3a8
         },
9ae3a8
+
9ae3a8
+        /* Options that are passed on, but have special semantics with -drive */
9ae3a8
+        {
9ae3a8
+            .name = "read-only",
9ae3a8
+            .type = QEMU_OPT_BOOL,
9ae3a8
+            .help = "open drive file as read-only",
9ae3a8
+        },{
9ae3a8
+            .name = "copy-on-read",
9ae3a8
+            .type = QEMU_OPT_BOOL,
9ae3a8
+            .help = "copy read data from backing file into image file",
9ae3a8
+        },
9ae3a8
+
9ae3a8
         { /* end of list */ }
9ae3a8
     },
9ae3a8
 };
9ae3a8
@@ -617,6 +625,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
9ae3a8
     int cyls, heads, secs, translation;
9ae3a8
     int max_devs, bus_id, unit_id, index;
9ae3a8
     const char *devaddr;
9ae3a8
+    bool read_only, copy_on_read;
9ae3a8
     Error *local_err = NULL;
9ae3a8
 
9ae3a8
     /* Change legacy command line options into QMP ones */
9ae3a8
@@ -688,6 +697,20 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
9ae3a8
         }
9ae3a8
     }
9ae3a8
 
9ae3a8
+    /* copy-on-read is disabled with a warning for read-only devices */
9ae3a8
+    read_only = qemu_opt_get_bool(legacy_opts, "read-only", false);
9ae3a8
+    copy_on_read = qemu_opt_get_bool(legacy_opts, "copy-on-read", false);
9ae3a8
+
9ae3a8
+    if (read_only && copy_on_read) {
9ae3a8
+        error_report("warning: disabling copy-on-read on read-only drive");
9ae3a8
+        copy_on_read = false;
9ae3a8
+    }
9ae3a8
+
9ae3a8
+    qdict_put(bs_opts, "read-only",
9ae3a8
+              qstring_from_str(read_only ? "on" : "off"));
9ae3a8
+    qdict_put(bs_opts, "copy-on-read",
9ae3a8
+              qstring_from_str(copy_on_read ? "on" :"off"));
9ae3a8
+
9ae3a8
     /* Controller type */
9ae3a8
     value = qemu_opt_get(legacy_opts, "if");
9ae3a8
     if (value) {
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8