From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by dpdk.org (Postfix) with ESMTP id B65AA11A4; Tue, 12 Mar 2019 08:14:04 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Mar 2019 00:14:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,470,1544515200"; d="scan'208";a="126186401" Received: from dpdk-tbie.sh.intel.com ([10.67.104.173]) by orsmga006.jf.intel.com with ESMTP; 12 Mar 2019 00:14:01 -0700 From: Tiwei Bie To: maxime.coquelin@redhat.com, zhihong.wang@intel.com, dev@dpdk.org Cc: stephen@networkplumber.org, ferruh.yigit@intel.com, stable@dpdk.org Date: Tue, 12 Mar 2019 15:13:07 +0800 Message-Id: <20190312071307.19393-1-tiwei.bie@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-dev] [PATCH] net/virtio-user: fix multiqueue support with vhost kernel 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: Tue, 12 Mar 2019 07:14:05 -0000 The multiqueue support in virtio-user with vhost kernel backend is broken when tap name isn't specified by users explicitly, because the tap name returned by ioctl(TUNSETIFF) isn't saved properly, and multiple tap interfaces will be created in this case. Fix this by saving the dynamically allocated tap name first before reusing the ifr structure. Besides, also make it possible to support the format string in tap name (e.g. foo%d) specified by users explicitly. Fixes: 791b43e08842 ("net/virtio-user: specify MAC of the tap") Cc: stable@dpdk.org Reported-by: Stephen Hemminger Signed-off-by: Tiwei Bie --- drivers/net/virtio/virtio_user/vhost_kernel_tap.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/net/virtio/virtio_user/vhost_kernel_tap.c b/drivers/net/virtio/virtio_user/vhost_kernel_tap.c index a3faf1d0c..fbd9e979d 100644 --- a/drivers/net/virtio/virtio_user/vhost_kernel_tap.c +++ b/drivers/net/virtio/virtio_user/vhost_kernel_tap.c @@ -62,6 +62,7 @@ vhost_kernel_open_tap(char **p_ifname, int hdr_size, int req_mq, const char *mac, uint64_t features) { unsigned int tap_features; + char *tap_name = NULL; int sndbuf = INT_MAX; struct ifreq ifr; int tapfd; @@ -112,6 +113,12 @@ vhost_kernel_open_tap(char **p_ifname, int hdr_size, int req_mq, goto error; } + tap_name = strdup(ifr.ifr_name); + if (!tap_name) { + PMD_DRV_LOG(ERR, "strdup ifname failed: %s", strerror(errno)); + goto error; + } + fcntl(tapfd, F_SETFL, O_NONBLOCK); if (ioctl(tapfd, TUNSETVNETHDRSZ, &hdr_size) < 0) { @@ -134,11 +141,12 @@ vhost_kernel_open_tap(char **p_ifname, int hdr_size, int req_mq, goto error; } - if (!(*p_ifname)) - *p_ifname = strdup(ifr.ifr_name); + free(*p_ifname); + *p_ifname = tap_name; return tapfd; error: + free(tap_name); close(tapfd); return -1; } -- 2.17.1