* [PATCH] metrics: return error code on initialization failures
@ 2022-09-29 9:38 Bruce Richardson
2022-09-29 11:16 ` Morten Brørup
0 siblings, 1 reply; 3+ messages in thread
From: Bruce Richardson @ 2022-09-29 9:38 UTC (permalink / raw)
To: dev; +Cc: thomas, Bruce Richardson
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>
---
doc/guides/rel_notes/deprecation.rst | 3 ---
lib/metrics/rte_metrics.c | 12 +++++++-----
lib/metrics/rte_metrics.h | 8 +++++++-
3 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/doc/guides/rel_notes/deprecation.rst b/doc/guides/rel_notes/deprecation.rst
index db261d33f7..688b8c2606 100644
--- a/doc/guides/rel_notes/deprecation.rst
+++ b/doc/guides/rel_notes/deprecation.rst
@@ -175,8 +175,5 @@ Deprecation Notices
``rte_event_vector::elem_offset`` gives the number of valid elements left
to process from the ``rte_event_vector::elem_offset``.
-* 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.
diff --git a/lib/metrics/rte_metrics.c b/lib/metrics/rte_metrics.c
index 6adcda501c..0ccdbabc04 100644
--- a/lib/metrics/rte_metrics.c
+++ b/lib/metrics/rte_metrics.c
@@ -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
diff --git a/lib/metrics/rte_metrics.h b/lib/metrics/rte_metrics.h
index c2815a252c..5c33af9999 100644
--- a/lib/metrics/rte_metrics.h
+++ b/lib/metrics/rte_metrics.h
@@ -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
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [PATCH] metrics: return error code on initialization failures
2022-09-29 9:38 [PATCH] metrics: return error code on initialization failures Bruce Richardson
@ 2022-09-29 11:16 ` Morten Brørup
2022-10-03 7:17 ` David Marchand
0 siblings, 1 reply; 3+ messages in thread
From: Morten Brørup @ 2022-09-29 11:16 UTC (permalink / raw)
To: Bruce Richardson, dev; +Cc: thomas
> From: Bruce Richardson [mailto:bruce.richardson@intel.com]
> Sent: Thursday, 29 September 2022 11.38
>
> 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>
> ---
Plain and simple is always good. :-)
Acked-by: Morten Brørup <mb@smartsharesystems.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] metrics: return error code on initialization failures
2022-09-29 11:16 ` Morten Brørup
@ 2022-10-03 7:17 ` David Marchand
0 siblings, 0 replies; 3+ messages in thread
From: David Marchand @ 2022-10-03 7:17 UTC (permalink / raw)
To: Bruce Richardson; +Cc: Morten Brørup, dev, thomas
On Thu, Sep 29, 2022 at 1:16 PM Morten Brørup <mb@smartsharesystems.com> wrote:
> > 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>
Lgtm too.
Added a note in the RN and applied.
Thanks Bruce.
--
David Marchand
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-10-03 7:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-29 9:38 [PATCH] metrics: return error code on initialization failures Bruce Richardson
2022-09-29 11:16 ` Morten Brørup
2022-10-03 7:17 ` David Marchand
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).