Whamcloud - gitweb
Branch b1_6
authoryujian <yujian>
Sat, 9 Jun 2007 07:09:09 +0000 (07:09 +0000)
committeryujian <yujian>
Sat, 9 Jun 2007 07:09:09 +0000 (07:09 +0000)
b=10760
i=brian
i=nathan

Improve the operation to get the corresponding NID(s) of the MGS node from
the "mgs nids" field of one lustre target line for checking lnet connectivity
between that lustre node and the MGS node.

lustre/scripts/lc_common
lustre/scripts/lc_md.in
lustre/scripts/lustre_config.in

index 06a547f..8b1bcbe 100644 (file)
@@ -292,7 +292,7 @@ nid2hostname() {
         fi
 
         # Execute remote command to get the host name
-        ret_str=$(${REMOTE} ${ip_addr} "hostname" 2>&1)
+        ret_str=$(${REMOTE} ${ip_addr} "hostname" 2>&1 </dev/null)
         if [ ${PIPESTATUS[0]} -ne 0 -a -n "${ret_str}" ]; then
             echo "`basename $0`: nid2hostname() error:" \
             "remote command to ${ip_addr} error: ${ret_str}"
@@ -522,3 +522,70 @@ check_nodelist() {
 
     return 0
 }
+
+# nid_in_nidlist nid nidlist
+# Given a nid, and a list of nids in one node (delimited by comma ','),
+# return true if the nid appears in the list of nids, or false otherwise.
+nid_in_nidlist() {
+    local nid="$1"
+    local nidlist="$2"
+    local my_nid
+
+    [ -z "${nid}" -o -z "${nidlist}" ] && false && return
+
+    if [[ "${nid}" != *@* || "${nid#*@}" == tcp* ]]; then
+        # network type is tcp
+        for my_nid in ${nidlist//,/ }; do
+            [ "${nid%@*}" = "${my_nid%@*}" ] && true && return
+        done
+    else
+        # network type is not tcp
+        [[ ,${nidlist}, == *,${nid},* ]] && true && return
+    fi
+
+    false && return
+}
+
+# get_mgs_nids mgs_hostname mgs_nids
+# Get the corresponding NID(s) of the MGS node ${mgs_hostname} from the
+# "mgs nids" field of one lustre target in the csv file
+get_mgs_nids() {
+    local mgs_node="$1"
+    local all_mgs_nids="$2"
+    local mgs_nids
+    local ret_str
+
+    # Check whether the hostname of the mgs node is in 
+    # the mgs nids string
+    for mgs_nids in ${all_mgs_nids//:/ }; do
+        if nid_in_nidlist ${mgs_node} ${mgs_nids}; then
+            echo ${mgs_nids}
+            return 0
+        fi
+    done
+
+    # Let's use lctl to get the real nids from the mgs node
+    ret_str=$(${REMOTE} ${mgs_node} "${LCTL} list_nids" 2>&1 </dev/null)
+    if [ ${PIPESTATUS[0]} -ne 0 -a -n "${ret_str}" ]; then
+        echo "$(basename $0): get_mgs_nids() error:" \
+        "remote command to ${mgs_node} error: ${ret_str}"
+        return 1
+    fi
+    remote_error "get_mgs_nids" ${mgs_node} "${ret_str}" && return 1
+
+    local real_mgs_nids=${ret_str//${mgs_node}:/}
+    for real_mgs_nid in ${real_mgs_nids}; do
+        for mgs_nids in ${all_mgs_nids//:/ }; do
+            if nid_in_nidlist ${real_mgs_nid} ${mgs_nids}; then
+                echo ${mgs_nids}
+                return 0
+            fi
+        done
+    done
+
+    echo "$(basename $0): get_mgs_nids() error:" \
+    "Can not figure out which nids corresponding to the MGS"\
+    "node ${mgs_node} from \"${all_mgs_nids}\"!"
+
+    return 1
+}
index 127974d..ab741af 100644 (file)
@@ -317,7 +317,7 @@ construct_mdadm_rm_cmdline() {
         # Remove the "missing" devices from the component devices
         real_devs=`echo ${MD_DEVS[i]} | sed 's/missing//g'`
         # Over-written the superblock with zeros
-        mdadm_cmd=${mdadm_cmd}" && ${MDADM} --zero-superblock ${real_devs}"
+        mdadm_cmd=${mdadm_cmd}" && ${MDADM} --zero-superblock ${real_devs} || true"
     fi
 
     echo ${mdadm_cmd}
index 47662b4..c89dca4 100644 (file)
@@ -243,9 +243,11 @@ declare -a TARGET_OPTS              # target services in one failover group
 declare -a HOST_NAME MODULE_OPTS DEVICE_NAME MOUNT_POINT DEVICE_TYPE FS_NAME
 declare -a MGS_NIDS INDEX FORMAT_OPTIONS MKFS_OPTIONS MOUNT_OPTIONS FAILOVERS
 
-# Corresponding to MGS_NIDS and FAILOVERS arrays,
-# IP addresses in which were converted to hostnames
-declare -a MGS_NIDS_NAMES FAILOVERS_NAMES
+# Heartbeat software requires that node names in the configuration directive
+# must (normally) match the "uname -n" of that machine. Since the value of the
+# "failover nids" field in the csv file is the NID(s) of failover partner node,
+# we have to figure out the corresponding hostname of that node.
+declare -a FAILOVERS_NAMES
 
 VERIFY_CONNECT=true
 CONFIG_MD_LVM=false
@@ -804,12 +806,6 @@ get_items() {
         MODULE_OPTS[idx]=`echo "${MODULE_OPTS[idx]}" | sed 's/"/\\\"/g'`
 
         # Convert IP addresses in NIDs to hostnames
-        MGS_NIDS_NAMES[idx]=$(ip2hostname_multi_node ${MGS_NIDS[idx]})
-        if [ ${PIPESTATUS[0]} -ne 0 ]; then
-            echo >&2 "${MGS_NIDS_NAMES[idx]}"
-            return 1
-        fi
-
         FAILOVERS_NAMES[idx]=$(ip2hostname_multi_node ${FAILOVERS[idx]})
         if [ ${PIPESTATUS[0]} -ne 0 ]; then
             echo >&2 "${FAILOVERS_NAMES[idx]}"
@@ -838,7 +834,6 @@ check_lnet_connect() {
 
     local COMMAND RET_STR
     local mgs_prim_nids
-    local nids nids_names
     local nids_str=
     local mgs_nid 
     local ping_mgs
@@ -849,7 +844,7 @@ check_lnet_connect() {
     "${HOST_NAME[i]} and the MGS node ${mgs_node}"
     mgs_prim_nids=`echo ${MGS_NIDS[i]} | awk -F: '{print $1}'`
 
-    if [ -z "${mgs_node}" ]; then
+    if [ -z "${mgs_node}" -o $MGS_NUM -eq 1 ]; then
         nids_str=${mgs_prim_nids}    # nids of primary MGS node
         if [ -z "${nids_str}" ]; then
             echo >&2 $"`basename $0`: check_lnet_connect() error:"\
@@ -858,21 +853,11 @@ check_lnet_connect() {
             return 1
         fi
     else
-        for nids in ${MGS_NIDS[i]//:/ }; do
-            nids_names=$(ip2hostname_single_node ${nids})
-            if [ ${PIPESTATUS[0]} -ne 0 ]; then
-                echo >&2 "${nids_names}"
-                return 1
-            fi
-
-            [ "${nids_names}" != "${nids_names#*$mgs_node*}" ]\
-            && nids_str=${nids} # nids of backup MGS node
-        done
-        if [ -z "${nids_str}" ]; then
-            echo >&2 $"`basename $0`: check_lnet_connect() error:"\
-            "Check the mgs nids item of host ${HOST_NAME[i]}!"\
-            "Can not figure out which nids corresponding to the MGS"\
-            "node ${mgs_node} from \"${MGS_NIDS[i]}\"!"
+        # Get the corresponding NID(s) of the MGS node ${mgs_node}
+        # from the "mgs nids" field
+        nids_str=$(get_mgs_nids ${mgs_node} ${MGS_NIDS[i]})
+        if [ ${PIPESTATUS[0]} -ne 0 ]; then
+            echo >&2 "${nids_str}"
             return 1
         fi
     fi