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