Patchwork [4/4] QemuOpts: command line switches for the config file.

login
register
mail settings
Submitter Nathan Baum
Date Oct. 16, 2009, 6:48 p.m.
Message ID <1255718902.25855.66.camel@localhost.localdomain>
Download mbox | patch
Permalink /patch/36268/
State New
Headers show

Comments

Nathan Baum - Oct. 16, 2009, 6:48 p.m.
On Wed, 2009-10-14 at 10:39 +0200, Gerd Hoffmann wrote:
> 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. 

It would probably be helpful for Qemu to put those in the config file. 

In the medium term, perhaps a "legacy_options" option which can be
automatically parsed by -readconfig.

In the short term, just put the non-QemuOpt options in a comment.

(In the long term, hopefully there won't be any legacy options.)

I've knocked up something which does the short term solution. There's
probably a much more elegant way. (Thinking about it, maybe another
field of QEMUOption should simply record whether the option has been
QemuOptified, then it shouldn't need to touch the code for each option.)

Signed-off-by: Nathan Baum <nathan@parenthephobia.org.uk>
---
                     exit(1);
@@ -5271,6 +5302,7 @@ int main(int argc, char **argv, char **envp)
                 }
                 break;
             case QEMU_OPTION_serial:
+	        qemu_opt_legacy_add("serial", optarg);
                 if (serial_device_index >= MAX_SERIAL_PORTS) {
                     fprintf(stderr, "qemu: too many serial ports\n");
                     exit(1);
@@ -5279,6 +5311,7 @@ int main(int argc, char **argv, char **envp)
                 serial_device_index++;
                 break;
             case QEMU_OPTION_watchdog:
+	        qemu_opt_legacy_add("watchdog", optarg);
                 if (watchdog) {
                     fprintf(stderr,
                             "qemu: only one watchdog option may be
given\n");
@@ -5287,12 +5320,14 @@ int main(int argc, char **argv, char **envp)
                 watchdog = optarg;
                 break;
             case QEMU_OPTION_watchdog_action:
+	        qemu_opt_legacy_add("watchdog-action", optarg);
                 if (select_watchdog_action(optarg) == -1) {
                     fprintf(stderr, "Unknown -watchdog-action parameter
\n");
                     exit(1);
                 }
                 break;
             case QEMU_OPTION_virtiocon:
+	        qemu_opt_legacy_add("virtiocon", optarg);
                 if (virtio_console_index >= MAX_VIRTIO_CONSOLES) {
                     fprintf(stderr, "qemu: too many virtio consoles
\n");
                     exit(1);
@@ -5301,6 +5336,7 @@ int main(int argc, char **argv, char **envp)
                 virtio_console_index++;
                 break;
             case QEMU_OPTION_parallel:
+	        qemu_opt_legacy_add("parallel", optarg);
                 if (parallel_device_index >= MAX_PARALLEL_PORTS) {
                     fprintf(stderr, "qemu: too many parallel ports\n");
                     exit(1);
@@ -5309,45 +5345,57 @@ int main(int argc, char **argv, char **envp)
                 parallel_device_index++;
                 break;
 	    case QEMU_OPTION_loadvm:
+	        qemu_opt_legacy_add("loadvm", optarg);
 		loadvm = optarg;
 		break;
             case QEMU_OPTION_full_screen:
+	        qemu_opt_legacy_add("full-screen", NULL);
                 full_screen = 1;
                 break;
 #ifdef CONFIG_SDL
             case QEMU_OPTION_no_frame:
+	        qemu_opt_legacy_add("no-frame", NULL);
                 no_frame = 1;
                 break;
             case QEMU_OPTION_alt_grab:
+	        qemu_opt_legacy_add("alt-grab", NULL);
                 alt_grab = 1;
                 break;
             case QEMU_OPTION_ctrl_grab:
+	        qemu_opt_legacy_add("ctrl-grab", NULL);
                 ctrl_grab = 1;
                 break;
             case QEMU_OPTION_no_quit:
+	        qemu_opt_legacy_add("no-quit", NULL);
                 no_quit = 1;
                 break;
             case QEMU_OPTION_sdl:
+	        qemu_opt_legacy_add("sdl", NULL);
                 display_type = DT_SDL;
                 break;
 #endif
             case QEMU_OPTION_pidfile:
+	        qemu_opt_legacy_add("pidfile", optarg);
                 pid_file = optarg;
                 break;
 #ifdef TARGET_I386
             case QEMU_OPTION_win2k_hack:
+	        qemu_opt_legacy_add("win2k-hack", NULL);
                 win2k_install_hack = 1;
                 break;
             case QEMU_OPTION_rtc_td_hack:
+                qemu_opt_legacy_add("rtc-td-hack", NULL);
                 rtc_td_hack = 1;
                 break;
             case QEMU_OPTION_acpitable:
+	        qemu_opt_legacy_add("acpitable", optarg);
                 if(acpi_table_add(optarg) < 0) {
                     fprintf(stderr, "Wrong acpi table provided\n");
                     exit(1);
                 }
                 break;
             case QEMU_OPTION_smbios:
+	        qemu_opt_legacy_add("smbios", optarg);
                 if(smbios_entry_add(optarg) < 0) {
                     fprintf(stderr, "Wrong smbios provided\n");
                     exit(1);
@@ -5356,13 +5404,16 @@ int main(int argc, char **argv, char **envp)
 #endif
 #ifdef CONFIG_KVM
             case QEMU_OPTION_enable_kvm:
+	        qemu_opt_legacy_add("enable-kvm", NULL);
                 kvm_allowed = 1;
                 break;
 #endif
             case QEMU_OPTION_usb:
+	        qemu_opt_legacy_add("usb", NULL);
                 usb_enabled = 1;
                 break;
             case QEMU_OPTION_usbdevice:
+	        qemu_opt_legacy_add("usbdevice", optarg);
                 usb_enabled = 1;
                 add_device_config(DEV_USB, optarg);
                 break;
@@ -5372,6 +5423,7 @@ int main(int argc, char **argv, char **envp)
                 }
                 break;
             case QEMU_OPTION_smp:
+	        qemu_opt_legacy_add("smp", optarg);
                 smp_parse(optarg);
                 if (smp_cpus < 1) {
                     fprintf(stderr, "Invalid number of CPUs\n");
@@ -5388,17 +5440,21 @@ int main(int argc, char **argv, char **envp)
                 }
                 break;
 	    case QEMU_OPTION_vnc:
+	        qemu_opt_legacy_add("vnc", optarg);
                 display_type = DT_VNC;
 		vnc_display = optarg;
 		break;
 #ifdef TARGET_I386
             case QEMU_OPTION_no_acpi:
+	        qemu_opt_legacy_add("no-acpi", NULL);
                 acpi_enabled = 0;
                 break;
             case QEMU_OPTION_no_hpet:
+	        qemu_opt_legacy_add("no-hpet", NULL);
                 no_hpet = 1;
                 break;
             case QEMU_OPTION_balloon:
+	        qemu_opt_legacy_add("balloon", optarg);
                 if (balloon_parse(optarg) < 0) {
                     fprintf(stderr, "Unknown -balloon argument %s\n",
optarg);
                     exit(1);
@@ -5406,15 +5462,19 @@ int main(int argc, char **argv, char **envp)
                 break;
 #endif
             case QEMU_OPTION_no_reboot:
+	        qemu_opt_legacy_add("no-reboot", NULL);
                 no_reboot = 1;
                 break;
             case QEMU_OPTION_no_shutdown:
+	        qemu_opt_legacy_add("no-shutdown", NULL);
                 no_shutdown = 1;
                 break;
             case QEMU_OPTION_show_cursor:
+	        qemu_opt_legacy_add("show-cursor", NULL);
                 cursor_hide = 0;
                 break;
             case QEMU_OPTION_uuid:
+	        qemu_opt_legacy_add("uuid", optarg);
                 if(qemu_uuid_parse(optarg, qemu_uuid) < 0) {
                     fprintf(stderr, "Fail to parse UUID string."
                             " Wrong format.\n");
@@ -5423,10 +5483,12 @@ int main(int argc, char **argv, char **envp)
                 break;
 #ifndef _WIN32
 	    case QEMU_OPTION_daemonize:
+	        qemu_opt_legacy_add("daemonize", NULL);
 		daemonize = 1;
 		break;
 #endif
 	    case QEMU_OPTION_option_rom:
+	        qemu_opt_legacy_add("option-rom", optarg);
 		if (nb_option_roms >= MAX_OPTION_ROMS) {
 		    fprintf(stderr, "Too many option ROMs\n");
 		    exit(1);
@@ -5436,10 +5498,12 @@ int main(int argc, char **argv, char **envp)
 		break;
 #if defined(TARGET_ARM) || defined(TARGET_M68K)
             case QEMU_OPTION_semihosting:
+	        qemu_opt_legacy_add("semihosting", NULL);
                 semihosting_enabled = 1;
                 break;
 #endif
             case QEMU_OPTION_name:
+	        qemu_opt_legacy_add("name", optarg);
                 qemu_name = qemu_strdup(optarg);
 		 {
 		     char *p = strchr(qemu_name, ',');
@@ -5456,6 +5520,7 @@ int main(int argc, char **argv, char **envp)
                 break;
 #if defined(TARGET_SPARC) || defined(TARGET_PPC)
             case QEMU_OPTION_prom_env:
+	        qemu_opt_legacy_add("prom-env", optarg);
                 if (nb_prom_envs >= MAX_PROM_ENVS) {
                     fprintf(stderr, "Too many prom variables\n");
                     exit(1);
@@ -5466,13 +5531,16 @@ int main(int argc, char **argv, char **envp)
 #endif
 #ifdef TARGET_ARM
             case QEMU_OPTION_old_param:
+	        qemu_opt_legacy_add("old-param", NULL);
                 old_param = 1;
                 break;
 #endif
             case QEMU_OPTION_clock:
+	        qemu_opt_legacy_add("clock", optarg);
                 configure_alarms(optarg);
                 break;
             case QEMU_OPTION_startdate:
+	        qemu_opt_legacy_add("startdate", optarg);
                 configure_rtc_date_offset(optarg, 1);
                 break;
             case QEMU_OPTION_rtc:
@@ -5484,11 +5552,13 @@ int main(int argc, char **argv, char **envp)
                 configure_rtc(opts);
                 break;
             case QEMU_OPTION_tb_size:
+	        qemu_opt_legacy_add("tb-size", optarg);
                 tb_size = strtol(optarg, NULL, 0);
                 if (tb_size < 0)
                     tb_size = 0;
                 break;
             case QEMU_OPTION_icount:
+	        qemu_opt_legacy_add("icount", optarg);
                 use_icount = 1;
                 if (strcmp(optarg, "auto") == 0) {
                     icount_time_shift = -1;
@@ -5497,24 +5567,30 @@ int main(int argc, char **argv, char **envp)
                 }
                 break;
             case QEMU_OPTION_incoming:
+	        qemu_opt_legacy_add("incoming", optarg);
                 incoming = optarg;
                 break;
 #ifndef _WIN32
             case QEMU_OPTION_chroot:
+	        qemu_opt_legacy_add("chroot", optarg);
                 chroot_dir = optarg;
                 break;
             case QEMU_OPTION_runas:
+	        qemu_opt_legacy_add("runas", optarg);
                 run_as = optarg;
                 break;
 #endif
 #ifdef CONFIG_XEN
             case QEMU_OPTION_xen_domid:
+	        qemu_opt_legacy_add("xen-domid", optarg);
                 xen_domid = atoi(optarg);
                 break;
             case QEMU_OPTION_xen_create:
+	        qemu_opt_legacy_add("xen-create", NULL);
                 xen_mode = XEN_CREATE;
                 break;
             case QEMU_OPTION_xen_attach:
+	        qemu_opt_legacy_add("xen-attach", NULL);
                 xen_mode = XEN_ATTACH;
                 break;
 #endif
Gerd Hoffmann - Oct. 16, 2009, 7:33 p.m.
On 10/16/09 20:48, Nathan Baum wrote:
> In the medium term, perhaps a "legacy_options" option which can be
> automatically parsed by -readconfig.
>
> In the short term, just put the non-QemuOpt options in a comment.
>
> (In the long term, hopefully there won't be any legacy options.)

Yes.

> I've knocked up something which does the short term solution.

Hmm, I'd prefer to simply ignore legacy options.  Then join forces for 
the long-term solution instead of implementing something temporary.

cheers,
   Gerd

Patch

diff --git a/qemu-config.c b/qemu-config.c
index 6075c20..fe4837d 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -285,6 +285,9 @@  void qemu_config_write(FILE *fp)
     int i;
 
     fprintf(fp, "# qemu config file\n\n");
+    fprintf(fp, "# legacy options:\n# ");
+    qemu_opt_legacy_print(fp);
+    fprintf(fp, "\n\n");
     for (i = 0; lists[i] != NULL; i++) {
         data.list = lists[i];
         qemu_opts_foreach(data.list, config_write_opts, &data, 0);
diff --git a/qemu-option.c b/qemu-option.c
index 49efd39..4d1453c 100644
--- a/qemu-option.c
+++ b/qemu-option.c
@@ -819,3 +819,20 @@  int qemu_opts_foreach(QemuOptsList *list,
qemu_opts_loopfunc func, void *opaque,
     }
     return rc;
 }
+
+static char legacy_options[8192];
+
+void qemu_opt_legacy_add(const char *opt, const char *optarg)
+{
+    strncat(legacy_options, " -", 8192);
+    strncat(legacy_options, opt, 8192);
+    if (optarg) {
+	strncat(legacy_options, " ", 8192);
+	strncat(legacy_options, optarg, 8192);
+    }
+}
+
+void qemu_opt_legacy_print(FILE *file)
+{
+    fprintf(file, "%s", legacy_options);
+}
diff --git a/qemu-option.h b/qemu-option.h
index 666b666..5a8cb61 100644
--- a/qemu-option.h
+++ b/qemu-option.h
@@ -124,4 +124,7 @@  int qemu_opts_print(QemuOpts *opts, void *dummy);
 int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void
*opaque,
                       int abort_on_failure);
 
+void qemu_opt_legacy_add(const char *opt, const char *optarg);
+void qemu_opt_legacy_print(FILE *file);
+
 #endif
diff --git a/vl.c b/vl.c
index b090022..44f8fed 100644
--- a/vl.c
+++ b/vl.c
@@ -4887,6 +4887,7 @@  int main(int argc, char **argv, char **envp)
 
             switch(popt->index) {
             case QEMU_OPTION_M:
+	        qemu_opt_legacy_add("M", optarg);
                 machine = find_machine(optarg);
                 if (!machine) {
                     QEMUMachine *m;
@@ -4903,6 +4904,7 @@  int main(int argc, char **argv, char **envp)
                 }
                 break;
             case QEMU_OPTION_cpu:
+	        qemu_opt_legacy_add("cpu", optarg);
                 /* hw initialization will check this */
                 if (*optarg == '?') {
 /* XXX: implement xxx_cpu_list for targets that still miss it */
@@ -4915,6 +4917,7 @@  int main(int argc, char **argv, char **envp)
                 }
                 break;
             case QEMU_OPTION_initrd:
+	        qemu_opt_legacy_add("initrd", optarg);
                 initrd_filename = optarg;
                 break;
             case QEMU_OPTION_hda:
@@ -4951,6 +4954,7 @@  int main(int argc, char **argv, char **envp)
                 drive_add(optarg, PFLASH_ALIAS);
                 break;
             case QEMU_OPTION_snapshot:
+	        qemu_opt_legacy_add("snapshot", NULL);
                 snapshot = 1;
                 break;
             case QEMU_OPTION_hdachs:
@@ -5003,6 +5007,7 @@  int main(int argc, char **argv, char **envp)
                 }
                 break;
             case QEMU_OPTION_numa:
+	        qemu_opt_legacy_add("numa", optarg);
                 if (nb_numa_nodes >= MAX_NODES) {
                     fprintf(stderr, "qemu: too many NUMA nodes\n");
                     exit(1);
@@ -5010,26 +5015,32 @@  int main(int argc, char **argv, char **envp)
                 numa_add(optarg);
                 break;
             case QEMU_OPTION_nographic:
+	        qemu_opt_legacy_add("nographic", NULL);
                 display_type = DT_NOGRAPHIC;
                 break;
 #ifdef CONFIG_CURSES
             case QEMU_OPTION_curses:
+	        qemu_opt_legacy_add("curses", NULL);
                 display_type = DT_CURSES;
                 break;
 #endif
             case QEMU_OPTION_portrait:
+	        qemu_opt_legacy_add("portrait", NULL);
                 graphic_rotate = 1;
                 break;
             case QEMU_OPTION_kernel:
+	        qemu_opt_legacy_add("kernel", optarg);
                 kernel_filename = optarg;
                 break;
             case QEMU_OPTION_append:
+	        qemu_opt_legacy_add("append", optarg);
                 kernel_cmdline = optarg;
                 break;
             case QEMU_OPTION_cdrom:
                 drive_add(optarg, CDROM_ALIAS);
                 break;
             case QEMU_OPTION_boot:
+	        qemu_opt_legacy_add("boot", optarg);
                 {
                     static const char * const params[] = {
                         "order", "once", "menu", NULL
@@ -5084,6 +5095,7 @@  int main(int argc, char **argv, char **envp)
                 break;
 #ifdef TARGET_I386
             case QEMU_OPTION_no_fd_bootchk:
+	        qemu_opt_legacy_add("no-fd-bootchk", NULL);
                 fd_bootchk = 0;
                 break;
 #endif
@@ -5099,23 +5111,28 @@  int main(int argc, char **argv, char **envp)
                 break;
 #ifdef CONFIG_SLIRP
             case QEMU_OPTION_tftp:
+	        qemu_opt_legacy_add("tftp", optarg);
                 legacy_tftp_prefix = optarg;
                 break;
             case QEMU_OPTION_bootp:
+	        qemu_opt_legacy_add("bootp", optarg);
                 legacy_bootp_filename = optarg;
                 break;
 #ifndef _WIN32
             case QEMU_OPTION_smb:
+	        qemu_opt_legacy_add("smb", optarg);
                 if (net_slirp_smb(optarg) < 0)
                     exit(1);
                 break;
 #endif
             case QEMU_OPTION_redir:
+	        qemu_opt_legacy_add("redir", optarg);
                 if (net_slirp_redir(optarg) < 0)
                     exit(1);
                 break;
 #endif
             case QEMU_OPTION_bt:
+	        qemu_opt_legacy_add("bt", optarg);
                 add_device_config(DEV_BT, optarg);
                 break;
 #ifdef HAS_AUDIO
@@ -5124,6 +5141,7 @@  int main(int argc, char **argv, char **envp)
                 exit (0);
                 break;
             case QEMU_OPTION_soundhw:
+	        qemu_opt_legacy_add("soundhw", optarg);
                 select_soundhw (optarg);
                 break;
 #endif
@@ -5135,6 +5153,7 @@  int main(int argc, char **argv, char **envp)
                 exit(0);
                 break;
             case QEMU_OPTION_m: {
+	        qemu_opt_legacy_add("m", optarg);
                 uint64_t value;
                 char *ptr;
 
@@ -5164,6 +5183,7 @@  int main(int argc, char **argv, char **envp)
                 break;
             }
             case QEMU_OPTION_d:
+	        qemu_opt_legacy_add("d", optarg);
                 {
                     int mask;
                     const CPULogItem *item;
@@ -5180,32 +5200,41 @@  int main(int argc, char **argv, char **envp)
                 }
                 break;
             case QEMU_OPTION_s:
+	        qemu_opt_legacy_add("s", NULL);
                 gdbstub_dev = "tcp::" DEFAULT_GDBSTUB_PORT;
                 break;
             case QEMU_OPTION_gdb:
+	        qemu_opt_legacy_add("gdb", optarg);
                 gdbstub_dev = optarg;
                 break;
             case QEMU_OPTION_L:
+	        qemu_opt_legacy_add("L", optarg);
                 data_dir = optarg;
                 break;
             case QEMU_OPTION_bios:
+	        qemu_opt_legacy_add("bios", optarg);
                 bios_name = optarg;
                 break;
             case QEMU_OPTION_singlestep:
+	        qemu_opt_legacy_add("singlestep", NULL);
                 singlestep = 1;
                 break;
             case QEMU_OPTION_S:
+	        qemu_opt_legacy_add("S", NULL);
                 autostart = 0;
                 break;
 #ifndef _WIN32
 	    case QEMU_OPTION_k:
+	        qemu_opt_legacy_add("k", optarg);
 		keyboard_layout = optarg;
 		break;
 #endif
             case QEMU_OPTION_localtime:
+	        qemu_opt_legacy_add("localtime", NULL);
                 rtc_utc = 0;
                 break;
             case QEMU_OPTION_vga:
+	        qemu_opt_legacy_add("vga", optarg);
                 select_vgahw (optarg);
                 break;
 #if defined(TARGET_PPC) || defined(TARGET_SPARC)
@@ -5245,6 +5274,7 @@  int main(int argc, char **argv, char **envp)
                 break;
 #endif
             case QEMU_OPTION_echr:
+	        qemu_opt_legacy_add("echr", optarg);
                 {
                     char *r;
                     term_escape_char = strtol(optarg, &r, 0);
@@ -5253,6 +5283,7 @@  int main(int argc, char **argv, char **envp)
                     break;
                 }
             case QEMU_OPTION_monitor:
+	        qemu_opt_legacy_add("monitor", optarg);
                 if (monitor_device_index >= MAX_MONITOR_DEVICES) {
                     fprintf(stderr, "qemu: too many monitor devices
\n");