Patchwork [07/15] xen: handle xenstore events

login
register
mail settings
Submitter Stefano Stabellini
Date Aug. 23, 2010, 9:50 a.m.
Message ID <1282557052-14285-7-git-send-email-stefano.stabellini@eu.citrix.com>
Download mbox | patch
Permalink /patch/62468/
State New
Headers show

Comments

Stefano Stabellini - Aug. 23, 2010, 9:50 a.m.
From: Anthony PERARD <anthony.perard@citrix.com>

Add an handler to process xenstore events.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
---
 target-xen/xenstore.c |   30 +++++++++++++++++++++++++++++-
 1 files changed, 29 insertions(+), 1 deletions(-)

Patch

diff --git a/target-xen/xenstore.c b/target-xen/xenstore.c
index bd74787..331b25f 100644
--- a/target-xen/xenstore.c
+++ b/target-xen/xenstore.c
@@ -1,13 +1,41 @@ 
 #include "hw/xen_backend.h"
 #include "xenstore.h"
 
+static void xenstore_process_event(void *opaque)
+{
+    char **vec;
+    unsigned int num;
+
+    vec = xs_read_watch(xenstore, &num);
+    if (!vec)
+        return;
+
+    free(vec);
+}
+
 int xen_dm_init(void)
 {
+    xenstore = xs_daemon_open();
+    if (!xenstore) {
+        xen_be_printf(NULL, 0, "can't connect to xenstored\n");
+        return -1;
+    }
+
+    if (qemu_set_fd_handler(xs_fileno(xenstore), xenstore_process_event, NULL, NULL) < 0)
+        goto err;
+
     xen_xc = xc_interface_open(NULL, NULL, 0);
     if (xen_xc == NULL) {
         xen_be_printf(NULL, 0, "can't open xen interface\n");
-        return -1;
+        goto err;
     }
 
     return 0;
+
+err:
+    qemu_set_fd_handler(xs_fileno(xenstore), NULL, NULL, NULL);
+    xs_daemon_close(xenstore);
+    xenstore = NULL;
+
+    return -1;
 }