From d279102850a15d11005450b59ee624a9544e4fd7 Mon Sep 17 00:00:00 2001 From: yinbin6 Date: Fri, 16 Aug 2024 16:01:02 +0800 Subject: [PATCH] sync virtio: mod virtio_user_name when multi process is on (cherry picked from commit 939090a9c23a75c52a2e8dfb88b204f68cf91036) --- ...program-establishes-a-network-connec.patch | 31 ++++ ...ode-did-not-bind-kernel-while-open-k.patch | 28 ++++ 0240-WRAP-fix-bind-log-error.patch | 49 ++++++ ...o_user_name-when-multi-process-is-on.patch | 154 ++++++++++++++++++ ...dump-ctrl-c-during-the-pressure-test.patch | 33 ++++ gazelle.spec | 14 +- 6 files changed, 308 insertions(+), 1 deletion(-) create mode 100644 0238-virtio_user-The-program-establishes-a-network-connec.patch create mode 100644 0239-WRAP-fix-ltran-mode-did-not-bind-kernel-while-open-k.patch create mode 100644 0240-WRAP-fix-bind-log-error.patch create mode 100644 0241-virtio-mod-virtio_user_name-when-multi-process-is-on.patch create mode 100644 0242-fix-redis-coredump-ctrl-c-during-the-pressure-test.patch diff --git a/0238-virtio_user-The-program-establishes-a-network-connec.patch b/0238-virtio_user-The-program-establishes-a-network-connec.patch new file mode 100644 index 0000000..ccabe82 --- /dev/null +++ b/0238-virtio_user-The-program-establishes-a-network-connec.patch @@ -0,0 +1,31 @@ +From 5d0f8bead56a19862ac1e5a9dbd30797e24be6b4 Mon Sep 17 00:00:00 2001 +From: hkk +Date: Sat, 10 Aug 2024 17:11:55 +0800 +Subject: [PATCH] virtio_user: The program establishes a network connection + when network card status is up + +--- + src/lstack/core/lstack_virtio.c | 7 +++++++ + 1 file changed, 7 insertions(+) + +diff --git a/src/lstack/core/lstack_virtio.c b/src/lstack/core/lstack_virtio.c +index f95b289..b8114e8 100644 +--- a/src/lstack/core/lstack_virtio.c ++++ b/src/lstack/core/lstack_virtio.c +@@ -147,6 +147,13 @@ static int virtio_netif_up(void) + } + + posix_api->close_fn(sockfd); ++ /* ++ * For virtio_user IPv6 addresses, the kernel will check if they are valid, ++ * so wait a few seconds for the address status to change from scope global tentative to scope global. ++ * 3:systerm check ipv6 addr ++ */ ++ sleep(3); ++ + return 0; + } + +-- +2.33.0 + diff --git a/0239-WRAP-fix-ltran-mode-did-not-bind-kernel-while-open-k.patch b/0239-WRAP-fix-ltran-mode-did-not-bind-kernel-while-open-k.patch new file mode 100644 index 0000000..caaa59b --- /dev/null +++ b/0239-WRAP-fix-ltran-mode-did-not-bind-kernel-while-open-k.patch @@ -0,0 +1,28 @@ +From 19ba97492e3e658301e801d1866a68ac17d87f2f Mon Sep 17 00:00:00 2001 +From: yinbin +Date: Sat, 10 Aug 2024 15:34:42 +0800 +Subject: [PATCH] WRAP:fix ltran mode did not bind kernel while open kni + +--- + src/lstack/api/lstack_wrap.c | 5 +++-- + 1 file changed, 3 insertions(+), 2 deletions(-) + +diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c +index afcd227..73281e9 100644 +--- a/src/lstack/api/lstack_wrap.c ++++ b/src/lstack/api/lstack_wrap.c +@@ -204,8 +204,9 @@ static int kernel_bind_process(int32_t s, const struct sockaddr *name, socklen_t + struct lwip_sock *sock = NULL; + int times = 10; + int ret = 0; +- +- if (get_global_cfg_params()->kni_switch == 0 && get_global_cfg_params()->flow_bifurcation == 0) { ++ /* lstack not sense if ltran enable kni, so only checks use_ltran. */ ++ if (!get_global_cfg_params()->use_ltran && !get_global_cfg_params()->kni_switch && ++ !get_global_cfg_params()->flow_bifurcation) { + return 0; + } + ret = posix_api->bind_fn(s, name, namelen); +-- +2.33.0 + diff --git a/0240-WRAP-fix-bind-log-error.patch b/0240-WRAP-fix-bind-log-error.patch new file mode 100644 index 0000000..d47cf47 --- /dev/null +++ b/0240-WRAP-fix-bind-log-error.patch @@ -0,0 +1,49 @@ +From 7601cb5b7f384750bb08c15179c43b8e4417d9c6 Mon Sep 17 00:00:00 2001 +From: yinbin +Date: Mon, 12 Aug 2024 14:32:08 +0800 +Subject: [PATCH] WRAP: fix bind log error + +--- + src/lstack/api/lstack_wrap.c | 7 ++++--- + 1 file changed, 4 insertions(+), 3 deletions(-) + +diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c +index 73281e9..8c3c731 100644 +--- a/src/lstack/api/lstack_wrap.c ++++ b/src/lstack/api/lstack_wrap.c +@@ -201,12 +201,13 @@ static int32_t do_accept4(int32_t s, struct sockaddr *addr, socklen_t *addrlen, + + static int kernel_bind_process(int32_t s, const struct sockaddr *name, socklen_t namelen) + { +- struct lwip_sock *sock = NULL; ++ struct lwip_sock *sock = lwip_get_socket(s); + int times = 10; + int ret = 0; + /* lstack not sense if ltran enable kni, so only checks use_ltran. */ + if (!get_global_cfg_params()->use_ltran && !get_global_cfg_params()->kni_switch && + !get_global_cfg_params()->flow_bifurcation) { ++ POSIX_SET_TYPE(sock, POSIX_LWIP); + return 0; + } + ret = posix_api->bind_fn(s, name, namelen); +@@ -232,7 +233,6 @@ static int kernel_bind_process(int32_t s, const struct sockaddr *name, socklen_t + } + /* not sure POSIX_LWIP or POSIX_KERNEL */ + } else { +- sock = lwip_get_socket(s); + POSIX_SET_TYPE(sock, POSIX_LWIP); + LSTACK_LOG(ERR, LSTACK, "kernel bind failed ret %d errno %d sa_family %u times %u\n", + ret, errno, name->sa_family, times); +@@ -266,7 +266,8 @@ static int32_t do_bind(int32_t s, const struct sockaddr *name, socklen_t namelen + memcpy_s(sock_addr.u_addr.ip6.addr, IPV6_ADDR_LEN, + ((struct sockaddr_in6 *)name)->sin6_addr.s6_addr, IPV6_ADDR_LEN); + } +- ++ ++ /* TODO: if addr == 127.0.0.1, try kernel and lwip */ + if (!match_host_addr(&sock_addr)) { + POSIX_SET_TYPE(sock, POSIX_KERNEL); + return posix_api->bind_fn(s, name, namelen); +-- +2.33.0 + diff --git a/0241-virtio-mod-virtio_user_name-when-multi-process-is-on.patch b/0241-virtio-mod-virtio_user_name-when-multi-process-is-on.patch new file mode 100644 index 0000000..266f5df --- /dev/null +++ b/0241-virtio-mod-virtio_user_name-when-multi-process-is-on.patch @@ -0,0 +1,154 @@ +From d6fab15b942ec7452c1a485741ecec7bb876390f Mon Sep 17 00:00:00 2001 +From: hkk +Date: Tue, 13 Aug 2024 10:09:50 +0800 +Subject: [PATCH] virtio: mod virtio_user_name when multi process is on + +--- + src/lstack/core/lstack_virtio.c | 57 ++++++++++++++++++++++++++------- + 1 file changed, 45 insertions(+), 12 deletions(-) + +diff --git a/src/lstack/core/lstack_virtio.c b/src/lstack/core/lstack_virtio.c +index b8114e8..9862b48 100644 +--- a/src/lstack/core/lstack_virtio.c ++++ b/src/lstack/core/lstack_virtio.c +@@ -13,6 +13,7 @@ + #include + #include + #include ++#include + #include + #include + #include "lstack_cfg.h" +@@ -21,14 +22,14 @@ + #include "lstack_virtio.h" + #include "securec.h" + +-#define VIRTIO_USER_NAME "virtio_user0" ++#define VIRTIO_USER_NAME "virtio_user" + #define VIRTIO_DPDK_PARA_LEN 256 + #define VIRTIO_TX_RX_RING_SIZE 1024 + + #define VIRTIO_MASK_BITS(mask) (32 - __builtin_clz(mask)) + + static struct virtio_instance g_virtio_instance = {0}; +- ++static char g_virtio_user_name[IFNAMSIZ] = {0}; + struct virtio_instance* virtio_instance_get(void) + { + return &g_virtio_instance; +@@ -46,7 +47,7 @@ static int virtio_set_ipv6_addr(void) + return -1; + } + +- int ret = strncpy_s(ifr.ifr_name, sizeof(ifr.ifr_name), VIRTIO_USER_NAME, sizeof(VIRTIO_USER_NAME)); ++ int ret = strncpy_s(ifr.ifr_name, sizeof(ifr.ifr_name), g_virtio_user_name, strlen(g_virtio_user_name)); + if (ret != 0) { + LSTACK_LOG(ERR, LSTACK, "virtio_set_ipv6_addr strncpy failed ret =%d errno=%d \n", ret, errno); + posix_api->close_fn(sockfd); +@@ -95,7 +96,7 @@ static int virtio_set_ipv4_addr(void) + struct ifreq ifr; + memset_s(&ifr, sizeof(ifr), 0, sizeof(ifr)); + +- ret = strcpy_s(ifr.ifr_name, sizeof(ifr.ifr_name), VIRTIO_USER_NAME); ++ ret = strcpy_s(ifr.ifr_name, sizeof(ifr.ifr_name), g_virtio_user_name); + if (ret != 0) { + LSTACK_LOG(ERR, LSTACK, "virtio_set_ipv4_addr strcpy_s failed ret=%d errno %d \n", ret, errno); + posix_api->close_fn(sockfd); +@@ -132,7 +133,7 @@ static int virtio_netif_up(void) + + struct ifreq ifr; + memset_s(&ifr, sizeof(ifr), 0, sizeof(ifr)); +- int ret = strcpy_s(ifr.ifr_name, sizeof(ifr.ifr_name), VIRTIO_USER_NAME); ++ int ret = strcpy_s(ifr.ifr_name, sizeof(ifr.ifr_name), g_virtio_user_name); + if (ret != 0) { + LSTACK_LOG(ERR, LSTACK, "virtio_netif_up strcpy_s failed ret=%d errno %d \n", ret, errno); + posix_api->close_fn(sockfd); +@@ -291,15 +292,47 @@ static int32_t virtio_port_start(uint16_t virtio_port) + g_virtio_instance.rx_queue_num, g_virtio_instance.tx_queue_num); + return 0; + } ++ ++static int virtio_get_netif_num(void) ++{ ++ int netif_num = 0; ++ struct ifaddrs *ifaddr, *ifa; ++ ++ if (getifaddrs(&ifaddr) == -1) { ++ LSTACK_LOG(ERR, LSTACK, "getifaddrs failed \n"); ++ return -1; ++ } ++ ++ for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { ++ if (strncmp(ifa->ifa_name, VIRTIO_USER_NAME, sizeof(VIRTIO_USER_NAME) - 1) == 0) { ++ netif_num++; ++ } ++ } ++ ++ freeifaddrs(ifaddr); ++ return netif_num; ++} ++ + int virtio_port_create(int lstack_net_port) + { + char portargs[VIRTIO_DPDK_PARA_LEN] = {0}; + + struct rte_ether_addr addr; + uint16_t virtio_port_id = 0xffff; // invalid val +- + struct rte_eth_dev_info dev_info; +- int ret = rte_eth_dev_info_get(lstack_net_port, &dev_info); ++ ++ int ret = virtio_get_netif_num(); ++ if (ret < 0) { ++ return -1; ++ } ++ ++ ret = sprintf_s(g_virtio_user_name, sizeof(g_virtio_user_name), VIRTIO_USER_NAME "%d", ret); ++ if (ret < 0) { ++ LSTACK_LOG(ERR, LSTACK, "sprintf_s failed ret=%d \n", ret); ++ return -1; ++ } ++ ++ ret = rte_eth_dev_info_get(lstack_net_port, &dev_info); + if (ret != 0) { + LSTACK_LOG(ERR, LSTACK, "get dev info ret=%d\n", ret); + return ret; +@@ -325,22 +358,22 @@ int virtio_port_create(int lstack_net_port) + g_virtio_instance.rx_queue_num : g_virtio_instance.tx_queue_num; + retval = snprintf(portargs, sizeof(portargs), + "path=/dev/vhost-net,queues=%u,queue_size=%u,iface=%s,mac=" RTE_ETHER_ADDR_PRT_FMT, +- actual_queue_num, VIRTIO_TX_RX_RING_SIZE, VIRTIO_USER_NAME, RTE_ETHER_ADDR_BYTES(&addr)); ++ actual_queue_num, VIRTIO_TX_RX_RING_SIZE, g_virtio_user_name, RTE_ETHER_ADDR_BYTES(&addr)); + if (retval < 0) { + LSTACK_LOG(ERR, LSTACK, "virtio portargs snprintf failed ret=%d \n", retval); + return retval; + } + LSTACK_LOG(INFO, LSTACK, "virtio portargs=%s \n", portargs); + +- retval = rte_eal_hotplug_add("vdev", VIRTIO_USER_NAME, portargs); ++ retval = rte_eal_hotplug_add("vdev", g_virtio_user_name, portargs); + if (retval < 0) { + LSTACK_LOG(ERR, LSTACK, "rte_eal_hotplug_add failed retval=%d : %s\n", retval, strerror(-retval)); + return retval; + } + +- retval = rte_eth_dev_get_port_by_name(VIRTIO_USER_NAME, &virtio_port_id); ++ retval = rte_eth_dev_get_port_by_name(g_virtio_user_name, &virtio_port_id); + if (retval != 0) { +- rte_eal_hotplug_remove("vdev", VIRTIO_USER_NAME); ++ rte_eal_hotplug_remove("vdev", g_virtio_user_name); + LSTACK_LOG(ERR, LSTACK, "virtio_user0 not found\n"); + return -1; + } +@@ -351,7 +384,7 @@ int virtio_port_create(int lstack_net_port) + retval = virtio_port_start(virtio_port_id); + if (retval != 0) { + LSTACK_LOG(ERR, LSTACK, "virtio_port_start failed ret=%d\n", retval); +- rte_eal_hotplug_remove("vdev", VIRTIO_USER_NAME); ++ rte_eal_hotplug_remove("vdev", g_virtio_user_name); + return retval; + } + return 0; +-- +2.33.0 + diff --git a/0242-fix-redis-coredump-ctrl-c-during-the-pressure-test.patch b/0242-fix-redis-coredump-ctrl-c-during-the-pressure-test.patch new file mode 100644 index 0000000..b755200 --- /dev/null +++ b/0242-fix-redis-coredump-ctrl-c-during-the-pressure-test.patch @@ -0,0 +1,33 @@ +From c080e30b41f47848de441e96232d255e541a7c1a Mon Sep 17 00:00:00 2001 +From: yangchen +Date: Thu, 1 Aug 2024 15:55:50 +0800 +Subject: [PATCH] fix redis coredump: ctrl+c during the pressure test + +--- + src/lstack/core/lstack_protocol_stack.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c +index 2867711..f0f2735 100644 +--- a/src/lstack/core/lstack_protocol_stack.c ++++ b/src/lstack/core/lstack_protocol_stack.c +@@ -882,7 +882,7 @@ void stack_tcp_send(struct rpc_msg *msg) + int replenish_again; + + struct lwip_sock *sock = lwip_get_socket(fd); +- if (sock == NULL) { ++ if (POSIX_IS_CLOSED(sock)) { + msg->result = -1; + LSTACK_LOG(ERR, LSTACK, "get sock error! fd=%d, len=%ld\n", fd, len); + return; +@@ -919,6 +919,6 @@ void stack_udp_send(struct rpc_msg *msg) + + struct lwip_sock *sock = lwip_get_socket(fd); +- if (sock == NULL) { ++ if (POSIX_IS_CLOSED(sock)) { + msg->result = -1; + LSTACK_LOG(ERR, LSTACK, "get sock error! fd=%d, len=%ld\n", fd, len); + return; +-- +2.33.0 + diff --git a/gazelle.spec b/gazelle.spec index d84e314..866b8dc 100644 --- a/gazelle.spec +++ b/gazelle.spec @@ -2,7 +2,7 @@ Name: gazelle Version: 1.0.2 -Release: 54 +Release: 55 Summary: gazelle is a high performance user-mode stack License: MulanPSL-2.0 URL: https://gitee.com/openeuler/gazelle @@ -254,6 +254,11 @@ Patch9234: 0234-WRAP-fix-double-connect-lead-posix-api-disable.patch Patch9235: 0235-virtio_user-add-vlan-info-for-kernerl-packets-when-v.patch Patch9236: 0236-virtio_user-solve-the-issue-that-failed-to-bind-virt.patch Patch9237: 0237-refector-fill-udp-sendring.patch +Patch9238: 0238-virtio_user-The-program-establishes-a-network-connec.patch +Patch9239: 0239-WRAP-fix-ltran-mode-did-not-bind-kernel-while-open-k.patch +Patch9240: 0240-WRAP-fix-bind-log-error.patch +Patch9241: 0241-virtio-mod-virtio_user_name-when-multi-process-is-on.patch +Patch9242: 0242-fix-redis-coredump-ctrl-c-during-the-pressure-test.patch %description %{name} is a high performance user-mode stack. @@ -295,6 +300,13 @@ install -Dpm 0640 %{_builddir}/%{name}-%{version}/src/ltran/ltran.conf %{b %config(noreplace) %{conf_path}/ltran.conf %changelog +* Fri Aug 16 2024 yinbin6 - 1.0.2-55 +- virtio: mod virtio_user_name when multi process is on +- WRAP: fix bind log error +- WRAP:fix ltran mode did not bind kernel while open kni +- virtio_user: The program establishes a network connection when network card status is up +- fix redis coredump ctrl-c during the pressure test + * Fri Aug 9 2024 yinbin6 - 1.0.2-54 - refector fill udp sendring - virtio_user: solve the issue that failed to bind virtio_user's IPv6 address