lc_md.in

来自「lustre 1.6.5 source code」· IN 代码 · 共 512 行 · 第 1/2 页

IN
512
字号
#!/bin/bash## vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:## lc_md - configure Linux MD devices from a csv file################################################################################## Usageusage() {    cat >&2 <<EOFUsage:  `basename $0` [options] <csv file>    This script is used to configure Linux MD devices in a Lustre cluster    from a csv file.    Options:    -a          select all the nodes from the csv file to operate on    -w hostname,hostname,...                select the specified list of nodes (separated by commas)    -x hostname,hostname,...                exclude the specified list of nodes (separated by commas)    -h          help and examples    -v          verbose mode    csv file    a spreadsheet that contains configuration parameters                (separated by commas) for each Linux MD device to be                configured in a Lustre clusterEOF    exit 1}# Samples sample() {    cat <<EOFThis script is used to configure Linux MD devices in a Lustre clusterfrom a csv file.Each line marked with "MD" in the csv file represents one MD device.The format is:hostname,MD,md name,operation mode,options,raid level,component deviceshostname            hostname of the node in the clusterMD                  marker of MD device linemd name             MD device name, e.g. /dev/md0operation mode      create or remove, default is createoptions             a "catchall" for other mdadm options, e.g. "-c 128"raid level          raid level: 0,1,4,5,6,10,linear and multipathcomponent devices   block devices to be combined into the MD device                    Multiple devices are separated by space or by using                    shell expansions, e.g. "/dev/sd{a,b,c}"Items left blank will be set to defaults.Example:-------------------------------------------------------# MD devices on mgsnodemgsnode,MD,/dev/md0,,-q -c 32,1,/dev/sda1 /dev/sdb1mgsnode,MD,/dev/md1,,-q -c 32,1,/dev/sdc1 /dev/sdd1mgsnode,MD,/dev/md2,,-q -c 32,0,/dev/md0 /dev/md1# MD device on ostnodeostnode,MD,/dev/md0,,-q -c 128,5,"/dev/sd{a,b,c,d,e}"-------------------------------------------------------EOF    exit 0}# Get the library of functions. @scriptlibdir@/lc_common#***************************** Global variables *****************************## All the MD device items in the csv filedeclare -a HOST_NAME MD_NAME OP_MODE OP_OPTS RAID_LEVEL MD_DEVS# Variables related to background executionsdeclare -a REMOTE_CMDdeclare -a REMOTE_PIDdeclare -i pid_num=0VERBOSE_OUTPUT=false# Get and check the positional parameterswhile getopts "aw:x:hv" OPTION; do    case $OPTION in    a)        [ -z "${SPECIFIED_NODELIST}" ] && [ -z "${EXCLUDED_NODELIST}" ] \        && USE_ALLNODES=true        ;;    w)        USE_ALLNODES=false        SPECIFIED_NODELIST=$OPTARG        ;;    x)        USE_ALLNODES=false        EXCLUDED_NODELIST=$OPTARG        ;;    h)        sample        ;;    v)        VERBOSE_OUTPUT=true        ;;    ?)        usage     esacdone# Toss out the parameters we've already processedshift  `expr $OPTIND - 1`# Here we expect the csv fileif [ $# -eq 0 ]; then    echo >&2 "`basename $0`: Missing csv file!"    usagefi# check_md_item index## Check the items required for managing MD device ${MD_NAME[index]}check_md_item() {    # Check argument    if [ $# -eq 0 ]; then        echo >&2 "`basename $0`: check_md_item() error:"\                 "Missing argument!"        return 1    fi    declare -i i=$1    # Check hostname    if [ -z "${HOST_NAME[i]}" ]; then        echo >&2 "`basename $0`: check_md_item() error:"\                 "hostname item has null value!"        return 1    fi    # Check items required by create mode    if [ -z "${OP_MODE[i]}" -o "${OP_MODE[i]}" = "create" ]; then        # Check MD device name         if [ -z "${MD_NAME[i]}" ]; then            echo >&2 "`basename $0`: check_md_item() error:"\            "md name item has null value!"            return 1        fi        if [ -z "${RAID_LEVEL[i]}" ]; then            echo >&2 "`basename $0`: check_md_item() error:"\            "raid level item of MD device ${MD_NAME[i]} has null value!"            return 1        fi        if [ -z "${MD_DEVS[i]}" ]; then            echo >&2 "`basename $0`: check_md_item() error:"\            "component devices item of ${MD_NAME[i]} has null value!"            return 1        fi    fi    return 0}# get_md_items csv_file## Get all the MD device items in the $csv_file and do some checks.get_md_items() {    # Check argument    if [ $# -eq 0 ]; then        echo >&2 "`basename $0`: get_md_items() error: Missing csv file!"        return 1    fi    CSV_FILE=$1    local LINE    local hostname    declare -i line_num=0    declare -i idx=0    while read -r LINE; do        let "line_num += 1"        # Skip the comment line        [ -z "`echo \"${LINE}\" | egrep -v \"([[:space:]]|^)#\"`" ] && continue        # Skip the non-MD line        [ "$(echo ${LINE} | cut -d, -f 2)" != "${MD_MARKER}" ] && continue        # 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            return 1            fi        HOST_NAME[idx]=${CONFIG_ITEM[0]}        MD_NAME[idx]=${CONFIG_ITEM[2]}        OP_MODE[idx]=${CONFIG_ITEM[3]}        OP_OPTS[idx]=${CONFIG_ITEM[4]}        RAID_LEVEL[idx]=${CONFIG_ITEM[5]}        MD_DEVS[idx]=${CONFIG_ITEM[6]}        # Check some required items        if ! check_md_item $idx; then            echo >&2 "`basename $0`: check_md_item() error:"\                     "Occurred on line ${line_num} in ${CSV_FILE}."            return 1            fi        let "idx += 1"    done < ${CSV_FILE}    return 0}# md_is_active host_name md_name## Run remote command to check whether $md_name is active in @host_namemd_is_active() {    local host_name=$1    local md_name=$2    local cmd ret_str    cmd="grep -q ${md_name##*/} /proc/mdstat 2>&1"    ret_str=$(${REMOTE} ${host_name} "${cmd}" 2>&1)    if [ ${PIPESTATUS[0]} -ne 0 ]; then        if [ -n "${ret_str}" ]; then            echo >&2 "`basename $0`: md_is_active() error:"\            "remote command to ${host_name} error: ${ret_str}!"            return 2    # Error occurred        else            return 1    # inactive        fi    fi    return 0            # active}# construct_mdadm_create_cmdline index## Construct the create operation command line of mdadm for ${MD_NAME[index]}construct_mdadm_create_cmdline() {    declare -i i=$1    local cmd_line    local echo_disk disk line    declare -i alldisks=0     declare -i raiddisks=0     declare -i sparedisks=0    cmd_line="${MDADM} -C -R ${MD_NAME[i]} ${OP_OPTS[i]} -l ${RAID_LEVEL[i]}"

⌨️ 快捷键说明

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