From patchwork Thu Jul 13 11:02:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ladi Prosek X-Patchwork-Id: 9838199 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1C0D4602D8 for ; Thu, 13 Jul 2017 11:04:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0CDE4286D1 for ; Thu, 13 Jul 2017 11:04:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 000C1286D4; Thu, 13 Jul 2017 11:04:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8A0CC286D1 for ; Thu, 13 Jul 2017 11:04:17 +0000 (UTC) Received: from localhost ([::1]:58736 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVbuq-0005j8-Md for patchwork-qemu-devel@patchwork.kernel.org; Thu, 13 Jul 2017 07:04:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40225) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVbtT-0005iE-2Z for qemu-devel@nongnu.org; Thu, 13 Jul 2017 07:02:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVbtP-0001Gf-Pd for qemu-devel@nongnu.org; Thu, 13 Jul 2017 07:02:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34006) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVbtP-0001FK-GR for qemu-devel@nongnu.org; Thu, 13 Jul 2017 07:02:47 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 69F3C804E9; Thu, 13 Jul 2017 11:02:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 69F3C804E9 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=lprosek@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 69F3C804E9 Received: from dhcp-1-107.brq.redhat.com (unknown [10.43.2.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 93F5C6C1E5; Thu, 13 Jul 2017 11:02:44 +0000 (UTC) From: Ladi Prosek To: qemu-devel@nongnu.org Date: Thu, 13 Jul 2017 13:02:30 +0200 Message-Id: <20170713110237.6712-2-lprosek@redhat.com> In-Reply-To: <20170713110237.6712-1-lprosek@redhat.com> References: <20170713110237.6712-1-lprosek@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 13 Jul 2017 11:02:46 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 1/8] qemu-error: introduce error_report_nolf X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: casasfernando@hotmail.com, mst@redhat.com, jasowang@redhat.com, armbru@redhat.com, groug@kaod.org, arei.gonglei@huawei.com, aneesh.kumar@linux.vnet.ibm.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Callers of error_report may want to compose the error message out of multiple separate format strings. To save them from always having to combine their strings into one (a process that would likely involve memory allocation which is good to avoid on error paths), new "nolf" variants of error_report and error_vreport are introduced. Signed-off-by: Ladi Prosek --- hw/virtio/virtio.c | 3 ++- include/qemu/error-report.h | 3 ++- util/qemu-error.c | 32 ++++++++++++++++++++++++++------ 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 464947f..0e76a73 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -2448,8 +2448,9 @@ void GCC_FMT_ATTR(2, 3) virtio_error(VirtIODevice *vdev, const char *fmt, ...) va_list ap; va_start(ap, fmt); - error_vreport(fmt, ap); + error_vreport_nolf(fmt, ap); va_end(ap); + error_printf("\n"); if (virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)) { virtio_set_status(vdev, vdev->status | VIRTIO_CONFIG_S_NEEDS_RESET); diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h index 3001865..cdee84f 100644 --- a/include/qemu/error-report.h +++ b/include/qemu/error-report.h @@ -35,7 +35,8 @@ void error_printf(const char *fmt, ...) GCC_FMT_ATTR(1, 2); void error_vprintf_unless_qmp(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0); void error_printf_unless_qmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2); void error_set_progname(const char *argv0); -void error_vreport(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0); +void error_vreport_nolf(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0); +void error_report_nolf(const char *fmt, ...) GCC_FMT_ATTR(1, 2); void error_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2); const char *error_get_progname(void); extern bool enable_timestamp_msg; diff --git a/util/qemu-error.c b/util/qemu-error.c index b331f8f..c7fd127 100644 --- a/util/qemu-error.c +++ b/util/qemu-error.c @@ -181,11 +181,13 @@ bool enable_timestamp_msg; /* * Print an error message to current monitor if we have one, else to stderr. * Format arguments like vsprintf(). The resulting message should be - * a single phrase, with no newline or trailing punctuation. - * Prepend the current location and append a newline. + * a single phrase, with no trailing punctuation. The no-LF version allows + * additional text to be appended with error_printf() or error_vprintf(). + * Make sure to always close with a newline after all text is printed. + * Prepends the current location. * It's wrong to call this in a QMP monitor. Use error_setg() there. */ -void error_vreport(const char *fmt, va_list ap) +void error_vreport_nolf(const char *fmt, va_list ap) { GTimeVal tv; gchar *timestr; @@ -199,14 +201,31 @@ void error_vreport(const char *fmt, va_list ap) error_print_loc(); error_vprintf(fmt, ap); - error_printf("\n"); +} + +/* + * Print an error message to current monitor if we have one, else to stderr. + * Format arguments like sprintf(). The resulting message should be a + * single phrase, with no trailing punctuation. The no-LF version allows + * additional text to be appended with error_printf() or error_vprintf(). + * Make sure to always close with a newline after all text is printed. + * Prepends the current location. + * It's wrong to call this in a QMP monitor. Use error_setg() there. + */ +void error_report_nolf(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + error_vreport_nolf(fmt, ap); + va_end(ap); } /* * Print an error message to current monitor if we have one, else to stderr. * Format arguments like sprintf(). The resulting message should be a * single phrase, with no newline or trailing punctuation. - * Prepend the current location and append a newline. + * Prepends the current location and appends a newline. * It's wrong to call this in a QMP monitor. Use error_setg() there. */ void error_report(const char *fmt, ...) @@ -214,6 +233,7 @@ void error_report(const char *fmt, ...) va_list ap; va_start(ap, fmt); - error_vreport(fmt, ap); + error_vreport_nolf(fmt, ap); va_end(ap); + error_printf("\n"); }