Patchwork [RFC,3/3] nbd: don't get ref if bs has no drive

login
register
mail settings
Submitter Fam Zheng
Date June 26, 2013, 3:59 a.m.
Message ID <1372219161-12209-4-git-send-email-famz@redhat.com>
Download mbox | patch
Permalink /patch/254566/
State New
Headers show

Comments

Fam Zheng - June 26, 2013, 3:59 a.m.
Signed-off-by: Fam Zheng <famz@redhat.com>
---
 blockdev-nbd.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Patch

diff --git a/blockdev-nbd.c b/blockdev-nbd.c
index 95f10c8..2657a90 100644
--- a/blockdev-nbd.c
+++ b/blockdev-nbd.c
@@ -81,6 +81,7 @@  void qmp_nbd_server_add(const char *device, bool has_writable, bool writable,
     BlockDriverState *bs;
     NBDExport *exp;
     NBDCloseNotifier *n;
+    DriveInfo *dinfo;
 
     if (server_fd == -1) {
         error_setg(errp, "NBD server not running");
@@ -109,7 +110,10 @@  void qmp_nbd_server_add(const char *device, bool has_writable, bool writable,
                          nbd_server_put_ref);
 
     nbd_export_set_name(exp, device);
-    drive_get_ref(drive_get_by_blockdev(bs));
+    dinfo = drive_get_by_blockdev(bs);
+    if (dinfo) {
+        drive_get_ref(dinfo);
+    }
 
     n = g_malloc0(sizeof(NBDCloseNotifier));
     n->n.notify = nbd_close_notifier;