Commit 65d823a5 authored by Maciej Szulik's avatar Maciej Szulik Committed by Jim Harris
Browse files

sock: align sendmsg_idx base with the kernel



By initializing to UINT32_MAX we can have the same base for
sock->sendmsg_idx, req->internal.offset (when used to cache the sendmsg
index) and the kernel UAPI, i.e. first sendmsg has index=0.

Signed-off-by: default avatarMaciej Szulik <maciej.szulik@intel.com>
Change-Id: I2c9e48d7d47acad2ad59a536b4ce4eb5cf0ca294
Reviewed-on: https://review.spdk.io/c/spdk/spdk/+/25659


Reviewed-by: default avatarJim Harris <jim.harris@nvidia.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
Reviewed-by: default avatarJacek Kalwas <jacek.kalwas@nutanix.com>
Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK Automated Test System <spdkbot@gmail.com>
parent 245490e4
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -432,6 +432,9 @@ posix_sock_init(struct spdk_posix_sock *sock, bool enable_zero_copy)
		rc = setsockopt(sock->fd, SOL_SOCKET, SO_ZEROCOPY, &flag, sizeof(flag));
		if (rc == 0) {
			sock->zcopy = true;
			/* Zcopy notification index from the kernel for first sendmsg is 0, so we need to start
			 * incrementing internal counter from UINT32_MAX. */
			sock->sendmsg_idx = UINT32_MAX;
		}
	}
#endif
@@ -1440,10 +1443,8 @@ _sock_flush(struct spdk_sock *sock)
				break;
			}
		} else {
			/* Re-use the offset field to hold the sendmsg call index. The
			 * index is 0 based, so subtract one here because we've already
			 * incremented above. */
			req->internal.offset = psock->sendmsg_idx - 1;
			/* Re-use the offset field to hold the sendmsg call index. */
			req->internal.offset = psock->sendmsg_idx;
		}

		if (rc == 0) {
+5 −4
Original line number Diff line number Diff line
@@ -457,6 +457,9 @@ uring_sock_alloc(int fd, struct spdk_sock_impl_opts *impl_opts, bool enable_zero
		if (rc == 0) {
			sock->zcopy = true;
			sock->zcopy_send_flags = MSG_ZEROCOPY;
			/* Zcopy notification index from the kernel for first sendmsg is 0, so we need to start
			 * incrementing internal counter from UINT32_MAX. */
			sock->sendmsg_idx = UINT32_MAX;
		}
	}
#endif
@@ -1115,10 +1118,8 @@ sock_complete_write_reqs(struct spdk_sock *_sock, ssize_t rc, bool is_zcopy)
				return retval;
			}
		} else {
			/* Re-use the offset field to hold the sendmsg call index. The
			 * index is 0 based, so subtract one here because we've already
			 * incremented above. */
			req->internal.offset = sock->sendmsg_idx - 1;
			/* Re-use the offset field to hold the sendmsg call index. */
			req->internal.offset = sock->sendmsg_idx;
		}

		if (rc == 0) {