From patchwork Wed Oct 9 23:56:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: aginwala aginwala X-Patchwork-Id: 1174211 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=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="lm3Y5Jxd"; dkim-atps=neutral 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 46pWNW6SSmz9s7T for ; Thu, 10 Oct 2019 10:57:14 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id DB563C2C; Wed, 9 Oct 2019 23:57:11 +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 35D44A7A for ; Wed, 9 Oct 2019 23:57:10 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 944C45F4 for ; Wed, 9 Oct 2019 23:57:09 +0000 (UTC) Received: by mail-pl1-f195.google.com with SMTP id c3so1851159plo.2 for ; Wed, 09 Oct 2019 16:57:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=EEwStMP17TKCseejrWBBs6A7HGc6uFgw+7j88l4V0Vk=; b=lm3Y5Jxdo4aDPBOZPexScj0NGo6Zd89Wn7eTUnH7E82cmsWdXzwA0aX8G2GYNmPlZN VsOCU8Gz5xNg9UL5VALHzL3JVm/SCw5eeP/JWPTi4GBbzsAAvA6hTiZV5KVheiW1XEIm F3XE9bLq/3yTZD4Q7W5gOx5tz3VFWdKybNUQpaqvWNXTdxC6s4Y4gbRfxLRU78q5IQUP 9Jok5rhxF69c4hX7QaAbLGh7MkDr+sVE+KqJNORWc+I4Fm8hzCP40bjCM3g9kWHZFf27 pXYj+EbGrylcH9wkyZn1OTUzpDQlyPixya0ZSGVMmz/dfreyRapXLOybwWGdKk/+ppOM 3vvA== 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:mime-version :content-transfer-encoding; bh=EEwStMP17TKCseejrWBBs6A7HGc6uFgw+7j88l4V0Vk=; b=tDkqScu4kp7+EPJBdDdUbUOMDSeT593KBwTqvoCCyjgfdofYHB5DQphwvwaxALzKL8 SOjTU6sCPdT2FRQQbfdNi8yzg3pDNAYv4Sug5L3uZYILd2MnYxxjTTNfDoNCRmZ1RhPt v1H1q6P9ZLd66rxCbG0GT2imrq6+wokp2aQrzuMJDD8Wx/9A9npksE81VW3bXBdZZL/Q zsVh236xeFdu2ztwPT6p3SvHv7Ai7891X14isAwNkTcrxFmbtP3lKUXwpAE0zqJbhZDI xOSVgG08QZuV8WsymszoKj9+aV9Js5Sxlbyeerwr0t58kKl56bEymjJPrYzFfN7wLz0Y fVNw== X-Gm-Message-State: APjAAAVvtIGTGg5ynxhB9a1yeCzk+KdiUG92RRI20dYhFCzAmmM30boh SUmoS+/6h0zvycvQIcwgPDaWWSp/ X-Google-Smtp-Source: APXvYqynbshKqCHkSRI2WggOnuID5na/st5v7Q+y5YwJt5bcnUotNa62P4SFcxN7xn/q3Gh+y07VnA== X-Received: by 2002:a17:902:209:: with SMTP id 9mr6079961plc.25.1570665428789; Wed, 09 Oct 2019 16:57:08 -0700 (PDT) Received: from LM-SJC-11015761.corp.ebay.com ([216.113.160.71]) by smtp.gmail.com with ESMTPSA id o11sm3023325pgp.13.2019.10.09.16.57.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 09 Oct 2019 16:57:08 -0700 (PDT) From: amginwal@gmail.com To: dev@openvswitch.org Date: Wed, 9 Oct 2019 16:56:40 -0700 Message-Id: <20191009235640.36470-1-amginwal@gmail.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) MIME-Version: 1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, 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 Cc: Aliasgar Ginwala Subject: [ovs-dev] [PATCH v1 ovn] ovn-nb/sbctl.c: Use env variables for passing 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: , Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org From: Aliasgar Ginwala Add new env variables OVN_NBCTL_OPTIONS and OVN_SBCTL_OPTIONS for ovn-nbctl and ovn-sbctl respectively where user can set any single supported option. e.g export OVN_NBCTL_OPTIONS=--no-leader-only. Above env var OVN_NBCTL_OPTIONS have no effect if user runs command as ovn-nbctl --no-leader-only Signed-off-by: Aliasgar Ginwala --- utilities/ovn-nbctl.8.xml | 7 +++++++ utilities/ovn-nbctl.c | 36 ++++++++++++++++++++++++++++++++++-- utilities/ovn-sbctl.8.in | 6 ++++++ utilities/ovn-sbctl.c | 36 ++++++++++++++++++++++++++++++++++-- 4 files changed, 81 insertions(+), 4 deletions(-) diff --git a/utilities/ovn-nbctl.8.xml b/utilities/ovn-nbctl.8.xml index fd75c0e44..6a7962973 100644 --- a/utilities/ovn-nbctl.8.xml +++ b/utilities/ovn-nbctl.8.xml @@ -1178,6 +1178,13 @@ wait at all. Use the sync command to override this behavior.

+ +

+ If the OVN_NBCTL_OPTIONS environment variable is set, + its value is used as the default to set above options. If user + passes options via cli, OVN_NBCTL_OPTIONS environment + variable will have no effect. +

