ia64/xen-unstable

changeset 6969:2796d45c5835

Fire watches once immediately upon registration.
It matches the model of programming used to avoid races with watches,
and also makes re-establishing watches on daemon restart easier.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Mon Sep 19 14:47:56 2005 +0000 (2005-09-19)
parents 0a2cc72ee6e4
children fc2eade714f9
files linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c linux-2.6-xen-sparse/drivers/xen/tpmback/xenbus.c linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c tools/xenstore/testsuite/07watch.test tools/xenstore/testsuite/14complexperms.test tools/xenstore/xenstored_watch.c tools/xenstore/xs_test.c
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c	Mon Sep 19 14:36:15 2005 +0000
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c	Mon Sep 19 14:47:56 2005 +0000
     1.3 @@ -228,6 +228,7 @@ static int blkback_probe(struct xenbus_d
     1.4  	be->dev = dev;
     1.5  	be->backend_watch.node = dev->nodename;
     1.6  	be->backend_watch.callback = backend_changed;
     1.7 +	/* Will implicitly call backend_changed once. */
     1.8  	err = register_xenbus_watch(&be->backend_watch);
     1.9  	if (err) {
    1.10  		be->backend_watch.node = NULL;
    1.11 @@ -249,8 +250,6 @@ static int blkback_probe(struct xenbus_d
    1.12  	}
    1.13  
    1.14  	dev->data = be;
    1.15 -
    1.16 -	backend_changed(&be->backend_watch, dev->nodename);
    1.17  	return 0;
    1.18  
    1.19   free_be:
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c	Mon Sep 19 14:36:15 2005 +0000
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c	Mon Sep 19 14:47:56 2005 +0000
     2.3 @@ -172,6 +172,7 @@ static int blkback_probe(struct xenbus_d
     2.4  	be->dev = dev;
     2.5  	be->backend_watch.node = dev->nodename;
     2.6  	be->backend_watch.callback = backend_changed;
     2.7 +	/* Registration implicitly fires backend_changed once */
     2.8  	err = register_xenbus_watch(&be->backend_watch);
     2.9  	if (err) {
    2.10  		be->backend_watch.node = NULL;
    2.11 @@ -193,8 +194,6 @@ static int blkback_probe(struct xenbus_d
    2.12  	}
    2.13  
    2.14  	dev->data = be;
    2.15 -
    2.16 -	backend_changed(&be->backend_watch, dev->nodename);
    2.17  	return 0;
    2.18  
    2.19   free_be:
     3.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c	Mon Sep 19 14:36:15 2005 +0000
     3.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c	Mon Sep 19 14:47:56 2005 +0000
     3.3 @@ -242,6 +242,7 @@ static int netback_probe(struct xenbus_d
     3.4  	be->dev = dev;
     3.5  	be->backend_watch.node = dev->nodename;
     3.6  	be->backend_watch.callback = backend_changed;
     3.7 +	/* Registration implicitly calls backend_changed. */
     3.8  	err = register_xenbus_watch(&be->backend_watch);
     3.9  	if (err) {
    3.10  		be->backend_watch.node = NULL;
    3.11 @@ -263,8 +264,6 @@ static int netback_probe(struct xenbus_d
    3.12  	}
    3.13  
    3.14  	dev->data = be;
    3.15 -
    3.16 -	backend_changed(&be->backend_watch, dev->nodename);
    3.17  	return 0;
    3.18  
    3.19   free_be:
     4.1 --- a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Mon Sep 19 14:36:15 2005 +0000
     4.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Mon Sep 19 14:47:56 2005 +0000
     4.3 @@ -1284,10 +1284,6 @@ static int netfront_probe(struct xenbus_
     4.4  		return err;
     4.5  	}
     4.6  
     4.7 -
     4.8 -	/* Call once in case entries already there. */
     4.9 -	watch_for_status(&info->watch, info->watch.node);
    4.10 -
    4.11  	return 0;
    4.12  }
    4.13  
     5.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/xenbus.c	Mon Sep 19 14:36:15 2005 +0000
     5.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/xenbus.c	Mon Sep 19 14:47:56 2005 +0000
     5.3 @@ -213,6 +213,7 @@ static int tpmback_probe(struct xenbus_d
     5.4  
     5.5  	be->dev = dev;
     5.6  	be->backend_watch.node     = dev->nodename;
     5.7 +	/* Implicitly calls backend_changed() once. */
     5.8  	be->backend_watch.callback = backend_changed;
     5.9  	be->instance = -1;
    5.10  	err = register_xenbus_watch(&be->backend_watch);
    5.11 @@ -236,8 +237,6 @@ static int tpmback_probe(struct xenbus_d
    5.12  	}
    5.13  
    5.14  	dev->data = be;
    5.15 -
    5.16 -	backend_changed(&be->backend_watch, dev->nodename);
    5.17  	return err;
    5.18  
    5.19  free_be:
     6.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c	Mon Sep 19 14:36:15 2005 +0000
     6.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c	Mon Sep 19 14:47:56 2005 +0000
     6.3 @@ -411,7 +411,6 @@ static int tpmfront_probe(struct xenbus_
     6.4  		return err;
     6.5  	}
     6.6  
     6.7 -	watch_for_status(&info->watch, info->watch.node);
     6.8  	return 0;
     6.9  }
    6.10  
     7.1 --- a/tools/xenstore/testsuite/07watch.test	Mon Sep 19 14:36:15 2005 +0000
     7.2 +++ b/tools/xenstore/testsuite/07watch.test	Mon Sep 19 14:47:56 2005 +0000
     7.3 @@ -168,10 +168,12 @@ 1 close
     7.4  # Watch event must have happened before we registered interest.
     7.5  1 watch / token
     7.6  2 write /test/subnode contents2
     7.7 -1 watch / token2 0
     7.8 +1 watchnoack / token2 0
     7.9  expect 1:/test/subnode:token
    7.10  1 waitwatch
    7.11  1 ackwatch token
    7.12 +expect 1:/:token2
    7.13 +1 waitwatch
    7.14  expect 1: waitwatch failed: Connection timed out
    7.15  1 waitwatch
    7.16  1 close
     8.1 --- a/tools/xenstore/testsuite/14complexperms.test	Mon Sep 19 14:36:15 2005 +0000
     8.2 +++ b/tools/xenstore/testsuite/14complexperms.test	Mon Sep 19 14:47:56 2005 +0000
     8.3 @@ -23,7 +23,8 @@ expect *Permission denied
     8.4  getperm /dir/file 
     8.5  expect *Permission denied
     8.6  setperm /dir/file 0 NONE 
     8.7 -watch /dir/file token 
     8.8 +# We get no watch event when there's no permission.  It's a corner case.
     8.9 +watchnoack /dir/file token 
    8.10  1 write /dir/file contents
    8.11  1 rm /dir/file
    8.12  expect waitwatch failed: Connection timed out
    8.13 @@ -63,7 +64,7 @@ expect *Permission denied
    8.14  getperm /dir/file 
    8.15  expect *Permission denied
    8.16  setperm /dir/file 0 NONE 
    8.17 -watch /dir/file token 
    8.18 +watchnoack /dir/file token 
    8.19  1 write /dir/file contents
    8.20  1 rm /dir/file
    8.21  expect waitwatch failed: Connection timed out
     9.1 --- a/tools/xenstore/xenstored_watch.c	Mon Sep 19 14:36:15 2005 +0000
     9.2 +++ b/tools/xenstore/xenstored_watch.c	Mon Sep 19 14:47:56 2005 +0000
     9.3 @@ -236,6 +236,9 @@ void do_watch(struct connection *conn, s
     9.4  	trace_create(watch, "watch");
     9.5  	talloc_set_destructor(watch, destroy_watch);
     9.6  	send_ack(conn, XS_WATCH);
     9.7 +
     9.8 +	/* We fire once up front: simplifies clients and restart. */
     9.9 +	add_event(conn, watch, watch->node);
    9.10  }
    9.11  
    9.12  void do_watch_ack(struct connection *conn, const char *token)
    10.1 --- a/tools/xenstore/xs_test.c	Mon Sep 19 14:36:15 2005 +0000
    10.2 +++ b/tools/xenstore/xs_test.c	Mon Sep 19 14:47:56 2005 +0000
    10.3 @@ -200,6 +200,7 @@ static void __attribute__((noreturn)) us
    10.4  	     "  setperm <path> <id> <flags> ...\n"
    10.5  	     "  shutdown\n"
    10.6  	     "  watch <path> <token>\n"
    10.7 +	     "  watchnoack <path> <token>\n"
    10.8  	     "  waitwatch\n"
    10.9  	     "  ackwatch <token>\n"
   10.10  	     "  unwatch <path> <token>\n"
   10.11 @@ -480,10 +481,20 @@ static void do_shutdown(unsigned int han
   10.12  		failed(handle);
   10.13  }
   10.14  
   10.15 -static void do_watch(unsigned int handle, const char *node, const char *token)
   10.16 +static void do_watch(unsigned int handle, const char *node, const char *token,
   10.17 +		     bool swallow_event)
   10.18  {
   10.19  	if (!xs_watch(handles[handle], node, token))
   10.20  		failed(handle);
   10.21 +
   10.22 +	/* Convenient for testing... */
   10.23 +	if (swallow_event) {
   10.24 +		char **vec = xs_read_watch(handles[handle]);
   10.25 +		if (!vec || !streq(vec[0], node) || !streq(vec[1], token))
   10.26 +			failed(handle);
   10.27 +		if (!xs_acknowledge_watch(handles[handle], token))
   10.28 +			failed(handle);
   10.29 +	}
   10.30  }
   10.31  
   10.32  static void set_timeout(void)
   10.33 @@ -767,7 +778,9 @@ static void do_command(unsigned int defa
   10.34  	else if (streq(command, "shutdown"))
   10.35  		do_shutdown(handle);
   10.36  	else if (streq(command, "watch"))
   10.37 -		do_watch(handle, arg(line, 1), arg(line, 2));
   10.38 +		do_watch(handle, arg(line, 1), arg(line, 2), true);
   10.39 +	else if (streq(command, "watchnoack"))
   10.40 +		do_watch(handle, arg(line, 1), arg(line, 2), false);
   10.41  	else if (streq(command, "waitwatch"))
   10.42  		do_waitwatch(handle);
   10.43  	else if (streq(command, "ackwatch"))