diff mbox series

[ovs-dev,v2,2/3] ovs-save: Use a file to restore flows instead of heredoc

Message ID b29194c2dff42280b9a36e3cece7ab5f545d54ba.1506350315.git.tredaelli@redhat.com
State Accepted
Headers show
Series ovs-save: Some refactors to speed-up save-flows | expand

Commit Message

Timothy Redaelli Sept. 25, 2017, 2:44 p.m. UTC
This patch makes ovs-save to use a file to restore flows instead of using
shell script here-document.
This is needed since eval + here-documents are much slower than reading a file
with the rules directly.

Signed-off-by: Timothy Redaelli <tredaelli@redhat.com>
---
 utilities/ovs-save | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

Comments

Flavio Leitner Oct. 17, 2017, 5:27 p.m. UTC | #1
On Mon, 25 Sep 2017 16:44:05 +0200
Timothy Redaelli <tredaelli@redhat.com> wrote:

> This patch makes ovs-save to use a file to restore flows instead of using
> shell script here-document.
> This is needed since eval + here-documents are much slower than reading a file
> with the rules directly.
> 
> Signed-off-by: Timothy Redaelli <tredaelli@redhat.com>
> ---
>  utilities/ovs-save | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
> 

Acked-by: Flavio Leitner <fbl@sysclose.org>
Thanks!
fbl
Ben Pfaff Oct. 27, 2017, 4:55 p.m. UTC | #2
On Tue, Oct 17, 2017 at 03:27:31PM -0200, Flavio Leitner wrote:
> On Mon, 25 Sep 2017 16:44:05 +0200
> Timothy Redaelli <tredaelli@redhat.com> wrote:
> 
> > This patch makes ovs-save to use a file to restore flows instead of using
> > shell script here-document.
> > This is needed since eval + here-documents are much slower than reading a file
> > with the rules directly.
> > 
> > Signed-off-by: Timothy Redaelli <tredaelli@redhat.com>
> > ---
> >  utilities/ovs-save | 13 +++++++------
> >  1 file changed, 7 insertions(+), 6 deletions(-)
> > 
> 
> Acked-by: Flavio Leitner <fbl@sysclose.org>
> Thanks!

Thanks Flavio and Timothy, I applied this to master.
diff mbox series

Patch

diff --git a/utilities/ovs-save b/utilities/ovs-save
index fc9418c3d..da65c41ec 100755
--- a/utilities/ovs-save
+++ b/utilities/ovs-save
@@ -110,6 +110,7 @@  save_flows () {
         exit 1
     fi
 
+    workdir=$(mktemp -d "${TMPDIR:-/tmp}/ovs-save.XXXXXXXXXX")
     for bridge in "$@"; do
         # Get the highest enabled OpenFlow version
         ofp_version=$(get_highest_ofp_version "$bridge")
@@ -120,19 +121,19 @@  save_flows () {
              cnt++;printf "{class="$1",type="$2",len="$3"}->"$4}'
         echo "'"
 
-        echo -n "ovs-ofctl -O $ofp_version add-flows ${bridge} "
+        echo -n "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 -n "--bundle "
-
-        echo  "- << EOF"
+        [ ${ofp_version#OpenFlow} -ge 14 ] && echo " --bundle" || echo
 
         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'
-        echo "EOF"
+                -e 's/\(idle\|hard\)_age=[^,]*,//g' > \
+                "$workdir/$bridge.flows.dump"
     done
+    echo "rm -rf \"$workdir\""
 }
 
 while [ $# -ne 0 ]