From patchwork Fri Oct 11 12:02:10 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 282720 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 7FC142C00C2 for ; Fri, 11 Oct 2013 23:02:55 +1100 (EST) Received: from localhost ([::1]:53949 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VUbQi-0002Tw-Tc for incoming@patchwork.ozlabs.org; Fri, 11 Oct 2013 08:02:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51219) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VUbQI-0002O9-7Y for qemu-devel@nongnu.org; Fri, 11 Oct 2013 08:02:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VUbQ9-0004AT-3k for qemu-devel@nongnu.org; Fri, 11 Oct 2013 08:02:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36084) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VUbQ8-0004AO-Qi for qemu-devel@nongnu.org; Fri, 11 Oct 2013 08:02:17 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r9BC2G3o006996 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 11 Oct 2013 08:02:16 -0400 Received: from localhost (dhcp-200-247.str.redhat.com [10.33.200.247]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r9BC2Emn027134 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Fri, 11 Oct 2013 08:02:15 -0400 From: Max Reitz To: qemu-devel@nongnu.org Date: Fri, 11 Oct 2013 14:02:10 +0200 Message-Id: <1381492931-30805-2-git-send-email-mreitz@redhat.com> In-Reply-To: <1381492931-30805-1-git-send-email-mreitz@redhat.com> References: <1381492931-30805-1-git-send-email-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 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 1/2] qemu-io: Let "open" pass options to block driver 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 Add an option to the open command to specify runtime options for the block driver used. Signed-off-by: Max Reitz --- qemu-io.c | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/qemu-io.c b/qemu-io.c index f4b8efc..3b3340a 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -16,6 +16,8 @@ #include "qemu-io.h" #include "qemu/main-loop.h" +#include "qemu/option.h" +#include "qemu/config-file.h" #include "block/block_int.h" #include "trace/control.h" @@ -44,7 +46,7 @@ static const cmdinfo_t close_cmd = { .oneline = "close the current open file", }; -static int openfile(char *name, int flags, int growable) +static int openfile(char *name, int flags, int growable, QDict *opts) { Error *local_err = NULL; @@ -54,7 +56,7 @@ static int openfile(char *name, int flags, int growable) } if (growable) { - if (bdrv_file_open(&qemuio_bs, name, NULL, flags, &local_err)) { + if (bdrv_file_open(&qemuio_bs, name, opts, flags, &local_err)) { fprintf(stderr, "%s: can't open device %s: %s\n", progname, name, error_get_pretty(local_err)); error_free(local_err); @@ -63,7 +65,7 @@ static int openfile(char *name, int flags, int growable) } else { qemuio_bs = bdrv_new("hda"); - if (bdrv_open(qemuio_bs, name, NULL, flags, NULL, &local_err) < 0) { + if (bdrv_open(qemuio_bs, name, opts, flags, NULL, &local_err) < 0) { fprintf(stderr, "%s: can't open device %s: %s\n", progname, name, error_get_pretty(local_err)); error_free(local_err); @@ -89,7 +91,8 @@ static void open_help(void) " -r, -- open file read-only\n" " -s, -- use snapshot file\n" " -n, -- disable host cache\n" -" -g, -- allow file to grow (only applies to protocols)" +" -g, -- allow file to grow (only applies to protocols)\n" +" -o, -- options to be given to the block driver" "\n"); } @@ -102,19 +105,30 @@ static const cmdinfo_t open_cmd = { .argmin = 1, .argmax = -1, .flags = CMD_NOFILE_OK, - .args = "[-Crsn] [path]", + .args = "[-Crsn] [-o options] [path]", .oneline = "open the file specified by path", .help = open_help, }; +static QemuOptsList empty_opts = { + .name = "drive", + .head = QTAILQ_HEAD_INITIALIZER(empty_opts.head), + .desc = { + /* no elements => accept any params */ + { /* end of list */ } + }, +}; + static int open_f(BlockDriverState *bs, int argc, char **argv) { int flags = 0; int readonly = 0; int growable = 0; int c; + QemuOpts *qopts; + QDict *opts = NULL; - while ((c = getopt(argc, argv, "snrg")) != EOF) { + while ((c = getopt(argc, argv, "snrgo:")) != EOF) { switch (c) { case 's': flags |= BDRV_O_SNAPSHOT; @@ -128,6 +142,15 @@ static int open_f(BlockDriverState *bs, int argc, char **argv) case 'g': growable = 1; break; + case 'o': + qopts = qemu_opts_parse(&empty_opts, optarg, 0); + if (qopts == NULL) { + printf("could not parse option list -- %s\n", optarg); + return 0; + } + opts = qemu_opts_to_qdict(qopts, opts); + qemu_opts_del(qopts); + break; default: return qemuio_command_usage(&open_cmd); } @@ -141,7 +164,7 @@ static int open_f(BlockDriverState *bs, int argc, char **argv) return qemuio_command_usage(&open_cmd); } - return openfile(argv[optind], flags, growable); + return openfile(argv[optind], flags, growable, opts); } static int quit_f(BlockDriverState *bs, int argc, char **argv) @@ -418,7 +441,7 @@ int main(int argc, char **argv) } if ((argc - optind) == 1) { - openfile(argv[optind], flags, growable); + openfile(argv[optind], flags, growable, NULL); } command_loop();