From nobody Mon Feb 9 17:57:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1644000738; cv=none; d=zohomail.com; s=zohoarc; b=Mx7JJYr7DwH4JTa+lsKQwxdrBnsiIy1LHFBmlSTwLjQ6kl/xmV3DUH2KpR4gR9olHarMl/KR0K9OsdZjRxAwlw/eJCWFWsVlCGrsZVI5E+yBRZ0xV/s8kOEX25p7kHK/MfkRt/0nLQiS8dAYuSVjZ0piYWcpsYBz/n8zc3nFUL8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644000738; 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=KR6cwXVAB49lPrLz9O4+K1NI6tSCLNLkRMfNOtHL920=; b=VeM6HSKIkGk8YoJ1WhSagUFwbVdgvnQx4s5ve7DyR9D3FedEA3jGk4x3DRoQy114DuNufXyA26ZiMWYjOPq0/O9PEDlI1UFAMAp+jjF9/3GBpEaY8wEowkcqukUS9DXs/JkAyPsrX/1TIk2MbfoTZcyDTG53/JaGEIIUxxL3Fw8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 1644000738252967.7403780938296; Fri, 4 Feb 2022 10:52:18 -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-398-L0Zv0Pq9Nj6hUzntR7x8Xw-1; Fri, 04 Feb 2022 13:52:14 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9425E871104; Fri, 4 Feb 2022 18:52:08 +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 702BD45D87; Fri, 4 Feb 2022 18:52:08 +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 3F9AF1809CB8; Fri, 4 Feb 2022 18:52:08 +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 214IpaOA002269 for ; Fri, 4 Feb 2022 13:51:36 -0500 Received: by smtp.corp.redhat.com (Postfix) id 38D75703B5; Fri, 4 Feb 2022 18:51:36 +0000 (UTC) Received: from harajuku.usersys.redhat.com (unknown [10.40.193.119]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7A5237243D for ; Fri, 4 Feb 2022 18:51:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644000737; 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=KR6cwXVAB49lPrLz9O4+K1NI6tSCLNLkRMfNOtHL920=; b=afSjz/MfoygVIrtdL2BOeIS+QWMzy/JfIaycbiJlFd4st+CbBXeq4whv2KS7+qslkNWMKp G7DWP3O+l784swU/nsTg0kONcHifGYV+AwdoZ9MNj9a5IIiWKABwc3u/Syr7HO5Vw2HlY/ 46c4NUjJAZSSzt1Z5D7vC3SbkEf7OQY= X-MC-Unique: L0Zv0Pq9Nj6hUzntR7x8Xw-1 From: Andrea Bolognani To: libvir-list@redhat.com Subject: [libvirt PATCH 12/14] qemu: Move utility functions close together Date: Fri, 4 Feb 2022 19:51:15 +0100 Message-Id: <20220204185117.61149-13-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.11 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: 1644000740418100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Andrea Bolognani --- src/qemu/qemu_tpm.c | 124 ++++++++++++++++++++++---------------------- 1 file changed, 62 insertions(+), 62 deletions(-) diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c index c0e875627d..264b9b1d60 100644 --- a/src/qemu/qemu_tpm.c +++ b/src/qemu/qemu_tpm.c @@ -98,6 +98,68 @@ qemuTPMEmulatorLogBuildPath(const char *logDir, } =20 =20 +/** + * qemuTPMEmulatorSocketBuildPath: + * @swtpmStateDir: directory for swtpm runtime state + * @shortName: short and unique name of the domain + * + * Generate the swtpm's Unix socket path. + */ +static char * +qemuTPMEmulatorSocketBuildPath(const char *swtpmStateDir, + const char *shortName) +{ + return g_strdup_printf("%s/%s-swtpm.sock", swtpmStateDir, shortName); +} + + +/** + * qemuTPMEmulatorPidFileBuildPath: + * @swtpmStateDir: directory for swtpm runtime state + * @shortName: short and unique name of the domain + * + * Generate the swtpm's pidfile path. + */ +static char * +qemuTPMEmulatorPidFileBuildPath(const char *swtpmStateDir, + const char *shortName) +{ + g_autofree char *devicename =3D NULL; + + devicename =3D g_strdup_printf("%s-swtpm", shortName); + + return virPidFileBuildPath(swtpmStateDir, devicename); +} + + +/* + * qemuTPMEmulatorGetPid + * + * @swtpmStateDir: the directory where swtpm writes the pidfile into + * @shortName: short name of the domain + * @pid: pointer to pid + * + * Return -1 upon error, or zero on successful reading of the pidfile. + * If the PID was not still alive, zero will be returned, and @pid will be + * set to -1; + */ +static int +qemuTPMEmulatorGetPid(const char *swtpmStateDir, + const char *shortName, + pid_t *pid) +{ + g_autofree char *pidfile =3D qemuTPMEmulatorPidFileBuildPath(swtpmStat= eDir, + shortName); + if (!pidfile) + return -1; + + if (virPidFileReadPathIfLocked(pidfile, pid) < 0) + return -1; + + return 0; +} + + /** * qemuTPMEmulatorCreateStorage: * @tpm: TPM definition for an emulator type @@ -162,21 +224,6 @@ qemuTPMEmulatorDeleteStorage(virDomainTPMDef *tpm) } =20 =20 -/** - * qemuTPMEmulatorSocketBuildPath: - * @swtpmStateDir: directory for swtpm runtime state - * @shortName: short and unique name of the domain - * - * Generate the swtpm's Unix socket path. - */ -static char * -qemuTPMEmulatorSocketBuildPath(const char *swtpmStateDir, - const char *shortName) -{ - return g_strdup_printf("%s/%s-swtpm.sock", swtpmStateDir, shortName); -} - - /* * qemuTPMEmulatorInitPaths: * @@ -213,53 +260,6 @@ qemuTPMEmulatorInitPaths(virDomainTPMDef *tpm, } =20 =20 -/** - * qemuTPMEmulatorPidFileBuildPath: - * @swtpmStateDir: directory for swtpm runtime state - * @shortName: short and unique name of the domain - * - * Generate the swtpm's pidfile path. - */ -static char * -qemuTPMEmulatorPidFileBuildPath(const char *swtpmStateDir, - const char *shortName) -{ - g_autofree char *devicename =3D NULL; - - devicename =3D g_strdup_printf("%s-swtpm", shortName); - - return virPidFileBuildPath(swtpmStateDir, devicename); -} - - -/* - * qemuTPMEmulatorGetPid - * - * @swtpmStateDir: the directory where swtpm writes the pidfile into - * @shortName: short name of the domain - * @pid: pointer to pid - * - * Return -1 upon error, or zero on successful reading of the pidfile. - * If the PID was not still alive, zero will be returned, and @pid will be - * set to -1; - */ -static int -qemuTPMEmulatorGetPid(const char *swtpmStateDir, - const char *shortName, - pid_t *pid) -{ - g_autofree char *pidfile =3D qemuTPMEmulatorPidFileBuildPath(swtpmStat= eDir, - shortName); - if (!pidfile) - return -1; - - if (virPidFileReadPathIfLocked(pidfile, pid) < 0) - return -1; - - return 0; -} - - /** * qemuTPMEmulatorCleanupHost: * @tpm: TPM definition --=20 2.34.1