Re: [PATCH 1/6] Introduce a set of APIs for managing architectures

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Dec 18, 2012 at 10:24:06AM +0100, Jiri Denemark wrote:
> On Tue, Dec 11, 2012 at 14:53:36 +0000, Daniel P. Berrange wrote:
> > From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>
> > 
> > Introduce a 'virArch' enum for CPU architectures. Include
> > data type providing wordsize and endianness, and APIs to
> > query this info and convert to/from enum and string form.
> ...
> > diff --git a/src/util/virarch.c b/src/util/virarch.c
> > new file mode 100644
> > index 0000000..8b7bec8
> > --- /dev/null
> > +++ b/src/util/virarch.c
> > @@ -0,0 +1,177 @@
> ...
> > +/**
> > + * virArchFromString:
> > + * @archstr: the CPU architecture string
> > + *
> > + * Return the architecture matching @archstr,
> > + * defaulting to VIR_ARCH_I686 if unidentified
> 
> This should be VIR_ARCH_NONE as Eric already noted.
> 
> > + */
> > +virArch virArchFromString(const char *archstr)
> > +{
> > +    size_t i;
> > +    for (i = 1 ; i < VIR_ARCH_LAST ; i++) {
> > +        if (STREQ(virArchData[i].name, archstr))
> > +            return i;
> > +    }
> > +
> > +    VIR_DEBUG("Unknown arch %s", archstr);
> > +    return VIR_ARCH_NONE;
> > +}
> > +
> > +
> > +/**
> > + * virArchFromHost:
> > + *
> > + * Return the host architecture. Prefer this to the
> > + * uname 'machine' field, since this will canonicalize
> > + * architecture names like 'amd64' into 'x86_64'.
> > + */
> > +virArch virArchFromHost(void)
> > +{
> > +    struct utsname ut;
> > +    virArch arch;
> > +
> > +    uname(&ut);
> > +
> > +    /* Some special cases we need to handle first
> > +     * for non-canonical names */
> > +    if (ut.machine[0] == 'i' &&
> > +        ut.machine[2] == '8' &&
> > +        ut.machine[3] == '6' &&
> > +        ut.machine[4] == '\0') {
> > +        arch = VIR_ARCH_I686;
> 
> This could access undefined memory in the unlikely case of ut.machine
> being just "i". Insert the ut.machine[1] != '\0' test to match the
> original code in qemu_command.c.
> 
> > +    } else if (STREQ(ut.machine, "ia64")) {
> > +        arch = VIR_ARCH_ITANIUM;
> > +    } else if (STREQ(ut.machine, "amd64")) {
> > +        arch = VIR_ARCH_X86_64;
> > +    } else {
> > +        /* Otherwise assume the canonical name */
> > +        if ((arch = virArchFromString(ut.machine)) == VIR_ARCH_NONE) {
> > +            VIR_WARN("Unknown host arch %s, report to libvir-list@xxxxxxxxxx",
> > +                     ut.machine);
> > +        }
> > +    }
> > +
> > +    VIR_DEBUG("Mapped %s to %d (%s)",
> > +              ut.machine, arch, virArchToString(arch));
> > +
> > +    return arch;
> > +}
> > diff --git a/src/util/virarch.h b/src/util/virarch.h
> > new file mode 100644
> > index 0000000..d29d7ef
> > --- /dev/null
> > +++ b/src/util/virarch.h
> > @@ -0,0 +1,81 @@
> ...
> > +#ifndef __VIR_ARCH_H__
> > +# define __VIR_ARCH_H__
> > +
> > +# include "internal.h"
> > +# include "util.h"
> 
> Looks like nothing from util.h is used in this header file.

Oh true. Originally I used the VIR_ENUM stuff, but I removed that
in the end

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 :|

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]