From nobody Mon May 6 11:58:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; 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 207.211.31.81 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=1591095227; cv=none; d=zohomail.com; s=zohoarc; b=oAva4hEeX2IhBqgbX6mHLozboigOyVnR34SBaZHxrNMY4c+yOBozt8h8/WMttxOS/Z7or2waXfKluSQEWlZmMpRfCTsVR6dIwBtHFJpo5w46QnWDvUDTbPT5nziTkdxD1C5uyB0+Xej8jl9lh0ys1AZy6vY34HC/wnbjK7urgvs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591095227; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=Ky/qwGhpiChsE7wZwGY7VneuKn5GUfUKtKFaPHI32xI=; b=G6U04bnhk4D1enYuCcaC1E0ghlRMlEABMkpiqieNMUKxdFD6qyTMQp5zUKKKwePSWNj0dO5biAZL5Wif+0q2zFI2IKzKUjzW7VfQ9UmUNCQ7XEzbn+wb+FA9mXO7dwF0sbttyNzyfNZ8lCPAQtGbkA86WjWn+yGM+eUwnrOmTeY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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 [207.211.31.81]) by mx.zohomail.com with SMTPS id 1591095227708684.0086982561587; Tue, 2 Jun 2020 03:53:47 -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-323-K7Uj41HwP1WImF60jJeh6w-1; Tue, 02 Jun 2020 06:53:44 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3CA3F107ACF3; Tue, 2 Jun 2020 10:53:39 +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 A56AE5C1D6; Tue, 2 Jun 2020 10:53:34 +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 490E9941D4; Tue, 2 Jun 2020 10:53:32 +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 052ArUrP026355 for ; Tue, 2 Jun 2020 06:53:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4BED410013D6; Tue, 2 Jun 2020 10:53:30 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.226]) by smtp.corp.redhat.com (Postfix) with ESMTP id C0C1510013C1 for ; Tue, 2 Jun 2020 10:53:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591095226; 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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Ky/qwGhpiChsE7wZwGY7VneuKn5GUfUKtKFaPHI32xI=; b=LAKQOpwAPjssdzHQbGFh49njmwuKt5cTt5BZWRD9C8kt7d+d80bhE8p1SzatEUjuGQxenG sevYhnT1iNm7YfQn5+lIWZv5XAabYrLC7O921mpMex6iD14nKYxGVCnz2BIiGVlJue/z0v Qukk+X6g4GHxMaSauDBhZMumGB/Bf+E= X-MC-Unique: K7Uj41HwP1WImF60jJeh6w-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH] virsysinfo: Parse OEM strings Date: Tue, 2 Jun 2020 12:53:18 +0200 Message-Id: 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.16 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 | 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, } =20 =20 +static int +virSysinfoParseOEMStrings(const char *base, + virSysinfoOEMStringsDefPtr *stringsRet) +{ + virSysinfoOEMStringsDefPtr strings =3D NULL; + 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; + + strings->values[strings->nvalues - 1] =3D g_strndup(cur, eol - cur= ); + } + + *stringsRet =3D g_steal_pointer(&strings); + ret =3D 0; + + cleanup: + virSysinfoOEMStringsDefFree(strings); + return ret; +} + + static int virSysinfoParseX86Processor(const char *base, virSysinfoDefPtr ret) { @@ -1132,7 +1187,7 @@ virSysinfoReadDMI(void) return NULL; } =20 - cmd =3D virCommandNewArgList(path, "-q", "-t", "0,1,2,3,4,17", NULL); + cmd =3D 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; =20 + if (virSysinfoParseOEMStrings(outbuf, &ret->oemStrings) < 0) + goto error; + 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..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/x86sys= info.expect index fcdd790cbd..118cc4277e 100644 --- a/tests/sysinfodata/x86sysinfo.expect +++ b/tests/sysinfodata/x86sysinfo.expect @@ -50,4 +50,14 @@ 29057112 IMSH2GS13A1F1C-10F + + Default string + Default string + MIAMI + Default string + FFFFFFFFFFFFF + FFFFFFFFFFFFF + FFFFFFFFFFFFF + Default string + --=20 2.26.2