From nobody Thu May 2 13:14:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1510937345032121.67548423519816; Fri, 17 Nov 2017 08:49:05 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7CC2525C20; Fri, 17 Nov 2017 16:49:03 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BE0708B130; Fri, 17 Nov 2017 16:49:02 +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 475983D380; Fri, 17 Nov 2017 16:49:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vAHGmxGT015026 for ; Fri, 17 Nov 2017 11:48:59 -0500 Received: by smtp.corp.redhat.com (Postfix) id CE7EC52FCE; Fri, 17 Nov 2017 16:48:59 +0000 (UTC) Received: from t460.redhat.com (unknown [10.33.36.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id A55A88B13A; Fri, 17 Nov 2017 16:48:55 +0000 (UTC) From: "Daniel P. Berrange" To: libvir-list@redhat.com Date: Fri, 17 Nov 2017 16:48:53 +0000 Message-Id: <20171117164853.29166-1-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] qemu: add support for setting OEM strings SMBIOS data fields 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 17 Nov 2017 16:49:03 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The OEM strings table in SMBIOS allows the vendor to pass arbitrary strings into the guest OS. This can be used as a way to pass data to an application= like cloud-init, or potentially as an alternative to the kernel command line for= OS installers where you can't modify the install ISO image to change the kernel args. As an example, consider if cloud-init and anaconda supported OEM strings you could use something like cloud-init:ds=3Dnocloud-net;s=3Dhttp://10.10.0.1:8000/ anaconda:method=3Dhttp://dl.fedoraproject.org/pub/fedora/linux= /releases/25/x86_64/os use of a application specific prefix as illustrated above is recommended so= that an app can reliably identify which of the many OEM strings are targetted at= it. Signed-off-by: Daniel P. Berrange --- NB, the QEMU side of this patch is queued but won't merge until 2.12 opens up for dev work, so this libvirt patch will need to wait a little docs/formatdomain.html.in | 13 ++++++ docs/schemas/domaincommon.rng | 9 ++++ src/conf/domain_conf.c | 53 ++++++++++++++++++= ++++ src/qemu/qemu_command.c | 28 ++++++++++++ src/util/virsysinfo.c | 33 ++++++++++++++ src/util/virsysinfo.h | 10 ++++ tests/qemuxml2argvdata/qemuxml2argv-smbios.args | 2 + tests/qemuxml2argvdata/qemuxml2argv-smbios.xml | 5 ++ tests/qemuxml2xmloutdata/qemuxml2xmlout-smbios.xml | 5 ++ 9 files changed, 158 insertions(+) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 8dbea6af71..bd7c542173 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -411,6 +411,10 @@ <entry name=3D'version'>0B98401 Pro</entry> <entry name=3D'serial'>W1KS427111E</entry> </baseBoard> + <oemStrings> + <entry>myappname:some arbitrary data</entry> + <entry>otherappname:more arbitrary data</entry> + </oemStrings> </sysinfo> ... =20 @@ -498,6 +502,15 @@ validation and date format checking, all values a= re passed as strings to the hypervisor driver. +
oemStrings
+
+ This is block 11 of SMBIOS. This element should appear once and + can have multiple entry child elements, each prov= iding + arbitrary string data. There are no restrictions on what data = can + be provided in the entries, however, if the data is intended t= o be + consumed by an application in the guest, it is recommended to = use + the application name as a prefix in the string. +
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 82fdfd5f73..98de7d2cb1 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -4834,6 +4834,15 @@ + + + + + + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 0e4f76f066..5d81fbb555 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -14315,6 +14315,48 @@ virSysinfoBaseBoardParseXML(xmlXPathContextPtr ctx= t, return ret; } =20 +static int +virSysinfoOEMStringsParseXML(xmlNodePtr node, + xmlXPathContextPtr ctxt, + virSysinfoOEMStringsDefPtr *oem) +{ + int ret =3D -1; + virSysinfoOEMStringsDefPtr def; + xmlNodePtr *strings =3D NULL; + int nstrings; + size_t i; + + if (!virXMLNodeNameEqual(node, "oemStrings")) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("XML does not contain expected 'system' element")= ); + return ret; + } + + nstrings =3D virXPathNodeSet("./entry", ctxt, &strings); + if (nstrings < 0) + return -1; + if (nstrings =3D=3D 0) + return 0; + + if (VIR_ALLOC(def) < 0) + goto cleanup; + + if (VIR_ALLOC_N(def->values, nstrings) < 0) + goto cleanup; + + def->nvalues =3D nstrings; + for (i =3D 0; i < nstrings; i++) + def->values[i] =3D virXMLNodeContentString(strings[i]); + + *oem =3D def; + def =3D NULL; + ret =3D 0; + cleanup: + VIR_FREE(strings); + virSysinfoOEMStringsDefFree(def); + return ret; +} + static virSysinfoDefPtr virSysinfoParseXML(xmlNodePtr node, xmlXPathContextPtr ctxt, @@ -14373,6 +14415,17 @@ virSysinfoParseXML(xmlNodePtr node, if (virSysinfoBaseBoardParseXML(ctxt, &def->baseBoard, &def->nbaseBoar= d) < 0) goto error; =20 + /* Extract system related metadata */ + if ((tmpnode =3D virXPathNode("./oemStrings[1]", ctxt)) !=3D NULL) { + oldnode =3D ctxt->node; + ctxt->node =3D tmpnode; + if (virSysinfoOEMStringsParseXML(tmpnode, ctxt, &def->oemStrings) = < 0) { + ctxt->node =3D oldnode; + goto error; + } + ctxt->node =3D oldnode; + } + cleanup: VIR_FREE(type); return def; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 56729e4981..01fb8dff6e 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6063,6 +6063,26 @@ qemuBuildSmbiosBaseBoardStr(virSysinfoBaseBoardDefPt= r def) } =20 =20 +static char * +qemuBuildSmbiosOEMStringsStr(virSysinfoOEMStringsDefPtr def) +{ + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + size_t i; + + if (!def) + return NULL; + + virBufferAddLit(&buf, "type=3D11"); + + for (i =3D 0; i < def->nvalues; i++) { + virBufferAddLit(&buf, ",value=3D"); + virQEMUBuildBufferEscapeComma(&buf, def->values[i]); + } + + return virBufferContentAndReset(&buf); +} + + static int qemuBuildSmbiosCommandLine(virCommandPtr cmd, virQEMUDriverPtr driver, @@ -6133,6 +6153,14 @@ qemuBuildSmbiosCommandLine(virCommandPtr cmd, virCommandAddArgList(cmd, "-smbios", smbioscmd, NULL); VIR_FREE(smbioscmd); } + + if (source->oemStrings) { + if (!(smbioscmd =3D qemuBuildSmbiosOEMStringsStr(source->oemSt= rings))) + return -1; + + virCommandAddArgList(cmd, "-smbios", smbioscmd, NULL); + VIR_FREE(smbioscmd); + } } =20 return 0; diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index ab81b1f7f0..0ad3e6c70d 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -106,6 +106,18 @@ void virSysinfoBaseBoardDefClear(virSysinfoBaseBoardDe= fPtr def) VIR_FREE(def->location); } =20 +void virSysinfoOEMStringsDefFree(virSysinfoOEMStringsDefPtr def) +{ + size_t i; + + if (def =3D=3D NULL) + return; + + for (i =3D 0; i < def->nvalues; i++) + VIR_FREE(def->values[i]); + VIR_FREE(def->values); +} + /** * virSysinfoDefFree: * @def: a sysinfo structure @@ -155,6 +167,8 @@ void virSysinfoDefFree(virSysinfoDefPtr def) } VIR_FREE(def->memory); =20 + virSysinfoOEMStringsDefFree(def->oemStrings); + VIR_FREE(def); } =20 @@ -1263,6 +1277,24 @@ virSysinfoMemoryFormat(virBufferPtr buf, virSysinfoD= efPtr def) } } =20 +static void +virSysinfoOEMStringsFormat(virBufferPtr buf, virSysinfoOEMStringsDefPtr de= f) +{ + size_t i; + + if (!def) + return; + + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + for (i =3D 0; i < def->nvalues; i++) { + virBufferEscapeString(buf, "%s\n", + def->values[i]); + } + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); +} + /** * virSysinfoFormat: * @buf: buffer to append output to (may use auto-indentation) @@ -1293,6 +1325,7 @@ virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr d= ef) virSysinfoBaseBoardFormat(&childrenBuf, def->baseBoard, def->nbaseBoar= d); virSysinfoProcessorFormat(&childrenBuf, def); virSysinfoMemoryFormat(&childrenBuf, def); + virSysinfoOEMStringsFormat(&childrenBuf, def->oemStrings); =20 virBufferAsprintf(buf, "CZC1065993 Upside down + + Hello + World + This is, more tricky value=3Descaped + hvm diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-smbios.xml b/tests/qem= uxml2xmloutdata/qemuxml2xmlout-smbios.xml index d21f6275f0..cbe616c7da 100644 --- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-smbios.xml +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-smbios.xml @@ -26,6 +26,11 @@ CZC1065993 Upside down + + Hello + World + This is, more tricky value=3Descaped + hvm --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list