From patchwork Fri Jul 13 18:36:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 943764 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 41S1k300rYz9s0n for ; Sat, 14 Jul 2018 04:36:58 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 88E83DB4; Fri, 13 Jul 2018 18:36:31 +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 6F2CCDA1 for ; Fri, 13 Jul 2018 18:36:29 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 03BCA7B0 for ; Fri, 13 Jul 2018 18:36:28 +0000 (UTC) Received: by mail-wm0-f65.google.com with SMTP id s14-v6so10287794wmc.1 for ; Fri, 13 Jul 2018 11:36:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=0SfbUdIAaNgOTbl9njp79hcC8Wv7UG54qNM01M4rhIY=; b=PGz2FvEwMBNjsjukiZhT/SevxgSFQ3G/5c8xEG+rJOgz4Y8bbQlHzN5VCm20pr4O1W UnmGuP1g6tqWCn+EVDD1C5NkppfzoUIAGl7/LRgneogSp164b7M3/AVekUwj/DdAPbkX TduR8SAkIBGWxBoZQ98T0oAzMHeipu2dxc1gRhH+1PD/TEPPjygMklKiun7phCeBOIcF xKTf6fOnQ5kAs4Oeuk4n92WNSzGeWsvO//ln8b56K4NqbNFXgIooCSAMAPTrXHa5CqOt ceagQGp2JvThNPGp0FOsFXSypcKzf2f77hj4gL6Yguypy1PHaPq+d0X+XDrMcuHKo9r0 EF0Q== X-Gm-Message-State: AOUpUlGPhw14d9EkeyQDJ4zrBYcb+vNQF4oBttN79f6oU/V8aQjVpMtN ame13pUHlqJDc/HbHGDrTsFJADbegDQ= X-Google-Smtp-Source: AAOMgpdgw2efm+aBPR0DP4wLK7mVCaBlPuDYtAyMDw0H6qREY7ZYrgHFk6hvknRHkbzuspgdIYZJkg== X-Received: by 2002:a1c:2442:: with SMTP id k63-v6mr4345584wmk.7.1531506987373; Fri, 13 Jul 2018 11:36:27 -0700 (PDT) Received: from redhat.com (218.red-2-136-166.dynamicip.rima-tde.net. [2.136.166.218]) by smtp.gmail.com with ESMTPSA id e13-v6sm47940877wrd.9.2018.07.13.11.36.26 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Jul 2018 11:36:26 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Fri, 13 Jul 2018 20:36:08 +0200 Message-Id: <20180713183624.16937-2-jkbs@redhat.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180713183624.16937-1-jkbs@redhat.com> References: <20180713183624.16937-1-jkbs@redhat.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE 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 v3 01/17] table: Introduce a constant for default table style. 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 Having a constant in addition to the constant expression for the default table style allows us to reset 'struct table_style' variables to default style. Signed-off-by: Jakub Sitnicki --- lib/table.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/table.h b/lib/table.h index 313ac1dd2..76e65bb70 100644 --- a/lib/table.h +++ b/lib/table.h @@ -20,6 +20,7 @@ #include #include #include "compiler.h" +#include "openvswitch/json.h" struct ds; struct table_style; @@ -83,6 +84,7 @@ struct table_style { }; #define TABLE_STYLE_DEFAULT { TF_LIST, CF_STRING, true, JSSF_SORT, 0 } +static const struct table_style table_style_default = TABLE_STYLE_DEFAULT; #define TABLE_OPTION_ENUMS \ OPT_NO_HEADINGS, \ From patchwork Fri Jul 13 18:36:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 943765 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 41S1kZ6NgFz9s0n for ; Sat, 14 Jul 2018 04:37:26 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 4DFC9E21; Fri, 13 Jul 2018 18:36:32 +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 E25AADB3 for ; Fri, 13 Jul 2018 18:36:30 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 64B8C7B0 for ; Fri, 13 Jul 2018 18:36:30 +0000 (UTC) Received: by mail-wr1-f68.google.com with SMTP id r16-v6so26006561wrt.11 for ; Fri, 13 Jul 2018 11:36:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wuT3+IW4vYRIuBgOmE2eoHhtP2E6vL8N5bb7cDqebec=; b=Ldu9dYRulhpj8j9yMEjmNK7d29YjNDTNIvAfnnztUowUKafJsirbqkKX5h5mUOk1Dh EbM3IXwuxW+DwwUyFHsh4vzuFGemr1CXzhL1JOO2LQbbXNgoHox/XyC1A4XbG6kaTBhe yl1mBcOw9EnX0x+oy4cEqsjR/DAJbgcAg5w7U/wYQqoqtxHiMH4jurGv8Cc5lmGCV6Us bUMhwjkp4eZ5gjDRsTi3CYJc3YKoYYKkGiwBMstnjki+63PIGHB7fhG95y2QZN+iBvBK uSjNhpcpGWyViFowsUr0K0A5WlOZSgHOrZpapfGr6T6vLwVSuwKVjVWm4ndfzF9wimIZ acLg== X-Gm-Message-State: AOUpUlFHP/uKzXfNHio5CiHaSihCURTmhBd1ms2lkCGAdbG2mRRg1ufl CfzGS4gaBJva00hj4pfCCNtPwGiAe2o= X-Google-Smtp-Source: AAOMgpcQMvRWaOsolp/tMiDTNh/+LBCbdWwSJs29MYjjglI17Gz1vJDHGeWVL6yxRoUxJnHThr1EsA== X-Received: by 2002:a5d:4007:: with SMTP id n7-v6mr5964949wrp.258.1531506988849; Fri, 13 Jul 2018 11:36:28 -0700 (PDT) Received: from redhat.com (218.red-2-136-166.dynamicip.rima-tde.net. [2.136.166.218]) by smtp.gmail.com with ESMTPSA id u135-v6sm6696459wmf.2.2018.07.13.11.36.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Jul 2018 11:36:28 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Fri, 13 Jul 2018 20:36:09 +0200 Message-Id: <20180713183624.16937-3-jkbs@redhat.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180713183624.16937-1-jkbs@redhat.com> References: <20180713183624.16937-1-jkbs@redhat.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE 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 v3 02/17] ovsdb-idl: Allow monitoring columns that are already monitored. 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 If IDL was created with monitoring and alerts turned on by default for all columns, then there is no harm in allowing the API users to ask again for monitoring and alerts to be enabled for any given column. This allows us to run prerequisites handlers for db-ctl and ovn-nbctl commands once the IDL has already ran once. Signed-off-by: Jakub Sitnicki --- lib/ovsdb-idl.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c index 9ab5d6723..ae0a55c3a 100644 --- a/lib/ovsdb-idl.c +++ b/lib/ovsdb-idl.c @@ -1116,6 +1116,20 @@ ovsdb_idl_db_get_mode(struct ovsdb_idl_db *db, return &table->modes[column - table->class_->columns]; } +static void +ovsdb_idl_db_set_mode(struct ovsdb_idl_db *db, + const struct ovsdb_idl_column *column, + unsigned char mode) +{ + const struct ovsdb_idl_table *table = ovsdb_idl_table_from_column(db, + column); + size_t column_idx = column - table->class_->columns; + + if (table->modes[column_idx] != mode) { + *ovsdb_idl_db_get_mode(db, column) = mode; + } +} + static void add_ref_table(struct ovsdb_idl_db *db, const struct ovsdb_base_type *base) { @@ -1136,7 +1150,7 @@ static void ovsdb_idl_db_add_column(struct ovsdb_idl_db *db, const struct ovsdb_idl_column *column) { - *ovsdb_idl_db_get_mode(db, column) = OVSDB_IDL_MONITOR | OVSDB_IDL_ALERT; + ovsdb_idl_db_set_mode(db, column, OVSDB_IDL_MONITOR | OVSDB_IDL_ALERT); add_ref_table(db, &column->type.key); add_ref_table(db, &column->type.value); } From patchwork Fri Jul 13 18:36:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 943766 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 41S1l757sLz9s0n for ; Sat, 14 Jul 2018 04:37:55 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 1BFB4E29; Fri, 13 Jul 2018 18:36:34 +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 604E2E27 for ; Fri, 13 Jul 2018 18:36:32 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wm0-f41.google.com (mail-wm0-f41.google.com [74.125.82.41]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id D27647B3 for ; Fri, 13 Jul 2018 18:36:31 +0000 (UTC) Received: by mail-wm0-f41.google.com with SMTP id h20-v6so10179639wmb.4 for ; Fri, 13 Jul 2018 11:36:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=eW8QL+SA2oAIAVJJouqT1NLBQS16FoZ7pTl+jdQBoDM=; b=rz06ekZIH0uuWUuA/5d9iZZvyPuKINeEZtkolZ7BH0GzXCROuo3ayjLt8Mc7WAAc9Y H9CEXvZu4109MCYVr+mMg5vTivLhq5Otp7DZH1JkLaRAPf35KKtDguZNVZEpQ79QZcmA kpGOy6O77oi90Z10kf953cejn74mMYl4CpkHo9rnIagGKcmc4sCvAycyL3fnmnX4tKNg SfJF8bVsXwuNvVC/tGdl+2skwMFIC/98m5q7Kke+Pp6w4ude72aUM2vpCYPMzWtDYZCv rx2aLzWp8JBNSPM8BsQc9vi/i0IuczC+1lhj/AnKSI4QMcAwX8VYbZWNM1n9m7ilygWM zifg== X-Gm-Message-State: AOUpUlGymNlfAJ9WY7VC7L9fSONtrdvnHpzmdYDGzZ26A0+6SckmlOeW eUZVdjorn+2Zr5dtGKHTRnXAMjc4O8o= X-Google-Smtp-Source: AAOMgpfdLQ9GGC2hEeplDi4rxPUahHaAlESNCgpX/dSr0KCjqtG8TUt3fAX07kADBanamvX7buGhzQ== X-Received: by 2002:a1c:c1c8:: with SMTP id r191-v6mr1678560wmf.103.1531506990275; Fri, 13 Jul 2018 11:36:30 -0700 (PDT) Received: from redhat.com (218.red-2-136-166.dynamicip.rima-tde.net. [2.136.166.218]) by smtp.gmail.com with ESMTPSA id t124-v6sm5833619wmf.37.2018.07.13.11.36.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Jul 2018 11:36:29 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Fri, 13 Jul 2018 20:36:10 +0200 Message-Id: <20180713183624.16937-4-jkbs@redhat.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180713183624.16937-1-jkbs@redhat.com> References: <20180713183624.16937-1-jkbs@redhat.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE 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 v3 03/17] ovn-nbctl: Extract the main loop. 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 Split out a routine for the main ovn-nbctl loop. Preparatory work for introducing daemon mode. Signed-off-by: Jakub Sitnicki --- ovn/utilities/ovn-nbctl.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index 47df19b23..a027553b7 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -88,6 +88,8 @@ static bool do_nbctl(const char *args, struct ctl_command *, size_t n, struct ovsdb_idl *); static const struct nbrec_dhcp_options *dhcp_options_get( struct ctl_context *ctx, const char *id, bool must_exist); +static void main_loop(const char *args, struct ctl_command *commands, + size_t n_commands, struct ovsdb_idl *idl); int main(int argc, char *argv[]) @@ -95,7 +97,6 @@ main(int argc, char *argv[]) struct ovsdb_idl *idl; struct ctl_command *commands; struct shash local_options; - unsigned int seqno; size_t n_commands; set_program_name(argv[0]); @@ -123,6 +124,18 @@ main(int argc, char *argv[]) ovsdb_idl_set_leader_only(idl, leader_only); run_prerequisites(commands, n_commands, idl); + main_loop(args, commands, n_commands, idl); + + free(args); + exit(EXIT_SUCCESS); +} + +static void +main_loop(const char *args, struct ctl_command *commands, size_t n_commands, + struct ovsdb_idl *idl) +{ + unsigned int seqno; + /* Execute the commands. * * 'seqno' is the database sequence number for which we last tried to @@ -136,14 +149,13 @@ main(int argc, char *argv[]) if (!ovsdb_idl_is_alive(idl)) { int retval = ovsdb_idl_get_last_error(idl); ctl_fatal("%s: database connection failed (%s)", - db, ovs_retval_to_string(retval)); + db, ovs_retval_to_string(retval)); } if (seqno != ovsdb_idl_get_seqno(idl)) { seqno = ovsdb_idl_get_seqno(idl); if (do_nbctl(args, commands, n_commands, idl)) { - free(args); - exit(EXIT_SUCCESS); + return; } } From patchwork Fri Jul 13 18:36:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 943767 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 41S1lf3xLcz9s0n for ; Sat, 14 Jul 2018 04:38:22 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id C7207E32; Fri, 13 Jul 2018 18:36:36 +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 0A758DE1 for ; Fri, 13 Jul 2018 18:36:34 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 8E3217B2 for ; Fri, 13 Jul 2018 18:36:33 +0000 (UTC) Received: by mail-wr1-f42.google.com with SMTP id b15-v6so26052889wrv.10 for ; Fri, 13 Jul 2018 11:36:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6+pIEnsjDbhPX4E+KjQ2Ks5ojGlh1XccI7EgGwqUzm8=; b=qZUggKFrVbvz8yH2cPnxtXNFaKLm+p9fSBXFbaK2Q2uAfQt6JcTwO2ebL3C5JKT7Wj fXZGCBEtFJVSlmO8KzHfEjn+qgWMfPSop98Yo9y1ASNbLOnvlsEtwWGUW+9w8+2581rw xHleswyqDmAvdQphrIDzH/WFuxPmwYWpppCOYaK+t9xyahZN8den0GQLNlwMocVy5pi5 X4PILu1VJUszvrDxlWQK7Egygqve6pZinBATtTbRJ0tNFOWyYsWW0SRLYodE26vQnTAM m1FTaBdKnPMXCjCti31yRQNAPsp8QV2VOIre6AAERSE/U53oqxOwRPf0OzN10q6yqcHu bBqg== X-Gm-Message-State: AOUpUlEYY07huKWbz3bVOdsCA+ZWVRVjLdgbCegrMR9JNFrI+bMjb2dS xkqQ05pZYJg2VKVPtVV+6gmAw2FIcNc= X-Google-Smtp-Source: AAOMgpdfxJrbaLzRWQnXF+Fp8ErxvVBuzOdNlQoJEqXsjyxVzcoKnm5lQi5lhoXpKuwsFL1kG0WkKw== X-Received: by 2002:adf:8541:: with SMTP id 59-v6mr5413308wrh.223.1531506992016; Fri, 13 Jul 2018 11:36:32 -0700 (PDT) Received: from redhat.com (218.red-2-136-166.dynamicip.rima-tde.net. [2.136.166.218]) by smtp.gmail.com with ESMTPSA id f133-v6sm6355209wme.42.2018.07.13.11.36.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Jul 2018 11:36:31 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Fri, 13 Jul 2018 20:36:11 +0200 Message-Id: <20180713183624.16937-5-jkbs@redhat.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180713183624.16937-1-jkbs@redhat.com> References: <20180713183624.16937-1-jkbs@redhat.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE 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 v3 04/17] ovn-nbctl: Pull up destroying commands from do_nbctl(). 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 Destroy commands in the same routine where they were allocated. Preparatory work for reusing the main loop in daemon mode. Signed-off-by: Jakub Sitnicki --- ovn/utilities/ovn-nbctl.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index a027553b7..51527741b 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -126,6 +126,13 @@ main(int argc, char *argv[]) main_loop(args, commands, n_commands, idl); + for (struct ctl_command *c = commands; c < &commands[n_commands]; c++) { + ds_destroy(&c->output); + table_destroy(c->table); + free(c->table); + shash_destroy_free_data(&c->options); + } + free(commands); free(args); exit(EXIT_SUCCESS); } @@ -4271,13 +4278,7 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, } else { fputs(ds_cstr(ds), stdout); } - ds_destroy(&c->output); - table_destroy(c->table); - free(c->table); - - shash_destroy_free_data(&c->options); } - free(commands); if (wait_type != NBCTL_WAIT_NONE && status != TXN_UNCHANGED) { ovsdb_idl_enable_reconnect(idl); From patchwork Fri Jul 13 18:36:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 943768 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 41S1mM0cnNz9s0n for ; Sat, 14 Jul 2018 04:38:59 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id A9E97E3E; Fri, 13 Jul 2018 18:36:38 +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 5E755E2A for ; Fri, 13 Jul 2018 18:36:37 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wm0-f51.google.com (mail-wm0-f51.google.com [74.125.82.51]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 61F9E7B0 for ; Fri, 13 Jul 2018 18:36:35 +0000 (UTC) Received: by mail-wm0-f51.google.com with SMTP id z13-v6so10258511wma.5 for ; Fri, 13 Jul 2018 11:36:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=pxKWi5+pOX80hJROYOcWfAVOe/s4QnwiG4+fddWZ/Es=; b=l/pz6MFCqXFSsLUBsK+32TlpStoE/fFhBaOtKdjtPYaHeDWD/Z0LZA8PHeDUUQBQi7 /gtt9ZStFIcKCMGWWhFH5hyYuw+fA2uIHrMyiQBEl7YejRgTSdCQpeXRTB9CE59P1dM7 b1ZMjzgXDelJUqVR0j1d4ybJFxKtUxSjXdnrdP08le8b3+i8XuzvN5QhKCl2mewk5unM kOTl4SFV1rbZEnsEyjOeKGOt6y2G1r9RkE48SFIgPcxiOBFe5TYEV64UBNf8SFyCDgYm xGLehWN2seiUYy+VOqHhkjxBdWluHtz2+vr7yUcGzyGNo3JnvmAIHXY266Pa2Q8nc3yN ZU1Q== X-Gm-Message-State: AOUpUlHtLQ01UF7sYuOyubtsn9AfeD5iquEe42O35p6QSdsY/srbqQMB 183u4oE7cC2EjcOPN7bsqJy++1+Oii8= X-Google-Smtp-Source: AAOMgpfM6CswnP5uwxr+LWa31vNvTp3MNccuokgHNs6oQVk/TsFhzt1sLzMRuFrbmme9WXDXvgrCCQ== X-Received: by 2002:a1c:7d58:: with SMTP id y85-v6mr4429223wmc.91.1531506993818; Fri, 13 Jul 2018 11:36:33 -0700 (PDT) Received: from redhat.com (218.red-2-136-166.dynamicip.rima-tde.net. [2.136.166.218]) by smtp.gmail.com with ESMTPSA id v190-v6sm9989716wme.21.2018.07.13.11.36.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Jul 2018 11:36:33 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Fri, 13 Jul 2018 20:36:12 +0200 Message-Id: <20180713183624.16937-6-jkbs@redhat.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180713183624.16937-1-jkbs@redhat.com> References: <20180713183624.16937-1-jkbs@redhat.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE 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 v3 05/17] ovn-nbctl: Pull up releasing IDL from do_nbctl(). 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 Destroy IDL resources in the routine where we allocated them. Preparatory work for reusing the main loop in daemon mode. Signed-off-by: Jakub Sitnicki --- ovn/utilities/ovn-nbctl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index 51527741b..a700695fe 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -126,6 +126,9 @@ main(int argc, char *argv[]) main_loop(args, commands, n_commands, idl); + ovsdb_idl_destroy(idl); + idl = the_idl = NULL; + for (struct ctl_command *c = commands; c < &commands[n_commands]; c++) { ds_destroy(&c->output); table_destroy(c->table); @@ -4299,7 +4302,6 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, } ovsdb_idl_txn_destroy(txn); - ovsdb_idl_destroy(idl); return true; From patchwork Fri Jul 13 18:36:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 943769 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 41S1mt3333z9s0n for ; Sat, 14 Jul 2018 04:39:26 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 6E0E5E3C; Fri, 13 Jul 2018 18:36:40 +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 185D7E04 for ; Fri, 13 Jul 2018 18:36:38 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id DDC4A7B2 for ; Fri, 13 Jul 2018 18:36:36 +0000 (UTC) Received: by mail-wr1-f50.google.com with SMTP id m1-v6so13283445wrg.5 for ; Fri, 13 Jul 2018 11:36:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+PQf2NbS8RkFzMyvsF7I/s0QkSSgaOO8vtEtXAbqO9s=; b=Zrn7ROPIRQ4QliL/JPqlRMD7i25GNSwXL5MrFTLJTb7BbQBgSbu1+ZeTNjtd5CrpUu QXhMHLfHN5iuyulQLHqJLsr5niL9jVBFGszKC3pk2cb8YtybE6tOe0hLUKt2O8kuBIAk BpSZ5PQ0fxM1JWmjgGXUL8rUMO2q3xGYpmIRN7jLsC/W6fpbVkHLhZ2RxmE6pYQwXRU3 x7vV6EkiIfH654jUb82LJ/T/m8tB2kdZT/ZyfGNqm1sLmQi/Y75ZCKM98qSZo4Nci+Ak 0SfuZtJs30+6Qxwr7ZrE8Y1sTaXeDMRXjmtRmCg584lRl6tXMQ8IEZTVjNqrrTdAmZIz DoIw== X-Gm-Message-State: AOUpUlGMRwbyRn9SwKvnzycym6L1o7SnhCdcGM0ln1E/Mrfwws9d+iqQ y4ExjVBFPiXk3BKwOeAG3AdSHnQzLe0= X-Google-Smtp-Source: AAOMgpfHELGOYQqy6+xRqPduu3RfB124qzOWr7LPHXqK7PuexLyoTA3oOUGi51SeQN/J1Cl2+3aAcw== X-Received: by 2002:adf:8f4a:: with SMTP id p68-v6mr5599355wrb.22.1531506995192; Fri, 13 Jul 2018 11:36:35 -0700 (PDT) Received: from redhat.com (218.red-2-136-166.dynamicip.rima-tde.net. [2.136.166.218]) by smtp.gmail.com with ESMTPSA id 63-v6sm5528224wmo.22.2018.07.13.11.36.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Jul 2018 11:36:34 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Fri, 13 Jul 2018 20:36:13 +0200 Message-Id: <20180713183624.16937-7-jkbs@redhat.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180713183624.16937-1-jkbs@redhat.com> References: <20180713183624.16937-1-jkbs@redhat.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE 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 v3 06/17] ovn-nbctl: Signal need to try again via an output param. 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 Introduce an output parameter for the flag that signals need to retry running the command. This leaves the return value for error reporting. Preparatory work for reusing the main loop in daemon mode. Signed-off-by: Jakub Sitnicki --- ovn/utilities/ovn-nbctl.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index a700695fe..360b25a89 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -84,8 +84,8 @@ OVS_NO_RETURN static void usage(void); static void parse_options(int argc, char *argv[], struct shash *local_options); static void run_prerequisites(struct ctl_command[], size_t n_commands, struct ovsdb_idl *); -static bool do_nbctl(const char *args, struct ctl_command *, size_t n, - struct ovsdb_idl *); +static void do_nbctl(const char *args, struct ctl_command *, size_t n, + struct ovsdb_idl *, bool *retry); static const struct nbrec_dhcp_options *dhcp_options_get( struct ctl_context *ctx, const char *id, bool must_exist); static void main_loop(const char *args, struct ctl_command *commands, @@ -164,7 +164,10 @@ main_loop(const char *args, struct ctl_command *commands, size_t n_commands, if (seqno != ovsdb_idl_get_seqno(idl)) { seqno = ovsdb_idl_get_seqno(idl); - if (do_nbctl(args, commands, n_commands, idl)) { + + bool retry; + do_nbctl(args, commands, n_commands, idl, &retry); + if (!retry) { return; } } @@ -4134,9 +4137,9 @@ run_prerequisites(struct ctl_command *commands, size_t n_commands, } } -static bool +static void do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, - struct ovsdb_idl *idl) + struct ovsdb_idl *idl, bool *retry) { struct ovsdb_idl_txn *txn; enum ovsdb_idl_txn_status status; @@ -4146,6 +4149,8 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, struct shash_node *node; int64_t next_cfg = 0; + ovs_assert(retry); + txn = the_idl_txn = ovsdb_idl_txn_create(idl); if (dry_run) { ovsdb_idl_txn_set_dry_run(txn); @@ -4303,7 +4308,8 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, ovsdb_idl_txn_destroy(txn); - return true; + *retry = false; + return; try_again: /* Our transaction needs to be rerun, or a prerequisite was not met. Free @@ -4318,7 +4324,7 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, table_destroy(c->table); free(c->table); } - return false; + *retry = true; } /* Frees the current transaction and the underlying IDL and then calls From patchwork Fri Jul 13 18:36:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 943770 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 41S1nN25CVz9s0n for ; Sat, 14 Jul 2018 04:39:52 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 2A5BDE48; Fri, 13 Jul 2018 18:36:42 +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 CB5F6E43 for ; Fri, 13 Jul 2018 18:36:39 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 963957B2 for ; Fri, 13 Jul 2018 18:36:38 +0000 (UTC) Received: by mail-wr1-f52.google.com with SMTP id m1-v6so13283512wrg.5 for ; Fri, 13 Jul 2018 11:36:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PVOT2BukTxFiIYIY9Bhpb+5zfNgWlYFWC44rgCeOj6c=; b=M/qyAzyr/Ba6H0QOjaYhSY3FhizfxWBJRf+qUchCMg4J0YhbWGDxT3i5BDFtRq+JIJ 4pA+Xcr0vP5pvFMRs94yRz/14wdAvPo5dcc6Ytj3NxGWeBFvcbD1VL3EYgy/CkjPKdLA 5VcA2ESDbThxFy5Fp8VttNbbIzBD8x23oO9JmGMUu9V1Ohf+tt3v5fFbCHx/o/j/zfdc 51p4gsqVBPKI5ECmdp2yeVbpP768THat9hYdEd6BENB3pemZ+BHcryh05J97rz7Lffxs CHouoMHSl69tVxQMn+YaInxMYXWoLjRGG8+xysgOttwyTDTok2psBWLQ7RttvZvw5bDW 6u3Q== X-Gm-Message-State: AOUpUlEHIh4+fLALsWDwq71/AjWaB8pi7q1ItdNEEwq75QVMSITixrNv 6PRWB2uasG3BinW7X82tn9lV7f7h+lc= X-Google-Smtp-Source: AAOMgpcxKOYGIasGnejNGafjN7jETB5nbcc+BekXOfyXp1H5pVvdxzm38mouLazHPKeS2RFJb6eCSQ== X-Received: by 2002:adf:9142:: with SMTP id j60-v6mr5495836wrj.180.1531506996948; Fri, 13 Jul 2018 11:36:36 -0700 (PDT) Received: from redhat.com (218.red-2-136-166.dynamicip.rima-tde.net. [2.136.166.218]) by smtp.gmail.com with ESMTPSA id s10-v6sm11532670wmb.12.2018.07.13.11.36.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Jul 2018 11:36:36 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Fri, 13 Jul 2018 20:36:14 +0200 Message-Id: <20180713183624.16937-8-jkbs@redhat.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180713183624.16937-1-jkbs@redhat.com> References: <20180713183624.16937-1-jkbs@redhat.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE 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 v3 07/17] ovn-nbctl: Propagate the error from do_nbctl(). 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 Instead of terminating the process, return the error to the caller. This will allow us to reuse the main loop in daemon mode. Signed-off-by: Jakub Sitnicki --- ovn/utilities/ovn-nbctl.c | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index 360b25a89..6e136e1d0 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -84,8 +84,9 @@ OVS_NO_RETURN static void usage(void); static void parse_options(int argc, char *argv[], struct shash *local_options); static void run_prerequisites(struct ctl_command[], size_t n_commands, struct ovsdb_idl *); -static void do_nbctl(const char *args, struct ctl_command *, size_t n, - struct ovsdb_idl *, bool *retry); +static char * OVS_WARN_UNUSED_RESULT do_nbctl(const char *args, + struct ctl_command *, size_t n, + struct ovsdb_idl *, bool *retry); static const struct nbrec_dhcp_options *dhcp_options_get( struct ctl_context *ctx, const char *id, bool must_exist); static void main_loop(const char *args, struct ctl_command *commands, @@ -166,7 +167,10 @@ main_loop(const char *args, struct ctl_command *commands, size_t n_commands, seqno = ovsdb_idl_get_seqno(idl); bool retry; - do_nbctl(args, commands, n_commands, idl, &retry); + char *error = do_nbctl(args, commands, n_commands, idl, &retry); + if (error) { + ctl_fatal("%s", error); + } if (!retry) { return; } @@ -4137,7 +4141,7 @@ run_prerequisites(struct ctl_command *commands, size_t n_commands, } } -static void +static char * do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, struct ovsdb_idl *idl, bool *retry) { @@ -4148,6 +4152,7 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, struct ctl_command *c; struct shash_node *node; int64_t next_cfg = 0; + char *error = NULL; ovs_assert(retry); @@ -4181,7 +4186,9 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, (c->syntax->run)(&ctx); } if (ctx.error) { - ctl_fatal("%s", ctx.error); + error = xstrdup(ctx.error); + ctl_context_done(&ctx, c); + goto out_error; } ctl_context_done_command(&ctx, c); @@ -4195,9 +4202,10 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, SHASH_FOR_EACH (node, &symtab->sh) { struct ovsdb_symbol *symbol = node->data; if (!symbol->created) { - ctl_fatal("row id \"%s\" is referenced but never created (e.g. " - "with \"-- --id=%s create ...\")", - node->name, node->name); + error = xasprintf("row id \"%s\" is referenced but never created " + "(e.g. with \"-- --id=%s create ...\")", + node->name, node->name); + goto out_error; } if (!symbol->strong_ref) { if (!symbol->weak_ref) { @@ -4222,7 +4230,9 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, ctl_context_init(&ctx, c, idl, txn, symtab, NULL); (c->syntax->postprocess)(&ctx); if (ctx.error) { - ctl_fatal("%s", ctx.error); + error = xstrdup(ctx.error); + ctl_context_done(&ctx, c); + goto out_error; } ctl_context_done(&ctx, c); } @@ -4236,7 +4246,8 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, case TXN_ABORTED: /* Should not happen--we never call ovsdb_idl_txn_abort(). */ - ctl_fatal("transaction aborted"); + error = xstrdup("transaction aborted"); + goto out_error; case TXN_UNCHANGED: case TXN_SUCCESS: @@ -4246,11 +4257,14 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, goto try_again; case TXN_ERROR: - ctl_fatal("transaction error: %s", ovsdb_idl_txn_get_error(txn)); + error = xasprintf("transaction error: %s", + ovsdb_idl_txn_get_error(txn)); + goto out_error; case TXN_NOT_LOCKED: /* Should not happen--we never call ovsdb_idl_set_lock(). */ - ctl_fatal("database not locked"); + error = xstrdup("database not locked"); + goto out_error; default: OVS_NOT_REACHED(); @@ -4309,11 +4323,14 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, ovsdb_idl_txn_destroy(txn); *retry = false; - return; + return NULL; try_again: /* Our transaction needs to be rerun, or a prerequisite was not met. Free * resources and return so that the caller can try again. */ + *retry = true; + +out_error: ovsdb_idl_txn_abort(txn); ovsdb_idl_txn_destroy(txn); the_idl_txn = NULL; @@ -4324,7 +4341,8 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, table_destroy(c->table); free(c->table); } - *retry = true; + + return error; } /* Frees the current transaction and the underlying IDL and then calls From patchwork Fri Jul 13 18:36:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 943771 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 41S1nn6hRRz9s0n for ; Sat, 14 Jul 2018 04:40:13 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id C8010E57; Fri, 13 Jul 2018 18:36:44 +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 9264FE48 for ; Fri, 13 Jul 2018 18:36:41 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wm0-f46.google.com (mail-wm0-f46.google.com [74.125.82.46]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 635E77B2 for ; Fri, 13 Jul 2018 18:36:40 +0000 (UTC) Received: by mail-wm0-f46.google.com with SMTP id s12-v6so9703618wmc.1 for ; Fri, 13 Jul 2018 11:36:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DS+vRToPFcrL1cxulJGQ0TJDm8UfBsmxjUVDtkhi6MM=; b=DMmiBV8RIHno6Z5cM3WZ67zwTUFEipFnTNGEGicSp92ZXEg2pMQxfjWRAyxBIl3UC9 pn0Ezc1757ygpGj8yEYmPS7ZNLFAgOy4zHRou4CHRFXl/sDPRgac8oRXLe8IrAlOGkA5 isQwMBIUcSi0RxtD73puFAGVWDD65j6/cShmF20ZxfW8lZ2KfHzTZknmU4OzWJ2sTIWt O0Y3C0lP/pml/hicziRxoIA+x/No6z1GmwCbQKCs/Ypt54jSBBMV2Y67PqZQIAt8JZqc Ux3Ki539PAlaK6ZCxaj7kqcGaD9s01TSFsGKP/92Oyyn2KvfmzjuQwgj584wqox22i9Y d2vw== X-Gm-Message-State: AOUpUlGan5LEAVeid4mAjRTLwuu+3E257Z/5Sk7F0wFDplZDcx8AWwYH tg9E88Cl37Ol9QEF9wbqgGZXR37vEHA= X-Google-Smtp-Source: AAOMgpd5CMuiw38AWwugM1jyNEk3AJLTT/Pb3jFWYUIiUa5sJjzT5mjFTkngTX47+kPbDLYM9uSUGw== X-Received: by 2002:a1c:7908:: with SMTP id l8-v6mr4425010wme.80.1531506998845; Fri, 13 Jul 2018 11:36:38 -0700 (PDT) Received: from redhat.com (218.red-2-136-166.dynamicip.rima-tde.net. [2.136.166.218]) by smtp.gmail.com with ESMTPSA id a145-v6sm8391157wmd.39.2018.07.13.11.36.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Jul 2018 11:36:38 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Fri, 13 Jul 2018 20:36:15 +0200 Message-Id: <20180713183624.16937-9-jkbs@redhat.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180713183624.16937-1-jkbs@redhat.com> References: <20180713183624.16937-1-jkbs@redhat.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE 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 v3 08/17] ovn-nbctl: Propagate errors from the main loop. 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 Let the caller handle the errors instead of reporting it and terminating. Prepare for reusing the main loop in daemon mode. Signed-off-by: Jakub Sitnicki --- ovn/utilities/ovn-nbctl.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index 6e136e1d0..747aa63b6 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -89,8 +89,10 @@ static char * OVS_WARN_UNUSED_RESULT do_nbctl(const char *args, struct ovsdb_idl *, bool *retry); static const struct nbrec_dhcp_options *dhcp_options_get( struct ctl_context *ctx, const char *id, bool must_exist); -static void main_loop(const char *args, struct ctl_command *commands, - size_t n_commands, struct ovsdb_idl *idl); +static char * OVS_WARN_UNUSED_RESULT main_loop(const char *args, + struct ctl_command *commands, + size_t n_commands, + struct ovsdb_idl *idl); int main(int argc, char *argv[]) @@ -125,7 +127,10 @@ main(int argc, char *argv[]) ovsdb_idl_set_leader_only(idl, leader_only); run_prerequisites(commands, n_commands, idl); - main_loop(args, commands, n_commands, idl); + char *error = main_loop(args, commands, n_commands, idl); + if (error) { + ctl_fatal("%s", error); + } ovsdb_idl_destroy(idl); idl = the_idl = NULL; @@ -141,7 +146,7 @@ main(int argc, char *argv[]) exit(EXIT_SUCCESS); } -static void +static char * main_loop(const char *args, struct ctl_command *commands, size_t n_commands, struct ovsdb_idl *idl) { @@ -169,10 +174,10 @@ main_loop(const char *args, struct ctl_command *commands, size_t n_commands, bool retry; char *error = do_nbctl(args, commands, n_commands, idl, &retry); if (error) { - ctl_fatal("%s", error); + return error; } if (!retry) { - return; + return NULL; } } @@ -181,6 +186,8 @@ main_loop(const char *args, struct ctl_command *commands, size_t n_commands, poll_block(); } } + + return NULL; } static void From patchwork Fri Jul 13 18:36:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 943772 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 41S1p54vKVz9s0n for ; Sat, 14 Jul 2018 04:40:29 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 71CD6DD1; Fri, 13 Jul 2018 18:36:45 +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 AFD90E4F for ; Fri, 13 Jul 2018 18:36:42 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wm0-f52.google.com (mail-wm0-f52.google.com [74.125.82.52]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 2C5047B2 for ; Fri, 13 Jul 2018 18:36:42 +0000 (UTC) Received: by mail-wm0-f52.google.com with SMTP id v25-v6so9698245wmc.0 for ; Fri, 13 Jul 2018 11:36:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XSiLMlQSkrr13ba23H0kZgB8E0U67NehF3mkbPyZeo4=; b=YlrqiBvdw3OcKqlh/1ir5ubHEdfx6LyPwDSWF3ssn42acjQK8uj9uGzScP4UqzemCM y/5vnBCSAWdYHvRF24MTaohSLVh/wivFiHfZV19Vlx36De9v0yEJB8ivUhSB4RGJnE1/ V2/sVnfoUUSc4nhHl6vS3ZwAxxYwsMy5YP1NaxHYRzMKGms6efG5dOnnGvnA4dmucCYr lZtPBoEk8xm2oQfkm3rRIDR+FcPbrKC6OdFrxi3fZkS89M5+PXENP7YlOvE8mCKqTcKN PJm3Nj9PBnFxofuUH+9WWWsF0O+s7kYwQFYPIg85SkD5xLRC365LqV1hAwTX9ZeQ+RDq Y8jA== X-Gm-Message-State: AOUpUlHqrHFOyEP9puzpmAMToKRqTSLQbI1FPt/fohNL/PG72LiSadt/ 0Js9LKrwnz1u1riEuWXXlTOjHZJmuVU= X-Google-Smtp-Source: AAOMgpcEAcit5iGAMP4B77fGyLljS2K1lMx7JSTHYtBxZb2plGTxlIS/A0A+G7JAGweRTcaWS1e0eg== X-Received: by 2002:a1c:c019:: with SMTP id q25-v6mr4533467wmf.148.1531507000617; Fri, 13 Jul 2018 11:36:40 -0700 (PDT) Received: from redhat.com (218.red-2-136-166.dynamicip.rima-tde.net. [2.136.166.218]) by smtp.gmail.com with ESMTPSA id z7-v6sm16830109wrh.85.2018.07.13.11.36.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Jul 2018 11:36:40 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Fri, 13 Jul 2018 20:36:16 +0200 Message-Id: <20180713183624.16937-10-jkbs@redhat.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180713183624.16937-1-jkbs@redhat.com> References: <20180713183624.16937-1-jkbs@redhat.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE 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 v3 09/17] ovn-nbctl: Propagate errors from prerequisites runner. 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 Instead of terminating the process, return the error to the caller. This will allow us to reuse the prerequisites runner in daemon mode. Signed-off-by: Jakub Sitnicki --- ovn/utilities/ovn-nbctl.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index 747aa63b6..154e7799a 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -82,8 +82,9 @@ static int leader_only = true; static void nbctl_cmd_init(void); OVS_NO_RETURN static void usage(void); static void parse_options(int argc, char *argv[], struct shash *local_options); -static void run_prerequisites(struct ctl_command[], size_t n_commands, - struct ovsdb_idl *); +static char * OVS_WARN_UNUSED_RESULT run_prerequisites(struct ctl_command[], + size_t n_commands, + struct ovsdb_idl *); static char * OVS_WARN_UNUSED_RESULT do_nbctl(const char *args, struct ctl_command *, size_t n, struct ovsdb_idl *, bool *retry); @@ -101,6 +102,7 @@ main(int argc, char *argv[]) struct ctl_command *commands; struct shash local_options; size_t n_commands; + char *error; set_program_name(argv[0]); fatal_ignore_sigpipe(); @@ -125,9 +127,12 @@ main(int argc, char *argv[]) /* Initialize IDL. */ idl = the_idl = ovsdb_idl_create(db, &nbrec_idl_class, true, false); ovsdb_idl_set_leader_only(idl, leader_only); - run_prerequisites(commands, n_commands, idl); + error = run_prerequisites(commands, n_commands, idl); + if (error) { + ctl_fatal("%s", error); + } - char *error = main_loop(args, commands, n_commands, idl); + error = main_loop(args, commands, n_commands, idl); if (error) { ctl_fatal("%s", error); } @@ -4117,7 +4122,7 @@ static const struct ctl_table_class tables[NBREC_N_TABLES] = { [NBREC_TABLE_ACL].row_ids[0] = {&nbrec_acl_col_name, NULL, NULL}, }; -static void +static char * run_prerequisites(struct ctl_command *commands, size_t n_commands, struct ovsdb_idl *idl) { @@ -4138,7 +4143,9 @@ run_prerequisites(struct ctl_command *commands, size_t n_commands, ctl_context_init(&ctx, c, idl, NULL, NULL, NULL); (c->syntax->prerequisites)(&ctx); if (ctx.error) { - ctl_fatal("%s", ctx.error); + char *error = xstrdup(ctx.error); + ctl_context_done(&ctx, c); + return error; } ctl_context_done(&ctx, c); @@ -4146,6 +4153,8 @@ run_prerequisites(struct ctl_command *commands, size_t n_commands, ovs_assert(!c->table); } } + + return NULL; } static char * From patchwork Fri Jul 13 18:36:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 943773 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 41S1ph36gKz9s0n for ; Sat, 14 Jul 2018 04:41:00 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 28649E53; Fri, 13 Jul 2018 18:36:46 +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 69535E3F for ; Fri, 13 Jul 2018 18:36:44 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id CED487B4 for ; Fri, 13 Jul 2018 18:36:43 +0000 (UTC) Received: by mail-wr1-f49.google.com with SMTP id s11-v6so26008345wra.13 for ; Fri, 13 Jul 2018 11:36:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WuMrQQB9HPGhcqwstHJimbLvwY1mJxoslq7hNt+99wQ=; b=c3po2wAOmcubPeo62k/Jo9lSQdthNY0G8gKoRQ+ckUl1KdGa6YVDkYgcJNBXzPlBro aBB/YvNyUZgNDQ2U5XzbN6fi0gPtmaUTOjy1Ee4WFvzs+XoHaxWh5XkdjOBxFYGChZr3 NPbRM3VNNz+ufjfj9ckQC2IF7Vd+Ga8hDaf8PrfgeRSDZsXM+RhDfLG/6hd6aqPfNLqM fpQKe8sQrERxZPWEvFFD5yTRWc5Ap1oF9tF9AqQ1MVQUcMsprux6Ccv7P4OBxdWJoc7Y 2ErPTsG72JsvB6S0a92S1RjCOIeXUkFA9i415i+fa8ZdXS666GssKT6pY07Ge/FHHHLd xerA== X-Gm-Message-State: AOUpUlG1qCfY0XWR9QwZBFLWfGLYSobMGL3OESq484h7+mSqYcrwtZWB ackJz9u3StGTcQq3YgCaiTYp1K49efs= X-Google-Smtp-Source: AAOMgpc4CxyvcNrWw7WLbiOEY9MIbYI3q82BKUEwLDgFYtGXSReSHXO4vI1RShioOMVcC1+wxLaFsQ== X-Received: by 2002:a5d:4306:: with SMTP id h6-v6mr5850471wrq.58.1531507002282; Fri, 13 Jul 2018 11:36:42 -0700 (PDT) Received: from redhat.com (218.red-2-136-166.dynamicip.rima-tde.net. [2.136.166.218]) by smtp.gmail.com with ESMTPSA id y5-v6sm15628155wrs.86.2018.07.13.11.36.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Jul 2018 11:36:41 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Fri, 13 Jul 2018 20:36:17 +0200 Message-Id: <20180713183624.16937-11-jkbs@redhat.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180713183624.16937-1-jkbs@redhat.com> References: <20180713183624.16937-1-jkbs@redhat.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE 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 v3 10/17] ovn-nbctl: Introduce a poll_timer based wait timeout. 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 Extend the main loop and the command runner so that the caller can specify a timeout for poll_block(). This will allow us to break out of the main loop when waiting on IDL, like in the blocked '--wait=sb/hv sync' case. Signed-off-by: Jakub Sitnicki --- ovn/utilities/ovn-nbctl.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index 154e7799a..7f83abc40 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -37,6 +37,7 @@ #include "svec.h" #include "table.h" #include "timeval.h" +#include "timer.h" #include "util.h" #include "openvswitch/vlog.h" @@ -87,13 +88,16 @@ static char * OVS_WARN_UNUSED_RESULT run_prerequisites(struct ctl_command[], struct ovsdb_idl *); static char * OVS_WARN_UNUSED_RESULT do_nbctl(const char *args, struct ctl_command *, size_t n, - struct ovsdb_idl *, bool *retry); + struct ovsdb_idl *, + const struct timer *, + bool *retry); static const struct nbrec_dhcp_options *dhcp_options_get( struct ctl_context *ctx, const char *id, bool must_exist); static char * OVS_WARN_UNUSED_RESULT main_loop(const char *args, struct ctl_command *commands, size_t n_commands, - struct ovsdb_idl *idl); + struct ovsdb_idl *idl, + const struct timer *); int main(int argc, char *argv[]) @@ -132,7 +136,7 @@ main(int argc, char *argv[]) ctl_fatal("%s", error); } - error = main_loop(args, commands, n_commands, idl); + error = main_loop(args, commands, n_commands, idl, NULL); if (error) { ctl_fatal("%s", error); } @@ -153,7 +157,7 @@ main(int argc, char *argv[]) static char * main_loop(const char *args, struct ctl_command *commands, size_t n_commands, - struct ovsdb_idl *idl) + struct ovsdb_idl *idl, const struct timer *wait_timeout) { unsigned int seqno; @@ -177,7 +181,8 @@ main_loop(const char *args, struct ctl_command *commands, size_t n_commands, seqno = ovsdb_idl_get_seqno(idl); bool retry; - char *error = do_nbctl(args, commands, n_commands, idl, &retry); + char *error = do_nbctl(args, commands, n_commands, idl, + wait_timeout, &retry); if (error) { return error; } @@ -4159,7 +4164,7 @@ run_prerequisites(struct ctl_command *commands, size_t n_commands, static char * do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, - struct ovsdb_idl *idl, bool *retry) + struct ovsdb_idl *idl, const struct timer *wait_timeout, bool *retry) { struct ovsdb_idl_txn *txn; enum ovsdb_idl_txn_status status; @@ -4286,8 +4291,6 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, OVS_NOT_REACHED(); } - ovsdb_symbol_table_destroy(symtab); - for (c = commands; c < &commands[n_commands]; c++) { struct ds *ds = &c->output; @@ -4331,11 +4334,19 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, } } ovsdb_idl_wait(idl); + if (wait_timeout) { + timer_wait(wait_timeout); + } poll_block(); + if (wait_timeout && timer_expired(wait_timeout)) { + error = xstrdup("timeout expired"); + goto out_error; + } } done: ; } + ovsdb_symbol_table_destroy(symtab); ovsdb_idl_txn_destroy(txn); *retry = false; From patchwork Fri Jul 13 18:36:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 943774 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 41S1q74SMJz9s0n for ; Sat, 14 Jul 2018 04:41:23 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id E23D4E63; Fri, 13 Jul 2018 18:36:47 +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 61C36E5D for ; Fri, 13 Jul 2018 18:36:46 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 80D3D7BB for ; Fri, 13 Jul 2018 18:36:45 +0000 (UTC) Received: by mail-wr1-f47.google.com with SMTP id q10-v6so26006703wrd.4 for ; Fri, 13 Jul 2018 11:36:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7inGvLT4xTVfZkr51qX57I+CItNdf29qG5qE/A2NhvE=; b=aKpSCZtJyDUWsef+VuIBZqmUcBds6Ci/8s5dhUuXcJSKxTMWIARZ/ctAAMB+bX6o9D rhCucRNyQV9aVqYbpc6LiPeOB1vZtbPQRwJeXV/dtT5qvMGvjARoPwlbBcIHzSqwZZzN /Z/B5Z4LosSiFmaCXaMqIEHBReEEtdnSHQR05GbZEiYeUITsU/8HJaQjBSRfTHmW/522 ZBp+biju+G2OYleT0cpV+j/4hBVgfhDSvRgY6O6VICmekz9c7NV1EnXDrYH4tYw+53ey +szWIs0xl2UOUV7KffiBmrhtpt8XUkP0HOBoLcEPw9YSOki1Rm4NsUuTVmqM5seimiLI KbSA== X-Gm-Message-State: AOUpUlEiC3ErbQqXWVNSgzsPXUj5PKtYTJxr0M44AkeA6w9J6P+YVF6y Js7LLpw9hNiqhHs+fqqjPnxWQnOQtvk= X-Google-Smtp-Source: AAOMgpdvC5caF/OKoGzhs12x0FMTHif59+Ey7jEvBr2Mb58M01JYbkBou6gUBphU89uQN19s3aiLAA== X-Received: by 2002:adf:97d5:: with SMTP id t21-v6mr6046025wrb.28.1531507003991; Fri, 13 Jul 2018 11:36:43 -0700 (PDT) Received: from redhat.com (218.red-2-136-166.dynamicip.rima-tde.net. [2.136.166.218]) by smtp.gmail.com with ESMTPSA id s16-v6sm20463697wrq.20.2018.07.13.11.36.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Jul 2018 11:36:43 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Fri, 13 Jul 2018 20:36:18 +0200 Message-Id: <20180713183624.16937-12-jkbs@redhat.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180713183624.16937-1-jkbs@redhat.com> References: <20180713183624.16937-1-jkbs@redhat.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE 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 v3 11/17] ovn-nbctl: Extract helper for printing oneline output. 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 This will allow us to direct oneline-formatted output to other sinks than stdout if needed. Preparatory work for daemon mode. Signed-off-by: Jakub Sitnicki --- ovn/utilities/ovn-nbctl.c | 53 ++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index 7f83abc40..3dd24d193 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -4162,6 +4162,39 @@ run_prerequisites(struct ctl_command *commands, size_t n_commands, return NULL; } +static void +oneline_format(struct ds *lines, struct ds *s) +{ + size_t j; + + ds_chomp(lines, '\n'); + for (j = 0; j < lines->length; j++) { + int ch = lines->string[j]; + switch (ch) { + case '\n': + ds_put_cstr(s, "\\n"); + break; + + case '\\': + ds_put_cstr(s, "\\\\"); + break; + + default: + ds_put_char(s, ch); + } + } + ds_put_char(s, '\n'); +} + +static void +oneline_print(struct ds *lines) +{ + struct ds s = DS_EMPTY_INITIALIZER; + oneline_format(lines, &s); + fputs(ds_cstr(&s), stdout); + ds_destroy(&s); +} + static char * do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, struct ovsdb_idl *idl, const struct timer *wait_timeout, bool *retry) @@ -4297,25 +4330,7 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, if (c->table) { table_print(c->table, &table_style); } else if (oneline) { - size_t j; - - ds_chomp(ds, '\n'); - for (j = 0; j < ds->length; j++) { - int ch = ds->string[j]; - switch (ch) { - case '\n': - fputs("\\n", stdout); - break; - - case '\\': - fputs("\\\\", stdout); - break; - - default: - putchar(ch); - } - } - putchar('\n'); + oneline_print(ds); } else { fputs(ds_cstr(ds), stdout); } From patchwork Fri Jul 13 18:36:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 943775 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 41S1qn3hJrz9s0n for ; Sat, 14 Jul 2018 04:41:57 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id C9F82E66; Fri, 13 Jul 2018 18:36:49 +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 15F22DD9 for ; Fri, 13 Jul 2018 18:36:48 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 649DF7B4 for ; Fri, 13 Jul 2018 18:36:47 +0000 (UTC) Received: by mail-wm0-f65.google.com with SMTP id s12-v6so9703847wmc.1 for ; Fri, 13 Jul 2018 11:36:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=agbjjLDV1yJLlWvDI+6e6pjh71dTSMtD1304HouP4NY=; b=jNg1IneAR0Fc35YSDn+w+d//+usm77ecat+5IzOCDILna7P0vXQhsQIYYD4sue0yVQ Djc/gaS0x6VB5eF33VgG6z3km1g8BZ5XpdnTyOWvYPRQo8TIUKRwiDxToPIGbXfbZxkq acFZCYzHGH183o3v5HUl+16uwsw+A5XCm580rZHd3nHZT2s5i1v+f6e6UStMbaYpP0Rb yNchAGP+ETvd+eN8Ng73fsjLvBPNhXw/qkJGoz90K4ncm8dI/he2CpdRbvvRb4MwX/Cb HMdMBZWpwUt2ENVbQm+11fAFjGi4fI8KBQY6pWF/nlUNsj1xC/dd0+4F5TXagYWputv0 cYNQ== X-Gm-Message-State: AOUpUlFmRpv3Aj1XYyZ7D05EWYMrwSy3mONmWYoHBUcHKNcrsM2tKIBe H+MVNDQWfu489NBFB9D4u0H30DEJfRM= X-Google-Smtp-Source: AAOMgpdAdrE7tgR6acwzIO2ATzuay64nD8h6Srnpzv0XUGITEjxYaRM5jCWEobPtkQvFGPZYnhuLOg== X-Received: by 2002:a1c:d946:: with SMTP id q67-v6mr4467228wmg.156.1531507005821; Fri, 13 Jul 2018 11:36:45 -0700 (PDT) Received: from redhat.com (218.red-2-136-166.dynamicip.rima-tde.net. [2.136.166.218]) by smtp.gmail.com with ESMTPSA id h61-v6sm11276357wrh.18.2018.07.13.11.36.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Jul 2018 11:36:45 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Fri, 13 Jul 2018 20:36:19 +0200 Message-Id: <20180713183624.16937-13-jkbs@redhat.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180713183624.16937-1-jkbs@redhat.com> References: <20180713183624.16937-1-jkbs@redhat.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE 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 v3 12/17] ovn-nbctl: Extract handling of options that affect main loop. 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 Provide a handler for options that change how the main loop behaves. This will allow code reuse for option parsing in daemon mode. Signed-off-by: Jakub Sitnicki --- ovn/utilities/ovn-nbctl.c | 136 ++++++++++++++++++++++++++++------------------ 1 file changed, 84 insertions(+), 52 deletions(-) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index 3dd24d193..72c78795c 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -200,38 +200,93 @@ main_loop(const char *args, struct ctl_command *commands, size_t n_commands, return NULL; } +/* All options that affect the main loop and are not external. */ +#define MAIN_LOOP_OPTION_ENUMS \ + OPT_NO_WAIT, \ + OPT_WAIT, \ + OPT_DRY_RUN, \ + OPT_ONELINE + +#define MAIN_LOOP_LONG_OPTIONS \ + {"no-wait", no_argument, NULL, OPT_NO_WAIT}, \ + {"wait", required_argument, NULL, OPT_WAIT}, \ + {"dry-run", no_argument, NULL, OPT_DRY_RUN}, \ + {"oneline", no_argument, NULL, OPT_ONELINE}, \ + {"timeout", required_argument, NULL, 't'} + +enum { + OPT_DB = UCHAR_MAX + 1, + OPT_NO_SYSLOG, + OPT_LOCAL, + OPT_COMMANDS, + OPT_OPTIONS, + OPT_BOOTSTRAP_CA_CERT, + MAIN_LOOP_OPTION_ENUMS, + VLOG_OPTION_ENUMS, + TABLE_OPTION_ENUMS, + SSL_OPTION_ENUMS, +}; + +static char * OVS_WARN_UNUSED_RESULT +handle_main_loop_option(int opt, const char *arg, bool *handled) +{ + ovs_assert(handled); + *handled = true; + + switch (opt) { + case OPT_ONELINE: + oneline = true; + break; + + case OPT_NO_WAIT: + wait_type = NBCTL_WAIT_NONE; + break; + + case OPT_WAIT: + if (!strcmp(arg, "none")) { + wait_type = NBCTL_WAIT_NONE; + } else if (!strcmp(arg, "sb")) { + wait_type = NBCTL_WAIT_SB; + } else if (!strcmp(arg, "hv")) { + wait_type = NBCTL_WAIT_HV; + } else { + return xstrdup("argument to --wait must be " + "\"none\", \"sb\", or \"hv\""); + } + break; + + case OPT_DRY_RUN: + dry_run = true; + break; + + case 't': + timeout = strtoul(arg, NULL, 10); + if (timeout < 0) { + return xasprintf("value %s on -t or --timeout is invalid", arg); + } + break; + + default: + *handled = false; + break; + } + + return NULL; +} + static void parse_options(int argc, char *argv[], struct shash *local_options) { - enum { - OPT_DB = UCHAR_MAX + 1, - OPT_NO_SYSLOG, - OPT_NO_WAIT, - OPT_WAIT, - OPT_DRY_RUN, - OPT_ONELINE, - OPT_LOCAL, - OPT_COMMANDS, - OPT_OPTIONS, - OPT_BOOTSTRAP_CA_CERT, - VLOG_OPTION_ENUMS, - TABLE_OPTION_ENUMS, - SSL_OPTION_ENUMS, - }; static const struct option global_long_options[] = { {"db", required_argument, NULL, OPT_DB}, {"no-syslog", no_argument, NULL, OPT_NO_SYSLOG}, - {"no-wait", no_argument, NULL, OPT_NO_WAIT}, - {"wait", required_argument, NULL, OPT_WAIT}, - {"dry-run", no_argument, NULL, OPT_DRY_RUN}, - {"oneline", no_argument, NULL, OPT_ONELINE}, - {"timeout", required_argument, NULL, 't'}, {"help", no_argument, NULL, 'h'}, {"commands", no_argument, NULL, OPT_COMMANDS}, {"options", no_argument, NULL, OPT_OPTIONS}, {"leader-only", no_argument, &leader_only, true}, {"no-leader-only", no_argument, &leader_only, false}, {"version", no_argument, NULL, 'V'}, + MAIN_LOOP_LONG_OPTIONS, VLOG_LONG_OPTIONS, STREAM_SSL_LONG_OPTIONS, {"bootstrap-ca-cert", required_argument, NULL, OPT_BOOTSTRAP_CA_CERT}, @@ -268,40 +323,24 @@ parse_options(int argc, char *argv[], struct shash *local_options) break; } + bool handled; + char *error = handle_main_loop_option(c, optarg, &handled); + if (error) { + ctl_fatal("%s", error); + } + if (handled) { + continue; + } + switch (c) { case OPT_DB: db = optarg; break; - case OPT_ONELINE: - oneline = true; - break; - case OPT_NO_SYSLOG: vlog_set_levels(&this_module, VLF_SYSLOG, VLL_WARN); break; - case OPT_NO_WAIT: - wait_type = NBCTL_WAIT_NONE; - break; - - case OPT_WAIT: - if (!strcmp(optarg, "none")) { - wait_type = NBCTL_WAIT_NONE; - } else if (!strcmp(optarg, "sb")) { - wait_type = NBCTL_WAIT_SB; - } else if (!strcmp(optarg, "hv")) { - wait_type = NBCTL_WAIT_HV; - } else { - ctl_fatal("argument to --wait must be " - "\"none\", \"sb\", or \"hv\""); - } - break; - - case OPT_DRY_RUN: - dry_run = true; - break; - case OPT_LOCAL: if (shash_find(local_options, options[idx].name)) { ctl_fatal("'%s' option specified multiple times", @@ -329,13 +368,6 @@ parse_options(int argc, char *argv[], struct shash *local_options) printf("DB Schema %s\n", nbrec_get_db_version()); exit(EXIT_SUCCESS); - case 't': - timeout = strtoul(optarg, NULL, 10); - if (timeout < 0) { - ctl_fatal("value %s on -t or --timeout is invalid", optarg); - } - break; - VLOG_OPTION_HANDLERS TABLE_OPTION_HANDLERS(&table_style) STREAM_SSL_OPTION_HANDLERS From patchwork Fri Jul 13 18:36:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 943776 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 41S1rK6Zdzz9s0n for ; Sat, 14 Jul 2018 04:42:25 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 84770E6B; Fri, 13 Jul 2018 18:36:51 +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 32514E6B for ; Fri, 13 Jul 2018 18:36:50 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 3A3587B3 for ; Fri, 13 Jul 2018 18:36:49 +0000 (UTC) Received: by mail-wm0-f65.google.com with SMTP id n17-v6so10287501wmh.2 for ; Fri, 13 Jul 2018 11:36:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=A3UMBlTuoCPLlTXCxrvicLjM+Njsy1IelNAPgHC/nD4=; b=DKGWsy1k8OwhKm6LWqkn4D+7hjI/EVPir/PiEtoRf+4sHO/+tFbE8RiVXtiklD2yAC BdpGpH0f87l1iQCI66x17wtyH1MEUzwSV3j8aHNunaqRG0e41Dbnowl+k7nBl7Okr6Fg dWYXGqG/D7FazD4piX+uLXDm1cb+u8gOOnRQ69+Jevcv651MGtKaPfE6PmO8Ea1Qiktd 2tvjPwV74jiQcNsei/0MN5pz6Cib7HGQVvjnYCt0fR7PmEKwhrxPLeQQwPWyTvfZgan7 YbRr3HIegM8ZB2WpX0kd4RGlw0bzsYzq2h1NrBWVAYCX5H1O7WzxpJqPX/FkTrEabd+o yNyA== X-Gm-Message-State: AOUpUlGhcTQ2+UD99IOsLoPm7FgKsUR7RBv6oMixFB+B4gKtXd8CrtML j2ZdOkIkWXASl0dGYqh3v4DJvRgaxCA= X-Google-Smtp-Source: AAOMgpcj3IkRQdPKDpoLWR0AsnyNKKqRj9jgyEEVIriIDTuRUA3KAmCbCDtCouuAwKVsh8q4FOXT3A== X-Received: by 2002:a1c:d942:: with SMTP id q63-v6mr4864085wmg.78.1531507007622; Fri, 13 Jul 2018 11:36:47 -0700 (PDT) Received: from redhat.com (218.red-2-136-166.dynamicip.rima-tde.net. [2.136.166.218]) by smtp.gmail.com with ESMTPSA id l127-v6sm17704942wma.41.2018.07.13.11.36.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Jul 2018 11:36:47 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Fri, 13 Jul 2018 20:36:20 +0200 Message-Id: <20180713183624.16937-14-jkbs@redhat.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180713183624.16937-1-jkbs@redhat.com> References: <20180713183624.16937-1-jkbs@redhat.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE 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 v3 13/17] ovn-nbctl: Extract a helper for building short options string. 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 Will be reused for parsing options in daemon mode. Signed-off-by: Jakub Sitnicki --- ovn/utilities/ovn-nbctl.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index 72c78795c..bac1c001d 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -274,6 +274,18 @@ handle_main_loop_option(int opt, const char *arg, bool *handled) return NULL; } +static char * OVS_WARN_UNUSED_RESULT +build_short_options(const struct option *long_options) +{ + char *tmp, *short_options; + + tmp = ovs_cmdl_long_options_to_short_options(long_options); + short_options = xasprintf("+%s", tmp); + free(tmp); + + return short_options; +} + static void parse_options(int argc, char *argv[], struct shash *local_options) { @@ -294,16 +306,14 @@ parse_options(int argc, char *argv[], struct shash *local_options) {NULL, 0, NULL, 0}, }; const int n_global_long_options = ARRAY_SIZE(global_long_options) - 1; - char *tmp, *short_options; + char *short_options; struct option *options; size_t allocated_options; size_t n_options; size_t i; - tmp = ovs_cmdl_long_options_to_short_options(global_long_options); - short_options = xasprintf("+%s", tmp); - free(tmp); + short_options = build_short_options(global_long_options); /* We want to parse both global and command-specific options here, but * getopt_long() isn't too convenient for the job. We copy our global From patchwork Fri Jul 13 18:36:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 943777 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 41S1rs35QHz9s0n for ; Sat, 14 Jul 2018 04:42:53 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 37CF6E71; Fri, 13 Jul 2018 18:36:53 +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 434B4E37 for ; Fri, 13 Jul 2018 18:36:51 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wm0-f48.google.com (mail-wm0-f48.google.com [74.125.82.48]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id C3D027B3 for ; Fri, 13 Jul 2018 18:36:50 +0000 (UTC) Received: by mail-wm0-f48.google.com with SMTP id z6-v6so5141739wma.0 for ; Fri, 13 Jul 2018 11:36:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=yJLwONWWv/ndDC4YfM/Eo2FRPuqHAUwqMs2gJ/Zj97U=; b=nnNkKlAlwJzTMqWRpSOI5ae9YtdPBuUHxduBft+RKZenXt0XD6P4dZr6Gbl0m5imG0 sjncd0ZpCXShZ32oT7mAbrIua4RY9V7D87hTYjhvPovryjZvUs/rYMeKtjXJuhUc0biq cyWuDMNxAw9MnXkqYW/sy7f+pP6bLW2z+EY1gfcM1eOhgNfYeLgvMQPahv0FoEWX1ysO m+NUwkbfmqBGx0rWh/u0Lx85hllc2h9FhltI7X6tzuLCEyrnzLweRkTq6H0EPK64kzS6 QSEs2U1wiPSTB5ITz0k1330jdOvD1iHSgx5Q9JXST15oJLCg3HLTSf8iILTYeJ1AkmJU sV3A== X-Gm-Message-State: AOUpUlGVa7AhZG7pv5CyIJkXsAOkd/b7Oigz7qJYollNEfRhMfAAEL3t sEKI/Wljqt/fUXEJrsqBXRxk5NbyglI= X-Google-Smtp-Source: AAOMgpdp85+Wo20WgH8b9V1dXg9yyuezsCBJrDBusMo8s/qIkFmb8VwYiLv/2oI34qIGfLuPMs67Ag== X-Received: by 2002:a1c:e5cd:: with SMTP id c196-v6mr4511340wmh.101.1531507009184; Fri, 13 Jul 2018 11:36:49 -0700 (PDT) Received: from redhat.com (218.red-2-136-166.dynamicip.rima-tde.net. [2.136.166.218]) by smtp.gmail.com with ESMTPSA id q200-v6sm11878552wmg.8.2018.07.13.11.36.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Jul 2018 11:36:48 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Fri, 13 Jul 2018 20:36:21 +0200 Message-Id: <20180713183624.16937-15-jkbs@redhat.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180713183624.16937-1-jkbs@redhat.com> References: <20180713183624.16937-1-jkbs@redhat.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE 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 v3 14/17] ovn-nbctl: Extract a helper for appending command options. 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 Will be reused when parsing options in daemon mode. Signed-off-by: Jakub Sitnicki --- ovn/utilities/ovn-nbctl.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index bac1c001d..c83d03218 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -286,6 +286,30 @@ build_short_options(const struct option *long_options) return short_options; } +static struct option * OVS_WARN_UNUSED_RESULT +append_command_options(const struct option *options, int opt_val) +{ + struct option *o; + size_t n_allocated; + size_t n_existing; + int i; + + for (i = 0; options[i].name; i++) { + ; + } + n_allocated = i + 1; + n_existing = i; + + /* We want to parse both global and command-specific options here, but + * getopt_long() isn't too convenient for the job. We copy our global + * options into a dynamic array, then append all of the command-specific + * options. */ + o = xmemdup(options, n_allocated * sizeof *options); + ctl_add_cmd_options(&o, &n_existing, &n_allocated, opt_val); + + return o; +} + static void parse_options(int argc, char *argv[], struct shash *local_options) { @@ -307,22 +331,11 @@ parse_options(int argc, char *argv[], struct shash *local_options) }; const int n_global_long_options = ARRAY_SIZE(global_long_options) - 1; char *short_options; - struct option *options; - size_t allocated_options; - size_t n_options; size_t i; short_options = build_short_options(global_long_options); - - /* We want to parse both global and command-specific options here, but - * getopt_long() isn't too convenient for the job. We copy our global - * options into a dynamic array, then append all of the command-specific - * options. */ - options = xmemdup(global_long_options, sizeof global_long_options); - allocated_options = ARRAY_SIZE(global_long_options); - n_options = n_global_long_options; - ctl_add_cmd_options(&options, &n_options, &allocated_options, OPT_LOCAL); + options = append_command_options(global_long_options, OPT_LOCAL); for (;;) { int idx; From patchwork Fri Jul 13 18:36:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 943780 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 41S1sS0lKWz9s0n for ; Sat, 14 Jul 2018 04:43:24 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id D5476E80; Fri, 13 Jul 2018 18:36:55 +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 1325EE74 for ; Fri, 13 Jul 2018 18:36:54 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 974A17B2 for ; Fri, 13 Jul 2018 18:36:52 +0000 (UTC) Received: by mail-wr1-f43.google.com with SMTP id m1-v6so13284098wrg.5 for ; Fri, 13 Jul 2018 11:36:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=0K+mbDRwuFnU1zU8nuDPjWh4GPHRy1sqKqMNSeCr41o=; b=ExT/mSjb9zqq9JkslzaIm4MI3M8MkRdgffD3JwgWmbpTvSMd1QDs55xK/Hl5iHWmao F23KLMbv/wTQ20l74HM18tjwrUXqLPFzKhHYwsIQHaoX3p+pSqm8ZUWGtCwG1Rlm+YHF 6eE5DApuVqy0hmGxT30Ld8gNzvdsefalsitzFfOybcB3y6C7eRkuG3VDekdau2hLh3fK NoNlEfwrkFVVJ2hyOCDEnyvK36y7xGK4crwDmzLg9gaaLXPwfAmbc1zU7et0EAHXy8ix tarX/Nh55DJ5enYy2NaASCpeh7qW/Haw/Kz7NHc+OLCPab16sWxfCkQw8mtWNWvu8TTw sETA== X-Gm-Message-State: AOUpUlFC9IYhxllX5JG3J53Ti0QpqFFMA9BGw8qzXlxkXYIKrpRkWMr5 gLfXa3L1fT5hIB7eAyGjx87SCi13NRc= X-Google-Smtp-Source: AAOMgpehS3dUJNDpGGVxY4aRa2wnD4EE6PDumkTQ9dvwB6KxoCgCxiGdUxgg2RivQoLF5luebaTl1w== X-Received: by 2002:adf:96c3:: with SMTP id u61-v6mr5587302wrb.72.1531507010759; Fri, 13 Jul 2018 11:36:50 -0700 (PDT) Received: from redhat.com (218.red-2-136-166.dynamicip.rima-tde.net. [2.136.166.218]) by smtp.gmail.com with ESMTPSA id b6-v6sm55671129wru.66.2018.07.13.11.36.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Jul 2018 11:36:50 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Fri, 13 Jul 2018 20:36:22 +0200 Message-Id: <20180713183624.16937-16-jkbs@redhat.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180713183624.16937-1-jkbs@redhat.com> References: <20180713183624.16937-1-jkbs@redhat.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE 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 v3 15/17] ovn-nbctl: Initial support for daemon mode. 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 Make ovn-nbctl act as a unixctl server if we were asked to detach. This turns ovn-nbctl into a long-lived process that acts a proxy for interacting with NB DB. The main difference to regular mode of ovn-nbctl is that in the daemon mode, a local copy of database contents has to be obtained only once. Just two unixctl commands are supported 'run' and 'exit'. The former can be used to run any ovn-nbctl command or a batch of them as so: ovs-appctl -t ovn-nbctl run [OPTIONS] COMMAND [-- [OPTIONS] COMMAND] ... Running commands that have not yet been converted to not use ctl_fatal() will result in death of the daemon process. However, --monitor option can be used to keep the daemon running. Signed-off-by: Jakub Sitnicki --- ovn/utilities/ovn-nbctl.8.xml | 40 ++++++ ovn/utilities/ovn-nbctl.c | 308 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 322 insertions(+), 26 deletions(-) diff --git a/ovn/utilities/ovn-nbctl.8.xml b/ovn/utilities/ovn-nbctl.8.xml index abba4ecdb..2cd2fab30 100644 --- a/ovn/utilities/ovn-nbctl.8.xml +++ b/ovn/utilities/ovn-nbctl.8.xml @@ -913,6 +913,43 @@ +

