Skip to contentSkip to conversation

Initial support for multi-process qemu

PATCH Superseded Jagannathan Raman 10 participants 117 messages Feb 24, 2020 – Mar 29, 2020 Page 2 of 2

Subsystems (4)

v5 of 21 Superseded Latest is v21 →

lore
Share & tools
lore
#68 lore raw

Re: [PATCH v5 36/50] multi-process/mon: enable QMP module support in the remote process

In reply to Jagannathan Raman
Quoted 5 lines · * Jagannathan Raman ([email protected]) wrote:

Build system changes to enable QMP module in the remote process

It's odd that this is labelled as QMP changes yet a lot of the code is actually HMP de-staticing.

Dave

Quoted 602 lines
---
 Makefile.objs              |  9 +++++
 Makefile.target            | 35 +++++++++++++++++--
 hmp-commands.hx            |  5 +--
 hw/core/Makefile.objs      |  1 +
 monitor/Makefile.objs      |  4 +++
 monitor/misc.c             | 84 +++++++++++++++++++++++++---------------------
 monitor/monitor-internal.h | 38 +++++++++++++++++++++
 qapi/Makefile.objs         |  2 ++
 qom/Makefile.objs          |  1 +
 ui/Makefile.objs           |  2 ++
 10 files changed, 139 insertions(+), 42 deletions(-)
Makefile.objs +9 -0
index 689a722..4b5db09 100644
@@ -32,6 +32,7 @@ remote-pci-obj-$(CONFIG_MPQEMU) += migration/
 remote-pci-obj-$(CONFIG_MPQEMU) += remote/
 remote-pci-obj-$(CONFIG_MPQEMU) += accel/
 remote-pci-obj-$(CONFIG_MPQEMU) += util/
+remote-pci-obj-$(CONFIG_MPQEMU) += monitor/
 
 remote-pci-obj-$(CONFIG_MPQEMU) += cpus-common.o
 remote-pci-obj-$(CONFIG_MPQEMU) += dma-helpers.o
@@ -44,6 +45,9 @@ remote-pci-obj-$(CONFIG_MPQEMU) += iothread.o
 # remote-lsi-obj-y is code used to implement remote LSI device
 
 remote-lsi-obj-$(CONFIG_MPQEMU) += hw/
+remote-lsi-obj-$(CONFIG_MPQEMU) += ui/
+
+remote-lsi-obj-$(CONFIG_MPQEMU) += device-hotplug.o
 
 #######################################################################
 # crypto-obj-y is code used by both qemu system emulation and qemu-img
@@ -105,6 +109,11 @@ common-obj-y += qapi/
 
 endif # CONFIG_SOFTMMU
 
+remote-pci-obj-$(CONFIG_MPQEMU) += qapi/
+remote-pci-obj-$(CONFIG_MPQEMU) += blockdev-nbd.o
+remote-pci-obj-$(CONFIG_MPQEMU) += job-qmp.o
+remote-pci-obj-$(CONFIG_MPQEMU) += balloon.o
+
 #######################################################################
 # Target-independent parts used in system and user emulation
 common-obj-y += cpus-common.o
Makefile.target +33 -2
index 035c23b..4ead5c3 100644
@@ -142,13 +142,32 @@ remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/hax-stub.o
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/whpx-stub.o
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/vl-stub.o
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/net-stub.o
-remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/monitor.o
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/replay.o
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/xen-mapcache.o
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/audio.o
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/monitor.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/migration.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/ui-stub.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/gdbstub.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/qapi-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/qapi-misc.o
 
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += remote/memory.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += arch_init.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += monitor/misc.o
+
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-introspect.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-block-core.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-block.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-misc.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-machine-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-misc-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-visit-machine-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-visit-misc-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-types-machine-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-types-misc-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-init-commands.o
 endif
 
 #########################################################
@@ -203,6 +222,10 @@ endif
 generated-files-y += hmp-commands.h hmp-commands-info.h
 generated-files-y += config-devices.h
 
+ifdef CONFIG_MPQEMU
+generated-files-y += hmp-scsi-commands.h hmp-scsi-commands-info.h
+endif
+
 endif # CONFIG_SOFTMMU
 
 dummy := $(call unnest-vars,,obj-y)
@@ -288,10 +311,18 @@ hmp-commands.h: $(SRC_PATH)/hmp-commands.hx $(SRC_PATH)/scripts/hxtool
 hmp-commands-info.h: $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/scripts/hxtool
 	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"GEN","$(TARGET_DIR)$@")
 
+ifdef CONFIG_MPQEMU
+hmp-scsi-commands.h: $(SRC_PATH)/hmp-commands.hx $(SRC_PATH)/scripts/hxtool
+	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -tgt scsi < $< > $@)
+
+hmp-scsi-commands-info.h: $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/scripts/hxtool
+	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -tgt scsi < $< > $@)
+endif
+
 clean: clean-target
 	rm -f *.a *~ $(PROGS)
 	rm -f $(shell find . -name '*.[od]')
-	rm -f hmp-commands.h gdbstub-xml.c
+	rm -f hmp-commands.h gdbstub-xml.c hmp-scsi-commands.h hmp-scsi-commands-info.h
 	rm -f trace/generated-helpers.c trace/generated-helpers.c-timestamp
 ifdef CONFIG_TRACE_SYSTEMTAP
 	rm -f *.stp
hmp-commands.hx +3 -2
index ecc6169..a1932c4 100644
@@ -14,7 +14,8 @@ ETEXI
         .args_type  = "name:S?",
         .params     = "[cmd]",
         .help       = "show the help",
-        .cmd        = do_help_cmd,
+        .cmd        = hmp_do_help_cmd,
+        .targets    = "scsi",
         .flags      = "p",
     },
 
@@ -618,7 +619,7 @@ ETEXI
         .args_type  = "fmt:/,val:l",
         .params     = "/fmt expr",
         .help       = "print expression value (use $reg for CPU register access)",
-        .cmd        = do_print,
+        .cmd        = hmp_do_print,
     },
 
 STEXI
hw/core/Makefile.objs +1 -0
index e3e8084..251b77b 100644
@@ -49,3 +49,4 @@ remote-pci-obj-$(CONFIG_MPQEMU) += numa.o
 remote-pci-obj-$(CONFIG_MPQEMU) += cpu.o
 remote-pci-obj-$(CONFIG_MPQEMU) += vmstate-if.o
 remote-pci-obj-$(CONFIG_MPQEMU) += resettable.o
+remote-pci-obj-$(CONFIG_MPQEMU) += machine-qmp-cmds.o
monitor/Makefile.objs +4 -0
index 9244d90..48d8017 100644
@@ -2,3 +2,7 @@ obj-y += misc.o
 common-obj-y += monitor.o qmp.o hmp.o
 common-obj-y += qmp-cmds.o qmp-cmds-control.o
 common-obj-y += hmp-cmds.o
+
+remote-pci-obj-$(CONFIG_MPQEMU) += monitor.o qmp.o hmp.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qmp-cmds.o qmp-cmds-control.o
+remote-pci-obj-$(CONFIG_MPQEMU) += hmp-cmds.o
monitor/misc.c +46 -38
index 6c41293..f1f09bf 100644
@@ -177,12 +177,12 @@ int hmp_compare_cmd(const char *name, const char *list)
     return 0;
 }
 
-static void do_help_cmd(Monitor *mon, const QDict *qdict)
+void hmp_do_help_cmd(Monitor *mon, const QDict *qdict)
 {
     help_cmd(mon, qdict_get_try_str(qdict, "name"));
 }
 
-static void hmp_trace_event(Monitor *mon, const QDict *qdict)
+void hmp_trace_event(Monitor *mon, const QDict *qdict)
 {
     const char *tp_name = qdict_get_str(qdict, "name");
     bool new_state = qdict_get_bool(qdict, "option");
@@ -226,7 +226,7 @@ static void hmp_trace_file(Monitor *mon, const QDict *qdict)
 }
 #endif
 
-static void hmp_info_help(Monitor *mon, const QDict *qdict)
+void hmp_info_help(Monitor *mon, const QDict *qdict)
 {
     help_cmd(mon, "info");
 }
@@ -314,7 +314,7 @@ int monitor_get_cpu_index(void)
     return cs ? cs->cpu_index : UNASSIGNED_CPU_INDEX;
 }
 
-static void hmp_info_registers(Monitor *mon, const QDict *qdict)
+void hmp_info_registers(Monitor *mon, const QDict *qdict)
 {
     bool all_cpus = qdict_get_try_bool(qdict, "cpustate_all", false);
     CPUState *cs;
@@ -337,7 +337,7 @@ static void hmp_info_registers(Monitor *mon, const QDict *qdict)
 }
 
 #ifdef CONFIG_TCG
-static void hmp_info_jit(Monitor *mon, const QDict *qdict)
+void hmp_info_jit(Monitor *mon, const QDict *qdict)
 {
     if (!tcg_enabled()) {
         error_report("JIT information is only available with accel=tcg");
@@ -348,13 +348,13 @@ static void hmp_info_jit(Monitor *mon, const QDict *qdict)
     dump_drift_info();
 }
 
-static void hmp_info_opcount(Monitor *mon, const QDict *qdict)
+void hmp_info_opcount(Monitor *mon, const QDict *qdict)
 {
     dump_opcount_info();
 }
 #endif
 
-static void hmp_info_sync_profile(Monitor *mon, const QDict *qdict)
+void hmp_info_sync_profile(Monitor *mon, const QDict *qdict)
 {
     int64_t max = qdict_get_try_int(qdict, "max", 10);
     bool mean = qdict_get_try_bool(qdict, "mean", false);
@@ -365,7 +365,7 @@ static void hmp_info_sync_profile(Monitor *mon, const QDict *qdict)
     qsp_report(max, sort_by, coalesce);
 }
 
-static void hmp_info_history(Monitor *mon, const QDict *qdict)
+void hmp_info_history(Monitor *mon, const QDict *qdict)
 {
     MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
     int i;
@@ -385,7 +385,7 @@ static void hmp_info_history(Monitor *mon, const QDict *qdict)
     }
 }
 
-static void hmp_info_cpustats(Monitor *mon, const QDict *qdict)
+void hmp_info_cpustats(Monitor *mon, const QDict *qdict)
 {
     CPUState *cs = mon_get_cpu();
 
@@ -396,7 +396,7 @@ static void hmp_info_cpustats(Monitor *mon, const QDict *qdict)
     cpu_dump_statistics(cs, 0);
 }
 
-static void hmp_info_trace_events(Monitor *mon, const QDict *qdict)
+void hmp_info_trace_events(Monitor *mon, const QDict *qdict)
 {
     const char *name = qdict_get_try_str(qdict, "name");
     bool has_vcpu = qdict_haskey(qdict, "vcpu");
@@ -456,7 +456,7 @@ void qmp_client_migrate_info(const char *protocol, const char *hostname,
     error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "protocol", "spice");
 }
 
-static void hmp_logfile(Monitor *mon, const QDict *qdict)
+void hmp_logfile(Monitor *mon, const QDict *qdict)
 {
     Error *err = NULL;
 
@@ -466,7 +466,7 @@ static void hmp_logfile(Monitor *mon, const QDict *qdict)
     }
 }
 
-static void hmp_log(Monitor *mon, const QDict *qdict)
+void hmp_log(Monitor *mon, const QDict *qdict)
 {
     int mask;
     const char *items = qdict_get_str(qdict, "items");
@@ -483,7 +483,7 @@ static void hmp_log(Monitor *mon, const QDict *qdict)
     qemu_set_log(mask);
 }
 
-static void hmp_singlestep(Monitor *mon, const QDict *qdict)
+void hmp_singlestep(Monitor *mon, const QDict *qdict)
 {
     const char *option = qdict_get_try_str(qdict, "option");
     if (!option || !strcmp(option, "on")) {
@@ -495,7 +495,7 @@ static void hmp_singlestep(Monitor *mon, const QDict *qdict)
     }
 }
 
-static void hmp_gdbserver(Monitor *mon, const QDict *qdict)
+void hmp_gdbserver(Monitor *mon, const QDict *qdict)
 {
     const char *device = qdict_get_try_str(qdict, "device");
     if (!device)
@@ -511,7 +511,7 @@ static void hmp_gdbserver(Monitor *mon, const QDict *qdict)
     }
 }
 
-static void hmp_watchdog_action(Monitor *mon, const QDict *qdict)
+void hmp_watchdog_action(Monitor *mon, const QDict *qdict)
 {
     const char *action = qdict_get_str(qdict, "action");
     if (select_watchdog_action(action) == -1) {
@@ -653,7 +653,7 @@ static void memory_dump(Monitor *mon, int count, int format, int wsize,
     }
 }
 
-static void hmp_memory_dump(Monitor *mon, const QDict *qdict)
+void hmp_memory_dump(Monitor *mon, const QDict *qdict)
 {
     int count = qdict_get_int(qdict, "count");
     int format = qdict_get_int(qdict, "format");
@@ -663,7 +663,7 @@ static void hmp_memory_dump(Monitor *mon, const QDict *qdict)
     memory_dump(mon, count, format, size, addr, 0);
 }
 
-static void hmp_physical_memory_dump(Monitor *mon, const QDict *qdict)
+void hmp_physical_memory_dump(Monitor *mon, const QDict *qdict)
 {
     int count = qdict_get_int(qdict, "count");
     int format = qdict_get_int(qdict, "format");
@@ -693,7 +693,7 @@ static void *gpa2hva(MemoryRegion **p_mr, hwaddr addr, Error **errp)
     return qemu_map_ram_ptr(mrs.mr->ram_block, mrs.offset_within_region);
 }
 
-static void hmp_gpa2hva(Monitor *mon, const QDict *qdict)
+void hmp_gpa2hva(Monitor *mon, const QDict *qdict)
 {
     hwaddr addr = qdict_get_int(qdict, "addr");
     Error *local_err = NULL;
@@ -713,7 +713,7 @@ static void hmp_gpa2hva(Monitor *mon, const QDict *qdict)
     memory_region_unref(mr);
 }
 
-static void hmp_gva2gpa(Monitor *mon, const QDict *qdict)
+void hmp_gva2gpa(Monitor *mon, const QDict *qdict)
 {
     target_ulong addr = qdict_get_int(qdict, "addr");
     MemTxAttrs attrs;
@@ -768,7 +768,7 @@ out:
     return ret;
 }
 
-static void hmp_gpa2hpa(Monitor *mon, const QDict *qdict)
+void hmp_gpa2hpa(Monitor *mon, const QDict *qdict)
 {
     hwaddr addr = qdict_get_int(qdict, "addr");
     Error *local_err = NULL;
@@ -795,7 +795,7 @@ static void hmp_gpa2hpa(Monitor *mon, const QDict *qdict)
 }
 #endif
 
-static void do_print(Monitor *mon, const QDict *qdict)
+void hmp_do_print(Monitor *mon, const QDict *qdict)
 {
     int format = qdict_get_int(qdict, "format");
     hwaddr val = qdict_get_int(qdict, "val");
@@ -821,7 +821,7 @@ static void do_print(Monitor *mon, const QDict *qdict)
     monitor_printf(mon, "\n");
 }
 
-static void hmp_sum(Monitor *mon, const QDict *qdict)
+void hmp_sum(Monitor *mon, const QDict *qdict)
 {
     uint32_t addr;
     uint16_t sum;
@@ -841,7 +841,7 @@ static void hmp_sum(Monitor *mon, const QDict *qdict)
 
 static int mouse_button_state;
 
-static void hmp_mouse_move(Monitor *mon, const QDict *qdict)
+void hmp_mouse_move(Monitor *mon, const QDict *qdict)
 {
     int dx, dy, dz, button;
     const char *dx_str = qdict_get_str(qdict, "dx_str");
@@ -865,7 +865,7 @@ static void hmp_mouse_move(Monitor *mon, const QDict *qdict)
     qemu_input_event_sync();
 }
 
-static void hmp_mouse_button(Monitor *mon, const QDict *qdict)
+void hmp_mouse_button(Monitor *mon, const QDict *qdict)
 {
     static uint32_t bmap[INPUT_BUTTON__MAX] = {
         [INPUT_BUTTON_LEFT]       = MOUSE_EVENT_LBUTTON,
@@ -882,7 +882,7 @@ static void hmp_mouse_button(Monitor *mon, const QDict *qdict)
     mouse_button_state = button_state;
 }
 
-static void hmp_ioport_read(Monitor *mon, const QDict *qdict)
+void hmp_ioport_read(Monitor *mon, const QDict *qdict)
 {
     int size = qdict_get_int(qdict, "size");
     int addr = qdict_get_int(qdict, "addr");
@@ -916,7 +916,7 @@ static void hmp_ioport_read(Monitor *mon, const QDict *qdict)
                    suffix, addr, size * 2, val);
 }
 
-static void hmp_ioport_write(Monitor *mon, const QDict *qdict)
+void hmp_ioport_write(Monitor *mon, const QDict *qdict)
 {
     int size = qdict_get_int(qdict, "size");
     int addr = qdict_get_int(qdict, "addr");
@@ -938,7 +938,7 @@ static void hmp_ioport_write(Monitor *mon, const QDict *qdict)
     }
 }
 
-static void hmp_boot_set(Monitor *mon, const QDict *qdict)
+void hmp_boot_set(Monitor *mon, const QDict *qdict)
 {
     Error *local_err = NULL;
     const char *bootdevice = qdict_get_str(qdict, "bootdevice");
@@ -951,7 +951,7 @@ static void hmp_boot_set(Monitor *mon, const QDict *qdict)
     }
 }
 
-static void hmp_info_mtree(Monitor *mon, const QDict *qdict)
+void hmp_info_mtree(Monitor *mon, const QDict *qdict)
 {
     bool flatview = qdict_get_try_bool(qdict, "flatview", false);
     bool dispatch_tree = qdict_get_try_bool(qdict, "dispatch_tree", false);
@@ -964,7 +964,7 @@ static void hmp_info_mtree(Monitor *mon, const QDict *qdict)
 
 int64_t dev_time;
 
-static void hmp_info_profile(Monitor *mon, const QDict *qdict)
+void hmp_info_profile(Monitor *mon, const QDict *qdict)
 {
     static int64_t last_cpu_exec_time;
     int64_t cpu_exec_time;
@@ -981,7 +981,7 @@ static void hmp_info_profile(Monitor *mon, const QDict *qdict)
     dev_time = 0;
 }
 #else
-static void hmp_info_profile(Monitor *mon, const QDict *qdict)
+void hmp_info_profile(Monitor *mon, const QDict *qdict)
 {
     monitor_printf(mon, "Internal profiler not compiled\n");
 }
@@ -990,7 +990,7 @@ static void hmp_info_profile(Monitor *mon, const QDict *qdict)
 /* Capture support */
 static QLIST_HEAD (capture_list_head, CaptureState) capture_head;
 
-static void hmp_info_capture(Monitor *mon, const QDict *qdict)
+void hmp_info_capture(Monitor *mon, const QDict *qdict)
 {
     int i;
     CaptureState *s;
@@ -1001,7 +1001,7 @@ static void hmp_info_capture(Monitor *mon, const QDict *qdict)
     }
 }
 
-static void hmp_stopcapture(Monitor *mon, const QDict *qdict)
+void hmp_stopcapture(Monitor *mon, const QDict *qdict)
 {
     int i;
     int n = qdict_get_int(qdict, "n");
@@ -1017,7 +1017,7 @@ static void hmp_stopcapture(Monitor *mon, const QDict *qdict)
     }
 }
 
-static void hmp_wavcapture(Monitor *mon, const QDict *qdict)
+void hmp_wavcapture(Monitor *mon, const QDict *qdict)
 {
     const char *path = qdict_get_str(qdict, "path");
     int freq = qdict_get_try_int(qdict, "freq", 44100);
@@ -1070,7 +1070,7 @@ static void hmp_warn_acl(void)
     warn_acl = true;
 }
 
-static void hmp_acl_show(Monitor *mon, const QDict *qdict)
+void hmp_acl_show(Monitor *mon, const QDict *qdict)
 {
     const char *aclname = qdict_get_str(qdict, "aclname");
     QAuthZList *auth = find_auth(mon, aclname);
@@ -1097,7 +1097,7 @@ static void hmp_acl_show(Monitor *mon, const QDict *qdict)
     }
 }
 
-static void hmp_acl_reset(Monitor *mon, const QDict *qdict)
+void hmp_acl_reset(Monitor *mon, const QDict *qdict)
 {
     const char *aclname = qdict_get_str(qdict, "aclname");
     QAuthZList *auth = find_auth(mon, aclname);
@@ -1114,7 +1114,7 @@ static void hmp_acl_reset(Monitor *mon, const QDict *qdict)
     monitor_printf(mon, "acl: removed all rules\n");
 }
 
-static void hmp_acl_policy(Monitor *mon, const QDict *qdict)
+void hmp_acl_policy(Monitor *mon, const QDict *qdict)
 {
     const char *aclname = qdict_get_str(qdict, "aclname");
     const char *policy = qdict_get_str(qdict, "policy");
@@ -1155,7 +1155,7 @@ static QAuthZListFormat hmp_acl_get_format(const char *match)
     }
 }
 
-static void hmp_acl_add(Monitor *mon, const QDict *qdict)
+void hmp_acl_add(Monitor *mon, const QDict *qdict)
 {
     const char *aclname = qdict_get_str(qdict, "aclname");
     const char *match = qdict_get_str(qdict, "match");
@@ -1208,7 +1208,7 @@ static void hmp_acl_add(Monitor *mon, const QDict *qdict)
     }
 }
 
-static void hmp_acl_remove(Monitor *mon, const QDict *qdict)
+void hmp_acl_remove(Monitor *mon, const QDict *qdict)
 {
     const char *aclname = qdict_get_str(qdict, "aclname");
     const char *match = qdict_get_str(qdict, "match");
@@ -1678,13 +1678,21 @@ int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp)
 
 /* Please update hmp-commands.hx when adding or changing commands */
 static HMPCommand hmp_info_cmds[] = {
+#if defined(SCSI_PROCESS)
+#include "hmp-scsi-commands-info.h"
+#else
 #include "hmp-commands-info.h"
+#endif
     { NULL, NULL, },
 };
 
 /* hmp_cmds and hmp_info_cmds would be sorted at runtime */
 HMPCommand hmp_cmds[] = {
+#if defined(SCSI_PROCESS)
+#include "hmp-scsi-commands.h"
+#else
 #include "hmp-commands.h"
+#endif
     { NULL, NULL, },
 };
 
monitor/monitor-internal.h +38 -0
index 3e6baba..26349cb 100644
@@ -183,4 +183,42 @@ int hmp_compare_cmd(const char *name, const char *list);
 void qmp_query_qmp_schema(QDict *qdict, QObject **ret_data,
                                  Error **errp);
 
+void hmp_do_help_cmd(Monitor *mon, const QDict *qdict);
+void hmp_trace_event(Monitor *mon, const QDict *qdict);
+void hmp_info_help(Monitor *mon, const QDict *qdict);
+void hmp_info_registers(Monitor *mon, const QDict *qdict);
+void hmp_info_jit(Monitor *mon, const QDict *qdict);
+void hmp_info_opcount(Monitor *mon, const QDict *qdict);
+void hmp_info_sync_profile(Monitor *mon, const QDict *qdict);
+void hmp_info_history(Monitor *mon, const QDict *qdict);
+void hmp_info_cpustats(Monitor *mon, const QDict *qdict);
+void hmp_info_trace_events(Monitor *mon, const QDict *qdict);
+void hmp_logfile(Monitor *mon, const QDict *qdict);
+void hmp_log(Monitor *mon, const QDict *qdict);
+void hmp_singlestep(Monitor *mon, const QDict *qdict);
+void hmp_gdbserver(Monitor *mon, const QDict *qdict);
+void hmp_watchdog_action(Monitor *mon, const QDict *qdict);
+void hmp_memory_dump(Monitor *mon, const QDict *qdict);
+void hmp_physical_memory_dump(Monitor *mon, const QDict *qdict);
+void hmp_gpa2hva(Monitor *mon, const QDict *qdict);
+void hmp_gva2gpa(Monitor *mon, const QDict *qdict);
+void hmp_gpa2hpa(Monitor *mon, const QDict *qdict);
+void hmp_do_print(Monitor *mon, const QDict *qdict);
+void hmp_sum(Monitor *mon, const QDict *qdict);
+void hmp_mouse_move(Monitor *mon, const QDict *qdict);
+void hmp_mouse_button(Monitor *mon, const QDict *qdict);
+void hmp_ioport_read(Monitor *mon, const QDict *qdict);
+void hmp_ioport_write(Monitor *mon, const QDict *qdict);
+void hmp_boot_set(Monitor *mon, const QDict *qdict);
+void hmp_info_mtree(Monitor *mon, const QDict *qdict);
+void hmp_info_profile(Monitor *mon, const QDict *qdict);
+void hmp_info_capture(Monitor *mon, const QDict *qdict);
+void hmp_stopcapture(Monitor *mon, const QDict *qdict);
+void hmp_wavcapture(Monitor *mon, const QDict *qdict);
+void hmp_acl_show(Monitor *mon, const QDict *qdict);
+void hmp_acl_reset(Monitor *mon, const QDict *qdict);
+void hmp_acl_policy(Monitor *mon, const QDict *qdict);
+void hmp_acl_add(Monitor *mon, const QDict *qdict);
+void hmp_acl_remove(Monitor *mon, const QDict *qdict);
+
 #endif
qapi/Makefile.objs +2 -0
index 20fcc37..a8a3925 100644
@@ -31,3 +31,5 @@ obj-y += qapi-events.o
 obj-y += $(QAPI_TARGET_MODULES:%=qapi-commands-%.o)
 obj-y += qapi-commands.o
 obj-y += qapi-init-commands.o
+
+remote-pci-obj-$(CONFIG_MPQEMU) += $(QAPI_COMMON_MODULES:%=qapi-commands-%.o)
qom/Makefile.objs +1 -0
index 07e50e5..16603d7 100644
@@ -5,3 +5,4 @@ common-obj-$(CONFIG_SOFTMMU) += qom-hmp-cmds.o qom-qmp-cmds.o
 
 remote-pci-obj-$(CONFIG_MPQEMU) += object.o qom-qobject.o container.o
 remote-pci-obj-$(CONFIG_MPQEMU) += object_interfaces.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qom-qmp-cmds.o qom-hmp-cmds.o
ui/Makefile.objs +2 -0
index e6da6ff..c3ac572 100644
@@ -68,3 +68,5 @@ console-gl.o-libs += $(OPENGL_LIBS)
 egl-helpers.o-libs += $(OPENGL_LIBS)
 egl-context.o-libs += $(OPENGL_LIBS)
 egl-headless.o-libs += $(OPENGL_LIBS)
+
+remote-lsi-obj-$(CONFIG_MPQEMU) += vnc-stubs.o
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

Reviewed-by on v5 37/50
#72 lore raw

Re: [PATCH v5 37/50] multi-process/mon: Refactor monitor/chardev functions out of vl.c

