thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
0a122b
From 33eef488233850a3eeb806bf11d562c86eaacb72 Mon Sep 17 00:00:00 2001
0a122b
From: Fam Zheng <famz@redhat.com>
0a122b
Date: Fri, 17 Jan 2014 03:07:51 +0100
0a122b
Subject: [PATCH 08/34] nbd: use BlockDriverState refcnt
0a122b
0a122b
RH-Author: Fam Zheng <famz@redhat.com>
0a122b
Message-id: <1389928083-8921-7-git-send-email-famz@redhat.com>
0a122b
Patchwork-id: 56768
0a122b
O-Subject: [RHEL-7 qemu-kvm PATCH 06/18] nbd: use BlockDriverState 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
Previously, nbd calls drive_get_ref() on the drive of bs. A BDS doesn't
0a122b
always have associated dinfo, which nbd doesn't care either. We already
0a122b
have BDS ref count, so use it to make it safe for a BDS w/o blockdev.
0a122b
0a122b
Signed-off-by: Fam Zheng <famz@redhat.com>
0a122b
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
(cherry picked from commit 38b54b6dc18ae7e2a32e5ae38b312fb13f0584c8)
0a122b
Signed-off-by: Fam Zheng <famz@redhat.com>
0a122b
---
0a122b
 blockdev-nbd.c | 10 +---------
0a122b
 nbd.c          |  5 +++++
0a122b
 2 files changed, 6 insertions(+), 9 deletions(-)
0a122b
0a122b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
0a122b
---
0a122b
 blockdev-nbd.c |   10 +---------
0a122b
 nbd.c          |    5 +++++
0a122b
 2 files changed, 6 insertions(+), 9 deletions(-)
0a122b
0a122b
diff --git a/blockdev-nbd.c b/blockdev-nbd.c
0a122b
index 95f10c8..922cf56 100644
0a122b
--- a/blockdev-nbd.c
0a122b
+++ b/blockdev-nbd.c
0a122b
@@ -69,12 +69,6 @@ static void nbd_close_notifier(Notifier *n, void *data)
0a122b
     g_free(cn);
0a122b
 }
0a122b
 
0a122b
-static void nbd_server_put_ref(NBDExport *exp)
0a122b
-{
0a122b
-    BlockDriverState *bs = nbd_export_get_blockdev(exp);
0a122b
-    drive_put_ref(drive_get_by_blockdev(bs));
0a122b
-}
0a122b
-
0a122b
 void qmp_nbd_server_add(const char *device, bool has_writable, bool writable,
0a122b
                         Error **errp)
0a122b
 {
0a122b
@@ -105,11 +99,9 @@ void qmp_nbd_server_add(const char *device, bool has_writable, bool writable,
0a122b
         writable = false;
0a122b
     }
0a122b
 
0a122b
-    exp = nbd_export_new(bs, 0, -1, writable ? 0 : NBD_FLAG_READ_ONLY,
0a122b
-                         nbd_server_put_ref);
0a122b
+    exp = nbd_export_new(bs, 0, -1, writable ? 0 : NBD_FLAG_READ_ONLY, NULL);
0a122b
 
0a122b
     nbd_export_set_name(exp, device);
0a122b
-    drive_get_ref(drive_get_by_blockdev(bs));
0a122b
 
0a122b
     n = g_malloc0(sizeof(NBDCloseNotifier));
0a122b
     n->n.notify = nbd_close_notifier;
0a122b
diff --git a/nbd.c b/nbd.c
0a122b
index 2606403..f258cdd 100644
0a122b
--- a/nbd.c
0a122b
+++ b/nbd.c
0a122b
@@ -881,6 +881,7 @@ NBDExport *nbd_export_new(BlockDriverState *bs, off_t dev_offset,
0a122b
     exp->nbdflags = nbdflags;
0a122b
     exp->size = size == -1 ? bdrv_getlength(bs) : size;
0a122b
     exp->close = close;
0a122b
+    bdrv_ref(bs);
0a122b
     return exp;
0a122b
 }
0a122b
 
0a122b
@@ -927,6 +928,10 @@ void nbd_export_close(NBDExport *exp)
0a122b
     }
0a122b
     nbd_export_set_name(exp, NULL);
0a122b
     nbd_export_put(exp);
0a122b
+    if (exp->bs) {
0a122b
+        bdrv_unref(exp->bs);
0a122b
+        exp->bs = NULL;
0a122b
+    }
0a122b
 }
0a122b
 
0a122b
 void nbd_export_get(NBDExport *exp)
0a122b
-- 
0a122b
1.7.1
0a122b