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
outscale-fne committed Nov 2, 2020
1 parent db56b17 commit e57befd
Show file tree
Hide file tree
Showing 6 changed files with 410 additions and 209 deletions.
20 changes: 14 additions & 6 deletions src/utils/qemu.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ int pg_util_spawn_qemu(const char *socket_path_0,
const char *socket_path_1,
const char *mac_0,
const char *mac_1,
const int is_client_0,
const int is_client_1,
const char *vm_image_path,
const char *vm_key_path,
const char *hugepages_path,
Expand All @@ -81,35 +83,41 @@ int pg_util_spawn_qemu(const char *socket_path_0,
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_client_1)
g_assert(g_file_test(socket_path_0, G_FILE_TEST_EXISTS));
if (socket_path_1 && !is_client_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_client_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_client_0 ? server_params : "",
mac_1);
argv_sock_1 = argv_sock_1_t;
}

Expand Down
2 changes: 2 additions & 0 deletions src/utils/qemu.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ int pg_util_spawn_qemu(const char *socket_path_0,
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,
Expand Down
Loading

0 comments on commit e57befd

Please sign in to comment.