]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-scripts: Protect against races when starting grace period
authorMartin Schwenke <mschwenke@ddn.com>
Fri, 10 May 2024 08:00:18 +0000 (18:00 +1000)
committerVolker Lendecke <vl@samba.org>
Thu, 30 May 2024 12:50:01 +0000 (12:50 +0000)
While the PID check is worth it in relevant cases, NFS-Ganesha still
might go away after the check.  Unfortunately, neither grace command
fails an indicative exit code, so invent one by checking error
messages.  This can then be converted to success by the caller.

Signed-off-by: Martin Schwenke <mschwenke@ddn.com>
Reviewed-by: Volker Lendecke <vl@samba.org>
Autobuild-User(master): Volker Lendecke <vl@samba.org>
Autobuild-Date(master): Thu May 30 12:50:01 UTC 2024 on atb-devel-224

ctdb/doc/examples/nfs-ganesha-callout

index b0017d6cc102ade31075e2f8e9452ff4f474107f..8b7df88456e16e8b101dd0d8fd95765623b5a17b 100755 (executable)
@@ -272,13 +272,34 @@ grace_period()
 {
        _arg="$1"
 
+       _gp_status=0
        if [ -x "/usr/bin/grace_period" ]; then
-               /usr/bin/grace_period "$_arg"
+               _out=$(/usr/bin/grace_period "$_arg" 2>&1) ||
+                       _gp_status=$?
+               _down_msg="Error: Can't talk to ganesha service on d-bus"
        else
-               dbus-send --print-reply --system --dest=org.ganesha.nfsd \
+               _out=$(dbus-send \
+                       --print-reply --system --dest=org.ganesha.nfsd \
                        /org/ganesha/nfsd/admin org.ganesha.nfsd.admin.grace \
-                       string:"$_arg"
+                       string:"$_arg" 2>&1) ||
+                       _gp_status=$?
+               _down_msg="Error org.freedesktop.DBus.Error.ServiceUnknown"
        fi
+
+       if [ -n "$_out" ]; then
+               echo "$_out"
+       fi
+
+       if [ $_gp_status -ne 0 ]; then
+               # If $_out contains $_down_msg then NFS-Ganesha is
+               # either down or is starting, so will be in grace
+               # anyway.
+               if [ "${_out#*"${_down_msg}"}" != "$_out" ]; then
+                       return 3 # ESRCH - No such process
+               fi
+       fi
+
+       return $_gp_status
 }
 
 grace_period_if_running()
@@ -290,7 +311,17 @@ grace_period_if_running()
                return 0
        fi
 
-       grace_period "$_arg"
+       _status=0
+       grace_period "$_arg" || _status=$?
+       case $_status in
+       3)
+               # Convert to success
+               return 0
+               ;;
+       *)
+               return $_status
+               ;;
+       esac
 }
 
 nfs_startipreallocate()