Add Processor Information to virSysinfoRead() from dmidecode type 4
Signed-off-by: Minoru Usui <usui(a)mxm.nes.nec.co.jp>
---
src/util/sysinfo.c | 207 +++++++++++++++++++++++++++++++++++++++++++++++++++-
src/util/sysinfo.h | 19 +++++
2 files changed, 225 insertions(+), 1 deletions(-)
diff --git a/src/util/sysinfo.c b/src/util/sysinfo.c
index 53122f7..a1eb92b 100644
--- a/src/util/sysinfo.c
+++ b/src/util/sysinfo.c
@@ -72,6 +72,9 @@ void virSysinfoDefFree(virSysinfoDefPtr def)
VIR_FREE(def->system_uuid);
VIR_FREE(def->system_sku);
VIR_FREE(def->system_family);
+
+ VIR_FREE(def->processor);
+
VIR_FREE(def);
}
@@ -190,6 +193,107 @@ no_memory:
return NULL;
}
+static char *
+parseProcessorInfo(char *base, virSysinfoDefPtr ret)
+{
+ char *cur, *eol, *tmp_base;
+ virProcessorinfoDefPtr processor;
+
+ while((tmp_base = strstr(base, "Processor Information")) != NULL) {
+ base = tmp_base;
+
+ if (VIR_EXPAND_N(ret->processor, ret->nprocessor, 1) < 0) {
+ goto no_memory;
+ }
+ processor = &ret->processor[ret->nprocessor - 1];
+
+ if ((cur = strstr(base, "Socket Designation: ")) != NULL) {
+ cur += 20;
+ eol = strchr(cur, '\n');
+ if ((eol) &&
+ ((processor->processor_socket_destination = strndup(cur, eol - cur))
== NULL))
+ goto no_memory;
+ }
+ if ((cur = strstr(base, "Type: ")) != NULL) {
+ cur += 6;
+ eol = strchr(cur, '\n');
+ if ((eol) &&
+ ((processor->processor_type = strndup(cur, eol - cur)) == NULL))
+ goto no_memory;
+ }
+ if ((cur = strstr(base, "Family: ")) != NULL) {
+ cur += 8;
+ eol = strchr(cur, '\n');
+ if ((eol) &&
+ ((processor->processor_family = strndup(cur, eol - cur)) == NULL))
+ goto no_memory;
+ }
+ if ((cur = strstr(base, "Manufacturer: ")) != NULL) {
+ cur += 14;
+ eol = strchr(cur, '\n');
+ if ((eol) &&
+ ((processor->processor_manufacturer = strndup(cur, eol - cur)) ==
NULL))
+ goto no_memory;
+ }
+ if ((cur = strstr(base, "Signature: ")) != NULL) {
+ cur += 11;
+ eol = strchr(cur, '\n');
+ if ((eol) &&
+ ((processor->processor_signature = strndup(cur, eol - cur)) == NULL))
+ goto no_memory;
+ }
+ if ((cur = strstr(base, "Version: ")) != NULL) {
+ cur += 9;
+ eol = strchr(cur, '\n');
+ if ((eol) &&
+ ((processor->processor_version = strndup(cur, eol - cur)) == NULL))
+ goto no_memory;
+ }
+ if ((cur = strstr(base, "External Clock: ")) != NULL) {
+ cur += 16;
+ eol = strchr(cur, '\n');
+ if ((eol) &&
+ ((processor->processor_external_clock = strndup(cur, eol - cur)) ==
NULL))
+ goto no_memory;
+ }
+ if ((cur = strstr(base, "Max Speed: ")) != NULL) {
+ cur += 11;
+ eol = strchr(cur, '\n');
+ if ((eol) &&
+ ((processor->processor_max_speed = strndup(cur, eol - cur)) == NULL))
+ goto no_memory;
+ }
+ if ((cur = strstr(base, "Status: ")) != NULL) {
+ cur += 8;
+ eol = strchr(cur, '\n');
+ if ((eol) &&
+ ((processor->processor_status = strndup(cur, eol - cur)) == NULL))
+ goto no_memory;
+ }
+ if ((cur = strstr(base, "Serial Number: ")) != NULL) {
+ cur += 15;
+ eol = strchr(cur, '\n');
+ if ((eol) &&
+ ((processor->processor_serial_number = strndup(cur, eol - cur)) ==
NULL))
+ goto no_memory;
+ }
+ if ((cur = strstr(base, "Part Number: ")) != NULL) {
+ cur += 13;
+ eol = strchr(cur, '\n');
+ if ((eol) &&
+ ((processor->processor_part_number = strndup(cur, eol - cur)) ==
NULL))
+ goto no_memory;
+ }
+
+ base = eol + 1;
+ }
+
+ return base;
+
+no_memory:
+ return NULL;
+}
+
virSysinfoDefPtr
virSysinfoRead(void) {
char *path, *base;
@@ -205,7 +309,7 @@ virSysinfoRead(void) {
return NULL;
}
- cmd = virCommandNewArgList(path, "-q", "-t",
"0,1,4,17", NULL);
+ cmd = virCommandNewArgList(path, "-q", "-t", "0,1,4",
NULL);
VIR_FREE(path);
virCommandSetOutputBuffer(cmd, &outbuf);
if (virCommandRun(cmd, NULL) < 0) {
@@ -228,6 +332,11 @@ virSysinfoRead(void) {
if ((base = parseSystemInfo(base, ret)) == NULL)
goto no_memory;
+ ret->nprocessor = 0;
+ ret->processor = NULL;
+ if ((base = parseProcessorInfo(base, ret)) == NULL)
+ goto no_memory;
+
cleanup:
VIR_FREE(outbuf);
virCommandFree(cmd);
@@ -339,6 +448,101 @@ SystemInfoFormat(virSysinfoDefPtr def, const char *prefix,
virBufferPtr buf)
return;
}
+static void
+ProcessorInfoFormat(virSysinfoDefPtr def, const char *prefix, virBufferPtr buf)
+{
+ int i;
+ int len = strlen(prefix);
+ virProcessorinfoDefPtr processor;
+
+ for (i = 0; i < def->nprocessor; i++) {
+ processor = &def->processor[i];
+
+ if ((processor->processor_socket_destination != NULL) ||
+ (processor->processor_type != NULL) ||
+ (processor->processor_family != NULL) ||
+ (processor->processor_manufacturer != NULL) ||
+ (processor->processor_signature != NULL) ||
+ (processor->processor_version != NULL) ||
+ (processor->processor_external_clock != NULL) ||
+ (processor->processor_max_speed != NULL) ||
+ (processor->processor_status != NULL) ||
+ (processor->processor_serial_number != NULL) ||
+ (processor->processor_part_number != NULL)) {
+ virBufferAsprintf(buf, "%s <processor>\n", prefix);
+ if (processor->processor_socket_destination != NULL) {
+ virBufferAdd(buf, prefix, len);
+ virBufferEscapeString(buf,
+ " <entry
name='socket_destination'>%s</entry>\n",
+ processor->processor_socket_destination);
+ }
+ if (processor->processor_type != NULL) {
+ virBufferAdd(buf, prefix, len);
+ virBufferEscapeString(buf,
+ " <entry
name='type'>%s</entry>\n",
+ processor->processor_type);
+ }
+ if (processor->processor_family != NULL) {
+ virBufferAdd(buf, prefix, len);
+ virBufferEscapeString(buf,
+ " <entry
name='family'>%s</entry>\n",
+ processor->processor_family);
+ }
+ if (processor->processor_manufacturer != NULL) {
+ virBufferAdd(buf, prefix, len);
+ virBufferEscapeString(buf,
+ " <entry
name='manufacturer'>%s</entry>\n",
+ processor->processor_manufacturer);
+ }
+ if (processor->processor_signature != NULL) {
+ virBufferAdd(buf, prefix, len);
+ virBufferEscapeString(buf,
+ " <entry
name='signature'>%s</entry>\n",
+ processor->processor_signature);
+ }
+ if (processor->processor_version != NULL) {
+ virBufferAdd(buf, prefix, len);
+ virBufferEscapeString(buf,
+ " <entry
name='version'>%s</entry>\n",
+ processor->processor_version);
+ }
+ if (processor->processor_external_clock != NULL) {
+ virBufferAdd(buf, prefix, len);
+ virBufferEscapeString(buf,
+ " <entry
name='external_clock'>%s</entry>\n",
+ processor->processor_external_clock);
+ }
+ if (processor->processor_max_speed != NULL) {
+ virBufferAdd(buf, prefix, len);
+ virBufferEscapeString(buf,
+ " <entry
name='max_speed'>%s</entry>\n",
+ processor->processor_max_speed);
+ }
+ if (processor->processor_status != NULL) {
+ virBufferAdd(buf, prefix, len);
+ virBufferEscapeString(buf,
+ " <entry
name='status'>%s</entry>\n",
+ processor->processor_status);
+ }
+ if (processor->processor_serial_number != NULL) {
+ virBufferAdd(buf, prefix, len);
+ virBufferEscapeString(buf,
+ " <entry
name='serial_number'>%s</entry>\n",
+ processor->processor_serial_number);
+ }
+ if (processor->processor_part_number != NULL) {
+ virBufferAdd(buf, prefix, len);
+ virBufferEscapeString(buf,
+ " <entry
name='part_number'>%s</entry>\n",
+ processor->processor_part_number);
+ }
+ virBufferAsprintf(buf, "%s </processor>\n", prefix);
+ }
+ }
+
+ return;
+}
+
/**
* virSysinfoFormat:
* @def: structure to convert to xml string
@@ -364,6 +568,7 @@ virSysinfoFormat(virSysinfoDefPtr def, const char *prefix)
BIOSInfoFormat(def, prefix, &buf);
SystemInfoFormat(def, prefix, &buf);
+ ProcessorInfoFormat(def, prefix, &buf);
virBufferAsprintf(&buf, "%s</sysinfo>\n", prefix);
diff --git a/src/util/sysinfo.h b/src/util/sysinfo.h
index f69b76c..f098e9d 100644
--- a/src/util/sysinfo.h
+++ b/src/util/sysinfo.h
@@ -33,6 +33,22 @@ enum virSysinfoType {
VIR_SYSINFO_LAST
};
+typedef struct _virProcessorinfoDef virProcessorinfoDef;
+typedef virProcessorinfoDef *virProcessorinfoDefPtr;
+struct _virProcessorinfoDef {
+ char *processor_socket_destination;
+ char *processor_type;
+ char *processor_family;
+ char *processor_manufacturer;
+ char *processor_signature;
+ char *processor_version;
+ char *processor_external_clock;
+ char *processor_max_speed;
+ char *processor_status;
+ char *processor_serial_number;
+ char *processor_part_number;
+};
+
typedef struct _virSysinfoDef virSysinfoDef;
typedef virSysinfoDef *virSysinfoDefPtr;
struct _virSysinfoDef {
@@ -50,6 +66,9 @@ struct _virSysinfoDef {
char *system_uuid;
char *system_sku;
char *system_family;
+
+ size_t nprocessor;
+ virProcessorinfoDefPtr processor;
};
virSysinfoDefPtr virSysinfoRead(void);
--
1.7.1