Skip to contentSkip to conversation

Xenstore watch rework

PATCH New Rusty Russell 1 participant 1 message Aug 4, 2005 Arm/actions semi architecture

lore
Share & tools
lore
#0 lore raw

PATCH 6/11 Xenstore watch rework

# HG changeset patch
# User Rusty Russell <[email protected]>
# Node ID b0de1894df67ac7c7d905bf61cdf0210b42752cc
# Parent ba5d5bd28edf8bce89bdf9fc64047ee4f1dceded
Xenstore watch rework
Change watches to all fire simultaneously, removing priority argument. Watches no longer fired back to connection/domain which caused event. Fix up testsuite to match
Use state enum, rather than return value inside daemon to determine blockage

linux-2.6.11-xen-sparse/drivers/xen/xenbus/xenbus_probe.c +0 -1
diff -r ba5d5bd28edf -r b0de1894df67 linux-2.6.11-xen-sparse/drivers/xen/xenbus/xenbus_probe.c
@@ -800,7 +800,6 @@
 {
         static int init_done = 0;
 	static struct xenbus_watch watch = { .node = "/", 
-					     .priority = 0, 
 					     .callback = test_callback };
 
         if(init_done) return;
linux-2.6.11-xen-sparse/drivers/xen/xenbus/xenbus_xs.c +5 -9
diff -r ba5d5bd28edf -r b0de1894df67 linux-2.6.11-xen-sparse/drivers/xen/xenbus/xenbus_xs.c
@@ -321,18 +321,14 @@
 	return xs_single(XS_GETDOMAINPATH, domid_str, NULL);
 }
 
-static int xs_watch(const char *path, const char *token, unsigned int priority)
-{
-	char prio[32];
-	struct kvec iov[3];
-
-	sprintf(prio, "%u", priority);
+static int xs_watch(const char *path, const char *token)
+{
+	struct kvec iov[2];
+
 	iov[0].iov_base = (void *)path;
 	iov[0].iov_len = strlen(path) + 1;
 	iov[1].iov_base = (void *)token;
 	iov[1].iov_len = strlen(token) + 1;
-	iov[2].iov_base = prio;
-	iov[2].iov_len = strlen(prio) + 1;
 
 	return xs_error(xs_talkv(XS_WATCH, iov, ARRAY_SIZE(iov), NULL));
 }
@@ -393,7 +389,7 @@
 	BUG_ON(find_watch(token));
 
 	down(&xs_lock);
-	err = xs_watch(watch->node, token, watch->priority);
+	err = xs_watch(watch->node, token);
 	up(&xs_lock);
 	if (!err)
 		list_add(&watch->list, &watches);
linux-2.6.11-xen-sparse/include/asm-xen/xenbus.h +0 -1
diff -r ba5d5bd28edf -r b0de1894df67 linux-2.6.11-xen-sparse/include/asm-xen/xenbus.h
@@ -117,7 +117,6 @@
 {
 	struct list_head list;
 	char *node;
-	unsigned int priority;
 	void (*callback)(struct xenbus_watch *, const char *node);
 };
 
tools/python/xen/lowlevel/xs/xs.c +4 -6
diff -r ba5d5bd28edf -r b0de1894df67 tools/python/xen/lowlevel/xs/xs.c
@@ -343,7 +343,6 @@
 #define xspy_watch_doc "\n"						\
 	"Watch a path, get notifications when it changes.\n"		\
 	" path     [string] : xenstore path.\n"				\
-	" priority [int]    : watch priority (default 0).\n"		\
 	" token    [string] : returned in watch notification.\n"	\
 	"\n"								\
 	"Returns: [int] 0 on success.\n"				\
@@ -352,10 +351,9 @@
 
 static PyObject *xspy_watch(PyObject *self, PyObject *args, PyObject *kwds)
 {
-    static char *kwd_spec[] = { "path", "priority", "token", NULL };
+    static char *kwd_spec[] = { "path", "token", NULL };
     static char *arg_spec = "s|is";
     char *path = NULL;
-    int priority = 0;
     char *token = "";
 
     struct xs_handle *xh = xshandle(self);
@@ -365,9 +363,9 @@
     if (!xh)
 	goto exit;
     if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec, 
-                                     &path, &priority, &token))
-        goto exit;
-    xsval = xs_watch(xh, path, token, priority);
+                                     &path, &token))
+        goto exit;
+    xsval = xs_watch(xh, path, token);
     val = pyvalue_int(xsval);
  exit:
     return val;
