From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f170.google.com (mail-wr0-f170.google.com [209.85.128.170]) by dpdk.org (Postfix) with ESMTP id 6FC8999E1 for ; Mon, 31 Jul 2017 12:59:30 +0200 (CEST) Received: by mail-wr0-f170.google.com with SMTP id v105so147379801wrb.0 for ; Mon, 31 Jul 2017 03:59:30 -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=QOZBSXuucMk+TZG/MNITjIW/Y6FtZTnsgy5EtuS/Cu0=; b=uNqlfkwaJBfYovfoFXV9llICc5pTLy3f0UtwO+HHimUMpHqhE6mJginm0at4j6N40C wrww64lIryzaqhsImoSrwCklgIyX9c/UxN3yYur9KQKSA9Rm4hRKPPHd09yXVW3S/TVl 5i9CidLdpJvR24YmZCmJHs0GDgIL97Mv8OCj/Zs88S8IxcCwrrj0/bRA/+lbM8QcL3lP mcNOQMrtSON/weSrlmq0MydjbU8ns6Yc53qu7ps5C7FqHJBL1fP5u/GD//dX7lVOdX6d iNpu5sAniQ4tpFtuAA/pk8+Rc8zPGUE6+YVOFgBBvXBq/+dx2fKerXBgvbcjOUw1mQ+Y kukQ== 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=QOZBSXuucMk+TZG/MNITjIW/Y6FtZTnsgy5EtuS/Cu0=; b=Zs71YIY51sGcZJU946iwCAzsir12RT+0pBzBjryMiwQAqYm4zfYJeCxQMcUvGmyd7q criGhc/tCiBdVRyzrNpjZhGsXaq2wqb1u8I1vCMCv1V1G8uo+OE4b1opIcy0CMQABhz5 q0IfCTe0+qoLDx3GRhWE3ESLQKWgvzKQNAdOIaE4X4T5ijWHlCw3ZXhBZGZF+AHgq2C9 RNs/MDJjI7BSypEcN1te/obg6EF2my5HJU2h1txwK+4WJf4ZxEZIR82edialzTnCx/yV xOQL3mrbGbJca6J7sQahvKLBST7K6+kLFJ/wqdLxrRVeAY3BvgLd+aXdczHNQCShIWNe tqtg== X-Gm-Message-State: AIVw111KhV5mBQGwkA0GR+Q4moz0Idaf1Abykeg/hvpyF7fuqssOlmQD S7xo9YFhaSpGUBaLYDw= X-Received: by 10.223.134.180 with SMTP id 49mr11368394wrx.157.1501498769589; Mon, 31 Jul 2017 03:59:29 -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 j18sm29008340wrd.90.2017.07.31.03.59.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 31 Jul 2017 03:59:28 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Mon, 31 Jul 2017 12:59:16 +0200 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: <30721dc00d3d6e2509974511ba4c7d1850191d77.1501496837.git.gaetan.rivet@6wind.com> References: <30721dc00d3d6e2509974511ba4c7d1850191d77.1501496837.git.gaetan.rivet@6wind.com> Subject: [dpdk-dev] [PATCH v2] 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: , X-List-Received-Date: Mon, 31 Jul 2017 10:59:30 -0000 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. Use the relevant functions to infer the intended bus. The limitation to PCI or vdev device is kept for strict API compatibility. 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. 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 -- 2.1.4