In reply to Jagannathan Raman
Quoted 8 lines · * Jagannathan Raman ([email protected]) wrote:

Some of the initialization helper functions w.r.t monitor & chardev in vl.c are also used by the remote process. Therefore, these functions are refactored into shared files that both QEMU & remote process could use.

This looks like another good candidate to go in a separate post that doesn't need to wait for the rest of multi-process; you are probably best splitting it into separate chardev and monitor chunks so they can go via their respective maintainers.

Dave

Quoted 206 lines
---
 chardev/char.c            | 14 ++++++++++++++
 include/chardev/char.h    |  1 +
 include/monitor/monitor.h |  2 ++
 monitor/monitor.c         | 40 ++++++++++++++++++++++++++++++++++++++-
 remote/remote-main.c      |  1 +
 remote/remote-opts.c      |  1 +
 softmmu/vl.c              | 48 -----------------------------------------------
 7 files changed, 58 insertions(+), 49 deletions(-)
chardev/char.c +14 -0
index 8723756..1d03ea0 100644
@@ -1189,4 +1189,18 @@ static void register_types(void)
     qemu_add_machine_init_done_notifier(&chardev_machine_done_notify);
 }
 
+int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp)
+{
+    Error *local_err = NULL;
+
+    if (!qemu_chr_new_from_opts(opts, NULL, &local_err)) {
+        if (local_err) {
+            error_propagate(errp, local_err);
+            return -1;
+        }
+        exit(0);
+    }
+    return 0;
+}
+
 type_init(register_types);
include/chardev/char.h +1 -0
index 00589a6..e370320 100644
@@ -290,4 +290,5 @@ GSource *qemu_chr_timeout_add_ms(Chardev *chr, guint ms,
 /* console.c */
 void qemu_chr_parse_vc(QemuOpts *opts, ChardevBackend *backend, Error **errp);
 
+int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp);
 #endif
include/monitor/monitor.h +2 -0
index b7bdd2b..d92bf1c 100644
@@ -45,5 +45,7 @@ int monitor_fdset_get_fd(int64_t fdset_id, int flags);
 int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd);
 void monitor_fdset_dup_fd_remove(int dup_fd);
 int64_t monitor_fdset_dup_fd_find(int dup_fd);
+void monitor_parse(const char *optarg, const char *mode, bool pretty);
+int mon_init_func(void *opaque, QemuOpts *opts, Error **errp);
 
 #endif /* MONITOR_H */
monitor/monitor.c +39 -1
index c1a6c44..5759b84 100644
@@ -33,7 +33,10 @@
 #include "sysemu/qtest.h"
 #include "sysemu/sysemu.h"
 #include "trace.h"
-
+#include "qemu/cutils.h"
+#include "qemu/option.h"
+#include "qemu-options.h"
+#include "qemu/config-file.h"
 /*
  * To prevent flooding clients, events can be throttled. The
  * throttling is calculated globally, rather than per-Monitor
@@ -609,6 +612,41 @@ void monitor_init_globals_core(void)
                                    NULL);
 }
 
+int mon_init_func(void *opaque, QemuOpts *opts, Error **errp)
+{
+    return monitor_init_opts(opts, errp);
+}
+
+void monitor_parse(const char *optarg, const char *mode, bool pretty)
+{
+    static int monitor_device_index;
+    QemuOpts *opts;
+    const char *p;
+    char label[32];
+
+    if (strstart(optarg, "chardev:", &p)) {
+        snprintf(label, sizeof(label), "%s", p);
+    } else {
+        snprintf(label, sizeof(label), "compat_monitor%d",
+                 monitor_device_index);
+        opts = qemu_chr_parse_compat(label, optarg, true);
+        if (!opts) {
+            error_report("parse error: %s", optarg);
+            exit(1);
+        }
+    }
+
+    opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal);
+    qemu_opt_set(opts, "mode", mode, &error_abort);
+    qemu_opt_set(opts, "chardev", label, &error_abort);
+    if (!strcmp(mode, "control")) {
+        qemu_opt_set_bool(opts, "pretty", pretty, &error_abort);
+    } else {
+        assert(pretty == false);
+    }
+    monitor_device_index++;
+}
+
 int monitor_init_opts(QemuOpts *opts, Error **errp)
 {
     Chardev *chr;
remote/remote-main.c +1 -0
index 5284ee9..23fc0df 100644
@@ -54,6 +54,7 @@
 #include "qemu/cutils.h"
 #include "remote-opts.h"
 #include "monitor/monitor.h"
+#include "chardev/char.h"
 #include "sysemu/reset.h"
 
 static MPQemuLinkState *mpqemu_link;
remote/remote-opts.c +1 -0
index 7e12700..565e641 100644
@@ -39,6 +39,7 @@
 #include "block/block.h"
 #include "remote/remote-opts.h"
 #include "include/qemu-common.h"
+#include "monitor/monitor.h"
 
 #include "vl.h"
 /*
softmmu/vl.c +0 -48
index a8a6f35..4a4f52c 100644
@@ -2133,19 +2133,6 @@ static int device_help_func(void *opaque, QemuOpts *opts, Error **errp)
     return qdev_device_help(opts);
 }
 
-static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp)
-{
-    Error *local_err = NULL;
-
-    if (!qemu_chr_new_from_opts(opts, NULL, &local_err)) {
-        if (local_err) {
-            error_propagate(errp, local_err);
-            return -1;
-        }
-        exit(0);
-    }
-    return 0;
-}
 
 #ifdef CONFIG_VIRTFS
 static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp)
@@ -2154,41 +2141,6 @@ static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp)
 }
 #endif
 
-static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp)
-{
-    return monitor_init_opts(opts, errp);
-}
-
-static void monitor_parse(const char *optarg, const char *mode, bool pretty)
-{
-    static int monitor_device_index = 0;
-    QemuOpts *opts;
-    const char *p;
-    char label[32];
-
-    if (strstart(optarg, "chardev:", &p)) {
-        snprintf(label, sizeof(label), "%s", p);
-    } else {
-        snprintf(label, sizeof(label), "compat_monitor%d",
-                 monitor_device_index);
-        opts = qemu_chr_parse_compat(label, optarg, true);
-        if (!opts) {
-            error_report("parse error: %s", optarg);
-            exit(1);
-        }
-    }
-
-    opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal);
-    qemu_opt_set(opts, "mode", mode, &error_abort);
-    qemu_opt_set(opts, "chardev", label, &error_abort);
-    if (!strcmp(mode, "control")) {
-        qemu_opt_set_bool(opts, "pretty", pretty, &error_abort);
-    } else {
-        assert(pretty == false);
-    }
-    monitor_device_index++;
-}
-
 struct device_config {
     enum {
         DEV_USB,       /* -usbdevice     */
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#85 lore raw

Re: [PATCH v5 41/50] multi-process/mig: Enable VMSD save in the Proxy object

In reply to Jagannathan Raman
Quoted 100 lines · * Jagannathan Raman ([email protected]) wrote:

Collect the VMSD from remote process on the source and save it to the channel leading to the destination

---
v4 -> v5:
- Using qemu_file_shutdown() instead of qemu_thread_cancel(). Removed patch which introduced qemu_thread_cancel()

 hw/proxy/qemu-proxy.c         | 135 ++++++++++++++++++++++++++++++++++++++++++
 include/hw/proxy/qemu-proxy.h |   2 +
 include/io/mpqemu-link.h      |   1 +
 3 files changed, 138 insertions(+)
hw/proxy/qemu-proxy.c +62 -0
index b1b9282..19f0dbb 100644
@@ -23,6 +23,14 @@
 #include "util/event_notifier-posix.c"
 #include "hw/boards.h"
 #include "include/qemu/log.h"
+#include "io/channel.h"
+#include "migration/qemu-file-types.h"
+#include "qapi/error.h"
+#include "io/channel-util.h"
+#include "migration/qemu-file-channel.h"
+#include "migration/qemu-file.h"
+#include "migration/migration.h"
+#include "migration/vmstate.h"
 
 QEMUTimer *hb_timer;
 static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp);
@@ -35,6 +43,9 @@ static void broadcast_init(void);
 static int config_op_send(PCIProxyDev *dev, uint32_t addr, uint32_t *val, int l,
                           unsigned int op);
 
+#define PAGE_SIZE qemu_real_host_page_size
+uint8_t *mig_data;
+
 static void childsig_handler(int sig, siginfo_t *siginfo, void *ctx)
 {
     /* TODO: Add proper handler. */
@@ -460,6 +471,129 @@ static void pci_proxy_dev_inst_init(Object *obj)
     dev->mem_init = false;
 }
 
+typedef struct {
+    QEMUFile *rem;
+    PCIProxyDev *dev;
+} proxy_mig_data;
+
+static void *proxy_mig_out(void *opaque)
+{
+    proxy_mig_data *data = opaque;
+    PCIProxyDev *dev = data->dev;
+    uint8_t byte;
+    uint64_t data_size = PAGE_SIZE;
+
+    mig_data = g_malloc(data_size);
+
+    while (true) {
+        byte = qemu_get_byte(data->rem);
+
+        if (qemu_file_get_error(data->rem)) {
+            break;
+        }
+
+        mig_data[dev->migsize++] = byte;
+        if (dev->migsize == data_size) {
+            data_size += PAGE_SIZE;
+            mig_data = g_realloc(mig_data, data_size);
+        }
+    }
+
+    return NULL;
+}
+
+static int proxy_pre_save(void *opaque)
+{
+    PCIProxyDev *pdev = opaque;
+    proxy_mig_data *mig_data;
+    QEMUFile *f_remote;
+    MPQemuMsg msg = {0};
+    QemuThread thread;
+    Error *err = NULL;
+    QIOChannel *ioc;
+    uint64_t size;
+    int fd[2];
+
+    if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) {
+        return -1;
+    }
+
+    ioc = qio_channel_new_fd(fd[0], &err);
+    if (err) {
+        error_report_err(err);
+        return -1;

hw/proxy/qemu-proxy.c static void pci_proxy_dev_inst_init(Object *obj) · line 534

Quoted 10 lines
hw/proxy/qemu-proxy.c +10 -0
+    }
+
+    qio_channel_set_name(QIO_CHANNEL(ioc), "PCIProxyDevice-mig");
+
+    f_remote = qemu_fopen_channel_input(ioc);
+
+    pdev->migsize = 0;
+
+    mig_data = g_malloc0(sizeof(proxy_mig_data));
+    mig_data->rem = f_remote;

This feels way too complicated. Since we know f_remote is always just
a simple fd we're getting we don't need to use qio or qemu_file here; just use the fd - nice and simple.

Then the code to read it can just use read(2) with a sensible size chunk rather than reading a byte at a time.

hw/proxy/qemu-proxy.c static void pci_proxy_dev_inst_init(Object *obj) · line 538

Quoted 4 lines
hw/proxy/qemu-proxy.c +4 -0
+    mig_data->dev = pdev;
+
+    qemu_thread_create(&thread, "Proxy MIG_OUT", proxy_mig_out, mig_data,
+                       QEMU_THREAD_DETACHED);

I'm just checking why a thread is necessary; is this because you need to be able to start reading before you block waiting for the remote to tell you the size - worrying that if you don't start reading then the remote might block waiting for us?

Quoted 9 lines
hw/proxy/qemu-proxy.c +9 -0
+    msg.cmd = START_MIG_OUT;
+    msg.bytestream = 0;
+    msg.num_fds = 2;
+    msg.fds[0] = fd[1];
+    msg.fds[1] = GET_REMOTE_WAIT;
+
+    mpqemu_msg_send(&msg, pdev->mpqemu_link->com);
+    size = wait_for_remote(msg.fds[1]);
+    PUT_REMOTE_WAIT(msg.fds[1]);

hw/proxy/qemu-proxy.c static void pci_proxy_dev_inst_init(Object *obj) · line 558

Quoted 10 lines
hw/proxy/qemu-proxy.c +10 -0
+
+    assert(size != ULLONG_MAX);
+
+    /*
+     * migsize is being update by a separate thread. Using volatile to
+     * instruct the compiler to fetch the value of this variable from
+     * memory during every read
+     */
+    while (*((volatile uint64_t *)&pdev->migsize) < size) {
+    }

Hmm. I suggest the following:

a) You create a shared 'size' variable; and initialize it to

    UINT64_MAX.
  b) The thread uses atomic_read(shared_size) to read that value.
  c) When you receive the size from the remote you do
     atomic_set(&shared_size, size);

d) The thread does:
while (received_size < atomic_read(&shared_size))

so the thread will quit either on EOF or it hitting the size.

e) We pthread_join here to wait for the thread
f) We then check a received size to make sure it matches what we
expect.

That removes the tight loop.

Quoted 12 lines
hw/proxy/qemu-proxy.c +12 -0
+    qemu_file_shutdown(f_remote);
+
+    qemu_fclose(f_remote);
+    close(fd[1]);
+
+    return 0;
+}
+
+static int proxy_post_save(void *opaque)
+{
+    MigrationState *ms = migrate_get_current();
+    PCIProxyDev *pdev = opaque;

hw/proxy/qemu-proxy.c static void pci_proxy_dev_inst_init(Object *obj) · line 581

Quoted 10 lines
hw/proxy/qemu-proxy.c +10 -0
+    uint64_t pos = 0;
+
+    while (pos < pdev->migsize) {
+        qemu_put_byte(ms->to_dst_file, mig_data[pos]);
+        pos++;
+    }
+
+    qemu_fflush(ms->to_dst_file);
+
+    return 0;

I don't think you need that.

hw/proxy/qemu-proxy.c static void pci_proxy_dev_inst_init(Object *obj) · line 592

Quoted 11 lines
hw/proxy/qemu-proxy.c +11 -0
+}
+
+const VMStateDescription vmstate_pci_proxy_device = {
+    .name = "PCIProxyDevice",
+    .version_id = 2,
+    .minimum_version_id = 1,
+    .pre_save = proxy_pre_save,
+    .post_save = proxy_post_save,
+    .fields = (VMStateField[]) {
+        VMSTATE_PCI_DEVICE(parent_dev, PCIProxyDev),
+        VMSTATE_UINT64(migsize, PCIProxyDev),

I think instead you should use a VMSTATE_VBUFFER here to save the mig_data.
What we should do is the post_save should g_free the buffer. (mig_data should be a field in proxy).

Dave

Quoted 43 lines
hw/proxy/qemu-proxy.c +5 -0
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 static void pci_proxy_dev_class_init(ObjectClass *klass, void *data)
 {
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
@@ -471,6 +605,7 @@ static void pci_proxy_dev_class_init(ObjectClass *klass, void *data)
     k->config_write = pci_proxy_write_config;
 
     dc->reset = proxy_device_reset;
+    dc->vmsd = &vmstate_pci_proxy_device;
 }
 
 static const TypeInfo pci_proxy_dev_type_info = {
include/hw/proxy/qemu-proxy.h +2 -0
index 5de8129..537c227 100644
@@ -75,6 +75,8 @@ struct PCIProxyDev {
                         bool need_spawn, Error **errp);
 
     ProxyMemoryRegion region[PCI_NUM_REGIONS];
+
+    uint64_t migsize;
 };
 
 typedef struct PCIProxyDevClass {
include/io/mpqemu-link.h +1 -0
index d2234ca..b42c003 100644
@@ -63,6 +63,7 @@ typedef enum {
     PROXY_PING,
     MMIO_RETURN,
     DEVICE_RESET,
+    START_MIG_OUT,
     MAX,
 } mpqemu_cmd_t;
 
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#89 lore raw

Re: [PATCH v5 42/50] multi-process/mig: Send VMSD of remote to the Proxy object

In reply to Jagannathan Raman
Quoted 17 lines · * Jagannathan Raman ([email protected]) wrote:

The remote process sends the VMSD to the Proxy object, on the source side

---
 migration/savevm.c   | 27 +++++++++++++++++++++++++++
 migration/savevm.h   |  2 ++
 remote/remote-main.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 72 insertions(+)
migration/savevm.c +0 -0
index 1d4220e..09af14d 100644

migration/savevm.c bool vmstate_check_only_migratable(const VMStateDescription *vmsd) · line 2945

Quoted 4 lines
migration/savevm.c +1 -0
@@ -2942,3 +2942,30 @@ bool vmstate_check_only_migratable(const VMStateDescription *vmsd)
 
     return !(vmsd && vmsd->unmigratable);
 }
+

Can we add something here commenting, e.g.
/* Called by the remote process to serialise migration back to the qemu
* */

Quoted 13 lines
migration/savevm.c +13 -0
+int qemu_remote_savevm(QEMUFile *f)
+{
+    SaveStateEntry *se;
+    int ret;
+
+    QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
+        if (!se->vmsd || !vmstate_save_needed(se->vmsd, se->opaque)) {
+            continue;
+        }
+
+        save_section_header(f, se, QEMU_VM_SECTION_FULL);
+
+        ret = vmstate_save(f, se, NULL);

migration/savevm.c bool vmstate_check_only_migratable(const VMStateDescription *vmsd) · line 2968

Quoted 10 lines
migration/savevm.c +10 -0
+        if (ret) {
+            qemu_file_set_error(f, ret);
+            return ret;
+        }
+
+        save_section_footer(f, se);
+    }
+
+    qemu_put_byte(f, QEMU_VM_EOF);
+    qemu_fflush(f);

You have a qemu_fflush in process_start_mig_out just after you call it
- so you don't need both; I suggest you remove this one.

migration/savevm.c bool vmstate_check_only_migratable(const VMStateDescription *vmsd) · line 2970

Quoted 1 line
migration/savevm.c +1 -0
+    return 0;

And make this return qemu_file_get_error(f); just like qemu_save_device_state and then makybe some day we can merge them.

Quoted 48 lines
migration/savevm.c +1 -0
+}
migration/savevm.h +2 -0
index ba64a7e..0491d3a 100644
@@ -65,4 +65,6 @@ void qemu_loadvm_state_cleanup(void);
 int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis);
 int qemu_load_device_state(QEMUFile *f);
 
+int qemu_remote_savevm(QEMUFile *f);
+
 #endif
remote/remote-main.c +19 -0
index 58d9905..e97eb76 100644
@@ -53,6 +53,16 @@
 #include "qemu/log.h"
 #include "qemu/cutils.h"
 #include "remote-opts.h"
+#include "qapi/error.h"
+#include "io/channel-util.h"
+
+#include "io/channel.h"
+#include "io/channel-socket.h"
+#include "migration/qemu-file-types.h"
+#include "migration/savevm.h"
+#include "migration/qemu-file-channel.h"
+#include "migration/qemu-file.h"
+
 #include "monitor/monitor.h"
 #include "chardev/char.h"
 #include "sysemu/reset.h"
@@ -322,6 +332,36 @@ static int setup_device(MPQemuMsg *msg, Error **errp)
 
 }
 
+static void process_start_mig_out(MPQemuMsg *msg)
+{
+    int wait = msg->fds[1];
+    Error *err = NULL;
+    QIOChannel *ioc;
+    QEMUFile *f;
+
+    ioc = qio_channel_new_fd(msg->fds[0], &err);
+    if (err) {

remote/remote-main.c static int setup_device(MPQemuMsg *msg, Error **errp) · line 353

Quoted 10 lines
remote/remote-main.c +10 -0
+        error_report_err(err);
+        return;
+    }
+
+    qio_channel_set_name(QIO_CHANNEL(ioc), "remote-migration-channel");
+
+    f = qemu_fopen_channel_output(ioc);
+
+    bdrv_drain_all();
+    (void)bdrv_flush_all();

Do remote process always have block code? I mean can't we have a remote process that's just say a NIC ?

remote/remote-main.c static int setup_device(MPQemuMsg *msg, Error **errp) · line 355

Quoted 1 line
remote/remote-main.c +1 -0
+    (void)qemu_remote_savevm(f);

It's probably bad to ignore errors here; what you could do is if there's an error, you shoul dprint something and then send a poison value back to the QEMU to let it know that you've failed.

Quoted 23 lines
remote/remote-main.c +11 -0
+    qemu_fflush(f);
+
+    notify_proxy(wait, (uint64_t)qemu_ftell(f));
+    PUT_REMOTE_WAIT(wait);
+
+    qemu_fclose(f);
+}
+
 static void process_msg(GIOCondition cond, MPQemuChannel *chan)
 {
     MPQemuMsg *msg = NULL;
@@ -411,6 +451,9 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)
             notify_proxy(msg->fds[0], 0);
         }
         break;
+    case START_MIG_OUT:
+        process_start_mig_out(msg);
+        break;
     default:
         error_setg(&err, "Unknown command");
         goto finalize_loop;
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#92 lore raw

Re: [PATCH v5 43/50] multi-process/mig: Load VMSD in the proxy object

In reply to Jagannathan Raman
Quoted 49 lines · * Jagannathan Raman ([email protected]) wrote:

From: Elena Ufimtseva <[email protected]>

The Proxy object loads the VMSD of remote process in source and send it to the remote process in the destination

---
 hw/proxy/qemu-proxy.c    | 50 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/io/mpqemu-link.h |  1 +
 2 files changed, 51 insertions(+)
hw/proxy/qemu-proxy.c +28 -0
index 19f0dbb..1649f60 100644
@@ -581,12 +581,62 @@ static int proxy_post_save(void *opaque)
     return 0;
 }
 
+static int proxy_post_load(void *opaque, int version_id)
+{
+    MigrationIncomingState *mis = migration_incoming_get_current();
+    PCIProxyDev *pdev = opaque;
+    QEMUFile *f_remote;
+    MPQemuMsg msg = {0};
+    Error *err = NULL;
+    QIOChannel *ioc;
+    uint64_t size;
+    uint8_t byte;
+    int fd[2];
+
+    if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) {
+        return -1;
+    }
+
+    ioc = qio_channel_new_fd(fd[0], &err);
+    if (err) {
+        error_report_err(err);
+        return -1;
+    }
+
+    qio_channel_set_name(QIO_CHANNEL(ioc), "proxy-migration-channel");
+
+    f_remote = qemu_fopen_channel_output(ioc);
+
+    msg.cmd = START_MIG_IN;
+    msg.bytestream = 0;

hw/proxy/qemu-proxy.c static int proxy_post_save(void *opaque) · line 621

Quoted 10 lines
hw/proxy/qemu-proxy.c +10 -0
+    msg.num_fds = 1;
+    msg.fds[0] = fd[1];
+
+    mpqemu_msg_send(&msg, pdev->mpqemu_link->com);
+
+    size = pdev->migsize;
+
+    while (size) {
+        byte = qemu_get_byte(mis->from_src_file);
+        qemu_put_byte(f_remote, byte);

My suggestion on the previous patch about using the VMSTATE_BUFFERV means you'd malloc on size, and do the put_byte's to the remote in the post_load.

Quoted 36 lines
hw/proxy/qemu-proxy.c +12 -0
+        size--;
+    }
+
+    qemu_fflush(f_remote);
+    qemu_fclose(f_remote);
+
+    close(fd[1]);
+
+    return 0;
+}
+
 const VMStateDescription vmstate_pci_proxy_device = {
     .name = "PCIProxyDevice",
     .version_id = 2,
     .minimum_version_id = 1,
     .pre_save = proxy_pre_save,
     .post_save = proxy_post_save,
+    .post_load = proxy_post_load,
     .fields = (VMStateField[]) {
         VMSTATE_PCI_DEVICE(parent_dev, PCIProxyDev),
         VMSTATE_UINT64(migsize, PCIProxyDev),
include/io/mpqemu-link.h +1 -0
index b42c003..01371fc 100644
@@ -64,6 +64,7 @@ typedef enum {
     MMIO_RETURN,
     DEVICE_RESET,
     START_MIG_OUT,
+    START_MIG_IN,
     MAX,
 } mpqemu_cmd_t;
 
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

author
#64 lore raw

Re: [PATCH v5 34/50] multi-process/mon: choose HMP commands based on target

In reply to Dr. David Alan Gilbert
Quoted 28 lines · Dr. David Alan Gilbert
Quoted 27 lines · * Jagannathan Raman ([email protected]) wrote:

From: Elena Ufimtseva <[email protected]>

Add "targets" field to HMP command definition to select the targets which would be supported by each command

---
  hmp-commands-info.hx | 10 ++++++++++
  hmp-commands.hx      | 20 ++++++++++++++++++++
  scripts/hxtool       | 44 ++++++++++++++++++++++++++++++++++++++++++--
  3 files changed, 72 insertions(+), 2 deletions(-)

mode change 100644 => 100755 scripts/hxtool

hmp-commands-info.hx +1 -0
index 257ee7d..631cc76 100644
@@ -19,6 +19,7 @@ ETEXI
          .params     = "",
          .help       = "show the version of QEMU",
          .cmd        = hmp_info_version,
+        .targets    = "scsi",
          .flags      = "p",
      },
 
Quoted 9 lines

hmp-commands-info.hx ETEXI · line 52

Quoted 5 lines
hmp-commands-info.hx +1 -0
@@ -48,6 +49,7 @@ ETEXI
          .params     = "",
          .help       = "show the character devices",
          .cmd        = hmp_info_chardev,
+        .targets    = "scsi",

I'm a bit confused what this means; is this saying that the scsi-remote will respond to 'info chardev' ? Why would it be interested in info chardev?

We found that QMP/HMP monitor is initialized as a chardev in QEMU. So we could use this to get info about the monitors attached to the remote process.

Quoted 256 lines
Quoted 256 lines
hmp-commands-info.hx +8 -0
          .flags      = "p",
      },
 
@@ -64,6 +66,7 @@ ETEXI
          .help       = "show info of one block device or all block devices "
                        "(-n: show named nodes; -v: show details)",
          .cmd        = hmp_info_block,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -78,6 +81,7 @@ ETEXI
          .params     = "",
          .help       = "show block device statistics",
          .cmd        = hmp_info_blockstats,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -92,6 +96,7 @@ ETEXI
          .params     = "",
          .help       = "show progress of ongoing block device operations",
          .cmd        = hmp_info_block_jobs,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -167,6 +172,7 @@ ETEXI
          .params     = "",
          .help       = "show the command line history",
          .cmd        = hmp_info_history,
+        .targets    = "scsi",
          .flags      = "p",
      },
 
@@ -224,6 +230,7 @@ ETEXI
          .params     = "",
          .help       = "show PCI info",
          .cmd        = hmp_info_pci,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -630,6 +637,7 @@ ETEXI
          .params     = "",
          .help       = "show device tree",
          .cmd        = hmp_info_qtree,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -644,6 +652,7 @@ ETEXI
          .params     = "",
          .help       = "show qdev device model list",
          .cmd        = hmp_info_qdm,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -658,6 +667,7 @@ ETEXI
          .params     = "[path]",
          .help       = "show QOM composition tree",
          .cmd        = hmp_info_qom_tree,
+        .targets    = "scsi",
          .flags      = "p",
      },
 
