[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 2/7] libvchan: create xenstore entries in one transaction



This will prevent race when client waits for server with xs_watch - all
entries should appear at once.

Signed-off-by: Marek Marczykowski <marmarek@xxxxxxxxxxxxxxxxxxxxxx>
---
 tools/libvchan/init.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/tools/libvchan/init.c b/tools/libvchan/init.c
index f0d2505..dbdcc6c 100644
--- a/tools/libvchan/init.c
+++ b/tools/libvchan/init.c
@@ -234,6 +234,7 @@ static int init_xs_srv(struct libxenvchan *ctrl, int 
domain, const char* xs_base
        char buf[64];
        char ref[16];
        char* domid_str = NULL;
+       xs_transaction_t xs_trans = NULL;
        xs = xs_domain_open();
        if (!xs)
                goto fail;
@@ -249,20 +250,29 @@ static int init_xs_srv(struct libxenvchan *ctrl, int 
domain, const char* xs_base
        perms[1].id = domain;
        perms[1].perms = XS_PERM_READ;
 
+retry_transaction:
+       xs_trans = xs_transaction_start(xs);
+       if (!xs_trans)
+               goto fail_xs_open;
+
        snprintf(ref, sizeof ref, "%d", ring_ref);
        snprintf(buf, sizeof buf, "%s/ring-ref", xs_base);
-       if (!xs_write(xs, 0, buf, ref, strlen(ref)))
+       if (!xs_write(xs, xs_trans, buf, ref, strlen(ref)))
                goto fail_xs_open;
-       if (!xs_set_permissions(xs, 0, buf, perms, 2))
+       if (!xs_set_permissions(xs, xs_trans, buf, perms, 2))
                goto fail_xs_open;
 
        snprintf(ref, sizeof ref, "%d", ctrl->event_port);
        snprintf(buf, sizeof buf, "%s/event-channel", xs_base);
-       if (!xs_write(xs, 0, buf, ref, strlen(ref)))
+       if (!xs_write(xs, xs_trans, buf, ref, strlen(ref)))
                goto fail_xs_open;
-       if (!xs_set_permissions(xs, 0, buf, perms, 2))
+       if (!xs_set_permissions(xs, xs_trans, buf, perms, 2))
                goto fail_xs_open;
 
+       if (!xs_transaction_end(xs, xs_trans, 0))
+               if (errno == EAGAIN)
+                       goto retry_transaction;
+
        ret = 0;
  fail_xs_open:
        free(domid_str);
-- 
1.8.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.