From: Jagannathan Raman <jag.raman@oracle.com>
To: qemu-devel@nongnu.org
Cc: elena.ufimtseva@oracle.com, fam@euphon.net,
john.g.johnson@oracle.com, kraxel@redhat.com,
jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com,
armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com,
ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com,
liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net,
kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com,
ross.lagerwall@citrix.com, marcandre.lureau@gmail.com,
pbonzini@redhat.com
Subject: [Qemu-devel] [RFC v3 PATCH 24/45] multi-process: remote: add setup_devices and setup_drive msg processing
Date: Tue, 3 Sep 2019 16:37:50 -0400 [thread overview]
Message-ID: <df6a748405162ef663cf7050661f407503177aed.1567534653.git.jag.raman@oracle.com> (raw)
In-Reply-To: <cover.1567534653.git.jag.raman@oracle.com>
In-Reply-To: <cover.1567534653.git.jag.raman@oracle.com>
From: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Receive by remote side the configuration messages and build the device
object from JSON device descriptions.
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
---
v1 -> v2:
- for new command line suboptions with libvirtd support, clean
the options before creating drives/devices
- use default pci bus/address for now
include/hw/qdev-core.h | 2 +
qdev-monitor.c | 2 +-
remote/remote-main.c | 231 +++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 234 insertions(+), 1 deletion(-)
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 136df77..2f81894 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -360,6 +360,8 @@ BusState *qdev_get_parent_bus(DeviceState *dev);
DeviceState *qdev_find_recursive(BusState *bus, const char *id);
+DeviceState *find_device_state(const char *id, Error **errp);
+
/* Returns 0 to walk children, > 0 to skip walk, < 0 to terminate walk. */
typedef int (qbus_walkerfn)(BusState *bus, void *opaque);
typedef int (qdev_walkerfn)(DeviceState *dev, void *opaque);
diff --git a/qdev-monitor.c b/qdev-monitor.c
index d6f7572..69e467e 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -1017,7 +1017,7 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp)
object_unref(OBJECT(dev));
}
-static DeviceState *find_device_state(const char *id, Error **errp)
+DeviceState *find_device_state(const char *id, Error **errp)
{
Object *obj;
diff --git a/remote/remote-main.c b/remote/remote-main.c
index 8af284e..3e92a83 100644
--- a/remote/remote-main.c
+++ b/remote/remote-main.c
@@ -48,6 +48,21 @@
#include "exec/memattrs.h"
#include "exec/address-spaces.h"
#include "remote/iohub.h"
+#include "qapi/qmp/qjson.h"
+#include "qapi/qmp/qobject.h"
+#include "qemu/option.h"
+#include "qemu/config-file.h"
+#include "monitor/qdev.h"
+#include "qapi/qmp/qdict.h"
+#include "sysemu/sysemu.h"
+#include "sysemu/blockdev.h"
+#include "block/block.h"
+#include "qapi/qmp/qstring.h"
+#include "hw/qdev-properties.h"
+#include "hw/scsi/scsi.h"
+#include "block/qdict.h"
+#include "qapi/qmp/qlist.h"
+#include "qemu/log.h"
static ProxyLinkState *proxy_link;
PCIDevice *remote_pci_dev;
@@ -138,6 +153,200 @@ fail:
PUT_REMOTE_WAIT(wait);
}
+static void process_device_add_msg(ProcMsg *msg)
+{
+ Error *local_err = NULL;
+ const char *json = (const char *)msg->data2;
+ int wait = msg->fds[0];
+ QObject *qobj = NULL;
+ QDict *qdict = NULL;
+ QemuOpts *opts = NULL;
+
+ qobj = qobject_from_json(json, &local_err);
+ if (local_err) {
+ goto fail;
+ }
+
+ qdict = qobject_to(QDict, qobj);
+ assert(qdict);
+
+ opts = qemu_opts_from_qdict(qemu_find_opts("device"), qdict, &local_err);
+ if (local_err) {
+ goto fail;
+ }
+
+ (void)qdev_device_add(opts, &local_err);
+ if (local_err) {
+ goto fail;
+ }
+
+fail:
+ if (local_err) {
+ error_report_err(local_err);
+ /* TODO: communicate the exact error message to proxy */
+ }
+
+ notify_proxy(wait, 1);
+
+ PUT_REMOTE_WAIT(wait);
+}
+
+static void process_device_del_msg(ProcMsg *msg)
+{
+ Error *local_err = NULL;
+ DeviceState *dev = NULL;
+ const char *json = (const char *)msg->data2;
+ int wait = msg->fds[0];
+ QObject *qobj = NULL;
+ QDict *qdict = NULL;
+ const char *id;
+
+ qobj = qobject_from_json(json, &local_err);
+ if (local_err) {
+ goto fail;
+ }
+
+ qdict = qobject_to(QDict, qobj);
+ assert(qdict);
+
+ id = qdict_get_try_str(qdict, "id");
+ assert(id);
+
+ dev = find_device_state(id, &local_err);
+ if (local_err) {
+ goto fail;
+ }
+
+ if (dev) {
+ qdev_unplug(dev, &local_err);
+ }
+
+fail:
+ if (local_err) {
+ error_report_err(local_err);
+ /* TODO: communicate the exact error message to proxy */
+ }
+
+ notify_proxy(wait, 1);
+
+ PUT_REMOTE_WAIT(wait);
+}
+
+static int init_drive(QDict *rqdict, Error **errp)
+{
+ QemuOpts *opts;
+ Error *local_error = NULL;
+
+ if (rqdict != NULL && qdict_size(rqdict) > 0) {
+ opts = qemu_opts_from_qdict(&qemu_drive_opts,
+ rqdict, &local_error);
+ if (!opts) {
+ error_propagate(errp, local_error);
+ return -EINVAL;
+ }
+ } else {
+ return -EINVAL;
+ }
+
+ qemu_opt_unset(opts, "rid");
+ qemu_opt_unset(opts, "socket");
+ qemu_opt_unset(opts, "remote");
+ qemu_opt_unset(opts, "command");
+
+ if (drive_new(opts, IF_IDE, &local_error) == NULL) {
+ error_propagate(errp, local_error);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int setup_drive(ProcMsg *msg, Error **errp)
+{
+ QObject *obj;
+ QDict *qdict;
+ QString *qstr;
+ Error *local_error = NULL;
+ int rc = -EINVAL;
+
+ if (!msg->data2) {
+ return rc;
+ }
+
+ qstr = qstring_from_str((char *)msg->data2);
+ obj = qobject_from_json(qstring_get_str(qstr), &local_error);
+ if (!obj) {
+ error_propagate(errp, local_error);
+ return rc;
+ }
+
+ qdict = qobject_to(QDict, obj);
+ if (!qdict) {
+ return rc;
+ }
+
+ if (init_drive(qdict, &local_error)) {
+ error_setg(errp, "init_drive failed in setup_drive.");
+ return rc;
+ }
+
+ return 0;
+}
+
+static int setup_device(ProcMsg *msg, Error **errp)
+{
+ QObject *obj;
+ QDict *qdict;
+ QString *qstr;
+ QemuOpts *opts;
+ DeviceState *dev = NULL;
+ int rc = -EINVAL;
+ Error *local_error = NULL;
+
+ if (!msg->data2) {
+ return rc;
+ }
+
+ qstr = qstring_from_str((char *)msg->data2);
+ obj = qobject_from_json(qstring_get_str(qstr), &local_error);
+ if (!obj) {
+ error_setg(errp, "Could not get object!");
+ return rc;
+ }
+
+ qdict = qobject_to(QDict, obj);
+ if (!qdict) {
+ return rc;
+ }
+
+ g_assert(qdict_size(qdict) > 1);
+
+ opts = qemu_opts_from_qdict(&qemu_device_opts, qdict, &local_error);
+ qemu_opt_unset(opts, "rid");
+ qemu_opt_unset(opts, "socket");
+ qemu_opt_unset(opts, "remote");
+ qemu_opt_unset(opts, "command");
+ /*
+ * TODO: use the bus and addr from the device options. For now
+ * we use default value.
+ */
+ qemu_opt_unset(opts, "bus");
+ qemu_opt_unset(opts, "addr");
+
+ dev = qdev_device_add(opts, &local_error);
+ if (!dev) {
+ error_setg(errp, "Could not add device %s.",
+ qstring_get_str(qobject_to_json(QOBJECT(qdict))));
+ return rc;
+ }
+ if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
+ remote_pci_dev = PCI_DEVICE(dev);
+ }
+ qemu_opts_del(opts);
+
+ return 0;
+}
+
static void process_msg(GIOCondition cond, ProcChannel *chan)
{
ProcMsg *msg = NULL;
@@ -183,11 +392,33 @@ static void process_msg(GIOCondition cond, ProcChannel *chan)
*/
remote_sysmem_reconfig(msg, &err);
if (err) {
+ error_report_err(err);
goto finalize_loop;
}
break;
case SET_IRQFD:
process_set_irqfd_msg(remote_pci_dev, msg);
+ qdev_machine_creation_done();
+ qemu_mutex_lock_iothread();
+ qemu_run_machine_init_done_notifiers();
+ qemu_mutex_unlock_iothread();
+
+ break;
+ case DRIVE_OPTS:
+ if (setup_drive(msg, &err)) {
+ error_report_err(err);
+ }
+ break;
+ case DEV_OPTS:
+ if (setup_device(msg, &err)) {
+ error_report_err(err);
+ }
+ break;
+ case DEVICE_ADD:
+ process_device_add_msg(msg);
+ break;
+ case DEVICE_DEL:
+ process_device_del_msg(msg);
break;
default:
error_setg(&err, "Unknown command");
--
1.8.3.1
next prev parent reply other threads:[~2019-09-03 20:58 UTC|newest]
Thread overview: 72+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-03 20:37 [Qemu-devel] [RFC v3 PATCH 00/45] Initial support of multi-process qemu Jagannathan Raman
2019-09-03 20:37 ` [Qemu-devel] [RFC v3 PATCH 01/45] multi-process: memory: alloc RAM from file at offset Jagannathan Raman
2019-09-04 8:11 ` Dr. David Alan Gilbert
2019-09-05 15:07 ` Jag Raman
2019-09-05 15:17 ` Dr. David Alan Gilbert
2019-09-03 20:37 ` [Qemu-devel] [RFC v3 PATCH 02/45] multi-process: util: Add qemu_thread_cancel() to cancel running thread Jagannathan Raman
2019-09-04 9:11 ` Daniel P. Berrangé
2019-09-05 15:10 ` Jag Raman
2019-09-03 20:37 ` [Qemu-devel] [RFC v3 PATCH 03/45] multi-process: add a command line option for debug file Jagannathan Raman
2019-09-03 20:37 ` [Qemu-devel] [RFC v3 PATCH 04/45] multi-process: Add stub functions to facilate build of multi-process Jagannathan Raman
2019-09-03 20:37 ` [Qemu-devel] [RFC v3 PATCH 05/45] multi-process: Add config option for multi-process QEMU Jagannathan Raman
2019-09-12 14:31 ` Stefan Hajnoczi
2019-09-03 20:37 ` [Qemu-devel] [RFC v3 PATCH 06/45] multi-process: build system for remote device process Jagannathan Raman
2019-09-03 20:37 ` [Qemu-devel] [RFC v3 PATCH 07/45] multi-process: define proxy-link object Jagannathan Raman
2019-09-04 8:22 ` Daniel P. Berrangé
2019-09-05 14:37 ` Eric Blake
2019-09-05 15:20 ` Jag Raman
2019-09-12 15:34 ` Stefan Hajnoczi
2019-10-09 13:37 ` Stefan Hajnoczi
2019-10-09 17:58 ` Elena Ufimtseva
2019-10-10 20:21 ` Jag Raman
2019-09-03 20:37 ` [Qemu-devel] [RFC v3 PATCH 08/45] multi-process: add functions to synchronize proxy and remote endpoints Jagannathan Raman
2019-09-12 15:45 ` Stefan Hajnoczi
2019-09-03 20:37 ` [Qemu-devel] [RFC v3 PATCH 09/45] multi-process: setup PCI host bridge for remote device Jagannathan Raman
2019-09-03 20:37 ` [Qemu-devel] [RFC v3 PATCH 10/45] multi-process: setup a machine object for remote device process Jagannathan Raman
2019-09-03 20:37 ` [Qemu-devel] [RFC v3 PATCH 11/45] multi-process: setup memory manager for remote device Jagannathan Raman
2019-09-03 20:37 ` [Qemu-devel] [RFC v3 PATCH 12/45] multi-process: remote process initialization Jagannathan Raman
2019-09-03 20:37 ` [Qemu-devel] [RFC v3 PATCH 13/45] multi-process: introduce proxy object Jagannathan Raman
2019-09-03 20:37 ` [Qemu-devel] [RFC v3 PATCH 14/45] mutli-process: build remote command line args Jagannathan Raman
2019-09-03 20:37 ` [Qemu-devel] [RFC v3 PATCH 15/45] multi-process: add support of device id to communication channel Jagannathan Raman
2019-09-03 20:37 ` [Qemu-devel] [RFC v3 PATCH 16/45] multi-process: PCI BAR read/write handling for proxy & remote endpoints Jagannathan Raman
2019-09-03 20:37 ` [Qemu-devel] [RFC v3 PATCH 17/45] multi-process: modify BARs read/write to support dev_id Jagannathan Raman
2019-09-03 20:37 ` [Qemu-devel] [RFC v3 PATCH 18/45] multi-process: support dev id in config read/write Jagannathan Raman
2019-09-03 20:37 ` [Qemu-devel] [RFC v3 PATCH 19/45] multi-process: Add LSI device proxy object Jagannathan Raman
2019-09-05 10:22 ` Gerd Hoffmann
2019-09-05 15:22 ` Jag Raman
2019-09-03 20:37 ` [Qemu-devel] [RFC v3 PATCH 20/45] multi-process: Synchronize remote memory Jagannathan Raman
2019-09-03 20:37 ` [Qemu-devel] [RFC v3 PATCH 21/45] multi-process: create IOHUB object to handle irq Jagannathan Raman
2019-09-03 20:37 ` [Qemu-devel] [RFC v3 PATCH 22/45] multi-process: configure remote side devices Jagannathan Raman
2019-09-03 20:37 ` [Qemu-devel] [RFC v3 PATCH 23/45] multi-process: add qdev_proxy_add to create proxy devices Jagannathan Raman
2019-09-03 20:37 ` Jagannathan Raman [this message]
2019-09-03 20:37 ` [Qemu-devel] [RFC v3 PATCH 25/45] multi-process: remote: use fd for socket from parent process Jagannathan Raman
2019-09-03 20:37 ` [Qemu-devel] [RFC v3 PATCH 26/45] multi-process: remote: add create_done condition Jagannathan Raman
2019-09-03 20:37 ` [Qemu-devel] [RFC v3 PATCH 27/45] multi-process: add processing of remote drive and device command line Jagannathan Raman
2019-09-03 20:37 ` [Qemu-devel] [RFC v3 PATCH 28/45] multi-process: Introduce build flags to separate remote process code Jagannathan Raman
2019-09-03 20:37 ` [Qemu-devel] [RFC v3 PATCH 29/45] multi-process: refractor vl.c code to re-use in remote Jagannathan Raman
2019-09-03 20:37 ` [Qemu-devel] [RFC v3 PATCH 30/45] multi-process: add remote option Jagannathan Raman
2019-09-03 20:37 ` [Qemu-devel] [RFC v3 PATCH 31/45] multi-process: add remote options parser Jagannathan Raman
2019-09-03 20:37 ` [Qemu-devel] [RFC v3 PATCH 32/45] multi-process: add parse_cmdline in remote process Jagannathan Raman
2019-09-03 20:37 ` [Qemu-devel] [RFC v3 PATCH 33/45] multi-process: add support for multiple devices Jagannathan Raman
2019-09-03 20:38 ` [Qemu-devel] [RFC v3 PATCH 34/45] multi-process: add heartbeat timer and signal handler Jagannathan Raman
2019-09-03 20:38 ` [Qemu-devel] [RFC v3 PATCH 35/45] multi-process: handle heartbeat messages in remote process Jagannathan Raman
2019-09-03 20:38 ` [Qemu-devel] [RFC v3 PATCH 36/45] multi-process: Use separate MMIO communication channel Jagannathan Raman
2019-09-03 20:38 ` [Qemu-devel] [RFC v3 PATCH 37/45] multi-process: perform device reset in the remote process Jagannathan Raman
2019-09-03 20:38 ` [Qemu-devel] [RFC v3 PATCH 38/45] multi-process/mon: stub functions to enable QMP module for " Jagannathan Raman
2019-09-03 20:38 ` [Qemu-devel] [RFC v3 PATCH 39/45] multi-process/mon: build system for QMP module in " Jagannathan Raman
2019-09-03 20:38 ` [Qemu-devel] [RFC v3 PATCH 40/45] multi-process/mon: Refactor monitor/chardev functions out of vl.c Jagannathan Raman
2019-09-04 8:37 ` Dr. David Alan Gilbert
2019-09-05 15:23 ` Jag Raman
2019-09-03 20:38 ` [Qemu-devel] [RFC v3 PATCH 41/45] multi-process/mon: trim HMP command set for remote storage processes Jagannathan Raman
2019-09-04 8:56 ` Dr. David Alan Gilbert
2019-09-05 15:54 ` Jag Raman
2019-09-05 15:57 ` Dr. David Alan Gilbert
2019-09-03 20:38 ` [Qemu-devel] [RFC v3 PATCH 42/45] multi-process/mon: Initialize QMP module for remote processes Jagannathan Raman
2019-09-03 20:38 ` [Qemu-devel] [RFC v3 PATCH 43/45] multi-process: prevent duplicate memory initialization in remote Jagannathan Raman
2019-09-03 20:38 ` [Qemu-devel] [RFC v3 PATCH 44/45] multi-process: add the concept description to docs/devel/qemu-multiprocess Jagannathan Raman
2019-09-05 10:10 ` Gerd Hoffmann
2019-09-05 10:16 ` Peter Maydell
2019-09-05 16:08 ` Elena Ufimtseva
2019-09-03 20:38 ` [Qemu-devel] [RFC v3 PATCH 45/45] multi-process: add configure and usage information Jagannathan Raman
2019-09-04 9:18 ` [Qemu-devel] [RFC v3 PATCH 00/45] Initial support of multi-process qemu Daniel P. Berrangé
2019-09-04 16:29 ` Jag Raman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=df6a748405162ef663cf7050661f407503177aed.1567534653.git.jag.raman@oracle.com \
--to=jag.raman@oracle.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=dgilbert@redhat.com \
--cc=ehabkost@redhat.com \
--cc=elena.ufimtseva@oracle.com \
--cc=fam@euphon.net \
--cc=john.g.johnson@oracle.com \
--cc=kanth.ghatraju@oracle.com \
--cc=konrad.wilk@oracle.com \
--cc=kraxel@redhat.com \
--cc=kwolf@redhat.com \
--cc=liran.alon@oracle.com \
--cc=marcandre.lureau@gmail.com \
--cc=mreitz@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=ross.lagerwall@citrix.com \
--cc=rth@twiddle.net \
--cc=stefanha@redhat.com \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).