Show a patch.

GET /api/patches/44082/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 44082,
    "url": "http://patches.dpdk.org/api/patches/44082/?format=api",
    "web_url": "http://patches.dpdk.org/patch/44082/",
    "project": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk"
    },
    "msgid": "<20180831092038.23051-3-adrien.mazarguil@6wind.com>",
    "date": "2018-08-31T09:57:30",
    "name": "[2/8] net/mlx5: clean up redundant interface name getters",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "94e8a3dc026f62e26e07dd4b13999115845f299a",
    "submitter": {
        "id": 165,
        "url": "http://patches.dpdk.org/api/people/165/?format=api",
        "name": "Adrien Mazarguil",
        "email": "adrien.mazarguil@6wind.com"
    },
    "delegate": null,
    "mbox": "http://patches.dpdk.org/patch/44082/mbox/",
    "series": [
        {
            "id": 1126,
            "url": "http://patches.dpdk.org/api/series/1126/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=1126",
            "date": "2018-08-31T09:57:25",
            "name": "net/mlx5: add switch offload for VXLAN encap/decap",
            "version": 1,
            "mbox": "http://patches.dpdk.org/series/1126/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/44082/comments/",
    "check": "success",
    "checks": "http://patches.dpdk.org/api/patches/44082/checks/",
    "tags": {},
    "headers": {
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "Content-Disposition": "inline",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "X-Gm-Message-State": "APzg51DU+zoF6WB+tkNriBrjfSFel8QJeC4kd+s+R1BtHJbBOb9lTMfN\n\t+6wUneKQlCfgq/jtNj81FsJ0Yw==",
        "X-Google-Smtp-Source": "ANB0Vdb7eoXkMqGXw/UlTefH4i9+eJRX7W7tGfFevaQD/NACdFTKKzAELquOLFq4SuMcDoCHcdq3ng==",
        "List-Post": "<mailto:dev@dpdk.org>",
        "MIME-Version": "1.0",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "X-BeenThere": "dev@dpdk.org",
        "References": "<20180831092038.23051-1-adrien.mazarguil@6wind.com>",
        "Subject": "[dpdk-dev] [PATCH 2/8] net/mlx5: clean up redundant interface name\n\tgetters",
        "Content-Type": "text/plain; charset=us-ascii",
        "Delivered-To": "patchwork@dpdk.org",
        "Received": [
            "from [92.243.14.124] (localhost [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id 013BC4CAF;\n\tFri, 31 Aug 2018 11:57:49 +0200 (CEST)",
            "from mail-wm0-f67.google.com (mail-wm0-f67.google.com\n\t[74.125.82.67]) by dpdk.org (Postfix) with ESMTP id C36F84CA9\n\tfor <dev@dpdk.org>; Fri, 31 Aug 2018 11:57:46 +0200 (CEST)",
            "by mail-wm0-f67.google.com with SMTP id b19-v6so4642715wme.3\n\tfor <dev@dpdk.org>; Fri, 31 Aug 2018 02:57:46 -0700 (PDT)",
            "from 6wind.com (host.78.145.23.62.rev.coltfrance.com.\n\t[62.23.145.78]) by smtp.gmail.com with ESMTPSA id\n\th7-v6sm10725264wrs.3.2018.08.31.02.57.45\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tFri, 31 Aug 2018 02:57:45 -0700 (PDT)"
        ],
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "X-Original-To": "patchwork@dpdk.org",
        "X-Mailer": "git-send-email 2.11.0",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:in-reply-to;\n\tbh=uH1dSiuRJOKF+4LK3P0pfJHBOSyO3TcVjT/YVmkriSg=;\n\tb=NLHYHvuHEj0eyj+cu0PDXWd8wnDy+EHNJw0eGrMTfTjzTcibAqpSDtQWK16XcCfr2X\n\tvjYC/BfOjKVrxn/lOXp/16OGmkBg5ljolaWV3BVH7dYpk3tyk34hlpFe3Wa3nssHYNDP\n\tqMk1oR7u5Na6N4J4vwWGG1N22eGfkEUpfdqf2kNSZVxTzb9OnpnG2lsXFwoHSQ0r3b68\n\tyhLnhFHwaKwjPAlzQYF5O8wGi7e3aeJvRIqSaTs+ZkvI8llAwvE3ubtGzUOAdpOBt6KR\n\tOdDj9DDBy2LjDK+KdlqCTz5q6PdRaBjiqQN26EBYLfsiKYXvIN5jrmJc8x6OzMSP1rtP\n\tmrMw==",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=6wind-com.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:in-reply-to;\n\tbh=uH1dSiuRJOKF+4LK3P0pfJHBOSyO3TcVjT/YVmkriSg=;\n\tb=UslJyv4Y4OGBAOtZLEPX0Z2ZBlDQibAq7P9yE/+emWtA5CnVwWc8jq4ZFoGuFfq/AV\n\tCJLw7HzxKDUhDDQVEHyy9GqJqJsVXoMttZi6Zz62uUqhNq3rMsenHnvnh57cIw6WX7sC\n\tJoxvviYO1Aom73PoalrAcnFVsiAQK2GO9BbFNaJZdcZQ9WeDF9b27E3cG2EMjVqYLSHj\n\txAbHnaGpz/Rz+L5KnEGu5ti7IX4TS8cIxmc/5E55knYfTHGb7pTPXDQ6s4CUdXOJWElL\n\tJ9sBZ9XPOmMTrMETj77/ddGdzl1x1QAsr4aY7lKBcp/cW4YQK1xQQy11DeQj5pbBvPf8\n\t0lFA==",
        "Message-ID": "<20180831092038.23051-3-adrien.mazarguil@6wind.com>",
        "Date": "Fri, 31 Aug 2018 11:57:30 +0200",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>",
        "X-Received": "by 2002:a1c:3545:: with SMTP id\n\tc66-v6mr4290165wma.120.1535709466427; \n\tFri, 31 Aug 2018 02:57:46 -0700 (PDT)",
        "To": "Shahaf Shuler <shahafs@mellanox.com>, Yongseok Koh <yskoh@mellanox.com>, \n\tSlava Ovsiienko <viacheslavo@mellanox.com>",
        "From": "Adrien Mazarguil <adrien.mazarguil@6wind.com>",
        "In-Reply-To": "<20180831092038.23051-1-adrien.mazarguil@6wind.com>",
        "Cc": "dev@dpdk.org",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Return-Path": "<dev-bounces@dpdk.org>"
    },
    "content": "In order to return the network interface index (ifindex) associated with a\ndevice, mlx5_ifindex() uses if_nametoindex() to convert the result of\nmlx5_get_ifname(). This is inefficient because the latter first retrieves\nifindex on its own to pass it through if_indextoname().\n\nSince indices are much more reliable than names (less prone to change) and\ninvolved in flow rule management where performance matters, this patch\nmoves ifindex-getting code directly into mlx5_ifindex() and replaces\nremaining mlx5_get_ifname() calls with if_indextoname().\n\nSimilarly, the new function mlx5_master_ifindex() replaces\nmlx5_get_master_ifname() while getting rid of irrelevant compatibility\ncode for unsupported Linux and MLNX_OFED versions.\n\nSigned-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>\n---\n drivers/net/mlx5/mlx5.c        |  15 +--\n drivers/net/mlx5/mlx5.h        |   3 -\n drivers/net/mlx5/mlx5_ethdev.c | 184 ++++++++++++++----------------------\n 3 files changed, 74 insertions(+), 128 deletions(-)",
    "diff": "diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c\nindex 55b73a03b..1414ce0c5 100644\n--- a/drivers/net/mlx5/mlx5.c\n+++ b/drivers/net/mlx5/mlx5.c\n@@ -734,7 +734,7 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,\n \tstruct ibv_counter_set_description cs_desc = { .counter_type = 0 };\n #endif\n \tstruct ether_addr mac;\n-\tchar name[RTE_ETH_NAME_MAX_LEN];\n+\tchar name[RTE_MAX(IF_NAMESIZE, RTE_ETH_NAME_MAX_LEN)];\n \tint own_domain_id = 0;\n \tstruct rte_flow_error flow_error;\n \tunsigned int i;\n@@ -1116,16 +1116,9 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,\n \t\tmac.addr_bytes[2], mac.addr_bytes[3],\n \t\tmac.addr_bytes[4], mac.addr_bytes[5]);\n #ifndef NDEBUG\n-\t{\n-\t\tchar ifname[IF_NAMESIZE];\n-\n-\t\tif (mlx5_get_ifname(eth_dev, &ifname) == 0)\n-\t\t\tDRV_LOG(DEBUG, \"port %u ifname is \\\"%s\\\"\",\n-\t\t\t\teth_dev->data->port_id, ifname);\n-\t\telse\n-\t\t\tDRV_LOG(DEBUG, \"port %u ifname is unknown\",\n-\t\t\t\teth_dev->data->port_id);\n-\t}\n+\tDRV_LOG(DEBUG, \"port %u ifname is \\\"%s\\\"\",\n+\t\teth_dev->data->port_id,\n+\t\tif_indextoname(priv->ifindex, name) ? name : \"\");\n #endif\n \t/* Get actual MTU if possible. */\n \terr = mlx5_get_mtu(eth_dev, &priv->mtu);\ndiff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h\nindex 4c2dec644..0807cf689 100644\n--- a/drivers/net/mlx5/mlx5.h\n+++ b/drivers/net/mlx5/mlx5.h\n@@ -241,9 +241,6 @@ int mlx5_getenv_int(const char *);\n \n /* mlx5_ethdev.c */\n \n-int mlx5_get_master_ifname(const struct rte_eth_dev *dev,\n-\t\t\t   char (*ifname)[IF_NAMESIZE]);\n-int mlx5_get_ifname(const struct rte_eth_dev *dev, char (*ifname)[IF_NAMESIZE]);\n unsigned int mlx5_ifindex(const struct rte_eth_dev *dev);\n int mlx5_ifreq(const struct rte_eth_dev *dev, int req, struct ifreq *ifr,\n \t       int master);\ndiff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c\nindex cf0b415b2..67149b7b3 100644\n--- a/drivers/net/mlx5/mlx5_ethdev.c\n+++ b/drivers/net/mlx5/mlx5_ethdev.c\n@@ -119,149 +119,104 @@ struct ethtool_link_settings {\n #endif\n \n /**\n- * Get master interface name from private structure.\n+ * Get network interface index associated with master device.\n+ *\n+ * Result differs from mlx5_ifindex() when the current device is a port\n+ * representor.\n  *\n  * @param[in] dev\n  *   Pointer to Ethernet device.\n- * @param[out] ifname\n- *   Interface name output buffer.\n  *\n  * @return\n- *   0 on success, a negative errno value otherwise and rte_errno is set.\n+ *   Nonzero interface index on success, zero otherwise and rte_errno is set.\n  */\n-int\n-mlx5_get_master_ifname(const struct rte_eth_dev *dev,\n-\t\t       char (*ifname)[IF_NAMESIZE])\n+static unsigned int\n+mlx5_master_ifindex(const struct rte_eth_dev *dev)\n {\n \tstruct priv *priv = dev->data->dev_private;\n-\tDIR *dir;\n-\tstruct dirent *dent;\n-\tunsigned int dev_type = 0;\n-\tunsigned int dev_port_prev = ~0u;\n-\tchar match[IF_NAMESIZE] = \"\";\n-\n-\t{\n-\t\tMKSTR(path, \"%s/device/net\", priv->ibdev_path);\n-\n-\t\tdir = opendir(path);\n-\t\tif (dir == NULL) {\n-\t\t\trte_errno = errno;\n-\t\t\treturn -rte_errno;\n-\t\t}\n-\t}\n-\twhile ((dent = readdir(dir)) != NULL) {\n-\t\tchar *name = dent->d_name;\n-\t\tFILE *file;\n-\t\tunsigned int dev_port;\n-\t\tint r;\n-\n-\t\tif ((name[0] == '.') &&\n-\t\t    ((name[1] == '\\0') ||\n-\t\t     ((name[1] == '.') && (name[2] == '\\0'))))\n-\t\t\tcontinue;\n+\tDIR *dir = NULL;\n+\tstruct dirent *dent = NULL;\n+\tsize_t size = 0;\n+\tunsigned int ifindex = 0;\n \n-\t\tMKSTR(path, \"%s/device/net/%s/%s\",\n-\t\t      priv->ibdev_path, name,\n-\t\t      (dev_type ? \"dev_id\" : \"dev_port\"));\n+\twhile (1) {\n+\t\tchar path[size];\n+\t\tFILE *file;\n+\t\tint ret;\n \n-\t\tfile = fopen(path, \"rb\");\n-\t\tif (file == NULL) {\n-\t\t\tif (errno != ENOENT)\n-\t\t\t\tcontinue;\n-\t\t\t/*\n-\t\t\t * Switch to dev_id when dev_port does not exist as\n-\t\t\t * is the case with Linux kernel versions < 3.15.\n-\t\t\t */\n-try_dev_id:\n-\t\t\tmatch[0] = '\\0';\n-\t\t\tif (dev_type)\n-\t\t\t\tbreak;\n-\t\t\tdev_type = 1;\n-\t\t\tdev_port_prev = ~0u;\n-\t\t\trewinddir(dir);\n+\t\tret = snprintf(path, size, \"%s/device/net/%s%s\",\n+\t\t\t       priv->ibdev_path,\n+\t\t\t       dent ? dent->d_name : \"\",\n+\t\t\t       dent ? \"/ifindex\" : \"\");\n+\t\tif (ret == -1)\n+\t\t\tgoto error;\n+\t\tif (!size) {\n+\t\t\tsize = ret + 1;\n \t\t\tcontinue;\n \t\t}\n-\t\tr = fscanf(file, (dev_type ? \"%x\" : \"%u\"), &dev_port);\n-\t\tfclose(file);\n-\t\tif (r != 1)\n-\t\t\tcontinue;\n-\t\t/*\n-\t\t * Switch to dev_id when dev_port returns the same value for\n-\t\t * all ports. May happen when using a MOFED release older than\n-\t\t * 3.0 with a Linux kernel >= 3.15.\n-\t\t */\n-\t\tif (dev_port == dev_port_prev)\n-\t\t\tgoto try_dev_id;\n-\t\tdev_port_prev = dev_port;\n-\t\tif (dev_port == 0)\n-\t\t\tstrlcpy(match, name, sizeof(match));\n-\t}\n+\t\tif (!dir) {\n+\t\t\tdir = opendir(path);\n+\t\t\tif (!dir)\n+\t\t\t\tgoto error;\n+\t\t}\n+\t\tfile = dent ? fopen(path, \"rb\") : NULL;\n+\t\tif (file) {\n+\t\t\t/* Only one ifindex is expected in there. */\n+\t\t\tret = !!ifindex;\n+\t\t\tif (fscanf(file, \"%u\", &ifindex) != 1)\n+\t\t\t\tret = 0;\n+\t\t\tfclose(file);\n+\t\t\tif (ret) {\n+\t\t\t\terrno = ENOTSUP;\n+\t\t\t\tgoto error;\n+\t\t\t}\n+\t\t}\n+\t\tdo {\n+\t\t\tdent = readdir(dir);\n+\t\t} while (dent &&\n+\t\t\t (!strcmp(dent->d_name, \".\") ||\n+\t\t\t  !strcmp(dent->d_name, \"..\")));\n+\t\tif (!dent)\n+\t\t\tbreak;\n+\t\tsize = 0;\n+\t};\n \tclosedir(dir);\n-\tif (match[0] == '\\0') {\n-\t\trte_errno = ENOENT;\n-\t\treturn -rte_errno;\n-\t}\n-\tstrncpy(*ifname, match, sizeof(*ifname));\n+\tif (!ifindex)\n+\t\trte_errno = ENXIO;\n+\treturn ifindex;\n+error:\n+\trte_errno = errno;\n+\tif (dir)\n+\t\tclosedir(dir);\n \treturn 0;\n }\n \n /**\n- * Get interface name from private structure.\n- *\n- * This is a port representor-aware version of mlx5_get_master_ifname().\n+ * Get network interface index associated with device.\n  *\n  * @param[in] dev\n  *   Pointer to Ethernet device.\n- * @param[out] ifname\n- *   Interface name output buffer.\n  *\n  * @return\n- *   0 on success, a negative errno value otherwise and rte_errno is set.\n+ *   Nonzero interface index on success, zero otherwise and rte_errno is set.\n  */\n-int\n-mlx5_get_ifname(const struct rte_eth_dev *dev, char (*ifname)[IF_NAMESIZE])\n+unsigned int\n+mlx5_ifindex(const struct rte_eth_dev *dev)\n {\n \tstruct priv *priv = dev->data->dev_private;\n \tunsigned int ifindex =\n \t\tpriv->nl_socket_rdma >= 0 ?\n \t\tmlx5_nl_ifindex(priv->nl_socket_rdma, priv->ibdev_name) : 0;\n \n-\tif (!ifindex) {\n-\t\tif (!priv->representor)\n-\t\t\treturn mlx5_get_master_ifname(dev, ifname);\n-\t\trte_errno = ENXIO;\n-\t\treturn -rte_errno;\n-\t}\n-\tif (if_indextoname(ifindex, &(*ifname)[0]))\n-\t\treturn 0;\n-\trte_errno = errno;\n+\tif (ifindex)\n+\t\treturn ifindex;\n+\tif (!priv->representor)\n+\t\treturn mlx5_master_ifindex(dev);\n+\trte_errno = ENXIO;\n \treturn -rte_errno;\n }\n \n /**\n- * Get the interface index from device name.\n- *\n- * @param[in] dev\n- *   Pointer to Ethernet device.\n- *\n- * @return\n- *   Nonzero interface index on success, zero otherwise and rte_errno is set.\n- */\n-unsigned int\n-mlx5_ifindex(const struct rte_eth_dev *dev)\n-{\n-\tchar ifname[IF_NAMESIZE];\n-\tunsigned int ifindex;\n-\n-\tif (mlx5_get_ifname(dev, &ifname))\n-\t\treturn 0;\n-\tifindex = if_nametoindex(ifname);\n-\tif (!ifindex)\n-\t\trte_errno = errno;\n-\treturn ifindex;\n-}\n-\n-/**\n  * Perform ifreq ioctl() on associated Ethernet device.\n  *\n  * @param[in] dev\n@@ -282,17 +237,18 @@ mlx5_ifreq(const struct rte_eth_dev *dev, int req, struct ifreq *ifr,\n \t   int master)\n {\n \tint sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);\n-\tint ret = 0;\n+\tunsigned int ifindex;\n+\tint ret;\n \n \tif (sock == -1) {\n \t\trte_errno = errno;\n \t\treturn -rte_errno;\n \t}\n \tif (master)\n-\t\tret = mlx5_get_master_ifname(dev, &ifr->ifr_name);\n+\t\tifindex = mlx5_master_ifindex(dev);\n \telse\n-\t\tret = mlx5_get_ifname(dev, &ifr->ifr_name);\n-\tif (ret)\n+\t\tifindex = mlx5_ifindex(dev);\n+\tif (!ifindex || !if_indextoname(ifindex, ifr->ifr_name))\n \t\tgoto error;\n \tret = ioctl(sock, req, ifr);\n \tif (ret == -1) {\n",
    "prefixes": [
        "2/8"
    ]
}