From nobody Sun Sep 28 14:52:12 2025 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=1758793605; cv=none; d=zohomail.com; s=zohoarc; b=CgCtFR85nf9lE/AUj4NCWQGN2J6R/zNE5Pw3ZlX/lq3YQEjVQCtCSrShp6Vf20xZWgCH+GHwlsmyitA/I1CIri4uVB5A7dt8I8VpyIBhrqTZ9Xruxo53qaSeQEsLsx+f/+JqYETG0CCK4eDTvBNZkxLHdGZ/gle5toGuF8UnCxA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758793605; 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=ew+TJ+ULudDPsPQa2ndt/jLM13vxDA+61FCxMS3PlS0=; b=iNzKNBEceJ+KoyfxaHBNObPTCHVcqVx1/gYYNXoMAu9w5UYiiN32zjHhMuLOkhiL4/8ifGKWnhKyi9wX+3rX+Ad2FBC5arnivOTRXKh+gJPFl3Skf+ZjPKenIY9iCFxUSCX+/VSgfbG++VtfLUqFd5RalcZKTbDRP5FsyLZvnNM= 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 1758793605188888.9368187801313; Thu, 25 Sep 2025 02:46:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1iXU-0000l3-2G; Thu, 25 Sep 2025 05:45:25 -0400 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 1v1iXF-0000f5-PR for qemu-devel@nongnu.org; Thu, 25 Sep 2025 05:45:10 -0400 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 1v1iX9-0001EW-2z for qemu-devel@nongnu.org; Thu, 25 Sep 2025 05:45:09 -0400 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-370-tEvw5vawNIyfdEmXsdId7g-1; Thu, 25 Sep 2025 05:44:57 -0400 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 71D54195608B; Thu, 25 Sep 2025 09:44:55 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.163]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 975A1300021A; Thu, 25 Sep 2025 09:44:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758793501; 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=ew+TJ+ULudDPsPQa2ndt/jLM13vxDA+61FCxMS3PlS0=; b=eWDlD36uoJAARBc3UuJSoVPXesrRZJNzDTDkccA1H1FXIZPV7nMz9ow8EK7/OCPwRH22H9 QooYGpNjPd99W2s3hPeF+Xwm+0nKgAkddCaJ00/yJnyApEzqMq89AfWUiWsve7Oi3jn6VU qCNmakPwLQZhCtb2coEePjiOD8l1Vh4= X-MC-Unique: tEvw5vawNIyfdEmXsdId7g-1 X-Mimecast-MFC-AGG-ID: tEvw5vawNIyfdEmXsdId7g_1758793495 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , qemu-rust@nongnu.org, Richard Henderson , Markus Armbruster , Christian Schoenebeck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , qemu-block@nongnu.org, Stefan Weil , "Dr. David Alan Gilbert" , Manos Pitsidianakis , Gerd Hoffmann , devel@lists.libvirt.org, Paolo Bonzini Subject: [PATCH v4 01/23] include: define constant for early constructor priority Date: Thu, 25 Sep 2025 10:44:19 +0100 Message-ID: <20250925094441.1651372-2-berrange@redhat.com> In-Reply-To: <20250925094441.1651372-1-berrange@redhat.com> References: <20250925094441.1651372-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: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.444, 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, T_SPF_TEMPERROR=0.01 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: 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: 1758793607368116600 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.50.1 From nobody Sun Sep 28 14:52:12 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1758794098; cv=none; d=zohomail.com; s=zohoarc; b=ItfliiyKC4hKWxp7hxvMrVfxZTyO0WfsGAL0ywfV8iFuBqIYrS1/vpn6PtabL7rOWLFthdy1NAa7CYBo8sDfEPp4/kV46zTTR9Nc4uPiAYEu+921ycGsNeI3YKYQ8iGG+lNUkXsBMkMXIr2UM/Yvfo52utGptz8+Py0nR0cvD14= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758794098; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id; bh=fcI0f/40UM6S++W5fRjwKPKMY6j7Dg0M4zkV/J73zRo=; b=SEFgtG58fecCxrzau4EXo3UH6eJZZkF5EejCLauZm6cPvclAVcRySWjFyxIDY0iUNW+LTK1N2X/vhHHUqraBSbtHVDH/2RYRSO09qIWTKtNsSbUhpI22nHoxqQn4f9CzBZXDDx3z4nRbvNHPQUy9hW2glAamAGrX7ujCa8iE6F8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1758794098185176.32293862170707; Thu, 25 Sep 2025 02:54:58 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 4C5AF417D6; Thu, 25 Sep 2025 05:54:57 -0400 (EDT) Received: from [172.19.199.14] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 0EBF843F6B; Thu, 25 Sep 2025 05:48:33 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id CB25E41846; Thu, 25 Sep 2025 05:48:18 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 564CC43F09 for ; Thu, 25 Sep 2025 05:45:07 -0400 (EDT) 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-119-3rXXKG-zM16ZeMJFCJGGcQ-1; Thu, 25 Sep 2025 05:45:03 -0400 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 3210C18004D4; Thu, 25 Sep 2025 09:45:01 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.163]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0C6C330002D0; Thu, 25 Sep 2025 09:44:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758793506; 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=fcI0f/40UM6S++W5fRjwKPKMY6j7Dg0M4zkV/J73zRo=; b=c3nsm6360n5aSNikdpnCp360cC4qFug9LYqfecy/MG/SNpDawr2Mq1EDHY1wq0amN3qxv7 S63IeMt7W10eiIba0JkyeefG/b43wy3Wfid5rXyFPvZzseLi6NqH+j4bUYK7dXhZn6XqqQ bXM2xelPCMMbofUcTmsRDhj3hfoBLac= X-MC-Unique: 3rXXKG-zM16ZeMJFCJGGcQ-1 X-Mimecast-MFC-AGG-ID: 3rXXKG-zM16ZeMJFCJGGcQ_1758793501 To: qemu-devel@nongnu.org Subject: [PATCH v4 02/23] monitor: initialize global data from a constructor Date: Thu, 25 Sep 2025 10:44:20 +0100 Message-ID: <20250925094441.1651372-3-berrange@redhat.com> In-Reply-To: <20250925094441.1651372-1-berrange@redhat.com> References: <20250925094441.1651372-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 Message-ID-Hash: M7OWBNV6KVK2B3Z5MKX2PB4PDZLGYDDF X-Message-ID-Hash: M7OWBNV6KVK2B3Z5MKX2PB4PDZLGYDDF X-MailFrom: berrange@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , qemu-rust@nongnu.org, Richard Henderson , Markus Armbruster , Christian Schoenebeck , qemu-block@nongnu.org, Stefan Weil , "Dr. David Alan Gilbert" , Manos Pitsidianakis , Gerd Hoffmann , devel@lists.libvirt.org, Paolo Bonzini X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9_via_Devel?= Reply-To: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758794099764116600 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 c5a5d30877..da54e1b1ce 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -704,18 +704,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.50.1 From nobody Sun Sep 28 14:52:12 2025 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=1758793842; cv=none; d=zohomail.com; s=zohoarc; b=CEhf+nPQGf9du2CSQTRVksqLvBrhRE9KG9mGlOCsOb35QH9XK33R0xau76Td8Pq8Aaj5U2UMqD6aAA7cKKXAq1huv5ypz68BTYfLNfBIB5hg8D21jZ6XlcJJgb5xSvCLphiulIZbLIuvqOJkdYuRkARITCXSH3Kid7Q6FZvDJFA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758793842; 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=hzXVtRQJctPbPCbqx/zO3nmd2w0V37e1/DdpV1iziZA=; b=Q/Yht1ZFte3a8tvOk1CDMTcSzwXgk3baD558mbFl03JP2eRyEYy59wO93bfP+D+SQYTHzA4AbOHLU0brFEdxMerTeCigVB+C6WWGqVAyJlRqXDCkk6zbdyfK5tOdNSeS2l6CUTJ9st67JFZv2HXddZSnnyRphVHoBsTBiyON4/4= 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 175879384211999.669580908032; Thu, 25 Sep 2025 02:50:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1iXa-0000pt-Ed; Thu, 25 Sep 2025 05:45:30 -0400 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 1v1iXX-0000o9-LT for qemu-devel@nongnu.org; Thu, 25 Sep 2025 05:45:27 -0400 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 1v1iXM-0001Rk-Du for qemu-devel@nongnu.org; Thu, 25 Sep 2025 05:45:27 -0400 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-30-IYNtwN0GNsOZ9i1n0cPajA-1; Thu, 25 Sep 2025 05:45:10 -0400 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 5AF441800371; Thu, 25 Sep 2025 09:45:08 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.163]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C4FF230002D1; Thu, 25 Sep 2025 09:45:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758793512; 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=hzXVtRQJctPbPCbqx/zO3nmd2w0V37e1/DdpV1iziZA=; b=Q+OuJf5o79sXTjq0WtxDSaI1cFFQhg/0axGwE/NmgcavQQqv/3Ycr4YnYr55i2tur7wty0 MUUWERsmJXfbIdPplDS4DlFzlZYoZ7oW8JiG3bGHb2JjClxuEmdx1xz3g4lvfn0L/9cU2K HJEh51hIqBoT4q70uL+grIh8retVUo0= X-MC-Unique: IYNtwN0GNsOZ9i1n0cPajA-1 X-Mimecast-MFC-AGG-ID: IYNtwN0GNsOZ9i1n0cPajA_1758793508 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , qemu-rust@nongnu.org, Richard Henderson , Markus Armbruster , Christian Schoenebeck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , qemu-block@nongnu.org, Stefan Weil , "Dr. David Alan Gilbert" , Manos Pitsidianakis , Gerd Hoffmann , devel@lists.libvirt.org, Paolo Bonzini Subject: [PATCH v4 03/23] system: unconditionally enable thread naming Date: Thu, 25 Sep 2025 10:44:21 +0100 Message-ID: <20250925094441.1651372-4-berrange@redhat.com> In-Reply-To: <20250925094441.1651372-1-berrange@redhat.com> References: <20250925094441.1651372-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, 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 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: 1758793844601116600 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 aa300bbd50..f920939c9a 100644 --- a/docs/about/deprecated.rst +++ b/docs/about/deprecated.rst @@ -68,6 +68,13 @@ configurations (e.g. -smp drawers=3D1,books=3D1,clusters= =3D1 for x86 PC machine) is marked deprecated since 9.0, users have to ensure that all the topology me= mbers described with -smp are supported by the target machine. =20 +``debug-threads`` option for ``-name`` (since 10.2) +''''''''''''''''''''''''''''''''''''''''''''''''''' + +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 00f3694725..e0884c1bb9 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.50.1 From nobody Sun Sep 28 14:52:12 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1758794764; cv=none; d=zohomail.com; s=zohoarc; b=jOymk/oX5dzBi38RFypfqiAXtqRz4fzLinDwDh/v06VKIsKBXGuUaSCy9328ApWm/ijbBmi27MOqCWReI2XC4DwGuh2g0XM8ckuetd/vrrwZq6fkwbF+TJAfU6mqegJp+Io7dIEnAQQt3aF6Okh9DirZqZKrN6kkqVyDpEiCyOs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758794764; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id; bh=WQs/xm4O7fINJK018PI4dm/6m98OdARg7ntB2NQYAdM=; b=TTWAJz/DWZXLPIIN5AMIDGBzIpV3lByGswtKX/n1Az4jWet7gB2qGsrGuMPtSgA7/+bRp1EcZ9d53G1EN+cWyyI4T1c8T0ZWZaITw1fdCbnbAjoZVd1oMge7Wz0KGufVoC8RWL4qusmOqNeXFleo+TsaQmrRCXmIdEr83TU9hvU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1758794764690616.7184169154064; Thu, 25 Sep 2025 03:06:04 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id A0E9643F37; Thu, 25 Sep 2025 06:06:03 -0400 (EDT) Received: from [172.19.199.14] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 6DF564404B; Thu, 25 Sep 2025 05:48:49 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 350E341B41; Thu, 25 Sep 2025 05:48:20 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id F27DF41C63 for ; Thu, 25 Sep 2025 05:45:19 -0400 (EDT) Received: from mx-prod-mc-02.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-407-NHEtfazLNDuaWqlNIapDEw-1; Thu, 25 Sep 2025 05:45:15 -0400 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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C400619560AB; Thu, 25 Sep 2025 09:45:13 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.163]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D363B30002D0; Thu, 25 Sep 2025 09:45:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758793519; 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=WQs/xm4O7fINJK018PI4dm/6m98OdARg7ntB2NQYAdM=; b=WDLXwhKEYXrl8+DNp3RKVdK2ChqNkjnqSLjho3evWniYbg9GARvewxiRLF64/XuLyfvb4A 2bukKwTAc2lGX1ga2GJeK/rK0aqj5GvfFAna/xoxG76EM4ErKHkbISyUroL0syvTer55/2 xsSppTt8OR1NZzX6nDowS1lBUw+37zA= X-MC-Unique: NHEtfazLNDuaWqlNIapDEw-1 X-Mimecast-MFC-AGG-ID: NHEtfazLNDuaWqlNIapDEw_1758793514 To: qemu-devel@nongnu.org Subject: [PATCH v4 04/23] util: expose qemu_thread_set_name Date: Thu, 25 Sep 2025 10:44:22 +0100 Message-ID: <20250925094441.1651372-5-berrange@redhat.com> In-Reply-To: <20250925094441.1651372-1-berrange@redhat.com> References: <20250925094441.1651372-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 Message-ID-Hash: 7DO2KABOQOXOURBHUTJFQQ7SBEZLHRPK X-Message-ID-Hash: 7DO2KABOQOXOURBHUTJFQQ7SBEZLHRPK X-MailFrom: berrange@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , qemu-rust@nongnu.org, Richard Henderson , Markus Armbruster , Christian Schoenebeck , qemu-block@nongnu.org, Stefan Weil , "Dr. David Alan Gilbert" , Manos Pitsidianakis , Gerd Hoffmann , devel@lists.libvirt.org, Paolo Bonzini X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9_via_Devel?= Reply-To: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758794766368116600 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 Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/qemu/thread.h | 1 + util/qemu-thread-posix.c | 26 ++++++++++++++++---------- util/qemu-thread-win32.c | 13 ++++++++----- 3 files changed, 25 insertions(+), 15 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 9595a5b090..4d2d663a9a 100644 --- a/util/qemu-thread-win32.c +++ b/util/qemu-thread-win32.c @@ -225,6 +225,7 @@ struct QemuThreadData { void *arg; short mode; NotifierList exit; + char *name; =20 /* Only used for joinable threads. */ bool exited; @@ -266,6 +267,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) { + qemu_thread_set_name(data->name); + g_clear_pointer(&data->name, g_free); + } qemu_thread_data =3D data; qemu_thread_exit(start_routine(thread_arg)); abort(); @@ -316,7 +321,7 @@ void *qemu_thread_join(QemuThread *thread) return ret; } =20 -static void set_thread_description(HANDLE h, const char *name) +void qemu_thread_set_name(const char *name) { g_autofree wchar_t *namew =3D NULL; =20 @@ -329,7 +334,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 +349,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 +361,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.50.1 From nobody Sun Sep 28 14:52:12 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1758795788; cv=none; d=zohomail.com; s=zohoarc; b=jNc/ssBxbhFoibU0l36qjc0fkOBFizZUhGDdjpCP0GzUu7qGnf4u6Oo6ps2/pS4kphCkeDrFnHUvScKDCY5Z5YSMWd/oQEWvOpC1V7z42y0BGp8i6G4VPyfcRInsCGPWgNjaUUPfuwR7WTC8Xa0wBWuRH7jgEbDLLjdKVEj5rtU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758795788; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id; bh=0e0TFv/CGlxU/vse5VywmrVZx48lnld4r/92cQWi2Vk=; b=AnRGca1dlrUz4KqKK+v5A63hUwofyQkp6x3w6A+IglIYscvUKyl0nUkMzt93uXVpzXuytlr19+3pFroNFdSlz9RHenW3mdo96wBfsqTtjKMUHQ/VTByBGh9utoYNPbmMVEyQxGk1zXLvGfH0FgCAjZO1IeOMLD8xDtu3L3lUeH0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1758795788270681.8592184088183; Thu, 25 Sep 2025 03:23:08 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 11D3643E6E; Thu, 25 Sep 2025 06:23:07 -0400 (EDT) Received: from [172.19.199.14] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 7B8BB4419E; Thu, 25 Sep 2025 05:49:17 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id CE50043E55; Thu, 25 Sep 2025 05:48:24 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id E1CB643E6D for ; Thu, 25 Sep 2025 05:45:25 -0400 (EDT) Received: from mx-prod-mc-02.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-125-agWRH4J8NPuSGuIukX37eg-1; Thu, 25 Sep 2025 05:45:21 -0400 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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6723019560B0; Thu, 25 Sep 2025 09:45:19 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.163]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4C70830002D0; Thu, 25 Sep 2025 09:45:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758793525; 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=0e0TFv/CGlxU/vse5VywmrVZx48lnld4r/92cQWi2Vk=; b=K7r6WD3Q9rznO2cLf5l4JnBlhe4ZfKcbWIgHfqDblt64SbvGzOvngek5jpsKBzPsb0GlPA U/vdVkWx/abt8uUiK2LyRm4WW4TBUTHzM/lCESfKVGskxrZbFTwW704bpExmgJcHNtpGRE NmPwxALUDR1EKzLQUMvDagMXbsrNUmM= X-MC-Unique: agWRH4J8NPuSGuIukX37eg-1 X-Mimecast-MFC-AGG-ID: agWRH4J8NPuSGuIukX37eg_1758793519 To: qemu-devel@nongnu.org Subject: [PATCH v4 05/23] audio: make jackaudio use qemu_thread_set_name Date: Thu, 25 Sep 2025 10:44:23 +0100 Message-ID: <20250925094441.1651372-6-berrange@redhat.com> In-Reply-To: <20250925094441.1651372-1-berrange@redhat.com> References: <20250925094441.1651372-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 Message-ID-Hash: LEHVB4G5T7NTF76BXHFQN2GQB7IRU5VM X-Message-ID-Hash: LEHVB4G5T7NTF76BXHFQN2GQB7IRU5VM X-MailFrom: berrange@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , qemu-rust@nongnu.org, Richard Henderson , Markus Armbruster , Christian Schoenebeck , qemu-block@nongnu.org, Stefan Weil , "Dr. David Alan Gilbert" , Manos Pitsidianakis , Gerd Hoffmann , devel@lists.libvirt.org, Paolo Bonzini X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9_via_Devel?= Reply-To: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758795788608116600 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 974a3caad3..69dce3f302 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 @@ -696,7 +714,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.50.1 From nobody Sun Sep 28 14:52:12 2025 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=1758793623; cv=none; d=zohomail.com; s=zohoarc; b=Rd9EVT9l8BFuJZFlM/eEASPdYC4Whnw25A+3qnO+Uw9OoHjIY5wvGkVFo66RQAFnebX9sbTMu77mEzXQL7O9wwCRWBTRkyJ0Q0KA9LqfrlVuRV2l3zEjltu3xjqNx5zUfyL6a3VKiqVOVUVUTPiLx/RAcPnwK2YxDzAFej3N9Dk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758793623; 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=jMMgQdxZOS+idaSUGw02GbMbHV34psi17koZpeJ7Adk=; b=LJ2O6S3PlJSkC5KOmtz5ldlKbqh1jFq3wW3xI3lBi3Kz0ilsJWI4ZT8h9Om6zIqr9AjiAHiwYI/Zy4fgdYfy4rYFUe1za7ktA+sPcH8BSQi6gxvCq+t/W8NGESLlQjfBT8nSmgwGKE60qohoNNvzy3r4f/xv9hL+NX0XM9eXlFI= 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 1758793623372634.2260013331321; Thu, 25 Sep 2025 02:47:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1iYE-00015U-2N; Thu, 25 Sep 2025 05:46:10 -0400 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 1v1iXz-0000vK-3f for qemu-devel@nongnu.org; Thu, 25 Sep 2025 05:45:59 -0400 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 1v1iXa-0001Vk-K1 for qemu-devel@nongnu.org; Thu, 25 Sep 2025 05:45:54 -0400 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-411-tpVKcBWAPYW_EvBV5b3fKg-1; Thu, 25 Sep 2025 05:45:26 -0400 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 EA95C1800350; Thu, 25 Sep 2025 09:45:24 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.163]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E0A0130002D1; Thu, 25 Sep 2025 09:45:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758793527; 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=jMMgQdxZOS+idaSUGw02GbMbHV34psi17koZpeJ7Adk=; b=ZSaVGdjRgEB8EXwTMC6Dci+z1eEd6WgDc9J1Wyu97UavD9SEVXkSVl58XCtzxrp781HIv6 IpqM19khBognBu/BtRO0/ng9hE1xWfYI09jFfUT0L0BtZNTaFIUkH98/G0G8OwAJX2GFra l3glhfr70qRIpkc32N25OKgI9tmcriM= X-MC-Unique: tpVKcBWAPYW_EvBV5b3fKg-1 X-Mimecast-MFC-AGG-ID: tpVKcBWAPYW_EvBV5b3fKg_1758793525 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , qemu-rust@nongnu.org, Richard Henderson , Markus Armbruster , Christian Schoenebeck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , qemu-block@nongnu.org, Stefan Weil , "Dr. David Alan Gilbert" , Manos Pitsidianakis , Gerd Hoffmann , devel@lists.libvirt.org, Paolo Bonzini Subject: [PATCH v4 06/23] util: set the name for the 'main' thread Date: Thu, 25 Sep 2025 10:44:24 +0100 Message-ID: <20250925094441.1651372-7-berrange@redhat.com> In-Reply-To: <20250925094441.1651372-1-berrange@redhat.com> References: <20250925094441.1651372-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: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.444, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 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: 1758793625611116600 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. Reviewed-by: Richard Henderson Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Daniel P. Berrang=C3=A9 --- util/qemu-thread-posix.c | 6 ++++++ util/qemu-thread-win32.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c index b1c127dbe3..afeac9ecad 100644 --- a/util/qemu-thread-posix.c +++ b/util/qemu-thread-posix.c @@ -22,6 +22,12 @@ #include #endif =20 +static void __attribute__((__constructor__(QEMU_CONSTRUCTOR_EARLY))) +qemu_thread_init(void) +{ + qemu_thread_set_name("main"); +} + static void error_exit(int err, const char *msg) { fprintf(stderr, "qemu: %s: %s\n", msg, strerror(err)); diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c index 4d2d663a9a..8ca6429ad3 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.50.1 From nobody Sun Sep 28 14:52:12 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1758795189; cv=none; d=zohomail.com; s=zohoarc; b=QDA3r3tO+OIX78Ohedr0wo6S73UWLJBsmXPVNC9GDAN8rb8k/eGnoI7NgOIkuQA053lQ3EExLM2OUOcaHThX/C0vWZwatulMkMaAW/aOGSO7oQXorVBXL9FHh/wkCVDKCmzjiBbGCE8v5J0JaMzuifTy61hlBcshKmrPCkmny9w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758795189; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id; bh=rMBZcWU4PJxmzuxZd6HMdIzoFn+S9YCttgs9zCAJA9A=; b=Rs/HjCpUvplpuKj2XYIfpC9ZaTOKOjxKzTPbXWlRfBZRDl33K+SE3iW/s/7331YuQuL7/yxiNrZn04AB9JSaZ67iqM0nGbwNjozidzs5rX3Ftx0xPOZciJ5Otv6g6/I+Wm/gpU6yCcDogBWlh0f89qQSwWAg4eel86PqVFyrSxg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1758795189271277.59464066856253; Thu, 25 Sep 2025 03:13:09 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 543CD418A8; Thu, 25 Sep 2025 06:13:08 -0400 (EDT) Received: from [172.19.199.14] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 9E7EC440DC; Thu, 25 Sep 2025 05:49:01 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id B9FEF3F36B; Thu, 25 Sep 2025 05:48:22 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 1CEEB3F36B for ; Thu, 25 Sep 2025 05:45:42 -0400 (EDT) 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-206-VsyeuCqDP_662C8ebuQGqQ-1; Thu, 25 Sep 2025 05:45:32 -0400 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 48F32180035C; Thu, 25 Sep 2025 09:45:30 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.163]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6BE8F300021A; Thu, 25 Sep 2025 09:45:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758793541; 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=rMBZcWU4PJxmzuxZd6HMdIzoFn+S9YCttgs9zCAJA9A=; b=Uluu2zZ995JUstx+JuGxVMi1BTP7jKXSu1aZJfeJ/ku0oYxfmwKi7zqplr2clQvtc0dr32 z9RRvo/bH+rFe3wwdrHyw+C8Oj4QwK55jxfRSprkqKdHpIiFtipdP87nvXxSn5UhHd6iCn LwG+Mayq8+MSFXtRb26OrXM8H0/Icv4= X-MC-Unique: VsyeuCqDP_662C8ebuQGqQ-1 X-Mimecast-MFC-AGG-ID: VsyeuCqDP_662C8ebuQGqQ_1758793530 To: qemu-devel@nongnu.org Subject: [PATCH v4 07/23] util: add API to fetch the current thread name Date: Thu, 25 Sep 2025 10:44:25 +0100 Message-ID: <20250925094441.1651372-8-berrange@redhat.com> In-Reply-To: <20250925094441.1651372-1-berrange@redhat.com> References: <20250925094441.1651372-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 Message-ID-Hash: S55GMFPPGLHMQKSWY67YNWRNSUA3RX4V X-Message-ID-Hash: S55GMFPPGLHMQKSWY67YNWRNSUA3RX4V X-MailFrom: berrange@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , qemu-rust@nongnu.org, Richard Henderson , Markus Armbruster , Christian Schoenebeck , qemu-block@nongnu.org, Stefan Weil , "Dr. David Alan Gilbert" , Manos Pitsidianakis , Gerd Hoffmann , devel@lists.libvirt.org, Paolo Bonzini X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9_via_Devel?= Reply-To: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758795191555116600 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. Signed-off-by: Daniel P. Berrang=C3=A9 --- include/qemu/thread.h | 1 + meson.build | 21 +++++++++++++++++ util/qemu-thread-posix.c | 33 ++++++++++++++++++++++++++- util/qemu-thread-win32.c | 49 ++++++++++++++++++++++++++++++++++++---- 4 files changed, 99 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 72da97829a..0893005919 100644 --- a/meson.build +++ b/meson.build @@ -2912,6 +2912,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 afeac9ecad..05c7ea4c00 100644 --- a/util/qemu-thread-posix.c +++ b/util/qemu-thread-posix.c @@ -18,7 +18,7 @@ #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 @@ -532,3 +532,34 @@ void *qemu_thread_join(QemuThread *thread) } return ret; } + +/* + * 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]; + +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) { + strlcpy(namebuf, "unnamed", G_N_ELEMENTS(namebuf)); + } + return namebuf; +} diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c index 8ca6429ad3..20165c6f95 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.50.1 From nobody Sun Sep 28 14:52:12 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1758794972; cv=none; d=zohomail.com; s=zohoarc; b=Uf2xYKV0DOt6egshIvOW1gWtgGCi3PbUIHs7yDBu/E6SVzM/1d31wzZac3EgmSrGb6VCoKAbd/D9XOXjpxrsZgualOW6wnkqadqFUOPWyMbrjMuBB2pXZHRJ65DftmWc+1fPGF0U4oD/howXE45rzU5plPaYmbrzdM9V4imO37U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758794972; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id; bh=lhvlmbocLMImejtfkUQoIH3CBQ2wk54B4Lb6eRqTx5U=; b=lvNJtEg4/piLZ8ZjWIk0aZbp6l5q84X3EwyfxA8veCZlVjeot2mvkDdhB7a98ydfNvpLBGNuZxOBBYi1FkTF3zpkvZB38o1kWSMe7XNEJWGMW7uZpdNouIg3z7KPxlXdMNkeRLaCvAj8V+W0v7x4XOHhPA50rdPEBeTEZTxpGLg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 17587949720861013.5242044213453; Thu, 25 Sep 2025 03:09:32 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 2D85543F75; Thu, 25 Sep 2025 06:09:30 -0400 (EDT) Received: from [172.19.199.14] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 2EF7B44094; Thu, 25 Sep 2025 05:48:55 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id BFDBC41A9A; Thu, 25 Sep 2025 05:48:20 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 5337343DC3 for ; Thu, 25 Sep 2025 05:45:42 -0400 (EDT) Received: from mx-prod-mc-04.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-410-EoJm9mPwOkqu78JmdZ4qmg-1; Thu, 25 Sep 2025 05:45:37 -0400 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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 25C001955D48; Thu, 25 Sep 2025 09:45:36 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.163]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B24C4300021A; Thu, 25 Sep 2025 09:45:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758793542; 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=lhvlmbocLMImejtfkUQoIH3CBQ2wk54B4Lb6eRqTx5U=; b=HQxlqo2fJAP82LgD/oOvqHrCmnH/tQ8xmdFxkomnaYhmqLvsm+plq/0rr67IZQAoO8savc BMBC4O8EBO/KVeQQjvFItbRQR4aTmZguzsvIHxUr7oKCCn3yO4bviVOFkPleWowFUGfpQs NTkghu7NzDp443cNW6NrcZKIpIobKS4= X-MC-Unique: EoJm9mPwOkqu78JmdZ4qmg-1 X-Mimecast-MFC-AGG-ID: EoJm9mPwOkqu78JmdZ4qmg_1758793536 To: qemu-devel@nongnu.org Subject: [PATCH v4 08/23] log: avoid repeated prefix on incremental qemu_log calls Date: Thu, 25 Sep 2025 10:44:26 +0100 Message-ID: <20250925094441.1651372-9-berrange@redhat.com> In-Reply-To: <20250925094441.1651372-1-berrange@redhat.com> References: <20250925094441.1651372-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 Message-ID-Hash: SJ6CZSYEMVBRBPPMA7Q7NBHTMWK3BFOI X-Message-ID-Hash: SJ6CZSYEMVBRBPPMA7Q7NBHTMWK3BFOI X-MailFrom: berrange@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , qemu-rust@nongnu.org, Richard Henderson , Markus Armbruster , Christian Schoenebeck , qemu-block@nongnu.org, Stefan Weil , "Dr. David Alan Gilbert" , Manos Pitsidianakis , Gerd Hoffmann , devel@lists.libvirt.org, Paolo Bonzini X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9_via_Devel?= Reply-To: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758794972880116601 Some code makes multiple qemu_log calls to incrementally emit a single message. Currently timestamps get prepended to all qemu_log calls, even those continuing a previous incomplete message. This changes the qemu_log so it skips adding a new line prefix, if the previous qemu_log call did NOT end with a newline. Fixes: 012842c07552 (log: make '-msg timestamp=3Don' apply to all qemu_log = usage) Reported-by: Richard Henderson Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- util/log.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/util/log.c b/util/log.c index abdcb6b311..2642a55c59 100644 --- a/util/log.c +++ b/util/log.c @@ -143,6 +143,12 @@ void qemu_log_unlock(FILE *logfile) } } =20 +/* + * 'true' if the previous log message lacked a trailing '\n', + * and thus the subsequent call must skip any prefix + */ +static __thread bool incomplete; + void qemu_log(const char *fmt, ...) { FILE *f; @@ -154,7 +160,7 @@ void qemu_log(const char *fmt, ...) * was emitted if we are delayed acquiring the * mutex */ - if (message_with_timestamp) { + if (message_with_timestamp && !incomplete) { g_autoptr(GDateTime) dt =3D g_date_time_new_now_utc(); timestr =3D g_date_time_format_iso8601(dt); } @@ -170,6 +176,7 @@ void qemu_log(const char *fmt, ...) va_start(ap, fmt); vfprintf(f, fmt, ap); va_end(ap); + incomplete =3D fmt[strlen(fmt) - 1] !=3D '\n'; qemu_log_unlock(f); } } --=20 2.50.1 From nobody Sun Sep 28 14:52:12 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1758795584; cv=none; d=zohomail.com; s=zohoarc; b=RpghgPF+uMCGdfJKfHK16Kgl27+xvWhEjZ7ZFLnVaPK7/2lj2KdSNTSKxBLU98fWhAYeEEFzaVh6TXtQguyy8NwJ4BJsmwLxWSQSI3+5N7OTOq1k7QPBnJeSs6RxmOaCTsfYa38LEN5VWTUxgSNr3eLs15GCVurLjfHvo+emQAg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758795584; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id; bh=XvkLe5PlKeo0HdSyG7FFTgKImW+3jifmX4pZMoyAdkQ=; b=So4VdziEyIj1/7gYSmG4Olvlx/uujR7AkZdg5penqzVNcRGZCLFXfWL/KUNUjoZ7jVAOb16xc5RTJIQDc+C3/TkpJw0geQvBWt/dhEp4VPpaXZUmdYuTwhpH6jF7hQKsWTLo/Kt/DMdY5qq5zP+7ExfDWC/7riRxi+py2m/o6Bw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1758795584122886.0994056736779; Thu, 25 Sep 2025 03:19:44 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 2BA11419A9; Thu, 25 Sep 2025 06:19:43 -0400 (EDT) Received: from [172.19.199.14] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 1D78643EFA; Thu, 25 Sep 2025 05:49:13 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 4CB7643EFA; Thu, 25 Sep 2025 05:48:24 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 5BBC543E4D for ; Thu, 25 Sep 2025 05:45:47 -0400 (EDT) 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-126-tUPuQASIN2CtD6daej_t6g-1; Thu, 25 Sep 2025 05:45:43 -0400 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 ECA18195605B; Thu, 25 Sep 2025 09:45:41 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.163]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id ACEE830002D1; Thu, 25 Sep 2025 09:45:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758793547; 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=XvkLe5PlKeo0HdSyG7FFTgKImW+3jifmX4pZMoyAdkQ=; b=NWYnNPN0WD2rotL+XpIkdCuBIZ8H2QOFW7W9flIvSWUBM42MNptBu7E7t+gcKitwBn/Ws2 ni7CLQw/joxQLWLqXKqYY3osUpHfnoWumUf0p2+gNRxqgun2he3Pl0scGv7BE6zZ/GaVaL 9DxF6ULK6TGUphcm3iWG7+qYF6hohfM= X-MC-Unique: tUPuQASIN2CtD6daej_t6g-1 X-Mimecast-MFC-AGG-ID: tUPuQASIN2CtD6daej_t6g_1758793542 To: qemu-devel@nongnu.org Subject: [PATCH v4 09/23] util: introduce some API docs for logging APIs Date: Thu, 25 Sep 2025 10:44:27 +0100 Message-ID: <20250925094441.1651372-10-berrange@redhat.com> In-Reply-To: <20250925094441.1651372-1-berrange@redhat.com> References: <20250925094441.1651372-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 Message-ID-Hash: 7VNHK4M3R23DZNMPYYAYXM7HC6VOBYDZ X-Message-ID-Hash: 7VNHK4M3R23DZNMPYYAYXM7HC6VOBYDZ X-MailFrom: berrange@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , qemu-rust@nongnu.org, Richard Henderson , Markus Armbruster , Christian Schoenebeck , qemu-block@nongnu.org, Stefan Weil , "Dr. David Alan Gilbert" , Manos Pitsidianakis , Gerd Hoffmann , devel@lists.libvirt.org, Paolo Bonzini X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9_via_Devel?= Reply-To: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758795586693116600 This addresses two key gotchas with the logging APIs: * Safely outputting a single line of text using multiple qemu_log() calls requires use of the qemu_log_trylock/unlock functions to avoid interleaving between threads * Directly outputting to the FILE object returned by qemu_log_trylock() must be discouraged because it prevents the inclusion of configured log message prefixes. Reported-by: Markus Armbruster Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Eric Blake --- include/qemu/log-for-trace.h | 35 ++++++++++++++++++++++++++++++++++- include/qemu/log.h | 26 ++++++++++++++++++++++++++ rust/util/src/log.rs | 7 +++++++ 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/include/qemu/log-for-trace.h b/include/qemu/log-for-trace.h index d47c9cd446..4e05b2e26f 100644 --- a/include/qemu/log-for-trace.h +++ b/include/qemu/log-for-trace.h @@ -29,7 +29,40 @@ 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, ending with a newline character. + * + * If intending to call this function multiple times to + * incrementally construct a line of text, locking must + * be used to ensure that output from different threads + * is not interleaved. + * + * This is achieved by calling qemu_log_trylock() before + * starting the log line; calling qemu_log() multiple + * times with the last call having a newline at the end + * of @fmt; finishing with a call to qemu_log_unlock(). + * + * The FILE object returned by qemu_log_trylock() does + * not need to be used for outputting text directly, + * it is merely used to associate the lock. + * + * FILE *f =3D qemu_log_trylock() + * + * qemu_log("Something"); + * qemu_log("Something"); + * qemu_log("Something"); + * qemu_log("The end\n"); + * + * qemu_log_unlock(f); + * + */ 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 aae72985f0..867fe327e4 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -41,7 +41,33 @@ bool qemu_log_separate(void); =20 /* Lock/unlock output. */ =20 +/** + * Acquires a lock on the current log output stream. + * The returned FILE object must be passed to + * qemu_log_unlock() to later release the lock. + * + * This should be used to protect a sequence of calls + * to qemu_log(), if they are being used to incrementally + * output a single line of text. For qemu_log() calls which + * output a complete line of text it is not required to + * take explicit locks. + * + * The returned FILE object may be used to directly + * output log messages, however, doing so will prevent + * the inclusion of configured log message prefixes. + * It is thus recommended that this be used sparingly, + * only in cases where it is required to dump large + * data volumes. Use of qemu_log() is preferred for + * most output tasks. + * + * 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 af9a3e9123..eaf493f0df 100644 --- a/rust/util/src/log.rs +++ b/rust/util/src/log.rs @@ -55,6 +55,13 @@ impl LogGuard { /// writeln!(log, "test"); /// } /// ``` + /// + /// Note that directly writing to the log output will prevent the + /// inclusion of configured log prefixes. It is thus recommended + /// that this be used sparingly, only in cases where it is required + /// to dump large data volumes. Use of [`log_mask_ln!()`](crate::log_m= ask_ln) + /// macro() is preferred for most output tasks. + pub fn new() -> Option { let f =3D unsafe { bindings::qemu_log_trylock() }.cast(); NonNull::new(f).map(Self) --=20 2.50.1 From nobody Sun Sep 28 14:52:12 2025 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=1758793921; cv=none; d=zohomail.com; s=zohoarc; b=iRSMhPWq/MQyyr0MP3aIB0Y69y/qDbeuVrU9wrnOL8GmyczaZEEW5lMDnJySAnNQvGwAe5mT0veyipDKNxvflFZPyGFJmu05MbmqN7LxewEaCHws8hk/baoQvRyM4d8Z3jKfjGeeUzhCOj0kqjKwPDDIAsIJKy8jAabtUtkky9A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758793921; 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=jD7prJ6ro51U/diLj3k7/GWH5jMUoGvOMefAMKMPzjA=; b=EAQTGw1Avz9rSp7S5TNVT8C86xBFNg57obvN4bQVjKY2QApzYeaMN7dpaVah0UCnLnCXDaW0TXKQ181X6YRT+Zz7THdgbW2g4sW7HwmC9WirDv9KdMu/tsCFqTkHX0A+ptgNKdyXDHSPigoc0Hzu6iygoeThpfYJRBo7zjJHTsU= 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 175879392129442.55508377118292; Thu, 25 Sep 2025 02:52:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1iZ0-0001d3-1w; Thu, 25 Sep 2025 05:46:58 -0400 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 1v1iYU-0001Hc-25 for qemu-devel@nongnu.org; Thu, 25 Sep 2025 05:46:26 -0400 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 1v1iY2-0001d3-0G for qemu-devel@nongnu.org; Thu, 25 Sep 2025 05:46:23 -0400 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-286-3K4yMJz_MuKvm04cz0dcCw-1; Thu, 25 Sep 2025 05:45:49 -0400 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 E38131800378; Thu, 25 Sep 2025 09:45:47 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.163]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 72F27300021A; Thu, 25 Sep 2025 09:45:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758793552; 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=jD7prJ6ro51U/diLj3k7/GWH5jMUoGvOMefAMKMPzjA=; b=SbWUbNY09cJ26Uo2ZRKMx//Q/RDUQ1g+IJs0Q2RiOdw2bVeVfg7vR1BvCvUboWqQFW0+6j 7PMVUQ1L3OT5p86Y6y2s9SqtUC6NtJeldTrv8EjzhVHdqjLqQO/L3siZVzbOQMq1V4yL44 X24Fd70n6VVNxGc4kI3kQ60iP+3kFmc= X-MC-Unique: 3K4yMJz_MuKvm04cz0dcCw-1 X-Mimecast-MFC-AGG-ID: 3K4yMJz_MuKvm04cz0dcCw_1758793548 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , qemu-rust@nongnu.org, Richard Henderson , Markus Armbruster , Christian Schoenebeck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , qemu-block@nongnu.org, Stefan Weil , "Dr. David Alan Gilbert" , Manos Pitsidianakis , Gerd Hoffmann , devel@lists.libvirt.org, Paolo Bonzini Subject: [PATCH v4 10/23] ui/vnc: remove use of error_printf_unless_qmp() Date: Thu, 25 Sep 2025 10:44:28 +0100 Message-ID: <20250925094441.1651372-11-berrange@redhat.com> In-Reply-To: <20250925094441.1651372-1-berrange@redhat.com> References: <20250925094441.1651372-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: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.444, 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 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: 1758793923451116600 The error_printf_unless_qmp() will print to the monitor if the current one is HMP, if it is QMP nothing will be printed, otherwise stderr will be used. This scenario is easily handled by checking !monitor_cur_is_qmp() and then calling the error_printf() function. Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Richard Henderson Reviewed-by: Markus Armbruster Signed-off-by: Daniel P. Berrang=C3=A9 --- ui/vnc.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/ui/vnc.c b/ui/vnc.c index 77c823bf2e..3cc5b4cfec 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -3530,8 +3530,10 @@ int vnc_display_password(const char *id, const char = *password) 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"); + if (!monitor_cur_is_qmp()) { + error_printf("If you want to use passwords, please enable " + "password auth using '-vnc ${dpy},password'.\n"); + } return -EINVAL; } =20 @@ -3570,9 +3572,11 @@ 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); + if (!monitor_cur_is_qmp()) { + error_printf("VNC server running on %s:%s\n", + addr->u.inet.host, + addr->u.inet.port); + } qapi_free_SocketAddress(addr); } =20 --=20 2.50.1 From nobody Sun Sep 28 14:52:12 2025 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=1758793881; cv=none; d=zohomail.com; s=zohoarc; b=QAyMOfLZAY23pV6wczz0ThR7zSPbO2+pMWoLf26ARgG/OCPiROo5xin7JRjIG7Dgp5sKF9zm3E+3JFNNmnmdTEs3osNexF1vGhhb0KvSh8021pcttS9MVoI5UVgyrXv1ne/9WVJWgPrUUslxwWaokTzpzKe72Ow/ZMb6X6nUiR0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758793881; 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=d8zaeKgrL77bsOTkPcLyH9cvhsAxPP+mGKTRj7L+pNs=; b=Dl8mNt96fo47Vm8aesNiPKYAjeUHMMrKeRjNU//9sb+WoPJzrsCO4zy5S+NOdUM5CwYbZe4pGnyAunYsIKhN4ArB3pCYOtB95WlVM8JAuD7KocnyXZ1d5/lr7LQzT+1OtucxvYqQ8K7CWCi4GsPGLZTROEnV9NIOGmIgdf3G8S0= 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 1758793881747267.41046658818016; Thu, 25 Sep 2025 02:51:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1iZ4-0001j9-2L; Thu, 25 Sep 2025 05:47:03 -0400 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 1v1iYc-0001LD-8w for qemu-devel@nongnu.org; Thu, 25 Sep 2025 05:46:38 -0400 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 1v1iY8-0001fB-TU for qemu-devel@nongnu.org; Thu, 25 Sep 2025 05:46:31 -0400 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-155-ve8lVXzDPHmUK3smHXezwQ-1; Thu, 25 Sep 2025 05:45:55 -0400 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 B3306180047F; Thu, 25 Sep 2025 09:45:53 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.163]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 493A6300021A; Thu, 25 Sep 2025 09:45:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758793560; 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=d8zaeKgrL77bsOTkPcLyH9cvhsAxPP+mGKTRj7L+pNs=; b=YZYZg32MA2N1I2J/oQ2gxCF7Ld8U5ODzXpxhyxDgHFpTH+TtBvqiV1Mh7WxG96JBkfEecx xrEo0l4mXRHnRfupOhIz/IjFr+ycww2XfvXYchOW1e1VfQ5Thtu8C1dHaguMQovhIdERbs SB8+14lx3Hp3BrpE3JiTjKOPmEw0h1g= X-MC-Unique: ve8lVXzDPHmUK3smHXezwQ-1 X-Mimecast-MFC-AGG-ID: ve8lVXzDPHmUK3smHXezwQ_1758793553 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , qemu-rust@nongnu.org, Richard Henderson , Markus Armbruster , Christian Schoenebeck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , qemu-block@nongnu.org, Stefan Weil , "Dr. David Alan Gilbert" , Manos Pitsidianakis , Gerd Hoffmann , devel@lists.libvirt.org, Paolo Bonzini Subject: [PATCH v4 11/23] monitor: remove redundant error_[v]printf_unless_qmp Date: Thu, 25 Sep 2025 10:44:29 +0100 Message-ID: <20250925094441.1651372-12-berrange@redhat.com> In-Reply-To: <20250925094441.1651372-1-berrange@redhat.com> References: <20250925094441.1651372-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: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.444, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 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: 1758793882853116600 These functions only had one caller which was easily converted to the normal error_printf() function. Remove them as they don't add sufficient value. 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 da54e1b1ce..03dbe5d131 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.50.1 From nobody Sun Sep 28 14:52:12 2025 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=1758793700; cv=none; d=zohomail.com; s=zohoarc; b=gTsIKd2yy+BrTmhJL3zyicbYkKjnlDYDeWVm9treOtu3m1/y4y3BARIG5UMs9O04uV1asa2MhB7qm+YWEsXBb4a8gBWojbEPEJB8CaAfUpzYj8/US4Sls0haTH+YZgYEc/ULGXB0hDVivXwOeK/wqXNZUyEUyop9B2wUSwo3gWs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758793700; 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=Ugudzj32e/ssPp8BKwBNNrrfFJbjTzUZnBF82CHpjVU=; b=HbgwGOZjYyouy7DAIu541zv2JIIuRpygzvmi52pT10zOH28jzfOUPZcGxZIcTcinZvzRu4BEXDz2k/qKQOJyD6EkM4gyfzhP0jDqRg4NffZ79vkP4K6/tZGYBfKpE0cOqpBMxC6TQTdB4WFo8nGT2MNTjNBv2gTontk+wIe8AXM= 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 1758793700822925.5290769742317; Thu, 25 Sep 2025 02:48:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1iZ6-0001h0-TF; Thu, 25 Sep 2025 05:47:05 -0400 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 1v1iYd-0001LB-6q for qemu-devel@nongnu.org; Thu, 25 Sep 2025 05:46:38 -0400 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 1v1iYD-0001fp-D4 for qemu-devel@nongnu.org; Thu, 25 Sep 2025 05:46:32 -0400 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-568-Xxa35lJBMXGKZZbOj_1S8w-1; Thu, 25 Sep 2025 05:46:01 -0400 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 F08F9180057A; Thu, 25 Sep 2025 09:45:59 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.163]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3567D300021A; Thu, 25 Sep 2025 09:45:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758793565; 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=Ugudzj32e/ssPp8BKwBNNrrfFJbjTzUZnBF82CHpjVU=; b=abwDldbRlAYjWIWJ2IY1871q7ZGBtAOlFIU/3z8cG4Y6ZpUW48Z+JB8iRTZnMRRI9J1W3r DatpBx/sII5cU/DwWUFzbyXggB98v08ufTcXzgn2tnIYgBBpSZXLqbQ/903Bq7FcRrD1lb 8Os++n/BnTTT6AsMGs8bUUxZwpn1170= X-MC-Unique: Xxa35lJBMXGKZZbOj_1S8w-1 X-Mimecast-MFC-AGG-ID: Xxa35lJBMXGKZZbOj_1S8w_1758793560 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , qemu-rust@nongnu.org, Richard Henderson , Markus Armbruster , Christian Schoenebeck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , qemu-block@nongnu.org, Stefan Weil , "Dr. David Alan Gilbert" , Manos Pitsidianakis , Gerd Hoffmann , devel@lists.libvirt.org, Paolo Bonzini Subject: [PATCH v4 12/23] monitor: refactor error_vprintf() Date: Thu, 25 Sep 2025 10:44:30 +0100 Message-ID: <20250925094441.1651372-13-berrange@redhat.com> In-Reply-To: <20250925094441.1651372-1-berrange@redhat.com> References: <20250925094441.1651372-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: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.444, 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 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: 1758793702417116600 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. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Richard Henderson --- monitor/monitor.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/monitor/monitor.c b/monitor/monitor.c index 03dbe5d131..c00f4aac5a 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -268,17 +268,19 @@ void monitor_printc(Monitor *mon, int c) monitor_printf(mon, "'"); } =20 -/* - * Print to current 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.50.1 From nobody Sun Sep 28 14:52:12 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1758796878; cv=none; d=zohomail.com; s=zohoarc; b=NEt4XebBn0aXHGHeDbI9H3FJbNoRYgmRLmB5dTiDWVnCnEXN2l1Cc2EU0h4bJiXhIeG/m33K/Yk5gyTwxfTUfjlcJaVrX0ER2CqSXJayEDi2ij9d7nOYTdw31DVKunSL+KxbNHJSoVcOHlQeBzyouMX6ZqItAyNcJGAcq4OcxAQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758796878; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id; bh=/7NCvE3YA5VgWxx+9mzBYupMJGGpqZizO+jRicuvJQE=; b=PCtVGU2E5flJVXfjsHHDkBXz3vWthUG4uarWYDDrrzSdWxvPsU4NXkdKsNTKDXODUZtBYQVbX6Li+W9/g5A40StQUqpXI4fBMBIZUEqRZj57yIr1Cb+pIWvgU+6usd0RTvAuYpWyA61dNalEEpb/ZXr8FmcbLhFjw1Tw6K+jXMw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1758796878061130.73256372840217; Thu, 25 Sep 2025 03:41:18 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id BF0A844037; Thu, 25 Sep 2025 06:41:16 -0400 (EDT) Received: from [172.19.199.14] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 5B4FB442E1; Thu, 25 Sep 2025 05:49:42 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id CCAAA43DC9; Thu, 25 Sep 2025 05:48:30 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 9561843EC9 for ; Thu, 25 Sep 2025 05:46:10 -0400 (EDT) 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-54-k3uQ7FnPPoO1ftCINJkTBw-1; Thu, 25 Sep 2025 05:46:06 -0400 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 62A8A18002CD; Thu, 25 Sep 2025 09:46:05 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.163]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 82E7D300021A; Thu, 25 Sep 2025 09:46:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758793570; 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=/7NCvE3YA5VgWxx+9mzBYupMJGGpqZizO+jRicuvJQE=; b=LkTa64TL7qMKK2CpQonFI6dYcSozI6aXQJXqNfjK450YhZ7WHWEJFNnb/sfJBpGFNCTSuY bI/jQVAUDZF9Hyap4NU8lekC46d0/zHTEseM+rOOkUMS/XXMQ4z+9n9pB0xFcOGzlCVBy6 gmkU2LK9B35kL21eH7ZuLsv+5sNfHmQ= X-MC-Unique: k3uQ7FnPPoO1ftCINJkTBw-1 X-Mimecast-MFC-AGG-ID: k3uQ7FnPPoO1ftCINJkTBw_1758793565 To: qemu-devel@nongnu.org Subject: [PATCH v4 13/23] monitor: move error_vprintf back to error-report.c Date: Thu, 25 Sep 2025 10:44:31 +0100 Message-ID: <20250925094441.1651372-14-berrange@redhat.com> In-Reply-To: <20250925094441.1651372-1-berrange@redhat.com> References: <20250925094441.1651372-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 Message-ID-Hash: RXN2AYOSN4OIDPOBB7S4XHRRCTC4EKNF X-Message-ID-Hash: RXN2AYOSN4OIDPOBB7S4XHRRCTC4EKNF X-MailFrom: berrange@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , qemu-rust@nongnu.org, Richard Henderson , Markus Armbruster , Christian Schoenebeck , qemu-block@nongnu.org, Stefan Weil , "Dr. David Alan Gilbert" , Manos Pitsidianakis , Gerd Hoffmann , devel@lists.libvirt.org, Paolo Bonzini X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9_via_Devel?= Reply-To: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758796879646116600 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_SLENT_ERROS 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. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Eric Blake Reviewed-by: Richard Henderson --- monitor/monitor.c | 15 --------------- stubs/error-printf.c | 18 ------------------ stubs/meson.build | 1 - stubs/monitor-core.c | 14 +++++++++++++- util/error-report.c | 15 +++++++++++++++ 5 files changed, 28 insertions(+), 35 deletions(-) delete mode 100644 stubs/error-printf.c diff --git a/monitor/monitor.c b/monitor/monitor.c index c00f4aac5a..e1e5dbfcbe 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -268,21 +268,6 @@ void monitor_printc(Monitor *mon, int c) monitor_printf(mon, "'"); } =20 -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 cef046e685..f58371f685 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..b262ad01cb 100644 --- a/util/error-report.c +++ b/util/error-report.c @@ -29,6 +29,21 @@ bool message_with_timestamp; bool error_with_guestname; const char *error_guest_name; =20 +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.50.1 From nobody Sun Sep 28 14:52:12 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1758797519; cv=none; d=zohomail.com; s=zohoarc; b=F8StVdKTwxCgyCpxFaaz7Zwn4LHu7onP6s6xmXJebuuGwBlZlx7FBHnP5K8l62oXBI8m4CIQTAv030oISdeUOzGrMZK57bZ4WEz54i3bwcY8/e4/PhcQp6McWlNLys8HQ8Ye8Isiyg3ettci7hZ188TKX2n1FmoO0Vh8UrLIFnc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758797519; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id; bh=vW6Zcy8SEi94ilhlXlW2XDXvc9roCnjBwhekfmMa7Ms=; b=Xo8lil26wv2B7h7fIzEkFt4f0zTIuo8uXrqWccJSnfzZHaDRycQFYNcIJCaWyQHGK+rgQQEPVk9ucFgGzCLd24GhSwbCRtv8UDvCcGVe0MSILqjyUNidMeqpY2de7sDSwvWfBm7nqQ/MXbggrW+BwgEUAKbfZBDJQiHbElHZ3a8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1758797519534333.0149551395449; Thu, 25 Sep 2025 03:51:59 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id A27FC41882; Thu, 25 Sep 2025 06:51:58 -0400 (EDT) Received: from [172.19.199.14] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id F2829443AC; Thu, 25 Sep 2025 05:49:54 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 5565E43F59; Thu, 25 Sep 2025 05:48:32 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 0369B43ECC for ; Thu, 25 Sep 2025 05:46:16 -0400 (EDT) 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-270-T6SAToMtM8K9tF8vIO7RwA-1; Thu, 25 Sep 2025 05:46:12 -0400 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 2234C18002C4; Thu, 25 Sep 2025 09:46:11 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.163]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id F21B9300021A; Thu, 25 Sep 2025 09:46:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758793576; 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=vW6Zcy8SEi94ilhlXlW2XDXvc9roCnjBwhekfmMa7Ms=; b=AGWTtLwYjg43yPbrHtCYV/z5ZAapD0odfoS3oFdQ+AqzCaX2z2UUG+GhNie7wCB9gkzgB/ SWuDoLM79w7pTwBQQ4Xv/zyHEf9kiLOI46vpUf95yJ7JnO6Tpc5FGG1R7wJuWvDe6IcB7R qYrT82g1o70KPZpOoQ1PkiA5uGslhHY= X-MC-Unique: T6SAToMtM8K9tF8vIO7RwA-1 X-Mimecast-MFC-AGG-ID: T6SAToMtM8K9tF8vIO7RwA_1758793571 To: qemu-devel@nongnu.org Subject: [PATCH v4 14/23] monitor: introduce monitor_cur_is_hmp() helper Date: Thu, 25 Sep 2025 10:44:32 +0100 Message-ID: <20250925094441.1651372-15-berrange@redhat.com> In-Reply-To: <20250925094441.1651372-1-berrange@redhat.com> References: <20250925094441.1651372-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 Message-ID-Hash: V5YBGJU7IL4NMJOECKMKQBBI253PEKZ3 X-Message-ID-Hash: V5YBGJU7IL4NMJOECKMKQBBI253PEKZ3 X-MailFrom: berrange@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , qemu-rust@nongnu.org, Richard Henderson , Markus Armbruster , Christian Schoenebeck , qemu-block@nongnu.org, Stefan Weil , "Dr. David Alan Gilbert" , Manos Pitsidianakis , Gerd Hoffmann , devel@lists.libvirt.org, Paolo Bonzini X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9_via_Devel?= Reply-To: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758797520435116600 Note that this is not simply the inverse of monitor_cur_is_qmp(), as both helpers require that monitor_cur() is first non-NULL. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Richard Henderson --- include/monitor/monitor.h | 1 + monitor/monitor.c | 10 ++++++++++ stubs/monitor-core.c | 6 ++++++ tests/unit/test-util-sockets.c | 1 + 4 files changed, 18 insertions(+) diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index 296690e1f1..9c71e6cf3c 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -16,6 +16,7 @@ extern QemuOptsList qemu_mon_opts; Monitor *monitor_cur(void); Monitor *monitor_set_cur(Coroutine *co, Monitor *mon); bool monitor_cur_is_qmp(void); +bool monitor_cur_is_hmp(void); =20 void monitor_init_globals(void); void monitor_init_globals_core(void); diff --git a/monitor/monitor.c b/monitor/monitor.c index e1e5dbfcbe..27be5d7c73 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -116,6 +116,16 @@ bool monitor_cur_is_qmp(void) return cur_mon && monitor_is_qmp(cur_mon); } =20 +/** + * Is the current monitor, if any, a HMP monitor? + */ +bool monitor_cur_is_hmp(void) +{ + Monitor *cur_mon =3D monitor_cur(); + + return cur_mon && !monitor_is_qmp(cur_mon); +} + /** * Is @mon is using readline? * Note: not all HMP monitors use readline, e.g., gdbserver has a diff --git a/stubs/monitor-core.c b/stubs/monitor-core.c index a7c32297c9..674211f48f 100644 --- a/stubs/monitor-core.c +++ b/stubs/monitor-core.c @@ -7,6 +7,12 @@ Monitor *monitor_cur(void) return NULL; } =20 +bool monitor_cur_is_hmp(void) +{ + /* since monitor_cur() above returns NULL, this can't be true */ + 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..4b7f408902 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_hmp(void) { return false; } =20 #ifndef _WIN32 static void test_socket_fd_pass_name_good(void) --=20 2.50.1 From nobody Sun Sep 28 14:52:12 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1758797304; cv=none; d=zohomail.com; s=zohoarc; b=A1qZAURMyOLEXJPl8Ud+k0i6qBDiVRFp6MNVafkqXbqmfGidHa2HedSfAFNuxQo5mdiL0S91XTcDCPhqXFCGqaZONnkEOo6XFm1coCBr4BhZ7QUOwp3zhTLELSgkB02LLnDbhEhDyc3dDrri20a0rxlxghWimBR3WnPdgD9vJ7c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758797304; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id; bh=4eqRD9Zdeyk92VWPnwKxNF1eluR+jCOfRnC3AfnbZNU=; b=fwSolSu/U55pClvPHvdIeTFkcajaUF7ubEGO2gXTLw3vIY1qBBcMGKK/cIc/q8ath9mG8cPkh9yNrcSXtA4691yJLy5Hl+KWvpEgDfmaYs4kakDeaRacMKe/6VvCHuAB1f6xBn95AwJc+KjOq4oYBA7oh4qguzCdGftHnESHPl8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1758797304354711.3007433987804; Thu, 25 Sep 2025 03:48:24 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 467354408A; Thu, 25 Sep 2025 06:48:23 -0400 (EDT) Received: from [172.19.199.14] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 479784435C; Thu, 25 Sep 2025 05:49:50 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id D15B941C83; Thu, 25 Sep 2025 05:48:31 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 75EC341ABE for ; Thu, 25 Sep 2025 05:46:20 -0400 (EDT) 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-467-t0MUrkWyNHW2HU3sj-E1Ag-1; Thu, 25 Sep 2025 05:46:18 -0400 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 0A374180057D; Thu, 25 Sep 2025 09:46:17 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.163]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B185730002D2; Thu, 25 Sep 2025 09:46:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758793580; 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=4eqRD9Zdeyk92VWPnwKxNF1eluR+jCOfRnC3AfnbZNU=; b=EcWH1+3a6U+Etd+psp7eblV+SOKlWT0Tu4lXusmwzPosv0uVfxNtbcdbq1tKrqPA98qfME GpwqIvnjRzsm7IZ9jNn9XzZSvmQqhx/+a1qMz8fF+MoZoa/1Vg4/SdZL3k/B/H+VHx0wgG sPPEnI57hLp8J8sU6sb2ts3F44yTRZE= X-MC-Unique: t0MUrkWyNHW2HU3sj-E1Ag-1 X-Mimecast-MFC-AGG-ID: t0MUrkWyNHW2HU3sj-E1Ag_1758793577 To: qemu-devel@nongnu.org Subject: [PATCH v4 15/23] util: don't skip error prefixes when QMP is active Date: Thu, 25 Sep 2025 10:44:33 +0100 Message-ID: <20250925094441.1651372-16-berrange@redhat.com> In-Reply-To: <20250925094441.1651372-1-berrange@redhat.com> References: <20250925094441.1651372-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 Message-ID-Hash: RCS3RONIMYUNYX2S34XGKQKN76MMT3KH X-Message-ID-Hash: RCS3RONIMYUNYX2S34XGKQKN76MMT3KH X-MailFrom: berrange@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , qemu-rust@nongnu.org, Richard Henderson , Markus Armbruster , Christian Schoenebeck , qemu-block@nongnu.org, Stefan Weil , "Dr. David Alan Gilbert" , Manos Pitsidianakis , Gerd Hoffmann , devel@lists.libvirt.org, Paolo Bonzini X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9_via_Devel?= Reply-To: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758797305661116600 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). Signed-off-by: Daniel P. Berrang=C3=A9 --- util/error-report.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/util/error-report.c b/util/error-report.c index b262ad01cb..872158ad90 100644 --- a/util/error-report.c +++ b/util/error-report.c @@ -159,7 +159,7 @@ static void print_loc(void) int i; const char *const *argp; =20 - if (!monitor_cur() && g_get_prgname()) { + if (!monitor_cur_is_hmp() && g_get_prgname()) { error_printf("%s:", g_get_prgname()); sep =3D " "; } @@ -203,14 +203,14 @@ static void vreport(report_type type, const char *fmt= , va_list ap) { gchar *timestr; =20 - if (message_with_timestamp && !monitor_cur()) { + if (message_with_timestamp && !monitor_cur_is_hmp()) { timestr =3D real_time_iso8601(); error_printf("%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()) { + if (error_with_guestname && error_guest_name && !monitor_cur_is_hmp())= { error_printf("%s ", error_guest_name); } =20 --=20 2.50.1 From nobody Sun Sep 28 14:52:13 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1758796466; cv=none; d=zohomail.com; s=zohoarc; b=Upxm5Tad1iaexHBgGXnKpAizQmipwuTOTj04FG3NhEFUrfk2Ee5qL4FigXarhBPCsQHrXiCwNaY6fISJPHATJst8aeMNPQmN/Z0WeeshJdjj1GJ+jSFp3/Ob4O8LzNWPvHEvTDISQXaAKT95NvpEQPFXeFJhSvK72j/EppeJQQw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758796466; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id; bh=7PgG9dCiPetJ2cgwCkBjjUAEVTES+WQEQc0OK6526QM=; b=auzf7+N2GnlOqr6UtitYDGQPW/RM2wrqG2DSjVQk7qqCUBsytSWPsMw5IZN8majMtJrwvdaDK8h6bNnXbJiyQaGzy6pW4Y+vTUC4aTsu24EpFVk5Z9R7CHrkxtgCypF+6JZ/qxB8550HGuC/M2JIKDMsrNyLza4P/qYMorwl9T0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1758796466439466.2660359669495; Thu, 25 Sep 2025 03:34:26 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 6FA8841AB3; Thu, 25 Sep 2025 06:34:25 -0400 (EDT) Received: from [172.19.199.14] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 4F49C4425B; Thu, 25 Sep 2025 05:49:32 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 23E2B43F5A; Thu, 25 Sep 2025 05:48:30 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id E12D941B48 for ; Thu, 25 Sep 2025 05:46:27 -0400 (EDT) Received: from mx-prod-mc-04.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-498-Cop-hN-HMNmu7CLBKcBHwQ-1; Thu, 25 Sep 2025 05:46:24 -0400 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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B01F919560AF; Thu, 25 Sep 2025 09:46:22 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.163]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 740FD30002D0; Thu, 25 Sep 2025 09:46:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758793587; 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=7PgG9dCiPetJ2cgwCkBjjUAEVTES+WQEQc0OK6526QM=; b=c74gZrtrZBVJe206gGUX5qL4B3vjsARtakUdwcq4uxXwLKD8yxvgoWNNB3TNEsPX6tadJe UMB0EUhfoOMMDsPrnPYqQylIuKYFDn9lW1kQM/XZ8QcRrcoguJ9hXDPYMsrQopkfVFCxBf bxFUeHrHNjylQLIgHKa3LaRP8yOpiic= X-MC-Unique: Cop-hN-HMNmu7CLBKcBHwQ-1 X-Mimecast-MFC-AGG-ID: Cop-hN-HMNmu7CLBKcBHwQ_1758793582 To: qemu-devel@nongnu.org Subject: [PATCH v4 16/23] util: fix interleaving of error & trace output Date: Thu, 25 Sep 2025 10:44:34 +0100 Message-ID: <20250925094441.1651372-17-berrange@redhat.com> In-Reply-To: <20250925094441.1651372-1-berrange@redhat.com> References: <20250925094441.1651372-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 Message-ID-Hash: NGKJDS7QL5YCDAZC3NDEBEHFBKDIRMW6 X-Message-ID-Hash: NGKJDS7QL5YCDAZC3NDEBEHFBKDIRMW6 X-MailFrom: berrange@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , qemu-rust@nongnu.org, Richard Henderson , Markus Armbruster , Christian Schoenebeck , qemu-block@nongnu.org, Stefan Weil , "Dr. David Alan Gilbert" , Manos Pitsidianakis , Gerd Hoffmann , devel@lists.libvirt.org, Paolo Bonzini X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9_via_Devel?= Reply-To: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758796467131116600 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. $ 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 Signed-off-by: Daniel P. Berrang=C3=A9 --- util/error-report.c | 67 +++++++++++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 21 deletions(-) diff --git a/util/error-report.c b/util/error-report.c index 872158ad90..222c40d0d1 100644 --- a/util/error-report.c +++ b/util/error-report.c @@ -29,9 +29,12 @@ bool message_with_timestamp; bool error_with_guestname; const char *error_guest_name; =20 -int error_vprintf(const char *fmt, va_list ap) +/* + * Print to current monitor if we have one, else to stderr. + */ +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 @@ -44,13 +47,30 @@ int error_vprintf(const char *fmt, va_list ap) return ret; } =20 +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; } @@ -153,34 +173,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_is_hmp() && g_get_prgname()) { - error_printf("%s:", g_get_prgname()); + if (!cur && g_get_prgname()) { + error_printf_mon(NULL, "%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 @@ -201,34 +221,39 @@ real_time_iso8601(void) G_GNUC_PRINTF(2, 0) static void vreport(report_type type, const char *fmt, va_list ap) { + Monitor *cur =3D NULL; gchar *timestr; =20 - if (message_with_timestamp && !monitor_cur_is_hmp()) { + if (monitor_cur_is_hmp()) { + cur =3D monitor_cur(); + } + + if (message_with_timestamp && !cur) { timestr =3D real_time_iso8601(); - error_printf("%s ", timestr); + error_printf_mon(NULL, "%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_is_hmp())= { - error_printf("%s ", error_guest_name); + if (error_with_guestname && error_guest_name && !cur) { + error_printf_mon(NULL, "%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.50.1 From nobody Sun Sep 28 14:52:13 2025 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=1758793975; cv=none; d=zohomail.com; s=zohoarc; b=ERHcQarDScjAUpm0e6I4ypLIsg+phlOXZOdSGm17tm6bsxfKXaESBBRHfhS3Vl5SKbKVMy4Z/FytaWidTV/DddPmZK337dUUEzfk/MiQuEo0iy8k/4zNAMB9spLZyZN4AHmI6ZRgTlPgifxGEGbxs5xHdQimZU5/1BghPvNnX7s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758793975; 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=VCiJbepTzAS/un2RtpHR4Hvplf9c95e2auSHQriyqk4=; b=QugZ43HiA14JnrtT/8/8yU9ZyX6gnYo+uHa5mentQjaUe/bF29QKaZEsnFWysRLMCELUOPF7iv0XFOkkrCYNubOChAW2l8DLEJJH8fOxv3zBXLRqypKAGP5z7oPHdLn+7+P3BNc/KiUUR8ArTthUeVJ8j3eItNGO/3ru5w6b4QE= 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 1758793975230544.1873384876495; Thu, 25 Sep 2025 02:52:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1iZI-00022t-PD; Thu, 25 Sep 2025 05:47:16 -0400 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 1v1iYu-0001Xo-O0 for qemu-devel@nongnu.org; Thu, 25 Sep 2025 05:46:55 -0400 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 1v1iYc-0001lP-PR for qemu-devel@nongnu.org; Thu, 25 Sep 2025 05:46:52 -0400 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-517-DE_8BKf3NRuGZdH2N0NOYg-1; Thu, 25 Sep 2025 05:46:29 -0400 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 6C7031800343; Thu, 25 Sep 2025 09:46:28 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.163]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1E0F7300021A; Thu, 25 Sep 2025 09:46:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758793591; 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=VCiJbepTzAS/un2RtpHR4Hvplf9c95e2auSHQriyqk4=; b=VW3UILIXzmiwAY4zqR6lN1RGNDPo8bBBT9sJ9+eKpZLRWYozYm6N2+Z3uEOzVMA0gLw+b5 ag6uvwFpws2fR0lB8qEW75yYVelWAeMoeSi/oPDKehbOguXQ8WR7rxAAJigTPOkN9sYUFk uHuqY8p+ddQOzCqSGqR5rx7g/Iso70o= X-MC-Unique: DE_8BKf3NRuGZdH2N0NOYg-1 X-Mimecast-MFC-AGG-ID: DE_8BKf3NRuGZdH2N0NOYg_1758793588 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , qemu-rust@nongnu.org, Richard Henderson , Markus Armbruster , Christian Schoenebeck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , qemu-block@nongnu.org, Stefan Weil , "Dr. David Alan Gilbert" , Manos Pitsidianakis , Gerd Hoffmann , devel@lists.libvirt.org, Paolo Bonzini Subject: [PATCH v4 17/23] util: fix interleaving of error prefixes Date: Thu, 25 Sep 2025 10:44:35 +0100 Message-ID: <20250925094441.1651372-18-berrange@redhat.com> In-Reply-To: <20250925094441.1651372-1-berrange@redhat.com> References: <20250925094441.1651372-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: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.444, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 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: 1758793976475116600 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. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson --- util/error-report.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/util/error-report.c b/util/error-report.c index 222c40d0d1..b6aa20dbae 100644 --- a/util/error-report.c +++ b/util/error-report.c @@ -226,6 +226,8 @@ static void vreport(report_type type, const char *fmt, = va_list ap) =20 if (monitor_cur_is_hmp()) { cur =3D monitor_cur(); + } else { + flockfile(stderr); } =20 if (message_with_timestamp && !cur) { @@ -254,6 +256,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) { + funlockfile(stderr); + } } =20 /* --=20 2.50.1 From nobody Sun Sep 28 14:52:13 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1758797724; cv=none; d=zohomail.com; s=zohoarc; b=nVBFE49sFjWchzPzfunQL4EJT/i2Vdxxb0Rt31fgCiP+p4av2OJEUlvIt1FHAH+KEJpNqjg+8EgG44UDqMOseZf122MGP5G4ddtjtNRx0bgdFBmH6bEDBUUw1aNQlF6nngwB7iFWjK83k4qfaJfA1HhgAyWS7wxQXgE9PZbH+gk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758797724; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id; bh=mZJoRmH0LzYy4u3t3prpzh/NicjETYCxcryAx0u5eAw=; b=Rd7jjjRNLUbsxRYiqyDBfg49D7Uh7QC6wkgnFV2cjj/FKLaelWUrfpN/B2TWDDdmugL32cNtoHgJt96xIqXpK1N+pb3cGYk4DFPnf+WKxax3CYpScngRg2UBWd9wdhMHqs7Kp0ncBronHYfqxQ52ZDabDmUbg/c4IIGoue87QGY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1758797724217918.5245802978734; Thu, 25 Sep 2025 03:55:24 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 306974409C; Thu, 25 Sep 2025 06:55:23 -0400 (EDT) Received: from [172.19.199.14] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 2A8F8443F3; Thu, 25 Sep 2025 05:49:59 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id D24BB43DE8; Thu, 25 Sep 2025 05:48:34 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 4EBE441837 for ; Thu, 25 Sep 2025 05:46:41 -0400 (EDT) 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-288-orMQIbdsMvqdmttta_mbwg-1; Thu, 25 Sep 2025 05:46:36 -0400 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 93B991956053; Thu, 25 Sep 2025 09:46:34 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.163]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 10F3B300021A; Thu, 25 Sep 2025 09:46:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758793601; 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=mZJoRmH0LzYy4u3t3prpzh/NicjETYCxcryAx0u5eAw=; b=I/DvQzaRejHcN4crhzatnb5zPtf05NSje4VsC2FSF/iQAbzI4yo5UnbdOITe9CATN+RJqJ tv9+KWL9MXm2M71so4X08McpgSoQJ+luqW9RM2Ju8EN6g8ylqIi9YKOinwX8hwTMD0HdLo EZWExg6AF694KGelIFg2kdDDhGtCMMM= X-MC-Unique: orMQIbdsMvqdmttta_mbwg-1 X-Mimecast-MFC-AGG-ID: orMQIbdsMvqdmttta_mbwg_1758793594 To: qemu-devel@nongnu.org Subject: [PATCH v4 18/23] util: introduce common helper for error-report & log code Date: Thu, 25 Sep 2025 10:44:36 +0100 Message-ID: <20250925094441.1651372-19-berrange@redhat.com> In-Reply-To: <20250925094441.1651372-1-berrange@redhat.com> References: <20250925094441.1651372-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 Message-ID-Hash: ROFFKLAK2H5GQFDYDBDDPZSJVOMV6GDH X-Message-ID-Hash: ROFFKLAK2H5GQFDYDBDDPZSJVOMV6GDH X-MailFrom: berrange@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , qemu-rust@nongnu.org, Richard Henderson , Markus Armbruster , Christian Schoenebeck , qemu-block@nongnu.org, Stefan Weil , "Dr. David Alan Gilbert" , Manos Pitsidianakis , Gerd Hoffmann , devel@lists.libvirt.org, Paolo Bonzini X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9_via_Devel?= Reply-To: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758797726802116600 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 | 22 ++++++++++++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 include/qemu/message.h create mode 100644 util/message.c diff --git a/MAINTAINERS b/MAINTAINERS index 24b71a4fc5..e128a9d3be 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3173,9 +3173,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 35029380a3..f5365e3b4f 100644 --- a/util/meson.build +++ b/util/meson.build @@ -40,6 +40,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..643f10c06a --- /dev/null +++ b/util/message.c @@ -0,0 +1,22 @@ +/* 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); + fprintf(fp, "%s ", timestr); + } +} --=20 2.50.1 From nobody Sun Sep 28 14:52:13 2025 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=1758794050; cv=none; d=zohomail.com; s=zohoarc; b=YHOFz6NX5WPswLz8EmtyCMvaO6gQQQSWco7eCngytzTI7fd4jmH6oo/rb6TGHTPIevSVEFXFJnplUQYq7nuMiAMhmCSS/omvSg9mQZ4NYMOMqXRnIRMZnDPiJNL8Yk2YrNawRqNOd8nr5UEL2xxYGA1PY9Hm5imOm2hpjHvQfhw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758794050; 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=FDsHnPrAoFbGd/P2xepGIRR9aZ5c2NPZs/ZC5HlKXtI=; b=NpTd3yK/H1kp2OneeKlZVbfnRaVmNF9oYlOqsuTC5l44s/G84s6M/RmBL2YSssNdocry793SbkPyadWDcyb3hNGYwLNquaWjBCMfqST7ltglBudfv6d5NDwx3TxzgrW5stmZVJsestONVXpKisSVu0KnMo2r2Ub92p/0uP/JKc8= 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 1758794050392176.00620487160438; Thu, 25 Sep 2025 02:54:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1iZN-00027u-CY; Thu, 25 Sep 2025 05:47:21 -0400 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 1v1iZH-00020P-7F for qemu-devel@nongnu.org; Thu, 25 Sep 2025 05:47:15 -0400 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 1v1iYr-0001oE-5s for qemu-devel@nongnu.org; Thu, 25 Sep 2025 05:47:12 -0400 Received: from mx-prod-mc-04.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-vl-18jdPOOyHrLUMS0_e3Q-1; Thu, 25 Sep 2025 05:46:41 -0400 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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4FAB81955DB8; Thu, 25 Sep 2025 09:46:40 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.163]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 133BC300021A; Thu, 25 Sep 2025 09:46:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758793605; 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=FDsHnPrAoFbGd/P2xepGIRR9aZ5c2NPZs/ZC5HlKXtI=; b=PxPTQbHznqdWPonjy17DYw9KHC4eoDrv89ZJCuIofTP4A9LtwJtWz6DvasgSDR1GJnMxK2 H/7zoyHIHSWr4Fa8V6FsbPjMcVumqgFF7BrzLH3yTrvnRtc5RdZvzh2Di2feOX9MucE9ew uj9EMBYWxW2VLsq/C0kjPjrF0M5pfME= X-MC-Unique: vl-18jdPOOyHrLUMS0_e3Q-1 X-Mimecast-MFC-AGG-ID: vl-18jdPOOyHrLUMS0_e3Q_1758793600 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , qemu-rust@nongnu.org, Richard Henderson , Markus Armbruster , Christian Schoenebeck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , qemu-block@nongnu.org, Stefan Weil , "Dr. David Alan Gilbert" , Manos Pitsidianakis , Gerd Hoffmann , devel@lists.libvirt.org, Paolo Bonzini Subject: [PATCH v4 19/23] util: convert error-report & log to message API for timestamp Date: Thu, 25 Sep 2025 10:44:37 +0100 Message-ID: <20250925094441.1651372-20-berrange@redhat.com> In-Reply-To: <20250925094441.1651372-1-berrange@redhat.com> References: <20250925094441.1651372-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: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.444, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 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: 1758794051244116600 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 | 21 ++++----------------- 5 files changed, 14 insertions(+), 36 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 e0884c1bb9..12bfdb3431 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" @@ -814,8 +815,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 54319c86c9..78f8b57660 100644 --- a/tests/unit/test-error-report.c +++ b/tests/unit/test-error-report.c @@ -13,6 +13,7 @@ =20 #include "qemu/error-report.h" #include "qapi/error.h" +#include "qemu/message.h" =20 static void test_error_report_simple(void) @@ -90,7 +91,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 b6aa20dbae..c1146ba553 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 @@ -204,13 +203,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. @@ -222,18 +214,12 @@ G_GNUC_PRINTF(2, 0) static void vreport(report_type type, const char *fmt, va_list ap) { Monitor *cur =3D NULL; - gchar *timestr; =20 if (monitor_cur_is_hmp()) { cur =3D monitor_cur(); } else { flockfile(stderr); - } - - if (message_with_timestamp && !cur) { - timestr =3D real_time_iso8601(); - error_printf_mon(NULL, "%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 2642a55c59..baa33ad8f1 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" @@ -151,26 +152,12 @@ static __thread bool incomplete; =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 && !incomplete) { - 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(); if (f) { va_list ap; =20 - if (timestr) { - fprintf(f, "%s ", timestr); + if (!incomplete) { + qmessage_context_print(f); } =20 va_start(ap, fmt); --=20 2.50.1 From nobody Sun Sep 28 14:52:13 2025 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=1758793876; cv=none; d=zohomail.com; s=zohoarc; b=bP7Fupd4a/txQeLTzVBeJGRl1Ly2MJi3XP3cfiN7swjJQnk2Xm7z0gl1hBOH8MO3FWTCuujzhdd5oPreOPwHNrPxeUqc4dg8ZGqYWrU74BEsjbAK5cJjbOyIQuj0ct1Nm9KtOJSt44GtI7KizL4z/LibwI7bWCFdjEhRNYTDTs0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758793876; 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=DXX2z9ShU+pBPsRKbZGjT/VjkF+HGXekgva0FZOKO1A=; b=F857qX1fgJI0c9UVGAeRROMg3oQRJq5sn0ci1qDPu9bwd3s0WlgSxGWLvyDQcDg9njjXyju4uCXozvM4aQHDmHFxD5JlK/Vx6SMGCpyQzrJe2X8I7CX5Vjp/+KDm6Kb6R6R2cj+6YqLoEleBgdVcITIvcclzoUjkw8hIlYe9a4c= 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 1758793876589839.6589557157497; Thu, 25 Sep 2025 02:51:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1iZU-0002I2-LU; Thu, 25 Sep 2025 05:47:29 -0400 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 1v1iZI-00022b-F9 for qemu-devel@nongnu.org; Thu, 25 Sep 2025 05:47:16 -0400 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 1v1iZ0-0001pm-FU for qemu-devel@nongnu.org; Thu, 25 Sep 2025 05:47:15 -0400 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-325-rPrbN7AxPMWHhXXq-vp1Mg-1; Thu, 25 Sep 2025 05:46:47 -0400 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 0DCFD19560B1; Thu, 25 Sep 2025 09:46:46 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.163]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C7879300021A; Thu, 25 Sep 2025 09:46:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758793613; 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=DXX2z9ShU+pBPsRKbZGjT/VjkF+HGXekgva0FZOKO1A=; b=ZscpACD+VP547Iqwtca1HXN6uy9AQnlPXjNoTyCEnj9BiDOzcPmooV2EXuqwjZdq9opPjy RCLbJibuFFJeE14QONyApCYUOdF3Fz6bEe7yzrRFY5un9/MuZDPREMz4YLWf9AxnbJS3Ip 5JROedFos30SJgQghEf3HZCKVKPTpJg= X-MC-Unique: rPrbN7AxPMWHhXXq-vp1Mg-1 X-Mimecast-MFC-AGG-ID: rPrbN7AxPMWHhXXq-vp1Mg_1758793606 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , qemu-rust@nongnu.org, Richard Henderson , Markus Armbruster , Christian Schoenebeck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , qemu-block@nongnu.org, Stefan Weil , "Dr. David Alan Gilbert" , Manos Pitsidianakis , Gerd Hoffmann , devel@lists.libvirt.org, Paolo Bonzini Subject: [PATCH v4 20/23] util: add support for formatting a workload name in messages Date: Thu, 25 Sep 2025 10:44:38 +0100 Message-ID: <20250925094441.1651372-21-berrange@redhat.com> In-Reply-To: <20250925094441.1651372-1-berrange@redhat.com> References: <20250925094441.1651372-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: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.444, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 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: 1758793878898116600 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 Reviewed-by: Philippe Mathieu-Daud=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 | 11 +++++++++++ 5 files changed, 25 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 12bfdb3431..56829880f6 100644 --- a/system/vl.c +++ b/system/vl.c @@ -819,7 +819,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 @@ -3521,7 +3523,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 c1146ba553..edb04585aa 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 current monitor if we have one, else to stderr. @@ -222,11 +220,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) { - error_printf_mon(NULL, "%s ", error_guest_name); - } - print_loc(cur); =20 switch (type) { diff --git a/util/message.c b/util/message.c index 643f10c06a..a91c008e08 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) { @@ -19,4 +25,9 @@ void qmessage_context_print(FILE *fp) g_autofree char *timestr =3D g_date_time_format_iso8601(dt); fprintf(fp, "%s ", timestr); } + + if ((message_format & QMESSAGE_FORMAT_WORKLOAD_NAME) && + message_workloadname) { + fprintf(fp, "%s ", message_workloadname); + } } --=20 2.50.1 From nobody Sun Sep 28 14:52:13 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1758798356; cv=none; d=zohomail.com; s=zohoarc; b=agZ68TlLLnUiZIhj6cMXHLW7ssyS/9OWvo7R3bePwHREL7qF+/6a7cmiNRmhGNR7+dy8dd1bE7uH3O4WLgKi9NISWPkBU3+//V3mDCI4xdRWx0E4lzUg8bparKpzgsNEYMkUJQyfuzbYpb6WYABgs5zAU6mpflfJP5BNlnDE6R8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758798356; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id; bh=BZnC6QiBd1lbYvGRWS1LNh6guPnvUdl77jy61phbsAI=; b=fYSYXGxrwQGPaRj9pfcLNbNysfGj/fq/j78pglqSHtyp1AP/5oBuCEvSgizMcoez/c5IhmSIvSUC1IKbdChumgYecJ7WoSoo2s9Ol5A4xo90VCP8YetH1tO2Uk2m2ncMpBGSiRqCJU43fWTRH/8fIa8yDuTH+/yxbeZvKDFPG4g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1758798356810562.3059967577097; Thu, 25 Sep 2025 04:05:56 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id CAFE4418BC; Thu, 25 Sep 2025 07:05:55 -0400 (EDT) Received: from [172.19.199.14] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 41A28445CA; Thu, 25 Sep 2025 05:50:13 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id E46AE4409F; Thu, 25 Sep 2025 05:48:56 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id AFBDE43E5B for ; Thu, 25 Sep 2025 05:46:58 -0400 (EDT) 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-EHxMsjApNcy_vYIeoM-fMA-1; Thu, 25 Sep 2025 05:46:53 -0400 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 ACBE21800299; Thu, 25 Sep 2025 09:46:51 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.163]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9D4EA300021A; Thu, 25 Sep 2025 09:46:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758793618; 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=BZnC6QiBd1lbYvGRWS1LNh6guPnvUdl77jy61phbsAI=; b=b9rfxcKJU516oNGMwkPwW5CnD1A00tOaYQBuWtb6LaVAcEYQHOCzrNFvcv/9DZLj8h9Qx2 Hq6pu7+f6rip+b0UKks60GNBhlBzeE2ihhYJ+VZBU6/Q2h8T6scWvXiCD51Hkfk9Ufdy7O VMkoZ4fPQPwuL2G5UKhZdNZpUcF0sxE= X-MC-Unique: EHxMsjApNcy_vYIeoM-fMA-1 X-Mimecast-MFC-AGG-ID: EHxMsjApNcy_vYIeoM-fMA_1758793611 To: qemu-devel@nongnu.org Subject: [PATCH v4 21/23] util: add support for formatting a program name in messages Date: Thu, 25 Sep 2025 10:44:39 +0100 Message-ID: <20250925094441.1651372-22-berrange@redhat.com> In-Reply-To: <20250925094441.1651372-1-berrange@redhat.com> References: <20250925094441.1651372-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 Message-ID-Hash: H22HSSHGIFGOI34OA4QI3KIKZWBT57FQ X-Message-ID-Hash: H22HSSHGIFGOI34OA4QI3KIKZWBT57FQ X-MailFrom: berrange@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , qemu-rust@nongnu.org, Richard Henderson , Markus Armbruster , Christian Schoenebeck , qemu-block@nongnu.org, Stefan Weil , "Dr. David Alan Gilbert" , Manos Pitsidianakis , Gerd Hoffmann , devel@lists.libvirt.org, Paolo Bonzini X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9_via_Devel?= Reply-To: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758798359350116600 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 Reviewed-by: Richard Henderson Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/qemu/message.h | 1 + system/vl.c | 2 +- tests/unit/test-error-report.c | 5 +++-- util/error-report.c | 4 ---- util/message.c | 9 ++++++++- 5 files changed, 13 insertions(+), 8 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/system/vl.c b/system/vl.c index 56829880f6..0ac1b11caf 100644 --- a/system/vl.c +++ b/system/vl.c @@ -815,7 +815,7 @@ 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; } diff --git a/tests/unit/test-error-report.c b/tests/unit/test-error-report.c index 78f8b57660..3987a8ed25 100644 --- a/tests/unit/test-error-report.c +++ b/tests/unit/test-error-report.c @@ -48,7 +48,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*\ "); } @@ -91,7 +91,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 edb04585aa..b010f97bda 100644 --- a/util/error-report.c +++ b/util/error-report.c @@ -176,10 +176,6 @@ static void print_loc(Monitor *cur) int i; const char *const *argp; =20 - if (!cur && g_get_prgname()) { - error_printf_mon(NULL, "%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 a91c008e08..1db9254733 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) @@ -30,4 +30,11 @@ void qmessage_context_print(FILE *fp) message_workloadname) { fprintf(fp, "%s ", message_workloadname); } + + if (message_format & QMESSAGE_FORMAT_PROGRAM_NAME) { + const char *pgnamestr =3D g_get_prgname(); + if (pgnamestr) { + fprintf(fp, "%s: ", pgnamestr); + } + } } --=20 2.50.1 From nobody Sun Sep 28 14:52:13 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1758798589; cv=none; d=zohomail.com; s=zohoarc; b=I2sQcklr+JNVw+fNBdKgv68ux4dcnajPSD/p48PhlyUt9Lk7liqukI7/TfeFwMB5AZUXWxMg5MMft25jXjfpC9FaO5nwgCF+hGQPHA5zlNvrMmRvgvVnJu/T1urdFx7PT0hw7B7B4lGtYQCrr2Pj5bF0kxITFlUQ14CgXFRjXTc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758798589; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id; bh=Ss2EscY3N3RFq85ydr0fm+jVUf1+/tbyts1gDknbeM0=; b=MSv8e5IgdpFcYrpSFt9hclV264Ay7GsO+WWIQj8XlCVibYxC0vFYW2lxHXOIQNNKlMiv06ByuN3uJ9vuupcLw4PZrGI6xV0fsZHSYZNk4QbZB9peY0ELVkWLKBXMfjyKWoHoLsxPwqrBmLUNis8n/mrk6qFogW4Ix4LoeYnummI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1758798589742593.773524539354; Thu, 25 Sep 2025 04:09:49 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id E044E44045; Thu, 25 Sep 2025 07:09:48 -0400 (EDT) Received: from [172.19.199.14] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 226D5446B4; Thu, 25 Sep 2025 05:50:22 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 6EF92440B4; Thu, 25 Sep 2025 05:48:58 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 12FE643E69 for ; Thu, 25 Sep 2025 05:47:02 -0400 (EDT) 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-90-Y-zSNa7SPvC8RKhUIRzx-g-1; Thu, 25 Sep 2025 05:46:58 -0400 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 1C8A818002BB; Thu, 25 Sep 2025 09:46:57 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.163]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2FBBD300021A; Thu, 25 Sep 2025 09:46:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758793621; 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=Ss2EscY3N3RFq85ydr0fm+jVUf1+/tbyts1gDknbeM0=; b=Lbom0sf5VKqfIv/uoDsq/QaEpvH3yge/+PRIo6PRWHLzlIPKRRP//e3CTNRwialPQOzdJ3 35YXIiMZfAMXGwTsHTaW5hIHoKMc7HAMlRpShJTpz0vCLtDihY7F8xYeoRfFMorXMqSoBr eRO5Zs8DinQQNdD13hIvEUjA29KyUSo= X-MC-Unique: Y-zSNa7SPvC8RKhUIRzx-g-1 X-Mimecast-MFC-AGG-ID: Y-zSNa7SPvC8RKhUIRzx-g_1758793617 To: qemu-devel@nongnu.org Subject: [PATCH v4 22/23] util: add support for formatting thread info in messages Date: Thu, 25 Sep 2025 10:44:40 +0100 Message-ID: <20250925094441.1651372-23-berrange@redhat.com> In-Reply-To: <20250925094441.1651372-1-berrange@redhat.com> References: <20250925094441.1651372-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 Message-ID-Hash: KWT3M2PK3EE4THXVB5W67EG6EYY6XK5Q X-Message-ID-Hash: KWT3M2PK3EE4THXVB5W67EG6EYY6XK5Q X-MailFrom: berrange@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , qemu-rust@nongnu.org, Richard Henderson , Markus Armbruster , Christian Schoenebeck , qemu-block@nongnu.org, Stefan Weil , "Dr. David Alan Gilbert" , Manos Pitsidianakis , Gerd Hoffmann , devel@lists.libvirt.org, Paolo Bonzini X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9_via_Devel?= Reply-To: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758798592962116600 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 Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/qemu/message.h | 1 + storage-daemon/qemu-storage-daemon.c | 6 ++++++ system/vl.c | 8 ++++++-- tests/qemu-iotests/041 | 2 +- tests/qemu-iotests/common.filter | 2 +- util/message.c | 7 +++++++ 6 files changed, 22 insertions(+), 4 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/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 0ac1b11caf..fb8cc41876 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; @@ -812,10 +816,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; } @@ -2889,6 +2892,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 511a55b1e8..84f352d30b 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 1db9254733..814ca0316e 100644 --- a/util/message.c +++ b/util/message.c @@ -37,4 +37,11 @@ void qmessage_context_print(FILE *fp) fprintf(fp, "%s: ", pgnamestr); } } + + 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.50.1 From nobody Sun Sep 28 14:52:13 2025 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=1758793942; cv=none; d=zohomail.com; s=zohoarc; b=VLY8ORKtJU9wu9wmIl+b4lOZIrROT63YIQEAQM44cob0eU9Fhsj1mb0KAYUXbZTEEwmOxGczeh5ksMXdVqk1V+aCBHTXcuyTDSfDRczwDyDiWRe4WXSxIhTs8sxAUq7GQuZmmdPE1fIIyAP+CZ9N7Td2UDXfIOqv/SdX5e6b468= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758793942; 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=7onLwSgDG8MwC4q4AzmFO1Ny6FrS9IFthDLL+WX7Fjc=; b=jQEXrLUgEI4qq1eBb1qwVABbJEQHoHk4L0z2opq6NiRs/DK1SQFj62G112ECzdX3V4mWPucyOU3/r6MrW47WdlS8+iilCawTxH+nDdFzr1kuSKaYooz0Y+F2yrxmzQrTDJ0V1G6gesgodtBu2SPWz+UPvJvvm/rJGHmf5zpz0Cg= 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 1758793942039395.6351118090131; Thu, 25 Sep 2025 02:52:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1iZi-0002W2-LY; Thu, 25 Sep 2025 05:47:42 -0400 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 1v1iZY-0002Lb-69 for qemu-devel@nongnu.org; Thu, 25 Sep 2025 05:47:33 -0400 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 1v1iZD-0001ry-Da for qemu-devel@nongnu.org; Thu, 25 Sep 2025 05:47:30 -0400 Received: from mx-prod-mc-02.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-455-7Bg_FVRqNmOEwks9vnVGeQ-1; Thu, 25 Sep 2025 05:47:04 -0400 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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CFFDF19560B0; Thu, 25 Sep 2025 09:47:02 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.163]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 96AE0300021A; Thu, 25 Sep 2025 09:46:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758793627; 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=7onLwSgDG8MwC4q4AzmFO1Ny6FrS9IFthDLL+WX7Fjc=; b=Jtu9uUr+GF0U4ypUmyVz/pmu4Z/1ELJRogyKt27UvcGQkLwNRvq3vjQWn3Ffc/7Z1X4pWF cuaF4/6/22fIV+pBERQJDtzAKEHD8krjl3XVti7V9lQqbMc2OrQ/4q2dHaEXTjyMaTga56 xwgOExwOBBGj1CfIKVydM5bDp0I4GGI= X-MC-Unique: 7Bg_FVRqNmOEwks9vnVGeQ-1 X-Mimecast-MFC-AGG-ID: 7Bg_FVRqNmOEwks9vnVGeQ_1758793622 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , qemu-rust@nongnu.org, Richard Henderson , Markus Armbruster , Christian Schoenebeck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , qemu-block@nongnu.org, Stefan Weil , "Dr. David Alan Gilbert" , Manos Pitsidianakis , Gerd Hoffmann , devel@lists.libvirt.org, Paolo Bonzini Subject: [PATCH v4 23/23] util: add brackets around guest name in message context Date: Thu, 25 Sep 2025 10:44:41 +0100 Message-ID: <20250925094441.1651372-24-berrange@redhat.com> In-Reply-To: <20250925094441.1651372-1-berrange@redhat.com> References: <20250925094441.1651372-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, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, T_SPF_TEMPERROR=0.01 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: 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: 1758793943675116600 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 Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- util/message.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/message.c b/util/message.c index 814ca0316e..7d94b9d970 100644 --- a/util/message.c +++ b/util/message.c @@ -28,7 +28,7 @@ void qmessage_context_print(FILE *fp) =20 if ((message_format & QMESSAGE_FORMAT_WORKLOAD_NAME) && message_workloadname) { - fprintf(fp, "%s ", message_workloadname); + fprintf(fp, "[%s] ", message_workloadname); } =20 if (message_format & QMESSAGE_FORMAT_PROGRAM_NAME) { --=20 2.50.1