Xenstore: implement watching of nodes which don't exist.
PATCH 11/11 Xenstore: implement watching of nodes which don't exist.
# HG changeset patch
# User Rusty Russell <[email protected]>
# Node ID 8899a3f0bc41e03c8346f67de142a8c87df6a95b
# Parent 92fd066729d9656628b4221da64139cedab63f91
Xenstore: implement watching of nodes which don't exist.
Requires permission check every time event is generated.
Requires generalization of permissions: ask arbitrary number of parents whether it's OK to tell about node (eg. watching /dir/subdir/x when /dir is deleted: root permissions will now determine whether we fire event). Add test that we don't leak information on whether a file exists or not.
tools/xenstore/Makefile +18 -4
@@ -69,10 +69,21 @@ rm -f xs_test xenstored_test xs_dom0_test -$(RM) $(PROG_DEP) -check: testsuite-run randomcheck stresstest +print-dir: + @echo -n tools/xenstore: + +print-end: + @echo + +check: print-dir testsuite-fast randomcheck-fast print-end + +fullcheck: testsuite-run randomcheck stresstest testsuite-run: xen xenstored_test xs_test - $(TESTENV) testsuite/test.sh + $(TESTENV) testsuite/test.sh && echo + +testsuite-fast: xen xenstored_test xs_test + @$(TESTENV) testsuite/test.sh --fast testsuite-clean: rm -rf $(TESTDIR)
@@ -81,9 +92,12 @@ # fail. RANDSEED=$(shell date +%s) randomcheck: xs_random xenstored_test - $(TESTENV) ./xs_random --simple --fast /tmp/xs_random 200000 $(RANDSEED) - $(TESTENV) ./xs_random --fast /tmp/xs_random 100000 $(RANDSEED) + $(TESTENV) ./xs_random --simple --fast /tmp/xs_random 200000 $(RANDSEED) && echo + $(TESTENV) ./xs_random --fast /tmp/xs_random 100000 $(RANDSEED) && echo $(TESTENV) ./xs_random --fail /tmp/xs_random 10000 $(RANDSEED) + +randomcheck-fast: xs_random xenstored_test + @$(TESTENV) ./xs_random --fast /tmp/xs_random 10000 $(RANDSEED) stresstest: xs_stress xenstored_test rm -rf $(TESTDIR)/store $(TESTDIR)/transactions
tools/xenstore/testsuite/test.sh +25 -7
@@ -7,16 +7,16 @@ { rm -rf $XENSTORED_ROOTDIR mkdir $XENSTORED_ROOTDIR -# Weird failures with this. - if type valgrind >/dev/null 2>&1; then + if [ $VALGRIND -eq 1 ]; then valgrind -q --logfile-fd=3 ./xenstored_test --output-pid --no-fork 3>testsuite/tmp/vgout > /tmp/pid 2> testsuite/tmp/xenstored_errors & while [ ! -s /tmp/pid ]; do sleep 0; done PID=`cat /tmp/pid` rm /tmp/pid else - PID=`./xenstored_test --output-pid` + # We don't get error messages from this, though. + PID=`./xenstored_test --output-pid --trace-file=testsuite/tmp/trace` fi - if sh -e $2 $1; then + if ./xs_test $2 $1; then if [ -s testsuite/tmp/vgout ]; then kill $PID echo VALGRIND errors:
@@ -33,9 +33,27 @@ fi } -for f in testsuite/[0-9]*.sh; do - if run_test $f; then - echo Test $f passed... +if [ x$1 = x--fast ]; then + VALGRIND=0 + SLOWTESTS="" + shift +else + if type valgrind >/dev/null 2>&1; then + VALGRIND=1 + else + echo "WARNING: valgrind not available" >&2 + VALGRIND=0 + fi + SLOWTESTS=testsuite/[0-9]*.slowtest +fi + +MATCH=${1:-"*"} +for f in testsuite/[0-9]*.test $SLOWTESTS; do + case `basename $f` in $MATCH) RUN=1;; esac + [ -n "$RUN" ] || continue + + if run_test $f > /dev/null; then + echo -n . else echo Test $f failed, running verbosely... run_test $f -x
tools/xenstore/xs_random.c +3 -13
@@ -1105,9 +1105,6 @@ data->ops->close (pre); } } -if (data->print_progress) -printf ("\n" ); - out: data->ops->close (h);return i;
@@ -1185,10 +1182,9 @@ try =try_simple (NULL , iters, verbose, &data);if (try == iters) {cleanup_xs_ops (); -printf ("Succeeded\n" );exit (0 ); } -printf ("Failed on iteration %u\n" , try +1 ); +printf ("Failed on iteration %u of seed %u\n" , try +1 , seed); data.print_progress = false;reduce_problem (try +1 , try_simple, &data); }
@@ -1399,8 +1395,6 @@talloc_free (fileh_pre); } } -if (data->print_progress) -printf ("\n" ); fail =NULL ;if (data->fast)
@@ -1428,10 +1422,9 @@ try =try_diff (NULL , iters, verbose, &data);if (try == iters) {cleanup_xs_ops (); -printf ("Succeeded\n" );exit (0 ); } -printf ("Failed on iteration %u\n" , try +1 ); +printf ("Failed on iteration %u of seed %u\n" , try +1 , seed); data.print_progress = false;reduce_problem (try +1 , try_diff, &data); }
@@ -1586,8 +1579,6 @@xs_close (tmpxsh);file_close (tmpfileh); } - -printf ("Total %u of %u not aborted\n" , tried - aborted, tried); out:if (xsh)xs_close (xsh);
@@ -1608,10 +1599,9 @@ try =try_fail (NULL , iters, verbose, &data);if (try == iters) {cleanup_xs_ops (); -printf ("Succeeded\n" );exit (0 ); } -printf ("Failed on iteration %u\n" , try +1 ); +printf ("Failed on iteration %u of seed %u\n" , try +1 , seed);fflush (stdout); data.print_progress = false;reduce_problem (try +1 , try_fail, &data);
tools/xenstore/xs_test.c +213 -59
439 lines not on this page · raw message
tools/xenstore/testsuite/01simple.test new file +4 -0
@@ -0,0 +1,4 @@ +# Create an entry, read it. +write /test create contents +expect contents +read /test
tools/xenstore/testsuite/02directory.test new file +34 -0
@@ -0,0 +1,34 @@ +# Root directory has only tool dir in it. +expect tool +dir / + +# Create a file. +write /test create contents + +# Directory shows it. +expect test +expect tool +dir / + +# Make a new directory, check it's there +mkdir /dir +expect dir +expect test +expect tool +dir / + +# Check it's empty. +dir /dir + +# Create a file, check it exists. +write /dir/test2 create contents2 +expect test2 +dir /dir +expect contents2 +read /dir/test2 + +# Creating dir over the top should fail. +expect mkdir failed: File exists +mkdir /dir +expect mkdir failed: File exists +mkdir /dir/test2
tools/xenstore/testsuite/03write.test new file +20 -0
@@ -0,0 +1,20 @@ +# Write without create fails. +expect write failed: No such file or directory +write /test none contents + +# Exclusive write succeeds +write /test excl contents +expect contents +read /test + +# Exclusive write fails to overwrite. +expect write failed: File exists +write /test excl contents + +# Non-exclusive overwrite succeeds. +write /test none contents2 +expect contents2 +read /test +write /test create contents3 +expect contents3 +read /test
tools/xenstore/testsuite/04rm.test new file +18 -0
@@ -0,0 +1,18 @@ +# Remove non-existant fails. +expect rm failed: No such file or directory +rm /test +expect rm failed: No such file or directory +rm /dir/test + +# Create file and remove it +write /test excl contents +rm /test + +# Create directory and remove it. +mkdir /dir +rm /dir + +# Create directory, create file, remove all. +mkdir /dir +write /dir/test excl contents +rm /dir
tools/xenstore/testsuite/05filepermissions.test new file +81 -0
81 lines not on this page · raw message
tools/xenstore/testsuite/06dirpermissions.test new file +119 -0
119 lines not on this page · raw message
tools/xenstore/testsuite/07watch.test new file +194 -0
194 lines not on this page · raw message
tools/xenstore/testsuite/08transaction.slowtest new file +21 -0
@@ -0,0 +1,21 @@ +# Test transaction timeouts. Take a second each. + +mkdir /test +write /test/entry1 create contents + +# Transactions can take as long as the want... +start /test +sleep 1100 +rm /test/entry1 +commit +dir /test + +# ... as long as noone is waiting. +1 start /test +notimeout +2 mkdir /test/dir +1 mkdir /test/dir +expect 1:dir +1 dir /test +expect 1: commit failed: Connection timed out +1 commit
tools/xenstore/testsuite/08transaction.test new file +96 -0
96 lines not on this page · raw message
tools/xenstore/testsuite/09domain.test new file +19 -0
@@ -0,0 +1,19 @@ +# Test domain communication. + +# Create a domain, write an entry. +expect handle is 1 +introduce 1 100 7 /my/home +1 write /entry1 create contents +expect entry1 +expect tool +dir / +close + +# Release that domain. +release 1 +close + +# Introduce and release by same connection. +expect handle is 2 +introduce 1 100 7 /my/home +release 1
tools/xenstore/testsuite/10domain-homedir.test new file +19 -0
@@ -0,0 +1,19 @@ +# Test domain "implicit" paths. + +# Create a domain, write an entry using implicit path, read using implicit +mkdir /home +expect handle is 1 +introduce 1 100 7 /home +1 write entry1 create contents +expect contents +read /home/entry1 +expect entry1 +dir /home + +# Place a watch using a relative path: expect relative answer. +1 mkdir foo +1 watch foo token +write /home/foo/bar create contents +expect 1:foo/bar:token +1 waitwatch +1 ackwatch token
tools/xenstore/testsuite/11domain-watch.test new file +52 -0
52 lines not on this page · raw message
tools/xenstore/testsuite/12readonly.test new file +41 -0
41 lines not on this page · raw message
tools/xenstore/testsuite/13watch-ack.test new file +22 -0
@@ -0,0 +1,22 @@ +# This demonstrates a bug where an xs_acknowledge_watch returns +# EINVAL, because the daemon doesn't track what watch event it sent +# and relies on it being the "first" watch which has an event. +# Watches firing after the first event is sent out will change this. + +# Create three things to watch. +mkdir /test +mkdir /test/1 +mkdir /test/2 +mkdir /test/3 + +# Watch all three, fire event on 2, read watch, fire event on 1 and 3, ack 2. +1 watch /test/1 token1 +1 watch /test/2 token2 +1 watch /test/3 token3 +2 write /test/2 create contents2 +expect 1:/test/2:token2 +1 waitwatch +3 write /test/1 create contents1 +4 write /test/3 create contents3 +1 ackwatch token2 +1 close
tools/xenstore/testsuite/14complexperms.test new file +99 -0
99 lines not on this page · raw message
tools/xenstore/testsuite/01simple.sh deleted +0 -4
@@ -1,4 +0,0 @@ -#! /bin/sh - -# Create an entry, read it. -[ "`echo -e 'write /test create contents\nread /test' | ./xs_test 2>&1`" = "contents" ]
tools/xenstore/testsuite/02directory.sh deleted +0 -32
@@ -1,32 +0,0 @@ -#! /bin/sh - -# Root directory has only tool dir in it. -[ "`echo -e 'dir /' | ./xs_test 2>&1`" = "tool" ] - -# Create a file. -[ "`echo -e 'write /test create contents' | ./xs_test 2>&1`" = "" ] - -# Directory shows it. -[ "`echo -e 'dir /' | ./xs_test 2>&1 | sort`" = "test -tool" ] - -# Make a new directory. -[ "`echo -e 'mkdir /dir' | ./xs_test 2>&1`" = "" ] - -# Check it's there. -DIR="`echo -e 'dir /' | ./xs_test 2>&1 | sort`" -[ "$DIR" = "dir -test -tool" ] - -# Check it's empty. -[ "`echo -e 'dir /dir' | ./xs_test 2>&1`" = "" ] - -# Create a file, check it exists. -[ "`echo -e 'write /dir/test2 create contents2' | ./xs_test 2>&1`" = "" ] -[ "`echo -e 'dir /dir' | ./xs_test 2>&1`" = "test2" ] -[ "`echo -e 'read /dir/test2' | ./xs_test 2>&1`" = "contents2" ] - -# Creating dir over the top should fail. -[ "`echo -e 'mkdir /dir' | ./xs_test 2>&1`" = "FATAL: mkdir: File exists" ] -[ "`echo -e 'mkdir /dir/test2' | ./xs_test 2>&1`" = "FATAL: mkdir: File exists" ]
tools/xenstore/testsuite/03write.sh deleted +0 -17
@@ -1,17 +0,0 @@ -#! /bin/sh - -# Write without create fails. -[ "`echo -e 'write /test none contents' | ./xs_test 2>&1`" = "FATAL: write: No such file or directory" ] - -# Exclusive write succeeds -[ "`echo -e 'write /test excl contents' | ./xs_test 2>&1`" = "" ] -[ "`echo -e 'read /test' | ./xs_test 2>&1`" = "contents" ] - -# Exclusive write fails to overwrite. -[ "`echo -e 'write /test excl contents' | ./xs_test 2>&1`" = "FATAL: write: File exists" ] - -# Non-exclusive overwrite succeeds. -[ "`echo -e 'write /test none contents2' | ./xs_test 2>&1`" = "" ] -[ "`echo -e 'read /test' | ./xs_test 2>&1`" = "contents2" ] -[ "`echo -e 'write /test create contents3' | ./xs_test 2>&1`" = "" ] -[ "`echo -e 'read /test' | ./xs_test 2>&1`" = "contents3" ]
tools/xenstore/testsuite/04rm.sh deleted +0 -18
@@ -1,18 +0,0 @@ -#! /bin/sh - -# Remove non-existant fails. -[ "`echo -e 'rm /test' | ./xs_test 2>&1`" = "FATAL: rm: No such file or directory" ] -[ "`echo -e 'rm /dir/test' | ./xs_test 2>&1`" = "FATAL: rm: No such file or directory" ] - -# Create file and remove it -[ "`echo -e 'write /test excl contents' | ./xs_test 2>&1`" = "" ] -[ "`echo -e 'rm /test' | ./xs_test 2>&1`" = "" ] - -# Create directory and remove it. -[ "`echo -e 'mkdir /dir' | ./xs_test 2>&1`" = "" ] -[ "`echo -e 'rm /dir' | ./xs_test 2>&1`" = "" ] - -# Create directory, create file, remove all. -[ "`echo -e 'mkdir /dir' | ./xs_test 2>&1`" = "" ] -[ "`echo -e 'write /dir/test excl contents' | ./xs_test 2>&1`" = "" ] -[ "`echo -e 'rm /dir' | ./xs_test 2>&1`" = "" ]
tools/xenstore/testsuite/05filepermissions.sh deleted +0 -49
49 lines not on this page · raw message
tools/xenstore/testsuite/06dirpermissions.sh deleted +0 -75
75 lines not on this page · raw message
tools/xenstore/testsuite/07watch.sh deleted +0 -159
159 lines not on this page · raw message
tools/xenstore/testsuite/08transaction.sh deleted +0 -81
81 lines not on this page · raw message
tools/xenstore/testsuite/09domain.sh deleted +0 -16
@@ -1,16 +0,0 @@ -#! /bin/sh -# Test domain communication. - -# Create a domain, write an entry. -[ "`echo -e 'introduce 1 100 7 /my/home -1 write /entry1 create contents -dir /' | ./xs_test 2>&1 | sort`" = "entry1 -handle is 1 -tool" ] - -# Release that domain. -[ "`echo -e 'release 1' | ./xs_test`" = "" ] - -# Introduce and release by same connection. -[ "`echo -e 'introduce 1 100 7 /my/home -release 1' | ./xs_test 2>&1`" = "handle is 1" ]
tools/xenstore/testsuite/10domain-homedir.sh deleted +0 -20
@@ -1,20 +0,0 @@ -#! /bin/sh -# Test domain "implicit" paths. - -# Create a domain, write an entry using implicit path, read using implicit -[ "`echo -e 'mkdir /home -introduce 1 100 7 /home -1 write entry1 create contents -read /home/entry1 -dir /home' | ./xs_test 2>&1`" = "handle is 1 -contents -entry1" ] - -# Place a watch using a relative path: expect relative answer. -[ "`echo 'introduce 1 100 7 /home -1 mkdir foo -1 watch foo token -write /home/foo/bar create contents -1 waitwatch -1 ackwatch token' | ./xs_test 2>&1`" = "handle is 1 -1:foo/bar:token" ]
tools/xenstore/testsuite/11domain-watch.sh deleted +0 -51
51 lines not on this page · raw message
tools/xenstore/testsuite/12readonly.sh deleted +0 -41
41 lines not on this page · raw message