thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
218e99
From c9f57b61fd600b60276a1f50be5af3eed7d8bafd Mon Sep 17 00:00:00 2001
218e99
From: Max Reitz <mreitz@redhat.com>
218e99
Date: Mon, 4 Nov 2013 22:32:07 +0100
218e99
Subject: [PATCH 14/87] w32: Fix access to host devices (regression)
218e99
218e99
RH-Author: Max Reitz <mreitz@redhat.com>
218e99
Message-id: <1383604354-12743-17-git-send-email-mreitz@redhat.com>
218e99
Patchwork-id: 55316
218e99
O-Subject: [RHEL-7.0 qemu-kvm PATCH 16/43] w32: Fix access to host devices (regression)
218e99
Bugzilla: 1026524
218e99
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
218e99
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
218e99
RH-Acked-by: Fam Zheng <famz@redhat.com>
218e99
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
218e99
218e99
From: Stefan Weil <sw@weilnetz.de>
218e99
218e99
BZ: 1026524
218e99
218e99
QEMU failed to open host devices like \\.\PhysicalDrive0 (first hard disk)
218e99
since some time (commit 8a79380b8ef1b02d2abd705dd026a18863b09020?).
218e99
218e99
Those devices use hdev_open which did not use the latest API for options.
218e99
This resulted in a fatal runtime error:
218e99
218e99
  Block protocol 'host_device' doesn't support the option 'filename'
218e99
218e99
Duplicate code from raw_open to fix this.
218e99
218e99
Cc: qemu-stable@nongnu.org
218e99
Reported-by: David Brenner <david.brenner3@gmail.com>
218e99
Signed-off-by: Stefan Weil <sw@weilnetz.de>
218e99
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
218e99
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
218e99
(cherry picked from commit 68dc036488dfea170627a55e6ee3dfd7f2c2063e)
218e99
218e99
Signed-off-by: Max Reitz <mreitz@redhat.com>
218e99
---
218e99
 block/raw-win32.c | 36 +++++++++++++++++++++++++++++-------
218e99
 1 file changed, 29 insertions(+), 7 deletions(-)
218e99
218e99
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
---
218e99
 block/raw-win32.c |   36 +++++++++++++++++++++++++++++-------
218e99
 1 files changed, 29 insertions(+), 7 deletions(-)
218e99
218e99
diff --git a/block/raw-win32.c b/block/raw-win32.c
218e99
index 7c03b6d..a324e5b 100644
218e99
--- a/block/raw-win32.c
218e99
+++ b/block/raw-win32.c
218e99
@@ -534,13 +534,29 @@ static int hdev_open(BlockDriverState *bs, QDict *options, int flags)
218e99
 {
218e99
     BDRVRawState *s = bs->opaque;
218e99
     int access_flags, create_flags;
218e99
+    int ret = 0;
218e99
     DWORD overlapped;
218e99
     char device_name[64];
218e99
-    const char *filename = qdict_get_str(options, "filename");
218e99
+
218e99
+    Error *local_err = NULL;
218e99
+    const char *filename;
218e99
+
218e99
+    QemuOpts *opts = qemu_opts_create_nofail(&raw_runtime_opts);
218e99
+    qemu_opts_absorb_qdict(opts, options, &local_err);
218e99
+    if (error_is_set(&local_err)) {
218e99
+        qerror_report_err(local_err);
218e99
+        error_free(local_err);
218e99
+        ret = -EINVAL;
218e99
+        goto done;
218e99
+    }
218e99
+
218e99
+    filename = qemu_opt_get(opts, "filename");
218e99
 
218e99
     if (strstart(filename, "/dev/cdrom", NULL)) {
218e99
-        if (find_cdrom(device_name, sizeof(device_name)) < 0)
218e99
-            return -ENOENT;
218e99
+        if (find_cdrom(device_name, sizeof(device_name)) < 0) {
218e99
+            ret = -ENOENT;
218e99
+            goto done;
218e99
+        }
218e99
         filename = device_name;
218e99
     } else {
218e99
         /* transform drive letters into device name */
218e99
@@ -563,11 +579,17 @@ static int hdev_open(BlockDriverState *bs, QDict *options, int flags)
218e99
     if (s->hfile == INVALID_HANDLE_VALUE) {
218e99
         int err = GetLastError();
218e99
 
218e99
-        if (err == ERROR_ACCESS_DENIED)
218e99
-            return -EACCES;
218e99
-        return -1;
218e99
+        if (err == ERROR_ACCESS_DENIED) {
218e99
+            ret = -EACCES;
218e99
+        } else {
218e99
+            ret = -1;
218e99
+        }
218e99
+        goto done;
218e99
     }
218e99
-    return 0;
218e99
+
218e99
+done:
218e99
+    qemu_opts_del(opts);
218e99
+    return ret;
218e99
 }
218e99
 
218e99
 static int hdev_has_zero_init(BlockDriverState *bs)
218e99
-- 
218e99
1.7.1
218e99