debuggers.hg

changeset 22264:a8c72f5a6bce

libxl: implementing legacy xm cpuid parser

To support compatibility with the xm config files, add a parser for the
old style cpuid= syntax. This uses a Python list, so it can be
distinguished from the new syntax easily.

Signed-off-by: Andre Przywara <andre.przywara@amd.com>
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
committer: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
author Andre Przywara <andre.przywara@amd.com>
date Fri Oct 01 17:21:01 2010 +0100 (2010-10-01)
parents 27c01a2e2a47
children 10b7696a5395
files tools/libxl/libxl.c tools/libxl/libxl.h
line diff
     1.1 --- a/tools/libxl/libxl.c	Fri Oct 01 17:20:41 2010 +0100
     1.2 +++ b/tools/libxl/libxl.c	Fri Oct 01 17:21:01 2010 +0100
     1.3 @@ -3743,6 +3743,66 @@ int libxl_cpuid_parse_config(libxl_cpuid
     1.4      return 0;
     1.5  }
     1.6  
     1.7 +/* parse a single list item from the legacy Python xend syntax, where
     1.8 + * the strings for each register were directly exposed to the user.
     1.9 + * Used for maintaining compatibility with older config files
    1.10 + */
    1.11 +int libxl_cpuid_parse_config_xend(libxl_cpuid_policy_list *cpuid,
    1.12 +                                  const char* str)
    1.13 +{
    1.14 +    char *endptr;
    1.15 +    unsigned long value;
    1.16 +    uint32_t leaf, subleaf = XEN_CPUID_INPUT_UNUSED;
    1.17 +    struct libxl__cpuid_policy *entry;
    1.18 +
    1.19 +    /* parse the leaf number */
    1.20 +    value = strtoul(str, &endptr, 0);
    1.21 +    if (str == endptr) {
    1.22 +        return 1;
    1.23 +    }
    1.24 +    leaf = value;
    1.25 +    /* check for an optional subleaf number */
    1.26 +    if (*endptr == ',') {
    1.27 +        str = endptr + 1;
    1.28 +        value = strtoul(str, &endptr, 0);
    1.29 +        if (str == endptr) {
    1.30 +            return 2;
    1.31 +        }
    1.32 +        subleaf = value;
    1.33 +    }
    1.34 +    if (*endptr != ':') {
    1.35 +        return 3;
    1.36 +    }
    1.37 +    str = endptr + 1;
    1.38 +    entry = cpuid_find_match(cpuid, leaf, subleaf);
    1.39 +    for (str = endptr + 1; *str != 0;) {
    1.40 +        if (str[0] != 'e' || str[2] != 'x') {
    1.41 +            return 4;
    1.42 +        }
    1.43 +        value = str[1] - 'a';
    1.44 +        endptr = strchr(str, '=');
    1.45 +        if (value < 0 || value > 3 || endptr == NULL) {
    1.46 +            return 4;
    1.47 +        }
    1.48 +        str = endptr + 1;
    1.49 +        endptr = strchr(str, ',');
    1.50 +        if (endptr == NULL) {
    1.51 +            endptr = strchr(str, 0);
    1.52 +        }
    1.53 +        if (endptr - str != 32) {
    1.54 +            return 5;
    1.55 +        }
    1.56 +        entry->policy[value] = calloc(32 + 1, 1);
    1.57 +        strncpy(entry->policy[value], str, 32);
    1.58 +        entry->policy[value][32] = 0;
    1.59 +        if (*endptr == 0) {
    1.60 +            break;
    1.61 +        }
    1.62 +        for (str = endptr + 1; *str == ' ' || *str == '\n'; str++);
    1.63 +    }
    1.64 +    return 0;
    1.65 +}
    1.66 +
    1.67  char *libxl_tmem_list(libxl_ctx *ctx, uint32_t domid, int use_long)
    1.68  {
    1.69      int rc;
     2.1 --- a/tools/libxl/libxl.h	Fri Oct 01 17:20:41 2010 +0100
     2.2 +++ b/tools/libxl/libxl.h	Fri Oct 01 17:21:01 2010 +0100
     2.3 @@ -412,6 +412,8 @@ int libxl_device_pci_list_assigned(libxl
     2.4  int libxl_device_pci_list_assignable(libxl_ctx *ctx, libxl_device_pci **list, int *num);
     2.5  int libxl_device_pci_parse_bdf(libxl_ctx *ctx, libxl_device_pci *pcidev, const char *str);
     2.6  int libxl_cpuid_parse_config(libxl_cpuid_policy_list *cpuid, const char* str);
     2.7 +int libxl_cpuid_parse_config_xend(libxl_cpuid_policy_list *cpuid,
     2.8 +                                  const char* str);
     2.9  
    2.10  /*
    2.11   * Functions for allowing users of libxl to store private data