sessiond: refcount `ust_error_accounting_entry`
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Fri, 16 Apr 2021 15:14:21 +0000 (11:14 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 23 Apr 2021 00:18:37 +0000 (20:18 -0400)
Keep a reference count of the `ust_error_accounting_entry` to reclaim
memory and cleanup handles as we go.

Triggers on a sessiond target all applications regardless of the UID of
both the trigger and the application. This means that whenever a new UST
counter is created for a UID, we need to keep it around as long as there
is 1. an application from that UID, or 2. an event notifier registered.

This commit achieves that by keeping a count of the registered event
notifiers. If the count is above zero, we keep a reference on every UID
entries. When the count reaches zero, we put that reference on every
entries.

The event notifier count is guarded by a mutex since it's accessed by
both the notification thread and UST registration thread.

Here is the pseudo code for the relevant error accounting events:
App registration:
  lookup entry for application UID in hashtable
  if found:
    get a reference on that existing entry
  else:
    create a new entry for that UID
    get a reference on that new entry
    if event_notifier_count > 0:
      get an extra reference on the behalf of the event notifiers

Event notifier registration:
  increment event_notifier_count
  if event_notifier_count == 1:
    get a reference on all existing UID entries

App unregistration:
  put reference on application UID entry

Event notifier unregistration:
  decrement event_notifier_count
  if event_notifier_count == 0:
    put ref on all existing UID entries

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I74667d30a5b6975bad7975b82f6819e263199cd0

src/bin/lttng-sessiond/event-notifier-error-accounting.c
src/bin/lttng-sessiond/ust-app.c
tests/regression/tools/notification/test_notification_notifier_discarded_count

index aac6854679f2cc49dbfbc8dd4b9c10877ed5a235..70fa39e023d4466431614e9499fde0d8797de2c7 100644 (file)
@@ -33,12 +33,13 @@ struct index_ht_entry {
 
 struct ust_error_accounting_entry {
        uid_t uid;
+       struct urcu_ref ref;
        struct lttng_ht_node_u64 node;
        struct rcu_head rcu_head;
        struct ustctl_daemon_counter *daemon_counter;
        /*
-        * Those `lttng_ust_abi_object_data` are anonymous handles to the counters
-        * objects.
+        * Those `lttng_ust_abi_object_data` are anonymous handles to the
+        * counters objects.
         * They are only used to be duplicated for each new applications of the
         * user. To destroy them, call with the `sock` parameter set to -1.
         * e.g. `ustctl_release_object(-1, data)`;
@@ -49,10 +50,10 @@ struct ust_error_accounting_entry {
 };
 
 struct kernel_error_accounting_entry {
-       int kernel_event_notifier_error_counter_fd;
+       int error_counter_fd;
 };
 
-static struct kernel_error_accounting_entry kernel_error_accountant;
+static struct kernel_error_accounting_entry kernel_error_accounting_entry;
 
 /* Hashtable mapping uid to error_account_entry. */
 static struct lttng_ht *error_counter_uid_ht;
@@ -111,6 +112,106 @@ const char *error_accounting_status_str(
        }
 }
 
+#ifdef HAVE_LIBLTTNG_UST_CTL
+struct event_notifier_counter {
+       pthread_mutex_t lock;
+       long count;
+};
+
+static struct event_notifier_counter the_event_notifier_counter;
+
+static void free_ust_error_accounting_entry(struct rcu_head *head)
+{
+       int i;
+       struct ust_error_accounting_entry *entry =
+                       caa_container_of(head, typeof(*entry), rcu_head);
+
+       for (i = 0; i < entry->nr_counter_cpu_fds; i++) {
+               ustctl_release_object(-1, entry->cpu_counters[i]);
+               free(entry->cpu_counters[i]);
+       }
+
+       free(entry->cpu_counters);
+
+       ustctl_release_object(-1, entry->counter);
+       free(entry->counter);
+
+       ustctl_destroy_counter(entry->daemon_counter);
+
+       free(entry);
+}
+
+static
+bool ust_error_accounting_entry_get(struct ust_error_accounting_entry *entry)
+{
+       return urcu_ref_get_unless_zero(&entry->ref);
+}
+
+static
+void ust_error_accounting_entry_release(struct urcu_ref *entry_ref)
+{
+       struct ust_error_accounting_entry *entry =
+                       container_of(entry_ref, typeof(*entry), ref);
+
+       rcu_read_lock();
+       cds_lfht_del(error_counter_uid_ht->ht, &entry->node.node);
+       call_rcu(&entry->rcu_head, free_ust_error_accounting_entry);
+       rcu_read_unlock();
+}
+
+
+static
+void ust_error_accounting_entry_put(struct ust_error_accounting_entry *entry)
+{
+       if (!entry) {
+               return;
+       }
+
+       urcu_ref_put(&entry->ref, ust_error_accounting_entry_release);
+}
+
+/*
+ * Put one reference to every UID entries.
+ */
+static
+void put_ref_all_ust_error_accounting_entry(void)
+{
+       struct lttng_ht_iter iter;
+       struct ust_error_accounting_entry *uid_entry;
+
+       ASSERT_LOCKED(the_event_notifier_counter.lock);
+
+       rcu_read_lock();
+       cds_lfht_for_each_entry(error_counter_uid_ht->ht, &iter.iter,
+                       uid_entry, node.node) {
+               ust_error_accounting_entry_put(uid_entry);
+       }
+
+       rcu_read_unlock();
+}
+
+/*
+ * Get one reference to every UID entries.
+ */
+static
+void get_ref_all_ust_error_accounting_entry(void)
+{
+       struct lttng_ht_iter iter;
+       struct ust_error_accounting_entry *uid_entry;
+
+       ASSERT_LOCKED(the_event_notifier_counter.lock);
+
+       rcu_read_lock();
+       cds_lfht_for_each_entry(error_counter_uid_ht->ht, &iter.iter,
+                       uid_entry, node.node) {
+               ust_error_accounting_entry_get(uid_entry);
+       }
+
+       rcu_read_unlock();
+}
+
+#endif /* HAVE_LIBLTTNG_UST_CTL */
+
 static
 enum event_notifier_error_accounting_status
 init_error_accounting_state(struct error_accounting_state *state,
@@ -199,6 +300,10 @@ end:
        return status;
 }
 
+/*
+ * Return the error counteur index associated to this event notifier tracer
+ * token. Returns _STATUS_OK if found and _STATUS_NOT_FOUND otherwise.
+ */
 static
 enum event_notifier_error_accounting_status get_error_counter_index_for_token(
                struct error_accounting_state *state, uint64_t tracer_token,
@@ -226,33 +331,49 @@ enum event_notifier_error_accounting_status get_error_counter_index_for_token(
 }
 
 #ifdef HAVE_LIBLTTNG_UST_CTL
+/*
+ * Find the entry for this app's UID, the caller acquires a reference if the
+ * entry is found.
+ */
 static
-struct ust_error_accounting_entry *get_uid_accounting_entry(const struct ust_app *app)
+struct ust_error_accounting_entry *ust_error_accounting_entry_find(
+               struct lttng_ht *uid_ht, const struct ust_app *app)
 {
        struct ust_error_accounting_entry *entry;
        struct lttng_ht_node_u64 *node;
        struct lttng_ht_iter iter;
        uint64_t key = app->uid;
 
-       lttng_ht_lookup(error_counter_uid_ht, &key, &iter);
+       lttng_ht_lookup(uid_ht, &key, &iter);
        node = lttng_ht_iter_get_node_u64(&iter);
        if(node == NULL) {
                entry = NULL;
        } else {
-               entry = caa_container_of(node, struct ust_error_accounting_entry, node);
+               bool got_ref;
+
+               entry = caa_container_of(node,
+                               struct ust_error_accounting_entry, node);
+
+               got_ref = ust_error_accounting_entry_get(entry);
+               if (!got_ref) {
+                       entry = NULL;
+               }
        }
 
        return entry;
 }
 
+/*
+ * Create the entry for this app's UID, the caller acquires a reference to the
+ * entry,
+ */
 static
-struct ust_error_accounting_entry *create_uid_accounting_entry(
-               const struct ust_app *app)
+struct ust_error_accounting_entry *ust_error_accounting_entry_create(
+               struct lttng_ht *uid_ht, const struct ust_app *app)
 {
-       int i, ret;
+       int i, ret, *cpu_counter_fds = NULL;
        struct ustctl_daemon_counter *daemon_counter;
        struct lttng_ust_abi_object_data *counter, **cpu_counters;
-       int *cpu_counter_fds = NULL;
        struct ust_error_accounting_entry *entry = NULL;
        const struct ustctl_counter_dimension dimension = {
                .size = ust_state.number_indices,
@@ -266,6 +387,7 @@ struct ust_error_accounting_entry *create_uid_accounting_entry(
                goto error;
        }
 
+       urcu_ref_init(&entry->ref);
        entry->uid = app->uid;
        entry->nr_counter_cpu_fds = ustctl_get_nr_cpu_per_counter();
 
@@ -274,7 +396,6 @@ struct ust_error_accounting_entry *create_uid_accounting_entry(
                PERROR("Failed to allocate event notifier error counter file descriptors array: application uid = %d, application name = '%s', pid = %d, allocation size = %zu",
                                (int) app->uid, app->name, (int) app->pid,
                                entry->nr_counter_cpu_fds * sizeof(*cpu_counter_fds));
-               ret = -1;
                goto error_counter_cpu_fds_alloc;
        }
 
@@ -288,7 +409,6 @@ struct ust_error_accounting_entry *create_uid_accounting_entry(
                PERROR("Failed to allocate event notifier error counter lttng_ust_abi_object_data array: application uid = %d, application name = '%s', pid = %d, allocation size = %zu",
                                (int) app->uid, app->name, (int) app->pid,
                                entry->nr_counter_cpu_fds * sizeof(struct lttng_ust_abi_object_data *));
-               ret = -1;
                goto error_counter_cpus_alloc;
        }
 
@@ -336,7 +456,7 @@ struct ust_error_accounting_entry *create_uid_accounting_entry(
        entry->counter = counter;
        entry->cpu_counters = cpu_counters;
 
-       lttng_ht_node_init_u64(&entry->node, app->uid);
+       lttng_ht_node_init_u64(&entry->node, entry->uid);
        lttng_ht_add_unique_u64(error_counter_uid_ht, &entry->node);
 
        goto end;
@@ -375,7 +495,8 @@ error_shm_alloc:
 
                        ret = close(cpu_counter_fds[i]);
                        if (ret) {
-                               PERROR("Failed to close error counter per-CPU shm file descriptor: fd = %d", cpu_counter_fds[i]);
+                               PERROR("Failed to close error counter per-CPU shm file descriptor: fd = %d",
+                                               cpu_counter_fds[i]);
                        }
                }
        }
@@ -470,13 +591,33 @@ event_notifier_error_accounting_register_app(struct ust_app *app)
         * app. If not, create one.
         */
        rcu_read_lock();
-       entry = get_uid_accounting_entry(app);
+       entry = ust_error_accounting_entry_find(error_counter_uid_ht, app);
        if (entry == NULL) {
-               entry = create_uid_accounting_entry(app);
+               /*
+                * Take the event notifier counter lock before creating the new
+                * entry to ensure that no event notifier is registered between
+                * the the entry creation and event notifier count check.
+                */
+               pthread_mutex_lock(&the_event_notifier_counter.lock);
+
+               entry = ust_error_accounting_entry_create(error_counter_uid_ht,
+                               app);
                if (!entry) {
                        status = EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_ERR;
-                       goto end;
+                       pthread_mutex_unlock(&the_event_notifier_counter.lock);
+                       goto error_creating_entry;
+               }
+
+               /*
+                * We just created a new UID entry, If there are event
+                * notifiers already registered, take one reference on their
+                * behalf.
+                */
+               if (the_event_notifier_counter.count > 0) {
+                       ust_error_accounting_entry_get(entry);
                }
+
+               pthread_mutex_unlock(&the_event_notifier_counter.lock);
        }
 
        /* Duplicate counter object data. */
@@ -486,7 +627,7 @@ event_notifier_error_accounting_register_app(struct ust_app *app)
                ERR("Failed to duplicate event notifier error accounting counter for application user: application uid = %d, pid = %d, application name = '%s'",
                                (int) app->uid, (int) app->pid, app->name);
                status = EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_ERR;
-               goto end;
+               goto error_duplicate_counter;
        }
 
        status = send_counter_data_to_ust(app, new_counter);
@@ -571,6 +712,10 @@ error_allocate_cpu_counters:
 error_send_counter_data:
        ustctl_release_object(-1, new_counter);
        free(new_counter);
+error_duplicate_counter:
+       ust_error_accounting_entry_put(entry);
+error_creating_entry:
+       app->event_notifier_group.counter = NULL;
 end:
        rcu_read_unlock();
        return status;
@@ -584,12 +729,26 @@ event_notifier_error_accounting_unregister_app(struct ust_app *app)
        int i;
 
        rcu_read_lock();
-       entry = get_uid_accounting_entry(app);
+
+       /* If an error occurred during app registration no entry was created. */
+       if (!app->event_notifier_group.counter) {
+               status = EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_OK;
+               goto end;
+       }
+
+       entry = ust_error_accounting_entry_find(error_counter_uid_ht, app);
        if (entry == NULL) {
                ERR("Failed to find event notitifier error accounting entry on application teardown: pid = %d, application name = '%s'",
                                app->pid, app->name);
                status = EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_ERR;
                goto end;
+       } else {
+               /*
+                * Put the entry twice as we acquired a reference from the
+                * `ust_error_accounting_entry_find()` above.
+                */
+               ust_error_accounting_entry_put(entry);
+               ust_error_accounting_entry_put(entry);
        }
 
        for (i = 0; i < app->event_notifier_group.nr_counter_cpu; i++) {
@@ -628,15 +787,7 @@ event_notifier_error_accounting_ust_get_count(
 
        get_trigger_info_for_log(trigger, &trigger_name, &trigger_owner_uid);
 
-       /*
-        * At the moment, the error counter index is domain wide. This means
-        * that if UID 1000 registers a event notifier and is allocated index 0
-        * in it's error counter, index zero will be unused in error counter of
-        * all other users.
-        */
-       status = get_error_counter_index_for_token(
-                       &ust_state,
-                       tracer_token,
+       status = get_error_counter_index_for_token(&ust_state, tracer_token,
                        &error_counter_index);
        if (status != EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_OK) {
 
@@ -706,16 +857,8 @@ enum event_notifier_error_accounting_status event_notifier_error_accounting_ust_
        size_t dimension_index;
        const uint64_t tracer_token = lttng_trigger_get_tracer_token(trigger);
 
-       /*
-        * Go over all error counters (ignoring uid) as a trigger (and trigger
-        * errors) can be generated from any applications that this session
-        * daemon is managing.
-        */
-
        rcu_read_lock();
-       status = get_error_counter_index_for_token(
-                       &ust_state,
-                       tracer_token,
+       status = get_error_counter_index_for_token(&ust_state, tracer_token,
                        &error_counter_index);
        if (status != EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_OK) {
                uid_t trigger_owner_uid;
@@ -733,6 +876,11 @@ enum event_notifier_error_accounting_status event_notifier_error_accounting_ust_
 
        dimension_index = error_counter_index;
 
+       /*
+        * Go over all error counters (ignoring uid) as a trigger (and trigger
+        * errors) can be generated from any applications that this session
+        * daemon is managing.
+        */
        cds_lfht_for_each_entry(error_counter_uid_ht->ht, &iter.iter,
                        uid_entry, node.node) {
                const int ret = ustctl_counter_clear(uid_entry->daemon_counter,
@@ -769,8 +917,7 @@ event_notifier_error_accounting_kernel_clear(
        enum event_notifier_error_accounting_status status;
        struct lttng_kernel_counter_clear counter_clear = {};
 
-       status = get_error_counter_index_for_token(
-                       &kernel_state,
+       status = get_error_counter_index_for_token(&kernel_state,
                        lttng_trigger_get_tracer_token(trigger),
                        &error_counter_index);
        if (status != EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_OK) {
@@ -790,7 +937,7 @@ event_notifier_error_accounting_kernel_clear(
        counter_clear.index.dimension_indexes[0] = error_counter_index;
 
        ret = kernctl_counter_clear(
-                       kernel_error_accountant.kernel_event_notifier_error_counter_fd,
+                       kernel_error_accounting_entry.error_counter_fd,
                        &counter_clear);
        if (ret) {
                uid_t trigger_owner_uid;
@@ -851,7 +998,7 @@ event_notifier_error_accounting_register_kernel(
        DBG("Created kernel event notifier group error counter: fd = %d",
                        error_counter_fd);
 
-       kernel_error_accountant.kernel_event_notifier_error_counter_fd =
+       kernel_error_accounting_entry.error_counter_fd =
                        error_counter_fd;
        status = EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_OK;
 
@@ -967,6 +1114,28 @@ event_notifier_error_accounting_register_event_notifier(
                break;
        }
 
+#ifdef HAVE_LIBLTTNG_UST_CTL
+       switch (lttng_trigger_get_underlying_domain_type_restriction(trigger)) {
+       case LTTNG_DOMAIN_UST:
+               pthread_mutex_lock(&the_event_notifier_counter.lock);
+               the_event_notifier_counter.count++;
+               if (the_event_notifier_counter.count == 1) {
+                       /*
+                        * On the first event notifier, we get a reference to
+                        * every existing UID entries. This ensures that the
+                        * entries are kept around if there are still
+                        * registered event notifiers but no apps.
+                        */
+                       get_ref_all_ust_error_accounting_entry();
+               }
+               pthread_mutex_unlock(&the_event_notifier_counter.lock);
+               break;
+       default:
+               break;
+       }
+#endif /* HAVE_LIBLTTNG_UST_CTL */
+
+
 end:
        return status;
 }
@@ -981,8 +1150,7 @@ event_notifier_error_accounting_kernel_get_count(
        uint64_t error_counter_index;
        int ret;
 
-       status = get_error_counter_index_for_token(
-                       &kernel_state,
+       status = get_error_counter_index_for_token(&kernel_state,
                        lttng_trigger_get_tracer_token(trigger),
                        &error_counter_index);
        if (status != EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_OK) {
@@ -994,10 +1162,10 @@ event_notifier_error_accounting_kernel_get_count(
        counter_aggregate.index.number_dimensions = 1;
        counter_aggregate.index.dimension_indexes[0] = error_counter_index;
 
-       assert(kernel_error_accountant.kernel_event_notifier_error_counter_fd);
+       assert(kernel_error_accounting_entry.error_counter_fd);
 
        ret = kernctl_counter_get_aggregate_value(
-                       kernel_error_accountant.kernel_event_notifier_error_counter_fd,
+                       kernel_error_accounting_entry.error_counter_fd,
                        &counter_aggregate);
        if (ret || counter_aggregate.value.value < 0) {
                uid_t trigger_owner_uid;
@@ -1090,20 +1258,39 @@ void event_notifier_error_accounting_unregister_event_notifier(
                /* Trigger details already logged by callee on error. */
                ERR("Failed to clear event notifier error counter during unregistration of event notifier: status = '%s'",
                                error_accounting_status_str(status));
+               goto end;
        }
 
+       rcu_read_lock();
+
        switch (lttng_trigger_get_underlying_domain_type_restriction(trigger)) {
        case LTTNG_DOMAIN_KERNEL:
                state = &kernel_state;
                break;
+#ifdef HAVE_LIBLTTNG_UST_CTL
        case LTTNG_DOMAIN_UST:
                state = &ust_state;
+
+               pthread_mutex_lock(&the_event_notifier_counter.lock);
+               the_event_notifier_counter.count--;
+               if (the_event_notifier_counter.count == 0) {
+
+                       /*
+                        * When unregistering the last event notifier, put one
+                        * reference to every uid entries on the behalf of all
+                        * event notifiers.
+                        */
+                       put_ref_all_ust_error_accounting_entry();
+               }
+
+               pthread_mutex_unlock(&the_event_notifier_counter.lock);
+
                break;
+#endif /* HAVE_LIBLTTNG_UST_CTL */
        default:
                abort();
        }
 
-       rcu_read_lock();
        lttng_ht_lookup(state->indices_ht, &tracer_token, &iter);
        node = lttng_ht_iter_get_node_u64(&iter);
        if (node) {
@@ -1133,61 +1320,20 @@ void event_notifier_error_accounting_unregister_event_notifier(
                call_rcu(&index_entry->rcu_head, free_index_ht_entry);
        }
 
+end:
        rcu_read_unlock();
 }
 
-#ifdef HAVE_LIBLTTNG_UST_CTL
-static void free_error_account_entry(struct rcu_head *head)
-{
-       int i;
-       struct ust_error_accounting_entry *entry =
-                       caa_container_of(head, typeof(*entry), rcu_head);
-
-       for (i = 0; i < entry->nr_counter_cpu_fds; i++) {
-               ustctl_release_object(-1, entry->cpu_counters[i]);
-               free(entry->cpu_counters[i]);
-       }
-
-       free(entry->cpu_counters);
-
-       ustctl_release_object(-1, entry->counter);
-       free(entry->counter);
-
-       ustctl_destroy_counter(entry->daemon_counter);
-
-       free(entry);
-}
-#else
-/* Not called without UST support. */
-static void free_error_account_entry(struct rcu_head *head) {}
-#endif /* HAVE_LIBLTTNG_UST_CTL */
-
 void event_notifier_error_accounting_fini(void)
 {
-       struct lttng_ht_iter iter;
-       struct ust_error_accounting_entry *uid_entry;
-
-       if (kernel_error_accountant.kernel_event_notifier_error_counter_fd) {
-               const int ret = close(kernel_error_accountant.kernel_event_notifier_error_counter_fd);
+       if (kernel_error_accounting_entry.error_counter_fd) {
+               const int ret = close(kernel_error_accounting_entry.error_counter_fd);
 
                if (ret) {
                        PERROR("Failed to close kernel event notifier error counter");
                }
        }
 
-       /*
-        * FIXME error account entries are not reference-counted and torn
-        * down on last use. They exist from the moment of their first use
-        * up until the teardown of the session daemon.
-        */
-       rcu_read_lock();
-       cds_lfht_for_each_entry(error_counter_uid_ht->ht, &iter.iter,
-                       uid_entry, node.node) {
-               cds_lfht_del(error_counter_uid_ht->ht, &uid_entry->node.node);
-               call_rcu(&uid_entry->rcu_head, free_error_account_entry);
-       }
-       rcu_read_unlock();
-
        lttng_ht_destroy(error_counter_uid_ht);
 
        fini_error_accounting_state(&kernel_state);
index 97cb6623250c9384dfdabbd227772870261687fe..f44a30d1b13774c73c66d77c3e59d9a51bb7ba72 100644 (file)
@@ -4069,7 +4069,8 @@ 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);
+       event_notifier_error_accounting_status =
+                       event_notifier_error_accounting_register_app(app);
        if (event_notifier_error_accounting_status != EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_OK) {
                if (event_notifier_error_accounting_status == EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_APP_DEAD) {
                        DBG3("Failed to setup event notifier error accounting (application is dead): app socket fd = %d",
index 5df86d60504368184f872a81687bad4cc205db87..9320140d354288007d3e36c984b308e5586b223e 100755 (executable)
@@ -28,7 +28,7 @@ FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}"
 FULL_LTTNG_SESSIOND_BIN="${TESTDIR}/../src/bin/lttng-sessiond/lttng-sessiond"
 
 UST_NUM_TESTS=15
-DESTRUCTIVE_TESTS_NUM=8
+DESTRUCTIVE_TESTS_NUM=12
 KERNEL_NUM_TESTS=$((14 + $DESTRUCTIVE_TESTS_NUM))
 NUM_TESTS=$(($UST_NUM_TESTS + $KERNEL_NUM_TESTS))
 
@@ -200,7 +200,7 @@ function test_ust_notifier_discarded_count
        # Remove the notifier.
        lttng_remove_trigger_ok "$trigger_name"
 
-       # Confirm that no notifier is enabled.
+       # Confirm that no trigger is enabled.
        list_triggers_line_count=$("$FULL_LTTNG_BIN" list-triggers | wc -l)
        is "$list_triggers_line_count" "0" "No \`event-rule-matches\` userspace notifier enabled as expected"
 
@@ -304,9 +304,9 @@ function test_ust_notifier_discarded_count_multi_uid
        user_trigger_discarded_nb=$(trigger_get_discarded_notif_number "$user_trigger_name")
 
        isnt $root_trigger_discarded_nb 0 \
-               "Root trigger discard notifications number ($root_trigger_discarded_nb) is non-zero"
+               "Root trigger discarded notifications number ($root_trigger_discarded_nb) is non-zero"
        isnt $user_trigger_discarded_nb 0 \
-               "User trigger discard notifications number ($user_trigger_discarded_nb) is non-zero"
+               "User trigger discarded notifications number ($user_trigger_discarded_nb) is non-zero"
 
        lttng_remove_trigger_ok "$root_trigger_name"
        lttng_remove_trigger_ok "$user_trigger_name" --user-id "$new_uid"
@@ -319,6 +319,75 @@ function test_ust_notifier_discarded_count_multi_uid
        rm -f "$list_triggers_stdout"
 }
 
+function test_ust_notifier_discarded_regardless_trigger_owner
+{
+       local sessiond_pipe=()
+       local root_trigger_name="root_trigger"
+       local user_trigger_name="user_trigger"
+       local list_triggers_stdout=$(mktemp -t list_triggers_stdout.XXXXXX)
+       local NR_USEC_WAIT=0
+       local PIPE_SIZE
+       local NR_ITER
+       local new_user="dummy_lttng_test_user"
+
+       PIPE_SIZE=$("$CURDIR"/default_pipe_size_getter)
+       if [ $? -ne 0 ]; then
+               BAIL_OUT "Failed to get system default pipe size"
+       else
+               diag "Default system pipe size: $PIPE_SIZE bytes"
+       fi
+
+       # Find the number of events needed to overflow the event notification
+       # pipe buffer. Each LTTng-UST notification is at least 42 bytes long.
+       # Double that number to ensure enough events are created to overflow
+       # the buffer.
+       NR_ITER=$(( (PIPE_SIZE / 42) * 2 ))
+       diag "Test applications will emit $NR_ITER events"
+
+       diag "UST event notifer error counter persists when a root trigger is present"
+
+       # Create a dummy user to run test apps as.
+       useradd --no-create-home "$new_user"
+       new_uid=$(id -u "$new_user")
+
+       # Used on sessiond launch.
+       LTTNG_SESSIOND_ENV_VARS="LTTNG_TESTPOINT_ENABLE=1 \
+               NOTIFIER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} \
+               LD_PRELOAD=${TESTPOINT}"
+
+       start_lttng_sessiond_notap
+
+       # This is needed since the testpoint create a pipe with the sessiond
+       # type suffixed.
+       for f in "$TESTPOINT_BASE_PATH"*; do
+               sessiond_pipe+=("$f")
+       done
+
+       lttng_add_trigger_ok "$root_trigger_name" \
+               --condition on-event --userspace tp:tptest \
+               --action notify
+
+       # Stop consumption of notifier tracer notifications.
+       echo -n 1 > $sessiond_pipe
+
+       su "$new_user" -c "$TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT"
+       ok $? "Generating $NR_ITER tracer notifications as UID: $new_uid"
+
+       root_trigger_discarded_nb=$(trigger_get_discarded_notif_number "$root_trigger_name")
+
+       isnt $root_trigger_discarded_nb 0 \
+               "Root trigger discarded notifications number ($root_trigger_discarded_nb) is non-zero"
+
+       lttng_remove_trigger_ok "$root_trigger_name"
+
+       stop_lttng_sessiond_notap
+
+       unset LTTNG_SESSIOND_ENV_VARS
+
+       userdel "$new_user"
+       rm -f "$list_triggers_stdout"
+}
+
 test_ust_notifier_discarded_count
 test_ust_notifier_discarded_count_max_bucket
 
@@ -332,10 +401,11 @@ if [ "$(id -u)" == "0" ]; then
        test_kernel_notifier_discarded_count_max_bucket
 
        if destructive_tests_enabled ; then
-               # This test adds a new user on the system. Since it's a quite
+               # Those tests add a new user on the system. Since it's a quite
                # intrusive change to the system, we decide to only run it when
                # the user knows what they are doing.
                test_ust_notifier_discarded_count_multi_uid
+               test_ust_notifier_discarded_regardless_trigger_owner
        else
                skip 0 "You need to set the LTTNG_ENABLE_DESTRUCTIVE_TESTS environment variable to \"will-break-my-system\" to run this test" $DESTRUCTIVE_TESTS_NUM
        fi
This page took 0.036791 seconds and 4 git commands to generate.