From nobody Mon Feb 9 09:08:46 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1591629067; cv=none; d=zohomail.com; s=zohoarc; b=Ix48JWEemX0iDIeH/lT/L1w3MxckymSoh2XINgxjYAXP70QvQlqUnf8XJU4DGsog71Uh4/b48zT3vV9Q3ZpFNlZnwv3TneSgjC9kvKIEEC3mCO67zV472DtMMOSRchwLj1YYkChr5GFdG1oxCSXfWq2EoJjCPhPJCR6Z6d5lwQI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591629067; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QVR/+EbPynxV6PCGCohP3+Lq40jxQrT2klmLIW6f9RU=; b=L76+wD1cibnohovyVAGwtwFHwV5J7Mba1Tdk/KO0g96iyIpgKBy/INkvamcrbJqA9mDR7oftqfOfuL2ByBUnY7cEJipNb4SIQJ4DVN1SH3qsiZg85oLolSDTeX/DYR7FYh68TyUu9R8Hr4k3sV9U34XrfK3ldQYQiTFZT+HXZ40= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 159162906736578.22796254194168; Mon, 8 Jun 2020 08:11:07 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-330-lpUjo-rSO0WlFEB2Df4GOA-1; Mon, 08 Jun 2020 11:10:09 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 19285107B7C5; Mon, 8 Jun 2020 15:10:02 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EC42E5D9E5; Mon, 8 Jun 2020 15:10:01 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B0EB21809547; Mon, 8 Jun 2020 15:10:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 058F6VUm004872 for ; Mon, 8 Jun 2020 11:06:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8933E10013D4; Mon, 8 Jun 2020 15:06:31 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.5]) by smtp.corp.redhat.com (Postfix) with ESMTP id 08C4210013C1 for ; Mon, 8 Jun 2020 15:06:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591629066; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=QVR/+EbPynxV6PCGCohP3+Lq40jxQrT2klmLIW6f9RU=; b=fZDBCpFGEfqRvll3Pi7FmStsuabD/YPsvmPBMXcEkkPy/csRzOtElISKqVjKiwAyFzt1Qj eYoht+MnXZnsC0ERJhRG77PG5XojkgwyFjPPJwSqT/3Ki0vMiTrzj1V4iE8dNiuSkOXPYu MxI7YAS9fvu11WS+7iXbHtFZW2NKTJY= X-MC-Unique: lpUjo-rSO0WlFEB2Df4GOA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 7/7] virsysinfo: Parse OEM strings Date: Mon, 8 Jun 2020 17:06:21 +0200 Message-Id: <602e77dacc9018844d1e88510f2c6bc5bd764db8.1591628594.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" 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 XML and if the domain is running Libvirt inside it can be obtained using virConnectGetSysinfo() API. Signed-off-by: Michal Privoznik --- src/util/virsysinfo.c | 102 +++++++++++++++++++++++++++- tests/sysinfodata/x86sysinfo.data | 6 ++ tests/sysinfodata/x86sysinfo.expect | 8 +++ tests/sysinfotest.c | 27 ++++++-- 4 files changed, 138 insertions(+), 5 deletions(-) diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index a26c27e83e..09e32df6a9 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -915,6 +915,103 @@ virSysinfoParseX86Chassis(const char *base, } =20 =20 +static int +virSysinfoDMIDecodeOEMString(size_t i, + char **str) +{ + g_autofree char *err =3D NULL; + g_autoptr(virCommand) cmd =3D virCommandNewArgList(DMIDECODE, "--dump", + "--oem-string", NULL); + virCommandAddArgFormat(cmd, "%zu", i); + virCommandSetOutputBuffer(cmd, str); + virCommandSetErrorBuffer(cmd, &err); + + if (virCommandRun(cmd, NULL) < 0) + return -1; + + /* Unfortunately, dmidecode returns 0 even if OEM String index is out + * of bounds, but it prints an error message in that case. Check stderr + * and return success/failure accordingly. */ + + if (err && *err !=3D '\0') + return -1; + + return 0; +} + + +static int +virSysinfoParseOEMStrings(const char *base, + virSysinfoOEMStringsDefPtr *stringsRet) +{ + virSysinfoOEMStringsDefPtr strings =3D NULL; + size_t i =3D 1; + int ret =3D -1; + const char *cur; + + if (!(cur =3D strstr(base, "OEM Strings"))) + return 0; + + if (VIR_ALLOC(strings) < 0) + return -1; + + while ((cur =3D strstr(cur, "String "))) { + char *eol; + + cur +=3D 7; + + if (!(eol =3D strchr(cur, '\n'))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Malformed output of dmidecode")); + goto cleanup; + } + + while (g_ascii_isdigit(*cur)) + cur++; + + if (*cur !=3D ':') { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Malformed output of dmidecode")); + goto cleanup; + } + + cur +=3D 2; + + virSkipSpacesBackwards(cur, &eol); + if (!eol) + continue; + + if (VIR_EXPAND_N(strings->values, strings->nvalues, 1) < 0) + goto cleanup; + + /* If OEM String contains newline, dmidecode escapes it as a dot. + * If this is the case then run dmidecode again to get raw string. + * Unfortunately, we can't dinstinguish betwen dot an new line at + * this level. */ + if (memchr(cur, '.', eol - cur)) { + char *str; + + if (virSysinfoDMIDecodeOEMString(i, &str) < 0) + goto cleanup; + + strings->values[strings->nvalues - 1] =3D g_steal_pointer(&str= ); + } else { + strings->values[strings->nvalues - 1] =3D g_strndup(cur, eol -= cur); + } + + i++; + cur =3D eol; + } + + *stringsRet =3D g_steal_pointer(&strings); + ret =3D 0; + + cleanup: + virSysinfoOEMStringsDefFree(strings); + return ret; +} + + static int virSysinfoParseX86Processor(const char *base, virSysinfoDefPtr ret) { @@ -1119,7 +1216,7 @@ virSysinfoReadDMI(void) g_autofree char *outbuf =3D NULL; g_autoptr(virCommand) cmd =3D NULL; =20 - cmd =3D virCommandNewArgList(DMIDECODE, "-q", "-t", "0,1,2,3,4,17", NU= LL); + cmd =3D virCommandNewArgList(DMIDECODE, "-q", "-t", "0,1,2,3,4,11,17",= NULL); virCommandSetOutputBuffer(cmd, &outbuf); if (virCommandRun(cmd, NULL) < 0) return NULL; @@ -1141,6 +1238,9 @@ virSysinfoReadDMI(void) if (virSysinfoParseX86Chassis(outbuf, &ret->chassis) < 0) return NULL; =20 + if (virSysinfoParseOEMStrings(outbuf, &ret->oemStrings) < 0) + return NULL; + ret->nprocessor =3D 0; ret->processor =3D NULL; if (virSysinfoParseX86Processor(outbuf, ret) < 0) diff --git a/tests/sysinfodata/x86sysinfo.data b/tests/sysinfodata/x86sysin= fo.data index 426261041d..3f0b654e4b 100644 --- a/tests/sysinfodata/x86sysinfo.data +++ b/tests/sysinfodata/x86sysinfo.data @@ -81,3 +81,9 @@ Memory Device Serial Number: 29057112 Asset Tag: 0839 Part Number: IMSH2GS13A1F1C-10F + +OEM Strings + String 1: Hello + String 2: World + String 3: Ha ha ha try parsing\n. String 3: this correctly. = String 4:then + String 4: This is, more tricky value=3Descaped diff --git a/tests/sysinfodata/x86sysinfo.expect b/tests/sysinfodata/x86sys= info.expect index fcdd790cbd..05add8f031 100644 --- a/tests/sysinfodata/x86sysinfo.expect +++ b/tests/sysinfodata/x86sysinfo.expect @@ -50,4 +50,12 @@ 29057112 IMSH2GS13A1F1C-10F + + Hello + World + Ha ha ha try parsing\n + String 3: this correctly + String 4:then + This is, more tricky value=3Descaped + diff --git a/tests/sysinfotest.c b/tests/sysinfotest.c index 10d24b823a..3b418955d0 100644 --- a/tests/sysinfotest.c +++ b/tests/sysinfotest.c @@ -56,10 +56,29 @@ testDMIDecodeDryRun(const char *const*args G_GNUC_UNUSE= D, { const char *sysinfo =3D opaque; =20 - if (virFileReadAll(sysinfo, 10 * 1024 * 1024, output) < 0) { - *error =3D g_strdup(virGetLastErrorMessage()); - *status =3D EXIT_FAILURE; - return; + if (STREQ_NULLABLE(args[1], "--dump") && + STREQ_NULLABLE(args[2], "--oem-string")) { + if (!args[3]) { + *error =3D g_strdup("dmidecode: option '--oem-string' requires= an argument"); + *status =3D EXIT_FAILURE; + return; + } + + if (STREQ(args[3], "3")) { + *output =3D g_strdup("Ha ha ha try parsing\\n\n" + " String 3: this correctly\n" + " String 4:then"); + } else { + *error =3D g_strdup_printf("No OEM string number %s", args[3]); + *status =3D EXIT_FAILURE; + return; + } + } else { + if (virFileReadAll(sysinfo, 10 * 1024 * 1024, output) < 0) { + *error =3D g_strdup(virGetLastErrorMessage()); + *status =3D EXIT_FAILURE; + return; + } } =20 *error =3D g_strdup(""); --=20 2.26.2