From nobody Sun Feb 8 12:14:07 2026 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1566305974; cv=none; d=zoho.com; s=zohoarc; b=G1w2ank2X38zierdpV1jKgVy3mMbOuqyFp5vycWCrnGmdmQFZn/D//q/XB+F0QuPQ2xajXt3OhKmKkDpLK4a0cn+kkWrSwCqyD6VNV9L2OBnAINUgPL8mBtLPp8SB7cvIA81YWmDdW7FRDgbiMjjS1bTugocgcg+hDr7Y/oO/jI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566305974; 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:ARC-Authentication-Results; bh=ATQnyY9/XX9wmqscaofFnAli24JJ9L+3Ltbx95HST1c=; b=l0iZx3s0Sz1aVNojDuk2ZP7EZuaZ4ronFvSoM+wJEhXYpoe82j//NzVI62sS69bojOI0Dbugk4H3oL2BU9QL4jMVa0W/ViJ9cevfTJ08NnFToImHqX7R5qJv5I8mly1q3J4mi8T5GqjMhKOmW2EFTZJdO9g18iONwbtGVzR2ibQ= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 156630597462445.94287202297721; Tue, 20 Aug 2019 05:59:34 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4E419A35FE8; Tue, 20 Aug 2019 12:59:33 +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 2504A13836; Tue, 20 Aug 2019 12:59:33 +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 D988A24F68; Tue, 20 Aug 2019 12:59:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7KCxRct023152 for ; Tue, 20 Aug 2019 08:59:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id 059CB13836; Tue, 20 Aug 2019 12:59:27 +0000 (UTC) Received: from icr.brq.redhat.com (unknown [10.43.2.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 825E718EE4 for ; Tue, 20 Aug 2019 12:59:26 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Tue, 20 Aug 2019 14:59:04 +0200 Message-Id: <74c2d6f219da7b114fa2ed189e3b018bbd1534ad.1566305923.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 05/19] qemu: move TPM vaildation to qemuDomainDeviceDefValidateTPM 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: , Content-Type: text/plain; charset="utf-8" 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.68]); Tue, 20 Aug 2019 12:59:33 +0000 (UTC) Simplify the command line formatter by complicating the validator. Signed-off-by: J=C3=A1n Tomko --- src/qemu/qemu_command.c | 15 +-------------- src/qemu/qemu_domain.c | 29 +++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 5e05916b23..3a4acb3166 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -10004,7 +10004,6 @@ qemuBuildTPMOpenBackendFDs(const char *tpmdev, static char * qemuBuildTPMBackendStr(const virDomainDef *def, virCommandPtr cmd, - virQEMUCapsPtr qemuCaps, int *tpmfd, int *cancelfd, char **chardev) @@ -10033,9 +10032,6 @@ qemuBuildTPMBackendStr(const virDomainDef *def, =20 switch (tpm->type) { case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH: - if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_TPM_PASSTHROUGH)) - goto no_support; - tpmdev =3D tpm->data.passthrough.source.data.file.path; if (!(cancel_path =3D virTPMCreateCancelPath(tpmdev))) goto error; @@ -10062,9 +10058,6 @@ qemuBuildTPMBackendStr(const virDomainDef *def, =20 break; case VIR_DOMAIN_TPM_TYPE_EMULATOR: - if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_TPM_EMULATOR)) - goto no_support; - virBufferAddLit(&buf, ",chardev=3Dchrtpm"); =20 if (virAsprintf(chardev, "socket,id=3Dchrtpm,path=3D%s", @@ -10081,12 +10074,6 @@ qemuBuildTPMBackendStr(const virDomainDef *def, =20 return virBufferContentAndReset(&buf); =20 - no_support: - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("The QEMU executable %s does not support TPM " - "backend type %s"), - def->emulator, type); - error: VIR_FREE(devset); VIR_FREE(cancel_path); @@ -10110,7 +10097,7 @@ qemuBuildTPMCommandLine(virCommandPtr cmd, if (!def->tpm) return 0; =20 - if (!(optstr =3D qemuBuildTPMBackendStr(def, cmd, qemuCaps, + if (!(optstr =3D qemuBuildTPMBackendStr(def, cmd, &tpmfd, &cancelfd, &chardev))) return -1; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index a06672333c..e34d03191d 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -6384,7 +6384,8 @@ qemuDomainDeviceDefValidateVsock(const virDomainVsock= Def *vsock, =20 static int qemuDomainDeviceDefValidateTPM(virDomainTPMDef *tpm, - const virDomainDef *def ATTRIBUTE_UNUSED) + const virDomainDef *def, + virQEMUCapsPtr qemuCaps) { /* TPM 1.2 and 2 are not compatible, so we choose a specific version h= ere */ if (tpm->version =3D=3D VIR_DOMAIN_TPM_VERSION_DEFAULT) @@ -6406,7 +6407,31 @@ qemuDomainDeviceDefValidateTPM(virDomainTPMDef *tpm, case VIR_DOMAIN_TPM_VERSION_LAST: break; } + + switch (tpm->type) { + case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH: + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_TPM_PASSTHROUGH)) + goto no_support; + break; + + case VIR_DOMAIN_TPM_TYPE_EMULATOR: + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_TPM_EMULATOR)) + goto no_support; + + break; + case VIR_DOMAIN_TPM_TYPE_LAST: + break; + } + return 0; + + no_support: + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("The QEMU executable %s does not support TPM " + "backend type %s"), + def->emulator, + virDomainTPMBackendTypeToString(tpm->type)); + return -1; } =20 =20 @@ -6847,7 +6872,7 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef = *dev, break; =20 case VIR_DOMAIN_DEVICE_TPM: - ret =3D qemuDomainDeviceDefValidateTPM(dev->data.tpm, def); + ret =3D qemuDomainDeviceDefValidateTPM(dev->data.tpm, def, qemuCap= s); break; =20 case VIR_DOMAIN_DEVICE_GRAPHICS: --=20 2.19.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list