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" \
261 # get hostname, device , device_id and device name
265 HOST_NAME=$(echo $1 | awk -F: '{ print $1 }')
266 DEVICE=$(echo $1 | awk -F: '{ print $2 }')
267 DEVICE_ID=$(echo $1 | awk -F: '{ print $3 }')
268 DEVICE_NAME=$(echo $1 | awk -F: '{ print $4 }')
269 DEVICE_MDS=$(echo $1 | awk -F: '{ print $5 }')
270 DEVICE_LOV=$(echo $1 | awk -F: '{ print $6 }')
271 DEVICE_SIZE=$(echo $1 | awk -F: '{ print $7 }')
274 # save command to file and do the command
277 echo "$@" >> "$LMC_BATCH_FILE"
280 # following user input to create xml config file
283 for device in $DEVICE_LIST ; do
284 get_name_in_list $device
285 echo -n " $DEVICE_NAME"
288 add_node "$HOST_NAME"
290 --node "$HOST_NAME" \
291 --mds "$DEVICE_NAME" \
292 --fstype "$DEFAULT_FSTYPE" \
294 --size "$DEVICE_SIZE"
298 --lov "$DEVICE_NAME" \
299 --mds "$DEVICE_MDS" \
300 --stripe_sz "$STRIPE_SIZE" \
301 --stripe_cnt "$STRIPE_CNT" \
302 --stripe_pattern "$STRIPE_PATTERN"
305 add_node "$HOST_NAME"
307 --node "$HOST_NAME" \
308 --lov "$DEVICE_LOV" \
309 --fstype "$DEFAULT_FSTYPE" \
311 --size "$DEVICE_SIZE"
314 add_node "$DEVICE_NAME"
316 --node "$DEVICE_NAME" \
317 --mds "$DEVICE_MDS" \
318 --lov "$DEVICE_LOV" \
329 [ -f "$1" ] || return 0
330 if ! (( $FORCE )) ; then
331 echo -n "${0##*/}: overwrite existing $2 \"$1\"? "
333 if ! [ "${answer:0:1}" = "y" -o "${answer:0:1}" = "Y" ] ; then
334 echo "(${0##*/}: (Exiting.)"
344 # some default definitions
345 LMC=${LMC:-"/usr/sbin/lmc"}
347 CONFIG_FILE=${CONFIG_FILE:-"lwizard.xml"}
349 # Remove exiting files.
351 maybe_clean "$CONFIG_FILE" "Lustre configuration file"
352 if [ "$LMC_BATCH_FILE" ] ; then
353 maybe_clean "$LMC_BATCH_FILE" "lmc batch file"
355 LMC_BATCH_FILE=$(mktemp -q "/tmp/${CONFIG_FILE##*/}.XXXXXX")
356 [ $? -eq 0 ] || fatal 1 "Couldn't create temporary batch file."
359 DEFAULT_FSTYPE=${DEFAULT_FSTYPE:-"ext3"}
360 DEFAULT_NETTYPE=${DEFAULT_NETTYPE:-"tcp"}
361 DEFAULT_MNTPT=${DEFAULT_MNTPT:-"/mnt/lustre"}
363 STRIPE_SIZE=${STRIPE_SIZE:-$((1 * 1024 * 1024))}
364 STRIPE_CNT=${STRIPE_CNT:-1}
365 STRIPE_PATTERN=${STRIPE_PATTERN:-0}
374 # print program information
376 ${0##*/} will help you create a Lustre configuration file.
385 $LMC --batch "$LMC_BATCH_FILE" -o "$CONFIG_FILE"
386 if [ $? -ne 0 ] ; then
387 fatal 1 "lmc returned an error; Please check above for more details."
390 echo "The Lustre configuration has been written to $CONFIG_FILE."
392 if (( $RM_BATCH_FILE )) ; then
393 rm -f "$LMC_BATCH_FILE"
395 echo "The lmc batch file has been written to $LMC_BATCH_FILE."