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 A6C7F45BB3; Wed, 23 Oct 2024 17:16:34 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 71F6C42E73; Wed, 23 Oct 2024 17:16:16 +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 6B8D842E61 for ; Wed, 23 Oct 2024 17:16:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729696572; 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=/wyREkPuyyV2GYk0zSYUrS4ENCxJmegr7vdF6lQpPGA=; b=Wwd8b3BjY2Mnb1wkIt6BGt6j92cWjkBK0Uw+2wvvuC8UKckvWf6GXXihZw4GAw+WZAOqpe T/+EDWBzzB9dkoCkwy6lBAwNFThEIvHJJfNUhAnaln4Gv8Cm9wYCCNjGo+Xl3DgIFAhNFg 210e+r5TImKI8SnTIG934JU7wcAKYbU= 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-372-juPDJ4BgPqKYlrnlLruXfA-1; Wed, 23 Oct 2024 11:16:07 -0400 X-MC-Unique: juPDJ4BgPqKYlrnlLruXfA-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 667921956069; Wed, 23 Oct 2024 15:16:06 +0000 (UTC) Received: from max-p1.redhat.com (unknown [10.39.208.26]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 14D4419560A2; Wed, 23 Oct 2024 15:16:04 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, david.marchand@redhat.com, chenbox@nvidia.com Cc: Maxime Coquelin Subject: [PATCH 5/6] vhost: fix and refactor VDUSE reconnect log check Date: Wed, 23 Oct 2024 17:15:51 +0200 Message-ID: <20241023151552.2863387-6-maxime.coquelin@redhat.com> In-Reply-To: <20241023151552.2863387-1-maxime.coquelin@redhat.com> References: <20241023151552.2863387-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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, 32 insertions(+), 19 deletions(-) diff --git a/lib/vhost/vduse.c b/lib/vhost/vduse.c index 985d4cc58d..0ce17e9690 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) { @@ -651,25 +680,9 @@ vduse_device_create(const char *path, bool compliant_ol_flags) goto out_ctrl_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) { + VHOST_CONFIG_LOG(name, ERR, "Reconnection log file check failed"); goto out_log_unmap; } } else if (errno == ENOENT) { -- 2.46.2