Add Memory Device Information to virSysinfoRead() from dmidecode type 17 Signed-off-by: Minoru Usui <usui@xxxxxxxxxxxxxxxxx> --- src/util/sysinfo.c | 195 +++++++++++++++++++++++++++++++++++++++++++++++++++- src/util/sysinfo.h | 18 +++++ 2 files changed, 212 insertions(+), 1 deletions(-) diff --git a/src/util/sysinfo.c b/src/util/sysinfo.c index a1eb92b..7ebf355 100644 --- a/src/util/sysinfo.c +++ b/src/util/sysinfo.c @@ -74,6 +74,7 @@ void virSysinfoDefFree(virSysinfoDefPtr def) VIR_FREE(def->system_family); VIR_FREE(def->processor); + VIR_FREE(def->memory); VIR_FREE(def); } @@ -294,6 +295,104 @@ no_memory: return NULL; } +static char * +parseMemoryDeviceInfo(char *base, virSysinfoDefPtr ret) +{ + char *cur, *eol, *tmp_base; + virMemoryDeviceinfoDefPtr memory; + + while ((tmp_base = strstr(base, "Memory Device")) != NULL) { + base = tmp_base; + + if (VIR_EXPAND_N(ret->memory, ret->nmemory, 1) < 0) { + goto no_memory; + } + memory = &ret->memory[ret->nmemory - 1]; + + if ((cur = strstr(base, "Size: ")) != NULL) { + cur += 6; + eol = strchr(cur, '\n'); + if (STREQLEN(cur, "No Module Installed", eol - cur)) + goto next; + + if ((eol) && + ((memory->memory_size = strndup(cur, eol - cur)) == NULL)) + goto no_memory; + } + if ((cur = strstr(base, "Form Factor: ")) != NULL) { + cur += 13; + eol = strchr(cur, '\n'); + if ((eol) && + ((memory->memory_form_factor = strndup(cur, eol - cur)) == NULL)) + goto no_memory; + } + if ((cur = strstr(base, "Locator: ")) != NULL) { + cur += 9; + eol = strchr(cur, '\n'); + if ((eol) && + ((memory->memory_locator = strndup(cur, eol - cur)) == NULL)) + goto no_memory; + } + if ((cur = strstr(base, "Bank Locator: ")) != NULL) { + cur += 14; + eol = strchr(cur, '\n'); + if ((eol) && + ((memory->memory_bank_locator = strndup(cur, eol - cur)) == NULL)) + goto no_memory; + } + if ((cur = strstr(base, "Type: ")) != NULL) { + cur += 6; + eol = strchr(cur, '\n'); + if ((eol) && + ((memory->memory_type = strndup(cur, eol - cur)) == NULL)) + goto no_memory; + } + if ((cur = strstr(base, "Type Detail: ")) != NULL) { + cur += 13; + eol = strchr(cur, '\n'); + if ((eol) && + ((memory->memory_type_detail = strndup(cur, eol - cur)) == NULL)) + goto no_memory; + } + if ((cur = strstr(base, "Speed: ")) != NULL) { + cur += 7; + eol = strchr(cur, '\n'); + if ((eol) && + ((memory->memory_speed = strndup(cur, eol - cur)) == NULL)) + goto no_memory; + } + if ((cur = strstr(base, "Manufacturer: ")) != NULL) { + cur += 14; + eol = strchr(cur, '\n'); + if ((eol) && + ((memory->memory_manufacturer = strndup(cur, eol - cur)) == NULL)) + goto no_memory; + } + if ((cur = strstr(base, "Serial Number: ")) != NULL) { + cur += 15; + eol = strchr(cur, '\n'); + if ((eol) && + ((memory->memory_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) && + ((memory->memory_part_number = strndup(cur, eol - cur)) == NULL)) + goto no_memory; + } + + next: + base = eol + 1; + } + + return base; + +no_memory: + return NULL; +} + virSysinfoDefPtr virSysinfoRead(void) { char *path, *base; @@ -309,7 +408,7 @@ virSysinfoRead(void) { return NULL; } - cmd = virCommandNewArgList(path, "-q", "-t", "0,1,4", NULL); + cmd = virCommandNewArgList(path, "-q", "-t", "0,1,4,17", NULL); VIR_FREE(path); virCommandSetOutputBuffer(cmd, &outbuf); if (virCommandRun(cmd, NULL) < 0) { @@ -337,6 +436,11 @@ virSysinfoRead(void) { if ((base = parseProcessorInfo(base, ret)) == NULL) goto no_memory; + ret->nmemory = 0; + ret->memory = NULL; + if ((base = parseMemoryDeviceInfo(base, ret)) == NULL) + goto no_memory; + cleanup: VIR_FREE(outbuf); virCommandFree(cmd); @@ -543,6 +647,94 @@ ProcessorInfoFormat(virSysinfoDefPtr def, const char *prefix, virBufferPtr buf) return; } +static void +MemoryDeviceInfoFormat(virSysinfoDefPtr def, const char *prefix, virBufferPtr buf) +{ + int i; + int len = strlen(prefix); + virMemoryDeviceinfoDefPtr memory; + + for (i = 0; i < def->nmemory; i++) { + memory = &def->memory[i]; + + if ((memory->memory_size != NULL) || + (memory->memory_form_factor != NULL) || + (memory->memory_locator != NULL) || + (memory->memory_bank_locator != NULL) || + (memory->memory_type != NULL) || + (memory->memory_type_detail != NULL) || + (memory->memory_speed != NULL) || + (memory->memory_manufacturer != NULL) || + (memory->memory_serial_number != NULL) || + (memory->memory_part_number != NULL)) { + virBufferAsprintf(buf, "%s <memory_device>\n", prefix); + if (memory->memory_size != NULL) { + virBufferAdd(buf, prefix, len); + virBufferEscapeString(buf, + " <entry name='size'>%s</entry>\n", + memory->memory_size); + } + if (memory->memory_form_factor != NULL) { + virBufferAdd(buf, prefix, len); + virBufferEscapeString(buf, + " <entry name='form_factor'>%s</entry>\n", + memory->memory_form_factor); + } + if (memory->memory_locator != NULL) { + virBufferAdd(buf, prefix, len); + virBufferEscapeString(buf, + " <entry name='locator'>%s</entry>\n", + memory->memory_locator); + } + if (memory->memory_bank_locator != NULL) { + virBufferAdd(buf, prefix, len); + virBufferEscapeString(buf, + " <entry name='bank_locator'>%s</entry>\n", + memory->memory_bank_locator); + } + if (memory->memory_type != NULL) { + virBufferAdd(buf, prefix, len); + virBufferEscapeString(buf, + " <entry name='type'>%s</entry>\n", + memory->memory_type); + } + if (memory->memory_type_detail != NULL) { + virBufferAdd(buf, prefix, len); + virBufferEscapeString(buf, + " <entry name='type_detail'>%s</entry>\n", + memory->memory_type_detail); + } + if (memory->memory_speed != NULL) { + virBufferAdd(buf, prefix, len); + virBufferEscapeString(buf, + " <entry name='speed'>%s</entry>\n", + memory->memory_speed); + } + if (memory->memory_manufacturer != NULL) { + virBufferAdd(buf, prefix, len); + virBufferEscapeString(buf, + " <entry name='manufacturer'>%s</entry>\n", + memory->memory_manufacturer); + } + if (memory->memory_serial_number != NULL) { + virBufferAdd(buf, prefix, len); + virBufferEscapeString(buf, + " <entry name='serial_number'>%s</entry>\n", + memory->memory_serial_number); + } + if (memory->memory_part_number != NULL) { + virBufferAdd(buf, prefix, len); + virBufferEscapeString(buf, + " <entry name='part_number'>%s</entry>\n", + memory->memory_part_number); + } + virBufferAsprintf(buf, "%s </memory_device>\n", prefix); + } + } + + return; +} + /** * virSysinfoFormat: * @def: structure to convert to xml string @@ -569,6 +761,7 @@ virSysinfoFormat(virSysinfoDefPtr def, const char *prefix) BIOSInfoFormat(def, prefix, &buf); SystemInfoFormat(def, prefix, &buf); ProcessorInfoFormat(def, prefix, &buf); + MemoryDeviceInfoFormat(def, prefix, &buf); virBufferAsprintf(&buf, "%s</sysinfo>\n", prefix); diff --git a/src/util/sysinfo.h b/src/util/sysinfo.h index f098e9d..a15c5ac 100644 --- a/src/util/sysinfo.h +++ b/src/util/sysinfo.h @@ -49,6 +49,21 @@ struct _virProcessorinfoDef { char *processor_part_number; }; +typedef struct _virMemoryDeviceinfoDef virMemoryDeviceinfoDef; +typedef virMemoryDeviceinfoDef *virMemoryDeviceinfoDefPtr; +struct _virMemoryDeviceinfoDef { + char *memory_size; + char *memory_form_factor; + char *memory_locator; + char *memory_bank_locator; + char *memory_type; + char *memory_type_detail; + char *memory_speed; + char *memory_manufacturer; + char *memory_serial_number; + char *memory_part_number; +}; + typedef struct _virSysinfoDef virSysinfoDef; typedef virSysinfoDef *virSysinfoDefPtr; struct _virSysinfoDef { @@ -69,6 +84,9 @@ struct _virSysinfoDef { size_t nprocessor; virProcessorinfoDefPtr processor; + + size_t nmemory; + virMemoryDeviceinfoDefPtr memory; }; virSysinfoDefPtr virSysinfoRead(void); -- 1.7.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list