hmp-commands.hx +20 -0
index dc23185..ecc6169 100644
@@ -49,6 +49,7 @@ ETEXI
          .params     = "",
          .help       = "quit the emulator",
          .cmd        = hmp_quit,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -82,6 +83,7 @@ ETEXI
          .params     = "device size",
          .help       = "resize a block image",
          .cmd        = hmp_block_resize,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -99,6 +101,7 @@ ETEXI
          .params     = "device [speed [base]]",
          .help       = "copy data from a backing file into a block device",
          .cmd        = hmp_block_stream,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -113,6 +116,7 @@ ETEXI
          .params     = "device speed",
          .help       = "set maximum speed for a background block operation",
          .cmd        = hmp_block_job_set_speed,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -129,6 +133,7 @@ ETEXI
                        "\n\t\t\t if you want to abort the operation immediately"
                        "\n\t\t\t instead of keep running until data is in sync)",
          .cmd        = hmp_block_job_cancel,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -143,6 +148,7 @@ ETEXI
          .params     = "device",
          .help       = "stop an active background block operation",
          .cmd        = hmp_block_job_complete,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -158,6 +164,7 @@ ETEXI
          .params     = "device",
          .help       = "pause an active background block operation",
          .cmd        = hmp_block_job_pause,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -172,6 +179,7 @@ ETEXI
          .params     = "device",
          .help       = "resume a paused background block operation",
          .cmd        = hmp_block_job_resume,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -186,6 +194,7 @@ ETEXI
          .params     = "[-f] device",
          .help       = "eject a removable medium (use -f to force it)",
          .cmd        = hmp_eject,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -200,6 +209,7 @@ ETEXI
          .params     = "device",
          .help       = "remove host block device",
          .cmd        = hmp_drive_del,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -219,6 +229,7 @@ ETEXI
          .params     = "device filename [format [read-only-mode]]",
          .help       = "change a removable medium, optional format",
          .cmd        = hmp_change,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -732,6 +743,7 @@ ETEXI
          .help       = "add device, like -device on the command line",
          .cmd        = hmp_device_add,
          .command_completion = device_add_completion,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -747,6 +759,7 @@ ETEXI
          .help       = "remove device",
          .cmd        = hmp_device_del,
          .command_completion = device_del_completion,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -1351,6 +1364,7 @@ ETEXI
                        "The -c flag requests QEMU to compress backup data\n\t\t\t"
                        "(if the target format supports it).\n\t\t\t",
          .cmd        = hmp_drive_backup,
+        .targets    = "scsi",
      },
  STEXI
  @item drive_backup
@@ -1368,6 +1382,7 @@ ETEXI
                        "[,readonly=on|off][,copy-on-read=on|off]",
          .help       = "add drive to PCI storage controller",
          .cmd        = hmp_drive_add,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -1816,6 +1831,7 @@ ETEXI
          .help       = "add chardev",
          .cmd        = hmp_chardev_add,
          .command_completion = chardev_add_completion,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -1831,6 +1847,7 @@ ETEXI
          .params     = "id args",
          .help       = "change chardev",
          .cmd        = hmp_chardev_change,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -1848,6 +1865,7 @@ ETEXI
          .help       = "remove chardev",
          .cmd        = hmp_chardev_remove,
          .command_completion = chardev_remove_completion,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -1864,6 +1882,7 @@ ETEXI
          .help       = "send a break on chardev",
          .cmd        = hmp_chardev_send_break,
          .command_completion = chardev_remove_completion,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -1940,6 +1959,7 @@ ETEXI
          .params     = "[subcommand]",
          .help       = "show various information about the system state",
          .cmd        = hmp_info_help,
+        .targets    = "scsi",
          .sub_table  = hmp_info_cmds,
          .flags      = "p",
      },
scripts/hxtool +8 -1
old mode 100644
new mode 100755
index 0003e7b..802cbd4
@@ -10,7 +10,14 @@ hxtoh()
              STEXI*|ETEXI*|SRST*|ERST*) flag=$(($flag^1))
              ;;
              *)
-            test $flag -eq 1 && printf "%s\n" "$str"
+            # Skip line that has ".targets" as it is for multi-process targets based hmp
+            # commands generation.
+            echo $str | grep -q '.targets'
+            if [ $? -eq 0 ]; then
+                continue
+            else
+                test $flag -eq 1 && printf "%s\n" "$str"
+            fi
              ;;
          esac
      done
@@ -84,16 +91,49 @@ hxtotexi()
              print_texi_heading "$(expr "$str" : "ARCHHEADING(\(.*\),.*)")"
Quoted 8 lines

scripts/hxtool hxtotexi() · line 96

Quoted 6 lines
scripts/hxtool +3 -1
              ;;
              *)
-            test $flag -eq 1 && printf '%s\n' "$str"
+            # Skip line that has ".targets" as it is for multi-process targets based hmp
+            # commands generation.
+            echo $str | grep -q '.targetss'

One extra 's' ?

Thanks, we'll fix it.

--
Jag

Quoted 50 lines
Quoted 47 lines
scripts/hxtool +31 -0
+            if [ $? -eq 0 ]; then
+                continue
+            else
+                test $flag -eq 1 && printf '%s\n' "$str"
+            fi
              ;;
          esac
          line=$((line+1))
      done
  }
 
+hxtoh_tgt()
+{
+    section=""
+    flag=1
+    use_section=0
+    while read -r str; do
+        # Print section if it has ".targets" and the second argument passed to the
+        # script, such as "scsi".
+        echo "$str" | grep -q -E ".targets.*$1"
+        if [ $? -eq 0 ]; then
+            use_section=1
+            continue
+        fi
+        case $str in
+            HXCOMM*)
+            ;;
+            STEXI*|ETEXI*) flag=$(($flag^1)); test $use_section -eq 1 && printf '%s' "$section"; section=""; use_section=0
+            ;;
+            *)
+            test $flag -eq 1 && section="${section} ${str} ${IFS}"
+            ;;
+        esac
+    done
+}
+
  case "$1" in
  "-h") hxtoh ;;
  "-t") hxtotexi ;;
+"-tgt") hxtoh_tgt $2 ;;
  *) exit 1 ;;
  esac
 
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

author
#69 lore raw

Re: [PATCH v5 36/50] multi-process/mon: enable QMP module support in the remote process

In reply to Dr. David Alan Gilbert
Quoted 9 lines · Dr. David Alan Gilbert
Quoted 5 lines · * Jagannathan Raman ([email protected]) wrote:

Build system changes to enable QMP module in the remote process

It's odd that this is labelled as QMP changes yet a lot of the code is actually HMP de-staticing.

This patch builds the QMP related code into the remote process. In order to facilitate the build, we need to de-staticize a bunch of HMP functions.

May be we could update the patch title to reflect the destaticing as well.

Thanks!
--
Jag

Quoted 608 lines

Dave

Quoted 602 lines
---
  Makefile.objs              |  9 +++++
  Makefile.target            | 35 +++++++++++++++++--
  hmp-commands.hx            |  5 +--
  hw/core/Makefile.objs      |  1 +
  monitor/Makefile.objs      |  4 +++
  monitor/misc.c             | 84 +++++++++++++++++++++++++---------------------
  monitor/monitor-internal.h | 38 +++++++++++++++++++++
  qapi/Makefile.objs         |  2 ++
  qom/Makefile.objs          |  1 +
  ui/Makefile.objs           |  2 ++
  10 files changed, 139 insertions(+), 42 deletions(-)
Makefile.objs +9 -0
index 689a722..4b5db09 100644
@@ -32,6 +32,7 @@ remote-pci-obj-$(CONFIG_MPQEMU) += migration/
  remote-pci-obj-$(CONFIG_MPQEMU) += remote/
  remote-pci-obj-$(CONFIG_MPQEMU) += accel/
  remote-pci-obj-$(CONFIG_MPQEMU) += util/
+remote-pci-obj-$(CONFIG_MPQEMU) += monitor/
 
  remote-pci-obj-$(CONFIG_MPQEMU) += cpus-common.o
  remote-pci-obj-$(CONFIG_MPQEMU) += dma-helpers.o
@@ -44,6 +45,9 @@ remote-pci-obj-$(CONFIG_MPQEMU) += iothread.o
  # remote-lsi-obj-y is code used to implement remote LSI device
 
  remote-lsi-obj-$(CONFIG_MPQEMU) += hw/
+remote-lsi-obj-$(CONFIG_MPQEMU) += ui/
+
+remote-lsi-obj-$(CONFIG_MPQEMU) += device-hotplug.o
 
  #######################################################################
  # crypto-obj-y is code used by both qemu system emulation and qemu-img
@@ -105,6 +109,11 @@ common-obj-y += qapi/
 
  endif # CONFIG_SOFTMMU
 
+remote-pci-obj-$(CONFIG_MPQEMU) += qapi/
+remote-pci-obj-$(CONFIG_MPQEMU) += blockdev-nbd.o
+remote-pci-obj-$(CONFIG_MPQEMU) += job-qmp.o
+remote-pci-obj-$(CONFIG_MPQEMU) += balloon.o
+
  #######################################################################
  # Target-independent parts used in system and user emulation
  common-obj-y += cpus-common.o
Makefile.target +33 -2
index 035c23b..4ead5c3 100644
@@ -142,13 +142,32 @@ remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/hax-stub.o
  remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/whpx-stub.o
  remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/vl-stub.o
  remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/net-stub.o
-remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/monitor.o
  remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/replay.o
  remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/xen-mapcache.o
  remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/audio.o
  remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/monitor.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/migration.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/ui-stub.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/gdbstub.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/qapi-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/qapi-misc.o
 
  remote-pci-tgt-obj-$(CONFIG_MPQEMU) += remote/memory.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += arch_init.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += monitor/misc.o
+
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-introspect.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-block-core.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-block.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-misc.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-machine-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-misc-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-visit-machine-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-visit-misc-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-types-machine-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-types-misc-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-init-commands.o
  endif
 
  #########################################################
@@ -203,6 +222,10 @@ endif
  generated-files-y += hmp-commands.h hmp-commands-info.h
  generated-files-y += config-devices.h
 
+ifdef CONFIG_MPQEMU
+generated-files-y += hmp-scsi-commands.h hmp-scsi-commands-info.h
+endif
+
  endif # CONFIG_SOFTMMU
 
  dummy := $(call unnest-vars,,obj-y)
@@ -288,10 +311,18 @@ hmp-commands.h: $(SRC_PATH)/hmp-commands.hx $(SRC_PATH)/scripts/hxtool
  hmp-commands-info.h: $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/scripts/hxtool
  	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"GEN","$(TARGET_DIR)$@")
 
+ifdef CONFIG_MPQEMU
+hmp-scsi-commands.h: $(SRC_PATH)/hmp-commands.hx $(SRC_PATH)/scripts/hxtool
+	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -tgt scsi < $< > $@)
+
+hmp-scsi-commands-info.h: $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/scripts/hxtool
+	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -tgt scsi < $< > $@)
+endif
+
  clean: clean-target
  	rm -f *.a *~ $(PROGS)
  	rm -f $(shell find . -name '*.[od]')
-	rm -f hmp-commands.h gdbstub-xml.c
+	rm -f hmp-commands.h gdbstub-xml.c hmp-scsi-commands.h hmp-scsi-commands-info.h
  	rm -f trace/generated-helpers.c trace/generated-helpers.c-timestamp
  ifdef CONFIG_TRACE_SYSTEMTAP
  	rm -f *.stp
hmp-commands.hx +3 -2
index ecc6169..a1932c4 100644
@@ -14,7 +14,8 @@ ETEXI
          .args_type  = "name:S?",
          .params     = "[cmd]",
          .help       = "show the help",
-        .cmd        = do_help_cmd,
+        .cmd        = hmp_do_help_cmd,
+        .targets    = "scsi",
          .flags      = "p",
      },
 
@@ -618,7 +619,7 @@ ETEXI
          .args_type  = "fmt:/,val:l",
          .params     = "/fmt expr",
          .help       = "print expression value (use $reg for CPU register access)",
-        .cmd        = do_print,
+        .cmd        = hmp_do_print,
      },
 
  STEXI
hw/core/Makefile.objs +1 -0
index e3e8084..251b77b 100644
@@ -49,3 +49,4 @@ remote-pci-obj-$(CONFIG_MPQEMU) += numa.o
  remote-pci-obj-$(CONFIG_MPQEMU) += cpu.o
  remote-pci-obj-$(CONFIG_MPQEMU) += vmstate-if.o
  remote-pci-obj-$(CONFIG_MPQEMU) += resettable.o
+remote-pci-obj-$(CONFIG_MPQEMU) += machine-qmp-cmds.o
monitor/Makefile.objs +4 -0
index 9244d90..48d8017 100644
@@ -2,3 +2,7 @@ obj-y += misc.o
  common-obj-y += monitor.o qmp.o hmp.o
  common-obj-y += qmp-cmds.o qmp-cmds-control.o
  common-obj-y += hmp-cmds.o
+
+remote-pci-obj-$(CONFIG_MPQEMU) += monitor.o qmp.o hmp.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qmp-cmds.o qmp-cmds-control.o
+remote-pci-obj-$(CONFIG_MPQEMU) += hmp-cmds.o
monitor/misc.c +46 -38
index 6c41293..f1f09bf 100644
@@ -177,12 +177,12 @@ int hmp_compare_cmd(const char *name, const char *list)
      return 0;
  }
 
-static void do_help_cmd(Monitor *mon, const QDict *qdict)
+void hmp_do_help_cmd(Monitor *mon, const QDict *qdict)
  {
      help_cmd(mon, qdict_get_try_str(qdict, "name"));
  }
 
-static void hmp_trace_event(Monitor *mon, const QDict *qdict)
+void hmp_trace_event(Monitor *mon, const QDict *qdict)
  {
      const char *tp_name = qdict_get_str(qdict, "name");
      bool new_state = qdict_get_bool(qdict, "option");
@@ -226,7 +226,7 @@ static void hmp_trace_file(Monitor *mon, const QDict *qdict)
  }
  #endif
 
-static void hmp_info_help(Monitor *mon, const QDict *qdict)
+void hmp_info_help(Monitor *mon, const QDict *qdict)
  {
      help_cmd(mon, "info");
  }
@@ -314,7 +314,7 @@ int monitor_get_cpu_index(void)
      return cs ? cs->cpu_index : UNASSIGNED_CPU_INDEX;
  }
 
-static void hmp_info_registers(Monitor *mon, const QDict *qdict)
+void hmp_info_registers(Monitor *mon, const QDict *qdict)
  {
      bool all_cpus = qdict_get_try_bool(qdict, "cpustate_all", false);
      CPUState *cs;
@@ -337,7 +337,7 @@ static void hmp_info_registers(Monitor *mon, const QDict *qdict)
  }
 
  #ifdef CONFIG_TCG
-static void hmp_info_jit(Monitor *mon, const QDict *qdict)
+void hmp_info_jit(Monitor *mon, const QDict *qdict)
  {
      if (!tcg_enabled()) {
          error_report("JIT information is only available with accel=tcg");
@@ -348,13 +348,13 @@ static void hmp_info_jit(Monitor *mon, const QDict *qdict)
      dump_drift_info();
  }
 
-static void hmp_info_opcount(Monitor *mon, const QDict *qdict)
+void hmp_info_opcount(Monitor *mon, const QDict *qdict)
  {
      dump_opcount_info();
  }
  #endif
 
-static void hmp_info_sync_profile(Monitor *mon, const QDict *qdict)
+void hmp_info_sync_profile(Monitor *mon, const QDict *qdict)
  {
      int64_t max = qdict_get_try_int(qdict, "max", 10);
      bool mean = qdict_get_try_bool(qdict, "mean", false);
@@ -365,7 +365,7 @@ static void hmp_info_sync_profile(Monitor *mon, const QDict *qdict)
      qsp_report(max, sort_by, coalesce);
  }
 
-static void hmp_info_history(Monitor *mon, const QDict *qdict)
+void hmp_info_history(Monitor *mon, const QDict *qdict)
  {
      MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
      int i;
@@ -385,7 +385,7 @@ static void hmp_info_history(Monitor *mon, const QDict *qdict)
      }
  }
 
-static void hmp_info_cpustats(Monitor *mon, const QDict *qdict)
+void hmp_info_cpustats(Monitor *mon, const QDict *qdict)
  {
      CPUState *cs = mon_get_cpu();
 
@@ -396,7 +396,7 @@ static void hmp_info_cpustats(Monitor *mon, const QDict *qdict)
      cpu_dump_statistics(cs, 0);
  }
 
-static void hmp_info_trace_events(Monitor *mon, const QDict *qdict)
+void hmp_info_trace_events(Monitor *mon, const QDict *qdict)
  {
      const char *name = qdict_get_try_str(qdict, "name");
      bool has_vcpu = qdict_haskey(qdict, "vcpu");
@@ -456,7 +456,7 @@ void qmp_client_migrate_info(const char *protocol, const char *hostname,
      error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "protocol", "spice");
  }
 
-static void hmp_logfile(Monitor *mon, const QDict *qdict)
+void hmp_logfile(Monitor *mon, const QDict *qdict)
  {
      Error *err = NULL;
 
@@ -466,7 +466,7 @@ static void hmp_logfile(Monitor *mon, const QDict *qdict)
      }
  }
 
-static void hmp_log(Monitor *mon, const QDict *qdict)
+void hmp_log(Monitor *mon, const QDict *qdict)
  {
      int mask;
      const char *items = qdict_get_str(qdict, "items");
@@ -483,7 +483,7 @@ static void hmp_log(Monitor *mon, const QDict *qdict)
      qemu_set_log(mask);
  }
 
-static void hmp_singlestep(Monitor *mon, const QDict *qdict)
+void hmp_singlestep(Monitor *mon, const QDict *qdict)
  {
      const char *option = qdict_get_try_str(qdict, "option");
      if (!option || !strcmp(option, "on")) {
@@ -495,7 +495,7 @@ static void hmp_singlestep(Monitor *mon, const QDict *qdict)
      }
  }
 
-static void hmp_gdbserver(Monitor *mon, const QDict *qdict)
+void hmp_gdbserver(Monitor *mon, const QDict *qdict)
  {
      const char *device = qdict_get_try_str(qdict, "device");
      if (!device)
@@ -511,7 +511,7 @@ static void hmp_gdbserver(Monitor *mon, const QDict *qdict)
      }
  }
 
-static void hmp_watchdog_action(Monitor *mon, const QDict *qdict)
+void hmp_watchdog_action(Monitor *mon, const QDict *qdict)
  {
      const char *action = qdict_get_str(qdict, "action");
      if (select_watchdog_action(action) == -1) {
@@ -653,7 +653,7 @@ static void memory_dump(Monitor *mon, int count, int format, int wsize,
      }
  }
 
-static void hmp_memory_dump(Monitor *mon, const QDict *qdict)
+void hmp_memory_dump(Monitor *mon, const QDict *qdict)
  {
      int count = qdict_get_int(qdict, "count");
      int format = qdict_get_int(qdict, "format");
@@ -663,7 +663,7 @@ static void hmp_memory_dump(Monitor *mon, const QDict *qdict)
      memory_dump(mon, count, format, size, addr, 0);
  }
 
-static void hmp_physical_memory_dump(Monitor *mon, const QDict *qdict)
+void hmp_physical_memory_dump(Monitor *mon, const QDict *qdict)
  {
      int count = qdict_get_int(qdict, "count");
      int format = qdict_get_int(qdict, "format");
@@ -693,7 +693,7 @@ static void *gpa2hva(MemoryRegion **p_mr, hwaddr addr, Error **errp)
      return qemu_map_ram_ptr(mrs.mr->ram_block, mrs.offset_within_region);
  }
 
-static void hmp_gpa2hva(Monitor *mon, const QDict *qdict)
+void hmp_gpa2hva(Monitor *mon, const QDict *qdict)
  {
      hwaddr addr = qdict_get_int(qdict, "addr");
      Error *local_err = NULL;
@@ -713,7 +713,7 @@ static void hmp_gpa2hva(Monitor *mon, const QDict *qdict)
      memory_region_unref(mr);
  }
 
-static void hmp_gva2gpa(Monitor *mon, const QDict *qdict)
+void hmp_gva2gpa(Monitor *mon, const QDict *qdict)
  {
      target_ulong addr = qdict_get_int(qdict, "addr");
      MemTxAttrs attrs;
@@ -768,7 +768,7 @@ out:
      return ret;
  }
 
-static void hmp_gpa2hpa(Monitor *mon, const QDict *qdict)
+void hmp_gpa2hpa(Monitor *mon, const QDict *qdict)
  {
      hwaddr addr = qdict_get_int(qdict, "addr");
      Error *local_err = NULL;
@@ -795,7 +795,7 @@ static void hmp_gpa2hpa(Monitor *mon, const QDict *qdict)
  }
  #endif
 
-static void do_print(Monitor *mon, const QDict *qdict)
+void hmp_do_print(Monitor *mon, const QDict *qdict)
  {
      int format = qdict_get_int(qdict, "format");
      hwaddr val = qdict_get_int(qdict, "val");
@@ -821,7 +821,7 @@ static void do_print(Monitor *mon, const QDict *qdict)
      monitor_printf(mon, "\n");
  }
 
-static void hmp_sum(Monitor *mon, const QDict *qdict)
+void hmp_sum(Monitor *mon, const QDict *qdict)
  {
      uint32_t addr;
      uint16_t sum;
@@ -841,7 +841,7 @@ static void hmp_sum(Monitor *mon, const QDict *qdict)
 
  static int mouse_button_state;
 
-static void hmp_mouse_move(Monitor *mon, const QDict *qdict)
+void hmp_mouse_move(Monitor *mon, const QDict *qdict)
  {
      int dx, dy, dz, button;
      const char *dx_str = qdict_get_str(qdict, "dx_str");
@@ -865,7 +865,7 @@ static void hmp_mouse_move(Monitor *mon, const QDict *qdict)
      qemu_input_event_sync();
  }
 
-static void hmp_mouse_button(Monitor *mon, const QDict *qdict)
+void hmp_mouse_button(Monitor *mon, const QDict *qdict)
  {
      static uint32_t bmap[INPUT_BUTTON__MAX] = {
          [INPUT_BUTTON_LEFT]       = MOUSE_EVENT_LBUTTON,
@@ -882,7 +882,7 @@ static void hmp_mouse_button(Monitor *mon, const QDict *qdict)
      mouse_button_state = button_state;
  }
 
-static void hmp_ioport_read(Monitor *mon, const QDict *qdict)
+void hmp_ioport_read(Monitor *mon, const QDict *qdict)
  {
      int size = qdict_get_int(qdict, "size");
      int addr = qdict_get_int(qdict, "addr");
@@ -916,7 +916,7 @@ static void hmp_ioport_read(Monitor *mon, const QDict *qdict)
                     suffix, addr, size * 2, val);
  }
 
-static void hmp_ioport_write(Monitor *mon, const QDict *qdict)
+void hmp_ioport_write(Monitor *mon, const QDict *qdict)
  {
      int size = qdict_get_int(qdict, "size");
      int addr = qdict_get_int(qdict, "addr");
@@ -938,7 +938,7 @@ static void hmp_ioport_write(Monitor *mon, const QDict *qdict)
      }
  }
 
-static void hmp_boot_set(Monitor *mon, const QDict *qdict)
+void hmp_boot_set(Monitor *mon, const QDict *qdict)
  {
      Error *local_err = NULL;
      const char *bootdevice = qdict_get_str(qdict, "bootdevice");
@@ -951,7 +951,7 @@ static void hmp_boot_set(Monitor *mon, const QDict *qdict)
      }
  }
 
-static void hmp_info_mtree(Monitor *mon, const QDict *qdict)
+void hmp_info_mtree(Monitor *mon, const QDict *qdict)
  {
      bool flatview = qdict_get_try_bool(qdict, "flatview", false);
      bool dispatch_tree = qdict_get_try_bool(qdict, "dispatch_tree", false);
@@ -964,7 +964,7 @@ static void hmp_info_mtree(Monitor *mon, const QDict *qdict)
 
  int64_t dev_time;
 
-static void hmp_info_profile(Monitor *mon, const QDict *qdict)
+void hmp_info_profile(Monitor *mon, const QDict *qdict)
  {
      static int64_t last_cpu_exec_time;
      int64_t cpu_exec_time;
@@ -981,7 +981,7 @@ static void hmp_info_profile(Monitor *mon, const QDict *qdict)
      dev_time = 0;
  }
  #else
-static void hmp_info_profile(Monitor *mon, const QDict *qdict)
+void hmp_info_profile(Monitor *mon, const QDict *qdict)
  {
      monitor_printf(mon, "Internal profiler not compiled\n");
  }
@@ -990,7 +990,7 @@ static void hmp_info_profile(Monitor *mon, const QDict *qdict)
  /* Capture support */
  static QLIST_HEAD (capture_list_head, CaptureState) capture_head;
 
-static void hmp_info_capture(Monitor *mon, const QDict *qdict)
+void hmp_info_capture(Monitor *mon, const QDict *qdict)
  {
      int i;
      CaptureState *s;
@@ -1001,7 +1001,7 @@ static void hmp_info_capture(Monitor *mon, const QDict *qdict)
      }
  }
 
-static void hmp_stopcapture(Monitor *mon, const QDict *qdict)
+void hmp_stopcapture(Monitor *mon, const QDict *qdict)
  {
      int i;
      int n = qdict_get_int(qdict, "n");
@@ -1017,7 +1017,7 @@ static void hmp_stopcapture(Monitor *mon, const QDict *qdict)
      }
  }
 
-static void hmp_wavcapture(Monitor *mon, const QDict *qdict)
+void hmp_wavcapture(Monitor *mon, const QDict *qdict)
  {
      const char *path = qdict_get_str(qdict, "path");
      int freq = qdict_get_try_int(qdict, "freq", 44100);
@@ -1070,7 +1070,7 @@ static void hmp_warn_acl(void)
      warn_acl = true;
  }
 
-static void hmp_acl_show(Monitor *mon, const QDict *qdict)
+void hmp_acl_show(Monitor *mon, const QDict *qdict)
  {
      const char *aclname = qdict_get_str(qdict, "aclname");
      QAuthZList *auth = find_auth(mon, aclname);
@@ -1097,7 +1097,7 @@ static void hmp_acl_show(Monitor *mon, const QDict *qdict)
      }
  }
 
-static void hmp_acl_reset(Monitor *mon, const QDict *qdict)
+void hmp_acl_reset(Monitor *mon, const QDict *qdict)
  {
      const char *aclname = qdict_get_str(qdict, "aclname");
      QAuthZList *auth = find_auth(mon, aclname);
@@ -1114,7 +1114,7 @@ static void hmp_acl_reset(Monitor *mon, const QDict *qdict)
      monitor_printf(mon, "acl: removed all rules\n");
  }
 
-static void hmp_acl_policy(Monitor *mon, const QDict *qdict)
+void hmp_acl_policy(Monitor *mon, const QDict *qdict)
  {
      const char *aclname = qdict_get_str(qdict, "aclname");
      const char *policy = qdict_get_str(qdict, "policy");
@@ -1155,7 +1155,7 @@ static QAuthZListFormat hmp_acl_get_format(const char *match)
      }
  }
 
