From d8cafc28bb6a9e910821aed33d20485a77cf4e27 Mon Sep 17 00:00:00 2001 From: Ziye Yang Date: Fri, 29 May 2020 20:42:38 +0800 Subject: [PATCH] Sock: The created pipe for sock should have a minimal value. Thus, we can make sure that when read data is larger than the pipe size, it will not read the data into the pipe. Change-Id: I87f3b03fd9b81eb693e9eae0fea9eef7d1b9eaa8 Signed-off-by: Ziye Yang Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/2450 Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Shuhei Matsumoto Reviewed-by: Aleksey Marchuk --- include/spdk_internal/sock.h | 1 + module/sock/posix/posix.c | 5 ++++- module/sock/uring/uring.c | 5 ++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/spdk_internal/sock.h b/include/spdk_internal/sock.h index c3effdd7d..d88d6bd03 100644 --- a/include/spdk_internal/sock.h +++ b/include/spdk_internal/sock.h @@ -48,6 +48,7 @@ extern "C" { #define MAX_EVENTS_PER_POLL 32 #define DEFAULT_SOCK_PRIORITY 0 +#define MIN_SOCK_PIPE_SIZE 1024 struct spdk_sock { struct spdk_net_impl *net_impl; diff --git a/module/sock/posix/posix.c b/module/sock/posix/posix.c index c82aa0af3..7057cbfc7 100644 --- a/module/sock/posix/posix.c +++ b/module/sock/posix/posix.c @@ -212,6 +212,9 @@ posix_sock_alloc_pipe(struct spdk_posix_sock *sock, int sz) sock->recv_pipe = NULL; sock->recv_buf = NULL; return 0; + } else if (sz < MIN_SOCK_PIPE_SIZE) { + SPDK_ERRLOG("The size of the pipe must be larger than %d\n", MIN_SOCK_PIPE_SIZE); + return -1; } /* Round up to next 64 byte multiple */ @@ -924,7 +927,7 @@ posix_sock_readv(struct spdk_sock *_sock, struct iovec *iov, int iovcnt) if (spdk_pipe_reader_bytes_available(sock->recv_pipe) == 0) { /* If the user is receiving a sufficiently large amount of data, * receive directly to their buffers. */ - if (len >= 1024) { + if (len >= MIN_SOCK_PIPE_SIZE) { return readv(sock->fd, iov, iovcnt); } diff --git a/module/sock/uring/uring.c b/module/sock/uring/uring.c index 2abdb20c9..b186420c8 100644 --- a/module/sock/uring/uring.c +++ b/module/sock/uring/uring.c @@ -232,6 +232,9 @@ uring_sock_alloc_pipe(struct spdk_uring_sock *sock, int sz) sock->recv_pipe = NULL; sock->recv_buf = NULL; return 0; + } else if (sz < MIN_SOCK_PIPE_SIZE) { + SPDK_ERRLOG("The size of the pipe must be larger than %d\n", MIN_SOCK_PIPE_SIZE); + return -1; } /* Round up to next 64 byte multiple */ @@ -660,7 +663,7 @@ uring_sock_readv(struct spdk_sock *_sock, struct iovec *iov, int iovcnt) if (spdk_pipe_reader_bytes_available(sock->recv_pipe) == 0) { /* If the user is receiving a sufficiently large amount of data, * receive directly to their buffers. */ - if (len >= 1024) { + if (len >= MIN_SOCK_PIPE_SIZE) { return readv(sock->fd, iov, iovcnt); }