[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 11/42] iscsi: use bdrv_new() instead of stack structu
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PULL 11/42] iscsi: use bdrv_new() instead of stack structure |
Date: |
Fri, 6 Sep 2013 17:38:42 +0200 |
From: Fam Zheng <address@hidden>
BlockDriverState structure needs bdrv_new() to initialize refcnt, don't
allocate a local structure variable and memset to 0, becasue with coming
refcnt implementation, bdrv_unref will crash if bs->refcnt not
initialized to 1.
Signed-off-by: Fam Zheng <address@hidden>
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
block/iscsi.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/block/iscsi.c b/block/iscsi.c
index 2bbee1f..b2be147 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -1241,11 +1241,11 @@ static int iscsi_create(const char *filename,
QEMUOptionParameter *options)
{
int ret = 0;
int64_t total_size = 0;
- BlockDriverState bs;
+ BlockDriverState *bs;
IscsiLun *iscsilun = NULL;
QDict *bs_options;
- memset(&bs, 0, sizeof(BlockDriverState));
+ bs = bdrv_new("");
/* Read out options */
while (options && options->name) {
@@ -1255,12 +1255,12 @@ static int iscsi_create(const char *filename,
QEMUOptionParameter *options)
options++;
}
- bs.opaque = g_malloc0(sizeof(struct IscsiLun));
- iscsilun = bs.opaque;
+ bs->opaque = g_malloc0(sizeof(struct IscsiLun));
+ iscsilun = bs->opaque;
bs_options = qdict_new();
qdict_put(bs_options, "filename", qstring_from_str(filename));
- ret = iscsi_open(&bs, bs_options, 0);
+ ret = iscsi_open(bs, bs_options, 0);
QDECREF(bs_options);
if (ret != 0) {
@@ -1274,7 +1274,7 @@ static int iscsi_create(const char *filename,
QEMUOptionParameter *options)
ret = -ENODEV;
goto out;
}
- if (bs.total_sectors < total_size) {
+ if (bs->total_sectors < total_size) {
ret = -ENOSPC;
goto out;
}
@@ -1284,7 +1284,9 @@ out:
if (iscsilun->iscsi != NULL) {
iscsi_destroy_context(iscsilun->iscsi);
}
- g_free(bs.opaque);
+ g_free(bs->opaque);
+ bs->opaque = NULL;
+ bdrv_delete(bs);
return ret;
}
--
1.8.3.1
- [Qemu-devel] [PULL 01/42] throttle: Add a new throttling API implementing continuous leaky bucket., (continued)
- [Qemu-devel] [PULL 01/42] throttle: Add a new throttling API implementing continuous leaky bucket., Stefan Hajnoczi, 2013/09/06
- [Qemu-devel] [PULL 03/42] block: Enable the new throttling code in the block layer., Stefan Hajnoczi, 2013/09/06
- [Qemu-devel] [PULL 02/42] throttle: Add units tests, Stefan Hajnoczi, 2013/09/06
- [Qemu-devel] [PULL 04/42] block: Add support for throttling burst max in QMP and the command line., Stefan Hajnoczi, 2013/09/06
- [Qemu-devel] [PULL 05/42] block: Add iops_size to do the iops accounting for a given io size., Stefan Hajnoczi, 2013/09/06
- [Qemu-devel] [PULL 06/42] qemu-iotests: Adjust test result 039, Stefan Hajnoczi, 2013/09/06
- [Qemu-devel] [PULL 08/42] w32: Fix access to host devices (regression), Stefan Hajnoczi, 2013/09/06
- [Qemu-devel] [PULL 07/42] add qemu-img convert -n option (skip target volume creation), Stefan Hajnoczi, 2013/09/06
- [Qemu-devel] [PULL 10/42] vvfat: use bdrv_new() to allocate BlockDriverState, Stefan Hajnoczi, 2013/09/06
- [Qemu-devel] [PULL 09/42] aio / timers: fix build of test/test-aio.c on non-linux platforms, Stefan Hajnoczi, 2013/09/06
- [Qemu-devel] [PULL 11/42] iscsi: use bdrv_new() instead of stack structure,
Stefan Hajnoczi <=
- [Qemu-devel] [PULL 12/42] block: implement reference count for BlockDriverState, Stefan Hajnoczi, 2013/09/06
- [Qemu-devel] [PULL 13/42] block: make bdrv_delete() static, Stefan Hajnoczi, 2013/09/06
- [Qemu-devel] [PULL 14/42] migration: omit drive ref as we have bdrv_ref now, Stefan Hajnoczi, 2013/09/06
- [Qemu-devel] [PULL 15/42] xen_disk: simplify blk_disconnect with refcnt, Stefan Hajnoczi, 2013/09/06
- [Qemu-devel] [PULL 27/42] qemu-img: always probe the input image for allocated sectors, Stefan Hajnoczi, 2013/09/06
- [Qemu-devel] [PULL 28/42] block: make bdrv_has_zero_init return false for copy-on-write-images, Stefan Hajnoczi, 2013/09/06
- [Qemu-devel] [PULL 29/42] block: introduce bdrv_get_block_status API, Stefan Hajnoczi, 2013/09/06
- [Qemu-devel] [PULL 31/42] block: return get_block_status data and flags for formats, Stefan Hajnoczi, 2013/09/06
- [Qemu-devel] [PULL 30/42] block: define get_block_status return value, Stefan Hajnoczi, 2013/09/06