xenstored updates:
PATCH 1/11 xenstored updates:
# HG changeset patch
# User Rusty Russell <[email protected]>
# Node ID bdc6aabe3e1a6f83e7119c68212c2c33a4cb851f
# Parent 22d7dda0e38dc4f9436682ab6e7879e4f7ae6ace xenstored updates:
--trace-file arg to xenstored for better diagnosis
Inherit permissions when creating files and directories Rework watch code so it only fires on watches active when event occurs More exhaustive tests for watches, and transactions
Fix watches on rm to cover deleted children
Watches placed using relative path return relative path when fired
Signed-off-by Rusty Russell <[email protected]>
tools/xenstore/Makefile +1 -1
@@ -88,7 +88,7 @@ stresstest: xs_stress xs_watch_stress xenstored_test rm -rf $(TESTDIR)/store - export $(TESTENV); PID=`./xenstored_test --output-pid`; ./xs_stress 5000; ret=$$?; kill $$PID; exit $$ret + export $(TESTENV); PID=`./xenstored_test --output-pid --trace-file=/tmp/trace`; ./xs_stress 5000; ret=$$?; kill $$PID; exit $$ret rm -rf $(TESTDIR)/store export $(TESTENV); PID=`./xenstored_test --output-pid`; ./xs_watch_stress; ret=$$?; kill $$PID; exit $$ret
tools/xenstore/testsuite/05filepermissions.sh +8 -8
@@ -4,17 +4,17 @@ [ "`echo -e 'getperm /test' | ./xs_test 2>&1`" = "FATAL: getperm: No such file or directory" ] [ "`echo -e 'getperm /dir/test' | ./xs_test 2>&1`" = "FATAL: getperm: No such file or directory" ] -# Create file: we own it, noone has access. +# Create file: inherits from root (0 READ) [ "`echo -e 'write /test excl contents' | ./xs_test 2>&1`" = "" ] -[ "`echo -e 'getperm /test' | ./xs_test 2>&1`" = "0 NONE" ] +[ "`echo -e 'getperm /test' | ./xs_test 2>&1`" = "0 READ" ] +[ "`echo -e 'setid 1\ngetperm /test' | ./xs_test 2>&1`" = "0 READ" ] +[ "`echo -e 'setid 1\nread /test' | ./xs_test 2>&1`" = "contents" ] +[ "`echo -e 'setid 1\nwrite /test none contents2' | ./xs_test 2>&1`" = "FATAL: write: Permission denied" ] + +# Take away read access to file. +[ "`echo -e 'setperm /test 0 NONE' | ./xs_test 2>&1`" = "" ] [ "`echo -e 'setid 1\ngetperm /test' | ./xs_test 2>&1`" = "FATAL: getperm: Permission denied" ] [ "`echo -e 'setid 1\nread /test' | ./xs_test 2>&1`" = "FATAL: read: Permission denied" ] -[ "`echo -e 'setid 1\nwrite /test none contents2' | ./xs_test 2>&1`" = "FATAL: write: Permission denied" ] - -# Grant everyone read access to file. -[ "`echo -e 'setperm /test 0 READ' | ./xs_test 2>&1`" = "" ] -[ "`echo -e 'setid 1\ngetperm /test' | ./xs_test 2>&1`" = "0 READ" ] -[ "`echo -e 'setid 1\nread /test' | ./xs_test 2>&1`" = "contents" ] [ "`echo -e 'setid 1\nwrite /test none contents2' | ./xs_test 2>&1`" = "FATAL: write: Permission denied" ] # Grant everyone write access to file.
tools/xenstore/testsuite/06dirpermissions.sh +22 -8
@@ -3,17 +3,17 @@ # Root directory: owned by tool, everyone has read access. [ "`echo -e 'getperm /' | ./xs_test 2>&1`" = "0 READ" ] -# Create directory: we own it, noone has access. +# Create directory: inherits from root. [ "`echo -e 'mkdir /dir' | ./xs_test 2>&1`" = "" ] -[ "`echo -e 'getperm /dir' | ./xs_test 2>&1`" = "0 NONE" ] +[ "`echo -e 'getperm /dir' | ./xs_test 2>&1`" = "0 READ" ] +[ "`echo -e 'setid 1\ngetperm /dir' | ./xs_test 2>&1`" = "0 READ" ] +[ "`echo -e 'setid 1\ndir /dir' | ./xs_test 2>&1`" = "" ] +[ "`echo -e 'setid 1\nwrite /dir/test create contents2' | ./xs_test 2>&1`" = "FATAL: write: Permission denied" ] + +# Remove everyone's read access to directoy. +[ "`echo -e 'setperm /dir 0 NONE' | ./xs_test 2>&1`" = "" ] [ "`echo -e 'setid 1\ndir /dir' | ./xs_test 2>&1`" = "FATAL: dir: Permission denied" ] [ "`echo -e 'setid 1\nread /dir/test create contents2' | ./xs_test 2>&1`" = "FATAL: read: Permission denied" ] -[ "`echo -e 'setid 1\nwrite /dir/test create contents2' | ./xs_test 2>&1`" = "FATAL: write: Permission denied" ] - -# Grant everyone read access to directoy. -[ "`echo -e 'setperm /dir 0 READ' | ./xs_test 2>&1`" = "" ] -[ "`echo -e 'setid 1\ngetperm /dir' | ./xs_test 2>&1`" = "0 READ" ] -[ "`echo -e 'setid 1\ndir /dir' | ./xs_test 2>&1`" = "" ] [ "`echo -e 'setid 1\nwrite /dir/test create contents2' | ./xs_test 2>&1`" = "FATAL: write: Permission denied" ] # Grant everyone write access to directory.
@@ -21,6 +21,8 @@ [ "`echo -e 'setid 1\ngetperm /dir' | ./xs_test 2>&1`" = "FATAL: getperm: Permission denied" ] [ "`echo -e 'setid 1\ndir /dir' | ./xs_test 2>&1`" = "FATAL: dir: Permission denied" ] [ "`echo -e 'setid 1\nwrite /dir/test create contents' | ./xs_test 2>&1`" = "" ] +[ "`echo -e 'getperm /dir/test' | ./xs_test 2>&1`" = "1 WRITE" ] +[ "`echo -e 'setperm /dir/test 0 NONE' | ./xs_test 2>&1`" = "" ] [ "`echo -e 'read /dir/test' | ./xs_test 2>&1`" = "contents" ] # Grant everyone both read and write access.
@@ -29,6 +31,7 @@ [ "`echo -e 'setid 1\ndir /dir' | ./xs_test 2>&1`" = "test" ] [ "`echo -e 'setid 1\nwrite /dir/test2 create contents' | ./xs_test 2>&1`" = "" ] [ "`echo -e 'setid 1\nread /dir/test2' | ./xs_test 2>&1`" = "contents" ] +[ "`echo -e 'setid 1\nsetperm /dir/test2 1 NONE' | ./xs_test 2>&1`" = "" ] # Change so that user 1 owns it, noone else can do anything. [ "`echo -e 'setperm /dir 1 NONE' | ./xs_test 2>&1`" = "" ]
@@ -59,3 +62,14 @@ test3" ] [ "`echo -e 'write /dir/test4 create contents' | ./xs_test 2>&1`" = "" ] +# Inherited by child. +[ "`echo -e 'mkdir /dir/subdir' | ./xs_test 2>&1`" = "" ] +[ "`echo -e 'getperm /dir/subdir' | ./xs_test 2>&1`" = "1 NONE" ] +[ "`echo -e 'write /dir/subfile excl contents' | ./xs_test 2>&1`" = "" ] +[ "`echo -e 'getperm /dir/subfile' | ./xs_test 2>&1`" = "1 NONE" ] + +# But for domains, they own it. +[ "`echo -e 'setperm /dir/subdir 2 READ/WRITE' | ./xs_test 2>&1`" = "" ] +[ "`echo -e 'getperm /dir/subdir' | ./xs_test 2>&1`" = "2 READ/WRITE" ] +[ "`echo -e 'setid 3\nwrite /dir/subdir/subfile excl contents' | ./xs_test 2>&1`" = "" ] +[ "`echo -e 'getperm /dir/subdir/subfile' | ./xs_test 2>&1`" = "3 READ/WRITE" ]
tools/xenstore/testsuite/07watch.sh +35 -1
@@ -77,13 +77,22 @@ 1 waitwatch 1 unwatch /dir token2' | ./xs_test 2>&1`" = "1:/dir/test2:token2" ] -# unwatch while watch pending. +# unwatch while watch pending. Next watcher gets the event. [ "`echo -e '1 watch /dir token1 0 2 watch /dir token2 1 write /dir/test create contents 2 unwatch /dir token2 1 waitwatch 1 ackwatch token1' | ./xs_test 2>&1`" = "1:/dir/test:token1" ] + +# unwatch while watch pending. Should clear this so we get next event. +[ "`echo -e '1 watch /dir token1 0 +write /dir/test create contents +1 unwatch /dir token1 +1 watch /dir/test token2 0 +write /dir/test none contents2 +1 waitwatch +1 ackwatch token2' | ./xs_test 2>&1`" = "1:/dir/test:token2" ] # check we only get notified once. [ "`echo -e '1 watch /test token 100
@@ -118,3 +127,28 @@ 1 waitwatch' | ./xs_test 2>&1`" = "1:/test/subnode:token 1:/test/subnode/subnode:token 1:waitwatch timeout" ] + +# Watch event must have happened before we registered interest. +[ "`echo -e '1 watch / token 100 +2 write /test/subnode create contents2 +2 watch / token2 0 +1 waitwatch +1 ackwatch token +2 waitwatch' | ./xs_test 2>&1`" = "1:/test/subnode:token +2:waitwatch timeout" ] + +# Rm fires notification on child. +[ "`echo -e '1 watch /test/subnode token 100 +2 rm /test +1 waitwatch +1 ackwatch token' | ./xs_test 2>&1`" = "1:/test/subnode:token" ] + +# Watch should not double-send after we ack, even if we did something in between. +[ "`echo -e '1 watch /test2 token 100 +2 write /test2/foo create contents2 +1 waitwatch +1 read /test2/foo +1 ackwatch token +1 waitwatch' | ./xs_test 2>&1`" = "1:/test2/foo:token +1:contents2 +1:waitwatch timeout" ]
tools/xenstore/testsuite/08transaction.sh +25 -0
@@ -52,3 +52,28 @@ 1 dir / 1 commit' | ./xs_test 2>&1`" = "1:dir FATAL: 1: commit: Connection timed out" ] + +# Events inside transactions don't trigger watches until (successful) commit. +[ "`echo -e '1 watch / token 100 +2 start / +2 mkdir /dir/sub +1 waitwatch' | ./xs_test 2>&1`" = "1:waitwatch timeout" ] +[ "`echo -e '1 watch / token 100 +2 start / +2 mkdir /dir/sub +2 abort +1 waitwatch' | ./xs_test 2>&1`" = "1:waitwatch timeout" ] +[ "`echo -e '1 watch / token 100 +2 start / +2 mkdir /dir/sub +2 commit +1 waitwatch +1 ackwatch token' | ./xs_test 2>&1`" = "1:/dir/sub:token" ] + +# Rm inside transaction works like rm outside: children get notified. +[ "`echo -e '1 watch /dir/sub token 100 +2 start / +2 rm /dir +2 commit +1 waitwatch +1 ackwatch token' | ./xs_test 2>&1`" = "1:/dir/sub:token" ]
tools/xenstore/testsuite/10domain-homedir.sh +8 -0
@@ -10,3 +10,11 @@ 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 0 +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/12readonly.sh +1 -1
@@ -14,7 +14,7 @@ start / abort' | ./xs_test --readonly 2>&1`" = "test contents -0 NONE" ] +0 READ" ] # These don't work [ "`echo 'write /test2 create contents' | ./xs_test --readonly 2>&1`" = "FATAL: write: Read-only file system" ]
tools/xenstore/xenstored_core.c +111 -17
229 lines not on this page · raw message
tools/xenstore/xenstored_core.h +5 -0
@@ -143,4 +143,9 @@/* Read entire contents of a talloced fd. */ void *read_all (int *fd,unsigned int *size); +/* Tracing infrastructure. */ +void trace_create (const void *data,const char *type); +void trace_destroy (const void *data,const char *type); +void trace_watch_timeout (const struct connection *conn,const char *node,const char *token); +#endif /* _XENSTORED_CORE_H */
tools/xenstore/xenstored_domain.c +2 -2
@@ -273,7 +273,7 @@ domain = talloc(in, struct domain); domain->domid =atoi (vec[0 ]); domain->port =atoi (vec[2 ]); -if (!domain->port || !domain->domid || !is_valid_nodename (vec[3 ])) +if ((domain->port <=0 ) || !is_valid_nodename (vec[3 ]))return send_error (conn,EINVAL ); domain->path =talloc_strdup (domain, vec[3 ]); domain->page = xc_map_foreign_range(*xc_handle, domain->domid,
@@ -349,7 +349,7 @@return send_error (conn,EINVAL ); domid =atoi (domid_str); -if (domid ==0 ) +if (domid ==DOMID_SELF ) domain = conn->domain;else domain =find_domain_by_domid (domid);
tools/xenstore/xenstored_domain.h +0 -2
@@ -16,7 +16,6 @@along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef _XENSTORED_DOMAIN_H#define _XENSTORED_DOMAIN_H
@@ -36,5 +35,4 @@/* Returns the implicit path of a connection (only domains have this) */ const char *get_implicit_path (const struct connection *conn); -#endif /* _XENSTORED_DOMAIN_H */
tools/xenstore/xenstored_transaction.c +9 -4
@@ -41,6 +41,9 @@/* The name of the node. */ char *node; + +/* And the children? (ie. rm) */ +bool recurse; };struct transaction
@@ -119,7 +122,7 @@/* Callers get a change node (which can fail) and only commit after they've * finished. This way they don't have to unwind eg. a write. */ -void add_change_node (struct transaction *trans,const char *node) +void add_change_node (struct transaction *trans,const char *node,bool recurse) {struct changed_node *i;
@@ -132,7 +135,7 @@ i = talloc(trans, struct changed_node); i->node =talloc_strdup (i, node); -INIT_LIST_HEAD (&i->list); + i->recurse = recurse;list_add_tail (&i->list, &trans->changes); }
@@ -176,6 +179,7 @@struct transaction *trans = _transaction;list_del (&trans->list); +trace_destroy (trans,"transaction" );return destroy_path (trans->divert); }
@@ -263,13 +267,14 @@timerclear (&transaction->timeout); transaction->destined_to_fail = false;list_add_tail (&transaction->list, &transactions); - conn->transaction = transaction;talloc_set_destructor (transaction, destroy_transaction); +trace_create (transaction,"transaction" );if (!copy_dir (dir, transaction->divert))return send_error (conn, errno);talloc_steal (conn, transaction); + conn->transaction = transaction;return send_ack (transaction->conn,XS_TRANSACTION_START ); }
@@ -292,7 +297,7 @@/* Fire off the watches for everything that changed. */ list_for_each_entry (i, &trans->changes, list) -fire_watches (NULL , i->node); +fire_watches (NULL , i->node, i->recurse);return true; }
tools/xenstore/xenstored_transaction.h +1 -1
@@ -40,7 +40,7 @@char *node_dir_inside_transaction (struct transaction *t,const char *node);/* This node was changed: can fail and longjmp. */ -void add_change_node (struct transaction *trans,const char *node); +void add_change_node (struct transaction *trans,const char *node,bool recurse);/* Get shortest timeout: leave tv unset if none. */ void shortest_transaction_timeout (struct timeval *tv);
tools/xenstore/xenstored_watch.c +108 -46
282 lines not on this page · raw message
tools/xenstore/xenstored_watch.h +2 -2
@@ -32,8 +32,8 @@/* Look through our watches: if any of them have an event, queue it. */ void queue_next_event (struct connection *conn); -/* Fire all watches. */ -void fire_watches (struct transaction *trans,const char *node); +/* Fire all watches: recurse means all the children are effected (ie. rm) */ +void fire_watches (struct transaction *trans,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.h +2 -2
@@ -47,7 +47,7 @@/* Get the value of a single file, nul terminated. * Returns a malloced value: call free() on it after use. -* len indicates length in bytes, not including the nul. +* len indicates length in bytes, not including terminator. */ void *xs_read (struct xs_handle *h,const char *path,unsigned int *len);
@@ -103,7 +103,7 @@*/ bool xs_acknowledge_watch (struct xs_handle *h,const char *token); -/* Remove a watch on a node. +/* Remove a watch on a node: implicitly acks any outstanding watch. * Returns false on failure (no watch on that node). */ bool xs_unwatch (struct xs_handle *h,const char *path,const char *token);
tools/xenstore/xs_random.c +40 -22
101 lines not on this page · raw message
Signature · 1 line
A bad analogy is like a leaky screwdriver -- Richard Braakman