From patchwork Thu Jun 16 12:40:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1644327 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Za9gzlDW; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LP2XD5h9kz9sGC for ; Thu, 16 Jun 2022 23:07:40 +1000 (AEST) Received: from localhost ([::1]:42614 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1pDm-0004HJ-Eu for incoming@patchwork.ozlabs.org; Thu, 16 Jun 2022 09:07:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41762) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1ooN-0001Cf-MI for qemu-devel@nongnu.org; Thu, 16 Jun 2022 08:41:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:48629) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1ont-0005FQ-VJ for qemu-devel@nongnu.org; Thu, 16 Jun 2022 08:41:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655383248; 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=fy92f6kQJ5+uPC2RTOYG/PSXahPriSC+sovWZGw5Ewk=; b=Za9gzlDW0MaUJ75Kn2oKlJHwZcJrhTWC181kC7kIMja23zuS8AhBAZC/cPhChXjLDDr4I5 kk+rIbznBybMPGkHNBKhMFYaL1yOc9wO9b1IPefCvgjquZAmKhMoaVxYrAHqcBfgkCZDAY eXrptQz9UEnv5yetWaDNFNdgNORSB8E= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-437-eOuc_wz5N4OnmteMfPfewA-1; Thu, 16 Jun 2022 08:40:44 -0400 X-MC-Unique: eOuc_wz5N4OnmteMfPfewA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2F94B833976; Thu, 16 Jun 2022 12:40:44 +0000 (UTC) Received: from localhost (unknown [10.39.208.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 47B811415107; Thu, 16 Jun 2022 12:40:42 +0000 (UTC) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Markus Armbruster , Michael Roth , Kevin Wolf , Laurent Vivier , Warner Losh , Kyle Evans , Hanna Reitz , Vladimir Sementsov-Ogievskiy , Fam Zheng , Eric Blake , "Dr. David Alan Gilbert" , Paolo Bonzini , qemu-block@nongnu.org, =?utf-8?q?Marc-?= =?utf-8?q?Andr=C3=A9_Lureau?= Subject: [PATCH 1/9] monitor: make error_vprintf_unless_qmp() static Date: Thu, 16 Jun 2022 16:40:26 +0400 Message-Id: <20220616124034.3381391-2-marcandre.lureau@redhat.com> In-Reply-To: <20220616124034.3381391-1-marcandre.lureau@redhat.com> References: <20220616124034.3381391-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_HELO_TEMPERROR=0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Marc-André Lureau Not needed outside monitor.c. Remove the needless stub. Signed-off-by: Marc-André Lureau --- include/monitor/monitor.h | 1 - monitor/monitor.c | 3 ++- stubs/error-printf.c | 5 ----- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index a4b40e8391db..44653e195b45 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -56,7 +56,6 @@ void monitor_register_hmp(const char *name, bool info, void monitor_register_hmp_info_hrt(const char *name, HumanReadableText *(*handler)(Error **errp)); -int error_vprintf_unless_qmp(const char *fmt, va_list ap) G_GNUC_PRINTF(1, 0); int error_printf_unless_qmp(const char *fmt, ...) G_GNUC_PRINTF(1, 2); #endif /* MONITOR_H */ diff --git a/monitor/monitor.c b/monitor/monitor.c index 86949024f643..ba4c1716a48a 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -273,7 +273,8 @@ int error_vprintf(const char *fmt, va_list ap) return vfprintf(stderr, fmt, ap); } -int error_vprintf_unless_qmp(const char *fmt, va_list ap) +G_GNUC_PRINTF(1, 0) +static int error_vprintf_unless_qmp(const char *fmt, va_list ap) { Monitor *cur_mon = monitor_cur(); diff --git a/stubs/error-printf.c b/stubs/error-printf.c index 0e326d801059..1afa0f62ca26 100644 --- a/stubs/error-printf.c +++ b/stubs/error-printf.c @@ -16,8 +16,3 @@ int error_vprintf(const char *fmt, va_list ap) } return vfprintf(stderr, fmt, ap); } - -int error_vprintf_unless_qmp(const char *fmt, va_list ap) -{ - return error_vprintf(fmt, ap); -} From patchwork Thu Jun 16 12:40:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1644324 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=b+efhreU; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LP2KT5dw1z9sGC for ; Thu, 16 Jun 2022 22:58:21 +1000 (AEST) Received: from localhost ([::1]:59622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1p4k-0004Y2-Lf for incoming@patchwork.ozlabs.org; Thu, 16 Jun 2022 08:58:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41770) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1ooN-0001Cj-NG for qemu-devel@nongnu.org; Thu, 16 Jun 2022 08:41:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:30161) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1onu-0005Fd-JM for qemu-devel@nongnu.org; Thu, 16 Jun 2022 08:41:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655383252; 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=mhY9PsABRcMLJF+tV+NJTVZCNMbp0QjCFVmkIu3F/XI=; b=b+efhreUPkhbDs60MW3QWnGmTXtAhOS65BSSv5NPj1aqvyOsSXZwJav4YcaqlXwTyaQqVF TT2kaL7faQF4rALHQCwONaqI1prbSug2XiAqUxM4ZH7THZSe+RWCe7SnLP73bDZ6eIAVkm 98cldX8WwYm1WiJlCWCvdG3XRk+Aai4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-650-EvbRXGxEP7i5lJzk7SWXVg-1; Thu, 16 Jun 2022 08:40:49 -0400 X-MC-Unique: EvbRXGxEP7i5lJzk7SWXVg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 91685185A7BA; Thu, 16 Jun 2022 12:40:48 +0000 (UTC) Received: from localhost (unknown [10.39.208.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5DE5C40C141F; Thu, 16 Jun 2022 12:40:47 +0000 (UTC) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Markus Armbruster , Michael Roth , Kevin Wolf , Laurent Vivier , Warner Losh , Kyle Evans , Hanna Reitz , Vladimir Sementsov-Ogievskiy , Fam Zheng , Eric Blake , "Dr. David Alan Gilbert" , Paolo Bonzini , qemu-block@nongnu.org, =?utf-8?q?Marc-?= =?utf-8?q?Andr=C3=A9_Lureau?= Subject: [PATCH 2/9] error-report: misc comment fix Date: Thu, 16 Jun 2022 16:40:27 +0400 Message-Id: <20220616124034.3381391-3-marcandre.lureau@redhat.com> In-Reply-To: <20220616124034.3381391-1-marcandre.lureau@redhat.com> References: <20220616124034.3381391-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_HELO_TEMPERROR=0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Marc-André Lureau Signed-off-by: Marc-André Lureau Reviewed-by: Markus Armbruster --- util/error-report.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/error-report.c b/util/error-report.c index 5edb2e604061..98f242b75bbf 100644 --- a/util/error-report.c +++ b/util/error-report.c @@ -390,7 +390,7 @@ void error_init(const char *argv0) { const char *p = strrchr(argv0, '/'); - /* Set the program name for error_print_loc(). */ + /* Set the program name for print_loc(). */ g_set_prgname(p ? p + 1 : argv0); /* From patchwork Thu Jun 16 12:40:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1644322 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=FzmpCtuj; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LP2Cr0fMkz9sG2 for ; Thu, 16 Jun 2022 22:53:26 +1000 (AEST) Received: from localhost ([::1]:51096 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1ozz-00072b-4d for incoming@patchwork.ozlabs.org; Thu, 16 Jun 2022 08:53:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41748) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1ooL-0001CR-0g for qemu-devel@nongnu.org; Thu, 16 Jun 2022 08:41:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:60460) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1oo7-0005Pb-Gn for qemu-devel@nongnu.org; Thu, 16 Jun 2022 08:41:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655383265; 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=rzIBgNsKYpHaLR13PS2PpWp9q632APSC+dXPHpCH13g=; b=FzmpCtujp4CT/MZpfFSpRLtF3Vfi/mgztJ44f1gfSen7XILh6B6i5JihtNOiLZB/teI4p3 N9Fp0J5SXaa5i6glWk79n/4e985NVi3BqId+6qRV2zAVJ2KqPhmZrlN1vBqoSoNrXb1wnc Vl+N9f2qvxSVBSq5a7a9DDjudVzKisg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-457-0Sap0AJEMF-yI9fy4sosfA-1; Thu, 16 Jun 2022 08:40:54 -0400 X-MC-Unique: 0Sap0AJEMF-yI9fy4sosfA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 50F80802D1F; Thu, 16 Jun 2022 12:40:54 +0000 (UTC) Received: from localhost (unknown [10.39.208.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1548A492CA5; Thu, 16 Jun 2022 12:40:52 +0000 (UTC) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Markus Armbruster , Michael Roth , Kevin Wolf , Laurent Vivier , Warner Losh , Kyle Evans , Hanna Reitz , Vladimir Sementsov-Ogievskiy , Fam Zheng , Eric Blake , "Dr. David Alan Gilbert" , Paolo Bonzini , qemu-block@nongnu.org, =?utf-8?q?Marc-?= =?utf-8?q?Andr=C3=A9_Lureau?= Subject: [PATCH 3/9] error-report: introduce "detailed" variable Date: Thu, 16 Jun 2022 16:40:28 +0400 Message-Id: <20220616124034.3381391-4-marcandre.lureau@redhat.com> In-Reply-To: <20220616124034.3381391-1-marcandre.lureau@redhat.com> References: <20220616124034.3381391-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Marc-André Lureau Let's use a more explicit variable "detailed" instead of calling monitor_cur() multiple times. Signed-off-by: Marc-André Lureau Reviewed-by: Markus Armbruster --- util/error-report.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/util/error-report.c b/util/error-report.c index 98f242b75bbf..893da10f19bc 100644 --- a/util/error-report.c +++ b/util/error-report.c @@ -195,16 +195,17 @@ real_time_iso8601(void) */ static void vreport(report_type type, const char *fmt, va_list ap) { + bool detailed = !monitor_cur(); gchar *timestr; - if (message_with_timestamp && !monitor_cur()) { + if (message_with_timestamp && detailed) { timestr = real_time_iso8601(); error_printf("%s ", timestr); g_free(timestr); } /* Only prepend guest name if -msg guest-name and -name guest=... are set */ - if (error_with_guestname && error_guest_name && !monitor_cur()) { + if (error_with_guestname && error_guest_name && detailed) { error_printf("%s ", error_guest_name); } From patchwork Thu Jun 16 12:40:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1644323 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=BdWtmv09; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LP2Cr4WV5z9sGF for ; Thu, 16 Jun 2022 22:53:28 +1000 (AEST) Received: from localhost ([::1]:51128 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1p02-00073z-0Z for incoming@patchwork.ozlabs.org; Thu, 16 Jun 2022 08:53:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41786) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1ooO-0001Cq-E7 for qemu-devel@nongnu.org; Thu, 16 Jun 2022 08:41:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:42974) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1oo5-0005P7-N7 for qemu-devel@nongnu.org; Thu, 16 Jun 2022 08:41:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655383263; 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=1o27EBUfNWT2QpBtPZu+Zc5UCpj4z+bwGHt6RXKOyfU=; b=BdWtmv09avGtKvJzZ7XECsu/Zi/SuNZshsMwURS4THsguWuHYsiZPvtvstB+ghEVnjuwuz 6yClNDYaWlvWv8ywQY/FGqDiNd8drQCV5xTNYN1qy518wwP5VPgfTZRZEeaZGbFXdRiZki hp3LB3IEjtpRo7GfvJWu4BWwrff/DHs= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-178-HahSN54VO6i1XBLDQsxNdQ-1; Thu, 16 Jun 2022 08:40:59 -0400 X-MC-Unique: HahSN54VO6i1XBLDQsxNdQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CDA771C1C1A9; Thu, 16 Jun 2022 12:40:58 +0000 (UTC) Received: from localhost (unknown [10.39.208.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id C2EB92166B26; Thu, 16 Jun 2022 12:40:57 +0000 (UTC) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Markus Armbruster , Michael Roth , Kevin Wolf , Laurent Vivier , Warner Losh , Kyle Evans , Hanna Reitz , Vladimir Sementsov-Ogievskiy , Fam Zheng , Eric Blake , "Dr. David Alan Gilbert" , Paolo Bonzini , qemu-block@nongnu.org, =?utf-8?q?Marc-?= =?utf-8?q?Andr=C3=A9_Lureau?= Subject: [PATCH 4/9] error-report: simplify print_loc() Date: Thu, 16 Jun 2022 16:40:29 +0400 Message-Id: <20220616124034.3381391-5-marcandre.lureau@redhat.com> In-Reply-To: <20220616124034.3381391-1-marcandre.lureau@redhat.com> References: <20220616124034.3381391-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Marc-André Lureau Pass the program name as "prefix" argument to print_loc() if printing with "details". This allows to get rid of monitor_cur() call in print_loc(). Signed-off-by: Marc-André Lureau Reviewed-by: Markus Armbruster --- util/error-report.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/util/error-report.c b/util/error-report.c index 893da10f19bc..c43227a975e2 100644 --- a/util/error-report.c +++ b/util/error-report.c @@ -138,14 +138,14 @@ void loc_set_file(const char *fname, int lno) /* * Print current location to current monitor if we have one, else to stderr. */ -static void print_loc(void) +static void print_loc(const char *prefix) { const char *sep = ""; int i; const char *const *argp; - if (!monitor_cur() && g_get_prgname()) { - error_printf("%s:", g_get_prgname()); + if (prefix) { + error_printf("%s:", prefix); sep = " "; } switch (cur_loc->kind) { @@ -209,7 +209,7 @@ static void vreport(report_type type, const char *fmt, va_list ap) error_printf("%s ", error_guest_name); } - print_loc(); + print_loc(detailed ? g_get_prgname() : NULL); switch (type) { case REPORT_TYPE_ERROR: From patchwork Thu Jun 16 12:40:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1644331 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=LmBqBOtX; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LP2gv62ZMz9sGC for ; Thu, 16 Jun 2022 23:14:19 +1000 (AEST) Received: from localhost ([::1]:32888 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1pKD-0008Um-Ge for incoming@patchwork.ozlabs.org; Thu, 16 Jun 2022 09:14:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41870) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1ooW-0001R0-By for qemu-devel@nongnu.org; Thu, 16 Jun 2022 08:41:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:55687) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1ooM-0005Vw-Hp for qemu-devel@nongnu.org; Thu, 16 Jun 2022 08:41:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655383275; 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=LJXySoeq0t7JZM5RA/pyaMohMd2V1GfWM/4dE5+QpiU=; b=LmBqBOtXLfTkxsSJevkFoxCVDacIaRYYvLHKoyl/9dPP6q0RxWayY78MaTKdGYpbgLALQc 0VxfxvoNsrSmZXJ93UFswSVt5J5RpAnc2ucV/zOJ5gOG6K4MDP9EVvvN65fsrTM3cfq48h +pZX8YfVZAcgPR2VoHfGfC9rSu/8oUg= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-440--GFDmYZlPrivwdr_DbXIcg-1; Thu, 16 Jun 2022 08:41:04 -0400 X-MC-Unique: -GFDmYZlPrivwdr_DbXIcg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F3CCC29DD98A; Thu, 16 Jun 2022 12:41:03 +0000 (UTC) Received: from localhost (unknown [10.39.208.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 86B17492CA8; Thu, 16 Jun 2022 12:41:02 +0000 (UTC) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Markus Armbruster , Michael Roth , Kevin Wolf , Laurent Vivier , Warner Losh , Kyle Evans , Hanna Reitz , Vladimir Sementsov-Ogievskiy , Fam Zheng , Eric Blake , "Dr. David Alan Gilbert" , Paolo Bonzini , qemu-block@nongnu.org, =?utf-8?q?Marc-?= =?utf-8?q?Andr=C3=A9_Lureau?= Subject: [PATCH 5/9] error-report: introduce ErrorReportDetailedFunc Date: Thu, 16 Jun 2022 16:40:30 +0400 Message-Id: <20220616124034.3381391-6-marcandre.lureau@redhat.com> In-Reply-To: <20220616124034.3381391-1-marcandre.lureau@redhat.com> References: <20220616124034.3381391-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Marc-André Lureau Remove monitor dependency from error printing code, by allowing programs to set a callback for when to use "detailed" reporting or not. Signed-off-by: Marc-André Lureau Reviewed-by: Warner Losh --- include/qemu/error-report.h | 4 +++- bsd-user/main.c | 2 +- linux-user/main.c | 2 +- qemu-img.c | 2 +- qemu-io.c | 2 +- qemu-nbd.c | 2 +- scsi/qemu-pr-helper.c | 2 +- softmmu/vl.c | 7 ++++++- storage-daemon/qemu-storage-daemon.c | 7 ++++++- util/error-report.c | 8 +++++--- 10 files changed, 26 insertions(+), 12 deletions(-) diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h index 3ae2357fda54..e2e630f207f0 100644 --- a/include/qemu/error-report.h +++ b/include/qemu/error-report.h @@ -13,6 +13,8 @@ #ifndef QEMU_ERROR_REPORT_H #define QEMU_ERROR_REPORT_H +typedef bool (*ErrorReportDetailedFunc)(void); + typedef struct Location { /* all members are private to qemu-error.c */ enum { LOC_NONE, LOC_CMDLINE, LOC_FILE } kind; @@ -46,7 +48,7 @@ bool error_report_once_cond(bool *printed, const char *fmt, ...) bool warn_report_once_cond(bool *printed, const char *fmt, ...) G_GNUC_PRINTF(2, 3); -void error_init(const char *argv0); +void error_init(const char *argv0, ErrorReportDetailedFunc detailed_fn); /* * Similar to error_report(), except it prints the message just once. diff --git a/bsd-user/main.c b/bsd-user/main.c index 6f09180d6541..d5f8fca863d7 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -292,7 +292,7 @@ int main(int argc, char **argv) save_proc_pathname(argv[0]); - error_init(argv[0]); + error_init(argv[0], NULL); module_call_init(MODULE_INIT_TRACE); qemu_init_cpu_list(); module_call_init(MODULE_INIT_QOM); diff --git a/linux-user/main.c b/linux-user/main.c index 651e32f5f248..84f380bd366d 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -646,7 +646,7 @@ int main(int argc, char **argv, char **envp) unsigned long max_reserved_va; bool preserve_argv0; - error_init(argv[0]); + error_init(argv[0], NULL); module_call_init(MODULE_INIT_TRACE); qemu_init_cpu_list(); module_call_init(MODULE_INIT_QOM); diff --git a/qemu-img.c b/qemu-img.c index 4cf4d2423df8..1f27a9fc70f6 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -5396,7 +5396,7 @@ int main(int argc, char **argv) #endif socket_init(); - error_init(argv[0]); + error_init(argv[0], NULL); module_call_init(MODULE_INIT_TRACE); qemu_init_exec_dir(argv[0]); diff --git a/qemu-io.c b/qemu-io.c index 2bd7bfb65073..b5cdc7c922a7 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -539,7 +539,7 @@ int main(int argc, char **argv) #endif socket_init(); - error_init(argv[0]); + error_init(argv[0], NULL); module_call_init(MODULE_INIT_TRACE); qemu_init_exec_dir(argv[0]); diff --git a/qemu-nbd.c b/qemu-nbd.c index 0cd5aa6f02bc..6bc632c93611 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -587,7 +587,7 @@ int main(int argc, char **argv) #endif socket_init(); - error_init(argv[0]); + error_init(argv[0], NULL); module_call_init(MODULE_INIT_TRACE); qcrypto_init(&error_fatal); diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c index 196b78c00df5..8d80e58d4498 100644 --- a/scsi/qemu-pr-helper.c +++ b/scsi/qemu-pr-helper.c @@ -910,7 +910,7 @@ int main(int argc, char **argv) signal(SIGPIPE, SIG_IGN); - error_init(argv[0]); + error_init(argv[0], NULL); module_call_init(MODULE_INIT_TRACE); module_call_init(MODULE_INIT_QOM); qemu_add_opts(&qemu_trace_opts); diff --git a/softmmu/vl.c b/softmmu/vl.c index 54e920ada1a1..3b46fc9c1fc5 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -2590,6 +2590,11 @@ void qmp_x_exit_preconfig(Error **errp) } } +static bool error_is_detailed(void) +{ + return !monitor_cur(); +} + void qemu_init(int argc, char **argv, char **envp) { QemuOpts *opts; @@ -2634,7 +2639,7 @@ void qemu_init(int argc, char **argv, char **envp) qemu_add_opts(&qemu_action_opts); module_call_init(MODULE_INIT_OPTS); - error_init(argv[0]); + error_init(argv[0], error_is_detailed); qemu_init_exec_dir(argv[0]); qemu_init_arch_modules(); diff --git a/storage-daemon/qemu-storage-daemon.c b/storage-daemon/qemu-storage-daemon.c index c104817cdddc..7e4d5030a045 100644 --- a/storage-daemon/qemu-storage-daemon.c +++ b/storage-daemon/qemu-storage-daemon.c @@ -368,13 +368,18 @@ static void pid_file_init(void) atexit(pid_file_cleanup); } +static bool error_is_detailed(void) +{ + return !monitor_cur(); +} + int main(int argc, char *argv[]) { #ifdef CONFIG_POSIX signal(SIGPIPE, SIG_IGN); #endif - error_init(argv[0]); + error_init(argv[0], error_is_detailed); qemu_init_exec_dir(argv[0]); os_setup_signal_handling(); diff --git a/util/error-report.c b/util/error-report.c index c43227a975e2..c2181f80a83d 100644 --- a/util/error-report.c +++ b/util/error-report.c @@ -11,7 +11,6 @@ */ #include "qemu/osdep.h" -#include "monitor/monitor.h" #include "qemu/error-report.h" /* @@ -28,6 +27,7 @@ typedef enum { bool message_with_timestamp; bool error_with_guestname; const char *error_guest_name; +ErrorReportDetailedFunc detailed_fn = NULL; int error_printf(const char *fmt, ...) { @@ -195,7 +195,7 @@ real_time_iso8601(void) */ static void vreport(report_type type, const char *fmt, va_list ap) { - bool detailed = !monitor_cur(); + bool detailed = detailed_fn ? detailed_fn() : TRUE; gchar *timestr; if (message_with_timestamp && detailed) { @@ -387,7 +387,7 @@ static void qemu_log_func(const gchar *log_domain, } } -void error_init(const char *argv0) +void error_init(const char *argv0, ErrorReportDetailedFunc detailed) { const char *p = strrchr(argv0, '/'); @@ -401,4 +401,6 @@ void error_init(const char *argv0) g_log_set_default_handler(qemu_log_func, NULL); g_warn_if_fail(qemu_glog_domains == NULL); qemu_glog_domains = g_strdup(g_getenv("G_MESSAGES_DEBUG")); + + detailed_fn = detailed; } From patchwork Thu Jun 16 12:40:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1644330 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=TK3+8Mqo; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LP2dN4vcVz9sGC for ; Thu, 16 Jun 2022 23:12:08 +1000 (AEST) Received: from localhost ([::1]:53292 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1pI6-00038Q-At for incoming@patchwork.ozlabs.org; Thu, 16 Jun 2022 09:12:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41812) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1ooT-0001Kq-M5 for qemu-devel@nongnu.org; Thu, 16 Jun 2022 08:41:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:39623) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1ooK-0005Yp-6h for qemu-devel@nongnu.org; Thu, 16 Jun 2022 08:41:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655383277; 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=w4voxXrKbyhL/lOz9FRDmaZJ++LuTFoliK+/VyoayUo=; b=TK3+8MqopHrh8z27Kcmg4LuXJwim5N/4aHN2+4+sMCMaNSkdB+Xzu79/Tz7KawieuA2dJV +909asxmflm5i1GMC9DpFynXvFUwDDZ3ZibueEOXojK1rdC5Eonck9Dl+bRRolgW2ApRIj fbZf09QJc7YxWukecY822FYLk237xX0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-574-Xn-lT_swMpOT305bRNzjOw-1; Thu, 16 Jun 2022 08:41:11 -0400 X-MC-Unique: Xn-lT_swMpOT305bRNzjOw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E1F1D833976; Thu, 16 Jun 2022 12:41:10 +0000 (UTC) Received: from localhost (unknown [10.39.208.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2235D492CA5; Thu, 16 Jun 2022 12:41:07 +0000 (UTC) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Markus Armbruster , Michael Roth , Kevin Wolf , Laurent Vivier , Warner Losh , Kyle Evans , Hanna Reitz , Vladimir Sementsov-Ogievskiy , Fam Zheng , Eric Blake , "Dr. David Alan Gilbert" , Paolo Bonzini , qemu-block@nongnu.org, =?utf-8?q?Marc-?= =?utf-8?q?Andr=C3=A9_Lureau?= Subject: [PATCH 6/9] error-report: add a callback to overwrite error_vprintf Date: Thu, 16 Jun 2022 16:40:31 +0400 Message-Id: <20220616124034.3381391-7-marcandre.lureau@redhat.com> In-Reply-To: <20220616124034.3381391-1-marcandre.lureau@redhat.com> References: <20220616124034.3381391-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_HELO_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Marc-André Lureau error_vprintf() is implemented in monitor.c, which overrides the default implementation from stubs/, while avoiding a direct dependency to the monitor from error-report.c. However, the stub solution isn't working when moving error-report.c and stubs/error-printf.c in a common library. Linking with such library creates conflicts for the error_vprintf() implementations (and weak symbols aren't great either). Instead, use the "traditional" approach to provide overidable callbacks. Signed-off-by: Marc-André Lureau --- include/monitor/monitor.h | 1 + include/qemu/error-report.h | 6 ++++-- bsd-user/main.c | 2 +- linux-user/main.c | 2 +- monitor/monitor.c | 2 +- qemu-img.c | 2 +- qemu-io.c | 2 +- qemu-nbd.c | 2 +- scsi/qemu-pr-helper.c | 2 +- softmmu/vl.c | 2 +- storage-daemon/qemu-storage-daemon.c | 2 +- stubs/error-printf.c | 18 ------------------ util/error-report.c | 27 ++++++++++++++++++++++++--- stubs/meson.build | 1 - 14 files changed, 38 insertions(+), 33 deletions(-) delete mode 100644 stubs/error-printf.c diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index 44653e195b45..e94ab2e74889 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -16,6 +16,7 @@ extern QemuOptsList qemu_mon_opts; Monitor *monitor_cur(void); Monitor *monitor_set_cur(Coroutine *co, Monitor *mon); bool monitor_cur_is_qmp(void); +int monitor_error_vprintf(const char *fmt, va_list ap); void monitor_init_globals(void); void monitor_init_globals_core(void); diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h index e2e630f207f0..a2bc030b4bfe 100644 --- a/include/qemu/error-report.h +++ b/include/qemu/error-report.h @@ -14,6 +14,7 @@ #define QEMU_ERROR_REPORT_H typedef bool (*ErrorReportDetailedFunc)(void); +typedef int (*ErrorReportVPrintfFunc)(const char *fmt, va_list ap) G_GNUC_PRINTF(1, 0); typedef struct Location { /* all members are private to qemu-error.c */ @@ -32,7 +33,6 @@ void loc_set_none(void); void loc_set_cmdline(char **argv, int idx, int cnt); void loc_set_file(const char *fname, int lno); -int error_vprintf(const char *fmt, va_list ap) G_GNUC_PRINTF(1, 0); int error_printf(const char *fmt, ...) G_GNUC_PRINTF(1, 2); void error_vreport(const char *fmt, va_list ap) G_GNUC_PRINTF(1, 0); @@ -48,7 +48,9 @@ bool error_report_once_cond(bool *printed, const char *fmt, ...) bool warn_report_once_cond(bool *printed, const char *fmt, ...) G_GNUC_PRINTF(2, 3); -void error_init(const char *argv0, ErrorReportDetailedFunc detailed_fn); +void error_init(const char *argv0, + ErrorReportDetailedFunc detailed_fn, + ErrorReportVPrintfFunc vprintf_fn); /* * Similar to error_report(), except it prints the message just once. diff --git a/bsd-user/main.c b/bsd-user/main.c index d5f8fca863d7..1cc1ba9b2e6e 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -292,7 +292,7 @@ int main(int argc, char **argv) save_proc_pathname(argv[0]); - error_init(argv[0], NULL); + error_init(argv[0], NULL, NULL); module_call_init(MODULE_INIT_TRACE); qemu_init_cpu_list(); module_call_init(MODULE_INIT_QOM); diff --git a/linux-user/main.c b/linux-user/main.c index 84f380bd366d..75f72099739d 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -646,7 +646,7 @@ int main(int argc, char **argv, char **envp) unsigned long max_reserved_va; bool preserve_argv0; - error_init(argv[0], NULL); + error_init(argv[0], NULL, NULL); module_call_init(MODULE_INIT_TRACE); qemu_init_cpu_list(); module_call_init(MODULE_INIT_QOM); diff --git a/monitor/monitor.c b/monitor/monitor.c index ba4c1716a48a..490e7babd895 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -263,7 +263,7 @@ int monitor_printf(Monitor *mon, const char *fmt, ...) /* * Print to current monitor if we have one, else to stderr. */ -int error_vprintf(const char *fmt, va_list ap) +int monitor_error_vprintf(const char *fmt, va_list ap) { Monitor *cur_mon = monitor_cur(); diff --git a/qemu-img.c b/qemu-img.c index 1f27a9fc70f6..00383f48f7bc 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -5396,7 +5396,7 @@ int main(int argc, char **argv) #endif socket_init(); - error_init(argv[0], NULL); + error_init(argv[0], NULL, NULL); module_call_init(MODULE_INIT_TRACE); qemu_init_exec_dir(argv[0]); diff --git a/qemu-io.c b/qemu-io.c index b5cdc7c922a7..09794cd781be 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -539,7 +539,7 @@ int main(int argc, char **argv) #endif socket_init(); - error_init(argv[0], NULL); + error_init(argv[0], NULL, NULL); module_call_init(MODULE_INIT_TRACE); qemu_init_exec_dir(argv[0]); diff --git a/qemu-nbd.c b/qemu-nbd.c index 6bc632c93611..112303674cfb 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -587,7 +587,7 @@ int main(int argc, char **argv) #endif socket_init(); - error_init(argv[0], NULL); + error_init(argv[0], NULL, NULL); module_call_init(MODULE_INIT_TRACE); qcrypto_init(&error_fatal); diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c index 8d80e58d4498..d265d11b6261 100644 --- a/scsi/qemu-pr-helper.c +++ b/scsi/qemu-pr-helper.c @@ -910,7 +910,7 @@ int main(int argc, char **argv) signal(SIGPIPE, SIG_IGN); - error_init(argv[0], NULL); + error_init(argv[0], NULL, NULL); module_call_init(MODULE_INIT_TRACE); module_call_init(MODULE_INIT_QOM); qemu_add_opts(&qemu_trace_opts); diff --git a/softmmu/vl.c b/softmmu/vl.c index 3b46fc9c1fc5..ef54af0efd6f 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -2639,7 +2639,7 @@ void qemu_init(int argc, char **argv, char **envp) qemu_add_opts(&qemu_action_opts); module_call_init(MODULE_INIT_OPTS); - error_init(argv[0], error_is_detailed); + error_init(argv[0], error_is_detailed, monitor_error_vprintf); qemu_init_exec_dir(argv[0]); qemu_init_arch_modules(); diff --git a/storage-daemon/qemu-storage-daemon.c b/storage-daemon/qemu-storage-daemon.c index 7e4d5030a045..0e0893695628 100644 --- a/storage-daemon/qemu-storage-daemon.c +++ b/storage-daemon/qemu-storage-daemon.c @@ -379,7 +379,7 @@ int main(int argc, char *argv[]) signal(SIGPIPE, SIG_IGN); #endif - error_init(argv[0], error_is_detailed); + error_init(argv[0], error_is_detailed, monitor_error_vprintf); qemu_init_exec_dir(argv[0]); os_setup_signal_handling(); diff --git a/stubs/error-printf.c b/stubs/error-printf.c deleted file mode 100644 index 1afa0f62ca26..000000000000 --- a/stubs/error-printf.c +++ /dev/null @@ -1,18 +0,0 @@ -#include "qemu/osdep.h" -#include "qemu/error-report.h" -#include "monitor/monitor.h" - -int error_vprintf(const char *fmt, va_list ap) -{ - int ret; - - if (g_test_initialized() && !g_test_subprocess() && - getenv("QTEST_SILENT_ERRORS")) { - char *msg = g_strdup_vprintf(fmt, ap); - g_test_message("%s", msg); - ret = strlen(msg); - g_free(msg); - return ret; - } - return vfprintf(stderr, fmt, ap); -} diff --git a/util/error-report.c b/util/error-report.c index c2181f80a83d..1452047cd2e8 100644 --- a/util/error-report.c +++ b/util/error-report.c @@ -23,11 +23,14 @@ typedef enum { REPORT_TYPE_INFO, } report_type; +static int error_vprintf(const char *fmt, va_list ap); + /* Prepend timestamp to messages */ bool message_with_timestamp; bool error_with_guestname; const char *error_guest_name; ErrorReportDetailedFunc detailed_fn = NULL; +ErrorReportVPrintfFunc vprintf_fn = error_vprintf; int error_printf(const char *fmt, ...) { @@ -35,7 +38,7 @@ int error_printf(const char *fmt, ...) int ret; va_start(ap, fmt); - ret = error_vprintf(fmt, ap); + ret = vprintf_fn(fmt, ap); va_end(ap); return ret; } @@ -222,7 +225,7 @@ static void vreport(report_type type, const char *fmt, va_list ap) break; } - error_vprintf(fmt, ap); + vprintf_fn(fmt, ap); error_printf("\n"); } @@ -387,7 +390,24 @@ static void qemu_log_func(const gchar *log_domain, } } -void error_init(const char *argv0, ErrorReportDetailedFunc detailed) +static int error_vprintf(const char *fmt, va_list ap) +{ + int ret; + + if (g_test_initialized() && !g_test_subprocess() && + getenv("QTEST_SILENT_ERRORS")) { + char *msg = g_strdup_vprintf(fmt, ap); + g_test_message("%s", msg); + ret = strlen(msg); + g_free(msg); + return ret; + } + return vfprintf(stderr, fmt, ap); +} + +void error_init(const char *argv0, + ErrorReportDetailedFunc detailed, + ErrorReportVPrintfFunc vprintf) { const char *p = strrchr(argv0, '/'); @@ -403,4 +423,5 @@ void error_init(const char *argv0, ErrorReportDetailedFunc detailed) qemu_glog_domains = g_strdup(g_getenv("G_MESSAGES_DEBUG")); detailed_fn = detailed; + vprintf_fn = vprintf ?: error_vprintf; } diff --git a/stubs/meson.build b/stubs/meson.build index d8f3fd5c44f2..498b6ee0466e 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -9,7 +9,6 @@ stub_ss.add(files('cpus-get-virtual-clock.c')) stub_ss.add(files('qemu-timer-notify-cb.c')) stub_ss.add(files('icount.c')) stub_ss.add(files('dump.c')) -stub_ss.add(files('error-printf.c')) stub_ss.add(files('fdset.c')) stub_ss.add(files('gdbstub.c')) stub_ss.add(files('get-vm-name.c')) From patchwork Thu Jun 16 12:40:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1644325 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Nl84ir6t; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LP2Sf3DYlz9sGC for ; Thu, 16 Jun 2022 23:04:32 +1000 (AEST) Received: from localhost ([::1]:38334 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1pAi-0000xX-OU for incoming@patchwork.ozlabs.org; Thu, 16 Jun 2022 09:04:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41880) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1ooW-0001SC-SQ for qemu-devel@nongnu.org; Thu, 16 Jun 2022 08:41:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:23674) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1ooN-0005ZD-N5 for qemu-devel@nongnu.org; Thu, 16 Jun 2022 08:41:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655383279; 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=4JCwGVreW5Z5NC5FZ9pjBxLt89NA5vi3SysqTGNE1zk=; b=Nl84ir6tgIpQYDEnFgo1zm5CjcM0IDE9Mh01co9O5BOAAoIOHXscSgfX4UeELSAiLJuOTu GnkvM+WNXUNjQtFU+8sbUDIbLJaLqZB+F0Z+5t1x+aYg2DlA2reXWXpVS/crqKoyW2qpqT H4ApD/Wl2FeXu3TLzJfsy6GWjz1M3/E= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-283-8YAX20ZCMKOsEfH_co3-qQ-1; Thu, 16 Jun 2022 08:41:16 -0400 X-MC-Unique: 8YAX20ZCMKOsEfH_co3-qQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CC57D802D1C; Thu, 16 Jun 2022 12:41:15 +0000 (UTC) Received: from localhost (unknown [10.39.208.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 90D061121314; Thu, 16 Jun 2022 12:41:14 +0000 (UTC) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Markus Armbruster , Michael Roth , Kevin Wolf , Laurent Vivier , Warner Losh , Kyle Evans , Hanna Reitz , Vladimir Sementsov-Ogievskiy , Fam Zheng , Eric Blake , "Dr. David Alan Gilbert" , Paolo Bonzini , qemu-block@nongnu.org, =?utf-8?q?Marc-?= =?utf-8?q?Andr=C3=A9_Lureau?= Subject: [PATCH 7/9] qapi: move QEMU-specific dispatch code in monitor Date: Thu, 16 Jun 2022 16:40:32 +0400 Message-Id: <20220616124034.3381391-8-marcandre.lureau@redhat.com> In-Reply-To: <20220616124034.3381391-1-marcandre.lureau@redhat.com> References: <20220616124034.3381391-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Marc-André Lureau Make QMP-dispatch code free from QEMU-specific OOB dispatch/async coroutine handling. This will allow to move the base code to qemu-common, and clear other users from potential mis-ususe (QGA doesn't have OOB or coroutine). To do that, introduce an optional callback QmpDispatchRun called when a QMP command should be run, to allow QEMU to override the default behaviour. Signed-off-by: Marc-André Lureau --- include/qapi/qmp/dispatch.h | 7 ++-- monitor/qmp.c | 68 ++++++++++++++++++++++++++++++++++++- qapi/qmp-dispatch.c | 64 +++------------------------------- qga/main.c | 2 +- tests/unit/test-qmp-cmds.c | 6 ++-- 5 files changed, 81 insertions(+), 66 deletions(-) diff --git a/include/qapi/qmp/dispatch.h b/include/qapi/qmp/dispatch.h index 1e4240fd0dbc..b659da613f2e 100644 --- a/include/qapi/qmp/dispatch.h +++ b/include/qapi/qmp/dispatch.h @@ -14,7 +14,6 @@ #ifndef QAPI_QMP_DISPATCH_H #define QAPI_QMP_DISPATCH_H -#include "monitor/monitor.h" #include "qemu/queue.h" typedef void (QmpCommandFunc)(QDict *, QObject **, Error **); @@ -41,6 +40,10 @@ typedef struct QmpCommand typedef QTAILQ_HEAD(QmpCommandList, QmpCommand) QmpCommandList; +typedef void (QmpDispatchRun)(bool oob, const QmpCommand *cmd, + QDict *args, QObject **ret, Error **errp, + void *run_data); + void qmp_register_command(QmpCommandList *cmds, const char *name, QmpCommandFunc *fn, QmpCommandOptions options, unsigned special_features); @@ -56,7 +59,7 @@ const char *qmp_command_name(const QmpCommand *cmd); bool qmp_has_success_response(const QmpCommand *cmd); QDict *qmp_error_response(Error *err); QDict *qmp_dispatch(const QmpCommandList *cmds, QObject *request, - bool allow_oob, Monitor *cur_mon); + bool allow_oob, QmpDispatchRun run_cb, void *run_data); bool qmp_is_oob(const QDict *dict); typedef void (*qmp_cmd_callback_fn)(const QmpCommand *cmd, void *opaque); diff --git a/monitor/qmp.c b/monitor/qmp.c index 092c527b6fc9..f8dec97c96bb 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -132,6 +132,72 @@ static void monitor_qmp_respond(MonitorQMP *mon, QDict *rsp) } } +typedef struct QmpDispatchBH { + const QmpCommand *cmd; + Monitor *cur_mon; + QDict *args; + QObject **ret; + Error **errp; + Coroutine *co; +} QmpDispatchBH; + +static void do_qmp_dispatch_bh(void *opaque) +{ + QmpDispatchBH *data = opaque; + + assert(monitor_cur() == NULL); + monitor_set_cur(qemu_coroutine_self(), data->cur_mon); + data->cmd->fn(data->args, data->ret, data->errp); + monitor_set_cur(qemu_coroutine_self(), NULL); + aio_co_wake(data->co); +} + +/* + * Runs outside of coroutine context for OOB commands, but in coroutine + * context for everything else. + */ +static void qmp_dispatch_run(bool oob, const QmpCommand *cmd, + QDict *args, QObject **ret, Error **errp, + void *run_data) +{ + Monitor *cur_mon = run_data; + + assert(!(oob && qemu_in_coroutine())); + assert(monitor_cur() == NULL); + + if (!!(cmd->options & QCO_COROUTINE) == qemu_in_coroutine()) { + monitor_set_cur(qemu_coroutine_self(), cur_mon); + cmd->fn(args, ret, errp); + monitor_set_cur(qemu_coroutine_self(), NULL); + } else { + /* + * Actual context doesn't match the one the command needs. + * + * Case 1: we are in coroutine context, but command does not + * have QCO_COROUTINE. We need to drop out of coroutine + * context for executing it. + * + * Case 2: we are outside coroutine context, but command has + * QCO_COROUTINE. Can't actually happen, because we get here + * outside coroutine context only when executing a command + * out of band, and OOB commands never have QCO_COROUTINE. + */ + assert(!oob && qemu_in_coroutine() && !(cmd->options & QCO_COROUTINE)); + + QmpDispatchBH data = { + .cur_mon = cur_mon, + .cmd = cmd, + .args = args, + .ret = ret, + .errp = errp, + .co = qemu_coroutine_self(), + }; + aio_bh_schedule_oneshot(qemu_get_aio_context(), do_qmp_dispatch_bh, + &data); + qemu_coroutine_yield(); + } +} + /* * Runs outside of coroutine context for OOB commands, but in * coroutine context for everything else. @@ -142,7 +208,7 @@ static void monitor_qmp_dispatch(MonitorQMP *mon, QObject *req) QDict *error; rsp = qmp_dispatch(mon->commands, req, qmp_oob_enabled(mon), - &mon->common); + qmp_dispatch_run, &mon->common); if (mon->commands == &qmp_cap_negotiation_commands) { error = qdict_get_qdict(rsp, "error"); diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index 0990873ec8ec..342b13d7ebbd 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -13,7 +13,6 @@ #include "qemu/osdep.h" -#include "block/aio.h" #include "qapi/compat-policy.h" #include "qapi/error.h" #include "qapi/qmp/dispatch.h" @@ -22,8 +21,6 @@ #include "qapi/qobject-input-visitor.h" #include "qapi/qobject-output-visitor.h" #include "qapi/qmp/qbool.h" -#include "qemu/coroutine.h" -#include "qemu/main-loop.h" Visitor *qobject_input_visitor_new_qmp(QObject *obj) { @@ -110,32 +107,8 @@ bool qmp_is_oob(const QDict *dict) && !qdict_haskey(dict, "execute"); } -typedef struct QmpDispatchBH { - const QmpCommand *cmd; - Monitor *cur_mon; - QDict *args; - QObject **ret; - Error **errp; - Coroutine *co; -} QmpDispatchBH; - -static void do_qmp_dispatch_bh(void *opaque) -{ - QmpDispatchBH *data = opaque; - - assert(monitor_cur() == NULL); - monitor_set_cur(qemu_coroutine_self(), data->cur_mon); - data->cmd->fn(data->args, data->ret, data->errp); - monitor_set_cur(qemu_coroutine_self(), NULL); - aio_co_wake(data->co); -} - -/* - * Runs outside of coroutine context for OOB commands, but in coroutine - * context for everything else. - */ QDict *qmp_dispatch(const QmpCommandList *cmds, QObject *request, - bool allow_oob, Monitor *cur_mon) + bool allow_oob, QmpDispatchRun run_cb, void *run_data) { Error *err = NULL; bool oob; @@ -203,39 +176,12 @@ QDict *qmp_dispatch(const QmpCommandList *cmds, QObject *request, qobject_ref(args); } - assert(!(oob && qemu_in_coroutine())); - assert(monitor_cur() == NULL); - if (!!(cmd->options & QCO_COROUTINE) == qemu_in_coroutine()) { - monitor_set_cur(qemu_coroutine_self(), cur_mon); - cmd->fn(args, &ret, &err); - monitor_set_cur(qemu_coroutine_self(), NULL); + if (run_cb) { + run_cb(oob, cmd, args, &ret, &err, run_data); } else { - /* - * Actual context doesn't match the one the command needs. - * - * Case 1: we are in coroutine context, but command does not - * have QCO_COROUTINE. We need to drop out of coroutine - * context for executing it. - * - * Case 2: we are outside coroutine context, but command has - * QCO_COROUTINE. Can't actually happen, because we get here - * outside coroutine context only when executing a command - * out of band, and OOB commands never have QCO_COROUTINE. - */ - assert(!oob && qemu_in_coroutine() && !(cmd->options & QCO_COROUTINE)); - - QmpDispatchBH data = { - .cur_mon = cur_mon, - .cmd = cmd, - .args = args, - .ret = &ret, - .errp = &err, - .co = qemu_coroutine_self(), - }; - aio_bh_schedule_oneshot(qemu_get_aio_context(), do_qmp_dispatch_bh, - &data); - qemu_coroutine_yield(); + cmd->fn(args, &ret, &err); } + qobject_unref(args); if (err) { /* or assert(!ret) after reviewing all handlers: */ diff --git a/qga/main.c b/qga/main.c index c373fec3ee69..fb7d673bea9f 100644 --- a/qga/main.c +++ b/qga/main.c @@ -569,7 +569,7 @@ static void process_event(void *opaque, QObject *obj, Error *err) } g_debug("processing command"); - rsp = qmp_dispatch(&ga_commands, obj, false, NULL); + rsp = qmp_dispatch(&ga_commands, obj, false, NULL, NULL); end: ret = send_response(s, rsp); diff --git a/tests/unit/test-qmp-cmds.c b/tests/unit/test-qmp-cmds.c index 6085c099950b..abe67a9bd880 100644 --- a/tests/unit/test-qmp-cmds.c +++ b/tests/unit/test-qmp-cmds.c @@ -150,7 +150,7 @@ static QObject *do_qmp_dispatch(bool allow_oob, const char *template, ...) req = qdict_from_vjsonf_nofail(template, ap); va_end(ap); - resp = qmp_dispatch(&qmp_commands, QOBJECT(req), allow_oob, NULL); + resp = qmp_dispatch(&qmp_commands, QOBJECT(req), allow_oob, NULL, NULL); g_assert(resp); ret = qdict_get(resp, "return"); g_assert(ret); @@ -173,7 +173,7 @@ static void do_qmp_dispatch_error(bool allow_oob, ErrorClass cls, req = qdict_from_vjsonf_nofail(template, ap); va_end(ap); - resp = qmp_dispatch(&qmp_commands, QOBJECT(req), allow_oob, NULL); + resp = qmp_dispatch(&qmp_commands, QOBJECT(req), allow_oob, NULL, NULL); g_assert(resp); error = qdict_get_qdict(resp, "error"); g_assert(error); @@ -229,7 +229,7 @@ static void test_dispatch_cmd_success_response(void) QDict *resp; qdict_put_str(req, "execute", "cmd-success-response"); - resp = qmp_dispatch(&qmp_commands, QOBJECT(req), false, NULL); + resp = qmp_dispatch(&qmp_commands, QOBJECT(req), false, NULL, NULL); g_assert_null(resp); qobject_unref(req); } From patchwork Thu Jun 16 12:40:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1644329 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=UQx59USx; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LP2bt42tMz9sGC for ; Thu, 16 Jun 2022 23:10:48 +1000 (AEST) Received: from localhost ([::1]:51040 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1pGm-0001cB-Sl for incoming@patchwork.ozlabs.org; Thu, 16 Jun 2022 09:10:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41936) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1ooZ-0001UI-Fy for qemu-devel@nongnu.org; Thu, 16 Jun 2022 08:41:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:37120) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1ooV-0005r8-Gy for qemu-devel@nongnu.org; Thu, 16 Jun 2022 08:41:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655383290; 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=qY6ywvOwDLELLr7tGfvyNuCLoI0xFYiPWuPvnh0yL98=; b=UQx59USx+6KovYHUaYLKBUyPYokeJsMnbRgnyutw3xgGiLi0vXlHO7t7CrHZF+KImu73jV YrsP8iEPNoboDeMAu+MI8ZMPgBLKW4EjDvWApp5EfsJ5i85emRjO+Dg2OfWTkoXWKfrhWn j3w6RguqkzrNil8nRKe17g7jAjgDxME= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-323-xpvjDBBwO1u7XapfK7ptsg-1; Thu, 16 Jun 2022 08:41:26 -0400 X-MC-Unique: xpvjDBBwO1u7XapfK7ptsg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D7E9F3833285; Thu, 16 Jun 2022 12:41:25 +0000 (UTC) Received: from localhost (unknown [10.39.208.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id DF067492CA5; Thu, 16 Jun 2022 12:41:23 +0000 (UTC) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Markus Armbruster , Michael Roth , Kevin Wolf , Laurent Vivier , Warner Losh , Kyle Evans , Hanna Reitz , Vladimir Sementsov-Ogievskiy , Fam Zheng , Eric Blake , "Dr. David Alan Gilbert" , Paolo Bonzini , qemu-block@nongnu.org, =?utf-8?q?Marc-?= =?utf-8?q?Andr=C3=A9_Lureau?= Subject: [PATCH 8/9] scripts/qapi-gen: add -i option Date: Thu, 16 Jun 2022 16:40:33 +0400 Message-Id: <20220616124034.3381391-9-marcandre.lureau@redhat.com> In-Reply-To: <20220616124034.3381391-1-marcandre.lureau@redhat.com> References: <20220616124034.3381391-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Marc-André Lureau Replace hard-coded "qemu/osdep.h" include with a qapi-gen option to specify the headers to include. This will allow to substitute QEMU osdep.h with glib.h for example, for projects with different global headers. For historical reasons, we can keep the default as "qemu/osdep.h". Signed-off-by: Marc-André Lureau --- scripts/qapi/commands.py | 15 ++++++++++----- scripts/qapi/events.py | 17 +++++++++++------ scripts/qapi/gen.py | 17 +++++++++++++++++ scripts/qapi/introspect.py | 11 +++++++---- scripts/qapi/main.py | 17 +++++++++++------ scripts/qapi/types.py | 17 +++++++++++------ scripts/qapi/visit.py | 17 +++++++++++------ 7 files changed, 78 insertions(+), 33 deletions(-) diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index 38ca38a7b9dd..781491b6390d 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -294,9 +294,9 @@ def gen_register_command(name: str, class QAPISchemaGenCommandVisitor(QAPISchemaModularCVisitor): - def __init__(self, prefix: str, gen_tracing: bool): + def __init__(self, prefix: str, include: List[str], gen_tracing: bool): super().__init__( - prefix, 'qapi-commands', + prefix, include, 'qapi-commands', ' * Schema-defined QAPI/QMP commands', None, __doc__, gen_tracing=gen_tracing) self._visited_ret_types: Dict[QAPIGenC, Set[QAPISchemaType]] = {} @@ -308,7 +308,8 @@ def _begin_user_module(self, name: str) -> None: types = self._module_basename('qapi-types', name) visit = self._module_basename('qapi-visit', name) self._genc.add(mcgen(''' -#include "qemu/osdep.h" +%(include)s + #include "qapi/compat-policy.h" #include "qapi/visitor.h" #include "qapi/qmp/qdict.h" @@ -318,6 +319,7 @@ def _begin_user_module(self, name: str) -> None: #include "%(commands)s.h" ''', + include=self.genc_include(), commands=commands, visit=visit)) if self._gen_tracing and commands != 'qapi-commands': @@ -344,7 +346,8 @@ def visit_begin(self, schema: QAPISchema) -> None: ''', c_prefix=c_name(self._prefix, protect=False))) self._genc.add(mcgen(''' -#include "qemu/osdep.h" +%(include)s + #include "%(prefix)sqapi-commands.h" #include "%(prefix)sqapi-init-commands.h" @@ -353,6 +356,7 @@ def visit_begin(self, schema: QAPISchema) -> None: QTAILQ_INIT(cmds); ''', + include=self.genc_include(), prefix=self._prefix, c_prefix=c_name(self._prefix, protect=False))) @@ -404,7 +408,8 @@ def visit_command(self, def gen_commands(schema: QAPISchema, output_dir: str, prefix: str, + include: List[str], gen_tracing: bool) -> None: - vis = QAPISchemaGenCommandVisitor(prefix, gen_tracing) + vis = QAPISchemaGenCommandVisitor(prefix, include, gen_tracing) schema.visit(vis) vis.write(output_dir) diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index 27b44c49f5e9..6e677d11d2e0 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -175,9 +175,9 @@ def gen_event_send(name: str, class QAPISchemaGenEventVisitor(QAPISchemaModularCVisitor): - def __init__(self, prefix: str): + def __init__(self, prefix: str, include: List[str]): super().__init__( - prefix, 'qapi-events', + prefix, include, 'qapi-events', ' * Schema-defined QAPI/QMP events', None, __doc__) self._event_enum_name = c_name(prefix + 'QAPIEvent', protect=False) self._event_enum_members: List[QAPISchemaEnumMember] = [] @@ -188,7 +188,8 @@ def _begin_user_module(self, name: str) -> None: types = self._module_basename('qapi-types', name) visit = self._module_basename('qapi-visit', name) self._genc.add(mcgen(''' -#include "qemu/osdep.h" +%(include)s + #include "%(prefix)sqapi-emit-events.h" #include "%(events)s.h" #include "%(visit)s.h" @@ -198,6 +199,7 @@ def _begin_user_module(self, name: str) -> None: #include "qapi/qmp-event.h" ''', + include=self.genc_include(), events=events, visit=visit, prefix=self._prefix)) self._genh.add(mcgen(''' @@ -209,9 +211,11 @@ def _begin_user_module(self, name: str) -> None: def visit_end(self) -> None: self._add_module('./emit', ' * QAPI Events emission') self._genc.preamble_add(mcgen(''' -#include "qemu/osdep.h" +%(include)s + #include "%(prefix)sqapi-emit-events.h" ''', + include=self.genc_include(), prefix=self._prefix)) self._genh.preamble_add(mcgen(''' #include "qapi/util.h" @@ -246,7 +250,8 @@ def visit_event(self, def gen_events(schema: QAPISchema, output_dir: str, - prefix: str) -> None: - vis = QAPISchemaGenEventVisitor(prefix) + prefix: str, + include: List[str]) -> None: + vis = QAPISchemaGenEventVisitor(prefix, include) schema.visit(vis) vis.write(output_dir) diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index 113b49134de4..54a70a5ff516 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -17,6 +17,7 @@ from typing import ( Dict, Iterator, + List, Optional, Sequence, Tuple, @@ -45,6 +46,12 @@ def gen_special_features(features: Sequence[QAPISchemaFeature]) -> str: return ' | '.join(special_features) or '0' +def genc_include(include: List[str]) -> str: + return '\n'.join(['#include ' + + (f'"{inc}"' if inc[0] not in ('<', '"') else inc) + for inc in include]) + + class QAPIGen: def __init__(self, fname: str): self.fname = fname @@ -228,16 +235,21 @@ def ifcontext(ifcond: QAPISchemaIfCond, *args: QAPIGenCCode) -> Iterator[None]: class QAPISchemaMonolithicCVisitor(QAPISchemaVisitor): def __init__(self, prefix: str, + include: List[str], what: str, blurb: str, pydoc: str): self._prefix = prefix + self._include = include self._what = what self._genc = QAPIGenC(self._prefix + self._what + '.c', blurb, pydoc) self._genh = QAPIGenH(self._prefix + self._what + '.h', blurb, pydoc) + def genc_include(self) -> str: + return genc_include(self._include) + def write(self, output_dir: str) -> None: self._genc.write(output_dir) self._genh.write(output_dir) @@ -246,12 +258,14 @@ def write(self, output_dir: str) -> None: class QAPISchemaModularCVisitor(QAPISchemaVisitor): def __init__(self, prefix: str, + include: List[str], what: str, user_blurb: str, builtin_blurb: Optional[str], pydoc: str, gen_tracing: bool = False): self._prefix = prefix + self._include = include self._what = what self._user_blurb = user_blurb self._builtin_blurb = builtin_blurb @@ -262,6 +276,9 @@ def __init__(self, self._main_module: Optional[str] = None self._gen_tracing = gen_tracing + def genc_include(self) -> str: + return genc_include(self._include) + @property def _genc(self) -> QAPIGenC: assert self._current_module is not None diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 67c7d89aae00..d965d1769447 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -170,9 +170,9 @@ def to_c_string(string: str) -> str: class QAPISchemaGenIntrospectVisitor(QAPISchemaMonolithicCVisitor): - def __init__(self, prefix: str, unmask: bool): + def __init__(self, prefix: str, include: List[str], unmask: bool): super().__init__( - prefix, 'qapi-introspect', + prefix, include, 'qapi-introspect', ' * QAPI/QMP schema introspection', __doc__) self._unmask = unmask self._schema: Optional[QAPISchema] = None @@ -180,10 +180,12 @@ def __init__(self, prefix: str, unmask: bool): self._used_types: List[QAPISchemaType] = [] self._name_map: Dict[str, str] = {} self._genc.add(mcgen(''' -#include "qemu/osdep.h" +%(include)s + #include "%(prefix)sqapi-introspect.h" ''', + include=self.genc_include(), prefix=prefix)) def visit_begin(self, schema: QAPISchema) -> None: @@ -384,7 +386,8 @@ def visit_event(self, name: str, info: Optional[QAPISourceInfo], def gen_introspect(schema: QAPISchema, output_dir: str, prefix: str, + include: List[str], opt_unmask: bool) -> None: - vis = QAPISchemaGenIntrospectVisitor(prefix, opt_unmask) + vis = QAPISchemaGenIntrospectVisitor(prefix, include, opt_unmask) schema.visit(vis) vis.write(output_dir) diff --git a/scripts/qapi/main.py b/scripts/qapi/main.py index fc216a53d32a..eba98cb9ace2 100644 --- a/scripts/qapi/main.py +++ b/scripts/qapi/main.py @@ -9,7 +9,7 @@ import argparse import sys -from typing import Optional +from typing import List, Optional from .commands import gen_commands from .common import must_match @@ -31,6 +31,7 @@ def invalid_prefix_char(prefix: str) -> Optional[str]: def generate(schema_file: str, output_dir: str, prefix: str, + include: List[str], unmask: bool = False, builtins: bool = False, gen_tracing: bool = False) -> None: @@ -48,11 +49,11 @@ def generate(schema_file: str, assert invalid_prefix_char(prefix) is None schema = QAPISchema(schema_file) - gen_types(schema, output_dir, prefix, builtins) - gen_visit(schema, output_dir, prefix, builtins) - gen_commands(schema, output_dir, prefix, gen_tracing) - gen_events(schema, output_dir, prefix) - gen_introspect(schema, output_dir, prefix, unmask) + gen_types(schema, output_dir, prefix, include, builtins) + gen_visit(schema, output_dir, prefix, include, builtins) + gen_commands(schema, output_dir, prefix, include, gen_tracing) + gen_events(schema, output_dir, prefix, include) + gen_introspect(schema, output_dir, prefix, include, unmask) def main() -> int: @@ -75,6 +76,9 @@ def main() -> int: parser.add_argument('-u', '--unmask-non-abi-names', action='store_true', dest='unmask', help="expose non-ABI names in introspection") + parser.add_argument('-i', '--include', nargs='*', + default=['qemu/osdep.h'], + help="top-level include headers") # Option --suppress-tracing exists so we can avoid solving build system # problems. TODO Drop it when we no longer need it. @@ -94,6 +98,7 @@ def main() -> int: generate(args.schema, output_dir=args.output_dir, prefix=args.prefix, + include=args.include, unmask=args.unmask, builtins=args.builtins, gen_tracing=not args.suppress_tracing) diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py index 477d02700137..9617b7d4edfa 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -282,18 +282,20 @@ def gen_type_cleanup(name: str) -> str: class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisitor): - def __init__(self, prefix: str): + def __init__(self, prefix: str, include: List[str]): super().__init__( - prefix, 'qapi-types', ' * Schema-defined QAPI types', + prefix, include, 'qapi-types', ' * Schema-defined QAPI types', ' * Built-in QAPI types', __doc__) def _begin_builtin_module(self) -> None: self._genc.preamble_add(mcgen(''' -#include "qemu/osdep.h" +%(include)s + #include "qapi/dealloc-visitor.h" #include "qapi/qapi-builtin-types.h" #include "qapi/qapi-builtin-visit.h" -''')) +''', + include=self.genc_include())) self._genh.preamble_add(mcgen(''' #include "qapi/util.h" ''')) @@ -302,11 +304,13 @@ def _begin_user_module(self, name: str) -> None: types = self._module_basename('qapi-types', name) visit = self._module_basename('qapi-visit', name) self._genc.preamble_add(mcgen(''' -#include "qemu/osdep.h" +%(include)s + #include "qapi/dealloc-visitor.h" #include "%(types)s.h" #include "%(visit)s.h" ''', + include=self.genc_include(), types=types, visit=visit)) self._genh.preamble_add(mcgen(''' #include "qapi/qapi-builtin-types.h" @@ -381,7 +385,8 @@ def visit_alternate_type(self, def gen_types(schema: QAPISchema, output_dir: str, prefix: str, + include: List[str], opt_builtins: bool) -> None: - vis = QAPISchemaGenTypeVisitor(prefix) + vis = QAPISchemaGenTypeVisitor(prefix, include) schema.visit(vis) vis.write(output_dir, opt_builtins) diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index 380fa197f589..1ff464c0360f 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -318,17 +318,19 @@ def gen_visit_object(name: str) -> str: class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisitor): - def __init__(self, prefix: str): + def __init__(self, prefix: str, include: List[str]): super().__init__( - prefix, 'qapi-visit', ' * Schema-defined QAPI visitors', + prefix, include, 'qapi-visit', ' * Schema-defined QAPI visitors', ' * Built-in QAPI visitors', __doc__) def _begin_builtin_module(self) -> None: self._genc.preamble_add(mcgen(''' -#include "qemu/osdep.h" +%(include)s + #include "qapi/error.h" #include "qapi/qapi-builtin-visit.h" -''')) +''', + include=self.genc_include())) self._genh.preamble_add(mcgen(''' #include "qapi/visitor.h" #include "qapi/qapi-builtin-types.h" @@ -339,11 +341,13 @@ def _begin_user_module(self, name: str) -> None: types = self._module_basename('qapi-types', name) visit = self._module_basename('qapi-visit', name) self._genc.preamble_add(mcgen(''' -#include "qemu/osdep.h" +%(include)s + #include "qapi/error.h" #include "qapi/qmp/qerror.h" #include "%(visit)s.h" ''', + include=self.genc_include(), visit=visit)) self._genh.preamble_add(mcgen(''' #include "qapi/qapi-builtin-visit.h" @@ -408,7 +412,8 @@ def visit_alternate_type(self, def gen_visit(schema: QAPISchema, output_dir: str, prefix: str, + include: List[str], opt_builtins: bool) -> None: - vis = QAPISchemaGenVisitVisitor(prefix) + vis = QAPISchemaGenVisitVisitor(prefix, include) schema.visit(vis) vis.write(output_dir, opt_builtins) From patchwork Thu Jun 16 12:40:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1644332 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=bbG1g7pZ; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LP2p60Gxgz9sGC for ; Thu, 16 Jun 2022 23:19:42 +1000 (AEST) Received: from localhost ([::1]:39370 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1pPP-0004cy-Nu for incoming@patchwork.ozlabs.org; Thu, 16 Jun 2022 09:19:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41966) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1ooe-0001X3-N5 for qemu-devel@nongnu.org; Thu, 16 Jun 2022 08:41:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:28648) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1ood-0005sN-4b for qemu-devel@nongnu.org; Thu, 16 Jun 2022 08:41:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655383295; 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=Et7o+gm789s34jZqe/LwIE8WIv+NIHpOHYPmrL3ytP8=; b=bbG1g7pZ8MUlOY2W7dp6upgt4+ynMwHO6P4ArcrqlRS3mZnRDYGrrCGrRQnNqc4XnAF+17 1ZTcO5ODTG4oU2Oy2IrLhcyBUx/I7N6KtPZ6nMbDgcwz2k8wOyd1riddTo3UUkQdNUQrt3 JsQlmAXOq4QwYDaBcGfUMD56ZPKNMT8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-607-mf8Vj5tQNSCy7A57D0VbIw-1; Thu, 16 Jun 2022 08:41:31 -0400 X-MC-Unique: mf8Vj5tQNSCy7A57D0VbIw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 301D5101E986; Thu, 16 Jun 2022 12:41:31 +0000 (UTC) Received: from localhost (unknown [10.39.208.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0D71D111F5; Thu, 16 Jun 2022 12:41:29 +0000 (UTC) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Markus Armbruster , Michael Roth , Kevin Wolf , Laurent Vivier , Warner Losh , Kyle Evans , Hanna Reitz , Vladimir Sementsov-Ogievskiy , Fam Zheng , Eric Blake , "Dr. David Alan Gilbert" , Paolo Bonzini , qemu-block@nongnu.org, =?utf-8?q?Marc-?= =?utf-8?q?Andr=C3=A9_Lureau?= Subject: [PATCH 9/9] scripts/qapi: add required system includes to visitor Date: Thu, 16 Jun 2022 16:40:34 +0400 Message-Id: <20220616124034.3381391-10-marcandre.lureau@redhat.com> In-Reply-To: <20220616124034.3381391-1-marcandre.lureau@redhat.com> References: <20220616124034.3381391-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Marc-André Lureau The generated visitor code includes abort() & assert(), we shouldn't rely on the global "-i" headers to include the necessary system headers. Signed-off-by: Marc-André Lureau --- scripts/qapi/visit.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index 1ff464c0360f..d686df17f4b6 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -326,6 +326,8 @@ def __init__(self, prefix: str, include: List[str]): def _begin_builtin_module(self) -> None: self._genc.preamble_add(mcgen(''' %(include)s +#include +#include #include "qapi/error.h" #include "qapi/qapi-builtin-visit.h" @@ -342,6 +344,8 @@ def _begin_user_module(self, name: str) -> None: visit = self._module_basename('qapi-visit', name) self._genc.preamble_add(mcgen(''' %(include)s +#include +#include #include "qapi/error.h" #include "qapi/qmp/qerror.h"