From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-eopbgr00045.outbound.protection.outlook.com [40.107.0.45]) by dpdk.org (Postfix) with ESMTP id 97DAF1B025 for ; Thu, 18 Jan 2018 11:02:05 +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=iQhIZwtRZkTOwkZz42Ju7iwMv2EK0/DBa1elds+Tz0k=; b=O8EgZzRyBJ8GczD9ugFDDXw0tUqnVun2vF+/10Fbxhg815WtD06ux/1u67648cqev1LRcKuzOkFZaQQSzyC/S5pPuxkhhMcpJkikVWK2KSGqubkyV8Xi4kxFVHRU5uqLrQ5mn2b+NTi6tE6jqw6xMIWBiRsB+9GoN/ZM6OWd2Qw= 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 10:02:03 +0000 From: Matan Azrad To: Ferruh Yigit Cc: Thomas Monjalon , dev@dpdk.org, stephen@networkplumber.org, Adrien Mazarguil Date: Thu, 18 Jan 2018 10:01:43 +0000 Message-Id: <1516269709-15252-3-git-send-email-matan@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1516269709-15252-1-git-send-email-matan@mellanox.com> References: <1516265026-6469-1-git-send-email-matan@mellanox.com> <1516269709-15252-1-git-send-email-matan@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [37.142.13.130] X-ClientProxiedBy: VI1PR0202CA0033.eurprd02.prod.outlook.com (2603:10a6:803:14::46) To AM6PR0502MB3797.eurprd05.prod.outlook.com (2603:10a6:209:a::26) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 670e685b-f5e2-4c30-6e25-08d55e5a86ad 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:ZhZbf8XzjIKg+PbotUbmin7njZxlZK3CQzTwNlc1d9vkMRJpBwhRZpYPpje0y7rkOU93lt0EWydsPU1J16k+zfIkPdyVbBUjh7PdNVufyH9Wuyx3yhb+F94AiNYLGMNZDIwDPnAvXNVE3SeuRpA9rcGvshNYc6HNYSGJmouZenxuZppNjgBdAT7LfSN0iEpSsUqxBYZSxP+FSf5u1YT9a5R0IKm1+VcqyaKYKBPKJAn4irRCxwtrgRap6FEU+Dw5; 25:CtSvVK7IMBFcpk6iq1fL5tE+pLgpw/Mh7RO9pXu8NJUzBMrNSpbfhG9mwRiajGzSKYZHIdViBuDnuPDsDQtDQMBY8i9fGkzJkEw+qcLvFxq0xL1YdNLpjZ/v+/SbWx5JBumSIoy7wupA/oxiDMo6HHm0RbaguE2TUCNefVzccUKS2Buw0QfbWd9vtJHtI7YxiCBbU2NjSDDpEVZ/nVQbH6f/XvQDreZBrA0wySJMMRByjVJwp6GE/r5+ETaR5O9cDqX5KujM4P+Xb7mzov0PH4Dac62to9WtkldyZmhK4maNpca8786x1AGIMrfPoLCB1gRd7Ny9faC8z2HhyAM0dg==; 31:vorfYAswyV8UZKvaa4pUeFrXSsjLPUTlcdSS9Y6K2zprmROjpe+PYozO8k1ra/kqxYWEvl/nBBT5W2NE8DjSULy3vXpdBnjTcxpRcqh4wBVFLZ+Tw/uLEUaFNxB6sEla1uEKC3c0R2Xd+ScvrP9kBYYzI1sHoIZnNoP6F+B4tsZ/2BeWx/3rwX02cYqQNWbIGaSqjPCYkmclT5P3fDpQHKztJeoS7DHdiSQvzI/Wc34= X-MS-TrafficTypeDiagnostic: AM6PR0502MB3797: X-LD-Processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; AM6PR0502MB3797; 20:s9hTQKa8RuhnjuaNA6llYXi3ybRHhkr80S2vQ0VAu7Mk129EM9CACvLSdCiu3ovmy3eMJXVMH4ysDQHxbRrymDaDX/uIE/9md8wlju5YsXeeCI8MhIcjXwVnqplcCgnR9N5OkAb7mg6tBvxJaVHYAzey3OOaeirYj7cQmyNTZ32rYj4coQpa2Aqg5waNT4VOZ4WniMWfpsPMAbo4rWHTBtjl23Lb2eztQgXLuDsoK1seAl3QBtlP0OA2rhHAhBWWtZ5zcKO/PUjz0iGriI3YPFT/4ElZcPGuBQ78zRIm9eG/X/ogR9UivmJTbqvKXciexAljuDkJ33F1Df9sfzoAPDwG3J61hMYhxi6racuUbtf5PveIKeBU/NFX+73cGQYlr2v6HVB5X0hWmjKhm8axYYdOkxdn0qhy3XZVynOfNUocePmglFoYkKUkLTjzP23vEqTGBO4+lKpj2eqWRlEcjeDqpWi5oOYfUVAaq9w+6OadBLrw54UcuUQDTPyY8fKj; 4:vSn1/LnuvFZ0njG5pfybc4ed4C7rN4lc1tKv98a9O4+x36miYe3I5zu/GKOVclWUctVVmF/QR6nJx1c2fp8CQJgGD6QU92FMEK0vxOwTFTMgjfY483jKX07tkNXQaK8op+KMoLO+zi/XTgn5Un3N6WFSAfEIFjGegyUoERdx94e7aJXLlJh/yDNL2Rkx3f+9RQGAmhYp/ifnQQHB0UQSogSDsIiF7MUhHAGOLHLvQJvj9oASjGPdZASctpdcHUtL6qEijXK0bnIx4EE8oRcdvdscjLJNNQvLDLyhXQ+wvEmPjHkhPp6k+aP1S2WiIJ2Y 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)(2400060)(944501161)(3002001)(93006095)(93001095)(6055026)(6041268)(20161123558120)(20161123564045)(20161123560045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(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)(39860400002)(366004)(39380400002)(346002)(396003)(376002)(199004)(189003)(6116002)(53936002)(76176011)(386003)(4720700003)(59450400001)(26005)(7736002)(305945005)(50466002)(66066001)(2906002)(47776003)(16586007)(54906003)(8676002)(478600001)(316002)(21086003)(2950100002)(25786009)(48376002)(52116002)(6666003)(51416003)(7696005)(6916009)(81166006)(81156014)(8936002)(4326008)(86362001)(16526018)(97736004)(68736007)(36756003)(50226002)(5660300001)(105586002)(3846002)(69596002)(106356001)(33026002)(55016002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM6PR0502MB3797; 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; AM6PR0502MB3797; 23:RLMNwvK6EUSuq1HxsQw87BpEmgVIryqFhlHmSI+?= =?us-ascii?Q?ErqrTUB2KO2zUxqaneKwvQTDTpvu350SajuMw23PW23fdqy0AUJDyg/lmAM2?= =?us-ascii?Q?YE6FtffYbxHByMEJ5mwqI4cqZ4tTLCR17CDspdBTEK/QP/30ZfKR3F9qZCOX?= =?us-ascii?Q?ugBarwTzEtttVmjJ+aCe+QiXy7xVjtLN9sYDvJsQpH81UguQHUQT1MvK6ffb?= =?us-ascii?Q?Ka7rd8IvcFf5mJPRZiNsUp7JluT5HhkNe2tJuAw5N+j4iNCpZ47pUM7JT4Oh?= =?us-ascii?Q?/AZf1h4nhSVWI2hqmsDRcrsS8SxBU5fKl8WseXfHM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q8kjWyi0Jahl2hDt70NO?= X-Microsoft-Exchange-Diagnostics: 1; AM6PR0502MB3797; 6:rsDUugBV6L+I938LTYaF0gNtGEC3pAf9hEoPr7SN71ETx1imS3uwlNxClfs0hMp0bCiiKDahROXGOT6eDPIGUf/N/uJZpGsMvnHjm6fdbGsloqnSfpKh1HZGp2y1WLPamupiIHjRat77vL/dOqR2ZAXL2yPU6DMUs08DfbZLOksJdolVvZLV9b26jx77AZCB7qGx1LVa27Ld8txwcwbNOSD0io13jK7537QaOLxOHAfgmAHSXLUcbxE6PM/T0N80WQytKaYo1sBiHMOWT+pe5mMBjkiBTlAocyHNo6KbNsKtzNupJPn9QbKJIQkEC1asx+lHweslkz6SQesN/Jkvs9eI9p8IK/WBrA8PJNLNJLE=; 5:0HYgnWpPYFsQwq5dY7YQm8WDyTAGLI5mU/89SKT+rbo1k9Zu9WsE+oKtku4T5RyvyUWGLMrKQxD0ewExU9n1sqvOv7p7S3q7szQptwdjBx5EzEuNuutG+zPKmCp//t7xW1q7yacB5hSM0K//TNneat16oMC1IOE5QFG6E54ocvA=; 24:mQbwSOg2JQ2rQoRjq1Ckx1XaI0KCNs89alI2NqTRp5reZgK5VOJQ8oWpv93RG/zeyi53Zs16QT87tWHzIls4bMInTDJyUoG5JJkSvlH2ivU=; 7:mXV55GPq0CYPaVidZd/4/hHXtLZ615FauGJq55Itg+BwLw/6W2Pk29xswXke26+QVbJPwamkoddDbZHhb1SESf2qfOza1dIvZ6w0HtlY1rKAIaIfu8iOjVzlVqIvLOuXwBXrLn456jRJX0Rmx4LJ/0yf1pHh7+5wpeForKyqijU8C989gWDQ/4am//SDyBqzIUmk756pqcSnvs1kgt9AhD3f04eDGOy8DVtImrxA90vM+4naLi8YmiS64RnoIZry SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jan 2018 10:02:03.5029 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 670e685b-f5e2-4c30-6e25-08d55e5a86ad 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 v5 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 10:02:05 -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..c711da4 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