yeahuh / rpms / qemu-kvm

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