WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

Re: [Xen-devel] [PATCH] libxl: make libxl_wait_for_device_model not racy

To: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
Subject: Re: [Xen-devel] [PATCH] libxl: make libxl_wait_for_device_model not racy
From: Jeremy Fitzhardinge <jeremy@xxxxxxxx>
Date: Wed, 23 Jun 2010 17:50:10 +0100
Cc: xen-devel@xxxxxxxxxxxxxxxxxxx
Delivery-date: Wed, 23 Jun 2010 09:51:18 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <alpine.DEB.2.00.1006231059110.22638@kaball-desktop>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <alpine.DEB.2.00.1006231059110.22638@kaball-desktop>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100430 Fedora/3.0.4-2.fc12 Lightning/1.0b2pre Thunderbird/3.0.4
On 06/23/2010 12:15 PM, Stefano Stabellini wrote:
> Hi all,
> at the moment libxl_wait_for_device_model waits on a xenstore watch
> before checking the current value of the xenstore node, that might
> contain already the value the function was looking for.
> This patch changes libxl_wait_for_device_model so that it checks the
> value of the xenstore node first, then waits for the watch.
>   

That can't help because it's still racy: what if the value changes
between the first check and the wait?  The watch must fire immediately
if the value is already in the desired state, or there's an unavoidable
deadlock.

On the other hand, the check-then-wait pattern reads more clearly, I think.

    J

> Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
>
> ---
>
> diff -r e2f5e4f3481c tools/libxl/libxl_device.c
> --- a/tools/libxl/libxl_device.c      Tue Jun 22 16:22:30 2010 +0100
> +++ b/tools/libxl/libxl_device.c      Wed Jun 23 11:04:49 2010 +0100
> @@ -418,7 +418,7 @@
>      char *path;
>      char *p;
>      unsigned int len;
> -    int rc;
> +    int rc = 0;
>      struct xs_handle *xsh;
>      int nfds;
>      fd_set rfds;
> @@ -432,28 +432,29 @@
>      tv.tv_sec = LIBXL_DEVICE_MODEL_START_TIMEOUT;
>      tv.tv_usec = 0;
>      nfds = xs_fileno(xsh) + 1;
> -    while (tv.tv_sec > 0) {
> +    while (rc > 0 || (!rc && tv.tv_sec > 0)) {
> +        p = xs_read(xsh, XBT_NULL, path, &len);
> +        if (p && (!state || !strcmp(state, p))) {
> +            free(p);
> +            xs_unwatch(xsh, path, path);
> +            xs_daemon_close(xsh);
> +            if (check_callback) {
> +                rc = check_callback(ctx, check_callback_userdata);
> +                if (rc) return rc;
> +            }
> +            return 0;
> +        }
> +        free(p);
> +again:
>          FD_ZERO(&rfds);
>          FD_SET(xs_fileno(xsh), &rfds);
> -        if (select(nfds, &rfds, NULL, NULL, &tv) > 0) {
> +        rc = select(nfds, &rfds, NULL, NULL, &tv);
> +        if (rc > 0) {
>              l = xs_read_watch(xsh, &num);
> -            if (l != NULL) {
> +            if (l != NULL)
>                  free(l);
> -                p = xs_read(xsh, XBT_NULL, path, &len);
> -                if (!p)
> -                    continue;
> -                if (!state || !strcmp(state, p)) {
> -                    free(p);
> -                    xs_unwatch(xsh, path, path);
> -                    xs_daemon_close(xsh);
> -                    if (check_callback) {
> -                        rc = check_callback(ctx, check_callback_userdata);
> -                        if (rc) return rc;
> -                    }
> -                    return 0;
> -                }
> -                free(p);
> -            }
> +            else
> +                goto again;
>          }
>      }
>      xs_unwatch(xsh, path, path);
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@xxxxxxxxxxxxxxxxxxx
> http://lists.xensource.com/xen-devel
>
>   


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel