From patchwork Tue Aug 8 14:42:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timothy Redaelli X-Patchwork-Id: 799223 X-Patchwork-Delegate: rbryant@redhat.com 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=) 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 3xRcdc4lybz9s78 for ; Wed, 9 Aug 2017 00:45:39 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 43470A49; Tue, 8 Aug 2017 14:45:36 +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 BC2438E2 for ; Tue, 8 Aug 2017 14:45:34 +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 E2A4044A for ; Tue, 8 Aug 2017 14:43:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 309E1C047B7D for ; Tue, 8 Aug 2017 14:42:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 309E1C047B7D Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=tredaelli@redhat.com Received: from graphite.redhat.com (ovpn-117-100.ams2.redhat.com [10.36.117.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9EB00776E0 for ; Tue, 8 Aug 2017 14:42:15 +0000 (UTC) From: Timothy Redaelli To: dev@openvswitch.org Date: Tue, 8 Aug 2017 16:42:12 +0200 Message-Id: <9efeb6665651db4c5c42717913d13b1c439db90c.1502202677.git.tredaelli@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 08 Aug 2017 14:42:16 +0000 (UTC) X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH] rhel: Add support for "systemctl reload openvswitch" 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 The reload procedure will trigger a script that saves the flows and tlv maps then it restarts ovsdb-server, it stops ovs-vswitchd, it sets other_config:flow-restore-wait=true (to wait till flow restore is finished), it starts ovs-vswitchd, it restore the backupped flows/tlv maps and it removes other_config:flow-restore-wait=true (logic mostly ripped from ovs-ctl). It uses systemctl with --job-mode=ignore-dependencies to restart ovsdb-server and stop and start ovs-vswitchd in order to avoid systemd to restart the other components due to dependencies (as explained in rhel/README.RHEL.rst). It also uses --bundle, when available, in order to minimize the downtime. Signed-off-by: Timothy Redaelli --- rhel/automake.mk | 1 + rhel/openvswitch-fedora.spec.in | 5 ++ rhel/usr_lib_systemd_system_openvswitch.service | 2 +- rhel/usr_lib_systemd_system_ovsdb-server.service | 1 - rhel/usr_share_openvswitch_scripts_ovs-reload | 73 ++++++++++++++++++++++++ 5 files changed, 80 insertions(+), 2 deletions(-) create mode 100755 rhel/usr_share_openvswitch_scripts_ovs-reload diff --git a/rhel/automake.mk b/rhel/automake.mk index 1265fa747..93dbeac0c 100644 --- a/rhel/automake.mk +++ b/rhel/automake.mk @@ -23,6 +23,7 @@ EXTRA_DIST += \ rhel/openvswitch.spec.in \ rhel/openvswitch-fedora.spec \ rhel/openvswitch-fedora.spec.in \ + rhel/usr_share_openvswitch_scripts_ovs-reload \ rhel/usr_share_openvswitch_scripts_sysconfig.template \ rhel/usr_share_openvswitch_scripts_systemd_sysconfig.template \ rhel/usr_lib_systemd_system_openvswitch.service \ diff --git a/rhel/openvswitch-fedora.spec.in b/rhel/openvswitch-fedora.spec.in index 1cad9406e..dc92ab3ca 100644 --- a/rhel/openvswitch-fedora.spec.in +++ b/rhel/openvswitch-fedora.spec.in @@ -289,6 +289,10 @@ install -d -m 0755 $RPM_BUILD_ROOT%{_prefix}/lib/ocf/resource.d/ovn ln -s %{_datadir}/openvswitch/scripts/ovndb-servers.ocf \ $RPM_BUILD_ROOT%{_prefix}/lib/ocf/resource.d/ovn/ovndb-servers +install -p -D -m 0755 \ + rhel/usr_share_openvswitch_scripts_ovs-reload \ + $RPM_BUILD_ROOT%{_datadir}/openvswitch/scripts/ovs-reload + # remove unpackaged files rm -f $RPM_BUILD_ROOT%{_bindir}/ovs-parse-backtrace \ $RPM_BUILD_ROOT%{_sbindir}/ovs-vlan-bug-workaround \ @@ -493,6 +497,7 @@ fi %{_datadir}/openvswitch/scripts/ovs-save %{_datadir}/openvswitch/scripts/ovs-vtep %{_datadir}/openvswitch/scripts/ovs-ctl +%{_datadir}/openvswitch/scripts/ovs-reload %config %{_datadir}/openvswitch/vswitch.ovsschema %config %{_datadir}/openvswitch/vtep.ovsschema %{_bindir}/ovs-appctl diff --git a/rhel/usr_lib_systemd_system_openvswitch.service b/rhel/usr_lib_systemd_system_openvswitch.service index faca44b54..2cf29f0e9 100644 --- a/rhel/usr_lib_systemd_system_openvswitch.service +++ b/rhel/usr_lib_systemd_system_openvswitch.service @@ -9,7 +9,7 @@ Requires=ovs-vswitchd.service [Service] Type=oneshot ExecStart=/bin/true -ExecReload=/bin/true +ExecReload=/usr/share/openvswitch/scripts/ovs-reload ExecStop=/bin/true RemainAfterExit=yes diff --git a/rhel/usr_lib_systemd_system_ovsdb-server.service b/rhel/usr_lib_systemd_system_ovsdb-server.service index 68deace7c..b9814bae1 100644 --- a/rhel/usr_lib_systemd_system_ovsdb-server.service +++ b/rhel/usr_lib_systemd_system_ovsdb-server.service @@ -2,7 +2,6 @@ Description=Open vSwitch Database Unit After=syslog.target network-pre.target Before=network.target network.service -ReloadPropagatedFrom=openvswitch.service PartOf=openvswitch.service [Service] diff --git a/rhel/usr_share_openvswitch_scripts_ovs-reload b/rhel/usr_share_openvswitch_scripts_ovs-reload new file mode 100755 index 000000000..793257390 --- /dev/null +++ b/rhel/usr_share_openvswitch_scripts_ovs-reload @@ -0,0 +1,73 @@ +#! /bin/sh + +# Copyright (c) 2017 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Highest OpenFlow version enabled by default +DEFAULT_OFP_VERSION=OpenFlow14 + +get_highest_ofp_version() { + ovs-vsctl get bridge "$1" protocols | \ + awk -v default_ofp_version="$DEFAULT_OFP_VERSION" \ + -F '"' '{ print (NF>1)? $(NF-1) : default_ofp_version }' +} + +save_flows () { + for bridge; do + # Get the highest enabled OpenFlow version + ofp_version=$(get_highest_ofp_version "$bridge") + + printf "ovs-ofctl -O $ofp_version add-tlv-map %s '" "$bridge" + ovs-ofctl -O $ofp_version dump-tlv-map $bridge | \ + awk '/^ 0x/ {if (cnt != 0) printf ","; \ + cnt++;printf "{class="$1",type="$2",len="$3"}->"$4}' + echo "'" + + printf "%s" "ovs-ofctl -O $ofp_version add-flows $bridge \ + \"$workdir/$bridge.flows.dump\"" + + # If possible, use OpenFlow 1.4 atomic bundle transaction to add flows + [ ${ofp_version#OpenFlow} -ge 14 ] && echo " --bundle" + + ovs-ofctl -O $ofp_version dump-flows --no-names --no-stats "$bridge" | \ + sed -e '/NXST_FLOW/d' \ + -e '/OFPST_FLOW/d' \ + -e 's/\(idle\|hard\)_age=[^,]*,//g' \ + > "$workdir/$bridge.flows.dump" + done +} + +workdir=$(mktemp -d) +trap 'rm -rf "$workdir"' EXIT + +# Save flows +bridges=$(ovs-vsctl -- --real list-br) +flows=$(save_flows $bridges) + +# Restart the database first, since a large database may take a +# while to load, and we want to minimize forwarding disruption. +systemctl --job-mode=ignore-dependencies restart ovsdb-server + +# Stop ovs-vswitchd. +systemctl --job-mode=ignore-dependencies stop ovs-vswitchd + +# Start vswitchd by asking it to wait till flow restore is finished. +ovs-vsctl --no-wait set open_vswitch . other_config:flow-restore-wait=true +systemctl --job-mode=ignore-dependencies start ovs-vswitchd + +# Restore saved flows and inform vswitchd that we are done. +eval "$flows" +ovs-vsctl --if-exists remove open_vswitch . other_config flow-restore-wait=true + +exit 0