From a43a1ebe51d61790a9f762ab04aa5b9d809953d5 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Fri, 18 Mar 2022 10:53:45 +1100 Subject: [PATCH] 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 Reviewed-by: Amitay Isaacs --- ctdb/config/nfs-linux-kernel-callout | 204 ++++++++++++++------------- 1 file changed, 106 insertions(+), 98 deletions(-) diff --git a/ctdb/config/nfs-linux-kernel-callout b/ctdb/config/nfs-linux-kernel-callout index 9c2d0418e55..1dce7595a36 100755 --- a/ctdb/config/nfs-linux-kernel-callout +++ b/ctdb/config/nfs-linux-kernel-callout @@ -28,7 +28,7 @@ systemd-*) nfs_rquotad_config="" # Not use with systemd, restart via service case "$nfs_distro_style" in - *-redhat|*-suse) + *-redhat | *-suse) : # Defaults only ;; *-debian) @@ -37,6 +37,7 @@ systemd-*) *) echo "Internal error" exit 1 + ;; esac ;; @@ -65,40 +66,42 @@ sysvinit-*) *) 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 </dev/null 2>&1 || true ;; mountd) - if [ -n "$nfs_mountd_service" ] ; then + if [ -n "$nfs_mountd_service" ]; then service "$nfs_mountd_service" stop return fi @@ -182,7 +187,7 @@ service_stop () killall -q -9 rpc.mountd ;; rquotad) - if [ -n "$nfs_rquotad_service" ] ; then + if [ -n "$nfs_rquotad_service" ]; then service "$nfs_rquotad_service" stop return fi @@ -191,7 +196,7 @@ service_stop () killall -q -9 rpc.rquotad ;; status) - if [ -n "$nfs_status_service" ] ; then + if [ -n "$nfs_status_service" ]; then service "$nfs_status_service" stop return fi @@ -201,10 +206,11 @@ service_stop () ;; *) usage + ;; esac } -service_start () +service_start() { case "$1" in nfs) @@ -214,35 +220,35 @@ service_start () basic_start "nfslock" ;; mountd) - if [ -n "$nfs_mountd_service" ] ; then + 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 + 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 + if [ -n "$nfs_status_service" ]; then service "$nfs_status_service" start return fi @@ -251,13 +257,13 @@ service_start () 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 @@ -265,96 +271,97 @@ service_start () ;; *) usage + ;; esac } ################################################## # service init startup and final shutdown -nfs_shutdown () +nfs_shutdown() { - basic_stop "nfs" + basic_stop "nfs" } -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 + basic_stop "nfs" || true + basic_start "nfs" + _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 + # 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 + # 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" + _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 - } + # 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 + # 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 } ################################################## # list share directories -nfs_monitor_list_shares () +nfs_monitor_list_shares() { - _cache_file="${CTDB_NFS_CALLOUT_STATE_DIR}/list_shares_cache" - # -nt operator is well supported in Linux: dash, bash, ksh, ... - # shellcheck disable=SC2039,SC3013 - if [ ! -r "$nfs_exports_file" ] || [ ! -r "$_cache_file" ] || \ - [ "$nfs_exports_file" -nt "$_cache_file" ] ; then - mkdir -p "$CTDB_NFS_CALLOUT_STATE_DIR" - # We could just use the contents of $nfs_exports_file. - # However, let's regard that file as internal to NFS and use - # exportfs, which is the public API. - if ! _exports=$(exportfs -v) ; then - echo "WARNING: failed to run exportfs to list NFS shares" >&2 - return + _cache_file="${CTDB_NFS_CALLOUT_STATE_DIR}/list_shares_cache" + # -nt operator is well supported in Linux: dash, bash, ksh, ... + # shellcheck disable=SC2039,SC3013 + if [ ! -r "$nfs_exports_file" ] || [ ! -r "$_cache_file" ] || + [ "$nfs_exports_file" -nt "$_cache_file" ]; then + mkdir -p "$CTDB_NFS_CALLOUT_STATE_DIR" + # We could just use the contents of $nfs_exports_file. + # However, let's regard that file as internal to NFS and use + # exportfs, which is the public API. + if ! _exports=$(exportfs -v); then + echo "WARNING: failed to run exportfs to list NFS shares" >&2 + return + fi + + echo "$_exports" | + grep '^/' | + sed -e 's@[[:space:]][[:space:]]*[^[:space:]()][^[:space:]()]*([^[:space:]()][^[:space:]()]*)$@@' | + sort -u >"$_cache_file" fi - echo "$_exports" | - grep '^/' | - sed -e 's@[[:space:]][[:space:]]*[^[:space:]()][^[:space:]()]*([^[:space:]()][^[:space:]()]*)$@@' | - sort -u >"$_cache_file" - fi - - cat "$_cache_file" + cat "$_cache_file" } ################################################## -nfs_register () +nfs_register() { - cat <