From nobody Mon Apr 29 05:08:10 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 1516210758430445.79741241994134; Wed, 17 Jan 2018 09:39:18 -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 3D6C18B10F; Wed, 17 Jan 2018 17:38:49 +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 56CF262499; Wed, 17 Jan 2018 17:38:46 +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 7B00918033DB; Wed, 17 Jan 2018 17:38:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0HHbstL007434 for ; Wed, 17 Jan 2018 12:37:54 -0500 Received: by smtp.corp.redhat.com (Postfix) id B69E45D97C; Wed, 17 Jan 2018 17:37:54 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id D3CC717AFC; Wed, 17 Jan 2018 17:37:53 +0000 (UTC) From: "Daniel P. Berrange" To: libvir-list@redhat.com Date: Wed, 17 Jan 2018 17:37:44 +0000 Message-Id: <20180117173745.17754-2-berrange@redhat.com> In-Reply-To: <20180117173745.17754-1-berrange@redhat.com> References: <20180117173745.17754-1-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 1/2] conf: 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.28]); Wed, 17 Jan 2018 17:39:11 +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, but not mandated, so that an app can reliably identify which of the many OEM strings are targetted at it. Signed-off-by: Daniel P. Berrange Reviewed-by: John Ferlan --- docs/formatdomain.html.in | 13 ++++++++++++ docs/schemas/domaincommon.rng | 9 +++++++++ src/conf/domain_conf.c | 47 +++++++++++++++++++++++++++++++++++++++= ++++ src/util/virsysinfo.c | 33 ++++++++++++++++++++++++++++++ src/util/virsysinfo.h | 10 +++++++++ 5 files changed, 112 insertions(+) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index d272cc1ba6..6af2d26209 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 f22c932f6c..a154b5a462 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -4857,6 +4857,15 @@ + + + + + + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a1c25060f9..6c0ad1ed7d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -14461,6 +14461,42 @@ 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; + + 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, @@ -14519,6 +14555,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/util/virsysinfo.c b/src/util/virsysinfo.c index 1fbdd778f9..60765c38de 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -108,6 +108,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 @@ -157,6 +169,8 @@ void virSysinfoDefFree(virSysinfoDefPtr def) } VIR_FREE(def->memory); =20 + virSysinfoOEMStringsDefFree(def->oemStrings); + VIR_FREE(def); } =20 @@ -1294,6 +1308,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) @@ -1324,6 +1356,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, " Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1516211312284245.15039665191864; Wed, 17 Jan 2018 09:48:32 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2DCC47854C; Wed, 17 Jan 2018 17:48:24 +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 441756090C; Wed, 17 Jan 2018 17:48:19 +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 DCDED4ED2D; Wed, 17 Jan 2018 17:48:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0HHbtwb007439 for ; Wed, 17 Jan 2018 12:37:55 -0500 Received: by smtp.corp.redhat.com (Postfix) id D23485D97C; Wed, 17 Jan 2018 17:37:55 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 189E05D969; Wed, 17 Jan 2018 17:37:54 +0000 (UTC) From: "Daniel P. Berrange" To: libvir-list@redhat.com Date: Wed, 17 Jan 2018 17:37:45 +0000 Message-Id: <20180117173745.17754-3-berrange@redhat.com> In-Reply-To: <20180117173745.17754-1-berrange@redhat.com> References: <20180117173745.17754-1-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 2/2] qemu: add support for generating SMBIOS OEM strings command line 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 17 Jan 2018 17:48:26 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This wires up the previously added OEM strings XML schema to be able to generate comamnd line args for QEMU. This requires QEMU >=3D 2.12 release containing this patch: commit 2d6dcbf93fb01b4a7f45a93d276d4d74b16392dd Author: Daniel P. Berrange Date: Sat Oct 28 21:51:36 2017 +0100 smbios: support setting OEM strings table Signed-off-by: Daniel P. Berrange Reviewed-by: John Ferlan --- src/qemu/qemu_command.c | 28 ++++++++++++++++++++++++++++ tests/qemuxml2argvdata/smbios.args | 2 ++ tests/qemuxml2argvdata/smbios.xml | 5 +++++ tests/qemuxml2xmloutdata/smbios.xml | 5 +++++ 4 files changed, 40 insertions(+) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index b8aede32d2..96bd0ad8ee 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6142,6 +6142,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, @@ -6212,6 +6232,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/tests/qemuxml2argvdata/smbios.args b/tests/qemuxml2argvdata/sm= bios.args index 3d94a109f9..d27d436a3a 100644 --- a/tests/qemuxml2argvdata/smbios.args +++ b/tests/qemuxml2argvdata/smbios.args @@ -17,6 +17,8 @@ serial=3D32dfcb37-5af1-552b-357c-be8c3aa38310,\ uuid=3Dc7a5fdbd-edaf-9455-926a-d65c16db1809,sku=3D1234567890,family=3DRed = Hat' \ -smbios 'type=3D2,manufacturer=3DHewlett-Packard,product=3D0B4Ch,version= =3DD,\ serial=3DCZC1065993,asset=3DCZC1065993,location=3DUpside down' \ +-smbios 'type=3D11,value=3DHello,value=3DWorld,value=3DThis is,,\ + more tricky value=3Descaped' \ -nographic \ -nodefaults \ -chardev socket,id=3Dcharmonitor,path=3D/tmp/lib/domain--1-QEMUGuest1/moni= tor.sock,\ diff --git a/tests/qemuxml2argvdata/smbios.xml b/tests/qemuxml2argvdata/smb= ios.xml index c12477dcb5..319bdf61df 100644 --- a/tests/qemuxml2argvdata/smbios.xml +++ b/tests/qemuxml2argvdata/smbios.xml @@ -26,6 +26,11 @@ CZC1065993 Upside down + + Hello + World + This is, more tricky value=3Descaped + hvm diff --git a/tests/qemuxml2xmloutdata/smbios.xml b/tests/qemuxml2xmloutdata= /smbios.xml index d21f6275f0..cbe616c7da 100644 --- a/tests/qemuxml2xmloutdata/smbios.xml +++ b/tests/qemuxml2xmloutdata/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