From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MWpJE-00038m-AM for qemu-devel@nongnu.org; Fri, 31 Jul 2009 06:25:56 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MWpJ8-000364-J5 for qemu-devel@nongnu.org; Fri, 31 Jul 2009 06:25:54 -0400 Received: from [199.232.76.173] (port=47780 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MWpJ7-00035r-TW for qemu-devel@nongnu.org; Fri, 31 Jul 2009 06:25:49 -0400 Received: from mx2.redhat.com ([66.187.237.31]:47167) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MWpJ7-0004kS-1D for qemu-devel@nongnu.org; Fri, 31 Jul 2009 06:25:49 -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 n6VAPl2H028372 for ; Fri, 31 Jul 2009 06:25:47 -0400 From: Gerd Hoffmann Date: Fri, 31 Jul 2009 12:25:36 +0200 Message-Id: <1249035941-4562-6-git-send-email-kraxel@redhat.com> In-Reply-To: <1249035941-4562-1-git-send-email-kraxel@redhat.com> References: <1249035941-4562-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PATCH 05/10] QemuOpts: add -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 One use case will be file for drives (no filename quoting issues), i.e. -drive id=test,if=virtio -set drive.test.file=/vmdisk/test-virtio.img It will work for any other option (assuming handled by QemuOpts) though. Except for id= for obvious reasons ;). Signed-off-by: Gerd Hoffmann --- qemu-config.c | 41 +++++++++++++++++++++++++++++++++++++++++ qemu-config.h | 2 ++ qemu-options.hx | 6 +++++- vl.c | 4 ++++ 4 files changed, 52 insertions(+), 1 deletions(-) diff --git a/qemu-config.c b/qemu-config.c index 786f055..bcfb6eb 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -71,3 +71,44 @@ QemuOptsList qemu_drive_opts = { }, }; +static QemuOptsList *lists[] = { + &qemu_drive_opts, + NULL, +}; + +int qemu_set_option(const char *str) +{ + char group[64], id[64], arg[64]; + QemuOpts *opts; + int i, rc, offset; + + rc = sscanf(str, "%63[^.].%63[^.].%63[^=]%n", group, id, arg, &offset); + if (rc < 3 || str[offset] != '=') { + fprintf(stderr, "can't parse: \"%s\"\n", str); + return -1; + } + + for (i = 0; lists[i] != NULL; i++) { + if (strcmp(lists[i]->name, group) == 0) + break; + } + if (lists[i] == NULL) { + fprintf(stderr, "there is no option group \"%s\"\n", group); + return -1; + } + + opts = qemu_opts_find(lists[i], id); + if (!opts) { + fprintf(stderr, "there is no %s \"%s\" defined\n", + lists[i]->name, id); + return -1; + } + + if (-1 == qemu_opt_set(opts, arg, str+offset+1)) { + fprintf(stderr, "failed to set \"%s\" for %s \"%s\"\n", + arg, lists[i]->name, id); + return -1; + } + return 0; +} + diff --git a/qemu-config.h b/qemu-config.h index 3ada418..7faec9b 100644 --- a/qemu-config.h +++ b/qemu-config.h @@ -1 +1,3 @@ extern QemuOptsList qemu_drive_opts; + +int qemu_set_option(const char *str); diff --git a/qemu-options.hx b/qemu-options.hx index 1b420a3..38989f1 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -95,8 +95,12 @@ 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("set", HAS_ARG, QEMU_OPTION_set, + "-set group.id.arg=value\n" + " set parameter for item of type \n" + " i.e. -set drive.$id.file=/path/to/image\n") STEXI @item -drive @var{option}[,@var{option}[,@var{option}[,...]]] diff --git a/vl.c b/vl.c index 5a9ff70..698182e 100644 --- a/vl.c +++ b/vl.c @@ -4963,6 +4963,10 @@ int main(int argc, char **argv, char **envp) case QEMU_OPTION_drive: drive_add(NULL, "%s", optarg); break; + case QEMU_OPTION_set: + if (qemu_set_option(optarg) != 0) + exit(1); + break; case QEMU_OPTION_mtdblock: drive_add(optarg, MTD_ALIAS); break; -- 1.6.2.5