-static void hmp_acl_add(Monitor *mon, const QDict *qdict)
+void hmp_acl_add(Monitor *mon, const QDict *qdict)
  {
      const char *aclname = qdict_get_str(qdict, "aclname");
      const char *match = qdict_get_str(qdict, "match");
@@ -1208,7 +1208,7 @@ static void hmp_acl_add(Monitor *mon, const QDict *qdict)
      }
  }
 
-static void hmp_acl_remove(Monitor *mon, const QDict *qdict)
+void hmp_acl_remove(Monitor *mon, const QDict *qdict)
  {
      const char *aclname = qdict_get_str(qdict, "aclname");
      const char *match = qdict_get_str(qdict, "match");
@@ -1678,13 +1678,21 @@ int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp)
 
  /* Please update hmp-commands.hx when adding or changing commands */
  static HMPCommand hmp_info_cmds[] = {
+#if defined(SCSI_PROCESS)
+#include "hmp-scsi-commands-info.h"
+#else
  #include "hmp-commands-info.h"
+#endif
      { NULL, NULL, },
  };
 
  /* hmp_cmds and hmp_info_cmds would be sorted at runtime */
  HMPCommand hmp_cmds[] = {
+#if defined(SCSI_PROCESS)
+#include "hmp-scsi-commands.h"
+#else
  #include "hmp-commands.h"
+#endif
      { NULL, NULL, },
  };
 
monitor/monitor-internal.h +38 -0
index 3e6baba..26349cb 100644
@@ -183,4 +183,42 @@ int hmp_compare_cmd(const char *name, const char *list);
  void qmp_query_qmp_schema(QDict *qdict, QObject **ret_data,
                                   Error **errp);
 
+void hmp_do_help_cmd(Monitor *mon, const QDict *qdict);
+void hmp_trace_event(Monitor *mon, const QDict *qdict);
+void hmp_info_help(Monitor *mon, const QDict *qdict);
+void hmp_info_registers(Monitor *mon, const QDict *qdict);
+void hmp_info_jit(Monitor *mon, const QDict *qdict);
+void hmp_info_opcount(Monitor *mon, const QDict *qdict);
+void hmp_info_sync_profile(Monitor *mon, const QDict *qdict);
+void hmp_info_history(Monitor *mon, const QDict *qdict);
+void hmp_info_cpustats(Monitor *mon, const QDict *qdict);
+void hmp_info_trace_events(Monitor *mon, const QDict *qdict);
+void hmp_logfile(Monitor *mon, const QDict *qdict);
+void hmp_log(Monitor *mon, const QDict *qdict);
+void hmp_singlestep(Monitor *mon, const QDict *qdict);
+void hmp_gdbserver(Monitor *mon, const QDict *qdict);
+void hmp_watchdog_action(Monitor *mon, const QDict *qdict);
+void hmp_memory_dump(Monitor *mon, const QDict *qdict);
+void hmp_physical_memory_dump(Monitor *mon, const QDict *qdict);
+void hmp_gpa2hva(Monitor *mon, const QDict *qdict);
+void hmp_gva2gpa(Monitor *mon, const QDict *qdict);
+void hmp_gpa2hpa(Monitor *mon, const QDict *qdict);
+void hmp_do_print(Monitor *mon, const QDict *qdict);
+void hmp_sum(Monitor *mon, const QDict *qdict);
+void hmp_mouse_move(Monitor *mon, const QDict *qdict);
+void hmp_mouse_button(Monitor *mon, const QDict *qdict);
+void hmp_ioport_read(Monitor *mon, const QDict *qdict);
+void hmp_ioport_write(Monitor *mon, const QDict *qdict);
+void hmp_boot_set(Monitor *mon, const QDict *qdict);
+void hmp_info_mtree(Monitor *mon, const QDict *qdict);
+void hmp_info_profile(Monitor *mon, const QDict *qdict);
+void hmp_info_capture(Monitor *mon, const QDict *qdict);
+void hmp_stopcapture(Monitor *mon, const QDict *qdict);
+void hmp_wavcapture(Monitor *mon, const QDict *qdict);
+void hmp_acl_show(Monitor *mon, const QDict *qdict);
+void hmp_acl_reset(Monitor *mon, const QDict *qdict);
+void hmp_acl_policy(Monitor *mon, const QDict *qdict);
+void hmp_acl_add(Monitor *mon, const QDict *qdict);
+void hmp_acl_remove(Monitor *mon, const QDict *qdict);
+
  #endif
qapi/Makefile.objs +2 -0
index 20fcc37..a8a3925 100644
@@ -31,3 +31,5 @@ obj-y += qapi-events.o
  obj-y += $(QAPI_TARGET_MODULES:%=qapi-commands-%.o)
  obj-y += qapi-commands.o
  obj-y += qapi-init-commands.o
+
+remote-pci-obj-$(CONFIG_MPQEMU) += $(QAPI_COMMON_MODULES:%=qapi-commands-%.o)
qom/Makefile.objs +1 -0
index 07e50e5..16603d7 100644
@@ -5,3 +5,4 @@ common-obj-$(CONFIG_SOFTMMU) += qom-hmp-cmds.o qom-qmp-cmds.o
 
  remote-pci-obj-$(CONFIG_MPQEMU) += object.o qom-qobject.o container.o
  remote-pci-obj-$(CONFIG_MPQEMU) += object_interfaces.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qom-qmp-cmds.o qom-hmp-cmds.o
ui/Makefile.objs +2 -0
index e6da6ff..c3ac572 100644
@@ -68,3 +68,5 @@ console-gl.o-libs += $(OPENGL_LIBS)
  egl-helpers.o-libs += $(OPENGL_LIBS)
  egl-context.o-libs += $(OPENGL_LIBS)
  egl-headless.o-libs += $(OPENGL_LIBS)
+
+remote-lsi-obj-$(CONFIG_MPQEMU) += vnc-stubs.o
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

author
#73 lore raw

Re: [PATCH v5 37/50] multi-process/mon: Refactor monitor/chardev functions out of vl.c

In reply to Dr. David Alan Gilbert
Quoted 10 lines · Dr. David Alan Gilbert
Quoted 8 lines · * Jagannathan Raman ([email protected]) wrote:

Some of the initialization helper functions w.r.t monitor & chardev in vl.c are also used by the remote process. Therefore, these functions are refactored into shared files that both QEMU & remote process could use.

Quoted 6 lines

This looks like another good candidate to go in a separate post that doesn't need to wait for the rest of multi-process; you are probably best splitting it into separate chardev and monitor chunks so they can go via their respective maintainers.

Sure, thanks!

--
Jag

Quoted 213 lines

Dave

Quoted 206 lines
---
  chardev/char.c            | 14 ++++++++++++++
  include/chardev/char.h    |  1 +
  include/monitor/monitor.h |  2 ++
  monitor/monitor.c         | 40 ++++++++++++++++++++++++++++++++++++++-
  remote/remote-main.c      |  1 +
  remote/remote-opts.c      |  1 +
  softmmu/vl.c              | 48 -----------------------------------------------
  7 files changed, 58 insertions(+), 49 deletions(-)
chardev/char.c +14 -0
index 8723756..1d03ea0 100644
@@ -1189,4 +1189,18 @@ static void register_types(void)
      qemu_add_machine_init_done_notifier(&chardev_machine_done_notify);
  }
 
+int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp)
+{
+    Error *local_err = NULL;
+
+    if (!qemu_chr_new_from_opts(opts, NULL, &local_err)) {
+        if (local_err) {
+            error_propagate(errp, local_err);
+            return -1;
+        }
+        exit(0);
+    }
+    return 0;
+}
+
  type_init(register_types);
include/chardev/char.h +1 -0
index 00589a6..e370320 100644
@@ -290,4 +290,5 @@ GSource *qemu_chr_timeout_add_ms(Chardev *chr, guint ms,
  /* console.c */
  void qemu_chr_parse_vc(QemuOpts *opts, ChardevBackend *backend, Error **errp);
 
+int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp);
  #endif
include/monitor/monitor.h +2 -0
index b7bdd2b..d92bf1c 100644
@@ -45,5 +45,7 @@ int monitor_fdset_get_fd(int64_t fdset_id, int flags);
  int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd);
  void monitor_fdset_dup_fd_remove(int dup_fd);
  int64_t monitor_fdset_dup_fd_find(int dup_fd);
+void monitor_parse(const char *optarg, const char *mode, bool pretty);
+int mon_init_func(void *opaque, QemuOpts *opts, Error **errp);
 
  #endif /* MONITOR_H */
monitor/monitor.c +39 -1
index c1a6c44..5759b84 100644
@@ -33,7 +33,10 @@
  #include "sysemu/qtest.h"
  #include "sysemu/sysemu.h"
  #include "trace.h"
-
+#include "qemu/cutils.h"
+#include "qemu/option.h"
+#include "qemu-options.h"
+#include "qemu/config-file.h"
  /*
   * To prevent flooding clients, events can be throttled. The
   * throttling is calculated globally, rather than per-Monitor
@@ -609,6 +612,41 @@ void monitor_init_globals_core(void)
                                     NULL);
  }
 
+int mon_init_func(void *opaque, QemuOpts *opts, Error **errp)
+{
+    return monitor_init_opts(opts, errp);
+}
+
+void monitor_parse(const char *optarg, const char *mode, bool pretty)
+{
+    static int monitor_device_index;
+    QemuOpts *opts;
+    const char *p;
+    char label[32];
+
+    if (strstart(optarg, "chardev:", &p)) {
+        snprintf(label, sizeof(label), "%s", p);
+    } else {
+        snprintf(label, sizeof(label), "compat_monitor%d",
+                 monitor_device_index);
+        opts = qemu_chr_parse_compat(label, optarg, true);
+        if (!opts) {
+            error_report("parse error: %s", optarg);
+            exit(1);
+        }
+    }
+
+    opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal);
+    qemu_opt_set(opts, "mode", mode, &error_abort);
+    qemu_opt_set(opts, "chardev", label, &error_abort);
+    if (!strcmp(mode, "control")) {
+        qemu_opt_set_bool(opts, "pretty", pretty, &error_abort);
+    } else {
+        assert(pretty == false);
+    }
+    monitor_device_index++;
+}
+
  int monitor_init_opts(QemuOpts *opts, Error **errp)
  {
      Chardev *chr;
remote/remote-main.c +1 -0
index 5284ee9..23fc0df 100644
@@ -54,6 +54,7 @@
  #include "qemu/cutils.h"
  #include "remote-opts.h"
  #include "monitor/monitor.h"
+#include "chardev/char.h"
  #include "sysemu/reset.h"
 
  static MPQemuLinkState *mpqemu_link;
remote/remote-opts.c +1 -0
index 7e12700..565e641 100644
@@ -39,6 +39,7 @@
  #include "block/block.h"
  #include "remote/remote-opts.h"
  #include "include/qemu-common.h"
+#include "monitor/monitor.h"
 
  #include "vl.h"
  /*
softmmu/vl.c +0 -48
index a8a6f35..4a4f52c 100644
@@ -2133,19 +2133,6 @@ static int device_help_func(void *opaque, QemuOpts *opts, Error **errp)
      return qdev_device_help(opts);
  }
 
-static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp)
-{
-    Error *local_err = NULL;
-
-    if (!qemu_chr_new_from_opts(opts, NULL, &local_err)) {
-        if (local_err) {
-            error_propagate(errp, local_err);
-            return -1;
-        }
-        exit(0);
-    }
-    return 0;
-}
 
  #ifdef CONFIG_VIRTFS
  static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp)
@@ -2154,41 +2141,6 @@ static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp)
  }
  #endif
 
-static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp)
-{
-    return monitor_init_opts(opts, errp);
-}
-
-static void monitor_parse(const char *optarg, const char *mode, bool pretty)
-{
-    static int monitor_device_index = 0;
-    QemuOpts *opts;
-    const char *p;
-    char label[32];
-
-    if (strstart(optarg, "chardev:", &p)) {
-        snprintf(label, sizeof(label), "%s", p);
-    } else {
-        snprintf(label, sizeof(label), "compat_monitor%d",
-                 monitor_device_index);
-        opts = qemu_chr_parse_compat(label, optarg, true);
-        if (!opts) {
-            error_report("parse error: %s", optarg);
-            exit(1);
-        }
-    }
-
-    opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal);
-    qemu_opt_set(opts, "mode", mode, &error_abort);
-    qemu_opt_set(opts, "chardev", label, &error_abort);
-    if (!strcmp(mode, "control")) {
-        qemu_opt_set_bool(opts, "pretty", pretty, &error_abort);
-    } else {
-        assert(pretty == false);
-    }
-    monitor_device_index++;
-}
-
  struct device_config {
      enum {
          DEV_USB,       /* -usbdevice     */
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#65 lore raw

Re: [PATCH v5 34/50] multi-process/mon: choose HMP commands based on target

In reply to Jag Raman
Quoted 40 lines · * Jag Raman ([email protected]) wrote:
Quoted 28 lines · Dr. David Alan Gilbert
Quoted 27 lines · * Jagannathan Raman ([email protected]) wrote:

From: Elena Ufimtseva <[email protected]>

Add "targets" field to HMP command definition to select the targets which would be supported by each command

---
  hmp-commands-info.hx | 10 ++++++++++
  hmp-commands.hx      | 20 ++++++++++++++++++++
  scripts/hxtool       | 44 ++++++++++++++++++++++++++++++++++++++++++--
  3 files changed, 72 insertions(+), 2 deletions(-)

mode change 100644 => 100755 scripts/hxtool

hmp-commands-info.hx +1 -0
index 257ee7d..631cc76 100644
@@ -19,6 +19,7 @@ ETEXI
          .params     = "",
          .help       = "show the version of QEMU",
          .cmd        = hmp_info_version,
+        .targets    = "scsi",
          .flags      = "p",
      },
@@ -48,6 +49,7 @@ ETEXI
Quoted 8 lines

hmp-commands-info.hx ETEXI · line 52

Quoted 4 lines
hmp-commands-info.hx +1 -0
          .params     = "",
          .help       = "show the character devices",
          .cmd        = hmp_info_chardev,
+        .targets    = "scsi",

I'm a bit confused what this means; is this saying that the scsi-remote will respond to 'info chardev' ? Why would it be interested in info chardev?

Quoted 3 lines

We found that QMP/HMP monitor is initialized as a chardev in QEMU. So we could use this to get info about the monitors attached to the remote process.

Ah OK.

Quoted 238 lines
Quoted 229 lines
Quoted 229 lines
hmp-commands-info.hx +8 -0
          .flags      = "p",
      },
@@ -64,6 +66,7 @@ ETEXI
          .help       = "show info of one block device or all block devices "
                        "(-n: show named nodes; -v: show details)",
          .cmd        = hmp_info_block,
+        .targets    = "scsi",
      },
  STEXI
@@ -78,6 +81,7 @@ ETEXI
          .params     = "",
          .help       = "show block device statistics",
          .cmd        = hmp_info_blockstats,
+        .targets    = "scsi",
      },
  STEXI
@@ -92,6 +96,7 @@ ETEXI
          .params     = "",
          .help       = "show progress of ongoing block device operations",
          .cmd        = hmp_info_block_jobs,
+        .targets    = "scsi",
      },
  STEXI
@@ -167,6 +172,7 @@ ETEXI
          .params     = "",
          .help       = "show the command line history",
          .cmd        = hmp_info_history,
+        .targets    = "scsi",
          .flags      = "p",
      },
@@ -224,6 +230,7 @@ ETEXI
          .params     = "",
          .help       = "show PCI info",
          .cmd        = hmp_info_pci,
+        .targets    = "scsi",
      },
  STEXI
@@ -630,6 +637,7 @@ ETEXI
          .params     = "",
          .help       = "show device tree",
          .cmd        = hmp_info_qtree,
+        .targets    = "scsi",
      },
  STEXI
@@ -644,6 +652,7 @@ ETEXI
          .params     = "",
          .help       = "show qdev device model list",
          .cmd        = hmp_info_qdm,
+        .targets    = "scsi",
      },
  STEXI
@@ -658,6 +667,7 @@ ETEXI
          .params     = "[path]",
          .help       = "show QOM composition tree",
          .cmd        = hmp_info_qom_tree,
+        .targets    = "scsi",
          .flags      = "p",
      },
hmp-commands.hx +20 -0
index dc23185..ecc6169 100644
@@ -49,6 +49,7 @@ ETEXI
          .params     = "",
          .help       = "quit the emulator",
          .cmd        = hmp_quit,
+        .targets    = "scsi",
      },
  STEXI
@@ -82,6 +83,7 @@ ETEXI
          .params     = "device size",
          .help       = "resize a block image",
          .cmd        = hmp_block_resize,
+        .targets    = "scsi",
      },
  STEXI
@@ -99,6 +101,7 @@ ETEXI
          .params     = "device [speed [base]]",
          .help       = "copy data from a backing file into a block device",
          .cmd        = hmp_block_stream,
+        .targets    = "scsi",
      },
  STEXI
@@ -113,6 +116,7 @@ ETEXI
          .params     = "device speed",
          .help       = "set maximum speed for a background block operation",
          .cmd        = hmp_block_job_set_speed,
+        .targets    = "scsi",
      },
  STEXI
@@ -129,6 +133,7 @@ ETEXI
                        "\n\t\t\t if you want to abort the operation immediately"
                        "\n\t\t\t instead of keep running until data is in sync)",
          .cmd        = hmp_block_job_cancel,
+        .targets    = "scsi",
      },
  STEXI
@@ -143,6 +148,7 @@ ETEXI
          .params     = "device",
          .help       = "stop an active background block operation",
          .cmd        = hmp_block_job_complete,
+        .targets    = "scsi",
      },
  STEXI
@@ -158,6 +164,7 @@ ETEXI
          .params     = "device",
          .help       = "pause an active background block operation",
          .cmd        = hmp_block_job_pause,
+        .targets    = "scsi",
      },
  STEXI
@@ -172,6 +179,7 @@ ETEXI
          .params     = "device",
          .help       = "resume a paused background block operation",
          .cmd        = hmp_block_job_resume,
+        .targets    = "scsi",
      },
  STEXI
@@ -186,6 +194,7 @@ ETEXI
          .params     = "[-f] device",
          .help       = "eject a removable medium (use -f to force it)",
          .cmd        = hmp_eject,
+        .targets    = "scsi",
      },
  STEXI
@@ -200,6 +209,7 @@ ETEXI
          .params     = "device",
          .help       = "remove host block device",
          .cmd        = hmp_drive_del,
+        .targets    = "scsi",
      },
  STEXI
@@ -219,6 +229,7 @@ ETEXI
          .params     = "device filename [format [read-only-mode]]",
          .help       = "change a removable medium, optional format",
          .cmd        = hmp_change,
+        .targets    = "scsi",
      },
  STEXI
@@ -732,6 +743,7 @@ ETEXI
          .help       = "add device, like -device on the command line",
          .cmd        = hmp_device_add,
          .command_completion = device_add_completion,
+        .targets    = "scsi",
      },
  STEXI
@@ -747,6 +759,7 @@ ETEXI
          .help       = "remove device",
          .cmd        = hmp_device_del,
          .command_completion = device_del_completion,
+        .targets    = "scsi",
      },
  STEXI
@@ -1351,6 +1364,7 @@ ETEXI
                        "The -c flag requests QEMU to compress backup data\n\t\t\t"
                        "(if the target format supports it).\n\t\t\t",
          .cmd        = hmp_drive_backup,
+        .targets    = "scsi",
      },
  STEXI
  @item drive_backup
@@ -1368,6 +1382,7 @@ ETEXI
                        "[,readonly=on|off][,copy-on-read=on|off]",
          .help       = "add drive to PCI storage controller",
          .cmd        = hmp_drive_add,
+        .targets    = "scsi",
      },
  STEXI
@@ -1816,6 +1831,7 @@ ETEXI
          .help       = "add chardev",
          .cmd        = hmp_chardev_add,
          .command_completion = chardev_add_completion,
+        .targets    = "scsi",
      },
  STEXI
@@ -1831,6 +1847,7 @@ ETEXI
          .params     = "id args",
          .help       = "change chardev",
          .cmd        = hmp_chardev_change,
+        .targets    = "scsi",
      },
  STEXI
@@ -1848,6 +1865,7 @@ ETEXI
          .help       = "remove chardev",
          .cmd        = hmp_chardev_remove,
          .command_completion = chardev_remove_completion,
+        .targets    = "scsi",
      },
  STEXI
@@ -1864,6 +1882,7 @@ ETEXI
          .help       = "send a break on chardev",
          .cmd        = hmp_chardev_send_break,
          .command_completion = chardev_remove_completion,
+        .targets    = "scsi",
      },
  STEXI
@@ -1940,6 +1959,7 @@ ETEXI
          .params     = "[subcommand]",
          .help       = "show various information about the system state",
          .cmd        = hmp_info_help,
+        .targets    = "scsi",
          .sub_table  = hmp_info_cmds,
          .flags      = "p",
      },
scripts/hxtool +8 -1
old mode 100644
new mode 100755
index 0003e7b..802cbd4
@@ -10,7 +10,14 @@ hxtoh()
              STEXI*|ETEXI*|SRST*|ERST*) flag=$(($flag^1))
              ;;
              *)
-            test $flag -eq 1 && printf "%s\n" "$str"
+            # Skip line that has ".targets" as it is for multi-process targets based hmp
+            # commands generation.
+            echo $str | grep -q '.targets'
+            if [ $? -eq 0 ]; then
+                continue
+            else
+                test $flag -eq 1 && printf "%s\n" "$str"
+            fi
              ;;
          esac
      done
@@ -84,16 +91,49 @@ hxtotexi()
              print_texi_heading "$(expr "$str" : "ARCHHEADING(\(.*\),.*)")"
Quoted 8 lines

scripts/hxtool hxtotexi() · line 96

Quoted 6 lines
scripts/hxtool +3 -1
              ;;
              *)
-            test $flag -eq 1 && printf '%s\n' "$str"
+            # Skip line that has ".targets" as it is for multi-process targets based hmp
+            # commands generation.
+            echo $str | grep -q '.targetss'

One extra 's' ?

Quoted 54 lines

Thanks, we'll fix it.

--
Jag

Quoted 48 lines
Quoted 45 lines
scripts/hxtool +31 -0
+            if [ $? -eq 0 ]; then
+                continue
+            else
+                test $flag -eq 1 && printf '%s\n' "$str"
+            fi
              ;;
          esac
          line=$((line+1))
      done
  }
+hxtoh_tgt()
+{
+    section=""
+    flag=1
+    use_section=0
+    while read -r str; do
+        # Print section if it has ".targets" and the second argument passed to the
+        # script, such as "scsi".
+        echo "$str" | grep -q -E ".targets.*$1"
+        if [ $? -eq 0 ]; then
+            use_section=1
+            continue
+        fi
+        case $str in
+            HXCOMM*)
+            ;;
+            STEXI*|ETEXI*) flag=$(($flag^1)); test $use_section -eq 1 && printf '%s' "$section"; section=""; use_section=0
+            ;;
+            *)
+            test $flag -eq 1 && section="${section} ${str} ${IFS}"
+            ;;
+        esac
+    done
+}
+
  case "$1" in
  "-h") hxtoh ;;
  "-t") hxtotexi ;;
+"-tgt") hxtoh_tgt $2 ;;
  *) exit 1 ;;
  esac
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#70 lore raw

Re: [PATCH v5 36/50] multi-process/mon: enable QMP module support in the remote process

In reply to Jag Raman
Quoted 13 lines · * Jag Raman ([email protected]) wrote:
Quoted 9 lines · Dr. David Alan Gilbert
Quoted 5 lines · * Jagannathan Raman ([email protected]) wrote:

Build system changes to enable QMP module in the remote process

It's odd that this is labelled as QMP changes yet a lot of the code is actually HMP de-staticing.

Quoted 6 lines

This patch builds the QMP related code into the remote process. In order to facilitate the build, we need to de-staticize a bunch of HMP functions.

May be we could update the patch title to reflect the destaticing as well.

Or split it into two.

Dave

Quoted 555 lines

Thanks!
--
Jag

Quoted 550 lines

Dave

Quoted 544 lines
---
  Makefile.objs              |  9 +++++
  Makefile.target            | 35 +++++++++++++++++--
  hmp-commands.hx            |  5 +--
  hw/core/Makefile.objs      |  1 +
  monitor/Makefile.objs      |  4 +++
  monitor/misc.c             | 84 +++++++++++++++++++++++++---------------------
  monitor/monitor-internal.h | 38 +++++++++++++++++++++
  qapi/Makefile.objs         |  2 ++
  qom/Makefile.objs          |  1 +
  ui/Makefile.objs           |  2 ++
  10 files changed, 139 insertions(+), 42 deletions(-)
Makefile.objs +9 -0
index 689a722..4b5db09 100644
@@ -32,6 +32,7 @@ remote-pci-obj-$(CONFIG_MPQEMU) += migration/
  remote-pci-obj-$(CONFIG_MPQEMU) += remote/
  remote-pci-obj-$(CONFIG_MPQEMU) += accel/
  remote-pci-obj-$(CONFIG_MPQEMU) += util/
+remote-pci-obj-$(CONFIG_MPQEMU) += monitor/
  remote-pci-obj-$(CONFIG_MPQEMU) += cpus-common.o
  remote-pci-obj-$(CONFIG_MPQEMU) += dma-helpers.o
@@ -44,6 +45,9 @@ remote-pci-obj-$(CONFIG_MPQEMU) += iothread.o
  # remote-lsi-obj-y is code used to implement remote LSI device
  remote-lsi-obj-$(CONFIG_MPQEMU) += hw/
+remote-lsi-obj-$(CONFIG_MPQEMU) += ui/
+
+remote-lsi-obj-$(CONFIG_MPQEMU) += device-hotplug.o
  #######################################################################
  # crypto-obj-y is code used by both qemu system emulation and qemu-img
@@ -105,6 +109,11 @@ common-obj-y += qapi/
  endif # CONFIG_SOFTMMU
+remote-pci-obj-$(CONFIG_MPQEMU) += qapi/
+remote-pci-obj-$(CONFIG_MPQEMU) += blockdev-nbd.o
+remote-pci-obj-$(CONFIG_MPQEMU) += job-qmp.o
+remote-pci-obj-$(CONFIG_MPQEMU) += balloon.o
+
  #######################################################################
  # Target-independent parts used in system and user emulation
  common-obj-y += cpus-common.o
Makefile.target +33 -2
index 035c23b..4ead5c3 100644
@@ -142,13 +142,32 @@ remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/hax-stub.o
  remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/whpx-stub.o
  remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/vl-stub.o
  remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/net-stub.o
-remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/monitor.o
  remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/replay.o
  remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/xen-mapcache.o
  remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/audio.o
  remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/monitor.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/migration.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/ui-stub.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/gdbstub.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/qapi-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/qapi-misc.o
  remote-pci-tgt-obj-$(CONFIG_MPQEMU) += remote/memory.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += arch_init.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += monitor/misc.o
+
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-introspect.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-block-core.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-block.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-misc.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-machine-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-misc-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-visit-machine-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-visit-misc-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-types-machine-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-types-misc-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-init-commands.o
  endif
  #########################################################
