From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <jblunck@gmail.com>
Received: from mail-wr0-f193.google.com (mail-wr0-f193.google.com
 [209.85.128.193]) by dpdk.org (Postfix) with ESMTP id 7E08B2C1A
 for <dev@dpdk.org>; Wed, 12 Jul 2017 10:27:35 +0200 (CEST)
Received: by mail-wr0-f193.google.com with SMTP id x23so4068736wrb.0
 for <dev@dpdk.org>; Wed, 12 Jul 2017 01:27:35 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=mime-version:sender:in-reply-to:references:from:date:message-id
 :subject:to:cc;
 bh=mNB96APpyPjgMaq/nNjsqJXLDX36vkSQUz4qZgJH4iQ=;
 b=KIewOjmFgacxHXojHqCo90Ne+Dvrrb9kk9RZ+CTSP4N7RRvzMhWKGLnO5GNkxShD8/
 lNeo2q40jNayw8zSEzJ5uTckkXrXDLvIoi5UDQaCGX6DLCF88RJzKlIIo08UG8cYuQUg
 cJZcQPZJX3VyzWW9qMoT4VaZ5PtPrcaFjgxxlfMn383RNiXgA9acuuzrzAQbBc8Ye1Zh
 Tmk/SwikBjtsr5k79ahOfSrvw6XeVrUvu7As8qgJAqM3LcI07Oxf2oXvCuafNvIIrnon
 qPfHIey1dsbldmeuHKWrJzVyRUHMPFDGbMPEstaliOzCsNLvVUvPpDeeOGqzsdau7aus
 pFQw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:mime-version:sender:in-reply-to:references:from
 :date:message-id:subject:to:cc;
 bh=mNB96APpyPjgMaq/nNjsqJXLDX36vkSQUz4qZgJH4iQ=;
 b=YhflWocA8LYz8C5Dby+qRGIGZadR7Mr3UDfU+sdz4PacMYC6Q+VRN/ivS8O19WSJWp
 JGA+lyFX2HczXMEJlIIGkceB/9Z8MJjRCri/SwOvSafleyWfgBnDGQPz26UVLagXuvT4
 cVrCz3JdSHD8JnT1qkWX4uKh10X6Sq05ck9XcOxL2jyectNAEkHpwOgz2VGSmkBMwZuW
 di0ISTdyoaB5+rZeShpf82GDCqC5JavpPJ1jJ36drXrICbeFB0SErjFv9YRCo8qXoP1O
 m32FBTzT/uvLSqRHmwBlF3OEHo+EuFhDI8TL1RqqZLawqCntOc4UIze0TpQyU+bOOeL6
 oKbw==
X-Gm-Message-State: AIVw111u6o0jO0P3F9QF17jf/ieg5Iw1wlGio7+zbOkFz6m0BdTZKXOt
 e4BL0vLLQT4uw4zC4TKLIOPW6+EYEw==
X-Received: by 10.223.133.211 with SMTP id 19mr2070096wru.27.1499848055132;
 Wed, 12 Jul 2017 01:27:35 -0700 (PDT)
MIME-Version: 1.0
Sender: jblunck@gmail.com
Received: by 10.28.45.210 with HTTP; Wed, 12 Jul 2017 01:27:34 -0700 (PDT)
In-Reply-To: <7d819b3f9666620afa3324e47de7698a7e203328.1499814957.git.gaetan.rivet@6wind.com>
References: <cover.1499728330.git.gaetan.rivet@6wind.com>
 <cover.1499814957.git.gaetan.rivet@6wind.com>
 <7d819b3f9666620afa3324e47de7698a7e203328.1499814957.git.gaetan.rivet@6wind.com>
From: Jan Blunck <jblunck@infradead.org>
Date: Wed, 12 Jul 2017 04:27:34 -0400
X-Google-Sender-Auth: -TmSV63yPt_ue0cS7MDQQdbsidA
Message-ID: <CALe+Z02bsS_1bZtRWRVWhB9xky2c_Tg5ey5ypFmpRY-jDFw++A@mail.gmail.com>
To: Gaetan Rivet <gaetan.rivet@6wind.com>
Cc: dev <dev@dpdk.org>
Content-Type: text/plain; charset="UTF-8"
Subject: Re: [dpdk-dev] [PATCH v3 2/8] 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: Wed, 12 Jul 2017 08:27:35 -0000

On Tue, Jul 11, 2017 at 7:25 PM, Gaetan Rivet <gaetan.rivet@6wind.com> wrote:
> 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.

I don't think that this is safe to do. The rte_device is using a
reference to the allocated rte_devargs so before we remove it we need
to make sure that the device is gone.

Besides that the comment says that its current user is inside the EAL
so I wonder why it is exported.

> 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      | 19 +++++++++++++++++++
>  lib/librte_eal/common/include/rte_devargs.h     | 18 ++++++++++++++++++
>  lib/librte_eal/linuxapp/eal/rte_eal_version.map |  1 +
>  4 files changed, 39 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..40cd523 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_remove;
>         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..bcdee13 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,24 @@ rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
>         return -1;
>  }
>
> +int
> +rte_eal_devargs_remove(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 0;
> +               }
> +       }
> +       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..36453b6 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_remove(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..a8ee349 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_remove;
>         rte_eal_hotplug_add;
>         rte_eal_hotplug_remove;
>
> --
> 2.1.4
>