All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marek Marczykowski <marmarek@invisiblethingslab.com>
To: David Vrabel <david.vrabel@citrix.com>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>,
	Ian Jackson <ian.jackson@eu.citrix.com>,
	Ian Campbell <ian.campbell@citrix.com>,
	xen-devel@lists.xen.org
Subject: Re: [PATCH 2/7] libvchan: create xenstore entries in one	transaction
Date: Mon, 29 Apr 2013 00:43:22 +0200	[thread overview]
Message-ID: <517DA60A.4060005@invisiblethingslab.com> (raw)
In-Reply-To: <517AC1BF.8060801@citrix.com>


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

On 26.04.2013 20:04, David Vrabel wrote:
> On 21/04/13 02:46, Marek Marczykowski wrote:
>> This will prevent race when client waits for server with xs_watch - all
>> entries should appear at once.
> 
> Aren't xenstore writes strictly ordered?  The client just needs to read
> the keys in the inverse order to avoid races, yes?

IMO this isn't the best idea - application gives only xenstore directory to
libxenvchan_*_init, I see no reason to assume anything in application:
a) what entries will be created/expected there,
b) in which order,
c) and it will not be changed in the future.

Adding it in one transaction seems to be better idea. Also this will fix
hypothetical race between two simultaneously started servers - when entries
are added without transaction it can happen to end up with event-channel from
one server and ring-ref from another.


> David
> 
>>
>> Signed-off-by: Marek Marczykowski <marmarek@invisiblethingslab.com>
>> ---
>>  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);
> 


-- 
Best Regards / Pozdrawiam,
Marek Marczykowski
Invisible Things Lab


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 555 bytes --]

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

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

  reply	other threads:[~2013-04-28 22:43 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-26 14:45 [PATCH 0/7] Optionally add libvchan to stubdom Marek Marczykowski
2013-04-21  1:46 ` [PATCH 2/7] libvchan: create xenstore entries in one transaction Marek Marczykowski
2013-04-26 18:04   ` David Vrabel
2013-04-28 22:43     ` Marek Marczykowski [this message]
2013-04-22  1:44 ` [PATCH 1/7] minios: enhance xenstore available for stubdoms Marek Marczykowski
2013-04-28 22:34   ` Samuel Thibault
2013-04-22  1:50 ` [PATCH 3/7] libvchan: remove unnecessary includes Marek Marczykowski
2013-04-22  2:10 ` [PATCH 6/7] stubdom: make libvchan available in stubdom Marek Marczykowski
2013-04-28 22:46   ` Samuel Thibault
2013-04-23  3:16 ` [PATCH 4/7] minios: add gnttab_find_grant_of_page Marek Marczykowski
2013-04-28 22:41   ` Samuel Thibault
2013-04-28 22:51     ` Marek Marczykowski
2013-04-23  3:17 ` [PATCH 5/7] libxc: implement gntshr for minios Marek Marczykowski
2013-04-28 22:44   ` Samuel Thibault
2013-04-28 23:17     ` Marek Marczykowski
2013-04-28 23:22       ` Samuel Thibault
2013-04-23  3:25 ` [PATCH 7/7] libvchan: do not use xc_gntshr_share_page_notify in Mini-OS Marek Marczykowski
2013-04-28 22:48   ` Samuel Thibault
2013-04-28 23:00     ` Marek Marczykowski
2013-04-26 14:55 ` [PATCH 0/7] Optionally add libvchan to stubdom George Dunlap
2013-04-26 14:56   ` Marek Marczykowski
2013-04-26 14:57     ` George Dunlap
2013-04-26 15:02       ` Marek Marczykowski
2013-04-26 15:03 ` Ian Campbell
2013-04-26 16:41   ` Daniel De Graaf
2013-04-28 22:52 ` Samuel Thibault
2013-04-28 23:08   ` Marek Marczykowski
2013-04-30 21:22     ` Samuel Thibault

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=517DA60A.4060005@invisiblethingslab.com \
    --to=marmarek@invisiblethingslab.com \
    --cc=david.vrabel@citrix.com \
    --cc=ian.campbell@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=xen-devel@lists.xen.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 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.