@@ -203,6 +222,10 @@ endif
  generated-files-y += hmp-commands.h hmp-commands-info.h
  generated-files-y += config-devices.h
+ifdef CONFIG_MPQEMU
+generated-files-y += hmp-scsi-commands.h hmp-scsi-commands-info.h
+endif
+
  endif # CONFIG_SOFTMMU
  dummy := $(call unnest-vars,,obj-y)
@@ -288,10 +311,18 @@ hmp-commands.h: $(SRC_PATH)/hmp-commands.hx $(SRC_PATH)/scripts/hxtool
  hmp-commands-info.h: $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/scripts/hxtool
  	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"GEN","$(TARGET_DIR)$@")
+ifdef CONFIG_MPQEMU
+hmp-scsi-commands.h: $(SRC_PATH)/hmp-commands.hx $(SRC_PATH)/scripts/hxtool
+	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -tgt scsi < $< > $@)
+
+hmp-scsi-commands-info.h: $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/scripts/hxtool
+	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -tgt scsi < $< > $@)
+endif
+
  clean: clean-target
  	rm -f *.a *~ $(PROGS)
  	rm -f $(shell find . -name '*.[od]')
-	rm -f hmp-commands.h gdbstub-xml.c
+	rm -f hmp-commands.h gdbstub-xml.c hmp-scsi-commands.h hmp-scsi-commands-info.h
  	rm -f trace/generated-helpers.c trace/generated-helpers.c-timestamp
  ifdef CONFIG_TRACE_SYSTEMTAP
  	rm -f *.stp
hmp-commands.hx +3 -2
index ecc6169..a1932c4 100644
@@ -14,7 +14,8 @@ ETEXI
          .args_type  = "name:S?",
          .params     = "[cmd]",
          .help       = "show the help",
-        .cmd        = do_help_cmd,
+        .cmd        = hmp_do_help_cmd,
+        .targets    = "scsi",
          .flags      = "p",
      },
@@ -618,7 +619,7 @@ ETEXI
          .args_type  = "fmt:/,val:l",
          .params     = "/fmt expr",
          .help       = "print expression value (use $reg for CPU register access)",
-        .cmd        = do_print,
+        .cmd        = hmp_do_print,
      },
  STEXI
hw/core/Makefile.objs +1 -0
index e3e8084..251b77b 100644
@@ -49,3 +49,4 @@ remote-pci-obj-$(CONFIG_MPQEMU) += numa.o
  remote-pci-obj-$(CONFIG_MPQEMU) += cpu.o
  remote-pci-obj-$(CONFIG_MPQEMU) += vmstate-if.o
  remote-pci-obj-$(CONFIG_MPQEMU) += resettable.o
+remote-pci-obj-$(CONFIG_MPQEMU) += machine-qmp-cmds.o
monitor/Makefile.objs +4 -0
index 9244d90..48d8017 100644
@@ -2,3 +2,7 @@ obj-y += misc.o
  common-obj-y += monitor.o qmp.o hmp.o
  common-obj-y += qmp-cmds.o qmp-cmds-control.o
  common-obj-y += hmp-cmds.o
+
+remote-pci-obj-$(CONFIG_MPQEMU) += monitor.o qmp.o hmp.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qmp-cmds.o qmp-cmds-control.o
+remote-pci-obj-$(CONFIG_MPQEMU) += hmp-cmds.o
monitor/misc.c +46 -38
index 6c41293..f1f09bf 100644
@@ -177,12 +177,12 @@ int hmp_compare_cmd(const char *name, const char *list)
      return 0;
  }
-static void do_help_cmd(Monitor *mon, const QDict *qdict)
+void hmp_do_help_cmd(Monitor *mon, const QDict *qdict)
  {
      help_cmd(mon, qdict_get_try_str(qdict, "name"));
  }
-static void hmp_trace_event(Monitor *mon, const QDict *qdict)
+void hmp_trace_event(Monitor *mon, const QDict *qdict)
  {
      const char *tp_name = qdict_get_str(qdict, "name");
      bool new_state = qdict_get_bool(qdict, "option");
@@ -226,7 +226,7 @@ static void hmp_trace_file(Monitor *mon, const QDict *qdict)
  }
  #endif
-static void hmp_info_help(Monitor *mon, const QDict *qdict)
+void hmp_info_help(Monitor *mon, const QDict *qdict)
  {
      help_cmd(mon, "info");
  }
@@ -314,7 +314,7 @@ int monitor_get_cpu_index(void)
      return cs ? cs->cpu_index : UNASSIGNED_CPU_INDEX;
  }
-static void hmp_info_registers(Monitor *mon, const QDict *qdict)
+void hmp_info_registers(Monitor *mon, const QDict *qdict)
  {
      bool all_cpus = qdict_get_try_bool(qdict, "cpustate_all", false);
      CPUState *cs;
@@ -337,7 +337,7 @@ static void hmp_info_registers(Monitor *mon, const QDict *qdict)
  }
  #ifdef CONFIG_TCG
-static void hmp_info_jit(Monitor *mon, const QDict *qdict)
+void hmp_info_jit(Monitor *mon, const QDict *qdict)
  {
      if (!tcg_enabled()) {
          error_report("JIT information is only available with accel=tcg");
@@ -348,13 +348,13 @@ static void hmp_info_jit(Monitor *mon, const QDict *qdict)
      dump_drift_info();
  }
-static void hmp_info_opcount(Monitor *mon, const QDict *qdict)
+void hmp_info_opcount(Monitor *mon, const QDict *qdict)
  {
      dump_opcount_info();
  }
  #endif
-static void hmp_info_sync_profile(Monitor *mon, const QDict *qdict)
+void hmp_info_sync_profile(Monitor *mon, const QDict *qdict)
  {
      int64_t max = qdict_get_try_int(qdict, "max", 10);
      bool mean = qdict_get_try_bool(qdict, "mean", false);
@@ -365,7 +365,7 @@ static void hmp_info_sync_profile(Monitor *mon, const QDict *qdict)
      qsp_report(max, sort_by, coalesce);
  }
-static void hmp_info_history(Monitor *mon, const QDict *qdict)
+void hmp_info_history(Monitor *mon, const QDict *qdict)
  {
      MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
      int i;
@@ -385,7 +385,7 @@ static void hmp_info_history(Monitor *mon, const QDict *qdict)
      }
  }
-static void hmp_info_cpustats(Monitor *mon, const QDict *qdict)
+void hmp_info_cpustats(Monitor *mon, const QDict *qdict)
  {
      CPUState *cs = mon_get_cpu();
@@ -396,7 +396,7 @@ static void hmp_info_cpustats(Monitor *mon, const QDict *qdict)
      cpu_dump_statistics(cs, 0);
  }
-static void hmp_info_trace_events(Monitor *mon, const QDict *qdict)
+void hmp_info_trace_events(Monitor *mon, const QDict *qdict)
  {
      const char *name = qdict_get_try_str(qdict, "name");
      bool has_vcpu = qdict_haskey(qdict, "vcpu");
@@ -456,7 +456,7 @@ void qmp_client_migrate_info(const char *protocol, const char *hostname,
      error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "protocol", "spice");
  }
-static void hmp_logfile(Monitor *mon, const QDict *qdict)
+void hmp_logfile(Monitor *mon, const QDict *qdict)
  {
      Error *err = NULL;
@@ -466,7 +466,7 @@ static void hmp_logfile(Monitor *mon, const QDict *qdict)
      }
  }
-static void hmp_log(Monitor *mon, const QDict *qdict)
+void hmp_log(Monitor *mon, const QDict *qdict)
  {
      int mask;
      const char *items = qdict_get_str(qdict, "items");
@@ -483,7 +483,7 @@ static void hmp_log(Monitor *mon, const QDict *qdict)
      qemu_set_log(mask);
  }
-static void hmp_singlestep(Monitor *mon, const QDict *qdict)
+void hmp_singlestep(Monitor *mon, const QDict *qdict)
  {
      const char *option = qdict_get_try_str(qdict, "option");
      if (!option || !strcmp(option, "on")) {
@@ -495,7 +495,7 @@ static void hmp_singlestep(Monitor *mon, const QDict *qdict)
      }
  }
-static void hmp_gdbserver(Monitor *mon, const QDict *qdict)
+void hmp_gdbserver(Monitor *mon, const QDict *qdict)
  {
      const char *device = qdict_get_try_str(qdict, "device");
      if (!device)
@@ -511,7 +511,7 @@ static void hmp_gdbserver(Monitor *mon, const QDict *qdict)
      }
  }
-static void hmp_watchdog_action(Monitor *mon, const QDict *qdict)
+void hmp_watchdog_action(Monitor *mon, const QDict *qdict)
  {
      const char *action = qdict_get_str(qdict, "action");
      if (select_watchdog_action(action) == -1) {
@@ -653,7 +653,7 @@ static void memory_dump(Monitor *mon, int count, int format, int wsize,
      }
  }
-static void hmp_memory_dump(Monitor *mon, const QDict *qdict)
+void hmp_memory_dump(Monitor *mon, const QDict *qdict)
  {
      int count = qdict_get_int(qdict, "count");
      int format = qdict_get_int(qdict, "format");
@@ -663,7 +663,7 @@ static void hmp_memory_dump(Monitor *mon, const QDict *qdict)
      memory_dump(mon, count, format, size, addr, 0);
  }
-static void hmp_physical_memory_dump(Monitor *mon, const QDict *qdict)
+void hmp_physical_memory_dump(Monitor *mon, const QDict *qdict)
  {
      int count = qdict_get_int(qdict, "count");
      int format = qdict_get_int(qdict, "format");
@@ -693,7 +693,7 @@ static void *gpa2hva(MemoryRegion **p_mr, hwaddr addr, Error **errp)
      return qemu_map_ram_ptr(mrs.mr->ram_block, mrs.offset_within_region);
  }
-static void hmp_gpa2hva(Monitor *mon, const QDict *qdict)
+void hmp_gpa2hva(Monitor *mon, const QDict *qdict)
  {
      hwaddr addr = qdict_get_int(qdict, "addr");
      Error *local_err = NULL;
@@ -713,7 +713,7 @@ static void hmp_gpa2hva(Monitor *mon, const QDict *qdict)
      memory_region_unref(mr);
  }
-static void hmp_gva2gpa(Monitor *mon, const QDict *qdict)
+void hmp_gva2gpa(Monitor *mon, const QDict *qdict)
  {
      target_ulong addr = qdict_get_int(qdict, "addr");
      MemTxAttrs attrs;
@@ -768,7 +768,7 @@ out:
      return ret;
  }
-static void hmp_gpa2hpa(Monitor *mon, const QDict *qdict)
+void hmp_gpa2hpa(Monitor *mon, const QDict *qdict)
  {
      hwaddr addr = qdict_get_int(qdict, "addr");
      Error *local_err = NULL;
@@ -795,7 +795,7 @@ static void hmp_gpa2hpa(Monitor *mon, const QDict *qdict)
  }
  #endif
-static void do_print(Monitor *mon, const QDict *qdict)
+void hmp_do_print(Monitor *mon, const QDict *qdict)
  {
      int format = qdict_get_int(qdict, "format");
      hwaddr val = qdict_get_int(qdict, "val");
@@ -821,7 +821,7 @@ static void do_print(Monitor *mon, const QDict *qdict)
      monitor_printf(mon, "\n");
  }
-static void hmp_sum(Monitor *mon, const QDict *qdict)
+void hmp_sum(Monitor *mon, const QDict *qdict)
  {
      uint32_t addr;
      uint16_t sum;
@@ -841,7 +841,7 @@ static void hmp_sum(Monitor *mon, const QDict *qdict)
  static int mouse_button_state;
-static void hmp_mouse_move(Monitor *mon, const QDict *qdict)
+void hmp_mouse_move(Monitor *mon, const QDict *qdict)
  {
      int dx, dy, dz, button;
      const char *dx_str = qdict_get_str(qdict, "dx_str");
@@ -865,7 +865,7 @@ static void hmp_mouse_move(Monitor *mon, const QDict *qdict)
      qemu_input_event_sync();
  }
-static void hmp_mouse_button(Monitor *mon, const QDict *qdict)
+void hmp_mouse_button(Monitor *mon, const QDict *qdict)
  {
      static uint32_t bmap[INPUT_BUTTON__MAX] = {
          [INPUT_BUTTON_LEFT]       = MOUSE_EVENT_LBUTTON,
@@ -882,7 +882,7 @@ static void hmp_mouse_button(Monitor *mon, const QDict *qdict)
      mouse_button_state = button_state;
  }
-static void hmp_ioport_read(Monitor *mon, const QDict *qdict)
+void hmp_ioport_read(Monitor *mon, const QDict *qdict)
  {
      int size = qdict_get_int(qdict, "size");
      int addr = qdict_get_int(qdict, "addr");
@@ -916,7 +916,7 @@ static void hmp_ioport_read(Monitor *mon, const QDict *qdict)
                     suffix, addr, size * 2, val);
  }
-static void hmp_ioport_write(Monitor *mon, const QDict *qdict)
+void hmp_ioport_write(Monitor *mon, const QDict *qdict)
  {
      int size = qdict_get_int(qdict, "size");
      int addr = qdict_get_int(qdict, "addr");
@@ -938,7 +938,7 @@ static void hmp_ioport_write(Monitor *mon, const QDict *qdict)
      }
  }
-static void hmp_boot_set(Monitor *mon, const QDict *qdict)
+void hmp_boot_set(Monitor *mon, const QDict *qdict)
  {
      Error *local_err = NULL;
      const char *bootdevice = qdict_get_str(qdict, "bootdevice");
@@ -951,7 +951,7 @@ static void hmp_boot_set(Monitor *mon, const QDict *qdict)
      }
  }
-static void hmp_info_mtree(Monitor *mon, const QDict *qdict)
+void hmp_info_mtree(Monitor *mon, const QDict *qdict)
  {
      bool flatview = qdict_get_try_bool(qdict, "flatview", false);
      bool dispatch_tree = qdict_get_try_bool(qdict, "dispatch_tree", false);
@@ -964,7 +964,7 @@ static void hmp_info_mtree(Monitor *mon, const QDict *qdict)
  int64_t dev_time;
-static void hmp_info_profile(Monitor *mon, const QDict *qdict)
+void hmp_info_profile(Monitor *mon, const QDict *qdict)
  {
      static int64_t last_cpu_exec_time;
      int64_t cpu_exec_time;
@@ -981,7 +981,7 @@ static void hmp_info_profile(Monitor *mon, const QDict *qdict)
      dev_time = 0;
  }
  #else
-static void hmp_info_profile(Monitor *mon, const QDict *qdict)
+void hmp_info_profile(Monitor *mon, const QDict *qdict)
  {
      monitor_printf(mon, "Internal profiler not compiled\n");
  }
@@ -990,7 +990,7 @@ static void hmp_info_profile(Monitor *mon, const QDict *qdict)
  /* Capture support */
  static QLIST_HEAD (capture_list_head, CaptureState) capture_head;
-static void hmp_info_capture(Monitor *mon, const QDict *qdict)
+void hmp_info_capture(Monitor *mon, const QDict *qdict)
  {
      int i;
      CaptureState *s;
@@ -1001,7 +1001,7 @@ static void hmp_info_capture(Monitor *mon, const QDict *qdict)
      }
  }
-static void hmp_stopcapture(Monitor *mon, const QDict *qdict)
+void hmp_stopcapture(Monitor *mon, const QDict *qdict)
  {
      int i;
      int n = qdict_get_int(qdict, "n");
@@ -1017,7 +1017,7 @@ static void hmp_stopcapture(Monitor *mon, const QDict *qdict)
      }
  }
-static void hmp_wavcapture(Monitor *mon, const QDict *qdict)
+void hmp_wavcapture(Monitor *mon, const QDict *qdict)
  {
      const char *path = qdict_get_str(qdict, "path");
      int freq = qdict_get_try_int(qdict, "freq", 44100);
@@ -1070,7 +1070,7 @@ static void hmp_warn_acl(void)
      warn_acl = true;
  }
-static void hmp_acl_show(Monitor *mon, const QDict *qdict)
+void hmp_acl_show(Monitor *mon, const QDict *qdict)
  {
      const char *aclname = qdict_get_str(qdict, "aclname");
      QAuthZList *auth = find_auth(mon, aclname);
@@ -1097,7 +1097,7 @@ static void hmp_acl_show(Monitor *mon, const QDict *qdict)
      }
  }
-static void hmp_acl_reset(Monitor *mon, const QDict *qdict)
+void hmp_acl_reset(Monitor *mon, const QDict *qdict)
  {
      const char *aclname = qdict_get_str(qdict, "aclname");
      QAuthZList *auth = find_auth(mon, aclname);
@@ -1114,7 +1114,7 @@ static void hmp_acl_reset(Monitor *mon, const QDict *qdict)
      monitor_printf(mon, "acl: removed all rules\n");
  }
-static void hmp_acl_policy(Monitor *mon, const QDict *qdict)
+void hmp_acl_policy(Monitor *mon, const QDict *qdict)
  {
      const char *aclname = qdict_get_str(qdict, "aclname");
      const char *policy = qdict_get_str(qdict, "policy");
@@ -1155,7 +1155,7 @@ static QAuthZListFormat hmp_acl_get_format(const char *match)
      }
  }
-static void hmp_acl_add(Monitor *mon, const QDict *qdict)
+void hmp_acl_add(Monitor *mon, const QDict *qdict)
  {
      const char *aclname = qdict_get_str(qdict, "aclname");
      const char *match = qdict_get_str(qdict, "match");
@@ -1208,7 +1208,7 @@ static void hmp_acl_add(Monitor *mon, const QDict *qdict)
      }
  }
-static void hmp_acl_remove(Monitor *mon, const QDict *qdict)
+void hmp_acl_remove(Monitor *mon, const QDict *qdict)
  {
      const char *aclname = qdict_get_str(qdict, "aclname");
      const char *match = qdict_get_str(qdict, "match");
@@ -1678,13 +1678,21 @@ int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp)
  /* Please update hmp-commands.hx when adding or changing commands */
  static HMPCommand hmp_info_cmds[] = {
+#if defined(SCSI_PROCESS)
+#include "hmp-scsi-commands-info.h"
+#else
  #include "hmp-commands-info.h"
+#endif
      { NULL, NULL, },
  };
  /* hmp_cmds and hmp_info_cmds would be sorted at runtime */
  HMPCommand hmp_cmds[] = {
+#if defined(SCSI_PROCESS)
+#include "hmp-scsi-commands.h"
+#else
  #include "hmp-commands.h"
+#endif
      { NULL, NULL, },
  };
monitor/monitor-internal.h +38 -0
index 3e6baba..26349cb 100644
@@ -183,4 +183,42 @@ int hmp_compare_cmd(const char *name, const char *list);
  void qmp_query_qmp_schema(QDict *qdict, QObject **ret_data,
                                   Error **errp);
+void hmp_do_help_cmd(Monitor *mon, const QDict *qdict);
+void hmp_trace_event(Monitor *mon, const QDict *qdict);
+void hmp_info_help(Monitor *mon, const QDict *qdict);
+void hmp_info_registers(Monitor *mon, const QDict *qdict);
+void hmp_info_jit(Monitor *mon, const QDict *qdict);
+void hmp_info_opcount(Monitor *mon, const QDict *qdict);
+void hmp_info_sync_profile(Monitor *mon, const QDict *qdict);
+void hmp_info_history(Monitor *mon, const QDict *qdict);
+void hmp_info_cpustats(Monitor *mon, const QDict *qdict);
+void hmp_info_trace_events(Monitor *mon, const QDict *qdict);
+void hmp_logfile(Monitor *mon, const QDict *qdict);
+void hmp_log(Monitor *mon, const QDict *qdict);
+void hmp_singlestep(Monitor *mon, const QDict *qdict);
+void hmp_gdbserver(Monitor *mon, const QDict *qdict);
+void hmp_watchdog_action(Monitor *mon, const QDict *qdict);
+void hmp_memory_dump(Monitor *mon, const QDict *qdict);
+void hmp_physical_memory_dump(Monitor *mon, const QDict *qdict);
+void hmp_gpa2hva(Monitor *mon, const QDict *qdict);
+void hmp_gva2gpa(Monitor *mon, const QDict *qdict);
+void hmp_gpa2hpa(Monitor *mon, const QDict *qdict);
+void hmp_do_print(Monitor *mon, const QDict *qdict);
+void hmp_sum(Monitor *mon, const QDict *qdict);
+void hmp_mouse_move(Monitor *mon, const QDict *qdict);
+void hmp_mouse_button(Monitor *mon, const QDict *qdict);
+void hmp_ioport_read(Monitor *mon, const QDict *qdict);
+void hmp_ioport_write(Monitor *mon, const QDict *qdict);
+void hmp_boot_set(Monitor *mon, const QDict *qdict);
+void hmp_info_mtree(Monitor *mon, const QDict *qdict);
+void hmp_info_profile(Monitor *mon, const QDict *qdict);
+void hmp_info_capture(Monitor *mon, const QDict *qdict);
+void hmp_stopcapture(Monitor *mon, const QDict *qdict);
+void hmp_wavcapture(Monitor *mon, const QDict *qdict);
+void hmp_acl_show(Monitor *mon, const QDict *qdict);
+void hmp_acl_reset(Monitor *mon, const QDict *qdict);
+void hmp_acl_policy(Monitor *mon, const QDict *qdict);
+void hmp_acl_add(Monitor *mon, const QDict *qdict);
+void hmp_acl_remove(Monitor *mon, const QDict *qdict);
+
  #endif
qapi/Makefile.objs +2 -0
index 20fcc37..a8a3925 100644
@@ -31,3 +31,5 @@ obj-y += qapi-events.o
  obj-y += $(QAPI_TARGET_MODULES:%=qapi-commands-%.o)
  obj-y += qapi-commands.o
  obj-y += qapi-init-commands.o
+
+remote-pci-obj-$(CONFIG_MPQEMU) += $(QAPI_COMMON_MODULES:%=qapi-commands-%.o)
qom/Makefile.objs +1 -0
index 07e50e5..16603d7 100644
@@ -5,3 +5,4 @@ common-obj-$(CONFIG_SOFTMMU) += qom-hmp-cmds.o qom-qmp-cmds.o
  remote-pci-obj-$(CONFIG_MPQEMU) += object.o qom-qobject.o container.o
  remote-pci-obj-$(CONFIG_MPQEMU) += object_interfaces.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qom-qmp-cmds.o qom-hmp-cmds.o
ui/Makefile.objs +2 -0
index e6da6ff..c3ac572 100644
@@ -68,3 +68,5 @@ console-gl.o-libs += $(OPENGL_LIBS)
  egl-helpers.o-libs += $(OPENGL_LIBS)
  egl-context.o-libs += $(OPENGL_LIBS)
  egl-headless.o-libs += $(OPENGL_LIBS)
+
+remote-lsi-obj-$(CONFIG_MPQEMU) += vnc-stubs.o
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#96 lore raw

Re: [PATCH v5 46/50] multi-process/mig: Restore the VMSD in remote process

In reply to Jagannathan Raman
Quoted 39 lines · * Jagannathan Raman ([email protected]) wrote:

From: Elena Ufimtseva <[email protected]>

The remote process accepts the VMSD from Proxy object and restores it

---
 migration/savevm.c   | 36 ++++++++++++++++++++++++++++++++++++
 migration/savevm.h   |  1 +
 remote/remote-main.c | 33 +++++++++++++++++++++++++++++++++
 3 files changed, 70 insertions(+)
migration/savevm.c +17 -0
index 09af14d..e95ea4a 100644
@@ -2969,3 +2969,39 @@ int qemu_remote_savevm(QEMUFile *f)
 
     return 0;
 }
+
+int qemu_remote_loadvm(QEMUFile *f)
+{
+    uint8_t section_type;
+    int ret = 0;
+
+    qemu_mutex_lock_iothread();
+
+    while (true) {
+        section_type = qemu_get_byte(f);
+
+        if (qemu_file_get_error(f)) {
+            ret = qemu_file_get_error(f);
+            break;
+        }
+
+        switch (section_type) {

migration/savevm.c int qemu_remote_savevm(QEMUFile *f) · line 2998

Quoted 10 lines
migration/savevm.c +10 -0
+        case QEMU_VM_SECTION_FULL:
+            ret = qemu_loadvm_section_start_full(f, NULL);
+            if (ret < 0) {
+                break;
+            }
+            break;
+        case QEMU_VM_EOF:
+            goto out;
+        default:
+            ret = -EINVAL;

It's good to print an error there - when it goes wrong we'll want to know it.

Quoted 64 lines
migration/savevm.c +9 -0
+            goto out;
+        }
+    }
+
+out:
+    qemu_mutex_unlock_iothread();
+
+    return ret;
+}
migration/savevm.h +1 -0
index 0491d3a..8741c66 100644
@@ -66,5 +66,6 @@ int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis);
 int qemu_load_device_state(QEMUFile *f);
 
 int qemu_remote_savevm(QEMUFile *f);
+int qemu_remote_loadvm(QEMUFile *f);
 
 #endif
remote/remote-main.c +25 -0
index 0260c7c..ab4ad0b 100644
@@ -68,6 +68,7 @@
 #include "chardev/char.h"
 #include "sysemu/reset.h"
 #include "vl.h"
+#include "migration/misc.h"
 
 static MPQemuLinkState *mpqemu_link;
 
@@ -363,6 +364,30 @@ static void process_start_mig_out(MPQemuMsg *msg)
     qemu_fclose(f);
 }
 
+static int process_start_mig_in(MPQemuMsg *msg)
+{
+    Error *err = NULL;
+    QIOChannel *ioc;
+    QEMUFile *f;
+    int rc = -EINVAL;
+
+    ioc = qio_channel_new_fd(msg->fds[0], &err);
+    if (err) {
+        error_report_err(err);
+        return rc;
+    }
+
+    qio_channel_set_name(QIO_CHANNEL(ioc), "remote-migration-channel");
+
+    f = qemu_fopen_channel_input(ioc);
+
+    rc = qemu_remote_loadvm(f);
+
+    qemu_fclose(f);
+
+    return rc;
+}
+
 static void process_msg(GIOCondition cond, MPQemuChannel *chan)
 {
     MPQemuMsg *msg = NULL;

remote/remote-main.c static void process_msg(GIOCondition cond, MPQemuChannel *chan) · line 488

Quoted 9 lines
remote/remote-main.c +6 -0
@@ -455,6 +480,12 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)
     case START_MIG_OUT:
         process_start_mig_out(msg);
         break;
+    case START_MIG_IN:
+        if (process_start_mig_in(msg)) {
+            error_setg(&err, "Incoming migration failed.");
+            goto finalize_loop;
+        }
+        break;

Do you have any sanity checks to make sure what happens if you were to receive a MIG_IN while you were already running?

Dave

Quoted 15 lines
remote/remote-main.c +2 -0
     case RUNSTATE_SET:
         remote_runstate_set(msg->data1.runstate.state);
         notify_proxy(msg->fds[0], 0);
