aboutsummaryrefslogtreecommitdiff
path: root/contrib/amd/scripts/test-attrcache.in
blob: 061308b42dbebcbd9b81869785b817ce5b3defe6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/sh
# Script to test the attribute cache behavior of the local OS client.
# If this script fails, it means that Amd cannot turn off the attrcache
# reliably on this host, and Amd therefore may not run reliably.  See
# the README.attrcache file distributed with this am-utils.
#	-Erez Zadok, September 29, 2005

# set PATH (must install am-utils first)
prefix=@prefix@
exec_prefix=@exec_prefix@
PATH=@sbindir@:@bindir@:/usr/ucb:/usr/bin:/bin:${PATH}
export PATH

# test if amd is running
amq -p > /dev/null 2>&1
if test $? = 0
then
	echo "### Amd already running... please shutdown Amd first"
	exit 1
fi

mapfile="/tmp/amd.testmap.$$"
logfile="/var/log/amd"
delay=1
a=/a

CreateMap1 () {
	echo "### Creating correct map"
	cat - >$mapfile <<EOF
a	type:=link;fs:=/tmp/a
EOF
}

CreateMap2 () {
	echo "### Creating weird map"
	cat - >$mapfile <<EOF
a	type:=link;fs:=/tmp/b
EOF
}

StopAMD () {
	ctl-amd stop
# do not delete files we may need to use to debug Amd
#	rm -f /tmp/a /tmp/b $mapfile $logfile
}

touch /tmp/a
touch /tmp/b

CreateMap1
echo amd -x all -D all -r -l $logfile $a $mapfile -cache:=mapdefault,sync
amd -x all -D all -r -l $logfile $a $mapfile -cache:=mapdefault,sync
sleep 3				# give amd chance to start properly
amq
inode_a=`ls -lLi /tmp/a | awk '{print $1}'`
inode_b=`ls -lLi /tmp/b | awk '{print $1}'`
ls -lLi $a/a
ls -lLi $a/b
ls -l $mapfile

# how many times to try until we call it a success...
maxtry=10
while test $maxtry -gt 0
do
	echo "$maxtry tries left ..."
	let maxtry=maxtry-1
	amq
	CreateMap1
	sleep $delay

	ls -l $mapfile
	echo "### looking at a... should get a"
	ino=`ls -lLi $a/a | awk '{print $1}'`
	if test -z "$ino"
	then
		ls -li $a/a
		amq
		amq -m
		stat $a
		echo "a link does not exist!"
		StopAMD
		exit 1
	fi
	if test $ino -ne $inode_a
	then
		ls -li $a/a
		amq
		amq -m
		stat $a
		echo "a link does not point to A!"
		StopAMD
		exit 1
	fi

# Here is the main trick we try: force amd to flush one entry, then
# change the amd map on disk, and then see if the kernel will have
# flushed the attribute cache; if it did, then Amd will see the
# correctly changed map entry.

	amq -u $a/a
	sleep $delay
	stat $a

	CreateMap2
	sleep $delay

	ls -l $mapfile
	echo "### looking at a... should get b"
	ino=`ls -lLi $a/a | awk '{print $1}'`
	if test -z "$ino"
	then
		ls -li $a/a
		amq
		amq -m
		stat $a
		echo "a link does not exist!"
		StopAMD
		exit 1
	fi
	if test $ino -ne $inode_b
	then
		ls -li $a/a
		amq
		amq -m
		stat $a
		echo "a link does not point to B!"
		StopAMD
		exit 1
	fi

	amq -u $a/a
	sleep $delay
	stat $a
done
StopAMD