From nobody Thu Feb 12 11:50:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1770823555; cv=none; d=zohomail.com; s=zohoarc; b=j4g8eRNBlfTrTBTE4K+wrO8aRv9NQBiI0rswohCRr4UnCgAZ4bkQEld20BXo7c3jZMVfNmgK0DLG/VxpCRwoVnfBH/KBim7n0uRehOfie3xmnHwwMRxxV/oSuGSnnK5weG85IJgYaczFNMXAvA2gWPdRQl2MrQvN9GNhI4C2nSI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770823555; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XaKfS+2R4T8oElRoS9wVjz31759POV1QCguEEkq0KoQ=; b=hhhIMu77V8WRs3SWtgnfzcnUGQtfDLO4qGrNm4o9EdvM2cWCyz1bi+WPtfGlKvgJABT4gXE77szgMPozGOJq5ETbboQT+nBAKAasmtm4FGvnQODmwS0PnKcl4NVL0epWEu+CTBzkYtn5lD9YgukF3jKUd5PXANO31in4XOVum9k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770823555108169.50899128045523; Wed, 11 Feb 2026 07:25:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqC5s-0004RC-Rh; Wed, 11 Feb 2026 10:25:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC5p-0004Q5-Kq for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:25:30 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC5o-0005Xp-9V for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:25:29 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-627-leivwDvAMD2G1_sN-QHPeA-1; Wed, 11 Feb 2026 10:25:24 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 514E518002FB; Wed, 11 Feb 2026 15:25:22 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.227.9]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D3ED130002D5; Wed, 11 Feb 2026 15:25:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770823527; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XaKfS+2R4T8oElRoS9wVjz31759POV1QCguEEkq0KoQ=; b=TUp1Fl8CH+05bUYLabkMRsdFMPJFFIjTmaqTdtK2KM2iXCJ4YZRA8G3823ZH0PU6jO3OVx Fhf0QjRJ0nRiG0MAU1/ZW5aLXAISM2Zb/dKUN6SASdNivsRJuEdYMrw3lTIPM4oXXMfWqs DEdtbaLclm9DdlFqU9N/j1+hN0ifLbY= X-MC-Unique: leivwDvAMD2G1_sN-QHPeA-1 X-Mimecast-MFC-AGG-ID: leivwDvAMD2G1_sN-QHPeA_1770823522 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Stefan Weil , "Dr. David Alan Gilbert" , Pierrick Bouvier , devel@lists.libvirt.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, qemu-rust@nongnu.org, Paolo Bonzini , Markus Armbruster , Gerd Hoffmann , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Christian Schoenebeck , Richard Henderson Subject: [PATCH v6 01/27] meson: don't access 'cxx' object without checking cpp lang Date: Wed, 11 Feb 2026 15:24:42 +0000 Message-ID: <20260211152508.732487-2-berrange@redhat.com> In-Reply-To: <20260211152508.732487-1-berrange@redhat.com> References: <20260211152508.732487-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1770823558121154100 Signed-off-by: Daniel P. Berrang=C3=A9 --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 2d114e9018..9ad16d1998 100644 --- a/meson.build +++ b/meson.build @@ -3194,7 +3194,7 @@ if host_os =3D=3D 'windows' endif =20 # Detect if ConvertStringToBSTR has been defined in _com_util namespace -if host_os =3D=3D 'windows' +if host_os =3D=3D 'windows' and 'cpp' in all_languages has_convert_string_to_bstr =3D cxx.links(''' #include int main() { --=20 2.53.0 From nobody Thu Feb 12 11:50:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1770823560; cv=none; d=zohomail.com; s=zohoarc; b=JLCKwQEhApS3jMvweCHYWYqAUUD9yzKoB2bLBPQpLuJpTK3hmxDBZ+ZYBgd5Cdb3cPEkrkw9GSDGKBnU7TvFRksCG5DhUpxvJtlxnOpxKOxq/+sYi/lmhCoOTYumf2TbdSDb79L2oHKriy4OLH8j2FmFB5MS2mgJ5Aieiz/RsfQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770823560; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=466Ssz0vv+5O0NggCHR+fBab7zapuxifn/iQGH4yMZE=; b=ndmjjVlzZX3sv8DOPQjaR/sPJtPf1YsVefreQ+yfVUVrRgNEPlx6AlDc5nonWNZdkn0AIXBEIFiJBdAjN5THv35HwSqfKy63JIhfG9H5E+e7lkH6cR134/vM9zIOnYTGZhLLLhfa5aoUJA4skLBBhhupjrrvhCbYbvzQBVBVEOg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770823560128789.6730679885904; Wed, 11 Feb 2026 07:26:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqC60-0004Ux-Hw; Wed, 11 Feb 2026 10:25:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC5w-0004SU-6I for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:25:36 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC5t-0005b2-Qm for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:25:35 -0500 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-677-kOToLUo9OvKfvPWBtwHkpw-1; Wed, 11 Feb 2026 10:25:29 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E3BE61956054; Wed, 11 Feb 2026 15:25:27 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.227.9]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AA17130001BF; Wed, 11 Feb 2026 15:25:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770823533; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=466Ssz0vv+5O0NggCHR+fBab7zapuxifn/iQGH4yMZE=; b=H3XpncUX0S8oI1xE8lXen4Yx1bE8G2KZ5NeoghO13f2B2oeV9UhO9OmasJrN2voVtFH9aL mi47+oQhJSc9mjnhQVGKXVd0ziXJJ/vtCmmT3zIzVRwd1P48zG/VqBRDD9weupR/s78Ovy S3bChTOC1rxzH0PR2BhUa0x9WZ4aKz8= X-MC-Unique: kOToLUo9OvKfvPWBtwHkpw-1 X-Mimecast-MFC-AGG-ID: kOToLUo9OvKfvPWBtwHkpw_1770823528 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Stefan Weil , "Dr. David Alan Gilbert" , Pierrick Bouvier , devel@lists.libvirt.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, qemu-rust@nongnu.org, Paolo Bonzini , Markus Armbruster , Gerd Hoffmann , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Christian Schoenebeck , Richard Henderson Subject: [PATCH v6 02/27] qemu-options: remove extraneous [] around arg values Date: Wed, 11 Feb 2026 15:24:43 +0000 Message-ID: <20260211152508.732487-3-berrange@redhat.com> In-Reply-To: <20260211152508.732487-1-berrange@redhat.com> References: <20260211152508.732487-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1770823562111158500 There are quite a few inappropriate uses of [...] around argument values. The [] are intended to indicate optionality, but in some cases it is used to wrap a set of enum values. In other cases it is being used to show the value is entirely optional, which was common behaviour for boolean values in the past. QEMU has deprecated short-form boolean options for quite a while though, and we should thus not advertize this possibility in the docs. Reviewed-by: Markus Armbruster Signed-off-by: Daniel P. Berrang=C3=A9 --- qemu-options.hx | 110 ++++++++++++++++++++++++------------------------ 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/qemu-options.hx b/qemu-options.hx index bd014a3244..cdb7fa20c2 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -25,7 +25,7 @@ SRST ERST =20 DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ - "-machine [type=3D]name[,prop[=3Dvalue][,...]]\n" + "-machine [type=3D]name[,prop=3Dvalue[,...]]\n" " selects emulated machine ('-machine help' for list)\n" " property accel=3Daccel1[:accel2[:...]] selects accele= rator\n" " supported accelerators are kvm, xen, hvf, nvmm, whpx,= mshv or tcg (default: tcg)\n" @@ -227,7 +227,7 @@ SRST ERST =20 DEF("accel", HAS_ARG, QEMU_OPTION_accel, - "-accel [accel=3D]accelerator[,prop[=3Dvalue][,...]]\n" + "-accel [accel=3D]accelerator[,prop=3Dvalue[,...]]\n" " select accelerator (kvm, xen, hvf, nvmm, whpx, mshv o= r tcg; use 'help' for a list)\n" " igd-passthru=3Don|off (enable Xen integrated Intel gr= aphics passthrough, default=3Doff)\n" " kernel-irqchip=3Don|off|split controls accelerated ir= qchip support (default=3Don)\n" @@ -789,17 +789,17 @@ ERST =20 =20 DEF("audio", HAS_ARG, QEMU_OPTION_audio, - "-audio [driver=3D]driver[,prop[=3Dvalue][,...]]\n" + "-audio [driver=3D]driver[,prop=3Dvalue[,...]]\n" " specifies default audio backend when `audiodev` is no= t\n" " used to create a machine or sound device;" " options are the same as for -audiodev\n" - "-audio [driver=3D]driver,model=3Dvalue[,prop[=3Dvalue][,...]]\n" + "-audio [driver=3D]driver,model=3Dvalue[,prop=3Dvalue[,...]]\n" " specifies the audio backend and device to use;\n" " apart from 'model', options are the same as for -audi= odev.\n" " use '-audio model=3Dhelp' to show possible devices.\n= ", QEMU_ARCH_ALL) SRST -``-audio [driver=3D]driver[,model=3Dvalue][,prop[=3Dvalue][,...]]`` +``-audio [driver=3D]driver[,model=3Dvalue][,prop=3Dvalue[,...]]`` If the ``model`` option is specified, ``-audio`` is a shortcut for configuring both the guest audio hardware and the host audio backend in one go. The guest hardware model can be set with @@ -827,7 +827,7 @@ SRST ERST =20 DEF("audiodev", HAS_ARG, QEMU_OPTION_audiodev, - "-audiodev [driver=3D]driver,id=3Did[,prop[=3Dvalue][,...]]\n" + "-audiodev [driver=3D]driver,id=3Did[,prop=3Dvalue[,...]]\n" " specifies the audio backend to use\n" " Use ``-audiodev help`` to list the available drivers\= n" " id=3D identifier of the backend\n" @@ -840,25 +840,25 @@ DEF("audiodev", HAS_ARG, QEMU_OPTION_audiodev, " valid values: s8, s16, s32, u8, u16, u32, f32\n" " in|out.voices=3D number of voices to use\n" " in|out.buffer-length=3D length of buffer in microseco= nds\n" - "-audiodev none,id=3Did,[,prop[=3Dvalue][,...]]\n" + "-audiodev none,id=3Did,[,prop=3Dvalue[,...]]\n" " dummy driver that discards all output\n" #ifdef CONFIG_AUDIO_ALSA - "-audiodev alsa,id=3Did[,prop[=3Dvalue][,...]]\n" + "-audiodev alsa,id=3Did[,prop=3Dvalue[,...]]\n" " in|out.dev=3D name of the audio device to use\n" " in|out.period-length=3D length of period in microseco= nds\n" " in|out.try-poll=3D attempt to use poll mode\n" " threshold=3D threshold (in microseconds) when playbac= k starts\n" #endif #ifdef CONFIG_AUDIO_COREAUDIO - "-audiodev coreaudio,id=3Did[,prop[=3Dvalue][,...]]\n" + "-audiodev coreaudio,id=3Did[,prop=3Dvalue[,...]]\n" " in|out.buffer-count=3D number of buffers\n" #endif #ifdef CONFIG_AUDIO_DSOUND - "-audiodev dsound,id=3Did[,prop[=3Dvalue][,...]]\n" + "-audiodev dsound,id=3Did[,prop=3Dvalue[,...]]\n" " latency=3D add extra latency to playback in microseco= nds\n" #endif #ifdef CONFIG_AUDIO_OSS - "-audiodev oss,id=3Did[,prop[=3Dvalue][,...]]\n" + "-audiodev oss,id=3Did[,prop=3Dvalue[,...]]\n" " in|out.dev=3D path of the audio device to use\n" " in|out.buffer-count=3D number of buffers\n" " in|out.try-poll=3D attempt to use poll mode\n" @@ -867,35 +867,35 @@ DEF("audiodev", HAS_ARG, QEMU_OPTION_audiodev, " dsp-policy=3D set timing policy (0..10), -1 to use fr= agment mode\n" #endif #ifdef CONFIG_AUDIO_PA - "-audiodev pa,id=3Did[,prop[=3Dvalue][,...]]\n" + "-audiodev pa,id=3Did[,prop=3Dvalue[,...]]\n" " server=3D PulseAudio server address\n" " in|out.name=3D source/sink device name\n" " in|out.latency=3D desired latency in microseconds\n" #endif #ifdef CONFIG_AUDIO_PIPEWIRE - "-audiodev pipewire,id=3Did[,prop[=3Dvalue][,...]]\n" + "-audiodev pipewire,id=3Did[,prop=3Dvalue[,...]]\n" " in|out.name=3D source/sink device name\n" " in|out.stream-name=3D name of pipewire stream\n" " in|out.latency=3D desired latency in microseconds\n" #endif #ifdef CONFIG_AUDIO_SDL - "-audiodev sdl,id=3Did[,prop[=3Dvalue][,...]]\n" + "-audiodev sdl,id=3Did[,prop=3Dvalue[,...]]\n" " in|out.buffer-count=3D number of buffers\n" #endif #ifdef CONFIG_AUDIO_SNDIO - "-audiodev sndio,id=3Did[,prop[=3Dvalue][,...]]\n" + "-audiodev sndio,id=3Did[,prop=3Dvalue[,...]]\n" #endif #ifdef CONFIG_SPICE - "-audiodev spice,id=3Did[,prop[=3Dvalue][,...]]\n" + "-audiodev spice,id=3Did[,prop=3Dvalue[,...]]\n" #endif #ifdef CONFIG_DBUS_DISPLAY - "-audiodev dbus,id=3Did[,prop[=3Dvalue][,...]]\n" + "-audiodev dbus,id=3Did[,prop=3Dvalue[,...]]\n" #endif - "-audiodev wav,id=3Did[,prop[=3Dvalue][,...]]\n" + "-audiodev wav,id=3Did[,prop=3Dvalue[,...]]\n" " path=3D path of wav file to record\n", QEMU_ARCH_ALL) SRST -``-audiodev [driver=3D]driver,id=3Did[,prop[=3Dvalue][,...]]`` +``-audiodev [driver=3D]driver,id=3Did[,prop=3Dvalue[,...]]`` Adds a new audio backend driver identified by id. There are global and driver specific properties. Some values can be set differently for input and output, they're marked with ``in|out.``. You can set @@ -954,11 +954,11 @@ SRST ``in|out.buffer-length=3Dusecs`` Sets the size of the buffer in microseconds. =20 -``-audiodev none,id=3Did[,prop[=3Dvalue][,...]]`` +``-audiodev none,id=3Did[,prop=3Dvalue[,...]]`` Creates a dummy backend that discards all outputs. This backend has no backend specific properties. =20 -``-audiodev alsa,id=3Did[,prop[=3Dvalue][,...]]`` +``-audiodev alsa,id=3Did[,prop=3Dvalue[,...]]`` Creates backend using the ALSA. This backend is only available on Linux. =20 @@ -977,7 +977,7 @@ SRST ``threshold=3Dthreshold`` Threshold (in microseconds) when playback starts. Default is 0. =20 -``-audiodev coreaudio,id=3Did[,prop[=3Dvalue][,...]]`` +``-audiodev coreaudio,id=3Did[,prop=3Dvalue[,...]]`` Creates a backend using Apple's Core Audio. This backend is only available on Mac OS and only supports playback. =20 @@ -986,7 +986,7 @@ SRST ``in|out.buffer-count=3Dcount`` Sets the count of the buffers. =20 -``-audiodev dsound,id=3Did[,prop[=3Dvalue][,...]]`` +``-audiodev dsound,id=3Did[,prop=3Dvalue[,...]]`` Creates a backend using Microsoft's DirectSound. This backend is only available on Windows and only supports playback. =20 @@ -996,7 +996,7 @@ SRST Add extra usecs microseconds latency to playback. Default is 10000 (10 ms). =20 -``-audiodev oss,id=3Did[,prop[=3Dvalue][,...]]`` +``-audiodev oss,id=3Did[,prop=3Dvalue[,...]]`` Creates a backend using OSS. This backend is available on most Unix-like systems. =20 @@ -1025,7 +1025,7 @@ SRST buffer sizes specified by ``buffer`` and ``buffer-count``. This option is ignored if you do not have OSS 4. Default is 5. =20 -``-audiodev pa,id=3Did[,prop[=3Dvalue][,...]]`` +``-audiodev pa,id=3Did[,prop=3Dvalue[,...]]`` Creates a backend using PulseAudio. This backend is available on most systems. =20 @@ -1041,7 +1041,7 @@ SRST Desired latency in microseconds. The PulseAudio server will try to honor this value but actual latencies may be lower or higher. =20 -``-audiodev pipewire,id=3Did[,prop[=3Dvalue][,...]]`` +``-audiodev pipewire,id=3Did[,prop=3Dvalue[,...]]`` Creates a backend using PipeWire. This backend is available on most systems. =20 @@ -1056,7 +1056,7 @@ SRST ``in|out.stream-name`` Specify the name of pipewire stream. =20 -``-audiodev sdl,id=3Did[,prop[=3Dvalue][,...]]`` +``-audiodev sdl,id=3Did[,prop=3Dvalue[,...]]`` Creates a backend using SDL. This backend is available on most systems, but you should use your platform's native backend if possible. @@ -1066,7 +1066,7 @@ SRST ``in|out.buffer-count=3Dcount`` Sets the count of the buffers. =20 -``-audiodev sndio,id=3Did[,prop[=3Dvalue][,...]]`` +``-audiodev sndio,id=3Did[,prop=3Dvalue[,...]]`` Creates a backend using SNDIO. This backend is available on OpenBSD and most other Unix-like systems. =20 @@ -1079,13 +1079,13 @@ SRST ``in|out.latency=3Dusecs`` Sets the desired period length in microseconds. =20 -``-audiodev spice,id=3Did[,prop[=3Dvalue][,...]]`` +``-audiodev spice,id=3Did[,prop=3Dvalue[,...]]`` Creates a backend that sends audio through SPICE. This backend requires ``-spice`` and automatically selected in that case, so usually you can ignore this option. This backend has no backend specific properties. =20 -``-audiodev wav,id=3Did[,prop[=3Dvalue][,...]]`` +``-audiodev wav,id=3Did[,prop=3Dvalue[,...]]`` Creates a backend that writes audio to a WAV file. =20 Backend specific options are: @@ -1096,21 +1096,21 @@ SRST ERST =20 DEF("device", HAS_ARG, QEMU_OPTION_device, - "-device driver[,prop[=3Dvalue][,...]]\n" + "-device driver[,prop=3Dvalue[,...]]\n" " add device (based on driver)\n" " prop=3Dvalue,... sets driver properties\n" " use '-device help' to print all possible drivers\n" " use '-device driver,help' to print all possible prope= rties\n", QEMU_ARCH_ALL) SRST -``-device driver[,prop[=3Dvalue][,...]]`` +``-device driver[,prop=3Dvalue[,...]]`` Add device driver. prop=3Dvalue sets driver properties. Valid properties depend on the driver. To get help on possible drivers and properties, use ``-device help`` and ``-device driver,help``. =20 Some drivers are: =20 -``-device ipmi-bmc-sim,id=3Did[,prop[=3Dvalue][,...]]`` +``-device ipmi-bmc-sim,id=3Did[,prop=3Dvalue[,...]]`` Add an IPMI BMC. This is a simulation of a hardware management interface processor that normally sits on a system. It provides a watchdog and the ability to reset and power control the system. You @@ -2308,19 +2308,19 @@ DEF("spice", HAS_ARG, QEMU_OPTION_spice, " [,x509-dh-key-file=3D][,addr=3Daddr]\n" " [,ipv4=3Don|off][,ipv6=3Don|off][,unix=3Don|off]\n" " [,tls-ciphers=3D]\n" - " [,tls-channel=3D[main|display|cursor|inputs|record|playback]]\= n" - " [,plaintext-channel=3D[main|display|cursor|inputs|record|playb= ack]]\n" + " [,tls-channel=3Dmain|display|cursor|inputs|record|playback]\n" + " [,plaintext-channel=3Dmain|display|cursor|inputs|record|playba= ck]\n" " [,sasl=3Don|off][,disable-ticketing=3Don|off]\n" " [,password-secret=3D]\n" - " [,image-compression=3D[auto_glz|auto_lz|quic|glz|lz|off]]\n" - " [,jpeg-wan-compression=3D[auto|never|always]]\n" - " [,zlib-glz-wan-compression=3D[auto|never|always]]\n" - " [,streaming-video=3D[off|all|filter]][,disable-copy-paste=3Don= |off]\n" - " [,disable-agent-file-xfer=3Don|off][,agent-mouse=3D[on|off]]\n" - " [,playback-compression=3D[on|off]][,seamless-migration=3D[on|o= ff]]\n" + " [,image-compression=3Dauto_glz|auto_lz|quic|glz|lz|off]\n" + " [,jpeg-wan-compression=3Dauto|never|always]\n" + " [,zlib-glz-wan-compression=3Dauto|never|always]\n" + " [,streaming-video=3Doff|all|filter][,disable-copy-paste=3Don|o= ff]\n" + " [,disable-agent-file-xfer=3Don|off][,agent-mouse=3Don|off]\n" + " [,playback-compression=3Don|off][,seamless-migration=3Don|off]= \n" " [,video-codec=3D\n" " [,max-refresh-rate=3Drate\n" - " [,gl=3D[on|off]][,rendernode=3D]\n" + " [,gl=3Don|off][,rendernode=3D]\n" " enable spice\n" " at least one of {port, tls-port} is mandatory\n", QEMU_ARCH_ALL) @@ -2380,7 +2380,7 @@ SRST ``tls-ciphers=3D`` Specify which ciphers to use. =20 - ``tls-channel=3D[main|display|cursor|inputs|record|playback]``; \ ``pl= aintext-channel=3D[main|display|cursor|inputs|record|playback]`` + ``tls-channel=3Dmain|display|cursor|inputs|record|playback``; \ ``plai= ntext-channel=3Dmain|display|cursor|inputs|record|playback`` Force specific channel to be used with or without TLS encryption. The options can be specified multiple times to configure multiple channels. The special name "default" can be @@ -2388,24 +2388,24 @@ SRST explicitly forced into one mode the spice client is allowed to pick tls/plaintext as he pleases. =20 - ``image-compression=3D[auto_glz|auto_lz|quic|glz|lz|off]`` + ``image-compression=3Dauto_glz|auto_lz|quic|glz|lz|off`` Configure image compression (lossless). Default is auto\_glz. =20 - ``jpeg-wan-compression=3D[auto|never|always]``; \ ``zlib-glz-wan-compr= ession=3D[auto|never|always]`` + ``jpeg-wan-compression=3Dauto|never|always``; \ ``zlib-glz-wan-compres= sion=3Dauto|never|always`` Configure wan image compression (lossy for slow links). Default is auto. =20 - ``streaming-video=3D[off|all|filter]`` + ``streaming-video=3Doff|all|filter`` Configure video stream detection. Default is off. =20 - ``agent-mouse=3D[on|off]`` + ``agent-mouse=3Don|off`` Enable/disable passing mouse events via vdagent. Default is on. =20 - ``playback-compression=3D[on|off]`` + ``playback-compression=3Don|off`` Enable/disable audio stream compression (using celt 0.5.1). Default is on. =20 - ``seamless-migration=3D[on|off]`` + ``seamless-migration=3Don|off`` Enable/disable spice seamless migration. Default is off. =20 ``video-codec=3D`` @@ -2419,7 +2419,7 @@ SRST Provide the maximum refresh rate (or FPS) at which the encoding requests should be sent to the Spice server. Default would be 30. =20 - ``gl=3D[on|off]`` + ``gl=3Don|off`` Enable/disable OpenGL context. Default is off. =20 ``rendernode=3D`` @@ -2649,7 +2649,7 @@ SRST bandwidth when playing videos. Disabling adaptive encodings restores the original static behavior of encodings like Tight. =20 - ``share=3D[allow-exclusive|force-shared|ignore]`` + ``share=3Dallow-exclusive|force-shared|ignore`` Set display sharing policy. 'allow-exclusive' allows clients to ask for exclusive access. As suggested by the rfb spec this is implemented by dropping other connections. Connecting multiple @@ -4823,9 +4823,9 @@ SRST ERST =20 DEF("mon", HAS_ARG, QEMU_OPTION_mon, \ - "-mon [chardev=3D]name[,mode=3Dreadline|control][,pretty[=3Don|off]]\n= ", QEMU_ARCH_ALL) + "-mon [chardev=3D]name[,mode=3Dreadline|control][,pretty=3Don|off]\n",= QEMU_ARCH_ALL) SRST -``-mon [chardev=3D]name[,mode=3Dreadline|control][,pretty[=3Don|off]]`` +``-mon [chardev=3D]name[,mode=3Dreadline|control][,pretty=3Don|off]`` Set up a monitor connected to the chardev ``name``. QEMU supports two monitors: the Human Monitor Protocol (HMP; for human interaction), and the QEMU Monitor Protocol @@ -5514,14 +5514,14 @@ ERST #endif =20 DEF("msg", HAS_ARG, QEMU_OPTION_msg, - "-msg [timestamp[=3Don|off]][,guest-name=3D[on|off]]\n" + "-msg [timestamp=3Don|off][,guest-name=3Don|off]\n" " control error message format\n" " timestamp=3Don enables timestamps (default: off)\n" " guest-name=3Don enables guest name prefix but only if= \n" " -name guest option is set (default: off= )\n", QEMU_ARCH_ALL) SRST -``-msg [timestamp[=3Don|off]][,guest-name[=3Don|off]]`` +``-msg [timestamp=3Don|off][,guest-name=3Don|off]`` Control error message format. =20 ``timestamp=3Don|off`` --=20 2.53.0 From nobody Thu Feb 12 11:50:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1770823563; cv=none; d=zohomail.com; s=zohoarc; b=P2eD0Lpiel0FAS70AKK8iI6ndpZ48IoDwjVZ5OMgi3s6IExAarMZn7UhFk1Xow08dsClc68RBIeA4U+JWCQ9ijKGMUejBi3wH2oaqNxb8b/PllY8z7K4f2dx5TzCGEukRz3zCyEPkVXlwcVf1At/lvauHXs0tVTRd1Gd521CBV0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770823563; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=4nNBnkbdOoq/TO93m2/cqfU9S+qOIByL3MN/2Z5FSuM=; b=nUGTIvETxK6J17BOr4iolfGv9CjSpW+M12ucdb5SERNAEGDPmgLPWHoSObvYBNbIhMdvWPEdr+CpqnEN7YY7R44rx5NOphnLSr/A9ZbRSlMUX/2AbB9ipI9rHe1fW6V+NZnLfoPI4aaIQyHdTdBZjD3i6itrm36JqruEHppZTEU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770823563721903.637602686726; Wed, 11 Feb 2026 07:26:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqC6F-0004cD-QJ; Wed, 11 Feb 2026 10:25:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC63-0004Xi-7w for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:25:45 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC61-0005dt-Oj for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:25:42 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-74-FTCQmgAGPwSyASZ7_ncZEw-1; Wed, 11 Feb 2026 10:25:35 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 97A8618003F5; Wed, 11 Feb 2026 15:25:33 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.227.9]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5E77430001A8; Wed, 11 Feb 2026 15:25:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770823538; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4nNBnkbdOoq/TO93m2/cqfU9S+qOIByL3MN/2Z5FSuM=; b=FlQ0oCV4qwMOQy6QHLArzNqVS91NamHNmLZmP9XUzV0hVO8DZ/xx6eGqIclyaOgStsxFoY 7wmigjEsi2DY5cGSRdAe/THvkOcvzshhNLrmZ7IZONcX4B5hyqzkrdWHl+rxwGjR6ZsSBZ LP9thSKb+0TABYNnRALE3Val6dzX2aw= X-MC-Unique: FTCQmgAGPwSyASZ7_ncZEw-1 X-Mimecast-MFC-AGG-ID: FTCQmgAGPwSyASZ7_ncZEw_1770823533 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Stefan Weil , "Dr. David Alan Gilbert" , Pierrick Bouvier , devel@lists.libvirt.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, qemu-rust@nongnu.org, Paolo Bonzini , Markus Armbruster , Gerd Hoffmann , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Christian Schoenebeck , Richard Henderson Subject: [PATCH v6 03/27] include: define constant for early constructor priority Date: Wed, 11 Feb 2026 15:24:44 +0000 Message-ID: <20260211152508.732487-4-berrange@redhat.com> In-Reply-To: <20260211152508.732487-1-berrange@redhat.com> References: <20260211152508.732487-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1770823565738158500 Functions marked with __attribute__((__constructor__)) will be invoked in linker order. In theory this is well defined, but in practice, it is hard to determine what this order will be with the layers of indirection through meson, ninja and the static libraries QEMU builds. Notably, the order currently appears different between Linux and Windows (as tested with Wine on Linux). This can cause problems when certain QEMU constructors have a dependancy on other QEMU constructors. To address this define a QEMU_CONSTRUCTOR_EARLY constant which provides a priority value that will run before other default constructors. This is to be used for QEMU constructors that are themselves self-contained, but may be relied upon by other constructors. Reviewed-by: Richard Henderson Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Daniel P. Berrang=C3=A9 --- include/qemu/compiler.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h index 1c2b673c05..4c49f52eb0 100644 --- a/include/qemu/compiler.h +++ b/include/qemu/compiler.h @@ -194,6 +194,14 @@ # define QEMU_USED #endif =20 +/* + * A priority for __attribute__((constructor(...))) that + * will run earlier than the default constructors. Must + * only be used for functions that have no dependency + * on global initialization of other QEMU subsystems. + */ +#define QEMU_CONSTRUCTOR_EARLY 101 + /* * Disable -ftrivial-auto-var-init on a local variable. * --=20 2.53.0 From nobody Thu Feb 12 11:50:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1770823654; cv=none; d=zohomail.com; s=zohoarc; b=GZ6oD+HeqdyaDdomxd5vyYsjNxZr80qhpAbGuAsjjGdfiKCZ0Ac58+9p1q/Jdf+fZY0KDL4lbscPcxIbDZdkXCE3Hl05iwaaUY4xGkOnMjGXQyssgIgdo4VrnLPo/otRXXGgnDC08Ci/StGIjH9eXXMOb4tgsgQGavY7m1HLA0Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770823654; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=kAnXty8ojb0QvYCAJwvtMMolNwPYeQ0lJZK1O5DK5TM=; b=BNm2NXaytvHpWYZrTUSCzw0ACPwoe9OFr2OBrBba2g9jAAaxHeslD2PVUY2oQKWAcv7CSmbNsbFHgNSCH31xAsoTwfkQPopjxMoKWNLcXm2NQXGj0nKjP1Ps9qXx2EScd/fPJfdSI8ahQVZvrk5GCsKBQmd0Mfh/8sGdVsdfkEA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770823654177126.51541570309689; Wed, 11 Feb 2026 07:27:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqC6H-0004j8-3H; Wed, 11 Feb 2026 10:25:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC68-0004ZL-SZ for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:25:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC66-0005hn-V9 for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:25:48 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-594-uSHY1e4TMZiN01Zdm3jaxg-1; Wed, 11 Feb 2026 10:25:41 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0D93F180034A; Wed, 11 Feb 2026 15:25:39 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.227.9]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 125A130001A8; Wed, 11 Feb 2026 15:25:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770823546; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kAnXty8ojb0QvYCAJwvtMMolNwPYeQ0lJZK1O5DK5TM=; b=AlvWkLh2q9kvkujtvhxT6wWaNJYREeGTNSINBGVu23LwgwA316cLQA1TY+YuSRw5D1UQ9r ogEC/9Dfo07iaR5hQd75LyMgGKEQdO6vg+73Tn/3KveZF+QVLk6GHclddNqyUZF8Mq8pPs hd/Ba8ZLDsEOrBkjq8OhlZOMMiCYD5Y= X-MC-Unique: uSHY1e4TMZiN01Zdm3jaxg-1 X-Mimecast-MFC-AGG-ID: uSHY1e4TMZiN01Zdm3jaxg_1770823539 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Stefan Weil , "Dr. David Alan Gilbert" , Pierrick Bouvier , devel@lists.libvirt.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, qemu-rust@nongnu.org, Paolo Bonzini , Markus Armbruster , Gerd Hoffmann , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Christian Schoenebeck , Richard Henderson Subject: [PATCH v6 04/27] monitor: initialize global data from a constructor Date: Wed, 11 Feb 2026 15:24:45 +0000 Message-ID: <20260211152508.732487-5-berrange@redhat.com> In-Reply-To: <20260211152508.732487-1-berrange@redhat.com> References: <20260211152508.732487-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1770823656920154100 Some monitor functions, most notably, monitor_cur() rely on global data being initialized by 'monitor_init_globals()'. The latter is called relatively late in startup. If code triggers error_report() before monitor_init_globals() is called, QEMU will abort when accessing the uninitialized monitor mutex. The critical monitor global data must be initialized from a constructor function, to improve the guarantee that it is done before any possible calls to monitor_cur(). Not only that, but the constructor must be marked to run before the default constructor in case any of them trigger error reporting. Note in particular that the RCU constructor will spawn a background thread so we might even have non-constructor QEMU code running concurrently with other constructors. As a general note, constructors should be extrememly careful about what QEMU code they invoke, as it cannot be guaranteed that the process is fully initialized and so not all normal QEMU API rules apply. Reviewed-by: Richard Henderson Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Markus Armbruster Fixes: e69ee454b5f9 (monitor: Make current monitor a per-coroutine property) Signed-off-by: Daniel P. Berrang=C3=A9 --- monitor/monitor.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/monitor/monitor.c b/monitor/monitor.c index 1273eb7260..dd2c45ded0 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -708,18 +708,22 @@ void monitor_cleanup(void) } } =20 -static void monitor_qapi_event_init(void) +/* + * Initialize static vars that have no deps on external + * module initialization, and are required for external + * functions to call things like monitor_cur() + */ +static void __attribute__((__constructor__(QEMU_CONSTRUCTOR_EARLY))) +monitor_init_static(void) { + qemu_mutex_init(&monitor_lock); + coroutine_mon =3D g_hash_table_new(NULL, NULL); monitor_qapi_event_state =3D g_hash_table_new(qapi_event_throttle_hash, qapi_event_throttle_equal); } =20 void monitor_init_globals(void) { - monitor_qapi_event_init(); - qemu_mutex_init(&monitor_lock); - coroutine_mon =3D g_hash_table_new(NULL, NULL); - /* * The dispatcher BH must run in the main loop thread, since we * have commands assuming that context. It would be nice to get --=20 2.53.0 From nobody Thu Feb 12 11:50:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1770823615; cv=none; d=zohomail.com; s=zohoarc; b=JN+jNj6GIPw6cMEHfRK/vheSMkJjuP/mV+037gDkLl0u4ja5q1ci7VPB0KCxDMjWf8xhvGSQlsY2ZiJOY5vgp6WGcDQwr7q6EVmcTxlWkZaHQDMqvgJaHKbouXIBuTc/MLC5kCZHg5g3A9JRQ8pGEe9mqrwf5NugTFanOiial5Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770823615; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Ui4fD1jz797G3RiFXRHLkhT2i8NLmus/BW0z4PdlSwg=; b=OBGKwxe8HAH7ppixtXfW2mYJ26Tu2tyzQXStMFQXe1kZa4HrCpp6M0UvfSvCH7ecx3TztHKETlx8qTm4Dh8mW8DfTSxsjWAtaZMf7kiKuVVGmkGDFdNOcYYx/S96FZownDFXda+zUWQDjW2cOtDzN6z6/YRYRdkjEgL6z0w5PsE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 177082361506754.38532139844028; Wed, 11 Feb 2026 07:26:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqC6H-0004jX-M6; Wed, 11 Feb 2026 10:25:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC6G-0004hc-HI for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:25:56 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC6C-0005kN-En for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:25:56 -0500 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-551-v8iV2EDrOeeM8lfubGXdFQ-1; Wed, 11 Feb 2026 10:25:47 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 870F51955E7A; Wed, 11 Feb 2026 15:25:45 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.227.9]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8D35C30001A8; Wed, 11 Feb 2026 15:25:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770823551; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ui4fD1jz797G3RiFXRHLkhT2i8NLmus/BW0z4PdlSwg=; b=d66G5DL7mETeh6Qo7f30pdns1GuJlhwS7m8ZSNqJotSpYYGzn2BwiWJg2n30OQawYUcxIo ijlbBmOeTaxUIA8n3c6sOhvi9mkHPDmX827AKM180UlftPvasmnASC8ecHZnevUQrfq4CN zq7hh0zNJrE5+cF8aY4KseDYiElgo2A= X-MC-Unique: v8iV2EDrOeeM8lfubGXdFQ-1 X-Mimecast-MFC-AGG-ID: v8iV2EDrOeeM8lfubGXdFQ_1770823545 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Stefan Weil , "Dr. David Alan Gilbert" , Pierrick Bouvier , devel@lists.libvirt.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, qemu-rust@nongnu.org, Paolo Bonzini , Markus Armbruster , Gerd Hoffmann , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Christian Schoenebeck , Richard Henderson Subject: [PATCH v6 05/27] system: unconditionally enable thread naming Date: Wed, 11 Feb 2026 15:24:46 +0000 Message-ID: <20260211152508.732487-6-berrange@redhat.com> In-Reply-To: <20260211152508.732487-1-berrange@redhat.com> References: <20260211152508.732487-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1770823616617154100 When thread naming was introduced years ago, it was disabled by default and put behind a command line flag: commit 8f480de0c91a18d550721f8d9af969ebfbda0793 Author: Dr. David Alan Gilbert Date: Thu Jan 30 10:20:31 2014 +0000 Add 'debug-threads' suboption to --name This was done based on a concern that something might depend on the historical thread naming. Thread names, however, were never promised to be part of QEMU's public API. The defaults will vary across platforms, so no assumptions should ever be made about naming. An opt-in behaviour is also unfortunately incompatible with RCU which creates its thread from an constructor function which is run before command line args are parsed. Thus the RCU thread lacks any name. libvirt has unconditionally enabled debug-threads=3Dyes on all VMs it creates for 10 years. Interestingly this DID expose a bug in libvirt, as it parsed /proc/$PID/stat and could not cope with a space in the thread name. This was a latent pre-existing bug in libvirt though, and not a part of QEMU's API. Having thread names always available, will allow thread names to be included in error reports and log messags QEMU prints by default, which will improve ability to triage QEMU bugs. Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Richard Henderson Reviewed-by: Markus Armbruster Signed-off-by: Daniel P. Berrang=C3=A9 --- docs/about/deprecated.rst | 7 +++++++ include/qemu/thread.h | 1 - system/vl.c | 12 +++++++----- util/qemu-thread-posix.c | 18 +----------------- util/qemu-thread-win32.c | 27 ++++++--------------------- 5 files changed, 21 insertions(+), 44 deletions(-) diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst index 1d5c4f3707..568a48f21c 100644 --- a/docs/about/deprecated.rst +++ b/docs/about/deprecated.rst @@ -54,6 +54,13 @@ as short-form boolean values, and passed to plugins as `= `arg_name=3Don``. However, short-form booleans are deprecated and full explicit ``arg_name= =3Don`` form is preferred. =20 +``debug-threads`` option for ``-name`` (since 11.0) +''''''''''''''''''''''''''''''''''''''''''''''''''' + +The ``debug-threads`` option of the ``-name`` argument is now +ignored. Thread naming is unconditionally enabled for all platforms +where it is supported. + QEMU Machine Protocol (QMP) commands ------------------------------------ =20 diff --git a/include/qemu/thread.h b/include/qemu/thread.h index f0302ed01f..3a286bb3ef 100644 --- a/include/qemu/thread.h +++ b/include/qemu/thread.h @@ -215,7 +215,6 @@ void *qemu_thread_join(QemuThread *thread); void qemu_thread_get_self(QemuThread *thread); bool qemu_thread_is_self(QemuThread *thread); G_NORETURN void qemu_thread_exit(void *retval); -void qemu_thread_naming(bool enable); =20 struct Notifier; /** diff --git a/system/vl.c b/system/vl.c index aa9a155041..d8676b3adf 100644 --- a/system/vl.c +++ b/system/vl.c @@ -403,9 +403,8 @@ static QemuOptsList qemu_name_opts =3D { }, { .name =3D "debug-threads", .type =3D QEMU_OPT_BOOL, - .help =3D "When enabled, name the individual threads; defaults= off.\n" - "NOTE: The thread names are for debugging and not a\n" - "stable API.", + .help =3D "Enable thread names" + "(deprecated, always enabled where supported)", }, { /* End of list */ } }, @@ -554,9 +553,12 @@ static int parse_name(void *opaque, QemuOpts *opts, Er= ror **errp) { const char *proc_name; =20 - if (qemu_opt_get(opts, "debug-threads")) { - qemu_thread_naming(qemu_opt_get_bool(opts, "debug-threads", false)= ); + if (qemu_opt_get(opts, "debug-threads") && + !qemu_opt_get_bool(opts, "debug-threads", false)) { + fprintf(stderr, "Ignoring deprecated 'debug-threads=3Dno' option, = " \ + "thread naming is unconditionally enabled\n"); } + qemu_name =3D qemu_opt_get(opts, "guest"); =20 proc_name =3D qemu_opt_get(opts, "process"); diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c index ba725444ba..7c985b5d38 100644 --- a/util/qemu-thread-posix.c +++ b/util/qemu-thread-posix.c @@ -22,22 +22,6 @@ #include #endif =20 -static bool name_threads; - -void qemu_thread_naming(bool enable) -{ - name_threads =3D enable; - -#if !defined CONFIG_PTHREAD_SETNAME_NP_W_TID && \ - !defined CONFIG_PTHREAD_SETNAME_NP_WO_TID && \ - !defined CONFIG_PTHREAD_SET_NAME_NP - /* This is a debugging option, not fatal */ - if (enable) { - fprintf(stderr, "qemu: thread naming not supported on this host\n"= ); - } -#endif -} - static void error_exit(int err, const char *msg) { fprintf(stderr, "qemu: %s: %s\n", msg, strerror(err)); @@ -361,7 +345,7 @@ static void *qemu_thread_start(void *args) /* Attempt to set the threads name; note that this is for debug, so * we're not going to fail if we can't set it. */ - if (name_threads && qemu_thread_args->name) { + if (qemu_thread_args->name) { # if defined(CONFIG_PTHREAD_SETNAME_NP_W_TID) pthread_setname_np(pthread_self(), qemu_thread_args->name); # elif defined(CONFIG_PTHREAD_SETNAME_NP_WO_TID) diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c index ca2e0b512e..9595a5b090 100644 --- a/util/qemu-thread-win32.c +++ b/util/qemu-thread-win32.c @@ -17,8 +17,6 @@ #include "qemu-thread-common.h" #include =20 -static bool name_threads; - typedef HRESULT (WINAPI *pSetThreadDescription) (HANDLE hThread, PCWSTR lpThreadDescriptio= n); static pSetThreadDescription SetThreadDescriptionFunc; @@ -44,16 +42,6 @@ static bool load_set_thread_description(void) return !!SetThreadDescriptionFunc; } =20 -void qemu_thread_naming(bool enable) -{ - name_threads =3D enable; - - if (enable && !load_set_thread_description()) { - fprintf(stderr, "qemu: thread naming not supported on this host\n"= ); - name_threads =3D false; - } -} - static void error_exit(int err, const char *msg) { char *pstr; @@ -328,23 +316,20 @@ void *qemu_thread_join(QemuThread *thread) return ret; } =20 -static bool set_thread_description(HANDLE h, const char *name) +static void set_thread_description(HANDLE h, const char *name) { - HRESULT hr; g_autofree wchar_t *namew =3D NULL; =20 if (!load_set_thread_description()) { - return false; + return; } =20 namew =3D g_utf8_to_utf16(name, -1, NULL, NULL, NULL); if (!namew) { - return false; + return; } =20 - hr =3D SetThreadDescriptionFunc(h, namew); - - return SUCCEEDED(hr); + SetThreadDescriptionFunc(h, namew); } =20 void qemu_thread_create(QemuThread *thread, const char *name, @@ -370,8 +355,8 @@ void qemu_thread_create(QemuThread *thread, const char = *name, if (!hThread) { error_exit(GetLastError(), __func__); } - if (name_threads && name && !set_thread_description(hThread, name)) { - fprintf(stderr, "qemu: failed to set thread description: %s\n", na= me); + if (name) { + set_thread_description(hThread, name); } CloseHandle(hThread); =20 --=20 2.53.0 From nobody Thu Feb 12 11:50:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1770823666; cv=none; d=zohomail.com; s=zohoarc; b=FEvtNIkpnyCew8wR4zt5yWYxIkqOk++3r5uo95ujb/+BfE0X+hPf2KycroHx93+Xw7vP7ILC/IepyD4ZvtEIfVaa9nG/9OfFQntkQR4Pq1ttaYL/y4zeXrOvbXcxitmJDjjfcU9F1iKrLA4SRQcjb7dN5QVVVmn78P5p5kC6Dcw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770823666; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=9ZUN9qo2kVOayeNkrm7meCbsEZa6wbphY9wEaykh81U=; b=FSf7WVA/XyxjGC/BJ/16ZUaY0FQlR+/o0UCdq0BvXxaALnF1x5iFllMZU5sLZfwsB1mA8shCLIuekyr/PdDCq5I7Pr9JjMLjL5S3+6nkDQgzZroQlKk+aX8Bykn94/FgPTXq1RY26V3+P0pd7zVtKory3onpbMTR+mlxI4kOn8Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770823666400603.1010943443275; Wed, 11 Feb 2026 07:27:46 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqC6P-0004sx-D2; Wed, 11 Feb 2026 10:26:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC6K-0004oZ-Rk for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:26:00 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC6J-0005ml-7u for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:26:00 -0500 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-317-vxqbIMosMR-SGpEGceCnzg-1; Wed, 11 Feb 2026 10:25:55 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6619C19560B2; Wed, 11 Feb 2026 15:25:51 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.227.9]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0057530001A8; Wed, 11 Feb 2026 15:25:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770823558; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9ZUN9qo2kVOayeNkrm7meCbsEZa6wbphY9wEaykh81U=; b=dU2vegMag2FHfFtpZHPLHSwUIURyjp02ifxq6SEPg+qEE6MRXCl63fMkkmSqP7QX9XVbn1 f/itRNbxblxP2EfaneAB7cQYoQootySF/ezxnT3JpZQ2xYNEtbbZ4RJQ7ogkUlp/bjrOtn gn2Vem33OMqw2Qe2eDMYDK6APuAE5FM= X-MC-Unique: vxqbIMosMR-SGpEGceCnzg-1 X-Mimecast-MFC-AGG-ID: vxqbIMosMR-SGpEGceCnzg_1770823551 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Stefan Weil , "Dr. David Alan Gilbert" , Pierrick Bouvier , devel@lists.libvirt.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, qemu-rust@nongnu.org, Paolo Bonzini , Markus Armbruster , Gerd Hoffmann , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Christian Schoenebeck , Richard Henderson Subject: [PATCH v6 06/27] util: fix race setting thread name on Win32 Date: Wed, 11 Feb 2026 15:24:47 +0000 Message-ID: <20260211152508.732487-7-berrange@redhat.com> In-Reply-To: <20260211152508.732487-1-berrange@redhat.com> References: <20260211152508.732487-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1770823669278154100 The call to set the thread name on Win32 platforms is done by the parent thread, after _beginthreadex() returns. At this point the new child thread is potentially already executing its start method. To ensure the thread name is guaranteed to be set before any "interesting" code starts executing, it must be done in the start method of the child thread itself. Reviewed-by: Richard Henderson Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Markus Armbruster Signed-off-by: Daniel P. Berrang=C3=A9 --- util/qemu-thread-win32.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c index 9595a5b090..255c88571f 100644 --- a/util/qemu-thread-win32.c +++ b/util/qemu-thread-win32.c @@ -22,6 +22,8 @@ typedef HRESULT (WINAPI *pSetThreadDescription) (HANDLE h= Thread, static pSetThreadDescription SetThreadDescriptionFunc; static HMODULE kernel32_module; =20 +static void set_thread_description(const char *name); + static bool load_set_thread_description(void) { static gsize _init_once =3D 0; @@ -225,6 +227,7 @@ struct QemuThreadData { void *arg; short mode; NotifierList exit; + char *name; /* Freed in win32_start_routine */ =20 /* Only used for joinable threads. */ bool exited; @@ -266,6 +269,10 @@ static unsigned __stdcall win32_start_routine(void *ar= g) void *(*start_routine)(void *) =3D data->start_routine; void *thread_arg =3D data->arg; =20 + if (data->name) { + set_thread_description(data->name); + g_clear_pointer(&data->name, g_free); + } qemu_thread_data =3D data; qemu_thread_exit(start_routine(thread_arg)); abort(); @@ -316,7 +323,7 @@ void *qemu_thread_join(QemuThread *thread) return ret; } =20 -static void set_thread_description(HANDLE h, const char *name) +static void set_thread_description(const char *name) { g_autofree wchar_t *namew =3D NULL; =20 @@ -329,7 +336,7 @@ static void set_thread_description(HANDLE h, const char= *name) return; } =20 - SetThreadDescriptionFunc(h, namew); + SetThreadDescriptionFunc(GetCurrentThread(), namew); } =20 void qemu_thread_create(QemuThread *thread, const char *name, @@ -344,6 +351,7 @@ void qemu_thread_create(QemuThread *thread, const char = *name, data->arg =3D arg; data->mode =3D mode; data->exited =3D false; + data->name =3D g_strdup(name); notifier_list_init(&data->exit); =20 if (data->mode !=3D QEMU_THREAD_DETACHED) { @@ -355,9 +363,6 @@ void qemu_thread_create(QemuThread *thread, const char = *name, if (!hThread) { error_exit(GetLastError(), __func__); } - if (name) { - set_thread_description(hThread, name); - } CloseHandle(hThread); =20 thread->data =3D data; --=20 2.53.0 From nobody Thu Feb 12 11:50:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1770823574; cv=none; d=zohomail.com; s=zohoarc; b=B8CLfZykiN4zRY2Yr8XAta5eTPbOWMu4HJnUsE+VitWOMMmKzHvWt6q7ByTUWlIli+3nlXtI8B2u5zkA7O0VqK5r4NS8bKX/d7xL/f7eXwz9VWVKIzGQYIiHOzzFWBp/+jZJ6qa3+FCF9KN0KGQWg6YxNEZiaCke9aWkRm5vGnw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770823574; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=eCtbl4tBYedLw5VjumdC/3noLHo9zL17FOSsYm0GecI=; b=m3qcKnGJLaj1YJO9b98KRiYwPu2IdXOuVlVrmwKbBv5Nh+TJPAZX46EKkBaoYaR1/+IccVGLK8x4XuiiimUD5DMW9AuXI5u5wBJn5HKXZi4vUCA1JlzYq00h8KSxUWGOZ6Mk0xxplc9+2y7SmnZ3apR5POg4jhGkmtqXgmEdvPo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770823574297132.38973226109192; Wed, 11 Feb 2026 07:26:14 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqC6P-0004t8-FX; Wed, 11 Feb 2026 10:26:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC6M-0004qp-Nb for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:26:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC6L-0005nJ-3l for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:26:02 -0500 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-372-d9x-ZiElN9Oad3NURlkNtA-1; Wed, 11 Feb 2026 10:25:58 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 099A91955F28; Wed, 11 Feb 2026 15:25:57 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.227.9]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D510C30002D8; Wed, 11 Feb 2026 15:25:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770823560; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eCtbl4tBYedLw5VjumdC/3noLHo9zL17FOSsYm0GecI=; b=IgBBWFhxkPGVepW3ZqIX72AkxIyT4yjKWTL7Wuc9YMqaZBoimJK+bpjFR0P62TlejCjQZv Jzi4ajSI3Pnwaxr1IV0RQaqkrXWGNAx5RGmEEotNlA8P7WqBexqvtZu0dtWk1Kb3J4wFlU Amf7sYmlX7WMiRO5iBlOWfZN27pgJP4= X-MC-Unique: d9x-ZiElN9Oad3NURlkNtA-1 X-Mimecast-MFC-AGG-ID: d9x-ZiElN9Oad3NURlkNtA_1770823557 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Stefan Weil , "Dr. David Alan Gilbert" , Pierrick Bouvier , devel@lists.libvirt.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, qemu-rust@nongnu.org, Paolo Bonzini , Markus Armbruster , Gerd Hoffmann , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Christian Schoenebeck , Richard Henderson Subject: [PATCH v6 07/27] util: expose qemu_thread_set_name Date: Wed, 11 Feb 2026 15:24:48 +0000 Message-ID: <20260211152508.732487-8-berrange@redhat.com> In-Reply-To: <20260211152508.732487-1-berrange@redhat.com> References: <20260211152508.732487-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1770823575723158500 The ability to set the thread name needs to be used in a number of places, so expose the current impls as public methods. Reviewed-by: Richard Henderson Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Markus Armbruster Signed-off-by: Daniel P. Berrang=C3=A9 --- include/qemu/thread.h | 1 + util/qemu-thread-posix.c | 26 ++++++++++++++++---------- util/qemu-thread-win32.c | 6 ++---- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/include/qemu/thread.h b/include/qemu/thread.h index 3a286bb3ef..27b888ab0a 100644 --- a/include/qemu/thread.h +++ b/include/qemu/thread.h @@ -215,6 +215,7 @@ void *qemu_thread_join(QemuThread *thread); void qemu_thread_get_self(QemuThread *thread); bool qemu_thread_is_self(QemuThread *thread); G_NORETURN void qemu_thread_exit(void *retval); +void qemu_thread_set_name(const char *name); =20 struct Notifier; /** diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c index 7c985b5d38..b1c127dbe3 100644 --- a/util/qemu-thread-posix.c +++ b/util/qemu-thread-posix.c @@ -329,6 +329,21 @@ static void qemu_thread_atexit_notify(void *arg) notifier_list_notify(&thread_exit, NULL); } =20 +void qemu_thread_set_name(const char *name) +{ + /* + * Attempt to set the threads name; note that this is for debug, so + * we're not going to fail if we can't set it. + */ +# if defined(CONFIG_PTHREAD_SETNAME_NP_W_TID) + pthread_setname_np(pthread_self(), name); +# elif defined(CONFIG_PTHREAD_SETNAME_NP_WO_TID) + pthread_setname_np(name); +# elif defined(CONFIG_PTHREAD_SET_NAME_NP) + pthread_set_name_np(pthread_self(), name); +# endif +} + typedef struct { void *(*start_routine)(void *); void *arg; @@ -342,17 +357,8 @@ static void *qemu_thread_start(void *args) void *arg =3D qemu_thread_args->arg; void *r; =20 - /* Attempt to set the threads name; note that this is for debug, so - * we're not going to fail if we can't set it. - */ if (qemu_thread_args->name) { -# if defined(CONFIG_PTHREAD_SETNAME_NP_W_TID) - pthread_setname_np(pthread_self(), qemu_thread_args->name); -# elif defined(CONFIG_PTHREAD_SETNAME_NP_WO_TID) - pthread_setname_np(qemu_thread_args->name); -# elif defined(CONFIG_PTHREAD_SET_NAME_NP) - pthread_set_name_np(pthread_self(), qemu_thread_args->name); -# endif + qemu_thread_set_name(qemu_thread_args->name); } QEMU_TSAN_ANNOTATE_THREAD_NAME(qemu_thread_args->name); g_free(qemu_thread_args->name); diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c index 255c88571f..31ec305a73 100644 --- a/util/qemu-thread-win32.c +++ b/util/qemu-thread-win32.c @@ -22,8 +22,6 @@ typedef HRESULT (WINAPI *pSetThreadDescription) (HANDLE h= Thread, static pSetThreadDescription SetThreadDescriptionFunc; static HMODULE kernel32_module; =20 -static void set_thread_description(const char *name); - static bool load_set_thread_description(void) { static gsize _init_once =3D 0; @@ -270,7 +268,7 @@ static unsigned __stdcall win32_start_routine(void *arg) void *thread_arg =3D data->arg; =20 if (data->name) { - set_thread_description(data->name); + qemu_thread_set_name(data->name); g_clear_pointer(&data->name, g_free); } qemu_thread_data =3D data; @@ -323,7 +321,7 @@ void *qemu_thread_join(QemuThread *thread) return ret; } =20 -static void set_thread_description(const char *name) +void qemu_thread_set_name(const char *name) { g_autofree wchar_t *namew =3D NULL; =20 --=20 2.53.0 From nobody Thu Feb 12 11:50:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1770823580; cv=none; d=zohomail.com; s=zohoarc; b=aGM3Nsf7Jrpb2yzlRnVVEjhaoNoSuZB2+FNP/spOAWfTu/gbpeGxeVJL8zNC3jCEjazy+5kvEJJupCfjJmEnfAKpWDkTjcnS+On4gSy2Dgb2XXtFOEz1XKHS2pmNRuk75PqfAHqXy8fDCjvmSyMbXdFCe/iUSs4DrANrXSoe0lA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770823580; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=nOCgj2qlPW9NgK8ySiK5skBFki+9TAoJVM1DGWNRx24=; b=lefh3JYyEPUYZJqvjOr0VPa9ta+kKF9MSMG9Rcn4KvX6W4veKZXjJkYJd36W93bF4l6I3FSU8e7OZLrvgvOVIMyO2fjB6iIhTQah40iI4ZC1emZbHtMuyXuV4p3N4XqtQjaupXakgd55m98rnmodN+xlP6bfO1lgPivVhpxv3YU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770823580666518.6713720053706; Wed, 11 Feb 2026 07:26:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqC6U-0004x5-Er; Wed, 11 Feb 2026 10:26:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC6T-0004wE-JX for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:26:09 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC6S-0005ov-83 for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:26:09 -0500 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-569-cgDM5_7OOMqPwZRsqY2v3A-1; Wed, 11 Feb 2026 10:26:04 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4AC6319560A7; Wed, 11 Feb 2026 15:26:02 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.227.9]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 79342300DDA3; Wed, 11 Feb 2026 15:25:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770823567; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nOCgj2qlPW9NgK8ySiK5skBFki+9TAoJVM1DGWNRx24=; b=Be2jmPamfSB+wr/u3yZn8EZ62nPhrRIfjoHLgCahshZl+p3cJ+lB09434yQNnE0HTF71X2 3W0ZyYgJj0KOwkiYw6rM61KSavaF3aL1qWnwipraYirUYnjPqAmEzCg8Ty4OvxHcRCU/2h pAEmZASTFpgEpDKN+W83SEgkDhSnlTo= X-MC-Unique: cgDM5_7OOMqPwZRsqY2v3A-1 X-Mimecast-MFC-AGG-ID: cgDM5_7OOMqPwZRsqY2v3A_1770823562 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Stefan Weil , "Dr. David Alan Gilbert" , Pierrick Bouvier , devel@lists.libvirt.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, qemu-rust@nongnu.org, Paolo Bonzini , Markus Armbruster , Gerd Hoffmann , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Christian Schoenebeck , Richard Henderson Subject: [PATCH v6 08/27] audio: make jackaudio use qemu_thread_set_name Date: Wed, 11 Feb 2026 15:24:49 +0000 Message-ID: <20260211152508.732487-9-berrange@redhat.com> In-Reply-To: <20260211152508.732487-1-berrange@redhat.com> References: <20260211152508.732487-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1770823581629158500 This has greater portability than directly call pthread_setname_np, which is only 1 out of 3 possible functions for pthreads that can set the name. The new API requires a trampoline function, since it can only set the name of the current thread. Reviewed-by: Christian Schoenebeck Signed-off-by: Daniel P. Berrang=C3=A9 --- audio/jackaudio.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/audio/jackaudio.c b/audio/jackaudio.c index 7a3fcaedba..c47a1a3781 100644 --- a/audio/jackaudio.c +++ b/audio/jackaudio.c @@ -629,18 +629,36 @@ static void qjack_enable_in(HWVoiceIn *hw, bool enabl= e) ji->c.enabled =3D enable; } =20 -#if !defined(WIN32) && defined(CONFIG_PTHREAD_SETNAME_NP_W_TID) +#if !defined(WIN32) +struct QJackThreadData { + void *(*function)(void *); + void *arg; +}; + +static void *qjack_thread_trampoline(void *targ) +{ + struct QJackThreadData *data =3D targ; + void *(*function)(void *) =3D data->function; + void *arg =3D data->arg; + + g_free(data); + qemu_thread_set_name("jack-client"); + + return function(arg); +} + static int qjack_thread_creator(jack_native_thread_t *thread, const pthread_attr_t *attr, void *(*function)(void *), void *arg) { - int ret =3D pthread_create(thread, attr, function, arg); + struct QJackThreadData *data =3D g_new0(struct QJackThreadData, 1); + data->function =3D function; + data->arg =3D arg; + int ret =3D pthread_create(thread, attr, qjack_thread_trampoline, data= ); if (ret !=3D 0) { + g_free(data); return ret; } =20 - /* set the name of the thread */ - pthread_setname_np(*thread, "jack-client"); - return ret; } #endif @@ -695,7 +713,7 @@ static void register_audio_jack(void) { qemu_mutex_init(&qjack_shutdown_lock); audio_driver_register(&jack_driver); -#if !defined(WIN32) && defined(CONFIG_PTHREAD_SETNAME_NP_W_TID) +#if !defined(WIN32) jack_set_thread_creator(qjack_thread_creator); #endif jack_set_error_function(qjack_error); --=20 2.53.0 From nobody Thu Feb 12 11:50:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1770823655; cv=none; d=zohomail.com; s=zohoarc; b=OkXd4x/jZ6rlYCDRnnzhuniShB59D0F+O1OkJ1jsQnuwl6SzqLyfmmYbJWZmzS4MNUve8yBo1v8R+hWGiUz34IstxZyZtMSVQXEpTYS8na2+R+47IXGXqvJGVwvzSixSnTZWisxiunqnWv4Rmp5gdLJR7wW7grM8hklMTsAItKo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770823655; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=IfI+E107HltjtYIZjk/qNK2uCDaVFBnkV/Ebpeb28yk=; b=WLTwlMI5up3jzAwDlAW0m/F6e0HOXp4yWeTIkHFhDIH5Wfr8MOd9psCny00H7A+MSB0V5DuwvoXO++O56gDW7iodEFDA4ygIlRWTcoT+q84gB+EHT0zEUF92l7MHHDQgN0dV8kPauPoKzrtCziXvDMItGpSWgnYj/H5KfgrqA5Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770823655282703.9809521675908; Wed, 11 Feb 2026 07:27:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqC6i-0006Jr-HI; Wed, 11 Feb 2026 10:26:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC6g-00067a-UI for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:26:22 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC6f-0005rm-Dc for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:26:22 -0500 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-607-xJcJMMbmOKuDJ8XpTGhgqA-1; Wed, 11 Feb 2026 10:26:10 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F2DD31956050; Wed, 11 Feb 2026 15:26:07 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.227.9]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BAF7D30001A8; Wed, 11 Feb 2026 15:26:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770823580; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IfI+E107HltjtYIZjk/qNK2uCDaVFBnkV/Ebpeb28yk=; b=GGKDlRd9Z5ko6bjBgJ1e4Cv+0gcjyPQLuiSMxIN4PXtWd5nvPxBfFgaI54oBNjAS8t37Yx qZpMrEkilDRJLZZjiSbNrMfboJ/f9/X0YHYil18kyRNUwG7gsOmLPzyGzLmmBrmu0kZxLq wjg0a4AGF6J1PIHzBfXP76h/V1G6CdM= X-MC-Unique: xJcJMMbmOKuDJ8XpTGhgqA-1 X-Mimecast-MFC-AGG-ID: xJcJMMbmOKuDJ8XpTGhgqA_1770823568 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Stefan Weil , "Dr. David Alan Gilbert" , Pierrick Bouvier , devel@lists.libvirt.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, qemu-rust@nongnu.org, Paolo Bonzini , Markus Armbruster , Gerd Hoffmann , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Christian Schoenebeck , Richard Henderson Subject: [PATCH v6 09/27] util: set the name for the 'main' thread on Windows Date: Wed, 11 Feb 2026 15:24:50 +0000 Message-ID: <20260211152508.732487-10-berrange@redhat.com> In-Reply-To: <20260211152508.732487-1-berrange@redhat.com> References: <20260211152508.732487-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1770823655769158500 The default main thread name is undefined, so use a constructor to explicitly set it to 'main'. This constructor is marked to run early as the thread name is intended to be used in error reporting / logs which may be triggered very early in QEMU execution. This is only done on Windows platforms, because on Linux (and possibly other POSIX) changing the main thread name has a side effect of changing the process name reported by tools like 'ps' which fetch from the file /proc/self/task/tid/comm, expecting it to be the binary name. The following patch will address POSIX platforms in a different way. Reviewed-by: Richard Henderson Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Daniel P. Berrang=C3=A9 --- util/qemu-thread-win32.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c index 31ec305a73..c330d924af 100644 --- a/util/qemu-thread-win32.c +++ b/util/qemu-thread-win32.c @@ -22,6 +22,12 @@ typedef HRESULT (WINAPI *pSetThreadDescription) (HANDLE = hThread, static pSetThreadDescription SetThreadDescriptionFunc; static HMODULE kernel32_module; =20 +static void __attribute__((__constructor__(QEMU_CONSTRUCTOR_EARLY))) +qemu_thread_init(void) +{ + qemu_thread_set_name("main"); +} + static bool load_set_thread_description(void) { static gsize _init_once =3D 0; --=20 2.53.0 From nobody Thu Feb 12 11:50:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1770823718; cv=none; d=zohomail.com; s=zohoarc; b=J6thzuTidL1xFQFs75GCksar/a7fZSYuKKTEQSlYRzSdg6H6/y3TDDTD3WyZTOda6Y/5IiGYhhi7UogV8jhuZV5k/5cZh9aCdHqH3GYs0fl9AbQ43Tc/IS6FZ9NOOn/Lo4YRGUAGjXdF3UUWfzoZsz4v97wBQZUjfJm7Z7kXle4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770823718; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=U4ooj0qoTlbTdZFthN2E2JErDMdhjQ9nsu3y5uVtROg=; b=DmKEMt3CRNF0WPW7qPGcAN6gRX0JMvs5crsClh6cjbuTTbh3a4A/byQlSm8qhMcuozOfVqebD23XRsNayM519MTLYgDb/Q00afF3iKzeyZrK4GtrChsD3cKZLTDTB/siP1FDViMBGBUn/B44M/MJ5dsqg6SFky5OTzd1L0Vuf4E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770823718006502.14668074677854; Wed, 11 Feb 2026 07:28:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqC6l-0006VF-NV; Wed, 11 Feb 2026 10:26:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC6j-0006Qj-IK for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:26:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC6g-0005s3-7z for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:26:25 -0500 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-161-1secoa4ANraGNLIINQv5Dg-1; Wed, 11 Feb 2026 10:26:16 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8294B180025F; Wed, 11 Feb 2026 15:26:13 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.227.9]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6DD2A30001A8; Wed, 11 Feb 2026 15:26:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770823581; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U4ooj0qoTlbTdZFthN2E2JErDMdhjQ9nsu3y5uVtROg=; b=UnJtGZJqdqN6iqugxXJkUgFczO9VE0a1OWlD9OfpfLI8FUOcfj/ckRamUpta21KmBEhsNn sTUSA7GTI/c/C5HaerSL6tvQomNOz+mG2YBOilEfSXvMroivD3A+rSIBdlMlQdbUGqtWX2 mxkYHGTd3hpC1kuYC5IUh8FNuZ1VBGY= X-MC-Unique: 1secoa4ANraGNLIINQv5Dg-1 X-Mimecast-MFC-AGG-ID: 1secoa4ANraGNLIINQv5Dg_1770823573 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Stefan Weil , "Dr. David Alan Gilbert" , Pierrick Bouvier , devel@lists.libvirt.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, qemu-rust@nongnu.org, Paolo Bonzini , Markus Armbruster , Gerd Hoffmann , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Christian Schoenebeck , Richard Henderson Subject: [PATCH v6 10/27] util: add API to fetch the current thread name Date: Wed, 11 Feb 2026 15:24:51 +0000 Message-ID: <20260211152508.732487-11-berrange@redhat.com> In-Reply-To: <20260211152508.732487-1-berrange@redhat.com> References: <20260211152508.732487-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1770823721862154100 This will be used to include the thread name in error reports in a later patch. It returns a const string stored in a thread local to avoid memory allocation when it is called repeatedly in a single thread. The thread name should be set at the very start of the thread execution, which is the case when using qemu_thread_create. This uses the official thread APIs for fetching thread names, so that it captures names of threads spawned by code in 3rd party libraries, not merely QEMU spawned thrads. This also addresses the gap from the previous patch for setting the name of the main thread. A constructor is used to initialize the 'namebuf' thread-local in the main thread only. Signed-off-by: Daniel P. Berrang=C3=A9 --- include/qemu/thread.h | 1 + meson.build | 21 ++++++++++++++++ util/qemu-thread-posix.c | 53 +++++++++++++++++++++++++++++++++++++++- util/qemu-thread-win32.c | 49 ++++++++++++++++++++++++++++++++++--- 4 files changed, 119 insertions(+), 5 deletions(-) diff --git a/include/qemu/thread.h b/include/qemu/thread.h index 27b888ab0a..98cc5c41ac 100644 --- a/include/qemu/thread.h +++ b/include/qemu/thread.h @@ -216,6 +216,7 @@ void qemu_thread_get_self(QemuThread *thread); bool qemu_thread_is_self(QemuThread *thread); G_NORETURN void qemu_thread_exit(void *retval); void qemu_thread_set_name(const char *name); +const char *qemu_thread_get_name(void); =20 struct Notifier; /** diff --git a/meson.build b/meson.build index 9ad16d1998..710aa2ed83 100644 --- a/meson.build +++ b/meson.build @@ -2845,6 +2845,27 @@ config_host_data.set('CONFIG_PTHREAD_SET_NAME_NP', c= c.links(osdep_prefix + ''' pthread_set_name_np(thread, "QEMU"); return 0; }''', dependencies: threads)) + +config_host_data.set('CONFIG_PTHREAD_GETNAME_NP', cc.links(osdep_prefix + = ''' + #include + + int main(void) + { + char buf[16]; + pthread_getname_np(pthread_self(), buf, sizeof(buf)); + return 0; + }''', dependencies: threads)) +config_host_data.set('CONFIG_PTHREAD_GET_NAME_NP', cc.links(osdep_prefix += ''' + #include + #include + + int main(void) + { + char buf[16]; + pthread_get_name_np(pthread_self(), buf, sizeof(buf)); + return 0; + }''', dependencies: threads)) + config_host_data.set('CONFIG_PTHREAD_CONDATTR_SETCLOCK', cc.links(osdep_pr= efix + ''' #include =20 diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c index b1c127dbe3..2b180d99ae 100644 --- a/util/qemu-thread-posix.c +++ b/util/qemu-thread-posix.c @@ -18,10 +18,41 @@ #include "qemu/tsan.h" #include "qemu/bitmap.h" =20 -#ifdef CONFIG_PTHREAD_SET_NAME_NP +#if defined(CONFIG_PTHREAD_SET_NAME_NP) || defined(CONFIG_PTHREAD_GET_NAME= _NP) #include #endif =20 +/* + * This is not defined on Linux, but the man page indicates + * the buffer must be at least 16 bytes, including the NUL + * terminator + */ +#ifndef PTHREAD_MAX_NAMELEN_NP +#define PTHREAD_MAX_NAMELEN_NP 16 +#endif + +static __thread char namebuf[PTHREAD_MAX_NAMELEN_NP]; + +static void __attribute__((__constructor__(QEMU_CONSTRUCTOR_EARLY))) +qemu_thread_init(void) +{ + /* + * Initialize the main thread name. We must not use + * qemu_thread_setname(), since on some platforms (at least Linux) + * this can change the process name that is reported by tools like + * 'ps'. + * + * This workaround suffices to ensure QEMU log/error messages + * get the main thread name, but at the cost of external tools + * like GDB not seeing it. + * + * NB using a constructor instead of static initializing namebuf, + * to ensure it only initializes the thread-local in the main + * thread + */ + g_strlcpy(namebuf, "main", sizeof(namebuf)); +} + static void error_exit(int err, const char *msg) { fprintf(stderr, "qemu: %s: %s\n", msg, strerror(err)); @@ -526,3 +557,23 @@ void *qemu_thread_join(QemuThread *thread) } return ret; } + +const char *qemu_thread_get_name(void) +{ + int rv; + if (namebuf[0] !=3D '\0') { + return namebuf; + } + +# if defined(CONFIG_PTHREAD_GETNAME_NP) + rv =3D pthread_getname_np(pthread_self(), namebuf, sizeof(namebuf)); +# elif defined(CONFIG_PTHREAD_GET_NAME_NP) + rv =3D pthread_get_name_np(pthread_self(), namebuf, sizeof(namebuf)); +# else + rv =3D -1; +# endif + if (rv !=3D 0) { + g_strlcpy(namebuf, "unnamed", G_N_ELEMENTS(namebuf)); + } + return namebuf; +} diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c index c330d924af..272afc3385 100644 --- a/util/qemu-thread-win32.c +++ b/util/qemu-thread-win32.c @@ -19,7 +19,10 @@ =20 typedef HRESULT (WINAPI *pSetThreadDescription) (HANDLE hThread, PCWSTR lpThreadDescriptio= n); +typedef HRESULT (WINAPI *pGetThreadDescription) (HANDLE hThread, + PWSTR *lpThreadDescriptio= n); static pSetThreadDescription SetThreadDescriptionFunc; +static pGetThreadDescription GetThreadDescriptionFunc; static HMODULE kernel32_module; =20 static void __attribute__((__constructor__(QEMU_CONSTRUCTOR_EARLY))) @@ -28,7 +31,7 @@ qemu_thread_init(void) qemu_thread_set_name("main"); } =20 -static bool load_set_thread_description(void) +static bool load_thread_description(void) { static gsize _init_once =3D 0; =20 @@ -38,14 +41,17 @@ static bool load_set_thread_description(void) SetThreadDescriptionFunc =3D (pSetThreadDescription)GetProcAddress(kernel32_module, "SetThreadDescriptio= n"); - if (!SetThreadDescriptionFunc) { + GetThreadDescriptionFunc =3D + (pGetThreadDescription)GetProcAddress(kernel32_module, + "GetThreadDescriptio= n"); + if (!SetThreadDescriptionFunc || !GetThreadDescriptionFunc) { FreeLibrary(kernel32_module); } } g_once_init_leave(&_init_once, 1); } =20 - return !!SetThreadDescriptionFunc; + return (SetThreadDescriptionFunc && GetThreadDescriptionFunc); } =20 static void error_exit(int err, const char *msg) @@ -331,7 +337,7 @@ void qemu_thread_set_name(const char *name) { g_autofree wchar_t *namew =3D NULL; =20 - if (!load_set_thread_description()) { + if (!load_thread_description()) { return; } =20 @@ -415,3 +421,38 @@ bool qemu_thread_is_self(QemuThread *thread) { return GetCurrentThreadId() =3D=3D thread->tid; } + +static __thread char namebuf[64]; + +const char *qemu_thread_get_name(void) +{ + HRESULT hr; + wchar_t *namew =3D NULL; + g_autofree char *name =3D NULL; + + if (namebuf[0] !=3D '\0') { + return namebuf; + } + + if (!load_thread_description()) { + goto error; + } + + hr =3D GetThreadDescriptionFunc(GetCurrentThread(), &namew); + if (!SUCCEEDED(hr)) { + goto error; + } + + name =3D g_utf16_to_utf8(namew, -1, NULL, NULL, NULL); + LocalFree(namew); + if (!name) { + goto error; + } + + g_strlcpy(namebuf, name, G_N_ELEMENTS(namebuf)); + return namebuf; + + error: + g_strlcpy(namebuf, "unnamed", G_N_ELEMENTS(namebuf)); + return namebuf; +} --=20 2.53.0 From nobody Thu Feb 12 11:50:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1770823651; cv=none; d=zohomail.com; s=zohoarc; b=FmwZoqiFSGtMoXkDH9h0kpuSmxvxzwPadKn9yMO7bL86EEs5sjJh45/rUnDiXqB0At9FyI5ZMyRsGhSrCSmMmDny2yKwuvOQG/OJ4VwwFbm/X8DE6hzz0M6GZHmvSMSGna59keXYO49m6jOhLTiP7R7iidFby0Es/k2vHRWIgnQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770823651; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=quFtc628f984Q3yp25Wk6fR4lXqtSsXdbUO1vrf3FKQ=; b=avfCrEoODULVIU+xGbpqia9YmcUw5GCj5HknDJ+YItXDCZNq93+dx2X/5wQoYFy5clbrHov3/FCU7nKpUWEXLU3zSK//SefKHcn/dVANsxYzR+Y8OQxU4X2drrbIniDDXQRZ7UEPcInMEC2il0Vvf+J/XzGQB/kJz79z0nCENAE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770823651571363.20992193167297; Wed, 11 Feb 2026 07:27:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqC6p-0006Z4-45; Wed, 11 Feb 2026 10:26:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC6o-0006WO-9X for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:26:30 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC6m-0005u9-6t for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:26:30 -0500 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-306-FVN3tseiN7q5m3q1l49CNA-1; Wed, 11 Feb 2026 10:26:23 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 814E51955F28; Wed, 11 Feb 2026 15:26:21 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.227.9]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id F3BB930001A8; Wed, 11 Feb 2026 15:26:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770823587; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=quFtc628f984Q3yp25Wk6fR4lXqtSsXdbUO1vrf3FKQ=; b=XGum1ddFipUAH/hYvTHdJweaOPPGUFkBf4H8jZS9gREAgHI2pkosMQ5TowJrYQWluG3591 yx6V73SPi/Q3f+aW9MOjmMG9Mlj3VRsl+ekm14nB1y+UY/GY3qA+0qGhXyICAcMoOTm6JW dR3mVPHHCxiopfwnW/JvUsASRDD9TDw= X-MC-Unique: FVN3tseiN7q5m3q1l49CNA-1 X-Mimecast-MFC-AGG-ID: FVN3tseiN7q5m3q1l49CNA_1770823581 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Stefan Weil , "Dr. David Alan Gilbert" , Pierrick Bouvier , devel@lists.libvirt.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, qemu-rust@nongnu.org, Paolo Bonzini , Markus Armbruster , Gerd Hoffmann , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Christian Schoenebeck , Richard Henderson Subject: [PATCH v6 11/27] util: introduce some API docs for logging APIs Date: Wed, 11 Feb 2026 15:24:52 +0000 Message-ID: <20260211152508.732487-12-berrange@redhat.com> In-Reply-To: <20260211152508.732487-1-berrange@redhat.com> References: <20260211152508.732487-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1770823653915158500 There is a gotcha with qemu_log() usage in a threaded process. If fragments of a log message are output via qemu_log() it is possible for messages from two threads to get mixed up. To prevent this qemu_log_trylock() should be used, along with fprintf(f) calls. This is a subtle problem that needs to be explained in the API docs to ensure correct usage. In the Rust code, the log_mask_ln method which is conceptually equivalent to the C qemu_log() call will unconditionally append a newline so must only ever be used for complete log messages. Reported-by: Markus Armbruster Signed-off-by: Daniel P. Berrang=C3=A9 --- include/qemu/log-for-trace.h | 17 ++++++++++++++++- include/qemu/log.h | 32 ++++++++++++++++++++++++++++++++ rust/util/src/log.rs | 6 ++++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/include/qemu/log-for-trace.h b/include/qemu/log-for-trace.h index f3a8791f1d..6861a1a4b7 100644 --- a/include/qemu/log-for-trace.h +++ b/include/qemu/log-for-trace.h @@ -29,7 +29,22 @@ static inline bool qemu_loglevel_mask(int mask) return (qemu_loglevel & mask) !=3D 0; } =20 -/* main logging function */ +/** + * qemu_log: report a log message + * @fmt: the format string for the message + * @...: the format string arguments + * + * This will emit a log message to the current output stream. + * + * The @fmt string should normally represent a complete line + * of text, and thus end with a newline character. + * + * While it is possible to incrementally output fragments of + * a complete line using qemu_log, this is inefficient and + * races with other threads. For outputting fragments it is + * strongly preferred to use the qemu_log_trylock() method + * combined with fprintf(). + */ void G_GNUC_PRINTF(1, 2) qemu_log(const char *fmt, ...); =20 #endif diff --git a/include/qemu/log.h b/include/qemu/log.h index 7effba4da4..b49a1a5fe3 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -41,7 +41,39 @@ bool qemu_log_separate(void); =20 /* Lock/unlock output. */ =20 +/** + * Acquires a lock on the current log output stream. + * The returned FILE object should be used with the + * fprintf() function to output the log message, and + * then qemu_log_unlock() called to release the lock. + * + * The primary use case is to be able to incrementally + * output fragments of a complete log message in an + * efficient and race free manner. + * + * The simpler qemu_log() method should normally only + * be used to output complete log messages, and not + * within scope of a qemu_log_trylock() call. + * + * A typical usage pattern would be + * + * FILE *f =3D qemu_log_trylock() + * + * fprintf(f, "Something "); + * fprintf(f, "Something "); + * fprintf(f, "Something "); + * fprintf(f, "The end\n"); + * + * qemu_log_unlock(f); + * + * Returns: the current FILE if available, NULL on error + */ FILE *qemu_log_trylock(void) G_GNUC_WARN_UNUSED_RESULT; + +/** + * Releases the lock on the log output, previously + * acquired by qemu_log_trylock(). + */ void qemu_log_unlock(FILE *fd); =20 /* Logging functions: */ diff --git a/rust/util/src/log.rs b/rust/util/src/log.rs index 0a4bc4249a..a85db804a7 100644 --- a/rust/util/src/log.rs +++ b/rust/util/src/log.rs @@ -134,6 +134,12 @@ fn drop(&mut self) { /// "Address 0x{:x} out of range", /// error_address, /// ); +/// +/// The `log_mask_ln` macro must only be used for emitting complete +/// log messages. Where it is required to incrementally output string +/// fragments to construct a complete message, `LogGuard::new()` must +/// be directly used in combination with `writeln()` to avoid output +/// races with other QEMU threads. /// ``` #[macro_export] macro_rules! log_mask_ln { --=20 2.53.0 From nobody Thu Feb 12 11:50:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1770823739; cv=none; d=zohomail.com; s=zohoarc; b=YLh5oaq/PReBA2QVm92PArF7cWjZ5oVgm2BAM1knVBkUpicFPZKtNiqdAUC4ujHKxSAmj6YM3384LZ7xGVNUat8h4O17XR/vGR1lzehcd9mJekjdDOYm85hmbVM8ab+q891d7KFekw6qniP0S2O/dlMqfy/LcwaAqAFrwxVSaTg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770823739; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ivMVOpUATjRZXgnDFtNQpL979jOHE0O+UHSIPG4QEn0=; b=Ym2XPVqKgoeEixlsFLIhD07bo2Z839Gapyrj9SXbXo5sxpHSiOyX/IxA0gAIkuxtq0eBwOFAgsMWntApVaPISyOf7F4N3U5No2IEOj593CWziCRB/BYR+v2+EttD0Ie9F++qSQmpfb29RuJilvAnAFHhINtqPdoIwcaTw4KE1SE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770823739987285.9443786366902; Wed, 11 Feb 2026 07:28:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqC7I-0006sz-G9; Wed, 11 Feb 2026 10:27:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC6x-0006e8-76 for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:26:39 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC6u-0005w9-LP for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:26:38 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-84-W5DJzJOzM3iDuOGI-5z7AA-1; Wed, 11 Feb 2026 10:26:28 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C81841800342; Wed, 11 Feb 2026 15:26:26 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.227.9]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EF9A8300DDA2; Wed, 11 Feb 2026 15:26:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770823594; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ivMVOpUATjRZXgnDFtNQpL979jOHE0O+UHSIPG4QEn0=; b=PSRRZjAOxpe0vB/ATORNcG7oofo6mltJ/QulBaBQdsZ+pjmANCtOnM/d2FbafI8k2O7awC IyACRP1MBxlecRMDoeuRACKbtq+RphJChpo/Z9drWrjlov9s++/Urs11O4fp/inz3JvSx6 21LYgw6uSSh40nFlGINmoE+NOpQRbnE= X-MC-Unique: W5DJzJOzM3iDuOGI-5z7AA-1 X-Mimecast-MFC-AGG-ID: W5DJzJOzM3iDuOGI-5z7AA_1770823586 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Stefan Weil , "Dr. David Alan Gilbert" , Pierrick Bouvier , devel@lists.libvirt.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, qemu-rust@nongnu.org, Paolo Bonzini , Markus Armbruster , Gerd Hoffmann , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Christian Schoenebeck , Richard Henderson Subject: [PATCH v6 12/27] util: avoid repeated prefix on incremental qemu_log calls Date: Wed, 11 Feb 2026 15:24:53 +0000 Message-ID: <20260211152508.732487-13-berrange@redhat.com> In-Reply-To: <20260211152508.732487-1-berrange@redhat.com> References: <20260211152508.732487-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1770823742080154100 There are three general patterns to QEMU log output 1. Single complete message calls qemu_log("Some message\n"); 2. Direct use of fprintf FILE *f =3D qemu_log_trylock() fprintf(f, "..."); fprintf(f, "..."); fprintf(f, "...\n"); qemu_log_unlock(f) 3. Mixed use of qemu_log_trylock/qemu_log() FILE *f =3D qemu_log_trylock() qemu_log("...."); qemu_log("...."); qemu_log("....\n"); qemu_log_unlock(f) When message prefixes are enabled, the timestamp will be unconditionally emitted for all qemu_log() calls. This works fine in the 1st case, and has no effect in the 2nd case. In the 3rd case, however, we get the timestamp printed over & over in each fragment. One can suggest that pattern (3) is pointless as it is functionally identical to (2) but with extra indirection and overhead. None the less we have a fair bit of code that does this. The qemu_log() call itself is nothing more than a wrapper which does pattern (2) with a single fprintf() call. One might question whether (2) should include the message prefix in the same way that (1), but there are scenarios where this could be inappropriate / unhelpful such as the CPU register dumps or linux-user strace output. This patch fixes the problem in pattern (3) by keeping track of the call depth of qemu_log_trylock() and then only emitting the the prefix when the starting depth was zero. In doing this qemu_log_trylock_context() is also introduced as a variant of qemu_log_trylock() that emits the prefix. Callers doing to batch output can thus choose whether a prefix is appropriate or not. Fixes: 012842c07552 (log: make '-msg timestamp=3Don' apply to all qemu_log = usage) Reported-by: Richard Henderson Signed-off-by: Daniel P. Berrang=C3=A9 --- include/qemu/log.h | 7 +++++++ util/log.c | 49 ++++++++++++++++++++++++++-------------------- 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/include/qemu/log.h b/include/qemu/log.h index b49a1a5fe3..92956e5d0f 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -70,6 +70,13 @@ bool qemu_log_separate(void); */ FILE *qemu_log_trylock(void) G_GNUC_WARN_UNUSED_RESULT; =20 +/** + * As qemu_log_trylock(), but will also print the message + * context, if any is configured and this caused the + * acquisition of the FILE lock + */ +FILE *qemu_log_trylock_with_context(void) G_GNUC_WARN_UNUSED_RESULT; + /** * Releases the lock on the log output, previously * acquired by qemu_log_trylock(). diff --git a/util/log.c b/util/log.c index c44d66b5ce..1644e6814b 100644 --- a/util/log.c +++ b/util/log.c @@ -127,13 +127,39 @@ static FILE *qemu_log_trylock_with_err(Error **errp) return logfile; } =20 +/* + * Zero if there's been no opening qemu_log_trylock call, + * indicating the need for message context to be emitted + * + * Non-zero if we're in the middle of printing a message, + * possibly over multiple lines and must skip further + * message context + */ +static __thread uint log_depth; + FILE *qemu_log_trylock(void) { - return qemu_log_trylock_with_err(NULL); + FILE *f =3D qemu_log_trylock_with_err(NULL); + log_depth++; + return f; +} + +FILE *qemu_log_trylock_with_context(void) +{ + FILE *f =3D qemu_log_trylock(); + if (f && log_depth =3D=3D 1 && message_with_timestamp) { + g_autofree const char *timestr =3D NULL; + g_autoptr(GDateTime) dt =3D g_date_time_new_now_utc(); + timestr =3D g_date_time_format_iso8601(dt); + fprintf(f, "%s ", timestr); + } + return f; } =20 void qemu_log_unlock(FILE *logfile) { + assert(log_depth); + log_depth--; if (logfile) { fflush(logfile); qemu_funlockfile(logfile); @@ -145,28 +171,9 @@ void qemu_log_unlock(FILE *logfile) =20 void qemu_log(const char *fmt, ...) { - FILE *f; - g_autofree const char *timestr =3D NULL; - - /* - * Prepare the timestamp *outside* the logging - * lock so it better reflects when the message - * was emitted if we are delayed acquiring the - * mutex - */ - if (message_with_timestamp) { - g_autoptr(GDateTime) dt =3D g_date_time_new_now_utc(); - timestr =3D g_date_time_format_iso8601(dt); - } - - f =3D qemu_log_trylock(); + FILE *f =3D qemu_log_trylock_with_context(); if (f) { va_list ap; - - if (timestr) { - fprintf(f, "%s ", timestr); - } - va_start(ap, fmt); vfprintf(f, fmt, ap); va_end(ap); --=20 2.53.0 From nobody Thu Feb 12 11:50:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1770823638; cv=none; d=zohomail.com; s=zohoarc; b=JAAqh1zsWDB1dXChtBOtcI+qxAVwTTer225NcZQwVV0tTp1I9kCPLS4ra1F3Kmyzd9Lyedf2ApEWlMqWch5XnolIW+KatGdhvKiLCA6T/AriwyJeToiehczNlQt0U4pP09rvNXJ5pIsz3WD4u/EElLoD5nIjMFCW1j0yMjC5OMA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770823638; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=BO1v7FggXljtP+vSgeaJUsMTzyoeVwe4/GHOoTCh4/c=; b=UjDW19/o2KcyuCP2XQ2+4t00dVWKHvVHOfqyWyOx4JpST43sBq+uu7qww6RwMRWUqwy4uU54L2MFot8tu2TxnJN/g7VCYm0ewgIBvkmaRRUkOYn3Oq7210oMPSrNiQDei6DODY+0KKxIKiRQFGoDip/7Af7Pj1Qb3UfCIHtX7fc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770823638534956.1318390126697; Wed, 11 Feb 2026 07:27:18 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqC7R-0006uq-Pk; Wed, 11 Feb 2026 10:27:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC6x-0006e9-AM for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:26:39 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC6w-0005wu-3r for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:26:39 -0500 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-217-q-zLx6ltMpyI7umqxZ9zbA-1; Wed, 11 Feb 2026 10:26:34 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4ED031800613; Wed, 11 Feb 2026 15:26:32 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.227.9]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 429E430002D8; Wed, 11 Feb 2026 15:26:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770823597; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BO1v7FggXljtP+vSgeaJUsMTzyoeVwe4/GHOoTCh4/c=; b=UkPytCpk2kZpuJVMq091nUStiv617ksrx80vl1WkVaxLBOV1t3HwtY13z09wnSyjyJ2vzw nzCoAkcfs7t9FQDiqkgjd8wgunmMBrFLt7mmPBnQXpKRHBKm5rGCUb1bnKpl0s9qMb75rb KM7Fh+u4dndsH1HNWcMhEFyUu+wJ97k= X-MC-Unique: q-zLx6ltMpyI7umqxZ9zbA-1 X-Mimecast-MFC-AGG-ID: q-zLx6ltMpyI7umqxZ9zbA_1770823592 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Stefan Weil , "Dr. David Alan Gilbert" , Pierrick Bouvier , devel@lists.libvirt.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, qemu-rust@nongnu.org, Paolo Bonzini , Markus Armbruster , Gerd Hoffmann , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Christian Schoenebeck , Richard Henderson Subject: [PATCH v6 13/27] util/log: add missing error reporting in qemu_log_trylock_with_err Date: Wed, 11 Feb 2026 15:24:54 +0000 Message-ID: <20260211152508.732487-14-berrange@redhat.com> In-Reply-To: <20260211152508.732487-1-berrange@redhat.com> References: <20260211152508.732487-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1770823639680158500 One codepath that could return NULL failed to populate the errp object. Reported-by: Markus Armbruster Signed-off-by: Daniel P. Berrang=C3=A9 --- util/log.c | 1 + 1 file changed, 1 insertion(+) diff --git a/util/log.c b/util/log.c index 1644e6814b..1c9c7adb2d 100644 --- a/util/log.c +++ b/util/log.c @@ -118,6 +118,7 @@ static FILE *qemu_log_trylock_with_err(Error **errp) logfile =3D qatomic_rcu_read((void **)&global_file); if (!logfile) { rcu_read_unlock(); + error_setg(errp, "Global log file output is not open"); return NULL; } } --=20 2.53.0 From nobody Thu Feb 12 11:50:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1770823999; cv=none; d=zohomail.com; s=zohoarc; b=khnyXFPrynL4a5AaJKS5A/bQGKqNq0ZF+dyaRJ1PrJGfMaiTrE+0uOFX3DMEWOKGPE1DjBgxHIRoi67OX6cmuCNMSHQoIKfp7udaTjfbB/jbAoDZ2EKxqRt+Q1TJklF8DngX0VvZfRytWCB9nLy/UpeSJpa6Owy0xYXBchxdU4c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770823999; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5X80YirqVbdBeezsX1Xx2uS/KBTswwOh/p3/QZ8PMc8=; b=kSrtTqpGnMKux1BCigjQahhTtH0UPFHNzCknWij5cPUUKRmLZ82OZWw4kHhs9DbeQZjkJnwLO7JmZT0VeHBqz0S2qOV9rNeIfVQxgJW6gAq1+Ek5x7Ad5F9xdrvP4oEcM+wPOsfHFa1r/LlF9R3ltO3sD4qK+IGvL5+QkuhGmaM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770823999152239.37388128252724; Wed, 11 Feb 2026 07:33:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqC7m-0007kS-6w; Wed, 11 Feb 2026 10:27:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC73-0006jq-R3 for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:26:48 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC71-0005yg-A0 for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:26:45 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-499-z2u0O0uqMTiSltl6P3I0HQ-1; Wed, 11 Feb 2026 10:26:39 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8E4651800370; Wed, 11 Feb 2026 15:26:37 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.227.9]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BF11A30001A8; Wed, 11 Feb 2026 15:26:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770823602; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5X80YirqVbdBeezsX1Xx2uS/KBTswwOh/p3/QZ8PMc8=; b=Vb9B0oAw0n/s05AC/33umOdUsof2r2YnVguyw+bhcf058qWu5Y7/xVcLWjeGxrAMWakZoM mv4GPWGZQBoT1HkbeKxd4pvPt/u8TufEF4VsKrziRUfbRY+iOjp0pVq2Eii7p12QnCecI4 ugHPYVKauumsGcJN7Gvigr3+OvVkP20= X-MC-Unique: z2u0O0uqMTiSltl6P3I0HQ-1 X-Mimecast-MFC-AGG-ID: z2u0O0uqMTiSltl6P3I0HQ_1770823597 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Stefan Weil , "Dr. David Alan Gilbert" , Pierrick Bouvier , devel@lists.libvirt.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, qemu-rust@nongnu.org, Paolo Bonzini , Markus Armbruster , Gerd Hoffmann , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Christian Schoenebeck , Richard Henderson Subject: [PATCH v6 14/27] ui: add proper error reporting for password changes Date: Wed, 11 Feb 2026 15:24:55 +0000 Message-ID: <20260211152508.732487-15-berrange@redhat.com> In-Reply-To: <20260211152508.732487-1-berrange@redhat.com> References: <20260211152508.732487-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1770824001733158500 Neither the VNC or SPICE code for password changes provides error reporting at source, leading the callers to report a largely useless generic error message. Fixing this removes one of the two remaining needs for the undesirable error_printf_unless_qmp() method. While fixing this the error message hint is improved to recommend the 'password-secret' option which allows securely passing a password at startup. Reported-by: Markus Armbruster Signed-off-by: Daniel P. Berrang=C3=A9 --- include/ui/console.h | 2 +- include/ui/qemu-spice-module.h | 3 ++- tests/functional/generic/test_vnc.py | 4 ++-- ui/spice-core.c | 25 ++++++++++++++++++------- ui/spice-module.c | 7 ++++--- ui/ui-qmp-cmds.c | 19 ++++++------------- ui/vnc-stubs.c | 6 +++--- ui/vnc.c | 10 +++++++--- 8 files changed, 43 insertions(+), 33 deletions(-) diff --git a/include/ui/console.h b/include/ui/console.h index 98feaa58bd..3677a9d334 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -457,7 +457,7 @@ void qemu_display_help(void); void vnc_display_init(const char *id, Error **errp); void vnc_display_open(const char *id, Error **errp); void vnc_display_add_client(const char *id, int csock, bool skipauth); -int vnc_display_password(const char *id, const char *password); +int vnc_display_password(const char *id, const char *password, Error **err= p); int vnc_display_pw_expire(const char *id, time_t expires); void vnc_parse(const char *str); int vnc_init_func(void *opaque, QemuOpts *opts, Error **errp); diff --git a/include/ui/qemu-spice-module.h b/include/ui/qemu-spice-module.h index 1f22d557ea..072efa0c83 100644 --- a/include/ui/qemu-spice-module.h +++ b/include/ui/qemu-spice-module.h @@ -29,7 +29,8 @@ struct QemuSpiceOps { void (*display_init)(void); int (*migrate_info)(const char *h, int p, int t, const char *s); int (*set_passwd)(const char *passwd, - bool fail_if_connected, bool disconnect_if_connected= ); + bool fail_if_connected, bool disconnect_if_connected, + Error **errp); int (*set_pw_expire)(time_t expires); int (*display_add_client)(int csock, int skipauth, int tls); #ifdef CONFIG_SPICE diff --git a/tests/functional/generic/test_vnc.py b/tests/functional/generi= c/test_vnc.py index f1dd1597cf..097f858ca1 100755 --- a/tests/functional/generic/test_vnc.py +++ b/tests/functional/generic/test_vnc.py @@ -48,7 +48,7 @@ def test_no_vnc_change_password(self): self.assertEqual(set_password_response['error']['class'], 'GenericError') self.assertEqual(set_password_response['error']['desc'], - 'Could not set password') + 'No VNC display is present'); =20 def launch_guarded(self): try: @@ -73,7 +73,7 @@ def test_change_password_requires_a_password(self): self.assertEqual(set_password_response['error']['class'], 'GenericError') self.assertEqual(set_password_response['error']['desc'], - 'Could not set password') + 'VNC password authentication is disabled') =20 def test_change_password(self): self.set_machine('none') diff --git a/ui/spice-core.c b/ui/spice-core.c index 8a6050f4ae..cdcec34f67 100644 --- a/ui/spice-core.c +++ b/ui/spice-core.c @@ -756,7 +756,7 @@ static void qemu_spice_init(void) tls_ciphers); } if (password) { - qemu_spice.set_passwd(password, false, false); + qemu_spice.set_passwd(password, false, false, NULL); } if (qemu_opt_get_bool(opts, "sasl", 0)) { if (spice_server_set_sasl(spice_server, 1) =3D=3D -1) { @@ -919,8 +919,10 @@ int qemu_spice_add_display_interface(QXLInstance *qxli= n, QemuConsole *con) return qemu_spice_add_interface(&qxlin->base); } =20 -static int qemu_spice_set_ticket(bool fail_if_conn, bool disconnect_if_con= n) +static int qemu_spice_set_ticket(bool fail_if_conn, bool disconnect_if_con= n, + Error **errp) { + int ret; time_t lifetime, now =3D time(NULL); char *passwd; =20 @@ -934,26 +936,35 @@ static int qemu_spice_set_ticket(bool fail_if_conn, b= ool disconnect_if_conn) passwd =3D NULL; lifetime =3D 1; } - return spice_server_set_ticket(spice_server, passwd, lifetime, - fail_if_conn, disconnect_if_conn); + ret =3D spice_server_set_ticket(spice_server, passwd, lifetime, + fail_if_conn, disconnect_if_conn); + if (ret < 0) { + error_setg(errp, "Unable to set SPICE server ticket"); + return -1; + } + return 0; } =20 static int qemu_spice_set_passwd(const char *passwd, - bool fail_if_conn, bool disconnect_if_con= n) + bool fail_if_conn, bool disconnect_if_con= n, + Error **errp) { if (strcmp(auth, "spice") !=3D 0) { + error_setg(errp, "SPICE authentication is disabled"); + error_append_hint(errp, + "To enable it use '-spice ...,password-secret=3D= ID'"); return -1; } =20 g_free(auth_passwd); auth_passwd =3D g_strdup(passwd); - return qemu_spice_set_ticket(fail_if_conn, disconnect_if_conn); + return qemu_spice_set_ticket(fail_if_conn, disconnect_if_conn, errp); } =20 static int qemu_spice_set_pw_expire(time_t expires) { auth_expires =3D expires; - return qemu_spice_set_ticket(false, false); + return qemu_spice_set_ticket(false, false, NULL); } =20 static int qemu_spice_display_add_client(int csock, int skipauth, int tls) diff --git a/ui/spice-module.c b/ui/spice-module.c index 3222335872..7651c85885 100644 --- a/ui/spice-module.c +++ b/ui/spice-module.c @@ -45,14 +45,15 @@ static int qemu_spice_migrate_info_stub(const char *h, = int p, int t, =20 static int qemu_spice_set_passwd_stub(const char *passwd, bool fail_if_connected, - bool disconnect_if_connected) + bool disconnect_if_connected, + Error **errp) { - return -1; + g_assert_not_reached(); } =20 static int qemu_spice_set_pw_expire_stub(time_t expires) { - return -1; + g_assert_not_reached(); } =20 static int qemu_spice_display_add_client_stub(int csock, int skipauth, diff --git a/ui/ui-qmp-cmds.c b/ui/ui-qmp-cmds.c index b49b636152..1173c82cf7 100644 --- a/ui/ui-qmp-cmds.c +++ b/ui/ui-qmp-cmds.c @@ -31,15 +31,14 @@ =20 void qmp_set_password(SetPasswordOptions *opts, Error **errp) { - int rc; - if (opts->protocol =3D=3D DISPLAY_PROTOCOL_SPICE) { if (!qemu_using_spice(errp)) { return; } - rc =3D qemu_spice.set_passwd(opts->password, - opts->connected =3D=3D SET_PASSWORD_ACTION_FAIL, - opts->connected =3D=3D SET_PASSWORD_ACTION_DISCONNECT); + qemu_spice.set_passwd(opts->password, + opts->connected =3D=3D SET_PASSWORD_ACTION_F= AIL, + opts->connected =3D=3D SET_PASSWORD_ACTION_D= ISCONNECT, + errp); } else { assert(opts->protocol =3D=3D DISPLAY_PROTOCOL_VNC); if (opts->connected !=3D SET_PASSWORD_ACTION_KEEP) { @@ -52,11 +51,7 @@ void qmp_set_password(SetPasswordOptions *opts, Error **= errp) * Note that setting an empty password will not disable login * through this interface. */ - rc =3D vnc_display_password(opts->u.vnc.display, opts->password); - } - - if (rc !=3D 0) { - error_setg(errp, "Could not set password"); + vnc_display_password(opts->u.vnc.display, opts->password, errp); } } =20 @@ -107,9 +102,7 @@ void qmp_expire_password(ExpirePasswordOptions *opts, E= rror **errp) #ifdef CONFIG_VNC void qmp_change_vnc_password(const char *password, Error **errp) { - if (vnc_display_password(NULL, password) < 0) { - error_setg(errp, "Could not set password"); - } + vnc_display_password(NULL, password, errp); } #endif =20 diff --git a/ui/vnc-stubs.c b/ui/vnc-stubs.c index a96bc86236..5de9bf9d70 100644 --- a/ui/vnc-stubs.c +++ b/ui/vnc-stubs.c @@ -2,11 +2,11 @@ #include "ui/console.h" #include "qapi/error.h" =20 -int vnc_display_password(const char *id, const char *password) +int vnc_display_password(const char *id, const char *password, Error **err= p) { - return -ENODEV; + g_assert_not_reached(); } int vnc_display_pw_expire(const char *id, time_t expires) { - return -ENODEV; + g_assert_not_reached(); }; diff --git a/ui/vnc.c b/ui/vnc.c index a61a4f937d..833e0e2e68 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -3526,16 +3526,20 @@ static void vnc_display_close(VncDisplay *vd) #endif } =20 -int vnc_display_password(const char *id, const char *password) +int vnc_display_password(const char *id, const char *password, Error **err= p) { VncDisplay *vd =3D vnc_display_find(id); =20 if (!vd) { + error_setg(errp, "No VNC display is present"); + error_append_hint(errp, + "To enable it, use '-vnc ...'"); return -EINVAL; } if (vd->auth =3D=3D VNC_AUTH_NONE) { - error_printf_unless_qmp("If you want use passwords please enable " - "password auth using '-vnc ${dpy},password= '.\n"); + error_setg(errp, "VNC password authentication is disabled"); + error_append_hint(errp, + "To enable it, use '-vnc ...,password-secret=3DI= D'"); return -EINVAL; } =20 --=20 2.53.0 From nobody Thu Feb 12 11:50:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1770823671; cv=none; d=zohomail.com; s=zohoarc; b=cTuBUzZvY1laRttQ52+Le1rtC/9g3NTsugyv8H8xAboYVQJf3ENHEhY2T7CzA5QqENfKDR4iwBvFJHxhNbClH+NNmVctVRCtryWRsEPhQ72u6viBxQ7N5swlCgbuGKmVir+PADI0XilyYctqyrBNKOGDRNUA851NQOqhydEPh+U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770823671; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=eK7Y9wa6E8Ejs/2GVwrT1km0ZDfxmHblP4R69ZgWde4=; b=M10nu+m/7yeh2jTlLw59/LXhRyXVaM03BkImWq0flxc1mIJNnP/A2aG4Ik+gQR+1GnIhWgvRctfq3Jyn6jNZASC4XBgw09OnVKMpUl+r0YyOBMhgyTeporu08YodsmT+ikYqsL9SZj189IPsmJXwfOeBgznxgO3K8QTdxwQ88NA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17708236716271021.6123035868501; Wed, 11 Feb 2026 07:27:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqC7k-0007Vb-OH; Wed, 11 Feb 2026 10:27:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC79-0006mB-FI for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:26:52 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC77-0005zX-F4 for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:26:51 -0500 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-661-Ay1dYe90Pda7J9D-TFZWEg-1; Wed, 11 Feb 2026 10:26:44 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 10A0E1955F20; Wed, 11 Feb 2026 15:26:43 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.227.9]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 09A3C30001A8; Wed, 11 Feb 2026 15:26:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770823607; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eK7Y9wa6E8Ejs/2GVwrT1km0ZDfxmHblP4R69ZgWde4=; b=XUp4oTzlWKVQmQTqvp88QYYazUFZ7XSSTUFxJCKu4cMasw7Cw/l9UR8gKtyneANmy/Vcs5 Qgn2x+bbDQj8oC7W9alSb7rcZkkb1h4oHa+GG308lQSPBcUxjg0iFj7CI/r1AP4xXqkgiv R3MMG/csYtX/Zwf4AiN7NTUgTb2hr7s= X-MC-Unique: Ay1dYe90Pda7J9D-TFZWEg-1 X-Mimecast-MFC-AGG-ID: Ay1dYe90Pda7J9D-TFZWEg_1770823603 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Stefan Weil , "Dr. David Alan Gilbert" , Pierrick Bouvier , devel@lists.libvirt.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, qemu-rust@nongnu.org, Paolo Bonzini , Markus Armbruster , Gerd Hoffmann , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Christian Schoenebeck , Richard Henderson Subject: [PATCH v6 15/27] ui: remove redundant use of error_printf_unless_qmp() Date: Wed, 11 Feb 2026 15:24:56 +0000 Message-ID: <20260211152508.732487-16-berrange@redhat.com> In-Reply-To: <20260211152508.732487-1-berrange@redhat.com> References: <20260211152508.732487-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1770823671825158500 The vnc_display_print_local_addr() method is intended to print the VNC listening address on the console at startup, so the user can see the auto-chosen port address when using the 'to=3D' flag. This is only called by vnc_display_open() which is in the QEMU startup callpath. The check for not being in QMP is thus redundant and can be removed. Signed-off-by: Daniel P. Berrang=C3=A9 --- ui/vnc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ui/vnc.c b/ui/vnc.c index 833e0e2e68..fe020dcc4c 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -3578,9 +3578,9 @@ static void vnc_display_print_local_addr(VncDisplay *= vd) qapi_free_SocketAddress(addr); return; } - error_printf_unless_qmp("VNC server running on %s:%s\n", - addr->u.inet.host, - addr->u.inet.port); + error_printf("VNC server running on %s:%s\n", + addr->u.inet.host, + addr->u.inet.port); qapi_free_SocketAddress(addr); } =20 --=20 2.53.0 From nobody Thu Feb 12 11:50:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1770823857; cv=none; d=zohomail.com; s=zohoarc; b=K4aqAJOrYriIoOxDoVhHSnJcAGPO7q45GL6iTQmUp+FXfXm39i5DZ7tPeekRfDvf24+FPqFPfxgO4nbA4Y7M8yaYrR5qqMwsd9nODQwLXfvK6cqAoHDSZ1MDxlBduOSjsK/V4xnFj8T0zCoynuvR8BrFvSpRJ2rcyPXX/luxThk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770823857; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6MgZnSu8FpgfVyxgsvWX6ruETMQfEejfRnUI7Ndvo2E=; b=n63n8t3Ux8rMf/unaBZkSXpay5+7u5UKN0xhp+p/rIpK7ivI2vdBaumdb5pwBQK7WPYGTxSLMfqqyuRqeuDrq8nrUHIBRq8IJNcauCl7rg39X5n4idaozaxeenUqju98H+nm/5d1ioJcOU3e2BalXtgJUvX8xSUTvPV/mNGxSkg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770823857058236.85362596658604; Wed, 11 Feb 2026 07:30:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqC7q-0008Jw-F4; Wed, 11 Feb 2026 10:27:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC7E-0006q1-La for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:26:58 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC7C-000612-AH for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:26:56 -0500 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-19-i8seQio8N4mPibSrxi86gA-1; Wed, 11 Feb 2026 10:26:50 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 91D7C180025C; Wed, 11 Feb 2026 15:26:48 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.227.9]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7F9CE30001A8; Wed, 11 Feb 2026 15:26:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770823613; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6MgZnSu8FpgfVyxgsvWX6ruETMQfEejfRnUI7Ndvo2E=; b=Y6/3Jm9nD+Dn39XxP/S3E4azlpwL3Wn+7vtW5kzdBWBtQkmIXxnkuX/BRzaJ40T2Y9LE8z Bx6XCC36I0ApL4Ngr7SvvECt8WhJglsFq1aLK2iHCSgzZNet5PCz58ah6QvYuv9VPMstbX cn224QWUCkdB1QYyiYyZFPNZAofB2FQ= X-MC-Unique: i8seQio8N4mPibSrxi86gA-1 X-Mimecast-MFC-AGG-ID: i8seQio8N4mPibSrxi86gA_1770823608 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Stefan Weil , "Dr. David Alan Gilbert" , Pierrick Bouvier , devel@lists.libvirt.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, qemu-rust@nongnu.org, Paolo Bonzini , Markus Armbruster , Gerd Hoffmann , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Christian Schoenebeck , Richard Henderson Subject: [PATCH v6 16/27] monitor: remove redundant error_[v]printf_unless_qmp Date: Wed, 11 Feb 2026 15:24:57 +0000 Message-ID: <20260211152508.732487-17-berrange@redhat.com> In-Reply-To: <20260211152508.732487-1-berrange@redhat.com> References: <20260211152508.732487-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1770823859005158500 The only callers of these functions have been removed. Adding any new usage of them is highly undesirable, so they should be entirely removed. Reviewed-by: Richard Henderson Reviewed-by: Markus Armbruster Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- include/monitor/monitor.h | 3 --- monitor/monitor.c | 24 ------------------------ stubs/error-printf.c | 5 ----- 3 files changed, 32 deletions(-) diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index c3740ec616..296690e1f1 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -59,7 +59,4 @@ void monitor_register_hmp(const char *name, bool info, void monitor_register_hmp_info_hrt(const char *name, HumanReadableText *(*handler)(Error **e= rrp)); =20 -int error_vprintf_unless_qmp(const char *fmt, va_list ap) G_GNUC_PRINTF(1,= 0); -int error_printf_unless_qmp(const char *fmt, ...) G_GNUC_PRINTF(1, 2); - #endif /* MONITOR_H */ diff --git a/monitor/monitor.c b/monitor/monitor.c index dd2c45ded0..4d26cd9496 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -281,30 +281,6 @@ int error_vprintf(const char *fmt, va_list ap) return vfprintf(stderr, fmt, ap); } =20 -int error_vprintf_unless_qmp(const char *fmt, va_list ap) -{ - Monitor *cur_mon =3D monitor_cur(); - - if (!cur_mon) { - return vfprintf(stderr, fmt, ap); - } - if (!monitor_cur_is_qmp()) { - return monitor_vprintf(cur_mon, fmt, ap); - } - return -1; -} - -int error_printf_unless_qmp(const char *fmt, ...) -{ - va_list ap; - int ret; - - va_start(ap, fmt); - ret =3D error_vprintf_unless_qmp(fmt, ap); - va_end(ap); - return ret; -} - static MonitorQAPIEventConf monitor_qapi_event_conf[QAPI_EVENT__MAX] =3D { /* Limit guest-triggerable events to 1 per second */ [QAPI_EVENT_RTC_CHANGE] =3D { 1000 * SCALE_MS }, diff --git a/stubs/error-printf.c b/stubs/error-printf.c index 0e326d8010..1afa0f62ca 100644 --- a/stubs/error-printf.c +++ b/stubs/error-printf.c @@ -16,8 +16,3 @@ int error_vprintf(const char *fmt, va_list ap) } return vfprintf(stderr, fmt, ap); } - -int error_vprintf_unless_qmp(const char *fmt, va_list ap) -{ - return error_vprintf(fmt, ap); -} --=20 2.53.0 From nobody Thu Feb 12 11:50:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1770823687; cv=none; d=zohomail.com; s=zohoarc; b=KylPHNlL3DW7GsLc8dkHMTtg3kdSKh/LOujMB+S1LBGcdTC06h8g8wBhFnDDUaHLPrcPq4/sHKuwDHjkq6XWu/ghYS7d6JFoT/y5721zx9vqONnuQTcRc1DeIJiNeqRQMIMcqQ+nMaTXof8DQLbZpCE0lbIj/HCwlGY/jhY30p0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770823687; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+9OSKcd31lWikFWaURufmE/FEdairRVtIzQDpvvKKEY=; b=Knmd2DxHNtoE8jveYTLGkcfYaXJUZNzuYkzP3RYARuZ04InIrALUIOohycoM//x7A9jpOHJuyeUNPypdnLh/eNJfF75wVxbbK93yyPPMqZ/QuSaDYOEXIqGg+oDhAxSJnRZLP/HvsMfo2H+WYrWtChJ+pYG4uYddx/jBPpD1WSk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770823687645519.2472728204433; Wed, 11 Feb 2026 07:28:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqC7k-0007YN-T3; Wed, 11 Feb 2026 10:27:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC7I-0006uE-Et for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:27:02 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC7G-00062B-Dt for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:26:59 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-448-40iIb_i9OIehk1EdD_l3fA-1; Wed, 11 Feb 2026 10:26:55 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B6D7C18002FF; Wed, 11 Feb 2026 15:26:53 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.227.9]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E9FAE30001A8; Wed, 11 Feb 2026 15:26:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770823617; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+9OSKcd31lWikFWaURufmE/FEdairRVtIzQDpvvKKEY=; b=chcsJ4x9CO1xsw0qploYyzhCe+ohl/2oeWDq/cgAx5JzjBZenS75x9bQaHJ/Frz+Pm8lMs 9QxdGhBlF+5Hiaz3/Qmr65t87oqhpRtoTnoyJCCMZjWMbU2gYEPw/U8nl0K7jZDRNFYHwN AD5eGwCm3OuYsEtDQYWtNQW7wHsGL24= X-MC-Unique: 40iIb_i9OIehk1EdD_l3fA-1 X-Mimecast-MFC-AGG-ID: 40iIb_i9OIehk1EdD_l3fA_1770823613 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Stefan Weil , "Dr. David Alan Gilbert" , Pierrick Bouvier , devel@lists.libvirt.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, qemu-rust@nongnu.org, Paolo Bonzini , Markus Armbruster , Gerd Hoffmann , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Christian Schoenebeck , Richard Henderson Subject: [PATCH v6 17/27] monitor: refactor error_vprintf() Date: Wed, 11 Feb 2026 15:24:58 +0000 Message-ID: <20260211152508.732487-18-berrange@redhat.com> In-Reply-To: <20260211152508.732487-1-berrange@redhat.com> References: <20260211152508.732487-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1770823689200154100 The monitor_vprintf() code will return -1 if either the monitor is NULL, or the monitor is QMP. The error_vprintf() code can take advantage of this to avoid having to duplicate the same checks, and instead simply look at the return value. Reviewed-by: Richard Henderson Reviewed-by: Markus Armbruster Signed-off-by: Daniel P. Berrang=C3=A9 --- monitor/monitor.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/monitor/monitor.c b/monitor/monitor.c index 4d26cd9496..64c552a047 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -269,16 +269,21 @@ void monitor_printc(Monitor *mon, int c) } =20 /* - * Print to current monitor if we have one, else to stderr. + * Print to the current human monitor if we have one, else to stderr. */ int error_vprintf(const char *fmt, va_list ap) { Monitor *cur_mon =3D monitor_cur(); - - if (cur_mon && !monitor_cur_is_qmp()) { - return monitor_vprintf(cur_mon, fmt, ap); + /* + * This will return -1 if 'cur_mon' is NULL, or is QMP. + * IOW this will only print if in HMP, otherwise we + * fallback to stderr for QMP / no-monitor scenarios. + */ + int ret =3D monitor_vprintf(cur_mon, fmt, ap); + if (ret =3D=3D -1) { + ret =3D vfprintf(stderr, fmt, ap); } - return vfprintf(stderr, fmt, ap); + return ret; } =20 static MonitorQAPIEventConf monitor_qapi_event_conf[QAPI_EVENT__MAX] =3D { --=20 2.53.0 From nobody Thu Feb 12 11:50:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1770823733; cv=none; d=zohomail.com; s=zohoarc; b=Cg0JX8MztgmuzY3KOtoLZcCfeAqhCBGtmEZTwZ5JxBfZC6FC1lUa1Sy90ZUJacggemRhDvlgL41JAGS+Mb5I4Fx6arU/C7v0I3ItaW+93j+iN8S4DaKgOFdgPtAkB5i/3jXu0ixUMzTFxsEuS/J43vBVxPjzh+KnKCtgfk3vp+g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770823733; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=S8FwGsc+U4X0RJkMPuDd8AeKnsrsM8ODFDWU/OsmlDA=; b=mOoMRGPcfstEs+qxgliVDjZeSgdLtNFvhTwCwwBSAeeM6eZ4gPdcJKVF9eDN04Vy46r3TsrHPE6qh9ed4TtGeLylKpp5uWz3rBf7sxBsJJEKTK0tCsLwRz1LCr+kH+gu6iJkl06v2DFdg+DhAJ2mINsnhmKJBX0SGYhX85ztoWU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770823733827232.85518314419437; Wed, 11 Feb 2026 07:28:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqC7o-000875-Vj; Wed, 11 Feb 2026 10:27:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC7O-000716-Ne for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:27:11 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC7N-00063X-1E for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:27:06 -0500 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-219-DCbKbnZdM9yzo4sA-KOGZg-1; Wed, 11 Feb 2026 10:27:01 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 79B871955E7E; Wed, 11 Feb 2026 15:26:59 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.227.9]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 30A9F30002D8; Wed, 11 Feb 2026 15:26:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770823624; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S8FwGsc+U4X0RJkMPuDd8AeKnsrsM8ODFDWU/OsmlDA=; b=JRu+rPjgMn6bxBxgb1YhtGjTRsfJ2q0K5RmTDu7+MJ3uXYp6lbGZaltYMDCQbCAoKloujc vIoo6vd9erkmdreUiv1dBaKJvdcH6BjBWfWLfCgq8Q0bS1yDVYXVjwWKkGaFi+hqIBWpog CSxRtyTCm/xbvm4KwwbnEniupmrZX4w= X-MC-Unique: DCbKbnZdM9yzo4sA-KOGZg-1 X-Mimecast-MFC-AGG-ID: DCbKbnZdM9yzo4sA-KOGZg_1770823619 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Stefan Weil , "Dr. David Alan Gilbert" , Pierrick Bouvier , devel@lists.libvirt.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, qemu-rust@nongnu.org, Paolo Bonzini , Markus Armbruster , Gerd Hoffmann , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Christian Schoenebeck , Richard Henderson , Eric Blake Subject: [PATCH v6 18/27] monitor: move error_vprintf back to error-report.c Date: Wed, 11 Feb 2026 15:24:59 +0000 Message-ID: <20260211152508.732487-19-berrange@redhat.com> In-Reply-To: <20260211152508.732487-1-berrange@redhat.com> References: <20260211152508.732487-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1770823736272158500 The current unit tests rely on monitor.o not being linked, such that the monitor stubs get linked instead. Since error_vprintf is in monitor.o this allows a stub error_vprintf impl to be used that calls g_test_message. This takes a different approach, with error_vprintf moving back to error-report.c such that it is always linked into the tests. The monitor_vprintf() stub is then changed to use g_test_message if QTEST_SILENT_ERRORS is set, otherwise it will return -1 and trigger error_vprintf to call vfprintf. The end result is functionally equivalent for the purposes of the unit tests. Reviewed-by: Richard Henderson Reviewed-by: Eric Blake Reviewed-by: Markus Armbruster Signed-off-by: Daniel P. Berrang=C3=A9 --- monitor/monitor.c | 18 ------------------ stubs/error-printf.c | 18 ------------------ stubs/meson.build | 1 - stubs/monitor-core.c | 14 +++++++++++++- util/error-report.c | 18 ++++++++++++++++++ 5 files changed, 31 insertions(+), 38 deletions(-) delete mode 100644 stubs/error-printf.c diff --git a/monitor/monitor.c b/monitor/monitor.c index 64c552a047..6dc5a7016d 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -268,24 +268,6 @@ void monitor_printc(Monitor *mon, int c) monitor_printf(mon, "'"); } =20 -/* - * Print to the current human monitor if we have one, else to stderr. - */ -int error_vprintf(const char *fmt, va_list ap) -{ - Monitor *cur_mon =3D monitor_cur(); - /* - * This will return -1 if 'cur_mon' is NULL, or is QMP. - * IOW this will only print if in HMP, otherwise we - * fallback to stderr for QMP / no-monitor scenarios. - */ - int ret =3D monitor_vprintf(cur_mon, fmt, ap); - if (ret =3D=3D -1) { - ret =3D vfprintf(stderr, fmt, ap); - } - return ret; -} - static MonitorQAPIEventConf monitor_qapi_event_conf[QAPI_EVENT__MAX] =3D { /* Limit guest-triggerable events to 1 per second */ [QAPI_EVENT_RTC_CHANGE] =3D { 1000 * SCALE_MS }, diff --git a/stubs/error-printf.c b/stubs/error-printf.c deleted file mode 100644 index 1afa0f62ca..0000000000 --- a/stubs/error-printf.c +++ /dev/null @@ -1,18 +0,0 @@ -#include "qemu/osdep.h" -#include "qemu/error-report.h" -#include "monitor/monitor.h" - -int error_vprintf(const char *fmt, va_list ap) -{ - int ret; - - if (g_test_initialized() && !g_test_subprocess() && - getenv("QTEST_SILENT_ERRORS")) { - char *msg =3D g_strdup_vprintf(fmt, ap); - g_test_message("%s", msg); - ret =3D strlen(msg); - g_free(msg); - return ret; - } - return vfprintf(stderr, fmt, ap); -} diff --git a/stubs/meson.build b/stubs/meson.build index 8a07059500..354bf97d74 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -3,7 +3,6 @@ # below, so that it is clear who needs the stubbed functionality. =20 stub_ss.add(files('cpu-get-clock.c')) -stub_ss.add(files('error-printf.c')) stub_ss.add(files('fdset.c')) stub_ss.add(files('iothread-lock.c')) stub_ss.add(files('is-daemonized.c')) diff --git a/stubs/monitor-core.c b/stubs/monitor-core.c index 1894cdfe1f..a7c32297c9 100644 --- a/stubs/monitor-core.c +++ b/stubs/monitor-core.c @@ -18,5 +18,17 @@ void qapi_event_emit(QAPIEvent event, QDict *qdict) =20 int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) { - abort(); + /* + * Pretend 'g_test_message' is our monitor console to + * stop the caller sending messages to stderr + */ + if (g_test_initialized() && !g_test_subprocess() && + getenv("QTEST_SILENT_ERRORS")) { + char *msg =3D g_strdup_vprintf(fmt, ap); + g_test_message("%s", msg); + size_t ret =3D strlen(msg); + g_free(msg); + return ret; + } + return -1; } diff --git a/util/error-report.c b/util/error-report.c index 1b17c11de1..f3aa24ec22 100644 --- a/util/error-report.c +++ b/util/error-report.c @@ -29,6 +29,24 @@ bool message_with_timestamp; bool error_with_guestname; const char *error_guest_name; =20 +/* + * Print to the current human monitor if we have one, else to stderr. + */ +int error_vprintf(const char *fmt, va_list ap) +{ + Monitor *cur_mon =3D monitor_cur(); + /* + * This will return -1 if 'cur_mon' is NULL, or is QMP. + * IOW this will only print if in HMP, otherwise we + * fallback to stderr for QMP / no-monitor scenarios. + */ + int ret =3D monitor_vprintf(cur_mon, fmt, ap); + if (ret =3D=3D -1) { + ret =3D vfprintf(stderr, fmt, ap); + } + return ret; +} + int error_printf(const char *fmt, ...) { va_list ap; --=20 2.53.0 From nobody Thu Feb 12 11:50:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1770823911; cv=none; d=zohomail.com; s=zohoarc; b=ckOq1pw8CvzFFqwGkZNcpc8KyMTo8TCh22M+NC2fgi3qCs0qgSHZcWYZ9PNsDQ1RTZT5J4SBxRLsu3ASUG4hpNZ0Ktd+rvGsW1jfq9IzlPHK79ufeNPMFtFVlVdRJLfzelFlLEVVDf7HDPXVGsNPeIe/oflzdR4mkz8U/TISV4M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770823911; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=RAw0M5DQrWvr04qhs1mJQ/D6Qx2tWsXmBnfqMP/fRAg=; b=T+TGY8rOILKahAWvnkpOElAvctsVfR4QcRRQAqVMCt+D/u3KIecliwCIrE4mTdF2O9ifC/1o8YiywPOayQ8uKliGMgE9B+9A3pPx9knqiTbBe1hgQ4749D0qZn1woZNX4H4oce2grwAQfNYo+sXYmoIj5WvWxHyWW7oW97pca3s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770823911925202.0490831270514; Wed, 11 Feb 2026 07:31:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqC7m-0007uu-SY; Wed, 11 Feb 2026 10:27:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC7Y-00073v-0k for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:27:16 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC7U-00064K-Pz for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:27:15 -0500 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-98-s9KGedNhOS2bf2mYapvZ5A-1; Wed, 11 Feb 2026 10:27:06 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CD4701955F1D; Wed, 11 Feb 2026 15:27:04 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.227.9]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D3DA230001A8; Wed, 11 Feb 2026 15:26:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770823632; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RAw0M5DQrWvr04qhs1mJQ/D6Qx2tWsXmBnfqMP/fRAg=; b=VclvwwfBDjvsU4OXByDEnODhG4UJgiaaynlsj/jWEZlUTpJjIP7GbYj/vaZM6JkrDx5b2O RXexJ2PSCus7S1P4IsVDxh7U7OxdNf8JGgFGjb9aRGMM+AmozSf5w7H0/aL8TC2D+MfWuc ARVbgCR7fmbEJfeY1nF05t/nkRNzcWc= X-MC-Unique: s9KGedNhOS2bf2mYapvZ5A-1 X-Mimecast-MFC-AGG-ID: s9KGedNhOS2bf2mYapvZ5A_1770823624 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Stefan Weil , "Dr. David Alan Gilbert" , Pierrick Bouvier , devel@lists.libvirt.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, qemu-rust@nongnu.org, Paolo Bonzini , Markus Armbruster , Gerd Hoffmann , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Christian Schoenebeck , Richard Henderson Subject: [PATCH v6 19/27] util: fix interleaving of error & trace output Date: Wed, 11 Feb 2026 15:25:00 +0000 Message-ID: <20260211152508.732487-20-berrange@redhat.com> In-Reply-To: <20260211152508.732487-1-berrange@redhat.com> References: <20260211152508.732487-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1770823913344158500 The monitor_cur_hmp() function will acquire/release mutex locks, which will trigger trace probes, which can in turn trigger qemu_log() calls. vreport() calls monitor_cur() multiple times through its execution both directly and indirectly via error_vprintf(). The result is that the prefix information printed by vreport() gets interleaved with qemu_log() output, when run outside the context of an HMP command dispatcher. This can be seen with: $ qemu-system-x86_64 \ -msg timestamp=3Don,guest-name=3Don \ -display none \ -object tls-creds-x509,id=3Df,dir=3Dfish \ -name fish \ -d trace:qemu_mutex* 2025-09-10T16:30:42.514374Z qemu_mutex_unlock released mutex 0x560b0339b= 4c0 (/var/home/berrange/src/virt/qemu/include/qemu/lockable.h:56) 2025-09-10T16:30:42.514400Z qemu_mutex_lock waiting on mutex 0x560b03398= 3e0 (/var/home/berrange/src/virt/qemu/include/qemu/lockable.h:56) 2025-09-10T16:30:42.514402Z qemu_mutex_locked taken mutex 0x560b033983e0= (/var/home/berrange/src/virt/qemu/include/qemu/lockable.h:56) 2025-09-10T16:30:42.514404Z qemu_mutex_unlock released mutex 0x560b03398= 3e0 (/var/home/berrange/src/virt/qemu/include/qemu/lockable.h:56) 2025-09-10T16:30:42.516716Z qemu_mutex_lock waiting on mutex 0x560b03398= 560 (../monitor/monitor.c:91) 2025-09-10T16:30:42.516723Z qemu_mutex_locked taken mutex 0x560b03398560= (../monitor/monitor.c:91) 2025-09-10T16:30:42.516726Z qemu_mutex_unlock released mutex 0x560b03398= 560 (../monitor/monitor.c:96) 2025-09-10T16:30:42.516728Z qemu_mutex_lock waiting on mutex 0x560b03398= 560 (../monitor/monitor.c:91) 2025-09-10T16:31:04.842057Z qemu_mutex_locked taken mutex 0x564f5e401560= (../monitor/monitor.c:91) 2025-09-10T16:31:04.842058Z qemu_mutex_unlock released mutex 0x564f5e401= 560 (../monitor/monitor.c:96) 2025-09-10T16:31:04.842055Z 2025-09-10T16:31:04.842060Z qemu_mutex_lock = waiting on mutex 0x564f5e401560 (../monitor/monitor.c:91) 2025-09-10T16:31:04.842061Z qemu_mutex_locked taken mutex 0x564f5e401560= (../monitor/monitor.c:91) 2025-09-10T16:31:04.842062Z qemu_mutex_unlock released mutex 0x564f5e401= 560 (../monitor/monitor.c:96) 2025-09-10T16:31:04.842064Z qemu_mutex_lock waiting on mutex 0x564f5e401= 560 (../monitor/monitor.c:91) 2025-09-10T16:31:04.842065Z qemu_mutex_locked taken mutex 0x564f5e401560= (../monitor/monitor.c:91) 2025-09-10T16:31:04.842066Z qemu_mutex_unlock released mutex 0x564f5e401= 560 (../monitor/monitor.c:96) fish 2025-09-10T16:31:04.842068Z qemu_mutex_lock waiting on mutex 0x564f= 5e401560 (../monitor/monitor.c:91) 2025-09-10T16:31:04.842069Z qemu_mutex_locked taken mutex 0x564f5e401560= (../monitor/monitor.c:91) 2025-09-10T16:31:04.842070Z qemu_mutex_unlock released mutex 0x564f5e401= 560 (../monitor/monitor.c:96) 2025-09-10T16:31:04.842072Z qemu_mutex_lock waiting on mutex 0x564f5e401= 560 (../monitor/monitor.c:91) 2025-09-10T16:31:04.842097Z qemu_mutex_locked taken mutex 0x564f5e401560= (../monitor/monitor.c:91) 2025-09-10T16:31:04.842099Z qemu_mutex_unlock released mutex 0x564f5e401= 560 (../monitor/monitor.c:96) qemu-system-x86_64:2025-09-10T16:31:04.842100Z qemu_mutex_lock waiting o= n mutex 0x564f5e401560 (../monitor/monitor.c:91) 2025-09-10T16:31:04.842102Z qemu_mutex_locked taken mutex 0x564f5e401560= (../monitor/monitor.c:91) 2025-09-10T16:31:04.842103Z qemu_mutex_unlock released mutex 0x564f5e401= 560 (../monitor/monitor.c:96) 2025-09-10T16:31:04.842105Z qemu_mutex_lock waiting on mutex 0x564f5e40= 1560 (../monitor/monitor.c:91) 2025-09-10T16:31:04.842106Z qemu_mutex_locked taken mutex 0x564f5e401560= (../monitor/monitor.c:91) 2025-09-10T16:31:04.842107Z qemu_mutex_unlock released mutex 0x564f5e401= 560 (../monitor/monitor.c:96) Unable to access credentials fish/ca-cert.pem: No such file or directory= 2025-09-10T16:31:04.842109Z qemu_mutex_lock waiting on mutex 0x564f5e401560= (../monitor/monitor.c:91) 2025-09-10T16:31:04.842110Z qemu_mutex_locked taken mutex 0x564f5e401560= (../monitor/monitor.c:91) 2025-09-10T16:31:04.842111Z qemu_mutex_unlock released mutex 0x564f5e401= 560 (../monitor/monitor.c:96) To avoid this interleaving (as well as reduce the huge number of mutex lock/unlock calls) we need to ensure that monitor_cur_is_hmp() is only called once at the start of vreport(), and if no HMP is present, no further monitor APIs can be called. This implies error_[v]printf() cannot be called from vreport(). Instead we must introduce error_[v]printf_mon() which accept a pre-acquired Monitor object. In some cases, however, fprintf can be called directly as output will never be directed to the monitor. $ qemu-system-x86_64 \ -msg timestamp=3Don,guest-name=3Don \ -display none \ -object tls-creds-x509,id=3Df,dir=3Dfish \ -name fish \ -d trace:qemu_mutex* 2025-09-10T16:31:22.701691Z qemu_mutex_unlock released mutex 0x5626fd3b8= 4c0 (/var/home/berrange/src/virt/qemu/include/qemu/lockable.h:56) 2025-09-10T16:31:22.701728Z qemu_mutex_lock waiting on mutex 0x5626fd3b5= 3e0 (/var/home/berrange/src/virt/qemu/include/qemu/lockable.h:56) 2025-09-10T16:31:22.701730Z qemu_mutex_locked taken mutex 0x5626fd3b53e0= (/var/home/berrange/src/virt/qemu/include/qemu/lockable.h:56) 2025-09-10T16:31:22.701732Z qemu_mutex_unlock released mutex 0x5626fd3b5= 3e0 (/var/home/berrange/src/virt/qemu/include/qemu/lockable.h:56) 2025-09-10T16:31:22.703989Z qemu_mutex_lock waiting on mutex 0x5626fd3b5= 560 (../monitor/monitor.c:91) 2025-09-10T16:31:22.703996Z qemu_mutex_locked taken mutex 0x5626fd3b5560= (../monitor/monitor.c:91) 2025-09-10T16:31:22.703999Z qemu_mutex_unlock released mutex 0x5626fd3b5= 560 (../monitor/monitor.c:96) 2025-09-10T16:31:22.704000Z fish qemu-system-x86_64: Unable to access cr= edentials fish/ca-cert.pem: No such file or directory Reviewed-by: Richard Henderson Signed-off-by: Daniel P. Berrang=C3=A9 --- util/error-report.c | 63 ++++++++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 21 deletions(-) diff --git a/util/error-report.c b/util/error-report.c index f3aa24ec22..b34a2bc7bc 100644 --- a/util/error-report.c +++ b/util/error-report.c @@ -32,9 +32,9 @@ const char *error_guest_name; /* * Print to the current human monitor if we have one, else to stderr. */ -int error_vprintf(const char *fmt, va_list ap) +static int G_GNUC_PRINTF(2, 0) +error_vprintf_mon(Monitor *cur_mon, const char *fmt, va_list ap) { - Monitor *cur_mon =3D monitor_cur(); /* * This will return -1 if 'cur_mon' is NULL, or is QMP. * IOW this will only print if in HMP, otherwise we @@ -47,13 +47,33 @@ int error_vprintf(const char *fmt, va_list ap) return ret; } =20 +/* + * Print to the current human monitor if we have one, else to stderr. + */ +static int G_GNUC_PRINTF(2, 3) +error_printf_mon(Monitor *cur_mon, const char *fmt, ...) +{ + va_list ap; + int ret; + + va_start(ap, fmt); + ret =3D error_vprintf_mon(cur_mon, fmt, ap); + va_end(ap); + return ret; +} + +int error_vprintf(const char *fmt, va_list ap) +{ + return error_vprintf_mon(monitor_cur(), fmt, ap); +} + int error_printf(const char *fmt, ...) { va_list ap; int ret; =20 va_start(ap, fmt); - ret =3D error_vprintf(fmt, ap); + ret =3D error_vprintf_mon(monitor_cur(), fmt, ap); va_end(ap); return ret; } @@ -156,34 +176,34 @@ void loc_set_file(const char *fname, int lno) /* * Print current location to current monitor if we have one, else to stder= r. */ -static void print_loc(void) +static void print_loc(Monitor *cur) { const char *sep =3D ""; int i; const char *const *argp; =20 - if (!monitor_cur() && g_get_prgname()) { - error_printf("%s:", g_get_prgname()); + if (!cur && g_get_prgname()) { + fprintf(stderr, "%s:", g_get_prgname()); sep =3D " "; } switch (cur_loc->kind) { case LOC_CMDLINE: argp =3D cur_loc->ptr; for (i =3D 0; i < cur_loc->num; i++) { - error_printf("%s%s", sep, argp[i]); + error_printf_mon(cur, "%s%s", sep, argp[i]); sep =3D " "; } - error_printf(": "); + error_printf_mon(cur, ": "); break; case LOC_FILE: - error_printf("%s:", (const char *)cur_loc->ptr); + error_printf_mon(cur, "%s:", (const char *)cur_loc->ptr); if (cur_loc->num) { - error_printf("%d:", cur_loc->num); + error_printf_mon(cur, "%d:", cur_loc->num); } - error_printf(" "); + error_printf_mon(cur, " "); break; default: - error_printf("%s", sep); + error_printf_mon(cur, "%s", sep); } } =20 @@ -204,34 +224,35 @@ real_time_iso8601(void) G_GNUC_PRINTF(2, 0) static void vreport(report_type type, const char *fmt, va_list ap) { + Monitor *cur =3D monitor_cur(); gchar *timestr; =20 - if (message_with_timestamp && !monitor_cur()) { + if (message_with_timestamp && !cur) { timestr =3D real_time_iso8601(); - error_printf("%s ", timestr); + fprintf(stderr, "%s ", timestr); g_free(timestr); } =20 /* Only prepend guest name if -msg guest-name and -name guest=3D... ar= e set */ - if (error_with_guestname && error_guest_name && !monitor_cur()) { - error_printf("%s ", error_guest_name); + if (error_with_guestname && error_guest_name && !cur) { + fprintf(stderr, "%s ", error_guest_name); } =20 - print_loc(); + print_loc(cur); =20 switch (type) { case REPORT_TYPE_ERROR: break; case REPORT_TYPE_WARNING: - error_printf("warning: "); + error_printf_mon(cur, "warning: "); break; case REPORT_TYPE_INFO: - error_printf("info: "); + error_printf_mon(cur, "info: "); break; } =20 - error_vprintf(fmt, ap); - error_printf("\n"); + error_vprintf_mon(cur, fmt, ap); + error_printf_mon(cur, "\n"); } =20 /* --=20 2.53.0 From nobody Thu Feb 12 11:50:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1770823787; cv=none; d=zohomail.com; s=zohoarc; b=O2v0mfv/4P0UmdsFVB6wdgqAgDCtb0ZFy0i+nwV0yrTMy42QqnjDwRILqei13g5AOEZm1T7GdmYWRBam80RkBx2zxeiAn4zAOH9oZuPK+8Lse+SuK8H1W/Xb2jIQ3oN7u2j4j2dET0OwW4lCFW92kAynZhZZEd1QrA/6RzsH27M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770823787; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ids8ssbjyqIGdjv1hvc90z9LCMXzQg8S2+lPCiRENwA=; b=VewBMFVdJFRDgI8EEJwZbf+y1/l6XjCqSPdiV7Y2eD3+Bkta8gpbGrebJRhFmq198Z0JHm53y9O15qC91VnF9R3eQorIEFLEN6hH10DB9z7E+O34Z8qdeh0GNt3Rk6pmea+nDUsCgApyYrTz6V+UG0KS0if7AQKXNMWwMXSUtJc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770823786952563.527969336231; Wed, 11 Feb 2026 07:29:46 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqC7s-00005H-9o; Wed, 11 Feb 2026 10:27:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC7g-0007I3-EI for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:27:26 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC7c-00065K-Bs for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:27:23 -0500 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-653-Y2Wf5-4YO6e9Q_Wy8Qnv-g-1; Wed, 11 Feb 2026 10:27:14 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 15D1D19560B2; Wed, 11 Feb 2026 15:27:10 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.227.9]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 485AE30001A8; Wed, 11 Feb 2026 15:27:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770823638; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ids8ssbjyqIGdjv1hvc90z9LCMXzQg8S2+lPCiRENwA=; b=OMnx2xnCLYF7s7VrESJRTU8Iu1GVUquFx0AtqFD1oAFElGEcBbF9LJ0ROs+KMxBieVTEc4 6UakDlJghViJl4ey9+74+WQXz4TYsDQV3rONLaqeYFVzG7AFJxs0Ym1CFy4K1ts/Ey+X8q YG6HWzPh/wvvqFysjYcoJlvOALRo3YA= X-MC-Unique: Y2Wf5-4YO6e9Q_Wy8Qnv-g-1 X-Mimecast-MFC-AGG-ID: Y2Wf5-4YO6e9Q_Wy8Qnv-g_1770823630 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Stefan Weil , "Dr. David Alan Gilbert" , Pierrick Bouvier , devel@lists.libvirt.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, qemu-rust@nongnu.org, Paolo Bonzini , Markus Armbruster , Gerd Hoffmann , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Christian Schoenebeck , Richard Henderson Subject: [PATCH v6 20/27] util: don't skip error prefixes when QMP is active Date: Wed, 11 Feb 2026 15:25:01 +0000 Message-ID: <20260211152508.732487-21-berrange@redhat.com> In-Reply-To: <20260211152508.732487-1-berrange@redhat.com> References: <20260211152508.732487-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1770823788445158500 The vreport() function will print to HMP if available, otherwise to stderr. In the event that vreport() is called during execution of a QMP command, it will print to stderr, but mistakenly omit the message prefixes (timestamp, guest name, program name). This new usage of monitor_is_cur_qmp() from vreport() requires that we add a stub to satisfy linking of non-system emulator binaries. Signed-off-by: Daniel P. Berrang=C3=A9 --- stubs/monitor-core.c | 5 +++++ tests/unit/test-util-sockets.c | 1 + util/error-report.c | 8 ++++++++ 3 files changed, 14 insertions(+) diff --git a/stubs/monitor-core.c b/stubs/monitor-core.c index a7c32297c9..078a5012e9 100644 --- a/stubs/monitor-core.c +++ b/stubs/monitor-core.c @@ -7,6 +7,11 @@ Monitor *monitor_cur(void) return NULL; } =20 +bool monitor_cur_is_qmp(void) +{ + return false; +} + Monitor *monitor_set_cur(Coroutine *co, Monitor *mon) { return NULL; diff --git a/tests/unit/test-util-sockets.c b/tests/unit/test-util-sockets.c index ee66d727c3..b9f2453e29 100644 --- a/tests/unit/test-util-sockets.c +++ b/tests/unit/test-util-sockets.c @@ -74,6 +74,7 @@ int monitor_get_fd(Monitor *mon, const char *fdname, Erro= r **errp) Monitor *monitor_cur(void) { return cur_mon; } Monitor *monitor_set_cur(Coroutine *co, Monitor *mon) { abort(); } int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) { abort(); } +bool monitor_cur_is_qmp(void) { abort(); }; =20 #ifndef _WIN32 static void test_socket_fd_pass_name_good(void) diff --git a/util/error-report.c b/util/error-report.c index b34a2bc7bc..052f0f68b8 100644 --- a/util/error-report.c +++ b/util/error-report.c @@ -227,6 +227,14 @@ static void vreport(report_type type, const char *fmt,= va_list ap) Monitor *cur =3D monitor_cur(); gchar *timestr; =20 + /* + * When current monitor is QMP, messages must go to stderr + * and have prefixes added + */ + if (monitor_cur_is_qmp()) { + cur =3D NULL; + } + if (message_with_timestamp && !cur) { timestr =3D real_time_iso8601(); fprintf(stderr, "%s ", timestr); --=20 2.53.0 From nobody Thu Feb 12 11:50:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1770823857; cv=none; d=zohomail.com; s=zohoarc; b=eIXXt/ZbouQb4hDzhy2urz4bzEPtz43+BSEWWie/5164fAaEMqtPtkDpIi4R2wUSm0CUGTcPudcdBir1UqfcZo6e7Q96qofw0t1QBj8cwLyZNL6B1aPHgnwcLhXhlwl7pIqD0Xcws/NcYXWSolXMTKFmcDbU/Jx0XknguWg+MEw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770823857; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=skHP4pTjXRgohkxWEwFUDHKfYizotJdlGmYSDlwigUI=; b=JHc1uLa6z/ADdn7CtDHzt8BUBOk0rBAO386wsjsNzD03fUIjgaq3Uu244XrZodufemMEAxjRr/cY8KwLmlkuusILXyejlvBVRnuzEj48iqm7lXOKSaKB/zqlWCJ6VML9mNcHiER8I4BUwpZqTkP46o4r2bd1/28J1SIcAsAu5rc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770823857529669.4732595028144; Wed, 11 Feb 2026 07:30:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqC7t-0000FG-EC; Wed, 11 Feb 2026 10:27:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC7g-0007I6-EI for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:27:26 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC7c-00065Q-ET for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:27:24 -0500 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-456-BRL-aCMlN9G42B_0iH0fgw-1; Wed, 11 Feb 2026 10:27:17 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7E74D19560B0; Wed, 11 Feb 2026 15:27:15 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.227.9]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 84B7730002D5; Wed, 11 Feb 2026 15:27:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770823638; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=skHP4pTjXRgohkxWEwFUDHKfYizotJdlGmYSDlwigUI=; b=KLyVjVCuufTs2VTjqnbldpevtfoRFMbb9RKBCWZ/44gLPK8sL5qDGpc0z33MDMBTsrMRB7 CpDNjQ2ZLBakEc04a2+5w2yCb872mc8txX/Kc2YBTrsT3XQFDEGD/4HQRd3I9kCkal4ulk TjudKXYh8pi1meGW5AO5+ikqyoDau7I= X-MC-Unique: BRL-aCMlN9G42B_0iH0fgw-1 X-Mimecast-MFC-AGG-ID: BRL-aCMlN9G42B_0iH0fgw_1770823635 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Stefan Weil , "Dr. David Alan Gilbert" , Pierrick Bouvier , devel@lists.libvirt.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, qemu-rust@nongnu.org, Paolo Bonzini , Markus Armbruster , Gerd Hoffmann , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Christian Schoenebeck , Richard Henderson Subject: [PATCH v6 21/27] util: fix interleaving of error prefixes Date: Wed, 11 Feb 2026 15:25:02 +0000 Message-ID: <20260211152508.732487-22-berrange@redhat.com> In-Reply-To: <20260211152508.732487-1-berrange@redhat.com> References: <20260211152508.732487-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1770823859931154100 The vreport() function will optionally emit an prefix for error messages which is output to stderr incrementally. In the event that two vreport() calls execute concurrently, there is a risk that the prefix output will interleave. To address this it is required to take a lock on 'stderr' when outputting errors. Reported-by: Markus Armbruster Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson Reviewed-by: Markus Armbruster Signed-off-by: Daniel P. Berrang=C3=A9 --- util/error-report.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/util/error-report.c b/util/error-report.c index 052f0f68b8..516d323ffe 100644 --- a/util/error-report.c +++ b/util/error-report.c @@ -234,6 +234,9 @@ static void vreport(report_type type, const char *fmt, = va_list ap) if (monitor_cur_is_qmp()) { cur =3D NULL; } + if (!cur) { + qemu_flockfile(stderr); + } =20 if (message_with_timestamp && !cur) { timestr =3D real_time_iso8601(); @@ -261,6 +264,10 @@ static void vreport(report_type type, const char *fmt,= va_list ap) =20 error_vprintf_mon(cur, fmt, ap); error_printf_mon(cur, "\n"); + + if (!cur) { + qemu_funlockfile(stderr); + } } =20 /* --=20 2.53.0 From nobody Thu Feb 12 11:50:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1770823817; cv=none; d=zohomail.com; s=zohoarc; b=jfeM6QUENN5SB4USscg/ifGIVO7m5Gy3GqANpOsQRPtGIRDiBYKN90UWnmERE0+hV6GqswzJmb06TZhsli5qjAc9AUyQ8sDEHEc9NQuxnHqqDYN9Q4j3YbP5/PzKNyy/fCuS1AwcHunHNGbQj4wdEAQOOi0b0crX1ifNa1GLyJo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770823817; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=RiGWGV9XhBIRb2VM0sXbC17FuOi6rcqgCKWUsAo60bY=; b=O47VtCmT3HeD1fkS9wXbKeT7DIdPKoSz/fCyyIFB0Z3kNnAZiVU9otmJyXj1sKlLsXnJ6pH3PC9+PNHf3UQdItH5lqCizAT0xPO1DiP33uUautiwSJb2KM4IIKmxWSdWrFqvwzlbci/E4mkw4gVqgEijbm2PjI1qRZeQcyOyHdI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770823817646443.44146224572034; Wed, 11 Feb 2026 07:30:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqC7t-0000E8-Al; Wed, 11 Feb 2026 10:27:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC7n-00081T-MD for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:27:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC7k-00067Y-F3 for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:27:31 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-144-7-6718ePMXO4T7KlgIQrfQ-1; Wed, 11 Feb 2026 10:27:23 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B16DA180047F; Wed, 11 Feb 2026 15:27:21 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.227.9]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EF96130001A8; Wed, 11 Feb 2026 15:27:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770823647; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RiGWGV9XhBIRb2VM0sXbC17FuOi6rcqgCKWUsAo60bY=; b=YTU/h2w1dEkaITwmtFwK7iQ/PUAY2SNx5HaMAgo4HEtuaoDMzSkl2NV5vagYu/XZTk1vWZ rJ8bIwaQCXL6NkUtp300M4Z/zm6LxvvVRniV3a3tRPi7P0yOkND663vx8auYhO42PC7j8o SsyUJeJ6RDmyWMTUMyKGync0cWW+Os0= X-MC-Unique: 7-6718ePMXO4T7KlgIQrfQ-1 X-Mimecast-MFC-AGG-ID: 7-6718ePMXO4T7KlgIQrfQ_1770823641 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Stefan Weil , "Dr. David Alan Gilbert" , Pierrick Bouvier , devel@lists.libvirt.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, qemu-rust@nongnu.org, Paolo Bonzini , Markus Armbruster , Gerd Hoffmann , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Christian Schoenebeck , Richard Henderson Subject: [PATCH v6 22/27] util: introduce common helper for error-report & log code Date: Wed, 11 Feb 2026 15:25:03 +0000 Message-ID: <20260211152508.732487-23-berrange@redhat.com> In-Reply-To: <20260211152508.732487-1-berrange@redhat.com> References: <20260211152508.732487-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1770823818672158500 The error-report and log code both have a need to add prefixes to messages they are printing, with the current example being a timestamp. The format and configuration they use should be consistent, so providing a common helper will ensure this is always the case. Initially the helper only emits a timestamp, but future patches will expand this. This takes the liberty of assigning the new file to the same maintainer as the existing error-report.c file, given it will be extracting some functionality from the latter. While vreport() dynamically changes between reporting to the monitor vs stderr, depending on whether HMP is active or not, message prefixes are only ever used in the non-HMP case. Thus the helper API can take a FILE * object and not have to deal with the monitor at all. Reviewed-by: Richard Henderson Signed-off-by: Daniel P. Berrang=C3=A9 --- MAINTAINERS | 2 ++ include/qemu/message.h | 28 ++++++++++++++++++++++++++++ util/meson.build | 1 + util/message.c | 23 +++++++++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 include/qemu/message.h create mode 100644 util/message.c diff --git a/MAINTAINERS b/MAINTAINERS index 29f88d48f3..96a4ce438e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3261,9 +3261,11 @@ M: Markus Armbruster S: Supported F: include/qapi/error.h F: include/qemu/error-report.h +F: include/qemu/message.h F: qapi/error.json F: util/error.c F: util/error-report.c +F: util/message.c F: scripts/coccinelle/err-bad-newline.cocci F: scripts/coccinelle/error-use-after-free.cocci F: scripts/coccinelle/error_propagate_null.cocci diff --git a/include/qemu/message.h b/include/qemu/message.h new file mode 100644 index 0000000000..0a06421f77 --- /dev/null +++ b/include/qemu/message.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#ifndef QEMU_MESSAGE_H +#define QEMU_MESSAGE_H + +enum QMessageFormatFlags { + QMESSAGE_FORMAT_TIMESTAMP =3D (1 << 0), +}; + +/** + * qmessage_set_format: + * @flags: the message information to emit + * + * Select which pieces of information to + * emit for messages + */ +void qmessage_set_format(int flags); + +/** + * qmessage_context_print: + * @fp: file to emit the prefix on + * + * Emit a message prefix with the information selected by + * an earlier call to qmessage_set_format. + */ +void qmessage_context_print(FILE *fp); + +#endif /* QEMU_MESSAGE_H */ diff --git a/util/meson.build b/util/meson.build index 7c9445615d..3035bd4bee 100644 --- a/util/meson.build +++ b/util/meson.build @@ -38,6 +38,7 @@ util_ss.add(files('host-utils.c')) util_ss.add(files('bitmap.c', 'bitops.c')) util_ss.add(files('fifo8.c')) util_ss.add(files('cacheflush.c')) +util_ss.add(files('message.c')) util_ss.add(files('error.c', 'error-report.c')) util_ss.add(files('qemu-print.c')) util_ss.add(files('id.c')) diff --git a/util/message.c b/util/message.c new file mode 100644 index 0000000000..99a403f9d0 --- /dev/null +++ b/util/message.c @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "qemu/osdep.h" + +#include "qemu/message.h" +#include "monitor/monitor.h" + +static int message_format; + +void qmessage_set_format(int flags) +{ + message_format =3D flags; +} + +void qmessage_context_print(FILE *fp) +{ + if (message_format & QMESSAGE_FORMAT_TIMESTAMP) { + g_autoptr(GDateTime) dt =3D g_date_time_new_now_utc(); + g_autofree char *timestr =3D g_date_time_format_iso8601(dt); + fputs(timestr, fp); + fputc(' ', fp); + } +} --=20 2.53.0 From nobody Thu Feb 12 11:50:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1770823887; cv=none; d=zohomail.com; s=zohoarc; b=NNPMjADfFUOa/hVNrpcqhVvSRvdmyqx69H028OBoe09XRAR6SPCfjZn4miaD96vA95cULDST62d/f/FkPaRAjsWscK0z/t2v6YZsM1Aa2SGSa4ZlHYGTzaGwUT0cmy2KuehgvYwksxNdKFBepi+SCgOaxXjK+SxLGUJnn4JmodE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770823887; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=kkoiLQEbFC048zZDPRGr8W03GXiPCxPb5ynydGF78mE=; b=DXP6W/63DFuVzXnfSmcbqwBP4I90gg8i5JNMEW7F6GjrLYdHbIgbSvZvbEgeIKpL/rgoipkhh4cV0Cryku1UveOEo9QAZ+Mz2vQ7MNbiUOE68D+vULMWPPheF4rSjhreL074//Et9jbY3LkwJmXL88AjvwPlW0Xe68UaubltfhY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770823887374870.6803539561213; Wed, 11 Feb 2026 07:31:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqC7u-0000Na-DY; Wed, 11 Feb 2026 10:27:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC7q-0008Lx-Q6 for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:27:34 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC7o-00068W-QA for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:27:34 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-550-FNvOBfwkOxWRYlS6u_bf6A-1; Wed, 11 Feb 2026 10:27:28 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F371E1800367; Wed, 11 Feb 2026 15:27:26 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.227.9]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2A71430001A8; Wed, 11 Feb 2026 15:27:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770823651; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kkoiLQEbFC048zZDPRGr8W03GXiPCxPb5ynydGF78mE=; b=dNt8eEvQAPyKxvGuN8zzqohYoVk+X+turWrBpJvhfz1BK+cuVgdPfJI5S6GtyEvpNmv9Pc XrlSzAwzf9vfB/1RogGVwhDIOL98TBiZif6H9l2cE42ZDQkS6vx43/JKnj+yuWI/K0/bG9 R8ND4o6vX6OEJlA4yJH4X383EfirpBI= X-MC-Unique: FNvOBfwkOxWRYlS6u_bf6A-1 X-Mimecast-MFC-AGG-ID: FNvOBfwkOxWRYlS6u_bf6A_1770823647 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Stefan Weil , "Dr. David Alan Gilbert" , Pierrick Bouvier , devel@lists.libvirt.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, qemu-rust@nongnu.org, Paolo Bonzini , Markus Armbruster , Gerd Hoffmann , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Christian Schoenebeck , Richard Henderson Subject: [PATCH v6 23/27] util: convert error-report & log to message API for timestamp Date: Wed, 11 Feb 2026 15:25:04 +0000 Message-ID: <20260211152508.732487-24-berrange@redhat.com> In-Reply-To: <20260211152508.732487-1-berrange@redhat.com> References: <20260211152508.732487-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1770823889175158501 Both the error-report and log APIs can optional emit a timestamp as a prefix on messages, with the '-msg timestamp=3Don' command line flag is set. Convert them to the new message API for formatting the context prefix, guaranteeing they will have matching behaviour going forward. There is no change in output format for either logs or errors with this conversion. There is a slight impact on logging code in that recording the timestamp is now potentially delayed by the need to acquire the logging mutex. Reviewed-by: Richard Henderson Signed-off-by: Daniel P. Berrang=C3=A9 --- include/qemu/error-report.h | 1 - system/vl.c | 7 ++++++- tests/unit/test-error-report.c | 3 ++- util/error-report.c | 18 ++---------------- util/log.c | 8 +++----- 5 files changed, 13 insertions(+), 24 deletions(-) diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h index 3ae2357fda..c8000778ec 100644 --- a/include/qemu/error-report.h +++ b/include/qemu/error-report.h @@ -70,7 +70,6 @@ void error_init(const char *argv0); fmt, ##__VA_ARGS__); \ }) =20 -extern bool message_with_timestamp; extern bool error_with_guestname; extern const char *error_guest_name; =20 diff --git a/system/vl.c b/system/vl.c index d8676b3adf..4ef41df747 100644 --- a/system/vl.c +++ b/system/vl.c @@ -26,6 +26,7 @@ #include "qemu/help-texts.h" #include "qemu/datadir.h" #include "qemu/units.h" +#include "qemu/message.h" #include "qemu/module.h" #include "qemu/target-info.h" #include "exec/cpu-common.h" @@ -818,8 +819,12 @@ static void realtime_init(void) =20 static void configure_msg(QemuOpts *opts) { - message_with_timestamp =3D qemu_opt_get_bool(opts, "timestamp", false); + int flags =3D 0; + if (qemu_opt_get_bool(opts, "timestamp", false)) { + flags |=3D QMESSAGE_FORMAT_TIMESTAMP; + } error_with_guestname =3D qemu_opt_get_bool(opts, "guest-name", false); + qmessage_set_format(flags); } =20 =20 diff --git a/tests/unit/test-error-report.c b/tests/unit/test-error-report.c index a8532fc58f..9c63019694 100644 --- a/tests/unit/test-error-report.c +++ b/tests/unit/test-error-report.c @@ -12,6 +12,7 @@ =20 #include "qemu/error-report.h" #include "qapi/error.h" +#include "qemu/message.h" =20 static void test_error_report_simple(void) @@ -89,7 +90,7 @@ static void test_error_report_timestamp(void) { if (g_test_subprocess()) { - message_with_timestamp =3D true; + qmessage_set_format(QMESSAGE_FORMAT_TIMESTAMP); warn_report("warn"); error_report("err"); return; diff --git a/util/error-report.c b/util/error-report.c index 516d323ffe..1ef65a7475 100644 --- a/util/error-report.c +++ b/util/error-report.c @@ -13,6 +13,7 @@ #include "qemu/osdep.h" #include "monitor/monitor.h" #include "qemu/error-report.h" +#include "qemu/message.h" =20 /* * @report_type is the type of message: error, warning or @@ -24,8 +25,6 @@ typedef enum { REPORT_TYPE_INFO, } report_type; =20 -/* Prepend timestamp to messages */ -bool message_with_timestamp; bool error_with_guestname; const char *error_guest_name; =20 @@ -207,13 +206,6 @@ static void print_loc(Monitor *cur) } } =20 -static char * -real_time_iso8601(void) -{ - g_autoptr(GDateTime) dt =3D g_date_time_new_now_utc(); - return g_date_time_format_iso8601(dt); -} - /* * Print a message to current monitor if we have one, else to stderr. * @report_type is the type of message: error, warning or informational. @@ -225,7 +217,6 @@ G_GNUC_PRINTF(2, 0) static void vreport(report_type type, const char *fmt, va_list ap) { Monitor *cur =3D monitor_cur(); - gchar *timestr; =20 /* * When current monitor is QMP, messages must go to stderr @@ -236,12 +227,7 @@ static void vreport(report_type type, const char *fmt,= va_list ap) } if (!cur) { qemu_flockfile(stderr); - } - - if (message_with_timestamp && !cur) { - timestr =3D real_time_iso8601(); - fprintf(stderr, "%s ", timestr); - g_free(timestr); + qmessage_context_print(stderr); } =20 /* Only prepend guest name if -msg guest-name and -name guest=3D... ar= e set */ diff --git a/util/log.c b/util/log.c index 1c9c7adb2d..b5aae22c83 100644 --- a/util/log.c +++ b/util/log.c @@ -22,6 +22,7 @@ #include "qemu/range.h" #include "qemu/error-report.h" #include "qapi/error.h" +#include "qemu/message.h" #include "qemu/cutils.h" #include "trace/control.h" #include "qemu/thread.h" @@ -148,11 +149,8 @@ FILE *qemu_log_trylock(void) FILE *qemu_log_trylock_with_context(void) { FILE *f =3D qemu_log_trylock(); - if (f && log_depth =3D=3D 1 && message_with_timestamp) { - g_autofree const char *timestr =3D NULL; - g_autoptr(GDateTime) dt =3D g_date_time_new_now_utc(); - timestr =3D g_date_time_format_iso8601(dt); - fprintf(f, "%s ", timestr); + if (f && log_depth =3D=3D 1) { + qmessage_context_print(f); } return f; } --=20 2.53.0 From nobody Thu Feb 12 11:50:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1770823903; cv=none; d=zohomail.com; s=zohoarc; b=W4XPmT6KTiW3/E+Ofol7Q5HUOoVwe1F7ZYDVCIytrMmzcQLzXoqcAS4wMWlIk80Qyrg4niVuhpENGF9HoLmUUO0u7r4HwQoR3tvWD9Tsa3sFB9wQ770gN3DfHlUSjftpzbqZITT2qexaWFW5t9VMgaSKwqcH/agzygCfz0KnOM8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770823903; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Ife0kgX5LU9dVRlkos1BTWzRMejsgLQmrReuIHPiUu8=; b=UK1gEJQHuhbBifvAQ4QqeSfLVXbkt9BTy+Pzy8TNs7eEwAnWXqiDrZk42c3/juk4OamCog7JvFCHHvnRJFvg9t4rIzlH7SQlbBfadZs/SeDayE+4RliO/10lNc+FfLxdRWsy2RQ9fjiWVnDby5V4Fq2l4twOYN9/VqVrMpGmCRA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 177082390333157.93272104919595; Wed, 11 Feb 2026 07:31:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqC7x-0000wG-1r; Wed, 11 Feb 2026 10:27:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC7v-0000jk-Tt for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:27:39 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC7t-0006Af-Vp for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:27:39 -0500 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-322-0HSJ2GshM8evB-fM57QhBg-1; Wed, 11 Feb 2026 10:27:34 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6F6A819560B9; Wed, 11 Feb 2026 15:27:32 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.227.9]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 705C430001A8; Wed, 11 Feb 2026 15:27:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770823657; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ife0kgX5LU9dVRlkos1BTWzRMejsgLQmrReuIHPiUu8=; b=NN1mCbSpNqaXhyw9BD9BazMsAL8Ex8RbQKT1K/4s3VmNcWyDjI9/nni5Vo0B7H+8vIeiIE zO1JrKdpUb0CO6vcel2UIAX0Sq+1gYDXQypLqqKvfiLdfMztR1RdsaqkY7Z3FoqZF8J3Db SyoPw9ajOJ/rf0KIIbpCGgfGdIHu638= X-MC-Unique: 0HSJ2GshM8evB-fM57QhBg-1 X-Mimecast-MFC-AGG-ID: 0HSJ2GshM8evB-fM57QhBg_1770823652 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Stefan Weil , "Dr. David Alan Gilbert" , Pierrick Bouvier , devel@lists.libvirt.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, qemu-rust@nongnu.org, Paolo Bonzini , Markus Armbruster , Gerd Hoffmann , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Christian Schoenebeck , Richard Henderson Subject: [PATCH v6 24/27] util: add support for formatting a workload name in messages Date: Wed, 11 Feb 2026 15:25:05 +0000 Message-ID: <20260211152508.732487-25-berrange@redhat.com> In-Reply-To: <20260211152508.732487-1-berrange@redhat.com> References: <20260211152508.732487-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1770823905210158500 The error_report function can include the guest name in any messages it prints. The qemu_log function has no equivalent behaviour. This introduces support for a "workload name" in the new messages API, which in the case of system emulators will be the guest name. The possibility of defining a workload name for other binaries is left as an exercise for the future. This change has no impact on the output of the error_report function, but will change the qemu_log function. This can be easily seen with the 'log' trace backend, and how it is now more closely matching error_report output. Before: # qemu-system-x86_64 -msg guest-name=3Don -name blah -object tls-creds-x5= 09,id=3Dt0,dir=3Dfish -d 'trace:qcrypto*' qcrypto_tls_creds_x509_load TLS creds x509 load creds=3D0x55b3af3fd870 di= r=3Dfish qcrypto_tls_creds_get_path TLS creds path creds=3D0x55b3af3fd870 filename= =3Dca-cert.pem path=3D blah qemu-system-x86_64: Unable to access credentials fish/ca-cert.pem: N= o such file or directory After: # qemu-system-x86_64 -msg guest-name=3Don -name blah -object tls-creds-x5= 09,id=3Dt0,dir=3Dfish -d 'trace:qcrypto*' blah qcrypto_tls_creds_x509_load TLS creds x509 load creds=3D0x55b3af3fd8= 70 dir=3Dfish blah qcrypto_tls_creds_get_path TLS creds path creds=3D0x55b3af3fd870 fil= ename=3Dca-cert.pem path=3D blah qemu-system-x86_64: Unable to access credentials fish/ca-cert.pem: N= o such file or directory Reviewed-by: Richard Henderson Signed-off-by: Daniel P. Berrang=C3=A9 --- include/qemu/error-report.h | 3 --- include/qemu/message.h | 10 ++++++++++ system/vl.c | 6 ++++-- util/error-report.c | 7 ------- util/message.c | 12 ++++++++++++ 5 files changed, 26 insertions(+), 12 deletions(-) diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h index c8000778ec..ffc305f828 100644 --- a/include/qemu/error-report.h +++ b/include/qemu/error-report.h @@ -70,7 +70,4 @@ void error_init(const char *argv0); fmt, ##__VA_ARGS__); \ }) =20 -extern bool error_with_guestname; -extern const char *error_guest_name; - #endif diff --git a/include/qemu/message.h b/include/qemu/message.h index 0a06421f77..cfc3c92648 100644 --- a/include/qemu/message.h +++ b/include/qemu/message.h @@ -5,6 +5,7 @@ =20 enum QMessageFormatFlags { QMESSAGE_FORMAT_TIMESTAMP =3D (1 << 0), + QMESSAGE_FORMAT_WORKLOAD_NAME =3D (1 << 1), }; =20 /** @@ -16,6 +17,15 @@ enum QMessageFormatFlags { */ void qmessage_set_format(int flags); =20 +/** + * qmessage_set_workload_name: + * @name: the name of the workload + * + * Set the workload name, which for a system emulator + * will be the guest VM name. + */ +void qmessage_set_workload_name(const char *name); + /** * qmessage_context_print: * @fp: file to emit the prefix on diff --git a/system/vl.c b/system/vl.c index 4ef41df747..be5862e55e 100644 --- a/system/vl.c +++ b/system/vl.c @@ -823,7 +823,9 @@ static void configure_msg(QemuOpts *opts) if (qemu_opt_get_bool(opts, "timestamp", false)) { flags |=3D QMESSAGE_FORMAT_TIMESTAMP; } - error_with_guestname =3D qemu_opt_get_bool(opts, "guest-name", false); + if (qemu_opt_get_bool(opts, "guest-name", false)) { + flags |=3D QMESSAGE_FORMAT_WORKLOAD_NAME; + } qmessage_set_format(flags); } =20 @@ -3526,7 +3528,7 @@ void qemu_init(int argc, char **argv) exit(1); } /* Capture guest name if -msg guest-name is used later */ - error_guest_name =3D qemu_opt_get(opts, "guest"); + qmessage_set_workload_name(qemu_opt_get(opts, "guest")); break; case QEMU_OPTION_prom_env: if (nb_prom_envs >=3D MAX_PROM_ENVS) { diff --git a/util/error-report.c b/util/error-report.c index 1ef65a7475..3009b93c23 100644 --- a/util/error-report.c +++ b/util/error-report.c @@ -25,8 +25,6 @@ typedef enum { REPORT_TYPE_INFO, } report_type; =20 -bool error_with_guestname; -const char *error_guest_name; =20 /* * Print to the current human monitor if we have one, else to stderr. @@ -230,11 +228,6 @@ static void vreport(report_type type, const char *fmt,= va_list ap) qmessage_context_print(stderr); } =20 - /* Only prepend guest name if -msg guest-name and -name guest=3D... ar= e set */ - if (error_with_guestname && error_guest_name && !cur) { - fprintf(stderr, "%s ", error_guest_name); - } - print_loc(cur); =20 switch (type) { diff --git a/util/message.c b/util/message.c index 99a403f9d0..fb2c947153 100644 --- a/util/message.c +++ b/util/message.c @@ -6,12 +6,18 @@ #include "monitor/monitor.h" =20 static int message_format; +static char *message_workloadname; =20 void qmessage_set_format(int flags) { message_format =3D flags; } =20 +void qmessage_set_workload_name(const char *name) +{ + message_workloadname =3D g_strdup(name); +} + void qmessage_context_print(FILE *fp) { if (message_format & QMESSAGE_FORMAT_TIMESTAMP) { @@ -20,4 +26,10 @@ void qmessage_context_print(FILE *fp) fputs(timestr, fp); fputc(' ', fp); } + + if ((message_format & QMESSAGE_FORMAT_WORKLOAD_NAME) && + message_workloadname) { + fputs(message_workloadname, fp); + fputc(' ', fp); + } } --=20 2.53.0 From nobody Thu Feb 12 11:50:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1770823761; cv=none; d=zohomail.com; s=zohoarc; b=nR1AYhpSKFXkKWFG7MRSEuT82UH/xOiejBQAsxFWccOkyBcbNiRDBiIrmz7U1BNMru3cx2a3/UoYHfy0xITxXXpo+iJlwEFHTyuSKvssh8TdsS+WZx838Pvtx+4+hqjH9Kn5ms1hdzmwbLOMlv0XdebTdKr7dwMVJZyusZw+uPM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770823761; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=YwhZVny6ANCAea7yxq04kQyFzA8sSOUNU+TBc2DZGz8=; b=Kg9ng/G9g2vwnBkQwYoB4iis+/EtBit20cNN0H/wtKI7bdalyn+TPP61UvxXsy8ZjKWUcE8VPpNFZMfu5FIZ5yKx/Yuuj6lB3Rd1o9Qhgrjv/mQHdWWU5sq5x6++CIH88lEVw5UXhhNqfN15/hGkHx4Gjl4qhpO5+YTadhWCADc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770823761241912.1440981107512; Wed, 11 Feb 2026 07:29:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqC83-0001iH-Oi; Wed, 11 Feb 2026 10:27:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC80-0001NZ-Ut for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:27:44 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC7y-0006CC-TI for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:27:44 -0500 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-653-Jhah7hOSPkajzZak78C0cA-1; Wed, 11 Feb 2026 10:27:40 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DDB9019560B7; Wed, 11 Feb 2026 15:27:37 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.227.9]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DEC8230001A8; Wed, 11 Feb 2026 15:27:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770823662; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YwhZVny6ANCAea7yxq04kQyFzA8sSOUNU+TBc2DZGz8=; b=SXom4KvkE1fH+GvUMGJ5XvMktLHZiCUmKMDzMLJ/BMO3TE5pyle1GHmolU9A37QkRCv1/V NR0tFWRJo8kDCax1LGnAU9yuGTK25n8GGT4f77ZKAMFy3jF7sttbU/1Lij6+z0gYrfh0DY tSRGDurr++6oN1QhJEfCQlH7gEFNfk4= X-MC-Unique: Jhah7hOSPkajzZak78C0cA-1 X-Mimecast-MFC-AGG-ID: Jhah7hOSPkajzZak78C0cA_1770823658 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Stefan Weil , "Dr. David Alan Gilbert" , Pierrick Bouvier , devel@lists.libvirt.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, qemu-rust@nongnu.org, Paolo Bonzini , Markus Armbruster , Gerd Hoffmann , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Christian Schoenebeck , Richard Henderson Subject: [PATCH v6 25/27] util: add support for formatting a program name in messages Date: Wed, 11 Feb 2026 15:25:06 +0000 Message-ID: <20260211152508.732487-26-berrange@redhat.com> In-Reply-To: <20260211152508.732487-1-berrange@redhat.com> References: <20260211152508.732487-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1770823762488154100 The error_report function can include the program name in any messages it prints. The qemu_log function has no equivalent behaviour. This introduces support for a "program name" in the new messages API, which will be included by default for all binaries. This change tweaks the output of the error_report function, adding a space between the program name and the location info. The qemu_log function will gain the program name. This can be easily seen with the 'log' trace backend, and how it is now more closely matching error_report output. Before: # qemu-system-x86_64 -object tls-creds-x509,id=3Dt0,dir=3Dfish -d 'trace:= qcrypto*' qcrypto_tls_creds_x509_load TLS creds x509 load creds=3D0x5584e13937f0 di= r=3Dfish qcrypto_tls_creds_get_path TLS creds path creds=3D0x5584e13937f0 filename= =3Dca-cert.pem path=3D qemu-system-x86_64: Unable to access credentials fish/ca-cert.pem: No suc= h file or directory After: # qemu-system-x86_64 -object tls-creds-x509,id=3Dt0,dir=3Dfish -d 'trace:= qcrypto*' qemu-system-x86_64: qcrypto_tls_creds_x509_load TLS creds x509 load creds= =3D0x5584e13937f0 dir=3Dfish qemu-system-x86_64: qcrypto_tls_creds_get_path TLS creds path creds=3D0x5= 584e13937f0 filename=3Dca-cert.pem path=3D qemu-system-x86_64: Unable to access credentials fish/ca-cert.pem: No suc= h file or directory When adding this the '-msg program-name=3Don|off' option is introduced, so that the program name (which is enabled by default) can be supressed if desired. This could be useful if '-msg guest-name=3Don' is being used as a more informative identifier. Reviewed-by: Richard Henderson Signed-off-by: Daniel P. Berrang=C3=A9 --- include/qemu/message.h | 1 + qemu-options.hx | 9 +++++++-- system/vl.c | 11 ++++++++++- tests/unit/test-error-report.c | 5 +++-- util/error-report.c | 4 ---- util/message.c | 10 +++++++++- 6 files changed, 30 insertions(+), 10 deletions(-) diff --git a/include/qemu/message.h b/include/qemu/message.h index cfc3c92648..b8518d06be 100644 --- a/include/qemu/message.h +++ b/include/qemu/message.h @@ -6,6 +6,7 @@ enum QMessageFormatFlags { QMESSAGE_FORMAT_TIMESTAMP =3D (1 << 0), QMESSAGE_FORMAT_WORKLOAD_NAME =3D (1 << 1), + QMESSAGE_FORMAT_PROGRAM_NAME =3D (1 << 2), }; =20 /** diff --git a/qemu-options.hx b/qemu-options.hx index cdb7fa20c2..84dcbb0983 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -5515,13 +5515,15 @@ ERST =20 DEF("msg", HAS_ARG, QEMU_OPTION_msg, "-msg [timestamp=3Don|off][,guest-name=3Don|off]\n" + " [,program-name=3Don|off]\n" " control error message format\n" " timestamp=3Don enables timestamps (default: off)\n" " guest-name=3Don enables guest name prefix but only if= \n" - " -name guest option is set (default: off= )\n", + " -name guest option is set (default: off= )\n" + " program-name=3Doff disables program name prefix (defa= ult: on)\n", QEMU_ARCH_ALL) SRST -``-msg [timestamp=3Don|off][,guest-name=3Don|off]`` +``-msg [timestamp=3Don|off][,guest-name=3Don|off][,program-name=3Don|off]`` Control error message format. =20 ``timestamp=3Don|off`` @@ -5530,6 +5532,9 @@ SRST ``guest-name=3Don|off`` Prefix messages with guest name but only if -name guest option is = set otherwise the option is ignored. Default is off. + + ``program-name=3Don|off`` + Prefix messages with the program name. Default is on. ERST =20 DEF("dump-vmstate", HAS_ARG, QEMU_OPTION_dump_vmstate, diff --git a/system/vl.c b/system/vl.c index be5862e55e..3e79bf47e0 100644 --- a/system/vl.c +++ b/system/vl.c @@ -381,6 +381,12 @@ static QemuOptsList qemu_msg_opts =3D { .help =3D "Prepends guest name for error messages but only if " "-name guest is set otherwise option is ignored\n", }, + { + .name =3D "program-name", + .type =3D QEMU_OPT_BOOL, + .help =3D "Prepends program name for error messages (enabled " + "by default)\n", + }, { /* end of list */ } }, }; @@ -819,13 +825,16 @@ static void realtime_init(void) =20 static void configure_msg(QemuOpts *opts) { - int flags =3D 0; + int flags =3D QMESSAGE_FORMAT_PROGRAM_NAME; if (qemu_opt_get_bool(opts, "timestamp", false)) { flags |=3D QMESSAGE_FORMAT_TIMESTAMP; } if (qemu_opt_get_bool(opts, "guest-name", false)) { flags |=3D QMESSAGE_FORMAT_WORKLOAD_NAME; } + if (!qemu_opt_get_bool(opts, "program-name", true)) { + flags &=3D ~QMESSAGE_FORMAT_PROGRAM_NAME; + } qmessage_set_format(flags); } =20 diff --git a/tests/unit/test-error-report.c b/tests/unit/test-error-report.c index 9c63019694..714eafc51e 100644 --- a/tests/unit/test-error-report.c +++ b/tests/unit/test-error-report.c @@ -47,7 +47,7 @@ test_error_report_loc(void) g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_passed(); g_test_trap_assert_stderr("\ -test-error-report:some-file.c:7717: test error1*\ +test-error-report: some-file.c:7717: test error1*\ test-error-report: test error2*\ "); } @@ -90,7 +90,8 @@ static void test_error_report_timestamp(void) { if (g_test_subprocess()) { - qmessage_set_format(QMESSAGE_FORMAT_TIMESTAMP); + qmessage_set_format(QMESSAGE_FORMAT_TIMESTAMP | + QMESSAGE_FORMAT_PROGRAM_NAME); warn_report("warn"); error_report("err"); return; diff --git a/util/error-report.c b/util/error-report.c index 3009b93c23..196d51618c 100644 --- a/util/error-report.c +++ b/util/error-report.c @@ -179,10 +179,6 @@ static void print_loc(Monitor *cur) int i; const char *const *argp; =20 - if (!cur && g_get_prgname()) { - fprintf(stderr, "%s:", g_get_prgname()); - sep =3D " "; - } switch (cur_loc->kind) { case LOC_CMDLINE: argp =3D cur_loc->ptr; diff --git a/util/message.c b/util/message.c index fb2c947153..dd01bf7462 100644 --- a/util/message.c +++ b/util/message.c @@ -5,7 +5,7 @@ #include "qemu/message.h" #include "monitor/monitor.h" =20 -static int message_format; +static int message_format =3D QMESSAGE_FORMAT_PROGRAM_NAME; static char *message_workloadname; =20 void qmessage_set_format(int flags) @@ -32,4 +32,12 @@ void qmessage_context_print(FILE *fp) fputs(message_workloadname, fp); fputc(' ', fp); } + + if (message_format & QMESSAGE_FORMAT_PROGRAM_NAME) { + const char *pgnamestr =3D g_get_prgname(); + if (pgnamestr) { + fputs(pgnamestr, fp); + fputs(": ", fp); + } + } } --=20 2.53.0 From nobody Thu Feb 12 11:50:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1770823791; cv=none; d=zohomail.com; s=zohoarc; b=CrfG/64j5cSMKj5RGQKbCqa39hOvhDMDFzZxZjjGFbWL7ukTVR3Ub1KJsQcv44dtLsmuVd5SOjAo9t+kjetkkVHctDz71ZoCMuw36WtLMA+G0Nl8lc34cbB6EaeNfa78416QxzBTE4SE9P+NtPtL8cBXwS4UCGouu0zyM7+9Dg4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770823791; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=JQpBBosBc75GeSIQlXLH7SixAcsChLt5pjUJzSan8Nc=; b=mIVzAVOQl14WMJY6vlII0nwLE9OL6MtWM29eQJegPU1+RV1cFc44GNlc/qtt7GYymG/2vNVt4SOzqTEK0PA3C9eR3wxE7o3/+wNSPMM48FXg174IjNlaMvuC8XgIcCRlAyZ7Dfhvs9SwCgoZcstkjNhTgjkI9o7fv+RmAAgHoi8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770823791313827.8384521508088; Wed, 11 Feb 2026 07:29:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqC89-0002a2-25; Wed, 11 Feb 2026 10:27:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC87-0002Eg-9f for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:27:51 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC84-0006DF-Ub for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:27:50 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-642-CJKlBn5tO3GyRuDNLhNnTA-1; Wed, 11 Feb 2026 10:27:45 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 373641800605; Wed, 11 Feb 2026 15:27:43 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.227.9]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5891B30001A8; Wed, 11 Feb 2026 15:27:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770823668; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JQpBBosBc75GeSIQlXLH7SixAcsChLt5pjUJzSan8Nc=; b=AkGvzwJIYdIBZOJ1d5iheqWrfysrBnf6Q5ooPNAYaKLQnCeZNQBWN2NXiSRdQljlVEQID6 2nfbUYWO/QCbVIMBxZGGGuPFH6wCn3I1xn4NLaxNf/WN5zkW/XtlcV+le8e5ggA18vHeAH pOmgaNaArHAMnn2jOxfItILXQ0io4c4= X-MC-Unique: CJKlBn5tO3GyRuDNLhNnTA-1 X-Mimecast-MFC-AGG-ID: CJKlBn5tO3GyRuDNLhNnTA_1770823663 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Stefan Weil , "Dr. David Alan Gilbert" , Pierrick Bouvier , devel@lists.libvirt.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, qemu-rust@nongnu.org, Paolo Bonzini , Markus Armbruster , Gerd Hoffmann , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Christian Schoenebeck , Richard Henderson Subject: [PATCH v6 26/27] util: add support for formatting thread info in messages Date: Wed, 11 Feb 2026 15:25:07 +0000 Message-ID: <20260211152508.732487-27-berrange@redhat.com> In-Reply-To: <20260211152508.732487-1-berrange@redhat.com> References: <20260211152508.732487-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1770823793258154100 The message context is now extended to be able to include the thread ID and thread name, after the program name. On Linux the thread ID will match the process TID visible in /proc, while on other platforms it will merely be an integer repr of the system thread object address/ID. This changes the output for both error_report and qemu_log, when running under the system emulators or the QEMU storage daemon. Other programs omit the thread information since they are largely single threaded, though potentially it would be useful to enable in all of them, given that the RCU thread will always get spawned by a constructor function. Before: # qemu-system-x86_64 -object tls-creds-x509,id=3Dt0,dir=3Dfish -d 'trace:= qcrypto*' qemu-system-x86_64: qcrypto_tls_creds_x509_load TLS creds x509 load creds= =3D0x560db818e080 dir=3Dfish qemu-system-x86_64: qcrypto_tls_creds_get_path TLS creds path creds=3D0x5= 60db818e080 filename=3Dca-cert.pem path=3D qemu-system-x86_64: Unable to access credentials fish/ca-cert.pem: No suc= h file or directory After: # qemu-system-x86_64 -object tls-creds-x509,id=3Dt0,dir=3Dfish -d 'trace:= qcrypto*' qemu-system-x86_64: (772366:main): qcrypto_tls_creds_x509_load TLS creds = x509 load creds=3D0x560db818e080 dir=3Dfish qemu-system-x86_64: (772366:main): qcrypto_tls_creds_get_path TLS creds p= ath creds=3D0x560db818e080 filename=3Dca-cert.pem path=3D qemu-system-x86_64: (772366:main): Unable to access credentials fish/ca-c= ert.pem: No such file or directory The '-msg thread-info=3Don|off' argument is introduced to allow this new default output to be supressed if desired. Reviewed-by: Richard Henderson Signed-off-by: Daniel P. Berrang=C3=A9 --- include/qemu/message.h | 1 + qemu-options.hx | 10 +++++++--- storage-daemon/qemu-storage-daemon.c | 6 ++++++ system/vl.c | 17 +++++++++++++++-- tests/qemu-iotests/041 | 2 +- tests/qemu-iotests/common.filter | 2 +- util/message.c | 7 +++++++ 7 files changed, 38 insertions(+), 7 deletions(-) diff --git a/include/qemu/message.h b/include/qemu/message.h index b8518d06be..2cc092c993 100644 --- a/include/qemu/message.h +++ b/include/qemu/message.h @@ -7,6 +7,7 @@ enum QMessageFormatFlags { QMESSAGE_FORMAT_TIMESTAMP =3D (1 << 0), QMESSAGE_FORMAT_WORKLOAD_NAME =3D (1 << 1), QMESSAGE_FORMAT_PROGRAM_NAME =3D (1 << 2), + QMESSAGE_FORMAT_THREAD_INFO =3D (1 << 3), }; =20 /** diff --git a/qemu-options.hx b/qemu-options.hx index 84dcbb0983..50cbecc7d7 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -5515,15 +5515,16 @@ ERST =20 DEF("msg", HAS_ARG, QEMU_OPTION_msg, "-msg [timestamp=3Don|off][,guest-name=3Don|off]\n" - " [,program-name=3Don|off]\n" + " [,program-name=3Don|off][,thread-info=3Don|off]\n" " control error message format\n" " timestamp=3Don enables timestamps (default: off)\n" " guest-name=3Don enables guest name prefix but only if= \n" " -name guest option is set (default: off= )\n" - " program-name=3Doff disables program name prefix (defa= ult: on)\n", + " program-name=3Doff disables program name prefix (defa= ult: on)\n" + " thread-info=3Doff disables thread ID and name prefix = (default: on)\n", QEMU_ARCH_ALL) SRST -``-msg [timestamp=3Don|off][,guest-name=3Don|off][,program-name=3Don|off]`` +``-msg [timestamp=3Don|off][,guest-name=3Don|off][,program-name=3Don|off][= ,thread-info=3Don|off]`` Control error message format. =20 ``timestamp=3Don|off`` @@ -5535,6 +5536,9 @@ SRST =20 ``program-name=3Don|off`` Prefix messages with the program name. Default is on. + + ``guest-info=3Don|off`` + Prefix messages with the thread ID and name. Default is on. ERST =20 DEF("dump-vmstate", HAS_ARG, QEMU_OPTION_dump_vmstate, diff --git a/storage-daemon/qemu-storage-daemon.c b/storage-daemon/qemu-sto= rage-daemon.c index eb72561358..cc44ed7848 100644 --- a/storage-daemon/qemu-storage-daemon.c +++ b/storage-daemon/qemu-storage-daemon.c @@ -47,6 +47,7 @@ #include "qemu/cutils.h" #include "qemu/config-file.h" #include "qemu/error-report.h" +#include "qemu/message.h" #include "qemu/help_option.h" #include "qemu/job.h" #include "qemu/log.h" @@ -65,6 +66,10 @@ static const char *pid_file; static char *pid_file_realpath; static volatile bool exit_requested =3D false; =20 +#define QMESSAGE_FORMAT_DEFAULT \ + (QMESSAGE_FORMAT_PROGRAM_NAME | \ + QMESSAGE_FORMAT_THREAD_INFO) + void qemu_system_killed(int signal, pid_t pid) { exit_requested =3D true; @@ -399,6 +404,7 @@ int main(int argc, char *argv[]) #endif =20 error_init(argv[0]); + qmessage_set_format(QMESSAGE_FORMAT_DEFAULT); qemu_init_exec_dir(argv[0]); os_setup_signal_handling(); =20 diff --git a/system/vl.c b/system/vl.c index 3e79bf47e0..bedda94103 100644 --- a/system/vl.c +++ b/system/vl.c @@ -145,6 +145,10 @@ =20 #define MAX_VIRTIO_CONSOLES 1 =20 +#define QMESSAGE_FORMAT_DEFAULT \ + (QMESSAGE_FORMAT_PROGRAM_NAME | \ + QMESSAGE_FORMAT_THREAD_INFO) + typedef struct BlockdevOptionsQueueEntry { BlockdevOptions *bdo; Location loc; @@ -387,6 +391,12 @@ static QemuOptsList qemu_msg_opts =3D { .help =3D "Prepends program name for error messages (enabled " "by default)\n", }, + { + .name =3D "program-name", + .type =3D QEMU_OPT_BOOL, + .help =3D "Prepends current thread ID and name for error messa= ges " + "(enabled by default)\n", + }, { /* end of list */ } }, }; @@ -822,10 +832,9 @@ static void realtime_init(void) } } =20 - static void configure_msg(QemuOpts *opts) { - int flags =3D QMESSAGE_FORMAT_PROGRAM_NAME; + int flags =3D QMESSAGE_FORMAT_DEFAULT; if (qemu_opt_get_bool(opts, "timestamp", false)) { flags |=3D QMESSAGE_FORMAT_TIMESTAMP; } @@ -835,6 +844,9 @@ static void configure_msg(QemuOpts *opts) if (!qemu_opt_get_bool(opts, "program-name", true)) { flags &=3D ~QMESSAGE_FORMAT_PROGRAM_NAME; } + if (!qemu_opt_get_bool(opts, "thread-info", true)) { + flags &=3D ~QMESSAGE_FORMAT_THREAD_INFO; + } qmessage_set_format(flags); } =20 @@ -2903,6 +2915,7 @@ void qemu_init(int argc, char **argv) module_call_init(MODULE_INIT_OPTS); =20 error_init(argv[0]); + qmessage_set_format(QMESSAGE_FORMAT_DEFAULT); qemu_init_exec_dir(argv[0]); =20 os_setup_limits(); diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041 index 8452845f44..dc2666afe7 100755 --- a/tests/qemu-iotests/041 +++ b/tests/qemu-iotests/041 @@ -1102,7 +1102,7 @@ class TestRepairQuorum(iotests.QMPTestCase): self.vm.shutdown() log =3D iotests.filter_qtest(self.vm.get_log()) log =3D re.sub(r'^Formatting.*\n', '', log) - log =3D re.sub(r'^%s: ' % os.path.basename(iotests.qemu_prog), '',= log) + log =3D re.sub(r'^%s: \(\d+:\w+\): ' % os.path.basename(iotests.qe= mu_prog), '', log) =20 self.assertEqual(log, "Can no longer replace 'img1' by 'repair0', becau= se " + diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.f= ilter index 26e6b45b04..c8cb2e860c 100644 --- a/tests/qemu-iotests/common.filter +++ b/tests/qemu-iotests/common.filter @@ -81,7 +81,7 @@ _filter_qemu_io() # replace occurrences of QEMU_PROG with "qemu" _filter_qemu() { - gsed -e "s#\\(^\\|(qemu) \\)$(basename $QEMU_PROG):#\1QEMU_PROG:#" \ + gsed -e "s#\\(^\\|(qemu) \\)$(basename $QEMU_PROG): ([0-9]\+:[-_a-zA-Z= ]\+):#\1QEMU_PROG:#" \ -e 's#^QEMU [0-9]\+\.[0-9]\+\.[0-9]\+ monitor#QEMU X.Y.Z monitor#'= \ -e $'s#\r##' # QEMU monitor uses \r\n line endings } diff --git a/util/message.c b/util/message.c index dd01bf7462..9bf640c8c4 100644 --- a/util/message.c +++ b/util/message.c @@ -40,4 +40,11 @@ void qmessage_context_print(FILE *fp) fputs(": ", fp); } } + + if (message_format & QMESSAGE_FORMAT_THREAD_INFO) { + int thid =3D qemu_get_thread_id(); + const char *thname =3D qemu_thread_get_name(); + + fprintf(fp, "(%d:%s): ", thid, thname); + } } --=20 2.53.0 From nobody Thu Feb 12 11:50:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1770823760; cv=none; d=zohomail.com; s=zohoarc; b=cI+aiSeYMNV02PBeHy8nRU1U0MQ8sAL1RpK0TmMuWlJuD19yDKqOulXlpLk6tNHrwfdXLrztM2pDsaOXXYumW98sWWc0SEVQNCKWqPelNmIOFBlOEtGu9lH79D+vuunP8zoNaBdHMNkYaIAVsP5Rh/C4yj2pUdQ1Bt7BaCMiNQM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770823760; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=jDpR5NJcavAUEvfzxab8e4tcKsmv2LldTjp4RPjPjCU=; b=bduWLuXYKUqQm7BISv+JWwa2rCymr7Yf6l0cgQl/bTyf/uhI7oxZyvvsFNewCAMNbKwxw4Yt8Op5AsWdimP2YiFKOzFJENmHIEvc+zYDD+WM9OiOoULKHAlhb3NT5uLB560W87yDp/5mRV1Po+OvrOuoX2IPrKu9jIgFigWR2gA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770823760568181.89621728406735; Wed, 11 Feb 2026 07:29:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqC8D-0002fU-SR; Wed, 11 Feb 2026 10:27:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC8B-0002eM-Qj for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:27:55 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqC8A-0006Ew-Bi for qemu-devel@nongnu.org; Wed, 11 Feb 2026 10:27:55 -0500 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-486-xWgxoQDkMaSVSJbQE2xOWA-1; Wed, 11 Feb 2026 10:27:50 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A4E1F1956053; Wed, 11 Feb 2026 15:27:48 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.227.9]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A739330001A8; Wed, 11 Feb 2026 15:27:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770823673; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jDpR5NJcavAUEvfzxab8e4tcKsmv2LldTjp4RPjPjCU=; b=fmPZAvC7pLRgDWOjzhBn62ijJ3CReFzltQcjZBTrmjmmGqDbgs0FFg1qVDWzwgBaIcd7bK 3EhdQNJiDOM55825Gq9Ya5cCSrfaleTmivGlm78sA31Mnk1ucM2xPSLOQTn8cQ6MlSkOQC Y8x8GuceBB56V9ya2JjoIBFvUcp9Nsw= X-MC-Unique: xWgxoQDkMaSVSJbQE2xOWA-1 X-Mimecast-MFC-AGG-ID: xWgxoQDkMaSVSJbQE2xOWA_1770823668 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Stefan Weil , "Dr. David Alan Gilbert" , Pierrick Bouvier , devel@lists.libvirt.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, qemu-rust@nongnu.org, Paolo Bonzini , Markus Armbruster , Gerd Hoffmann , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Christian Schoenebeck , Richard Henderson Subject: [PATCH v6 27/27] util: add brackets around guest name in message context Date: Wed, 11 Feb 2026 15:25:08 +0000 Message-ID: <20260211152508.732487-28-berrange@redhat.com> In-Reply-To: <20260211152508.732487-1-berrange@redhat.com> References: <20260211152508.732487-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1770823762343158500 The message context can optionally include the guest name if the argument '-msg guest-name=3Don' is given. The formatting, however, does not look good if the guest name contains whitespace. Change the output to include square brackets to demarcate the name. Before: # qemu-system-x86_64 -object tls-creds-x509,id=3Dt0,dir=3Dfish -d 'trace:= qcrypto*' -msg guest-name=3Don -name "fish food" fish food qemu-system-x86_64: (1146846:main): qcrypto_tls_creds_x509_load= TLS creds x509 load creds=3D0x55657e94e690 dir=3Dfish fish food qemu-system-x86_64: (1146846:main): qcrypto_tls_creds_get_path = TLS creds path creds=3D0x55657e94e690 filename=3Dca-cert.pem path=3D fish food qemu-system-x86_64: (1146846:main): Unable to access credential= s fish/ca-cert.pem: No such file or directory After: # qemu-system-x86_64 -object tls-creds-x509,id=3Dt0,dir=3Dfish -d 'trace:= qcrypto*' -msg guest-name=3Don -name "fish food" [fish food] qemu-system-x86_64: (1144713:main): qcrypto_tls_creds_x509_lo= ad TLS creds x509 load creds=3D0x5604ada2c950 dir=3Dfish [fish food] qemu-system-x86_64: (1144713:main): qcrypto_tls_creds_get_pat= h TLS creds path creds=3D0x5604ada2c950 filename=3Dca-cert.pem path=3D [fish food] qemu-system-x86_64: (1144713:main): Unable to access credenti= als fish/ca-cert.pem: No such file or directory Reviewed-by: Richard Henderson Signed-off-by: Daniel P. Berrang=C3=A9 --- util/message.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/util/message.c b/util/message.c index 9bf640c8c4..73af8e8ca4 100644 --- a/util/message.c +++ b/util/message.c @@ -29,8 +29,9 @@ void qmessage_context_print(FILE *fp) =20 if ((message_format & QMESSAGE_FORMAT_WORKLOAD_NAME) && message_workloadname) { + fputc('[', fp); fputs(message_workloadname, fp); - fputc(' ', fp); + fputs("] ", fp); } =20 if (message_format & QMESSAGE_FORMAT_PROGRAM_NAME) { --=20 2.53.0