@@ -532,6 +563,8 @@ int main(int argc, char *argv[])
     }
     mpqemu_init_channel(mpqemu_link, &mpqemu_link->mmio, fd);
 
+    migration_object_init();
+
     parse_cmdline(argc - 3, argv + 3, NULL);
 
     mpqemu_link_set_callback(mpqemu_link, process_msg);
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#90 lore raw

Re: [PATCH v5 42/50] multi-process/mig: Send VMSD of remote to the Proxy object

In reply to Dr. David Alan Gilbert
Quoted 19 lines · Dr. David Alan Gilbert
Quoted 18 lines · * Jagannathan Raman ([email protected]) wrote:

The remote process sends the VMSD to the Proxy object, on the source side

---
 migration/savevm.c   | 27 +++++++++++++++++++++++++++
 migration/savevm.h   |  2 ++
 remote/remote-main.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 72 insertions(+)
migration/savevm.c +0 -0
index 1d4220e..09af14d 100644
@@ -2942,3 +2942,30 @@ bool vmstate_check_only_migratable(const VMStateDescription *vmsd)
 
Quoted 7 lines

migration/savevm.c bool vmstate_check_only_migratable(const VMStateDescription *vmsd) · line 2945

Quoted 3 lines
migration/savevm.c +1 -0
     return !(vmsd && vmsd->unmigratable);
 }
+

Can we add something here commenting, e.g.
/* Called by the remote process to serialise migration back to the qemu
* */

Will add this.

Quoted 18 lines
Quoted 18 lines
migration/savevm.c +18 -0
+int qemu_remote_savevm(QEMUFile *f)
+{
+    SaveStateEntry *se;
+    int ret;
+
+    QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
+        if (!se->vmsd || !vmstate_save_needed(se->vmsd, se->opaque)) {
+            continue;
+        }
+
+        save_section_header(f, se, QEMU_VM_SECTION_FULL);
+
+        ret = vmstate_save(f, se, NULL);
+        if (ret) {
+            qemu_file_set_error(f, ret);
+            return ret;
+        }
+
Quoted 9 lines

migration/savevm.c bool vmstate_check_only_migratable(const VMStateDescription *vmsd) · line 2968

Quoted 5 lines
migration/savevm.c +5 -0
+        save_section_footer(f, se);
+    }
+
+    qemu_put_byte(f, QEMU_VM_EOF);
+    qemu_fflush(f);

You have a qemu_fflush in process_start_mig_out just after you call it
- so you don't need both; I suggest you remove this one.

Ok.

Quoted 5 lines

migration/savevm.c bool vmstate_check_only_migratable(const VMStateDescription *vmsd) · line 2970

Quoted 1 line
migration/savevm.c +1 -0
+    return 0;

And make this return qemu_file_get_error(f); just like qemu_save_device_state and then makybe some day we can merge them.

Will do.

Quoted 53 lines
Quoted 53 lines
migration/savevm.c +1 -0
+}
migration/savevm.h +2 -0
index ba64a7e..0491d3a 100644
@@ -65,4 +65,6 @@ void qemu_loadvm_state_cleanup(void);
 int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis);
 int qemu_load_device_state(QEMUFile *f);
 
+int qemu_remote_savevm(QEMUFile *f);
+
 #endif
remote/remote-main.c +24 -0
index 58d9905..e97eb76 100644
@@ -53,6 +53,16 @@
 #include "qemu/log.h"
 #include "qemu/cutils.h"
 #include "remote-opts.h"
+#include "qapi/error.h"
+#include "io/channel-util.h"
+
+#include "io/channel.h"
+#include "io/channel-socket.h"
+#include "migration/qemu-file-types.h"
+#include "migration/savevm.h"
+#include "migration/qemu-file-channel.h"
+#include "migration/qemu-file.h"
+
 #include "monitor/monitor.h"
 #include "chardev/char.h"
 #include "sysemu/reset.h"
@@ -322,6 +332,36 @@ static int setup_device(MPQemuMsg *msg, Error **errp)
 
 }
 
+static void process_start_mig_out(MPQemuMsg *msg)
+{
+    int wait = msg->fds[1];
+    Error *err = NULL;
+    QIOChannel *ioc;
+    QEMUFile *f;
+
+    ioc = qio_channel_new_fd(msg->fds[0], &err);
+    if (err) {
+        error_report_err(err);
+        return;
+    }
+
+    qio_channel_set_name(QIO_CHANNEL(ioc), "remote-migration-channel");
Quoted 8 lines

remote/remote-main.c static int setup_device(MPQemuMsg *msg, Error **errp) · line 353

Quoted 5 lines
remote/remote-main.c +5 -0
+
+    f = qemu_fopen_channel_output(ioc);
+
+    bdrv_drain_all();
+    (void)bdrv_flush_all();

Do remote process always have block code? I mean can't we have a remote process that's just say a NIC ?

Not always (in the future), we will account for this.

Quoted 7 lines

remote/remote-main.c static int setup_device(MPQemuMsg *msg, Error **errp) · line 355

Quoted 2 lines
remote/remote-main.c +1 -0
+    (void)qemu_remote_savevm(f);

It's probably bad to ignore errors here; what you could do is if there's an error, you shoul dprint something and then send a poison value back to the QEMU to let it know that you've failed.

Yes, will add this.

Quoted 27 lines
Quoted 23 lines
remote/remote-main.c +11 -0
+    qemu_fflush(f);
+
+    notify_proxy(wait, (uint64_t)qemu_ftell(f));
+    PUT_REMOTE_WAIT(wait);
+
+    qemu_fclose(f);
+}
+
 static void process_msg(GIOCondition cond, MPQemuChannel *chan)
 {
     MPQemuMsg *msg = NULL;
@@ -411,6 +451,9 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)
             notify_proxy(msg->fds[0], 0);
         }
         break;
+    case START_MIG_OUT:
+        process_start_mig_out(msg);
+        break;
     default:
         error_setg(&err, "Unknown command");
         goto finalize_loop;
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

author
#86 lore raw

Re: [PATCH v5 41/50] multi-process/mig: Enable VMSD save in the Proxy object

In reply to Dr. David Alan Gilbert
Quoted 116 lines · Dr. David Alan Gilbert
Quoted 100 lines · * Jagannathan Raman ([email protected]) wrote:

Collect the VMSD from remote process on the source and save it to the channel leading to the destination

---
v4 -> v5:
- Using qemu_file_shutdown() instead of qemu_thread_cancel(). Removed patch which introduced qemu_thread_cancel()

  hw/proxy/qemu-proxy.c         | 135 ++++++++++++++++++++++++++++++++++++++++++
  include/hw/proxy/qemu-proxy.h |   2 +
  include/io/mpqemu-link.h      |   1 +
  3 files changed, 138 insertions(+)
hw/proxy/qemu-proxy.c +62 -0
index b1b9282..19f0dbb 100644
@@ -23,6 +23,14 @@
  #include "util/event_notifier-posix.c"
  #include "hw/boards.h"
  #include "include/qemu/log.h"
+#include "io/channel.h"
+#include "migration/qemu-file-types.h"
+#include "qapi/error.h"
+#include "io/channel-util.h"
+#include "migration/qemu-file-channel.h"
+#include "migration/qemu-file.h"
+#include "migration/migration.h"
+#include "migration/vmstate.h"
 
  QEMUTimer *hb_timer;
  static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp);
@@ -35,6 +43,9 @@ static void broadcast_init(void);
  static int config_op_send(PCIProxyDev *dev, uint32_t addr, uint32_t *val, int l,
                            unsigned int op);
 
+#define PAGE_SIZE qemu_real_host_page_size
+uint8_t *mig_data;
+
  static void childsig_handler(int sig, siginfo_t *siginfo, void *ctx)
  {
      /* TODO: Add proper handler. */
@@ -460,6 +471,129 @@ static void pci_proxy_dev_inst_init(Object *obj)
      dev->mem_init = false;
  }
 
+typedef struct {
+    QEMUFile *rem;
+    PCIProxyDev *dev;
+} proxy_mig_data;
+
+static void *proxy_mig_out(void *opaque)
+{
+    proxy_mig_data *data = opaque;
+    PCIProxyDev *dev = data->dev;
+    uint8_t byte;
+    uint64_t data_size = PAGE_SIZE;
+
+    mig_data = g_malloc(data_size);
+
+    while (true) {
+        byte = qemu_get_byte(data->rem);
+
+        if (qemu_file_get_error(data->rem)) {
+            break;
+        }
+
+        mig_data[dev->migsize++] = byte;
+        if (dev->migsize == data_size) {
+            data_size += PAGE_SIZE;
+            mig_data = g_realloc(mig_data, data_size);
+        }
+    }
+
+    return NULL;
+}
+
+static int proxy_pre_save(void *opaque)
+{
+    PCIProxyDev *pdev = opaque;
+    proxy_mig_data *mig_data;
+    QEMUFile *f_remote;
+    MPQemuMsg msg = {0};
+    QemuThread thread;
+    Error *err = NULL;
+    QIOChannel *ioc;
+    uint64_t size;
+    int fd[2];
+
+    if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) {
+        return -1;
+    }
+
+    ioc = qio_channel_new_fd(fd[0], &err);
+    if (err) {
+        error_report_err(err);
+        return -1;

hw/proxy/qemu-proxy.c static void pci_proxy_dev_inst_init(Object *obj) · line 534

Quoted 10 lines
hw/proxy/qemu-proxy.c +10 -0
+    }
+
+    qio_channel_set_name(QIO_CHANNEL(ioc), "PCIProxyDevice-mig");
+
+    f_remote = qemu_fopen_channel_input(ioc);
+
+    pdev->migsize = 0;
+
+    mig_data = g_malloc0(sizeof(proxy_mig_data));
+    mig_data->rem = f_remote;

This feels way too complicated. Since we know f_remote is always just
a simple fd we're getting we don't need to use qio or qemu_file here; just use the fd - nice and simple.

Quoted 2 lines

Then the code to read it can just use read(2) with a sensible size chunk rather than reading a byte at a time.

Hi Dave,

Upon closer inspection, we found that the migration code on the remote (which uses QEMUFile) could sometimes set an error on the channel using qemu_file_set_error(). We needed to use qemu_file_get_error() to catch these errors and abort migration. So we had to stick with QEMUFile at the receiving end as well.

Quoted 10 lines

hw/proxy/qemu-proxy.c static void pci_proxy_dev_inst_init(Object *obj) · line 538

Quoted 5 lines
hw/proxy/qemu-proxy.c +4 -0
+    mig_data->dev = pdev;
+
+    qemu_thread_create(&thread, "Proxy MIG_OUT", proxy_mig_out, mig_data,
+                       QEMU_THREAD_DETACHED);

I'm just checking why a thread is necessary; is this because you need to be able to start reading before you block waiting for the remote to tell you the size - worrying that if you don't start reading then the remote might block waiting for us?

Yes, Dave. That is correct.

Quoted 31 lines
Quoted 10 lines
hw/proxy/qemu-proxy.c +9 -0
+    msg.cmd = START_MIG_OUT;
+    msg.bytestream = 0;
+    msg.num_fds = 2;
+    msg.fds[0] = fd[1];
+    msg.fds[1] = GET_REMOTE_WAIT;
+
+    mpqemu_msg_send(&msg, pdev->mpqemu_link->com);
+    size = wait_for_remote(msg.fds[1]);
+    PUT_REMOTE_WAIT(msg.fds[1]);

hw/proxy/qemu-proxy.c static void pci_proxy_dev_inst_init(Object *obj) · line 558

Quoted 10 lines
hw/proxy/qemu-proxy.c +10 -0
+
+    assert(size != ULLONG_MAX);
+
+    /*
+     * migsize is being update by a separate thread. Using volatile to
+     * instruct the compiler to fetch the value of this variable from
+     * memory during every read
+     */
+    while (*((volatile uint64_t *)&pdev->migsize) < size) {
+    }

Hmm. I suggest the following:

a) You create a shared 'size' variable; and initialize it to

     UINT64_MAX.
   b) The thread uses atomic_read(shared_size) to read that value.
   c) When you receive the size from the remote you do
      atomic_set(&shared_size, size);

d) The thread does:
while (received_size < atomic_read(&shared_size))

Quoted 7 lines

so the thread will quit either on EOF or it hitting the size.

e) We pthread_join here to wait for the thread
f) We then check a received size to make sure it matches what we
expect.

That removes the tight loop.

Sure, will do.

Quoted 26 lines
Quoted 13 lines
hw/proxy/qemu-proxy.c +12 -0
+    qemu_file_shutdown(f_remote);
+
+    qemu_fclose(f_remote);
+    close(fd[1]);
+
+    return 0;
+}
+
+static int proxy_post_save(void *opaque)
+{
+    MigrationState *ms = migrate_get_current();
+    PCIProxyDev *pdev = opaque;

hw/proxy/qemu-proxy.c static void pci_proxy_dev_inst_init(Object *obj) · line 581

Quoted 10 lines
hw/proxy/qemu-proxy.c +10 -0
+    uint64_t pos = 0;
+
+    while (pos < pdev->migsize) {
+        qemu_put_byte(ms->to_dst_file, mig_data[pos]);
+        pos++;
+    }
+
+    qemu_fflush(ms->to_dst_file);
+
+    return 0;

I don't think you need that.

Quoted 16 lines

hw/proxy/qemu-proxy.c static void pci_proxy_dev_inst_init(Object *obj) · line 592

Quoted 11 lines
hw/proxy/qemu-proxy.c +11 -0
+}
+
+const VMStateDescription vmstate_pci_proxy_device = {
+    .name = "PCIProxyDevice",
+    .version_id = 2,
+    .minimum_version_id = 1,
+    .pre_save = proxy_pre_save,
+    .post_save = proxy_post_save,
+    .fields = (VMStateField[]) {
+        VMSTATE_PCI_DEVICE(parent_dev, PCIProxyDev),
+        VMSTATE_UINT64(migsize, PCIProxyDev),

I think instead you should use a VMSTATE_VBUFFER here to save the mig_data.
What we should do is the post_save should g_free the buffer. (mig_data should be a field in proxy).

We noticed that VMSTATE_BUFFER requires that the buffer be part of a "struct" and that the buffer is an array. Since the buffer we're using is neither an array nor part of a "struct", we decided to go with writing the buffer directly to the migration stream in proxy_post_save() instead of using VMSTATE_BUFFER.

I think we should nevertheless g_free this buffer in post_save like you pointed out.

Thank you!
--
Jag

Quoted 50 lines

Dave

Quoted 43 lines
hw/proxy/qemu-proxy.c +5 -0
+        VMSTATE_END_OF_LIST()
+    }
+};
+
  static void pci_proxy_dev_class_init(ObjectClass *klass, void *data)
  {
      PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
@@ -471,6 +605,7 @@ static void pci_proxy_dev_class_init(ObjectClass *klass, void *data)
      k->config_write = pci_proxy_write_config;
 
      dc->reset = proxy_device_reset;
+    dc->vmsd = &vmstate_pci_proxy_device;
  }
 
  static const TypeInfo pci_proxy_dev_type_info = {
include/hw/proxy/qemu-proxy.h +2 -0
index 5de8129..537c227 100644
@@ -75,6 +75,8 @@ struct PCIProxyDev {
                          bool need_spawn, Error **errp);
 
      ProxyMemoryRegion region[PCI_NUM_REGIONS];
+
+    uint64_t migsize;
  };
 
  typedef struct PCIProxyDevClass {
include/io/mpqemu-link.h +1 -0
index d2234ca..b42c003 100644
@@ -63,6 +63,7 @@ typedef enum {
      PROXY_PING,
      MMIO_RETURN,
      DEVICE_RESET,
+    START_MIG_OUT,
      MAX,
  } mpqemu_cmd_t;
 
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#87 lore raw

Re: [PATCH v5 41/50] multi-process/mig: Enable VMSD save in the Proxy object

Quoted 119 lines · * Jag Raman ([email protected]) wrote:
Quoted 113 lines · Dr. David Alan Gilbert
Quoted 97 lines · * Jagannathan Raman ([email protected]) wrote:

Collect the VMSD from remote process on the source and save it to the channel leading to the destination

---
v4 -> v5:
- Using qemu_file_shutdown() instead of qemu_thread_cancel(). Removed patch which introduced qemu_thread_cancel()

  hw/proxy/qemu-proxy.c         | 135 ++++++++++++++++++++++++++++++++++++++++++
  include/hw/proxy/qemu-proxy.h |   2 +
  include/io/mpqemu-link.h      |   1 +
  3 files changed, 138 insertions(+)
hw/proxy/qemu-proxy.c +62 -0
index b1b9282..19f0dbb 100644
@@ -23,6 +23,14 @@
  #include "util/event_notifier-posix.c"
  #include "hw/boards.h"
  #include "include/qemu/log.h"
+#include "io/channel.h"
+#include "migration/qemu-file-types.h"
+#include "qapi/error.h"
+#include "io/channel-util.h"
+#include "migration/qemu-file-channel.h"
+#include "migration/qemu-file.h"
+#include "migration/migration.h"
+#include "migration/vmstate.h"
  QEMUTimer *hb_timer;
  static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp);
@@ -35,6 +43,9 @@ static void broadcast_init(void);
  static int config_op_send(PCIProxyDev *dev, uint32_t addr, uint32_t *val, int l,
                            unsigned int op);
+#define PAGE_SIZE qemu_real_host_page_size
+uint8_t *mig_data;
+
  static void childsig_handler(int sig, siginfo_t *siginfo, void *ctx)
  {
      /* TODO: Add proper handler. */
@@ -460,6 +471,129 @@ static void pci_proxy_dev_inst_init(Object *obj)
      dev->mem_init = false;
  }
+typedef struct {
+    QEMUFile *rem;
+    PCIProxyDev *dev;
+} proxy_mig_data;
+
+static void *proxy_mig_out(void *opaque)
+{
+    proxy_mig_data *data = opaque;
+    PCIProxyDev *dev = data->dev;
+    uint8_t byte;
+    uint64_t data_size = PAGE_SIZE;
+
+    mig_data = g_malloc(data_size);
+
+    while (true) {
+        byte = qemu_get_byte(data->rem);
+
+        if (qemu_file_get_error(data->rem)) {
+            break;
+        }
+
+        mig_data[dev->migsize++] = byte;
+        if (dev->migsize == data_size) {
+            data_size += PAGE_SIZE;
+            mig_data = g_realloc(mig_data, data_size);
+        }
+    }
+
+    return NULL;
+}
+
+static int proxy_pre_save(void *opaque)
+{
+    PCIProxyDev *pdev = opaque;
+    proxy_mig_data *mig_data;
+    QEMUFile *f_remote;
+    MPQemuMsg msg = {0};
+    QemuThread thread;
+    Error *err = NULL;
+    QIOChannel *ioc;
+    uint64_t size;
+    int fd[2];
+
+    if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) {
+        return -1;
+    }
+
+    ioc = qio_channel_new_fd(fd[0], &err);
+    if (err) {
+        error_report_err(err);
+        return -1;

hw/proxy/qemu-proxy.c static void pci_proxy_dev_inst_init(Object *obj) · line 533

Quoted 10 lines
hw/proxy/qemu-proxy.c +10 -0
+    }
+
+    qio_channel_set_name(QIO_CHANNEL(ioc), "PCIProxyDevice-mig");
+
+    f_remote = qemu_fopen_channel_input(ioc);
+
+    pdev->migsize = 0;
+
+    mig_data = g_malloc0(sizeof(proxy_mig_data));
+    mig_data->rem = f_remote;

This feels way too complicated. Since we know f_remote is always just
a simple fd we're getting we don't need to use qio or qemu_file here; just use the fd - nice and simple.

Quoted 2 lines

Then the code to read it can just use read(2) with a sensible size chunk rather than reading a byte at a time.

Quoted 7 lines

Hi Dave,

Upon closer inspection, we found that the migration code on the remote (which uses QEMUFile) could sometimes set an error on the channel using qemu_file_set_error(). We needed to use qemu_file_get_error() to catch these errors and abort migration. So we had to stick with QEMUFile at the receiving end as well.

I realise you need to use a QEMUFile on the part that connects to the Savevm code/vmstate code - but that doesn't mean you need it on the side that just connects between your pipe and the qemu.

Quoted 97 lines
Quoted 10 lines

hw/proxy/qemu-proxy.c static void pci_proxy_dev_inst_init(Object *obj) · line 538

Quoted 5 lines
hw/proxy/qemu-proxy.c +4 -0
+    mig_data->dev = pdev;
+
+    qemu_thread_create(&thread, "Proxy MIG_OUT", proxy_mig_out, mig_data,
+                       QEMU_THREAD_DETACHED);

I'm just checking why a thread is necessary; is this because you need to be able to start reading before you block waiting for the remote to tell you the size - worrying that if you don't start reading then the remote might block waiting for us?

Yes, Dave. That is correct.

Quoted 31 lines
Quoted 10 lines
hw/proxy/qemu-proxy.c +9 -0
+    msg.cmd = START_MIG_OUT;
+    msg.bytestream = 0;
+    msg.num_fds = 2;
+    msg.fds[0] = fd[1];
+    msg.fds[1] = GET_REMOTE_WAIT;
+
+    mpqemu_msg_send(&msg, pdev->mpqemu_link->com);
+    size = wait_for_remote(msg.fds[1]);
+    PUT_REMOTE_WAIT(msg.fds[1]);

hw/proxy/qemu-proxy.c static void pci_proxy_dev_inst_init(Object *obj) · line 558

Quoted 10 lines
hw/proxy/qemu-proxy.c +10 -0
+
+    assert(size != ULLONG_MAX);
+
+    /*
+     * migsize is being update by a separate thread. Using volatile to
+     * instruct the compiler to fetch the value of this variable from
+     * memory during every read
+     */
+    while (*((volatile uint64_t *)&pdev->migsize) < size) {
+    }

Hmm. I suggest the following:

a) You create a shared 'size' variable; and initialize it to

     UINT64_MAX.
   b) The thread uses atomic_read(shared_size) to read that value.
   c) When you receive the size from the remote you do
      atomic_set(&shared_size, size);

d) The thread does:
while (received_size < atomic_read(&shared_size))

Quoted 7 lines

so the thread will quit either on EOF or it hitting the size.

e) We pthread_join here to wait for the thread
f) We then check a received size to make sure it matches what we
expect.

That removes the tight loop.

Sure, will do.

