Patchwork xen: handle backend deletion from xenstore

login
register
mail settings
Submitter Stefano Stabellini
Date April 11, 2012, 1:42 p.m.
Message ID <1334151739-10484-1-git-send-email-stefano.stabellini@eu.citrix.com>
Download mbox | patch
Permalink /patch/151795/
State New
Headers show

Comments

Stefano Stabellini - April 11, 2012, 1:42 p.m.
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
---
 hw/xen_backend.c |   17 +++++++++--------
 hw/xen_disk.c    |    4 ++++
 2 files changed, 13 insertions(+), 8 deletions(-)
Gerd Hoffmann - April 16, 2012, 8:17 a.m.
On 04/11/12 15:42, Stefano Stabellini wrote:
> Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> ---
>  hw/xen_backend.c |   17 +++++++++--------
>  hw/xen_disk.c    |    4 ++++
>  2 files changed, 13 insertions(+), 8 deletions(-)
> 
> diff --git a/hw/xen_backend.c b/hw/xen_backend.c
> index d876cab..555da41 100644
> --- a/hw/xen_backend.c
> +++ b/hw/xen_backend.c
> @@ -589,7 +589,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);
> @@ -608,15 +608,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);
> +        }
>      }
>  }
>  
> diff --git a/hw/xen_disk.c b/hw/xen_disk.c
> index e9bbbf7..8217109 100644
> --- a/hw/xen_disk.c
> +++ b/hw/xen_disk.c
> @@ -824,6 +824,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);

Acked-by: Gerd Hoffmann <kraxel@redhat.com>

cheers,
  Gerd

Patch

diff --git a/hw/xen_backend.c b/hw/xen_backend.c
index d876cab..555da41 100644
--- a/hw/xen_backend.c
+++ b/hw/xen_backend.c
@@ -589,7 +589,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);
@@ -608,15 +608,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);
+        }
     }
 }
 
diff --git a/hw/xen_disk.c b/hw/xen_disk.c
index e9bbbf7..8217109 100644
--- a/hw/xen_disk.c
+++ b/hw/xen_disk.c
@@ -824,6 +824,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);