From patchwork Tue Jul 11 23:25:38 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: 26835 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 6E1007D00; Wed, 12 Jul 2017 01:26:18 +0200 (CEST) Received: from mail-wr0-f176.google.com (mail-wr0-f176.google.com [209.85.128.176]) by dpdk.org (Postfix) with ESMTP id D1C1B7CC5 for ; Wed, 12 Jul 2017 01:26:02 +0200 (CEST) Received: by mail-wr0-f176.google.com with SMTP id 77so9930573wrb.1 for ; Tue, 11 Jul 2017 16:26:02 -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=rOfdKa30KA7mMqLbTyJb3rUJ1t07dPwfPxosdKi3Dlo=; b=10vIZavBF8rJF/8ck6Xmv1ZWEc3uRI3I5NLdu6qyN2xfFH+NB3w8MeL4bD2graSQ+7 PsATwyi1Jt5Ak7y3e0RbQFsGbw5ZWumoJMe00FkAJ1hzF95em45Nee2/zie+d1LXz6tE KHAOzryON7PCsmArVtkbMXI0DQuEUXrFk+S927CpgeNNPkJrq1BB49B06wH1865hRObX uRXkKdSSwftpDq+wQCzh8B4Gd9EJYjYPbON8DKxkq/OkVGYOUx3v9i+Rix128A5KXFrz xIipuVo3M0Y5ohRVosRzUYSZ97oNVzEBiuhACfn68UeP1x3LMMSRHc3RQynPWVOWnk8H sAiA== 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=rOfdKa30KA7mMqLbTyJb3rUJ1t07dPwfPxosdKi3Dlo=; b=A31St0+TJoX0ejtwBSziSVs8Xb36fZfGGrBs7VzfSAW0kI517YCgAbg9vFpxjNwR+6 pGLgIHrv0KX5fyH/I0sedRBqdBjVLJ1xmIfxIzis+cli5w8OIXaCk+c0vtnUfq4iM12d pxioRDY9GPEogl43auc2+7HXWLjnTf2wsQTRBBB7iDOj1Pebk2fobLOu4IjRi8l/5O1d Wrin8fb+vltW0/HmaG0t7rBEUcQcTtL3Aa60TD4aaK48mq5151q5IZF4SCaoL3Ud/yIP Xj/GrTqIP8D/kaXV+B/apeSrARSFb8qNpX/mEBRTvUAt7iNZP5HKWXdCRP+kG4QZkLMf pi+Q== X-Gm-Message-State: AIVw112Q+6uO7vn29DdShg21WbaXn/bg3xv27OrmpDeruh1JwPFRczYy Yt8N6aHlPPWcwoqnga4= X-Received: by 10.223.145.10 with SMTP id j10mr1087638wrj.172.1499815562222; Tue, 11 Jul 2017 16:26:02 -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 66sm407576wmj.29.2017.07.11.16.26.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 11 Jul 2017 16:26:01 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Wed, 12 Jul 2017 01:25:38 +0200 Message-Id: <1eb5a98019675d97547ec3965738d23b350302ab.1499814957.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 v3 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The hotplug API requires a few properties that were not previously explicitly enforced: - Idempotency, two consecutive scans should result in the same state. - Upon returning, internal devices are now allocated and available through the new `find_device` operator, meaning that they should be identifiable. The current rte_eal_hotplug_add implementation identifies devices by their names, as it is readily available and easy to define. The device name must be passed to the internal rte_device handle in order to be available during scan, when it is then assigned to the device. The current way of passing down this information from the device declaration is through the global rte_devargs list. Furthermore, the rte_device cannot take a bus-specific generated name, as it is then not identifiable by the `find_device` operator. The device must take the user-defined name. Ideally, an rte_device name should not change during its existence. This commit generates a new rte_devargs associated with the plugged device and inserts it in the global rte_devargs list. It consequently releases it upon device removal. 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",