From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 61CCBA052A; Tue, 26 Jan 2021 11:23:59 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 186DA141451; Tue, 26 Jan 2021 11:18:52 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mails.dpdk.org (Postfix) with ESMTP id EB183141448 for ; Tue, 26 Jan 2021 11:18:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611656327; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bV+VK7GP4jLkhRqmpdH9ZEXdksebbGkXSYQhDugo24o=; b=a+C4d2n2T89tnXRe9OI8SB5LPArLAr/a8i5n2lj9TPf+2NgXHG0CTkCiZjy/Ejdcc6w3rx gFTnaHVEMPZevVxecuIaIN1ZLJA4zMNkkwxmL5qNVIAgHyq1DtX9CAHrTq2OAc36xEfy4d jAGJBzjNjEVcePZTAwByMMJhR6RVOEw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-545-jTF3vI0iMYy--9WI58Fe_w-1; Tue, 26 Jan 2021 05:18:45 -0500 X-MC-Unique: jTF3vI0iMYy--9WI58Fe_w-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6D72C1005504; Tue, 26 Jan 2021 10:18:44 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.36.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id DDF3A72171; Tue, 26 Jan 2021 10:18:39 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, chenbo.xia@intel.com, olivier.matz@6wind.com, amorenoz@redhat.com, david.marchand@redhat.com Cc: Maxime Coquelin Date: Tue, 26 Jan 2021 11:16:38 +0100 Message-Id: <20210126101639.250481-44-maxime.coquelin@redhat.com> In-Reply-To: <20210126101639.250481-1-maxime.coquelin@redhat.com> References: <20210126101639.250481-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Subject: [dpdk-dev] [PATCH v4 43/44] net/virtio: improve Vhost-user error logging X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch improves error logging in vhost_user_read, especially printing errno when recv() fails. Suggested-by: Adrian Moreno Signed-off-by: Maxime Coquelin Reviewed-by: Chenbo Xia --- drivers/net/virtio/virtio_user/vhost_user.c | 31 ++++++++++++--------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/drivers/net/virtio/virtio_user/vhost_user.c b/drivers/net/virtio/virtio_user/vhost_user.c index 088aae3aa3..ec2c53c8fb 100644 --- a/drivers/net/virtio/virtio_user/vhost_user.c +++ b/drivers/net/virtio/virtio_user/vhost_user.c @@ -148,38 +148,43 @@ vhost_user_read(int fd, struct vhost_user_msg *msg) int ret, sz_hdr = VHOST_USER_HDR_SIZE, sz_payload; ret = recv(fd, (void *)msg, sz_hdr, 0); - if (ret < sz_hdr) { + if (ret < 0) { + PMD_DRV_LOG(ERR, "Failed to recv msg header: %s", strerror(errno)); + return -1; + } else if (ret < sz_hdr) { PMD_DRV_LOG(ERR, "Failed to recv msg hdr: %d instead of %d.", ret, sz_hdr); - goto fail; + return -1; } /* validate msg flags */ if (msg->flags != (valid_flags)) { - PMD_DRV_LOG(ERR, "Failed to recv msg: flags %x instead of %x.", + PMD_DRV_LOG(ERR, "Failed to recv msg: flags 0x%x instead of 0x%x.", msg->flags, valid_flags); - goto fail; + return -1; } sz_payload = msg->size; - if ((size_t)sz_payload > sizeof(msg->payload)) - goto fail; + if ((size_t)sz_payload > sizeof(msg->payload)) { + PMD_DRV_LOG(ERR, "Payload size overflow, header says %d but max %zu\n", + sz_payload, sizeof(msg->payload)); + return -1; + } if (sz_payload) { ret = recv(fd, (void *)((char *)msg + sz_hdr), sz_payload, 0); - if (ret < sz_payload) { - PMD_DRV_LOG(ERR, - "Failed to recv msg payload: %d instead of %d.", + if (ret < 0) { + PMD_DRV_LOG(ERR, "Failed to recv msg payload: %s", strerror(errno)); + return -1; + } else if (ret < sz_payload) { + PMD_DRV_LOG(ERR, "Failed to recv msg payload: %d instead of %u.", ret, msg->size); - goto fail; + return -1; } } return 0; - -fail: - return -1; } static int -- 2.29.2