From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id A4D20A04B5; Wed, 30 Sep 2020 10:35:08 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 836FB1D695; Wed, 30 Sep 2020 10:35:07 +0200 (CEST) Received: from huawei.com (szxga01-in.huawei.com [45.249.212.187]) by dpdk.org (Postfix) with ESMTP id 0607B1D68D for ; Wed, 30 Sep 2020 10:35:05 +0200 (CEST) Received: from DGGEMM401-HUB.china.huawei.com (unknown [172.30.72.55]) by Forcepoint Email with ESMTP id 983EDF38B1BBD50AAAB1; Wed, 30 Sep 2020 16:35:02 +0800 (CST) Received: from DGGEMM533-MBX.china.huawei.com ([169.254.5.102]) by DGGEMM401-HUB.china.huawei.com ([10.3.20.209]) with mapi id 14.03.0487.000; Wed, 30 Sep 2020 16:34:58 +0800 From: wangyunjian To: Thomas Monjalon , "dev@dpdk.org" CC: "ferruh.yigit@intel.com" , "arybchenko@solarflare.com" , Keith Wiles , Anatoly Burakov Thread-Topic: [PATCH v3 20/29] net/tap: release port upon close Thread-Index: AQHWle1HtnSwC+WnWki5QDIVn1hRBamA1icA Date: Wed, 30 Sep 2020 08:34:58 +0000 Message-ID: <34EFBCA9F01B0748BEB6B629CE643AE60DA7FA82@DGGEMM533-MBX.china.huawei.com> References: <20200913220711.3768597-1-thomas@monjalon.net> <20200928231437.414489-1-thomas@monjalon.net> <20200928231437.414489-21-thomas@monjalon.net> In-Reply-To: <20200928231437.414489-21-thomas@monjalon.net> Accept-Language: en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.174.185.168] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-CFilter-Loop: Reflected Subject: Re: [dpdk-dev] [PATCH v3 20/29] net/tap: release port upon close 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" I have checked and tested it, no issue found. Thanks, Yunjian > -----Original Message----- > From: Thomas Monjalon [mailto:thomas@monjalon.net] > Sent: Tuesday, September 29, 2020 7:14 AM > To: dev@dpdk.org > Cc: ferruh.yigit@intel.com; arybchenko@solarflare.com; wangyunjian > ; Keith Wiles ; Anatoly > Burakov > Subject: [PATCH v3 20/29] net/tap: release port upon close >=20 > From: Yunjian Wang >=20 > The flag RTE_ETH_DEV_CLOSE_REMOVE is set so all port resources can be > freed by rte_eth_dev_close(). >=20 > Freeing of private port resources is moved from the ".remove(device)" to = the > ".dev_close(port)" operation. >=20 > Signed-off-by: Yunjian Wang > Signed-off-by: Thomas Monjalon > --- > drivers/net/tap/rte_eth_tap.c | 51 +++++++++++++++++++---------------- > 1 file changed, 28 insertions(+), 23 deletions(-) >=20 > diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.= c index > 2d1e4e365a..0d217f1486 100644 > --- a/drivers/net/tap/rte_eth_tap.c > +++ b/drivers/net/tap/rte_eth_tap.c > @@ -72,6 +72,10 @@ >=20 > static int tap_devices_count; >=20 > +static const char *tuntap_types[ETH_TUNTAP_TYPE_MAX] =3D { > + "UNKNOWN", "TUN", "TAP" > +}; > + > static const char *valid_arguments[] =3D { > ETH_TAP_IFACE_ARG, > ETH_TAP_REMOTE_ARG, > @@ -1075,6 +1079,11 @@ tap_dev_close(struct rte_eth_dev *dev) > struct pmd_process_private *process_private =3D dev->process_private; > struct rx_queue *rxq; >=20 > + if (rte_eal_process_type() !=3D RTE_PROC_PRIMARY) { > + rte_free(dev->process_private); > + return 0; > + } > + > tap_link_set_down(dev); > if (internals->nlsk_fd !=3D -1) { > tap_flow_flush(dev, NULL); > @@ -1112,6 +1121,23 @@ tap_dev_close(struct rte_eth_dev *dev) > close(internals->ka_fd); > internals->ka_fd =3D -1; > } > + > + /* mac_addrs must not be freed alone because part of dev_private */ > + dev->data->mac_addrs =3D NULL; > + > + internals =3D dev->data->dev_private; > + TAP_LOG(DEBUG, "Closing %s Ethernet device on numa %u", > + tuntap_types[internals->type], rte_socket_id()); > + > + if (internals->ioctl_sock !=3D -1) { > + close(internals->ioctl_sock); > + internals->ioctl_sock =3D -1; > + } > + rte_free(dev->process_private); > + dev->process_private =3D NULL; > + if (tap_devices_count =3D=3D 1) > + rte_mp_action_unregister(TAP_MP_KEY); > + tap_devices_count--; > /* > * Since TUN device has no more opened file descriptors > * it will be removed from kernel > @@ -1845,10 +1871,6 @@ static const struct eth_dev_ops ops =3D { > .filter_ctrl =3D tap_dev_filter_ctrl, > }; >=20 > -static const char *tuntap_types[ETH_TUNTAP_TYPE_MAX] =3D { > - "UNKNOWN", "TUN", "TAP" > -}; > - > static int > eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name, > char *remote_iface, struct rte_ether_addr *mac_addr, @@ > -1900,7 +1922,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const > char *tap_name, > /* Setup some default values */ > data =3D dev->data; > data->dev_private =3D pmd; > - data->dev_flags =3D RTE_ETH_DEV_INTR_LSC; > + data->dev_flags =3D RTE_ETH_DEV_INTR_LSC | > RTE_ETH_DEV_CLOSE_REMOVE; > data->numa_node =3D numa_node; >=20 > data->dev_link =3D pmd_link; > @@ -2492,30 +2514,13 @@ static int > rte_pmd_tap_remove(struct rte_vdev_device *dev) { > struct rte_eth_dev *eth_dev =3D NULL; > - struct pmd_internals *internals; >=20 > /* find the ethdev entry */ > eth_dev =3D rte_eth_dev_allocated(rte_vdev_device_name(dev)); > if (!eth_dev) > - return -ENODEV; > - > - /* mac_addrs must not be freed alone because part of dev_private */ > - eth_dev->data->mac_addrs =3D NULL; > - > - if (rte_eal_process_type() !=3D RTE_PROC_PRIMARY) > - return rte_eth_dev_release_port(eth_dev); > + return 0; >=20 > tap_dev_close(eth_dev); > - > - internals =3D eth_dev->data->dev_private; > - TAP_LOG(DEBUG, "Closing %s Ethernet device on numa %u", > - tuntap_types[internals->type], rte_socket_id()); > - > - close(internals->ioctl_sock); > - rte_free(eth_dev->process_private); > - if (tap_devices_count =3D=3D 1) > - rte_mp_action_unregister(TAP_MP_KEY); > - tap_devices_count--; > rte_eth_dev_release_port(eth_dev); >=20 > return 0; > -- > 2.28.0