]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-scripts: Factor out function kill_tcp_summarise()
authorMartin Schwenke <mschwenke@ddn.com>
Fri, 25 Aug 2023 00:00:57 +0000 (10:00 +1000)
committerMartin Schwenke <martins@samba.org>
Wed, 6 Nov 2024 23:03:42 +0000 (23:03 +0000)
This will be used in a slightly different context in a subsequent
commit.  In that case, the number of killed connections will be passed
instead of the total number of connections, so support this here via
different modes instead of churning later.

Signed-off-by: Martin Schwenke <mschwenke@ddn.com>
Reviewed-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jerry Heyman <jheyman@ddn.com>
ctdb/config/functions

index ad191ac44686974f777582764056d56cec24a9ec..d1579e5156c3e00ea1d5bc90a3a9c7abf86bc85a 100755 (executable)
@@ -509,6 +509,38 @@ ctdb_check_unix_socket()
 ################################################
 # kill off any TCP connections with the given IP
 ################################################
+
+kill_tcp_summarise()
+{
+       _mode="$1"
+       _count="$2"
+
+       _connections=$(get_tcp_connections_for_ip "$_ip")
+       if [ -z "$_connections" ]; then
+               _remaining=0
+       else
+               _remaining=$(echo "$_connections" | wc -l)
+       fi
+
+       case "$_mode" in
+       total)
+               _total="$_count"
+               _killed=$((_total - _remaining))
+               ;;
+       killed)
+               _killed="$_count"
+               _total=$((_killed + _remaining))
+               ;;
+       esac
+
+       _t="${_killed}/${_total}"
+       echo "Killed ${_t} TCP connections to released IP ${_ip}"
+       if [ -n "$_connections" ]; then
+               echo "Remaining connections:"
+               echo "$_connections" | sed -e 's|^|  |'
+       fi
+}
+
 kill_tcp_connections()
 {
        _iface="$1"
@@ -556,22 +588,7 @@ kill_tcp_connections()
                        return
                }
 
-               _connections=$(get_tcp_connections_for_ip "$_ip")
-               if [ -z "$_connections" ]; then
-                       _remaining=0
-               else
-                       _remaining=$(echo "$_connections" | wc -l)
-               fi
-
-               _actually_killed=$((_killcount - _remaining))
-
-               _t="${_actually_killed}/${_killcount}"
-               echo "Killed ${_t} TCP connections to released IP $_ip"
-
-               if [ -n "$_connections" ]; then
-                       echo "Remaining connections:"
-                       echo "$_connections" | sed -e 's|^|  |'
-               fi
+               kill_tcp_summarise "total" "$_killcount"
        }
 }