Message ID | 20190307072212.9058-1-elena.ufimtseva@oracle.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Initial support of multi-process qemu | expand |
* elena.ufimtseva@oracle.com (elena.ufimtseva@oracle.com) wrote: > From: Jagannathan Raman <jag.raman@oracle.com> > > Add query-remote QMP command and remote-proc-list HMP command, to list > the remote processes spawned by QEMU. > > Signed-off-by: Jagannathan Raman <jag.raman@oracle.com> > Signed-off-by: John G Johnson <john.g.johnson@oracle.com> > Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com> > --- > hmp-commands.hx | 16 +++++++++ > hmp.h | 1 + > hw/proxy/Makefile.objs | 1 + > hw/proxy/monitor.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ > qapi/block-core.json | 29 ++++++++++++++++ > 5 files changed, 136 insertions(+) > create mode 100644 hw/proxy/monitor.c > > diff --git a/hmp-commands.hx b/hmp-commands.hx > index 9b40359..fb3c8ba 100644 > --- a/hmp-commands.hx > +++ b/hmp-commands.hx > @@ -725,6 +725,22 @@ STEXI > Add device. > ETEXI > > +#if defined(CONFIG_MPQEMU) > + { > + .name = "remote_proc_list", > + .args_type = "", > + .params = "", > + .help = "list remote devices and their linux process IDs", Should probably just say 'process IDs' - it's not that Linux specific. > + .cmd = hmp_remote_proc_list, > + }, > + > +STEXI > +@item remote_proc_list > +@findex remote_proc_list > +List remote devices and their linux process IDs. > +ETEXI > +#endif > + > { > .name = "device_del", > .args_type = "id:s", > diff --git a/hmp.h b/hmp.h > index e0f32f0..0940634 100644 > --- a/hmp.h > +++ b/hmp.h > @@ -149,5 +149,6 @@ void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict); > void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict); > void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict); > void hmp_info_sev(Monitor *mon, const QDict *qdict); > +void hmp_remote_proc_list(Monitor *mon, const QDict *qdict); > > #endif > diff --git a/hw/proxy/Makefile.objs b/hw/proxy/Makefile.objs > index f562f5a..e642060 100644 > --- a/hw/proxy/Makefile.objs > +++ b/hw/proxy/Makefile.objs > @@ -1,2 +1,3 @@ > common-obj-$(CONFIG_MPQEMU) += qemu-proxy.o > common-obj-$(CONFIG_MPQEMU) += proxy-lsi53c895a.o > +common-obj-$(CONFIG_MPQEMU) += monitor.o > diff --git a/hw/proxy/monitor.c b/hw/proxy/monitor.c > new file mode 100644 > index 0000000..3005eec > --- /dev/null > +++ b/hw/proxy/monitor.c > @@ -0,0 +1,89 @@ > +/* > + * QEMU monitor command handler for multi-process QEMU > + * > + * Copyright 2019, Oracle and/or its affiliates. All rights reserved. > + * > + * Permission is hereby granted, free of charge, to any person obtaining a copy > + * of this software and associated documentation files (the "Software"), to deal > + * in the Software without restriction, including without limitation the rights > + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell > + * copies of the Software, and to permit persons to whom the Software is > + * furnished to do so, subject to the following conditions: > + * > + * The above copyright notice and this permission notice shall be included in > + * all copies or substantial portions of the Software. > + * > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL > + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER > + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, > + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN > + * THE SOFTWARE. > + */ > + > +#include <sys/types.h> > + > +#include "qemu/osdep.h" > +#include "qapi/qapi-types-block-core.h" > +#include "qapi/qapi-commands-block-core.h" > +#include "monitor/monitor.h" > +#include "qemu/option.h" > +#include "hmp.h" > +#include "hw/boards.h" > +#include "hw/i386/pc.h" > +#include "hw/proxy/qemu-proxy.h" > + > +/* > + * TODO: Is there a callback where the allocated memory for QMP could be free'd I think qmp will clean that up when it returns your list that you create (by making calls to qapi_free_RemoteProc or qapi_free_RemoteProcList as appropriate.) > + */ > +RemoteProcList *qmp_query_remote(Error **errp) > +{ > + PCMachineState *pcms = PC_MACHINE(current_machine); > + RemoteProcList *proclist, *proc; > + GHashTableIter itr; > + PCIProxyDev *pdev; > + PCIProxyDevClass *k; > + DeviceState *d; > + char *id; > + > + proclist = NULL; > + > + g_hash_table_iter_init(&itr, pcms->remote_devs); > + > + while (g_hash_table_iter_next(&itr, (gpointer *)&id, (gpointer *)&pdev)) { > + k = PCI_PROXY_DEV_GET_CLASS(pdev); > + d = DEVICE(pdev); > + > + proc = g_malloc0(sizeof(RemoteProcList)); > + proc->next = proclist; > + proclist = proc; > + proc->value = g_malloc0(sizeof(RemoteProc)); > + proc->value->pid = pdev->remote_pid; > + proc->value->id = g_strdup(d->id); > + proc->value->proc = g_strdup(k->command); > + } > + > + return proclist; > +} > + > +void hmp_remote_proc_list(Monitor *mon, const QDict *qdict) > +{ > + PCMachineState *pcms = PC_MACHINE(current_machine); > + GHashTableIter itr; > + PCIProxyDev *pdev; > + PCIProxyDevClass *k; > + char *id; > + > + g_hash_table_iter_init(&itr, pcms->remote_devs); > + > + monitor_printf(mon, "%8.8s\t%16.16s\t%16.16s\t%16.16s\n\n", "PID", "RID", > + "QEMU ID", "PROCESS NAME"); > + > + while (g_hash_table_iter_next(&itr, (gpointer *)&id, (gpointer *)&pdev)) { > + k = PCI_PROXY_DEV_GET_CLASS(pdev); > + > + monitor_printf(mon, "%8.8d\t%16.16s\t%16.16s\t%16.16s\n", > + pdev->remote_pid, pdev->rid, id, k->command); I don't think I understand what a RID is here. A more common way to write HMP commands is to call the qmp command and format it's output; having said that your code here is probably simpler. > + } > +} > diff --git a/qapi/block-core.json b/qapi/block-core.json > index 2b8afbb..05394c4 100644 > --- a/qapi/block-core.json > +++ b/qapi/block-core.json > @@ -647,6 +647,23 @@ > '*dirty-bitmaps': ['BlockDirtyInfo'] } } > > ## > +# @RemoteProc: > +# > +# Remote process information. > +# > +# @id: Device ID > +# > +# @pid: Linux Process ID > +# > +# @proc: Process name > +# > +# Since: 3.0.93 Note 'Since:' should be the version it gets merged into so it'll be 4.1 or 5.0 etc > +## > +{ 'struct': 'RemoteProc', > + 'data': {'id': 'str', 'pid': 'int32', 'proc': 'str' }, > + 'if': 'defined(CONFIG_MPQEMU)' } > + > +## > # @BlockMeasureInfo: > # > # Image file size calculation information. This structure describes the size > @@ -768,6 +785,18 @@ > ## > { 'command': 'query-block', 'returns': ['BlockInfo'] } > > +## > +# @query-remote: > +# > +# Get a list of all the remote processes spawned by QEMU. > +# > +# Returns: a list of @RemoteProc describing each remote process. > +# > +# Since: 3.0.93 > +# > +## > +{ 'command': 'query-remote', 'returns': ['RemoteProc'], > + 'if': 'defined(CONFIG_MPQEMU)' } > > ## > # @BlockDeviceTimedStats: > -- > 1.8.3.1 > -- Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
diff --git a/hmp-commands.hx b/hmp-commands.hx index 9b40359..fb3c8ba 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -725,6 +725,22 @@ STEXI Add device. ETEXI +#if defined(CONFIG_MPQEMU) + { + .name = "remote_proc_list", + .args_type = "", + .params = "", + .help = "list remote devices and their linux process IDs", + .cmd = hmp_remote_proc_list, + }, + +STEXI +@item remote_proc_list +@findex remote_proc_list +List remote devices and their linux process IDs. +ETEXI +#endif + { .name = "device_del", .args_type = "id:s", diff --git a/hmp.h b/hmp.h index e0f32f0..0940634 100644 --- a/hmp.h +++ b/hmp.h @@ -149,5 +149,6 @@ void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict); void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict); void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict); void hmp_info_sev(Monitor *mon, const QDict *qdict); +void hmp_remote_proc_list(Monitor *mon, const QDict *qdict); #endif diff --git a/hw/proxy/Makefile.objs b/hw/proxy/Makefile.objs index f562f5a..e642060 100644 --- a/hw/proxy/Makefile.objs +++ b/hw/proxy/Makefile.objs @@ -1,2 +1,3 @@ common-obj-$(CONFIG_MPQEMU) += qemu-proxy.o common-obj-$(CONFIG_MPQEMU) += proxy-lsi53c895a.o +common-obj-$(CONFIG_MPQEMU) += monitor.o diff --git a/hw/proxy/monitor.c b/hw/proxy/monitor.c new file mode 100644 index 0000000..3005eec --- /dev/null +++ b/hw/proxy/monitor.c @@ -0,0 +1,89 @@ +/* + * QEMU monitor command handler for multi-process QEMU + * + * Copyright 2019, Oracle and/or its affiliates. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include <sys/types.h> + +#include "qemu/osdep.h" +#include "qapi/qapi-types-block-core.h" +#include "qapi/qapi-commands-block-core.h" +#include "monitor/monitor.h" +#include "qemu/option.h" +#include "hmp.h" +#include "hw/boards.h" +#include "hw/i386/pc.h" +#include "hw/proxy/qemu-proxy.h" + +/* + * TODO: Is there a callback where the allocated memory for QMP could be free'd + */ +RemoteProcList *qmp_query_remote(Error **errp) +{ + PCMachineState *pcms = PC_MACHINE(current_machine); + RemoteProcList *proclist, *proc; + GHashTableIter itr; + PCIProxyDev *pdev; + PCIProxyDevClass *k; + DeviceState *d; + char *id; + + proclist = NULL; + + g_hash_table_iter_init(&itr, pcms->remote_devs); + + while (g_hash_table_iter_next(&itr, (gpointer *)&id, (gpointer *)&pdev)) { + k = PCI_PROXY_DEV_GET_CLASS(pdev); + d = DEVICE(pdev); + + proc = g_malloc0(sizeof(RemoteProcList)); + proc->next = proclist; + proclist = proc; + proc->value = g_malloc0(sizeof(RemoteProc)); + proc->value->pid = pdev->remote_pid; + proc->value->id = g_strdup(d->id); + proc->value->proc = g_strdup(k->command); + } + + return proclist; +} + +void hmp_remote_proc_list(Monitor *mon, const QDict *qdict) +{ + PCMachineState *pcms = PC_MACHINE(current_machine); + GHashTableIter itr; + PCIProxyDev *pdev; + PCIProxyDevClass *k; + char *id; + + g_hash_table_iter_init(&itr, pcms->remote_devs); + + monitor_printf(mon, "%8.8s\t%16.16s\t%16.16s\t%16.16s\n\n", "PID", "RID", + "QEMU ID", "PROCESS NAME"); + + while (g_hash_table_iter_next(&itr, (gpointer *)&id, (gpointer *)&pdev)) { + k = PCI_PROXY_DEV_GET_CLASS(pdev); + + monitor_printf(mon, "%8.8d\t%16.16s\t%16.16s\t%16.16s\n", + pdev->remote_pid, pdev->rid, id, k->command); + } +} diff --git a/qapi/block-core.json b/qapi/block-core.json index 2b8afbb..05394c4 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -647,6 +647,23 @@ '*dirty-bitmaps': ['BlockDirtyInfo'] } } ## +# @RemoteProc: +# +# Remote process information. +# +# @id: Device ID +# +# @pid: Linux Process ID +# +# @proc: Process name +# +# Since: 3.0.93 +## +{ 'struct': 'RemoteProc', + 'data': {'id': 'str', 'pid': 'int32', 'proc': 'str' }, + 'if': 'defined(CONFIG_MPQEMU)' } + +## # @BlockMeasureInfo: # # Image file size calculation information. This structure describes the size @@ -768,6 +785,18 @@ ## { 'command': 'query-block', 'returns': ['BlockInfo'] } +## +# @query-remote: +# +# Get a list of all the remote processes spawned by QEMU. +# +# Returns: a list of @RemoteProc describing each remote process. +# +# Since: 3.0.93 +# +## +{ 'command': 'query-remote', 'returns': ['RemoteProc'], + 'if': 'defined(CONFIG_MPQEMU)' } ## # @BlockDeviceTimedStats: