Bug 607598 - Incorrect & misleading error reporting when failing to open a drive due to block driver whitelist denial
Summary: Incorrect & misleading error reporting when failing to open a drive due to bl...
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: qemu-kvm (Show other bugs)
(Show other bugs)
Version: 6.0
Hardware: All Linux
low
medium
Target Milestone: rc
: 6.1
Assignee: Markus Armbruster
QA Contact: Virtualization Bugs
URL:
Whiteboard:
Keywords: Triaged
Depends On:
Blocks: 580953
TreeView+ depends on / blocked
 
Reported: 2010-06-24 13:08 UTC by Daniel Berrange
Modified: 2013-01-09 22:47 UTC (History)
6 users (show)

Fixed In Version: qemu-kvm-0.12.1.2-2.149.el6
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2011-05-19 11:31:51 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)


External Trackers
Tracker ID Priority Status Summary Last Updated
Red Hat Product Errata RHSA-2011:0534 normal SHIPPED_LIVE Important: qemu-kvm security, bug fix, and enhancement update 2011-05-19 11:20:36 UTC

Description Daniel Berrange 2010-06-24 13:08:07 UTC
Description of problem:
When attempting to launch a KVM instance with a disk using the vvfat protocol, QEMU exits with apparently random error messages reported back

So far I've seen 

qemu: could not open disk image fat:floppy:/home/berrange/src/virt/libvirt-tck/fat: Inappropriate ioctl for device

qemu: could not open disk image fat:floppy:/tmp: No such file or directory

qemu: could not open disk image fat:floppy:/tmp: Invalid argument

This appears to be a flaw in vl.c handling of bdrv_open() return codes. It currently does


         fprintf(stderr, "qemu: could not open disk image %s: %s\n",
                         file, strerror(errno));

However, the bdrv_open() API contract does *not* actually set errno, so this is just reporting the last errno that happened to be set by some other random piece of QEMU code. The actual error is in the bdrv_open() return value.

Something like this appears to be neccessary:

diff --git a/vl.c b/vl.c
index 6d08ec8..4a4c818 100644
--- a/vl.c
+++ b/vl.c
@@ -792,6 +792,7 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque,
     const char *devaddr;
     DriveInfo *dinfo;
     int snapshot = 0;
+    int err;
 
     *fatal_error = 1;
 
@@ -1122,9 +1123,9 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque,
 
     bdrv_flags |= ro ? 0 : BDRV_O_RDWR;
 
-    if (bdrv_open(dinfo->bdrv, file, bdrv_flags, drv) < 0) {
+    if ((err = bdrv_open(dinfo->bdrv, file, bdrv_flags, drv)) < 0) {
         fprintf(stderr, "qemu: could not open disk image %s: %s\n",
-                        file, strerror(errno));
+                        file, strerror(-err));
         return NULL;
     }
 

There is still a problem with this though. When bdrv_open() fails to open a disk due to its protocol/format not being in the whitelist, it set  ret=-ENOENT.

The ENOENT error code is a very commonly seen error in user configuration errors due to typos in disk paths. Thus it is rather mis-leading as a way of reporting a block driver is not allowed by the whitelist.

Ideally this will all use qerror() eventually, but in the meantime, it would be more helpful to use a different errno for this case


diff --git a/block.c b/block.c
index 39724c1..36b7e3f 100644
--- a/block.c
+++ b/block.c
@@ -565,7 +565,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags,
     }
 
     if (!drv) {
-        ret = -ENOENT;
+        ret = -ENOSYS;
         goto unlink_and_fail;
     }
 


This makes it report:

qemu: could not open disk image fat:floppy:/tmp: Function not implemented


which gives a better indication that the fat capability has been disabled by the whitelist.

Version-Release number of selected component (if applicable):
qemu-kvm-0.12.1.2-2.78.el6.x86_64

How reproducible:
Sometimes, occassionally the previously set errno matches the currently ENOENT, but often it doesn't.  Regardless ENOENT is a very misleading code.

Steps to Reproduce:
1. qemu -drive file=fat:floppy:/tmp
2.
3.
  
Actual results:
qemu: could not open disk image fat:floppy:/tmp: No such file or directory


Expected results:
qemu: could not open disk image fat:floppy:/tmp: Function not implemented


Additional info:

Comment 2 RHEL Product and Program Management 2010-06-24 13:32:53 UTC
This request was evaluated by Red Hat Product Management for inclusion in a Red
Hat Enterprise Linux major release.  Product Management has requested further
review of this request by Red Hat Engineering, for potential inclusion in a Red
Hat Enterprise Linux Major release.  This request is not yet committed for
inclusion.

Comment 5 Markus Armbruster 2011-02-16 18:05:19 UTC
Need to backport two upstream patches:
236f1f6 Fix error message in drive_init
c98ac35 block: Use error codes from lower levels for error message

Comment 10 Shaolong Hu 2011-03-18 14:45:29 UTC
Reproduced on qemu-kvm-0.12.1.2-2.147.el6 as following steps.

Reproduce Procedure:
---------------------
1. boot a guest with: -drive file=fat:floppy:/tmp

Actual results:
----------------
qemu: could not open disk image fat:floppy:/tmp: No such file or directory



Verify this bug on qemu-img-0.12.1.2-2.150.el6 as same steps above.

Actual results:
----------------
qemu: could not open disk image fat:floppy:/tmp: Operation not supported.



Conclusion:
-------------
According to results above, this bug has been resolved.

Comment 11 errata-xmlrpc 2011-05-19 11:31:51 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHSA-2011-0534.html

Comment 12 errata-xmlrpc 2011-05-19 12:46:03 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHSA-2011-0534.html


Note You need to log in before you can comment on or make changes to this bug.