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 43C3945BBE; Thu, 24 Oct 2024 09:55:31 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9E8DC433CA; Thu, 24 Oct 2024 09:55:07 +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 E024A433B6 for ; Thu, 24 Oct 2024 09:55:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729756502; 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=fldlpHhzAcEFA2u9j+024g4qr4/GNjv5IP9yKOHMsXc=; b=O+15hJFgzExWY4UnAFEO9OhCLs7ioZU8o2OU34SzTl9/FQf3OGvq+7eEMkKjm6BkaBBwOa +ru5mIyLDKJ34V7WUdXFiw/qq3zPDW1Lb9rUbQDf/gIoe3lf1JHxMo2TKslEpwT+0j3yEA DsWUtaleYquJCR5+8JxG2nrxXZ5rVWg= Received: from mx-prod-mc-01.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-654-sojzclpaMGmgERjQydGDog-1; Thu, 24 Oct 2024 03:54:58 -0400 X-MC-Unique: sojzclpaMGmgERjQydGDog-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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B6021195608C; Thu, 24 Oct 2024 07:54:57 +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 62A12300018D; Thu, 24 Oct 2024 07:54:56 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, david.marchand@redhat.com, chenbox@nvidia.com Cc: Maxime Coquelin Subject: [PATCH v2 5/6] vhost: fix and refactor VDUSE reconnect log check Date: Thu, 24 Oct 2024 09:54:40 +0200 Message-ID: <20241024075441.3723352-6-maxime.coquelin@redhat.com> In-Reply-To: <20241024075441.3723352-1-maxime.coquelin@redhat.com> References: <20241024075441.3723352-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, 32 insertions(+), 19 deletions(-) diff --git a/lib/vhost/vduse.c b/lib/vhost/vduse.c index d93661edbe..c548b42f62 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,25 +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) { + VHOST_CONFIG_LOG(name, ERR, "Reconnection log file check failed"); goto out_log_unmap; } } else if (errno == ENOENT) { -- 2.46.2