tools/xenstore/Makefile +3 -6
diff -r ba5d5bd28edf -r b0de1894df67 tools/xenstore/Makefile
@@ -42,9 +42,8 @@
 xs_test: xs_test.o xs_lib.o utils.o
 xs_random: xs_random.o xs_test_lib.o xs_lib.o talloc.o utils.o
 xs_stress: xs_stress.o xs_test_lib.o xs_lib.o talloc.o utils.o
-xs_watch_stress: xs_watch_stress.o xs_test_lib.o xs_lib.o talloc.o utils.o
 
-xs_test.o xs_stress.o xs_watch_stress.o xenstored_core_test.o xenstored_watch_test.o xenstored_transaction_test.o xenstored_domain_test.o xs_random.o xs_test_lib.o talloc_test.o fake_libxc.o: CFLAGS=$(BASECFLAGS) $(TESTFLAGS)
+xs_test.o xs_stress.o xenstored_core_test.o xenstored_watch_test.o xenstored_transaction_test.o xenstored_domain_test.o xs_random.o xs_test_lib.o talloc_test.o fake_libxc.o: CFLAGS=$(BASECFLAGS) $(TESTFLAGS)
 
 xenstored_%_test.o: xenstored_%.c
 	$(COMPILE.c) -o $@ $<
@@ -66,7 +65,7 @@
 
 clean: testsuite-clean
 	rm -f *.o *.opic *.a
-	rm -f xen xenstored xs_random xs_stress xs_watch_stress
+	rm -f xen xenstored xs_random xs_stress
 	rm -f xs_test xenstored_test xs_dom0_test
 	-$(RM) $(PROG_DEP)
 
@@ -86,11 +85,9 @@
 	$(TESTENV) ./xs_random --fast /tmp/xs_random 100000 $(RANDSEED)
 	$(TESTENV) ./xs_random --fail /tmp/xs_random 10000 $(RANDSEED)
 
-stresstest: xs_stress xs_watch_stress xenstored_test
+stresstest: xs_stress xenstored_test
 	rm -rf $(TESTDIR)/store $(TESTDIR)/transactions
 	export $(TESTENV); PID=`./xenstored_test --output-pid --trace-file=/tmp/trace`; ./xs_stress 5000; ret=$$?; kill $$PID; exit $$ret
-	rm -rf $(TESTDIR)/store $(TESTDIR)/transactions
-	export $(TESTENV); PID=`./xenstored_test --output-pid`; ./xs_watch_stress; ret=$$?; kill $$PID; exit $$ret
 
 xs_dom0_test: xs_dom0_test.o utils.o
 	$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -lxc -o $@
tools/xenstore/testsuite/07watch.sh +33 -28

155 lines not on this page · raw message

tools/xenstore/testsuite/08transaction.sh +6 -6
diff -r ba5d5bd28edf -r b0de1894df67 tools/xenstore/testsuite/08transaction.sh
@@ -45,27 +45,27 @@
 sleep 1
 rm /test/entry1
 commit
