From patchwork Sun Jan 26 19:02:42 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 314238 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id C33402C0081 for ; Mon, 27 Jan 2014 06:05:37 +1100 (EST) Received: from localhost ([::1]:55896 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W7V1T-0002zZ-Ki for incoming@patchwork.ozlabs.org; Sun, 26 Jan 2014 14:05:35 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44194) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W7UxI-0005nl-66 for qemu-devel@nongnu.org; Sun, 26 Jan 2014 14:01:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W7UxC-0001Td-7r for qemu-devel@nongnu.org; Sun, 26 Jan 2014 14:01:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:2090) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W7UxC-0001TT-0b for qemu-devel@nongnu.org; Sun, 26 Jan 2014 14:01:10 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s0QJ19Sh003604 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sun, 26 Jan 2014 14:01:09 -0500 Received: from localhost (ovpn-116-36.ams2.redhat.com [10.36.116.36]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s0QJ17lI030982 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Sun, 26 Jan 2014 14:01:08 -0500 From: Max Reitz To: qemu-devel@nongnu.org Date: Sun, 26 Jan 2014 20:02:42 +0100 Message-Id: <1390762963-25538-10-git-send-email-mreitz@redhat.com> In-Reply-To: <1390762963-25538-1-git-send-email-mreitz@redhat.com> References: <1390762963-25538-1-git-send-email-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Stefan Hajnoczi , Max Reitz Subject: [Qemu-devel] [PATCH 09/10] block: Reuse success path from bdrv_open() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The fail and success paths of bdrv_file_open() may be further shortened by reusing code already existent in bdrv_open(). This includes bdrv_file_open() not taking the reference to options which allows the removal of QDECREF(options) in that function. Signed-off-by: Max Reitz --- block.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/block.c b/block.c index f847c4b..b1bae23 100644 --- a/block.c +++ b/block.c @@ -943,9 +943,7 @@ free_and_fail: * Opens a file using a protocol (file, host_device, nbd, ...) * * options is a QDict of options to pass to the block drivers, or NULL for an - * empty set of options. The reference to the QDict belongs to the block layer - * after the call (even on failure), so if the caller intends to reuse the - * dictionary, it needs to use QINCREF() before calling bdrv_file_open. + * empty set of options. */ static int bdrv_file_open(BlockDriverState *bs, const char *filename, QDict *options, int flags, Error **errp) @@ -1010,8 +1008,8 @@ static int bdrv_file_open(BlockDriverState *bs, const char *filename, } if (!drv->bdrv_file_open) { + QINCREF(options); ret = bdrv_open(&bs, filename, NULL, options, flags, drv, &local_err); - options = NULL; } else { ret = bdrv_open_common(bs, NULL, options, flags, drv, &local_err); } @@ -1020,21 +1018,10 @@ static int bdrv_file_open(BlockDriverState *bs, const char *filename, goto fail; } - /* Check if any unknown options were used */ - if (options && (qdict_size(options) != 0)) { - const QDictEntry *entry = qdict_first(options); - error_setg(errp, "Block protocol '%s' doesn't support the option '%s'", - drv->format_name, entry->key); - ret = -EINVAL; - goto fail; - } - QDECREF(options); - bs->growable = 1; return 0; fail: - QDECREF(options); return ret; } @@ -1238,7 +1225,6 @@ int bdrv_open(BlockDriverState **pbs, const char *filename, assert(!drv); ret = bdrv_file_open(bs, filename, options, flags & ~BDRV_O_PROTOCOL, &local_err); - options = NULL; if (ret) { if (bs->drv) { goto close_and_fail; @@ -1246,8 +1232,7 @@ int bdrv_open(BlockDriverState **pbs, const char *filename, goto fail; } } - *pbs = bs; - return 0; + goto done; } /* For snapshot=on, create a temporary qcow2 overlay */ @@ -1377,12 +1362,18 @@ int bdrv_open(BlockDriverState **pbs, const char *filename, } } +done: /* Check if any unknown options were used */ if (qdict_size(options) != 0) { const QDictEntry *entry = qdict_first(options); - error_setg(errp, "Block format '%s' used by device '%s' doesn't " - "support the option '%s'", drv->format_name, bs->device_name, - entry->key); + if (flags & BDRV_O_PROTOCOL) { + error_setg(errp, "Block protocol '%s' doesn't support the option " + "'%s'", drv->format_name, entry->key); + } else { + error_setg(errp, "Block format '%s' used by device '%s' doesn't " + "support the option '%s'", drv->format_name, + bs->device_name, entry->key); + } ret = -EINVAL; goto close_and_fail;