From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <3chas3@gmail.com> Received: from mail-qk0-f176.google.com (mail-qk0-f176.google.com [209.85.220.176]) by dpdk.org (Postfix) with ESMTP id CAD768D9E for ; Fri, 2 Oct 2015 17:00:18 +0200 (CEST) Received: by qkcf65 with SMTP id f65so43772433qkc.3 for ; Fri, 02 Oct 2015 08:00:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=5r13Cnl6jyeQKlXMutTiytVYrDmmPwsH7pW79coIiW4=; b=o6cbN2kf6RDa4IHQH1iDk6JyZ3vSJxvItOqr59Dq3NlKpWkp1n+rBX4b5oah0A/GGk T/YSVjqt9TUJIdE/9Jqbg+bmJJ9ipJqIOge4lCD9IYP9m95neBitfDVf5+4nwCc1oMCx wCwNGggyN5eeOch6jfWMozjvf8ykT2sYe+6lFtMjF5yAE9qGDU9RRcKYFlGWluHSreNG yr7kOmYn1yX9CQ0mvR5cumuNGWs23EdktCFtVqWQHCYeaxkRAB2HSgPUEnioTMhhhpx7 16/ji5ADqO9CG1skS9Le9k/gee8sP9GCcws+6KeC5EXadlTN1741nA5is2/7Vz0SbFrd rd5g== X-Received: by 10.55.31.72 with SMTP id f69mr2080726qkf.94.1443798015811; Fri, 02 Oct 2015 08:00:15 -0700 (PDT) Received: from foobar.home (pool-71-163-182-126.washdc.fios.verizon.net. [71.163.182.126]) by smtp.gmail.com with ESMTPSA id z19sm4784417qge.38.2015.10.02.08.00.15 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Oct 2015 08:00:15 -0700 (PDT) From: Chas Williams <3chas3@gmail.com> To: dev@dpdk.org Date: Fri, 2 Oct 2015 11:00:07 -0400 Message-Id: <1443798007-20122-1-git-send-email-3chas3@gmail.com> X-Mailer: git-send-email 2.1.0 Subject: [dpdk-dev] [PATCH] devargs: add blacklisting by linux interface name X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Oct 2015 15:00:19 -0000 If a system is using deterministic interface names, it may be easier in some cases to use the interface name to blacklist an interface. Signed-off-by: Chas Williams <3chas3@gmail.com> --- app/test/test_devargs.c | 2 ++ lib/librte_eal/common/eal_common_devargs.c | 8 ++++++++ lib/librte_eal/common/eal_common_options.c | 10 ++++++++++ lib/librte_eal/common/eal_common_pci.c | 17 +++++++++++------ lib/librte_eal/common/eal_options.h | 2 ++ lib/librte_eal/common/include/rte_devargs.h | 5 +++++ lib/librte_eal/common/include/rte_pci.h | 1 + lib/librte_eal/linuxapp/eal/eal_pci.c | 15 +++++++++++++++ 8 files changed, 54 insertions(+), 6 deletions(-) diff --git a/app/test/test_devargs.c b/app/test/test_devargs.c index f7fc59c..c204c49 100644 --- a/app/test/test_devargs.c +++ b/app/test/test_devargs.c @@ -85,6 +85,8 @@ test_devargs(void) goto fail; if (rte_eal_devargs_type_count(RTE_DEVTYPE_VIRTUAL) != 2) goto fail; + if (rte_eal_devargs_add(RTE_DEVTYPE_BLACKLISTED_NAME, "eth0") < 0) + goto fail; free_devargs_list(); /* check virtual device with argument parsing */ diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c index ec56165..cac651b 100644 --- a/lib/librte_eal/common/eal_common_devargs.c +++ b/lib/librte_eal/common/eal_common_devargs.c @@ -113,6 +113,14 @@ rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str) goto fail; break; + case RTE_DEVTYPE_BLACKLISTED_NAME: + /* save interface name */ + ret = snprintf(devargs->name.name, + sizeof(devargs->name.name), "%s", buf); + if (ret < 0 || ret >= (int)sizeof(devargs->name.name)) + goto fail; + + break; } free(buf); diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c index 1f459ac..c08126d 100644 --- a/lib/librte_eal/common/eal_common_options.c +++ b/lib/librte_eal/common/eal_common_options.c @@ -90,6 +90,7 @@ eal_long_options[] = { {OPT_VFIO_INTR, 1, NULL, OPT_VFIO_INTR_NUM }, {OPT_VMWARE_TSC_MAP, 0, NULL, OPT_VMWARE_TSC_MAP_NUM }, {OPT_XEN_DOM0, 0, NULL, OPT_XEN_DOM0_NUM }, + {OPT_BLACKLISTED_NAME, 1, NULL, OPT_BLACKLISTED_NAME_NUM }, {0, 0, NULL, 0 } }; @@ -785,6 +786,13 @@ eal_parse_common_option(int opt, const char *optarg, } break; + case OPT_BLACKLISTED_NAME_NUM: + if (rte_eal_devargs_add(RTE_DEVTYPE_BLACKLISTED_NAME, + optarg) < 0) { + return -1; + } + break; + /* don't know what to do, leave this to caller */ default: return 1; @@ -898,6 +906,8 @@ eal_common_usage(void) " --"OPT_VDEV" Add a virtual device.\n" " The argument format is [,key=val,...]\n" " (ex: --vdev=eth_pcap0,iface=eth2).\n" + " --"OPT_BLACKLISTED_NAME" Add a device name to the black list.\n" + " Prevent EAL from using this named interface.\n" " --"OPT_VMWARE_TSC_MAP" Use VMware TSC map instead of native RDTSC\n" " --"OPT_PROC_TYPE" Type of this process (primary|secondary|auto)\n" " --"OPT_SYSLOG" Set syslog facility\n" diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c index dcfe947..41a7690 100644 --- a/lib/librte_eal/common/eal_common_pci.c +++ b/lib/librte_eal/common/eal_common_pci.c @@ -90,11 +90,15 @@ static struct rte_devargs *pci_devargs_lookup(struct rte_pci_device *dev) struct rte_devargs *devargs; TAILQ_FOREACH(devargs, &devargs_list, next) { - if (devargs->type != RTE_DEVTYPE_BLACKLISTED_PCI && - devargs->type != RTE_DEVTYPE_WHITELISTED_PCI) - continue; - if (!rte_eal_compare_pci_addr(&dev->addr, &devargs->pci.addr)) - return devargs; + if (devargs->type == RTE_DEVTYPE_BLACKLISTED_PCI || + devargs->type == RTE_DEVTYPE_WHITELISTED_PCI) { + if (!rte_eal_compare_pci_addr(&dev->addr, &devargs->pci.addr)) + return devargs; + } + if (devargs->type == RTE_DEVTYPE_BLACKLISTED_NAME) { + if (strcmp(dev->name, devargs->name.name) == 0) + return devargs; + } } return NULL; } @@ -174,7 +178,8 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *d /* no initialization when blacklisted, return without error */ if (dev->devargs != NULL && - dev->devargs->type == RTE_DEVTYPE_BLACKLISTED_PCI) { + (dev->devargs->type == RTE_DEVTYPE_BLACKLISTED_PCI || + dev->devargs->type == RTE_DEVTYPE_BLACKLISTED_NAME)) { RTE_LOG(DEBUG, EAL, " Device is blacklisted, not initializing\n"); return 1; } diff --git a/lib/librte_eal/common/eal_options.h b/lib/librte_eal/common/eal_options.h index f6714d9..2aea553 100644 --- a/lib/librte_eal/common/eal_options.h +++ b/lib/librte_eal/common/eal_options.h @@ -45,6 +45,8 @@ enum { /* first long only option value must be >= 256, so that we won't * conflict with short options */ OPT_LONG_MIN_NUM = 256, +#define OPT_BLACKLISTED_NAME "blacklisted-name" + OPT_BLACKLISTED_NAME_NUM, #define OPT_BASE_VIRTADDR "base-virtaddr" OPT_BASE_VIRTADDR_NUM, #define OPT_CREATE_UIO_DEV "create-uio-dev" diff --git a/lib/librte_eal/common/include/rte_devargs.h b/lib/librte_eal/common/include/rte_devargs.h index 7084ae2..8531405 100644 --- a/lib/librte_eal/common/include/rte_devargs.h +++ b/lib/librte_eal/common/include/rte_devargs.h @@ -59,6 +59,7 @@ enum rte_devtype { RTE_DEVTYPE_WHITELISTED_PCI, RTE_DEVTYPE_BLACKLISTED_PCI, RTE_DEVTYPE_VIRTUAL, + RTE_DEVTYPE_BLACKLISTED_NAME, }; /** @@ -87,6 +88,10 @@ struct rte_devargs { /** Driver name. */ char drv_name[32]; } virtual; + struct { + /** Interface name. */ + char name[32]; + } name; }; /** Arguments string as given by user or "" for no argument. */ char *args; diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h index 83e3c28..852c149 100644 --- a/lib/librte_eal/common/include/rte_pci.h +++ b/lib/librte_eal/common/include/rte_pci.h @@ -161,6 +161,7 @@ struct rte_pci_device { struct rte_pci_resource mem_resource[PCI_MAX_RESOURCE]; /**< PCI Memory Resource */ struct rte_intr_handle intr_handle; /**< Interrupt handle */ struct rte_pci_driver *driver; /**< Associated driver */ + char name[32]; /**< Interface name (if any) */ uint16_t max_vfs; /**< sriov enable if not zero */ int numa_node; /**< NUMA node connection */ struct rte_devargs *devargs; /**< Device user arguments */ diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index bc5b5be..c417d01 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -260,6 +260,8 @@ pci_scan_one(const char *dirname, uint16_t domain, uint8_t bus, unsigned long tmp; struct rte_pci_device *dev; char driver[PATH_MAX]; + struct dirent *e; + DIR *dir; int ret; dev = malloc(sizeof(*dev)); @@ -352,6 +354,19 @@ pci_scan_one(const char *dirname, uint16_t domain, uint8_t bus, return -1; } + /* get network interface name */ + snprintf(filename, sizeof(filename), "%s/net", dirname); + dir = opendir(filename); + if (dir) { + while ((e = readdir(dir)) != NULL) { + if (e->d_name[0] == '.') + continue; + + strcpy(dev->name, e->d_name); + } + closedir(dir); + } + if (!ret) { if (!strcmp(driver, "vfio-pci")) dev->kdrv = RTE_KDRV_VFIO; -- 2.1.0