From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f175.google.com (mail-wr0-f175.google.com [209.85.128.175]) by dpdk.org (Postfix) with ESMTP id 598317CAA for ; Tue, 11 Jul 2017 01:19:29 +0200 (CEST) Received: by mail-wr0-f175.google.com with SMTP id r103so159320276wrb.0 for ; Mon, 10 Jul 2017 16:19:29 -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=6Dgfmc+A2B3bFJs2bLel2QIi0Qe468mVn4zhnGTdO7U=; b=jswXlxyeQLzxmFf03OoTRFw8HyVdflF8ThIQcXAynQzrX4ATXoUP0r9Ku6bIFjeSIe WrNJXlCeIdOzv3fHfXes/Wep2LOp047S777n2d0bsTbCrWL0UIQFyBcuGxqrVofgdCNI cmbp2x0F1Cwo4YHpbK4VFDRcRuDCG5B0M2E0aOqI4/aCf1RUm0q8tekBEgjedM7rldnd kpVTkO3OxNj6aW6VPB+IJPU9z/P3BYq/zM8n+BeKdjUBMdikZbSMfdvVytvV+90vK4EB 4tlDFT/59HVVJ0Wv/pGudiKD5ZGYlxQQSETUgyE17qAdjW4/5PiiIAuNCdrevjtJIXG/ ffkw== 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=6Dgfmc+A2B3bFJs2bLel2QIi0Qe468mVn4zhnGTdO7U=; b=jEXYJBPEoydx4FaTEBtB+AwU69DxgDNd9B9q6d2wgnXOl5XgYbixPEvJdw/OWJtMxp C7IGrI0LY2EBUrmk27eiRbBV20A9ovLMn5IztkSnCkgVr4brIvzZeHR+Vngj/iDj0Xti x9YqrDZYhdQx+Nm0adTS7yGGorIF94s0CLqzY4skJxjLy7kwrCWCrK7/QK+dfkW/IFeF 8cOMOOEmc1cLOidljhTArIKSyrUYbQo0rNLs1wiXWY2j3CTo7E/5pRk1mIuZG5gWinwp ck4uX3P0TM+9iBHGO/88E/YwOd3uxCtF0VLUObODpf8ykVgsxmFdNHbW+z5CmUe1e8Vm dT3A== X-Gm-Message-State: AIVw110Q9gMWQrZV2EDd5Vh1TQPQLpwhRFfqEnMkHJLfeFGMSiouHw0f 8Ln9TvLVQAps4/+1HoQ= X-Received: by 10.28.65.66 with SMTP id o63mr361848wma.71.1499728768607; Mon, 10 Jul 2017 16:19:28 -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 j190sm43773wmd.22.2017.07.10.16.19.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Jul 2017 16:19:27 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Tue, 11 Jul 2017 01:19:03 +0200 Message-Id: <5f9ae5a1d9230c96cf7edeff89cc316523732747.1499728330.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 v2 4/8] eal: fix hotplug add / remove 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, 10 Jul 2017 23:19:29 -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. When a device is introduced using the hotplug API, it is implicitly whitelisted. As such, it can conflict with existing bus configuration. The new rte_devargs uses the new rte_eal_devargs_insert function that supersedes previous rte_devargs, allowing to force the insertion of new devices. Upon device removal, the newly allocated rte_devargs are freed. Fixes: a3ee360f4440 ("eal: add hotplug add/remove device") Signed-off-by: Gaetan Rivet --- lib/librte_eal/common/eal_common_dev.c | 57 ++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index 32e12b5..f5566a6 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -118,11 +118,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; +} + int rte_eal_hotplug_add(const char *busname, const char *devname, const char *devargs) { struct rte_bus *bus; struct rte_device *dev; + struct rte_devargs *da; + char *name; int ret; bus = rte_bus_find_by_name(busname); @@ -137,21 +158,49 @@ int rte_eal_hotplug_add(const char *busname, const char *devname, return -ENOTSUP; } + name = full_dev_name(busname, devname, devargs); + if (name == NULL) + return -ENOMEM; + + da = calloc(1, sizeof(*da)); + if (da == NULL) { + ret = -ENOMEM; + goto err_name; + } + + ret = rte_eal_devargs_parse(name, da); + if (ret) + goto err_devarg; + + ret = rte_eal_devargs_insert(da); + if (ret) + goto err_devarg; + ret = bus->scan(); if (ret) - return ret; + goto err_devarg; dev = bus->find_device(NULL, cmp_detached_dev_name, devname); if (dev == NULL) { RTE_LOG(ERR, EAL, "Cannot find unplugged device (%s)\n", devname); - return -EINVAL; + ret = -ENODEV; + goto err_devarg; } ret = bus->plug(dev, devargs); - if (ret) + if (ret) { RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n", dev->name); + goto err_devarg; + } + free(name); + return 0; + +err_devarg: + rte_eal_devargs_remove(busname, devname); +err_name: + free(name); return ret; } @@ -179,6 +228,8 @@ int rte_eal_hotplug_remove(const char *busname, const char *devname) return -EINVAL; } + rte_eal_devargs_remove(busname, devname); + dev->devargs = NULL; ret = bus->unplug(dev); if (ret) RTE_LOG(ERR, EAL, "Driver cannot detach the device (%s)\n", -- 2.1.4