metrics: return error code on initialization failures

DPDK libraries should never call rte_exit on failure, so change the
function return type of rte_metrics_init to "int" to allow returning an
error code to the application rather than exiting the whole app on init
failure.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
This commit is contained in:
Bruce Richardson 2022-09-29 10:38:29 +01:00 committed by David Marchand
parent 9856af4044
commit 6d03ef606b
4 changed files with 17 additions and 9 deletions

View File

@ -154,8 +154,5 @@ Deprecation Notices
Event will be one of the configuration fields,
together with additional vector parameters.
* metrics: The function ``rte_metrics_init`` will have a non-void return
in order to notify errors instead of calling ``rte_exit``.
* raw/dpaa2_cmdif: The ``dpaa2_cmdif`` rawdev driver will be deprecated
in DPDK 22.11, as it is no longer in use, no active user known.

View File

@ -247,6 +247,9 @@ API Changes
and security capability structure ``rte_security_capability``
to accommodate MACsec capabilities.
* metrics: Updated ``rte_metrics_init`` so it returns an error code instead
of calling ``rte_exit``.
* telemetry: The allowed characters in names for dictionary values
are now limited to alphanumeric characters and a small subset of additional
printable characters.

View File

@ -5,6 +5,7 @@
#include <stdlib.h>
#include <string.h>
#include <rte_errno.h>
#include <rte_common.h>
#include <rte_string_fns.h>
#include <rte_metrics.h>
@ -54,28 +55,29 @@ struct rte_metrics_data_s {
rte_spinlock_t lock;
};
void
int
rte_metrics_init(int socket_id)
{
struct rte_metrics_data_s *stats;
const struct rte_memzone *memzone;
if (metrics_initialized)
return;
return 0;
if (rte_eal_process_type() != RTE_PROC_PRIMARY)
return;
return -E_RTE_SECONDARY;
memzone = rte_memzone_lookup(RTE_METRICS_MEMZONE_NAME);
if (memzone != NULL)
return;
return -EEXIST;
memzone = rte_memzone_reserve(RTE_METRICS_MEMZONE_NAME,
sizeof(struct rte_metrics_data_s), socket_id, 0);
if (memzone == NULL)
rte_exit(EXIT_FAILURE, "Unable to allocate stats memzone\n");
return -ENOMEM;
stats = memzone->addr;
memset(stats, 0, sizeof(struct rte_metrics_data_s));
rte_spinlock_init(&stats->lock);
metrics_initialized = 1;
return 0;
}
int

View File

@ -79,8 +79,14 @@ struct rte_metric_value {
*
* @param socket_id
* Socket to use for shared memory allocation.
* @return
* 0 on success
* Negative error code (from rte_errno.h) on error:
* -EEXIST - a memzone for metrics already exists but metrics is not initialized
* -ENOMEM - cannot allocate metrics memzone
* -E_RTE_SECONDARY - function called from secondary process
*/
void rte_metrics_init(int socket_id);
int rte_metrics_init(int socket_id);
/**
* Deinitialize metric module. This function must be called from