Whamcloud - gitweb
LU-140 Remove leftovers of iopen
[fs/lustre-release.git] / lustre / scripts / lustre_createcsv.in
index 986e6e5..48cb432 100644 (file)
@@ -1,4 +1,7 @@
 #!/bin/bash
+
+# vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
+
 #
 # lustre_createcsv - generate a csv file from a running lustre cluster
 #
@@ -13,7 +16,7 @@
 
 # Usage
 usage() {
-       cat >&2 <<EOF
+       cat <<EOF
 
 Usage: `basename $0` [-t HAtype] [-d] [-h] [-v] [-f csv_filename]
 
@@ -33,7 +36,6 @@ Usage:        `basename $0` [-t HAtype] [-d] [-h] [-v] [-f csv_filename]
                        Default is lustre_config.csv.
 
 EOF
-       exit 1
 }
 
 # Get the library of functions
@@ -86,7 +88,7 @@ let "LDD_F_SV_TYPE_MGS = 0x0004"
 
 # Permanent mount options for ext3 or ldiskfs
 ALWAYS_MNTOPTS=${ALWAYS_MNTOPTS:-"errors=remount-ro"}
-MDT_MGS_ALWAYS_MNTOPTS=${MDT_MGS_ALWAYS_MNTOPTS:-",iopen_nopriv,user_xattr"}
+MDT_MGS_ALWAYS_MNTOPTS=${MDT_MGS_ALWAYS_MNTOPTS:-"user_xattr"}
 OST_ALWAYS_MNTOPTS=${OST_ALWAYS_MNTOPTS:-",asyncdel"}
 OST_DEFAULT_MNTOPTS=${OST_DEFAULT_MNTOPTS:-",extents,mballoc"}
 
@@ -111,35 +113,36 @@ while getopts "t:dhvf:" OPTION; do
                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
@@ -159,7 +162,7 @@ get_hostnames() {
        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
@@ -188,14 +191,14 @@ get_hostnames() {
        # 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
 
@@ -247,7 +250,8 @@ get_md_configs() {
                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" \
@@ -265,11 +269,12 @@ get_pv_configs() {
        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}
@@ -295,7 +300,7 @@ get_vg_pvnames() {
        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
@@ -333,12 +338,12 @@ get_vg_configs() {
        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}
@@ -357,7 +362,7 @@ get_vg_configs() {
                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"
@@ -395,7 +400,7 @@ get_lv_configs() {
                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}"
@@ -439,7 +444,7 @@ get_module_opts() {
        # 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
@@ -519,7 +524,7 @@ is_ha_target() {
        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
@@ -577,7 +582,7 @@ get_hb_configs() {
         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
@@ -607,7 +612,7 @@ get_hb_configs() {
                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
@@ -726,14 +731,14 @@ get_cluman_configs() {
                # 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
 
@@ -828,7 +833,7 @@ get_svnames(){
                        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
@@ -869,7 +874,7 @@ get_devname() {
        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
@@ -926,7 +931,7 @@ get_devsize() {
 
        # 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}"
@@ -962,7 +967,7 @@ get_realdevname() {
 
        # 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}"
@@ -1038,7 +1043,7 @@ get_devnames(){
                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
 
@@ -1048,7 +1053,7 @@ get_devnames(){
                                               "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
@@ -1059,7 +1064,7 @@ get_devnames(){
                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
 
@@ -1070,7 +1075,7 @@ get_devnames(){
                        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
 
@@ -1078,7 +1083,7 @@ get_devnames(){
                        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
@@ -1095,7 +1100,7 @@ is_target() {
        "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
                ;;
@@ -1262,8 +1267,8 @@ get_stripecount() {
                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
@@ -1355,10 +1360,11 @@ get_ldds(){
                                params=`echo ${params#Parameters:}`
                                break
                        fi
-               done < <(${REMOTE} ${host_name} "${TUNEFS} --print --verbose ${TARGET_DEVNAMES[i]} 2>/dev/null")
+               done < <(${REMOTE} ${host_name} "PATH=\$PATH:/sbin:/usr/sbin
+               ${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!"
@@ -1375,7 +1381,7 @@ get_ldds(){
                # 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
@@ -1389,7 +1395,7 @@ get_ldds(){
                # 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
@@ -1397,7 +1403,7 @@ get_ldds(){
                # 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
 
@@ -1421,7 +1427,7 @@ get_ldds(){
                        # 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
 
@@ -1452,8 +1458,8 @@ get_journalsize() {
        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}"
@@ -1470,8 +1476,8 @@ get_journalsize() {
        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}"
@@ -1530,8 +1536,8 @@ figure_journal_size() {
        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}"
@@ -1613,8 +1619,8 @@ get_ratio() {
        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}"
@@ -1631,8 +1637,8 @@ get_ratio() {
        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}"
@@ -1713,8 +1719,8 @@ get_isize() {
        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}"
@@ -1850,7 +1856,7 @@ get_mkfsopts(){
                        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
@@ -1859,7 +1865,7 @@ get_mkfsopts(){
                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
 
@@ -1875,7 +1881,7 @@ get_mkfsopts(){
                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
 
@@ -1891,7 +1897,7 @@ get_mkfsopts(){
                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
 
@@ -1955,7 +1961,7 @@ get_target_configs() {
 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