qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 4/5] QemuOpts: add -drive-set option


From: Gerd Hoffmann
Subject: [Qemu-devel] [PATCH 4/5] QemuOpts: add -drive-set option
Date: Thu, 30 Jul 2009 12:43:40 +0200

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 <address@hidden>
---
 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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]