QemuOpts: add -set option
authorGerd Hoffmann <kraxel@redhat.com>
Fri, 31 Jul 2009 10:25:36 +0000 (12:25 +0200)
committerAnthony Liguori <aliguori@us.ibm.com>
Mon, 10 Aug 2009 18:05:26 +0000 (13:05 -0500)
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:

qemu-config.c
qemu-config.h
qemu-options.hx
vl.c

index 786f055d00bc0ee51b1540c8141737d41b11a12c..bcfb6eb6e55fe976aa5e2d3773100d5a3fa2d691 100644 (file)
@@ -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;
+}
+
index 3ada41837832d89cc4f294b5e96b9bd23d5043b8..7faec9bdd8a34b1dfbab0328985b6ef87d929c73 100644 (file)
@@ -1 +1,3 @@
 extern QemuOptsList qemu_drive_opts;
+
+int qemu_set_option(const char *str);
index 1b420a3c591df3540c150c2302e1d68248946fb5..38989f18b2e0937245c93a3f770ff47bd23be8f2 100644 (file)
@@ -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 <arg> parameter for item <id> of type <group>\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 ca84fa9793a4e5c3a546df3f0aac3a1f054ce020..5542df31bf4c5b6d57fcf7a13e8de1cfbda680a6 100644 (file)
--- a/vl.c
+++ b/vl.c
@@ -4966,6 +4966,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;