numam-dpdk/drivers/bus/vdev/vdev_params.c
Olivier Matz 6aebb94290 kvargs: add function to get from key and value
A quite common scenario with kvargs is to lookup for a <key>=<value> in
a kvlist. For instance, check if name=foo is present in
name=toto,name=foo,name=bar. This is currently done in drivers/bus with
rte_kvargs_process() + the rte_kvargs_strcmp() handler.

This approach is not straightforward, and can be replaced by this new
function.

rte_kvargs_strcmp() is then removed.

Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
Reviewed-by: Xueming Li <xuemingl@nvidia.com>
Reviewed-by: David Marchand <david.marchand@redhat.com>
Acked-by: Ray Kinsella <mdr@ashroe.eu>
2021-09-30 17:38:02 +02:00

58 lines
1.2 KiB
C

/* SPDX-License-Identifier: BSD-3-Clause
* Copyright 2018 Gaëtan Rivet
*/
#include <string.h>
#include <rte_dev.h>
#include <rte_bus.h>
#include <rte_kvargs.h>
#include <rte_errno.h>
#include "vdev_logs.h"
#include "vdev_private.h"
enum vdev_params {
RTE_VDEV_PARAM_NAME,
RTE_VDEV_PARAM_MAX,
};
static const char * const vdev_params_keys[] = {
[RTE_VDEV_PARAM_NAME] = "name",
[RTE_VDEV_PARAM_MAX] = NULL,
};
static int
vdev_dev_match(const struct rte_device *dev,
const void *_kvlist)
{
const struct rte_kvargs *kvlist = _kvlist;
const char *key = vdev_params_keys[RTE_VDEV_PARAM_NAME];
if (rte_kvargs_get_with_value(kvlist, key, dev->name) == NULL)
return -1;
return 0;
}
void *
rte_vdev_dev_iterate(const void *start,
const char *str,
const struct rte_dev_iterator *it __rte_unused)
{
struct rte_kvargs *kvargs = NULL;
struct rte_device *dev;
if (str != NULL) {
kvargs = rte_kvargs_parse(str, vdev_params_keys);
if (kvargs == NULL) {
VDEV_LOG(ERR, "cannot parse argument list\n");
rte_errno = EINVAL;
return NULL;
}
}
dev = rte_vdev_find_device(start, vdev_dev_match, kvargs);
rte_kvargs_free(kvargs);
return dev;
}