lc_lvm.in

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

IN
594
字号
#!/bin/bash## vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:## lc_lvm - configure Linux LVM devices from a csv file################################################################################## Usageusage() {    cat >&2 <<EOFUsage:  `basename $0` [options] <csv file>    This script is used to configure Linux LVM 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 LVM component                (PV, VG, LV) to be configured in a Lustre clusterEOF    exit 1}# Samples sample() {    cat <<EOFThis script is used to configure Linux LVM devices in a Lustre clusterfrom a csv file.LVM is a Logical Volume Manager for the Linux operating system. Thethree-level components of it are PV (Physical Volume), VG (Volume Group)and LV (Logical Volume).Each line marked with "PV" in the csv file represents one or more PVs.The format is:hostname,PV,pv names,operation mode,optionshostname            hostname of the node in the clusterPV                  marker of PV linepv names            devices or loopback files to be initialized for later                    use by LVM or to be wiped the label, e.g. /dev/sda                    Multiple devices or files are separated by space or by                    using shell expansions, e.g. "/dev/sd{a,b,c}"operation mode      create or remove, default is createoptions             a "catchall" for other pvcreate/pvremove options                    e.g. "-vv"Each line marked with "VG" in the csv file represents one VG.The format is:hostname,VG,vg name,operation mode,options,pv pathshostname            hostname of the node in the clusterVG                  marker of VG linevg name             name of the volume group, e.g. ost_vgoperation mode      create or remove, default is createoptions             a "catchall" for other vgcreate/vgremove options                    e.g. "-s 32M"pv paths            physical volumes to construct this VG, required by                    create mode                    Multiple PVs are separated by space or by using                    shell expansions, e.g. "/dev/sd[k-m]1"Each line marked with "LV" in the csv file represents one LV.The format is:hostname,LV,lv name,operation mode,options,lv size,vg namehostname            hostname of the node in the clusterLV                  marker of LV linelv name             name of the logical volume to be created (optional)                    or path of the logical volume to be removed (required                    by remove mode)operation mode      create or remove, default is createoptions             a "catchall" for other lvcreate/lvremove options                    e.g. "-i 2 -I 128"lv size             size [kKmMgGtT] to be allocated for the new LV                    Default unit is megabytes.vg name             name of the VG in which the new LV will be createdItems left blank will be set to defaults.Example:-------------------------------------------------------# MD/LVM devices on mgsnode# Remove the LVM devices in the mgsnodemgsnode,LV,/dev/mgs_vg/mdt1,removemgsnode,LV,/dev/mgs_vg/mdt2,removemgsnode,VG,mgs_vg,removemgsnode,PV,"/dev/sd{a,b}1",remove# Create MD device in the mgsnodemgsnode,MD,/dev/md0,,-q,1,/dev/sda1 /dev/sdb1# MD/LVM devices on ostnode# Create MD and LVM devices in the ostnodeostnode,MD,/dev/md0,,-q -c 128,5,"/dev/sd{a,b,c}"ostnode,MD,/dev/md1,,-q -c 128,5,"/dev/sd{d,e,f}"ostnode,PV,/dev/md0 /dev/md1ostnode,VG,ost_vg,,-s 32M,"/dev/md{0,1}"ostnode,LV,ost0,,-i 2 -I 128,300G,ost_vgostnode,LV,ost1,,-i 2 -I 128,300G,ost_vg-------------------------------------------------------EOF    exit 0}# Get the library of functions. @scriptlibdir@/lc_common#***************************** Global variables *****************************## All the LVM device items in the csv filedeclare -a HOST_NAME LINE_MARKER LVM_NAME OP_MODE OP_OPTS SIXTH_ITEM SEVENTH_ITEM# 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_lvm_item index## Check the items required for managing LVM device ${LVM_NAME[index]}check_lvm_item() {    # Check argument    if [ $# -eq 0 ]; then        echo >&2 "`basename $0`: check_lvm_item() error:"\                 "Missing argument!"        return 1    fi    declare -i i=$1    # Check hostname    if [ -z "${HOST_NAME[i]}" ]; then        echo >&2 "`basename $0`: check_lvm_item() error:"\                 "hostname item has null value!"        return 1    fi    # Check LVM device name     if [ -z "${LVM_NAME[i]}" ] \    && [ "${LINE_MARKER[i]}" != "${LV_MARKER}" -a "${OP_MODE[i]}" != "remove" ]    then        echo >&2 "`basename $0`: check_lvm_item() error:"\                 "LVM component name item has null value!"        return 1    fi    # Check the operation mode    if [ -n "${OP_MODE[i]}" ] \    && [ "${OP_MODE[i]}" != "create" -a "${OP_MODE[i]}" != "remove" ]    then        echo >&2 "`basename $0`: check_lvm_item() error:"\                 "Invalid operation mode item - \"${OP_MODE[i]}\"!"        return 1    fi    # Check items required by create mode    if [ -z "${OP_MODE[i]}" -o "${OP_MODE[i]}" = "create" ]; then        if [ "${LINE_MARKER[i]}" = "${VG_MARKER}" -a -z "${SIXTH_ITEM[i]}" ]        then            echo >&2 "`basename $0`: check_lvm_item() error:"\            "pv paths item of vg ${LVM_NAME[i]} has null value!"            return 1        fi        if [ "${LINE_MARKER[i]}" = "${LV_MARKER}" ]; then            if [ -z "${SIXTH_ITEM[i]}" ]; then                echo >&2 "`basename $0`: check_lvm_item() error:"\                         "lv size item has null value!"                return 1            fi            if [ -z "${SEVENTH_ITEM[i]}" ]; then                echo >&2 "`basename $0`: check_lvm_item() error:"\                         "vg name item has null value!"                return 1            fi        fi    fi    return 0}# get_lvm_items csv_file## Get all the LVM device items in the $csv_file and do some checks.get_lvm_items() {    # Check argument    if [ $# -eq 0 ]; then        echo >&2 "`basename $0`: get_lvm_items() error: Missing csv file!"        return 1    fi    CSV_FILE=$1    local LINE line_marker    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-LVM line        line_marker=$(echo ${LINE} | cut -d, -f 2)        [ "${line_marker}" != "${PV_MARKER}" ] \        && [ "${line_marker}" != "${VG_MARKER}" ] \        && [ "${line_marker}" != "${LV_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]}        LINE_MARKER[idx]=${CONFIG_ITEM[1]}        LVM_NAME[idx]=${CONFIG_ITEM[2]}        OP_MODE[idx]=${CONFIG_ITEM[3]}        OP_OPTS[idx]=${CONFIG_ITEM[4]}        SIXTH_ITEM[idx]=${CONFIG_ITEM[5]}        SEVENTH_ITEM[idx]=${CONFIG_ITEM[6]}        # Check some required items        if ! check_lvm_item $idx; then            echo >&2 "`basename $0`: check_lvm_item() error:"\                     "Occurred on line ${line_num} in ${CSV_FILE}."            return 1            fi        let "idx += 1"    done < ${CSV_FILE}    return 0}# construct_lvm_create_cmdline index## Construct the creation command line for ${LVM_NAME[index]}construct_lvm_create_cmdline() {

⌨️ 快捷键说明

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