net/failsafe: add fd parameter
This parameter enables applications to provide device definitions through an arbitrary file descriptor number. Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com> Signed-off-by: Matan Azrad <matan@mellanox.com> Acked-by: Gaetan Rivet <gaetan.rivet@6wind.com>
This commit is contained in:
parent
9720e325f0
commit
d1b961dba6
@ -106,6 +106,15 @@ Fail-safe command line parameters
|
|||||||
All commas within the ``shell command`` are replaced by spaces before
|
All commas within the ``shell command`` are replaced by spaces before
|
||||||
executing the command. This helps using scripts to specify devices.
|
executing the command. This helps using scripts to specify devices.
|
||||||
|
|
||||||
|
- **fd(<file descriptor number>)** parameter
|
||||||
|
|
||||||
|
This parameter reads a device definition from an arbitrary file descriptor
|
||||||
|
number in ``<iface>`` 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]
|
- **mac** parameter [MAC address]
|
||||||
|
|
||||||
This parameter allows the user to set a default MAC address to the fail-safe
|
This parameter allows the user to set a default MAC address to the fail-safe
|
||||||
|
@ -31,7 +31,11 @@
|
|||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include <rte_debug.h>
|
#include <rte_debug.h>
|
||||||
@ -160,6 +164,67 @@ ret_pclose:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
static int
|
||||||
fs_parse_device_param(struct rte_eth_dev *dev, const char *param,
|
fs_parse_device_param(struct rte_eth_dev *dev, const char *param,
|
||||||
uint8_t head)
|
uint8_t head)
|
||||||
@ -202,6 +267,14 @@ fs_parse_device_param(struct rte_eth_dev *dev, const char *param,
|
|||||||
}
|
}
|
||||||
if (ret)
|
if (ret)
|
||||||
goto free_args;
|
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 {
|
} else {
|
||||||
ERROR("Unrecognized device type: %.*s", (int)b, param);
|
ERROR("Unrecognized device type: %.*s", (int)b, param);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@ -409,6 +482,8 @@ failsafe_args_free(struct rte_eth_dev *dev)
|
|||||||
FOREACH_SUBDEV(sdev, i, dev) {
|
FOREACH_SUBDEV(sdev, i, dev) {
|
||||||
free(sdev->cmdline);
|
free(sdev->cmdline);
|
||||||
sdev->cmdline = NULL;
|
sdev->cmdline = NULL;
|
||||||
|
free(sdev->fd_str);
|
||||||
|
sdev->fd_str = NULL;
|
||||||
free(sdev->devargs.args);
|
free(sdev->devargs.args);
|
||||||
sdev->devargs.args = NULL;
|
sdev->devargs.args = NULL;
|
||||||
}
|
}
|
||||||
@ -424,7 +499,8 @@ fs_count_device(struct rte_eth_dev *dev, const char *param,
|
|||||||
param[b] != '\0')
|
param[b] != '\0')
|
||||||
b++;
|
b++;
|
||||||
if (strncmp(param, "dev", b) != 0 &&
|
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);
|
ERROR("Unrecognized device type: %.*s", (int)b, param);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
@ -463,6 +539,8 @@ failsafe_args_parse_subs(struct rte_eth_dev *dev)
|
|||||||
continue;
|
continue;
|
||||||
if (sdev->cmdline)
|
if (sdev->cmdline)
|
||||||
ret = fs_execute_cmd(sdev, sdev->cmdline);
|
ret = fs_execute_cmd(sdev, sdev->cmdline);
|
||||||
|
else if (sdev->fd_str)
|
||||||
|
ret = fs_read_fd(sdev, sdev->fd_str);
|
||||||
else
|
else
|
||||||
ret = fs_parse_sub_device(sdev);
|
ret = fs_parse_sub_device(sdev);
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
|
@ -48,6 +48,7 @@
|
|||||||
#define PMD_FAILSAFE_PARAM_STRING \
|
#define PMD_FAILSAFE_PARAM_STRING \
|
||||||
"dev(<ifc>)," \
|
"dev(<ifc>)," \
|
||||||
"exec(<shell command>)," \
|
"exec(<shell command>)," \
|
||||||
|
"fd(<fd number>)," \
|
||||||
"mac=mac_addr," \
|
"mac=mac_addr," \
|
||||||
"hotplug_poll=u64" \
|
"hotplug_poll=u64" \
|
||||||
""
|
""
|
||||||
@ -112,6 +113,8 @@ struct sub_device {
|
|||||||
struct fs_stats stats_snapshot;
|
struct fs_stats stats_snapshot;
|
||||||
/* Some device are defined as a command line */
|
/* Some device are defined as a command line */
|
||||||
char *cmdline;
|
char *cmdline;
|
||||||
|
/* Others are retrieved through a file descriptor */
|
||||||
|
char *fd_str;
|
||||||
/* fail-safe device backreference */
|
/* fail-safe device backreference */
|
||||||
struct rte_eth_dev *fs_dev;
|
struct rte_eth_dev *fs_dev;
|
||||||
/* flag calling for recollection */
|
/* flag calling for recollection */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user