[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] [BLKTAP] Blktapctrl: Add asynchronous watch on dom0 name entry for blktapctrl on startup. This patch cleans up the synchronisation issues between blktapctrl and xend at initialisation if the Dom0 entries have not yet been populated.



# HG changeset patch
# User jchesterfield@xxxxxxxxxxxxxxxxxxxxxxx
# Node ID a72fdb6a19a1fd65415773a5b6fa1aa39efacf63
# Parent  ad926cc0a50e2808bbfd8cd1a446471cc8465516
[BLKTAP] Blktapctrl: Add asynchronous watch on dom0 name entry for blktapctrl 
on startup. This patch cleans up the synchronisation issues between blktapctrl 
and xend at initialisation if the Dom0 entries have not yet been populated.

Signed-off-by: Julian Chesterfield <julian@xxxxxxxxxxxxx>
---
 tools/blktap/drivers/blktapctrl.c |   16 +++----
 tools/blktap/lib/blktaplib.h      |    4 -
 tools/blktap/lib/xenbus.c         |   77 ++++++++++++++++++++++++++++++++++----
 tools/blktap/lib/xs_api.c         |    4 -
 tools/blktap/lib/xs_api.h         |    2 
 5 files changed, 82 insertions(+), 21 deletions(-)

diff -r ad926cc0a50e -r a72fdb6a19a1 tools/blktap/drivers/blktapctrl.c
--- a/tools/blktap/drivers/blktapctrl.c Thu Oct 05 10:09:25 2006 +0100
+++ b/tools/blktap/drivers/blktapctrl.c Thu Oct 05 10:55:13 2006 +0100
@@ -669,6 +669,7 @@ int main(int argc, char *argv[])
                goto open_failed;
        }
 
+
  retry:
        /* Set up store connection and watch. */
        h = xs_daemon_open();
@@ -682,15 +683,14 @@ int main(int argc, char *argv[])
                 } else goto open_failed;
        }
        
