9ae3a8
From 8ca7d4d814e7443da7f00696f37fb9f6f06dd668 Mon Sep 17 00:00:00 2001
9ae3a8
From: Max Reitz <mreitz@redhat.com>
9ae3a8
Date: Mon, 4 Nov 2013 22:31:58 +0100
9ae3a8
Subject: [PATCH 05/87] iscsi: use bdrv_new() instead of stack structure
9ae3a8
9ae3a8
RH-Author: Max Reitz <mreitz@redhat.com>
9ae3a8
Message-id: <1383604354-12743-8-git-send-email-mreitz@redhat.com>
9ae3a8
Patchwork-id: 55307
9ae3a8
O-Subject: [RHEL-7.0 qemu-kvm PATCH 07/43] iscsi: use bdrv_new() instead of stack structure
9ae3a8
Bugzilla: 1026524
9ae3a8
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
RH-Acked-by: Fam Zheng <famz@redhat.com>
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
9ae3a8
From: Fam Zheng <famz@redhat.com>
9ae3a8
9ae3a8
BZ: 1026524
9ae3a8
9ae3a8
BlockDriverState structure needs bdrv_new() to initialize refcnt, don't
9ae3a8
allocate a local structure variable and memset to 0, becasue with coming
9ae3a8
refcnt implementation, bdrv_unref will crash if bs->refcnt not
9ae3a8
initialized to 1.
9ae3a8
9ae3a8
Signed-off-by: Fam Zheng <famz@redhat.com>
9ae3a8
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
(cherry picked from commit 13c91cb7e28b47f5c4227f7e88a1378570117704)
9ae3a8
9ae3a8
Signed-off-by: Max Reitz <mreitz@redhat.com>
9ae3a8
---
9ae3a8
 block/iscsi.c | 16 +++++++++-------
9ae3a8
 1 file changed, 9 insertions(+), 7 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 block/iscsi.c |   16 +++++++++-------
9ae3a8
 1 files changed, 9 insertions(+), 7 deletions(-)
9ae3a8
9ae3a8
diff --git a/block/iscsi.c b/block/iscsi.c
9ae3a8
index 4ab9edc..cc2017e 100644
9ae3a8
--- a/block/iscsi.c
9ae3a8
+++ b/block/iscsi.c
9ae3a8
@@ -1252,11 +1252,11 @@ static int iscsi_create(const char *filename, QEMUOptionParameter *options)
9ae3a8
 {
9ae3a8
     int ret = 0;
9ae3a8
     int64_t total_size = 0;
9ae3a8
-    BlockDriverState bs;
9ae3a8
+    BlockDriverState *bs;
9ae3a8
     IscsiLun *iscsilun = NULL;
9ae3a8
     QDict *bs_options;
9ae3a8
 
9ae3a8
-    memset(&bs, 0, sizeof(BlockDriverState));
9ae3a8
+    bs = bdrv_new("");
9ae3a8
 
9ae3a8
     /* Read out options */
9ae3a8
     while (options && options->name) {
9ae3a8
@@ -1266,12 +1266,12 @@ static int iscsi_create(const char *filename, QEMUOptionParameter *options)
9ae3a8
         options++;
9ae3a8
     }
9ae3a8
 
9ae3a8
-    bs.opaque = g_malloc0(sizeof(struct IscsiLun));
9ae3a8
-    iscsilun = bs.opaque;
9ae3a8
+    bs->opaque = g_malloc0(sizeof(struct IscsiLun));
9ae3a8
+    iscsilun = bs->opaque;
9ae3a8
 
9ae3a8
     bs_options = qdict_new();
9ae3a8
     qdict_put(bs_options, "filename", qstring_from_str(filename));
9ae3a8
-    ret = iscsi_open(&bs, bs_options, 0);
9ae3a8
+    ret = iscsi_open(bs, bs_options, 0);
9ae3a8
     QDECREF(bs_options);
9ae3a8
 
9ae3a8
     if (ret != 0) {
9ae3a8
@@ -1285,7 +1285,7 @@ static int iscsi_create(const char *filename, QEMUOptionParameter *options)
9ae3a8
         ret = -ENODEV;
9ae3a8
         goto out;
9ae3a8
     }
9ae3a8
-    if (bs.total_sectors < total_size) {
9ae3a8
+    if (bs->total_sectors < total_size) {
9ae3a8
         ret = -ENOSPC;
9ae3a8
         goto out;
9ae3a8
     }
9ae3a8
@@ -1295,7 +1295,9 @@ out:
9ae3a8
     if (iscsilun->iscsi != NULL) {
9ae3a8
         iscsi_destroy_context(iscsilun->iscsi);
9ae3a8
     }
9ae3a8
-    g_free(bs.opaque);
9ae3a8
+    g_free(bs->opaque);
9ae3a8
+    bs->opaque = NULL;
9ae3a8
+    bdrv_delete(bs);
9ae3a8
     return ret;
9ae3a8
 }
9ae3a8
 
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8