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-devel

Re: [Xen-devel] xenstore test crash

On Thu, 2005-06-09 at 22:21 -0500, Paul Larson wrote:
> Yeah, seemed odd to me too, but it was easily reproducible as long as I 
> was using --readonly.  Without the --readonly flag, the test passed with 
> no crash.

Untested code is buggy code.  Here's the patch (should apply with maybe
some minor fixups).

Rusty.

Index: xs_test.c
===================================================================
RCS file: /var/cvs/xeno-unstable/tools/xenstore/xs_test.c,v
retrieving revision 1.7
diff -u -r1.7 xs_test.c
--- xs_test.c   8 Jun 2005 09:06:12 -0000       1.7
+++ xs_test.c   10 Jun 2005 14:06:40 -0000
@@ -176,11 +176,11 @@
             "  watch <path> <token> <prio>\n"
             "  waitwatch\n"
             "  ackwatch <token>\n"
-            "  unwatch <path>\n"
+            "  unwatch <path> <token>\n"
             "  close\n"
             "  start <node>\n"
             "  abort\n"
-            "  introduce <domid> <mfn> <eventchn>\n"
+            "  introduce <domid> <mfn> <eventchn> <path>\n"
             "  commit\n"
             "  sleep <seconds>\n"
             "  dump\n");
Index: xsdaemon_core.c
===================================================================
RCS file: /var/cvs/xeno-unstable/tools/xenstore/xsdaemon_core.c,v
retrieving revision 1.25
diff -u -r1.25 xsdaemon_core.c
--- xsdaemon_core.c     9 Jun 2005 04:52:01 -0000       1.25
+++ xsdaemon_core.c     10 Jun 2005 14:06:41 -0000
@@ -645,7 +645,7 @@
                return false;
        }
 
-       if (!conn->write && (perm & XS_PERM_WRITE)) {
+       if (!conn->can_write && (perm & XS_PERM_WRITE)) {
                errno = EROFS;
                return false;
        }
@@ -972,9 +972,12 @@
                return do_set_perms(conn, in);
 
        case XS_SHUTDOWN:
+               /* FIXME: Implement gentle shutdown too. */
                /* Only tools can do this. */
                if (conn->id != 0)
                        return send_error(conn, EACCES);
+               if (!conn->can_write)
+                       return send_error(conn, EROFS);
                send_ack(conn, XS_SHUTDOWN);
                /* Everything hangs off auto-free context, freed at exit. */
                exit(0);
@@ -1173,6 +1176,7 @@
        new->transaction = NULL;
        new->write = write;
        new->read = read;
+       new->can_write = true;
 
        talloc_set_fail_handler(out_of_mem, &talloc_fail);
        if (setjmp(talloc_fail)) {
@@ -1206,10 +1210,11 @@
        if (fd < 0)
                return;
 
-       conn = new_connection(canwrite ? writefd : NULL, readfd);
-       if (conn)
+       conn = new_connection(writefd, readfd);
+       if (conn) {
                conn->fd = fd;
-       else
+               conn->can_write = canwrite;
+       } else
                close(fd);
 }
 
Index: xsdaemon_core.h
===================================================================
RCS file: /var/cvs/xeno-unstable/tools/xenstore/xsdaemon_core.h,v
retrieving revision 1.9
diff -u -r1.9 xsdaemon_core.h
--- xsdaemon_core.h     8 Jun 2005 09:06:12 -0000       1.9
+++ xsdaemon_core.h     10 Jun 2005 14:06:42 -0000
@@ -56,6 +56,9 @@
        /* Are we blocked waiting for a transaction to end?  Contains node. */
        char *blocked;
 
+       /* Is this a read-only connection? */
+       bool can_write;
+
        /* Are we waiting for a watch event ack? */
        bool waiting_for_ack;
 
Index: xsdaemon_domain.c
===================================================================
RCS file: /var/cvs/xeno-unstable/tools/xenstore/xsdaemon_domain.c,v
retrieving revision 1.16
diff -u -r1.16 xsdaemon_domain.c
--- xsdaemon_domain.c   6 Jun 2005 01:30:55 -0000       1.16
+++ xsdaemon_domain.c   10 Jun 2005 14:06:42 -0000
@@ -271,6 +271,9 @@
        if (conn->id != 0)
                return send_error(conn, EACCES);
 
+       if (!conn->can_write)
+               return send_error(conn, EROFS);
+
        /* Hang domain off "in" until we're finished. */
        domain = talloc(in, struct domain);
        domain->domid = atoi(vec[0]);

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


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