[libvirt PATCH 3/6] hostcpu: Implement virHostCPUGetSignature for x86
Ján Tomko
jtomko at redhat.com
Tue May 19 14:55:14 UTC 2020
On a Monday in 2020, Jiri Denemark wrote:
>Signed-off-by: Jiri Denemark <jdenemar at redhat.com>
>---
> src/util/virhostcpu.c | 50 +++++++++++++++++--
> .../linux-x86_64-test1.signature | 1 +
> .../linux-x86_64-test2.signature | 1 +
> .../linux-x86_64-test3.signature | 1 +
> .../linux-x86_64-test4.signature | 1 +
> .../linux-x86_64-test5.signature | 1 +
> .../linux-x86_64-test6.signature | 1 +
> .../linux-x86_64-test7.signature | 1 +
> .../linux-x86_64-test8.signature | 1 +
> .../linux-x86_64-with-die.signature | 1 +
> 10 files changed, 56 insertions(+), 3 deletions(-)
> create mode 100644 tests/virhostcpudata/linux-x86_64-test1.signature
> create mode 100644 tests/virhostcpudata/linux-x86_64-test2.signature
> create mode 100644 tests/virhostcpudata/linux-x86_64-test3.signature
> create mode 100644 tests/virhostcpudata/linux-x86_64-test4.signature
> create mode 100644 tests/virhostcpudata/linux-x86_64-test5.signature
> create mode 100644 tests/virhostcpudata/linux-x86_64-test6.signature
> create mode 100644 tests/virhostcpudata/linux-x86_64-test7.signature
> create mode 100644 tests/virhostcpudata/linux-x86_64-test8.signature
> create mode 100644 tests/virhostcpudata/linux-x86_64-with-die.signature
>
>diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c
>index bfef022f64..851c0015f7 100644
>--- a/src/util/virhostcpu.c
>+++ b/src/util/virhostcpu.c
>@@ -1418,10 +1418,54 @@ virHostCPUGetTscInfo(void)
> (defined(__linux__) || defined(__FreeBSD__)) */
>
> int
>-virHostCPUReadSignature(virArch arch G_GNUC_UNUSED,
>- FILE *cpuinfo G_GNUC_UNUSED,
>- char **signature G_GNUC_UNUSED)
>+virHostCPUReadSignature(virArch arch,
>+ FILE *cpuinfo,
>+ char **signature)
> {
>+ size_t lineLen = 1024;
>+ g_autofree char *line = g_new0(char, lineLen);
>+ g_autofree char *vendor = NULL;
>+ g_autofree char *name = NULL;
>+ g_autofree char *family = NULL;
>+ g_autofree char *model = NULL;
>+ g_autofree char *stepping = NULL;
>+
>+ if (!ARCH_IS_X86(arch))
>+ return 0;
>+
>+ while (fgets(line, lineLen, cpuinfo)) {
>+ g_auto(GStrv) parts = g_strsplit(line, ": ", 2);
Indendation
>+
>+ if (g_strv_length(parts) != 2)
>+ continue;
>+
>+ g_strstrip(parts[0]);
>+ g_strstrip(parts[1]);
>+
>+ if (STREQ(parts[0], "vendor_id")) {
>+ if (!vendor)
>+ vendor = g_steal_pointer(&parts[1]);
>+ } else if (STREQ(parts[0], "model name")) {
>+ if (!name)
>+ name = g_steal_pointer(&parts[1]);
>+ } else if (STREQ(parts[0], "cpu family")) {
>+ if (!family)
>+ family = g_steal_pointer(&parts[1]);
>+ } else if (STREQ(parts[0], "model")) {
>+ if (!model)
>+ model = g_steal_pointer(&parts[1]);
>+ } else if (STREQ(parts[0], "stepping")) {
>+ if (!stepping)
>+ stepping = g_steal_pointer(&parts[1]);
>+ }
>+
>+ if (vendor && name && family && model && stepping) {
>+ *signature = g_strdup_printf("%s, %s, family: %s, model: %s, stepping: %s",
>+ vendor, name, family, model, stepping);
>+ return 0;
>+ }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20200519/659dd724/attachment-0001.sig>
More information about the libvir-list
mailing list