From patchwork Thu Jan 22 20:10:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 431982 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 D388C140083 for ; Fri, 23 Jan 2015 07:13:40 +1100 (AEDT) Received: from localhost ([::1]:55847 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YEO8I-0002iY-TP for incoming@patchwork.ozlabs.org; Thu, 22 Jan 2015 15:13:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49166) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YEO5D-0006CW-W6 for qemu-devel@nongnu.org; Thu, 22 Jan 2015 15:10:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YEO59-0005ym-Kt for qemu-devel@nongnu.org; Thu, 22 Jan 2015 15:10:27 -0500 Received: from mx1.redhat.com ([209.132.183.28]:32910) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YEO59-0005yX-EJ for qemu-devel@nongnu.org; Thu, 22 Jan 2015 15:10:23 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t0MKAM2A014187 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 22 Jan 2015 15:10:23 -0500 Received: from localhost ([10.18.17.71]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t0MKAM1i032373 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO); Thu, 22 Jan 2015 15:10:22 -0500 From: Max Reitz To: qemu-devel@nongnu.org Date: Thu, 22 Jan 2015 15:10:06 -0500 Message-Id: <1421957411-31759-10-git-send-email-mreitz@redhat.com> In-Reply-To: <1421957411-31759-1-git-send-email-mreitz@redhat.com> References: <1421957411-31759-1-git-send-email-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Markus Armbruster , Stefan Hajnoczi , Max Reitz Subject: [Qemu-devel] [PATCH v2 09/14] qemu-io: Use blk_new_open() in openfile() 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 Signed-off-by: Max Reitz --- qemu-io.c | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/qemu-io.c b/qemu-io.c index 91a445a..81f8f64 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -39,7 +39,6 @@ static ReadLineState *readline_state; static int close_f(BlockDriverState *bs, int argc, char **argv) { blk_unref(qemuio_blk); - qemuio_bs = NULL; qemuio_blk = NULL; return 0; } @@ -51,34 +50,29 @@ static const cmdinfo_t close_cmd = { .oneline = "close the current open file", }; -static int openfile(char *name, BlockDriver *drv, int flags, int growable, - QDict *opts) +static int openfile(char *name, int flags, int growable, QDict *opts) { Error *local_err = NULL; - if (qemuio_bs) { + if (qemuio_blk) { fprintf(stderr, "file open already, try 'help close'\n"); QDECREF(opts); return 1; } - qemuio_blk = blk_new_with_bs("hda", &error_abort); - qemuio_bs = blk_bs(qemuio_blk); - if (growable) { flags |= BDRV_O_PROTOCOL; } - if (bdrv_open(&qemuio_bs, name, NULL, opts, flags, drv, &local_err) < 0) { + qemuio_blk = blk_new_open("hda", name, NULL, opts, flags, &local_err); + if (!qemuio_blk) { fprintf(stderr, "%s: can't open%s%s: %s\n", progname, name ? " device " : "", name ?: "", error_get_pretty(local_err)); error_free(local_err); - blk_unref(qemuio_blk); - qemuio_bs = NULL; - qemuio_blk = NULL; return 1; } + qemuio_bs = blk_bs(qemuio_blk); return 0; } @@ -170,9 +164,9 @@ static int open_f(BlockDriverState *bs, int argc, char **argv) qemu_opts_reset(&empty_opts); if (optind == argc - 1) { - return openfile(argv[optind], NULL, flags, growable, opts); + return openfile(argv[optind], flags, growable, opts); } else if (optind == argc) { - return openfile(NULL, NULL, flags, growable, opts); + return openfile(NULL, flags, growable, opts); } else { QDECREF(opts); return qemuio_command_usage(&open_cmd); @@ -387,8 +381,8 @@ int main(int argc, char **argv) int c; int opt_index = 0; int flags = BDRV_O_UNMAP; - BlockDriver *drv = NULL; Error *local_error = NULL; + QDict *opts = NULL; #ifdef CONFIG_POSIX signal(SIGPIPE, SIG_IGN); @@ -414,11 +408,10 @@ int main(int argc, char **argv) } break; case 'f': - drv = bdrv_find_format(optarg); - if (!drv) { - error_report("Invalid format '%s'", optarg); - exit(EXIT_FAILURE); + if (!opts) { + opts = qdict_new(); } + qdict_put_obj(opts, "driver", QOBJECT(qstring_from_str(optarg))); break; case 'c': add_user_command(optarg); @@ -489,7 +482,7 @@ int main(int argc, char **argv) } if ((argc - optind) == 1) { - openfile(argv[optind], drv, flags, growable, NULL); + openfile(argv[optind], flags, growable, opts); } command_loop();