From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marek Marczykowski Subject: Re: [PATCH 2/7] libvchan: create xenstore entries in one transaction Date: Mon, 29 Apr 2013 00:43:22 +0200 Message-ID: <517DA60A.4060005@invisiblethingslab.com> References: <60be83ff5fbc2fff2332e5ab6d32e6335b9543db.1366987505.git.marmarek@invisiblethingslab.com> <517AC1BF.8060801@citrix.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============8321537973738875273==" Return-path: In-Reply-To: <517AC1BF.8060801@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: David Vrabel Cc: Stefano Stabellini , Ian Jackson , Ian Campbell , xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --===============8321537973738875273== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="----enig2ARODUHSPPINCTDKKPDNA" This is an OpenPGP/MIME signed message (RFC 4880 and 3156) ------enig2ARODUHSPPINCTDKKPDNA Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 - al= l >> entries should appear at once. >=20 > 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 entri= es are added without transaction it can happen to end up with event-channel = from one server and ring-ref from another. > David >=20 >> >> Signed-off-by: Marek Marczykowski >> --- >> 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, i= nt domain, const char* xs_base >> char buf[64]; >> char ref[16]; >> char* domid_str =3D NULL; >> + xs_transaction_t xs_trans =3D NULL; >> xs =3D 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 =3D domain; >> perms[1].perms =3D XS_PERM_READ; >> =20 >> +retry_transaction: >> + xs_trans =3D 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; >> =20 >> 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; >> =20 >> + if (!xs_transaction_end(xs, xs_trans, 0)) >> + if (errno =3D=3D EAGAIN) >> + goto retry_transaction; >> + >> ret =3D 0; >> fail_xs_open: >> free(domid_str); >=20 --=20 Best Regards / Pozdrawiam, Marek Marczykowski Invisible Things Lab ------enig2ARODUHSPPINCTDKKPDNA Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.13 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJRfaYLAAoJENuP0xzK19csiscH/2sa5x384yK0pjI7MivcNzsV q1hTn7v3U2i3ZP7LDadeRLGTn4/JRyhYQxnbxFkkZgXJrtjf9swfZFDBKGt04HNE KTLaozokJaYD4PaugBbtBb9wiyC7egUdUdOzD17FNSYKhWdOre1pQbv17NOG1v05 17YRay4b2IV6EXzChplbagHtFfURRv9JhBAr5UbWckxIv14f0WDMo09rmLyPMGtA O/SxeMAOnwTAEIyJAgcMmN4Q1K818ALY7qhxB8z3vRhj+jaFCf2bOQ9/Mh7mD7l6 lag1WJ7FzQ/zbOrvTNA95NdFyIGhDU24NHmfx1/XQZv1YeDz5zZESZo8siSpZQw= =FSoi -----END PGP SIGNATURE----- ------enig2ARODUHSPPINCTDKKPDNA-- --===============8321537973738875273== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --===============8321537973738875273==--