From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53167) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V59uJ-0001mO-HD for qemu-devel@nongnu.org; Fri, 02 Aug 2013 03:36:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V59u9-0001Sz-Nc for qemu-devel@nongnu.org; Fri, 02 Aug 2013 03:36:15 -0400 Received: from e23smtp03.au.ibm.com ([202.81.31.145]:55508) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V59u7-0001Ro-MN for qemu-devel@nongnu.org; Fri, 02 Aug 2013 03:36:05 -0400 Received: from /spool/local by e23smtp03.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 2 Aug 2013 17:25:23 +1000 Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [9.190.235.152]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id 30E0D2BB004F for ; Fri, 2 Aug 2013 17:35:49 +1000 (EST) Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r727K4fU43188254 for ; Fri, 2 Aug 2013 17:20:05 +1000 Received: from d23av04.au.ibm.com (loopback [127.0.0.1]) by d23av04.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r727Zlwn014871 for ; Fri, 2 Aug 2013 17:35:47 +1000 Message-ID: <51FB6120.2000104@linux.vnet.ibm.com> Date: Fri, 02 Aug 2013 15:34:56 +0800 From: Wenchao Xia MIME-Version: 1.0 References: <1375265640-27307-1-git-send-email-famz@redhat.com> <1375265640-27307-3-git-send-email-famz@redhat.com> In-Reply-To: <1375265640-27307-3-git-send-email-famz@redhat.com> Content-Type: text/plain; charset=GB2312 Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH v3 2/7] iscsi: use bdrv_new() instead of stack structure List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: kwolf@redhat.com, jcody@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com ÓÚ 2013-7-31 18:13, Fam Zheng дµÀ: > 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 > --- > block/iscsi.c | 14 +++++++------- > 1 file changed, 7 insertions(+), 7 deletions(-) > > diff --git a/block/iscsi.c b/block/iscsi.c > index 5f28c6a..db8a699 100644 > --- a/block/iscsi.c > +++ b/block/iscsi.c > @@ -1247,11 +1247,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) { > @@ -1261,12 +1261,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) { > @@ -1280,7 +1280,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; > } > @@ -1290,7 +1290,7 @@ out: > if (iscsilun->iscsi != NULL) { > iscsi_destroy_context(iscsilun->iscsi); > } > - g_free(bs.opaque); bs,opaque seems leaked. bdrv_delete() will not free it unless bs->drv != NULL. > + bdrv_delete(bs); > return ret; > } > -- Best Regards Wenchao Xia