From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by dpdk.org (Postfix) with ESMTP id 54F931BB9A for ; Fri, 11 Jan 2019 21:35:34 +0100 (CET) Received: by mail-pl1-f195.google.com with SMTP id p8so7257225plo.2 for ; Fri, 11 Jan 2019 12:35:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=h9HkD8ZLwGy2kyuiB1QX6Db1tBcyNluhse7XiIZQrB8=; b=UXVX779ktNQWA2gTcDSifG4szJELaytHP92xCjbCbukykRJyUtaLfQZDN9+ZcuNFhE Y3orpd7XeDKeCRkuBc7va5UnIRSHP9pUB4KgS9JoKK0BI6PxNbcuTnvmq8+zt9k+H+K0 6dYrbt8su9/ofQ6EDnWxnxD66/+ORHkzg8509yP8jAkZYybCu2F9/FT6dXMkN1kiQ4DQ POfpZ94r7uRwltAzhNRrJJJhpys6KLnauQ/Xo72xBEwJpYy6DSsx9XJrYMpayWK3946B l3SLUWEHKxy5c1S/cV6THqNRY/5M/HExq1Ajj5MFsOqEHL0gbV9d94YH6gsna9tPlUPe A4zQ== 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:mime-version:content-transfer-encoding; bh=h9HkD8ZLwGy2kyuiB1QX6Db1tBcyNluhse7XiIZQrB8=; b=PW1LsIH7wxPTSWtCesB3zVqjZNiRVXUz14SmW6dmY9pFPpG+B1SilJwsbuD8gcCABt oDQNp1mCPsQFk4LWGw0jiIIZxMr0lciMEagVNivyUrbjXubtxya34ADTgehV/DDI7rxj siUAybLy0X/ToZlrQbYYH6n1WWEireawazr0essphbNjDv8c/S5adZ/1FnI3d9XgUkxw GB7cvinPfolXhMBeF0Uxxg4a2CG6x3gxSTeb6GXiElV0YW4G9J5CwBQasuNowkLd7a6U 2u2hmIufnFKNIbXfJYuJfCbyVOuVxTs92kH+Hk1j5JiXjGCuyMOJC6hVCAP6Ek4hhBU0 RkIQ== X-Gm-Message-State: AJcUukd71V18xYjBK2xj6emSCGEPS+qYOlt1I3/CZIk4E7L67bC5SQdF 5N+aRm6Yye2pPS5DMrojuIEm8A== X-Google-Smtp-Source: ALg8bN6scL/ZqX6TphCwTSiAgyFFF8HWk9DP1V3w+ZuRQV2KVNjzqt7VsyRzfZECHOXKgnnTzANsIg== X-Received: by 2002:a17:902:4523:: with SMTP id m32mr15996795pld.53.1547238933474; Fri, 11 Jan 2019 12:35:33 -0800 (PST) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id f32sm96610438pgf.80.2019.01.11.12.35.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Jan 2019 12:35:32 -0800 (PST) From: Stephen Hemminger To: keith.wiles@intel.com Cc: dev@dpdk.org, Stephen Hemminger , hfli@netitest.com Date: Fri, 11 Jan 2019 12:35:18 -0800 Message-Id: <20190111203520.19944-6-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190111203520.19944-1-stephen@networkplumber.org> References: <20190111180659.5972-1-stephen@networkplumber.org> <20190111203520.19944-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2 5/7] net/tap: let kernel choose tun device name 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: Fri, 11 Jan 2019 20:35:34 -0000 Assigning tun and tap index in DPDK tap device driver is racy and fails if used with primary/secondary. Instead use the kernel feature of device wildcarding where if a name with %d is used the kernel will fill in the next available device. Reported-by: hfli@netitest.com Fixes: 02f96a0a82d1 ("net/tap: add TUN/TAP device PMD") Signed-off-by: Stephen Hemminger Acked-by Keith Wiles --- drivers/net/tap/rte_eth_tap.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c index d699b4fb095d..ed8483cb96bc 100644 --- a/drivers/net/tap/rte_eth_tap.c +++ b/drivers/net/tap/rte_eth_tap.c @@ -79,9 +79,6 @@ static const char *valid_arguments[] = { NULL }; -static unsigned int tap_unit; -static unsigned int tun_unit; - static char tuntap_name[8]; static volatile uint32_t tap_trigger; /* Rx trigger */ @@ -151,8 +148,6 @@ tun_alloc(struct pmd_internals *pmd, int is_keepalive) IFF_TAP : IFF_TUN | IFF_POINTOPOINT; strlcpy(ifr.ifr_name, pmd->name, IFNAMSIZ); - TAP_LOG(DEBUG, "ifr_name '%s'", ifr.ifr_name); - fd = open(TUN_TAP_DEV_PATH, O_RDWR); if (fd < 0) { TAP_LOG(ERR, "Unable to create %s interface", tuntap_name); @@ -186,6 +181,13 @@ tun_alloc(struct pmd_internals *pmd, int is_keepalive) goto error; } + /* + * Name passed to kernel might be wildcard like dtun%d + * and need to find the resulting device. + */ + TAP_LOG(DEBUG, "Device name is '%s'", ifr.ifr_name); + strlcpy(pmd->name, ifr.ifr_name, RTE_ETH_NAME_MAX_LEN); + if (is_keepalive) { /* * Detach the TUN/TAP keep-alive queue @@ -1756,6 +1758,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name, TAP_LOG(ERR, "Unable to create %s interface", tuntap_name); goto error_exit; } + TAP_LOG(DEBUG, "allocated %s", pmd->name); ifr.ifr_mtu = dev->data->mtu; if (tap_ioctl(pmd, SIOCSIFMTU, &ifr, 1, LOCAL_AND_REMOTE) < 0) @@ -1918,8 +1921,8 @@ set_interface_name(const char *key __rte_unused, } strlcpy(name, value, RTE_ETH_NAME_MAX_LEN); } else { - snprintf(name, RTE_ETH_NAME_MAX_LEN, "%s%d", - DEFAULT_TAP_NAME, tap_unit - 1); + /* use tap%d which causes kernel to choose next available */ + strlcpy(name, DEFAULT_TAP_NAME "%d", RTE_ETH_NAME_MAX_LEN); } return 0; } @@ -2032,8 +2035,8 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev) return 0; } - snprintf(tun_name, sizeof(tun_name), "%s%u", - DEFAULT_TUN_NAME, tun_unit++); + /* use tun%d which causes kernel to choose next available */ + strlcpy(tun_name, DEFAULT_TUN_NAME "%d", RTE_ETH_NAME_MAX_LEN); if (params && (params[0] != '\0')) { TAP_LOG(DEBUG, "parameters (%s)", params); @@ -2053,17 +2056,15 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev) } pmd_link.link_speed = ETH_SPEED_NUM_10G; - TAP_LOG(DEBUG, "Initializing pmd_tun for %s as %s", - name, tun_name); + TAP_LOG(DEBUG, "Initializing pmd_tun for %s", name); ret = eth_dev_tap_create(dev, tun_name, remote_iface, 0, - ETH_TUNTAP_TYPE_TUN); + ETH_TUNTAP_TYPE_TUN); leave: if (ret == -1) { TAP_LOG(ERR, "Failed to create pmd for %s as %s", name, tun_name); - tun_unit--; /* Restore the unit number */ } rte_kvargs_free(kvlist); @@ -2219,8 +2220,9 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev) } speed = ETH_SPEED_NUM_10G; - snprintf(tap_name, sizeof(tap_name), "%s%u", - DEFAULT_TAP_NAME, tap_unit++); + + /* use tap%d which causes kernel to choose next available */ + strlcpy(tap_name, DEFAULT_TAP_NAME "%d", RTE_ETH_NAME_MAX_LEN); memset(remote_iface, 0, RTE_ETH_NAME_MAX_LEN); if (params && (params[0] != '\0')) { @@ -2283,7 +2285,6 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev) rte_mp_action_unregister(TAP_MP_KEY); tap_devices_count--; } - tap_unit--; /* Restore the unit number */ } rte_kvargs_free(kvlist); -- 2.20.1