All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libvchan: create xenstore entries in one transaction
@ 2018-10-30 23:49 Marek Marczykowski-Górecki
  2018-10-31  9:41 ` Wei Liu
  2018-10-31 10:08 ` Paul Durrant
  0 siblings, 2 replies; 6+ messages in thread
From: Marek Marczykowski-Górecki @ 2018-10-30 23:49 UTC (permalink / raw)
  To: xen-devel; +Cc: Wei Liu, Ian Jackson, Marek Marczykowski-Górecki

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

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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] libvchan: create xenstore entries in one transaction
  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
  1 sibling, 0 replies; 6+ messages in thread
From: Wei Liu @ 2018-10-31  9:41 UTC (permalink / raw)
  To: Marek Marczykowski-Górecki; +Cc: xen-devel, Ian Jackson, Wei Liu

On Wed, Oct 31, 2018 at 12:49:05AM +0100, Marek Marczykowski-Górecki wrote:
> This will prevent race when client waits for server with xs_watch - all
> entries should appear at once.
> 
> Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>

I would prefer it is written as a while(1){} loop, but that's just a
matter of taste, so:

Acked-by: Wei Liu <wei.liu2@citrix.com>

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] libvchan: create xenstore entries in one transaction
  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
  2018-10-31 10:17   ` Wei Liu
  1 sibling, 1 reply; 6+ messages in thread
From: Paul Durrant @ 2018-10-31 10:08 UTC (permalink / raw)
  To: 'Marek Marczykowski-Górecki', xen-devel; +Cc: Ian Jackson, Wei Liu

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] libvchan: create xenstore entries in one transaction
  2018-10-31 10:08 ` Paul Durrant
@ 2018-10-31 10:17   ` Wei Liu
  2018-10-31 10:40     ` Paul Durrant
  2018-10-31 10:43     ` 'Marek Marczykowski-Górecki'
  0 siblings, 2 replies; 6+ messages in thread
From: Wei Liu @ 2018-10-31 10:17 UTC (permalink / raw)
  To: Paul Durrant
  Cc: xen-devel, Wei Liu, 'Marek Marczykowski-Górecki',
	Ian Jackson

On Wed, Oct 31, 2018 at 10:08:26AM +0000, Paul Durrant wrote:
> > -----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.

AIUI libxenvchan doesn't have a "state" key. We can introduce one now
but we still need to handle old code which doesn't know about the new
key.

I could be wrong about the protocol though.

Wei.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] libvchan: create xenstore entries in one transaction
  2018-10-31 10:17   ` Wei Liu
@ 2018-10-31 10:40     ` Paul Durrant
  2018-10-31 10:43     ` 'Marek Marczykowski-Górecki'
  1 sibling, 0 replies; 6+ messages in thread
From: Paul Durrant @ 2018-10-31 10:40 UTC (permalink / raw)
  Cc: xen-devel, Wei Liu, 'Marek Marczykowski-Górecki',
	Ian Jackson

> -----Original Message-----
> From: Wei Liu [mailto:wei.liu2@citrix.com]
> Sent: 31 October 2018 10:17
> To: Paul Durrant <Paul.Durrant@citrix.com>
> Cc: 'Marek Marczykowski-Górecki' <marmarek@invisiblethingslab.com>; xen-
> devel@lists.xenproject.org; Wei Liu <wei.liu2@citrix.com>; Ian Jackson
> <Ian.Jackson@citrix.com>
> Subject: Re: [Xen-devel] [PATCH] libvchan: create xenstore entries in one
> transaction
> 
> On Wed, Oct 31, 2018 at 10:08:26AM +0000, Paul Durrant wrote:
> > > -----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.
> 
> AIUI libxenvchan doesn't have a "state" key.

It appears you're right. OMG. How on earth is one and supposed to know the state of the other end? This is an awful 'protocol'.

> We can introduce one now
> but we still need to handle old code which doesn't know about the new
> key.
> 

Indeed, but this really should be replaced by a protocol which actually has defined state transitions.

  Paul

> I could be wrong about the protocol though.
> 
> Wei.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] libvchan: create xenstore entries in one transaction
  2018-10-31 10:17   ` Wei Liu
  2018-10-31 10:40     ` Paul Durrant
@ 2018-10-31 10:43     ` 'Marek Marczykowski-Górecki'
  1 sibling, 0 replies; 6+ messages in thread
From: 'Marek Marczykowski-Górecki' @ 2018-10-31 10:43 UTC (permalink / raw)
  To: Wei Liu; +Cc: xen-devel, Paul Durrant, Ian Jackson


[-- Attachment #1.1: Type: text/plain, Size: 1336 bytes --]

On Wed, Oct 31, 2018 at 10:17:03AM +0000, Wei Liu wrote:
> On Wed, Oct 31, 2018 at 10:08:26AM +0000, Paul Durrant wrote:
> > > -----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.
> 
> AIUI libxenvchan doesn't have a "state" key. We can introduce one now
> but we still need to handle old code which doesn't know about the new
> key.

Wei is right, there is no "state" key in libxenvchan.

-- 
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 157 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-10-31 10:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2018-10-31 10:17   ` Wei Liu
2018-10-31 10:40     ` Paul Durrant
2018-10-31 10:43     ` 'Marek Marczykowski-Górecki'

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.