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 0E850A0A05; Tue, 19 Jan 2021 22:31:39 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A3EB1140FEA; Tue, 19 Jan 2021 22:28:44 +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 19FEB140FEA for ; Tue, 19 Jan 2021 22:28:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611091722; 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=yfOw0Y78SH+whHgCPA15zYTG1CwYYZhVhamTXODzzcU=; b=H/8YUSQsnehqQJkxxuJpf/HAq6EU5JGxAqyxc6YIGTByCm/38bjxb49+2w4DrAzXCsOYF8 D4Xgsk9Gj5EqtqDOK0nkjkTD0VKKeYWQuC+yq9F3wQasE+TXusbNSh5RKPBuJqmz+KYOnf J2rEH/aXiaHwHGFCOG97cTIwSKtgoic= 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-45-97z_SFdIN8SEvn5woG0ujA-1; Tue, 19 Jan 2021 16:28:40 -0500 X-MC-Unique: 97z_SFdIN8SEvn5woG0ujA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7A9EC801817; Tue, 19 Jan 2021 21:28:39 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.36.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1119D5D9DD; Tue, 19 Jan 2021 21:28:37 +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, 19 Jan 2021 22:25:06 +0100 Message-Id: <20210119212507.1043636-44-maxime.coquelin@redhat.com> In-Reply-To: <20210119212507.1043636-1-maxime.coquelin@redhat.com> References: <20210119212507.1043636-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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 v2 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 --- drivers/net/virtio/virtio_user/vhost_user.c | 29 ++++++++++++--------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/drivers/net/virtio/virtio_user/vhost_user.c b/drivers/net/virtio/virtio_user/vhost_user.c index f046655af6..be91c99cea 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.", 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