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 61C1445BC0; Thu, 24 Oct 2024 11:44:50 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A000E43418; Thu, 24 Oct 2024 11:44:28 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 93CDE4340D for ; Thu, 24 Oct 2024 11:44:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729763062; 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=y4Mh9hI/rABe3qq5SUwGSKkVRVXK4O+mxj5dsMDb9qA=; b=GoWEv1LqbNtQ9jYuKAMXRwMsEcMmRHC8DFvgbCxnjVjiEkegf96I37+/PdaTE+An+AwsWN 70Qyi6YvDvpjkv8o/LL6BUDAzQ7nK3EgDy/gDT4xWm0BtRbUNbCtQqyU2Y1OWU5Z++qe8v KBtacvVL2ii+WrzqfFygjbx/0A+uYbg= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-518-Y-ycGVPwMtm4d6kb4PwVCQ-1; Thu, 24 Oct 2024 05:44:20 -0400 X-MC-Unique: Y-ycGVPwMtm4d6kb4PwVCQ-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id AAC6F19560BD; Thu, 24 Oct 2024 09:44:19 +0000 (UTC) Received: from max-p1.redhat.com (unknown [10.39.208.26]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 59E8C300018D; Thu, 24 Oct 2024 09:44:18 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, david.marchand@redhat.com, chenbox@nvidia.com Cc: Maxime Coquelin Subject: [PATCH v3 5/6] vhost: fix and refactor VDUSE reconnect log check Date: Thu, 24 Oct 2024 11:44:05 +0200 Message-ID: <20241024094406.3826637-6-maxime.coquelin@redhat.com> In-Reply-To: <20241024094406.3826637-1-maxime.coquelin@redhat.com> References: <20241024094406.3826637-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 This patch fixes missing error handling in checking the reconnect log version, and takes the opportunity to move all the checks into a dedicated function to simply VDUSE device creation code. Fixes: da79cc7fda76 ("vhost: add reconnection support to VDUSE") Signed-off-by: Maxime Coquelin --- lib/vhost/vduse.c | 51 ++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/lib/vhost/vduse.c b/lib/vhost/vduse.c index aae20dfc55..c18692f834 100644 --- a/lib/vhost/vduse.c +++ b/lib/vhost/vduse.c @@ -533,6 +533,35 @@ vduse_reconnect_log_map(const char *dev_name, struct vhost_reconnect_data **reco return ret; } +static int +vduse_reconnect_log_check(struct vhost_reconnect_data *reco_log, + const char *dev_name, + uint64_t features, uint32_t total_queues) +{ + if (reco_log->version != VHOST_RECONNECT_VERSION) { + VHOST_CONFIG_LOG(dev_name, ERR, + "Version mismatch between backend (0x%x) & reconnection file (0x%x)", + VHOST_RECONNECT_VERSION, reco_log->version); + return -1; + } + + if ((reco_log->features & features) != reco_log->features) { + VHOST_CONFIG_LOG(dev_name, ERR, + "Features mismatch between backend (0x%" PRIx64 ") & reconnection file (0x%" PRIx64 ")", + features, reco_log->features); + return -1; + } + + if (reco_log->nr_vrings != total_queues) { + VHOST_CONFIG_LOG(dev_name, ERR, + "Queues number mismatch between backend (%u) and reconnection file (%u)", + total_queues, reco_log->nr_vrings); + return -1; + } + + return 0; +} + static void vduse_reconnect_handler(int fd, void *arg, int *remove) { @@ -648,27 +677,9 @@ vduse_device_create(const char *path, bool compliant_ol_flags) if (ret < 0) goto out_dev_close; - if (reconnect_log->version != VHOST_RECONNECT_VERSION) { - VHOST_CONFIG_LOG(name, ERR, - "Version mismatch between backend (0x%x) & reconnection file (0x%x)", - VHOST_RECONNECT_VERSION, reconnect_log->version); - } - - if ((reconnect_log->features & features) != reconnect_log->features) { - VHOST_CONFIG_LOG(name, ERR, - "Features mismatch between backend (0x%" PRIx64 ") & reconnection file (0x%" PRIx64 ")", - features, reconnect_log->features); - ret = -1; - goto out_log_unmap; - } - - if (reconnect_log->nr_vrings != total_queues) { - VHOST_CONFIG_LOG(name, ERR, - "Queues number mismatch between backend (%u) and reconnection file (%u)", - total_queues, reconnect_log->nr_vrings); - ret = -1; + ret = vduse_reconnect_log_check(reconnect_log, name, features, total_queues); + if (ret < 0) goto out_log_unmap; - } } else if (errno == ENOENT) { struct vduse_dev_config *dev_config; -- 2.46.2