From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on0069.outbound.protection.outlook.com [104.47.1.69]) by dpdk.org (Postfix) with ESMTP id 133E01B16F for ; Thu, 18 Jan 2018 09:44:08 +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=dRve2YbjpHQOAJqEZlrBvyP89nF3iW07lOLoqRj1GhM=; b=EhndMbMoU8R3YEWY0lwEEqP9nWVvO4zUDaisQvoZvZNQLJxpo0f/oA+xoBc1HzgG2mpxNO7+oAmWskBe2VQO3Anv9SYI5aR80CRxDrR2jx9F+8OJGPMEXnwOm/KQEmwEyjPSwaezyKrUNzD10HJYFhjCGjM1YUteaDvMwAK0yCU= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=matan@mellanox.com; Received: from mellanox.com (37.142.13.130) by AM6PR0502MB3797.eurprd05.prod.outlook.com (2603:10a6:209:a::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.428.17; Thu, 18 Jan 2018 08:44:06 +0000 From: Matan Azrad To: Ferruh Yigit Cc: Thomas Monjalon , dev@dpdk.org, stephen@networkplumber.org, Adrien Mazarguil , Gaetan Rivet Date: Thu, 18 Jan 2018 08:43:40 +0000 Message-Id: <1516265026-6469-3-git-send-email-matan@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1516265026-6469-1-git-send-email-matan@mellanox.com> References: <1515509253-17834-1-git-send-email-matan@mellanox.com> <1516265026-6469-1-git-send-email-matan@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [37.142.13.130] X-ClientProxiedBy: VI1PR0902CA0040.eurprd09.prod.outlook.com (2603:10a6:802:1::29) To AM6PR0502MB3797.eurprd05.prod.outlook.com (2603:10a6:209:a::26) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 007d96d1-9d5e-461a-4f55-08d55e4fa347 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(48565401081)(2017052603307)(7153060)(7193020); SRVR:AM6PR0502MB3797; X-Microsoft-Exchange-Diagnostics: 1; AM6PR0502MB3797; 3:Q4aYmiARE6Hc024Vnb12dfB4g3xURHemQG98zstejLU6iqD/QVKk12qOt/e5xu6KLgsH35lNdkSqrcCNPYEcEGPU9mwEW6fXAVtyHLnoQ33ESzJAxNRPltt2VhEVCbw/wzxsqXb1krhJIWkzb6hTu2HgiNIqc4Zvho87kZaZLEh5HrjTgUco1D8aYvXZfm+PppxVXdNDWgtLDSPtY7VmTAqWxzGyrLBymxs/6GpDA8cu8i08VLCdw5ChQYDNrZdM; 25:ZTsKxAH1suOQdQaWjLPpMc3TSnrzq6o/3dLoOs/SzsTVQnaHdRFY+D6j2I8lPcmG3Ice23VNWrRBb7lOim4h59jWNbAm0E4WhnNHVSxsLKpZ3fXHypQRvEz82tOzJPNJJzcQWw2E232vTaLAbcY6/TQsHeMWfya9mnpHbD8MRklxqDY0QIm8VDVU/sZjyKOM89+T15XeJuzaYDVrboRDp6mXgUES7G3lrTm6l6W8IChXCQY6ewDzZ2TST6Gr54MKhJWsgUA8mWeWyZZe+O7bHqBOGEFb8FAKHLTDrZCXoZewy4NOvodlhMODgfdMziyoRV2IbV98aTsWLacQSyTWhQ==; 31:UXXVZVSbY9ysh7tikqRTHQBfhsS9kP5/ZAg0vEp5VzQPkfGOHnFQ+6RuexerhJ1N4lPNjsuuE2ojCE/bwKBk7p+WzR5shy29c5xrogXrCy/hYAfXuo5aVPc6+qTYVXEaY17gzZwX9tNcaqiVblssm/kBjheX6+WiMJix/JzW4I6CkQzZlZPQHe7RHtFVb1/VvJa/dMoCHecQ+JOFBcNx80s/CP2G1/dh3k/cpBUVLvA= X-MS-TrafficTypeDiagnostic: AM6PR0502MB3797: X-LD-Processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; AM6PR0502MB3797; 20:VChjwKfu3XIyuvDt/ku+vctlwJBsssIWIeXTzAdhw0NdDlypbCYFKE2oReziN8vYNgqgAGjnKw0cLfH5r8mHGZE0NAkPyDZlFzLYjwJ2yPEi1lPUkM6Ya2h4Rt6OFUgRnaOShvHQaWdfhfTburO6pXZnNTEHa6v9KKbIThHHaACd16M4xbrBrFnAROqgiGwb1hqjLcW53J6iv589ck7alkcpiDeKcBWzhcwY+JaIBJc8i1TpOZ++QYtLMGj4OEue79FQBzxsrCsdg3Yt0f6qYUh5wZs4RsSw3OVo2exrKISDC0qkWaEzXGN2vNDAgv3zPrtIij1Q187wSD1lYuUQje6xnGZ/1Kc4xNeBrfGarCWRc6oemtROZVOcTw3MnDlLayEKmFZXAifL2FbRVzuhjpNcLc5/lq8qluMOKqWmwyP/KAfRDMrfXP1TUSvtNtjk6qs88JMayPkb3ut7KhNQfrTk13XC5iM8md97OuXogWEemiwTLxaZnVG6pBLqlQxq; 4:eviuo4qwqZeprnXOU8Fy6kmQo/njcsTf18zcLGfqUedIYbuF1zJxu/XEn66dIWVSE0Q2oJv68pzYw6LewxZhs7xvldCOAlXwBh7AchM2ioN7Yg4LbN2EgzlghcHEixQ3zvedImxFpGYLgt3oBUo0C4d5GLAt6P5f6n/lt5/IXrugup6ISnzoLtE8cwFVyRimxCWXSxh+aMtQFVLXx7g3jc7aNU/JYgMrSG1CUWffBpPpsFVfDesnHPSJh5o417Wg28uWGe6+Cay7pQ0do5zd+NUSRp39V4cWvzOJoIicJbMZ/Lod4imr+KX5CMrFfX5w X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(278428928389397); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040470)(2401047)(5005006)(8121501046)(10201501046)(3231023)(2400058)(944501161)(3002001)(93006095)(93001095)(6055026)(6041268)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123558120)(20161123562045)(20161123560045)(6072148)(201708071742011); SRVR:AM6PR0502MB3797; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:AM6PR0502MB3797; X-Forefront-PRVS: 05568D1FF7 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(346002)(39380400002)(396003)(376002)(366004)(39860400002)(189003)(199004)(97736004)(68736007)(36756003)(50226002)(4326008)(86362001)(16526018)(81156014)(81166006)(8936002)(33026002)(55016002)(105586002)(5660300001)(106356001)(69596002)(3846002)(53936002)(66066001)(7736002)(305945005)(47776003)(2906002)(6116002)(76176011)(26005)(59450400001)(386003)(4720700003)(50466002)(52116002)(6666003)(51416003)(6916009)(7696005)(25786009)(21086003)(2950100002)(48376002)(16586007)(54906003)(8676002)(316002)(478600001); DIR:OUT; SFP:1101; SCL:1; SRVR:AM6PR0502MB3797; H:mellanox.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A: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; AM6PR0502MB3797; 23:yci3h7tuMFk+RSUypBZzA8WZA/zIVjBvY56oUG4?= =?us-ascii?Q?U1oQwDbPORxtmfF9Hk/Y3hOFJR5nm7kuRcDIj7467Hvnua/IQuUoaJVrlLWS?= =?us-ascii?Q?0GOTE5xqi1LsKYegysixDDn0NM4xs0tANNfPoV7nBw6Uxl7GiqOCSwAWdBf4?= =?us-ascii?Q?lIOyINp8WoVy0t8fa+eJPZEKd0JFhgwKGuOyT14zRoy+iCY7Jn+IicQsKmZj?= =?us-ascii?Q?KATxwSQMT4v1tETwImVfrDcdfyrNSAF3SJj48vjxnTi6mK6hqf7Ltk9GVzOB?= =?us-ascii?Q?NHoBzd+rgK5P+k8PvRciLk1ykKitqHoUnN5uJTpMZxXnqHavnUk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A7g80wpKsUL0N?= X-Microsoft-Exchange-Diagnostics: 1; AM6PR0502MB3797; 6:1HESb4mjBSt7cSHDFdrFxOywwJGhhe4gQAsjIsK3/YPBlwvy/FAmejyP4fOHoMOL/SX+T8k+6cdFyptSvP6Gp/bct+XdDAiRAvy2M6SMquz2tQjBCoJIfA//D9MWVXhMH/0IL0DmagESbjvxGcFbzai9zFzu9oPvTjH/hOYt3Ov8ZPCJuhWDhMfP6tgY6eKLO2FcFmxK0o1obL4s4RO10TxVkGregi55FMsCy3iLZ1LIdD5DLG9PORiDUtbjkKxvfpXnezSGhHrqgJjThjzD/Iq/wmCJX46xnxvvoqKvNlAe773V0K4qAIoLHciezaN/YXqKa90CwRexU551TcrJAMaqDm2ju2h9vBUNumNheD4=; 5:AzAIDHo4CWzkV5GRBKBtgEv068U+hqvqMcYq52Ywdirhp698zs/FRwS/EenYnrXnGkIBlYFuQ0I6EvNpUt1K7Os/sWw1o/+In2gFjX7FKbOQfZjWsh0GKHI167FJvSvS9sL1DseC3FdIe/Wcwfc5SKuEbXWTOLR9K9hLJXDmULs=; 24:B0EZs7ejdlz9Ge7sadUA4mDibIUCl7OZh6FmzzqPJGGE71x23bBPgJ9p2wxjFsRE+Y6XMAByDBQIUOdPz497MneoLCT21aw6HX/C85tXHDo=; 7:ePDs3Ndsd8FyWvaB4/ZMuYyyI3bYPwlDO+MbFUuotUwhbHbdbR8ks0Ap4zVbNhpxyZtDq+F+ik6+2/t4sSBgxC4hBpPJTzDXdp1mYgPbRgsHBOlFgL/bcAFt+Ly9ZEsP/zRPeE1Gqo4XS/fX/zzX3GJcIkLrh9ehGaQr5r1nb0tnNlsna+90ut/gA8/drjUDQNlgtMAcWHPFO7iAALqUoYk1PHXrCBCiXixVbkJFqczyZfELwgYZ9wrwcqMwG6bi SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jan 2018 08:44:06.9142 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 007d96d1-9d5e-461a-4f55-08d55e4fa347 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR0502MB3797 Subject: [dpdk-dev] [PATCH v4 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 08:44:09 -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 Cc: 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..db5235b 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, fd | O_NONBLOCK) == -1) + goto error; + fp = fdopen(fd, "r"); + if (!fp) + 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