Red Hat Bugzilla – Bug 607598
Incorrect & misleading error reporting when failing to open a drive due to block driver whitelist denial
Last modified: 2013-01-09 17:47:09 EST
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:
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.
Need to backport two upstream patches: 236f1f6 Fix error message in drive_init c98ac35 block: Use error codes from lower levels for error message
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.
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