From patchwork Fri Oct 11 15:05:15 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 282876 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E302A2C032E for ; Sat, 12 Oct 2013 04:41:06 +1100 (EST) Received: from localhost ([::1]:54920 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VUeU3-0004eR-45 for incoming@patchwork.ozlabs.org; Fri, 11 Oct 2013 11:18:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43118) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VUeIh-0007cJ-Ul for qemu-devel@nongnu.org; Fri, 11 Oct 2013 11:06:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VUeIb-0005Ti-5W for qemu-devel@nongnu.org; Fri, 11 Oct 2013 11:06:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:9357) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VUeIa-0005Rc-Rc for qemu-devel@nongnu.org; Fri, 11 Oct 2013 11:06:41 -0400 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 r9BF6dJ4019117 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 11 Oct 2013 11:06:39 -0400 Received: from dhcp-200-207.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r9BF5s2g006329; Fri, 11 Oct 2013 11:06:38 -0400 From: Kevin Wolf To: anthony@codemonkey.ws Date: Fri, 11 Oct 2013 17:05:15 +0200 Message-Id: <1381503951-27985-26-git-send-email-kwolf@redhat.com> In-Reply-To: <1381503951-27985-1-git-send-email-kwolf@redhat.com> References: <1381503951-27985-1-git-send-email-kwolf@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: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PULL 25/61] block: Improve driver whitelist checks 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 main intent of this patch is to consolidate the whitelist checks to a single point in the code instead of spreading it everywhere. This adds a nicer error message for read-only whitelisting, too, in places where it was still missing. The patch also contains a bonus bug fix: By finding the format first in bdrv_open() and then independently checking against the whitelist only later, we avoid the case that use of a non-whitelisted format results in probing rather than an error message. Previously, this could happen when using the driver=... option. Signed-off-by: Kevin Wolf Reviewed-by: Fam Zheng --- block.c | 10 +++++++--- blockdev.c | 8 ++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/block.c b/block.c index beea027..84c0eac 100644 --- a/block.c +++ b/block.c @@ -769,7 +769,11 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file, bs->read_only = !(open_flags & BDRV_O_RDWR); if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv, bs->read_only)) { - error_setg(errp, "Driver '%s' is not whitelisted", drv->format_name); + error_setg(errp, + !bs->read_only && bdrv_is_whitelisted(drv, true) + ? "Driver '%s' can only be used for read-only devices" + : "Driver '%s' is not whitelisted", + drv->format_name); return -ENOTSUP; } @@ -881,7 +885,7 @@ int bdrv_file_open(BlockDriverState **pbs, const char *filename, /* Find the right block driver */ drvname = qdict_get_try_str(options, "driver"); if (drvname) { - drv = bdrv_find_whitelisted_format(drvname, !(flags & BDRV_O_RDWR)); + drv = bdrv_find_format(drvname); if (!drv) { error_setg(errp, "Unknown driver '%s'", drvname); } @@ -1123,7 +1127,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options, /* Find the right image format driver */ drvname = qdict_get_try_str(options, "driver"); if (drvname) { - drv = bdrv_find_whitelisted_format(drvname, !(flags & BDRV_O_RDWR)); + drv = bdrv_find_format(drvname); qdict_del(options, "driver"); } diff --git a/blockdev.c b/blockdev.c index a91d5a8..ab79df7 100644 --- a/blockdev.c +++ b/blockdev.c @@ -468,13 +468,9 @@ static DriveInfo *blockdev_init(QemuOpts *all_opts, return NULL; } - drv = bdrv_find_whitelisted_format(buf, ro); + drv = bdrv_find_format(buf); if (!drv) { - if (!ro && bdrv_find_whitelisted_format(buf, !ro)) { - error_report("'%s' can be only used as read-only device.", buf); - } else { - error_report("'%s' invalid format", buf); - } + error_report("'%s' invalid format", buf); return NULL; } }