From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43091) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WEVvQ-0003bw-Ra for qemu-devel@nongnu.org; Fri, 14 Feb 2014 22:28:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WEVvL-0003JG-Ql for qemu-devel@nongnu.org; Fri, 14 Feb 2014 22:28:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49385) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WEVvL-0003J1-GC for qemu-devel@nongnu.org; Fri, 14 Feb 2014 22:28:15 -0500 From: Max Reitz Date: Sat, 15 Feb 2014 04:30:22 +0100 Message-Id: <1392435024-26694-7-git-send-email-mreitz@redhat.com> In-Reply-To: <1392435024-26694-1-git-send-email-mreitz@redhat.com> References: <1392435024-26694-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH v3 6/8] block: Handle bs->options in bdrv_open() only List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Jeff Cody , =?UTF-8?q?Beno=C3=AEt=20Canet?= , Stefan Hajnoczi , Max Reitz The fail paths of bdrv_file_open() and bdrv_open() naturally exhibit similarities, thus it is possible to reuse the one from bdrv_open() and shorten the one in bdrv_file_open() accordingly. Also, setting bs->options in bdrv_file_open() is not necessary if it is already done in bdrv_open(). Signed-off-by: Max Reitz Reviewed-by: Benoit Canet Reviewed-by: Kevin Wolf --- block.c | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/block.c b/block.c index 7243630..c11d4d0 100644 --- a/block.c +++ b/block.c @@ -962,14 +962,6 @@ static int bdrv_file_open(BlockDriverState *bs, const char *filename, Error *local_err = NULL; int ret; - /* NULL means an empty set of options */ - if (options == NULL) { - options = qdict_new(); - } - - bs->options = options; - options = qdict_clone_shallow(options); - /* Fetch the file name from the options QDict if necessary */ if (!filename) { filename = qdict_get_try_str(options, "filename"); @@ -1044,9 +1036,6 @@ static int bdrv_file_open(BlockDriverState *bs, const char *filename, fail: QDECREF(options); - if (!bs->drv) { - QDECREF(bs->options); - } return ret; } @@ -1248,18 +1237,6 @@ int bdrv_open(BlockDriverState **pbs, const char *filename, bs = bdrv_new(""); } - if (flags & BDRV_O_PROTOCOL) { - assert(!drv); - ret = bdrv_file_open(bs, filename, options, flags & ~BDRV_O_PROTOCOL, - errp); - if (ret && !*pbs) { - bdrv_unref(bs); - } else if (!ret) { - *pbs = bs; - } - return ret; - } - /* NULL means an empty set of options */ if (options == NULL) { options = qdict_new(); @@ -1268,6 +1245,21 @@ int bdrv_open(BlockDriverState **pbs, const char *filename, bs->options = options; options = qdict_clone_shallow(options); + if (flags & BDRV_O_PROTOCOL) { + assert(!drv); + ret = bdrv_file_open(bs, filename, options, flags & ~BDRV_O_PROTOCOL, + &local_err); + options = NULL; + if (!ret) { + *pbs = bs; + return 0; + } else if (bs->drv) { + goto close_and_fail; + } else { + goto fail; + } + } + /* For snapshot=on, create a temporary qcow2 overlay */ if (flags & BDRV_O_SNAPSHOT) { BlockDriverState *bs1; -- 1.8.5.4