+++ /dev/null
-#! /bin/sh
-# Copyright (C) 2003 Cluster File Systems, Inc.
-# Create a Lustre configuration file
-#
-# Usage: lwizard
-#
-# Jerrifer <jerrifer@clusterfs.com>
-# wangdi <wangdi@clusterfs.com>
-
-# fatal error to exit
-fatal()
-{
- if [ "$#" -gt "1" ]; then
- echo
- echo "$2"
- exit 1
- fi
-
- exit 1
-}
-
-#print usage and exit
-usage()
-{
- cat <<EOF
-Usage: ${0##*/} [OPTIONS]...
-
-${##*/} asks the user questions about their cluster configuration, and
-writes an appropriate configuration file to config.xml.
-
-Options:
- -o, --file=CONFIG_FILE
- write configuration to CONFIG_FILE (default: config.xml)
- --stripe_size=SIZE
- specify the size (in KB) of each stripe on an OST (default: 64)
- --stripe_cnt=COUNT
- sepcify the number of OSTs files are striped to (default: 1)
- --help
- to get this help
-EOF
-
- exit 0
-}
-
-# check if $1 is a number
-check_number()
-{
- local num=$(expr "$1" : "[0-9]*$")
- if [ $num -gt "0" ]; then
- return 0
- fi
-
- return 1
-}
-
-#parse options of this shell
-get_option()
-{
- local long_options="file:,mds_size:,ost_size:,stripe_size"
- local options
-
- long_options="$long_options:,stripe_cnt:,stripe_pattern"
- options=$(getopt -o o:h --long "$long_options":,help -- "$@")
-
- if [ $? -ne 0 ] ; then
- usage
- fi
- eval set -- "$options"
-
- while true ; do
- case "$1" in
- -o | --file)
- CONFIG_FILE=$2
- shift 2
- ;;
- --stripe_size)
- STRIPE_SIZE=$(($2 * 1024))
- check_number $STRIPE_SIZE || fatal 1 "bad stripe_size"
- shift 2
- ;;
- --stripe_cnt)
- STRIPE_CNT=$2
- check_number $STRIPE_CNT || fatal 1 "bad stripe_cnt"
- shift 2
- ;;
- -h | --help)
- usage
- ;;
- --)
- shift 1
- break
- esac
- done
-}
-
-# if $1 in $2
-in_list()
-{
- local node
-
- for node in $2 ; do
- [ "$1" = "$node" ] && return 0
- done
- return 1
-}
-
-# read line from stdin
-read_ln()
-{
- local substr=$1
- local default_value
- local answer
-
- unset ANS
-
- [ $# -gt 1 ] && default_value=$2
- [ $# -gt 2 ] && answer=$3
-
- while [ -z "$ANS" ]; do
- echo -n "$substr"
- [ "$default_value" ] && echo -n " ($default_value)"
- echo -n ": "
- read ANS
- [ -z "$ANS" -a "$default_value" ] && ANS=$default_value
- if [ "$ANS" -a "$answer" ] ; then
- in_list "$ANS" "$ANSWER" || ANS=""
- fi
- done
-
- return 0
-}
-
-#ask user some questions to add a device
-add_device()
-{
- local first
- local hostname
-
- [ $# -gt 2 ] && first=$3
-
- if [ -z "$first" ] ; then
- read_ln "Do you want to add another $1 (yes/no)?" "no" "$ANSWER"
- else
- ANS="yes"
- fi
-
- [ "$ANS" = "no" ] && return 1
-
- echo "Creating $1 \"$1$2\"..."
- read_ln "Please enter $1$2's hostname"
- hostname=$ANS
- read_ln "Please enter $1$2's device"
-
- device=$ANS
-
- DEVICE="$hostname:$device:$2:$1$2"
-
- return 0
-}
-
-# get mds information
-add_mds()
-{
- local id=1
- local host_name
-
- while :; do
- add_device "mds" "$id" "first" || break
- in_list "$DEVICE" "$MDS_LIST" && continue
- MDS_LIST="$MDS_LIST $DEVICE" #add mds to MDS_LIST
- ((id++))
- break
- done
-
- return 0
-}
-
-# ask user to add ost
-add_ost()
-{
- local first="first"
- local id=1
-
- while :; do
- add_device "ost" "$id" "$first" || break
- in_list "$DEVICE" "$OST_LIST" && continue
- OST_LIST="$OST_LIST $DEVICE" #add ost to MDS_LIST
- ((id++))
- first=""
- done
-
- return 0
-}
-
-# ask user to add client to lustre
-add_client()
-{
- read_ln "Please enter the mountpoint for your clients" "$DEFAULT_MNTPT"
- CLIENT_LIST="*:$ANS:client:client"
- return 0
-}
-
-#save node config into config file
-add_node()
-{
- local node=$1
- local nettype=$DEFAULT_NETTYPE
- local config_file=$2
-
- in_list "$node" "$NODE_LIST" && return 0
- NODE_LIST="$NODE_LIST $node"
-
- $LMC -m "$config_file" --add node --node "$node" || return 1
- $LMC -m "$config_file" --add net --node "$node" --nid "$node" \
- --nettype "$nettype" || return 1
- return 0
-}
-
-#get hostname, device , device_id and device name
-#from mds node
-get_name_in_list()
-{
- HOST_NAME=$(echo $1 | awk -F: '{ print $1 }')
- DEVICE=$(echo $1 | awk -F: '{ print $2 }')
- DEVICE_ID=$(echo $1 | awk -F: '{ print $3 }')
- DEVICE_NAME=$(echo $1 | awk -F: '{ print $4 }')
-}
-
-# following user input to create xml config file
-create_config()
-{
- local mds_name
- local config_file=$1
-
- for mds in $MDS_LIST ; do
- get_name_in_list $mds
- echo -n " $DEVICE_NAME"
- add_node "$HOST_NAME" "$config_file" || return 1
- $LMC -m "$config_file" --add mds --node "$HOST_NAME" \
- --mds "$DEVICE_NAME" \
- --nid "$HOST_NAME" --fstype "$DEFAULT_FSTYPE" \
- --dev "$DEVICE" || return 1
-
- mds_name="$DEVICE_NAME"
- done
-
- #add lov information FIXME --stripe_sz and
- #--stripe_cnt should be input by user
- echo -n " lov1"
- $LMC -m "$config_file" --add lov --lov lov1 --mds "$mds_name" \
- --stripe_sz "$STRIPE_SIZE" --stripe_cnt "$STRIPE_CNT" \
- --stripe_pattern "$STRIPE_PATTERN" || return 1
-
- for ost in $OST_LIST ; do
- get_name_in_list $ost
- echo -n " $DEVICE_NAME"
- add_node "$HOST_NAME" "$config_file" || return 1
- $LMC -m "$config_file" --add ost --node "$HOST_NAME" \
- --ost "$DEVICE_NAME" \
- --lov lov1 --fstype "$DEFAULT_FSTYPE" \
- --dev "$DEVICE" || return 1
- done
-
- for client in $CLIENT_LIST ; do
- get_name_in_list $client
- echo -n " $DEVICE_NAME"
- add_node "client" "$config_file" || return 1
- $LMC -m "$config_file" --add mtpt --nod client \
- --mds "$mds_name" --lov lov1 --path "$DEVICE" || return 1
- done
- echo
- return 0
-}
-
-#parse options
-get_option "$@"
-
-#some default definitions
-LMC=${LMC:-"/usr/sbin/lmc"}
-CONFIG_FILE=${CONFIG_FILE:-"config.xml"}
-TMP_CONFIG_FILE=${TMP_CONFIG_FILE:-".config.xml.tmp"}
-DEFAULT_FSTYPE=${DEFAULT_FSTYPE:-"ext3"}
-DEFAULT_NETTYPE=${DEFAULT_NETTYPE:-"tcp"}
-DEFAULT_MNTPT=${DEFAULT_MNTPT:-"/mnt/lustre"}
-STRIPE_SIZE=${STRIPE_SIZE:-65536}
-STRIPE_CNT=${STRIPE_CNT:-1}
-STRIPE_PATTERN=${STRIPE_PATTERN:-0}
-ANSWER="yes no"
-
-#print program information
-cat <<EOF
-This script will help you create a Lustre configuration file.
-
-EOF
-
-#add mds to lustre
-unset $MDS_LIST
-add_mds || fatal 1 "Cannot add mds to your lustre"
-
-#add ost to lustre
-unset $OST_LIST
-add_ost || fatal 1 "Cannot add ost to your lustre"
-
-#add client to lustre
-unset $CLIENT_LIST
-add_client || fatal 1 "Cannot add client to your lustre"
-
-rm -f "$TMP_CONFIG_FILE"
-echo -n "Saving configuration to $CONFIG_FILE:"
-create_config "$TMP_CONFIG_FILE" || \
- fatal 1 "There was an error saving the config file."
-mv -f "$TMP_CONFIG_FILE" "$CONFIG_FILE" || \
- fatal 1 "There was an error saving the config file."
-
-cat <<EOF
-
-Your configuration has been saved to $CONFIG_FILE.
-EOF
-exit 0