-dir /test' | ./xs_test`" = "" ]
+dir /test' | ./xs_test --no-timeout`" = "" ]
 
 # ... as long as noone is waiting.
 [ "`echo -e '1 start /test
 2 mkdir /test/dir
 1 mkdir /test/dir
 1 dir /test
-1 commit' | ./xs_test 2>&1`" = "1:dir
+1 commit' | ./xs_test --no-timeout 2>&1`" = "1:dir
 FATAL: 1: commit: Connection timed out" ]
 
 # Events inside transactions don't trigger watches until (successful) commit.
-[ "`echo -e '1 watch /test token 100
+[ "`echo -e '1 watch /test token
 2 start /test
 2 mkdir /test/dir/sub
 1 waitwatch' | ./xs_test 2>&1`" = "1:waitwatch timeout" ]
-[ "`echo -e '1 watch /test token 100
+[ "`echo -e '1 watch /test token
 2 start /test
 2 mkdir /test/dir/sub
 2 abort
 1 waitwatch' | ./xs_test 2>&1`" = "1:waitwatch timeout" ]
-[ "`echo -e '1 watch /test token 100
+[ "`echo -e '1 watch /test token
 2 start /test
 2 mkdir /test/dir/sub
 2 commit
@@ -73,7 +73,7 @@
 1 ackwatch token' | ./xs_test 2>&1`" = "1:/test/dir/sub:token" ]
 
 # Rm inside transaction works like rm outside: children get notified.
-[ "`echo -e '1 watch /test/dir/sub token 100
+[ "`echo -e '1 watch /test/dir/sub token
 2 start /test
 2 rm /test/dir
 2 commit
tools/xenstore/testsuite/10domain-homedir.sh +1 -1
diff -r ba5d5bd28edf -r b0de1894df67 tools/xenstore/testsuite/10domain-homedir.sh
@@ -13,7 +13,7 @@
 # Place a watch using a relative path: expect relative answer.
 [ "`echo 'introduce 1 100 7 /home
 1 mkdir foo
-1 watch foo token 0
+1 watch foo token
 write /home/foo/bar create contents
 1 waitwatch
 1 ackwatch token' | ./xs_test 2>&1`" = "handle is 1
tools/xenstore/testsuite/11domain-watch.sh +7 -7
diff -r ba5d5bd28edf -r b0de1894df67 tools/xenstore/testsuite/11domain-watch.sh
@@ -6,7 +6,7 @@
 [ "`echo -e 'mkdir /dir' | ./xs_test 2>&1`" = "" ]
 
 [ "`echo -e 'introduce 1 100 7 /my/home
-1 watch /test token 100
+1 watch /test token
 write /test create contents2
 1 waitwatch
 1 ackwatch token
@@ -16,8 +16,8 @@
 
 # ignore watches while doing commands, should work.
 [ "`echo -e 'introduce 1 100 7 /my/home
-1 watch /dir token 100
-1 write /dir/test create contents
+1 watch /dir token
+write /dir/test create contents
 1 read /dir/test
 1 waitwatch
 1 ackwatch token
@@ -27,9 +27,9 @@
 
 # unwatch
 [ "`echo -e 'introduce 1 100 7 /my/home
-1 watch /dir token1 0
+1 watch /dir token1
 1 unwatch /dir token1
-1 watch /dir token2 0
+1 watch /dir token2
 2 write /dir/test2 create contents
 1 waitwatch
 1 unwatch /dir token2
@@ -39,8 +39,8 @@
 # unwatch while watch pending.
 [ "`echo -e 'introduce 1 100 7 /my/home
 introduce 2 101 8 /my/secondhome
-1 watch /dir token1 0
-2 watch /dir token2 1
+1 watch /dir token1
+2 watch /dir token2
 write /dir/test create contents
 2 unwatch /dir token2
 1 waitwatch
tools/xenstore/testsuite/12readonly.sh +2 -2
diff -r ba5d5bd28edf -r b0de1894df67 tools/xenstore/testsuite/12readonly.sh
@@ -9,7 +9,7 @@
 
 [ "`echo 'read /test
 getperm /test
-watch /test token 0
+watch /test token
 unwatch /test token 
 start /
 commit
@@ -27,7 +27,7 @@
 
 # Check that watches work like normal.
 set -m
-[ "`echo 'watch / token 0
+[ "`echo 'watch / token
 waitwatch
 ackwatch token' | ./xs_test --readonly 2>&1`" = "/test:token" ] &
 
tools/xenstore/xenstored_core.c +225 -148

641 lines not on this page · raw message

tools/xenstore/xenstored_core.h +21 -6
diff -r ba5d5bd28edf -r b0de1894df67 tools/xenstore/xenstored_core.h
@@ -47,6 +47,14 @@
 typedef int connwritefn_t(struct connection *, const void *, unsigned int);
 typedef int connreadfn_t(struct connection *, void *, unsigned int);
 
+enum state
+{
+	/* Blocked by transaction. */
+	BLOCKED,
+	/* Completed */
+	OK,
+};
+
 struct connection
 {
 	struct list_head list;
@@ -57,8 +65,11 @@
 	/* Who am I?  0 for socket connections. */
 	domid_t id;
 
-	/* Are we blocked waiting for a transaction to end?  Contains node. */
-	char *blocked;
+	/* Blocked on transaction? */
+	enum state state;
+
+	/* Node we are waiting for (if state == BLOCKED) */
+	char *blocked_by;
 
 	/* Is this a read-only connection? */
 	bool can_write;
@@ -81,10 +92,14 @@
 	/* The domain I'm associated with, if any. */
 	struct domain *domain;
 
+	/* My watches. */
+	struct list_head watches;
+
 	/* Methods for communicating over this connection: write can be NULL */
 	connwritefn_t *write;
 	connreadfn_t *read;
 };
+extern struct list_head connections;
 
 /* Return length of string (including nul) at this offset. */
 unsigned int get_string(const struct buffered_data *data,
@@ -100,14 +115,14 @@
 /* Create a new buffer with lifetime of context. */
 struct buffered_data *new_buffer(void *ctx);
 
-bool send_reply(struct connection *conn, enum xsd_sockmsg_type type,
-                const void *data, unsigned int len);
+void send_reply(struct connection *conn, enum xsd_sockmsg_type type,
+		const void *data, unsigned int len);
 
 /* Some routines (write, mkdir, etc) just need a non-error return */
-bool send_ack(struct connection *conn, enum xsd_sockmsg_type type);
+void send_ack(struct connection *conn, enum xsd_sockmsg_type type);
 
 /* Send an error: error is usually "errno". */
-bool send_error(struct connection *conn, int error);
+void send_error(struct connection *conn, int error);
 
 /* Canonicalize this path if possible. */
 char *canonicalize(struct connection *conn, const char *node);
tools/xenstore/xenstored_domain.c +64 -42

154 lines not on this page · raw message

tools/xenstore/xenstored_domain.h +3 -3
diff -r ba5d5bd28edf -r b0de1894df67 tools/xenstore/xenstored_domain.h
@@ -22,13 +22,13 @@
 void handle_event(int event_fd);
 
 /* domid, mfn, eventchn, path */
-bool do_introduce(struct connection *conn, struct buffered_data *in);
+void do_introduce(struct connection *conn, struct buffered_data *in);
 
 /* domid */
-bool do_release(struct connection *conn, const char *domid_str);
+void do_release(struct connection *conn, const char *domid_str);
 
 /* domid */
-bool do_get_domain_path(struct connection *conn, const char *domid_str);
+void do_get_domain_path(struct connection *conn, const char *domid_str);
 
 /* Returns the event channel handle */
 int domain_init(void);
tools/xenstore/xenstored_transaction.c +49 -38

133 lines not on this page · raw message

tools/xenstore/xenstored_transaction.h +2 -2
diff -r ba5d5bd28edf -r b0de1894df67 tools/xenstore/xenstored_transaction.h
@@ -22,8 +22,8 @@
 
 struct transaction;
 
-bool do_transaction_start(struct connection *conn, const char *node);
-bool do_transaction_end(struct connection *conn, const char *arg);
+void do_transaction_start(struct connection *conn, const char *node);
+void do_transaction_end(struct connection *conn, const char *arg);
 
 /* Is node covered by this transaction? */
 bool within_transaction(struct transaction *trans, const char *node);
tools/xenstore/xenstored_watch.c +137 -239

483 lines not on this page · raw message

tools/xenstore/xenstored_watch.h +6 -5
diff -r ba5d5bd28edf -r b0de1894df67 tools/xenstore/xenstored_watch.h
@@ -22,9 +22,9 @@
 
 #include "xenstored_core.h"
 
-bool do_watch(struct connection *conn, struct buffered_data *in);
-bool do_watch_ack(struct connection *conn, const char *token);
-bool do_unwatch(struct connection *conn, struct buffered_data *in);
+void do_watch(struct connection *conn, struct buffered_data *in);
+void do_watch_ack(struct connection *conn, const char *token);
+void do_unwatch(struct connection *conn, struct buffered_data *in);
 
 /* Is this a watch event message for this connection? */
 bool is_watch_event(struct connection *conn, struct buffered_data *out);
@@ -32,8 +32,9 @@
 /* Look through our watches: if any of them have an event, queue it. */
 void queue_next_event(struct connection *conn);
 
-/* Fire all watches: recurse means all the children are effected (ie. rm) */
-void fire_watches(struct transaction *trans, const char *node, bool recurse);
+/* Fire all watches: recurse means all the children are effected (ie. rm).
+ */
+void fire_watches(struct connection *conn, const char *node, bool recurse);
 
 /* Find shortest timeout: if any, reduce tv (may already be set). */
 void shortest_watch_ack_timeout(struct timeval *tv);
tools/xenstore/xs.c +4 -10
diff -r ba5d5bd28edf -r b0de1894df67 tools/xenstore/xs.c
@@ -401,22 +401,16 @@
 /* Watch a node for changes (poll on fd to detect, or call read_watch()).
  * When the node (or any child) changes, fd will become readable.
  * Token is returned when watch is read, to allow matching.
- * Priority indicates order if multiple watchers: higher is first.
  * Returns false on failure.
  */
-bool xs_watch(struct xs_handle *h, const char *path, const char *token,
-	      unsigned int priority)
-{
-	char prio[MAX_STRLEN(priority)];
-	struct iovec iov[3];
-
-	sprintf(prio, "%u", priority);
+bool xs_watch(struct xs_handle *h, const char *path, const char *token)
+{
+	struct iovec iov[2];
+
 	iov[0].iov_base = (void *)path;
 	iov[0].iov_len = strlen(path) + 1;
 	iov[1].iov_base = (void *)token;
 	iov[1].iov_len = strlen(token) + 1;
-	iov[2].iov_base = prio;
-	iov[2].iov_len = strlen(prio) + 1;
 
 	return xs_bool(xs_talkv(h, XS_WATCH, iov, ARRAY_SIZE(iov), NULL));
 }
tools/xenstore/xs.h +1 -3
diff -r ba5d5bd28edf -r b0de1894df67 tools/xenstore/xs.h
@@ -82,11 +82,9 @@
 /* Watch a node for changes (poll on fd to detect, or call read_watch()).
  * When the node (or any child) changes, fd will become readable.
  * Token is returned when watch is read, to allow matching.
- * Priority indicates order if multiple watchers: higher is first.
  * Returns false on failure.
  */
-bool xs_watch(struct xs_handle *h, const char *path, const char *token,
-	      unsigned int priority);
+bool xs_watch(struct xs_handle *h, const char *path, const char *token);
 
 /* Return the FD to poll on to see if a watch has fired. */
 int xs_fileno(struct xs_handle *h);
tools/xenstore/xs_test.c +127 -106

289 lines not on this page · raw message

tools/xenstore/xs_watch_stress.c deleted +0 -120

120 lines not on this page · raw message