Setting OEM strings for a domain was introduced in v4.1.0-rc1~315. However, any application that wanted to use them (e.g. to point to an URL where a config file is stored) had to 'dmidecode -u --oem-string N' (where N is index of the string). Well, we can expose them under our <sysinfo/> XML and if the domain is running Libvirt inside it can be obtained using virConnectGetSysinfo() API. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/util/virsysinfo.c | 60 ++++++++++++++++++++++++++++- tests/sysinfodata/x86sysinfo.data | 10 +++++ tests/sysinfodata/x86sysinfo.expect | 10 +++++ 3 files changed, 79 insertions(+), 1 deletion(-) diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index 41f4d1cff9..94f7ca8811 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -919,6 +919,61 @@ virSysinfoParseX86Chassis(const char *base, } +static int +virSysinfoParseOEMStrings(const char *base, + virSysinfoOEMStringsDefPtr *stringsRet) +{ + virSysinfoOEMStringsDefPtr strings = NULL; + int ret = -1; + const char *cur; + + if (!(cur = strstr(base, "OEM Strings"))) + return 0; + + if (VIR_ALLOC(strings) < 0) + return -1; + + while ((cur = strstr(cur, "String "))) { + char *eol; + + cur += 7; + + if (!(eol = strchr(cur, '\n'))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Malformed output of dmidecode")); + goto cleanup; + } + + while (g_ascii_isdigit(*cur)) + cur++; + + if (*cur != ':') { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Malformed output of dmidecode")); + goto cleanup; + } + + cur += 2; + + virSkipSpacesBackwards(cur, &eol); + if (!eol) + continue; + + if (VIR_EXPAND_N(strings->values, strings->nvalues, 1) < 0) + goto cleanup; + + strings->values[strings->nvalues - 1] = g_strndup(cur, eol - cur); + } + + *stringsRet = g_steal_pointer(&strings); + ret = 0; + + cleanup: + virSysinfoOEMStringsDefFree(strings); + return ret; +} + + static int virSysinfoParseX86Processor(const char *base, virSysinfoDefPtr ret) { @@ -1132,7 +1187,7 @@ virSysinfoReadDMI(void) return NULL; } - cmd = virCommandNewArgList(path, "-q", "-t", "0,1,2,3,4,17", NULL); + cmd = virCommandNewArgList(path, "-q", "-t", "0,1,2,3,4,11,17", NULL); VIR_FREE(path); virCommandSetOutputBuffer(cmd, &outbuf); if (virCommandRun(cmd, NULL) < 0) @@ -1155,6 +1210,9 @@ virSysinfoReadDMI(void) if (virSysinfoParseX86Chassis(outbuf, &ret->chassis) < 0) goto error; + if (virSysinfoParseOEMStrings(outbuf, &ret->oemStrings) < 0) + goto error; + ret->nprocessor = 0; ret->processor = NULL; if (virSysinfoParseX86Processor(outbuf, ret) < 0) diff --git a/tests/sysinfodata/x86sysinfo.data b/tests/sysinfodata/x86sysinfo.data index 426261041d..5615e144fb 100644 --- a/tests/sysinfodata/x86sysinfo.data +++ b/tests/sysinfodata/x86sysinfo.data @@ -81,3 +81,13 @@ Memory Device Serial Number: 29057112 Asset Tag: 0839 Part Number: IMSH2GS13A1F1C-10F + +OEM Strings + String 1: Default string + String 2: Default string + String 3: MIAMI + String 4: Default string + String 5: FFFFFFFFFFFFF + String 6: FFFFFFFFFFFFF + String 7: FFFFFFFFFFFFF + String 8: Default string diff --git a/tests/sysinfodata/x86sysinfo.expect b/tests/sysinfodata/x86sysinfo.expect index fcdd790cbd..118cc4277e 100644 --- a/tests/sysinfodata/x86sysinfo.expect +++ b/tests/sysinfodata/x86sysinfo.expect @@ -50,4 +50,14 @@ <entry name='serial_number'>29057112</entry> <entry name='part_number'>IMSH2GS13A1F1C-10F</entry> </memory_device> + <oemStrings> + <entry>Default string</entry> + <entry>Default string</entry> + <entry>MIAMI</entry> + <entry>Default string</entry> + <entry>FFFFFFFFFFFFF</entry> + <entry>FFFFFFFFFFFFF</entry> + <entry>FFFFFFFFFFFFF</entry> + <entry>Default string</entry> + </oemStrings> </sysinfo> -- 2.26.2