[systemd-devel] [PATCH 3/3] ARM: detect-virt: detect QEMU/KVM

Andrew Jones drjones at redhat.com
Tue Mar 31 01:48:31 PDT 2015


On Tue, Mar 31, 2015 at 09:18:08AM +0200, Lennart Poettering wrote:
> On Mon, 30.03.15 21:15, Andrew Jones (drjones at redhat.com) wrote:
> 
> > QEMU/KVM guests do not have hypervisor nodes, but they do have
> > fw-cfg nodes (since qemu v2.3.0-rc0). fw-cfg nodes are documented,
> > see kernel doc Documentation/devicetree/bindings/arm/fw-cfg.txt,
> > and therefore we should be able to rely on it in this detection.
> > 
> > Unfortunately, we currently don't have enough information in the
> > DT, or elsewhere, to determine if we're using KVM acceleration
> > with QEMU or not, so we can only report 'qemu' at this time, even
> > if KVM is in use. This shouldn't really matter in practice though,
> > because if detect-virt is used interactively it will be clear to
> > the user whether or not KVM acceleration is present by the overall
> > speed of the guest. If used by a script, then the script's behavior
> > should not change whether it's 'qemu' or 'kvm'. QEMU emulated
> > guests and QEMU/KVM guests of the same type should behave
> > identically, only the speed at which they run should differ.
> > 
> > ---
> >  src/shared/virt.c | 14 ++++++++++++++
> >  1 file changed, 14 insertions(+)
> > 
> > diff --git a/src/shared/virt.c b/src/shared/virt.c
> > index 712523210d720..ddb76687975ba 100644
> > --- a/src/shared/virt.c
> > +++ b/src/shared/virt.c
> > @@ -115,6 +115,20 @@ static int detect_vm_devicetree(const char **_id) {
> >                          *_id = "xen";
> >                          return 1;
> >                  }
> > +        } else if (r == -ENOENT) {
> > +                _cleanup_closedir_ DIR *dir = NULL;
> > +                struct dirent *dent;
> > +
> > +                dir = opendir("/proc/device-tree");
> > +                if (!dir)
> > +                        return 0;
> 
> It's probably a good idea to return an error if this fails unless
> errno is ENOENT?
> 
> > +
> > +                for (dent = readdir(dir); dent != NULL; dent =
> > readdir(dir)) {
> 
> Please use the FOREACH_DIRENT macro for this!
> 
> Lennart

Thanks for the review. Will send a v2 with your suggestions shortly.

drew
> 
> -- 
> Lennart Poettering, Red Hat


More information about the systemd-devel mailing list