X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Faction-executor.cpp;h=34d3b7130f0a713b089bff4461cab34c9ce36445;hb=c9753f7250f33184a1859088a691291f37161f25;hp=cc7834f2745ca6e58d8299dd7c649fe68ecc0aaa;hpb=7966af5763c4aaca39df9bbfa9277ff15715c720;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/action-executor.cpp b/src/bin/lttng-sessiond/action-executor.cpp index cc7834f27..34d3b7130 100644 --- a/src/bin/lttng-sessiond/action-executor.cpp +++ b/src/bin/lttng-sessiond/action-executor.cpp @@ -301,42 +301,35 @@ static int action_executor_start_session_handler( * existed. If not skip the action altogether. */ if (!item->context.session_id.is_set) { - DBG("Session `%s` was not present at the moment the work item was enqueued for %s` action of trigger `%s`", + DBG("Session `%s` was not present at the moment the work item was enqueued for `%s` action of trigger `%s`", session_name, get_action_name(action), get_trigger_name(work_item->trigger)); lttng_action_increase_execution_failure_count(action); - ret = 0; goto end; } session_lock_list(); - session = session_find_by_name(session_name); + rcu_read_lock(); + session = session_find_by_id(LTTNG_OPTIONAL_GET(item->context.session_id)); if (!session) { DBG("Failed to find session `%s` by name while executing `%s` action of trigger `%s`", session_name, get_action_name(action), get_trigger_name(work_item->trigger)); + lttng_action_increase_execution_failure_count(action); goto error_unlock_list; } - /* - * Check if the session id is the same as when the work item was - * enqueued. - */ - if (session->id != LTTNG_OPTIONAL_GET(item->context.session_id)) { - DBG("Session id for session `%s` (id: %" PRIu64 - " is not the same that was sampled (id: %" PRIu64 - " at the moment the work item was enqueued for %s` action of trigger `%s`", - session_name, session->id, - LTTNG_OPTIONAL_GET(item->context.session_id), + session_lock(session); + if (session->destroyed) { + DBG("Session `%s` with id = %" PRIu64 " is flagged as destroyed. Skipping: action = `%s`, trigger = `%s`", + session->name, session->id, get_action_name(action), get_trigger_name(work_item->trigger)); - ret = 0; - goto error_unlock_list; + goto error_unlock_session; } - session_lock(session); if (!is_trigger_allowed_for_session(work_item->trigger, session)) { - goto error_dispose_session; + goto error_unlock_session; } cmd_ret = (lttng_error_code) cmd_start_trace(session); @@ -357,10 +350,11 @@ static int action_executor_start_session_handler( break; } -error_dispose_session: +error_unlock_session: session_unlock(session); session_put(session); error_unlock_list: + rcu_read_unlock(); session_unlock_list(); end: return ret; @@ -392,16 +386,16 @@ static int action_executor_stop_session_handler( * existed. If not, skip the action altogether. */ if (!item->context.session_id.is_set) { - DBG("Session `%s` was not present at the moment the work item was enqueued for %s` action of trigger `%s`", + DBG("Session `%s` was not present at the moment the work item was enqueued for `%s` action of trigger `%s`", session_name, get_action_name(action), get_trigger_name(work_item->trigger)); lttng_action_increase_execution_failure_count(action); - ret = 0; goto end; } session_lock_list(); - session = session_find_by_name(session_name); + rcu_read_lock(); + session = session_find_by_id(LTTNG_OPTIONAL_GET(item->context.session_id)); if (!session) { DBG("Failed to find session `%s` by name while executing `%s` action of trigger `%s`", session_name, get_action_name(action), @@ -410,25 +404,17 @@ static int action_executor_stop_session_handler( goto error_unlock_list; } - /* - * Check if the session id is the same as when the work item was - * enqueued - */ - if (session->id != LTTNG_OPTIONAL_GET(item->context.session_id)) { - DBG("Session id for session `%s` (id: %" PRIu64 - " is not the same that was sampled (id: %" PRIu64 - " at the moment the work item was enqueued for %s` action of trigger `%s`", - session_name, session->id, - LTTNG_OPTIONAL_GET(item->context.session_id), + session_lock(session); + if (session->destroyed) { + DBG("Session `%s` with id = %" PRIu64 " is flagged as destroyed. Skipping: action = `%s`, trigger = `%s`", + session->name, session->id, get_action_name(action), get_trigger_name(work_item->trigger)); - ret = 0; - goto error_unlock_list; + goto error_unlock_session; } - session_lock(session); if (!is_trigger_allowed_for_session(work_item->trigger, session)) { - goto error_dispose_session; + goto error_unlock_session; } cmd_ret = (lttng_error_code) cmd_stop_trace(session); @@ -449,10 +435,11 @@ static int action_executor_stop_session_handler( break; } -error_dispose_session: +error_unlock_session: session_unlock(session); session_put(session); error_unlock_list: + rcu_read_unlock(); session_unlock_list(); end: return ret; @@ -484,16 +471,16 @@ static int action_executor_rotate_session_handler( * existed. If not, skip the action altogether. */ if (!item->context.session_id.is_set) { - DBG("Session `%s` was not present at the moment the work item was enqueued for %s` action of trigger `%s`", + DBG("Session `%s` was not present at the moment the work item was enqueued for `%s` action of trigger `%s`", session_name, get_action_name(action), get_trigger_name(work_item->trigger)); lttng_action_increase_execution_failure_count(action); - ret = 0; goto end; } session_lock_list(); - session = session_find_by_name(session_name); + rcu_read_lock(); + session = session_find_by_id(LTTNG_OPTIONAL_GET(item->context.session_id)); if (!session) { DBG("Failed to find session `%s` by name while executing `%s` action of trigger `%s`", session_name, get_action_name(action), @@ -502,25 +489,17 @@ static int action_executor_rotate_session_handler( goto error_unlock_list; } - /* - * Check if the session id is the same as when the work item was - * enqueued. - */ - if (session->id != LTTNG_OPTIONAL_GET(item->context.session_id)) { - DBG("Session id for session `%s` (id: %" PRIu64 - " is not the same that was sampled (id: %" PRIu64 - " at the moment the work item was enqueued for %s` action of trigger `%s`", - session_name, session->id, - LTTNG_OPTIONAL_GET(item->context.session_id), + session_lock(session); + if (session->destroyed) { + DBG("Session `%s` with id = %" PRIu64 " is flagged as destroyed. Skipping: action = `%s`, trigger = `%s`", + session->name, session->id, get_action_name(action), get_trigger_name(work_item->trigger)); - ret = 0; - goto error_unlock_list; + goto error_unlock_session; } - session_lock(session); if (!is_trigger_allowed_for_session(work_item->trigger, session)) { - goto error_dispose_session; + goto error_unlock_session; } cmd_ret = (lttng_error_code) cmd_rotate_session(session, NULL, false, @@ -548,10 +527,11 @@ static int action_executor_rotate_session_handler( break; } -error_dispose_session: +error_unlock_session: session_unlock(session); session_put(session); error_unlock_list: + rcu_read_unlock(); session_unlock_list(); end: return ret; @@ -579,11 +559,10 @@ static int action_executor_snapshot_session_handler( * existed. If not, skip the action altogether. */ if (!item->context.session_id.is_set) { - DBG("Session was not present at the moment the work item was enqueued for %s` action of trigger `%s`", + DBG("Session was not present at the moment the work item was enqueued for `%s` action of trigger `%s`", get_action_name(action), get_trigger_name(work_item->trigger)); lttng_action_increase_execution_failure_count(action); - ret = 0; goto end; } @@ -607,7 +586,8 @@ static int action_executor_snapshot_session_handler( } session_lock_list(); - session = session_find_by_name(session_name); + rcu_read_lock(); + session = session_find_by_id(LTTNG_OPTIONAL_GET(item->context.session_id)); if (!session) { DBG("Failed to find session `%s` by name while executing `%s` action of trigger `%s`", session_name, get_action_name(action), @@ -616,25 +596,17 @@ static int action_executor_snapshot_session_handler( goto error_unlock_list; } - /* - * Check if the session id is the same as when the work item was - * enqueued. - */ - if (session->id != LTTNG_OPTIONAL_GET(item->context.session_id)) { - DBG("Session id for session `%s` (id: %" PRIu64 - " is not the same that was sampled (id: %" PRIu64 - " at the moment the work item was enqueued for %s` action of trigger `%s`", - session_name, session->id, - LTTNG_OPTIONAL_GET(item->context.session_id), + session_lock(session); + if (session->destroyed) { + DBG("Session `%s` with id = %" PRIu64 " is flagged as destroyed. Skipping: action = `%s`, trigger = `%s`", + session->name, session->id, get_action_name(action), get_trigger_name(work_item->trigger)); - ret = 0; - goto error_unlock_list; + goto error_unlock_session; } - session_lock(session); if (!is_trigger_allowed_for_session(work_item->trigger, session)) { - goto error_dispose_session; + goto error_unlock_session; } cmd_ret = (lttng_error_code) cmd_snapshot_record(session, snapshot_output, 0); @@ -651,10 +623,11 @@ static int action_executor_snapshot_session_handler( break; } -error_dispose_session: +error_unlock_session: session_unlock(session); session_put(session); error_unlock_list: + rcu_read_unlock(); session_unlock_list(); end: return ret; @@ -787,7 +760,7 @@ static void *action_executor_thread(void *_data) work_item->trigger, &trigger_owner_uid); LTTNG_ASSERT(trigger_status == LTTNG_TRIGGER_STATUS_OK); - DBG("Work item skipped since the associated trigger is no longer registered: work item id = %" PRIu64 ", trigger name = '%s', trigger owner uid = %d", + DBG("Work item skipped since the associated trigger is no longer registered: work item id = %" PRIu64 ", trigger name = `%s`, trigger owner uid = %d", work_item->id, trigger_name, (int) trigger_owner_uid); ret = 0; @@ -907,6 +880,7 @@ enum action_executor_status action_executor_enqueue_trigger( bool signal = false; LTTNG_ASSERT(trigger); + ASSERT_RCU_READ_LOCKED(); pthread_mutex_lock(&executor->work.lock); /* Check for queue overflow. */ @@ -920,7 +894,7 @@ enum action_executor_status action_executor_enqueue_trigger( work_item = (action_work_item *) zmalloc(sizeof(*work_item)); if (!work_item) { - PERROR("Failed to allocate action executor work item: trigger name = '%s'", + PERROR("Failed to allocate action executor work item: trigger name = `%s`", get_trigger_name(trigger)); executor_status = ACTION_EXECUTOR_STATUS_ERROR; goto error_unlock;