[libvirt] [PATCH 3/4] Cache result of QEMU capabilities extraction

Daniel P. Berrange berrange at redhat.com
Thu Mar 6 09:29:00 UTC 2014


On Wed, Mar 05, 2014 at 05:53:48PM -0700, Eric Blake wrote:
> On 03/05/2014 10:53 AM, Daniel P. Berrange wrote:
> > Extracting capabilities from QEMU takes a notable amount of time
> > when all QEMU binaries are installed. Each system emulator
> > needs about 200-300ms multiplied by 26 binaries == ~5-8 seconds.
> > 
> > This change causes the QEMU driver to save an XML file containing
> > the content of the virQEMUCaps object instance in the cache
> > dir eg /var/cache/libvirt/qemu/capabilities/$SHA256(binarypath).xml
> > or $HOME/.cache/libvirt/qemu/cache/capabilities/$SHA256(binarypath).xml
> > 
> > We attempt to load this and only if it fails, do we fallback to
> > probing the QEMU binary. The timestamp of the file is compared to
> > the timestamp of the QEMU binary and discarded if the QEMU binary
> > is newer.
> > 
> > Signed-off-by: Daniel P. Berrange <berrange at redhat.com>
> > ---
> >  src/qemu/qemu_capabilities.c | 412 ++++++++++++++++++++++++++++++++++++++++++-
> >  src/qemu/qemu_capabilities.h |   2 +
> >  src/qemu/qemu_driver.c       |   1 +
> >  3 files changed, 407 insertions(+), 8 deletions(-)
> > 
> 
> > @@ -44,6 +45,7 @@
> >  #include <unistd.h>
> >  #include <sys/wait.h>
> >  #include <stdarg.h>
> > +#include <utime.h>
> 
> <utime.h> (and the utime() function) is deprecated by POSIX and
> therefore no longer portable because it corrupts sub-second timestamps.
>  Better is to use gnulib's utimensat (or futimens).  But what timestamps
> do we actually have to munge?
> 
> > +
> > +    ut.actime = qemuCaps->mtime;
> > +    ut.modtime = qemuCaps->mtime;
> > +    if (utime(filename, &ut) < 0) {
> > +        virReportSystemError(errno,
> > +                             _("Failed to set mtime on '%s' for '%s'"),
> > +                             filename, qemuCaps->binary);
> 
> Why not just store the qemu binary timestamp in the XML, rather than
> playing games with the mtime of the xml file?

I wanted to be able to detect out of date cache files without having
to go through parsing them.

Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|




More information about the libvir-list mailing list