sock: Add a priority parameter in SPDK_NET_IMPL_REGISTER
Purpose: Prepare for setting priorities for different kernel based sock implementations. The g_net_impls list is maintained in decreasing order according to the priority of each sock implementation. For examaple, if there are 3 sock implementations, i.e., posix (priority = 0), vpp (priority = 1), sock_ut (priority =2), then the list will be maintained as: sock_ut -> vpp -> posix. Then if users use spdk_sock_open/listen with impl_name as NULL, then the order to try is: sock_ut, vpp, then posix Signed-off-by: Ziye Yang <ziye.yang@intel.com> Change-Id: I43899de5bac14751ab060a11eb814cd7a0a83cc6 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/479488 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Community-CI: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
parent
0bfaaace8f
commit
d1a8a7bee1
@ -47,6 +47,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#define MAX_EVENTS_PER_POLL 32
|
||||
#define DEFAULT_SOCK_PRIORITY 0
|
||||
|
||||
struct spdk_sock {
|
||||
struct spdk_net_impl *net_impl;
|
||||
@ -80,6 +81,7 @@ struct spdk_sock_group_impl {
|
||||
|
||||
struct spdk_net_impl {
|
||||
const char *name;
|
||||
int priority;
|
||||
|
||||
int (*getaddr)(struct spdk_sock *sock, char *saddr, int slen, uint16_t *sport, char *caddr,
|
||||
int clen, uint16_t *cport);
|
||||
@ -113,12 +115,12 @@ struct spdk_net_impl {
|
||||
STAILQ_ENTRY(spdk_net_impl) link;
|
||||
};
|
||||
|
||||
void spdk_net_impl_register(struct spdk_net_impl *impl);
|
||||
void spdk_net_impl_register(struct spdk_net_impl *impl, int priority);
|
||||
|
||||
#define SPDK_NET_IMPL_REGISTER(name, impl) \
|
||||
#define SPDK_NET_IMPL_REGISTER(name, impl, priority) \
|
||||
static void __attribute__((constructor)) net_impl_register_##name(void) \
|
||||
{ \
|
||||
spdk_net_impl_register(impl); \
|
||||
spdk_net_impl_register(impl, priority); \
|
||||
}
|
||||
|
||||
static inline void
|
||||
|
@ -593,10 +593,21 @@ spdk_sock_group_close(struct spdk_sock_group **group)
|
||||
}
|
||||
|
||||
void
|
||||
spdk_net_impl_register(struct spdk_net_impl *impl)
|
||||
spdk_net_impl_register(struct spdk_net_impl *impl, int priority)
|
||||
{
|
||||
if (!strcmp("posix", impl->name)) {
|
||||
STAILQ_INSERT_TAIL(&g_net_impls, impl, link);
|
||||
struct spdk_net_impl *cur, *prev;
|
||||
|
||||
impl->priority = priority;
|
||||
prev = NULL;
|
||||
STAILQ_FOREACH(cur, &g_net_impls, link) {
|
||||
if (impl->priority > cur->priority) {
|
||||
break;
|
||||
}
|
||||
prev = cur;
|
||||
}
|
||||
|
||||
if (prev) {
|
||||
STAILQ_INSERT_AFTER(&g_net_impls, prev, impl, link);
|
||||
} else {
|
||||
STAILQ_INSERT_HEAD(&g_net_impls, impl, link);
|
||||
}
|
||||
|
@ -885,4 +885,4 @@ static struct spdk_net_impl g_posix_net_impl = {
|
||||
.group_impl_close = spdk_posix_sock_group_impl_close,
|
||||
};
|
||||
|
||||
SPDK_NET_IMPL_REGISTER(posix, &g_posix_net_impl);
|
||||
SPDK_NET_IMPL_REGISTER(posix, &g_posix_net_impl, DEFAULT_SOCK_PRIORITY);
|
||||
|
@ -1469,7 +1469,7 @@ static struct spdk_net_impl g_vpp_net_impl = {
|
||||
.group_impl_close = spdk_vpp_sock_group_impl_close,
|
||||
};
|
||||
|
||||
SPDK_NET_IMPL_REGISTER(vpp, &g_vpp_net_impl);
|
||||
SPDK_NET_IMPL_REGISTER(vpp, &g_vpp_net_impl, DEFAULT_SOCK_PRIORITY + 1);
|
||||
|
||||
static void
|
||||
spdk_vpp_net_framework_fini(void)
|
||||
|
@ -40,7 +40,7 @@
|
||||
|
||||
#include "sock/posix/posix.c"
|
||||
|
||||
DEFINE_STUB_V(spdk_net_impl_register, (struct spdk_net_impl *impl));
|
||||
DEFINE_STUB_V(spdk_net_impl_register, (struct spdk_net_impl *impl, int priority));
|
||||
DEFINE_STUB(spdk_sock_close, int, (struct spdk_sock **s), 0);
|
||||
|
||||
static void
|
||||
|
@ -356,7 +356,7 @@ static struct spdk_net_impl g_ut_net_impl = {
|
||||
.group_impl_close = spdk_ut_sock_group_impl_close,
|
||||
};
|
||||
|
||||
SPDK_NET_IMPL_REGISTER(ut, &g_ut_net_impl);
|
||||
SPDK_NET_IMPL_REGISTER(ut, &g_ut_net_impl, DEFAULT_SOCK_PRIORITY + 2);
|
||||
|
||||
static void
|
||||
_sock(const char *ip, int port, char *impl_name)
|
||||
|
Loading…
Reference in New Issue
Block a user