#!/bin/bash
+
+# vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
+
#
# lustre_createcsv - generate a csv file from a running lustre cluster
#
# Usage
usage() {
- cat >&2 <<EOF
+ cat <<EOF
Usage: `basename $0` [-t HAtype] [-d] [-h] [-v] [-f csv_filename]
Default is lustre_config.csv.
EOF
- exit 1
}
# Get the library of functions
if [ "${HATYPE_OPT}" != "${HBVER_HBV1}" ] \
&& [ "${HATYPE_OPT}" != "${HBVER_HBV2}" ] \
&& [ "${HATYPE_OPT}" != "${HATYPE_CLUMGR}" ]; then
- echo >&2 "`basename $0`: Invalid HA software type" \
+ error_output "Invalid HA software type" \
"- ${HATYPE_OPT}!"
- usage
+ usage 1>&2
+ exit 1
fi
;;
d) GET_MDLVM_INFO=true;;
- h) usage;;
+ h) usage && exit 0;;
v) VERBOSE_OUTPUT=true;;
f) LUSTRE_CSV_FILE=$OPTARG;;
- ?) usage
+ ?) usage 1>&2 && exit 1;;
esac
done
# Verify the local host is the MGS node
mgs_node() {
if [ ! -e ${LUSTRE_PROC_DEVICES} ]; then
- echo >&2 "`basename $0`: error: ${LUSTRE_PROC_DEVICES} does" \
+ error_output "${LUSTRE_PROC_DEVICES} does" \
"not exist. Lustre kernel modules may not be loaded!"
return 1
fi
if [ -z "`cat ${LUSTRE_PROC_DEVICES}`" ]; then
- echo >&2 "`basename $0`: error: ${LUSTRE_PROC_DEVICES} is" \
+ error_output "${LUSTRE_PROC_DEVICES} is" \
"empty. Lustre services may not be started!"
return 1
fi
if [ -z "`grep ${MGS_TYPE} ${LUSTRE_PROC_DEVICES}`" ]; then
- echo >&2 "`basename $0`: error: This node is not a MGS node." \
+ error_output "This node is not a MGS node." \
"The script should be run on the MGS node!"
return 1
fi
fi
if [ ! -e ${LNET_PROC_PEERS} ]; then
- echo >&2 "`basename $0`: error: ${LNET_PROC_PEERS} does not" \
+ error_output "${LNET_PROC_PEERS} does not" \
"exist. LNET kernel modules may not be loaded" \
"or LNET network may not be up!"
return 1
# Get the hostnames of the nodes
for ((idx = 1, i = 1; idx < ${#HOST_NIDS[@]}; idx++, i++)); do
if [ -z "${HOST_NIDS[idx]}" ]; then
- echo >&2 "`basename $0`: get_hostnames() error:" \
+ error_output "get_hostnames():" \
"Invalid nid - \"${HOST_NIDS[idx]}\"!"
return 1
fi
HOST_NAMES[i]=$(nid2hostname ${HOST_NIDS[idx]})
if [ $? -ne 0 ]; then
- echo >&2 "${HOST_NAMES[i]}"
+ error_output "${HOST_NAMES[i]}"
return 1
fi
if [ "${first_item}" != "${first_item#devices=}" ]; then
MD_DEVS[j]=`echo "${line}" | sed -e 's/devices=//' -e 's/,/ /g'`
fi
- done < <(${REMOTE} ${host_name} "${MDADM} --detail --scan --verbose")
+ done < <(${REMOTE} ${host_name} "PATH=\$PATH:/sbin:/usr/sbin
+ ${MDADM} --detail --scan --verbose")
if [ $i -eq 0 ]; then
verbose_output "There are no active MD devices" \
local cmd ret_str
# Execute remote command to get all the PV informations.
- cmd="${EXPORT_PATH} pvdisplay -c | awk -F: '{print \$1}' | xargs"
+ cmd="PATH=\$PATH:/sbin:/usr/sbin \
+pvdisplay -c | awk -F: '{print \$1}' | xargs"
ret_str=`${REMOTE} ${host_name} "${cmd}" 2>&1`
if [ $? -ne 0 ]; then
if [ -n "${ret_str}" ]; then
- echo >&2 "`basename $0`: get_pv_configs() error:" \
+ error_output "get_pv_configs():" \
"remote command to ${host_name} error: ${ret_str}"
else
remote_error "get_pv_configs" ${host_name}
local cmd ret_str
# Execute remote command to get the PV names.
- cmd="${EXPORT_PATH} vgdisplay -v ${vg_name} 2>/dev/null\
+ cmd="PATH=\$PATH:/sbin:/usr/sbin vgdisplay -v ${vg_name} 2>/dev/null\
| grep \"PV Name\" | awk '{print \$3}' | xargs"
ret_str=`${REMOTE} ${host_name} "${cmd}" 2>&1`
if [ $? -ne 0 ]; then
unset VG_PVNAMES
# Execute remote command to get all the VG names.
- cmd="${EXPORT_PATH} vgdisplay \
+ cmd="PATH=\$PATH:/sbin:/usr/sbin vgdisplay \
| grep \"VG Name\" | awk '{print \$3}' | xargs"
ret_str=`${REMOTE} ${host_name} "${cmd}" 2>&1`
if [ $? -ne 0 ]; then
if [ -n "${ret_str}" ]; then
- echo >&2 "`basename $0`: get_vg_configs() error:" \
+ error_output "get_vg_configs():" \
"remote command to ${host_name} error: ${ret_str}"
else
remote_error "get_vg_configs" ${host_name}
VG_NAME[i]=${vg_name}
VG_PVNAMES[i]=$(get_vg_pvnames ${host_name} ${VG_NAME[i]})
if [ $? -ne 0 ]; then
- echo >&2 "${VG_PVNAMES[i]}"
+ error_output "${VG_PVNAMES[i]}"
return 1
fi
let "i += 1"
LV_SIZE[i]=`echo "${line}" | awk -F: '{print $7}' | sed -e 's/.*/&K/'`
let "i += 1"
- done < <(${REMOTE} ${host_name} "${EXPORT_PATH} lvdisplay -c")
+ done < <(${REMOTE} ${host_name} "PATH=\$PATH:/sbin:/usr/sbin lvdisplay -c")
if [ $i -eq 0 ]; then
verbose_output "There are no LVs in the host ${host_name}"
# Execute remote command to get the kernel version
ret_str=`${REMOTE} ${host_name} "uname -r" 2>&1`
if [ $? -ne 0 -a -n "${ret_str}" ]; then
- echo >&2 "`basename $0`: get_module_opts() error:" \
+ error_output "get_module_opts():" \
"remote command error: ${ret_str}"
return 1
fi
ret_str=`${REMOTE} ${host_name} \
"grep ${target_svname} ${res_file}" 2>&1`
if [ $? -ne 0 -a -n "${ret_str}" ]; then
- echo >&2 "`basename $0`: is_ha_target() error:" \
+ error_output "is_ha_target():" \
"remote command error: ${ret_str}"
return 1
fi
done < <(${REMOTE} ${host_name} "cat ${HA_CF}")
if [ -z "${HB_CHANNELS}" ]; then
- echo >&2 "`basename $0`: get_hb_configs() error:" \
+ error_output "get_hb_configs():" \
"There are no heartbeat channel configs in ${HA_CF}" \
"of host ${host_name} or ${HA_CF} does not exist!"
return 0
done < <(${REMOTE} ${host_name} "cat ${HA_RES}")
if [ -z "${SRV_IPADDRS}" ]; then
- echo >&2 "`basename $0`: get_hb_configs() error: There"\
+ error_output "get_hb_configs(): There"\
"are no service address in ${HA_RES} of host"\
"${host_name} or ${HA_RES} does not exist!"
return 0
# Execute remote command to get Heartbeat channel
HB_CHANNELS=$(get_cluman_channel ${host_name})
if [ $? -ne 0 ]; then
- echo >&2 "${HB_CHANNELS}"
+ error_output "${HB_CHANNELS}"
fi
# Execute remote command to get service IP address
SRV_IPADDRS=$(get_cluman_srvaddr ${host_name} \
${TARGET_SVNAMES[i]})
if [ $? -ne 0 ]; then
- echo >&2 "${SRV_IPADDRS}"
+ error_output "${SRV_IPADDRS}"
return 0
fi
let "i += 1"
let "j += 1"
else
- echo >&2 "`basename $0`: get_svnames() error: Invalid"\
+ error_output "get_svnames(): Invalid"\
"line in ${host_name}'s ${LUSTRE_PROC_DEVICES}"\
"- \"${line}\"!"
return 1
if [ "${target_svname}" = "${MGS_SVNAME}" ]; then
# Execute remote command to get the device name of mgs target
ret_str=`${REMOTE} ${host_name} \
- "/sbin/findfs LABEL=${target_svname}" 2>&1`
+ "PATH=\$PATH:/sbin:/usr/sbin findfs LABEL=${target_svname}" 2>&1`
if [ $? -ne 0 -a -n "${ret_str}" ]; then
if [ "${ret_str}" = "${ret_str#*Unable to resolve*}" ]
then
# Execute remote command to get the device size
ret_str=`${REMOTE} ${host_name} \
- "/sbin/blockdev --getsize ${target_devname}" 2>&1`
+ "PATH=\$PATH:/sbin:/usr/sbin blockdev --getsize ${target_devname}" 2>&1`
if [ $? -ne 0 -a -n "${ret_str}" ]; then
echo "`basename $0`: get_devsize() error:" \
"remote command error: ${ret_str}"
# Execute remote command to get the real device name
ret_str=`${REMOTE} ${host_name} \
- "/sbin/losetup ${loop_dev}" 2>&1`
+ "PATH=\$PATH:/sbin:/usr/sbin losetup ${loop_dev}" 2>&1`
if [ $? -ne 0 -a -n "${ret_str}" ]; then
echo "`basename $0`: get_realdevname() error:" \
"remote command error: ${ret_str}"
TARGET_DEVNAMES[i]=$(get_devname ${host_name} \
${TARGET_SVNAMES[i]})
if [ $? -ne 0 ]; then
- echo >&2 "${TARGET_DEVNAMES[i]}"
+ error_output "${TARGET_DEVNAMES[i]}"
return 1
fi
"target in ${host_name}."
continue
else
- echo >&2 "`basename $0`: get_devname() error:"\
+ error_output "get_devname():"\
"No device corresponding to target" \
"${TARGET_SVNAMES[i]} in ${host_name}!"
return 1
TARGET_MNTPNTS[i]=$(get_mntpnt ${host_name} \
${TARGET_DEVNAMES[i]})
if [ $? -ne 0 ]; then
- echo >&2 "${TARGET_MNTPNTS[i]}"
+ error_output "${TARGET_MNTPNTS[i]}"
return 1
fi
TARGET_DEVSIZES[i]=$(get_devsize ${host_name} \
${TARGET_DEVNAMES[i]})
if [ $? -ne 0 ]; then
- echo >&2 "${TARGET_DEVSIZES[i]}"
+ error_output "${TARGET_DEVSIZES[i]}"
return 1
fi
TARGET_DEVNAMES[i]=$(get_realdevname ${host_name} \
${TARGET_DEVNAMES[i]})
if [ $? -ne 0 ]; then
- echo >&2 "${TARGET_DEVNAMES[i]}"
+ error_output "${TARGET_DEVNAMES[i]}"
return 1
fi
fi
"ost") let "ret = $2 & LDD_F_SV_TYPE_OST";;
"mgs") let "ret = $2 & LDD_F_SV_TYPE_MGS";;
"*")
- echo >&2 "`basename $0`: is_target() error: Invalid" \
+ error_output "is_target(): Invalid" \
"target service type - \"$1\"!"
return 1
;;
stripe_count=`echo ${ret_str} | awk '{print $1}'`
fi
- if [ -z "`echo ${stripe_count}|awk '/^[[:digit:]]/ {print $0}'`" ]
- then
+ if [ "$stripe_count" != "-1" ] && \
+ [ -z "`echo ${stripe_count}|awk '/^[[:digit:]]/ {print $0}'`" ]; then
echo "`basename $0`: get_stripecount() error: can't" \
"get stripe count of ${target_fsname} in ${host_name}!"
return 1
${TUNEFS} --print --verbose ${TARGET_DEVNAMES[i]} 2>/dev/null")
if [ -z "${flags}" ]; then
- echo >&2 "`basename $0`: get_ldds() error: Invalid" \
+ error_output "get_ldds(): Invalid" \
"ldd_flags of target ${TARGET_DEVNAMES[i]}" \
"in host ${host_name} - it's value is null!"\
"Check ${TUNEFS} command!"
# Get the lustre target service type
TARGET_DEVTYPES[i]=$(get_devtype ${flags})
if [ $? -ne 0 ]; then
- echo >&2 "${TARGET_DEVTYPES[i]} From device" \
+ error_output "${TARGET_DEVTYPES[i]} From device" \
"${TARGET_DEVNAMES[i]} in host ${host_name}!"
return 1
fi
# Get failover nids of the lustre target
TARGET_FAILNIDS[i]=$(get_failnids "${params}")
if [ $? -ne 0 ]; then
- echo >&2 "${TARGET_FAILNIDS[i]} From device" \
+ error_output "${TARGET_FAILNIDS[i]} From device" \
"${TARGET_DEVNAMES[i]} in host ${host_name}!"
return 1
fi
# Get other format options of the lustre target
TARGET_FMTOPTS[i]=$(get_fmtopts ${TARGET_DEVNAMES[i]} ${host_name} "${params}")
if [ $? -ne 0 ]; then
- echo >&2 "${TARGET_FMTOPTS[i]}"
+ error_output "${TARGET_FMTOPTS[i]}"
return 1
fi
# Get the stripe count option
stripecount_opt=$(get_stripecount_opt ${host_name} ${TARGET_FSNAMES[i]})
if [ $? -ne 0 ]; then
- echo >&2 "${stripecount_opt}"
+ error_output "${stripecount_opt}"
return 1
fi
local ret_str
# Execute remote command to get the journal inode number
- ret_str=`${REMOTE} ${host_name} "/sbin/debugfs -R 'stats -h' \
- ${target_devname} | grep 'Journal inode:'" 2>&1`
+ ret_str=`${REMOTE} ${host_name} "PATH=\$PATH:/sbin:/usr/sbin \
+debugfs -R 'stats -h' ${target_devname} | grep 'Journal inode:'" 2>&1`
if [ $? -ne 0 -a -n "${ret_str}" ]; then
echo "`basename $0`: get_journalsize() error:" \
"remote command error: ${ret_str}"
fi
# Execute remote command to get the journal size
- ret_str=`${REMOTE} ${host_name} "/sbin/debugfs -R \
- 'stat <${journal_inode}>' ${target_devname}|grep '^User:'" 2>&1`
+ ret_str=`${REMOTE} ${host_name} "PATH=\$PATH:/sbin:/usr/sbin \
+debugfs -R 'stat <${journal_inode}>' ${target_devname}|grep '^User:'" 2>&1`
if [ $? -ne 0 -a -n "${ret_str}" ]; then
echo "`basename $0`: get_journalsize() error:" \
"remote command error: ${ret_str}"
declare -i journal_size
# Execute remote command to get the block count
- ret_str=`${REMOTE} ${host_name} "/sbin/debugfs -R 'stats -h' \
- ${target_devname} | grep 'Block count:'" 2>&1`
+ ret_str=`${REMOTE} ${host_name} "PATH=\$PATH:/sbin:/usr/sbin \
+debugfs -R 'stats -h' ${target_devname} | grep 'Block count:'" 2>&1`
if [ $? -ne 0 -a -n "${ret_str}" ]; then
echo "`basename $0`: figure_journal_size() error:" \
"remote command error: ${ret_str}"
local ret_str
# Execute remote command to get the inode count
- ret_str=`${REMOTE} ${host_name} "/sbin/debugfs -R 'stats -h' \
- ${target_devname} | grep 'Inode count:'" 2>&1`
+ ret_str=`${REMOTE} ${host_name} "PATH=\$PATH:/sbin:/usr/sbin \
+debugfs -R 'stats -h' ${target_devname} | grep 'Inode count:'" 2>&1`
if [ $? -ne 0 -a -n "${ret_str}" ]; then
echo "`basename $0`: get_ratio() error:" \
"remote command error: ${ret_str}"
fi
# Execute remote command to get the block count
- ret_str=`${REMOTE} ${host_name} "/sbin/debugfs -R 'stats -h' \
- ${target_devname} | grep 'Block count:'" 2>&1`
+ ret_str=`${REMOTE} ${host_name} "PATH=\$PATH:/sbin:/usr/sbin \
+debugfs -R 'stats -h' ${target_devname} | grep 'Block count:'" 2>&1`
if [ $? -ne 0 -a -n "${ret_str}" ]; then
echo "`basename $0`: get_ratio() error:" \
"remote command error: ${ret_str}"
local ret_str
# Execute remote command to get the inode size
- ret_str=`${REMOTE} ${host_name} "/sbin/debugfs -R 'stats -h' \
- ${target_devname} | grep 'Inode size:'" 2>&1`
+ ret_str=`${REMOTE} ${host_name} "PATH=\$PATH:/sbin:/usr/sbin \
+debugfs -R 'stats -h' ${target_devname} | grep 'Inode size:'" 2>&1`
if [ $? -ne 0 -a -n "${ret_str}" ]; then
echo "`basename $0`: get_isize() error:" \
"remote command error: ${ret_str}"
TARGET_DEVSIZES[i]=$(get_devsize ${host_name} \
${TARGET_DEVNAMES[i]})
if [ $? -ne 0 ]; then
- echo >&2 "${TARGET_DEVSIZES[i]}"
+ error_output "${TARGET_DEVSIZES[i]}"
return 1
fi
fi
journal_opt=$(get_J_opt ${host_name} ${TARGET_DEVNAMES[i]} \
${TARGET_DEVSIZES[i]})
if [ $? -ne 0 ]; then
- echo >&2 "${journal_opt}"
+ error_output "${journal_opt}"
return 1
fi
ratio_opt=$(get_i_opt ${host_name} ${TARGET_DEVNAMES[i]} \
${TARGET_DEVTYPES[i]} ${TARGET_DEVSIZES[i]})
if [ $? -ne 0 ]; then
- echo >&2 "${ratio_opt}"
+ error_output "${ratio_opt}"
return 1
fi
inode_size_opt=$(get_I_opt ${host_name} ${TARGET_DEVNAMES[i]} \
${TARGET_DEVTYPES[i]} ${TARGET_FSNAMES[i]})
if [ $? -ne 0 ]; then
- echo >&2 "${inode_size_opt}"
+ error_output "${inode_size_opt}"
return 1
fi
get_configs() {
# Check the hostname
if [ -z "$1" ]; then
- echo >&2 "`basename $0`: get_configs() error:" \
+ error_output "get_configs():" \
"Missing hostname!"
return 1
fi