peterdelevoryas / rpms / qemu

Forked from rpms/qemu 2 years ago
Clone

Blame 0021-w32-Fix-access-to-host-devices-regression.patch

298366
From e8601a4e3102321d054ce3d641c03ebcd0519357 Mon Sep 17 00:00:00 2001
298366
From: Stefan Weil <sw@weilnetz.de>
298366
Date: Sun, 1 Sep 2013 22:59:25 +0200
298366
Subject: [PATCH] w32: Fix access to host devices (regression)
298366
298366
QEMU failed to open host devices like \\.\PhysicalDrive0 (first hard disk)
298366
since some time (commit 8a79380b8ef1b02d2abd705dd026a18863b09020?).
298366
298366
Those devices use hdev_open which did not use the latest API for options.
298366
This resulted in a fatal runtime error:
298366
298366
  Block protocol 'host_device' doesn't support the option 'filename'
298366
298366
Duplicate code from raw_open to fix this.
298366
298366
Cc: qemu-stable@nongnu.org
298366
Reported-by: David Brenner <david.brenner3@gmail.com>
298366
Signed-off-by: Stefan Weil <sw@weilnetz.de>
298366
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
298366
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
298366
(cherry picked from commit 68dc036488dfea170627a55e6ee3dfd7f2c2063e)
298366
298366
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
298366
---
298366
 block/raw-win32.c | 36 +++++++++++++++++++++++++++++-------
298366
 1 file changed, 29 insertions(+), 7 deletions(-)
298366
298366
diff --git a/block/raw-win32.c b/block/raw-win32.c
298366
index 9b5b2af..d2d2d9f 100644
298366
--- a/block/raw-win32.c
298366
+++ b/block/raw-win32.c
298366
@@ -535,13 +535,29 @@ static int hdev_open(BlockDriverState *bs, QDict *options, int flags)
298366
 {
298366
     BDRVRawState *s = bs->opaque;
298366
     int access_flags, create_flags;
298366
+    int ret = 0;
298366
     DWORD overlapped;
298366
     char device_name[64];
298366
-    const char *filename = qdict_get_str(options, "filename");
298366
+
298366
+    Error *local_err = NULL;
298366
+    const char *filename;
298366
+
298366
+    QemuOpts *opts = qemu_opts_create_nofail(&raw_runtime_opts);
298366
+    qemu_opts_absorb_qdict(opts, options, &local_err);
298366
+    if (error_is_set(&local_err)) {
298366
+        qerror_report_err(local_err);
298366
+        error_free(local_err);
298366
+        ret = -EINVAL;
298366
+        goto done;
298366
+    }
298366
+
298366
+    filename = qemu_opt_get(opts, "filename");
298366
 
298366
     if (strstart(filename, "/dev/cdrom", NULL)) {
298366
-        if (find_cdrom(device_name, sizeof(device_name)) < 0)
298366
-            return -ENOENT;
298366
+        if (find_cdrom(device_name, sizeof(device_name)) < 0) {
298366
+            ret = -ENOENT;
298366
+            goto done;
298366
+        }
298366
         filename = device_name;
298366
     } else {
298366
         /* transform drive letters into device name */
298366
@@ -564,11 +580,17 @@ static int hdev_open(BlockDriverState *bs, QDict *options, int flags)
298366
     if (s->hfile == INVALID_HANDLE_VALUE) {
298366
         int err = GetLastError();
298366
 
298366
-        if (err == ERROR_ACCESS_DENIED)
298366
-            return -EACCES;
298366
-        return -1;
298366
+        if (err == ERROR_ACCESS_DENIED) {
298366
+            ret = -EACCES;
298366
+        } else {
298366
+            ret = -1;
298366
+        }
298366
+        goto done;
298366
     }
298366
-    return 0;
298366
+
298366
+done:
298366
+    qemu_opts_del(opts);
298366
+    return ret;
298366
 }
298366
 
298366
 static BlockDriver bdrv_host_device = {