From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gaetan.rivet@6wind.com>
Received: from mail-wr0-f177.google.com (mail-wr0-f177.google.com
 [209.85.128.177]) by dpdk.org (Postfix) with ESMTP id D52F35598
 for <dev@dpdk.org>; Sun,  9 Jul 2017 03:46:02 +0200 (CEST)
Received: by mail-wr0-f177.google.com with SMTP id 77so93679174wrb.1
 for <dev@dpdk.org>; Sat, 08 Jul 2017 18:46: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=VYNWAvyDr5893tewEoemSN8NIYd+/n5sbCbm94F7DEI=;
 b=P/2SCgLPamjGlkdNuvOuk10IAQxsAvI+gPtMN3jakWRpCt9dF5M7hyPs+iIwqMrFNV
 mld+oa4jHiewJ7ZDV9zQBHz5CMspfWaLChlsnn6frFgyirmxgUctPHXpsBPzBkDPMHRN
 m1wS3CLX4GJCp/7+pvqwODmx4fmEaDJfq0L24Rx5m32SS47aNpWSfl94174qOep/nDJl
 QgdnPmnXeQtXv42yuUfhqMPP6PhYGgitdfdoQa8y7YHQO3uSL8y1HAx4z2GPanHIYTkB
 EhTztUecl3YUBDLNGg3sWKkVDtGu+PY1HAdjNxdAEc50wZYqf6y+jeCXSce6dwznyUTM
 hEWA==
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=VYNWAvyDr5893tewEoemSN8NIYd+/n5sbCbm94F7DEI=;
 b=UM19LVuKAK2YcAAStGixypwDW6uzsYBSjGZ53z313mP4sIBChrvBY7qhDV6twebO8u
 oMpgsB5Yzj8L+EOmp7TpFqvdnQ7YEWB/U0Xwgs1aulADI4E21aqZV20SOlEC3UmoApW1
 +homGD/qOEXrtf9Wr/zRnFafzRdno/2MTSyn3banxkh8oi98T0XiCigfoKFtEeU5OBKV
 p64Ol76Vb1XdD2o4pTQTrUKlGQTuKXrNk+AKQaulARYTHXDLXr0495+uEsOQ14gxk2iK
 85Ent7UsSMr2dRmvjicRvIAXjdcoVfhYr3ro3V9XS61YmkvQUZ1/E4FMRPAF9xfqPDWq
 Dq1g==
X-Gm-Message-State: AIVw110ORlaO2+wvK09W6BABOrPI3Br+R+DdC/8Dz0OJkRgqKp8ZtojZ
 y8x04tU+P2rEGfRNd5o=
X-Received: by 10.28.147.200 with SMTP id v191mr3414656wmd.95.1499564762024;
 Sat, 08 Jul 2017 18:46: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 h130sm2430609wmd.34.2017.07.08.18.46.00
 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);
 Sat, 08 Jul 2017 18:46:01 -0700 (PDT)
From: Gaetan Rivet <gaetan.rivet@6wind.com>
To: dev@dpdk.org
Cc: Gaetan Rivet <gaetan.rivet@6wind.com>
Date: Sun,  9 Jul 2017 03:45:39 +0200
Message-Id: <42bfad3c65a3ea99418c2e44e472779287dfed8a.1499563730.git.gaetan.rivet@6wind.com>
X-Mailer: git-send-email 2.1.4
In-Reply-To: <cover.1499563730.git.gaetan.rivet@6wind.com>
References: <cover.1499563730.git.gaetan.rivet@6wind.com>
In-Reply-To: <cover.1499563730.git.gaetan.rivet@6wind.com>
References: <cover.1499563730.git.gaetan.rivet@6wind.com>
Subject: [dpdk-dev] [PATCH 3/9] devargs: introduce removal function
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Sun, 09 Jul 2017 01:46:03 -0000

Hotplug support introduces the possibility of removing devices from the
system. Allocated resources must be freed.

Extend the rte_devargs API to allow freeing allocated resources.

This API is experimental and bound to change. It is currently designed
as a symetrical to rte_eal_devargs_add(), but the latter will evolve
shortly anyway.

Its DEVTYPE parameter is currently only used to specify scan policies,
and those will evolve in the next release. This evolution should
rationalize the rte_devargs API.

As such, the proposed API here is not the most convenient, but is
taylored to follow the current design and integrate easily with its main
use within rte_eal_hotplug_* functions.

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  1 +
 lib/librte_eal/common/eal_common_devargs.c      | 18 ++++++++++++++++++
 lib/librte_eal/common/include/rte_devargs.h     | 18 ++++++++++++++++++
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  1 +
 4 files changed, 38 insertions(+)

diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 381f895..d3cf1ae 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -207,6 +207,7 @@ EXPERIMENTAL {
 	global:
 
 	rte_eal_devargs_parse;
+	rte_eal_devargs_rmv;
 	rte_eal_hotplug_add;
 	rte_eal_hotplug_remove;
 
diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
index 49d43a3..4a89282 100644
--- a/lib/librte_eal/common/eal_common_devargs.c
+++ b/lib/librte_eal/common/eal_common_devargs.c
@@ -41,6 +41,7 @@
 #include <string.h>
 
 #include <rte_devargs.h>
+#include <rte_tailq.h>
 #include "eal_private.h"
 
 /** Global list of user devices */
@@ -182,6 +183,23 @@ rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
 	return -1;
 }
 
+int
+rte_eal_devargs_rmv(const char *busname, const char *devname)
+{
+	struct rte_devargs *d;
+	void *tmp;
+
+	TAILQ_FOREACH_SAFE(d, &devargs_list, next, tmp) {
+		if (strcmp(d->bus->name, busname) == 0 &&
+		    strcmp(d->name, devname) == 0) {
+			TAILQ_REMOVE(&devargs_list, d, next);
+			free(d->args);
+			free(d);
+		}
+	}
+	return 1;
+}
+
 /* count the number of devices of a specified type */
 unsigned int
 rte_eal_devargs_type_count(enum rte_devtype devtype)
diff --git a/lib/librte_eal/common/include/rte_devargs.h b/lib/librte_eal/common/include/rte_devargs.h
index a0427cd..89679bb 100644
--- a/lib/librte_eal/common/include/rte_devargs.h
+++ b/lib/librte_eal/common/include/rte_devargs.h
@@ -163,6 +163,24 @@ rte_eal_devargs_parse(const char *dev,
 int rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str);
 
 /**
+ * Remove a device from the user device list.
+ * Its resources are freed.
+ * If the devargs cannot be found, nothing happens.
+ *
+ * @param busname
+ *   bus name of the devargs to remove.
+ *
+ * @param devname
+ *   device name of the devargs to remove.
+ *
+ * @return
+ *   0 on success.
+ *   <0 on error.
+ *   >0 if the devargs was not within the user device list.
+ */
+int rte_eal_devargs_rmv(const char *busname, const char *devname);
+
+/**
  * Count the number of user devices of a specified type
  *
  * @param devtype
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index 0f9e009..d59308a 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -212,6 +212,7 @@ EXPERIMENTAL {
 	global:
 
 	rte_eal_devargs_parse;
+	rte_eal_devargs_rmv;
 	rte_eal_hotplug_add;
 	rte_eal_hotplug_remove;
 
-- 
2.1.4