From patchwork Wed Jan 29 19:56:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Zhou X-Patchwork-Id: 1231081 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.166.137; helo=fraxinus.osuosl.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 fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 487Dlc4mbRz9sNT for ; Thu, 30 Jan 2020 06:57:00 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 2545786193; Wed, 29 Jan 2020 19:56:59 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id T4gO27KpXVIJ; Wed, 29 Jan 2020 19:56:57 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id BC53186054; Wed, 29 Jan 2020 19:56:47 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 91A13C1D8B; Wed, 29 Jan 2020 19:56:47 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 17861C0171 for ; Wed, 29 Jan 2020 19:56:46 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 1268286132 for ; Wed, 29 Jan 2020 19:56:46 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id aVLZVcmIxFM5 for ; Wed, 29 Jan 2020 19:56:44 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by fraxinus.osuosl.org (Postfix) with ESMTPS id E8C84860C5 for ; Wed, 29 Jan 2020 19:56:39 +0000 (UTC) X-Originating-IP: 216.113.160.77 Received: from localhost.localdomain.localdomain (unknown [216.113.160.77]) (Authenticated sender: hzhou@ovn.org) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id C123C240007; Wed, 29 Jan 2020 19:56:37 +0000 (UTC) From: Han Zhou To: dev@openvswitch.org Date: Wed, 29 Jan 2020 11:56:06 -0800 Message-Id: <1580327768-36501-12-git-send-email-hzhou@ovn.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1580327768-36501-1-git-send-email-hzhou@ovn.org> References: <1580327768-36501-1-git-send-email-hzhou@ovn.org> Cc: Han Zhou Subject: [ovs-dev] [PATCH ovn v4 11/13] ovn-ctl: Refactor to reduce redundant code. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" 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__() {