From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR02-VE1-obe.outbound.protection.outlook.com (mail-eopbgr20066.outbound.protection.outlook.com [40.107.2.66]) by dpdk.org (Postfix) with ESMTP id C6A011B1C4 for ; Tue, 9 Jan 2018 15:47:58 +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=hKvtXaF/ID0MobNf8nAkWG4J92BuoMTwEgFxprRZNlk=; b=oWfSTf1dkCuROpNS4YT2zTqh/F4chAdew+CXtjhshwUeJwS5FR1FPPRtYus+MueMmvzW8wMD7q/4tRb6aICb16rdyfgdGAQlvFBpeIrbRAWno4F1Ubsr1Hzga5iGaxgf4zZ4SnhSBQWC3GfuZVwAatN/lRiN72NcGZtRNczhCj0= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=matan@mellanox.com; Received: from mellanox.com (37.142.13.130) by AM6PR0502MB3799.eurprd05.prod.outlook.com (2603:10a6:209:a::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.386.5; Tue, 9 Jan 2018 14:47:56 +0000 From: Matan Azrad To: Ferruh Yigit Cc: Thomas Monjalon , dev@dpdk.org, stephen@networkplumber.org, Adrien Mazarguil , Gaetan Rivet Date: Tue, 9 Jan 2018 14:47:27 +0000 Message-Id: <1515509253-17834-3-git-send-email-matan@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1515509253-17834-1-git-send-email-matan@mellanox.com> References: <20171222173846.20731-1-adrien.mazarguil@6wind.com> <1515509253-17834-1-git-send-email-matan@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [37.142.13.130] X-ClientProxiedBy: HE1P191CA0006.EURP191.PROD.OUTLOOK.COM (2603:10a6:3:cf::16) To AM6PR0502MB3799.eurprd05.prod.outlook.com (2603:10a6:209:a::28) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 3c4cc321-2e3d-4a7b-b078-08d5576ff92f X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(48565401081)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:AM6PR0502MB3799; X-Microsoft-Exchange-Diagnostics: 1; AM6PR0502MB3799; 3:K9IkbA0jf5gzFc4QNBd33AJ18MpO1Koyk5clhdEwdMNCl0ychirVKtJTZqxwKTbgoZo6xW137FBFklJAorAbMhWEajabprK7TEbsXdCXchDt0ZF9xTh9GSnOBQLN9xyaijsBl/nU2Fxe9TbwNtzi/2ROSOr4p4tDy46by0y+JAE08nCCD9pnrw3osk+C0TrYSPPVrvkVPFKQYHSRipbT7WGD13pwJc68hZbdi/DjDI7XkT7yzEerGwMj2mtBAzEK; 25:ilf1MuVDcwZIL4WUBiMRczo3byuK6quYEwi1PfbhIscjawW8p7FfUGfBibWRfoir8JQObMNnCyBvyTk1eBA/9Tc5TYlf7e+DXAsAukviFDmDxvq3+1d2lQcGmlwS2ODiNHO9mwOcxO47flM4LJ2ae9yisgCbgKJLw5CMFr6/VOocKQ0JHOJsoUJxlRcbc1k/s89I6uG0Rks6B5J0lAcjd47bB70VH29v6jlKrbdn0mPICPrKqrCefU96PJCTp+AhYyY/SxqGApuxUe29bJiM0LpUSCUWcH2Auu12VtGjl08dga+RLFOIWaSyOn/CdEdRosHfh/9M7hbdEa30B65h5Q==; 31:Gumvc501TsLaltr4zw3OOJlVtAvyBh1fVzHJqbzesyd0kqTa4IWFfb7/D6VlaIL/rbSRRF1l0KJZRcw/W81zdapKX6McMO6qrY0bvAhz3dDHwOpJNUaGe78V5FmLEffJO9eIbVlKneU26F9JNSicDFK/BqD92JyiCXCcYEOOlgPaB1UsQqXMIH1jJXrqlsoKGGHAIVOSiVEL7zfmotoikTte+sBVqaea7luvPEWr+IM= X-MS-TrafficTypeDiagnostic: AM6PR0502MB3799: X-LD-Processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; AM6PR0502MB3799; 20:Y2+YZSI4iVYhdLcs5sE8Mw8aUYjEkSZgOzPeR6rocm4jLsX6tjpx7EvgZ+NvMK+05wNB9Gry07Fh/xE/bddzyVgNMhqRTY7nAG2tcpaWihphV+eyKqLrZda0rfVCopQ6lWYTdrVewfybOGYy2NX5EFDILZwbe3NYYVYnxqXDTTkIvuRH6N4061zA9GJnPOcfJX3Klq2GnzaR2XdAeS3N6U+C7YxQsjoEf8788PvdOsEv7dK/xrtaf2IzkJCQ2v4gjZPmLJuQooQDL78oKSlojrMbKap58ObslQdd5v/MeMVm77bXl12YJAQ0shV2joDn6nhtN9eNgyj0es0qcfoLc7L5zFzTL48yrL2L4/sIgH6g0K4leXCMexfXt2K1YuMiRxJrgdbksCzwvO45ta4DRrisA3t9EpM3C2bkXboAs6ch5ncZ691OpiGG4m4odMnfc04neQN1ZNfbMeRSyEHH7eM+cO7Bdw8jthb4HWJbPMot1fcuNBR/a24AiuI6Q0O+; 4:OgnbTIwZQKewSTFu0LV+8J5+J0AIK7XbHsbm7t4RPvWjPZb1A8mTCadRlq6bB/xFxKuOP9I5ikaFh639k61gNvTVVg0e7LcrK2xADtlmRT7IIvNCDGpqzytEtu3tNs5cpPfKlvZFEEMpk0dnGsMi8+j0Pn6nupYk52AcZGmnoE18gy0YqBoTodqgpVxLSsl3f+b2O+X9NwMrcJIdtkjaHwlikdSDsX0c05VstXQ+vwNvjjq6Vi1ykzsFW9aG0Ykfu6OKWL8XNRSra6CkVr5JRrC0SdKyH4uyLyDG1mPIyRHkpXAWLVRDT6hZ5cg3Trvx 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)(3231023)(944501075)(3002001)(10201501046)(93006095)(93001095)(6055026)(6041268)(20161123560045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(6072148)(201708071742011); SRVR:AM6PR0502MB3799; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:AM6PR0502MB3799; X-Forefront-PRVS: 0547116B72 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(396003)(39860400002)(39380400002)(346002)(366004)(376002)(189003)(199004)(21086003)(16586007)(8676002)(575784001)(8936002)(54906003)(316002)(3846002)(51416003)(97736004)(33026002)(386003)(6116002)(55016002)(81156014)(86362001)(16526018)(50466002)(48376002)(69596002)(81166006)(50226002)(76176011)(53936002)(2950100002)(6916009)(59450400001)(7696005)(105586002)(36756003)(68736007)(4720700003)(25786009)(5660300001)(106356001)(305945005)(47776003)(52116002)(2906002)(4326008)(7736002)(478600001)(66066001)(6666003); DIR:OUT; SFP:1101; SCL:1; SRVR:AM6PR0502MB3799; 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; AM6PR0502MB3799; 23:SA34iR7d7F9hLt84sCkoTRgo+BdVvBQwx11rE8O?= =?us-ascii?Q?Rt2C/iuNlpPRw6mgl7nMGHb36CTgDQdp4I4d9z7Ld3VZ1BGk5r309NXVsVPO?= =?us-ascii?Q?jWmsgMEpM+lsujAdj3R9aj07uErII3QUU4IdB21xgMIKf1AQeoCi8ejNOhjL?= =?us-ascii?Q?UW20ntqIL54sOeWJd8uMG/DQskGHgoLlW9P/s3FOMAcv25w5wMrqtNVZs56y?= =?us-ascii?Q?/RS/fGEjU63TQBSpwaLboMiQVAV/s/Ox7IVzoyun39RnFZs7AfdC63TsH9Jx?= =?us-ascii?Q?w6T+BxCLJIJgCKHzbq2R+7I5AKicBrAEfoCH3Q1K1nRGeym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g: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jan 2018 14:47:56.5494 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3c4cc321-2e3d-4a7b-b078-08d5576ff92f X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR0502MB3799 Subject: [dpdk-dev] [PATCH v3 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: Tue, 09 Jan 2018 14:47:59 -0000 From: Adrien Mazarguil This parameter enables applications to provide device definitions through an arbitrary file descriptor number. Signed-off-by: Adrien Mazarguil Cc: Gaetan Rivet --- doc/guides/nics/fail_safe.rst | 9 ++++ drivers/net/failsafe/failsafe_args.c | 86 ++++++++++++++++++++++++++++++++- drivers/net/failsafe/failsafe_private.h | 3 ++ 3 files changed, 97 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..7a86051 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,73 @@ 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 ret; + + 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; + ret = fcntl(fd, F_GETFL); + if (ret == -1) + goto error; + ret = fcntl(fd, F_SETFL, fd | O_NONBLOCK); + if (ret == -1) + goto error; + fp = fdopen(fd, "r"); + if (!fp) + goto error; + fd = -1; + /* Only take the last line into account */ + ret = 0; + while (fgets(output, sizeof(output), fp)) + ++ret; + if (feof(fp)) { + if (!ret) + goto error; + } else if (ferror(fp)) { + if (errno != EAGAIN || !ret) + goto error; + } else if (!ret) { + goto error; + } + /* Line must end with a newline character */ + fs_sanitize_cmdline(output); + if (output[0] == '\0') + goto error; + ret = fs_parse_device(sdev, output); + if (ret) + ERROR("Parsing device '%s' failed", output); + err = ret; +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 +273,14 @@ typedef int (parse_cb)(struct rte_eth_dev *dev, const char *params, } if (ret) goto free_args; + } else if (strncmp(param, "fd", 2) == 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 +488,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 +505,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 +545,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 d81cc3c..a0d3675 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" \ "" @@ -111,6 +112,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