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

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



On Tue, Dec 11, 2012 at 14:53:36 +0000, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange" <berrange redhat com>
> 
> 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 redhat com",
> +                     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.

...

ACK with the nits fixed.

Jirka


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