X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fust-app.c;h=3efda83c194149bedcf68a083db077897297e4dd;hp=2a5ec9e23bdd4260595edf111230266d792a600b;hb=412d7227e69ec845e44c49082a417f9454d9b55d;hpb=3273699db2c8b23e71ab5f534caf93267da448b4 diff --git a/src/bin/lttng-sessiond/ust-app.c b/src/bin/lttng-sessiond/ust-app.c index 2a5ec9e23..3efda83c1 100644 --- a/src/bin/lttng-sessiond/ust-app.c +++ b/src/bin/lttng-sessiond/ust-app.c @@ -7,11 +7,14 @@ */ #define _LGPL_SOURCE +#include +#include #include #include #include #include #include +#include #include #include #include @@ -32,6 +35,7 @@ #include #include "buffer-registry.h" +#include "condition-internal.h" #include "fd-limit.h" #include "health-sessiond.h" #include "ust-app.h" @@ -44,6 +48,8 @@ #include "notification-thread-commands.h" #include "rotate.h" #include "event.h" +#include "event-notifier-error-accounting.h" + struct lttng_ht *ust_app_ht; struct lttng_ht *ust_app_ht_by_sock; @@ -999,16 +1005,23 @@ void delete_ust_app(struct ust_app *app) */ if (app->event_notifier_group.object) { enum lttng_error_code ret_code; + enum event_notifier_error_accounting_status status; + const int event_notifier_read_fd = lttng_pipe_get_readfd( app->event_notifier_group.event_pipe); ret_code = notification_thread_command_remove_tracer_event_source( - notification_thread_handle, + the_notification_thread_handle, event_notifier_read_fd); if (ret_code != LTTNG_OK) { ERR("Failed to remove application tracer event source from notification thread"); } + status = event_notifier_error_accounting_unregister_app(app); + if (status != EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_OK) { + ERR("Error unregistering app from event notifier error accounting"); + } + ustctl_release_object(sock, app->event_notifier_group.object); free(app->event_notifier_group.object); } @@ -2106,6 +2119,7 @@ static int create_ust_event_notifier(struct ust_app *app, init_ust_event_notifier_from_event_rule(event_rule, &event_notifier); event_notifier.event.token = ua_event_notifier_rule->token; + event_notifier.error_counter_index = ua_event_notifier_rule->error_counter_index; /* Create UST event notifier against the tracer. */ pthread_mutex_lock(&app->sock_lock); @@ -3338,11 +3352,12 @@ static int create_channel_per_uid(struct ust_app *app, pthread_mutex_unlock(®_uid->registry->reg.ust->lock); notification_ret = notification_thread_command_add_channel( - notification_thread_handle, session->name, - lttng_credentials_get_uid(&ua_sess->effective_credentials), - lttng_credentials_get_gid(&ua_sess->effective_credentials), - ua_chan->name, - ua_chan->key, LTTNG_DOMAIN_UST, + the_notification_thread_handle, session->name, + lttng_credentials_get_uid( + &ua_sess->effective_credentials), + lttng_credentials_get_gid( + &ua_sess->effective_credentials), + ua_chan->name, ua_chan->key, LTTNG_DOMAIN_UST, ua_chan->attr.subbuf_size * ua_chan->attr.num_subbuf); if (notification_ret != LTTNG_OK) { ret = - (int) notification_ret; @@ -3439,11 +3454,12 @@ static int create_channel_per_pid(struct ust_app *app, pthread_mutex_unlock(®istry->lock); cmd_ret = notification_thread_command_add_channel( - notification_thread_handle, session->name, - lttng_credentials_get_uid(&ua_sess->effective_credentials), - lttng_credentials_get_gid(&ua_sess->effective_credentials), - ua_chan->name, - ua_chan->key, LTTNG_DOMAIN_UST, + the_notification_thread_handle, session->name, + lttng_credentials_get_uid( + &ua_sess->effective_credentials), + lttng_credentials_get_gid( + &ua_sess->effective_credentials), + ua_chan->name, ua_chan->key, LTTNG_DOMAIN_UST, ua_chan->attr.subbuf_size * ua_chan->attr.num_subbuf); if (cmd_ret != LTTNG_OK) { ret = - (int) cmd_ret; @@ -3674,12 +3690,12 @@ int create_ust_app_event_notifier_rule(struct lttng_trigger *trigger, DBG2("UST app create token event rule completed: app = '%s' (ppid: %d), token = %" PRIu64, app->name, app->ppid, lttng_trigger_get_tracer_token(trigger)); -end: - return ret; + goto end; error: /* The RCU read side lock is already being held by the caller. */ delete_ust_app_event_notifier_rule(-1, ua_event_notifier_rule, app); +end: return ret; } @@ -3836,9 +3852,11 @@ struct ust_app *ust_app_create(struct ust_register_msg *msg, int sock) DBG3("UST app creating application for socket %d", sock); if ((msg->bits_per_long == 64 && - (uatomic_read(&ust_consumerd64_fd) == -EINVAL)) - || (msg->bits_per_long == 32 && - (uatomic_read(&ust_consumerd32_fd) == -EINVAL))) { + (uatomic_read(&the_ust_consumerd64_fd) == + -EINVAL)) || + (msg->bits_per_long == 32 && + (uatomic_read(&the_ust_consumerd32_fd) == + -EINVAL))) { ERR("Registration failed: application \"%s\" (pid: %d) has " "%d-bit long, but no consumerd for this size is available.\n", msg->name, msg->pid, msg->bits_per_long); @@ -3994,6 +4012,7 @@ int ust_app_setup_event_notifier_group(struct ust_app *app) int event_pipe_write_fd; struct lttng_ust_abi_object_data *event_notifier_group = NULL; enum lttng_error_code lttng_ret; + enum event_notifier_error_accounting_status event_notifier_error_accounting_status; assert(app); @@ -4031,8 +4050,9 @@ int ust_app_setup_event_notifier_group(struct ust_app *app) lttng_fd_put(LTTNG_FD_APPS, 1); lttng_ret = notification_thread_command_add_tracer_event_source( - notification_thread_handle, - lttng_pipe_get_readfd(app->event_notifier_group.event_pipe), + the_notification_thread_handle, + lttng_pipe_get_readfd( + app->event_notifier_group.event_pipe), LTTNG_DOMAIN_UST); if (lttng_ret != LTTNG_OK) { ERR("Failed to add tracer event source to notification thread"); @@ -4042,11 +4062,20 @@ int ust_app_setup_event_notifier_group(struct ust_app *app) /* Assign handle only when the complete setup is valid. */ app->event_notifier_group.object = event_notifier_group; + + event_notifier_error_accounting_status = event_notifier_error_accounting_register_app(app); + if (event_notifier_error_accounting_status != EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_OK) { + ERR("Failed to setup event notifier error accounting for app"); + ret = -1; + goto error; + } + return ret; error: ustctl_release_object(app->sock, app->event_notifier_group.object); free(app->event_notifier_group.object); + app->event_notifier_group.object = NULL; return ret; } @@ -5622,7 +5651,7 @@ void ust_app_synchronize_event_notifier_rules(struct ust_app *app) /* Get all triggers using uid 0 (root) */ ret_code = notification_thread_command_list_triggers( - notification_thread_handle, 0, &triggers); + the_notification_thread_handle, 0, &triggers); if (ret_code != LTTNG_OK) { ret = -1; goto end; @@ -5735,38 +5764,20 @@ end: } /* - * The caller must ensure that the application is compatible and is tracked - * by the process attribute trackers. + * RCU read lock must be held by the caller. */ static -void ust_app_synchronize(struct ltt_ust_session *usess, +void ust_app_synchronize_all_channels(struct ltt_ust_session *usess, + struct ust_app_session *ua_sess, struct ust_app *app) { int ret = 0; struct cds_lfht_iter uchan_iter; struct ltt_ust_channel *uchan; - struct ust_app_session *ua_sess = NULL; - /* - * The application's configuration should only be synchronized for - * active sessions. - */ - assert(usess->active); - - ret = find_or_create_ust_app_session(usess, app, &ua_sess, NULL); - if (ret < 0) { - /* Tracer is probably gone or ENOMEM. */ - goto error; - } + assert(usess); assert(ua_sess); - - pthread_mutex_lock(&ua_sess->lock); - if (ua_sess->deleted) { - pthread_mutex_unlock(&ua_sess->lock); - goto end; - } - - rcu_read_lock(); + assert(app); cds_lfht_for_each_entry(usess->domain_global.channels->ht, &uchan_iter, uchan, node.node) { @@ -5785,7 +5796,7 @@ void ust_app_synchronize(struct ltt_ust_session *usess, app, uchan, &ua_chan); if (ret) { /* Tracer is probably gone or ENOMEM. */ - goto error_unlock; + goto end; } if (!ua_chan) { @@ -5798,7 +5809,7 @@ void ust_app_synchronize(struct ltt_ust_session *usess, ret = ust_app_channel_synchronize_event(ua_chan, uevent, ua_sess, app); if (ret) { - goto error_unlock; + goto end; } } @@ -5807,10 +5818,47 @@ void ust_app_synchronize(struct ltt_ust_session *usess, enable_ust_app_channel(ua_sess, uchan, app) : disable_ust_app_channel(ua_sess, ua_chan, app); if (ret) { - goto error_unlock; + goto end; } } } +end: + return; +} + +/* + * The caller must ensure that the application is compatible and is tracked + * by the process attribute trackers. + */ +static +void ust_app_synchronize(struct ltt_ust_session *usess, + struct ust_app *app) +{ + int ret = 0; + struct ust_app_session *ua_sess = NULL; + + /* + * The application's configuration should only be synchronized for + * active sessions. + */ + assert(usess->active); + + ret = find_or_create_ust_app_session(usess, app, &ua_sess, NULL); + if (ret < 0) { + /* Tracer is probably gone or ENOMEM. */ + goto error; + } + assert(ua_sess); + + pthread_mutex_lock(&ua_sess->lock); + if (ua_sess->deleted) { + pthread_mutex_unlock(&ua_sess->lock); + goto end; + } + + rcu_read_lock(); + + ust_app_synchronize_all_channels(usess, ua_sess, app); /* * Create the metadata for the application. This returns gracefully if a @@ -5943,6 +5991,20 @@ void ust_app_global_update_all_event_notifier_rules(void) rcu_read_unlock(); } +void ust_app_update_event_notifier_error_count(struct lttng_trigger *trigger) +{ + uint64_t error_count = 0; + enum event_notifier_error_accounting_status status; + struct lttng_condition *condition = lttng_trigger_get_condition(trigger); + + status = event_notifier_error_accounting_get_count(trigger, &error_count); + if (status != EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_OK) { + ERR("Error getting trigger error count."); + } + + lttng_condition_on_event_set_error_count(condition, error_count); +} + /* * Add context to a specific channel for global UST domain. */