The branch, master has been updated via 80ba66013ef ctdb-scripts: Drop use of eval in CTDB callout handling via 4cbb0b13ba2 ctdb-tests: Do not require eval tricks for faking NFS callout via 0247fd8a02b ctdb-scripts: Avoid ShellCheck warning SC2162 via 7f799a8d6f8 ctdb-tests: Fix faking of program stack traces via 0b728a4e8f6 ctdb-tests: Improve Debian-style event script unit testing via 7f3a0c7e9c5 ctdb-scripts: Parameterise /etc directory to aid testing via 337ef7c1b41 ctdb-scripts: Set NFS services to "AUTO" if started by another service via 8b8660d883c ctdb-scripts: Refactor the manual RPC service start/stop via cd018d0ff5c ctdb-scripts: Simplify and rename basic_stop() and basic_start() via 09fd1e55796 ctdb-scripts: Move nfslock out of basic_stop() and basic_start() via a43a1ebe51d ctdb-tests: Reformat script from 8458449ddf1 s3:waf: Fix version number of public libsmbconf
https://git.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit 80ba66013efeec2f2df8429321a8630ef7780a8f Author: Martin Schwenke <mar...@meltin.net> Date: Fri May 27 23:19:46 2022 +1000 ctdb-scripts: Drop use of eval in CTDB callout handling eval is not required and causes the follow ShellCheck warning: SC2294 (warning): eval negates the benefit of arrays. Drop eval to preserve whitespace/symbols (or eval as string). Signed-off-by: Martin Schwenke <mar...@meltin.net> Reviewed-by: Amitay Isaacs <ami...@gmail.com> Autobuild-User(master): Amitay Isaacs <ami...@samba.org> Autobuild-Date(master): Fri Jun 24 10:40:50 UTC 2022 on sn-devel-184 commit 4cbb0b13ba26a4b8de1334f1d166e0cb33d89383 Author: Martin Schwenke <mar...@meltin.net> Date: Fri May 27 23:16:28 2022 +1000 ctdb-tests: Do not require eval tricks for faking NFS callout The current code requires the use of eval in the NFS callout handling to facilitate testing. Improve the code to remove this need. Signed-off-by: Martin Schwenke <mar...@meltin.net> Reviewed-by: Amitay Isaacs <ami...@gmail.com> commit 0247fd8a02bf3840940d781c8323be3fa07c4d5e Author: Martin Schwenke <mar...@meltin.net> Date: Fri Mar 18 13:40:20 2022 +1100 ctdb-scripts: Avoid ShellCheck warning SC2162 SC2162 read without -r will mangle backslashes Signed-off-by: Martin Schwenke <mar...@meltin.net> Reviewed-by: Amitay Isaacs <ami...@gmail.com> commit 7f799a8d6f89d2b9f7ae06858e901981d9cc186a Author: Martin Schwenke <mar...@meltin.net> Date: Fri Mar 18 13:00:40 2022 +1100 ctdb-tests: Fix faking of program stack traces The current code works in all current cases but is lazy and wrong. Fix it to avoid breaking on code changes involving different thread setups. Signed-off-by: Martin Schwenke <mar...@meltin.net> Reviewed-by: Amitay Isaacs <ami...@gmail.com> commit 0b728a4e8f6f81b5c2b44fa65d2b68167eb8e7ce Author: Martin Schwenke <mar...@meltin.net> Date: Fri Mar 18 12:55:07 2022 +1100 ctdb-tests: Improve Debian-style event script unit testing Tests can be run by hand using different distro styles, such as: CTDB_NFS_DISTRO_STYLE=systemd-debian \ ./tests/run_tests.sh ./tests/UNIT/eventscripts/{06,60}.nfs.* This fixes known problems for Debian styles, so the tests now pass for the following values of CTDB_NFS_DISTRO_STYLE: systemd-redhat sysvinit-redhat systemd-debian sysvinit-debian Signed-off-by: Martin Schwenke <mar...@meltin.net> Reviewed-by: Amitay Isaacs <ami...@gmail.com> commit 7f3a0c7e9c5388b5947e0d79105335508967a7ea Author: Martin Schwenke <mar...@meltin.net> Date: Fri Mar 18 12:52:10 2022 +1100 ctdb-scripts: Parameterise /etc directory to aid testing At the moment test results can be influenced by real system configuration files. Signed-off-by: Martin Schwenke <mar...@meltin.net> Reviewed-by: Amitay Isaacs <ami...@gmail.com> commit 337ef7c1b417cce94a6f1480f17dae477fadf565 Author: Martin Schwenke <mar...@meltin.net> Date: Fri Mar 18 12:47:10 2022 +1100 ctdb-scripts: Set NFS services to "AUTO" if started by another service For example, in Sys-V init "rquotad" is started by the main "nfs" service. At the moment the call-out can't distinguish between this case and "should never be run". Services set to "AUTO" are hand-stopped/started via service_stop()/service_start() on failure via restart_after. Signed-off-by: Martin Schwenke <mar...@meltin.net> Reviewed-by: Amitay Isaacs <ami...@gmail.com> commit 8b8660d883cb5130f40fa8993cd4cae96cf1dde4 Author: Martin Schwenke <mar...@meltin.net> Date: Mon May 23 14:21:37 2022 +1000 ctdb-scripts: Refactor the manual RPC service start/stop This logic needs improving, so factor the decision making into new functions service_or_manual_stop() and service_or_manual_start(). Signed-off-by: Martin Schwenke <mar...@meltin.net> Reviewed-by: Amitay Isaacs <ami...@gmail.com> commit cd018d0ff5c57ccd50f64fd0ed1591e3dfe27baf Author: Martin Schwenke <mar...@meltin.net> Date: Fri Mar 18 10:41:26 2022 +1100 ctdb-scripts: Simplify and rename basic_stop() and basic_start() Drop the argument. These now just stop/start the overall NFS service, so rename them appropriately. Signed-off-by: Martin Schwenke <mar...@meltin.net> Reviewed-by: Amitay Isaacs <ami...@gmail.com> commit 09fd1e55796509b08a8cce39420c3c656024455c Author: Martin Schwenke <mar...@meltin.net> Date: Fri Mar 18 10:33:05 2022 +1100 ctdb-scripts: Move nfslock out of basic_stop() and basic_start() These are only called in one place and should be done inline, since that is less confusing. Signed-off-by: Martin Schwenke <mar...@meltin.net> Reviewed-by: Amitay Isaacs <ami...@gmail.com> commit a43a1ebe51d61790a9f762ab04aa5b9d809953d5 Author: Martin Schwenke <mar...@meltin.net> Date: Fri Mar 18 10:53:45 2022 +1100 ctdb-tests: Reformat script Samba is reformatting shell scripts using shfmt -w -p -i 0 -fn so update this one before editing. Signed-off-by: Martin Schwenke <mar...@meltin.net> Reviewed-by: Amitay Isaacs <ami...@gmail.com> ----------------------------------------------------------------------- Summary of changes: ctdb/config/functions | 4 +- ctdb/config/nfs-linux-kernel-callout | 414 ++++++++++++--------- .../UNIT/eventscripts/06.nfs.releaseip.001.sh | 6 +- .../UNIT/eventscripts/06.nfs.releaseip.002.sh | 6 +- ctdb/tests/UNIT/eventscripts/06.nfs.takeip.001.sh | 6 +- ctdb/tests/UNIT/eventscripts/06.nfs.takeip.002.sh | 6 +- ctdb/tests/UNIT/eventscripts/60.nfs.monitor.108.sh | 6 +- ctdb/tests/UNIT/eventscripts/60.nfs.monitor.109.sh | 6 +- .../UNIT/eventscripts/60.nfs.releaseip.002.sh | 6 +- .../tests/UNIT/eventscripts/60.nfs.shutdown.002.sh | 6 +- ctdb/tests/UNIT/eventscripts/60.nfs.startup.002.sh | 6 +- ctdb/tests/UNIT/eventscripts/60.nfs.takeip.002.sh | 6 +- ctdb/tests/UNIT/eventscripts/scripts/60.nfs.sh | 37 +- ctdb/tests/UNIT/eventscripts/scripts/local.sh | 6 + .../tests/UNIT/eventscripts/stubs/nfs-fake-callout | 15 + 15 files changed, 307 insertions(+), 229 deletions(-) create mode 100755 ctdb/tests/UNIT/eventscripts/stubs/nfs-fake-callout Changeset truncated at 500 lines: diff --git a/ctdb/config/functions b/ctdb/config/functions index a4e73ad0594..82ed0957aa0 100755 --- a/ctdb/config/functions +++ b/ctdb/config/functions @@ -920,7 +920,7 @@ nfs_callout_register () echo "$CTDB_NFS_CALLOUT" >"$nfs_callout_cache_callout" - _t=$(eval "$CTDB_NFS_CALLOUT" "register") + _t=$("$CTDB_NFS_CALLOUT" "register") if [ -n "$_t" ] ; then echo "$_t" | while IFS="" read _op ; do @@ -945,7 +945,7 @@ nfs_callout () # Run the operation if it is registered... if [ -e "${nfs_callout_cache_ops}/${1}" ] || \ [ -e "${nfs_callout_cache_ops}/ALL" ]; then - eval "$CTDB_NFS_CALLOUT" "$@" + "$CTDB_NFS_CALLOUT" "$@" fi } diff --git a/ctdb/config/nfs-linux-kernel-callout b/ctdb/config/nfs-linux-kernel-callout index 9c2d0418e55..f2f3e3824d0 100755 --- a/ctdb/config/nfs-linux-kernel-callout +++ b/ctdb/config/nfs-linux-kernel-callout @@ -16,6 +16,16 @@ nfs_exports_file="${CTDB_NFS_EXPORTS_FILE:-/var/lib/nfs/etab}" # test variable only. nfs_distro_style="${CTDB_NFS_DISTRO_STYLE:-systemd-redhat}" +# As above, edit the default value below. CTDB_SYS_ETCDIR is a +# test variable only. +etc_dir="${CTDB_SYS_ETCDIR:-/etc}" + +# A value of "AUTO" for any service means that service is usually +# automatically started and stopped by one of the other services. +# Such services will still be restarted by hand on failure, if +# configured to do so. This allows services that should not be +# running to be set to "". + case "$nfs_distro_style" in systemd-*) # Defaults @@ -24,11 +34,11 @@ systemd-*) nfs_mountd_service="nfs-mountd" nfs_status_service="rpc-statd" nfs_rquotad_service="rpc-rquotad" - nfs_config="/etc/sysconfig/nfs" + nfs_config="${etc_dir}/sysconfig/nfs" nfs_rquotad_config="" # Not use with systemd, restart via service case "$nfs_distro_style" in - *-redhat|*-suse) + *-redhat | *-suse) : # Defaults only ;; *-debian) @@ -37,17 +47,18 @@ systemd-*) *) echo "Internal error" exit 1 + ;; esac ;; sysvinit-*) # Defaults nfs_service="nfs" - nfs_lock_service="" - nfs_mountd_service="" - nfs_status_service="" - nfs_rquotad_service="" - nfs_config="/etc/sysconfig/nfs" + nfs_lock_service="AUTO" + nfs_mountd_service="AUTO" + nfs_status_service="AUTO" + nfs_rquotad_service="AUTO" + nfs_config="${etc_dir}/sysconfig/nfs" nfs_rquotad_config="$nfs_config" case "$nfs_distro_style" in @@ -59,302 +70,334 @@ sysvinit-*) ;; *-debian) nfs_service="nfs-kernel-server" - nfs_config="/etc/default/nfs-kernel-server" - nfs_rquotad_config="/etc/default/quota" + nfs_config="${etc_dir}/default/nfs-kernel-server" + nfs_rquotad_config="${etc_dir}/default/quota" ;; *) echo "Internal error" exit 1 + ;; esac ;; *) echo "Internal error" exit 1 + ;; esac # Override for unit testing -if [ -z "$PROCFS_PATH" ] ; then - PROCFS_PATH="/proc" +if [ -z "$PROCFS_PATH" ]; then + PROCFS_PATH="/proc" fi ################################################## -usage () +usage() { - _c=$(basename "$0") - cat <<EOF + _c=$(basename "$0") + cat <<EOF usage: $_c { shutdown | startup } $_c { stop | start } { nfs | nlockmgr } $_c { monitor-list-shares | monitor-post } $_c { register } EOF - exit 1 + exit 1 } ################################################## -nfs_load_config () +nfs_load_config() { _config="${1:-${nfs_config}}" - if [ -r "$_config" ] ; then + if [ -r "$_config" ]; then . "$_config" fi } ################################################## -# Basic service stop and start -basic_stop () +service_is_auto_started() { - case "$1" in - nfs) - if [ -n "$nfs_rquotad_service" ] ; then - service "$nfs_rquotad_service" stop - fi + [ "$1" = "AUTO" ] +} - service "$nfs_service" stop +service_is_defined() +{ + _service="$1" - if [ -n "$nfs_lock_service" ] ; then - service "$nfs_lock_service" stop - fi - ;; - nfslock) - if [ -n "$nfs_lock_service" ] ; then - service "$nfs_lock_service" stop - else - service "$nfs_service" stop - fi - ;; - *) - usage - esac + [ -n "$_service" ] && ! service_is_auto_started "$_service" } -basic_start () +service_if_defined() { - case "$1" in - nfs) - if [ -n "$nfs_lock_service" ] ; then - service "$nfs_lock_service" start - fi + _service="$1" + _action="$2" + + if service_is_defined "$_service"; then + service "$_service" "$_action" + fi +} - service "$nfs_service" start +################################################## +# Overall NFS service stop and start - if [ -n "$nfs_rquotad_service" ] ; then - service "$nfs_rquotad_service" start - fi +nfs_service_stop() +{ + service_if_defined "$nfs_rquotad_service" stop + + service "$nfs_service" stop + + service_if_defined "$nfs_lock_service" stop +} + +nfs_service_start() +{ + service_if_defined "$nfs_lock_service" start + + service "$nfs_service" start + + service_if_defined "$nfs_rquotad_service" start +} + +################################################## +# service "stop" and "start" options for restarting + +manual_stop() +{ + case "$1" in + mountd) + killall -q -9 rpc.mountd ;; - nfslock) - if [ -n "$nfs_lock_service" ] ; then - service "$nfs_lock_service" start - else - service "$nfs_service" start - fi + rquotad) + killall -q -9 rpc.rquotad + ;; + status) + killall -q -9 rpc.statd ;; *) - usage + echo "$0: Internal error - invalid call to manual_stop()" + exit 1 + ;; esac } -################################################## -# service "stop" and "start" options for restarting +service_or_manual_stop() +{ + _rpc_service="$1" + _system_service="$2" + + if service_is_defined "$_system_service"; then + service "$_system_service" stop + elif service_is_auto_started "$_system_service"; then + manual_stop "$_rpc_service" + fi +} -service_stop () +service_stop() { - case "$1" in + _rpc_service="$1" + + case "$_rpc_service" in nfs) echo 0 >"${PROCFS_PATH}/fs/nfsd/threads" - basic_stop "nfs" >/dev/null 2>&1 || true + nfs_service_stop >/dev/null 2>&1 || true pkill -9 nfsd ;; nlockmgr) - basic_stop "nfslock" >/dev/null 2>&1 || true + if service_is_defined "$nfs_lock_service" ; then + service "$nfs_lock_service" stop >/dev/null 2>&1 || true + else + service "$nfs_service" stop >/dev/null 2>&1 || true + fi ;; mountd) - if [ -n "$nfs_mountd_service" ] ; then - service "$nfs_mountd_service" stop - return - fi - - # Default to stopping by hand - killall -q -9 rpc.mountd + service_or_manual_stop "$_rpc_service" "$nfs_mountd_service" ;; rquotad) - if [ -n "$nfs_rquotad_service" ] ; then - service "$nfs_rquotad_service" stop - return - fi - - # Default to stopping by hand - killall -q -9 rpc.rquotad + service_or_manual_stop "$_rpc_service" "$nfs_rquotad_service" ;; status) - if [ -n "$nfs_status_service" ] ; then - service "$nfs_status_service" stop - return - fi - - # Default to stopping by hand - killall -q -9 rpc.statd + service_or_manual_stop "$_rpc_service" "$nfs_status_service" ;; *) usage + ;; esac } -service_start () +manual_start() { case "$1" in - nfs) - basic_start "nfs" - ;; - nlockmgr) - basic_start "nfslock" - ;; mountd) - if [ -n "$nfs_mountd_service" ] ; then - service "$nfs_mountd_service" start - return - fi - - # Default to starting by hand nfs_load_config - if [ -z "$RPCMOUNTDOPTS" ] ; then + if [ -z "$RPCMOUNTDOPTS" ]; then RPCMOUNTDOPTS="${MOUNTD_PORT:+-p }$MOUNTD_PORT" fi # shellcheck disable=SC2086 rpc.mountd $RPCMOUNTDOPTS ;; rquotad) - if [ -n "$nfs_rquotad_service" ] ; then - service "$nfs_rquotad_service" start - return - fi - - # Default to starting by hand nfs_load_config "$nfs_rquotad_config" - if [ -z "$RPCRQUOTADOPTS" ] ; then + if [ -z "$RPCRQUOTADOPTS" ]; then RPCRQUOTADOPTS="${RQUOTAD_PORT:+-p }$RQUOTAD_PORT" fi # shellcheck disable=SC2086 rpc.rquotad $RPCRQUOTADOPTS ;; status) - if [ -n "$nfs_status_service" ] ; then - service "$nfs_status_service" start - return - fi - - # Default to starting by hand nfs_load_config # Red Hat uses STATDARG, Debian uses STATDOPTS opts="${STATDARG:-${STATDOPTS:-''}}" - if [ -z "$opts" ] ; then + if [ -z "$opts" ]; then # shellcheck disable=SC2086 set -- \ - ${STATD_HA_CALLOUT:+-H} $STATD_HA_CALLOUT \ - ${STATD_HOSTNAME:+-n} $STATD_HOSTNAME \ - ${STATD_PORT:+-p} $STATD_PORT \ - ${STATD_OUTGOING_PORT:+-o} $STATD_OUTGOING_PORT + ${STATD_HA_CALLOUT:+-H} $STATD_HA_CALLOUT \ + ${STATD_HOSTNAME:+-n} $STATD_HOSTNAME \ + ${STATD_PORT:+-p} $STATD_PORT \ + ${STATD_OUTGOING_PORT:+-o} $STATD_OUTGOING_PORT opts="$*" fi # shellcheck disable=SC2086 rpc.statd $opts ;; + *) + echo "$0: Internal error - invalid call to manual_start()" + exit 1 + ;; + esac +} + +service_or_manual_start() +{ + _rpc_service="$1" + _system_service="$2" + + if service_is_defined "$_system_service"; then + service "$_system_service" start + elif service_is_auto_started "$_system_service"; then + manual_start "$_rpc_service" + fi +} + +service_start() +{ + _rpc_service="$1" + + case "$_rpc_service" in + nfs) + nfs_service_start + ;; + nlockmgr) + if service_is_defined "$nfs_lock_service" ; then + service "$nfs_lock_service" start + else + service "$nfs_service" start + fi + ;; + mountd) + service_or_manual_start "$_rpc_service" "$nfs_mountd_service" + ;; + rquotad) + service_or_manual_start "$_rpc_service" "$nfs_rquotad_service" + ;; + status) + service_or_manual_start "$_rpc_service" "$nfs_status_service" + ;; *) usage + ;; esac } ################################################## # service init startup and final shutdown -nfs_shutdown () +nfs_shutdown() { - basic_stop "nfs" + nfs_service_stop } -nfs_startup () +nfs_startup() { - basic_stop "nfs" || true - basic_start "nfs" - _f="${PROCFS_PATH}/sys/net/ipv4/tcp_tw_recycle" - if [ -f "$_f" ] ; then - echo 1 >"$_f" - fi + nfs_service_stop || true + nfs_service_start + _f="${PROCFS_PATH}/sys/net/ipv4/tcp_tw_recycle" + if [ -f "$_f" ]; then + echo 1 >"$_f" + fi } ################################################## # monitor-post support -nfs_check_thread_count () +nfs_check_thread_count() { - # Load NFS configuration to get desired number of threads. - nfs_load_config - - # If $RPCNFSDCOUNT/$USE_KERNEL_NFSD_NUMBER isn't set then we could - # guess the default from the initscript. However, let's just - # assume that those using the default don't care about the number - # of threads and that they have switched on this feature in error. - _configured_threads="${RPCNFSDCOUNT:-${USE_KERNEL_NFSD_NUMBER}}" - if [ -z "$_configured_threads" ] && type nfsconf >/dev/null 2>&1 ; then - _configured_threads=$(nfsconf --get nfsd threads) || true - fi - [ -n "$_configured_threads" ] || return 0 - - _threads_file="${PROCFS_PATH}/fs/nfsd/threads" - - # nfsd should be running the configured number of threads. If - # there are a different number of threads then tell nfsd the - # correct number. - read _running_threads <"$_threads_file" || { - echo "WARNING: Reading \"${_threads_file}\" unexpectedly failed" - exit 0 - } - - # Intentionally not arithmetic comparison - avoids extra errors - # when above read fails in an unexpected way... - if [ "$_running_threads" != "$_configured_threads" ] ; then - echo "Attempting to correct number of nfsd threads from ${_running_threads} to ${_configured_threads}" - echo "$_configured_threads" >"$_threads_file" - fi + # Load NFS configuration to get desired number of threads. + nfs_load_config + + # If $RPCNFSDCOUNT/$USE_KERNEL_NFSD_NUMBER isn't set then we could -- Samba Shared Repository