Make local variable usage consistent throughout
authorBryn M. Reeves <bmr@redhat.com>
Mon, 21 Jan 2013 12:42:41 +0000 (12:42 +0000)
committerBryn M. Reeves <bmr@redhat.com>
Mon, 21 Jan 2013 12:42:41 +0000 (12:42 +0000)
Fix sloppy local variable naming and usage. All local variables
are declared and all start with a '_' prefix.

blkdevalias

index 55c4b61..157f1b1 100755 (executable)
@@ -25,7 +25,6 @@ declare -A NAMEMAP
 declare -A TYPEMAP
 declare -A PARTMAP
 
-
 # To enable debug output set the BA_DEBUG environment variable to "yes".
 #BA_DEBUG="yes"
 BA_DEFAULT_USER="oracle"
@@ -67,15 +66,16 @@ _debug () {
 
 # store the WWID map to disk
 ba_store_wwid_map() {
-    TMP_MAP=$(mktemp --tmpdir=$BA_CONF_DIR)
-    if [ ! -f "$TMP_MAP" ]; then
+    local _WWID _TMP_MAP
+    _TMP_MAP=$(mktemp --tmpdir=$BA_CONF_DIR)
+    if [ ! -f "$_TMP_MAP" ]; then
         _error "could not write temporary file"
         exit 1
     fi
-    for WWID in ${!WWIDMAP[@]}; do
-        echo "$WWID ${WWIDMAP[$WWID]} ${TYPEMAP[$WWID]} ${PARTMAP[$WWID]}"
-    done  >> $TMP_MAP
-    mv $TMP_MAP $BA_MAP_PATH
+    for _WWID in ${!WWIDMAP[@]}; do
+        echo "$_WWID ${WWIDMAP[$_WWID]} ${TYPEMAP[$_WWID]} ${PARTMAP[$_WWID]}"
+    done  >> $_TMP_MAP
+    mv $_TMP_MAP $BA_MAP_PATH
     # we may be running as root - if so re-chown the configs
     if [ "$BA_REAL_UID" == "0" ] || [ "$BA_REAL_GID" == "0" ]; then
         ba_chown_configs $BA_USER $BA_GROUP
@@ -84,106 +84,109 @@ ba_store_wwid_map() {
 
 # read the WWID map from disk
 ba_load_wwid_map() {
+    local _WWID _ALIAS _TYPE _PART
     if [ ! -f "$BA_MAP_PATH" ] || [ ! -r "$BA_MAP_PATH"  ]; then
         _error "$BA_MAP_PATH does not exist or is not readable"
         exit 1
     fi
-    while read WWID ALIAS TYPE PART; do
-        if [[ $WWID == \#* ]] || [[ $WWID == "" ]]; then
+    while read _WWID _ALIAS _TYPE _PART; do
+        if [[ $_WWID == \#* ]] || [[ $_WWID == "" ]]; then
             continue
         fi
-        WWIDMAP[$WWID]="$ALIAS"
-        NAMEMAP[$ALIAS]="$WWID"
-        TYPEMAP[$WWID]="$TYPE"
-        PARTMAP[$WWID]="$PART"
+        WWIDMAP[$_WWID]="$_ALIAS"
+        NAMEMAP[$_ALIAS]="$_WWID"
+        TYPEMAP[$_WWID]="$_TYPE"
+        PARTMAP[$_WWID]="$_PART"
     done < $BA_MAP_PATH
 }
 
 # ba_add_wwid_mapping <wwid> <alias> <sd|mpath> <part>
 ba_add_wwid_mapping() {
-    local WWID
-    WWID="$1"
-    ALIAS="$2"
-    TYPE="$3"
-    PART="$4"
-    DEV="$5"
-    _debug "ba_add_wwid_mapping: WWID=\"$WWID\" ALIAS=\"$ALIAS\"" \
-        "TYPE=\"$TYPE\" PART=\"$PART\""
-    if [ "$WWID" == "" ]; then
+    local _WWID _ALIAS _TYPE _PART _DEV
+    _WWID="$1"
+    _ALIAS="$2"
+    _TYPE="$3"
+    _PART="$4"
+    _DEV="$5"
+    _debug "ba_add_wwid_mapping: WWID=\"$_WWID\" ALIAS=\"$_ALIAS\"" \
+        "TYPE=\"$_TYPE\" PART=\"$_PART\""
+    if [ "$_WWID" == "" ]; then
         _warn "no wwid given"
         return
     fi
-    if [ "$ALIAS" == "" ]; then
+    if [ "$_ALIAS" == "" ]; then
         _warn "no alias given"
         return
     fi
-    if [ "$PART" == "" ]; then
+    if [ "$_PART" == "" ]; then
         _warn "no partition number given"
     fi
-    if [ "${WWIDMAP[$WWID]}" != "" ]; then
-        _debug "ba_add_wwid_mapping: WWIDMAP[\$WWID]=${WWIDMAP[$WWID]}"
-        _warn "$DEV already mapped to alias ${WWIDMAP[$WWID]}; replacing it."
-        ba_del_wwid_mapping "$WWID"
+    if [ "${WWIDMAP[$_WWID]}" != "" ]; then
+        _debug "ba_add_wwid_mapping: WWIDMAP[\$WWID]=${WWIDMAP[$_WWID]}"
+        _warn "$DEV already mapped to alias ${WWIDMAP[$_WWID]}; replacing it."
+        ba_del_wwid_mapping "$_WWID"
     fi
-    if [ "${NAMEMAP[$ALIAS]}" != "" ]; then
-        _debug "ba_add_wwid_mapping: NAMEMAP[\$ALIAS]=${NAMEMAP[$ALIAS]}"
-        _warn "$DEV already mapped to disk ${NAMEMAP[$ALIAS]}; replacing it."
-        ba_del_wwid_mapping ${NAMEMAP[$ALIAS]}
+    if [ "${NAMEMAP[$_ALIAS]}" != "" ]; then
+        _debug "ba_add_wwid_mapping: NAMEMAP[\$ALIAS]=${NAMEMAP[$_ALIAS]}"
+        _warn "$DEV already mapped to disk ${NAMEMAP[$_ALIAS]}; replacing it."
+        ba_del_wwid_mapping ${NAMEMAP[$_ALIAS]}
     fi
-    WWIDMAP[$WWID]="$ALIAS"
-    NAMEMAP[$ALIAS]="$WWID"
-    TYPEMAP[$WWID]=${TYPE:-"sd"}
-    PARTMAP[$WWID]="$PART"
+    WWIDMAP[$_WWID]="$_ALIAS"
+    NAMEMAP[$_ALIAS]="$_WWID"
+    TYPEMAP[$_WWID]=${_TYPE:-"sd"}
+    PARTMAP[$_WWID]="$_PART"
 }
 
 # ba_del_wwid_mapping <wwid>
 ba_del_wwid_mapping() {
-    local WWID ALIAS
-    WWID="$1"
-    if [ "$WWID" == "" ]; then
+    local _WWID _ALIAS
+    _WWID="$1"
+    if [ "$_WWID" == "" ]; then
         return 1
     fi
-    if [ "${WWIDMAP[$WWID]}" == "" ]; then
-        _warn "WARNING: $WWID does not exist; doing nothing."
+    if [ "${WWIDMAP[$_WWID]}" == "" ]; then
+        _warn "WARNING: $_WWID does not exist; doing nothing."
         return 1
     fi
-    _debug "\nba_del_wwid_mapping: unsetting WWIDMAP[$WWID]"
-    ALIAS=${WWIDMAP[$WWID]}
-    unset WWIDMAP[$WWID]
-    unset NAMEMAP[$ALIAS]
-    unset TYPEMAP[$WWID]
-    unset PARTMAP[$WWID]
+    _debug "\nba_del_wwid_mapping: unsetting WWIDMAP[$_WWID]"
+    _ALIAS=${WWIDMAP[$_WWID]}
+    unset WWIDMAP[$_WWID]
+    unset NAMEMAP[$_ALIAS]
+    unset TYPEMAP[$_WWID]
+    unset PARTMAP[$_WWID]
 }
 
 ba_get_partnum () {
-    local DEV="$1"
+    local _DEV _NUM
+    _DEV="$1"
     if [[ $DEV == dm-* ]]; then
-        DEV=$DM_NAME
+        _DEV=$DM_NAME
     fi
-    _debug "ba_get_partnum: $DEV"
-    /sbin/dmsetup info $DEV > /dev/null 2>&1
+    _debug "ba_get_partnum: $_DEV"
+    /sbin/dmsetup info $_DEV > /dev/null 2>&1
     if [ "$?" == "0" ]; then
-        NUM=$(echo $DEV | sed -e 's/\/dev.*\///' -e 's/.*p\([0-9]*\).*/\1/')
+        _NUM=$(echo $_DEV | sed -e 's/\/dev.*\///' -e 's/.*p\([0-9]*\).*/\1/')
     else
-        NUM=$(echo $DEV | sed 's/\(\/dev\/\)*sd[a-z]*//')
+        _NUM=$(echo $_DEV | sed 's/\(\/dev\/\)*sd[a-z]*//')
     fi
-    if [ "$NUM" == "" ]; then
-        NUM="0"
+    if [ "$_NUM" == "" ]; then
+        _NUM="0"
     fi
-    echo $NUM
+    echo $_NUM
 }
 
 ba_scsi_id () {
-    local DEV=$1
-    _debug "ba_scsi_id: getting ID for device $DEV"
-    dmsetup info $DEV > /dev/null  2>&1
+    local _DEV
+    _DEV="$1"
+    _debug "ba_scsi_id: getting ID for device $_DEV"
+    dmsetup info $_DEV > /dev/null  2>&1
     if [ $? -eq 0 ]; then
-        DEV=$(echo $DEV | sed 's/p[0-9].*//')
+        _DEV=$(echo $_DEV | sed 's/p[0-9].*//')
     else
-        DEV=$(echo $DEV | sed 's/[0-9].*//')
+        _DEV=$(echo $_DEV | sed 's/[0-9].*//')
     fi
-     _debug "ba_scsi_id: calling \"$BA_SCSI_ID $BA_SCSI_ID_FLAGS $DEV\""
-    $BA_SUDO $BA_SCSI_ID $BA_SCSI_ID_FLAGS $DEV
+     _debug "ba_scsi_id: calling \"$BA_SCSI_ID $BA_SCSI_ID_FLAGS $_DEV\""
+    $BA_SUDO $BA_SCSI_ID $BA_SCSI_ID_FLAGS $_DEV
 }
 
 # ba_chown_configs <user> <group>
@@ -216,6 +219,7 @@ ba_refresh_device () {
 }
 
 ba_configure () {
+    local _BA_USER _BA_GROUP _BA_DEV_PATH _TMP_CONF
     cat <<EOF
 Configuring the blkdevalias map.
 
@@ -279,91 +283,92 @@ EOF
 
 # createdisk <alias> <device>
 ba_createdisk () {
-    local WWID DEV ALIAS PART
-    ALIAS="$1"
-    DEV="$2"
-    if [ "$DEV" == "" ] || [ "$ALIAS" == "" ]; then
+    local _WWID _DEV _ALIAS _TYPE _PART
+    _ALIAS="$1"
+    _DEV="$2"
+    if [ "$_DEV" == "" ] || [ "$_ALIAS" == "" ]; then
         echo "Usage: $0 createdisk <alias> <device>"
         exit 2
     fi
-    _debug "ba_createdisk: DEV=\"$DEV\" ALIAS=\"$ALIAS\""
+    _debug "ba_createdisk: DEV=\"$_DEV\" ALIAS=\"$_ALIAS\""
 
-    WWID=$(ba_scsi_id $DEV)
-    if [ "$WWID" == "" ]; then
-        _error "could not get SCSI ID for $DEV"
+    _WWID=$(ba_scsi_id $_DEV)
+    if [ "$_WWID" == "" ]; then
+        _error "could not get SCSI ID for $_DEV"
         exit 1
     fi
-    _debug "ba_createdisk: WWID=\"$WWID\""
+    _debug "ba_createdisk: WWID=\"$_WWID\""
 
-    if dmsetup info $DEV > /dev/null  2>&1; then
-        TYPE="mpath"
+    if dmsetup info $_DEV > /dev/null  2>&1; then
+        _TYPE="mpath"
     else
-        TYPE="sd"
+        _TYPE="sd"
     fi
 
-    PART=$(ba_get_partnum $DEV) 
-    _debug "ba_createdisk: PART=\"$PART\""
+    _PART=$(ba_get_partnum $_DEV) 
+    _debug "ba_createdisk: PART=\"$_PART\""
 
-    ba_add_wwid_mapping $WWID $ALIAS $TYPE $PART $DEV
+    ba_add_wwid_mapping $_WWID $_ALIAS $_TYPE $_PART $_DEV
     ba_store_wwid_map
-    ba_refresh_device $DEV
+    ba_refresh_device $_DEV
 }
 
 ba_deletedisk () {
-    local WWID ALIAS DEVPATH
-    ALIAS=$1
-    if [ "$ALIAS" == "" ]; then
+    local _WWID _ALIAS _DEVPATH
+    _ALIAS=$1
+    if [ "$_ALIAS" == "" ]; then
         echo "Usage: $0 deletedisk <alias>"
         exit 2
     fi
-    WWID=${NAMEMAP[$ALIAS]}
-    if [ "$WWID" == "" ]; then
-        _error "\"$ALIAS\" does not exist"
+    _WWID=${NAMEMAP[$_ALIAS]}
+    if [ "$_WWID" == "" ]; then
+        _error "\"$_ALIAS\" does not exist"
         echo "Usage: $0 deletedisk <alias>"
         exit 2
     fi
-    echo -n "Removing wwid map disk \"$ALIAS\":"
+    echo -n "Removing wwid map disk \"$_ALIAS\":"
     # generate device path for refresh call
-    DEVPATH="/dev/$BA_DEV_PATH/${WWIDMAP[$WWID]}"
-    ba_del_wwid_mapping $WWID \
+    _DEVPATH="/dev/$BA_DEV_PATH/${WWIDMAP[$_WWID]}"
+    ba_del_wwid_mapping $_WWID \
     && if [ "$BA_DEBUG" != "yes" ]; then
         echo "                                  [  OK  ]"
     fi
     ba_store_wwid_map
-    ba_refresh_device $DEVPATH
+    ba_refresh_device $_DEVPATH
 }
 
 ba_list_disks () {
-    for D in ${WWIDMAP[@]}; do
-        local DEVPATH
-        DEVPATH="/dev/$BA_DEV_PATH/${WWIDMAP[${NAMEMAP[$D]}]}"
-        echo -n $D " $DEVPATH -> "
-        echo $(readlink $DEVPATH)
+    local _D
+    for _D in ${WWIDMAP[@]}; do
+        local _DEVPATH
+        _DEVPATH="/dev/$BA_DEV_PATH/${WWIDMAP[${NAMEMAP[$_D]}]}"
+        echo -n $_D " $_DEVPATH -> "
+        echo $(readlink $_DEVPATH)
     done | sort -V
 }
 
 ba_querydisk () {
-    local LISTDEV ONDEV WWID ALIAS
+    local _LISTDEV _ONDEV _WWID _ALIAS
     if [ "$1" == "-d" ]; then
-        LISTDEV=1
+        _LISTDEV=1
         shift
     fi
-    ALIAS=$1
-    if [ "$ALIAS" == "" ]; then
+    _ALIAS=$1
+    if [ "$_ALIAS" == "" ]; then
         echo "Usage: $0 querydisk <alias>"
         exit 2
     fi
-    WWID=${NAMEMAP[$ALIAS]}
-    _debug "ba_querydisk: ALIAS=\"$ALIAS\" WWID=\"$WWID\" LISTDEV=\"$LISTDEV\""
-    if [ "$LISTDEV" == "1" ]; then
-        DEV="/dev/$BA_DEV_PATH/$(readlink "/dev/$BA_DEV_PATH/$ALIAS")"
+    _WWID=${NAMEMAP[$_ALIAS]}
+    _debug "ba_querydisk: ALIAS=\"$_ALIAS\" WWID=\"$_WWID\" LISTDEV=\"$_LISTDEV\""
+    if [ "$_LISTDEV" == "1" ]; then
+        DEV="/dev/$BA_DEV_PATH/$(readlink "/dev/$BA_DEV_PATH/$_ALIAS")"
         MAJ="$[0x$(stat --format "%t" $DEV)]"
         MIN="$[0x$(stat --format "%T" $DEV)]"
-        ONDEV="on device [$MAJ,$MIN]"
+        _ONDEV="on device [$MAJ,$MIN]"
         _debug "ba_querydisk: DEV=\"$DEV\" MAJ=\"$MAJ\" MIN=\"$MIN\""
     fi
-    if [ "$WWID" != "" ]; then
-        echo "$ALIAS is a valid blkdevalias disk $ONDEV"
+    if [ "$_WWID" != "" ]; then
+        echo "$_ALIAS is a valid blkdevalias disk $_ONDEV"
         return
     fi
     exit 1
@@ -374,25 +379,25 @@ ba_scandisks () {
 }
 
 ba_map () {
-    local WWID TYPE PART
-    WWID="$1"
-    if [ "$WWID" == "" ] || [ "${WWIDMAP[$WWID]}" == "" ]; then
+    local _WWID _TYPE _PART
+    _WWID="$1"
+    if [ "$_WWID" == "" ] || [ "${WWIDMAP[$_WWID]}" == "" ]; then
         echo "Usage: $0 map <wwid>" 1>&2
         exit 2
     fi
-    PART=$(ba_get_partnum $DEVNAME)
+    _PART=$(ba_get_partnum $DEVNAME)
     if [ "$ID_BUS" == "scsi" ]; then
-        TYPE=sd
+        _TYPE=sd
     else
-        TYPE=mpath
+        _TYPE=mpath
     fi
-    if [ "$PART" != ${PARTMAP[$WWID]} ] \
-        || [ "$TYPE" != ${TYPEMAP[$WWID]} ] ; then
+    if [ "$_PART" != ${PARTMAP[$_WWID]} ] \
+        || [ "$_TYPE" != ${TYPEMAP[$_WWID]} ] ; then
         exit 1
     fi
-    echo "BA_WWID=$WWID"
-    echo "BA_NAME=$BA_DEV_PATH/${WWIDMAP[$WWID]}"
-    echo "BA_TYPE=${TYPEMAP[$WWID]}"
+    echo "BA_WWID=$_WWID"
+    echo "BA_NAME=$BA_DEV_PATH/${WWIDMAP[$_WWID]}"
+    echo "BA_TYPE=${TYPEMAP[$_WWID]}"
     echo "BA_USER=$BA_USER"
     echo "BA_GROUP=$BA_GROUP"
     echo "BA_MODE=$BA_MODE"