[PATCH 2/2] Allow x86 to fetch sysinfo from /proc/cpuinfo when dmidecode is absent.

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

 



From: Prerna Saxena <prerna@xxxxxxxxxxxxxxxxxx>
Date: Thu, 16 Feb 2012 15:33:43 +0530
Subject: [PATCH 2/2] Sysinfo : Allow x86 to fetch sysinfo from
 /proc/cpuinfo in the event 'dmidecode' is absent in the
 system.

Based on Eric's suggestion
(http://www.redhat.com/archives/libvir-list/2012-February/msg00509.html)

--- src/util/sysinfo.c |   95
+++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 91
insertions(+), 4 deletions(-)

diff --git a/src/util/sysinfo.c b/src/util/sysinfo.c
index 0161b22..5ca725e 100644
--- a/src/util/sysinfo.c
+++ b/src/util/sysinfo.c
@@ -596,6 +596,96 @@ no_memory:
     return -1;
 }
 
+/* If a call to 'dmidecode' fails,
+ * extract basic sysinfo from /proc/cpuinfo */
+
+static int
+virSysinfoParseCPUInfoProcessor(const char *base, virSysinfoDefPtr ret)
+{
+    char *cur, *eol, *tmp_base;
+    virSysinfoProcessorDefPtr processor;
+
+    while((tmp_base = strstr(base, "processor")) != NULL) {
+        base = tmp_base;
+        eol = strchr(base, '\n');
+        cur = strchr(base, ':') + 1;
+
+        if (VIR_EXPAND_N(ret->processor, ret->nprocessor, 1) < 0) {
+            goto no_memory;
+        }
+
+        processor = &ret->processor[ret->nprocessor - 1];
+        if ((eol) &&
+            ((processor->processor_socket_destination =
+                               strndup(cur, eol - cur)) == NULL))
+            goto no_memory;
+        virSkipSpaces(&(processor->processor_socket_destination));
+
+        if ((cur = strstr(base, "vendor_id")) != NULL) {
+            cur = strchr(cur, ':') + 1;
+            eol = strchr(cur, '\n');
+            if ((eol) &&
+                ((processor->processor_manufacturer =
+                                  strndup(cur, eol - cur)) == NULL))
+                goto no_memory;
+            virSkipSpaces(&(processor->processor_manufacturer));
+        }
+
+        if ((cur = strstr(base, "cpu family")) != NULL) {
+            cur = strchr(cur, ':') + 1;
+            eol = strchr(cur, '\n');
+            if ((eol) &&
+                ((processor->processor_family = strndup(cur, eol -
cur)) ==
+
NULL))
+                goto no_memory;
+            virSkipSpaces(&(processor->processor_family));
+        }
+
+        if ((cur = strstr(base, "model name")) != NULL) {
+            cur = strchr(cur, ':') + 1;
+            eol = strchr(cur, '\n');
+            if ((eol) &&
+                ((processor->processor_type = strndup(cur, eol - cur))
==
+
NULL))
+                goto no_memory;
+            virSkipSpaces(&(processor->processor_type));
+        }
+
+        base = cur;
+    }
+
+    return 0;
+
+no_memory:
+    return -1;
+}
+
+static virSysinfoDefPtr
+virCPUInfoSysinfoRead(void) {
+    virSysinfoDefPtr ret = NULL;
+    char *outbuf = NULL;
+
+    if (VIR_ALLOC(ret) < 0)
+        goto no_memory;
+
+    if(virFileReadAll(CPUINFO, 20000, &outbuf) < 0) {
+        virSmbiosReportError(VIR_ERR_INTERNAL_ERROR,
+                             _("Failed to open %s"), CPUINFO);
+        return NULL;
+    }
+
+    ret->nprocessor = 0;
+    ret->processor = NULL;
+    if (virSysinfoParseCPUInfoProcessor(outbuf, ret) < 0)
+        goto no_memory;
+
+    return ret;
+
+no_memory:
+    VIR_FREE(outbuf);
+    return NULL;
+}
+
 virSysinfoDefPtr
 virSysinfoRead(void) {
     char *path;
@@ -605,10 +695,7 @@ virSysinfoRead(void) {
 
     path = virFindFileInPath(SYSINFO_SMBIOS_DECODER);
     if (path == NULL) {
-        virSmbiosReportError(VIR_ERR_INTERNAL_ERROR,
-                             _("Failed to find path for %s binary"),
-                             SYSINFO_SMBIOS_DECODER);
-        return NULL;
+        return virCPUInfoSysinfoRead();
     }
 
     cmd = virCommandNewArgList(path, "-q", "-t", "0,1,4,17", NULL);
-- 
1.7.7



-- 
Prerna Saxena

Linux Technology Centre,
IBM Systems and Technology Lab,
Bangalore, India

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[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]