From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-eopbgr10040.outbound.protection.outlook.com [40.107.1.40]) by dpdk.org (Postfix) with ESMTP id 4691E1B2F3 for ; Thu, 18 Jan 2018 14:52:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=QwMPRQ3qWK+UNACX6wfEJSeV1VK6/cW7CglkcDH+I8w=; b=IHu1THGS/FhIqngLCZjlPmUIWc/IPMz0Av/pryuBlI7inYX5nabscJzy+zfv1CSbXo2fFQTjff4mfeR/GqQt54ndcGoPWAs2/xGHJVpSIwsqnELvKETskvYqpc4L8JU07ON6lYEEqfqAKzY6E9kemjMlALxniLiBpGTAHxd2c3E= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=matan@mellanox.com; Received: from mellanox.com (37.142.13.130) by AM6PR0502MB3798.eurprd05.prod.outlook.com (2603:10a6:209:a::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.407.7; Thu, 18 Jan 2018 13:51:59 +0000 From: Matan Azrad To: Ferruh Yigit , Adrien Mazarguil , Gaetan Rivet Cc: Thomas Monjalon , dev@dpdk.org Date: Thu, 18 Jan 2018 13:51:40 +0000 Message-Id: <1516283506-21198-3-git-send-email-matan@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1516283506-21198-1-git-send-email-matan@mellanox.com> References: <1516269709-15252-1-git-send-email-matan@mellanox.com> <1516283506-21198-1-git-send-email-matan@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [37.142.13.130] X-ClientProxiedBy: VI1PR08CA0115.eurprd08.prod.outlook.com (2603:10a6:800:d4::17) To AM6PR0502MB3798.eurprd05.prod.outlook.com (2603:10a6:209:a::27) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 7247be16-873c-4395-9fda-08d55e7aa571 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534125)(4602075)(4627221)(201703031133081)(201702281549075)(48565401081)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:AM6PR0502MB3798; X-Microsoft-Exchange-Diagnostics: 1; AM6PR0502MB3798; 3:LE5ggQYo8KWZjr71IbSAcLCU8X9pTc6VJtOMSN8DlFb9nPqLCWiO4dirm8H2xYUq8xBHKJT1qwepKnff69I4rua0C+ipD93ERnTcdVYciCSZUYtph9Ub1iAzO/XQiVuQ87EJwiFDweK6Kc+U+/MhdysNqHif8zocvIfbeaIq7XcQKZxP14J0V6xVa78vqp/u7OECJ//DxToXt9iH3ydcyzbHkYSV9jNrrOkD+VUaC8nxb8OuFJG7JMvj5DlkyyFZ; 25:FPjrt/TIO4Jg+gbPM34PFyc2bV9LpbC25UdM2b4h0Jag7PxAu7CRKs6QwOm7UGRTwmvLrro/+ar5/j3O6nDyrnkz89FRNR/N/gjeOe4T/jcS5aDM6hRtzn6wXgTfXBu79vbLOM7IWJ3Dg2IHJou5VpLaelhEaazpUypW97xa/wl3WKGykP3zPbR1P7la4A2AjFD0pd6lFxvTyPednbGj4+uYmIK8LcNgbgh4tY7a4ZgpBMIJziToSb+LSUppUVy/DPMHP4A70SizzL1ZE6tLTMhdiSy4WK1VH9GhxYJyZOb2GmHXBG50n2KELbkVeQQKilTDwqTTJ12OrDhZe6Kd2w==; 31:Q1bTqxLCv3fH+96e7iuDsZg9zgHE8apzWmgkRLNuZ54/fV5QQGwzYfMafiETGuXetUH5xYzlFdIc+3JlSb2gllB1QOSfUFbkVwJ7c6Nn9oZPjVOn0LLZDqSiAb4Za/o3/LXjsdYFHLRj5zbDYen6DR7ozaK4d3INOd9LLZ67Oj4i0/OqkzWK59Zv7gvH+s9JIrGRA6hoQGkfL6+vEDcQb5s9EQAX/EjBlR8XkBb48AY= X-MS-TrafficTypeDiagnostic: AM6PR0502MB3798: X-LD-Processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; AM6PR0502MB3798; 20:Yfz/OCW1yOht3Ar6kDo8kxW3Gm+TVf/hWYgckKNj/j9zgMPn70/8CM8+c46BidEt/A5/05dQ/n1P/cKvsJHicD4339G1Ciz54LmrO45h4k1sqTYTnmVAE2noKKPVDP+uOy4DNUGhza049dFLg8yWy72+B76nfRH3C3UfOp3wreNp7K1ga9FRhObu8hn4jfwAcIWlDF6fnEsoyLICE08+voULiQ6Iqk6PGNRKBcZiUB0KuIgcVKGWWG8plAXWruUbVcrE4r5SYfrdizcKvjbfgQ640wM1CxKr9CRW4TiweakyHJaQhmK4/2XPUaWnrTlxA+5sCtz696tWgGl4hP4pmA8ySXhyHOOP95TqvGrUNOv+LZjPkLaoCSJHZfQI5qUv26eJoKZWk59VbPCTgP2CcyiUhembY92N9hx848cZPYgYRRc2YMF8aNSMYqviMaVedrcInpzbuQuWrXseTMvxkNBXEjvjp3TbYP6FHhJPwqZDZM8dhKJgxpFtyaI15Ywd; 4:lRADIF6ZrOPLA2NidhJa1ndqTab4hA4GCD30XgEmkZFEGvNGDVduzEELH/oNqBgMoEbQ+ese9JarKzahlbVz6wZsRkOxMrNpsqkbVFFpBWTzd3tNdPZu9MByl6uNY58ZmJAEu8i7IT2o9PjQpQyMLJxC9EzosYG6MdaoSjwU9HAqHwL5CPn4kZGVhs6zrh4PlUaKdXFk78ux6gWzbx7x8OnLiM9wuiBRsiwxIgI9iKyTh7gbus56nAqH4zU78Tiowr/Ve4nCihBay9/z77UieYl7x+kc17bh4aA51Kne+1RDBnE00DlzSnmI54JwduZ7 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(278428928389397); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040470)(2401047)(8121501046)(5005006)(3002001)(10201501046)(3231023)(944501161)(93006095)(93001095)(6055026)(6041268)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123558120)(6072148)(201708071742011); SRVR:AM6PR0502MB3798; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:AM6PR0502MB3798; X-Forefront-PRVS: 05568D1FF7 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(366004)(396003)(346002)(39380400002)(39860400002)(376002)(199004)(189003)(386003)(2906002)(51416003)(81156014)(81166006)(5660300001)(305945005)(4326008)(21086003)(7696005)(106356001)(8676002)(68736007)(26005)(69596002)(76176011)(59450400001)(105586002)(86362001)(97736004)(3846002)(6116002)(52116002)(53936002)(6666003)(50226002)(55016002)(4720700003)(33026002)(7736002)(2950100002)(36756003)(47776003)(478600001)(16526018)(8936002)(66066001)(316002)(110136005)(48376002)(50466002)(16586007)(25786009); DIR:OUT; SFP:1101; SCL:1; SRVR:AM6PR0502MB3798; H:mellanox.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM6PR0502MB3798; 23:WABPPJqQkOsA2OePmOPd8nY7J7NTaHvvjzJuip4?= =?us-ascii?Q?ezreENDeFNJPIHz0aa7ZzA1tZUUo/OJTESP04Zu4uZN6phvKf1xzrjUj3G9D?= =?us-ascii?Q?VjrRZL9daxKVB4b1l6SMwofl0GgEOb3FoPAsnulMa6uo66vqGyRcD51XMqM6?= =?us-ascii?Q?vpZFuhB/sa3AYWhhghcY3/zUN7dRLRKk3QwoBwjxTZfn670La31xntXls8nt?= =?us-ascii?Q?XpWVpdjPnsNlwhqkHkxxm8LC7FOBevTJM+8ZR8D2q8/JwGenbHWHPXgaZL19?= =?us-ascii?Q?hoYyNAKv0A0V4Uz5Ffopj99Lt7G/FpI9sOUEeX+/mdaQYOaXKSRY6S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soft-Exchange-Diagnostics: 1; AM6PR0502MB3798; 6:NAf+/G9DJLwk6vIIYLdU5pdO+SMi5yZMykoL/g3wLpHpl0+t+iSMkfJpSkoKARMvl7zkYY307eDGreH9VQs3xtXkjyjYtxBqiKv/fWaDMYsctuOii4bRk+oLOBZgMiORgCbbmGbS0BsBe74PL39RHZKM/Bi5oDKjeAgrh1guNAURxlTr+JuEao60wBivVhq559A7UOG/GdgVp72I5oEdbiFrPsbeloHDeg5XxdDFjW6gJ0Yeb4qxHurWl3tF4sbRFq2l7aC3GqRcM1GHyi7njV1zHU+J8nVeHjlQujjpCDR0BV6i3MQiYUCxRRna9T7hRWitj7f5FhQ6Da3R3kDE769Fm3+2aMpB+OAmHgY67vQ=; 5:qlbBb+5++Fgk9sjSTs178tEjm5u8BPSPup6EF3taFLP14vN7nv9H8D/EupS9mX6l2ZMOFXYBdezhOwlr0Z2nMWFVFYolszNDBAuV0nxqB9MjhKvajhy16YBoNWHrdFj0z8cV+QYD270kXtZyhHSz0Q7c61S2rqUtb0jguaJHQJY=; 24:lrGQTYKkYkluehBMZHK6MB1YFhHVld06eyDvjJ4p8rdakyB/pJpyZZG3PNtD4dVO6OZ5bkeyttFKwNuCJvQ6Wnbz5IsH4YJuzouarC3/6xQ=; 7:K3e+qQbNVKqTKx4FS1utiH/eoCqtu8MP1plp1HmUFaYf9z/Bz8CYXjA7XhnIHS8vMCQhMFGF9XcHvcrmDQzReikMAbzl/mVzxYakyS/bZvBA536Uth7V+2nYu7LRK+PHqsa13rdPZ3CoPKtuj8LudGJQUKg/94BsfilJbb6mJRsQQWBhORZnNc0tLo8eJ27CcI/cSYYEbks9ujaFsM13RmsfmiS8ovHHshbKJJKN9MudXGFdpa+Yv/zd2F5iC7m6 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jan 2018 13:51:59.0313 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7247be16-873c-4395-9fda-08d55e7aa571 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR0502MB3798 Subject: [dpdk-dev] [PATCH v6 2/8] net/failsafe: add "fd" parameter 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: Thu, 18 Jan 2018 13:52:01 -0000 This parameter enables applications to provide device definitions through an arbitrary file descriptor number. Signed-off-by: Adrien Mazarguil Signed-off-by: Matan Azrad Acked-by: Gaetan Rivet --- doc/guides/nics/fail_safe.rst | 9 ++++ drivers/net/failsafe/failsafe_args.c | 80 ++++++++++++++++++++++++++++++++- drivers/net/failsafe/failsafe_private.h | 3 ++ 3 files changed, 91 insertions(+), 1 deletion(-) diff --git a/doc/guides/nics/fail_safe.rst b/doc/guides/nics/fail_safe.rst index c4e3d2e..5b1b47e 100644 --- a/doc/guides/nics/fail_safe.rst +++ b/doc/guides/nics/fail_safe.rst @@ -106,6 +106,15 @@ Fail-safe command line parameters All commas within the ``shell command`` are replaced by spaces before executing the command. This helps using scripts to specify devices. +- **fd()** parameter + + This parameter reads a device definition from an arbitrary file descriptor + number in ```` format as described above. + + The file descriptor is read in non-blocking mode and is never closed in + order to take only the last line into account (unlike ``exec()``) at every + probe attempt. + - **mac** parameter [MAC address] This parameter allows the user to set a default MAC address to the fail-safe diff --git a/drivers/net/failsafe/failsafe_args.c b/drivers/net/failsafe/failsafe_args.c index ec63ac9..a1fb3fa 100644 --- a/drivers/net/failsafe/failsafe_args.c +++ b/drivers/net/failsafe/failsafe_args.c @@ -31,7 +31,11 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include +#include +#include #include +#include #include #include @@ -161,6 +165,67 @@ typedef int (parse_cb)(struct rte_eth_dev *dev, const char *params, } static int +fs_read_fd(struct sub_device *sdev, char *fd_str) +{ + FILE *fp = NULL; + int fd = -1; + /* store possible newline as well */ + char output[DEVARGS_MAXLEN + 1]; + int err = -ENODEV; + int oflags; + int lcount; + + RTE_ASSERT(fd_str != NULL || sdev->fd_str != NULL); + if (sdev->fd_str == NULL) { + sdev->fd_str = strdup(fd_str); + if (sdev->fd_str == NULL) { + ERROR("Command line allocation failed"); + return -ENOMEM; + } + } + errno = 0; + fd = strtol(fd_str, &fd_str, 0); + if (errno || *fd_str || fd < 0) { + ERROR("Parsing FD number failed"); + goto error; + } + /* Fiddle with copy of file descriptor */ + fd = dup(fd); + if (fd == -1) + goto error; + oflags = fcntl(fd, F_GETFL); + if (oflags == -1) + goto error; + if (fcntl(fd, F_SETFL, oflags | O_NONBLOCK) == -1) + goto error; + fp = fdopen(fd, "r"); + if (fp == NULL) + goto error; + fd = -1; + /* Only take the last line into account */ + lcount = 0; + while (fgets(output, sizeof(output), fp)) + ++lcount; + if (lcount == 0) + goto error; + else if (ferror(fp) && errno != EAGAIN) + goto error; + /* Line must end with a newline character */ + fs_sanitize_cmdline(output); + if (output[0] == '\0') + goto error; + err = fs_parse_device(sdev, output); + if (err) + ERROR("Parsing device '%s' failed", output); +error: + if (fp) + fclose(fp); + if (fd != -1) + close(fd); + return err; +} + +static int fs_parse_device_param(struct rte_eth_dev *dev, const char *param, uint8_t head) { @@ -202,6 +267,14 @@ typedef int (parse_cb)(struct rte_eth_dev *dev, const char *params, } if (ret) goto free_args; + } else if (strncmp(param, "fd(", 3) == 0) { + ret = fs_read_fd(sdev, args); + if (ret == -ENODEV) { + DEBUG("Reading device info from FD failed"); + ret = 0; + } + if (ret) + goto free_args; } else { ERROR("Unrecognized device type: %.*s", (int)b, param); return -EINVAL; @@ -409,6 +482,8 @@ typedef int (parse_cb)(struct rte_eth_dev *dev, const char *params, FOREACH_SUBDEV(sdev, i, dev) { free(sdev->cmdline); sdev->cmdline = NULL; + free(sdev->fd_str); + sdev->fd_str = NULL; free(sdev->devargs.args); sdev->devargs.args = NULL; } @@ -424,7 +499,8 @@ typedef int (parse_cb)(struct rte_eth_dev *dev, const char *params, param[b] != '\0') b++; if (strncmp(param, "dev", b) != 0 && - strncmp(param, "exec", b) != 0) { + strncmp(param, "exec", b) != 0 && + strncmp(param, "fd(", b) != 0) { ERROR("Unrecognized device type: %.*s", (int)b, param); return -EINVAL; } @@ -463,6 +539,8 @@ typedef int (parse_cb)(struct rte_eth_dev *dev, const char *params, continue; if (sdev->cmdline) ret = fs_execute_cmd(sdev, sdev->cmdline); + else if (sdev->fd_str) + ret = fs_read_fd(sdev, sdev->fd_str); else ret = fs_parse_sub_device(sdev); if (ret == 0) diff --git a/drivers/net/failsafe/failsafe_private.h b/drivers/net/failsafe/failsafe_private.h index 54b5b91..5e04ffe 100644 --- a/drivers/net/failsafe/failsafe_private.h +++ b/drivers/net/failsafe/failsafe_private.h @@ -48,6 +48,7 @@ #define PMD_FAILSAFE_PARAM_STRING \ "dev()," \ "exec()," \ + "fd()," \ "mac=mac_addr," \ "hotplug_poll=u64" \ "" @@ -112,6 +113,8 @@ struct sub_device { struct fs_stats stats_snapshot; /* Some device are defined as a command line */ char *cmdline; + /* Others are retrieved through a file descriptor */ + char *fd_str; /* fail-safe device backreference */ struct rte_eth_dev *fs_dev; /* flag calling for recollection */ -- 1.8.3.1