[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v5 14/50] mutli-process: build remote command line args
From: |
Jagannathan Raman |
Subject: |
[PATCH v5 14/50] mutli-process: build remote command line args |
Date: |
Mon, 24 Feb 2020 15:55:05 -0500 |
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>
---
v4 -> v5:
- Added "exec" suboption to get the executable's name
- Addressed feedback about variable names
- Removed redundant check for spawning a process
hw/proxy/qemu-proxy.c | 68 +++++++++++++++++++++++++++++++++----------
include/hw/proxy/qemu-proxy.h | 2 +-
2 files changed, 54 insertions(+), 16 deletions(-)
diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
index 828bbd7..d792e86 100644
--- a/hw/proxy/qemu-proxy.c
+++ b/hw/proxy/qemu-proxy.c
@@ -19,19 +19,50 @@
static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp);
+static int add_argv(char *opts_str, char **argv, int argc)
+{
+ int max_args = 64;
+
+ if (argc < max_args - 1) {
+ argv[argc++] = opts_str;
+ argv[argc] = 0;
+ } else {
+ return 0;
+ }
+
+ return argc;
+}
+
+static int make_argv(char *opts_str, char **argv, int argc)
+{
+ int max_args = 64;
+
+ char *p2 = strtok(opts_str, " ");
+ while (p2 && argc < max_args - 1) {
+ argv[argc++] = p2;
+ p2 = strtok(0, " ");
+ }
+ argv[argc] = 0;
+
+ return argc;
+}
+
static int remote_spawn(PCIProxyDev *pdev, const char *opts,
const char *exec_name, Error **errp)
{
- char *args[3];
pid_t rpid;
int fd[2] = {-1, -1};
Error *local_error = NULL;
+ char *argv[64];
+ int argc = 0;
+ char *sfd;
+ char *exec_dir;
int rc = -EINVAL;
if (pdev->managed) {
/* Child is forked by external program (such as libvirt). */
error_setg(errp, "Remote processed is managed and launched by external
program");
- return -1;
+ return rc;
}
if (!exec_name) {
@@ -41,32 +72,38 @@ static int remote_spawn(PCIProxyDev *pdev, const char *opts,
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(), exec_name);
+ argc = add_argv(exec_dir, argv, argc);
+ sfd = g_strdup_printf("%d", fd[1]);
+ argc = add_argv(sfd, argv, argc);
+ argc = make_argv((char *)opts, 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(exec_name);
- args[1] = g_strdup_printf("%d", fd[1]);
- args[2] = NULL;
- execvp(args[0], (char *const *)args);
+ rc = execv(argv[0], (char *const *)argv);
exit(1);
}
pdev->remote_pid = rpid;
+ pdev->socket = fd[0];
+
+ rc = 0;
+fail:
close(fd[1]);
- return 0;
+ return rc;
}
static int get_proxy_sock(PCIDevice *dev)
@@ -177,16 +214,17 @@ static void pci_proxy_dev_register_types(void)
type_init(pci_proxy_dev_register_types)
static void init_proxy(PCIDevice *dev, char *command, char *exec_name,
- Error **errp)
+ bool need_spawn, Error **errp)
{
PCIProxyDev *pdev = PCI_PROXY_DEV(dev);
Error *local_error = NULL;
if (!pdev->managed) {
- if (command) {
- remote_spawn(pdev, command, exec_name, &local_error);
- } else {
- return;
+ if (need_spawn) {
+ if (remote_spawn(pdev, command, exec_name, &local_error)) {
+ error_propagate(errp, 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 28b0114..29fa2e9 100644
--- a/include/hw/proxy/qemu-proxy.h
+++ b/include/hw/proxy/qemu-proxy.h
@@ -39,7 +39,7 @@ typedef struct PCIProxyDev {
void (*proxy_ready) (PCIDevice *dev);
void (*init_proxy) (PCIDevice *dev, char *command, char *exec_name,
- Error **errp);
+ bool need_spawn, Error **errp);
} PCIProxyDev;
--
1.8.3.1
- [PATCH v5 03/50] multi-process: add a command line option for debug file, (continued)
- [PATCH v5 03/50] multi-process: add a command line option for debug file, Jagannathan Raman, 2020/02/24
- [PATCH v5 01/50] multi-process: memory: alloc RAM from file at offset, Jagannathan Raman, 2020/02/24
- [PATCH v5 05/50] multi-process: Add config option for multi-process QEMU, Jagannathan Raman, 2020/02/24
- [PATCH v5 07/50] multi-process: define mpqemu-link object, Jagannathan Raman, 2020/02/24
- [PATCH v5 09/50] multi-process: setup PCI host bridge for remote device, Jagannathan Raman, 2020/02/24
- [PATCH v5 06/50] multi-process: build system for remote device process, Jagannathan Raman, 2020/02/24
- [PATCH v5 08/50] multi-process: add functions to synchronize proxy and remote endpoints, Jagannathan Raman, 2020/02/24
- [PATCH v5 11/50] multi-process: setup memory manager for remote device, Jagannathan Raman, 2020/02/24
- [PATCH v5 10/50] multi-process: setup a machine object for remote device process, Jagannathan Raman, 2020/02/24
- [PATCH v5 12/50] multi-process: remote process initialization, Jagannathan Raman, 2020/02/24
- [PATCH v5 14/50] mutli-process: build remote command line args,
Jagannathan Raman <=
- [PATCH v5 13/50] multi-process: introduce proxy object, Jagannathan Raman, 2020/02/24
- [PATCH v5 15/50] multi-process: PCI BAR read/write handling for proxy & remote endpoints, Jagannathan Raman, 2020/02/24
- [PATCH v5 16/50] multi-process: Synchronize remote memory, Jagannathan Raman, 2020/02/24
- [PATCH v5 18/50] multi-process: configure remote side devices, Jagannathan Raman, 2020/02/24
- [PATCH v5 17/50] multi-process: create IOHUB object to handle irq, Jagannathan Raman, 2020/02/24
- [PATCH v5 20/50] multi-process: add qdev_proxy_add to create proxy devices, Jagannathan Raman, 2020/02/24
- [PATCH v5 19/50] multi-process: Retrieve PCI info from remote process, Jagannathan Raman, 2020/02/24
- [PATCH v5 21/50] multi-process: remote: add setup_devices msg processing, Jagannathan Raman, 2020/02/24
- [PATCH v5 23/50] multi-process: remote: add create_done condition, Jagannathan Raman, 2020/02/24
- [PATCH v5 25/50] multi-process: Introduce build flags to separate remote process code, Jagannathan Raman, 2020/02/24