QEMU: “Could not open disk image”

April 6th, 2011

Hit this strange problem today on RHEL5.6. Saw a QEMU disk image (qcow2 format; let’s call it “image2”) which was a copy-on-write link to a base OS image (let’s call it “image1”). Trying to start a KVM virtual machine using it resulted in the error “Could not open disk image”. After checking various things including that both images were OK (“qemu-img” check, loop mount) permissions, SELinux etc., it turned out that what this error actually means (in this case) is “You are using a copy-on-write image with a backing file of format ‘vpc’. This doesn’t work”. So, “qemu-img convert” solved the problem.

Good example of some poor error reporting…maybe it will help someone else out.

Error and exception handling in PHP

June 23rd, 2010

For as long as I’ve been developing PHP, I’ve always cared about code quality and wanted robust error handling, to fix root cause issues. Back in 2001, I wrote a class for PHPOF called XError, which did a pretty decent job of handling errors gracefully and reporting (via e-mail or rate-limited log) a backtrace with (usually) enough information to fix the problem.

With the advent of PHP 5 and proper exceptions (at last!), I cleaned up and substantially re-wrote that class to form a new one, which has actually been on my PEAR channel for several years and is in use across many live systems at work, but which I’ve never written up. It’s called Exception_DefaultHandler and is, well, a great class to throw in any project to use as a default error/exception handler. It’s lightweight, should work anywhere really, and is a major help with root cause analysis. It’s often still helpful to use higher level exception handling in your application, but even then you might want to pass the exception down to Exception_DefaultHandler::handleExceptionManual() to take advantage of its convenient reporting functions.