From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by dpdk.org (Postfix) with ESMTP id 2B0771DBC for ; Mon, 30 Apr 2018 16:54:59 +0200 (CEST) Received: by mail-wm0-f65.google.com with SMTP id f6so13669829wmc.4 for ; Mon, 30 Apr 2018 07:54:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=v7XuHctPbLSqinu4GbvwFboEFWwHUzqgjFMqlzncQzc=; b=p1CdWUNw20ACq8ilM91XR9DvSG9wDdOHpFRleogRI3B4LBkF+P7hEGWWMNtNqDGfog XrbaD4BjYmqSLzQJ1COfTwYv8FseIHCjUt6vElE6oAY+yOkVwj4Q5+ybZ6/pENuAOjy9 9OQUExm/SPQlkFxwxfmoqZbemfTK1+DYbkDvXyWR7ILBHPMqPHqIvS3FrodzaCFkgI+Q mRpseYEqpVXvBPtYbjaJ89u5XJ6smQQT71Mb5nGTNTezgysaMxXeuWdbXncOEGEe5lgn PN2Q04N6UmKUdUml6S+THZle8cTRZU9DI5O9yYlrvn8cMr7cc0VCQAEAU40tiXiCSwKb 1f1A== 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; bh=v7XuHctPbLSqinu4GbvwFboEFWwHUzqgjFMqlzncQzc=; b=NitNbcQQjs/VbDsa48yYY4MJk9Wrb6ar8N2xYL8WNZsYR2yL93u0u8zbS+NkzMq+fD plv3J7FyuzNK0SEhLNtaOI87Yz+8bk5pINHkz1uQ6RTAGwBRysNy2vTPWAy+lzpXsI2p nLVMpjIq2JlSFXQLytYp3/U+ZE0p9bi7rDmo4ayIHzIExoIDx4R2INeUwqXUA0tX9HA+ JjdWCktuO3pL62wf6rdKYqkdSLPnpKeIH8drhQH5y7MgS/s5D1lsXxNJN/FeHsSmbBCY pP+ahxl56l6p3AOCvDaxxDE3ifE9x6Y/kcuwvHhI0UsiikZujiyu42ma3LwUL70+s+bM 3itg== X-Gm-Message-State: ALQs6tA/cwBMkLKUWKVgdn4C28W05hW9kDJjqGn39zfXJIikppwxChT0 8FMlPSxmGz7v5++OufX3PAKi30Qm8zo= X-Google-Smtp-Source: AB8JxZrDuVt5qzz0kgxdYiYGsIYXNQ4k0neQNKcxS3MDoie7RWp5bh5/hnW7mIj6ClrEekjuR7XpZQ== X-Received: by 10.28.140.207 with SMTP id o198mr8301280wmd.82.1525100098741; Mon, 30 Apr 2018 07:54:58 -0700 (PDT) Received: from localhost ([2a00:23c5:be9a:5200:ce4c:82c0:d567:ecbb]) by smtp.gmail.com with ESMTPSA id y100sm14960961wmh.2.2018.04.30.07.54.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 30 Apr 2018 07:54:57 -0700 (PDT) From: luca.boccassi@gmail.com To: Matan Azrad Cc: dpdk stable Date: Mon, 30 Apr 2018 15:53:54 +0100 Message-Id: <20180430145402.23057-35-luca.boccassi@gmail.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180430145402.23057-1-luca.boccassi@gmail.com> References: <20180430144223.18657-85-luca.boccassi@gmail.com> <20180430145402.23057-1-luca.boccassi@gmail.com> Subject: [dpdk-stable] patch 'net/vdev_netvsc: prefer netvsc devices in scan' has been queued to stable release 18.02.2 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Apr 2018 14:54:59 -0000 Hi, FYI, your patch has been queued to stable release 18.02.2 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 05/02/18. So please shout if anyone has objections. Thanks. Luca Boccassi --- >>From 9a71a97480e9138429a9c9e432d4b4ed22b9f275 Mon Sep 17 00:00:00 2001 From: Matan Azrad Date: Tue, 10 Apr 2018 13:32:08 +0000 Subject: [PATCH] net/vdev_netvsc: prefer netvsc devices in scan [ upstream commit 4205da3a470974b879d05d337fff2e8bdfec1f70 ] There is an option to run a non-netvsc device as a netvsc device only when the "force" parameter is set to 1 in the EAL command line. Consequently, more than one device may be found to be matching the "mac" parameter specifying the device. Prefer netvsc devices to be scanned before any non-netvsc device, even when the "force" parameter is set. Signed-off-by: Matan Azrad --- drivers/net/vdev_netvsc/vdev_netvsc.c | 122 ++++++++++++++++++---------------- 1 file changed, 65 insertions(+), 57 deletions(-) diff --git a/drivers/net/vdev_netvsc/vdev_netvsc.c b/drivers/net/vdev_netvsc/vdev_netvsc.c index 018ffae5d..75aec8980 100644 --- a/drivers/net/vdev_netvsc/vdev_netvsc.c +++ b/drivers/net/vdev_netvsc/vdev_netvsc.c @@ -97,6 +97,43 @@ vdev_netvsc_ctx_destroy(struct vdev_netvsc_ctx *ctx) free(ctx); } +/** + * Determine if a network interface is NetVSC. + * + * @param[in] iface + * Pointer to netdevice description structure (name and index). + * + * @return + * A nonzero value when interface is detected as NetVSC. In case of error, + * rte_errno is updated and 0 returned. + */ +static int +vdev_netvsc_iface_is_netvsc(const struct if_nameindex *iface) +{ + static const char temp[] = "/sys/class/net/%s/device/class_id"; + char path[sizeof(temp) + IF_NAMESIZE]; + FILE *f; + int ret; + int len = 0; + + ret = snprintf(path, sizeof(path), temp, iface->if_name); + if (ret == -1 || (size_t)ret >= sizeof(path)) { + rte_errno = ENOBUFS; + return 0; + } + f = fopen(path, "r"); + if (!f) { + rte_errno = errno; + return 0; + } + ret = fscanf(f, NETVSC_CLASS_ID "%n", &len); + if (ret == EOF) + rte_errno = errno; + ret = len == (int)strlen(NETVSC_CLASS_ID); + fclose(f); + return ret; +} + /** * Iterate over system network interfaces. * @@ -106,6 +143,8 @@ vdev_netvsc_ctx_destroy(struct vdev_netvsc_ctx *ctx) * @param func * Callback function pointer. List traversal is aborted when this function * returns a nonzero value. + * @param is_netvsc + * Indicates the device type to iterate - netvsc or non-netvsc. * @param ... * Variable parameter list passed as @p va_list to @p func. * @@ -117,7 +156,7 @@ vdev_netvsc_ctx_destroy(struct vdev_netvsc_ctx *ctx) static int vdev_netvsc_foreach_iface(int (*func)(const struct if_nameindex *iface, const struct ether_addr *eth_addr, - va_list ap), ...) + va_list ap), int is_netvsc, ...) { struct if_nameindex *iface = if_nameindex(); int s = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); @@ -135,10 +174,14 @@ vdev_netvsc_foreach_iface(int (*func)(const struct if_nameindex *iface, goto error; } for (i = 0; iface[i].if_name; ++i) { + int is_netvsc_ret; struct ifreq req; struct ether_addr eth_addr; va_list ap; + is_netvsc_ret = vdev_netvsc_iface_is_netvsc(&iface[i]) ? 1 : 0; + if (is_netvsc ^ is_netvsc_ret) + continue; strncpy(req.ifr_name, iface[i].if_name, sizeof(req.ifr_name)); if (ioctl(s, SIOCGIFHWADDR, &req) == -1) { DRV_LOG(WARNING, "cannot retrieve information about" @@ -153,7 +196,7 @@ vdev_netvsc_foreach_iface(int (*func)(const struct if_nameindex *iface, } memcpy(eth_addr.addr_bytes, req.ifr_hwaddr.sa_data, RTE_DIM(eth_addr.addr_bytes)); - va_start(ap, func); + va_start(ap, is_netvsc); ret = func(&iface[i], ð_addr, ap); va_end(ap); if (ret) @@ -167,43 +210,6 @@ error: return ret; } -/** - * Determine if a network interface is NetVSC. - * - * @param[in] iface - * Pointer to netdevice description structure (name and index). - * - * @return - * A nonzero value when interface is detected as NetVSC. In case of error, - * rte_errno is updated and 0 returned. - */ -static int -vdev_netvsc_iface_is_netvsc(const struct if_nameindex *iface) -{ - static const char temp[] = "/sys/class/net/%s/device/class_id"; - char path[sizeof(temp) + IF_NAMESIZE]; - FILE *f; - int ret; - int len = 0; - - ret = snprintf(path, sizeof(path), temp, iface->if_name); - if (ret == -1 || (size_t)ret >= sizeof(path)) { - rte_errno = ENOBUFS; - return 0; - } - f = fopen(path, "r"); - if (!f) { - rte_errno = errno; - return 0; - } - ret = fscanf(f, NETVSC_CLASS_ID "%n", &len); - if (ret == EOF) - rte_errno = errno; - ret = len == (int)strlen(NETVSC_CLASS_ID); - fclose(f); - return ret; -} - /** * Determine if a network interface has a route. * @@ -379,8 +385,6 @@ vdev_netvsc_device_probe(const struct if_nameindex *iface, strncpy(ctx->if_name, iface->if_name, sizeof(ctx->if_name)); return 0; } - if (vdev_netvsc_iface_is_netvsc(iface)) - return 0; if (!is_same_ether_addr(eth_addr, &ctx->if_addr)) return 0; /* Look for associated PCI device. */ @@ -449,7 +453,8 @@ vdev_netvsc_alarm(__rte_unused void *arg) int ret; LIST_FOREACH(ctx, &vdev_netvsc_ctx_list, entry) { - ret = vdev_netvsc_foreach_iface(vdev_netvsc_device_probe, ctx); + ret = vdev_netvsc_foreach_iface(vdev_netvsc_device_probe, 0, + ctx); if (ret < 0) break; } @@ -505,7 +510,6 @@ vdev_netvsc_netvsc_probe(const struct if_nameindex *iface, { const char *name = va_arg(ap, const char *); struct rte_kvargs *kvargs = va_arg(ap, struct rte_kvargs *); - int force = va_arg(ap, int); unsigned int specified = va_arg(ap, unsigned int); unsigned int *matched = va_arg(ap, unsigned int *); unsigned int i; @@ -559,13 +563,6 @@ vdev_netvsc_netvsc_probe(const struct if_nameindex *iface, iface->if_name, iface->if_index); return 0; } - if (!vdev_netvsc_iface_is_netvsc(iface)) { - if (!specified || !force) - return 0; - DRV_LOG(WARNING, - "using non-NetVSC interface \"%s\" (index %u)", - iface->if_name, iface->if_index); - } /* Routed NetVSC should not be probed. */ if (vdev_netvsc_has_route(iface, AF_INET) || vdev_netvsc_has_route(iface, AF_INET6)) { @@ -632,7 +629,7 @@ vdev_netvsc_netvsc_probe(const struct if_nameindex *iface, /* Request virtual device generation. */ DRV_LOG(DEBUG, "generating virtual device \"%s\" with arguments \"%s\"", ctx->devname, ctx->devargs); - vdev_netvsc_foreach_iface(vdev_netvsc_device_probe, ctx); + vdev_netvsc_foreach_iface(vdev_netvsc_device_probe, 0, ctx); ret = rte_eal_hotplug_add("vdev", ctx->devname, ctx->devargs); if (ret) goto error; @@ -709,14 +706,25 @@ vdev_netvsc_vdev_probe(struct rte_vdev_device *dev) } rte_eal_alarm_cancel(vdev_netvsc_alarm, NULL); /* Gather interfaces. */ - ret = vdev_netvsc_foreach_iface(vdev_netvsc_netvsc_probe, name, kvargs, - force, specified, &matched); + ret = vdev_netvsc_foreach_iface(vdev_netvsc_netvsc_probe, 1, name, + kvargs, specified, &matched); if (ret < 0) goto error; - if (matched < specified) - DRV_LOG(WARNING, - "some of the specified parameters did not match" - " recognized network interfaces"); + if (specified && matched < specified) { + if (!force) { + DRV_LOG(ERR, "Cannot find the specified netvsc device"); + goto error; + } + /* Try to force probing on non-netvsc specified device. */ + if (vdev_netvsc_foreach_iface(vdev_netvsc_netvsc_probe, 0, name, + kvargs, specified, &matched) < 0) + goto error; + if (matched < specified) { + DRV_LOG(ERR, "Cannot find the specified device"); + goto error; + } + DRV_LOG(WARNING, "non-netvsc device was probed as netvsc"); + } ret = rte_eal_alarm_set(VDEV_NETVSC_PROBE_MS * 1000, vdev_netvsc_alarm, NULL); if (ret < 0) { -- 2.14.2