From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f176.google.com (mail-wr0-f176.google.com [209.85.128.176]) by dpdk.org (Postfix) with ESMTP id CBBB65598 for ; Sun, 9 Jul 2017 03:46:01 +0200 (CEST) Received: by mail-wr0-f176.google.com with SMTP id 77so93678926wrb.1 for ; Sat, 08 Jul 2017 18:46:01 -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 :in-reply-to:references; bh=y4bB3sb2KS//yUL2GZQhdfm3gM0xE+KK72RVXbIfinM=; b=crMB9ugW29FXN23YBggrcN3zd6obM67rmyrSgPp8+P6nboZauPgMLNiqfk4IJ4/Gwu DNDcjEbCkkxIElEQ05C1wuFrQo56/VjrTUZqNfQDnvqglHEaJ1M8zTi9UK/urQVSeZsx rLi0NfEpV4sl6mFmbcQSuB5dufXWU3n93yWeKBoujDe1fbOAWWuY8BV5c60iEZJLLVcy gGr/fZYGUDyd1llmuzXeu18rIFh90uY07j+wYdUXyZyK5LQ01+wxXH1RPUQqKnEM6GSd r8jbxYsH1XLlJ5g30IaxfUQF+EZ0EaC2ZmRFRp6+kiHGH6eCkHusSKeFRFPldRcJl+FB sX2g== 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:in-reply-to:references; bh=y4bB3sb2KS//yUL2GZQhdfm3gM0xE+KK72RVXbIfinM=; b=Wq/05eQo1t0ufh/7KpHITlz7Ed9Y/W0WLAr5+X/zuZGbKAL3U6BL8V48D9ywBr4JmG LFqHNetLa6xlC0KqPOWePxPdW/2hwR6++hDPTRcLuChoWWye53IUwdMsNOO+Q1Uyxnup j8j8dllgZgllnbaBu9cxXFvePPQ3wRCrzEyl0+WHEbm4psDOgw1WBoUHZ1QFs1QcVyFj bcVWOkhkcFcX2+L1J4ERbIlJbV+60gxs+RsgCe0rHdUGq7Ky9AkoniujnTs6uzMhgE+3 uYpNc0o680h7Fn3XORgQXZUNRa92nOqxELSsDu+3RtbAwGMcR2QtSyXqXzti6SbsrZZu H7OA== X-Gm-Message-State: AIVw113uNOYyQ5z/7G1BmfQZmXon/aj1jrneICMcgAyYA5rs8WFWI0a8 GD2xmsnsZwgP7MXIrXM= X-Received: by 10.28.52.142 with SMTP id b136mr3496234wma.48.1499564760970; Sat, 08 Jul 2017 18:46:00 -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 h130sm2430609wmd.34.2017.07.08.18.45.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 08 Jul 2017 18:46:00 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Sun, 9 Jul 2017 03:45:38 +0200 Message-Id: <41c3144256e26834a73e25251b46770d39fe5cd9.1499563730.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH 2/9] eal: fix hotplug add 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: Sun, 09 Jul 2017 01:46:02 -0000 New device should be represented by an rte_devargs prior to being plugged. Device parameters are available to rte_devices via their devargs field. This field should be set up as soon as possible, as central information are stored within, such as the device name which is used to search the newly scanned device before plugging it in. Fixes: a3ee360f4440 ("eal: add hotplug add/remove device") Signed-off-by: Gaetan Rivet --- lib/librte_eal/common/eal_common_dev.c | 43 +++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index 292fefe..708c8e9 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -120,12 +120,32 @@ int rte_eal_dev_detach(struct rte_device *dev) return ret; } +static char * +full_dev_name(const char *bus, const char *dev, const char *args) +{ + char *name; + size_t len; + + len = strlen(bus) + 1 + + strlen(dev) + 1 + + strlen(args) + 1; + name = calloc(1, len); + if (name == NULL) { + RTE_LOG(ERR, EAL, "Could not allocate full device name\n"); + return NULL; + } + snprintf(name, len, "%s:%s,%s", bus, dev, + args ? args : ""); + return name; +} + struct rte_device * rte_eal_hotplug_add(const char *busname, const char *devname, const char *devargs) { struct rte_bus *bus; struct rte_device *dev; + char *name; int ret; bus = rte_bus_find_by_name(busname); @@ -142,10 +162,22 @@ rte_eal_hotplug_add(const char *busname, const char *devname, return NULL; } + name = full_dev_name(busname, devname, devargs); + if (name == NULL) { + rte_errno = ENOMEM; + return NULL; + } + + ret = rte_eal_devargs_add(RTE_DEVTYPE_WHITELISTED, name); + if (ret) { + rte_errno = EINVAL; + goto err_name; + } + ret = bus->scan(); if (ret) { rte_errno = -ret; - return NULL; + goto err_name; } dev = bus->find_device(NULL, cmp_detached_dev_name, devname); @@ -153,7 +185,7 @@ rte_eal_hotplug_add(const char *busname, const char *devname, RTE_LOG(ERR, EAL, "Cannot find unplugged device (%s)\n", devname); rte_errno = EINVAL; - return NULL; + goto err_name; } ret = bus->plug(dev, devargs); @@ -161,9 +193,14 @@ rte_eal_hotplug_add(const char *busname, const char *devname, RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n", dev->name); rte_errno = -ret; - return NULL; + goto err_name; } + free(name); return dev; + +err_name: + free(name); + return NULL; } int rte_eal_hotplug_remove(const char *busname, const char *devname) -- 2.1.4