From nobody Sun Sep 28 17:03:45 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=1757527851; cv=none; d=zohomail.com; s=zohoarc; b=JqHd5Zt56jx+SUqObODJgozaHX1+qQhGwxHbZhhjAm4RiK94X0ONZj2tQQSV0FKQ84x83dZRHv/6o8LTx264bHeezAJsMWU0Tuf0T3rKaBUfNmHtcn6/cXtNhwy1NU8sBf3KauI9NEzztI/Y7txsMm1pOJ3oRul0AWodYJVge+8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757527851; 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=Cebg/z4xjgbMQ1Fuh630jVOpy1mS0CJTstQlRS4nrdYBWd4K+ghALTnp7FEAgeotuPuR+oaLyqrboVESVzJmveRcG9k6Qp0fp10flGGgAgoqVE7GzaQ6VLQGC6BIeC7FH5FwD9SfkJ12PsBd9pASPzxsYKl5KozkNgLilTBrsnc= 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 1757527851008431.02023505567945; Wed, 10 Sep 2025 11:10:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwPB7-0007s4-Pf; Wed, 10 Sep 2025 14:04: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 1uwPB3-0007qY-Bx for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:04:17 -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 1uwPB0-0004em-Vw for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:04:17 -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-21-jI1BXoPBM0eEoopY93HxWQ-1; Wed, 10 Sep 2025 14:04:09 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 7EC2519560A7; Wed, 10 Sep 2025 18:04:07 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.57]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C78001800447; Wed, 10 Sep 2025 18:04:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757527452; 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=J8j+OHcSQ258M3XK/voi2y4cQGY7e8k5VPYZWMqk7p3KUUZI7Gl0saCFHQu5+yJNP1JUMW L1/ZVTJ7W+PW03kjBNdhGp4r989burer6CbT9g3vS2Ut5lQnUOc4KscuSKG46NcYiFjkgj VnHuU4XhD9LGOWvi0w0rQ6BTI36sD0E= X-MC-Unique: jI1BXoPBM0eEoopY93HxWQ-1 X-Mimecast-MFC-AGG-ID: jI1BXoPBM0eEoopY93HxWQ_1757527447 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Hanna Reitz , Kevin Wolf , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Christian Schoenebeck , Richard Henderson , Manos Pitsidianakis , Stefan Weil , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Paolo Bonzini , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v3 01/20] include: define constant for early constructor priority Date: Wed, 10 Sep 2025 19:03:38 +0100 Message-ID: <20250910180357.320297-2-berrange@redhat.com> In-Reply-To: <20250910180357.320297-1-berrange@redhat.com> References: <20250910180357.320297-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.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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: 1757527852691116600 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 17:03:45 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=1757527589; cv=none; d=zohomail.com; s=zohoarc; b=lERYFeqMTfmW7kJ9+MfZl7W96Mcza4v0uHsmBeZ3SGr4bBaZWvmbGXi9LCpEVCYm0GgS5ybNUG8iCeFRhw09OdbEznxbT6IG4Ed3U9BQ8lv0eq773bASMRJAI5YBt5NOen08Q57zKrcy/6GeEytcqWmZIWZnf9wveWx7QKmY4aw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757527589; 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=BcrB75/R+NNCB4eg5mAoBzqzkku+VwsQ0AwmZXXftUc=; b=LHNiTSKlpLO083DSfPw3x9z3OdgIJkUM/r6eNaEu/+uelSofM5WpJimWk2bg7nOIj8ZLWBROhUF54vs+3iz6vW9bMBiwWPDPNrzAAIVlI6YKu9s0H9zESi0NCTgHzN0/VUjbjFNwUxZ+Xpa4xEw72WVgWX5nhOiHFguLJkQLE/c= 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 1757527589079480.6302545552295; Wed, 10 Sep 2025 11:06:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwPBA-0007sw-Lt; Wed, 10 Sep 2025 14:04:24 -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 1uwPB8-0007sJ-4O for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:04:22 -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 1uwPB6-0004fV-AH for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:04:21 -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-518-0FwO_hZ3O7qQAH7gXF6dSQ-1; Wed, 10 Sep 2025 14:04:13 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 C3C28180047F; Wed, 10 Sep 2025 18:04:11 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.57]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EE4AC1800446; Wed, 10 Sep 2025 18:04:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757527458; 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=BcrB75/R+NNCB4eg5mAoBzqzkku+VwsQ0AwmZXXftUc=; b=RPQx6i/p1rRwBv1m9gTh8HyyBgYDpKY73rVYrFNir9TXwfAntpUYfvOezZwVc8czadWMZj Z/07I9N/WTCYupBPFPw06QFsDc4wW3ZDaksnIJSu5g5WKqU3WNNgk4hAnaB2Ip2O5yBvwI CSq8M2Vk3SKz16V3xnppYNyzVV0Ie/g= X-MC-Unique: 0FwO_hZ3O7qQAH7gXF6dSQ-1 X-Mimecast-MFC-AGG-ID: 0FwO_hZ3O7qQAH7gXF6dSQ_1757527452 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Hanna Reitz , Kevin Wolf , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Christian Schoenebeck , Richard Henderson , Manos Pitsidianakis , Stefan Weil , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Paolo Bonzini , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v3 02/20] monitor: initialize global data from a constructor Date: Wed, 10 Sep 2025 19:03:39 +0100 Message-ID: <20250910180357.320297-3-berrange@redhat.com> In-Reply-To: <20250910180357.320297-1-berrange@redhat.com> References: <20250910180357.320297-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.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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: 1757527595345116600 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. Reviewed-by: Richard Henderson Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Markus Armbruster --- 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 17:03:45 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=1757527539; cv=none; d=zohomail.com; s=zohoarc; b=SOm9fxgobHA5c/wiwvonmGYg+IDkdeVABR2a4fHgTGS4DyfLkUPqB6WqxuO3aNcnBoqR1XpNMDwXeFFaYWUtbNi9pmFaVsdfRI2APnkZYW40wJdKBp7karMrEvWiZw9WMGL2YXJ03B5ENINjK4hTI8dTL4tBDG87ICEkxfovTVI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757527539; 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=vN84PwUyt6jGJGYSy/yPDC1T6ntX0KRCfmO+hFPYtNg=; b=APGm72jUuoLpNk6RzFW40g95iU29ny5GMDpJcfyJWnn28F3wFqEcrY0sK5Wgrl5/Gw3kT0mSmcgkFrkoUurfm++4UF95nI66G8eBvVLDaHknIJHPvlJR2fNh3vp/0g72SXuU0rRQGiB0QBF7OSMAhNRPCKp2ZrCQUq+UWZPJr9c= 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 1757527539206624.6111810011153; Wed, 10 Sep 2025 11:05:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwPBE-0007tq-0q; Wed, 10 Sep 2025 14:04:28 -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 1uwPBC-0007tX-FY for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:04: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 1uwPB9-0004gG-LT for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:04:26 -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-658-eLuK_o4xO12O6ANWc0KK7g-1; Wed, 10 Sep 2025 14:04:19 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 C1F0F1800284; Wed, 10 Sep 2025 18:04:15 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.57]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2D7FD1800447; Wed, 10 Sep 2025 18:04:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757527462; 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=vN84PwUyt6jGJGYSy/yPDC1T6ntX0KRCfmO+hFPYtNg=; b=S6eCeUi6DlsmikQC6hpSJbd/mf+pMOMdiqXImzY3n599cmeE2PlCmaNuuweWrRsVyDEnXZ ol02uk0e7LJItEH5hyOXHNoRyocG2M+ln45tALiccqvy4q018EZvMujjM+qbH0n4UKCZY8 tn1TDMInr3+sQC0skvNOoPRxCnHBKpI= X-MC-Unique: eLuK_o4xO12O6ANWc0KK7g-1 X-Mimecast-MFC-AGG-ID: eLuK_o4xO12O6ANWc0KK7g_1757527458 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Hanna Reitz , Kevin Wolf , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Christian Schoenebeck , Richard Henderson , Manos Pitsidianakis , Stefan Weil , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Paolo Bonzini , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v3 03/20] system: unconditionally enable thread naming Date: Wed, 10 Sep 2025 19:03:40 +0100 Message-ID: <20250910180357.320297-4-berrange@redhat.com> In-Reply-To: <20250910180357.320297-1-berrange@redhat.com> References: <20250910180357.320297-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.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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: 1757527540896116600 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 Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Markus Armbruster --- docs/about/deprecated.rst | 7 +++++++ include/qemu/thread.h | 1 - system/vl.c | 11 ++++++----- util/qemu-thread-posix.c | 18 +----------------- util/qemu-thread-win32.c | 27 ++++++--------------------- 5 files changed, 20 insertions(+), 44 deletions(-) diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst index b2420732e1..7187ea15fa 100644 --- a/docs/about/deprecated.rst +++ b/docs/about/deprecated.rst @@ -81,6 +81,13 @@ kernel since 2001. None of the board types QEMU supports= need ``param_struct`` support, so this option has been deprecated and will be removed in a future QEMU version. =20 +``debug-threads`` option for ``-name`` +'''''''''''''''''''''''''''''''''''''' + +Thread ``debug-threads`` option for 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 3b7057e6c6..a64fd90d4a 100644 --- a/system/vl.c +++ b/system/vl.c @@ -403,9 +403,7 @@ 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 "DEPRECATED: thread names are always set where suppo= rted", }, { /* End of list */ } }, @@ -554,9 +552,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 17:03:45 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=1757527529; cv=none; d=zohomail.com; s=zohoarc; b=T7MP3DNek90BjSqoriXy6tzlwiSwhz8ykHlMoK9m33Y/KDkt43lXDE+VvYrfCoLc/6ippGdwSat/57V+n4xqqSGWR5Xujk7CiusxEx2Otc9pmfySYL0GQc59cGENrDtKll6FclqOMc4HN/KKW5Qr3qNHEeRUsIgDBM6GEV7xAgE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757527529; 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=1RgvNPbkkCQoZ7eRMrGxi8qVAUUZRp3mbVKqx4BnIII=; b=hVQg0xiwMLXRKPiN+Y0u/78FOzjFTkNCrduKGf/0J2cNQggAF6oU7BvbUijnovpfCnROCwO7dxfeBdcipG3CPYZ1wcQIslo5I7gfd19qnzhH4l94M8RYHb5sYBPbETygwBOW4q+ImS0T+Bbl+2G04wZ8wiqDFmJgU5JITAcyvtA= 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 175752752972469.25397158588919; Wed, 10 Sep 2025 11:05:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwPBF-0007uW-4r; Wed, 10 Sep 2025 14:04: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 1uwPBE-0007ts-3t for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:04:28 -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 1uwPBB-0004gX-IJ for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:04:27 -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-662-AIULWwQuPSSwKzYmfq7u7Q-1; Wed, 10 Sep 2025 14:04:22 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 4B00319560A1; Wed, 10 Sep 2025 18:04:20 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.57]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 546C71800447; Wed, 10 Sep 2025 18:04:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757527464; 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=1RgvNPbkkCQoZ7eRMrGxi8qVAUUZRp3mbVKqx4BnIII=; b=dK7/uERDlK28hCcPUdE1nVSk3L2vMDjH+z/S5owYWn6CHQzrxx86ymtAFH2+LMS6vCKJvD ck9nc6jvMdD4JDVjg8vP5TrrezMtMqgy1XpaxzhsfmJtbPJB3mIk014X0VU9edWiUGfG6a /Mmi/QB/sqe7Q5Gsl/TEoLxM0ffVg1Y= X-MC-Unique: AIULWwQuPSSwKzYmfq7u7Q-1 X-Mimecast-MFC-AGG-ID: AIULWwQuPSSwKzYmfq7u7Q_1757527460 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Hanna Reitz , Kevin Wolf , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Christian Schoenebeck , Richard Henderson , Manos Pitsidianakis , Stefan Weil , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Paolo Bonzini , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v3 04/20] util: expose qemu_thread_set_name Date: Wed, 10 Sep 2025 19:03:41 +0100 Message-ID: <20250910180357.320297-5-berrange@redhat.com> In-Reply-To: <20250910180357.320297-1-berrange@redhat.com> References: <20250910180357.320297-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.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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: 1757527534700116600 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 --- include/qemu/thread.h | 1 + util/qemu-thread-posix.c | 30 ++++++++++++++++++------------ util/qemu-thread-win32.c | 6 +++--- 3 files changed, 22 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..ddaa1de4dd 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,20 +357,11 @@ 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); } - QEMU_TSAN_ANNOTATE_THREAD_NAME(qemu_thread_args->name); - g_free(qemu_thread_args->name); g_free(qemu_thread_args); =20 /* diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c index 9595a5b090..62eaa11026 100644 --- a/util/qemu-thread-win32.c +++ b/util/qemu-thread-win32.c @@ -316,7 +316,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 +329,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, @@ -356,7 +356,7 @@ void qemu_thread_create(QemuThread *thread, const char = *name, error_exit(GetLastError(), __func__); } if (name) { - set_thread_description(hThread, name); + qemu_thread_set_name(name); } CloseHandle(hThread); =20 --=20 2.50.1 From nobody Sun Sep 28 17:03:45 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=1757527595; cv=none; d=zohomail.com; s=zohoarc; b=STGt4hKA8RKucfce9FJybfe+1XXjPBDbzybQ7bzZ9noBHbmWHHEkQmML+1Nlto1prX3kt95X/C3l/FnoZybrGy06Rgl6ueFVZOwMxC4XbdIubvR91cRzReL6O2M7sTsRZodsYiez+/xopHeYLgsFXw2Sx064PhYc3CrSJdqb/RY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757527595; 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=8U4JGpe8oY8jn8vL5TXbHGmcWR602uNhf/50IZVuU5g=; b=AgrI9PGm3u5aO0egO7X9kBsc2qNoednL/voJelNaaJ1+tVL2WwbWot0vz0KRnQXqBGn+kr/xbPUp0qj73h9I76IyhUFouDaYEPiesbyXHwacsJuTcziilBMMcuf799CHu6hkOEqMtwj0BtGmCDxdvOqP3SbQNXjRZEEtAp0QDIY= 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 1757527595313723.6510854815327; Wed, 10 Sep 2025 11:06:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwPBI-0007vW-Ec; Wed, 10 Sep 2025 14:04:32 -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 1uwPBH-0007v6-Io for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:04:31 -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 1uwPBF-0004hb-TB for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:04:31 -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-68-pMmHt2xrNfCqzWzFaLYr2Q-1; Wed, 10 Sep 2025 14:04:25 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 78B84195608B; Wed, 10 Sep 2025 18:04:24 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.57]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D78981800447; Wed, 10 Sep 2025 18:04:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757527469; 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=8U4JGpe8oY8jn8vL5TXbHGmcWR602uNhf/50IZVuU5g=; b=CW85m0q/YYdVTc0MbpZCvhjXYlTXq2EX6qc2JWx7cisO41x0SQHv5evHXjOeUYVouVs9ru MNWVnNNtzXZORO/Nk+shDT4sq7uTX5G2DlaqAk4VF+X8fzw/F2X8dKNH+ed+6eRE9FWyfK eQhucVukiwbjjs2hYDYqSfbGtXYcYIA= X-MC-Unique: pMmHt2xrNfCqzWzFaLYr2Q-1 X-Mimecast-MFC-AGG-ID: pMmHt2xrNfCqzWzFaLYr2Q_1757527464 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Hanna Reitz , Kevin Wolf , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Christian Schoenebeck , Richard Henderson , Manos Pitsidianakis , Stefan Weil , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Paolo Bonzini , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v3 05/20] audio: make jackaudio use qemu_thread_set_name Date: Wed, 10 Sep 2025 19:03:42 +0100 Message-ID: <20250910180357.320297-6-berrange@redhat.com> In-Reply-To: <20250910180357.320297-1-berrange@redhat.com> References: <20250910180357.320297-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.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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: 1757527597316116600 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. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Christian Schoenebeck --- 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 17:03:45 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=1757527794; cv=none; d=zohomail.com; s=zohoarc; b=Rf3UryYcG6eX0ZlW95k02G9+O/hnbd+WWCA7hDZ17ks4DhiOBYmdMlhZe6gF5nP+jRYQoZFXrbYbbNzl8AX6OMPYZm/MeD0EBR57YpaC6d197GxvCZoUf4caMqVPTktYMbPmc7KKghAAZk/7QxCnYZ6TW3XZbtAftbklt1JePBM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757527794; 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=ogDRARt6wNTv90Ti5JrqANHVrLfMuN7+XaSFFWWHEZM=; b=VryJECAOBtZv/Y7YCv5lCLf6PmSixpHfNjkAfQxMjn8UJmy71yIIAOq6S22jMWZc5YZo5ooJQOjT4lv4zkvoITRpFDqZGm9Ro8DOuJ5LV0oHJ62jTMobN0EgriABFpy7V4f/LTX2h/4TtjOa7ekFxFXN7muKXGjXO/wYSpT5COU= 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 1757527794881204.49342500482396; Wed, 10 Sep 2025 11:09:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwPBO-0007xx-DQ; Wed, 10 Sep 2025 14:04:38 -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 1uwPBM-0007xF-W5 for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:04:37 -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 1uwPBL-0004iE-3r for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:04:36 -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-615-FbzSzisSNzq9cyAYCV-ojw-1; Wed, 10 Sep 2025 14:04:30 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 18C2D19560AF; Wed, 10 Sep 2025 18:04:29 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.57]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D5CE41800447; Wed, 10 Sep 2025 18:04:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757527474; 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=ogDRARt6wNTv90Ti5JrqANHVrLfMuN7+XaSFFWWHEZM=; b=LSB/O2kmdhhflbc6aUw1PqILVnsRnLOLeKiquIOQaPKbfsKM13c1fuvAxZ3aIBdE7JekLA YlcjEKaQG6hjpGn1nXvNvsip+Xd6vXlXwimJVXJeTuDUyTNyatF/d183F6myN001BbvLG4 EWD1Pjx8hFaEITTD0yHYTrZdhcovq7U= X-MC-Unique: FbzSzisSNzq9cyAYCV-ojw-1 X-Mimecast-MFC-AGG-ID: FbzSzisSNzq9cyAYCV-ojw_1757527469 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Hanna Reitz , Kevin Wolf , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Christian Schoenebeck , Richard Henderson , Manos Pitsidianakis , Stefan Weil , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Paolo Bonzini , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v3 06/20] util: set the name for the 'main' thread Date: Wed, 10 Sep 2025 19:03:43 +0100 Message-ID: <20250910180357.320297-7-berrange@redhat.com> In-Reply-To: <20250910180357.320297-1-berrange@redhat.com> References: <20250910180357.320297-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.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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: 1757527795951116600 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 ddaa1de4dd..275445ed94 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 62eaa11026..7a734a7a09 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 17:03:45 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=1757527983; cv=none; d=zohomail.com; s=zohoarc; b=nHCJwyoii0fBiapl9H7PVHMWcMyqbfTBlKBQa4zoScba+YAUhQ1bYcvZVSPc/Ri7XLKTlow1ep067C1IzpQhVxAwj7Ys2hlYgoXx5cqHbfeq+xJeECOz1FybfEjw4du8dl5JM+hfyACIyglZPyX/4oHPz1AbVy34ZUBmVRageAY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757527983; 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=ksiCewlUMa6gkJLmmfbF1PaSCeQGDxUBMFxmtS2Pb7A=; b=AAC1zuuVuWHoWJywr26lTyfQHpoBiqpu7ef3lG75CmuR79PkhAxgCLT5ukkuLJTb5WRrDesYgAAKOGBegEm4cqAjTyDSqPfC84AIvz9j4YpYiO6bDgPkiooFp1++th3AzN1mml9utTPD6sJXqEYII8+TJRuBRbwAGaOrwg0PmQ0= 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 175752798347410.712408552190823; Wed, 10 Sep 2025 11:13:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwPBR-0007yX-73; Wed, 10 Sep 2025 14:04:41 -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 1uwPBQ-0007yL-A3 for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:04:40 -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 1uwPBO-0004il-Ax for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:04:40 -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-454-grssG7fkO92Pr_7tNBOgbQ-1; Wed, 10 Sep 2025 14:04:35 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 901001800452; Wed, 10 Sep 2025 18:04:33 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.57]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8EE9D1800446; Wed, 10 Sep 2025 18:04:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757527477; 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=ksiCewlUMa6gkJLmmfbF1PaSCeQGDxUBMFxmtS2Pb7A=; b=YVhArrZwAMZcH+yrDZ/zOy8CaGvgQhskJ3O/O4xSXJ5MXVEnOS7yyglEyLD+YbOMZACZbc 2UmTCK1kD5MaO/r85jfqt8ktNEUtD7R0YHq6iW3YMPhSDD0rmujth8qDvg+V+zEWW+YmzS Gp7XZuySWsNs0OV5//cSLJ/r2rg8cKw= X-MC-Unique: grssG7fkO92Pr_7tNBOgbQ-1 X-Mimecast-MFC-AGG-ID: grssG7fkO92Pr_7tNBOgbQ_1757527473 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Hanna Reitz , Kevin Wolf , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Christian Schoenebeck , Richard Henderson , Manos Pitsidianakis , Stefan Weil , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Paolo Bonzini , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v3 07/20] util: add API to fetch the current thread name Date: Wed, 10 Sep 2025 19:03:44 +0100 Message-ID: <20250910180357.320297-8-berrange@redhat.com> In-Reply-To: <20250910180357.320297-1-berrange@redhat.com> References: <20250910180357.320297-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.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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: 1757527984732116600 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. This makes the assumption that the thread name is set at the very start of the thread, 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 | 28 ++++++++++++++++++++++- util/qemu-thread-win32.c | 49 ++++++++++++++++++++++++++++++++++++---- 4 files changed, 94 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 fa6186db33..6aa673f4b2 100644 --- a/meson.build +++ b/meson.build @@ -2920,6 +2920,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 275445ed94..fbb94ca97b 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,29 @@ void *qemu_thread_join(QemuThread *thread) } return ret; } + +#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 7a734a7a09..e3789c20d1 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) @@ -326,7 +332,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 @@ -412,3 +418,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: + strlcpy(namebuf, "unnamed", G_N_ELEMENTS(namebuf)); + return namebuf; +} --=20 2.50.1 From nobody Sun Sep 28 17:03:45 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=1757527981; cv=none; d=zohomail.com; s=zohoarc; b=ELeehEoT4w3VP4bZwjFWq+sRwTP1B1SnJgoSBwqRrpMr546p1+hn7kjiJYun+HYa5UjtrV7Ub3TO1uXgqbn2l8QGvP7vPq2LmZds2+kCFvx+gjDgthbx+vnOe0K++N5hvX9NNRfhSEf4Nslj3H5HmNAjt39Z23Bi7N9K+ImEpxg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757527981; 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=TwEOa+l6LoighEebVVlGwnEROumGJcjNVxWy72+VXdU=; b=AQbGWI5eUKL325NurPTTlHy3OsdvtEBMsFRdgmJH6uFJJUnqqN9noeWBob+UIoIOrmr2xzMaVvuZsS2UdjO4iVjV10SvVVxNkf6VsZmWPGIiMoZahfU5zES5q75tsinek9QiMNeRWXMPY0qZMLtkcmZpT+36q3sH8IICD92QyJc= 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 1757527981673124.75833731628256; Wed, 10 Sep 2025 11:13:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwPBW-0007zo-5M; Wed, 10 Sep 2025 14:04:46 -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 1uwPBU-0007zT-Aw for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:04:44 -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 1uwPBS-0004j5-Jl for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:04:44 -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-543-kE8yN8t7NvC7FIz4jr1cfQ-1; Wed, 10 Sep 2025 14:04:39 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 024F1180057C; Wed, 10 Sep 2025 18:04:38 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.57]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id F39281800446; Wed, 10 Sep 2025 18:04:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757527480; 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=TwEOa+l6LoighEebVVlGwnEROumGJcjNVxWy72+VXdU=; b=OvSf3dzuI1+H2wqo3v89mtTUSZ+toVefQGiBbpsYNvOQdkXxFNO+HK7UWBe7z4a743MeLn jlQschMT3i2hz7VaHkcNJ9wq6zBdpniZizDZnWZY45FQ/o9sxO6PknfgJx+8FOuBk+vLby QkjgQdYr4L2HVnl7wki+dR9JNE7rCzQ= X-MC-Unique: kE8yN8t7NvC7FIz4jr1cfQ-1 X-Mimecast-MFC-AGG-ID: kE8yN8t7NvC7FIz4jr1cfQ_1757527478 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Hanna Reitz , Kevin Wolf , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Christian Schoenebeck , Richard Henderson , Manos Pitsidianakis , Stefan Weil , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Paolo Bonzini , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v3 08/20] log: avoid repeated prefix on incremental qemu_log calls Date: Wed, 10 Sep 2025 19:03:45 +0100 Message-ID: <20250910180357.320297-9-berrange@redhat.com> In-Reply-To: <20250910180357.320297-1-berrange@redhat.com> References: <20250910180357.320297-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.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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: 1757527982283116600 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. Reported-by: Richard Henderson Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson --- 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 17:03:45 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=1757527616; cv=none; d=zohomail.com; s=zohoarc; b=GB6SRwrgdLQ5a/Mi5jhzqzU1TYtWMD0GVb1Ox6eXuBirJ+MnnqvWvOMQZjC9MX0F53pZniYrKMFHS9pqSroz2xy6jNtbKn65MCSoJynZWViySsA11b6eOET8EkQC4Btv/HDbwqlxes9Euj9K5JjRbKbZhY2ucSsXbUZ9Ua1qn50= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757527616; 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=q4+CEe/wAFjZNRupv5OHeYe/sqf/0adXjag9Bu5LdD0=; b=gsCnIxI14PK4J2COCXvI1SJM5Q4Z7kkd8S22NEzQxZHcG1FhUn/KjpDVJ9OX7Ki7wPUEVWs03TLsTCDRgaorP5dSWNaEK0ax+9y0r+9IciuC3tMi2tLoBwzy7Fmy/GxELgZLLp51iIqZHmxFqrGWShjV3pJ1ggvxNpdCqcP3u8g= 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 1757527616471513.0554996140133; Wed, 10 Sep 2025 11:06:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwPBe-00087V-9F; Wed, 10 Sep 2025 14:04:55 -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 1uwPBa-000810-FF for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:04:50 -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 1uwPBX-0004jT-JH for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:04:49 -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-518-N89ze5LAP7uYM1Ujexhymw-1; Wed, 10 Sep 2025 14:04:43 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 346AC1956087; Wed, 10 Sep 2025 18:04:42 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.57]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 625641800447; Wed, 10 Sep 2025 18:04:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757527486; 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=q4+CEe/wAFjZNRupv5OHeYe/sqf/0adXjag9Bu5LdD0=; b=gX1pj54s7Kp4tcjBwRgDoljNFe47iRXnIWm+5guyTgEYO2YHoNC/HMfvAnBBJEArSvij9Y y0VPFPEvDP4D8sAdFGitS0p0dNJQ3kS6SU5P0GMpBWkyUiXE5jSj9uBMvu7maNMjS22FKj WfPuH2FnLGXtDjqz1NXUp9dBNSSYxng= X-MC-Unique: N89ze5LAP7uYM1Ujexhymw-1 X-Mimecast-MFC-AGG-ID: N89ze5LAP7uYM1Ujexhymw_1757527482 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Hanna Reitz , Kevin Wolf , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Christian Schoenebeck , Richard Henderson , Manos Pitsidianakis , Stefan Weil , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Paolo Bonzini , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v3 09/20] ui/vnc: remove use of error_printf_unless_qmp() Date: Wed, 10 Sep 2025 19:03:46 +0100 Message-ID: <20250910180357.320297-10-berrange@redhat.com> In-Reply-To: <20250910180357.320297-1-berrange@redhat.com> References: <20250910180357.320297-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.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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: 1757527617685116600 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. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Markus Armbruster Reviewed-by: Richard Henderson --- ui/vnc.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/ui/vnc.c b/ui/vnc.c index 68ca4a68e7..439d586358 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 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 17:03:45 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=1757527662; cv=none; d=zohomail.com; s=zohoarc; b=jZpV3qOATV+16YcjHGf/+yPwQf5sD4AtKFsK8Euc3PwRi9sbXqVEgQBZou3edWAjdVJwRfXTyNG7vyk6MBJRrYNn0SbtupTBVH5wMWgPD/XasAdiFuRip98yplCdETSCnB/QOFD86E2wAVDTNrvvqCPoF0v9S91WUJWLPHDG3dk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757527662; 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=HSmmeE4LX6+dAdVzSESwN9nzUTHN9b8kMqEf0jlqxZU=; b=VYS7czVj6nhj6YfYZU8ybodqWYe2Y1nPXgMa4b2g+QI5LKKtnyQR51H0booKQvaqLId6EUTLQ5dra9VoE+uuhEyS5S3wLtnktERQN+FL6gUj/qOYj3uUlsL816+tm73ieLVO63IM8VRO4Ob1uXUp2GZOYQ92Jnpsh/NHYZwJtMU= 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 1757527662771731.3352742290127; Wed, 10 Sep 2025 11:07:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwPBl-0008Eg-8E; Wed, 10 Sep 2025 14:05:01 -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 1uwPBg-00088x-BG for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:04:58 -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 1uwPBa-0004jd-8N for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:04:55 -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-195-ueaW2QoiPnebkgk45w3TvA-1; Wed, 10 Sep 2025 14:04:47 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 3070C180045C; Wed, 10 Sep 2025 18:04:46 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.57]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A807F1800447; Wed, 10 Sep 2025 18:04:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757527489; 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=HSmmeE4LX6+dAdVzSESwN9nzUTHN9b8kMqEf0jlqxZU=; b=ZmmRqsCdcwo5GVirF6sbdFAjqUwH8DzzjQ0s5kEWGSmdO9+BvXdKwSAqxkkFfv8eJc/Seq uDSPCPcFbDdqRyjJzmNMPXzkEqcXxu79usxcoB37QVG3xJ+26GcOWrGGfaAKZAf/SGV50f 74dXMsCFFmSXvQ21ctikFA7psTJPMvI= X-MC-Unique: ueaW2QoiPnebkgk45w3TvA-1 X-Mimecast-MFC-AGG-ID: ueaW2QoiPnebkgk45w3TvA_1757527486 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Hanna Reitz , Kevin Wolf , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Christian Schoenebeck , Richard Henderson , Manos Pitsidianakis , Stefan Weil , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Paolo Bonzini , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v3 10/20] monitor: remove redundant error_[v]printf_unless_qmp Date: Wed, 10 Sep 2025 19:03:47 +0100 Message-ID: <20250910180357.320297-11-berrange@redhat.com> In-Reply-To: <20250910180357.320297-1-berrange@redhat.com> References: <20250910180357.320297-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.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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: 1757527664371116600 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. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Markus Armbruster Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson --- 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 17:03:45 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=1757527546; cv=none; d=zohomail.com; s=zohoarc; b=mCzYhNuIWQFf/IYfHwGOsQUFqO+PzqYsSQCBOcGYRh78Aqq7FX8AM5ecAnHF8hHN9Li9OP7LCs0oiwz5StItmp6TNe8A/liGfk0TdoZpyMBZYHt83hlkJxbuYdJ0D5KNc5QxfrNR408JHF5qy+VzUK30lwtlnKkoVpMqQBWELQc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757527546; 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=MXwL0r/tjoy05r/8F/g9cS3d2URvCgjgPUpPVhxoyGM=; b=ZRpLmmjAXjarYtAWFSDDqD6xf+/LfbM9ZTvC1b305Xhqx/YcHLkThgsgzA3JNu9n2wgsp1eGQhAYkV4mHQ6XxugBf6+Fj+pjGHtNVMuNXTA8hitNBICcDPT9bn1U34EKV08kv13oQxBTGWcgQQyISTKubfTwc3pyduq6lyW3HjE= 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 1757527546568264.66300548033144; Wed, 10 Sep 2025 11:05:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwPBn-0008HW-Hv; Wed, 10 Sep 2025 14:05:04 -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 1uwPBi-00089v-LA for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:04:58 -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 1uwPBg-0004kE-5c for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:04:57 -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-167-iQ9rIKKqPgGrn5beHaetKA-1; Wed, 10 Sep 2025 14:04:51 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 486D2180057F; Wed, 10 Sep 2025 18:04:50 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.57]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8EF491800578; Wed, 10 Sep 2025 18:04:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757527494; 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=MXwL0r/tjoy05r/8F/g9cS3d2URvCgjgPUpPVhxoyGM=; b=b8f2kuvoDilgv3lcRmGmZQO4jdEnR71/U0zYzYBsLZYh/ONtNDQLfEW2QZCdswTu3CysFA zZZP1LotStWfeAbekP2vukwvXp0byNgl1gbRuO1pFsR8awrY2rNtM4g1BltgCLFKl+w/PN xcVc9EbDh5QtIgsdV/wi1jn9Hw7ZY9o= X-MC-Unique: iQ9rIKKqPgGrn5beHaetKA-1 X-Mimecast-MFC-AGG-ID: iQ9rIKKqPgGrn5beHaetKA_1757527490 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Hanna Reitz , Kevin Wolf , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Christian Schoenebeck , Richard Henderson , Manos Pitsidianakis , Stefan Weil , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Paolo Bonzini , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v3 11/20] monitor: move error_vprintf() back to error-report.c Date: Wed, 10 Sep 2025 19:03:48 +0100 Message-ID: <20250910180357.320297-12-berrange@redhat.com> In-Reply-To: <20250910180357.320297-1-berrange@redhat.com> References: <20250910180357.320297-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.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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: 1757527548508116600 This conceptually reverts 397d30e9401d2da96dbdf0ce49805d6d4bb68833. The discussion around stubs in that commit does not appear to be important to the current state of the codebase. This makes the error_vprintf() impl source file match that of error_printf(), and also match the header where it is declared. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Richard Henderson --- monitor/monitor.c | 13 ------------- stubs/monitor-core.c | 5 +++++ tests/unit/test-util-sockets.c | 1 + util/error-report.c | 13 +++++++++++++ 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/monitor/monitor.c b/monitor/monitor.c index 03dbe5d131..e1e5dbfcbe 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -268,19 +268,6 @@ 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); - } - return vfprintf(stderr, fmt, ap); -} - 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/monitor-core.c b/stubs/monitor-core.c index 1894cdfe1f..b498a0f1af 100644 --- a/stubs/monitor-core.c +++ b/stubs/monitor-core.c @@ -7,6 +7,11 @@ Monitor *monitor_cur(void) return NULL; } =20 +bool monitor_cur_is_qmp(void) +{ + return false; +} + Monitor *monitor_set_cur(Coroutine *co, Monitor *mon) { return NULL; diff --git a/tests/unit/test-util-sockets.c b/tests/unit/test-util-sockets.c index ee66d727c3..bd48731ea2 100644 --- a/tests/unit/test-util-sockets.c +++ b/tests/unit/test-util-sockets.c @@ -72,6 +72,7 @@ int monitor_get_fd(Monitor *mon, const char *fdname, Erro= r **errp) * otherwise we get duplicate syms at link time. */ Monitor *monitor_cur(void) { return cur_mon; } +bool monitor_cur_is_qmp(void) { return false; } Monitor *monitor_set_cur(Coroutine *co, Monitor *mon) { abort(); } int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) { abort(); } =20 diff --git a/util/error-report.c b/util/error-report.c index 1b17c11de1..79b6f23e64 100644 --- a/util/error-report.c +++ b/util/error-report.c @@ -29,6 +29,19 @@ bool message_with_timestamp; bool error_with_guestname; const char *error_guest_name; =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); + } + return vfprintf(stderr, fmt, ap); +} + int error_printf(const char *fmt, ...) { va_list ap; --=20 2.50.1 From nobody Sun Sep 28 17:03:45 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=1757527618; cv=none; d=zohomail.com; s=zohoarc; b=LVxoRciXLypkxaB0iP+RjgX6SHOtn7h0jcphT0JBsO9sBjlbqv4Nys0fXe0ZMn5w369zTOVsj/q8W/+t9zwUFc5O4U9HdaYRnaEKQG+HLYQJHP+bxd/PoBXSNO03FUbb4737SMy6vPU1+8vajmumTNxqbCYesWU9w43NS+33FnY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757527618; 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=6KBbFO7LRmS7uXQcAahtGaA/mkmtl6dsOkZZBLrYkYc=; b=mMTrrbJrK8fhtHh0omYmGahiUmtS7RPWPHjUIRHfFgZu6tS5BIwiaxRi+ddjdYo7dntR/rIY9BIL9IA1VoJjKwvKmunreRwghscfD05YEowqDkruaLCxFbi9S/iN3oz8Nnqlp59bs13lvaD+6hY74BZHkmhCNDumr9s/1fiBdPU= 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 1757527618734765.0644019567704; Wed, 10 Sep 2025 11:06:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwPBq-0008LM-S2; Wed, 10 Sep 2025 14:05:06 -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 1uwPBm-0008I1-PV for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:05:03 -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 1uwPBk-0004kn-A9 for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:05:02 -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-348-gjT0pskJP12qgr_I9j3aRg-1; Wed, 10 Sep 2025 14:04:56 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 C4B041956094; Wed, 10 Sep 2025 18:04:54 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.57]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BF5E61800447; Wed, 10 Sep 2025 18:04:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757527499; 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=6KBbFO7LRmS7uXQcAahtGaA/mkmtl6dsOkZZBLrYkYc=; b=R5+OGUaLkBSFa/gMpVZqQ3EAmbkqZXTqWfXZywKdJmh1phVIx3e4ndI+CB/lymNOEXi/Gi F3oGUfBLp/+qZO+vLCImsXMKFTXxYZtaqEWB7FGAJF9/HHdyymSqOxw6elTwomwrq3kptX YBXaQmZ0xVP0ZuPISG3dlzyN5i4J3RU= X-MC-Unique: gjT0pskJP12qgr_I9j3aRg-1 X-Mimecast-MFC-AGG-ID: gjT0pskJP12qgr_I9j3aRg_1757527494 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Hanna Reitz , Kevin Wolf , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Christian Schoenebeck , Richard Henderson , Manos Pitsidianakis , Stefan Weil , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Paolo Bonzini , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v3 12/20] monitor: introduce monitor_cur_hmp() function Date: Wed, 10 Sep 2025 19:03:49 +0100 Message-ID: <20250910180357.320297-13-berrange@redhat.com> In-Reply-To: <20250910180357.320297-1-berrange@redhat.com> References: <20250910180357.320297-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.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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: 1757527619640116601 A number of callers use monitor_cur() followed by !monitor_cur_is_qmp(). This is undesirable because monitor_cur_is_qmp() will itself call monitor_cur() again, and monitor_cur() must acquire locks and do hash table lookups. Introducing a monitor_cur_hmp() helper will combine the two operations into one reducing cost. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Richard Henderson --- include/monitor/monitor.h | 1 + monitor/monitor.c | 14 ++++++++++++++ stubs/monitor-core.c | 5 +++++ tests/unit/test-util-sockets.c | 1 + 4 files changed, 21 insertions(+) diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index 296690e1f1..c3b79b960a 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -14,6 +14,7 @@ typedef struct MonitorOptions MonitorOptions; extern QemuOptsList qemu_mon_opts; =20 Monitor *monitor_cur(void); +Monitor *monitor_cur_hmp(void); Monitor *monitor_set_cur(Coroutine *co, Monitor *mon); bool monitor_cur_is_qmp(void); =20 diff --git a/monitor/monitor.c b/monitor/monitor.c index e1e5dbfcbe..cff502c53e 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -84,6 +84,20 @@ Monitor *monitor_cur(void) return mon; } =20 +Monitor *monitor_cur_hmp(void) +{ + Monitor *mon; + + qemu_mutex_lock(&monitor_lock); + mon =3D g_hash_table_lookup(coroutine_mon, qemu_coroutine_self()); + if (mon && monitor_is_qmp(mon)) { + mon =3D NULL; + } + qemu_mutex_unlock(&monitor_lock); + + return mon; +} + /** * Sets a new current monitor and returns the old one. * diff --git a/stubs/monitor-core.c b/stubs/monitor-core.c index b498a0f1af..1e0b11ec29 100644 --- a/stubs/monitor-core.c +++ b/stubs/monitor-core.c @@ -7,6 +7,11 @@ Monitor *monitor_cur(void) return NULL; } =20 +Monitor *monitor_cur_hmp(void) +{ + return NULL; +} + bool monitor_cur_is_qmp(void) { return false; diff --git a/tests/unit/test-util-sockets.c b/tests/unit/test-util-sockets.c index bd48731ea2..d40813c682 100644 --- a/tests/unit/test-util-sockets.c +++ b/tests/unit/test-util-sockets.c @@ -72,6 +72,7 @@ int monitor_get_fd(Monitor *mon, const char *fdname, Erro= r **errp) * otherwise we get duplicate syms at link time. */ Monitor *monitor_cur(void) { return cur_mon; } +Monitor *monitor_cur_hmp(void) { return cur_mon; } bool monitor_cur_is_qmp(void) { return false; } Monitor *monitor_set_cur(Coroutine *co, Monitor *mon) { abort(); } int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) { abort(); } --=20 2.50.1 From nobody Sun Sep 28 17:03:45 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=1757527788; cv=none; d=zohomail.com; s=zohoarc; b=Br/w0QvX9EjaLpTFv+LvXcDAlYgTfJvJ7GXjbdPSqlKWs47xMmBFSEnU3cHuaWHzh56Rer0fGKCJ5rDdUc/lna3eyFQk0vORmJQBItcUYEE55t9m7253kY7MypW8Dwb+LzM9D4E+GPnFORejIyuYcyCzOV7gsnqviEmi4/O8n5A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757527788; 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=zwEMMHbEmgJDVB/xeKh2fCOUkpEHTfgjT4rA2HHkxBw=; b=aoJtw/C0mkKPm/VhV4dpIS+7kyawjsWsCxJWKiDpOhAVgN6SdNFmLipFd2Z9Kfumo3dWpK2Da6adB39iGewGX8wyCxbt/cXcm5X2XIsbVJm6uXcSqR42k9wowZNoRGM1dnhhNBih/XipAuXx+8aXGixZ284Hc/CU2YdcHLeF3Mo= 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 1757527788631652.5181446970844; Wed, 10 Sep 2025 11:09:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwPBr-0008MR-KB; Wed, 10 Sep 2025 14:05:07 -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 1uwPBq-0008LI-Jt for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:05:06 -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 1uwPBo-0004qL-PV for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:05:06 -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-479-4zM5zn98N_aiYc2J0fCGug-1; Wed, 10 Sep 2025 14:05:00 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 DC3401956087; Wed, 10 Sep 2025 18:04:58 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.57]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2C5211800446; Wed, 10 Sep 2025 18:04:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757527503; 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=zwEMMHbEmgJDVB/xeKh2fCOUkpEHTfgjT4rA2HHkxBw=; b=JeL64Y3Z1o8xsyRdlwckV4picjjwpl7ZyZzA6am835BJ6ERgLbvYzB+K/+LtKY0dWjeW19 hXKDlEB6S/YPVXxjNDr2GVvOsTsGUzZQFlL08qafsj8mEH018Pcz/rZsJZvcy8IU+u7iCY 1kiQhYKH0RUpQyJrzip/jT/lYRz0/nw= X-MC-Unique: 4zM5zn98N_aiYc2J0fCGug-1 X-Mimecast-MFC-AGG-ID: 4zM5zn98N_aiYc2J0fCGug_1757527499 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Hanna Reitz , Kevin Wolf , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Christian Schoenebeck , Richard Henderson , Manos Pitsidianakis , Stefan Weil , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Paolo Bonzini , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v3 13/20] util: don't skip error prefixes when QMP is active Date: Wed, 10 Sep 2025 19:03:50 +0100 Message-ID: <20250910180357.320297-14-berrange@redhat.com> In-Reply-To: <20250910180357.320297-1-berrange@redhat.com> References: <20250910180357.320297-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.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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: 1757527789987116600 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 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/util/error-report.c b/util/error-report.c index 79b6f23e64..c0fcf388de 100644 --- a/util/error-report.c +++ b/util/error-report.c @@ -34,9 +34,9 @@ const char *error_guest_name; */ int error_vprintf(const char *fmt, va_list ap) { - Monitor *cur_mon =3D monitor_cur(); + Monitor *cur_mon =3D monitor_cur_hmp(); =20 - if (cur_mon && !monitor_cur_is_qmp()) { + if (cur_mon) { return monitor_vprintf(cur_mon, fmt, ap); } return vfprintf(stderr, fmt, ap); @@ -157,7 +157,7 @@ static void print_loc(void) int i; const char *const *argp; =20 - if (!monitor_cur() && g_get_prgname()) { + if (!monitor_cur_hmp() && g_get_prgname()) { error_printf("%s:", g_get_prgname()); sep =3D " "; } @@ -201,14 +201,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_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_hmp()) { error_printf("%s ", error_guest_name); } =20 --=20 2.50.1 From nobody Sun Sep 28 17:03:45 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=1757527621; cv=none; d=zohomail.com; s=zohoarc; b=YhyakpZVH9sgE6HKjRKa2XXcg+uPZbxJ/WIQchXRfThO18oaFJe7qnHYjVM1/eLKEJgWlN+FqSp3pHXqLn0K/ndIxYnq+zzuyD9axxU90YOdf7Jp3AVextb2dMerbUzFoeanEff425L7BTS+timwpOaVtXXojYMcvez4DkJJHCM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757527621; 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=CdBgoYxIvUWgwyeZLw6CowPy0PcFEK/INVG0xv0t5KE=; b=XYRwoN6Z6jMelwFP6MmvmuTSvLa2YJt2L0Itor2ylK2KJbdWMFbbYqikHixyIDz+YLKiuCAd4yDfFWBqDFJnUeWr7dOq8XK/MFcpJ7wMdG7feW/ifdY3uX9wRRR6rMsLMqdkL+BhqWF31vgFZVgsqht81HWqd7x+6eP2kviBgOg= 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 1757527621042436.0923866708514; Wed, 10 Sep 2025 11:07:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwPCY-0000MR-IN; Wed, 10 Sep 2025 14:05:54 -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 1uwPC4-0008PE-36 for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:05:21 -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 1uwPBu-0004wt-H6 for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:05:19 -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-166-MZPVpweVMH20HsRhSFIDOg-1; Wed, 10 Sep 2025 14:05:04 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 15230180034F; Wed, 10 Sep 2025 18:05:03 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.57]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5E08E1800446; Wed, 10 Sep 2025 18:04:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757527508; 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=CdBgoYxIvUWgwyeZLw6CowPy0PcFEK/INVG0xv0t5KE=; b=FV8LdrWQk8iyRulrFNhqmsWRuE4lHYTZeRMJg4+kmdbKisFZrck5v+uVkPeVUuxDJ7E9Gd q5Zpnxvo2boQTcaWWVtlwQO6PCRFTzzaRGEBxT+fxUq9DwwYKkGxdnQudvqzyydo9Yx2Rg zEu/NJwOkVYfLBV4GM0djxDXcXQzR5g= X-MC-Unique: MZPVpweVMH20HsRhSFIDOg-1 X-Mimecast-MFC-AGG-ID: MZPVpweVMH20HsRhSFIDOg_1757527503 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Hanna Reitz , Kevin Wolf , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Christian Schoenebeck , Richard Henderson , Manos Pitsidianakis , Stefan Weil , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Paolo Bonzini , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v3 14/20] util: fix interleaving of error & trace output Date: Wed, 10 Sep 2025 19:03:51 +0100 Message-ID: <20250910180357.320297-15-berrange@redhat.com> In-Reply-To: <20250910180357.320297-1-berrange@redhat.com> References: <20250910180357.320297-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.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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: 1757527621944116600 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_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 a decision about whether output will go to monitor_[v]printf() or fprintf() must be made upfront, and then those functions called directly. $ 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 This change requires adding a stub for monitor_printf() since that is now called directly by vreport(), where monitor_vprintf() was only needed previously. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Richard Henderson --- stubs/monitor-core.c | 5 +++ tests/unit/test-util-sockets.c | 1 + util/error-report.c | 60 ++++++++++++++++++++++++---------- 3 files changed, 48 insertions(+), 18 deletions(-) diff --git a/stubs/monitor-core.c b/stubs/monitor-core.c index 1e0b11ec29..70b1f7a994 100644 --- a/stubs/monitor-core.c +++ b/stubs/monitor-core.c @@ -30,3 +30,8 @@ int monitor_vprintf(Monitor *mon, const char *fmt, va_lis= t ap) { abort(); } + +int monitor_printf(Monitor *mon, const char *fmt, ...) +{ + abort(); +} diff --git a/tests/unit/test-util-sockets.c b/tests/unit/test-util-sockets.c index d40813c682..53733163dd 100644 --- a/tests/unit/test-util-sockets.c +++ b/tests/unit/test-util-sockets.c @@ -76,6 +76,7 @@ Monitor *monitor_cur_hmp(void) { return cur_mon; } bool monitor_cur_is_qmp(void) { return false; } Monitor *monitor_set_cur(Coroutine *co, Monitor *mon) { abort(); } int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) { abort(); } +int monitor_printf(Monitor *mon, const char *fmt, ...) { abort(); } =20 #ifndef _WIN32 static void test_socket_fd_pass_name_good(void) diff --git a/util/error-report.c b/util/error-report.c index c0fcf388de..6c887047e3 100644 --- a/util/error-report.c +++ b/util/error-report.c @@ -29,6 +29,9 @@ bool message_with_timestamp; bool error_with_guestname; const char *error_guest_name; =20 +typedef void (*error_print_func)(void *opaque, const char *fmt, ...); +typedef void (*error_print_vfunc)(void *opaque, const char *fmt, va_list a= p); + /* * Print to current monitor if we have one, else to stderr. */ @@ -151,34 +154,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(bool cur, error_print_func print_func, void *print_o= paque) { const char *sep =3D ""; int i; const char *const *argp; =20 - if (!monitor_cur_hmp() && g_get_prgname()) { - error_printf("%s:", g_get_prgname()); + if (!cur && g_get_prgname()) { + print_func(print_opaque, "%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]); + print_func(print_opaque, "%s%s", sep, argp[i]); sep =3D " "; } - error_printf(": "); + print_func(print_opaque, ": "); break; case LOC_FILE: - error_printf("%s:", (const char *)cur_loc->ptr); + print_func(print_opaque, "%s:", (const char *)cur_loc->ptr); if (cur_loc->num) { - error_printf("%d:", cur_loc->num); + print_func(print_opaque, "%d:", cur_loc->num); } - error_printf(" "); + print_func(print_opaque, " "); break; default: - error_printf("%s", sep); + print_func(print_opaque, "%s", sep); } } =20 @@ -199,34 +202,55 @@ real_time_iso8601(void) G_GNUC_PRINTF(2, 0) static void vreport(report_type type, const char *fmt, va_list ap) { + /* + * Calling monitor_cur_hmp() will acquire/release mutexes, + * which triggers trace probes, which can trigger + * qemu_log calls, which would interleave with output + * from this. Hence cache the monitor handle upfront + * so any tracing appears before we start outputting. + */ + Monitor *cur =3D monitor_cur_hmp(); + error_print_func print_func; + error_print_vfunc print_vfunc; + void *print_opaque; gchar *timestr; =20 - if (message_with_timestamp && !monitor_cur_hmp()) { + if (cur) { + print_func =3D (error_print_func)monitor_printf; + print_vfunc =3D (error_print_vfunc)monitor_vprintf; + print_opaque =3D cur; + } else { + print_func =3D (error_print_func)fprintf; + print_vfunc =3D (error_print_vfunc)vfprintf; + print_opaque =3D stderr; + } + + if (message_with_timestamp && !cur) { timestr =3D real_time_iso8601(); - error_printf("%s ", timestr); + print_func(print_opaque, "%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_hmp()) { - error_printf("%s ", error_guest_name); + if (error_with_guestname && error_guest_name && !cur) { + print_func(print_opaque, "%s ", error_guest_name); } =20 - print_loc(); + print_loc(!!cur, print_func, print_opaque); =20 switch (type) { case REPORT_TYPE_ERROR: break; case REPORT_TYPE_WARNING: - error_printf("warning: "); + print_func(print_opaque, "warning: "); break; case REPORT_TYPE_INFO: - error_printf("info: "); + print_func(print_opaque, "info: "); break; } =20 - error_vprintf(fmt, ap); - error_printf("\n"); + print_vfunc(print_opaque, fmt, ap); + print_func(print_opaque, "\n"); } =20 /* --=20 2.50.1 From nobody Sun Sep 28 17:03:45 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=1757527582; cv=none; d=zohomail.com; s=zohoarc; b=EvB4HFmhztksEw0c2btc1OG3rqsocKdWR91IzpreJOG9cQHBMJSQOav4lHkV5RAW5H9I1waVp49h08OkRGmAVwION8YmA7GFkrM4kqbQv3KTDH/uLr/ICQLcqG5ck01woGomooNNIv55gSMct/bLw2/kAIWpk+mEtLvfa+BmEyw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757527582; 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=jFr0Gr75/iLAwmNu8zI2hgHqbYuIQZBy2JzT3sEkBQs=; b=awRmadK5YwviIhO891M3mtypxx+aZoEf9ZIK5Sgf3ryTOCGEIiZym2oZ6I5XvaQN0ssoIgdW03Dxwq3msN1mt3ACnP9AmgX9KeKH3SWyD5l0tB0IeJvigZ8uSgawKLSJlAdmmX3R4ASIjvOsf0I9tp75XhAogj8ptXIPyPfsiF4= 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 1757527582569432.14406279006516; Wed, 10 Sep 2025 11:06:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwPCe-0000Yg-PW; Wed, 10 Sep 2025 14:05:59 -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 1uwPC4-0008PF-3n for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:05:23 -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 1uwPBz-0004xC-7R for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:05:18 -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-267-RyVTb9Z9NkCc45803BhDDA-1; Wed, 10 Sep 2025 14:05:08 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 2530B1956094; Wed, 10 Sep 2025 18:05:07 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.57]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 719EB1800452; Wed, 10 Sep 2025 18:05:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757527513; 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=jFr0Gr75/iLAwmNu8zI2hgHqbYuIQZBy2JzT3sEkBQs=; b=a5y8b0Wid9ogoBAsIH2X1wXLPpW9iJlte17mxDUWn6DQ/52q2DpJHlB5Hf5X9alC1s9hoB H1qb/DdbfGugDRsk41SlAVbyis+RzeagRRuTLmGYU6aJdTuGX5gGEQYDk5czIF4aFlez6b S4PI1vNEYys7AwtQG6rpDxLhc6AZWSs= X-MC-Unique: RyVTb9Z9NkCc45803BhDDA-1 X-Mimecast-MFC-AGG-ID: RyVTb9Z9NkCc45803BhDDA_1757527507 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Hanna Reitz , Kevin Wolf , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Christian Schoenebeck , Richard Henderson , Manos Pitsidianakis , Stefan Weil , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Paolo Bonzini , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v3 15/20] util: introduce common helper for error-report & log code Date: Wed, 10 Sep 2025 19:03:52 +0100 Message-ID: <20250910180357.320297-16-berrange@redhat.com> In-Reply-To: <20250910180357.320297-1-berrange@redhat.com> References: <20250910180357.320297-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.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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: 1757527583293116600 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. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Richard Henderson --- MAINTAINERS | 2 ++ include/qemu/message.h | 28 ++++++++++++++++++++++++++++ util/meson.build | 1 + util/message.c | 23 +++++++++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 include/qemu/message.h create mode 100644 util/message.c diff --git a/MAINTAINERS b/MAINTAINERS index 1ae28e8804..5af014ca45 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3171,9 +3171,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..ef70e08c5f --- /dev/null +++ b/util/message.c @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "qemu/osdep.h" + +#include "qemu/message.h" +#include "monitor/monitor.h" + +static int message_format; + +void qmessage_set_format(int flags) +{ + message_format =3D flags; +} + +void qmessage_context_print(FILE *fp) +{ + + if (message_format & QMESSAGE_FORMAT_TIMESTAMP) { + g_autoptr(GDateTime) dt =3D g_date_time_new_now_utc(); + g_autofree char *timestr =3D g_date_time_format_iso8601(dt); + fprintf(fp, "%s ", timestr); + } +} --=20 2.50.1 From nobody Sun Sep 28 17:03:45 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=1757527984; cv=none; d=zohomail.com; s=zohoarc; b=GJ37dhi33hpZ7BAnJ9I0UBb04yO99cOOZmFdJ4dBQRP0huPyi/0SGqq90f2TBhh50sjhjYC069mVvQs0G1KASYZuiPFRZp72XCzBTO6Fzw6HPCBEZqMjzUyXnnXpo0OWTFLaiVovd5sVzThNhSZXl6DwoPEGKhRnMLMFwFFzNaU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757527984; 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=2cUjnHXP+2yLDsC7cDBwPJsCA0A+uWS2z3y2xXWSqbk=; b=ZdrTwkfxv9gN8cgAmuml/xEB/p4IB8Pzn76NYpmMxf51fkuzeZBJk4b8r3kjcmCht8T3Q2mIbOPCAKa1PJ1V4R5rbCm76+gTAqPH/N3bgE0qo8G+ID9HYUrRsY8NtEXesI594ukWPD4nObbJoFOo/uD3FOB2+YCLQIyHjcCzBaE= 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 1757527984301679.3354142319048; Wed, 10 Sep 2025 11:13:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwPCx-0001QP-S5; Wed, 10 Sep 2025 14:06:15 -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 1uwPC4-0008PH-4G for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:05:23 -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 1uwPC0-0004xK-28 for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:05:19 -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-30-lBaOwhgDMKeTJ-ICCBiqfg-1; Wed, 10 Sep 2025 14:05:12 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 284A2180029A; Wed, 10 Sep 2025 18:05:11 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.57]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 86A911800446; Wed, 10 Sep 2025 18:05:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757527514; 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=2cUjnHXP+2yLDsC7cDBwPJsCA0A+uWS2z3y2xXWSqbk=; b=EhJtqS/m3ocETmyKIzpesUrJW7+qgbcZPpd2OZRXK9K/pCLL1fDQMu01kUCmUwyhRTQETX eDF4K6ohL+L614WIlBK5AZ9fCx2wHhI5eduH+x7is+6s2Q3JwZPOh8tx83rkE2VoanZ54r XJZsql8BBdvAAhJvtw7uCy5D5v4PBNE= X-MC-Unique: lBaOwhgDMKeTJ-ICCBiqfg-1 X-Mimecast-MFC-AGG-ID: lBaOwhgDMKeTJ-ICCBiqfg_1757527511 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Hanna Reitz , Kevin Wolf , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Christian Schoenebeck , Richard Henderson , Manos Pitsidianakis , Stefan Weil , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Paolo Bonzini , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v3 16/20] util: convert error-report & log to message API for timestamp Date: Wed, 10 Sep 2025 19:03:53 +0100 Message-ID: <20250910180357.320297-17-berrange@redhat.com> In-Reply-To: <20250910180357.320297-1-berrange@redhat.com> References: <20250910180357.320297-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.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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: 1757527986487116601 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. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Richard Henderson --- include/qemu/error-report.h | 1 - system/vl.c | 7 ++++++- tests/unit/test-error-report.c | 3 ++- util/error-report.c | 17 ++--------------- util/log.c | 21 ++++----------------- 5 files changed, 14 insertions(+), 35 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 a64fd90d4a..696dd92669 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" @@ -813,8 +814,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 6c887047e3..719f059494 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 @@ -185,13 +184,6 @@ static void print_loc(bool cur, error_print_func print= _func, void *print_opaque) } } =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. @@ -213,7 +205,6 @@ static void vreport(report_type type, const char *fmt, = va_list ap) error_print_func print_func; error_print_vfunc print_vfunc; void *print_opaque; - gchar *timestr; =20 if (cur) { print_func =3D (error_print_func)monitor_printf; @@ -223,12 +214,8 @@ static void vreport(report_type type, const char *fmt,= va_list ap) print_func =3D (error_print_func)fprintf; print_vfunc =3D (error_print_vfunc)vfprintf; print_opaque =3D stderr; - } =20 - if (message_with_timestamp && !cur) { - timestr =3D real_time_iso8601(); - print_func(print_opaque, "%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 17:03:45 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=1757527838; cv=none; d=zohomail.com; s=zohoarc; b=X6WtF5ELw7EQNHEvsBHAwBcMk9a0Fz5JOW6EHH07ouWAGU3S795uhSHx4YeTM+nunP/aQH1wT96nhWEUoT6DUCutqDWQJJyEOGYwbvcM/OsyxwDEH1N9EmhdFs7krVMTSdFp+KYmp8lXv03qNvCXx7YdBRL/pKvQkTGbIoTT4Lc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757527838; 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=vxWJYGru1Gg7qht2WyJDwScYuEQEAZ6WAAEk9BmPzFc=; b=Qn047wmQTX32wBkoNwXrfu6u8Dcc8rXapGPK3I8Q/GhtXhQizDbDCn1RjLn4L/NfK2ulRWyJquEOwaZ/ljz8PfboPoKRo1/WBZmCJVIjtcAh4vTQMyO+0LFXx2aQzZ0JaaAdy+a651nfJcT9iugM02My8GYSc5dOgL+MMcHobHM= 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 1757527838653836.4758366595605; Wed, 10 Sep 2025 11:10:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwPD4-0001Xh-73; Wed, 10 Sep 2025 14:06:23 -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 1uwPCE-00005h-5s for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:05: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 1uwPC7-0004yB-GW for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:05:28 -0400 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-363-TSPtSEpcPiekgaXFfx2LQQ-1; Wed, 10 Sep 2025 14:05:16 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 2F89C19560B7; Wed, 10 Sep 2025 18:05:15 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.57]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A43A91800452; Wed, 10 Sep 2025 18:05:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757527521; 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=vxWJYGru1Gg7qht2WyJDwScYuEQEAZ6WAAEk9BmPzFc=; b=UrJseWhkip8BuzIBIeCAN3sdbL18WRCvxDApq2z2lSRUSf7Z5ulFIrdpxksz8CFJ2FsZkV mIeWh6HzdvehUwIdMTnPf6wISn/42Hgge+8friZ/pLXj7TLpWAlZoWVT0VmefCnl/pWrHS WxL8r/7La9/bIottWrElvnIFYYAdHYE= X-MC-Unique: TSPtSEpcPiekgaXFfx2LQQ-1 X-Mimecast-MFC-AGG-ID: TSPtSEpcPiekgaXFfx2LQQ_1757527515 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Hanna Reitz , Kevin Wolf , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Christian Schoenebeck , Richard Henderson , Manos Pitsidianakis , Stefan Weil , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Paolo Bonzini , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v3 17/20] util: add support for formatting a workload name in messages Date: Wed, 10 Sep 2025 19:03:54 +0100 Message-ID: <20250910180357.320297-18-berrange@redhat.com> In-Reply-To: <20250910180357.320297-1-berrange@redhat.com> References: <20250910180357.320297-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.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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: 1757527840603116600 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 Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Richard Henderson --- include/qemu/error-report.h | 3 --- include/qemu/message.h | 10 ++++++++++ system/vl.c | 6 ++++-- util/error-report.c | 7 ------- util/message.c | 12 +++++++++++- 5 files changed, 25 insertions(+), 13 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 696dd92669..fee6fdf7b1 100644 --- a/system/vl.c +++ b/system/vl.c @@ -818,7 +818,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 @@ -3520,7 +3522,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 719f059494..c40cdf3bb3 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 typedef void (*error_print_func)(void *opaque, const char *fmt, ...); typedef void (*error_print_vfunc)(void *opaque, const char *fmt, va_list a= p); @@ -218,11 +216,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) { - print_func(print_opaque, "%s ", error_guest_name); - } - print_loc(!!cur, print_func, print_opaque); =20 switch (type) { diff --git a/util/message.c b/util/message.c index ef70e08c5f..a91c008e08 100644 --- a/util/message.c +++ b/util/message.c @@ -6,18 +6,28 @@ #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_context_print(FILE *fp) +void qmessage_set_workload_name(const char *name) { + message_workloadname =3D g_strdup(name); +} =20 +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); } + + if ((message_format & QMESSAGE_FORMAT_WORKLOAD_NAME) && + message_workloadname) { + fprintf(fp, "%s ", message_workloadname); + } } --=20 2.50.1 From nobody Sun Sep 28 17:03:45 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=1757527706; cv=none; d=zohomail.com; s=zohoarc; b=EbLon0gCDCgDv75HdXt2wNgnqtn03cahUL4m5tAVMzYZ2EXRrdI2sz78lT3tlX6Eub8RTUdVmHAbhPUlRkwAAWsWyqbHPSPU0flygQJ9t78ec+dOap01ixHqk/wpnSCFBWdHCVqluFmSkQb4ek0iPdUH9wTYgAwRu01jYZ6JU6c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757527706; 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=is3SBFpDORKjYTG0YU7LRi9TAXlLNDBCh+mVPfED7To=; b=LGya2q5kThv2DlVIrmJumu08+4uU67J1GW+G7xTlY4Mx3MZx3YdvhdX2baT9hNmD/QPSt1qE6V8zQi5Rvz5aZclEePwgds4k+hFi0EYrMi+BWfFtKRf7lBlJ98seLYnWcrQ0ITozhnQgj1GVeB7lZ7wKO7ab02bYRgbbSTX642k= 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 1757527706361246.47623240848498; Wed, 10 Sep 2025 11:08:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwPD9-0002HM-DY; Wed, 10 Sep 2025 14:06: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 1uwPCH-00009L-ET for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:05:36 -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 1uwPCD-0004yS-11 for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:05:31 -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-227-iErZd3f4OSa_FzFTuksRvQ-1; Wed, 10 Sep 2025 14:05:21 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 8EFDC1956095; Wed, 10 Sep 2025 18:05:19 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.57]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A23D51800446; Wed, 10 Sep 2025 18:05:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757527525; 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=is3SBFpDORKjYTG0YU7LRi9TAXlLNDBCh+mVPfED7To=; b=Jln7xUWnZAtcqlLZyfp3jyBBp4zmKmI4v49wV8+r+u2Z6+s6OLc0bIxALsqbFXaA5pPI/3 W+u/ybD1N32i/+csUJjoxGmVfijr9nzpLHJGYYbTtv20oe/f1hk1ghcv/LLus1BY9wfst4 0J+zCZK8QX5YuJ4uOB5M0PV2ZD0/eBE= X-MC-Unique: iErZd3f4OSa_FzFTuksRvQ-1 X-Mimecast-MFC-AGG-ID: iErZd3f4OSa_FzFTuksRvQ_1757527519 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Hanna Reitz , Kevin Wolf , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Christian Schoenebeck , Richard Henderson , Manos Pitsidianakis , Stefan Weil , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Paolo Bonzini , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v3 18/20] util: add support for formatting a program name in messages Date: Wed, 10 Sep 2025 19:03:55 +0100 Message-ID: <20250910180357.320297-19-berrange@redhat.com> In-Reply-To: <20250910180357.320297-1-berrange@redhat.com> References: <20250910180357.320297-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.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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: 1757527708937116600 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 Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Richard Henderson --- 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 fee6fdf7b1..9030212c50 100644 --- a/system/vl.c +++ b/system/vl.c @@ -814,7 +814,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 c40cdf3bb3..d3a234b8b9 100644 --- a/util/error-report.c +++ b/util/error-report.c @@ -157,10 +157,6 @@ static void print_loc(bool cur, error_print_func print= _func, void *print_opaque) int i; const char *const *argp; =20 - if (!cur && g_get_prgname()) { - print_func(print_opaque, "%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 17:03:45 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=1757527736; cv=none; d=zohomail.com; s=zohoarc; b=D6nfpXO5p1ezlAPC3DI+biNLIDCJZ1xv4HxRD1Tm32A+YhV15LEeWKQY+IpWTgHT1VClgCwbAyU8jvbEjEskcutUUSvdcEkKzK4cXKWpXyaN/MwjibmAFY5sIZd2HmK74pDnOBNqaJTZZsfJRdggEVPQLF4G9oydLBv/Nhj7E4Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757527736; 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=NO3qcMLq197Tg5EtsdlSetOWDZScfGDl9ja1Ma2ak8k=; b=htiDFqY7/3w5gnH+GKOoVdnt+dN6NRjfcvBFXyI3MV6c9GefcYHH9nBX1gdEfwUEvJSZHug+mERvmulcnTbOPVb6yG+xz2G0ATCayj6RXE4d1xvEXKVv1t5wAXtfhzQQDrvbD0fvoEtvaGFyirjw2b9ytJOtUpN6CZPEpwCWHN8= 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 1757527736876207.11173576613737; Wed, 10 Sep 2025 11:08:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwPCx-0001OF-Du; Wed, 10 Sep 2025 14:06:15 -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 1uwPCP-0000Me-Hb for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:05:43 -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 1uwPCF-0004z0-7c for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:05:39 -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-596-5oMaHKO5PVKC810BNXbLQQ-1; Wed, 10 Sep 2025 14:05:25 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 A698D19560AF; Wed, 10 Sep 2025 18:05:23 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.57]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id ECB121800447; Wed, 10 Sep 2025 18:05:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757527529; 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=NO3qcMLq197Tg5EtsdlSetOWDZScfGDl9ja1Ma2ak8k=; b=KCxjXEVpCiF79TGrXelFJMwvQyioKMwfIuoylFs9AnhN5jF1f21pF8CsfHVW5fB9xus2LD EYWQWfQQtstP5glan7Uqa/mBlRuu3/mZBmpcdy8GlxFRg9swJE/WhWeVFqImqYZTji8vll oxUpb6uNDHgbZOHcRF7c2LZErk/2TMw= X-MC-Unique: 5oMaHKO5PVKC810BNXbLQQ-1 X-Mimecast-MFC-AGG-ID: 5oMaHKO5PVKC810BNXbLQQ_1757527523 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Hanna Reitz , Kevin Wolf , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Christian Schoenebeck , Richard Henderson , Manos Pitsidianakis , Stefan Weil , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Paolo Bonzini , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v3 19/20] util: add support for formatting thread info in messages Date: Wed, 10 Sep 2025 19:03:56 +0100 Message-ID: <20250910180357.320297-20-berrange@redhat.com> In-Reply-To: <20250910180357.320297-1-berrange@redhat.com> References: <20250910180357.320297-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.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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: 1757527737565116600 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 x5= 09 load creds=3D0x560db818e080 dir=3Dfish qemu-system-x86_64(772366:main): qcrypto_tls_creds_get_path TLS creds pat= h creds=3D0x560db818e080 filename=3Dca-cert.pem path=3D qemu-system-x86_64(772366:main): Unable to access credentials fish/ca-cer= t.pem: No such file or directory Signed-off-by: Daniel P. Berrang=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 9030212c50..20b655a7bc 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; @@ -811,10 +815,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; } @@ -2888,6 +2891,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 17:03:45 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=1757527614; cv=none; d=zohomail.com; s=zohoarc; b=REKHdvFZm6bdmuCDumep3m5h1F5dZjdn+ue0WIEgqLlJ0DEhXcyXVVB0y2caw8xh+t2e2GF/wwoVqjRUspwBmzUB/xfKzUADpC0IH0nxki18orRPoN2f1z2jWlQ3dMMQV98kQsQG7GAoSFnVXyagkWtlSq7ybxZFEzm9etsRa+8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757527614; 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=fy2hCOizZ1P8nfNJTFHtbE21ChLZDVppYA1lOHsHttE=; b=Q7NxY3wTB44bx+kUb/aa4K230SjjpvSHCfMHvYuqzvIxmcfm387hvWYLj6FCJ7jSaVjEh9OekMTeWe3dYpA2LeCwbQfYMNMnHhWwp8OYrpjKrmvdZAgeSAntS/esj/bv4T3hAbZ9tzibehl9CPDaYP5WqmSe0RYvLNfafsSXj/U= 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 1757527614981102.10345645855523; Wed, 10 Sep 2025 11:06:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwPCv-00016I-K9; Wed, 10 Sep 2025 14:06:13 -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 1uwPCL-0000IJ-Jl for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:05:39 -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 1uwPCJ-0004zl-Mb for qemu-devel@nongnu.org; Wed, 10 Sep 2025 14:05:37 -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-213-FAqXAgcIPQuQIoHXLYQfgw-1; Wed, 10 Sep 2025 14:05:30 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 BF7861800291; Wed, 10 Sep 2025 18:05:28 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.57]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 102491800446; Wed, 10 Sep 2025 18:05:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757527534; 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=fy2hCOizZ1P8nfNJTFHtbE21ChLZDVppYA1lOHsHttE=; b=P5W8rwQefhgPPR2/P0cwo6DzFPhlZAMr/8eqwKhx+eflACixeeaWl7o6bge8fo/+xkroyV TpVyLkHNM4qcgZqAagjB0/oglDYc3fAyH9/klpBxwPKAuZn0rM9KJq3hlYysjnxEOYMMvt 16taxX6kzSWiyuIw+euwivK91QoOApo= X-MC-Unique: FAqXAgcIPQuQIoHXLYQfgw-1 X-Mimecast-MFC-AGG-ID: FAqXAgcIPQuQIoHXLYQfgw_1757527528 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Hanna Reitz , Kevin Wolf , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Christian Schoenebeck , Richard Henderson , Manos Pitsidianakis , Stefan Weil , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Paolo Bonzini , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v3 20/20] util: add brackets around guest name in message context Date: Wed, 10 Sep 2025 19:03:57 +0100 Message-ID: <20250910180357.320297-21-berrange@redhat.com> In-Reply-To: <20250910180357.320297-1-berrange@redhat.com> References: <20250910180357.320297-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.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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: 1757527615611116600 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 T= LS creds x509 load creds=3D0x55657e94e690 dir=3Dfish fish food qemu-system-x86_64(1146846:main): qcrypto_tls_creds_get_path TL= S creds path creds=3D0x55657e94e690 filename=3Dca-cert.pem path=3D fish food qemu-system-x86_64(1146846:main): Unable to access credentials = 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_load= TLS creds x509 load creds=3D0x5604ada2c950 dir=3Dfish [fish food] qemu-system-x86_64(1144713:main): qcrypto_tls_creds_get_path = TLS creds path creds=3D0x5604ada2c950 filename=3Dca-cert.pem path=3D [fish food] qemu-system-x86_64(1144713:main): Unable to access credential= s fish/ca-cert.pem: No such file or directory Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Richard Henderson --- 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