Bug 607598

Summary: Incorrect & misleading error reporting when failing to open a drive due to block driver whitelist denial
Product: Red Hat Enterprise Linux 6 Reporter: Daniel Berrangé <berrange>
Component: qemu-kvmAssignee: Markus Armbruster <armbru>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: low    
Version: 6.0CC: lihuang, michen, mkenneth, shu, tburke, virt-maint
Target Milestone: rcKeywords: Triaged
Target Release: 6.1   
Hardware: All   
OS: Linux   
Whiteboard:
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: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 580953    

Description Daniel Berrangé 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 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