From patchwork Mon Jul 31 12:58:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ga=C3=ABtan_Rivet?= X-Patchwork-Id: 27284 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id C365D99F1; Mon, 31 Jul 2017 14:58:43 +0200 (CEST) Received: from mail-wr0-f171.google.com (mail-wr0-f171.google.com [209.85.128.171]) by dpdk.org (Postfix) with ESMTP id 2E2619961 for ; Mon, 31 Jul 2017 14:58:42 +0200 (CEST) Received: by mail-wr0-f171.google.com with SMTP id 12so179189167wrb.1 for ; Mon, 31 Jul 2017 05:58:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=hjzj+TDIDNstngZfuV7qPwTq1b97VfcBzhSU70x1ZTA=; b=0aD0U45p7EyoeVtaEfPpUMh6hcViMAYKbWS++wQkp5XtFtSpm9uE+VcNhkJWVvQNdi rG3pCuCKFaCksyxMDulsuUWgKGpQ86Sq09VbUaqZgMD6prTEY0kN3FKjAic5FusfC55h HPPep26Ay/73ofw1Ih7MsGk5kSFiqZHuF7PDSYDtAwqV1dv+t4ZJDcUIoKTyZEH3Qgu+ UmA42B4nelJeROXejKl5+KYniZPk8F/rGIWAiV0SHeKPSMWoTNBmhI9GgCF7j8Pt32UT ++mOze6RCTRpjP7naE1IWBK9SR6ACQe4Dvr9znc9RwztsdsojPmEXWdVusqemmLwnfKl CR2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=hjzj+TDIDNstngZfuV7qPwTq1b97VfcBzhSU70x1ZTA=; b=eQhUWhvmleBcwhmC6+Yjht7Nea+FBvm+23voKyVi+p+GttQxC8IjUq41fEZCBsIm5l 8n70hpX7Txcpzhn1vSKttVKWite4MpHzZ9g76MqvYLcd2l64AabU1iI+ttIyWy3uNreF +GewXvyb7FOJHdJRYCnAZEPYEX7owu3qZynkwQbhTk6lO4MtnqNsuCWHBMVzr2vKHiEN xKw3q1FmTtwxUwLloFdi44acGgJTVvLiEF113phCFeQLfJwiZu4Bf0oBNIG2TxE93Sjk 1cg4jmRaVXc1xJ6VbHiPnqwmoJMuSk71xCCaQzIkzp55YO4ucFE7h5gWYRU3EfI4s0sW 3y3A== X-Gm-Message-State: AIVw113miJb5Bbwqlk724AmL3eYy5ZC5g+sQ9xvIanMfaYENTXSR/WiA xWDypMw7zoXt+tlQxHM= X-Received: by 10.223.176.57 with SMTP id f54mr8491652wra.194.1501505921372; Mon, 31 Jul 2017 05:58:41 -0700 (PDT) Received: from bidouze.dev.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id 195sm6383600wmv.25.2017.07.31.05.58.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 31 Jul 2017 05:58:40 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Mon, 31 Jul 2017 14:58:29 +0200 Message-Id: <032453ede0e0c6d5464bd9d53a45b48cf4d229db.1501505748.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v3] dev: fix virtual dev attach X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 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" Checking against error values returned by rte_eal_hotplug_add is inelegant and prone to mistakes. Additionally, the failed PCI probe prints a useless error that would throw off unsuspecting users: ERROR: failed to parse device "pci:net_ring0" This error is printed when attempting to probe a virtual device first with the PCI bus (here, a net_ring0 device), which will inevitably fail. Use the relevant functions to infer the intended bus. The limitation to PCI or vdev device is kept for strict API compatibility. Thus the PCI probe attempt is avoided and the right function is directly called. Fixes: 1c35f666df07 ("dev: fix attach proceeding with vdev on PCI success") Signed-off-by: Gaetan Rivet --- v2: - Avoid the PCI parsing error when attaching a vdev. v3: - Explain the parsing error previously thrown that the current version of the patch avoids. lib/librte_eal/common/eal_common_dev.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index d74f978..f98302d 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -66,6 +66,7 @@ static int cmp_dev_name(const struct rte_device *dev, const void *_name) int rte_eal_dev_attach(const char *name, const char *devargs) { + struct rte_bus *bus; int ret; if (name == NULL || devargs == NULL) { @@ -73,9 +74,18 @@ int rte_eal_dev_attach(const char *name, const char *devargs) return -EINVAL; } - ret = rte_eal_hotplug_add("pci", name, devargs); - if (ret != -EINVAL) - return ret; + bus = rte_bus_find_by_device_name(name); + if (bus == NULL) { + RTE_LOG(ERR, EAL, "Unable to find a bus for the device '%s'\n", + name); + return -EINVAL; + } + if (strcmp(bus->name, "pci") == 0) + return rte_eal_hotplug_add("pci", name, devargs); + if (strcmp(bus->name, "vdev") != 0) { + RTE_LOG(ERR, EAL, "Device attach is only supported for PCI and vdev devices.\n"); + return -ENOTSUP; + } /* * If we haven't found a bus device the user meant to "hotplug" a