]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - contrib/amd/scripts/test-attrcache.in
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / contrib / amd / scripts / test-attrcache.in
1 #!/bin/sh
2 # Script to test the attribute cache behavior of the local OS client.
3 # If this script fails, it means that Amd cannot turn off the attrcache
4 # reliably on this host, and Amd therefore may not run reliably.  See
5 # the README.attrcache file distributed with this am-utils.
6 #       -Erez Zadok, September 29, 2005
7
8 # set PATH (must install am-utils first)
9 prefix=@prefix@
10 exec_prefix=@exec_prefix@
11 PATH=@sbindir@:@bindir@:/usr/ucb:/usr/bin:/bin:${PATH}
12 export PATH
13
14 # test if amd is running
15 amq -p > /dev/null 2>&1
16 if test $? = 0
17 then
18         echo "### Amd already running... please shutdown Amd first"
19         exit 1
20 fi
21
22 mapfile="/tmp/amd.testmap.$$"
23 logfile="/var/log/amd"
24 delay=1
25 a=/a
26
27 CreateMap1 () {
28         echo "### Creating correct map"
29         cat - >$mapfile <<EOF
30 a       type:=link;fs:=/tmp/a
31 EOF
32 }
33
34 CreateMap2 () {
35         echo "### Creating weird map"
36         cat - >$mapfile <<EOF
37 a       type:=link;fs:=/tmp/b
38 EOF
39 }
40
41 StopAMD () {
42         ctl-amd stop
43 # do not delete files we may need to use to debug Amd
44 #       rm -f /tmp/a /tmp/b $mapfile $logfile
45 }
46
47 touch /tmp/a
48 touch /tmp/b
49
50 CreateMap1
51 echo amd -x all -D all -r -l $logfile $a $mapfile -cache:=mapdefault,sync
52 amd -x all -D all -r -l $logfile $a $mapfile -cache:=mapdefault,sync
53 sleep 3                         # give amd chance to start properly
54 amq
55 inode_a=`ls -lLi /tmp/a | awk '{print $1}'`
56 inode_b=`ls -lLi /tmp/b | awk '{print $1}'`
57 ls -lLi $a/a
58 ls -lLi $a/b
59 ls -l $mapfile
60
61 # how many times to try until we call it a success...
62 maxtry=10
63 while test $maxtry -gt 0
64 do
65         echo "$maxtry tries left ..."
66         let maxtry=maxtry-1
67         amq
68         CreateMap1
69         sleep $delay
70
71         ls -l $mapfile
72         echo "### looking at a... should get a"
73         ino=`ls -lLi $a/a | awk '{print $1}'`
74         if test -z "$ino"
75         then
76                 ls -li $a/a
77                 amq
78                 amq -m
79                 stat $a
80                 echo "a link does not exist!"
81                 StopAMD
82                 exit 1
83         fi
84         if test $ino -ne $inode_a
85         then
86                 ls -li $a/a
87                 amq
88                 amq -m
89                 stat $a
90                 echo "a link does not point to A!"
91                 StopAMD
92                 exit 1
93         fi
94
95 # Here is the main trick we try: force amd to flush one entry, then
96 # change the amd map on disk, and then see if the kernel will have
97 # flushed the attribute cache; if it did, then Amd will see the
98 # correctly changed map entry.
99
100         amq -u $a/a
101         sleep $delay
102         stat $a
103
104         CreateMap2
105         sleep $delay
106
107         ls -l $mapfile
108         echo "### looking at a... should get b"
109         ino=`ls -lLi $a/a | awk '{print $1}'`
110         if test -z "$ino"
111         then
112                 ls -li $a/a
113                 amq
114                 amq -m
115                 stat $a
116                 echo "a link does not exist!"
117                 StopAMD
118                 exit 1
119         fi
120         if test $ino -ne $inode_b
121         then
122                 ls -li $a/a
123                 amq
124                 amq -m
125                 stat $a
126                 echo "a link does not point to B!"
127                 StopAMD
128                 exit 1
129         fi
130
131         amq -u $a/a
132         sleep $delay
133         stat $a
134 done
135 StopAMD