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)
9prefix=@prefix@
10exec_prefix=@exec_prefix@
11PATH=@sbindir@:@bindir@:/usr/ucb:/usr/bin:/bin:${PATH}
12export PATH
13
14# test if amd is running
15amq -p > /dev/null 2>&1
16if test $? = 0
17then
18	echo "### Amd already running... please shutdown Amd first"
19	exit 1
20fi
21
22mapfile="/tmp/amd.testmap.$$"
23logfile="/var/log/amd"
24delay=1
25a=/a
26
27CreateMap1 () {
28	echo "### Creating correct map"
29	cat - >$mapfile <<EOF
30a	type:=link;fs:=/tmp/a
31EOF
32}
33
34CreateMap2 () {
35	echo "### Creating weird map"
36	cat - >$mapfile <<EOF
37a	type:=link;fs:=/tmp/b
38EOF
39}
40
41StopAMD () {
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
47touch /tmp/a
48touch /tmp/b
49
50CreateMap1
51echo amd -x all -D all -r -l $logfile $a $mapfile -cache:=mapdefault,sync
52amd -x all -D all -r -l $logfile $a $mapfile -cache:=mapdefault,sync
53sleep 3				# give amd chance to start properly
54amq
55inode_a=`ls -lLi /tmp/a | awk '{print $1}'`
56inode_b=`ls -lLi /tmp/b | awk '{print $1}'`
57ls -lLi $a/a
58ls -lLi $a/b
59ls -l $mapfile
60
61# how many times to try until we call it a success...
62maxtry=10
63while test $maxtry -gt 0
64do
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
134done
135StopAMD
136