sessiond: setup event notifier group for registering app
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Fri, 10 Jan 2020 21:05:48 +0000 (16:05 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 12 Jan 2021 19:57:03 +0000 (14:57 -0500)
Create a pipe for each application and setup an event notifier group
associated with that pipe. Transfer the write side to the app, and
transfer the read side to the notification thread as an application
event source ([...]_ADD_TRACER_EVENT_SOURCE)

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I3e4aab84e3270ddef1f50f72f946a4d80b3f36e0
Depends-on: lttng-ust: I5a800fc92e588c2a6a0e26282b0ad5f31c044479

src/bin/lttng-sessiond/dispatch.c
src/bin/lttng-sessiond/ust-app.c
src/bin/lttng-sessiond/ust-app.h

index 4fe3dfce70e40d22a05d361e3071e8966e610258..52d253d47d3578923d5fbf69c1ce52b438ee5330 100644 (file)
@@ -386,6 +386,8 @@ static void *thread_dispatch_ust_registration(void *data)
                                /* Set app version. This call will print an error if needed. */
                                (void) ust_app_version(app);
 
+                               (void) ust_app_setup_event_notifier_group(app);
+
                                /* Send notify socket through the notify pipe. */
                                ret = send_socket_to_thread(
                                                notifiers->apps_cmd_notify_pipe_write_fd,
index b07bf684bcf870c59a2a212712ffec25db037af4..b30089dbc2fd6029f590adf8c05752ddda2d3225 100644 (file)
@@ -921,6 +921,28 @@ void delete_ust_app(struct ust_app *app)
        ht_cleanup_push(app->ust_sessions_objd);
        ht_cleanup_push(app->ust_objd);
 
+       /*
+        * This could be NULL if the event notifier setup failed (e.g the app
+        * was killed or the tracer does not support this feature).
+        */
+       if (app->event_notifier_group.object) {
+               enum lttng_error_code ret_code;
+               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,
+                               event_notifier_read_fd);
+               if (ret_code != LTTNG_OK) {
+                       ERR("Failed to remove application tracer event source from notification thread");
+               }
+
+               ustctl_release_object(sock, app->event_notifier_group.object);
+               free(app->event_notifier_group.object);
+       }
+
+       lttng_pipe_destroy(app->event_notifier_group.event_pipe);
+
        /*
         * Wait until we have deleted the application from the sock hash table
         * before closing this socket, otherwise an application could re-use the
@@ -3312,6 +3334,7 @@ error:
 struct ust_app *ust_app_create(struct ust_register_msg *msg, int sock)
 {
        struct ust_app *lta = NULL;
+       struct lttng_pipe *event_notifier_event_source_pipe = NULL;
 
        assert(msg);
        assert(sock >= 0);
@@ -3328,12 +3351,21 @@ struct ust_app *ust_app_create(struct ust_register_msg *msg, int sock)
                goto error;
        }
 
+       event_notifier_event_source_pipe = lttng_pipe_open(FD_CLOEXEC);
+       if (!event_notifier_event_source_pipe) {
+               PERROR("Failed to open application event source pipe: '%s' (ppid = %d)",
+                               msg->name, msg->ppid);
+               goto error;
+       }
+
        lta = zmalloc(sizeof(struct ust_app));
        if (lta == NULL) {
                PERROR("malloc");
-               goto error;
+               goto error_free_pipe;
        }
 
+       lta->event_notifier_group.event_pipe = event_notifier_event_source_pipe;
+
        lta->ppid = msg->ppid;
        lta->uid = msg->uid;
        lta->gid = msg->gid;
@@ -3371,8 +3403,12 @@ struct ust_app *ust_app_create(struct ust_register_msg *msg, int sock)
        lttng_ht_node_init_ulong(&lta->sock_n, (unsigned long) lta->sock);
 
        CDS_INIT_LIST_HEAD(&lta->teardown_head);
-error:
        return lta;
+
+error_free_pipe:
+       lttng_pipe_destroy(event_notifier_event_source_pipe);
+error:
+       return NULL;
 }
 
 /*
@@ -3438,6 +3474,61 @@ int ust_app_version(struct ust_app *app)
        return ret;
 }
 
+/*
+ * Setup the base event notifier group.
+ *
+ * Return 0 on success else a negative value either an errno code or a
+ * LTTng-UST error code.
+ */
+int ust_app_setup_event_notifier_group(struct ust_app *app)
+{
+       int ret;
+       int event_pipe_write_fd;
+       struct lttng_ust_object_data *event_notifier_group = NULL;
+       enum lttng_error_code lttng_ret;
+
+       assert(app);
+
+       /* Get the write side of the pipe. */
+       event_pipe_write_fd = lttng_pipe_get_writefd(
+                       app->event_notifier_group.event_pipe);
+
+       pthread_mutex_lock(&app->sock_lock);
+       ret = ustctl_create_event_notifier_group(app->sock,
+                       event_pipe_write_fd, &event_notifier_group);
+       pthread_mutex_unlock(&app->sock_lock);
+       if (ret < 0) {
+               if (ret != -LTTNG_UST_ERR_EXITING && ret != -EPIPE) {
+                       ERR("Failed to create application event notifier group: ret = %d, app socket fd = %d, event_pipe_write_fd = %d",
+                                       ret, app->sock, event_pipe_write_fd);
+               } else {
+                       DBG("Failed to create application event notifier group (application is dead): app socket fd = %d",
+                                       app->sock);
+               }
+
+               goto error;
+       }
+
+       lttng_ret = notification_thread_command_add_tracer_event_source(
+                       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");
+               ret = - 1;
+               goto error;
+       }
+
+       /* Assign handle only when the complete setup is valid. */
+       app->event_notifier_group.object = event_notifier_group;
+       return ret;
+
+error:
+       ustctl_release_object(app->sock, app->event_notifier_group.object);
+       free(app->event_notifier_group.object);
+       return ret;
+}
+
 /*
  * Unregister app by removing it from the global traceable app list and freeing
  * the data struct.
index 164bc2c6f2c95acf59d91e2a339cd55f3b338fef..449173cd36a94a2f965a6a31c2ee351732e8fc22 100644 (file)
@@ -292,6 +292,17 @@ struct ust_app {
         * Used for path creation
         */
        time_t registration_time;
+       /*
+        * Event notifier
+        */
+       struct {
+               /*
+                * Handle to the lttng_ust object representing the event
+                * notifier group.
+                */
+               struct lttng_ust_object_data *object;
+               struct lttng_pipe *event_pipe;
+       } event_notifier_group;
 };
 
 #ifdef HAVE_LIBLTTNG_UST_CTL
@@ -356,6 +367,8 @@ int ust_app_release_object(struct ust_app *app,
 enum lttng_error_code ust_app_clear_session(struct ltt_session *session);
 enum lttng_error_code ust_app_open_packets(struct ltt_session *session);
 
+int ust_app_setup_event_notifier_group(struct ust_app *app);
+
 static inline
 int ust_app_supported(void)
 {
@@ -444,6 +457,14 @@ static inline
 void ust_app_global_update(struct ltt_ust_session *usess, struct ust_app *app)
 {}
 static inline
+void ust_app_global_update_tokens(struct ust_app *app)
+{}
+static inline
+int ust_app_setup_event_notifier_group(struct ust_app *app)
+{
+       return 0;
+}
+static inline
 int ust_app_disable_channel_glb(struct ltt_ust_session *usess,
                struct ltt_ust_channel *uchan)
 {
This page took 0.041247 seconds and 4 git commands to generate.