--db database
diff --git a/utilities/ovn-nbctl.c b/utilities/ovn-nbctl.c index a89a9cb4d..8d2bc0968 100644 --- a/utilities/ovn-nbctl.c +++ b/utilities/ovn-nbctl.c @@ -124,18 +124,49 @@ static char * OVS_WARN_UNUSED_RESULT main_loop(const char *args, static void server_loop(struct ovsdb_idl *idl, int argc, char *argv[]); int -main(int argc, char *argv[]) +main(int argc, char *argv_[]) { struct ovsdb_idl *idl; struct shash local_options; - set_program_name(argv[0]); + set_program_name(argv_[0]); fatal_ignore_sigpipe(); vlog_set_levels(NULL, VLF_CONSOLE, VLL_WARN); vlog_set_levels_from_string_assert("reconnect:warn"); nbctl_cmd_init(); + /* Check if options are set via env var. */ + static int ops_passed = false; + int i, j = 0; + char *ovn_nbctl_options = getenv("OVN_NBCTL_OPTIONS"); + char **argv = xcalloc(argc + 1, sizeof( *argv_) + 1); + if (ovn_nbctl_options) { + for (i = 0; i < argc; i++) { + if (strcmp(argv_[i], ovn_nbctl_options) == 0) { + ops_passed = true; + break; + } + } + /* if option not passed via cli, read env var set by user.*/ + if (!ops_passed) { + for (i = 0, j = 0; i < argc; i++, j++) { + if (j == 1) { + argv[j] = ovn_nbctl_options; + j++; + } + argv[j] = xstrdup(argv_[i]); + } + argc = j; + } + } + if (ops_passed || !ovn_nbctl_options) { + /* Copy args for parsing as is from argv_ */ + for (i = 0; i < argc; i++) { + argv[i] = xstrdup(argv_[i]); + } + } + /* ovn-nbctl has three operation modes: * * - Direct: Executes commands by contacting ovsdb-server directly. @@ -240,6 +271,7 @@ main(int argc, char *argv[]) idl = the_idl = NULL; free(args); + free(argv); exit(EXIT_SUCCESS); } diff --git a/utilities/ovn-sbctl.8.in b/utilities/ovn-sbctl.8.in index 2aaa457e8..b9cfde897 100644 --- a/utilities/ovn-sbctl.8.in +++ b/utilities/ovn-sbctl.8.in @@ -93,6 +93,12 @@ to approximately \fIsecs\fR seconds. If the timeout expires, would normally happen only if the database cannot be contacted, or if the system is overloaded.) . +.IP "\fBOVN_SBCTL_OPTIONS\fR" +If \fBOVN_SBCTL_OPTIONS\fR environment variable is set, +its value is used as the default to set above options. If user +passes options via cli, \fBOVN_SBCTL_OPTIONS\fR environment +variable will have no effect. +. .so lib/vlog.man .so lib/common.man . diff --git a/utilities/ovn-sbctl.c b/utilities/ovn-sbctl.c index 9a9b6f0ec..51bfe7101 100644 --- a/utilities/ovn-sbctl.c +++ b/utilities/ovn-sbctl.c @@ -93,7 +93,7 @@ static bool do_sbctl(const char *args, struct ctl_command *, size_t n, struct ovsdb_idl *); int -main(int argc, char *argv[]) +main(int argc, char *argv_[]) { struct ovsdb_idl *idl; struct ctl_command *commands; @@ -101,13 +101,44 @@ main(int argc, char *argv[]) unsigned int seqno; size_t n_commands; - set_program_name(argv[0]); + set_program_name(argv_[0]); fatal_ignore_sigpipe(); vlog_set_levels(NULL, VLF_CONSOLE, VLL_WARN); vlog_set_levels_from_string_assert("reconnect:warn"); sbctl_cmd_init(); + /* Check if options are set via env var. */ + static int ops_passed = false; + int i, j = 0; + char *ovn_sbctl_options = getenv("OVN_SBCTL_OPTIONS"); + char **argv = xcalloc(argc + 1, sizeof( *argv_) + 1); + if (ovn_sbctl_options) { + for (i = 0; i < argc; i++) { + if (strcmp(argv_[i], ovn_sbctl_options) == 0) { + ops_passed = true; + break; + } + } + /* if option not passed via cli, read env var set by user.*/ + if (!ops_passed) { + for (i = 0, j = 0; i < argc; i++, j++) { + if (j == 1) { + argv[j] = ovn_sbctl_options; + j++; + } + argv[j] = xstrdup(argv_[i]); + } + argc = j; + } + } + if (ops_passed || !ovn_sbctl_options) { + /* Copy args for parsing as is from argv_ */ + for (i = 0; i < argc; i++) { + argv[i] = xstrdup(argv_[i]); + } + } + /* Parse command line. */ char *args = process_escape_args(argv); shash_init(&local_options); @@ -147,6 +178,7 @@ main(int argc, char *argv[]) seqno = ovsdb_idl_get_seqno(idl); if (do_sbctl(args, commands, n_commands, idl)) { free(args); + free(argv); exit(EXIT_SUCCESS); } }