SC2154: VAR is referenced but not assigned.
Change ctdb_setup_service_state_dir(), ctdb_get_pnn() and
ctdb_get_ip_address() to print the value so it can be assigned to a
variable. The performance gain from avoiding the sub-shells when
calling these functions is close to zero.
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
loadconfig
-ctdb_setup_service_state_dir "ctdb"
-
############################################################
select_tdb_checker ()
loadconfig
-ctdb_setup_service_state_dir "system-monitoring"
+service_state_dir=$(ctdb_setup_service_state_dir "system-monitoring") || exit $?
validate_percentage ()
{
service_name="nfs"
loadconfig
-ctdb_setup_service_state_dir
+service_state_dir=$(ctdb_setup_service_state_dir) || exit $?
######################################################################
######################################################################
-nfs_callout_init
+nfs_callout_init "$service_state_dir"
ctdb_start_stop_service
takeover_assigned_ips ()
{
- ctdb_get_pnn
+ _pnn=$(ctdb_get_pnn)
$CTDB -X ip |
awk -F'|' '{print $2}' |
while read ip ; do
_ip_details=$(ip_maskbits_iface "$ip")
if [ -n "$_ip_details" ] ; then
- echo "Assigning $ip to this node ($pnn)"
- $CTDB moveip "$ip" "$pnn"
+ echo "Assigning $ip to this node (${_pnn})"
+ $CTDB moveip "$ip" "$_pnn"
fi
done
}
[ -n "$CTDB_NATGW_NODES" ] || exit 0
export CTDB_NATGW_NODES
-ctdb_setup_service_state_dir
+service_state_dir=$(ctdb_setup_service_state_dir) || exit $?
natgw_cfg_new="${service_state_dir}/cfg_new"
natgw_cfg_old="${service_state_dir}/cfg_old"
ctdb_natgw_slave_only ()
{
- ctdb_get_ip_address
+ _ip_address=$(ctdb_get_ip_address)
- awk -v my_ip="$ip_address" \
+ awk -v my_ip="$_ip_address" \
'$1 == my_ip { if ($2 ~ "slave-only") { exit 0 } else { exit 1 } }' \
"$CTDB_NATGW_NODES"
}
updatenatgw|ipreallocated)
natgw_check_config
- ctdb_get_pnn
-
natgw_ensure_master
natgw_config_has_changed || natgw_master_has_changed || exit 0
natgw_clear
+ pnn=$(ctdb_get_pnn)
if [ "$pnn" = "$natgwmaster" ]; then
natgw_set_master
else
[ -n "$CTDB_MONITOR_MPDEVICES" ] || exit 0
-ctdb_setup_service_state_dir
+service_state_dir=$(ctdb_setup_service_state_dir) || exit $?
multipath_fail="${service_state_dir}/fail"
loadconfig
-ctdb_setup_service_state_dir
-
service_start ()
{
service "$CTDB_SERVICE_WINBIND" stop >/dev/null 2>&1
loadconfig
-ctdb_setup_service_state_dir
+service_state_dir=$(ctdb_setup_service_state_dir) || exit $?
service_start ()
{
service_name="nfs"
loadconfig
-ctdb_setup_service_state_dir
+service_state_dir=$(ctdb_setup_service_state_dir) || exit $?
######################################################################
######################################################################
-nfs_callout_init
+nfs_callout_init "$service_state_dir"
ctdb_start_stop_service
# Stop iSCSI daemon
killall -9 tgtd >/dev/null 2>/dev/null
- ctdb_get_pnn
+ pnn=$(ctdb_get_pnn)
[ -n "$pnn" ] || die "Failed to get node pnn"
# Start iSCSI daemon
lvs_slave_only ()
{
- ctdb_get_ip_address
-
- awk -v my_ip="$ip_address" \
+ _ip_address=$(ctdb_get_ip_address)
+ awk -v my_ip="$_ip_address" \
'$1 == my_ip { if ($2 ~ "slave-only") { exit 0 } else { exit 1 } }' \
"$CTDB_LVS_NODES"
}
kill_tcp_connections_local_only \
"$CTDB_LVS_PUBLIC_IFACE" "$CTDB_LVS_PUBLIC_IP"
- ctdb_get_pnn
+ pnn=$(ctdb_get_pnn)
lvsmaster=$("${CTDB_HELPER_BINDIR}/ctdb_lvs" master)
if [ "$pnn" != "$lvsmaster" ] ; then
# This node is not the LVS master so change the IP address
######################################################
# Cached retrieval of PNN from local node. This never changes so why
# open a client connection to the server each time this is needed?
-# This sets $pnn - this avoid an unnecessary subprocess.
ctdb_get_pnn ()
{
_pnn_file="${CTDB_SCRIPT_VARDIR}/my-pnn"
$CTDB pnn | sed -e 's@.*:@@' >"$_pnn_file"
fi
- read pnn <"$_pnn_file"
+ cat "$_pnn_file"
}
# Cached retrieval of private IP address from local node. This never
-# changes. Sets $ip_address to avoid an unnecessary subprocess.
+# changes.
ctdb_get_ip_address ()
{
_ip_addr_file="${CTDB_SCRIPT_VARDIR}/my-ip-address"
# ip_address is used by caller
# shellcheck disable=SC2034
- read ip_address <"$_ip_addr_file"
+ cat "$_ip_addr_file"
}
######################################################
ctdb_setup_service_state_dir ()
{
- service_state_dir="${CTDB_SCRIPT_VARDIR}/service_state/${1:-${service_name}}"
- mkdir -p "$service_state_dir" || {
- echo "Error creating state dir \"$service_state_dir\""
- exit 1
- }
+ _s="${1:-${service_name}}"
+
+ _service_state_dir="${CTDB_SCRIPT_VARDIR}/service_state/${_s}"
+ mkdir -p "$_service_state_dir" ||
+ die "Error creating state dir \"${_service_state_dir}\""
+
+ echo "$_service_state_dir"
}
########################################################
nfs_callout_init ()
{
+ _state_dir="$1"
+
if [ -z "$CTDB_NFS_CALLOUT" ] ; then
CTDB_NFS_CALLOUT="${CTDB_BASE}/nfs-linux-kernel-callout"
fi
export CTDB_NFS_CALLOUT
# If the callout wants to use this then it must create it
- export CTDB_NFS_CALLOUT_STATE_DIR="${service_state_dir}/callout-state"
+ export CTDB_NFS_CALLOUT_STATE_DIR="${_state_dir}/callout-state"
# Export, if set, for use by clustered NFS callouts
if [ -n "$CTDB_NFS_STATE_FS_TYPE" ] ; then
export CTDB_NFS_STATE_MNT
fi
- nfs_callout_cache="${service_state_dir}/nfs_callout_cache"
+ nfs_callout_cache="${_state_dir}/nfs_callout_cache"
nfs_callout_cache_callout="${nfs_callout_cache}/CTDB_NFS_CALLOUT"
nfs_callout_cache_ops="${nfs_callout_cache}/ops"
}
tickledir="${CTDB_SCRIPT_VARDIR}/tickles"
mkdir -p "$tickledir"
- ctdb_get_pnn
-
# What public IPs do I hold?
- _ips=$($CTDB -X ip | awk -F'|' -v pnn="$pnn" '$3 == pnn {print $2}')
+ _pnn=$(ctdb_get_pnn)
+ _ips=$($CTDB -X ip | awk -F'|' -v pnn="$_pnn" '$3 == pnn {print $2}')
# IPs and port as ss filters
_ip_filter=""
nl="
"
-ctdb_setup_service_state_dir "statd-callout"
+service_state_dir=$(ctdb_setup_service_state_dir "statd-callout") || exit $?
cd "$service_state_dir" || \
die "Failed to change directory to \"${service_state_dir}\""
+pnn=$(ctdb_get_pnn)
+
case "$1" in
# Keep a single file to keep track of the last "add-client" or
# "del-client'. These get pushed to ctdb.tdb during "update",
# statd does not tell us to which IP the client connected so
# we must add it to all the IPs that we serve
cip="$2"
- ctdb_get_pnn
date=$(date '+%s')
# x is intentionally ignored
# shellcheck disable=SC2034
# statd does not tell us from which IP the client disconnected
# so we must add it to all the IPs that we serve
cip="$2"
- ctdb_get_pnn
# x is intentionally ignored
# shellcheck disable=SC2034
$CTDB ip -X |
fi
# Filter out lines for any IP addresses that are not currently
# hosted public IP addresses.
- ctdb_get_pnn
ctdb_ips=$($CTDB ip | tail -n +2)
sed_expr=$(echo "$ctdb_ips" |
awk -v pnn="$pnn" 'pnn == $2 { \
# probability that the client will accept the statd notify packet and
# not just ignore it.
# For all IPs we serve, collect info and push to the config database
- ctdb_get_pnn
# Construct a sed expression to take catdb output and produce pairs of:
# server-IP client-IP