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

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