From patchwork Mon Oct 21 00:51:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Zhou X-Patchwork-Id: 1180144 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) 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=none (p=none dis=none) header.from=ovn.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 46xJHF0jLKz9sPT for ; Mon, 21 Oct 2019 12:01:13 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 6FF0ACF3; Mon, 21 Oct 2019 00:52:04 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp2.linuxfoundation.org (smtp2.linux-foundation.org [172.17.192.36]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 17810D36 for ; Mon, 21 Oct 2019 00:52:03 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by smtp2.linuxfoundation.org (Postfix) with ESMTPS id 424FE1DAA7 for ; Mon, 21 Oct 2019 00:52:02 +0000 (UTC) Received: from localhost.localdomain.localdomain (unknown [216.113.160.71]) (Authenticated sender: hzhou@ovn.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id AC96F100003; Mon, 21 Oct 2019 00:51:59 +0000 (UTC) From: Han Zhou To: dev@openvswitch.org Date: Sun, 20 Oct 2019 17:51:17 -0700 Message-Id: <1571619079-75503-18-git-send-email-hzhou@ovn.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1571619079-75503-1-git-send-email-hzhou@ovn.org> References: <1571619079-75503-1-git-send-email-hzhou@ovn.org> X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp2.linux-foundation.org Cc: Han Zhou Subject: [ovs-dev] [PATCH ovn 17/19] ovn-ctl: Refactor to reduce redundant code. 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 patch helps reducing redundant code in next patch for adding support for interconnection related DBs and daemon. Signed-off-by: Han Zhou --- utilities/ovn-ctl | 61 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/utilities/ovn-ctl b/utilities/ovn-ctl index 576a983..2e4e773 100755 --- a/utilities/ovn-ctl +++ b/utilities/ovn-ctl @@ -42,16 +42,18 @@ pidfile_is_running () { test -e "$pidfile" && [ -s "$pidfile" ] && pid=`cat "$pidfile"` && pid_exists "$pid" } >/dev/null 2>&1 -stop_nb_ovsdb() { - if pidfile_is_running $DB_NB_PID; then - ovn-appctl -t $OVN_RUNDIR/ovnnb_db.ctl exit +stop_xx_ovsdb() { + if pidfile_is_running $1; then + ovn-appctl -t $OVN_RUNDIR/$2 exit fi } +stop_nb_ovsdb() { + stop_xx_ovsdb $DB_NB_PID ovnnb_db.ctl +} + stop_sb_ovsdb() { - if pidfile_is_running $DB_SB_PID; then - ovn-appctl -t $OVN_RUNDIR/ovnsb_db.ctl exit - fi + stop_xx_ovsdb $DB_SB_PID ovnsb_db.ctl } stop_ovsdb () { @@ -59,42 +61,49 @@ stop_ovsdb () { stop_sb_ovsdb } -demote_ovnnb() { - if test ! -z "$DB_NB_SYNC_FROM_ADDR"; then - echo "$DB_NB_SYNC_FROM_PROTO:$DB_NB_SYNC_FROM_ADDR:$DB_NB_SYNC_FROM_PORT" > $ovnnb_active_conf_file +demote_xx_ovsdb () { + local sync_from_addr=$1 + local sync_from_proto=$2 + local sync_from_port=$3 + local active_conf_file=$4 + local ctl_file=$5 + + if test ! -z "$sync_from_addr"; then + echo "$sync_from_proto:$sync_from_addr:$sync_from_port" > $active_conf_file fi - if test -e $ovnnb_active_conf_file; then - ovn-appctl -t $OVN_RUNDIR/ovnnb_db.ctl ovsdb-server/set-active-ovsdb-server `cat $ovnnb_active_conf_file` - ovn-appctl -t $OVN_RUNDIR/ovnnb_db.ctl ovsdb-server/connect-active-ovsdb-server + if test -e $active_conf_file; then + ovn-appctl -t $OVN_RUNDIR/$ctl_file ovsdb-server/set-active-ovsdb-server `cat $active_conf_file` + ovn-appctl -t $OVN_RUNDIR/$ctl_file ovsdb-server/connect-active-ovsdb-server else echo >&2 "$0: active server details not set" exit 1 fi } +demote_ovnnb() { + demote_xx_ovsdb $DB_NB_SYNC_FROM_ADDR $DB_NB_SYNC_FROM_PROTO \ + $DB_NB_SYNC_FROM_PORT $ovnnb_active_conf_file ovnnb_db.ctl +} + demote_ovnsb() { - if test ! -z "$DB_SB_SYNC_FROM_ADDR"; then - echo "$DB_SB_SYNC_FROM_PROTO:$DB_SB_SYNC_FROM_ADDR:$DB_SB_SYNC_FROM_PORT" > $ovnsb_active_conf_file - fi + demote_xx_ovsdb $DB_SB_SYNC_FROM_ADDR $DB_SB_SYNC_FROM_PROTO \ + $DB_SB_SYNC_FROM_PORT $ovnsb_active_conf_file ovnsb_db.ctl +} - if test -e $ovnsb_active_conf_file; then - ovn-appctl -t $OVN_RUNDIR/ovnsb_db.ctl ovsdb-server/set-active-ovsdb-server `cat $ovnsb_active_conf_file` - ovn-appctl -t $OVN_RUNDIR/ovnsb_db.ctl ovsdb-server/connect-active-ovsdb-server - else - echo >&2 "$0: active server details not set" - exit 1 - fi +promote_xx_ovsdb() { + local active_conf_file=$1 + local ctl_file=$2 + rm -f $active_conf_file + ovn-appctl -t $OVN_RUNDIR/$2 ovsdb-server/disconnect-active-ovsdb-server } promote_ovnnb() { - rm -f $ovnnb_active_conf_file - ovn-appctl -t $OVN_RUNDIR/ovnnb_db.ctl ovsdb-server/disconnect-active-ovsdb-server + promote_xx_ovsdb $ovnnb_active_conf_file ovnnb_db.ctl } promote_ovnsb() { - rm -f $ovnsb_active_conf_file - ovn-appctl -t $OVN_RUNDIR/ovnsb_db.ctl ovsdb-server/disconnect-active-ovsdb-server + promote_xx_ovsdb $ovnsb_active_conf_file ovnsb_db.ctl } start_ovsdb__() {