diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2009-07-31 12:25:36 +0200 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2009-08-10 13:05:26 -0500 |
commit | d058fe03e53699b5a85db1ea36edcf59273775a8 (patch) | |
tree | a3c098a7931ff36df0e564709b06ccc255f456ce /qemu-config.c | |
parent | 7282a0331f11edd021efa3687dc2ec7fd557ace9 (diff) | |
download | qemu-d058fe03e53699b5a85db1ea36edcf59273775a8.zip qemu-d058fe03e53699b5a85db1ea36edcf59273775a8.tar.gz qemu-d058fe03e53699b5a85db1ea36edcf59273775a8.tar.bz2 |
QemuOpts: add -set option
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 <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Message-Id:
Diffstat (limited to 'qemu-config.c')
-rw-r--r-- | qemu-config.c | 41 |
1 files changed, 41 insertions, 0 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; +} + |