]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-scripts: Use ctdb_killtcp helper to kill connections
authorMartin Schwenke <martin@meltin.net>
Fri, 11 Mar 2016 04:30:47 +0000 (15:30 +1100)
committerAmitay Isaacs <amitay@samba.org>
Fri, 1 Apr 2016 02:42:12 +0000 (04:42 +0200)
ctdb_killtcp will take up to 5 seconds to kill connections, so don't
wait in a loop.  Just check if there are remaining connections on
completion and log a message either way.

Also add a test stub.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/config/functions
ctdb/tests/eventscripts/10.interface.releaseip.011.sh
ctdb/tests/eventscripts/stubs/ctdb_killtcp [new file with mode: 0755]

index aab7a143529c18d2a85a664daab7af3d4a38a148..7c28e4ce04b6eefcb9b893bbc87af9a523546630 100755 (executable)
@@ -464,29 +464,21 @@ kill_tcp_connections ()
            return
        fi
 
-       echo "$_connections" | ctdb killtcp || {
-           echo "Failed to send killtcp control"
-           return
+       echo "$_connections" | \
+               "${CTDB_HELPER_BINDIR}/ctdb_killtcp" "$_iface" || {
+               echo "Failed to kill TCP connections"
+               return
        }
 
-       _count=0
-       while : ; do
-           _remaining=$(get_tcp_connections_for_ip $_ip | wc -l)
+       _remaining=$(get_tcp_connections_for_ip $_ip | wc -l)
 
-           if [ $_remaining -eq 0 ] ; then
+       if [ $_remaining -eq 0 ] ; then
                echo "Killed $_killcount TCP connections to released IP $_ip"
                return
-           fi
-
-           _count=$(($_count + 1))
-           if [ $_count -gt 3 ] ; then
-               echo "Timed out killing tcp connections for IP $_ip ($_remaining remaining)"
-               return
-           fi
+       fi
 
-           echo "Waiting for $_remaining connections to be killed for IP $_ip"
-           sleep 1
-       done
+       _t="${_remaining}/${_killcount}"
+       echo "Failed to kill TCP connections for IP $_ip (${_t} remaining)"
     }
 }
 
index e1514eea8806ee4e667dddb93b3a94efd0c40eb9..6203b97e2f5285aa4623b9ddbb725286e08cf877 100755 (executable)
@@ -31,10 +31,7 @@ while read dev ip bits ; do
     ok <<EOF
 Killing TCP connection 10.254.254.1:43210 ${ip}:445
 $out
-Waiting for 1 connections to be killed for IP ${ip}
-Waiting for 1 connections to be killed for IP ${ip}
-Waiting for 1 connections to be killed for IP ${ip}
-Timed out killing tcp connections for IP $ip (1 remaining)
+Failed to kill TCP connections for IP 10.0.0.3 (1/11 remaining)
 EOF
 
     simple_test $dev $ip $bits
diff --git a/ctdb/tests/eventscripts/stubs/ctdb_killtcp b/ctdb/tests/eventscripts/stubs/ctdb_killtcp
new file mode 100755 (executable)
index 0000000..cb5b6e5
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+# Only supports reading from stdin
+
+iface="$1"  # ignored
+
+while read src dst ; do
+       sed -i -e "/^${dst} ${src}\$/d" "$FAKE_NETSTAT_TCP_ESTABLISHED_FILE"
+done