Quoted 26 lines
Quoted 13 lines
hw/proxy/qemu-proxy.c +12 -0
+    qemu_file_shutdown(f_remote);
+
+    qemu_fclose(f_remote);
+    close(fd[1]);
+
+    return 0;
+}
+
+static int proxy_post_save(void *opaque)
+{
+    MigrationState *ms = migrate_get_current();
+    PCIProxyDev *pdev = opaque;

hw/proxy/qemu-proxy.c static void pci_proxy_dev_inst_init(Object *obj) · line 581

Quoted 10 lines
hw/proxy/qemu-proxy.c +10 -0
+    uint64_t pos = 0;
+
+    while (pos < pdev->migsize) {
+        qemu_put_byte(ms->to_dst_file, mig_data[pos]);
+        pos++;
+    }
+
+    qemu_fflush(ms->to_dst_file);
+
+    return 0;

I don't think you need that.

Quoted 16 lines

hw/proxy/qemu-proxy.c static void pci_proxy_dev_inst_init(Object *obj) · line 592

Quoted 11 lines
hw/proxy/qemu-proxy.c +11 -0
+}
+
+const VMStateDescription vmstate_pci_proxy_device = {
+    .name = "PCIProxyDevice",
+    .version_id = 2,
+    .minimum_version_id = 1,
+    .pre_save = proxy_pre_save,
+    .post_save = proxy_post_save,
+    .fields = (VMStateField[]) {
+        VMSTATE_PCI_DEVICE(parent_dev, PCIProxyDev),
+        VMSTATE_UINT64(migsize, PCIProxyDev),

I think instead you should use a VMSTATE_VBUFFER here to save the mig_data.
What we should do is the post_save should g_free the buffer. (mig_data should be a field in proxy).

Quoted 8 lines

We noticed that VMSTATE_BUFFER requires that the buffer be part of a "struct" and that the buffer is an array. Since the buffer we're using is neither an array nor part of a "struct", we decided to go with writing the buffer directly to the migration stream in proxy_post_save() instead of using VMSTATE_BUFFER.

I think we should nevertheless g_free this buffer in post_save like you pointed out.

Note I'm suggesting using VMSTATE_VBUFFER, not VMSTATE_BUFFER; VBUFFER is expecting a unsigned char *; it does expect that to be in your structure, so I'd expect your proxy to have a mig_data and uint32_t mig_len fields.

Dave

Quoted 50 lines

Thank you!
--
Jag

Quoted 45 lines

Dave

Quoted 38 lines
hw/proxy/qemu-proxy.c +5 -0
+        VMSTATE_END_OF_LIST()
+    }
+};
+
  static void pci_proxy_dev_class_init(ObjectClass *klass, void *data)
  {
      PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
@@ -471,6 +605,7 @@ static void pci_proxy_dev_class_init(ObjectClass *klass, void *data)
      k->config_write = pci_proxy_write_config;
      dc->reset = proxy_device_reset;
+    dc->vmsd = &vmstate_pci_proxy_device;
  }
  static const TypeInfo pci_proxy_dev_type_info = {
include/hw/proxy/qemu-proxy.h +2 -0
index 5de8129..537c227 100644
@@ -75,6 +75,8 @@ struct PCIProxyDev {
                          bool need_spawn, Error **errp);
      ProxyMemoryRegion region[PCI_NUM_REGIONS];
+
+    uint64_t migsize;
  };
  typedef struct PCIProxyDevClass {
include/io/mpqemu-link.h +1 -0
index d2234ca..b42c003 100644
@@ -63,6 +63,7 @@ typedef enum {
      PROXY_PING,
      MMIO_RETURN,
      DEVICE_RESET,
+    START_MIG_OUT,
      MAX,
  } mpqemu_cmd_t;
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#82 lore raw

Re: [PATCH v5 40/50] multi-process/mig: build migration module in the remote process

In reply to Dr. David Alan Gilbert
Quoted 109 lines · Dr. David Alan Gilbert
Quoted 103 lines · * Jag Raman ([email protected]) wrote:
Quoted 85 lines · Dr. David Alan Gilbert
Quoted 79 lines · * Jag Raman ([email protected]) wrote:
Quoted 67 lines · Dr. David Alan Gilbert
Quoted 66 lines · * Jagannathan Raman ([email protected]) wrote:

Add Makefile support to enable migration in remote process

---
   Makefile.objs           |  4 +++-
   Makefile.target         |  1 +
   migration/Makefile.objs | 13 ++++++++++++-
   net/Makefile.objs       |  2 ++
   softmmu/vl.c            |  2 --
   stubs/migration.c       | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
   stubs/net-stub.c        | 21 +++++++++++++++++++++
   stubs/qapi-misc.c       |  2 ++
   stubs/replay.c          |  8 ++++++++
   stubs/vl-stub.c         | 24 ++++++++++++++++++++++++
   vl-parse.c              |  3 +++
   11 files changed, 125 insertions(+), 4 deletions(-)
Makefile.objs +3 -1
index 4b5db09..65009da 100644
@@ -74,6 +74,8 @@ common-obj-y += qdev-monitor.o device-hotplug.o
   common-obj-$(CONFIG_WIN32) += os-win32.o
   common-obj-$(CONFIG_POSIX) += os-posix.o
+remote-pci-obj-$(CONFIG_POSIX) += os-posix.o
+
   common-obj-$(CONFIG_LINUX) += fsdev/
   common-obj-y += accel/
@@ -104,11 +106,11 @@ common-obj-y += vl-parse.o
   #######################################################################
   # qapi
-
   common-obj-y += qapi/
   endif # CONFIG_SOFTMMU
+remote-pci-obj-$(CONFIG_MPQEMU) += net/
   remote-pci-obj-$(CONFIG_MPQEMU) += qapi/
   remote-pci-obj-$(CONFIG_MPQEMU) += blockdev-nbd.o
   remote-pci-obj-$(CONFIG_MPQEMU) += job-qmp.o
Makefile.target +1 -0
index 4ead5c3..4012ae5 100644
@@ -240,6 +240,7 @@ all-remote-pci-obj-y += exec.o
   all-remote-pci-obj-y += exec-vary.o
   all-remote-pci-obj-y += ioport.o
   all-remote-pci-obj-y += cpus.o
+all-remote-pci-obj-y += migration/ram.o
   endif
   remote-pci-obj-y :=
migration/Makefile.objs +8 -1
index e7cdc76..21f9d8d 100644
@@ -15,4 +15,15 @@ common-obj-$(CONFIG_LIVE_BLOCK_MIGRATION) += block.o
   rdma.o-libs := $(RDMA_LIBS)
-remote-pci-obj-$(CONFIG_MPQEMU) += qemu-file.o vmstate.o qjson.o vmstate-types.o
+remote-pci-obj-$(CONFIG_MPQEMU) += migration.o socket.o fd.o exec.o
+remote-pci-obj-$(CONFIG_MPQEMU) += tls.o channel.o savevm.o
+remote-pci-obj-$(CONFIG_MPQEMU) += colo.o colo-failover.o
+remote-pci-obj-$(CONFIG_MPQEMU) += vmstate.o vmstate-types.o page_cache.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qemu-file.o global_state.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qemu-file-channel.o
+remote-pci-obj-$(CONFIG_MPQEMU) += xbzrle.o postcopy-ram.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qjson.o
Quoted 8 lines

migration/Makefile.objs common-obj-$(CONFIG_LIVE_BLOCK_MIGRATION) += block.o · line 29

Quoted 4 lines
migration/Makefile.objs +4 -0
+remote-pci-obj-$(CONFIG_MPQEMU) += block-dirty-bitmap.o
+remote-pci-obj-$(CONFIG_RDMA) += rdma.o
+remote-pci-obj-$(CONFIG_MPQEMU) += block.o
+remote-pci-obj-$(CONFIG_MPQEMU) += multifd.o

Hmm, are you really going to want all this lot in your remote process? Assuming it's just devices, I can understand the first line or two, but it seems odd to have all of this.

Quoted 4 lines

Yeah, we ended up needing to compile these in to enable migration. We are only using "fd" to enable migration. Although we don't use tls, xbzrle, rdma, multifd, etc... for example, the migration code does support these protocols and, therefore, we had to compile them in.

Quoted 4 lines

But are you even running a migration stream from the remote process? Aren't you just doing vmstate migration of devices; i.e. do you need anything relating to incremental RAM migration (e.g. xbzrle, rdma, postcopy).

We are running a migration stream from the remote process. We are only doing the vmstate migration of devices, and not anything incremental related to RAM.

We are using QEMU's existing migration infrastructure (vmstate_save / qemu_loadvm_section_start_full) to move the vmstate. Based on my limited experience with the migration code, I get that it comes as a suite. Without some refactoring, we would need to build all of the files within the migration folder.

Quoted 4 lines

The vmstate functions communicate over QEMUFile, which would be using fd, tcp, rdma, etc... at the backend. These functions also need other functions defined in migration.c, which require the building of xbzrle, postcopy, etc...

Quoted 7 lines

OK, I bet we can refactor some of that to be modular fairly easily; some is harder than others. For example there are different QEMUFile subclasses for RDMA, so you should be able to have just the top level QEMUFile and the implementations you need.
Similarly the vmstate code shouldn't depend on the ram code; we can look at splitting it up some how.

Hi Dave

We did initially tried to split some of the vmstate code, and it was a lot of code to add to already big patchset. So we could do this split later on as a separate series. Would that be an option or you would rather see it in this set?

Thank you!

Elena

Quoted 235 lines

Dave

Quoted 230 lines

Thank you!
--
Jag

Quoted 225 lines

Dave

Quoted 219 lines

Thank you!
--
Jag

Quoted 214 lines

Dave

Quoted 208 lines
net/Makefile.objs +2 -0
index c5d076d..a8ad986 100644
@@ -30,3 +30,5 @@ common-obj-$(CONFIG_WIN32) += tap-win32.o
   vde.o-libs = $(VDE_LIBS)
   common-obj-$(CONFIG_CAN_BUS) += can/
+
+remote-pci-obj-$(CONFIG_MPQEMU) += announce.o
softmmu/vl.c +0 -2
index 4a4f52c..42d5682 100644
@@ -128,7 +128,6 @@ const char* keyboard_layout = NULL;
   ram_addr_t ram_size;
   const char *mem_path = NULL;
   int mem_prealloc = 0; /* force preallocation of physical target memory */
-bool enable_mlock = false;
   bool enable_cpu_pm = false;
   int nb_nics;
   NICInfo nd_table[MAX_NICS];
@@ -168,7 +167,6 @@ const char *prom_envs[MAX_PROM_ENVS];
   int boot_menu;
   bool boot_strict;
   uint8_t *boot_splash_filedata;
-int only_migratable; /* turn it off unless user states otherwise */
   bool wakeup_suspend_enabled;
   int icount_align_option;
stubs/migration.c +49 -0
index 28ccf80..dbd12db 100644
@@ -6,6 +6,35 @@
   #include "qapi/qapi-types-migration.h"
   #include "qapi/qapi-commands-migration.h"
   #include "qapi/qapi-types-net.h"
+#include "net/filter.h"
+#include "net/colo-compare.h"
+
+#pragma weak qmp_query_migrate_capabilities
+#pragma weak qmp_query_migrate_parameters
+#pragma weak migrate_announce_params
+#pragma weak qmp_query_migrate
+#pragma weak qmp_migrate_set_capabilities
+#pragma weak qmp_migrate_set_parameters
+#pragma weak qmp_migrate_incoming
+#pragma weak qmp_migrate_recover
+#pragma weak qmp_migrate_pause
+#pragma weak qmp_migrate
+#pragma weak qmp_migrate_cancel
+#pragma weak qmp_migrate_continue
+#pragma weak qmp_migrate_set_cache_size
+#pragma weak qmp_query_migrate_cache_size
+#pragma weak qmp_migrate_set_speed
+#pragma weak qmp_migrate_set_downtime
+#pragma weak qmp_migrate_start_postcopy
+#pragma weak migration_global_dump
+#pragma weak save_snapshot
+#pragma weak qmp_xen_save_devices_state
+#pragma weak load_snapshot
+#pragma weak qmp_xen_set_replication
+#pragma weak qmp_query_xen_replication_status
+#pragma weak qmp_xen_colo_do_checkpoint
+#pragma weak qmp_query_colo_status
+#pragma weak qmp_x_colo_lost_heartbeat
   MigrationInfo *qmp_query_migrate(Error **errp)
   {
@@ -160,3 +189,23 @@ AnnounceParameters *migrate_announce_params(void)
       return NULL;
   }
+
+void colo_notify_filters_event(int event, Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+void colo_notify_compares_event(void *opaque, int event, Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+void colo_compare_register_notifier(Notifier *notify)
+{
+    qemu_debug_assert(0);
+}
+
+void colo_compare_unregister_notifier(Notifier *notify)
+{
+    qemu_debug_assert(0);
+}
stubs/net-stub.c +21 -0
index 962827e..ddfd1e4 100644
@@ -5,6 +5,8 @@
   #include "qapi/qapi-commands-net.h"
   #include "qapi/qapi-commands-rocker.h"
+#pragma weak qmp_announce_self
+
   int qemu_find_net_clients_except(const char *id, NetClientState **ncs,
                                    NetClientDriver type, int max)
   {
@@ -98,3 +100,22 @@ void netdev_add(QemuOpts *opts, Error **errp)
   {
       qemu_debug_assert(0);
   }
+
+NetClientState *qemu_get_queue(NICState *nic)
+{
+    qemu_debug_assert(0);
+
+    return NULL;
+}
+
+ssize_t qemu_send_packet_raw(NetClientState *nc, const uint8_t *buf, int size)
+{
+    qemu_debug_assert(0);
+
+    return 0;
+}
+
+void qemu_foreach_nic(qemu_nic_foreach func, void *opaque)
+{
+    qemu_debug_assert(0);
+}
stubs/qapi-misc.c +2 -0
index 3eeedd9..824eac1 100644
@@ -5,6 +5,8 @@
   #include "./qapi/qapi-types-dump.h"
   #include "qapi/qapi-commands-dump.h"
+#pragma weak qmp_xen_load_devices_state
+
   void qmp_dump_guest_memory(bool paging, const char *file,
                              bool has_detach, bool detach,
                              bool has_begin, int64_t begin, bool has_length,
stubs/replay.c +8 -0
index 9b53c0c..6fc7850 100644
@@ -1,4 +1,5 @@
   #include "qemu/osdep.h"
+#include "qemu-common.h"
   #include "sysemu/replay.h"
   ReplayMode replay_mode;
@@ -106,3 +107,10 @@ void replay_account_executed_instructions(void)
   void replay_add_blocker(Error *reason)
   {
   }
+
+bool replay_can_snapshot(void)
+{
+    qemu_debug_assert(0);
+
+    return false;
+}
stubs/vl-stub.c +24 -0
index 606f078..5f308c1 100644
@@ -14,6 +14,8 @@
   #include "disas/disas.h"
   #include "audio/audio.h"
+#pragma weak qemu_add_exit_notifier
+
   bool tcg_allowed;
   bool xen_allowed;
   bool boot_strict;
@@ -169,3 +171,25 @@ int wav_start_capture(AudioState *state, CaptureState *s, const char *path,
       return -1;
   }
+
+void qemu_system_killed(int signal, pid_t pid)
+{
+    qemu_debug_assert(0);
+}
+
+void qemu_system_reset(ShutdownCause reason)
+{
+    qemu_debug_assert(0);
+}
+
+bool runstate_store(char *str, size_t size)
+{
+    qemu_debug_assert(0);
+
+    return false;
+}
+
+void qemu_add_exit_notifier(Notifier *notify)
+{
+    qemu_debug_assert(0);
+}
vl-parse.c +3 -0
index 1f6a3f0..423f4a0 100644
@@ -27,6 +27,9 @@
   #include "vl.h"
+int only_migratable; /* turn it off unless user states otherwise */
+bool enable_mlock;
+
   /***********************************************************/
   /* QEMU Block devices */
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#83 lore raw

Re: [PATCH v5 40/50] multi-process/mig: build migration module in the remote process

Quoted 118 lines · * Elena Ufimtseva ([email protected]) wrote:
Quoted 109 lines · Dr. David Alan Gilbert
Quoted 103 lines · * Jag Raman ([email protected]) wrote:
Quoted 85 lines · Dr. David Alan Gilbert
Quoted 79 lines · * Jag Raman ([email protected]) wrote:
Quoted 67 lines · Dr. David Alan Gilbert
Quoted 66 lines · * Jagannathan Raman ([email protected]) wrote:

Add Makefile support to enable migration in remote process

---
   Makefile.objs           |  4 +++-
   Makefile.target         |  1 +
   migration/Makefile.objs | 13 ++++++++++++-
   net/Makefile.objs       |  2 ++
   softmmu/vl.c            |  2 --
   stubs/migration.c       | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
   stubs/net-stub.c        | 21 +++++++++++++++++++++
   stubs/qapi-misc.c       |  2 ++
   stubs/replay.c          |  8 ++++++++
   stubs/vl-stub.c         | 24 ++++++++++++++++++++++++
   vl-parse.c              |  3 +++
   11 files changed, 125 insertions(+), 4 deletions(-)
Makefile.objs +3 -1
index 4b5db09..65009da 100644
@@ -74,6 +74,8 @@ common-obj-y += qdev-monitor.o device-hotplug.o
   common-obj-$(CONFIG_WIN32) += os-win32.o
   common-obj-$(CONFIG_POSIX) += os-posix.o
+remote-pci-obj-$(CONFIG_POSIX) += os-posix.o
+
   common-obj-$(CONFIG_LINUX) += fsdev/
   common-obj-y += accel/
@@ -104,11 +106,11 @@ common-obj-y += vl-parse.o
   #######################################################################
   # qapi
-
   common-obj-y += qapi/
   endif # CONFIG_SOFTMMU
+remote-pci-obj-$(CONFIG_MPQEMU) += net/
   remote-pci-obj-$(CONFIG_MPQEMU) += qapi/
   remote-pci-obj-$(CONFIG_MPQEMU) += blockdev-nbd.o
   remote-pci-obj-$(CONFIG_MPQEMU) += job-qmp.o
Makefile.target +1 -0
index 4ead5c3..4012ae5 100644
@@ -240,6 +240,7 @@ all-remote-pci-obj-y += exec.o
   all-remote-pci-obj-y += exec-vary.o
   all-remote-pci-obj-y += ioport.o
   all-remote-pci-obj-y += cpus.o
+all-remote-pci-obj-y += migration/ram.o
   endif
   remote-pci-obj-y :=
migration/Makefile.objs +8 -1
index e7cdc76..21f9d8d 100644
@@ -15,4 +15,15 @@ common-obj-$(CONFIG_LIVE_BLOCK_MIGRATION) += block.o
   rdma.o-libs := $(RDMA_LIBS)
-remote-pci-obj-$(CONFIG_MPQEMU) += qemu-file.o vmstate.o qjson.o vmstate-types.o
+remote-pci-obj-$(CONFIG_MPQEMU) += migration.o socket.o fd.o exec.o
+remote-pci-obj-$(CONFIG_MPQEMU) += tls.o channel.o savevm.o
+remote-pci-obj-$(CONFIG_MPQEMU) += colo.o colo-failover.o
+remote-pci-obj-$(CONFIG_MPQEMU) += vmstate.o vmstate-types.o page_cache.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qemu-file.o global_state.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qemu-file-channel.o
+remote-pci-obj-$(CONFIG_MPQEMU) += xbzrle.o postcopy-ram.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qjson.o
Quoted 8 lines

migration/Makefile.objs common-obj-$(CONFIG_LIVE_BLOCK_MIGRATION) += block.o · line 27

Quoted 4 lines
migration/Makefile.objs +4 -0
+remote-pci-obj-$(CONFIG_MPQEMU) += block-dirty-bitmap.o
+remote-pci-obj-$(CONFIG_RDMA) += rdma.o
+remote-pci-obj-$(CONFIG_MPQEMU) += block.o
+remote-pci-obj-$(CONFIG_MPQEMU) += multifd.o

Hmm, are you really going to want all this lot in your remote process? Assuming it's just devices, I can understand the first line or two, but it seems odd to have all of this.

Quoted 4 lines

Yeah, we ended up needing to compile these in to enable migration. We are only using "fd" to enable migration. Although we don't use tls, xbzrle, rdma, multifd, etc... for example, the migration code does support these protocols and, therefore, we had to compile them in.

Quoted 4 lines

But are you even running a migration stream from the remote process? Aren't you just doing vmstate migration of devices; i.e. do you need anything relating to incremental RAM migration (e.g. xbzrle, rdma, postcopy).

We are running a migration stream from the remote process. We are only doing the vmstate migration of devices, and not anything incremental related to RAM.

We are using QEMU's existing migration infrastructure (vmstate_save / qemu_loadvm_section_start_full) to move the vmstate. Based on my limited experience with the migration code, I get that it comes as a suite. Without some refactoring, we would need to build all of the files within the migration folder.

Quoted 4 lines

The vmstate functions communicate over QEMUFile, which would be using fd, tcp, rdma, etc... at the backend. These functions also need other functions defined in migration.c, which require the building of xbzrle, postcopy, etc...

Quoted 7 lines

OK, I bet we can refactor some of that to be modular fairly easily; some is harder than others. For example there are different QEMUFile subclasses for RDMA, so you should be able to have just the top level QEMUFile and the implementations you need.
Similarly the vmstate code shouldn't depend on the ram code; we can look at splitting it up some how.

Quoted 5 lines

Hi Dave

We did initially tried to split some of the vmstate code, and it was a lot of code to add to already big patchset. So we could do this split later on as a separate series. Would that be an option or you would rather see it in this set?

I'd say see if there are any easy things you can split; if there are then lets take those as part of this series.

Dave

Quoted 239 lines

Thank you!

Elena

Quoted 235 lines

Dave

Quoted 230 lines

Thank you!
--
Jag

Quoted 225 lines

Dave

Quoted 219 lines

Thank you!
--
Jag

Quoted 214 lines

Dave

Quoted 208 lines
net/Makefile.objs +2 -0
index c5d076d..a8ad986 100644
@@ -30,3 +30,5 @@ common-obj-$(CONFIG_WIN32) += tap-win32.o
   vde.o-libs = $(VDE_LIBS)
   common-obj-$(CONFIG_CAN_BUS) += can/
+
+remote-pci-obj-$(CONFIG_MPQEMU) += announce.o
softmmu/vl.c +0 -2
index 4a4f52c..42d5682 100644
@@ -128,7 +128,6 @@ const char* keyboard_layout = NULL;
   ram_addr_t ram_size;
   const char *mem_path = NULL;
   int mem_prealloc = 0; /* force preallocation of physical target memory */
-bool enable_mlock = false;
   bool enable_cpu_pm = false;
   int nb_nics;
   NICInfo nd_table[MAX_NICS];
@@ -168,7 +167,6 @@ const char *prom_envs[MAX_PROM_ENVS];
   int boot_menu;
   bool boot_strict;
   uint8_t *boot_splash_filedata;
-int only_migratable; /* turn it off unless user states otherwise */
   bool wakeup_suspend_enabled;
   int icount_align_option;
stubs/migration.c +49 -0
index 28ccf80..dbd12db 100644
@@ -6,6 +6,35 @@
   #include "qapi/qapi-types-migration.h"
   #include "qapi/qapi-commands-migration.h"
   #include "qapi/qapi-types-net.h"
+#include "net/filter.h"
+#include "net/colo-compare.h"
+
+#pragma weak qmp_query_migrate_capabilities
+#pragma weak qmp_query_migrate_parameters
+#pragma weak migrate_announce_params
+#pragma weak qmp_query_migrate
+#pragma weak qmp_migrate_set_capabilities
+#pragma weak qmp_migrate_set_parameters
+#pragma weak qmp_migrate_incoming
+#pragma weak qmp_migrate_recover
+#pragma weak qmp_migrate_pause
+#pragma weak qmp_migrate
+#pragma weak qmp_migrate_cancel
+#pragma weak qmp_migrate_continue
+#pragma weak qmp_migrate_set_cache_size
+#pragma weak qmp_query_migrate_cache_size
+#pragma weak qmp_migrate_set_speed
+#pragma weak qmp_migrate_set_downtime
+#pragma weak qmp_migrate_start_postcopy
+#pragma weak migration_global_dump
+#pragma weak save_snapshot
+#pragma weak qmp_xen_save_devices_state
+#pragma weak load_snapshot
+#pragma weak qmp_xen_set_replication
+#pragma weak qmp_query_xen_replication_status
+#pragma weak qmp_xen_colo_do_checkpoint
+#pragma weak qmp_query_colo_status
+#pragma weak qmp_x_colo_lost_heartbeat
   MigrationInfo *qmp_query_migrate(Error **errp)
   {
@@ -160,3 +189,23 @@ AnnounceParameters *migrate_announce_params(void)
       return NULL;
   }
+
+void colo_notify_filters_event(int event, Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+void colo_notify_compares_event(void *opaque, int event, Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+void colo_compare_register_notifier(Notifier *notify)
+{
+    qemu_debug_assert(0);
+}
+
+void colo_compare_unregister_notifier(Notifier *notify)
+{
+    qemu_debug_assert(0);
+}
stubs/net-stub.c +21 -0
index 962827e..ddfd1e4 100644
@@ -5,6 +5,8 @@
   #include "qapi/qapi-commands-net.h"
   #include "qapi/qapi-commands-rocker.h"
+#pragma weak qmp_announce_self
+
   int qemu_find_net_clients_except(const char *id, NetClientState **ncs,
                                    NetClientDriver type, int max)
   {
@@ -98,3 +100,22 @@ void netdev_add(QemuOpts *opts, Error **errp)
   {
       qemu_debug_assert(0);
   }
+
+NetClientState *qemu_get_queue(NICState *nic)
+{
+    qemu_debug_assert(0);
+
+    return NULL;
+}
+
+ssize_t qemu_send_packet_raw(NetClientState *nc, const uint8_t *buf, int size)
+{
+    qemu_debug_assert(0);
+
+    return 0;
+}
+
+void qemu_foreach_nic(qemu_nic_foreach func, void *opaque)
+{
+    qemu_debug_assert(0);
+}
stubs/qapi-misc.c +2 -0
index 3eeedd9..824eac1 100644
@@ -5,6 +5,8 @@
   #include "./qapi/qapi-types-dump.h"
   #include "qapi/qapi-commands-dump.h"
+#pragma weak qmp_xen_load_devices_state
+
   void qmp_dump_guest_memory(bool paging, const char *file,
                              bool has_detach, bool detach,
                              bool has_begin, int64_t begin, bool has_length,
stubs/replay.c +8 -0
index 9b53c0c..6fc7850 100644
@@ -1,4 +1,5 @@
   #include "qemu/osdep.h"
+#include "qemu-common.h"
   #include "sysemu/replay.h"
   ReplayMode replay_mode;
@@ -106,3 +107,10 @@ void replay_account_executed_instructions(void)
   void replay_add_blocker(Error *reason)
   {
   }
+
+bool replay_can_snapshot(void)
+{
+    qemu_debug_assert(0);
+
+    return false;
+}
stubs/vl-stub.c +24 -0
index 606f078..5f308c1 100644
@@ -14,6 +14,8 @@
   #include "disas/disas.h"
   #include "audio/audio.h"
+#pragma weak qemu_add_exit_notifier
+
   bool tcg_allowed;
   bool xen_allowed;
   bool boot_strict;
@@ -169,3 +171,25 @@ int wav_start_capture(AudioState *state, CaptureState *s, const char *path,
       return -1;
   }
+
+void qemu_system_killed(int signal, pid_t pid)
+{
+    qemu_debug_assert(0);
+}
+
+void qemu_system_reset(ShutdownCause reason)
+{
+    qemu_debug_assert(0);
+}
+
+bool runstate_store(char *str, size_t size)
+{
+    qemu_debug_assert(0);
+
+    return false;
+}
+
+void qemu_add_exit_notifier(Notifier *notify)
+{
+    qemu_debug_assert(0);
+}
vl-parse.c +3 -0
index 1f6a3f0..423f4a0 100644
@@ -27,6 +27,9 @@
   #include "vl.h"
+int only_migratable; /* turn it off unless user states otherwise */
+bool enable_mlock;
+
   /***********************************************************/
   /* QEMU Block devices */
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#35 lore raw

Re: [PATCH v5 14/50] mutli-process: build remote command line args

In reply to Daniel P. Berrangé
Quoted 169 lines · Daniel P. Berrangé
Quoted 168 lines · Elena Ufimtseva
Quoted 139 lines · Daniel P. Berrangé
Quoted 92 lines · Elena Ufimtseva
Quoted 81 lines · Daniel P. Berrangé
Quoted 63 lines · Elena Ufimtseva
Quoted 3 lines · Daniel P. Berrangé
Quoted 2 lines · Philippe Mathieu-Daudé

typo "multi" in patch subject.

Thank Philippe, will fix.

Quoted 40 lines
Quoted 40 lines · Jagannathan Raman
Quoted 39 lines

From: Elena Ufimtseva <[email protected]>

---
v4 -> v5:
- Added "exec" suboption to get the executable's name
- Addressed feedback about variable names
- Removed redundant check for spawning a process

  hw/proxy/qemu-proxy.c         | 68 +++++++++++++++++++++++++++++++++----------
  include/hw/proxy/qemu-proxy.h |  2 +-
  2 files changed, 54 insertions(+), 16 deletions(-)
hw/proxy/qemu-proxy.c +18 -0
index 828bbd7..d792e86 100644
@@ -19,19 +19,50 @@
  static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp);
+static int add_argv(char *opts_str, char **argv, int argc)
+{
+    int max_args = 64;
+
+    if (argc < max_args - 1) {
+        argv[argc++] = opts_str;
+        argv[argc] = 0;
+    } else {
+        return 0;
+    }
+
+    return argc;
+}
+
+static int make_argv(char *opts_str, char **argv, int argc)
+{
+    int max_args = 64;
+
Quoted 9 lines
Quoted 8 lines

hw/proxy/qemu-proxy.c line 43

Quoted 6 lines
hw/proxy/qemu-proxy.c +6 -0
+    char *p2 = strtok(opts_str, " ");
+    while (p2 && argc < max_args - 1) {
+        argv[argc++] = p2;
+        p2 = strtok(0, " ");
+    }
+    argv[argc] = 0;

Is there a GLib function to do that?

Hi Daniel

Quoted 2 lines

g_shell_parse_argv() perhaps

Thanks for the suggestion.

Quoted 8 lines
Quoted 6 lines

https://developer.gnome.org/glib/stable/glib-Shell-related-Utilities.html

Though my preference would be to avoid the need to do this at all, by not accepting a raw shell command line string in the first place.

Can you please clarify? Did you mean that it would be better if Qemu somehow verifies the options and then passes it to a remote process via a message?

I've not been able to trace the code paths back all the way, so I can't point to where I think needs fixing. I assuming that something, somewhere in this patch series should starts out with a binary name and a list of argv as an array of char *. ie a "char **argv". At some point this array gets mashed together into a single 'char *' string where all the argv are separated by a space. This patch now tries to parse this and turn it back into a "char **argv" array.

Quoted 4 lines

So my key point is that we should try hard to avoid this intermediate shell command line string stage entirely. Always keep the argv in an array form, and never mash them together such that they then need parsing again.

Hi Daniel

Thank you for explanation.
At this point there is no intermediate stage as we grab the arguments as a raw string from the command line option -remote:

Quoted 8 lines

-remote rid=8,exec=qemu-scsi-dev,command="-drive id=drive_image2,,file=/root/remote-process-disk.img"

So the command="" string is being later parsed into the array and remote process gets spawned with the "char **argv".

Stefan expressed his concern that its not convenient to use due to the double escaping commas, spaces, quotes and we do agree with that. We were seeking an advice on what is the better approach.

I've not looked closely enough to understand the range of different options we need to be able to pass to the remote QEMU ? Is it just "-drive" options, or can it be absolutely any QEMU option ?

If it is just -drive, then I could imagine a -remote-drive option such that we end up with with a set of args

   $QEMU \
   -remote rid=8,exec=qemu-scsi-dev \
   -remote-drive rid=8,id=drive_image1,file=/root/remote-process-disk1.img \
   -remote-drive rid=8,id=drive_image2,file=/root/remote-process-disk2.img \
   -remote rid=9,exec=qemu-scsi-dev \
   -remote-drive rid=9,id=drive_image3,file=/root/remote-process-disk3.img \
   -remote-drive rid=9,id=drive_image4,file=/root/remote-process-disk4.img

And this gets turned into 2 execs:

   qemu-scsi-dev \
   -drive rid=8,id=drive_image1,file=/root/remote-process-disk1.img \
   -drive rid=8,id=drive_image2,file=/root/remote-process-disk2.img
   
   qemu-scsi-dev \
   -drive rid=9,id=drive_image3,file=/root/remote-process-disk3.img \
   -drive rid=9,id=drive_image4,file=/root/remote-process-disk4.img

Or maybe instead of having a '-remote-drive' arg, we can make the '-drive' arg take an optional "rid" attribute to associate it with the remote process

   $QEMU \
   -remote rid=8,exec=qemu-scsi-dev \
   -drive rid=8,id=drive_image1,file=/root/remote-process-disk1.img \
   -drive rid=8,id=drive_image2,file=/root/remote-process-disk2.img \
   -remote rid=9,exec=qemu-scsi-dev \
   -drive rid=9,id=drive_image3,file=/root/remote-process-disk3.img \
   -drive rid=9,id=drive_image4,file=/root/remote-process-disk4.img
Quoted 8 lines

When 'rid' is seen, instead of creating a local block backend, the args get used for the remote process.

This would have the nice user behaviour that you can take an existing QEMU command line, and turn it into a multi-process command line simply by adding the '-remote ...' arg, and adding 'rid=NN' to each -drive. Nothing else about your existing command line need change.

This does look good, especially unmodified -drive.
And -monitor for the remote process could also be similarly added with only rid specified instead of plugging it into the raw string.

Stefan did mention in the another patch that he thinks that adding -remote option is too invasive and suggested using -object itself to further separate remote process devices.

So to compile both replies, the command line for the remote process will look something like this:

(quoted diff) +0 -6
-object remote-device,id=rid0,exec=qemu-scsi-dev \
-device remote-pci-device,id=scsi0,remote-device=rid0 \
-device scsi-hd,drive=drive_image1,bus=scsi0.0,scsi-id=0,remote-device=rid0 \
-drive id=drive_image3,file=/root/remote-process-disk3.img,remote-device=rid0 \
-drive id=drive_image4,file=/root/remote-process-disk4.img,remote-device=rid0 \
-monitor unix:/home/qmp-sock,,server,,nowait,remote-device=rid0
Quoted 8 lines
Quoted 4 lines

And in experimental version we imply that remote-pci-device is the LSI controller. For vfio-over-socket it will represent any remote PCI device.

What your thoughts on this?

Looks like a reasonable idea to me. I guess I'm not sure how much the block maintainers will like having a -drive additional property. Probably depends how much it impacts the code paths processing it.

Not all of the remote program's command-line options may be known to QEMU, so passing through just a few options like -drive does not fix the problem.

I suggest just providing the arguments as a single string parameter like this patch series already does, but make sure to consider the escaping rules for commas and other special characters.

Stefan

#109 lore raw

Re: [PATCH v5 50/50] multi-process: add configure and usage information

In reply to Elena Ufimtseva
Quoted 39 lines · Elena Ufimtseva
Quoted 28 lines · Stefan Hajnoczi
Quoted 5 lines · Jagannathan Raman
docs/qemu-multiprocess.txt new file +5 -0
+* The devices to be emulated in the separate process are defined as
+  before with addition of "rid" suboption that serves as a remote group
+  identificator.
+
+  -device <device options>,rid="remote process id"

docs/qemu-multiprocess.txt line 41

Quoted 10 lines
docs/qemu-multiprocess.txt new file +10 -0
+
+  For example, for non multi-process qemu:
+    -device lsi53c895a,id=scsi0 device
+    -device scsi-hd,drive=drive0,bus=scsi0.0,scsi-id=0
+    -drive id=drive0,file=data-disk.img
+
+  and for multi-process qemu and no libvirt
+  support (i.e. QEMU forks child processes):
+    -device lsi53c895a,id=scsi0,rid=0
+    -device scsi-hd,drive=drive0,bus=scsi0.0,scsi-id=0,rid=0

This approach is invasive:
* lsi53c895a should not need to be modified with a new rid= option.
* QEMU should not know about the scsi-hd device or drive0. Only the device emulation process needs to know about scsi-hd.

In order to cleanly separate QEMU and the device emulation process syntax like this is needed:

-object remote-device,id=rid0,...
-device remote-pci-device,id=scsi0,remote-device=rid0

Quoted 9 lines

The "remote-device" object could be part of remote-pci-device, but keeping it separate may be useful in the future in order to support things like reconnection.

The generic "remote-pci-device" device handles any remote PCI device, not just the LSI SCSI controller.

Do you agree with this approach?

Quoted 7 lines

We discussed these changes and they seem to be along the lines with the future work on vfio over socket approach we will be working on later.

Could we for this experimental version have the changes you propose here with one modification - instead of having generic remote-pci-device imply that that is LSI device? And while we work towards vfio over socket this will become any remote PCI device?

Yes, that sounds good.

Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
docs/qemu-multiprocess.txt new file +7 -0
+  The drives to be emulated by the remote process are specified as part of
+  this command sub-option. The device to be used to connect to the monitor
+  is also specified as part of this suboption.
+
+  For example, the following option adds a drive and monitor to the remote
+  process:
+  -remote rid=0,exec="qemu-scsi-dev",command="-drive id=drive0,,file=data-disk.img -monitor unix:/home/qmp-sock,,server,,nowait"
Quoted 8 lines

docs/qemu-multiprocess.txt line 58

Quoted 4 lines
docs/qemu-multiprocess.txt new file +4 -0
+
+  Note: There's an issue with this "command" sub-option which we are in the
+  process of fixing. To work around this issue, it requires additional
+  "comma" characters as illustrated above, and in the example below.

command= (which could be called args= for clarity) will be difficult to use not just because of comma escaping but also because of double-quote escaping. How do you pass a command-line argument that contains spaces?

Quoted 3 lines

Yes, this is not great. And spaces are the problem at the moment. I am looking if the -object has some properties that can allow for arbitrary strings. Maybe such as data for "secret" object would do?

I'm not aware of a way to avoid the comma escaping. The space escaping is a question of how the remote process is spawned. If the command-line is processed by a shell like with system(3) then backslash can be used to escape spaces.

Stefan

#59 lore raw

Re: [PATCH v5 32/50] multi-process: Use separate MMIO communication channel

In reply to Jagannathan Raman

This went unanswered in the last revision:

Quoted 41 lines · Stefan Hajnoczi
Quoted 7 lines · Jag Raman
Quoted 5 lines · Stefan Hajnoczi
Quoted 2 lines · Jagannathan Raman

Using a separate communication channel for MMIO helps with improving Performance

Why?

Quoted 8 lines

Typical initiation of IO operations involves multiple MMIO accesses per IO operation. In some legacy devices like LSI, the completion of the IO operations is also accomplished by polling on MMIO registers. Therefore, MMIO traffic can be hefty in some cases and contribute to Performance.

Having a dedicated channel for MMIO ensures that it doesn't have to compete with other messages to the remote process, especially when there are multiple devices emulated by a single remote process.

A vCPU doing a polling read on an MMIO register will cause a BAR_READ message to be sent to the remote process. The vCPU thread waits for the response to this message.

When there are multiple remote devices each has its own socket, so communication with different remote processes does not interfere.

The only scenarios I can think of are:
1. Interference within a single device between vCPUs and/or the QEMU monitor.
2. A single process serving multiple devices that is implemented in a way such that different devices interfere with each other.

It sounds like you are saying the problem is #2, but this is still unclear to me. If the remote process can be implemented in a way such that there is no interference when each device has a special MMIO socket, then why can't it be implemented in a way such that there is no interference when each device's main socket is used (each device has it's own!).

Maybe I've missed the point. It would be good if you could explain in more detail.

Stefan

#11 lore raw

Re: [PATCH v5 07/50] multi-process: define mpqemu-link object

In reply to Jagannathan Raman
Quoted 4 lines · Jagannathan Raman

+/*
+ * TODO: Dont use mpqemu link object since it is
+ * not needed to be created via -object.
+ */

Please investigate and resolve this TODO.

include/io/mpqemu-link.h line 79

Quoted 4 lines
include/io/mpqemu-link.h new file +4 -0
+struct conf_data_msg {
+    uint32_t addr;
+    uint32_t val;
+    int l;

Please use a self-explanatory field name. I'm not sure what 'l' is.

conf_data_msg is not used in this patch. Please introduce things when they are needed to make the patch series easier to review in a linear fashion.

Quoted 4 lines

+/*
+ * TODO: make all communications asynchronous and run in the main
+ * loop or existing IOThread.
+ */

Please investigate and decide how to resolve this TODO.

Quoted 57 lines
io/mpqemu-link.c new file +57 -0
+void mpqemu_msg_send(MPQemuMsg *msg, MPQemuChannel *chan)
+{
+    int rc;
+    uint8_t *data;
+    union {
+        char control[CMSG_SPACE(REMOTE_MAX_FDS * sizeof(int))];
+        struct cmsghdr align;
+    } u;
+    struct msghdr hdr;
+    struct cmsghdr *chdr;
+    int sock = chan->sock;
+    QemuMutex *lock = &chan->send_lock;
+
+    struct iovec iov = {
+        .iov_base = (char *) msg,
+        .iov_len = MPQEMU_MSG_HDR_SIZE,
+    };
+
+    memset(&hdr, 0, sizeof(hdr));
+    memset(&u, 0, sizeof(u));
+
+    hdr.msg_iov = &iov;
+    hdr.msg_iovlen = 1;
+
+    if (msg->num_fds > REMOTE_MAX_FDS) {
+        qemu_log_mask(LOG_REMOTE_DEBUG, "%s: Max FDs exceeded\n", __func__);
+        return;
+    }
+
+    if (msg->num_fds > 0) {
+        size_t fdsize = msg->num_fds * sizeof(int);
+
+        hdr.msg_control = &u;
+        hdr.msg_controllen = sizeof(u);
+
+        chdr = CMSG_FIRSTHDR(&hdr);
+        chdr->cmsg_len = CMSG_LEN(fdsize);
+        chdr->cmsg_level = SOL_SOCKET;
+        chdr->cmsg_type = SCM_RIGHTS;
+        memcpy(CMSG_DATA(chdr), msg->fds, fdsize);
+        hdr.msg_controllen = CMSG_SPACE(fdsize);
+    }
+
+    qemu_mutex_lock(lock);
+
+    do {
+        rc = sendmsg(sock, &hdr, 0);
+    } while (rc < 0 && (errno == EINTR || errno == EAGAIN));
+
+    if (rc < 0) {
+        qemu_log_mask(LOG_REMOTE_DEBUG, "%s - sendmsg rc is %d, errno is %d,"
+                      " sock %d\n", __func__, rc, errno, sock);
+        qemu_mutex_unlock(lock);
+        return;
+    }
+
+    if (msg->bytestream) {

io/mpqemu-link.c line 129

Quoted 10 lines
io/mpqemu-link.c new file +10 -0
+        data = msg->data2;
+    } else {
+        data = (uint8_t *)msg + MPQEMU_MSG_HDR_SIZE;
+    }
+
+    do {
+        rc = write(sock, data, msg->size);
+    } while (rc < 0 && (errno == EINTR || errno == EAGAIN));
+
+    qemu_mutex_unlock(lock);

Can this lock be avoided by using a single sendmsg(2) syscall instead of sendmsg() + write()? I feel deja vu here, like I maybe have raised this in a previous revision of this patch series.

io/mpqemu-link.c line 185

Quoted 13 lines
io/mpqemu-link.c new file +13 -0
+    msg->num_fds = 0;
+    for (chdr = CMSG_FIRSTHDR(&hdr); chdr != NULL;
+         chdr = CMSG_NXTHDR(&hdr, chdr)) {
+        if ((chdr->cmsg_level == SOL_SOCKET) &&
+            (chdr->cmsg_type == SCM_RIGHTS)) {
+            fdsize = chdr->cmsg_len - CMSG_LEN(0);
+            msg->num_fds = fdsize / sizeof(int);
+            if (msg->num_fds > REMOTE_MAX_FDS) {
+                /*
+                 * TODO: Security issue detected. Sender never sends more
+                 * than REMOTE_MAX_FDS. This condition should be signaled to
+                 * the admin
+                 */

This TODO doesn't seem actionable. The error is already handled.

io/mpqemu-link.c line 188

Quoted 3 lines
io/mpqemu-link.c new file +3 -0
+                qemu_log_mask(LOG_REMOTE_DEBUG,
+                              "%s: Max FDs exceeded\n", __func__);
+                return -ERANGE;

The mutex must be released.

author
#60 lore raw

Re: [PATCH v5 32/50] multi-process: Use separate MMIO communication channel

In reply to Stefan Hajnoczi
Quoted 42 lines · Stefan Hajnoczi

This went unanswered in the last revision:

Quoted 39 lines · Stefan Hajnoczi
Quoted 7 lines · Jag Raman
Quoted 5 lines · Stefan Hajnoczi
Quoted 2 lines · Jagannathan Raman

Using a separate communication channel for MMIO helps with improving Performance

Why?

Quoted 8 lines

Typical initiation of IO operations involves multiple MMIO accesses per IO operation. In some legacy devices like LSI, the completion of the IO operations is also accomplished by polling on MMIO registers. Therefore, MMIO traffic can be hefty in some cases and contribute to Performance.

Having a dedicated channel for MMIO ensures that it doesn't have to compete with other messages to the remote process, especially when there are multiple devices emulated by a single remote process.

A vCPU doing a polling read on an MMIO register will cause a BAR_READ message to be sent to the remote process. The vCPU thread waits for the response to this message.

When there are multiple remote devices each has its own socket, so communication with different remote processes does not interfere.

The only scenarios I can think of are:
1. Interference within a single device between vCPUs and/or the QEMU monitor.
2. A single process serving multiple devices that is implemented in a way such that different devices interfere with each other.

It sounds like you are saying the problem is #2, but this is still unclear to me. If the remote process can be implemented in a way such that there is no interference when each device has a special MMIO socket, then why can't it be implemented in a way such that there is no interference when each device's main socket is used (each device has it's own!).

Maybe I've missed the point. It would be good if you could explain in more detail.

Hi Stefan,

Sorry we missed this comment. We originally added this to enable separate MMIO channels for each device in the remote process.

Given we are going to add a separate channel for each device in the remote process based on the recent discussions, we could remove the separate channel for MMIO.

Thank you very much!
--
Jag

Quoted 2 lines
Quoted 2 lines

Stefan

#12 lore raw

Re: [PATCH v5 07/50] multi-process: define mpqemu-link object

In reply to Stefan Hajnoczi
Quoted 8 lines · Stefan Hajnoczi
Quoted 4 lines · Jagannathan Raman

+/*
+ * TODO: Dont use mpqemu link object since it is
+ * not needed to be created via -object.
+ */

Please investigate and resolve this TODO.

Thank you Stefan for reviewing more patches. This particular TODO have to be removed and I am guessing followed us from the earlier code.

Quoted 10 lines

include/io/mpqemu-link.h line 79

Quoted 4 lines
include/io/mpqemu-link.h new file +4 -0
+struct conf_data_msg {
+    uint32_t addr;
+    uint32_t val;
+    int l;

Please use a self-explanatory field name. I'm not sure what 'l' is.

conf_data_msg is not used in this patch. Please introduce things when they are needed to make the patch series easier to review in a linear fashion.

Will do.

Quoted 71 lines
Quoted 5 lines

+/*
+ * TODO: make all communications asynchronous and run in the main
+ * loop or existing IOThread.
+ */

Please investigate and decide how to resolve this TODO.

Quoted 63 lines
io/mpqemu-link.c new file +63 -0
+void mpqemu_msg_send(MPQemuMsg *msg, MPQemuChannel *chan)
+{
+    int rc;
+    uint8_t *data;
+    union {
+        char control[CMSG_SPACE(REMOTE_MAX_FDS * sizeof(int))];
+        struct cmsghdr align;
+    } u;
+    struct msghdr hdr;
+    struct cmsghdr *chdr;
+    int sock = chan->sock;
+    QemuMutex *lock = &chan->send_lock;
+
+    struct iovec iov = {
+        .iov_base = (char *) msg,
+        .iov_len = MPQEMU_MSG_HDR_SIZE,
+    };
+
+    memset(&hdr, 0, sizeof(hdr));
+    memset(&u, 0, sizeof(u));
+
+    hdr.msg_iov = &iov;
+    hdr.msg_iovlen = 1;
+
+    if (msg->num_fds > REMOTE_MAX_FDS) {
+        qemu_log_mask(LOG_REMOTE_DEBUG, "%s: Max FDs exceeded\n", __func__);
+        return;
+    }
+
+    if (msg->num_fds > 0) {
+        size_t fdsize = msg->num_fds * sizeof(int);
+
+        hdr.msg_control = &u;
+        hdr.msg_controllen = sizeof(u);
+
+        chdr = CMSG_FIRSTHDR(&hdr);
+        chdr->cmsg_len = CMSG_LEN(fdsize);
+        chdr->cmsg_level = SOL_SOCKET;
+        chdr->cmsg_type = SCM_RIGHTS;
+        memcpy(CMSG_DATA(chdr), msg->fds, fdsize);
+        hdr.msg_controllen = CMSG_SPACE(fdsize);
+    }
+
+    qemu_mutex_lock(lock);
+
+    do {
+        rc = sendmsg(sock, &hdr, 0);
+    } while (rc < 0 && (errno == EINTR || errno == EAGAIN));
+
+    if (rc < 0) {
+        qemu_log_mask(LOG_REMOTE_DEBUG, "%s - sendmsg rc is %d, errno is %d,"
+                      " sock %d\n", __func__, rc, errno, sock);
+        qemu_mutex_unlock(lock);
+        return;
+    }
+
+    if (msg->bytestream) {
+        data = msg->data2;
+    } else {
+        data = (uint8_t *)msg + MPQEMU_MSG_HDR_SIZE;
+    }
+
+    do {
Quoted 9 lines

io/mpqemu-link.c line 129

Quoted 4 lines
io/mpqemu-link.c new file +4 -0
+        rc = write(sock, data, msg->size);
+    } while (rc < 0 && (errno == EINTR || errno == EAGAIN));
+
+    qemu_mutex_unlock(lock);

Can this lock be avoided by using a single sendmsg(2) syscall instead of sendmsg() + write()? I feel deja vu here, like I maybe have raised this in a previous revision of this patch series.

Indeed, you did mention this. Sorry, it got forgotten.
It seems to be possible, we will investigate further and include in the next version.

Quoted 14 lines

io/mpqemu-link.c line 185

Quoted 13 lines
io/mpqemu-link.c new file +13 -0
+    msg->num_fds = 0;
+    for (chdr = CMSG_FIRSTHDR(&hdr); chdr != NULL;
+         chdr = CMSG_NXTHDR(&hdr, chdr)) {
+        if ((chdr->cmsg_level == SOL_SOCKET) &&
+            (chdr->cmsg_type == SCM_RIGHTS)) {
+            fdsize = chdr->cmsg_len - CMSG_LEN(0);
+            msg->num_fds = fdsize / sizeof(int);
+            if (msg->num_fds > REMOTE_MAX_FDS) {
+                /*
+                 * TODO: Security issue detected. Sender never sends more
+                 * than REMOTE_MAX_FDS. This condition should be signaled to
+                 * the admin
+                 */
Quoted 7 lines

This TODO doesn't seem actionable. The error is already handled.

io/mpqemu-link.c line 188

Quoted 3 lines
io/mpqemu-link.c new file +3 -0
+                qemu_log_mask(LOG_REMOTE_DEBUG,
+                              "%s: Max FDs exceeded\n", __func__);
+                return -ERANGE;

The mutex must be released.

Thank you! Will fix this and above.

Elena

#13 lore raw

Re: [PATCH v5 07/50] multi-process: define mpqemu-link object

Quoted 18 lines · Elena Ufimtseva
Quoted 17 lines · Stefan Hajnoczi

io/mpqemu-link.c line 185

Quoted 13 lines · Jagannathan Raman
io/mpqemu-link.c new file +13 -0
+    msg->num_fds = 0;
+    for (chdr = CMSG_FIRSTHDR(&hdr); chdr != NULL;
+         chdr = CMSG_NXTHDR(&hdr, chdr)) {
+        if ((chdr->cmsg_level == SOL_SOCKET) &&
+            (chdr->cmsg_type == SCM_RIGHTS)) {
+            fdsize = chdr->cmsg_len - CMSG_LEN(0);
+            msg->num_fds = fdsize / sizeof(int);
+            if (msg->num_fds > REMOTE_MAX_FDS) {
+                /*
+                 * TODO: Security issue detected. Sender never sends more
+                 * than REMOTE_MAX_FDS. This condition should be signaled to
+                 * the admin
+                 */

This TODO doesn't seem actionable. The error is already handled.

Quoted 7 lines
Quoted 5 lines

io/mpqemu-link.c line 188

Quoted 3 lines
io/mpqemu-link.c new file +3 -0
+                qemu_log_mask(LOG_REMOTE_DEBUG,
+                              "%s: Max FDs exceeded\n", __func__);
+                return -ERANGE;

The mutex must be released.

Thank you! Will fix this and above.

I have posted a patch series that adds lock guards (automatic unlocking) to prevent cases like this in the future:
https://lists.gnu.org/archive/html/qemu-devel/2020-03/msg04628.html

You can use the QEMU_LOCK_GUARD() and/or WITH_QEMU_LOCK_GUARD() macros to avoid the need for manual qemu_mutex_unlock() calls.

Stefan

#5 lore raw

Re: [PATCH v5 02/50] multi-process: Refactor machine_init and exit notifiers

In reply to Jagannathan Raman

Hi

Quoted 2 lines · Jagannathan Raman

Relocate machine_int and exit notifiers into common code

utils/notify.c is not a good place to relocate those.

eventually, add a new softmmu/notifiers.c ?

And that patch broke make check test-char /char/mux, because it overrides machine_init_done from stubs/machine-init-done.c..

Quoted 156 lines
---
 include/sysemu/sysemu.h |  2 ++
 softmmu/vl.c            | 42 ------------------------------------------
 util/notify.c           | 43 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 42 deletions(-)
include/sysemu/sysemu.h +2 -0
index dec64fc..2f37e2b 100644
@@ -17,11 +17,13 @@ extern bool qemu_uuid_set;
 
 void qemu_add_exit_notifier(Notifier *notify);
 void qemu_remove_exit_notifier(Notifier *notify);
+void qemu_run_exit_notifiers(void);
 
 extern bool machine_init_done;
 
 void qemu_add_machine_init_done_notifier(Notifier *notify);
 void qemu_remove_machine_init_done_notifier(Notifier *notify);
+void qemu_run_machine_init_done_notifiers(void);
 
 extern int autostart;
 
softmmu/vl.c +0 -42
index 92c7b3a..94a7b93 100644
@@ -173,12 +173,6 @@ int icount_align_option;
 QemuUUID qemu_uuid;
 bool qemu_uuid_set;
 
-static NotifierList exit_notifiers =
-    NOTIFIER_LIST_INITIALIZER(exit_notifiers);
-
-static NotifierList machine_init_done_notifiers =
-    NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
-
 bool xen_allowed;
 uint32_t xen_domid;
 enum xen_mode xen_mode = XEN_EMULATE;
@@ -2324,21 +2318,6 @@ static MachineClass *machine_parse(const char *name, GSList *machines)
     return mc;
 }
 
-void qemu_add_exit_notifier(Notifier *notify)
-{
-    notifier_list_add(&exit_notifiers, notify);
-}
-
-void qemu_remove_exit_notifier(Notifier *notify)
-{
-    notifier_remove(notify);
-}
-
-static void qemu_run_exit_notifiers(void)
-{
-    notifier_list_notify(&exit_notifiers, NULL);
-}
-
 static const char *pid_file;
 static Notifier qemu_unlink_pidfile_notifier;
 
@@ -2349,27 +2328,6 @@ static void qemu_unlink_pidfile(Notifier *n, void *data)
     }
 }
 
-bool machine_init_done;
-
-void qemu_add_machine_init_done_notifier(Notifier *notify)
-{
-    notifier_list_add(&machine_init_done_notifiers, notify);
-    if (machine_init_done) {
-        notify->notify(notify, NULL);
-    }
-}
-
-void qemu_remove_machine_init_done_notifier(Notifier *notify)
-{
-    notifier_remove(notify);
-}
-
-static void qemu_run_machine_init_done_notifiers(void)
-{
-    machine_init_done = true;
-    notifier_list_notify(&machine_init_done_notifiers, NULL);
-}
-
 static const QEMUOption *lookup_opt(int argc, char **argv,
                                     const char **poptarg, int *poptind)
 {
util/notify.c +43 -1
index 76bab21..0e7479b 100644
@@ -15,6 +15,15 @@
 
 #include "qemu/osdep.h"
 #include "qemu/notify.h"
+#include "sysemu/sysemu.h"
+
+bool machine_init_done;
+
+static NotifierList machine_init_done_notifiers =
+    NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
+
+static NotifierList exit_notifiers =
+    NOTIFIER_LIST_INITIALIZER(exit_notifiers);
 
 void notifier_list_init(NotifierList *list)
 {
@@ -74,3 +83,37 @@ int notifier_with_return_list_notify(NotifierWithReturnList *list, void *data)
     }
     return ret;
 }
+
+void qemu_add_machine_init_done_notifier(Notifier *notify)
+{
+    notifier_list_add(&machine_init_done_notifiers, notify);
+    if (machine_init_done) {
+        notify->notify(notify, NULL);
+    }
+}
+
+void qemu_remove_machine_init_done_notifier(Notifier *notify)
+{
+    notifier_remove(notify);
+}
+
+void qemu_run_machine_init_done_notifiers(void)
+{
+    machine_init_done = true;
+    notifier_list_notify(&machine_init_done_notifiers, NULL);
+}
+
+void qemu_add_exit_notifier(Notifier *notify)
+{
+    notifier_list_add(&exit_notifiers, notify);
+}
+
+void qemu_remove_exit_notifier(Notifier *notify)
+{
+    notifier_remove(notify);
+}
+
+void qemu_run_exit_notifiers(void)
+{
+    notifier_list_notify(&exit_notifiers, NULL);
+}
--

1.8.3.1

Signature · 1 line
Marc-André Lureau