Skip to content

Commit 715a664

Browse files
kraxelAnthony Liguori
authored and
Anthony Liguori
committed
QemuOpts: command line switches for the config file.
Adds -readconfig and -writeconfig command line switches to read/write QemuOpts from config file. In theory you should be able to do: qemu < machine config cmd line switches here > -writeconfig vm.cfg qemu -readconfig vm.cfg In practice it will not work. Not all command line switches are converted to QemuOpts, so you'll have to keep the not-yet converted ones on the second line. Also there might be bugs lurking which prevent even the converted ones from working correctly. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
1 parent 42262ba commit 715a664

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

qemu-options.hx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,3 +1915,8 @@ DEF("semihosting", 0, QEMU_OPTION_semihosting,
19151915
DEF("old-param", 0, QEMU_OPTION_old_param,
19161916
"-old-param old param mode\n")
19171917
#endif
1918+
DEF("readconfig", HAS_ARG, QEMU_OPTION_readconfig,
1919+
"-readconfig <file>\n")
1920+
DEF("writeconfig", HAS_ARG, QEMU_OPTION_writeconfig,
1921+
"-writeconfig <file>\n"
1922+
" read/write config file")

vl.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5364,6 +5364,36 @@ int main(int argc, char **argv, char **envp)
53645364
xen_mode = XEN_ATTACH;
53655365
break;
53665366
#endif
5367+
case QEMU_OPTION_readconfig:
5368+
{
5369+
FILE *fp;
5370+
fp = fopen(optarg, "r");
5371+
if (fp == NULL) {
5372+
fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));
5373+
exit(1);
5374+
}
5375+
if (qemu_config_parse(fp) != 0) {
5376+
exit(1);
5377+
}
5378+
fclose(fp);
5379+
break;
5380+
}
5381+
case QEMU_OPTION_writeconfig:
5382+
{
5383+
FILE *fp;
5384+
if (strcmp(optarg, "-") == 0) {
5385+
fp = stdout;
5386+
} else {
5387+
fp = fopen(optarg, "w");
5388+
if (fp == NULL) {
5389+
fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));
5390+
exit(1);
5391+
}
5392+
}
5393+
qemu_config_write(fp);
5394+
fclose(fp);
5395+
break;
5396+
}
53675397
}
53685398
}
53695399
}

0 commit comments

Comments
 (0)