* [Qemu-devel] [RFC PATCH v2 24/35] multi-process: add qdev_proxy_add to create proxy devices
@ 2019-06-17 18:16 elena.ufimtseva
2019-06-17 19:22 ` Eric Blake
0 siblings, 1 reply; 3+ messages in thread
From: elena.ufimtseva @ 2019-06-17 18:16 UTC (permalink / raw)
To: qemu-devel
Cc: elena.ufimtseva, john.g.johnson, jag.raman, konrad.wilk,
ross.lagerwall, imammedo, liran.alon, stefanha, marcandre.lureau,
kanth.ghatraju
From: Elena Ufimtseva <elena.ufimtseva@oracle.com>
This is handled while parsing the command line options.
The parsed options are being sent to remote process
as the messgaes containing JSON strings.
Changes in v2:
- parse socket and command suboptions of drive/device commands;
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>
---
include/hw/proxy/qemu-proxy.h | 7 ++
include/monitor/qdev.h | 5 +
qdev-monitor.c | 166 ++++++++++++++++++++++++++++++++++
3 files changed, 178 insertions(+)
diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h
index 4e949f778b..a4c6989248 100644
--- a/include/hw/proxy/qemu-proxy.h
+++ b/include/hw/proxy/qemu-proxy.h
@@ -85,6 +85,13 @@ typedef struct PCIProxyDevClass {
int remote_spawn(PCIProxyDev *pdev, const char *command, Error **errp);
+typedef struct PCIProxyDevList {
+ QLIST_HEAD(, PCIProxyDev) devices;
+} proxy_dev_list_t;
+
+extern QemuMutex proxy_list_lock;
+extern proxy_dev_list_t proxy_dev_list;
+
void proxy_default_bar_write(PCIProxyDev *dev, MemoryRegion *mr, hwaddr addr,
uint64_t val, unsigned size, bool memory);
diff --git a/include/monitor/qdev.h b/include/monitor/qdev.h
index c7642f7c2d..965c58d127 100644
--- a/include/monitor/qdev.h
+++ b/include/monitor/qdev.h
@@ -2,6 +2,7 @@
#define MONITOR_QDEV_H
#include "hw/qdev-core.h"
+#include "hw/proxy/qemu-proxy.h"
/*** monitor commands ***/
@@ -12,8 +13,12 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp);
void qmp_rdevice_add(QDict *qdict, QObject **ret_data, Error **errp);
void qmp_rdevice_del(const char *id, Error **errp);
+DeviceState *qdev_remote_add(QemuOpts *opts, bool device, Error **errp);
+void qdev_proxy_fire(void);
int qdev_device_help(QemuOpts *opts);
+DeviceState *qdev_proxy_add(const char *rid, const char *id, char *command,
+ int rsocket, bool managed, Error **errp);
DeviceState *qdev_device_add(QemuOpts *opts, Error **errp);
void qdev_set_id(DeviceState *dev, const char *id);
diff --git a/qdev-monitor.c b/qdev-monitor.c
index 744c807b0f..596d01f49a 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -35,6 +35,16 @@
#include "sysemu/block-backend.h"
#include "migration/misc.h"
#include "hw/boards.h"
+#include "hw/proxy/qemu-proxy.h"
+#include "qapi/qmp/qjson.h"
+#include "qapi/qmp/qstring.h"
+#include "sysemu/sysemu.h"
+#include "hw/proxy/proxy-lsi53c895a.h"
+#include "include/qemu/cutils.h"
+#include "include/qemu/log.h"
+#include "qapi/qmp/qlist.h"
+#include "hw/proxy/qemu-proxy.h"
+#include "io/proxy-link.h"
/*
* Aliases were a bad idea from the start. Let's keep them
@@ -47,6 +57,8 @@ typedef struct QDevAlias
uint32_t arch_mask;
} QDevAlias;
+proxy_dev_list_t proxy_dev_list;
+QemuMutex proxy_list_lock;
/* Please keep this table sorted by typename. */
static const QDevAlias qdev_alias_table[] = {
{ "e1000", "e1000-82540em" },
@@ -562,6 +574,160 @@ void qdev_set_id(DeviceState *dev, const char *id)
}
}
+#if defined(CONFIG_MPQEMU)
+PCIProxyDev *get_proxy_object(const char *rid);
+PCIProxyDev *get_proxy_object(const char *rid)
+{
+ PCIProxyDev *entry;
+
+ qemu_mutex_lock(&proxy_list_lock);
+ QLIST_FOREACH(entry, &proxy_dev_list.devices, next) {
+ if (strncmp(entry->rid, rid, strlen(entry->rid)) == 0) {
+ qemu_mutex_unlock(&proxy_list_lock);
+ return entry;
+ }
+ }
+ qemu_mutex_unlock(&proxy_list_lock);
+ return NULL;
+
+}
+
+#define MAX_RID_LENGTH 10
+void qdev_proxy_fire(void)
+{
+ PCIProxyDev *entry;
+
+ QLIST_FOREACH(entry, &proxy_dev_list.devices, next) {
+ if (entry->proxy_ready) {
+ entry->proxy_ready(PCI_DEVICE(entry));
+ }
+ }
+}
+
+DeviceState *qdev_proxy_add(const char *rid, const char *id, char *command,
+ int rsocket, bool managed, Error **errp)
+{
+ DeviceState *ds;
+ PCIProxyDev *pdev;
+ QemuOpts *proxy_opts;
+ const char *proxy_type;
+ Error *local_err = NULL;
+ QDict *qdict;
+ const char *str;
+
+ pdev = get_proxy_object(rid);
+ if (pdev) {
+ return DEVICE(pdev);
+ }
+
+ if (strlen(rid) > MAX_RID_LENGTH) {
+ error_setg(errp, "rid %s is too long.", rid);
+ return NULL;
+ }
+
+ proxy_opts = qemu_opts_create(&qemu_device_opts, NULL, 0,
+ errp);
+
+ /* TODO: remove hardcoded type and add approptiate type identification. */
+ proxy_type = TYPE_PROXY_LSI53C895A;
+
+ qemu_opts_set_id(proxy_opts, (char *)rid);
+ qemu_opt_set(proxy_opts, "driver", proxy_type, &local_err);
+
+ qdict = qemu_opts_to_qdict(proxy_opts, NULL);
+ str = qstring_get_str(qobject_to_json(QOBJECT(qdict)));
+
+ ds = qdev_device_add(proxy_opts, &local_err);
+ if (!ds) {
+ error_setg(errp, "Could not create proxy device"
+ " with opts %s.", str);
+ qemu_opts_del(proxy_opts);
+ return NULL;
+ }
+ qdev_set_id(ds, qemu_opts_id(proxy_opts));
+
+ pdev = PCI_PROXY_DEV(ds);
+ if (!pdev) {
+ error_setg(errp, "qdev_device_add failed.");
+ qemu_opts_del(proxy_opts);
+ return NULL;
+ }
+ pdev->rid = g_strdup(rid);
+ pdev->rsocket = managed ? rsocket : -1;
+ pdev->managed = managed;
+ pdev->init_proxy(PCI_DEVICE(ds), command, errp);
+
+ qemu_mutex_lock(&proxy_list_lock);
+ QLIST_INSERT_HEAD(&proxy_dev_list.devices, pdev, next);
+ qemu_mutex_unlock(&proxy_list_lock);
+
+ qemu_opts_del(proxy_opts);
+ return ds;
+}
+
+DeviceState *qdev_remote_add(QemuOpts *opts, bool device, Error **errp)
+{
+ PCIProxyDev *pdev = NULL;
+ DeviceState *dev;
+ const char *rid, *rsocket = NULL, *command = NULL;
+ QDict *qdict_new;
+
+ if (!proxy_list_lock.initialized) {
+ QLIST_INIT(&proxy_dev_list.devices);
+ qemu_mutex_init(&proxy_list_lock);
+ }
+
+ rid = qemu_opt_get(opts, "rid");
+ if (!rid) {
+ error_setg(errp, "rdevice option needs rid specified.");
+ return NULL;
+ }
+
+ rsocket = qemu_opt_get(opts, "socket");
+ if (rsocket) {
+ if (strlen(rsocket) > MAX_RID_LENGTH) {
+ error_setg(errp, "Socket number is incorrect.");
+ return NULL;
+ }
+ }
+
+ /*
+ * TODO: verify command with known commands and on remote end.
+ * How else can we verify the binary we launch without libvirtd support?
+ */
+ command = qemu_opt_get(opts, "command");
+ if (!rsocket && !command) {
+ error_setg(errp, "rdevice option needs socket or command specified.");
+ return NULL;
+ }
+ dev = qdev_proxy_add(rid, qemu_opt_get(opts, "id"), (char *)command,
+ rsocket ? atoi(rsocket) : -1, rsocket ? true : false, errp);
+ if (!dev) {
+ error_setg(errp, "qdev_proxy_add error.");
+ return NULL;
+ }
+
+ qdict_new = qemu_opts_to_qdict(opts, NULL);
+
+ if (!qdict_new) {
+ error_setg(errp, "Could not parse rdevice options.");
+ return NULL;
+ }
+
+ pdev = PCI_PROXY_DEV(dev);
+ if (!pdev->set_remote_opts) {
+ /* TODO: destroy proxy? */
+ error_setg(errp, "set_remote_opts not set.");
+ return NULL;
+ } else {
+ pdev->set_remote_opts(PCI_DEVICE(pdev), qdict_new,
+ device ? DEV_OPTS : DRIVE_OPTS);
+ }
+
+ return dev;
+}
+#endif /*defined(CONFIG_MPQEMU)*/
+
DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
{
DeviceClass *dc;
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [RFC PATCH v2 24/35] multi-process: add qdev_proxy_add to create proxy devices
2019-06-17 18:16 [Qemu-devel] [RFC PATCH v2 24/35] multi-process: add qdev_proxy_add to create proxy devices elena.ufimtseva
@ 2019-06-17 19:22 ` Eric Blake
2019-06-17 19:47 ` Elena Ufimtseva
0 siblings, 1 reply; 3+ messages in thread
From: Eric Blake @ 2019-06-17 19:22 UTC (permalink / raw)
To: elena.ufimtseva, qemu-devel
Cc: john.g.johnson, jag.raman, konrad.wilk, ross.lagerwall,
liran.alon, stefanha, marcandre.lureau, imammedo, kanth.ghatraju
[-- Attachment #1.1: Type: text/plain, Size: 1228 bytes --]
On 6/17/19 1:16 PM, elena.ufimtseva@oracle.com wrote:
> From: Elena Ufimtseva <elena.ufimtseva@oracle.com>
>
> This is handled while parsing the command line options.
> The parsed options are being sent to remote process
> as the messgaes containing JSON strings.
s/messgaes/messages/
>
> Changes in v2:
> - parse socket and command suboptions of drive/device commands;
The changelog paragraph belongs...
>
> 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>
> ---
...here, after the --- divider. It is useful to reviewers, but gets
stripped by 'git am' when the maintainer applies the series. A year from
now, we won't care how many iterations the patches went through on list,
only the one version that got committed to git.
> include/hw/proxy/qemu-proxy.h | 7 ++
> include/monitor/qdev.h | 5 +
> qdev-monitor.c | 166 ++++++++++++++++++++++++++++++++++
> 3 files changed, 178 insertions(+)
>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [RFC PATCH v2 24/35] multi-process: add qdev_proxy_add to create proxy devices
2019-06-17 19:22 ` Eric Blake
@ 2019-06-17 19:47 ` Elena Ufimtseva
0 siblings, 0 replies; 3+ messages in thread
From: Elena Ufimtseva @ 2019-06-17 19:47 UTC (permalink / raw)
To: Eric Blake
Cc: john.g.johnson, jag.raman, konrad.wilk, qemu-devel,
ross.lagerwall, liran.alon, stefanha, marcandre.lureau, imammedo,
kanth.ghatraju
On Mon, Jun 17, 2019 at 02:22:08PM -0500, Eric Blake wrote:
> On 6/17/19 1:16 PM, elena.ufimtseva@oracle.com wrote:
> > From: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> >
> > This is handled while parsing the command line options.
> > The parsed options are being sent to remote process
> > as the messgaes containing JSON strings.
>
> s/messgaes/messages/
>
> >
> > Changes in v2:
> > - parse socket and command suboptions of drive/device commands;
>
> The changelog paragraph belongs...
>
> >
> > 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>
> > ---
>
> ...here, after the --- divider. It is useful to reviewers, but gets
> stripped by 'git am' when the maintainer applies the series. A year from
> now, we won't care how many iterations the patches went through on list,
> only the one version that got committed to git.
>
That one slipped trough with this, will fix.
> > include/hw/proxy/qemu-proxy.h | 7 ++
> > include/monitor/qdev.h | 5 +
> > qdev-monitor.c | 166 ++++++++++++++++++++++++++++++++++
> > 3 files changed, 178 insertions(+)
> >
>
>
> --
> Eric Blake, Principal Software Engineer
> Red Hat, Inc. +1-919-301-3226
> Virtualization: qemu.org | libvirt.org
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-06-17 19:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-17 18:16 [Qemu-devel] [RFC PATCH v2 24/35] multi-process: add qdev_proxy_add to create proxy devices elena.ufimtseva
2019-06-17 19:22 ` Eric Blake
2019-06-17 19:47 ` Elena Ufimtseva
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).