From: Paul Durrant <Paul.Durrant@citrix.com>
To: "'Marek Marczykowski-Górecki'" <marmarek@invisiblethingslab.com>,
"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Cc: Ian Jackson <Ian.Jackson@citrix.com>, Wei Liu <wei.liu2@citrix.com>
Subject: Re: [PATCH] libvchan: create xenstore entries in one transaction
Date: Wed, 31 Oct 2018 10:08:26 +0000 [thread overview]
Message-ID: <e8b0cc9d963d4afca2c9cd140cfe8567@AMSPEX02CL03.citrite.net> (raw)
In-Reply-To: <20181030234905.26142-1-marmarek@invisiblethingslab.com>
> -----Original Message-----
> From: Xen-devel [mailto:xen-devel-bounces@lists.xenproject.org] On Behalf
> Of Marek Marczykowski-Górecki
> Sent: 30 October 2018 23:49
> To: xen-devel@lists.xenproject.org
> Cc: Wei Liu <wei.liu2@citrix.com>; Ian Jackson <Ian.Jackson@citrix.com>;
> Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
> Subject: [Xen-devel] [PATCH] 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.
Watches should be put on the "state" key to avoid this kind of thing. That key should always be the last thing modified and hence there should never really be the need for xenstore transactions at all.
Paul
>
> Signed-off-by: Marek Marczykowski-Górecki
> <marmarek@invisiblethingslab.com>
> ---
> tools/libvchan/init.c | 21 ++++++++++++++++-----
> 1 file changed, 16 insertions(+), 5 deletions(-)
>
> diff --git a/tools/libvchan/init.c b/tools/libvchan/init.c
> index 0b3759a056..ba5a6eb29e 100644
> --- a/tools/libvchan/init.c
> +++ b/tools/libvchan/init.c
> @@ -250,6 +250,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;
> @@ -265,21 +266,31 @@ 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;
>
> - ret = 0;
> + if (!xs_transaction_end(xs, xs_trans, 0)) {
> + if (errno == EAGAIN)
> + goto retry_transaction;
> + } else {
> + ret = 0;
> + }
> fail_xs_open:
> free(domid_str);
> xs_daemon_close(xs);
> --
> 2.17.2
>
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xenproject.org
> https://lists.xenproject.org/mailman/listinfo/xen-devel
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2018-10-31 10:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-30 23:49 [PATCH] libvchan: create xenstore entries in one transaction Marek Marczykowski-Górecki
2018-10-31 9:41 ` Wei Liu
2018-10-31 10:08 ` Paul Durrant [this message]
2018-10-31 10:17 ` Wei Liu
2018-10-31 10:40 ` Paul Durrant
2018-10-31 10:43 ` 'Marek Marczykowski-Górecki'
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e8b0cc9d963d4afca2c9cd140cfe8567@AMSPEX02CL03.citrite.net \
--to=paul.durrant@citrix.com \
--cc=Ian.Jackson@citrix.com \
--cc=marmarek@invisiblethingslab.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).