WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-tools

[Xen-tools] [PATCH] Fire watches once on registration

To: Christian Limpach <Christian.Limpach@xxxxxxxxxxxx>
Subject: [Xen-tools] [PATCH] Fire watches once on registration
From: Rusty Russell <rusty@xxxxxxxxxxxxxxx>
Date: Sat, 17 Sep 2005 12:36:51 +1000
Cc: Xen Tools <xen-tools@xxxxxxxxxxxxxxxxxxx>
Delivery-date: Sat, 17 Sep 2005 02:34:43 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-tools-request@lists.xensource.com?subject=help>
List-id: Xen control tools developers <xen-tools.lists.xensource.com>
List-post: <mailto:xen-tools@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-tools>, <mailto:xen-tools-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-tools>, <mailto:xen-tools-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-tools-bounces@xxxxxxxxxxxxxxxxxxx
Signed-off-by: Rusty Russell <rusty@xxxxxxxxxxxxxxx>

# HG changeset patch
# User Rusty Russell <rusty@xxxxxxxxxxxxxxx>
# Node ID 2b6c78f9faea3bbbae6053ccc047a822f7340f7a
# Parent  fd19e760932d095b23d38e67eaec24dd02ba3aba
Fire watches once immediately upon registration.
Christian suggested this a while ago: it matches the model of programming used 
to avoid races with watches, and also makes re-establishing watches on daemon 
restart easier.

diff -r fd19e760932d -r 2b6c78f9faea 
linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c
--- a/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c Thu Sep 15 19:46:14 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c Sat Sep 17 02:35:31 2005
@@ -228,6 +228,7 @@
        be->dev = dev;
        be->backend_watch.node = dev->nodename;
        be->backend_watch.callback = backend_changed;
+       /* Will implicitly call backend_changed once. */
        err = register_xenbus_watch(&be->backend_watch);
        if (err) {
                be->backend_watch.node = NULL;
@@ -249,8 +250,6 @@
        }
 
        dev->data = be;
-
-       backend_changed(&be->backend_watch, dev->nodename);
        return 0;
 
  free_be:
diff -r fd19e760932d -r 2b6c78f9faea 
linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c
--- a/linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c  Thu Sep 15 19:46:14 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c  Sat Sep 17 02:35:31 2005
@@ -172,6 +172,7 @@
        be->dev = dev;
        be->backend_watch.node = dev->nodename;
        be->backend_watch.callback = backend_changed;
+       /* Registration implicitly fires backend_changed once */
        err = register_xenbus_watch(&be->backend_watch);
        if (err) {
                be->backend_watch.node = NULL;
@@ -193,8 +194,6 @@
        }
 
        dev->data = be;
-
-       backend_changed(&be->backend_watch, dev->nodename);
        return 0;
 
  free_be:
diff -r fd19e760932d -r 2b6c78f9faea 
linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c
--- a/linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c Thu Sep 15 19:46:14 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c Sat Sep 17 02:35:31 2005
@@ -242,6 +242,7 @@
        be->dev = dev;
        be->backend_watch.node = dev->nodename;
        be->backend_watch.callback = backend_changed;
+       /* Registration implicitly calls backend_changed. */
        err = register_xenbus_watch(&be->backend_watch);
        if (err) {
                be->backend_watch.node = NULL;
@@ -263,8 +264,6 @@
        }
 
        dev->data = be;
-
-       backend_changed(&be->backend_watch, dev->nodename);
        return 0;
 
  free_be:
diff -r fd19e760932d -r 2b6c78f9faea 
linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c
--- a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c      Thu Sep 15 
19:46:14 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c      Sat Sep 17 
02:35:31 2005
@@ -1279,10 +1279,6 @@
                return err;
        }
 
-
-       /* Call once in case entries already there. */
-       watch_for_status(&info->watch, info->watch.node);
-
        return 0;
 }
 
diff -r fd19e760932d -r 2b6c78f9faea 
linux-2.6-xen-sparse/drivers/xen/tpmback/xenbus.c
--- a/linux-2.6-xen-sparse/drivers/xen/tpmback/xenbus.c Thu Sep 15 19:46:14 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/xenbus.c Sat Sep 17 02:35:31 2005
@@ -213,6 +213,7 @@
 
        be->dev = dev;
        be->backend_watch.node     = dev->nodename;
+       /* Implicitly calls backend_changed() once. */
        be->backend_watch.callback = backend_changed;
        be->instance = -1;
        err = register_xenbus_watch(&be->backend_watch);
@@ -236,8 +237,6 @@
        }
 
        dev->data = be;
-
-       backend_changed(&be->backend_watch, dev->nodename);
        return err;
 
 free_be:
