From nobody Mon Feb 9 00:56:43 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 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=1658136745; cv=none; d=zohomail.com; s=zohoarc; b=cklUsPqbrL1W0bVW+3yZanuBh2lGdXRlyCmKmJm6r3n/0fva0QplWM1RWvSzGokn3AXofZhjmTItUG+HWjkIuaUlReKBrCzHPIHn3AT0dZkC7jf58eei0ENc/swx6ukzwKJeIPP8nLZjPDOCfx+R2y+Kaz5sRuM+Nk+r/06xCGo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658136745; 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=7b+WiEFf9fxAlmMwB4QRhYC+vOY+4sdVbaUtaFZE4fE=; b=gl6LTh1kvPzs86f1YsnuZwVxGZ4jbE0DAgaMu6ZbMUM+M4diYpqhsGoQq8UFskFWDDfNvterBx/F56JN6/E9/mfOczam4HsqLrLvg6+PZazniB048tNzSVGxKIvne2zRlpFHz96Ad98htCXpap0DMRkxFjN4S+kTSs8TP4gs+Ts= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 165813674500351.661232289986174; Mon, 18 Jul 2022 02:32:25 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-377-eHlR6z-vPt6xkKhRXRQyrw-1; Mon, 18 Jul 2022 05:30:59 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E323529DD9AC; Mon, 18 Jul 2022 09:30:56 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id C85AE492C3B; Mon, 18 Jul 2022 09:30:56 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 800121947065; Mon, 18 Jul 2022 09:30:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 6649C1947075 for ; Mon, 18 Jul 2022 09:30:55 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 3FD812166B2A; Mon, 18 Jul 2022 09:30:55 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id E04092166B26 for ; Mon, 18 Jul 2022 09:30:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658136744; 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=7b+WiEFf9fxAlmMwB4QRhYC+vOY+4sdVbaUtaFZE4fE=; b=T+8OXpxK7Ece7uNGVm3tX9tdJWGYjoTzIgv/zLdIQH5j2+jRg9ml0Yw4WlI+BYB8byVQhq 0dACBwrT/Ro7p4BeUA/YG3jEShu9S9ZNk8awt7Wvbym+WD2de5kvV9pBcKhzlE8XAfvnp2 r0E1J5Vsqhlnyh4fbUkSRdQSRUXFHeo= X-MC-Unique: eHlR6z-vPt6xkKhRXRQyrw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 5/8] conf: Use virXMLPropEnum more when parsing TPM Date: Mon, 18 Jul 2022 11:30:47 +0200 Message-Id: <44ef366882685c1520480244acc4d0202f2735cd.1658136603.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658136746502100001 Content-Type: text/plain; charset="utf-8"; x-default="true" When parsing a TPM device plenty of virXMLPropString() + enum2int() combos are used. These can be replaced with virXMLPropEnum(). Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/conf/domain_conf.c | 39 ++++++++++++--------------------------- src/conf/domain_conf.h | 6 +++--- src/qemu/qemu_command.c | 2 +- src/qemu/qemu_domain.c | 2 +- 4 files changed, 17 insertions(+), 32 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 28f0e75e60..6263d90fdb 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10347,9 +10347,6 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlopt, int nnodes; size_t i; g_autofree char *path =3D NULL; - g_autofree char *model =3D NULL; - g_autofree char *backend =3D NULL; - g_autofree char *version =3D NULL; g_autofree char *secretuuid =3D NULL; g_autofree char *persistent_state =3D NULL; g_autofree xmlNodePtr *backends =3D NULL; @@ -10358,13 +10355,11 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlop= t, =20 def =3D g_new0(virDomainTPMDef, 1); =20 - model =3D virXMLPropString(node, "model"); - if (model !=3D NULL && - (def->model =3D virDomainTPMModelTypeFromString(model)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unknown TPM frontend model '%s'"), model); + if (virXMLPropEnum(node, "model", + virDomainTPMModelTypeFromString, + VIR_XML_PROP_NONZERO, + &def->model) < 0) goto error; - } =20 ctxt->node =3D node; =20 @@ -10383,18 +10378,11 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlop= t, goto error; } =20 - if (!(backend =3D virXMLPropString(backends[0], "type"))) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("missing TPM device backend type")); + if (virXMLPropEnum(backends[0], "type", + virDomainTPMBackendTypeFromString, + VIR_XML_PROP_REQUIRED, + &def->type) < 0) goto error; - } - - if ((def->type =3D virDomainTPMBackendTypeFromString(backend)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unknown TPM backend type '%s'"), - backend); - goto error; - } =20 switch (def->type) { case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH: @@ -10407,14 +10395,11 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlop= t, def->data.passthrough.source->data.file.path =3D g_steal_pointer(&= path); break; case VIR_DOMAIN_TPM_TYPE_EMULATOR: - version =3D virXMLPropString(backends[0], "version"); - if (version && - (def->data.emulator.version =3D virDomainTPMVersionTypeFromStr= ing(version)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unsupported TPM version '%s'"), - version); + if (virXMLPropEnum(backends[0], "version", + virDomainTPMVersionTypeFromString, + VIR_XML_PROP_NONZERO, + &def->data.emulator.version) < 0) goto error; - } =20 if (!(def->data.emulator.source =3D virDomainChrSourceDefNew(xmlop= t))) goto error; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 3362042db5..bab667d026 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1436,15 +1436,15 @@ typedef enum { #define VIR_DOMAIN_TPM_DEFAULT_DEVICE "/dev/tpm0" =20 struct _virDomainTPMDef { - int type; /* virDomainTPMBackendType */ + virDomainTPMModel model; + virDomainTPMBackendType type; virDomainDeviceInfo info; - int model; /* virDomainTPMModel */ union { struct { virDomainChrSourceDef *source; } passthrough; struct { - int version; /* virDomainTPMVersion */ + virDomainTPMVersion version; virDomainChrSourceDef *source; char *storagepath; char *logfile; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 262fffe5fe..93ea8748c7 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -9840,7 +9840,7 @@ qemuBuildTPMCommandLine(virCommand *cmd, g_autoptr(qemuFDPass) passtpm =3D NULL; g_autoptr(qemuFDPass) passcancel =3D NULL; =20 - switch ((virDomainTPMBackendType) tpm->type) { + switch (tpm->type) { case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH: { VIR_AUTOCLOSE fdtpm =3D -1; VIR_AUTOCLOSE fdcancel =3D -1; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 0343fd3597..09fc88e7fa 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11752,7 +11752,7 @@ qemuDomainDeviceBackendChardevForeachOne(virDomainD= eviceDef *dev, return cb(dev, dev->data.rng->source.chardev, opaque); =20 case VIR_DOMAIN_DEVICE_TPM: - switch ((virDomainTPMBackendType) dev->data.tpm->type) { + switch (dev->data.tpm->type) { case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH: return cb(dev, dev->data.tpm->data.passthrough.source, opaque); =20 --=20 2.35.1