Whamcloud - gitweb
New tag 2.15.63
[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_ENABLE_OVERSTRIPE=${RACER_ENABLE_OVERSTRIPE:-true}
8 RACER_LOV_MAX_STRIPECOUNT=${RACER_LOV_MAX_STRIPECOUNT:-$LOV_MAX_STRIPE_COUNT}
9 RACER_EXTRA_LAYOUT=${RACER_EXTRA_LAYOUT:-""}
10 DIR=$1
11 MAX=$2
12 MAX_MB=${RACER_MAX_MB:-8}
13
14 layout=(raid0 raid0)
15
16 # check if it supports PFL layout
17 $RACER_ENABLE_PFL && layout+=(pfl pfl pfl)
18
19 # check if it supports DoM
20 $RACER_ENABLE_DOM && layout+=(dom dom dom)
21
22 # check if it supports FLR
23 $RACER_ENABLE_FLR && layout+=(flr flr flr)
24
25 # check if it supports PFL layout
26 $RACER_ENABLE_SEL && layout+=(sel sel sel)
27 [[ -n "$RACER_EXTRA_LAYOUT" ]] && layout+=(extra extra extra)
28
29 echo "layout: ${layout[*]}"
30
31 while /bin/true; do
32         file=$((RANDOM % MAX))
33         (( RANDOM % 100 < 25 )) && file+="/$((RANDOM % MAX))"
34         # $RANDOM is between 0 and 32767, and we want $blockcount in 64kB units
35         blockcount=$((RANDOM * MAX_MB / 32 / 64))
36         $RACER_ENABLE_OVERSTRIPE &&
37                 stripecount="-C $((RANDOM %
38                         (RACER_LOV_MAX_STRIPECOUNT +  1)))" ||
39                 stripecount="-c $((RANDOM % (OSTCOUNT + 1)))"
40
41         [ ${stripecount:2} -gt 0 ] && {
42                 stripesize=$(((1 << (RANDOM % 5)) * 64))K
43                 comp_end=$((${stripesize%K} * (RANDOM % 8 + 1)))K
44                 pattern=${layout[$RANDOM % ${#layout[*]}]}
45
46                 case $pattern in
47                 dom) opt="setstripe -E $stripesize -L mdt -E eof $stripecount -S 1M" ;;
48                 pfl) opt="setstripe -E $comp_end -S $stripesize -E eof $stripecount -S 2M" ;;
49                 flr) opt="mirror create -N2 -E $comp_end -S $stripesize -E eof $stripecount -S 2M" ;;
50                 sel) opt="setstripe -E 128M -S $stripesize -z 64M -E eof $stripecount -S 2M -z 128M" ;;
51                 raid0) opt="setstripe -S $stripesize $stripecount" ;;
52                 extra) opt="setstripe $RACER_EXTRA_LAYOUT" ;;
53                 esac
54
55                 if $RACER_ENABLE_FILE_MIGRATE && (( RANDOM % 20 == 0 )); then
56                         if [ "$pattern" = "flr" ]; then
57                                 opt=${opt/create/extend}
58                         else
59                                 opt=${opt/setstripe/migrate}
60                                 (( file % 8 == 0 )) && opt+=" --block"
61                         fi
62                 fi
63                 $LFS $opt $DIR/$file 2> /dev/null || true
64         }
65
66         # offset between 0 and 16MB (256 64k chunks), with 1/2 at offset 0
67         seek=$((RANDOM / 64)); [ $seek -gt 256 ] && seek=0
68         dd if=/dev/zero of=$DIR/$file bs=64k count=$blockcount \
69                 seek=$seek 2> /dev/null || true
70 done
71