diff -r fd19e760932d -r 2b6c78f9faea 
linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c
--- a/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c      Thu Sep 15 
19:46:14 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c      Sat Sep 17 
02:35:31 2005
@@ -412,7 +412,6 @@
                return err;
        }
 
-       watch_for_status(&info->watch, info->watch.node);
        return 0;
 }
 
diff -r fd19e760932d -r 2b6c78f9faea tools/xenstore/testsuite/07watch.test
--- a/tools/xenstore/testsuite/07watch.test     Thu Sep 15 19:46:14 2005
+++ b/tools/xenstore/testsuite/07watch.test     Sat Sep 17 02:35:31 2005
@@ -168,10 +168,12 @@
 # Watch event must have happened before we registered interest.
 1 watch / token
 2 write /test/subnode create contents2
-1 watch / token2 0
+1 watchnoack / token2 0
 expect 1:/test/subnode:token
 1 waitwatch
 1 ackwatch token
+expect 1:/:token2
+1 waitwatch
 expect 1: waitwatch failed: Connection timed out
 1 waitwatch
 1 close
diff -r fd19e760932d -r 2b6c78f9faea 
tools/xenstore/testsuite/14complexperms.test
--- a/tools/xenstore/testsuite/14complexperms.test      Thu Sep 15 19:46:14 2005
+++ b/tools/xenstore/testsuite/14complexperms.test      Sat Sep 17 02:35:31 2005
@@ -29,7 +29,8 @@
 getperm /dir/file 
 expect *Permission denied
 setperm /dir/file 0 NONE 
-watch /dir/file token 
+# We get no watch event when there's no permission.  It's a corner case.
+watchnoack /dir/file token 
 1 write /dir/file create contents
 1 rm /dir/file
 expect waitwatch failed: Connection timed out
@@ -75,7 +76,7 @@
 getperm /dir/file 
 expect *Permission denied
 setperm /dir/file 0 NONE 
-watch /dir/file token 
+watchnoack /dir/file token
 1 write /dir/file create contents
 1 rm /dir/file
 expect waitwatch failed: Connection timed out
diff -r fd19e760932d -r 2b6c78f9faea tools/xenstore/xenstored_watch.c
--- a/tools/xenstore/xenstored_watch.c  Thu Sep 15 19:46:14 2005
+++ b/tools/xenstore/xenstored_watch.c  Sat Sep 17 02:35:31 2005
@@ -236,6 +236,9 @@
        trace_create(watch, "watch");
        talloc_set_destructor(watch, destroy_watch);
        send_ack(conn, XS_WATCH);
+
+       /* We fire once up front: simplifies clients and restart. */
+       add_event(conn, watch, watch->node);
 }
 
 void do_watch_ack(struct connection *conn, const char *token)
diff -r fd19e760932d -r 2b6c78f9faea tools/xenstore/xs_test.c
--- a/tools/xenstore/xs_test.c  Thu Sep 15 19:46:14 2005
+++ b/tools/xenstore/xs_test.c  Sat Sep 17 02:35:31 2005
@@ -200,6 +200,7 @@
             "  setperm <path> <id> <flags> ...\n"
             "  shutdown\n"
             "  watch <path> <token>\n"
+            "  watchnoack <path> <token>\n"
             "  waitwatch\n"
             "  ackwatch <token>\n"
             "  unwatch <path> <token>\n"
@@ -505,10 +506,20 @@
                failed(handle);
 }
 
-static void do_watch(unsigned int handle, const char *node, const char *token)
+static void do_watch(unsigned int handle, const char *node, const char *token,
+                    bool swallow_event)
 {
        if (!xs_watch(handles[handle], node, token))
                failed(handle);
+
+       /* Convenient for testing... */
+       if (swallow_event) {
+               char **vec = xs_read_watch(handles[handle]);
+               if (!vec || !streq(vec[0], node) || !streq(vec[1], token))
+                       failed(handle);
+               if (!xs_acknowledge_watch(handles[handle], token))
+                       failed(handle);
+       }
 }
 
 static void set_timeout(void)
@@ -793,7 +804,9 @@
        else if (streq(command, "shutdown"))
                do_shutdown(handle);
        else if (streq(command, "watch"))
-               do_watch(handle, arg(line, 1), arg(line, 2));
+               do_watch(handle, arg(line, 1), arg(line, 2), true);
+       else if (streq(command, "watchnoack"))
+               do_watch(handle, arg(line, 1), arg(line, 2), false);
        else if (streq(command, "waitwatch"))
                do_waitwatch(handle);
        else if (streq(command, "ackwatch"))

-- 
A bad analogy is like a leaky screwdriver -- Richard Braakman


_______________________________________________
Xen-tools mailing list
Xen-tools@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-tools

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-tools] [PATCH] Fire watches once on registration, Rusty Russell <=