From patchwork Thu Aug 1 18:43:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Michelson X-Patchwork-Id: 1140691 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 45zzjP2Tt6z9s00 for ; Fri, 2 Aug 2019 04:44:23 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 4B5D23187; Thu, 1 Aug 2019 18:44:20 +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 E7C42315E for ; Thu, 1 Aug 2019 18:43:46 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 3236189D for ; Thu, 1 Aug 2019 18:43:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 95B2819DE6C for ; Thu, 1 Aug 2019 18:43:45 +0000 (UTC) Received: from monae.redhat.com (ovpn-122-92.rdu2.redhat.com [10.10.122.92]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2EF03600C4 for ; Thu, 1 Aug 2019 18:43:43 +0000 (UTC) From: Mark Michelson To: dev@openvswitch.org Date: Thu, 1 Aug 2019 14:43:38 -0400 Message-Id: <20190801184338.4310-1-mmichels@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 01 Aug 2019 18:43:45 +0000 (UTC) X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH ovn] Add -u option to 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 This option can be used in one of two ways. When paired with --detach, this creates a unixctl socket with the name given as the argument to '-u'. When not paired with --detach, this tells the ovn-nbctl client the name of the unixctl socket to attempt to connect to. Signed-off-by: Mark Michelson Acked-by: Numan Siddique --- tests/ovn.at | 19 +++++++++++++++++++ utilities/ovn-nbctl.8.xml | 20 ++++++++++++++++++++ utilities/ovn-nbctl.c | 17 +++++++++++++++-- 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/tests/ovn.at b/tests/ovn.at index e88cffa20..533594849 100644 --- a/tests/ovn.at +++ b/tests/ovn.at @@ -14990,3 +14990,22 @@ OVN_CHECK_PACKETS([hv2/vif3-tx.pcap], [expected]) OVN_CLEANUP([hv1], [hv2]) AT_CLEANUP + +AT_SETUP([ovn -- unixctl socket]) +ovn_start + +sockfile="$at_group_dir/my_sock.ctl" + +# Specifying -u should fail since we have no daemon running +AT_CHECK([ovn-nbctl -u $sockfile show], [1], [ignore], [ignore]) + +AT_CHECK_UNQUOTED([ovn-nbctl --detach -u $sockfile --pidfile], [0], [$sockfile +]) +AT_CHECK([if test -f "$sockfile" ; then exit 99 ; fi]) +on_exit 'kill $(cat ovn-nbctl.pid)' + +# We can't confirm that the nbctl client is actually using the sockfile, +# but we can still ensure that the command is successful. +AT_CHECK([ovn-nbctl -u $sockfile show]) + +AT_CLEANUP diff --git a/utilities/ovn-nbctl.8.xml b/utilities/ovn-nbctl.8.xml index 41d50b694..fd75c0e44 100644 --- a/utilities/ovn-nbctl.8.xml +++ b/utilities/ovn-nbctl.8.xml @@ -1085,6 +1085,26 @@ unset OVN_NB_DAEMON +

+ When using daemon mode, an alternative to the OVN_NB_DAEMON environment + variable is to specify a path for the Unix socket. When starting the + ovn-nbctl daemon, specify the -u option with a full path to + the location of the socket file. Here is an exmple: +

+ +
+      ovn-nbctl --detach -u /tmp/mysock.ctl
+    
+ +

+ Then to connect to the running daemon, use the -u option + with the full path to the socket created when the daemon was started: +

+ +
+      ovn-nbctl -u /tmp/mysock.ctl show
+    
+

Daemon mode is experimental.

diff --git a/utilities/ovn-nbctl.c b/utilities/ovn-nbctl.c index ad999dd96..9a2e84530 100644 --- a/utilities/ovn-nbctl.c +++ b/utilities/ovn-nbctl.c @@ -167,8 +167,9 @@ main(int argc, char *argv[]) * - An OVN_NB_DAEMON environment variable implies client mode. * * - Otherwise, we're in direct mode. */ - char *socket_name = getenv("OVN_NB_DAEMON"); - if (socket_name && socket_name[0] + char *socket_name = unixctl_path ?: getenv("OVN_NB_DAEMON"); + if (((socket_name && socket_name[0]) + || has_option(parsed_options, n_parsed_options, 'u')) && !will_detach(parsed_options, n_parsed_options)) { nbctl_client(socket_name, parsed_options, n_parsed_options, argc, argv); @@ -422,6 +423,7 @@ get_all_options(void) {"shuffle-remotes", no_argument, NULL, OPT_SHUFFLE_REMOTES}, {"no-shuffle-remotes", no_argument, NULL, OPT_NO_SHUFFLE_REMOTES}, {"version", no_argument, NULL, 'V'}, + {"unixctl", required_argument, NULL, 'u'}, MAIN_LOOP_LONG_OPTIONS, DAEMON_LONG_OPTIONS, VLOG_LONG_OPTIONS, @@ -533,6 +535,10 @@ apply_options_direct(const struct ovs_cmdl_parsed_option *parsed_options, shuffle_remotes = false; break; + case 'u': + unixctl_path = optarg; + break; + case 'V': ovs_print_version(0, 0); printf("DB Schema %s\n", nbrec_get_db_version()); @@ -5996,6 +6002,10 @@ nbctl_client(const char *socket_name, po->o->name); break; + case 'u': + socket_name = optarg; + break; + case 'V': ovs_print_version(0, 0); printf("DB Schema %s\n", nbrec_get_db_version()); @@ -6020,6 +6030,9 @@ nbctl_client(const char *socket_name, break; } } + + ovs_assert(socket_name && socket_name[0]); + svec_add(&args, "--"); for (int i = optind; i < argc; i++) { svec_add(&args, argv[i]);