qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

monitor: Move monitor option parsing to monitor/monitor.c

Both the system emulators and tools with QMP support (specifically, the
planned storage daemon) will need to parse monitor options, so move that
code to monitor/monitor.c, which can be linked into binaries that aren't
a system emulator.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200129102239.31435-2-kwolf@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>

authored by

Kevin Wolf and committed by
Markus Armbruster
c3e95551 9ced5c7c

+52 -45
+3
include/monitor/monitor.h
··· 10 10 11 11 #define QMP_REQ_QUEUE_LEN_MAX 8 12 12 13 + extern QemuOptsList qemu_mon_opts; 14 + 13 15 bool monitor_cur_is_qmp(void); 14 16 15 17 void monitor_init_globals(void); 16 18 void monitor_init_globals_core(void); 17 19 void monitor_init_qmp(Chardev *chr, bool pretty); 18 20 void monitor_init_hmp(Chardev *chr, bool use_readline); 21 + int monitor_init_opts(QemuOpts *opts, Error **errp); 19 22 void monitor_cleanup(void); 20 23 21 24 int monitor_suspend(Monitor *mon);
-1
include/sysemu/sysemu.h
··· 125 125 extern QemuOptsList qemu_nic_opts; 126 126 extern QemuOptsList qemu_net_opts; 127 127 extern QemuOptsList qemu_global_opts; 128 - extern QemuOptsList qemu_mon_opts; 129 128 extern QemuOptsList qemu_semihosting_config_opts; 130 129 131 130 #endif
+48
monitor/monitor.c
··· 609 609 NULL); 610 610 } 611 611 612 + int monitor_init_opts(QemuOpts *opts, Error **errp) 613 + { 614 + Chardev *chr; 615 + bool qmp; 616 + bool pretty = false; 617 + const char *chardev; 618 + const char *mode; 619 + 620 + mode = qemu_opt_get(opts, "mode"); 621 + if (mode == NULL) { 622 + mode = "readline"; 623 + } 624 + if (strcmp(mode, "readline") == 0) { 625 + qmp = false; 626 + } else if (strcmp(mode, "control") == 0) { 627 + qmp = true; 628 + } else { 629 + error_setg(errp, "unknown monitor mode \"%s\"", mode); 630 + return -1; 631 + } 632 + 633 + if (!qmp && qemu_opt_get(opts, "pretty")) { 634 + warn_report("'pretty' is deprecated for HMP monitors, it has no effect " 635 + "and will be removed in future versions"); 636 + } 637 + if (qemu_opt_get_bool(opts, "pretty", 0)) { 638 + pretty = true; 639 + } 640 + 641 + chardev = qemu_opt_get(opts, "chardev"); 642 + if (!chardev) { 643 + error_report("chardev is required"); 644 + exit(1); 645 + } 646 + chr = qemu_chr_find(chardev); 647 + if (chr == NULL) { 648 + error_setg(errp, "chardev \"%s\" not found", chardev); 649 + return -1; 650 + } 651 + 652 + if (qmp) { 653 + monitor_init_qmp(chr, pretty); 654 + } else { 655 + monitor_init_hmp(chr, true); 656 + } 657 + return 0; 658 + } 659 + 612 660 QemuOptsList qemu_mon_opts = { 613 661 .name = "mon", 614 662 .implied_opt_name = "chardev",
+1 -44
vl.c
··· 2127 2127 2128 2128 static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp) 2129 2129 { 2130 - Chardev *chr; 2131 - bool qmp; 2132 - bool pretty = false; 2133 - const char *chardev; 2134 - const char *mode; 2135 - 2136 - mode = qemu_opt_get(opts, "mode"); 2137 - if (mode == NULL) { 2138 - mode = "readline"; 2139 - } 2140 - if (strcmp(mode, "readline") == 0) { 2141 - qmp = false; 2142 - } else if (strcmp(mode, "control") == 0) { 2143 - qmp = true; 2144 - } else { 2145 - error_setg(errp, "unknown monitor mode \"%s\"", mode); 2146 - return -1; 2147 - } 2148 - 2149 - if (!qmp && qemu_opt_get(opts, "pretty")) { 2150 - warn_report("'pretty' is deprecated for HMP monitors, it has no effect " 2151 - "and will be removed in future versions"); 2152 - } 2153 - if (qemu_opt_get_bool(opts, "pretty", 0)) { 2154 - pretty = true; 2155 - } 2156 - 2157 - chardev = qemu_opt_get(opts, "chardev"); 2158 - if (!chardev) { 2159 - error_report("chardev is required"); 2160 - exit(1); 2161 - } 2162 - chr = qemu_chr_find(chardev); 2163 - if (chr == NULL) { 2164 - error_setg(errp, "chardev \"%s\" not found", chardev); 2165 - return -1; 2166 - } 2167 - 2168 - if (qmp) { 2169 - monitor_init_qmp(chr, pretty); 2170 - } else { 2171 - monitor_init_hmp(chr, true); 2172 - } 2173 - return 0; 2130 + return monitor_init_opts(opts, errp); 2174 2131 } 2175 2132 2176 2133 static void monitor_parse(const char *optarg, const char *mode, bool pretty)