From patchwork Mon Feb 16 15:46:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 440256 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 63A5E140190 for ; Tue, 17 Feb 2015 03:05:35 +1100 (AEDT) Received: from localhost ([::1]:40488 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNOAv-0007lO-7t for incoming@patchwork.ozlabs.org; Mon, 16 Feb 2015 11:05:33 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52228) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNNuR-0000p7-6A for qemu-devel@nongnu.org; Mon, 16 Feb 2015 10:48:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YNNuQ-0006ff-3Q for qemu-devel@nongnu.org; Mon, 16 Feb 2015 10:48:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48282) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNNuP-0006fQ-CY for qemu-devel@nongnu.org; Mon, 16 Feb 2015 10:48:30 -0500 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 t1GFmP5g002898 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 16 Feb 2015 10:48:25 -0500 Received: from localhost (ovpn-112-67.ams2.redhat.com [10.36.112.67]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t1GFmOAI001165; Mon, 16 Feb 2015 10:48:24 -0500 From: Stefan Hajnoczi To: Date: Mon, 16 Feb 2015 15:46:21 +0000 Message-Id: <1424101590-7627-57-git-send-email-stefanha@redhat.com> In-Reply-To: <1424101590-7627-1-git-send-email-stefanha@redhat.com> References: <1424101590-7627-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Peter Maydell , Stefan Hajnoczi , Max Reitz Subject: [Qemu-devel] [PULL v2 56/65] qemu-img: Use blk_new_open() in img_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 From: Max Reitz Signed-off-by: Max Reitz Reviewed-by: Eric Blake Message-id: 1423162705-32065-8-git-send-email-mreitz@redhat.com Signed-off-by: Stefan Hajnoczi --- qemu-img.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 8790546..7dea370 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -293,32 +293,24 @@ static BlockBackend *img_open(const char *id, const char *filename, { BlockBackend *blk; BlockDriverState *bs; - BlockDriver *drv; char password[256]; Error *local_err = NULL; - int ret; - - blk = blk_new_with_bs(id, &error_abort); - bs = blk_bs(blk); + QDict *options = NULL; if (fmt) { - drv = bdrv_find_format(fmt); - if (!drv) { - error_report("Unknown file format '%s'", fmt); - goto fail; - } - } else { - drv = NULL; + options = qdict_new(); + qdict_put(options, "driver", qstring_from_str(fmt)); } - ret = bdrv_open(&bs, filename, NULL, NULL, flags, drv, &local_err); - if (ret < 0) { + blk = blk_new_open(id, filename, NULL, options, flags, &local_err); + if (!blk) { error_report("Could not open '%s': %s", filename, error_get_pretty(local_err)); error_free(local_err); goto fail; } + bs = blk_bs(blk); if (bdrv_is_encrypted(bs) && require_io) { qprintf(quiet, "Disk image '%s' is encrypted.\n", filename); if (read_password(password, sizeof(password)) < 0) {