From e2f773aafc2f5515f19a17aeb3e0b556b23fdff9 Mon Sep 17 00:00:00 2001 From: Liu Xiaodong Date: Tue, 27 Oct 2020 04:23:45 -0400 Subject: [PATCH] reactor: check calloc failure in gather_metrics A round of _reactors_scheduler_gather_metrics should be stopped when there is calloc failure. Change-Id: Ic2220c561abb07a849ea37d3c88af3f6d5d1ffa1 Signed-off-by: Liu Xiaodong Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/4882 Reviewed-by: Tomasz Zawadzki Reviewed-by: Jim Harris Tested-by: SPDK CI Jenkins --- lib/event/reactor.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/event/reactor.c b/lib/event/reactor.c index cabe2c151..c16437856 100644 --- a/lib/event/reactor.c +++ b/lib/event/reactor.c @@ -517,6 +517,18 @@ _reactors_scheduler_fini(void *arg1, void *arg2) } } +static void +_reactors_scheduler_cancel(void *arg1, void *arg2) +{ + struct spdk_reactor *reactor; + uint32_t i; + + SPDK_ENV_FOREACH_CORE(i) { + reactor = spdk_reactor_get(i); + reactor->flags.is_scheduling = false; + } +} + /* Phase 1 of thread scheduling is to gather metrics on the existing threads */ static void _reactors_scheduler_gather_metrics(void *arg1, void *arg2) @@ -551,6 +563,14 @@ _reactors_scheduler_gather_metrics(void *arg1, void *arg2) if (core_info->threads_count > 0) { core_info->threads = calloc(core_info->threads_count, sizeof(struct spdk_lw_thread *)); + if (core_info->threads == NULL) { + SPDK_ERRLOG("Failed to allocate memory when gathering metrics on %u\n", reactor->lcore); + + /* Cancel this round of schedule work */ + evt = spdk_event_allocate(g_scheduling_reactor->lcore, _reactors_scheduler_cancel, NULL, NULL); + spdk_event_call(evt); + return; + } i = 0; TAILQ_FOREACH(lw_thread, &reactor->threads, link) {