From patchwork Tue Feb 26 14:25:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Michelson X-Patchwork-Id: 1048395 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4481Zx5jn0z9sCH for ; Wed, 27 Feb 2019 01:36:09 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 083AF7935; Tue, 26 Feb 2019 14:35:43 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id BDFCE791F for ; Tue, 26 Feb 2019 14:26:02 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 408C2826 for ; Tue, 26 Feb 2019 14:26:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C2437C05A1D9 for ; Tue, 26 Feb 2019 14:26:01 +0000 (UTC) Received: from monae.redhat.com (ovpn-121-115.rdu2.redhat.com [10.10.121.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id 57E7C2899B for ; Tue, 26 Feb 2019 14:26:01 +0000 (UTC) From: Mark Michelson To: dev@openvswitch.org Date: Tue, 26 Feb 2019 09:25:59 -0500 Message-Id: <20190226142600.3542-2-mmichels@redhat.com> In-Reply-To: <20190226142600.3542-1-mmichels@redhat.com> References: <20190226142600.3542-1-mmichels@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 26 Feb 2019 14:26:01 +0000 (UTC) X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH 2.10 v2 1/2] table: Create method for resetting table formatting. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Table formatting has a local static integer that is intended to insert line breaks between tables. This works exactly as intended, as long as each call to table_format() is done as a single unit within the run of a process. When ovn-nbctl is run in daemon mode, it is a long-running process that makes multiple calls to table_format() throughout its lifetime. After the first call, this results in an unexpected newline prepended to table output on each subsequent ovn-nbctl invocation. The solution is to introduce a function to reset table formatting. This way, the first time after resetting table formatting, no newline is prepended. Signed-off-by: Mark Michelson Signed-off-by: Ben Pfaff Acked-by: Numan Siddique --- lib/table.c | 23 +++++++++++++++++------ lib/table.h | 1 + ovn/utilities/ovn-nbctl.c | 1 + tests/ovn-nbctl.at | 13 +++++++++++++ 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/lib/table.c b/lib/table.c index ab72668c7..48d18b651 100644 --- a/lib/table.c +++ b/lib/table.c @@ -236,15 +236,18 @@ table_print_timestamp__(const struct table *table, struct ds *s) } } +static bool first_table = true; + static void table_print_table__(const struct table *table, const struct table_style *style, struct ds *s) { - static int n = 0; int *widths; size_t x, y; - if (n++ > 0) { + if (first_table) { + first_table = false; + } else { ds_put_char(s, '\n'); } @@ -318,10 +321,11 @@ static void table_print_list__(const struct table *table, const struct table_style *style, struct ds *s) { - static int n = 0; size_t x, y; - if (n++ > 0) { + if (first_table) { + first_table = false; + } else { ds_put_char(s, '\n'); } @@ -469,10 +473,11 @@ static void table_print_csv__(const struct table *table, const struct table_style *style, struct ds *s) { - static int n = 0; size_t x, y; - if (n++ > 0) { + if (first_table) { + first_table = false; + } else { ds_put_char(s, '\n'); } @@ -614,6 +619,12 @@ table_format(const struct table *table, const struct table_style *style, } } +void +table_format_reset(void) +{ + first_table = true; +} + /* Outputs 'table' on stdout in the specified 'style'. */ void table_print(const struct table *table, const struct table_style *style) diff --git a/lib/table.h b/lib/table.h index 76e65bb70..33263e2a2 100644 --- a/lib/table.h +++ b/lib/table.h @@ -133,6 +133,7 @@ void table_parse_cell_format(struct table_style *, const char *format); void table_print(const struct table *, const struct table_style *); void table_format(const struct table *, const struct table_style *, struct ds *); +void table_format_reset(void); void table_usage(void); #endif /* table.h */ diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index 09bbcf76a..b5ee0a6e1 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -5231,6 +5231,7 @@ server_cmd_run(struct unixctl_conn *conn, int argc, const char **argv_, } struct ds output = DS_EMPTY_INITIALIZER; + table_format_reset(); for (struct ctl_command *c = commands; c < &commands[n_commands]; c++) { if (c->table) { table_format(c->table, &table_style, &output); diff --git a/tests/ovn-nbctl.at b/tests/ovn-nbctl.at index a599b1bf7..7d627cdc0 100644 --- a/tests/ovn-nbctl.at +++ b/tests/ovn-nbctl.at @@ -1517,3 +1517,16 @@ AT_CHECK([ovn-nbctl create Port_Group name=pg0], [0], [ignore]) AT_CHECK([ovn-nbctl get Port_Group pg0 name], [0], [dnl "pg0" ])]) + + +OVN_NBCTL_TEST([ovn_nbctl_extra_newlines], [extra newlines], [ +dnl This test addresses a specific issue seen when running ovn-nbctl in +dnl daemon mode. All we have to do is ensure that each time we list database +dnl information, there is not an extra newline at the beginning of the output. +AT_CHECK([ovn-nbctl ls-add sw1], [0], [ignore]) +AT_CHECK([ovn-nbctl --columns=name list logical_switch sw1], [0], [dnl +name : "sw1" +]) +AT_CHECK([ovn-nbctl --columns=name list logical_switch sw1], [0], [dnl +name : "sw1" +])])