sock: set the default placement_id to -1

Purpose: The default value of placement_id in spdk_sock
should be set to -1 in spdk_sock_connect_ext. If we still let it to 0 and call
sock_get_placement_id for the spdk socket used in the initiator side,
we will never get the correct placement_id when enable_placement_id configuration
is configured, because we will always get placement_id = 0
instead. And the same comments in spdk_sock_accept function.

And this patch also change the judgement of placement_id in other related places.

PS: Why we need to explictly set default placement_id = -1, because when use
"enable_placement_id=2" for the socket, placment_id=0 is a valid value.

Signed-off-by: Ziye Yang <ziye.yang@intel.com>
Change-Id: I9fcc3a1c6a5007c22d11da5aeed0022577652a76
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6955
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Community-CI: Mellanox Build Bot
This commit is contained in:
Ziye Yang 2021-03-20 00:05:29 +08:00 committed by Tomasz Zawadzki
parent f209637c9d
commit 1e27c23d09

View File

@ -269,6 +269,8 @@ spdk_sock_connect_ext(const char *ip, int port, char *_impl_name, struct spdk_so
/* Copy the contents, both the two structures are the same ABI version */
memcpy(&sock->opts, &opts_local, sizeof(sock->opts));
sock->net_impl = impl;
/* Set the placement_id to -1 explicitly */
sock->placement_id = -1;
TAILQ_INIT(&sock->queued_reqs);
TAILQ_INIT(&sock->pending_reqs);
return sock;
@ -339,6 +341,7 @@ spdk_sock_accept(struct spdk_sock *sock)
new_sock->opts = sock->opts;
memcpy(&new_sock->opts, &sock->opts, sizeof(new_sock->opts));
new_sock->net_impl = sock->net_impl;
/* Set the placement_id to -1 explicitly */
new_sock->placement_id = -1;
TAILQ_INIT(&new_sock->queued_reqs);
TAILQ_INIT(&new_sock->pending_reqs);
@ -552,7 +555,7 @@ spdk_sock_group_add_sock(struct spdk_sock_group *group, struct spdk_sock *sock,
}
placement_id = sock_get_placement_id(sock);
if (placement_id != 0) {
if (placement_id != -1) {
rc = sock_map_insert(placement_id, group, 0);
if (rc < 0) {
return -1;
@ -601,7 +604,7 @@ spdk_sock_group_remove_sock(struct spdk_sock_group *group, struct spdk_sock *soc
assert(group_impl == sock->group_impl);
placement_id = sock_get_placement_id(sock);
if (placement_id != 0) {
if (placement_id != -1) {
sock_map_release(placement_id);
}