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

[Xen-changelog] [xen-unstable] xenstore: Make sure that libxs reports an

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] xenstore: Make sure that libxs reports an error if xenstored drops
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Thu, 27 May 2010 01:45:15 -0700
Delivery-date: Thu, 27 May 2010 01:46:14 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1274944826 -3600
# Node ID 5be2d2a7f445bab61617b09627ca7f6a8ec90a69
# Parent  22ecd71786082c8361f019a5e6f41b8f8a752c8b
xenstore: Make sure that libxs reports an error if xenstored drops
the connection, rather than getting stuck forever.

Patch from: Steven Smith <steven.smith@xxxxxxxxxxxxx>
Signed-off-by: Tim Deegan <Tim.Deegan@xxxxxxxxxx>
---
 tools/xenstore/xs.c |   36 +++++++++++++++++++++++++++++++++---
 1 files changed, 33 insertions(+), 3 deletions(-)

diff -r 22ecd7178608 -r 5be2d2a7f445 tools/xenstore/xs.c
--- a/tools/xenstore/xs.c       Thu May 27 08:19:47 2010 +0100
+++ b/tools/xenstore/xs.c       Thu May 27 08:20:26 2010 +0100
@@ -94,6 +94,8 @@ struct xs_handle {
  */
 #define cleanup_pop(run)        ((void)0); pthread_cleanup_pop(run)
 
+#define read_thread_exists(h)  (h->read_thr_exists)
+
 static void *read_thread(void *arg);
 
 #else /* !defined(USE_PTHREAD) */
@@ -112,6 +114,7 @@ struct xs_handle {
 #define condvar_wait(c,m,hnd)  read_message(hnd)
 #define cleanup_push(f, a)     ((void)0)
 #define cleanup_pop(run)       ((void)0)
+#define read_thread_exists(h)  (0)
 
 #endif
 
@@ -330,16 +333,25 @@ static void *read_reply(
 {
        struct xs_stored_msg *msg;
        char *body;
+       int read_from_thread;
+
+       read_from_thread = read_thread_exists(h);
 
 #ifdef USE_PTHREAD
        /* Read from comms channel ourselves if there is no reader thread. */
-       if (!h->read_thr_exists && (read_message(h) == -1))
+       if (!read_from_thread && (read_message(h) == -1))
                return NULL;
 #endif
 
        mutex_lock(&h->reply_mutex);
-       while (list_empty(&h->reply_list))
+       while (list_empty(&h->reply_list) && (!read_from_thread || 
read_thread_exists(h)))
                condvar_wait(&h->reply_condvar, &h->reply_mutex, h);
+       if (read_from_thread && !read_thread_exists(h)) {
+               mutex_unlock(&h->reply_mutex);
+               errno = EINVAL;
+               return NULL;
+       }
+       assert(!list_empty(&h->reply_list));
        msg = list_top(&h->reply_list, struct xs_stored_msg, list);
        list_del(&msg->list);
        assert(list_empty(&h->reply_list));
@@ -647,8 +659,13 @@ char **xs_read_watch(struct xs_handle *h
        mutex_lock(&h->watch_mutex);
 
        /* Wait on the condition variable for a watch to fire. */
-       while (list_empty(&h->watch_list))
+       while (list_empty(&h->watch_list) && read_thread_exists(h))
                condvar_wait(&h->watch_condvar, &h->watch_mutex, h);
+       if (!read_thread_exists(h)) {
+               mutex_unlock(&h->watch_mutex);
+               errno = EINVAL;
+               return NULL;
+       }
        msg = list_top(&h->watch_list, struct xs_stored_msg, list);
        list_del(&msg->list);
 
@@ -944,6 +961,19 @@ static void *read_thread(void *arg)
        while (read_message(h) != -1)
                continue;
 
+       /* Kick anyone waiting for a reply */
+       pthread_mutex_lock(&h->request_mutex);
+       h->read_thr_exists = 0;
+       pthread_mutex_unlock(&h->request_mutex);
+
+       pthread_mutex_lock(&h->reply_mutex);
+       pthread_cond_signal(&h->reply_condvar);
+       pthread_mutex_unlock(&h->reply_mutex);
+
+       pthread_mutex_lock(&h->watch_mutex);
+       pthread_cond_signal(&h->watch_condvar);
+       pthread_mutex_unlock(&h->watch_mutex);
+
        return NULL;
 }
 #endif

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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] xenstore: Make sure that libxs reports an error if xenstored drops, Xen patchbot-unstable <=