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