From nobody Tue Feb 10 00:58:18 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=1644000756; cv=none; d=zohomail.com; s=zohoarc; b=eobjyKn7Of5kJW595Q7Ojdvab3jz5oGJmN/JpQ1jgzmT1hQgDCbYxULZH/QnNSw6j/mg2Zj3GESPkoItX5ciOWAXsdFT4hsEYjhbbRrnMk2Fju909llRz69MZnNTNnDJYvugTNOIE6Un9nFizXtDIY1xcdlmJIScwfTMK/6h5/Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644000756; 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=4wGDinYyyh2heKJFOoXKQ11IwmQrkglIrSUPSck8XwQ=; b=eZrmABk8R+J/zD6HL7LNH4S2itOQ0T5YTo8c3UGSfFPqHZuKIT7a7MeaoU2LtEfj3csdm9z2YPeoANGMDCRq2IQF4hBvlQsvcYSNoOFhcRNOu1VxD3HSN2uXa6t7cIduXZ+6DVlvN7EQbHmi/0ZDDOGr1wU1Vy7ZZi82usSrRwY= 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 1644000756001285.84265692263614; Fri, 4 Feb 2022 10:52:36 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-401-Br-KZLqBMW2Kjz_i8pMf1A-1; Fri, 04 Feb 2022 13:52:30 -0500 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 4A5C5344B8; Fri, 4 Feb 2022 18:52:24 +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 1EB58838E3; Fri, 4 Feb 2022 18:52:24 +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 E14051809CBA; Fri, 4 Feb 2022 18:52:23 +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 214IpUE3002190 for ; Fri, 4 Feb 2022 13:51:30 -0500 Received: by smtp.corp.redhat.com (Postfix) id 224B0703B5; Fri, 4 Feb 2022 18:51:30 +0000 (UTC) Received: from harajuku.usersys.redhat.com (unknown [10.40.193.119]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 61E9772416 for ; Fri, 4 Feb 2022 18:51:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644000754; 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=4wGDinYyyh2heKJFOoXKQ11IwmQrkglIrSUPSck8XwQ=; b=JHikaRt9PwwTT/+y3O1o97ffyNYKMcWPTbOU80V8zWtoy423d1Vf0VsIiznUk1Ojuolcjm dOFr8VOvTPFt+Dy/hgu2xw2TpO6ADyW5nji8mwhzRorbeMB68mgl61yps4tjBK0Tuy1wYq nsrIYug+RDu+WsSdxzZLOKs8mK+03s4= X-MC-Unique: Br-KZLqBMW2Kjz_i8pMf1A-1 From: Andrea Bolognani To: libvir-list@redhat.com Subject: [libvirt PATCH 07/14] qemu: Introduce qemuExtTPMEmulatorSetupCgroup() Date: Fri, 4 Feb 2022 19:51:10 +0100 Message-Id: <20220204185117.61149-8-abologna@redhat.com> In-Reply-To: <20220204185117.61149-1-abologna@redhat.com> References: <20220204185117.61149-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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 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: 1644000756949100003 Content-Type: text/plain; charset="utf-8" This leaves qemuExtTPMSetupCgroup() to only deal with looping over TPM devices, same as other qemuExtTPMDoThing() functions. Signed-off-by: Andrea Bolognani --- src/qemu/qemu_tpm.c | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c index 2196b5c567..2a2e585080 100644 --- a/src/qemu/qemu_tpm.c +++ b/src/qemu/qemu_tpm.c @@ -797,6 +797,36 @@ qemuTPMEmulatorStop(const char *swtpmStateDir, } =20 =20 +/** + * qemuExtTPMEmulatorSetupCgroup: + * @swtpmStateDir: directory for swtpm's persistent state + * @shortName: short and unique name of the domain + * @cgroup: cgroup to add the swtpm process to + * + * Add the swtpm process to the appropriate cgroup. + */ +static int +qemuExtTPMEmulatorSetupCgroup(const char *swtpmStateDir, + const char *shortName, + virCgroup *cgroup) +{ + int rc; + pid_t pid; + + rc =3D qemuTPMEmulatorGetPid(swtpmStateDir, shortName, &pid); + if (rc < 0 || (rc =3D=3D 0 && pid =3D=3D (pid_t)-1)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not get process id of swtpm")); + return -1; + } + + if (virCgroupAddProcess(cgroup, pid) < 0) + return -1; + + return 0; +} + + int qemuExtTPMInitPaths(virQEMUDriver *driver, virDomainDef *def) @@ -1019,8 +1049,6 @@ qemuExtTPMSetupCgroup(virQEMUDriver *driver, virCgroup *cgroup) { g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); - int rc; - pid_t pid; size_t i; =20 for (i =3D 0; i < def->ntpms; i++) { @@ -1032,13 +1060,8 @@ qemuExtTPMSetupCgroup(virQEMUDriver *driver, shortName =3D virDomainDefGetShortName(def); if (!shortName) return -1; - rc =3D qemuTPMEmulatorGetPid(cfg->swtpmStateDir, shortName, &pid); - if (rc < 0 || (rc =3D=3D 0 && pid =3D=3D (pid_t)-1)) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Could not get process id of swtpm")); - return -1; - } - if (virCgroupAddProcess(cgroup, pid) < 0) + + if (qemuExtTPMEmulatorSetupCgroup(cfg->swtpmStateDir, shortName, c= group) < 0) return -1; } =20 --=20 2.34.1