Daemon Mode

+ +

+ If ovn-nbctl is invoked with the --detach + option (see Daemon Options, below), it runs in the + background as a daemon and accepts commands from ovs-appctl + (or another JSON-RPC client) indefinitely. The currently supported + commands are described below. +

+ +

+ +

+ +
+
+ run [options] command + [arg...] [-- [options] + command [arg...] ...] +
+
+ Instructs the daemon process to run one or more ovn-nbctl + commands described above and reply with the results of running these + commands. Accepts the --no-wait, --wait, + --timeout, --dry-run, --oneline, + and the options described under Table Formatting Options + in addition to the the command-specific options. +
+ +
exit
+
Causes ovn-nbctl to gracefully terminate.
+
+ +

+ Daemon mode is considered experimental. +

+

Options

@@ -982,6 +1019,9 @@
+

Daemon Options

+ +

Logging options

diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index c83d03218..46e923cb9 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -20,6 +20,7 @@ #include #include "command-line.h" +#include "daemon.h" #include "db-ctl-base.h" #include "dirs.h" #include "fatal-signal.h" @@ -38,6 +39,7 @@ #include "table.h" #include "timeval.h" #include "timer.h" +#include "unixctl.h" #include "util.h" #include "openvswitch/vlog.h" @@ -80,6 +82,13 @@ OVS_NO_RETURN static void nbctl_exit(int status); /* --leader-only, --no-leader-only: Only accept the leader in a cluster. */ static int leader_only = true; +/* --unixctl-path: Path to use for unixctl server, for "monitor" and "snoop" + commands. */ +static char *unixctl_path; + +static unixctl_cb_func server_cmd_exit; +static unixctl_cb_func server_cmd_run; + static void nbctl_cmd_init(void); OVS_NO_RETURN static void usage(void); static void parse_options(int argc, char *argv[], struct shash *local_options); @@ -98,15 +107,13 @@ static char * OVS_WARN_UNUSED_RESULT main_loop(const char *args, size_t n_commands, struct ovsdb_idl *idl, const struct timer *); +static void server_loop(struct ovsdb_idl *idl); int main(int argc, char *argv[]) { struct ovsdb_idl *idl; - struct ctl_command *commands; struct shash local_options; - size_t n_commands; - char *error; set_program_name(argv[0]); fatal_ignore_sigpipe(); @@ -119,38 +126,55 @@ main(int argc, char *argv[]) char *args = process_escape_args(argv); shash_init(&local_options); parse_options(argc, argv, &local_options); - commands = ctl_parse_commands(argc - optind, argv + optind, &local_options, - &n_commands); - VLOG(ctl_might_write_to_db(commands, n_commands) ? VLL_INFO : VLL_DBG, - "Called as %s", args); - - if (timeout) { - time_alarm(timeout); - } + argc -= optind; + argv += optind; /* Initialize IDL. */ idl = the_idl = ovsdb_idl_create(db, &nbrec_idl_class, true, false); ovsdb_idl_set_leader_only(idl, leader_only); - error = run_prerequisites(commands, n_commands, idl); - if (error) { - ctl_fatal("%s", error); - } - error = main_loop(args, commands, n_commands, idl, NULL); - if (error) { - ctl_fatal("%s", error); + if (get_detach()) { + if (argc != 0) { + ctl_fatal("non-option arguments not supported with --detach " + "(use --help for help)"); + } + server_loop(idl); + } else { + struct ctl_command *commands; + size_t n_commands; + char *error; + + commands = ctl_parse_commands(argc, argv, &local_options, &n_commands); + VLOG(ctl_might_write_to_db(commands, n_commands) ? VLL_INFO : VLL_DBG, + "Called as %s", args); + + if (timeout) { + time_alarm(timeout); + } + + error = run_prerequisites(commands, n_commands, idl); + if (error) { + ctl_fatal("%s", error); + } + + error = main_loop(args, commands, n_commands, idl, NULL); + if (error) { + ctl_fatal("%s", error); + } + + struct ctl_command *c; + for (c = commands; c < &commands[n_commands]; c++) { + ds_destroy(&c->output); + table_destroy(c->table); + free(c->table); + shash_destroy_free_data(&c->options); + } + free(commands); } ovsdb_idl_destroy(idl); idl = the_idl = NULL; - for (struct ctl_command *c = commands; c < &commands[n_commands]; c++) { - ds_destroy(&c->output); - table_destroy(c->table); - free(c->table); - shash_destroy_free_data(&c->options); - } - free(commands); free(args); exit(EXIT_SUCCESS); } @@ -160,6 +184,7 @@ main_loop(const char *args, struct ctl_command *commands, size_t n_commands, struct ovsdb_idl *idl, const struct timer *wait_timeout) { unsigned int seqno; + bool idl_ready; /* Execute the commands. * @@ -169,6 +194,11 @@ main_loop(const char *args, struct ctl_command *commands, size_t n_commands, * it's because the database changed and we need to obtain an up-to-date * view of the database before we try the transaction again. */ seqno = ovsdb_idl_get_seqno(idl); + + /* IDL might have already obtained the database copy during previous + * invocation. If so, we can't expect the sequence number to change before + * we issue any new requests. */ + idl_ready = ovsdb_idl_has_ever_connected(idl); for (;;) { ovsdb_idl_run(idl); if (!ovsdb_idl_is_alive(idl)) { @@ -177,7 +207,8 @@ main_loop(const char *args, struct ctl_command *commands, size_t n_commands, db, ovs_retval_to_string(retval)); } - if (seqno != ovsdb_idl_get_seqno(idl)) { + if (idl_ready || seqno != ovsdb_idl_get_seqno(idl)) { + idl_ready = false; seqno = ovsdb_idl_get_seqno(idl); bool retry; @@ -222,6 +253,7 @@ enum { OPT_OPTIONS, OPT_BOOTSTRAP_CA_CERT, MAIN_LOOP_OPTION_ENUMS, + DAEMON_OPTION_ENUMS, VLOG_OPTION_ENUMS, TABLE_OPTION_ENUMS, SSL_OPTION_ENUMS, @@ -323,6 +355,7 @@ parse_options(int argc, char *argv[], struct shash *local_options) {"no-leader-only", no_argument, &leader_only, false}, {"version", no_argument, NULL, 'V'}, MAIN_LOOP_LONG_OPTIONS, + DAEMON_LONG_OPTIONS, VLOG_LONG_OPTIONS, STREAM_SSL_LONG_OPTIONS, {"bootstrap-ca-cert", required_argument, NULL, OPT_BOOTSTRAP_CA_CERT}, @@ -391,6 +424,7 @@ parse_options(int argc, char *argv[], struct shash *local_options) printf("DB Schema %s\n", nbrec_get_db_version()); exit(EXIT_SUCCESS); + DAEMON_OPTION_HANDLERS VLOG_OPTION_HANDLERS TABLE_OPTION_HANDLERS(&table_style) STREAM_SSL_OPTION_HANDLERS @@ -584,6 +618,7 @@ Options:\n\ program_name, program_name, ctl_get_db_cmd_usage(), ctl_list_db_tables_usage(), default_nb_db()); table_usage(); + daemon_usage(); vlog_usage(); printf("\ --no-syslog equivalent to --verbose=nbctl:syslog:warn\n"); @@ -4617,3 +4652,224 @@ nbctl_cmd_init(void) ctl_init(&nbrec_idl_class, nbrec_table_classes, tables, NULL, nbctl_exit); ctl_register_commands(nbctl_commands); } + +static char * OVS_WARN_UNUSED_RESULT +server_parse_options(int argc, char *argv[], struct shash *local_options, + int *n_options_p) +{ + static const struct option global_long_options[] = { + MAIN_LOOP_LONG_OPTIONS, + TABLE_LONG_OPTIONS, + {NULL, 0, NULL, 0}, + }; + const int n_global_long_options = ARRAY_SIZE(global_long_options) - 1; + char *short_options; + struct option *options; + char *error = NULL; + + ovs_assert(n_options_p); + + short_options = build_short_options(global_long_options); + options = append_command_options(global_long_options, OPT_LOCAL); + + optind = 0; + opterr = 0; + for (;;) { + int idx; + int c; + + c = getopt_long(argc, argv, short_options, options, &idx); + if (c == -1) { + break; + } + + bool handled; + error = handle_main_loop_option(c, optarg, &handled); + if (error) { + goto out; + } + if (handled) { + continue; + } + + switch (c) { + case OPT_LOCAL: + if (shash_find(local_options, options[idx].name)) { + error = xasprintf("'%s' option specified multiple times", + options[idx].name); + goto out; + } + shash_add_nocopy(local_options, + xasprintf("--%s", options[idx].name), + nullable_xstrdup(optarg)); + break; + + VLOG_OPTION_HANDLERS + TABLE_OPTION_HANDLERS(&table_style) + + case '?': + error = xstrdup("Invalid option or argument"); + goto out; + break; + + case 0: + break; + + default: + error = xasprintf("Unhandled option '%c'", c); + goto out; + break; + } + } + *n_options_p = optind; + +out: + for (int i = n_global_long_options; options[i].name; i++) { + free(CONST_CAST(char *, options[i].name)); + } + free(options); + free(short_options); + + return error; +} + +static void +server_cmd_exit(struct unixctl_conn *conn, int argc OVS_UNUSED, + const char *argv[] OVS_UNUSED, void *exiting_) +{ + bool *exiting = exiting_; + *exiting = true; + unixctl_command_reply(conn, NULL); +} + +static void +server_cmd_run(struct unixctl_conn *conn, int argc, const char **argv_, + void *idl_) +{ + struct ovsdb_idl *idl = idl_; + struct ctl_command *commands = NULL; + struct shash local_options; + size_t n_commands = 0; + int n_options = 0; + char *error = NULL; + + /* Copy args so that getopt() can permute them. Leave last entry NULL. */ + char **argv = xcalloc(argc + 1, sizeof *argv); + for (int i = 0; i < argc; i++) { + argv[i] = xstrdup(argv_[i]); + } + + /* Reset global state. */ + oneline = false; + dry_run = false; + wait_type = NBCTL_WAIT_NONE; + force_wait = false; + timeout = 0; + table_style = table_style_default; + + /* Parse commands & options. */ + char *args = process_escape_args(argv); + shash_init(&local_options); + error = server_parse_options(argc, argv, &local_options, &n_options); + if (error) { + unixctl_command_reply_error(conn, error); + goto out; + } + commands = ctl_parse_commands(argc - n_options, argv + n_options, + &local_options, &n_commands); + VLOG(ctl_might_write_to_db(commands, n_commands) ? VLL_INFO : VLL_DBG, + "Running command %s", args); + + struct timer *wait_timeout = NULL; + struct timer wait_timeout_; + if (timeout) { + wait_timeout = &wait_timeout_; + timer_set_duration(wait_timeout, timeout * 1000); + } + + error = run_prerequisites(commands, n_commands, idl); + if (error) { + unixctl_command_reply_error(conn, error); + goto out; + } + error = main_loop(args, commands, n_commands, idl, wait_timeout); + if (error) { + unixctl_command_reply_error(conn, error); + goto out; + } + + struct ds output = DS_EMPTY_INITIALIZER; + for (struct ctl_command *c = commands; c < &commands[n_commands]; c++) { + if (c->table) { + table_format(c->table, &table_style, &output); + } else if (oneline) { + oneline_format(&c->output, &output); + } else { + ds_put_cstr(&output, ds_cstr_ro(&c->output)); + } + + ds_destroy(&c->output); + table_destroy(c->table); + free(c->table); + } + unixctl_command_reply(conn, ds_cstr_ro(&output)); + ds_destroy(&output); + +out: + free(error); + for (struct ctl_command *c = commands; c < &commands[n_commands]; c++) { + shash_destroy_free_data(&c->options); + } + free(commands); + shash_destroy_free_data(&local_options); + free(args); + for (int i = 0; i < argc; i++) { + free(argv[i]); + } + free(argv); +} + +static void +server_cmd_init(struct ovsdb_idl *idl, bool *exiting) +{ + unixctl_command_register("exit", "", 0, 0, server_cmd_exit, exiting); + unixctl_command_register("run", "", 1, INT_MAX, server_cmd_run, idl); +} + +static void +server_loop(struct ovsdb_idl *idl) +{ + struct unixctl_server *server = NULL; + bool exiting = false; + + daemonize_start(false); + int error = unixctl_server_create(unixctl_path, &server); + if (error) { + ctl_fatal("failed to create unixctl server (%s)", + ovs_retval_to_string(error)); + } + server_cmd_init(idl, &exiting); + + for (;;) { + ovsdb_idl_run(idl); + if (!ovsdb_idl_is_alive(idl)) { + int retval = ovsdb_idl_get_last_error(idl); + ctl_fatal("%s: database connection failed (%s)", + db, ovs_retval_to_string(retval)); + } + + if (ovsdb_idl_has_ever_connected(idl)) { + daemonize_complete(); + unixctl_server_run(server); + } + if (exiting) { + break; + } + + ovsdb_idl_wait(idl); + unixctl_server_wait(server); + poll_block(); + } + + unixctl_server_destroy(server); +} From patchwork Fri Jul 13 18:36:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 943781 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 41S1t35HwGz9s0n for ; Sat, 14 Jul 2018 04:43:55 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 890BEE7D; Fri, 13 Jul 2018 18:36:56 +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 98696E74 for ; Fri, 13 Jul 2018 18:36:54 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wm0-f44.google.com (mail-wm0-f44.google.com [74.125.82.44]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 1CDF67B2 for ; Fri, 13 Jul 2018 18:36:54 +0000 (UTC) Received: by mail-wm0-f44.google.com with SMTP id v128-v6so9601977wme.5 for ; Fri, 13 Jul 2018 11:36:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=MsksL+AwbxDwEWR/P7+27KiEvSLkPSS4RbSh0oQXE1c=; b=WKiKrE77j3rJd9HY/zFfmDaChCHWBF1K2cMNV4YB6EVce/3fpZVHGZgUVy+cLLLkaY PNWkdA+vyrnanimr1mP0CVXfWzNbvRzM36SpznwSw9Y4tWIsrEC95jpAHEAc1AHZLcZH AMceQm9S5ORYjOvuiDJ7ivQn8wDx59IMdegi3PY62/xnLwjbqHgwWHnXTe5Ve1tvxGri aVxSGd6wVNWdAenlw0gSR6oHOJDM2IjvlgZLHs9KqbjbcBFwMWUCaTcn4aXIdd7dh0Sq E3E0GEO4Uf8wqwtIa19k0mtZ2t6HQALGqX8bvXddV9Q/eCkNYctxmNqGWRiX+dM7va9G dWbw== X-Gm-Message-State: AOUpUlHQqI2mPwS2u6X+CgaJZenmS1Lrt5PrfLNXbaD9ASz6THW9oGj5 HOGzXbiV/LvXHyaZbhMxaL8jRAL/D3w= X-Google-Smtp-Source: AAOMgpctqG10kYeCHssCXOlq2tL6m1CAE3uOAEUvh2AvR/mHWQlDm8X560Qh8rhaNcFbqZkBkDVpyQ== X-Received: by 2002:a1c:1182:: with SMTP id 124-v6mr4569436wmr.75.1531507012579; Fri, 13 Jul 2018 11:36:52 -0700 (PDT) Received: from redhat.com (218.red-2-136-166.dynamicip.rima-tde.net. [2.136.166.218]) by smtp.gmail.com with ESMTPSA id j3-v6sm10336694wrt.70.2018.07.13.11.36.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Jul 2018 11:36:52 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Fri, 13 Jul 2018 20:36:23 +0200 Message-Id: <20180713183624.16937-17-jkbs@redhat.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180713183624.16937-1-jkbs@redhat.com> References: <20180713183624.16937-1-jkbs@redhat.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE 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 v3 16/17] tests: Add test for ovn-nbctl dry run mode. 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 Signed-off-by: Jakub Sitnicki --- tests/ovn-nbctl.at | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/ovn-nbctl.at b/tests/ovn-nbctl.at index 73a61a4be..89daf631a 100644 --- a/tests/ovn-nbctl.at +++ b/tests/ovn-nbctl.at @@ -1382,3 +1382,24 @@ inactivity_probe : 30000 OVN_NBCTL_TEST_STOP AT_CLEANUP + +dnl --------------------------------------------------------------------- + +AT_SETUP([ovn-nbctl - dry run mode]) +OVN_NBCTL_TEST_START + +# Check that dry run has no permanent effect. +AT_CHECK([ovn-nbctl --dry-run ls-add ls0 -- ls-list | uuidfilt], [0], [dnl +<0> (ls0) +]) +AT_CHECK([ovn-nbctl ls-list | uuidfilt], [0], [dnl +]) + +# Check that dry-run mode is not sticky. +AT_CHECK([ovn-nbctl ls-add ls0]) +AT_CHECK([ovn-nbctl ls-list | uuidfilt], [0], [dnl +<0> (ls0) +]) + +OVN_NBCTL_TEST_STOP +AT_CLEANUP From patchwork Fri Jul 13 18:36:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 943782 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 41S1tl0sVyz9s0n for ; Sat, 14 Jul 2018 04:44:31 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 69C7DE92; Fri, 13 Jul 2018 18:36:58 +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 7114DE7E for ; Fri, 13 Jul 2018 18:36:56 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id ED4A17B0 for ; Fri, 13 Jul 2018 18:36:55 +0000 (UTC) Received: by mail-wr1-f53.google.com with SMTP id h10-v6so26013285wre.6 for ; Fri, 13 Jul 2018 11:36:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=VmaYYtjVAA79uGWGkxp2fegHwLytIa7OaWfQeqmBcjY=; b=i2NpRyjzhRz8YYS7y4vEmp5hBjfNDmzyZDPAGvWQiTWBOSf2jZPPd7CByFFOKs9esW jKUX/vz5ww50fRc5INzXOxFYaodK+jKO5qXnZKTCVo3FEmCRgJmj7OCvuYoCGJEB3QBW W9w3WXjkqHNh8cxN8X8p3lZLVJmNUkNslyo3YuaukpJZvtXmoHLGz6H4LwS/6ph+O8H5 /IQi7mMtDtdWPXtyJ9G6Ul7M91Z1E8WBZPIDKv690Pd0Y5nm4H89gAwfAvE+KvHB56eU jXrz1A/j1bbrYnfcmdrzwg/XdMlOKUQnIZ/XZLoN7qkx6gie2+xzSqoI59ybOfwosglc Uqvg== X-Gm-Message-State: AOUpUlEAdFJbZfU6cJZa/mW3v5Il7r8eiyOfSVooExyJBdMAQP6GolzB sMdNr4BnkkaieJla7CW8Bo6sMyszKpw= X-Google-Smtp-Source: AAOMgpeVFO7MzHyWC0WUFJNlu4DIONfhF4Ph0L8l9XdRk5hgw8+3mFy9058tNWxwP9QvOErrsPT1kw== X-Received: by 2002:adf:a285:: with SMTP id s5-v6mr5429844wra.114.1531507014418; Fri, 13 Jul 2018 11:36:54 -0700 (PDT) Received: from redhat.com (218.red-2-136-166.dynamicip.rima-tde.net. [2.136.166.218]) by smtp.gmail.com with ESMTPSA id v190-v6sm9990229wme.21.2018.07.13.11.36.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Jul 2018 11:36:53 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Fri, 13 Jul 2018 20:36:24 +0200 Message-Id: <20180713183624.16937-18-jkbs@redhat.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180713183624.16937-1-jkbs@redhat.com> References: <20180713183624.16937-1-jkbs@redhat.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE 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 v3 17/17] tests: Add test for oneline-formatted output for ovn-nbctl. 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 Signed-off-by: Jakub Sitnicki --- tests/ovn-nbctl.at | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/ovn-nbctl.at b/tests/ovn-nbctl.at index 89daf631a..60b4d0c9c 100644 --- a/tests/ovn-nbctl.at +++ b/tests/ovn-nbctl.at @@ -1403,3 +1403,24 @@ AT_CHECK([ovn-nbctl ls-list | uuidfilt], [0], [dnl OVN_NBCTL_TEST_STOP AT_CLEANUP + +dnl --------------------------------------------------------------------- + +AT_SETUP([ovn-nbctl - oneline output]) +OVN_NBCTL_TEST_START + +AT_CHECK([ovn-nbctl ls-add ls0 -- ls-add ls1]) + +# Expect one line for one command. +AT_CHECK([ovn-nbctl --oneline ls-list | uuidfilt], [0], [dnl +<0> (ls0)\n<1> (ls1) +]) + +# Expect lines for two commands. +AT_CHECK([ovn-nbctl --oneline ls-list -- ls-list | uuidfilt], [0], [dnl +<0> (ls0)\n<1> (ls1) +<0> (ls0)\n<1> (ls1) +]) + +OVN_NBCTL_TEST_STOP +AT_CLEANUP