Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MWT77-0008QR-4T for qemu-devel@nongnu.org; Thu, 30 Jul 2009 06:43:57 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MWT72-0008Ka-1a for qemu-devel@nongnu.org; Thu, 30 Jul 2009 06:43:56 -0400 Received: from [199.232.76.173] (port=54162 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MWT70-0008KC-VQ for qemu-devel@nongnu.org; Thu, 30 Jul 2009 06:43:51 -0400 Received: from mx2.redhat.com ([66.187.237.31]:38594) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MWT70-0005U3-5i for qemu-devel@nongnu.org; Thu, 30 Jul 2009 06:43:50 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n6UAhmFh009528 for ; Thu, 30 Jul 2009 06:43:48 -0400 From: Gerd Hoffmann Date: Thu, 30 Jul 2009 12:43:40 +0200 Message-Id: <1248950621-22249-5-git-send-email-kraxel@redhat.com> In-Reply-To: <1248950621-22249-1-git-send-email-kraxel@redhat.com> References: <1248950621-22249-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PATCH 4/5] QemuOpts: add -drive-set option List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Gerd Hoffmann The typical use case will be file (no filename quoting issues), i.e. -drive id=test,if=virtio -drive-set test.file=/vmdisk/test-virtio.img It will work for any drive argument though. Except id= for obvious reasons ;). Signed-off-by: Gerd Hoffmann --- qemu-options.hx | 5 ++++- vl.c | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletions(-) diff --git a/qemu-options.hx b/qemu-options.hx index 1b420a3..1b26588 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -95,8 +95,11 @@ DEF("drive", HAS_ARG, QEMU_OPTION_drive, "-drive [file=file][,if=type][,bus=n][,unit=m][,media=d][,index=i]\n" " [,cyls=c,heads=h,secs=s[,trans=t]][,snapshot=on|off]\n" " [,cache=writethrough|writeback|none][,format=f][,serial=s]\n" - " [,addr=A]\n" + " [,addr=A][,id=name]\n" " use 'file' as a drive image\n") +DEF("drive-set", HAS_ARG, QEMU_OPTION_drive_set, + "-drive-set id.arg=value\n" + " set arg parameter for drive id\n") STEXI @item -drive @var{option}[,@var{option}[,@var{option}[,...]]] diff --git a/vl.c b/vl.c index 4f322c1..e602369 100644 --- a/vl.c +++ b/vl.c @@ -1887,6 +1887,27 @@ QemuOpts *drive_add(const char *file, const char *fmt, ...) return opts; } +static int drive_add_arg(const char *str) +{ + char id[32], arg[32], value[1024]; + QemuOpts *opts; + + if (sscanf(str, "%31[^.].%31[^=]=%s", id, arg, value) != 3) { + fprintf(stderr, "can't parse: \"%s\"\n", str); + return -1; + } + opts = qemu_opts_find(&drive_opt_list, id); + if (!opts) { + fprintf(stderr, "there is no drive \"%s\" defined\n", id); + return -1; + } + if (-1 == qemu_opt_set(opts, arg, value)) { + fprintf(stderr, "failed to set \"%s\" for drive \"%s\"\n", arg, id); + return -1; + } + return 0; +} + DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit) { DriveInfo *dinfo; @@ -5031,6 +5052,10 @@ int main(int argc, char **argv, char **envp) case QEMU_OPTION_drive: drive_add(NULL, "%s", optarg); break; + case QEMU_OPTION_drive_set: + if (drive_add_arg(optarg) != 0) + exit(1); + break; case QEMU_OPTION_mtdblock: drive_add(optarg, MTD_ALIAS); break; -- 1.6.2.5