0a122b
From e81a83acac1f44ade1e28879203ca95466dad805 Mon Sep 17 00:00:00 2001
0a122b
From: Fam Zheng <famz@redhat.com>
0a122b
Date: Fri, 17 Jan 2014 03:07:50 +0100
0a122b
Subject: [PATCH 07/34] xen_disk: simplify blk_disconnect with refcnt
0a122b
0a122b
RH-Author: Fam Zheng <famz@redhat.com>
0a122b
Message-id: <1389928083-8921-6-git-send-email-famz@redhat.com>
0a122b
Patchwork-id: 56767
0a122b
O-Subject: [RHEL-7 qemu-kvm PATCH 05/18] xen_disk: simplify blk_disconnect with refcnt
0a122b
Bugzilla: 1041301
0a122b
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
0a122b
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
0a122b
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
0a122b
We call bdrv_attach_dev when initializing whether or not bs is created
0a122b
locally, so call bdrv_detach_dev and let the refcnt handle the
0a122b
lifecycle.
0a122b
0a122b
Signed-off-by: Fam Zheng <famz@redhat.com>
0a122b
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
(cherry picked from commit c0777fe18b08c3a6de0c53325d6b9b75ebb9de9a)
0a122b
Signed-off-by: Fam Zheng <famz@redhat.com>
0a122b
0a122b
Conflicts:
0a122b
	hw/block/xen_disk.c
0a122b
0a122b
Contextual conflict because of backport of 4f8a066b.
0a122b
0a122b
Signed-off-by: Fam Zheng <famz@redhat.com>
0a122b
---
0a122b
 hw/block/xen_disk.c | 11 +++++------
0a122b
 1 file changed, 5 insertions(+), 6 deletions(-)
0a122b
0a122b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
0a122b
---
0a122b
 hw/block/xen_disk.c |   11 +++++------
0a122b
 1 files changed, 5 insertions(+), 6 deletions(-)
0a122b
0a122b
diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c
0a122b
index 138ab94..a2653b2 100644
0a122b
--- a/hw/block/xen_disk.c
0a122b
+++ b/hw/block/xen_disk.c
0a122b
@@ -822,6 +822,9 @@ static int blk_connect(struct XenDevice *xendev)
0a122b
             blkdev->bs = NULL;
0a122b
             return -1;
0a122b
         }
0a122b
+        /* blkdev->bs is not create by us, we get a reference
0a122b
+         * so we can bdrv_unref() unconditionally */
0a122b
+        bdrv_ref(blkdev->bs);
0a122b
     }
0a122b
     bdrv_attach_dev_nofail(blkdev->bs, blkdev);
0a122b
     blkdev->file_size = bdrv_getlength(blkdev->bs);
0a122b
@@ -920,12 +923,8 @@ static void blk_disconnect(struct XenDevice *xendev)
0a122b
     struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);
0a122b
 
0a122b
     if (blkdev->bs) {
0a122b
-        if (!blkdev->dinfo) {
0a122b
-            /* close/delete only if we created it ourself */
0a122b
-            bdrv_close(blkdev->bs);
0a122b
-            bdrv_detach_dev(blkdev->bs, blkdev);
0a122b
-            bdrv_unref(blkdev->bs);
0a122b
-        }
0a122b
+        bdrv_detach_dev(blkdev->bs, blkdev);
0a122b
+        bdrv_unref(blkdev->bs);
0a122b
         blkdev->bs = NULL;
0a122b
     }
0a122b
     xen_be_unbind_evtchn(&blkdev->xendev);
0a122b
-- 
0a122b
1.7.1
0a122b