[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC v4 PATCH 14/49] mutli-process: build remote command line args
From: |
Jagannathan Raman |
Subject: |
[RFC v4 PATCH 14/49] mutli-process: build remote command line args |
Date: |
Thu, 24 Oct 2019 05:08:55 -0400 |
From: Elena Ufimtseva <address@hidden>
Signed-off-by: Elena Ufimtseva <address@hidden>
Signed-off-by: Jagannathan Raman <address@hidden>
Signed-off-by: John G Johnson <address@hidden>
---
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 baba4da..ca7dd1a 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 3648a77..f97b103 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
- [RFC v4 PATCH 03/49] multi-process: add a command line option for debug file, (continued)
- [RFC v4 PATCH 03/49] multi-process: add a command line option for debug file, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 01/49] multi-process: memory: alloc RAM from file at offset, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 02/49] multi-process: util: Add qemu_thread_cancel() to cancel running thread, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 04/49] multi-process: Add stub functions to facilate build of multi-process, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 05/49] multi-process: Add config option for multi-process QEMU, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 06/49] multi-process: build system for remote device process, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 09/49] multi-process: setup PCI host bridge for remote device, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 11/49] multi-process: setup memory manager for remote device, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 10/49] multi-process: setup a machine object for remote device process, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 13/49] multi-process: introduce proxy object, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 14/49] mutli-process: build remote command line args,
Jagannathan Raman <=
- [RFC v4 PATCH 16/49] multi-process: Add LSI device proxy object, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 15/49] multi-process: PCI BAR read/write handling for proxy & remote endpoints, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 19/49] multi-process: configure remote side devices, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 18/49] multi-process: create IOHUB object to handle irq, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 20/49] multi-process: add qdev_proxy_add to create proxy devices, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 21/49] multi-process: remote: add setup_devices and setup_drive msg processing, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 22/49] multi-process: remote: use fd for socket from parent process, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 23/49] multi-process: remote: add create_done condition, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 24/49] multi-process: add processing of remote drive and device command line, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 26/49] multi-process: refractor vl.c code to re-use in remote, Jagannathan Raman, 2019/10/24