diff mbox series

vhost: fix check peer close

Message ID 20200407034550.1814-1-roland.qi@ucloud.cn (mailing list archive)
State Superseded, archived
Delegated to: Maxime Coquelin
Headers show
Series vhost: fix check peer close | expand

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/travis-robot success Travis build: passed
ci/iol-testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/checkpatch success coding style OK

Commit Message

Roland Qi April 7, 2020, 3:45 a.m. UTC
In process_slave_message_reply(), there is a
possibility that receiving a peer close
message instead of a real message response.

this patch targeting to handle the peer close
scenario and report the correct error message.

Signed-off-by: qikai <roland.qi@ucloud.cn>
---
 lib/librte_vhost/vhost_user.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Comments

Maxime Coquelin April 17, 2020, 2:10 p.m. UTC | #1
On 4/7/20 5:45 AM, qikai wrote:
> In process_slave_message_reply(), there is a
> possibility that receiving a peer close
> message instead of a real message response.
> 
> this patch targeting to handle the peer close
> scenario and report the correct error message.
> 
> Signed-off-by: qikai <roland.qi@ucloud.cn>

Could you please provide you full name to be compliant with
the contribution guidelines?

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>


Thanks,
Maxime

> ---
>  lib/librte_vhost/vhost_user.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c
> index bd1be0104..971ccdb01 100644
> --- a/lib/librte_vhost/vhost_user.c
> +++ b/lib/librte_vhost/vhost_user.c
> @@ -2812,11 +2812,19 @@ static int process_slave_message_reply(struct virtio_net *dev,
>  	if ((msg->flags & VHOST_USER_NEED_REPLY) == 0)
>  		return 0;
>  
> -	if (read_vhost_message(dev->slave_req_fd, &msg_reply) < 0) {
> +	ret = read_vhost_message(dev->slave_req_fd, &msg_reply);
> +	if (ret <= 0) {
> +		if (ret < 0)
> +			VHOST_LOG_CONFIG(ERR,
> +				"vhost read slave message reply failed\n");
> +		else
> +			VHOST_LOG_CONFIG(INFO,
> +				"vhost peer closed\n");
>  		ret = -1;
>  		goto out;
>  	}
>  
> +	ret = 0;
>  	if (msg_reply.request.slave != msg->request.slave) {
>  		VHOST_LOG_CONFIG(ERR,
>  			"Received unexpected msg type (%u), expected %u\n",
>
diff mbox series

Patch

diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c
index bd1be0104..971ccdb01 100644
--- a/lib/librte_vhost/vhost_user.c
+++ b/lib/librte_vhost/vhost_user.c
@@ -2812,11 +2812,19 @@  static int process_slave_message_reply(struct virtio_net *dev,
 	if ((msg->flags & VHOST_USER_NEED_REPLY) == 0)
 		return 0;
 
-	if (read_vhost_message(dev->slave_req_fd, &msg_reply) < 0) {
+	ret = read_vhost_message(dev->slave_req_fd, &msg_reply);
+	if (ret <= 0) {
+		if (ret < 0)
+			VHOST_LOG_CONFIG(ERR,
+				"vhost read slave message reply failed\n");
+		else
+			VHOST_LOG_CONFIG(INFO,
+				"vhost peer closed\n");
 		ret = -1;
 		goto out;
 	}
 
+	ret = 0;
 	if (msg_reply.request.slave != msg->request.slave) {
 		VHOST_LOG_CONFIG(ERR,
 			"Received unexpected msg type (%u), expected %u\n",