The existing driver code strips down CPU model strings returned by
Hyper-V hosts so they fit into the 32 character limit of the
virNodeInfo.model field. However, this did not work well for my AMD CPU
for which Hyper-V returns the string "AMD FX(tm)-8350 Eight-Core
Processor". Therefore, this patch improves that code block to be case
insensitive (so that the "(tm)" part is removed) and additionally
removes the trailing " Processor" suffix. While this change alone worked
for me, I have also added a line to terminate the stripped down string
at 32nd character to make sure that any other CPU string we did not come
across yet won't trigger the error - the virNodeInfo has other useful
info that is arguably more important than CPU model string, e.g. core
count, or memory size
Signed-off-by: Dawid Zamirski <dzrudy(a)gmail.com>
Reviewed-by: Neal Gompa <ngompa13(a)gmail.com>
---
Changes since v1:
* Added missing Signed-off-by
* Add Reviewed-by
* Reworded commit message
src/hyperv/hyperv_driver.c | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index 17f5be1f0d..6e03aa4f18 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -1948,14 +1948,14 @@ hypervNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info)
if (STRPREFIX(tmp, " ")) {
memmove(tmp, tmp + 1, strlen(tmp + 1) + 1);
continue;
- } else if (STRPREFIX(tmp, "(R)") || STRPREFIX(tmp, "(C)")) {
+ } else if (STRCASEPREFIX(tmp, "(R)") || STRCASEPREFIX(tmp,
"(C)")) {
memmove(tmp, tmp + 3, strlen(tmp + 3) + 1);
continue;
- } else if (STRPREFIX(tmp, "(TM)")) {
+ } else if (STRCASEPREFIX(tmp, "(TM)")) {
memmove(tmp, tmp + 4, strlen(tmp + 4) + 1);
continue;
- } else if (STRPREFIX(tmp, " @ ")) {
- /* Remove " @ X.YZGHz" from the end. */
+ } else if (STRPREFIX(tmp, " @ ") || STRPREFIX(tmp, "
Processor")) {
+ /* Remove " @ X.YZGHz" or " Processor" from the end. */
*tmp = '\0';
break;
}
@@ -1963,13 +1963,12 @@ hypervNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info)
++tmp;
}
+ /* trim whatever is left to 32 characters - better this than nothing */
+ processorList->data->Name[31] = '\0';
+
/* Fill struct */
- if (virStrcpyStatic(info->model, processorList->data->Name) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("CPU model %s too long for destination"),
- processorList->data->Name);
+ if (virStrcpyStatic(info->model, processorList->data->Name) < 0)
return -1;
- }
info->memory = computerSystem->data->TotalPhysicalMemory / 1024; /* byte to
kilobyte */
info->mhz = processorList->data->MaxClockSpeed;
--
2.31.1