From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33859) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wx1e5-0008Si-OD for qemu-devel@nongnu.org; Tue, 17 Jun 2014 18:14:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wx1dz-0000A5-ES for qemu-devel@nongnu.org; Tue, 17 Jun 2014 18:14:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34801) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wx1dz-00009y-5j for qemu-devel@nongnu.org; Tue, 17 Jun 2014 18:14:19 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s5HMEIIh002259 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 17 Jun 2014 18:14:18 -0400 From: Max Reitz Date: Wed, 18 Jun 2014 00:14:09 +0200 Message-Id: <1403043250-28472-2-git-send-email-mreitz@redhat.com> In-Reply-To: <1403043250-28472-1-git-send-email-mreitz@redhat.com> References: <1403043250-28472-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH 1/2] block: Do not prematurely remove "filename" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Stefan Hajnoczi , Max Reitz If "filename" is removed from the options QDict before entering bdrv_open_common(), it cannot be stored in the BDS. Therefore, wait until it has been copied there and remove it from the options only afterwards. This fixes "filename" in the BDS being empty for block drivers which do not need the filename because they have parsed it already (e.g. NBD). Signed-off-by: Max Reitz --- block.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index 43abe96..1fdfa66 100644 --- a/block.c +++ b/block.c @@ -954,6 +954,14 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file, bs->filename[0] = '\0'; } + if (!drv->bdrv_needs_filename) { + qdict_del(options, "filename"); + /* The pointer "filename" may reference the just deleted QDict entry; in + * any case, it is no longer needed, so indicate that by setting it to + * NULL. */ + filename = NULL; + } + bs->drv = drv; bs->opaque = g_malloc0(drv->instance_size); @@ -1070,9 +1078,7 @@ static int bdrv_file_open(BlockDriverState *bs, const char *filename, goto fail; } - if (!drv->bdrv_needs_filename) { - qdict_del(*options, "filename"); - } else { + if (drv->bdrv_needs_filename) { filename = qdict_get_str(*options, "filename"); } } -- 2.0.0