libxl: implementing legacy xm cpuid parser
authorAndre Przywara <andre.przywara@amd.com>
Fri, 1 Oct 2010 16:21:01 +0000 (17:21 +0100)
committerAndre Przywara <andre.przywara@amd.com>
Fri, 1 Oct 2010 16:21:01 +0000 (17:21 +0100)
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>

tools/libxl/libxl.c
tools/libxl/libxl.h

index b61f8599c38ce414cda32acdbce53950c35e1f73..7e7bc3ddeb49ad3a226d874c504c2e2c3f4577b9 100644 (file)
@@ -3743,6 +3743,66 @@ int libxl_cpuid_parse_config(libxl_cpuid_policy_list *cpuid, const char* str)
     return 0;
 }
 
+/* parse a single list item from the legacy Python xend syntax, where
+ * the strings for each register were directly exposed to the user.
+ * Used for maintaining compatibility with older config files
+ */
+int libxl_cpuid_parse_config_xend(libxl_cpuid_policy_list *cpuid,
+                                  const char* str)
+{
+    char *endptr;
+    unsigned long value;
+    uint32_t leaf, subleaf = XEN_CPUID_INPUT_UNUSED;
+    struct libxl__cpuid_policy *entry;
+
+    /* parse the leaf number */
+    value = strtoul(str, &endptr, 0);
+    if (str == endptr) {
+        return 1;
+    }
+    leaf = value;
+    /* check for an optional subleaf number */
+    if (*endptr == ',') {
+        str = endptr + 1;
+        value = strtoul(str, &endptr, 0);
+        if (str == endptr) {
+            return 2;
+        }
+        subleaf = value;
+    }
+    if (*endptr != ':') {
+        return 3;
+    }
+    str = endptr + 1;
+    entry = cpuid_find_match(cpuid, leaf, subleaf);
+    for (str = endptr + 1; *str != 0;) {
+        if (str[0] != 'e' || str[2] != 'x') {
+            return 4;
+        }
+        value = str[1] - 'a';
+        endptr = strchr(str, '=');
+        if (value < 0 || value > 3 || endptr == NULL) {
+            return 4;
+        }
+        str = endptr + 1;
+        endptr = strchr(str, ',');
+        if (endptr == NULL) {
+            endptr = strchr(str, 0);
+        }
+        if (endptr - str != 32) {
+            return 5;
+        }
+        entry->policy[value] = calloc(32 + 1, 1);
+        strncpy(entry->policy[value], str, 32);
+        entry->policy[value][32] = 0;
+        if (*endptr == 0) {
+            break;
+        }
+        for (str = endptr + 1; *str == ' ' || *str == '\n'; str++);
+    }
+    return 0;
+}
+
 char *libxl_tmem_list(libxl_ctx *ctx, uint32_t domid, int use_long)
 {
     int rc;
index a1e0fa400c340ddf7a08f61fd067f030bfb95a0f..21030e4d7066f6105b7fa1c239608d2402ea70cc 100644 (file)
@@ -412,6 +412,8 @@ int libxl_device_pci_list_assigned(libxl_ctx *ctx, libxl_device_pci **list, uint
 int libxl_device_pci_list_assignable(libxl_ctx *ctx, libxl_device_pci **list, int *num);
 int libxl_device_pci_parse_bdf(libxl_ctx *ctx, libxl_device_pci *pcidev, const char *str);
 int libxl_cpuid_parse_config(libxl_cpuid_policy_list *cpuid, const char* str);
+int libxl_cpuid_parse_config_xend(libxl_cpuid_policy_list *cpuid,
+                                  const char* str);
 
 /*
  * Functions for allowing users of libxl to store private data