From nobody Sun Sep 28 15:29:07 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=1756568139; cv=none; d=zohomail.com; s=zohoarc; b=UiVKpsnzDXiOlLzP7IWaLsdLjz7RYv6HAOY6D9iJ8X3/PNDMdta9ZZcVs/6xAegltC71OZ+ZxSwBtS0IeBTLaWbS2vim/08/+XmBWZo1ITPmVZmdnqjajaHfNCwlNMH/x7NT/ajRKJn4tYE58VGbDFXdaPMrVO/2Tvlzn4t41NA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756568139; 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=nCbGcsiVAJlNscguLMny9mM9bwo/qEQWFgH5PtIu/kE=; b=ZKX+DTWAptOSwsG+l10ErgD3ejoCy5Z/Ak8dOnLQ5VcEtw+MccvdnHJH33FUxH9S20u/IVyGOb8Y119TLNKKEgG4twaDryAkmybLsb8TSl3alyxrhSmq0bNk51KzNl9Dm5ArHEOLSdVscAiYD0QU96FZvMKVStNUAyP3CHhOtZQ= 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 1756568139093773.4688087661897; Sat, 30 Aug 2025 08:35:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1usNaG-00017F-TX; Sat, 30 Aug 2025 11:33: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 1us3Sf-0005Tv-9D for qemu-devel@nongnu.org; Fri, 29 Aug 2025 14:04:29 -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 1us3SX-0005Nu-Vh for qemu-devel@nongnu.org; Fri, 29 Aug 2025 14:04:25 -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-127-oaJGw1AHPlS_BtMHk5oe2Q-1; Fri, 29 Aug 2025 14:04:08 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 0E41719560AA; Fri, 29 Aug 2025 18:04:07 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.108]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0ED5619560B4; Fri, 29 Aug 2025 18:04:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1756490652; 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=nCbGcsiVAJlNscguLMny9mM9bwo/qEQWFgH5PtIu/kE=; b=St8a1VwbuaWbwRKOsDj3wL4ChM8YtOM7Xu8XFVuzYBiEJJ96j2RMWTRvquJT/hhAu0ImuH 51J/7UA5DIY8iWlU7IaBTuUX2S0CoqiYCk3wXBRCYYWri6oLHy9lGgvP4sTF3yGNjRrVHE rlgBhRiRfLpXkuElhceMWkDWqqyVZzY= X-MC-Unique: oaJGw1AHPlS_BtMHk5oe2Q-1 X-Mimecast-MFC-AGG-ID: oaJGw1AHPlS_BtMHk5oe2Q_1756490647 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefan Weil , qemu-block@nongnu.org, Manos Pitsidianakis , "Dr. David Alan Gilbert" , Kevin Wolf , Hanna Reitz , Gerd Hoffmann , Christian Schoenebeck , Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 01/14] include: define constant for early constructor priority Date: Fri, 29 Aug 2025 19:03:41 +0100 Message-ID: <20250829180354.2922145-2-berrange@redhat.com> In-Reply-To: <20250829180354.2922145-1-berrange@redhat.com> References: <20250829180354.2922145-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.0 on 10.30.177.12 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1756568141295124100 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. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Richard Henderson --- 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 15:29:07 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=1756573123; cv=none; d=zohomail.com; s=zohoarc; b=fenbnkSQ7JYh0d1JUajwL+prLq6K6//mgxlZXhR/31wk/2ODAmT2tb8zcNhbGdcfqnxOfpQz4JXVXaTUHUizvFsgLiraPn8mUaFx147TjRQP1LpZ63lak5H57HHM3cVhF+4DdAG6Kj0SwxrTFSWEqXk7qeKs+/Tsr6sC1Iqr6SM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756573123; 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=wVZICUMCqxqz7az1/nfHmwGiaD1oCFJORFGMoNZGToI=; b=HSZjkysRAyQlZAJ/yJgzrWCU7Z6mqzT9CRrhUQQb9dEPsn0f2H83yoCdmhLUTV9fRCCSgrKGYHM5Vmdrjh4ThpnDJQNi2FfHyhtLC0y0YWA6x8j2ExOAAdDqF47HIlUpVDFzQ3DGssvbM1+8vcC2ml44JFFnX0Ou/UMEIhQgZ3Y= 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 1756573123181277.4405419078365; Sat, 30 Aug 2025 09:58:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1usNaM-0001kw-MR; Sat, 30 Aug 2025 11:33: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 1us3Sf-0005Tr-8S for qemu-devel@nongnu.org; Fri, 29 Aug 2025 14:04:29 -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 1us3SY-0005PF-H9 for qemu-devel@nongnu.org; Fri, 29 Aug 2025 14:04:25 -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-112-7vG2dPVPNouSKl29-JRabg-1; Fri, 29 Aug 2025 14:04:13 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 16CA6195E917; Fri, 29 Aug 2025 18:04:12 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.108]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8238419560BC; Fri, 29 Aug 2025 18:04:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1756490657; 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=wVZICUMCqxqz7az1/nfHmwGiaD1oCFJORFGMoNZGToI=; b=VDhPbrftrdEVDTQa4eE4FLdyP2W6pDN/R/2OS75swAb1I00pVa7g0JcVKavpG9aDRy0lRC Ux6v8KyFlwCRkd3vDGVJUEhPDG1XgMSU1TeGGMyI3KY/Jwr3x1WOZqRfD2vqphynPCvb53 PbXOlFB656hCjIT+RwjGpB0C+qhnweM= X-MC-Unique: 7vG2dPVPNouSKl29-JRabg-1 X-Mimecast-MFC-AGG-ID: 7vG2dPVPNouSKl29-JRabg_1756490652 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefan Weil , qemu-block@nongnu.org, Manos Pitsidianakis , "Dr. David Alan Gilbert" , Kevin Wolf , Hanna Reitz , Gerd Hoffmann , Christian Schoenebeck , Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 02/14] monitor: initialize global data from a constructor Date: Fri, 29 Aug 2025 19:03:42 +0100 Message-ID: <20250829180354.2922145-3-berrange@redhat.com> In-Reply-To: <20250829180354.2922145-1-berrange@redhat.com> References: <20250829180354.2922145-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.0 on 10.30.177.12 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1756573125174124100 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. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Richard Henderson --- 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 15:29:07 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=1756568555; cv=none; d=zohomail.com; s=zohoarc; b=HC+s1OfrXHZwXiJESe2kuEj8vjuh3L80KcK2okC0cgMirrkqyqwOg0Jp3Auix8ku2/yMoB2H2hLwBsWUkF82+mDqhXYYW4cNqoRIArnNbjUYyEwgJIJERl/cSb0gjamR/pitCzeScL4dJoHkxmXtG/vJnokelejN2+wE6F322jE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756568555; 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=BZrujp2kh9NNpbbbIPrh/8zPN6bh45S5q39N1+WuZqE=; b=VeDitqeLD2IouJbIHxEbWGgd+U/oURgls4oBm4ykyAkRWvzzeidnvWum65bVcjGb1idz5K24DzF9WDtvO1bpmhwtWgDtA+wIeD9ctW4inG9icCmKUSlvSjXs9LdEYkAnQWHq8po/WoKGXDvTlj5yLp6AWBpf65jXwqHOLsNT1v0= 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 1756568555698885.5293998538579; Sat, 30 Aug 2025 08:42:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1usNZG-0008Cf-5A; Sat, 30 Aug 2025 11:32: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 1us3Sf-0005Tw-9l for qemu-devel@nongnu.org; Fri, 29 Aug 2025 14:04:29 -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 1us3Sa-0005Rv-TR for qemu-devel@nongnu.org; Fri, 29 Aug 2025 14:04:27 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-649-n4T4kEdCPduUprlvxXTxXA-1; Fri, 29 Aug 2025 14:04:20 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 9669218002C9; Fri, 29 Aug 2025 18:04:18 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.108]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AD03719560B4; Fri, 29 Aug 2025 18:04:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1756490664; 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=BZrujp2kh9NNpbbbIPrh/8zPN6bh45S5q39N1+WuZqE=; b=NUMFuHrsvJL+MUXxwUXrRx/Ng35KnHXScLs17CMB5cH9r7tJBSJYgEzSskT5mvpy1tjN4w ZkLmGojvseB6AojmbtNs2qzLtQTjty5M5jGXvlnREqqjOn9ra3de/fOSFQo1VBVfVtSTNQ bvU0MkERvuUYLBdp9pymEriBTQSTpDI= X-MC-Unique: n4T4kEdCPduUprlvxXTxXA-1 X-Mimecast-MFC-AGG-ID: n4T4kEdCPduUprlvxXTxXA_1756490658 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefan Weil , qemu-block@nongnu.org, Manos Pitsidianakis , "Dr. David Alan Gilbert" , Kevin Wolf , Hanna Reitz , Gerd Hoffmann , Christian Schoenebeck , Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 03/14] system: unconditionally enable thread naming Date: Fri, 29 Aug 2025 19:03:43 +0100 Message-ID: <20250829180354.2922145-4-berrange@redhat.com> In-Reply-To: <20250829180354.2922145-1-berrange@redhat.com> References: <20250829180354.2922145-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.0 on 10.30.177.12 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1756568556574116600 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 Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Richard Henderson --- 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 d50645a071..bd6f865558 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. + User-mode emulator command line arguments ----------------------------------------- =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 15:29:07 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=1756568955; cv=none; d=zohomail.com; s=zohoarc; b=iCGgmqL/toj84Xw0btk7QDvDvTL0GURfTQKxdq+dwxdBNTboMAga39uyetVrPseyaRFWkN4aJpTDBnktC0oFjWcV0wwgp/17+Zn2vzz2zlqfcRlsMd25I5ATRRq+mzocnG84zr/dUrJqTEMb1ZurF6+II6Va4qpNzEpRPJvgWw0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756568955; 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=CsQMr5QH89/FrV0mKBjbQ6m8jB0T4odnEedDXMKrtRU=; b=F3KpyltkNzNtBWnECBWds+6kMWxfVRN+FSYpCHPYZrHD0T9kljmunT7NcEIUJu5qOAKIvu2R8rUM0gwTZ0zff+k3TeL4/w/XTG0t5hthyA0eId5aCHHOwg+HKA7xgcuEdMlf7ZK5KCsiUANI5mWJcspcrwFQdRVm1DW3JwIy6vk= 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 1756568955562346.27944371452963; Sat, 30 Aug 2025 08:49:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1usNZd-0000Pq-QP; Sat, 30 Aug 2025 11:33:02 -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 1us3Sq-0005WW-Il for qemu-devel@nongnu.org; Fri, 29 Aug 2025 14:04:42 -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 1us3Si-0005U6-Og for qemu-devel@nongnu.org; Fri, 29 Aug 2025 14:04:39 -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-170-wEn-PJviPTW09Z31JbEcnQ-1; Fri, 29 Aug 2025 14:04:25 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 0CC3019560B4; Fri, 29 Aug 2025 18:04:24 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.108]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3289219560B4; Fri, 29 Aug 2025 18:04:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1756490669; 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=CsQMr5QH89/FrV0mKBjbQ6m8jB0T4odnEedDXMKrtRU=; b=gTrTzWS8AuFn9Ivtbk5dHta+8Yozu22Q8CpgDkAB4c5qeI+ZZP5kMFj1PQANblzAR2I4cz CbbpXUdVd5qiOicLTFHJ3u7pH0oDaJx3aP622cFasRH+YONMafEPtbSc6eWmDRgLmoz5NE sikJ2pN1UVDWnReY0d9O5qVkY4NbEDU= X-MC-Unique: wEn-PJviPTW09Z31JbEcnQ-1 X-Mimecast-MFC-AGG-ID: wEn-PJviPTW09Z31JbEcnQ_1756490664 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefan Weil , qemu-block@nongnu.org, Manos Pitsidianakis , "Dr. David Alan Gilbert" , Kevin Wolf , Hanna Reitz , Gerd Hoffmann , Christian Schoenebeck , Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 04/14] util: expose qemu_thread_set_name Date: Fri, 29 Aug 2025 19:03:44 +0100 Message-ID: <20250829180354.2922145-5-berrange@redhat.com> In-Reply-To: <20250829180354.2922145-1-berrange@redhat.com> References: <20250829180354.2922145-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.0 on 10.30.177.12 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=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: 1756568958209124100 The ability to set the thread name needs to be used in a number of places, so expose the current impls as public methods. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Richard Henderson --- 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 15:29:08 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=1756576499; cv=none; d=zohomail.com; s=zohoarc; b=U1UszwK/emy7A2R+4+/FXlwEnEKyG02N6l5iWLPKKrTnQtd8ObcMkRQEtdaGjpkx9dUzSVhcQE+goHkgCH7cOyH17A4kMzAFHxJEspz2Jc88ri0MV0+2lDtgi34Ar0YkAmBGytAgFdM/NdFvTflH2e523BGmP+CQWgI/R+CHav8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756576499; 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=XFoXFoRHsSZ4hvmRYV9ZwsMGx9Bv6rZuE8b3f6MHfZw=; b=h0bgreJ2nKkXPaqPvcyCRPIyf/Nq7MqAfDohwvqWVD1e8A5CXuikYP59N0RwykT1Vdjk1q8YG01P+RqsY/1Ajr2OSH+2mdYSiVz+KtgoW7mQWAWDbJAV/Xn3eMEbQOpnQSPOpRAFn33wCUz4j3fQoRI2EwT1qkV6mZ4PCBbQV34= 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 1756576499264487.45361129483524; Sat, 30 Aug 2025 10:54:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1usNaQ-00025T-JJ; Sat, 30 Aug 2025 11:33:50 -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 1us3Sq-0005WU-IO for qemu-devel@nongnu.org; Fri, 29 Aug 2025 14:04:42 -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 1us3Sn-0005WO-7j for qemu-devel@nongnu.org; Fri, 29 Aug 2025 14:04:39 -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-680-kFuzWI-QPf6xYD7hcl-rNg-1; Fri, 29 Aug 2025 14:04:30 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 29928195C27C; Fri, 29 Aug 2025 18:04:29 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.108]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9A4E41955E89; Fri, 29 Aug 2025 18:04:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1756490675; 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=XFoXFoRHsSZ4hvmRYV9ZwsMGx9Bv6rZuE8b3f6MHfZw=; b=i03zWHpCWuiNvcGFBpI0DFeX0bwGmwr+Nw/J7+85jg465j3R4A3brGe9CTO/ctyOLg/ejy jTJ7YZsbuPCGnkk5dF4Eee7Ow0YsaAVE1UHZln8Lb1w6g9UWOrr3x00zAFOE1qGGmFycCA zQN6FCBlO6oiQKstPzzvw/uXqFceDgU= X-MC-Unique: kFuzWI-QPf6xYD7hcl-rNg-1 X-Mimecast-MFC-AGG-ID: kFuzWI-QPf6xYD7hcl-rNg_1756490669 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefan Weil , qemu-block@nongnu.org, Manos Pitsidianakis , "Dr. David Alan Gilbert" , Kevin Wolf , Hanna Reitz , Gerd Hoffmann , Christian Schoenebeck , Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 05/14] audio: make jackaudio use qemu_thread_set_name Date: Fri, 29 Aug 2025 19:03:45 +0100 Message-ID: <20250829180354.2922145-6-berrange@redhat.com> In-Reply-To: <20250829180354.2922145-1-berrange@redhat.com> References: <20250829180354.2922145-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.0 on 10.30.177.12 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1756576501730124100 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: Dr. David Alan Gilbert --- audio/jackaudio.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/audio/jackaudio.c b/audio/jackaudio.c index 974a3caad3..48ffbf735f 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 --=20 2.50.1 From nobody Sun Sep 28 15:29:08 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=1756568284; cv=none; d=zohomail.com; s=zohoarc; b=GzfMNCAgYZs5VgVJWgohTZ1Osu7UQXk/o7vcTt6l4zzb5qnqDQPdIr3R1hTfdlrV3Siv3bgM66LCb3LJsOCPZz4dn96IcKe2Z5ZN43dSnfLilZzpCso8yXLXeHbTyw1dOgYq99q6WZNXtptHGVtlYIwIfVe0tDrw8iJQHeZebfw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756568284; 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=y5WgckRyPOl+OzwTIqRF01uc4XyMNWmTjVaQHTrfBS4=; b=R1ZjJiFP4tDb34Rc+itqfKm1fQpCxLxWS3BGccUuPmNUfteWTu8mZq1FmY4YuvsM8jdTi+UcR+wkFS2ewgNFcLtbncyUV7z2PEjG4zfZNNNhPyVUjkeCKkUdzIvzLZ5jpowlu9r8ky6Wbl+DslD9bdvSlnVNCgvvF7RAT1bKCNo= 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 17565682845421016.5714502606157; Sat, 30 Aug 2025 08:38:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1usNa7-0000mG-M8; Sat, 30 Aug 2025 11:33:34 -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 1us3St-0005YK-An for qemu-devel@nongnu.org; Fri, 29 Aug 2025 14:04:43 -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 1us3Sq-0005YL-C6 for qemu-devel@nongnu.org; Fri, 29 Aug 2025 14:04:43 -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-499-SjuWimgVPiu2TamYRYZlAg-1; Fri, 29 Aug 2025 14:04:35 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 D8324180044F; Fri, 29 Aug 2025 18:04:33 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.108]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9E87C19560B4; Fri, 29 Aug 2025 18:04:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1756490679; 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=y5WgckRyPOl+OzwTIqRF01uc4XyMNWmTjVaQHTrfBS4=; b=dcQhTgfuIMTadQYn8PPuWnpWsRdPVIA9Vzqi44pbBmfXBLhLsiIOnrtP13OU9qzpCpb1yj YWQPztt2Sz31BKnCg7wx5oJkKpoE39zUyV8vSwhaiVVwwmjKdK9l5t0g8ROgKzU9k8Xoj/ jLSDxTbUNI1+MILM/OZ3XvWI0XxTAlY= X-MC-Unique: SjuWimgVPiu2TamYRYZlAg-1 X-Mimecast-MFC-AGG-ID: SjuWimgVPiu2TamYRYZlAg_1756490674 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefan Weil , qemu-block@nongnu.org, Manos Pitsidianakis , "Dr. David Alan Gilbert" , Kevin Wolf , Hanna Reitz , Gerd Hoffmann , Christian Schoenebeck , Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 06/14] util: set the name for the 'main' thread Date: Fri, 29 Aug 2025 19:03:46 +0100 Message-ID: <20250829180354.2922145-7-berrange@redhat.com> In-Reply-To: <20250829180354.2922145-1-berrange@redhat.com> References: <20250829180354.2922145-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.0 on 10.30.177.12 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1756568286684124100 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. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Richard Henderson --- 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 15:29:08 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=1756578017; cv=none; d=zohomail.com; s=zohoarc; b=laR8CupPGq3umzVog7hL73NaKaLZyLzPhwwEMbIVWELkxjo9ESs46nw7H+cOGn5O30NibGu74Fon9/2BrqPPs4qye3OpC7bfFYZSGry+S9JN0tuoAdWeIkjrbdFTs/bKvPnYKtV8C3IkdNqCTIcA6MiKPRxRCwJsM1Nd282C6pE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756578017; 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=DfwSqq/b4hHS1NgiMr1RScFvay2XswWXsOaYXHkww6Y=; b=OcaxIcynHyiZIFlpjx3om2A1f67HswdDQEfNQ9GS9UNr0GEkyKk35DVh+95ZBY2c+EFnRcOs3GUEiX/SlYzRW1FZY2cdvUEqgnZm4Q5UmLPAOw0fYY6aO+6lo9mwcNfpVmXDpRLh/LNWGTpLTOGWlHn9SEZYMYgd6FTNek0C+eA= 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 1756578017503614.5794930868462; Sat, 30 Aug 2025 11:20:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1usNaR-0002Bj-G9; Sat, 30 Aug 2025 11:33:51 -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 1us3TK-0005eL-1f for qemu-devel@nongnu.org; Fri, 29 Aug 2025 14:05:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1us3TH-0005vP-Rz for qemu-devel@nongnu.org; Fri, 29 Aug 2025 14:05:09 -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-630-CGJZAov9Pk-4sCMJqBtaTQ-1; Fri, 29 Aug 2025 14:04:44 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 93ED3195608E; Fri, 29 Aug 2025 18:04:38 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.108]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5A1EE19560B4; Fri, 29 Aug 2025 18:04:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1756490706; 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=DfwSqq/b4hHS1NgiMr1RScFvay2XswWXsOaYXHkww6Y=; b=g5hQWeuC8ni4eaT5vjHoPUlk9ZbjH4VEG+/Zn1sj2fOVAzHcuKrxWkceiXiggaVc7rtxyi NqrqVKunel2TIskqM8yXK0bPDsGBpJ7ZpY/eU+50qCvwTiAEXzhqMwdjkENNMZ+gOACKSa ffFFrwtAsCQBTRMPLI7IxaAT2WmPxBw= X-MC-Unique: CGJZAov9Pk-4sCMJqBtaTQ-1 X-Mimecast-MFC-AGG-ID: CGJZAov9Pk-4sCMJqBtaTQ_1756490680 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefan Weil , qemu-block@nongnu.org, Manos Pitsidianakis , "Dr. David Alan Gilbert" , Kevin Wolf , Hanna Reitz , Gerd Hoffmann , Christian Schoenebeck , Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 07/14] util: add API to fetch the current thread name Date: Fri, 29 Aug 2025 19:03:47 +0100 Message-ID: <20250829180354.2922145-8-berrange@redhat.com> In-Reply-To: <20250829180354.2922145-1-berrange@redhat.com> References: <20250829180354.2922145-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.0 on 10.30.177.12 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1756578018656124100 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 0d42de61ae..5d610224fa 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 15:29:08 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=1756570107; cv=none; d=zohomail.com; s=zohoarc; b=jGo5qzynPRQ7Gyrj27RfViDqfEZekA7fP7nsmoRruQUzb1iDjl2kXYxXkjaaSS5ub6C3uaHnjNrUSLa42u4wh5BPQTreUNdUHfsp59IufUU0EHG3rVtX0B5q0irrk3UqgrjrbGKkbZPGjxxSkY6WYBN7BEHSLoLFIqMJCjs/FYk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756570107; 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=/d1KbXp3NlbzRl97qpGniZuRtrRxyln2ywplCOuUaXM=; b=YNP9EE/30wmnlh/erORqxDB22gSjJ0292ffBpQwCkHw1OpFjT/5uGK0yHj1cU+TZiPSgVHrT/jvbqtHhu7b40lgFOQMKVZaaNSZRH/5FI8K6XYs+9UO+NdoFhiZJoPwqC0NKdUPhO+V4DHMZ5DbpZfjww0PpmioJ59aIp6QlDC0= 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 1756570107399568.9206543778638; Sat, 30 Aug 2025 09:08:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1usNaH-00017U-3f; Sat, 30 Aug 2025 11:33: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 1us3T0-0005aS-UZ for qemu-devel@nongnu.org; Fri, 29 Aug 2025 14:04:50 -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 1us3Sz-0005ca-IO for qemu-devel@nongnu.org; Fri, 29 Aug 2025 14:04:50 -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-107-edvmDuEcMJuJZ6GrDQULTg-1; Fri, 29 Aug 2025 14:04:44 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 BF0EE180035D; Fri, 29 Aug 2025 18:04:42 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.108]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E389119560B4; Fri, 29 Aug 2025 18:04:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1756490688; 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=/d1KbXp3NlbzRl97qpGniZuRtrRxyln2ywplCOuUaXM=; b=L432BJAiwxCgSNSnHtHyw+txycz8RutjuzV8Gv8g1sfasE5f0nz7BUZicH51EvjkioQr8N Dyq5falE9H1iQkKHdsbX/lp5oNDJD/xa7JhVzmTXzgE+9YYCrJNOfHY+NPw5eZ8BgQch3T 6UopNOTofMTKxYb+CzqIaCtBV4hyzr0= X-MC-Unique: edvmDuEcMJuJZ6GrDQULTg-1 X-Mimecast-MFC-AGG-ID: edvmDuEcMJuJZ6GrDQULTg_1756490682 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefan Weil , qemu-block@nongnu.org, Manos Pitsidianakis , "Dr. David Alan Gilbert" , Kevin Wolf , Hanna Reitz , Gerd Hoffmann , Christian Schoenebeck , Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 08/14] log: avoid prefix on split qemu_log calls Date: Fri, 29 Aug 2025 19:03:48 +0100 Message-ID: <20250829180354.2922145-9-berrange@redhat.com> In-Reply-To: <20250829180354.2922145-1-berrange@redhat.com> References: <20250829180354.2922145-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.0 on 10.30.177.12 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1756570109078116600 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. Richard Henderson Signed-off-by: Daniel P. Berrang=C3=A9 --- util/log.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/util/log.c b/util/log.c index abdcb6b311..2642a55c59 100644 --- a/util/log.c +++ b/util/log.c @@ -143,6 +143,12 @@ void qemu_log_unlock(FILE *logfile) } } =20 +/* + * 'true' if the previous log message lacked a trailing '\n', + * and thus the subsequent call must skip any prefix + */ +static __thread bool incomplete; + void qemu_log(const char *fmt, ...) { FILE *f; @@ -154,7 +160,7 @@ void qemu_log(const char *fmt, ...) * was emitted if we are delayed acquiring the * mutex */ - if (message_with_timestamp) { + if (message_with_timestamp && !incomplete) { g_autoptr(GDateTime) dt =3D g_date_time_new_now_utc(); timestr =3D g_date_time_format_iso8601(dt); } @@ -170,6 +176,7 @@ void qemu_log(const char *fmt, ...) va_start(ap, fmt); vfprintf(f, fmt, ap); va_end(ap); + incomplete =3D fmt[strlen(fmt) - 1] !=3D '\n'; qemu_log_unlock(f); } } --=20 2.50.1 From nobody Sun Sep 28 15:29:08 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=1756570100; cv=none; d=zohomail.com; s=zohoarc; b=MiqthvPJYlISilCsW/f9b/je1UuCk4kwya6WZitgt1JRNYVXRQO5SF5AN6kmtNeDbIifwolHbNL4zpWtQunDNrr53ZtE+FwmXP+Z2lk6seeGpsgDYCwghtBW1cnPuWB5ZJyQUipjWdc44ncp30isNIkrx4B0KHS0s9yWqCo/Buk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756570100; 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=jtcgiTR+hV3kOEoC/nDAryRSy1qlZZs7wPQv7aLHav4=; b=dc5QzksKiOh/qyrYjqnkZcYfWt/HEst5gP2+BNwoOBQ2x+StpKRndPjzcyI8M7NnPKUCKJl79oTHjVnqicUzBsH5f6U5QTB/hJdxwyRZBNzQwq47vEkzttcQoR6gPn7oOCtfHDPZ3+tIJ7svW5y9JtKWDOt34jsSM7ooJgDcfzs= 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 1756570100966711.3260979410038; Sat, 30 Aug 2025 09:08:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1usNaL-0001XK-9F; Sat, 30 Aug 2025 11:33:45 -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 1us3T4-0005ba-Ob for qemu-devel@nongnu.org; Fri, 29 Aug 2025 14:04:54 -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 1us3T3-0005dr-21 for qemu-devel@nongnu.org; Fri, 29 Aug 2025 14:04:54 -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-202-XGCHxwd7M1CVsGPYHpm4BA-1; Fri, 29 Aug 2025 14:04:48 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 5F01F180036E; Fri, 29 Aug 2025 18:04:47 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.108]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 301A819560B4; Fri, 29 Aug 2025 18:04:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1756490691; 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=jtcgiTR+hV3kOEoC/nDAryRSy1qlZZs7wPQv7aLHav4=; b=TIWEdjn6i3obCrsisoVL/7dUXj+umYTny/LZgzf8Qv26mkF/bqpCdUVM6/ZhHK2VN8JKsI 9mH/MzbWK6Rxtk7ywbHYcpkcHI/nocC4foULSMyU/b+MUkXNGY/Ecymp20LWXctfpYPVOm utxrH6Mk1Qvej+NxhZ4S6sVYuzlA41o= X-MC-Unique: XGCHxwd7M1CVsGPYHpm4BA-1 X-Mimecast-MFC-AGG-ID: XGCHxwd7M1CVsGPYHpm4BA_1756490687 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefan Weil , qemu-block@nongnu.org, Manos Pitsidianakis , "Dr. David Alan Gilbert" , Kevin Wolf , Hanna Reitz , Gerd Hoffmann , Christian Schoenebeck , Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 09/14] util: introduce common helper for error-report & log code Date: Fri, 29 Aug 2025 19:03:49 +0100 Message-ID: <20250829180354.2922145-10-berrange@redhat.com> In-Reply-To: <20250829180354.2922145-1-berrange@redhat.com> References: <20250829180354.2922145-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.0 on 10.30.177.12 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1756570103106116600 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. Signed-off-by: Daniel P. Berrang=C3=A9 --- MAINTAINERS | 2 ++ include/qemu/message.h | 40 ++++++++++++++++++++++++++++++++++++++++ util/meson.build | 1 + util/message.c | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+) create mode 100644 include/qemu/message.h create mode 100644 util/message.c diff --git a/MAINTAINERS b/MAINTAINERS index 8f074e4371..851d97b846 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3176,9 +3176,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..160bee8417 --- /dev/null +++ b/include/qemu/message.h @@ -0,0 +1,40 @@ +/* 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); + +enum QMessageContextFlags { + QMESSAGE_CONTEXT_SKIP_MONITOR =3D (1 << 0), +}; + +/* + * qmessage_context: + * @flags: the message formatting control flags + * + * Format a message prefix with the information + * previously selected by a call to + * qmessage_set_format. + * + * If @flags contains QMESSAGE_CONTEXT_SKIP_MONITOR + * an empty string will be returned if running in + * the context of a HMP command + * + * Returns: a formatted message prefix, or empty string; + * to be freed by the caller. + */ +char *qmessage_context(int flags); + +#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..1052a2d6aa --- /dev/null +++ b/util/message.c @@ -0,0 +1,36 @@ +/* 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; +} + +char *qmessage_context(int flags) +{ + g_autofree char *timestr =3D NULL; + + if ((flags & QMESSAGE_CONTEXT_SKIP_MONITOR) && + monitor_cur()) { + return NULL; + } + + if (message_format & QMESSAGE_FORMAT_TIMESTAMP) { + g_autoptr(GDateTime) dt =3D g_date_time_new_now_utc(); + timestr =3D g_date_time_format_iso8601(dt); + } + + if (!timestr) { + return NULL; + } + + return g_strdup_printf("%s%s", + timestr ? timestr : "", + timestr ? " " : ""); +} --=20 2.50.1 From nobody Sun Sep 28 15:29:08 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=1756572279; cv=none; d=zohomail.com; s=zohoarc; b=jAhR7uwoX6IIoiKK+NyZUPvATda1Wd8xFtGch7R5W6XsahzokQdQhv+7DDOfu/bFEz6k+QiEV5ZLv8l+rgCQFg1LB2Hg/Oo4TvKbyVpB0Rtnhb5BErHG4qaVL3iB3YEQBmowywW0QpofSUxbHe9qlUO9Ti2x454BsLYnAf6m0vA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756572279; 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=F/cobAJwGDXoAJ4ItSXx4mK66gP1Qq/p1TnARKbFAtM=; b=AEa+b3WfNznJEZNuCF0yitb0DrpfOZwrEs6hl0Fa7M0cvLnNrrkntQb2QLCndP+Ikd59Oe9lEqkNi/5XwyOYGULJqUncY0HtoetS7/6MFVW62/iUoUeGA2SJG0L3KAea1ZBeG1M6Mz9ey2AYzDy8TBxYXymh3Q2BQZZgpDGSNiY= 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 175657227939336.396084397548634; Sat, 30 Aug 2025 09:44:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1usNaO-0001sd-GA; Sat, 30 Aug 2025 11:33:48 -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 1us3TB-0005cn-WC for qemu-devel@nongnu.org; Fri, 29 Aug 2025 14:05:02 -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 1us3TA-0005gl-6J for qemu-devel@nongnu.org; Fri, 29 Aug 2025 14:05:01 -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-655-xVYzwrrmN42N4zYGB54JbA-1; Fri, 29 Aug 2025 14:04:54 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 1F88A19560A5; Fri, 29 Aug 2025 18:04:53 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.108]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EEFAB19560B4; Fri, 29 Aug 2025 18:04:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1756490698; 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=F/cobAJwGDXoAJ4ItSXx4mK66gP1Qq/p1TnARKbFAtM=; b=Remka6pqBauT4NNlHbY47UpLrGvW69vpz2G2VOEtOgL4xBgrUUYdXa7L5O8DK5BJ4zLrCA UF8fJwrIf7lax4Wt9n1qaKLdbaAvxgeAcdtZ0r9LiWxe4PeTbYQdepTS4zdR7YOHiq8xWk zgCqGHBZjcqPe4BrGitAulhU9eJZeK8= X-MC-Unique: xVYzwrrmN42N4zYGB54JbA-1 X-Mimecast-MFC-AGG-ID: xVYzwrrmN42N4zYGB54JbA_1756490693 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefan Weil , qemu-block@nongnu.org, Manos Pitsidianakis , "Dr. David Alan Gilbert" , Kevin Wolf , Hanna Reitz , Gerd Hoffmann , Christian Schoenebeck , Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 10/14] util: convert error-report & log to message API for timestamp Date: Fri, 29 Aug 2025 19:03:50 +0100 Message-ID: <20250829180354.2922145-11-berrange@redhat.com> In-Reply-To: <20250829180354.2922145-1-berrange@redhat.com> References: <20250829180354.2922145-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.0 on 10.30.177.12 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1756572282772116600 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, guaranteeign 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 --- include/qemu/error-report.h | 1 - system/vl.c | 7 ++++++- tests/unit/test-error-report.c | 3 ++- util/error-report.c | 18 ++++-------------- util/log.c | 21 +++++++++------------ 5 files changed, 21 insertions(+), 29 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 1b17c11de1..9ee164b1dd 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 @@ -169,13 +168,6 @@ static void print_loc(void) } } =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. @@ -186,12 +178,10 @@ real_time_iso8601(void) G_GNUC_PRINTF(2, 0) static void vreport(report_type type, const char *fmt, va_list ap) { - gchar *timestr; + g_autofree gchar *context =3D qmessage_context(QMESSAGE_CONTEXT_SKIP_M= ONITOR); =20 - if (message_with_timestamp && !monitor_cur()) { - timestr =3D real_time_iso8601(); - error_printf("%s ", timestr); - g_free(timestr); + if (context !=3D NULL) { + error_printf("%s", context); } =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..fc900cde0c 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" @@ -152,25 +153,21 @@ static __thread bool incomplete; 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 + * Prepare the context *outside* the logging + * lock so any timestamp 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); - } + g_autofree const char *context =3D + incomplete ? NULL : qmessage_context(0); =20 f =3D qemu_log_trylock(); if (f) { va_list ap; =20 - if (timestr) { - fprintf(f, "%s ", timestr); + if (context !=3D NULL) { + fwrite(context, 1, strlen(context), f); } =20 va_start(ap, fmt); --=20 2.50.1 From nobody Sun Sep 28 15:29:08 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=1756571753; cv=none; d=zohomail.com; s=zohoarc; b=PSmnLFI/H2eoiSpCuoQ5xUPYieSX1vG5Y00kN0hZwsMWj7yCT2NVw0KvKimVKGcH9Ezx+WHNo903s3ubbB691HQGuBd0XtAuvUWoWATJOc09ocfr71E0tjV0WKEa0bp/U1J5/bFxfYc/tC5XPuehF48nytKWGY+mW6oJCP/KcUk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756571753; 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=X2gWQlEfB4k8/uLBxq36Vz6SXee4VFCCoPQdnhFTZjc=; b=KF1q5OjczG7uttf0MqnQTXQAPNvVSFZmQJvCEnRq+vlQEfxyDVme7tegSfydLgQHHY/f11vWtjANewYQEsTVKGmTzChncASK60ELl5hGe4uEbaD69k7lAVmHSGZPdPl6TF5hXrYUecGcjrEtbFYKIvZ6SnPGqAi8PAsA9tJl+O8= 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 1756571753275539.489981010805; Sat, 30 Aug 2025 09:35:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1usNaX-0002hn-Tq; Sat, 30 Aug 2025 11:33:57 -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 1us3TK-0005eT-Uu for qemu-devel@nongnu.org; Fri, 29 Aug 2025 14:05:12 -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 1us3TE-0005ry-EL for qemu-devel@nongnu.org; Fri, 29 Aug 2025 14:05:10 -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-661-kmLqpySHNqWYUoXoCBupZw-1; Fri, 29 Aug 2025 14:05:00 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 BBB421956056; Fri, 29 Aug 2025 18:04:58 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.108]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AE7BB19560B4; Fri, 29 Aug 2025 18:04:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1756490703; 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=X2gWQlEfB4k8/uLBxq36Vz6SXee4VFCCoPQdnhFTZjc=; b=bb0LfgLG7DKwo0gUPtkevcExqvrV1XFqS3wDKWdlVkyHvu251VPqSQRkw4ziYAG3VwNyKt S94WdX4tksDggusSBw0oaUdeOTybQr1g+ds4UakvKHfYhZJlZeOi4iQ/tKeHPQJjdjFVmQ w06LEu3vw5jPnA1ogxAOD1Lk3HGVtM8= X-MC-Unique: kmLqpySHNqWYUoXoCBupZw-1 X-Mimecast-MFC-AGG-ID: kmLqpySHNqWYUoXoCBupZw_1756490698 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefan Weil , qemu-block@nongnu.org, Manos Pitsidianakis , "Dr. David Alan Gilbert" , Kevin Wolf , Hanna Reitz , Gerd Hoffmann , Christian Schoenebeck , Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 11/14] util: add support for formatting a workload name in messages Date: Fri, 29 Aug 2025 19:03:51 +0100 Message-ID: <20250829180354.2922145-12-berrange@redhat.com> In-Reply-To: <20250829180354.2922145-1-berrange@redhat.com> References: <20250829180354.2922145-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.0 on 10.30.177.12 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1756571754463116600 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 --- include/qemu/error-report.h | 3 --- include/qemu/message.h | 14 ++++++++++++-- system/vl.c | 6 ++++-- util/error-report.c | 7 ------- util/message.c | 21 ++++++++++++++++++--- 5 files changed, 34 insertions(+), 17 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 160bee8417..95fab69424 100644 --- a/include/qemu/message.h +++ b/include/qemu/message.h @@ -5,9 +5,10 @@ =20 enum QMessageFormatFlags { QMESSAGE_FORMAT_TIMESTAMP =3D (1 << 0), + QMESSAGE_FORMAT_WORKLOAD_NAME =3D (1 << 1), }; =20 -/* +/** * qmessage_set_format: * @flags: the message information to emit * @@ -16,11 +17,20 @@ 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); + enum QMessageContextFlags { QMESSAGE_CONTEXT_SKIP_MONITOR =3D (1 << 0), }; =20 -/* +/** * qmessage_context: * @flags: the message formatting control flags * 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 9ee164b1dd..37c803f69f 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 int error_printf(const char *fmt, ...) { @@ -184,11 +182,6 @@ static void vreport(report_type type, const char *fmt,= va_list ap) error_printf("%s", context); } =20 - /* Only prepend guest name if -msg guest-name and -name guest=3D... ar= e set */ - if (error_with_guestname && error_guest_name && !monitor_cur()) { - error_printf("%s ", error_guest_name); - } - print_loc(); =20 switch (type) { diff --git a/util/message.c b/util/message.c index 1052a2d6aa..0ec9a56d21 100644 --- a/util/message.c +++ b/util/message.c @@ -6,15 +6,24 @@ #include "monitor/monitor.h" =20 static int message_format; +static char *message_workloadname; =20 void qmessage_set_format(int flags) { message_format =3D flags; } =20 + +void qmessage_set_workload_name(const char *name) +{ + message_workloadname =3D g_strdup(name); +} + + char *qmessage_context(int flags) { g_autofree char *timestr =3D NULL; + const char *wknamestr =3D NULL; =20 if ((flags & QMESSAGE_CONTEXT_SKIP_MONITOR) && monitor_cur()) { @@ -26,11 +35,17 @@ char *qmessage_context(int flags) timestr =3D g_date_time_format_iso8601(dt); } =20 - if (!timestr) { + if (message_format & QMESSAGE_FORMAT_WORKLOAD_NAME) { + wknamestr =3D message_workloadname; + } + + if (!timestr && !wknamestr) { return NULL; } =20 - return g_strdup_printf("%s%s", + return g_strdup_printf("%s%s%s%s", timestr ? timestr : "", - timestr ? " " : ""); + timestr ? " " : "", + wknamestr ? wknamestr : "", + wknamestr ? " " : ""); } --=20 2.50.1 From nobody Sun Sep 28 15:29:08 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=1756570886; cv=none; d=zohomail.com; s=zohoarc; b=VM26OBxxZJXDoQ9XdiC6f7IjmY5iCEbaexJSQoMl8+HSIuA7FC7kjARhFalXd6bldTt+dncl9u2mNqGx7Fv55PhPrcdqt4MbmfIhLP6NPG2UiWxbFgO2hrav+u18HRyJoYQjJ333YtFneBz5rGz1jfUKePA+u+YqeDNi2bFb7IQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756570886; 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=ptpQoMHLmEj+E1Yc+lwarnrkVCsuSzh+kwgjJksTpG4=; b=At78aN5YPvZCNiMLOWU4ZUs8wQfbdTwDf58qpu76KAuPWPwmqhQbrVolUvfa98prUT9AguwW0BIhxntfAszHPe0xMBUG6BMunS0FArBEl/jjaw3BANnBZtJk1SUmwsHqQPhc7dHFok2qxkJjX1i+gIk7H73ZK5ZbF3OK7HojUgc= 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 1756570886522943.3590756343032; Sat, 30 Aug 2025 09:21:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1usNaa-0002sr-1b; Sat, 30 Aug 2025 11:34:00 -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 1us3TM-0005eV-2f for qemu-devel@nongnu.org; Fri, 29 Aug 2025 14:05:12 -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 1us3TJ-0005wF-SL for qemu-devel@nongnu.org; Fri, 29 Aug 2025 14:05:11 -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-499-9wpQNefVOXi_02z_mgv9kQ-1; Fri, 29 Aug 2025 14:05:05 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 F1CA21800451; Fri, 29 Aug 2025 18:05:03 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.108]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 546D019560B4; Fri, 29 Aug 2025 18:04:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1756490709; 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=ptpQoMHLmEj+E1Yc+lwarnrkVCsuSzh+kwgjJksTpG4=; b=MBm/a53oN8uhNY3FDMnwgqjfIPW9U6dFRC6x/Qh261xxp54TsmDwhBxHfC8+wO/rZFbq8+ yhoHlBJ9Mk5/uZo/1MA5zj9I8pCASUOXGOqaIJXKn++I3M7W/uehpv7eebvfgP1J/E1JVy UruJMfyKsozNpKivvHV0Nl7GY9iIks4= X-MC-Unique: 9wpQNefVOXi_02z_mgv9kQ-1 X-Mimecast-MFC-AGG-ID: 9wpQNefVOXi_02z_mgv9kQ_1756490704 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefan Weil , qemu-block@nongnu.org, Manos Pitsidianakis , "Dr. David Alan Gilbert" , Kevin Wolf , Hanna Reitz , Gerd Hoffmann , Christian Schoenebeck , Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 12/14] util: add support for formatting a program name in messages Date: Fri, 29 Aug 2025 19:03:52 +0100 Message-ID: <20250829180354.2922145-13-berrange@redhat.com> In-Reply-To: <20250829180354.2922145-1-berrange@redhat.com> References: <20250829180354.2922145-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.0 on 10.30.177.12 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1756570888078116600 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 --- include/qemu/message.h | 1 + system/vl.c | 2 +- tests/unit/test-error-report.c | 5 +++-- util/error-report.c | 4 ---- util/message.c | 15 +++++++++++---- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/include/qemu/message.h b/include/qemu/message.h index 95fab69424..4550ce8ed7 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 37c803f69f..2e58ee1c50 100644 --- a/util/error-report.c +++ b/util/error-report.c @@ -141,10 +141,6 @@ static void print_loc(void) int i; const char *const *argp; =20 - if (!monitor_cur() && g_get_prgname()) { - error_printf("%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 0ec9a56d21..cb3ffd6700 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) @@ -24,6 +24,7 @@ char *qmessage_context(int flags) { g_autofree char *timestr =3D NULL; const char *wknamestr =3D NULL; + const char *pgnamestr =3D NULL; =20 if ((flags & QMESSAGE_CONTEXT_SKIP_MONITOR) && monitor_cur()) { @@ -39,13 +40,19 @@ char *qmessage_context(int flags) wknamestr =3D message_workloadname; } =20 - if (!timestr && !wknamestr) { + if (message_format & QMESSAGE_FORMAT_PROGRAM_NAME) { + pgnamestr =3D g_get_prgname(); + } + + if (!timestr && !wknamestr && !pgnamestr) { return NULL; } =20 - return g_strdup_printf("%s%s%s%s", + return g_strdup_printf("%s%s%s%s%s%s", timestr ? timestr : "", timestr ? " " : "", wknamestr ? wknamestr : "", - wknamestr ? " " : ""); + wknamestr ? " " : "", + pgnamestr ? pgnamestr : "", + pgnamestr ? ": " : ""); } --=20 2.50.1 From nobody Sun Sep 28 15:29:08 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=1756576881; cv=none; d=zohomail.com; s=zohoarc; b=LPzyVE1mcpU1DmRdJXfmBMsCBA+KazcUHxfcmnBAkVl5yDvOenDvH7qdFCtrJdirEzWSJ1L+f8ONDb2lfK3I4CTtOBRQt4qfUv88I1QGV5tXiSw8twUIwg/05+raIdmA1Hc5Zfb7wN1awB9MKsBr05/Btg+vencEmhJgPSzdCQA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756576881; 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=DgjbyrOEn0brWKK2GHDnSTslVOsxwhRJLAenTWwHYrA=; b=AckcxHpUykIXvBcszWBAt1poADKBoD/5bQ5cUf3h3hQclduGtXtq8bPxTuEl+iPFrEC7T0MWlUGIArN9KH+rx4yyYe2osmkfSQnI2R3th2hXGQjj8ob63q7tKdp3X6PhQJS9S2/i+1fu35nK/wfnImqEpOmqHQc8OR+iOsxz3dI= 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 1756576881517657.5117577033111; Sat, 30 Aug 2025 11:01:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1usNaQ-00027g-OW; Sat, 30 Aug 2025 11:33:51 -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 1us3TQ-0005fz-UC for qemu-devel@nongnu.org; Fri, 29 Aug 2025 14:05:19 -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 1us3TP-0005yZ-33 for qemu-devel@nongnu.org; Fri, 29 Aug 2025 14:05:16 -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-636-IeRTXkO0MCu5zH4c3t5MTQ-1; Fri, 29 Aug 2025 14:05:10 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 4B6F1180034F; Fri, 29 Aug 2025 18:05:09 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.108]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8AF5719560B4; Fri, 29 Aug 2025 18:05:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1756490714; 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=DgjbyrOEn0brWKK2GHDnSTslVOsxwhRJLAenTWwHYrA=; b=Qs03drpDXG7D7RwO9kjA9RepkN0hCTPIoJpfXs+Jr24vclfEGM3JB8zALepZLQ8x5LiCyw J3L6UguOky3W9bGZXixwvWmDdHeNzZ3iaI3O9p/OhVZOAsWU5wsKOv2povBQn2CBS8mIHW znCZmuWfHEHVkRS3SuOnC/75eyrEbD0= X-MC-Unique: IeRTXkO0MCu5zH4c3t5MTQ-1 X-Mimecast-MFC-AGG-ID: IeRTXkO0MCu5zH4c3t5MTQ_1756490709 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefan Weil , qemu-block@nongnu.org, Manos Pitsidianakis , "Dr. David Alan Gilbert" , Kevin Wolf , Hanna Reitz , Gerd Hoffmann , Christian Schoenebeck , Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 13/14] util: add support for formatting thread info in messages Date: Fri, 29 Aug 2025 19:03:53 +0100 Message-ID: <20250829180354.2922145-14-berrange@redhat.com> In-Reply-To: <20250829180354.2922145-1-berrange@redhat.com> References: <20250829180354.2922145-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.0 on 10.30.177.12 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1756576884081116600 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 | 33 +++++++++++++++++++--------- 6 files changed, 38 insertions(+), 14 deletions(-) diff --git a/include/qemu/message.h b/include/qemu/message.h index 4550ce8ed7..6dbb068ca9 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..d9954da42b 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\(.*\): ' % os.path.basename(iotests.qemu_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..ecf74c223e 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)(.*):#\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 cb3ffd6700..5201ffc569 100644 --- a/util/message.c +++ b/util/message.c @@ -44,15 +44,28 @@ char *qmessage_context(int flags) pgnamestr =3D g_get_prgname(); } =20 - if (!timestr && !wknamestr && !pgnamestr) { - return NULL; - } + if (message_format & QMESSAGE_FORMAT_THREAD_INFO) { + int thid =3D qemu_get_thread_id(); + const char *thname =3D qemu_thread_get_name(); =20 - return g_strdup_printf("%s%s%s%s%s%s", - timestr ? timestr : "", - timestr ? " " : "", - wknamestr ? wknamestr : "", - wknamestr ? " " : "", - pgnamestr ? pgnamestr : "", - pgnamestr ? ": " : ""); + return g_strdup_printf("%s%s%s%s%s(%d:%s): ", + timestr ? timestr : "", + timestr ? " " : "", + wknamestr ? wknamestr : "", + wknamestr ? " " : "", + pgnamestr ? pgnamestr : "", + thid, thname); + } else { + if (!timestr && !wknamestr && !pgnamestr) { + return NULL; + } + + return g_strdup_printf("%s%s%s%s%s%s", + timestr ? timestr : "", + timestr ? " " : "", + wknamestr ? wknamestr : "", + wknamestr ? " " : "", + pgnamestr ? pgnamestr : "", + pgnamestr ? ": " : ""); + } } --=20 2.50.1 From nobody Sun Sep 28 15:29:08 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=1756572978; cv=none; d=zohomail.com; s=zohoarc; b=SvnXDy+uhldHnYA8Rg+c6r++Atm7B2hsPrmI0+EgKndS0M2bViQ/6ZoulIRzRArlX7ioYj5NjB5Xz0qbXT2j2XxdlEAhq0GRHpEJG29TrUAVb7TIMxr8U1t4Y5IMGza84Z2ktLSfSr+UznBivFAyUnPXp1WpiFU0LcwuEgh3tyg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756572978; 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=hFnegfN+ZJEFrktf/Xt9S8f7de5z0ix1bAkH/iyhqK8=; b=e5wQVe9OaBVxmuX8to9BeIesT0AKKzsfy8g9YasyJJ53y0iTcSJBsGEfpzLKbXyu62RAG5sixede4eClQ6UJ2REUPfHZq2ePgd1PFQnCbQkvoi7jRAEXKTF86cV4DCsyLPJxNGRgKSqa7Xuj+VPbaHMyS+8DOKD1ldquvTHvoDc= 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 1756572977997860.5938837640072; Sat, 30 Aug 2025 09:56:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1usNaW-0002d4-Io; Sat, 30 Aug 2025 11:33:56 -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 1us3TX-0005hG-9J for qemu-devel@nongnu.org; Fri, 29 Aug 2025 14:05:24 -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 1us3TU-00060C-Aa for qemu-devel@nongnu.org; Fri, 29 Aug 2025 14:05:22 -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-A27-3dUVOTC3WsdXfTbViQ-1; Fri, 29 Aug 2025 14:05:15 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 35F43195609F; Fri, 29 Aug 2025 18:05:14 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.108]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DA5ED19560BC; Fri, 29 Aug 2025 18:05:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1756490719; 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=hFnegfN+ZJEFrktf/Xt9S8f7de5z0ix1bAkH/iyhqK8=; b=KAEVVkwqEW3o+2dSNxWKbbV9Q5GY5R32nIY2E/E8DhnbV2qx3bB0H0b00DxOfxjXrewCZu 0r6kaJowJ0/KidKA+46TZjDGShEUom2JzDt8ufCHdoDtZB0Zy1ae4Vhk04emLqDvJg4qES J5k7vee7ovhOm3E9qV5Z+hNBTfnBzo8= X-MC-Unique: A27-3dUVOTC3WsdXfTbViQ-1 X-Mimecast-MFC-AGG-ID: A27-3dUVOTC3WsdXfTbViQ_1756490714 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefan Weil , qemu-block@nongnu.org, Manos Pitsidianakis , "Dr. David Alan Gilbert" , Kevin Wolf , Hanna Reitz , Gerd Hoffmann , Christian Schoenebeck , Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 14/14] util: add brackets around guest name in message context Date: Fri, 29 Aug 2025 19:03:54 +0100 Message-ID: <20250829180354.2922145-15-berrange@redhat.com> In-Reply-To: <20250829180354.2922145-1-berrange@redhat.com> References: <20250829180354.2922145-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.0 on 10.30.177.12 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1756572979588124100 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 --- util/message.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/util/message.c b/util/message.c index 5201ffc569..6d3580b7be 100644 --- a/util/message.c +++ b/util/message.c @@ -48,11 +48,12 @@ char *qmessage_context(int flags) int thid =3D qemu_get_thread_id(); const char *thname =3D qemu_thread_get_name(); =20 - return g_strdup_printf("%s%s%s%s%s(%d:%s): ", + return g_strdup_printf("%s%s%s%s%s%s(%d:%s): ", timestr ? timestr : "", timestr ? " " : "", + wknamestr ? "[" : "", wknamestr ? wknamestr : "", - wknamestr ? " " : "", + wknamestr ? "] " : "", pgnamestr ? pgnamestr : "", thid, thname); } else { @@ -60,11 +61,12 @@ char *qmessage_context(int flags) return NULL; } =20 - return g_strdup_printf("%s%s%s%s%s%s", + return g_strdup_printf("%s%s%s%s%s%s%s", timestr ? timestr : "", timestr ? " " : "", + wknamestr ? "[" : "", wknamestr ? wknamestr : "", - wknamestr ? " " : "", + wknamestr ? "] " : "", pgnamestr ? pgnamestr : "", pgnamestr ? ": " : ""); } --=20 2.50.1