From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by dpdk.org (Postfix) with ESMTP id AA8F11B424 for ; Fri, 22 Dec 2017 19:01:45 +0100 (CET) Received: by mail-wm0-f67.google.com with SMTP id r78so23357413wme.5 for ; Fri, 22 Dec 2017 10:01:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=iOdKaNYm57dM0cl2NqrczxFGg6zkzYxibma7eed0/HE=; b=pKii18NWfQuurtfoR14lJbnfBO18nM+Xw+tXpEGba0msXksdiv5S/4HNDPweYweB6+ ZR5bGmR2HsF5Z2+pAHncwK2mZGfnzkLvL5mycTPFnIzk6BLphxetcaKU0jrgBYXokfv+ I07JmzRfR8/7sOnnRkZPs6aNJBRI2t4CBmbIgJmtJIlW6WTmTcHOnm2i98QClezCpzdA gAf1GnqOEjvCgYRcy2BS4k7fpeSoQhLfpswDnhxkpwrcQtoS6Wl048Nf8T1NqkgaGjsN cSvcyBXbNkiWP1y9vxVOuHRHmk2989tGJI9r/whjo6KdobxmOTHDiSQZPa3/pItiocAf zrZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=iOdKaNYm57dM0cl2NqrczxFGg6zkzYxibma7eed0/HE=; b=T5QLlp4bWuCO/yt+bvwEW1FiZOW5qFhqbC97LMOZoziu3hFplIPp/xHZ/Kw11diKr7 VVm4gi2ni0FheyRbZ1j57Hy17Dyw8yRMO1/Gu/uVkLZKUwSWJhAELq6VcA4s1Ku8j15d vrxPqnl4p/jTguWkJaGgbwuvwD0VJXNOa6JPimyZPU7/JjuR/YReM5HQnYUBNy3ejZ7x zaPkEIclIPqodAVb87Txa3ZlwPhvqUChwNXumiC67tQQC8DxOjJV1NTM37qVbXa39Xac UqGF0fNbjmYPmloKKXS9OHiF8HgGy/d2E9hRgN5JZpu3ZUeiVm7q3BHD5HecASf0O3mU QzMg== X-Gm-Message-State: AKGB3mI66uLTf8I90vAqmP59rrGmcrzZAWl0Y6C0Zf8ICHZ/vbY/IBKB 4maznmuSlgEYJ/Q6xiwyHhUdZg== X-Google-Smtp-Source: ACJfBot4DPs1UCwspkKdwXWTo82FdkLUduEAinYPTirWKODumFqkdYooesaDT4qm5MYH4/spY33ePg== X-Received: by 10.28.193.66 with SMTP id r63mr12107017wmf.18.1513965705338; Fri, 22 Dec 2017 10:01:45 -0800 (PST) Received: from 6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id 47sm4111227wru.27.2017.12.22.10.01.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Dec 2017 10:01:44 -0800 (PST) Date: Fri, 22 Dec 2017 19:01:33 +0100 From: Adrien Mazarguil To: Ferruh Yigit Cc: dev@dpdk.org, Gaetan Rivet Message-ID: <20171222173846.20731-3-adrien.mazarguil@6wind.com> References: <20171218162443.12971-1-adrien.mazarguil@6wind.com> <20171222173846.20731-1-adrien.mazarguil@6wind.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171222173846.20731-1-adrien.mazarguil@6wind.com> X-Mailer: git-send-email 2.11.0 Subject: [dpdk-dev] [PATCH v2 2/5] 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: Fri, 22 Dec 2017 18:01:45 -0000 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 c4e3d2e8d..5b1b47e56 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 ec63ac972..7a8605174 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 @@ fs_execute_cmd(struct sub_device *sdev, char *cmdline) } 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 @@ fs_parse_device_param(struct rte_eth_dev *dev, const char *param, } 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 @@ failsafe_args_free(struct rte_eth_dev *dev) 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 @@ fs_count_device(struct rte_eth_dev *dev, const char *param, 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 @@ failsafe_args_parse_subs(struct rte_eth_dev *dev) 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 d81cc3ca6..a0d36751f 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 */ -- 2.11.0