diff --git a/include/spdk_internal/sock.h b/include/spdk_internal/sock.h index 1437991a4..af7f8450a 100644 --- a/include/spdk_internal/sock.h +++ b/include/spdk_internal/sock.h @@ -49,10 +49,11 @@ extern "C" { #define MAX_EVENTS_PER_POLL 32 struct spdk_sock { - struct spdk_net_impl *net_impl; - spdk_sock_cb cb_fn; - void *cb_arg; - TAILQ_ENTRY(spdk_sock) link; + struct spdk_net_impl *net_impl; + spdk_sock_cb cb_fn; + void *cb_arg; + struct spdk_sock_group_impl *group_impl; + TAILQ_ENTRY(spdk_sock) link; }; struct spdk_sock_group { diff --git a/lib/sock/sock.c b/lib/sock/sock.c index b312a34ef..dfb7229bb 100644 --- a/lib/sock/sock.c +++ b/lib/sock/sock.c @@ -363,7 +363,7 @@ spdk_sock_group_add_sock(struct spdk_sock_group *group, struct spdk_sock *sock, return -1; } - if (sock->cb_fn != NULL) { + if (sock->group_impl != NULL) { /* * This sock is already part of a sock_group. Currently we don't * support this. @@ -394,6 +394,7 @@ spdk_sock_group_add_sock(struct spdk_sock_group *group, struct spdk_sock *sock, rc = group_impl->net_impl->group_impl_add_sock(group_impl, sock); if (rc == 0) { TAILQ_INSERT_TAIL(&group_impl->socks, sock, link); + sock->group_impl = group_impl; sock->cb_fn = cb_fn; sock->cb_arg = cb_arg; } @@ -418,6 +419,8 @@ spdk_sock_group_remove_sock(struct spdk_sock_group *group, struct spdk_sock *soc return -1; } + assert(group_impl == sock->group_impl); + rc = sock->net_impl->get_placement_id(sock, &placement_id); if (!rc && (placement_id != 0)) { spdk_sock_map_release(placement_id); @@ -426,6 +429,7 @@ spdk_sock_group_remove_sock(struct spdk_sock_group *group, struct spdk_sock *soc rc = group_impl->net_impl->group_impl_remove_sock(group_impl, sock); if (rc == 0) { TAILQ_REMOVE(&group_impl->socks, sock, link); + sock->group_impl = NULL; sock->cb_fn = NULL; sock->cb_arg = NULL; }