Skip to content

Commit

Permalink
src/vhost.c: allow working with qemu as a vhost server.
Browse files Browse the repository at this point in the history
  • Loading branch information
Cloud User authored and outscale-fne committed Sep 15, 2020
1 parent db56b17 commit 4da028f
Show file tree
Hide file tree
Showing 6 changed files with 317 additions and 194 deletions.
42 changes: 25 additions & 17 deletions src/utils/qemu.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,49 +67,57 @@ int pg_util_ssh(const char *host,
}

int pg_util_spawn_qemu(const char *socket_path_0,
const char *socket_path_1,
const char *mac_0,
const char *mac_1,
const char *vm_image_path,
const char *vm_key_path,
const char *hugepages_path,
struct pg_error **errp)
const char *socket_path_1,
const char *mac_0,
const char *mac_1,
const int is_server_0,
const int is_server_1,
const char *vm_image_path,
const char *vm_key_path,
const char *hugepages_path,
struct pg_error **errp)
{
int child_pid = 0;
static uint16_t vm_id;
char **argv = NULL;
pg_autofree char *argv_qemu = NULL;
const char *argv_sock_0 = "";
const char *argv_sock_1 = "";
const char *server_params = ",server,nowait";
pg_autofree char *argv_sock_0_t = NULL;
pg_autofree char *argv_sock_1_t = NULL;
pg_autofree char *ssh_cmd = NULL;
GError *error = NULL;

g_assert(g_file_test(socket_path_0, G_FILE_TEST_EXISTS));
if (socket_path_1)
if(!is_server_1)
g_assert(g_file_test(socket_path_0, G_FILE_TEST_EXISTS));
if (socket_path_1 && !is_server_1)
g_assert(g_file_test(socket_path_1, G_FILE_TEST_EXISTS));
g_assert(g_file_test(vm_image_path, G_FILE_TEST_EXISTS));
g_assert(g_file_test(vm_key_path, G_FILE_TEST_EXISTS));
g_assert(g_file_test(hugepages_path, G_FILE_TEST_EXISTS));

if (socket_path_0) {
argv_sock_0_t = g_strdup_printf(
PG_STRCAT(" -chardev socket,id=char0,path=%s",
PG_STRCAT(" -chardev socket,id=char0,path=%s%s",
" -netdev type=vhost-user,id=mynet0,",
"chardev=char0,vhostforce",
" -device virtio-net-pci,mac=%s",
",netdev=mynet0"), socket_path_0, mac_0);
",netdev=mynet0"), socket_path_0,
is_server_0 ? server_params : "",
mac_0);
argv_sock_0 = argv_sock_0_t;
}

if (socket_path_1) {
argv_sock_1_t = g_strdup_printf(
PG_STRCAT(" -chardev socket,id=char1,path=%s",
PG_STRCAT(" -chardev socket,id=char1,path=%s%s",
" -netdev type=vhost-user,id=mynet1,",
"chardev=char1,vhostforce",
" -device virtio-net-pci,mac=%s",
",netdev=mynet1"), socket_path_1, mac_1);
",netdev=mynet1"), socket_path_1,
is_server_0 ? server_params : "",
mac_1);
argv_sock_1 = argv_sock_1_t;
}

Expand All @@ -133,10 +141,10 @@ int pg_util_spawn_qemu(const char *socket_path_0,
argv = g_strsplit(argv_qemu, " ", 0);

g_assert(g_spawn_async(NULL, argv, NULL,
(GSpawnFlags) G_SPAWN_SEARCH_PATH |
G_SPAWN_DO_NOT_REAP_CHILD,
(GSpawnChildSetupFunc) NULL,
NULL, &child_pid, &error));
(GSpawnFlags) G_SPAWN_SEARCH_PATH |
G_SPAWN_DO_NOT_REAP_CHILD,
(GSpawnChildSetupFunc) NULL,
NULL, &child_pid, &error));
g_assert(!error);

ssh_cmd = g_strdup_printf(
Expand Down
16 changes: 9 additions & 7 deletions src/utils/qemu.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ int pg_util_ssh(const char *host,
__attribute__((__format__(__printf__, 4, 5)));

int pg_util_spawn_qemu(const char *socket_path_0,
const char *socket_path_1,
const char *mac_0,
const char *mac_1,
const char *vm_image_path,
const char *vm_ssh_key_path,
const char *hugepages_path,
struct pg_error **errp);
const char *socket_path_1,
const char *mac_0,
const char *mac_1,
const int is_server_0,
const int is_server_1,
const char *vm_image_path,
const char *vm_ssh_key_path,
const char *hugepages_path,
struct pg_error **errp);

void pg_util_stop_qemu(int qemu_pid, int signal);

Expand Down
Loading

0 comments on commit 4da028f

Please sign in to comment.