lustre_config.in

来自「lustre 1.6.5 source code」· IN 代码 · 共 1,221 行 · 第 1/3 页

IN
1,221
字号
          fi        done    done    return 0}# Get and check MGS servers.# There should be no more than one MGS specified in the entire csv file.check_mgs() {    declare -i i    declare -i j    declare -i exp_idx    # Index of explicit MGS servers    declare -i imp_idx    # Index of implicit MGS servers    local is_exp_mgs is_imp_mgs    local mgs_node    # Initialize the MGS_NODENAME and MGS_IDX arrays    unset MGS_NODENAME    unset MGS_IDX    exp_idx=1    imp_idx=1    for ((i = 0; i < ${#HOST_NAME[@]}; i++)); do        is_exp_mgs=false        is_imp_mgs=false        # Check whether this node is an explicit MGS node         # or an implicit one        if [ "${DEVICE_TYPE[i]#*mgs*}" != "${DEVICE_TYPE[i]}" ]; then            verbose_output "Explicit MGS target" \            "${DEVICE_NAME[i]} in host ${HOST_NAME[i]}."            is_exp_mgs=true        fi        if [ "${DEVICE_TYPE[i]}" = "mdt" -a -z "${MGS_NIDS[i]}" ]; then            verbose_output "Implicit MGS target" \            "${DEVICE_NAME[i]} in host ${HOST_NAME[i]}."            is_imp_mgs=true        fi        # Get and check MGS servers        if ${is_exp_mgs} || ${is_imp_mgs}; then            # Check whether more than one MGS target in one MGS node            if is_mgs_node ${HOST_NAME[i]}; then                echo >&2 $"`basename $0`: check_mgs() error:"\                "More than one MGS target in the same node -"\                "\"${HOST_NAME[i]}\"!"                return 1            fi            # Get and check primary MGS server and backup MGS server                    if [ "${FORMAT_OPTIONS[i]}" = "${FORMAT_OPTIONS[i]#*noformat*}" ]            then                # Primary MGS server                if [ -z "${MGS_NODENAME[0]}" ]; then                    if [ "${is_exp_mgs}" = "true" -a ${imp_idx} -gt 1 ] \                    || [ "${is_imp_mgs}" = "true" -a ${exp_idx} -gt 1 ]; then                        echo >&2 $"`basename $0`: check_mgs() error:"\                        "There exist both explicit and implicit MGS"\                        "targets in the csv file!"                        return 1                    fi                    MGS_NODENAME[0]=${HOST_NAME[i]}                    MGS_IDX[0]=$i                else                    mgs_node=${MGS_NODENAME[0]}                    if [ "${FAILOVERS_NAMES[i]#*$mgs_node*}" = "${FAILOVERS_NAMES[i]}" ]                    then                        echo >&2 $"`basename $0`: check_mgs() error:"\                        "More than one primary MGS nodes in the csv" \                        "file - ${MGS_NODENAME[0]} and ${HOST_NAME[i]}!"                    else                        echo >&2 $"`basename $0`: check_mgs() error:"\                        "MGS nodes ${MGS_NODENAME[0]} and ${HOST_NAME[i]}"\                        "are failover pair, one of them should use"\                        "\"--noformat\" in the format options item!"                    fi                    return 1                fi            else    # Backup MGS server                if [ "${is_exp_mgs}" = "true" -a ${imp_idx} -gt 1 ] \                || [ "${is_imp_mgs}" = "true" -a ${exp_idx} -gt 1 ]; then                    echo >&2 $"`basename $0`: check_mgs() error:"\                    "There exist both explicit and implicit MGS"\                    "targets in the csv file!"                    return 1                fi                if ${is_exp_mgs}; then # Explicit MGS                    MGS_NODENAME[exp_idx]=${HOST_NAME[i]}                    MGS_IDX[exp_idx]=$i                    exp_idx=$(( exp_idx + 1 ))                else    # Implicit MGS                    MGS_NODENAME[imp_idx]=${HOST_NAME[i]}                    MGS_IDX[imp_idx]=$i                    imp_idx=$(( imp_idx + 1 ))                fi            fi        fi #End of "if ${is_exp_mgs} || ${is_imp_mgs}"    done    # Check whether the MGS nodes are in the same failover group    if ! check_mgs_group; then        return 1    fi    return 0}# Construct the command line of mkfs.lustreconstruct_mkfs_cmdline() {    # Check argument    if [ $# -eq 0 ]; then        echo >&2 $"`basename $0`: construct_mkfs_cmdline() error:"\                  "Missing argument for function construct_mkfs_cmdline()!"        return 1    fi    declare -i i=$1    local mgsnids mgsnids_str    local failnids failnids_str    if $UPGRADE_TARGET; then        MKFS_CMD="$TUNEFS --writeconf"    else        MKFS_CMD="$MKFS $REFORMAT_OPTION"    fi    case "${DEVICE_TYPE[i]}" in    "ost")        MKFS_CMD="$MKFS_CMD --ost"        ;;    "mdt")        MKFS_CMD="$MKFS_CMD --mdt"        ;;    "mgs")        MKFS_CMD="$MKFS_CMD --mgs"        ;;    "mdt|mgs" | "mgs|mdt")        MKFS_CMD="$MKFS_CMD --mgs --mdt"        ;;    *)        echo >&2 $"`basename $0`: construct_mkfs_cmdline() error:"\                  "Invalid device type - \"${DEVICE_TYPE[i]}\"!"        return 1        ;;    esac    if [ -n "${FS_NAME[i]}" ]; then        MKFS_CMD="$MKFS_CMD --fsname=${FS_NAME[i]}"    fi    if [ -n "${MGS_NIDS[i]}" ]; then        mgsnids_str=${MGS_NIDS[i]}        for mgsnids in ${mgsnids_str//:/ }; do            MKFS_CMD="$MKFS_CMD --mgsnode=$mgsnids"        done    fi    if [ -n "${INDEX[i]}" ]; then        MKFS_CMD="$MKFS_CMD --index=${INDEX[i]}"    fi    if [ -n "${FORMAT_OPTIONS[i]}" ]; then        MKFS_CMD="$MKFS_CMD ${FORMAT_OPTIONS[i]}"    fi    if ! $UPGRADE_TARGET && [ -n "${MKFS_OPTIONS[i]}" ]; then        MKFS_CMD="$MKFS_CMD --mkfsoptions=\"${MKFS_OPTIONS[i]}\""    fi    if [ -n "${MOUNT_OPTIONS[i]}" ] && ! $MODIFY_FSTAB; then        MKFS_CMD="$MKFS_CMD --mountfsoptions=\"${MOUNT_OPTIONS[i]}\""    fi    if [ -n "${FAILOVERS[i]}" ]; then        failnids_str=${FAILOVERS[i]}        for failnids in ${failnids_str//:/ }; do            MKFS_CMD="$MKFS_CMD --failnode=$failnids"        done    fi    MKFS_CMD="$MKFS_CMD ${DEVICE_NAME[i]}"    return 0} # Get all the node names in this failover groupget_nodenames() {    # Check argument    if [ $# -eq 0 ]; then        echo >&2 $"`basename $0`: get_nodenames() error: Missing"\                  "argument for function get_nodenames()!"        return 1    fi    declare -i i=$1    declare -i idx    local nids    # Initialize the NODE_NAMES array    unset NODE_NAMES    NODE_NAMES[0]=${HOST_NAME[i]}    idx=1    for nids in ${FAILOVERS_NAMES[i]//:/ }    do        NODE_NAMES[idx]=$(nids2hostname ${nids})        if [ ${PIPESTATUS[0]} -ne 0 ]; then            echo >&2 "${NODE_NAMES[idx]}"            return 1        fi            idx=$idx+1    done    return 0}# Verify whether the format line has HA itemsis_ha_line() {    declare -i i=$1    [ -n "${FAILOVERS[i]}" ] && return 0    return 1}# Produce HA software's configuration filesgen_ha_config() {    declare -i i=$1    declare -i idx    local  cmd_line    # Prepare parameters    # Hostnames option    HOSTNAME_OPT=${HOST_NAME[i]}    if ! get_nodenames $i; then        echo >&2 $"`basename $0`: gen_ha_config() error: Can not get the"\        "failover nodenames from failover nids - \"${FAILOVERS[i]}\" in"\        "the \"${HOST_NAME[i]}\" failover group!"        return 1    fi    for ((idx = 1; idx < ${#NODE_NAMES[@]}; idx++)); do        HOSTNAME_OPT=${HOSTNAME_OPT}$":"${NODE_NAMES[idx]}    done    # Target devices option    DEVICE_OPT=" -d "${TARGET_OPTS[0]}    for ((idx = 1; idx < ${#TARGET_OPTS[@]}; idx++)); do        DEVICE_OPT=${DEVICE_OPT}" -d "${TARGET_OPTS[idx]}    done    # Construct the generation script command line    case "${HATYPE_OPT}" in    "${HBVER_HBV1}"|"${HBVER_HBV2}")    # Heartbeat         cmd_line=${GEN_HB_CONFIG}$" -r ${HATYPE_OPT} -n ${HOSTNAME_OPT}"        cmd_line=${cmd_line}${DEVICE_OPT}${VERBOSE_OPT}        ;;    "${HATYPE_CLUMGR}")                 # CluManager        cmd_line=${GEN_CLUMGR_CONFIG}$" -n ${HOSTNAME_OPT}"        cmd_line=${cmd_line}${DEVICE_OPT}${VERBOSE_OPT}        ;;    esac        # Execute script to generate HA software's configuration files    verbose_output "Generating HA software's configurations in"\               "${HOST_NAME[i]} failover group..."    verbose_output "${cmd_line}"    eval $(echo "${cmd_line}")    if [ ${PIPESTATUS[0]} -ne 0 ]; then        return 1    fi    verbose_output "Generate HA software's configurations in"\               "${HOST_NAME[i]} failover group OK"        return 0}# Configure HA softwareconfig_ha() {    if $UPGRADE_TARGET || [ -z "${HATYPE_OPT}" ]; then        return 0    fi    declare -i i j k    declare -i prim_idx         # Index for PRIM_HOSTNAMES array    declare -i target_idx       # Index for TARGET_OPTS and HOST_INDEX arrays    declare -a PRIM_HOSTNAMES   # Primary hostnames in all the failover                                # groups in the lustre cluster    declare -a HOST_INDEX       # Indices for the same node in all the                                 # format lines in the csv file    local prim_host    # Initialize the PRIM_HOSTNAMES array    prim_idx=0    unset PRIM_HOSTNAMES    # Get failover groups and generate HA configuration files    for ((i = 0; i < ${#HOST_NAME[@]}; i++)); do        prim_host=${HOST_NAME[i]}        for ((j = 0; j < ${#PRIM_HOSTNAMES[@]}; j++)); do            [ "${prim_host}" = "${PRIM_HOSTNAMES[j]}" ] && continue 2        done        target_idx=0        unset HOST_INDEX        unset TARGET_OPTS        for ((k = 0; k < ${#HOST_NAME[@]}; k++)); do            if [ "${prim_host}" = "${HOST_NAME[k]}" ] && is_ha_line "${k}"            then                HOST_INDEX[target_idx]=$k                TARGET_OPTS[target_idx]=${DEVICE_NAME[k]}:${MOUNT_POINT[k]}                target_idx=$(( target_idx + 1 ))            fi        done        if [ ${#TARGET_OPTS[@]} -ne 0 ]; then            PRIM_HOSTNAMES[prim_idx]=${prim_host}            prim_idx=$(( prim_idx + 1 ))            if ! gen_ha_config ${HOST_INDEX[0]}; then                return 1            fi        fi    done    if [ ${#PRIM_HOSTNAMES[@]} -eq 0 ]; then        verbose_output "There are no \"failover nids\" items in the"\        "csv file. No HA configuration files are generated!"    fi    rm -rf ${TMP_DIRS}    return 0}# Get all the items in the csv file and do some checks.get_items() {    # Check argument    if [ $# -eq 0 ]; then        echo >&2 $"`basename $0`: get_items() error: Missing argument"\                  "for function get_items()!"        return 1    fi    CSV_FILE=$1    local LINE    local marker    local hostname    declare -i line_num=0    declare -i idx=0    exec 9< ${CSV_FILE}    while read -u 9 -r LINE; do        line_num=${line_num}+1        # verbose_output "Parsing line ${line_num}: $LINE"        # Get rid of the empty line        if [ -z "`echo ${LINE}|awk '/[[:alnum:]]/ {print $0}'`" ]; then            continue        fi        # Get rid of the comment line        if [ -z "`echo \"${LINE}\" | egrep -v \"([[:space:]]|^)#\"`" ]        then            continue        fi        # Skip the Linux MD/LVM line        marker=$(echo ${LINE} | cut -d, -f 2)        if [ "${marker}" = "${MD_MARKER}" -o "${marker}" = "${PV_MARKER}" ] \        || [ "${marker}" = "${VG_MARKER}" -o "${marker}" = "${LV_MARKER}" ]; then            continue        fi        # Skip the host which is not specified in the host list        if ! ${USE_ALLNODES}; then            hostname=$(echo ${LINE} | cut -d, -f 1)            ! host_in_hostlist ${hostname} ${NODES_TO_USE} && continue        fi        # Parse the config line into CONFIG_ITEM        if ! parse_line "$LINE"; then            echo >&2 $"`basename $0`: parse_line() error: Occurred"\                  "on line ${line_num} in ${CSV_FILE}: $LINE"            return 1            fi        HOST_NAME[idx]=${CONFIG_ITEM[0]}        MODULE_OPTS[idx]=${CONFIG_ITEM[1]}        DEVICE_NAME[idx]=${CONFIG_ITEM[2]}        MOUNT_POINT[idx]=${CONFIG_ITEM[3]}        DEVICE_TYPE[idx]=${CONFIG_ITEM[4]}        FS_NAME[idx]=${CONFIG_ITEM[5]}        MGS_NIDS[idx]=${CONFIG_ITEM[6]}        INDEX[idx]=${CONFIG_ITEM[7]}        FORMAT_OPTIONS[idx]=${CONFIG_ITEM[8]}        MKFS_OPTIONS[idx]=${CONFIG_ITEM[9]}        MOUNT_OPTIONS[idx]=${CONFIG_ITEM[10]}        FAILOVERS[idx]=${CONFIG_ITEM[11]}        MODULE_OPTS[idx]=`echo "${MODULE_OPTS[idx]}" | sed 's/"/\\\"/g'`

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?