Whamcloud - gitweb
78d68e5edb85d9c80663922fe64f96ec40ef2059
[fs/lustre-release.git] / lustre / tests / racer / file_create.sh
1 #!/bin/bash
2 trap 'kill $(jobs -p)' EXIT
3 RACER_ENABLE_PFL=${RACER_ENABLE_PFL:-true}
4 RACER_ENABLE_DOM=${RACER_ENABLE_DOM:-true}
5 RACER_ENABLE_FLR=${RACER_ENABLE_FLR:-true}
6 RACER_ENABLE_SEL=${RACER_ENABLE_SEL:-true}
7 RACER_EXTRA_LAYOUT=${RACER_EXTRA_LAYOUT:-""}
8 DIR=$1
9 MAX=$2
10 MAX_MB=${RACER_MAX_MB:-8}
11
12 layout=(raid0 raid0)
13
14 # check if it supports PFL layout
15 $RACER_ENABLE_PFL && layout+=(pfl pfl pfl)
16
17 # check if it supports DoM
18 $RACER_ENABLE_DOM && layout+=(dom dom dom)
19
20 # check if it supports FLR
21 $RACER_ENABLE_FLR && layout+=(flr flr flr)
22
23 # check if it supports PFL layout
24 $RACER_ENABLE_SEL && layout+=(sel sel sel)
25 [[ -n "$RACER_EXTRA_LAYOUT" ]] && layout+=(extra extra extra)
26
27 echo "layout: ${layout[*]}"
28
29 while /bin/true; do
30         file=$((RANDOM % MAX))
31         # $RANDOM is between 0 and 32767, and we want $blockcount in 64kB units
32         blockcount=$((RANDOM * MAX_MB / 32 / 64))
33         stripecount=$((RANDOM % (OSTCOUNT + 1)))
34
35         [ $stripecount -gt 0 ] && {
36                 stripesize=$(((1 << (RANDOM % 5)) * 64))K
37                 comp_end=$((${stripesize%K} * (RANDOM % 8 + 1)))K
38                 pattern=${layout[$RANDOM % ${#layout[*]}]}
39
40                 case $pattern in
41                 dom) opt="setstripe -E $stripesize -L mdt -E eof -c $stripecount -S 1M" ;;
42                 pfl) opt="setstripe -E $comp_end -S $stripesize -E eof -c $stripecount -S 2M" ;;
43                 flr) opt="mirror create -N2 -E $comp_end -S $stripesize -E eof -c $stripecount -S 2M" ;;
44                 sel) opt="setstripe -E 128M -S $stripesize -z 64M -E eof -c $stripecount -S 2M -z 128M" ;;
45                 raid0) opt="setstripe -S $stripesize -c $stripecount" ;;
46                 extra) opt="setstripe $RACER_EXTRA_LAYOUT" ;;
47                 esac
48
49                 $LFS $opt $DIR/$file 2> /dev/null || true
50         }
51
52         # offset between 0 and 16MB (256 64k chunks), with 1/2 at offset 0
53         seek=$((RANDOM / 64)); [ $seek -gt 256 ] && seek=0
54         dd if=/dev/zero of=$DIR/$file bs=64k count=$blockcount \
55                 seek=$seek 2> /dev/null || true
56 done
57