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 14/45] mutli-process: build remote command line args
Date: Tue, 3 Sep 2019 16:37:40 -0400 [thread overview]
Message-ID: <b299af7f81ff976a7f9facd8758231b17691e7ec.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>
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>
---
New patch in v3
hw/proxy/qemu-proxy.c | 80 +++++++++++++++++++++++++++++++++----------
include/hw/proxy/qemu-proxy.h | 2 +-
2 files changed, 62 insertions(+), 20 deletions(-)
diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
index 0ec7bb6..e5fd4bb 100644
--- a/hw/proxy/qemu-proxy.c
+++ b/hw/proxy/qemu-proxy.c
@@ -45,47 +45,89 @@
static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp);
+static int add_argv(char *command_str, char **argv, int argc)
+{
+ int max_args = 64;
+
+ if (argc < max_args - 1) {
+ argv[argc++] = command_str;
+ argv[argc] = 0;
+ } else {
+ return 0;
+ }
+
+ return argc;
+}
+
+static int make_argv(char *command_str, char **argv, int argc)
+{
+ int max_args = 64;
+
+ char *p2 = strtok(command_str, " ");
+ while (p2 && argc < max_args - 1) {
+ argv[argc++] = p2;
+ p2 = strtok(0, " ");
+ }
+ argv[argc] = 0;
+
+ return argc;
+}
+
int remote_spawn(PCIProxyDev *pdev, const char *command, Error **errp)
{
- char *args[3];
pid_t rpid;
int fd[2] = {-1, -1};
Error *local_error = NULL;
+ char *argv[64];
+ int argc = 0, _argc;
+ char *sfd;
+ char *exec_dir;
+ int rc = -EINVAL;
if (pdev->managed) {
/* Child is forked by external program (such as libvirt). */
- return -1;
+ return rc;
}
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) {
error_setg(errp, "Unable to create unix socket.");
- return -1;
+ return rc;
}
+ exec_dir = g_strdup_printf("%s/%s", qemu_get_exec_dir(), "qemu-scsi-dev");
+ argc = add_argv(exec_dir, argv, argc);
+ sfd = g_strdup_printf("%d", fd[1]);
+ argc = add_argv(sfd, argv, argc);
+ _argc = argc;
+ argc = make_argv((char *)command, argv, argc);
+
/* TODO: Restrict the forked process' permissions and capabilities. */
rpid = qemu_fork(&local_error);
if (rpid == -1) {
error_setg(errp, "Unable to spawn emulation program.");
close(fd[0]);
- close(fd[1]);
- return -1;
+ goto fail;
}
if (rpid == 0) {
close(fd[0]);
-
- args[0] = g_strdup(command);
- args[1] = g_strdup_printf("%d", fd[1]);
- args[2] = NULL;
- execvp(args[0], (char *const *)args);
+ execvp(argv[0], (char *const *)argv);
exit(1);
}
pdev->remote_pid = rpid;
- pdev->rsocket = fd[0];
+ pdev->rsocket = fd[1];
+ pdev->socket = fd[0];
+ rc = 0;
+
+fail:
close(fd[1]);
- return 0;
+ for (int i = 0; i < _argc; i++) {
+ g_free(argv[i]);
+ }
+
+ return rc;
}
static int get_proxy_sock(PCIDevice *dev)
@@ -94,7 +136,7 @@ static int get_proxy_sock(PCIDevice *dev)
pdev = PCI_PROXY_DEV(dev);
- return pdev->rsocket;
+ return pdev->socket;
}
static void set_proxy_sock(PCIDevice *dev, int socket)
@@ -103,7 +145,7 @@ static void set_proxy_sock(PCIDevice *dev, int socket)
pdev = PCI_PROXY_DEV(dev);
- pdev->rsocket = socket;
+ pdev->socket = socket;
pdev->managed = true;
}
@@ -198,16 +240,16 @@ static void pci_proxy_dev_register_types(void)
type_init(pci_proxy_dev_register_types)
-static void init_proxy(PCIDevice *dev, char *command, Error **errp)
+static void init_proxy(PCIDevice *dev, char *command, bool need_spawn, Error **errp)
{
PCIProxyDev *pdev = PCI_PROXY_DEV(dev);
Error *local_error = NULL;
if (!pdev->managed) {
- if (command) {
- remote_spawn(pdev, command, &local_error);
- } else {
- return;
+ if (need_spawn) {
+ if (!remote_spawn(pdev, command, &local_error)) {
+ return;
+ }
}
} else {
pdev->remote_pid = atoi(pdev->rid);
diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h
index ee21818..3b37b65 100644
--- a/include/hw/proxy/qemu-proxy.h
+++ b/include/hw/proxy/qemu-proxy.h
@@ -63,7 +63,7 @@ typedef struct PCIProxyDev {
void (*set_remote_opts) (PCIDevice *dev, QDict *qdict, unsigned int cmd);
void (*proxy_ready) (PCIDevice *dev);
- void (*init_proxy) (PCIDevice *pdev, char *command, Error **errp);
+ void (*init_proxy) (PCIDevice *dev, char *command, bool need_spawn, Error **errp);
} PCIProxyDev;
--
1.8.3.1
next prev parent reply other threads:[~2019-09-03 20:50 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 ` Jagannathan Raman [this message]
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 ` [Qemu-devel] [RFC v3 PATCH 24/45] multi-process: remote: add setup_devices and setup_drive msg processing Jagannathan Raman
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=b299af7f81ff976a7f9facd8758231b17691e7ec.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).