Re: [PATCH] hyperv: Handle long CPU models better.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Apr 8, 2021 at 11:52 AM Dawid Zamirski <dzrudy@xxxxxxxxx> wrote:
>
> Apparenlly exising code was dealing with stripping down Intel CPU models
> as reported by Hyper-V host but was still having issues with my AMD CPU
> for which Hyper-V returns "AMD FX(tm)-8350 Eight-Core Processor".
> Therefore, this patch deals with it by stripping out the "
> Processor" part, and if there's another CPU that we don't know of
> yet that causes trouble, trim the resulting string to 32 characters
> rather than failing as the node info has other information that are
> more useful than the model.
> ---
>  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
>

Looks reasonable to me.

When you resend with the Signed-off-by statement added, you can also add:

Reviewed-by: Neal Gompa <ngompa13@xxxxxxxxx>


-- 
真実はいつも一つ!/ Always, there's only one truth!





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux