2 # Copyright (C) 2003 Cluster File Systems, Inc.
3 # Create a Lustre configuration file
7 # Jerrifer <jerrifer@clusterfs.com>
8 # wangdi <wangdi@clusterfs.com>
13 if [ "$#" -gt "1" ]; then
26 Usage: ${0##*/} [OPTIONS]...
28 ${0##*/} asks the user questions about their cluster configuration,
29 and writes an appropriate configuration file to config.xml.
33 save lmc batch commands to FILE
35 write Lustre configuration to FILE (default: lwizard.xml)
37 force existing files to be overwritten
41 size (in KB) of each stripe on an OST (default: 64)
43 the number of OSTs files are striped to (default: 1)
49 # check if $1 is a number
52 local num=$(expr "$1" : "[0-9]*$")
53 if [ $num -gt "0" ]; then
60 # parse options of this shell
66 local long_options="batch:,file:,force:,help,stripe_size:,stripe_count:"
69 options=$(getopt -o o:hf --long "$long_options" -- "$@")
71 if [ $? -ne 0 ] ; then
74 eval set -- "$options"
93 check_number $STRIPE_CNT || \
94 fatal 1 "Stripe count should be a number."
98 STRIPE_SIZE=$(($2 * 1024))
99 check_number $STRIPE_SIZE || \
100 fatal 1 "Stripe size should be a number."
119 [ "$1" = "$node" ] && return 0
124 # read device size from user and check devive size and convert device
133 if [ -z $size ]; then
138 device_size=$(echo $size | awk -F[a-z,A-Z] '{print $1; }')
139 [ -z $device_size ] && return 1
140 tail=$(echo $size | awk -F$device_size '{print $2; }')
141 [ -z $tail ] && return 0
146 (( device_size *= 1024 ))
149 (( device_size *= (1024 * 1024) ))
159 # ask user some questions to add a device
166 echo "Creating $1 \"$1$2\"..."
167 if [ "$2" -gt "1" ]; then
168 echo -n "Please enter the hostname(s) for $1$2, or just hit enter to finish: "
170 echo -n "Please enter the hostname(s) for $1$2: "
174 if [ -z "$hostnames" ] ; then
178 for hostname in $hostnames ; do
180 while [ -z "$device" ] ; do
181 echo -n "Please enter the device or loop file name for $1$2 on ${hostname}: "
183 echo -n "Please enter the device size or 0 to use entire device: "
184 while ! get_device_size ; do
185 echo -n "Please enter the device size or 0 to use entire device: "
188 newdev="$hostname:$device:$2:$1$2:$CURRENT_MDS:$CURRENT_LOV:$device_size"
189 DEVICE_LIST="$DEVICE_LIST $newdev"
197 # get mds information
202 add_device "mds" "$cur_mds_id" || return 1
203 CURRENT_LOV="lov$cur_mds_id"
204 CURRENT_MDS="mds$cur_mds_id"
206 DEVICE_LIST="$DEVICE_LIST *:*:lov:$CURRENT_LOV:$CURRENT_MDS:*:"
214 # ask user to add ost
217 # We have to add one...
218 while ! add_device "ost" "$cur_ost_id" ; do
225 while add_device "ost" "$cur_ost_id" ; do
233 # ask user to add client to lustre
236 echo -n "Please enter the clients' mountpoint (/mnt/lustre): "
238 [ -z "$mtpt" ] && mtpt="/mnt/lustre"
239 newdev="*:$mtpt:client:client:$CURRENT_MDS:$CURRENT_LOV"
240 DEVICE_LIST="$DEVICE_LIST $newdev"
245 # save node config into config file
249 local nettype=$DEFAULT_NETTYPE
251 in_list "$node" "$NODE_LIST" && return 0
252 NODE_LIST="$NODE_LIST $node"
254 run_lmc --add node --node "$node"
255 run_lmc --add net --node "$node" --nid "$node" \
260 # save client node config into config file
264 local nettype=$DEFAULT_NETTYPE
266 in_list "$node" "$NODE_LIST" && return 0
267 NODE_LIST="$NODE_LIST $node"
269 run_lmc --add node --node "$node"
270 run_lmc --add net --node "$node" --nid "*" \
276 # get hostname, device , device_id and device name
280 HOST_NAME=$(echo $1 | awk -F: '{ print $1 }')
281 DEVICE=$(echo $1 | awk -F: '{ print $2 }')
282 DEVICE_ID=$(echo $1 | awk -F: '{ print $3 }')
283 DEVICE_NAME=$(echo $1 | awk -F: '{ print $4 }')
284 DEVICE_MDS=$(echo $1 | awk -F: '{ print $5 }')
285 DEVICE_LOV=$(echo $1 | awk -F: '{ print $6 }')
286 DEVICE_SIZE=$(echo $1 | awk -F: '{ print $7 }')
289 # save command to file and do the command
292 echo "$@" >> "$LMC_BATCH_FILE"
295 # following user input to create xml config file
298 for device in $DEVICE_LIST ; do
299 get_name_in_list $device
300 echo -n " $DEVICE_NAME"
303 add_client_node "$DEVICE_NAME"
305 --node "$HOST_NAME" \
306 --mds "$DEVICE_NAME" \
307 --fstype "$DEFAULT_FSTYPE" \
309 --size "$DEVICE_SIZE"
313 --lov "$DEVICE_NAME" \
314 --mds "$DEVICE_MDS" \
315 --stripe_sz "$STRIPE_SIZE" \
316 --stripe_cnt "$STRIPE_CNT" \
317 --stripe_pattern "$STRIPE_PATTERN"
320 add_node "$HOST_NAME"
322 --node "$HOST_NAME" \
323 --lov "$DEVICE_LOV" \
324 --fstype "$DEFAULT_FSTYPE" \
326 --size "$DEVICE_SIZE"
329 add_node "$DEVICE_NAME"
331 --node "$DEVICE_NAME" \
332 --mds "$DEVICE_MDS" \
333 --lov "$DEVICE_LOV" \
344 [ -f "$1" ] || return 0
345 if ! (( $FORCE )) ; then
346 echo -n "${0##*/}: overwrite existing $2 \"$1\"? "
348 if ! [ "${answer:0:1}" = "y" -o "${answer:0:1}" = "Y" ] ; then
349 echo "(${0##*/}: (Exiting.)"
359 # some default definitions
360 LMC=${LMC:-"/usr/sbin/lmc"}
362 CONFIG_FILE=${CONFIG_FILE:-"lwizard.xml"}
364 # Remove exiting files.
366 maybe_clean "$CONFIG_FILE" "Lustre configuration file"
367 if [ "$LMC_BATCH_FILE" ] ; then
368 maybe_clean "$LMC_BATCH_FILE" "lmc batch file"
370 LMC_BATCH_FILE=$(mktemp -q "/tmp/${CONFIG_FILE##*/}.XXXXXX")
371 [ $? -eq 0 ] || fatal 1 "Couldn't create temporary batch file."
374 DEFAULT_FSTYPE=${DEFAULT_FSTYPE:-"ext3"}
375 DEFAULT_NETTYPE=${DEFAULT_NETTYPE:-"tcp"}
376 DEFAULT_MNTPT=${DEFAULT_MNTPT:-"/mnt/lustre"}
378 STRIPE_SIZE=${STRIPE_SIZE:-$((1 * 1024 * 1024))}
379 STRIPE_CNT=${STRIPE_CNT:-1}
380 STRIPE_PATTERN=${STRIPE_PATTERN:-0}
389 # print program information
391 ${0##*/} will help you create a Lustre configuration file.
400 $LMC --batch "$LMC_BATCH_FILE" -o "$CONFIG_FILE"
401 if [ $? -ne 0 ] ; then
402 fatal 1 "lmc returned an error; Please check above for more details."
405 echo "The Lustre configuration has been written to $CONFIG_FILE."
407 if (( $RM_BATCH_FILE )) ; then
408 rm -f "$LMC_BATCH_FILE"
410 echo "The lmc batch file has been written to $LMC_BATCH_FILE."