-       ret = add_blockdevice_probe_watch(h, "Domain-0");
-       if (ret != 0) {
+       ret = setup_probe_watch(h);
+       if (ret < 0) {
                DPRINTF("Failed adding device probewatch\n");
-                if (count < MAX_ATTEMPTS) {
-                        count++;
-                        sleep(2);
-                        xs_daemon_close(h);
-                        goto retry;
-                } else goto open_failed;
+               xs_daemon_close(h);
+               goto open_failed;
+       } else {
+               DPRINTF("Added probe %s\n", 
+                      (ret ? "ASYNCHRONOUSLY":"SYNCHRONOUSLY"));
        }
 
        ioctl(ctlfd, BLKTAP_IOCTL_SETMODE, BLKTAP_MODE_INTERPOSE );
diff -r ad926cc0a50e -r a72fdb6a19a1 tools/blktap/lib/blktaplib.h
--- a/tools/blktap/lib/blktaplib.h      Thu Oct 05 10:09:25 2006 +0100
+++ b/tools/blktap/lib/blktaplib.h      Thu Oct 05 10:55:13 2006 +0100
@@ -193,8 +193,8 @@ typedef struct msg_pid {
 #define CTLMSG_PID_RSP     10
 
 /* xenstore/xenbus: */
-extern int add_blockdevice_probe_watch(struct xs_handle *h, 
-                                       const char *domname);
+#define DOMNAME "Domain-0"
+int setup_probe_watch(struct xs_handle *h);
 int xs_fire_next_watch(struct xs_handle *h);
 
 
diff -r ad926cc0a50e -r a72fdb6a19a1 tools/blktap/lib/xenbus.c
--- a/tools/blktap/lib/xenbus.c Thu Oct 05 10:09:25 2006 +0100
+++ b/tools/blktap/lib/xenbus.c Thu Oct 05 10:55:13 2006 +0100
@@ -356,16 +356,11 @@ static void ueblktap_probe(struct xs_han
  *are created, we initalise the state and attach a disk.
  */
 
-int add_blockdevice_probe_watch(struct xs_handle *h, const char *domname)
-{
-       char *domid, *path;
+int add_blockdevice_probe_watch(struct xs_handle *h, const char *domid)
+{
+       char *path;
        struct xenbus_watch *vbd_watch;
        int er;
-       
-       domid = get_dom_domid(h, domname);
-
-       DPRINTF("%s: %s\n", 
-               domname, (domid != NULL) ? domid : "[ not found! ]");
        
        asprintf(&path, "/local/domain/%s/backend/tap", domid);
        if (path == NULL) 
@@ -385,3 +380,69 @@ int add_blockdevice_probe_watch(struct x
        }
        return 0;
 }
+
+/*
+ *Asynch callback to check for /local/domain/<DOMID>/name
+ */
+void check_dom(struct xs_handle *h, struct xenbus_watch *w, 
+              const char *bepath_im) {
+       char *domid = NULL;
+
+       domid = get_dom_domid(h);
+       if (domid) {
+               add_blockdevice_probe_watch(h, domid);
+               free(domid);
+               unregister_xenbus_watch(h, w);
+       }
+       return; 
+}
+
+/*
+ *We must wait for xend to register /local/domain/<DOMID>
+ */
+int watch_for_domid(struct xs_handle *h)
+{
+       struct xenbus_watch *domid_watch;
+       char *path = NULL;
+       int er;
+
+       asprintf(&path, "/local/domain");
+       if (path == NULL) 
+               return -ENOMEM;
+
+       domid_watch = (struct xenbus_watch *)malloc(sizeof(struct 
xenbus_watch));
+       if (!domid_watch) {
+               DPRINTF("ERROR: unable to malloc domid_watch [%s]\n", path);
+               return -EINVAL;
+       }       
+       domid_watch->node     = path;
+       domid_watch->callback = check_dom;
+       er = register_xenbus_watch(h, domid_watch);
+       if (er == 0) {
+               DPRINTF("ERROR: adding vbd probe watch %s\n", path);
+               return -EINVAL;
+       }
+       if (path == NULL) 
+               return -ENOMEM; 
+       return 1;
+}
+
+int setup_probe_watch(struct xs_handle *h)
+{
+       char *domid = NULL, *path;
+       int ret;
+       
+       domid = get_dom_domid(h);
+
+       if (!domid) {
+                /*Asynchronous path*/
+               ret = watch_for_domid(h);
+               goto finish;
+       } else {
+               /*Synchronous path*/
+               ret = add_blockdevice_probe_watch(h, domid);
+               free(domid);
+       }
+ finish:
+       return ret;
+}
diff -r ad926cc0a50e -r a72fdb6a19a1 tools/blktap/lib/xs_api.c
--- a/tools/blktap/lib/xs_api.c Thu Oct 05 10:09:25 2006 +0100
+++ b/tools/blktap/lib/xs_api.c Thu Oct 05 10:55:13 2006 +0100
@@ -165,7 +165,7 @@ int xs_exists(struct xs_handle *h, const
  * This assumes that the domain name we are looking for is unique. 
  * Name parameter Domain-0 
  */
-char *get_dom_domid(struct xs_handle *h, const char *name)
+char *get_dom_domid(struct xs_handle *h)
 {
        char **e, *val, *domid = NULL;
        unsigned int num, len;
@@ -187,7 +187,7 @@ char *get_dom_domid(struct xs_handle *h,
                if (val == NULL)
                        continue;
                
-               if (strcmp(val, name) == 0) {
+               if (strcmp(val, DOMNAME) == 0) {
                        /* match! */
                        asprintf(&path, "/local/domain/%s/domid", e[i]);
                        domid = xs_read(h, xth, path, &len);
diff -r ad926cc0a50e -r a72fdb6a19a1 tools/blktap/lib/xs_api.h
--- a/tools/blktap/lib/xs_api.h Thu Oct 05 10:09:25 2006 +0100
+++ b/tools/blktap/lib/xs_api.h Thu Oct 05 10:55:13 2006 +0100
@@ -42,7 +42,7 @@ int xs_printf(struct xs_handle *h, const
 int xs_printf(struct xs_handle *h, const char *dir, const char *node, 
              const char *fmt, ...);
 int xs_exists(struct xs_handle *h, const char *path);
-char *get_dom_domid(struct xs_handle *h, const char *name);
+char *get_dom_domid(struct xs_handle *h);
 int convert_dev_name_to_num(char *name);
 int register_xenbus_watch(struct xs_handle *h, struct xenbus_watch *watch);
 int unregister_xenbus_watch(struct xs_handle *h, struct xenbus_watch *watch);

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


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.