debuggers.hg

changeset 22265:10b7696a5395

xl: allow parsing of both old and new cpuid syntax

Allow parsing of both versions of the cpuid syntax, the old xm used one
and the new one for xl. This works automatically, as the parser can tell
a Python list apart from a string before processing the line.

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:22:40 2010 +0100 (2010-10-01)
parents a8c72f5a6bce
children fb8291d00262
files tools/libxl/xl_cmdimpl.c
line diff
     1.1 --- a/tools/libxl/xl_cmdimpl.c	Fri Oct 01 17:21:01 2010 +0100
     1.2 +++ b/tools/libxl/xl_cmdimpl.c	Fri Oct 01 17:22:40 2010 +0100
     1.3 @@ -647,7 +647,7 @@ static void parse_config_data(const char
     1.4      const char *buf;
     1.5      long l;
     1.6      XLU_Config *config;
     1.7 -    XLU_ConfigList *vbds, *nics, *pcis, *cvfbs, *net2s;
     1.8 +    XLU_ConfigList *vbds, *nics, *pcis, *cvfbs, *net2s, *cpuids;
     1.9      int pci_power_mgmt = 0;
    1.10      int pci_msitranslate = 1;
    1.11      int e;
    1.12 @@ -1085,15 +1085,82 @@ skip_vfb:
    1.13          }
    1.14      }
    1.15  
    1.16 -    if (!xlu_cfg_get_string(config, "cpuid", &buf)) {
    1.17 -        char *buf2, *p, *strtok_ptr;
    1.18 -
    1.19 -        buf2 = strdup(buf);
    1.20 -        p = strtok_r(buf2, ",", &strtok_ptr);
    1.21 -        for (p = strtok_r(NULL, ",", &strtok_ptr); p != NULL;
    1.22 -             p = strtok_r(NULL, ",", &strtok_ptr))
    1.23 -            libxl_cpuid_parse_config(&b_info->cpuid, p);
    1.24 -        free(buf2);
    1.25 +    switch (xlu_cfg_get_list(config, "cpuid", &cpuids, 0, 1)) {
    1.26 +    case 0:
    1.27 +        {
    1.28 +            int i;
    1.29 +            char *errstr;
    1.30 +
    1.31 +            for (i = 0; (buf = xlu_cfg_get_listitem(cpuids, i)) != NULL; i++) {
    1.32 +                e = libxl_cpuid_parse_config_xend(&b_info->cpuid, buf);
    1.33 +                switch (e) {
    1.34 +                case 0: continue;
    1.35 +                case 1:
    1.36 +                    errstr = "illegal leaf number";
    1.37 +                    break;
    1.38 +                case 2:
    1.39 +                    errstr = "illegal subleaf number";
    1.40 +                    break;
    1.41 +                case 3:
    1.42 +                    errstr = "missing colon";
    1.43 +                    break;
    1.44 +                case 4:
    1.45 +                    errstr = "invalid register name (must be e[abcd]x)";
    1.46 +                    break;
    1.47 +                case 5:
    1.48 +                    errstr = "policy string must be exactly 32 characters long";
    1.49 +                    break;
    1.50 +                default:
    1.51 +                    errstr = "unknown error";
    1.52 +                    break;
    1.53 +                }
    1.54 +                fprintf(stderr, "while parsing CPUID line: \"%s\":\n", buf);
    1.55 +                fprintf(stderr, "  error #%i: %s\n", e, errstr);
    1.56 +            }
    1.57 +        }
    1.58 +        break;
    1.59 +    case EINVAL:    /* config option is not a list, parse as a string */
    1.60 +        if (!xlu_cfg_get_string(config, "cpuid", &buf)) {
    1.61 +            char *buf2, *p, *errstr, *strtok_ptr = NULL;
    1.62 +
    1.63 +            buf2 = strdup(buf);
    1.64 +            p = strtok_r(buf2, ",", &strtok_ptr);
    1.65 +            if (p == NULL) {
    1.66 +                free(buf2);
    1.67 +                break;
    1.68 +            }
    1.69 +            if (strcmp(p, "host")) {
    1.70 +                fprintf(stderr, "while parsing CPUID string: \"%s\":\n", buf);
    1.71 +                fprintf(stderr, "  error: first word must be \"host\"\n");
    1.72 +                free(buf2);
    1.73 +                break;
    1.74 +            }
    1.75 +            for (p = strtok_r(NULL, ",", &strtok_ptr); p != NULL;
    1.76 +                 p = strtok_r(NULL, ",", &strtok_ptr)) {
    1.77 +                e = libxl_cpuid_parse_config(&b_info->cpuid, p);
    1.78 +                switch (e) {
    1.79 +                case 0: continue;
    1.80 +                case 1:
    1.81 +                    errstr = "missing \"=\" in key=value";
    1.82 +                    break;
    1.83 +                case 2:
    1.84 +                    errstr = "unknown CPUID flag name";
    1.85 +                    break;
    1.86 +                case 3:
    1.87 +                    errstr = "illegal CPUID value (must be: [0|1|x|k|s])";
    1.88 +                    break;
    1.89 +                default:
    1.90 +                    errstr = "unknown error";
    1.91 +                    break;
    1.92 +                }
    1.93 +                fprintf(stderr, "while parsing CPUID flag: \"%s\":\n", p);
    1.94 +                fprintf(stderr, "  error #%i: %s\n", e, errstr);
    1.95 +            }
    1.96 +            free(buf2);
    1.97 +        }
    1.98 +        break;
    1.99 +    default:
   1.100 +        break;
   1.101      }
   1.102  
   1.103      if (c_info->hvm == 1) {