All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 5/5] xl: enable parser switch for both legacy and new cpuid parsers
@ 2010-09-16 13:12 Andre Przywara
  0 siblings, 0 replies; 2+ messages in thread
From: Andre Przywara @ 2010-09-16 13:12 UTC (permalink / raw)
  To: Stefano Stabellini, Ian Campbell; +Cc: xen-devel, Keir Fraser

[-- Attachment #1: Type: text/plain, Size: 322 bytes --]

Allow parsing of both versions of cpuid syntax. 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>

-- 
Andre Przywara
AMD-Operating System Research Center (OSRC), Dresden, Germany
Tel: +49 351 448-3567-12

[-- Attachment #2: 0005-xl-enable-parser-switch-for-both-legacy-and-new-cpui.patch --]
[-- Type: text/x-patch, Size: 4368 bytes --]

>From 74bcb38310c5ed7f81abb034b5b066dc7a40cae9 Mon Sep 17 00:00:00 2001
From: Andre Przywara <andre.przywara@amd.com>
Date: Mon, 6 Sep 2010 18:01:59 +0200
Subject: [PATCH 5/5] xl: enable parser switch for both legacy and new cpuid parsers

allow parsing of both versions of cpuid syntax. 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>
---
 tools/libxl/xl_cmdimpl.c |   85 ++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 75 insertions(+), 10 deletions(-)

diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index 646f162..ee7f36a 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -577,7 +577,7 @@ static void parse_config_data(const char *configfile_filename_report,
     const char *buf;
     long l;
     XLU_Config *config;
-    XLU_ConfigList *vbds, *nics, *pcis, *cvfbs, *net2s;
+    XLU_ConfigList *vbds, *nics, *pcis, *cvfbs, *net2s, *cpuids;
     int pci_power_mgmt = 0;
     int pci_msitranslate = 1;
     int e;
@@ -1012,15 +1012,80 @@ skip_vfb:
         }
     }
 
-    if (!xlu_cfg_get_string(config, "cpuid", &buf)) {
-        char *buf2, *p, *strtok_ptr;
+    switch (xlu_cfg_get_type(config, "cpuid")) {
+    case XLU_CFG_LIST:
+        if (!xlu_cfg_get_list(config, "cpuid", &cpuids, 0)) {
+            int i;
+            char *errstr;
 
-        buf2 = strdup(buf);
-        p = strtok_r(buf2, ",", &strtok_ptr);
-        for (p = strtok_r(NULL, ",", &strtok_ptr); p != NULL;
-             p = strtok_r(NULL, ",", &strtok_ptr))
-            libxl_cpuid_parse_config(&b_info->cpuid, p);
-        free(buf2);
+            for(i = 0; (buf = xlu_cfg_get_listitem (cpuids, i)) != NULL; i++) {
+                e = libxl_cpuid_parse_config_legacy(&b_info->cpuid, buf);
+                switch (e) {
+                case 0: continue;
+                case 1:
+                    errstr = "illegal leaf number";
+                    break;
+                case 2:
+                    errstr = "illegal subleaf number";
+                    break;
+                case 3:
+                    errstr = "missing colon";
+                    break;
+                case 4:
+                    errstr = "invalid register name (must be e[abcd]x)";
+                    break;
+                case 5:
+                    errstr = "policy string must be exactly 32 characters long";
+                    break;
+                default:
+                    errstr = "unknown error";
+                    break;
+                }
+                fprintf(stderr, "while parsing CPUID line: \"%s\":\n", buf);
+                fprintf(stderr, "  error #%i: %s\n", e, errstr);
+            }
+        }
+        break;
+    case XLU_CFG_STRING:
+        if (!xlu_cfg_get_string(config, "cpuid", &buf)) {
+            char *buf2, *p, *errstr, *strtok_ptr;
+
+            buf2 = strdup(buf);
+            p = strtok_r(buf2, ",", &strtok_ptr);
+            if (p == NULL) {
+                free(buf2);
+                break;
+            }
+            if (strcmp(p, "host")) {
+                fprintf(stderr, "while parsing CPUID string: \"%s\":\n", buf);
+                fprintf(stderr, "  error: first word must be \"host\"\n");
+                free(buf2);
+                break;
+            }
+            for (p = strtok_r(NULL, ",", &strtok_ptr); p != NULL;
+                 p = strtok_r(NULL, ",", &strtok_ptr)) {
+                e = libxl_cpuid_parse_config(&b_info->cpuid, p);
+                switch (e) {
+                case 0: continue;
+                case 1:
+                    errstr = "missing \"=\" in key=value";
+                    break;
+                case 2:
+                    errstr = "unknown CPUID flag name";
+                    break;
+                case 3:
+                    errstr = "illegal CPUID value (must be: [0|1|x|k|s])";
+                    break;
+                default:
+                    errstr = "unknown error";
+                    break;
+                }
+                fprintf(stderr, "while parsing CPUID flag: \"%s\":\n", p);
+                fprintf(stderr, "  error #%i: %s\n", e, errstr);
+            }
+            free(buf2);
+        }
+        break;
     }
 
     if (c_info->hvm == 1) {
-- 
1.6.4


[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 5/5] xl: enable parser switch for both legacy and new cpuid parsers
@ 2010-09-08  9:24 Andre Przywara
  0 siblings, 0 replies; 2+ messages in thread
From: Andre Przywara @ 2010-09-08  9:24 UTC (permalink / raw)
  To: Stefano Stabellini, Keir Fraser; +Cc: xen-devel

[-- Attachment #1: Type: text/plain, Size: 322 bytes --]

Allow parsing of both versions of cpuid syntax. 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>

-- 
Andre Przywara
AMD-Operating System Research Center (OSRC), Dresden, Germany
Tel: +49 351 448-3567-12

[-- Attachment #2: 0005-xl-enable-parser-switch-for-both-legacy-and-new-cpui.patch --]
[-- Type: text/x-patch, Size: 4038 bytes --]

>From 40ed291421fa138a645605c7110fa9595c951e18 Mon Sep 17 00:00:00 2001
From: Andre Przywara <andre.przywara@amd.com>
Date: Mon, 6 Sep 2010 18:01:59 +0200
Subject: [PATCH 5/5] xl: enable parser switch for both legacy and new cpuid parsers

allow parsing of both versions of cpuid syntax. 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>
---
 tools/libxl/xl_cmdimpl.c |   76 +++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 68 insertions(+), 8 deletions(-)

diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index 018e5b0..e7b9d74 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -574,7 +574,7 @@ static void parse_config_data(const char *configfile_filename_report,
     const char *buf;
     long l;
     XLU_Config *config;
-    XLU_ConfigList *vbds, *nics, *pcis, *cvfbs, *net2s;
+    XLU_ConfigList *vbds, *nics, *pcis, *cvfbs, *net2s, *cpuids;
     int pci_power_mgmt = 0;
     int pci_msitranslate = 1;
     int e;
@@ -1015,14 +1015,74 @@ skip_vfb:
         }
     }
 
-    if (!xlu_cfg_get_string(config, "cpuid", &buf)) {
-        char *buf2, *p;
+    switch (xlu_cfg_get_type(config, "cpuid")) {
+    case XLU_CFG_LIST:
+        if (!xlu_cfg_get_list(config, "cpuid", &cpuids, 0)) {
+            int i;
+            char *errstr;
 
-        buf2 = strdup(buf);
-        p = strtok(buf2, ",");
-        for (p = strtok(NULL, ","); p != NULL; p = strtok(NULL, ","))
-            libxl_cpuid_parse_config(&b_info->cpuid, p);
-        free(buf2);
+            for(i = 0; (buf = xlu_cfg_get_listitem (cpuids, i)) != NULL; i++) {
+                e = libxl_cpuid_parse_config_legacy(&b_info->cpuid, buf);
+                switch (e) {
+                case 0: continue;
+                case 1:
+                    errstr = "illegal leaf number";
+                    break;
+                case 2:
+                    errstr = "illegal subleaf number";
+                    break;
+                case 3:
+                    errstr = "missing colon";
+                    break;
+                case 4:
+                    errstr = "invalid register name (must be e[abcd]x)";
+                    break;
+                case 5:
+                    errstr = "policy string must be exactly 32 characters long";
+                    break;
+                default:
+                    errstr = "unknown error";
+                    break;
+                }
+                fprintf(stderr, "while parsing CPUID line: \"%s\":\n", buf);
+                fprintf(stderr, "  error #%i: %s\n", e, errstr);
+            }
+        }
+        break;
+    case XLU_CFG_STRING:
+        if (!xlu_cfg_get_string(config, "cpuid", &buf)) {
+            char *buf2, *p, *errstr;
+
+            buf2 = strdup(buf);
+            p = strtok(buf2, ",");
+            if (strcmp(p, "host")) {
+                fprintf(stderr, "first word in CPUID must be host\n");
+                free(buf2);
+                break;
+            }
+            for (p = strtok(NULL, ","); p != NULL; p = strtok(NULL, ",")) {
+                e = libxl_cpuid_parse_config(&b_info->cpuid, p);
+                switch (e) {
+                case 0: continue;
+                case 1:
+                    errstr = "missing \"=\" in key=value";
+                    break;
+                case 2:
+                    errstr = "unknown CPUID flag name";
+                    break;
+                case 3:
+                    errstr = "illegal CPUID value (must be: [0|1|x|k|s])";
+                    break;
+                default:
+                    errstr = "unknown error";
+                    break;
+                }
+                fprintf(stderr, "while parsing CPUID flag: \"%s\":\n", p);
+                fprintf(stderr, "  error #%i: %s\n", e, errstr);
+            }
+            free(buf2);
+        }
+        break;
     }
 
     if (c_info->hvm == 1) {
-- 
1.6.4


[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-09-16 13:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-16 13:12 [PATCH 5/5] xl: enable parser switch for both legacy and new cpuid parsers Andre Przywara
  -- strict thread matches above, loose matches on Subject: below --
2010-09-08  9:24 Andre Przywara

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.