Blame SOURCES/kvm-block-create-Do-not-abort-if-a-block-driver-is-not-a.patch

8b1478
From a87f7f01dbdf6d87d6cd0f1a2e48341d4b2269ba Mon Sep 17 00:00:00 2001
8b1478
From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= <philmd@redhat.com>
8b1478
Date: Fri, 13 Sep 2019 14:12:25 +0200
8b1478
Subject: [PATCH 2/4] block/create: Do not abort if a block driver is not
8b1478
 available
8b1478
MIME-Version: 1.0
8b1478
Content-Type: text/plain; charset=UTF-8
8b1478
Content-Transfer-Encoding: 8bit
8b1478
8b1478
RH-Author: Philippe Mathieu-Daudé <philmd@redhat.com>
8b1478
Message-id: <20190913141225.12022-2-philmd@redhat.com>
8b1478
Patchwork-id: 90451
8b1478
O-Subject: [RHEL-7.7 qemu-kvm-rhev + RHEL-AV-8.1.0 qemu-kvm PATCH v2 1/1] block/create: Do not abort if a block driver is not available
8b1478
Bugzilla: 1746224
8b1478
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
8b1478
RH-Acked-by: John Snow <jsnow@redhat.com>
8b1478
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
8b1478
8b1478
The 'blockdev-create' QMP command was introduced as experimental
8b1478
feature in commit b0292b851b8, using the assert() debug call.
8b1478
It got promoted to 'stable' command in 3fb588a0f2c, but the
8b1478
assert call was not removed.
8b1478
8b1478
Some block drivers are optional, and bdrv_find_format() might
8b1478
return a NULL value, triggering the assertion.
8b1478
8b1478
Stable code is not expected to abort, so return an error instead.
8b1478
8b1478
This is easily reproducible when libnfs is not installed:
8b1478
8b1478
  ./configure
8b1478
  [...]
8b1478
  module support    no
8b1478
  Block whitelist (rw)
8b1478
  Block whitelist (ro)
8b1478
  libiscsi support  yes
8b1478
  libnfs support    no
8b1478
  [...]
8b1478
8b1478
Start QEMU:
8b1478
8b1478
  $ qemu-system-x86_64 -S -qmp unix:/tmp/qemu.qmp,server,nowait
8b1478
8b1478
Send the 'blockdev-create' with the 'nfs' driver:
8b1478
8b1478
  $ ( cat << 'EOF'
8b1478
  {'execute': 'qmp_capabilities'}
8b1478
  {'execute': 'blockdev-create', 'arguments': {'job-id': 'x', 'options': {'size': 0, 'driver': 'nfs', 'location': {'path': '/', 'server': {'host': '::1', 'type': 'inet'}}}}, 'id': 'x'}
8b1478
  EOF
8b1478
  ) | socat STDIO UNIX:/tmp/qemu.qmp
8b1478
  {"QMP": {"version": {"qemu": {"micro": 50, "minor": 1, "major": 4}, "package": "v4.1.0-733-g89ea03a7dc"}, "capabilities": ["oob"]}}
8b1478
  {"return": {}}
8b1478
8b1478
QEMU crashes:
8b1478
8b1478
  $ gdb qemu-system-x86_64 core
8b1478
  Program received signal SIGSEGV, Segmentation fault.
8b1478
  (gdb) bt
8b1478
  #0  0x00007ffff510957f in raise () at /lib64/libc.so.6
8b1478
  #1  0x00007ffff50f3895 in abort () at /lib64/libc.so.6
8b1478
  #2  0x00007ffff50f3769 in _nl_load_domain.cold.0 () at /lib64/libc.so.6
8b1478
  #3  0x00007ffff5101a26 in .annobin_assert.c_end () at /lib64/libc.so.6
8b1478
  #4  0x0000555555d7e1f1 in qmp_blockdev_create (job_id=0x555556baee40 "x", options=0x555557666610, errp=0x7fffffffc770) at block/create.c:69
8b1478
  #5  0x0000555555c96b52 in qmp_marshal_blockdev_create (args=0x7fffdc003830, ret=0x7fffffffc7f8, errp=0x7fffffffc7f0) at qapi/qapi-commands-block-core.c:1314
8b1478
  #6  0x0000555555deb0a0 in do_qmp_dispatch (cmds=0x55555645de70 <qmp_commands>, request=0x7fffdc005c70, allow_oob=false, errp=0x7fffffffc898) at qapi/qmp-dispatch.c:131
8b1478
  #7  0x0000555555deb2a1 in qmp_dispatch (cmds=0x55555645de70 <qmp_commands>, request=0x7fffdc005c70, allow_oob=false) at qapi/qmp-dispatch.c:174
8b1478
8b1478
With this patch applied, QEMU returns a QMP error:
8b1478
8b1478
  {'execute': 'blockdev-create', 'arguments': {'job-id': 'x', 'options': {'size': 0, 'driver': 'nfs', 'location': {'path': '/', 'server': {'host': '::1', 'type': 'inet'}}}}, 'id': 'x'}
8b1478
  {"id": "x", "error": {"class": "GenericError", "desc": "Block driver 'nfs' not found or not supported"}}
8b1478
8b1478
Cc: qemu-stable@nongnu.org
8b1478
Reported-by: Xu Tian <xutian@redhat.com>
8b1478
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
8b1478
Reviewed-by: Eric Blake <eblake@redhat.com>
8b1478
Reviewed-by: John Snow <jsnow@redhat.com>
8b1478
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8b1478
(cherry picked from commit d90d5cae2b10efc0e8d0b3cc91ff16201853d3ba)
8b1478
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
8b1478
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
8b1478
---
8b1478
 block/create.c | 6 +++++-
8b1478
 1 file changed, 5 insertions(+), 1 deletion(-)
8b1478
8b1478
diff --git a/block/create.c b/block/create.c
8b1478
index 9534121..de5e97b 100644
8b1478
--- a/block/create.c
8b1478
+++ b/block/create.c
8b1478
@@ -63,9 +63,13 @@ void qmp_blockdev_create(const char *job_id, BlockdevCreateOptions *options,
8b1478
     const char *fmt = BlockdevDriver_str(options->driver);
8b1478
     BlockDriver *drv = bdrv_find_format(fmt);
8b1478
 
8b1478
+    if (!drv) {
8b1478
+        error_setg(errp, "Block driver '%s' not found or not supported", fmt);
8b1478
+        return;
8b1478
+    }
8b1478
+
8b1478
     /* If the driver is in the schema, we know that it exists. But it may not
8b1478
      * be whitelisted. */
8b1478
-    assert(drv);
8b1478
     if (bdrv_uses_whitelist() && !bdrv_is_whitelisted(drv, false)) {
8b1478
         error_setg(errp, "Driver is not whitelisted");
8b1478
         return;
8b1478
-- 
8b1478
1.8.3.1
8b1478