sock: Fix return value of spdk_sock_group_poll to return number of events
spdk_sock_group_poll() and spdk_sock_group_poll_count() had returned 0 on success. The implementation didn't match the specification described in the header file, and couldn't be used to collect stats correctly because 0 means idle. This patch fixes the return value of spdk_sock_group_poll() and spdk_sock_group_poll_count() to return number of events and the callers not to overwrite the return value by 0. Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Change-Id: I7e2a17187fc74ea44d3acf2f35d63f5e5a254eda Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/463710 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
5a8033a5f3
commit
cf95d4a24f
@ -249,7 +249,7 @@ int spdk_sock_group_remove_sock(struct spdk_sock_group *group, struct spdk_sock
|
|||||||
*
|
*
|
||||||
* \param group Group to poll.
|
* \param group Group to poll.
|
||||||
*
|
*
|
||||||
* \return 0 on success, -1 on failure.
|
* \return the number of events on success, -1 on failure.
|
||||||
*/
|
*/
|
||||||
int spdk_sock_group_poll(struct spdk_sock_group *group);
|
int spdk_sock_group_poll(struct spdk_sock_group *group);
|
||||||
|
|
||||||
|
@ -1177,7 +1177,7 @@ iscsi_poll_group_poll(void *ctx)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -2776,10 +2776,9 @@ spdk_nvmf_tcp_poll_group_poll(struct spdk_nvmf_transport_poll_group *group)
|
|||||||
rc = spdk_sock_group_poll(tgroup->sock_group);
|
rc = spdk_sock_group_poll(tgroup->sock_group);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
SPDK_ERRLOG("Failed to poll sock_group=%p\n", tgroup->sock_group);
|
SPDK_ERRLOG("Failed to poll sock_group=%p\n", tgroup->sock_group);
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -456,14 +456,14 @@ spdk_sock_group_impl_poll_count(struct spdk_sock_group_impl *group_impl,
|
|||||||
assert(sock->cb_fn != NULL);
|
assert(sock->cb_fn != NULL);
|
||||||
sock->cb_fn(sock->cb_arg, group, sock);
|
sock->cb_fn(sock->cb_arg, group, sock);
|
||||||
}
|
}
|
||||||
return 0;
|
return num_events;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
spdk_sock_group_poll_count(struct spdk_sock_group *group, int max_events)
|
spdk_sock_group_poll_count(struct spdk_sock_group *group, int max_events)
|
||||||
{
|
{
|
||||||
struct spdk_sock_group_impl *group_impl = NULL;
|
struct spdk_sock_group_impl *group_impl = NULL;
|
||||||
int rc, final_rc = 0;
|
int rc, num_events = 0;
|
||||||
|
|
||||||
if (max_events < 1) {
|
if (max_events < 1) {
|
||||||
errno = -EINVAL;
|
errno = -EINVAL;
|
||||||
@ -480,14 +480,16 @@ spdk_sock_group_poll_count(struct spdk_sock_group *group, int max_events)
|
|||||||
|
|
||||||
STAILQ_FOREACH_FROM(group_impl, &group->group_impls, link) {
|
STAILQ_FOREACH_FROM(group_impl, &group->group_impls, link) {
|
||||||
rc = spdk_sock_group_impl_poll_count(group_impl, group, max_events);
|
rc = spdk_sock_group_impl_poll_count(group_impl, group, max_events);
|
||||||
if (rc != 0) {
|
if (rc < 0) {
|
||||||
final_rc = rc;
|
num_events = -1;
|
||||||
SPDK_ERRLOG("group_impl_poll_count for net(%s) failed\n",
|
SPDK_ERRLOG("group_impl_poll_count for net(%s) failed\n",
|
||||||
group_impl->net_impl->name);
|
group_impl->net_impl->name);
|
||||||
|
} else if (num_events >= 0) {
|
||||||
|
num_events += rc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return final_rc;
|
return num_events;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -510,7 +510,7 @@ _sock_group(const char *ip, int port)
|
|||||||
g_bytes_read = 0;
|
g_bytes_read = 0;
|
||||||
rc = spdk_sock_group_poll(group);
|
rc = spdk_sock_group_poll(group);
|
||||||
|
|
||||||
CU_ASSERT(rc == 0);
|
CU_ASSERT(rc == 1);
|
||||||
CU_ASSERT(g_read_data_called == true);
|
CU_ASSERT(g_read_data_called == true);
|
||||||
CU_ASSERT(g_bytes_read == 7);
|
CU_ASSERT(g_bytes_read == 7);
|
||||||
|
|
||||||
@ -621,7 +621,7 @@ posix_sock_group_fairness(void)
|
|||||||
*/
|
*/
|
||||||
g_server_sock_read = NULL;
|
g_server_sock_read = NULL;
|
||||||
rc = spdk_sock_group_poll_count(group, 1);
|
rc = spdk_sock_group_poll_count(group, 1);
|
||||||
CU_ASSERT(rc == 0);
|
CU_ASSERT(rc == 1);
|
||||||
CU_ASSERT(g_server_sock_read == server_sock[0]);
|
CU_ASSERT(g_server_sock_read == server_sock[0]);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -636,17 +636,17 @@ posix_sock_group_fairness(void)
|
|||||||
|
|
||||||
g_server_sock_read = NULL;
|
g_server_sock_read = NULL;
|
||||||
rc = spdk_sock_group_poll_count(group, 1);
|
rc = spdk_sock_group_poll_count(group, 1);
|
||||||
CU_ASSERT(rc == 0);
|
CU_ASSERT(rc == 1);
|
||||||
CU_ASSERT(g_server_sock_read == server_sock[1]);
|
CU_ASSERT(g_server_sock_read == server_sock[1]);
|
||||||
|
|
||||||
g_server_sock_read = NULL;
|
g_server_sock_read = NULL;
|
||||||
rc = spdk_sock_group_poll_count(group, 1);
|
rc = spdk_sock_group_poll_count(group, 1);
|
||||||
CU_ASSERT(rc == 0);
|
CU_ASSERT(rc == 1);
|
||||||
CU_ASSERT(g_server_sock_read == server_sock[2]);
|
CU_ASSERT(g_server_sock_read == server_sock[2]);
|
||||||
|
|
||||||
g_server_sock_read = NULL;
|
g_server_sock_read = NULL;
|
||||||
rc = spdk_sock_group_poll_count(group, 1);
|
rc = spdk_sock_group_poll_count(group, 1);
|
||||||
CU_ASSERT(rc == 0);
|
CU_ASSERT(rc == 1);
|
||||||
CU_ASSERT(g_server_sock_read == server_sock[0]);
|
CU_ASSERT(g_server_sock_read == server_sock[0]);
|
||||||
|
|
||||||
for (i = 0; i < 3; i++) {
|
for (i = 0; i < 3; i++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user