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