Blame SOURCES/0026-blockdev-ignore-cache-options-for-empty-CDROM-drives.patch

4a2fec
From 454f60447bfea904d561ef282fc0446229484c02 Mon Sep 17 00:00:00 2001
4a2fec
From: John Snow <jsnow@redhat.com>
4a2fec
Date: Fri, 16 Sep 2016 22:06:28 +0200
4a2fec
Subject: blockdev: ignore cache options for empty CDROM drives
4a2fec
4a2fec
RH-Author: John Snow <jsnow@redhat.com>
4a2fec
Message-id: <1474063588-6370-2-git-send-email-jsnow@redhat.com>
4a2fec
Patchwork-id: 72377
4a2fec
O-Subject: [RHEV-7.3 qemu-kvm-rhev PATCH 1/1] blockdev: ignore cache options for empty CDROM drives
4a2fec
Bugzilla: 1342999
4a2fec
RH-Acked-by: Max Reitz <mreitz@redhat.com>
4a2fec
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
4a2fec
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
4a2fec
4a2fec
In qemu-kvm-rhev-2.3.0, QEMU will accept cache options for empty CDROM
4a2fec
devices, but silently ignore them as they will be overwritten when the
4a2fec
next CDROM is inserted.
4a2fec
4a2fec
Libvirt and VMM are capable of generating XML configurations which
4a2fec
attempt to specify these cache options to QEMU, though they don't have
4a2fec
any effect.
4a2fec
4a2fec
Upstream, a refactoring of cache option mechanisms means that we have
4a2fec
started rejecting invalid configurations where cache options are supplied
4a2fec
without any target to actually apply them to.
4a2fec
4a2fec
This means that there are combinations of QEMU and libvirt that will fail
4a2fec
to start a VM if a user selects a cache option.
4a2fec
4a2fec
This patch is a downstream-only workaround until libvirt can stop
4a2fec
supplying cache settings for empty CDROMs and/or until libvirt can take
4a2fec
advantage of the new QMP tray/medium manipulation mechanisms that will
4a2fec
allow proper cache specification for removable media.
4a2fec
4a2fec
Signed-off-by: John Snow <jsnow@redhat.com>
4a2fec
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
(cherry picked from commit 89b162019bfd202bbbd00563d03a030c2f7c1395)
4a2fec
---
4a2fec
 blockdev.c | 28 +++++++++++++++++++++++++++-
4a2fec
 1 file changed, 27 insertions(+), 1 deletion(-)
4a2fec
4a2fec
diff --git a/blockdev.c b/blockdev.c
4a2fec
index e525ebf..6d4cb70 100644
4a2fec
--- a/blockdev.c
4a2fec
+++ b/blockdev.c
4a2fec
@@ -450,6 +450,32 @@ static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags,
4a2fec
     }
4a2fec
 }
4a2fec
 
4a2fec
+/**
4a2fec
+ * libvirt expects to be able to pass cache options for CDROM drives without
4a2fec
+ * inserted media. Historically, QEMU eventually ignores these cache options as
4a2fec
+ * they are lost when media is inserted. Recently, QEMU started rejecting these
4a2fec
+ * configurations. Libvirt however still generates such configurations.
4a2fec
+ *
4a2fec
+ * To prevent QEMU from being unable to start, pretend there are no options
4a2fec
+ * present if the only options present are cache options for the BDS.
4a2fec
+ */
4a2fec
+static bool __redhat_com_has_bs_opts(QDict *bs_opts)
4a2fec
+{
4a2fec
+    size_t n, s;
4a2fec
+    s = qdict_size(bs_opts);
4a2fec
+
4a2fec
+    if (s == 0) {
4a2fec
+        return false;
4a2fec
+    } else if (s > 2) {
4a2fec
+        return true;
4a2fec
+    }
4a2fec
+
4a2fec
+    n = qdict_haskey(bs_opts, BDRV_OPT_CACHE_DIRECT);
4a2fec
+    n += qdict_haskey(bs_opts, BDRV_OPT_CACHE_NO_FLUSH);
4a2fec
+
4a2fec
+    return s != n;
4a2fec
+}
4a2fec
+
4a2fec
 /* Takes the ownership of bs_opts */
4a2fec
 static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
4a2fec
                                    Error **errp)
4a2fec
@@ -557,7 +583,7 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
4a2fec
     read_only = qemu_opt_get_bool(opts, BDRV_OPT_READ_ONLY, false);
4a2fec
 
4a2fec
     /* init */
4a2fec
-    if ((!file || !*file) && !qdict_size(bs_opts)) {
4a2fec
+    if ((!file || !*file) && !__redhat_com_has_bs_opts(bs_opts)) {
4a2fec
         BlockBackendRootState *blk_rs;
4a2fec
 
4a2fec
         blk = blk_new(0, BLK_PERM_ALL);
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec