[PATCHv2 5/5] S390: Added sysinfo for host on s390x.

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

 



From: Thang Pham <thang.pham@xxxxxxxxxx>

In order to retrieve some sysinfo data we need to parse /proc/sysinfo and
/proc/cpuinfo.

Signed-off-by: Thang Pham <thang.pham@xxxxxxxxxx>
Signed-off-by: Viktor Mihajlovski <mihajlov@xxxxxxxxxxxxxxxxxx>
---
 src/util/sysinfo.c |  154 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 154 insertions(+), 0 deletions(-)

diff --git a/src/util/sysinfo.c b/src/util/sysinfo.c
index 78efc32..01cce98 100644
--- a/src/util/sysinfo.c
+++ b/src/util/sysinfo.c
@@ -44,6 +44,7 @@
                          __FUNCTION__, __LINE__, __VA_ARGS__)
 
 #define SYSINFO_SMBIOS_DECODER "dmidecode"
+#define SYSINFO "/proc/sysinfo"
 #define CPUINFO "/proc/cpuinfo"
 
 VIR_ENUM_IMPL(virSysinfo, VIR_SYSINFO_LAST,
@@ -241,6 +242,159 @@ no_memory:
     return NULL;
 }
 
+#elif defined(__s390__) || defined(__s390x__)
+
+static int
+virSysinfoParseSystem(const char *base, virSysinfoDefPtr ret)
+{
+    char *cur, *eol = NULL;
+    const char *property;
+
+    /* Return if Manufacturer field is not found */
+    if ((cur = strstr(base, "Manufacturer")) == NULL)
+        return 0;
+
+    base = cur;
+    if ((cur = strstr(base, "Manufacturer")) != NULL) {
+        cur = strchr(cur, ':') + 1;
+        eol = strchr(cur, '\n');
+        virSkipSpacesBackwards(cur, &eol);
+        if ((eol) && ((property = strndup(cur, eol - cur)) == NULL))
+            goto no_memory;
+        virSkipSpaces(&property);
+        ret->system_manufacturer = (char *) property;
+    }
+    if ((cur = strstr(base, "Type")) != NULL) {
+        cur = strchr(cur, ':') + 1;
+        eol = strchr(cur, '\n');
+        virSkipSpacesBackwards(cur, &eol);
+        if ((eol) && ((property = strndup(cur, eol - cur)) == NULL))
+            goto no_memory;
+        virSkipSpaces(&property);
+        ret->system_family = (char *) property;
+    }
+    if ((cur = strstr(base, "Sequence Code")) != NULL) {
+        cur = strchr(cur, ':') + 1;
+        eol = strchr(cur, '\n');
+        virSkipSpacesBackwards(cur, &eol);
+        if ((eol) && ((property = strndup(cur, eol - cur)) == NULL))
+            goto no_memory;
+        virSkipSpaces(&property);
+        ret->system_serial = (char *) property;
+    }
+
+    return 0;
+
+no_memory:
+    return -1;
+}
+
+static int
+virSysinfoParseProcessor(const char *base, virSysinfoDefPtr ret)
+{
+    char *cur, *eol, *tmp_base;
+    char *manufacturer;
+    const char *tmp;
+    virSysinfoProcessorDefPtr processor;
+
+    if ((cur = strstr(base, "vendor_id")) != NULL) {
+        cur = strchr(cur, ':') + 1;
+        eol = strchr(cur, '\n');
+        virSkipSpacesBackwards(cur, &eol);
+        if ((eol) && ((tmp = strndup(cur, eol - cur)) == NULL))
+            goto no_memory;
+        virSkipSpaces(&tmp);
+        manufacturer = (char *) tmp;
+    }
+
+    /* Find processor N: line and gather the processor manufacturer, version, serial number, and family */
+    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];
+
+        /* Set the processor manufacturer */
+        processor->processor_manufacturer = manufacturer;
+
+        if ((cur = strstr(base, "version =")) != NULL) {
+            cur += sizeof("version =");
+            eol = strchr(cur, ',');
+            if ((eol) &&
+                ((processor->processor_version = strndup(cur, eol - cur)) == NULL))
+                goto no_memory;
+        }
+        if ((cur = strstr(base, "identification =")) != NULL) {
+            cur += sizeof("identification =");
+            eol = strchr(cur, ',');
+            if ((eol) &&
+                ((processor->processor_serial_number = strndup(cur, eol - cur)) == NULL))
+                goto no_memory;
+        }
+        if ((cur = strstr(base, "machine =")) != NULL) {
+            cur += sizeof("machine =");
+            eol = strchr(cur, '\n');
+            if ((eol) &&
+                ((processor->processor_family = strndup(cur, eol - cur)) == NULL))
+                goto no_memory;
+        }
+
+        base = cur;
+    }
+
+    return 0;
+
+no_memory:
+    return -1;
+}
+
+/* virSysinfoRead for s390x
+ * Gathers sysinfo data from /proc/sysinfo and /proc/cpuinfo */
+virSysinfoDefPtr
+virSysinfoRead(void) {
+    virSysinfoDefPtr ret = NULL;
+    char *outbuf = NULL;
+
+    if (VIR_ALLOC(ret) < 0)
+        goto no_memory;
+
+    /* Gather info from /proc/cpuinfo */
+    if(virFileReadAll(CPUINFO, 2048, &outbuf) < 0) {
+        virSmbiosReportError(VIR_ERR_INTERNAL_ERROR,
+                             _("Failed to open %s"), CPUINFO);
+        return NULL;
+    }
+
+    ret->nprocessor = 0;
+    ret->processor = NULL;
+    if (virSysinfoParseProcessor(outbuf, ret) < 0)
+        goto no_memory;
+
+    /* Free buffer before reading next file */
+    VIR_FREE(outbuf);
+
+    /* Gather info from /proc/sysinfo */
+    if(virFileReadAll(SYSINFO, 4096, &outbuf) < 0) {
+              virSmbiosReportError(VIR_ERR_INTERNAL_ERROR,
+                                   _("Failed to open %s"), SYSINFO);
+              return NULL;
+       }
+
+    if (virSysinfoParseSystem(outbuf, ret) < 0)
+        goto no_memory;
+
+    return ret;
+
+no_memory:
+    VIR_FREE(outbuf);
+    return NULL;
+}
+
 #elif defined(WIN32) || \
     !(defined(__x86_64__) || \
       defined(__i386__) ||   \
-- 
1.7.0.4

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