xen: handle backend deletion from xenstore
authorStefano Stabellini <stefano.stabellini@eu.citrix.com>
Fri, 30 Mar 2012 14:33:03 +0000 (14:33 +0000)
committerStefano Stabellini <stefano.stabellini@eu.citrix.com>
Fri, 13 Apr 2012 17:34:26 +0000 (17:34 +0000)
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
hw/xen_backend.c
hw/xen_disk.c

index 2673ace185f2ab95e6371705957a0c26adbad716..66cb144397042421deabdd4aa20980f1b867200c 100644 (file)
@@ -592,7 +592,7 @@ static void xenstore_update_be(char *watch, char *type, int dom,
                                struct XenDevOps *ops)
 {
     struct XenDevice *xendev;
-    char path[XEN_BUFSIZE], *dom0;
+    char path[XEN_BUFSIZE], *dom0, *bepath;
     unsigned int len, dev;
 
     dom0 = xs_get_domain_path(xenstore, 0);
@@ -611,15 +611,16 @@ static void xenstore_update_be(char *watch, char *type, int dom,
         return;
     }
 
-    if (0) {
-        /* FIXME: detect devices being deleted from xenstore ... */
-        xen_be_del_xendev(dom, dev);
-    }
-
     xendev = xen_be_get_xendev(type, dom, dev, ops);
     if (xendev != NULL) {
-        xen_be_backend_changed(xendev, path);
-        xen_be_check_state(xendev);
+        bepath = xs_read(xenstore, 0, xendev->be, &len);
+        if (bepath == NULL) {
+            xen_be_del_xendev(dom, dev);
+        } else {
+            free(bepath);
+            xen_be_backend_changed(xendev, path);
+            xen_be_check_state(xendev);
+        }
     }
 }
 
index 9719395b09dd262fbaf7bd5b2fe777a630726758..22dbd10303f17e795667e6e266bc9730afbc1e6f 100644 (file)
@@ -745,6 +745,10 @@ static int blk_free(struct XenDevice *xendev)
     struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);
     struct ioreq *ioreq;
 
+    if (blkdev->bs || blkdev->sring) {
+        blk_disconnect(xendev);
+    }
+
     while (!QLIST_EMPTY(&blkdev->freelist)) {
         ioreq = QLIST_FIRST(&blkdev->freelist);
         QLIST_REMOVE(ioreq, list);