Whamcloud - gitweb
LU-10657 utils: fd leak in mirror_split()
[fs/lustre-release.git] / lustre / tests / lockorder.sh
1 #!/bin/sh
2 set -e
3
4 export PATH=`dirname $0`:`dirname $0`/../utils:$PATH
5 CREATEMANY=${CREATEMANY:-createmany}
6 STATMANY=${STATMANY:-statmany}
7 UNLINKMANY=${UNLINKMANY:-unlinkmany}
8 LCTL=${LCTL:-lctl}
9
10 MOUNT=${MOUNT:-/mnt/lustre}
11 MOUNT2=${MOUNT2:-/mnt/lustre2}
12 DIR=${DIR:-$MOUNT}
13 DIR2=${DIR2:-$MOUNT2}
14 COUNT=${COUNT:-100}
15
16 cleanup() {
17         [ $CR_PID ] && kill -9 $CR_PID
18         [ $ST_PID ] && kill -9 $ST_PID
19 }
20
21 trap cleanup EXIT
22
23 LOCKDIR=$DIR/lockdir
24 LOCKFILE=$LOCKDIR/lockfile
25 rm -rf $LOCKDIR
26
27 NUM=0
28
29 MINDIR=$DIR
30 MAXDIR=$DIR
31 MINRES=4294967295
32 MAXRES=0
33 mkdir -p $MINDIR
34 while [ $MINRES -gt $MAXRES ]; do
35         FILETMP=$MINDIR/f$$${NUM}
36         DIRTMP=$DIR/d$$/d${NUM}
37         touch $FILETMP
38         mkdir -p $DIRTMP
39         FILERES=`ls -id $FILETMP | awk '{ print $1 }'`
40         DIRRES=`ls -id $DIRTMP | awk '{ print $1 }'`
41         if [ $DIRRES -gt $MAXRES ]; then
42                 MAXDIR=$DIRTMP
43                 MAXRES=$DIRRES
44         fi
45         if [ $FILERES -lt $MINRES -o -z "$MINFILE" ]; then
46                 [ -f "$MINFILE" ] && rm $MINFILE
47                 MINFILE=$FILETMP
48                 MINRES=$FILERES
49         else
50                 rm $FILETMP
51         fi
52         NUM=$(($NUM + 1))
53 done
54
55 mv $MAXDIR $LOCKDIR
56 mv $MINFILE $LOCKFILE
57 rm -rf $DIR/d$$
58
59 $LCTL mark "start dir: $LOCKDIR=$MAXRES file: $LOCKFILE=$MINRES"
60 # link will lock $LOCKFILE and $DIR as it creates ${LOCKFILE}{0,1,...}
61 $CREATEMANY -l$LOCKFILE $LOCKFILE -$COUNT &
62 CR_PID=$!
63
64 while ! test -f ${LOCKFILE}1 ; do
65         sleep 1
66 done
67
68 # this will lock $DIR and ${LOCKFILE}0
69 $STATMANY -s $DIR2/lockdir/lockfile 1 -$COUNT &
70 ST_PID=$!
71
72 sleep $(($COUNT / 2))
73
74 $UNLINKMANY $DIR2/lockdir/lockfile 1 $(($COUNT * 1000)) || true
75
76 trap 0
77 kill $CR_PID || true
78 kill $ST_PID || true
79
80 rm -rf $LOCKDIR