From patchwork Sun Dec 25 11:39:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Blakey X-Patchwork-Id: 708708 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3tmgZx5MG0z9t17 for ; Sun, 25 Dec 2016 22:56:41 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 2DC18BD7; Sun, 25 Dec 2016 11:48:52 +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 37997B8F for ; Sun, 25 Dec 2016 11:48:47 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by smtp1.linuxfoundation.org (Postfix) with ESMTP id E933F13A for ; Sun, 25 Dec 2016 11:48:44 +0000 (UTC) Received: from Internal Mail-Server by MTLPINE1 (envelope-from paulb@mellanox.com) with ESMTPS (AES256-SHA encrypted); 25 Dec 2016 13:40:36 +0200 Received: from dev-r-vrt-176.mtr.labs.mlnx (dev-r-vrt-176.mtr.labs.mlnx [10.212.176.1]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id uBPBeXbJ029898; Sun, 25 Dec 2016 13:40:36 +0200 From: Paul Blakey To: dev@openvswitch.org, Andy Gospodarek , Simon Horman , Jiri Pirko , John Fastabend , Lance Richardson , Marcelo Ricardo Leitner , Joe Stringer Date: Sun, 25 Dec 2016 13:39:47 +0200 Message-Id: <1482665989-791-20-git-send-email-paulb@mellanox.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1482665989-791-1-git-send-email-paulb@mellanox.com> References: <1482665989-791-1-git-send-email-paulb@mellanox.com> X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Shahar Klein , Mark Bloch , Hadar Hen Zion , Rony Efraim , Or Gerlitz Subject: [ovs-dev] [PATCH ovs V2 19/21] dpctl: read vswitch config on start 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 Use Open vSwitch IDL pattern to read OVS configuration on dpctl start, needed as some functionality is dependent on that configuration. Signed-off-by: Paul Blakey Reviewed-by: Roi Dayan --- lib/dpctl.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ lib/dpctl.h | 2 ++ utilities/ovs-dpctl.c | 2 ++ 3 files changed, 48 insertions(+) diff --git a/lib/dpctl.c b/lib/dpctl.c index edccb7f..a892632 100644 --- a/lib/dpctl.c +++ b/lib/dpctl.c @@ -50,6 +50,10 @@ #include "unixctl.h" #include "util.h" #include "openvswitch/ofp-parse.h" +#include "ovsdb-idl.h" +#include "vswitch-idl.h" +#include "db-ctl-base.h" +#include "tc.h" typedef int dpctl_command_handler(int argc, const char *argv[], struct dpctl_params *); @@ -1645,6 +1649,46 @@ static const struct dpctl_command *get_all_dpctl_commands(void) return all_commands; } +int +dpctl_read_db() +{ + char *db = ctl_default_db(); + struct ovsdb_idl *idl = ovsdb_idl_create(db, &ovsrec_idl_class, true, + true); + ovsdb_idl_track_add_all(idl); + unsigned int seqno = ovsdb_idl_get_seqno(idl); + const struct ovsrec_open_vswitch *cfg; + + for (;;) { + /* synchronize OVSDB */ + 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 (seqno != ovsdb_idl_get_seqno(idl)) { + cfg = ovsrec_open_vswitch_first(idl); + if (cfg) { + netdev_set_flow_api_enabled(smap_get_bool(&cfg->other_config, + "hw-offload", + false)); + tc_set_skip_hw(smap_get_bool(&cfg->other_config, "skip_hw", + false)); + break; + } + } else { + ovsdb_idl_wait(idl); + } + } + + ovsdb_idl_destroy(idl); + return 0; +} + /* Runs the command designated by argv[0] within the command table specified by * 'commands', which must be terminated by a command whose 'name' member is a * null pointer. */ diff --git a/lib/dpctl.h b/lib/dpctl.h index 4ee083f..4828f3d 100644 --- a/lib/dpctl.h +++ b/lib/dpctl.h @@ -50,6 +50,8 @@ struct dpctl_params { void (*usage)(void *aux); }; +int dpctl_read_db(void); + int dpctl_run_command(int argc, const char *argv[], struct dpctl_params *dpctl_p); diff --git a/utilities/ovs-dpctl.c b/utilities/ovs-dpctl.c index 843d305..135035d 100644 --- a/utilities/ovs-dpctl.c +++ b/utilities/ovs-dpctl.c @@ -66,6 +66,8 @@ main(int argc, char *argv[]) dpctl_p.output = dpctl_print; dpctl_p.usage = usage; + dpctl_read_db(); + error = dpctl_run_command(argc - optind, (const char **) argv + optind, &dpctl_p); return error ? EXIT_FAILURE : EXIT_SUCCESS;