From: Gaetan Rivet <gaetan.rivet@6wind.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH 08/12] net/failsafe: add flexible device definition
Date: Fri, 3 Mar 2017 16:40:30 +0100 [thread overview]
Message-ID: <9e230b6fec17e05d004184accd10dbc9f50976ca.1488550982.git.gaetan.rivet@6wind.com> (raw)
In-Reply-To: <cover.1488550982.git.gaetan.rivet@6wind.com>
Add the "exec" device type.
The parameters given to this type of device will be executed in a shell.
The output of this command is then used as a definition for a device.
That command can be re-interpreted if the related device is not
plugged-in. It allows for a device definition to react to system
changes (e.g. changing PCI bus for a given device).
Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
Acked-by: Olga Shern <olgas@mellanox.com>
---
drivers/net/failsafe/failsafe_args.c | 102 ++++++++++++++++++++++++++++++++
drivers/net/failsafe/failsafe_ether.c | 7 +++
drivers/net/failsafe/failsafe_private.h | 4 ++
3 files changed, 113 insertions(+)
diff --git a/drivers/net/failsafe/failsafe_args.c b/drivers/net/failsafe/failsafe_args.c
index 773b322..839831f 100644
--- a/drivers/net/failsafe/failsafe_args.c
+++ b/drivers/net/failsafe/failsafe_args.c
@@ -112,6 +112,80 @@ parse_device(struct sub_device *sdev, char *args)
return 0;
}
+static void
+sanitize_cmdline(char *args)
+{
+ size_t len;
+
+ len = strnlen(args, DEVARGS_MAXLEN);
+ args[len - 1] = '\0';
+}
+
+static int
+execute_cmd(struct sub_device *sdev, char *cmdline)
+{
+ FILE *fp;
+ /* store possible newline as well */
+ char output[DEVARGS_MAXLEN + 1];
+ size_t len;
+ int old_err;
+ int ret;
+
+ DEBUG("'%s'", cmdline);
+ if (cmdline == NULL &&
+ sdev->cmdline == NULL) {
+ /* debug: should never happen to a user */
+ DEBUG("Invalid command line");
+ return -EINVAL;
+ }
+ if (sdev->cmdline == NULL) {
+ char *new_str;
+
+ len = strlen(cmdline) + 1;
+ new_str = rte_realloc(sdev->cmdline, len,
+ RTE_CACHE_LINE_SIZE);
+ if (new_str == NULL) {
+ ERROR("Command line allocation failed");
+ return -ENOMEM;
+ }
+ sdev->cmdline = new_str;
+ snprintf(sdev->cmdline, len, "%s", cmdline);
+ } else {
+ if (strcmp(sdev->cmdline, cmdline))
+ DEBUG("cmd mismatch: '%s' != '%s'",
+ sdev->cmdline, cmdline);
+ cmdline = sdev->cmdline;
+ }
+ old_err = errno;
+ fp = popen(cmdline, "r");
+ if (fp == NULL) {
+ ret = errno;
+ ERROR("popen: %s", strerror(errno));
+ errno = old_err;
+ return ret;
+ }
+ /* We only read one line */
+ if (fgets(output, sizeof(output) - 1, fp) == NULL) {
+ DEBUG("Could not read command output");
+ return -ENODEV;
+ }
+ sanitize_cmdline(output);
+ ret = parse_device(sdev, output);
+ if (ret) {
+ ERROR("Parsing device '%s' failed", output);
+ goto ret_pclose;
+ }
+ret_pclose:
+ ret = pclose(fp);
+ if (ret) {
+ ret = errno;
+ ERROR("pclose: %s", strerror(errno));
+ errno = old_err;
+ return ret;
+ }
+ return ret;
+}
+
static int
parse_device_param(struct rte_eth_dev *dev, const char *param,
uint8_t head)
@@ -146,6 +220,14 @@ parse_device_param(struct rte_eth_dev *dev, const char *param,
ret = parse_device(sdev, args);
if (ret)
goto free_args;
+ } else if (strncmp(param, "exec", 4) == 0) {
+ ret = execute_cmd(sdev, args);
+ if (ret == -ENODEV) {
+ DEBUG("Reading device info from command line failed");
+ ret = 0;
+ }
+ if (ret)
+ goto free_args;
} else {
ERROR("Unrecognized device type: %.*s", (int)b, param);
return -EINVAL;
@@ -347,6 +429,8 @@ failsafe_args_free(struct rte_eth_dev *dev)
uint8_t i;
FOREACH_SUBDEV(sdev, i, dev) {
+ rte_free(sdev->cmdline);
+ sdev->cmdline = NULL;
free(sdev->devargs.args);
sdev->devargs.args = NULL;
}
@@ -377,3 +461,21 @@ failsafe_args_count_subdevice(struct rte_eth_dev *dev,
return parse_sub_devices(count_device,
dev, params);
}
+
+int
+failsafe_args_parse_subs(struct rte_eth_dev *dev)
+{
+ struct sub_device *sdev;
+ uint8_t i;
+ int ret = 0;
+
+ FOREACH_SUBDEV(sdev, i, dev) {
+ if (sdev->state >= DEV_PARSED)
+ continue;
+ if (sdev->cmdline)
+ ret = execute_cmd(sdev, sdev->cmdline);
+ if (ret == 0)
+ sdev->state = DEV_PARSED;
+ }
+ return 0;
+}
diff --git a/drivers/net/failsafe/failsafe_ether.c b/drivers/net/failsafe/failsafe_ether.c
index 9f4a0a0..2d90bcb 100644
--- a/drivers/net/failsafe/failsafe_ether.c
+++ b/drivers/net/failsafe/failsafe_ether.c
@@ -188,6 +188,13 @@ failsafe_eth_dev_state_sync(struct rte_eth_dev *dev)
int ret;
uint8_t i;
+ if (PRIV(dev)->state < DEV_PARSED)
+ return 0;
+
+ ret = failsafe_args_parse_subs(dev);
+ if (ret)
+ return ret;
+
if (PRIV(dev)->state < DEV_PROBED)
return 0;
ret = failsafe_eal_init(dev);
diff --git a/drivers/net/failsafe/failsafe_private.h b/drivers/net/failsafe/failsafe_private.h
index 8659c6f..c1aa24d 100644
--- a/drivers/net/failsafe/failsafe_private.h
+++ b/drivers/net/failsafe/failsafe_private.h
@@ -94,6 +94,9 @@ struct sub_device {
struct rte_eth_dev_data data;
/* Device state machine */
enum dev_state state;
+
+ /* Some device are defined as a command line */
+ char *cmdline;
};
struct fs_priv {
@@ -140,6 +143,7 @@ uint16_t failsafe_tx_burst(void *txq,
int failsafe_args_parse(struct rte_eth_dev *dev, const char *params);
void failsafe_args_free(struct rte_eth_dev *dev);
int failsafe_args_count_subdevice(struct rte_eth_dev *dev, const char *params);
+int failsafe_args_parse_subs(struct rte_eth_dev *dev);
/* EAL */
--
2.1.4
next prev parent reply other threads:[~2017-03-03 15:40 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-03 15:40 [dpdk-dev] [PATCH 00/12] introduce fail-safe PMD Gaetan Rivet
2017-03-03 15:40 ` [dpdk-dev] [PATCH 01/12] ethdev: save VLAN filter setting Gaetan Rivet
2017-03-03 17:33 ` Stephen Hemminger
2017-03-03 15:40 ` [dpdk-dev] [PATCH 02/12] ethdev: add flow API rule copy function Gaetan Rivet
2017-03-03 15:40 ` [dpdk-dev] [PATCH 03/12] ethdev: add deferred intermediate device state Gaetan Rivet
2017-03-03 17:34 ` Stephen Hemminger
2017-03-03 15:40 ` [dpdk-dev] [PATCH 04/12] pci: expose device detach routine Gaetan Rivet
2017-03-03 15:40 ` [dpdk-dev] [PATCH 05/12] pci: expose parse and probe routines Gaetan Rivet
2017-03-03 15:40 ` [dpdk-dev] [PATCH 06/12] net/failsafe: add fail-safe PMD Gaetan Rivet
2017-03-03 17:38 ` Stephen Hemminger
2017-03-06 14:19 ` Gaëtan Rivet
2017-03-03 15:40 ` [dpdk-dev] [PATCH 07/12] net/failsafe: add plug-in support Gaetan Rivet
2017-03-03 15:40 ` Gaetan Rivet [this message]
2017-03-03 15:40 ` [dpdk-dev] [PATCH 09/12] net/failsafe: support flow API Gaetan Rivet
2017-03-03 15:40 ` [dpdk-dev] [PATCH 10/12] net/failsafe: support offload capabilities Gaetan Rivet
2017-03-03 15:40 ` [dpdk-dev] [PATCH 11/12] net/failsafe: add fast burst functions Gaetan Rivet
2017-03-03 15:40 ` [dpdk-dev] [PATCH 12/12] net/failsafe: support device removal Gaetan Rivet
2017-03-03 16:14 ` [dpdk-dev] [PATCH 00/12] introduce fail-safe PMD Bruce Richardson
2017-03-06 13:53 ` Gaëtan Rivet
2017-03-03 17:27 ` Stephen Hemminger
2017-03-08 15:15 ` [dpdk-dev] [PATCH v2 00/13] " Gaetan Rivet
2017-03-08 15:15 ` [dpdk-dev] [PATCH v2 01/13] ethdev: save VLAN filter setting Gaetan Rivet
2017-03-08 15:15 ` [dpdk-dev] [PATCH v2 02/13] ethdev: add flow API rule copy function Gaetan Rivet
2017-03-08 15:15 ` [dpdk-dev] [PATCH v2 03/13] ethdev: add deferred intermediate device state Gaetan Rivet
2017-03-08 15:15 ` [dpdk-dev] [PATCH v2 04/13] pci: expose device detach routine Gaetan Rivet
2017-03-08 15:15 ` [dpdk-dev] [PATCH v2 05/13] pci: expose parse and probe routines Gaetan Rivet
2017-03-08 15:15 ` [dpdk-dev] [PATCH v2 06/13] net/failsafe: add fail-safe PMD Gaetan Rivet
2017-03-08 15:15 ` [dpdk-dev] [PATCH v2 07/13] net/failsafe: add plug-in support Gaetan Rivet
2017-03-08 15:15 ` [dpdk-dev] [PATCH v2 08/13] net/failsafe: add flexible device definition Gaetan Rivet
2017-03-08 15:15 ` [dpdk-dev] [PATCH v2 09/13] net/failsafe: support flow API Gaetan Rivet
2017-03-08 15:15 ` [dpdk-dev] [PATCH v2 10/13] net/failsafe: support offload capabilities Gaetan Rivet
2017-03-08 15:15 ` [dpdk-dev] [PATCH v2 11/13] net/failsafe: add fast burst functions Gaetan Rivet
2017-03-08 15:15 ` [dpdk-dev] [PATCH v2 12/13] net/failsafe: support device removal Gaetan Rivet
2017-03-08 15:15 ` [dpdk-dev] [PATCH v2 13/13] net/failsafe: support link status change event Gaetan Rivet
2017-03-08 16:54 ` [dpdk-dev] [PATCH v2 00/13] introduce fail-safe PMD Neil Horman
2017-03-09 9:15 ` Bruce Richardson
2017-03-10 9:13 ` Gaëtan Rivet
2017-03-10 22:43 ` Neil Horman
2017-03-14 14:49 ` Gaëtan Rivet
2017-03-15 3:28 ` Bruce Richardson
2017-03-15 11:15 ` Thomas Monjalon
2017-03-15 14:25 ` Gaëtan Rivet
2017-03-16 20:50 ` Neil Horman
2017-03-17 10:56 ` Gaëtan Rivet
2017-03-18 19:51 ` Neil Horman
2017-03-20 15:00 ` Thomas Monjalon
2017-05-17 12:50 ` Ferruh Yigit
2017-05-17 16:59 ` Gaëtan Rivet
2017-03-23 13:01 ` Ferruh Yigit
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9e230b6fec17e05d004184accd10dbc9f50976ca.1488550982.git.gaetan.rivet@6wind.com \
--to=gaetan.rivet@6wind.com \
--cc=dev@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).