SoW-2020-0002: Trace Hit Counters
[deliverable/lttng-modules.git] / src / lttng-abi.c
index 4dd6e7e5e2fff77290f493664b543e66471b0a96..f65caf936a5fde6184efa741ec8254ac973c79f8 100644 (file)
@@ -37,6 +37,7 @@
 #include <wrapper/poll.h>
 #include <wrapper/file.h>
 #include <wrapper/kref.h>
+#include <wrapper/barrier.h>
 #include <lttng/string-utils.h>
 #include <lttng/abi.h>
 #include <lttng/abi-old.h>
@@ -44,6 +45,7 @@
 #include <lttng/tracer.h>
 #include <lttng/tp-mempool.h>
 #include <ringbuffer/frontend_types.h>
+#include <ringbuffer/iterator.h>
 
 /*
  * This is LTTng's own personal way to create a system call as an external
 
 static struct proc_dir_entry *lttng_proc_dentry;
 
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0))
+#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,6,0))
 static const struct proc_ops lttng_proc_ops;
 #else
 static const struct file_operations lttng_proc_ops;
 #endif
 
 static const struct file_operations lttng_session_fops;
+static const struct file_operations lttng_event_notifier_group_fops;
 static const struct file_operations lttng_channel_fops;
 static const struct file_operations lttng_metadata_fops;
 static const struct file_operations lttng_event_fops;
@@ -67,6 +70,17 @@ static struct file_operations lttng_stream_ring_buffer_file_operations;
 static int put_u64(uint64_t val, unsigned long arg);
 static int put_u32(uint32_t val, unsigned long arg);
 
+static int validate_zeroed_padding(char *p, size_t len)
+{
+       size_t i;
+
+       for (i = 0; i < len; i++) {
+               if (p[i])
+                       return -1;
+       }
+       return 0;
+}
+
 /*
  * Teardown management: opened file descriptors keep a refcount on the module,
  * so it can only exit when all file descriptors are closed.
@@ -105,6 +119,52 @@ fd_error:
        return ret;
 }
 
+void event_notifier_send_notification_work_wakeup(struct irq_work *entry)
+{
+       struct lttng_event_notifier_group *event_notifier_group =
+                       container_of(entry, struct lttng_event_notifier_group,
+                                       wakeup_pending);
+       wake_up_interruptible(&event_notifier_group->read_wait);
+}
+
+static
+int lttng_abi_create_event_notifier_group(void)
+{
+       struct lttng_event_notifier_group *event_notifier_group;
+       struct file *event_notifier_group_file;
+       int event_notifier_group_fd, ret;
+
+       event_notifier_group = lttng_event_notifier_group_create();
+       if (!event_notifier_group)
+               return -ENOMEM;
+
+       event_notifier_group_fd = lttng_get_unused_fd();
+       if (event_notifier_group_fd < 0) {
+               ret = event_notifier_group_fd;
+               goto fd_error;
+       }
+       event_notifier_group_file = anon_inode_getfile("[lttng_event_notifier_group]",
+                                         &lttng_event_notifier_group_fops,
+                                         event_notifier_group, O_RDWR);
+       if (IS_ERR(event_notifier_group_file)) {
+               ret = PTR_ERR(event_notifier_group_file);
+               goto file_error;
+       }
+
+       event_notifier_group->file = event_notifier_group_file;
+       init_waitqueue_head(&event_notifier_group->read_wait);
+       init_irq_work(&event_notifier_group->wakeup_pending,
+                     event_notifier_send_notification_work_wakeup);
+       fd_install(event_notifier_group_fd, event_notifier_group_file);
+       return event_notifier_group_fd;
+
+file_error:
+       put_unused_fd(event_notifier_group_fd);
+fd_error:
+       lttng_event_notifier_group_destroy(event_notifier_group);
+       return ret;
+}
+
 static
 int lttng_abi_tracepoint_list(void)
 {
@@ -306,6 +366,8 @@ long lttng_abi_add_context(struct file *file,
  *             Returns after all previously running probes have completed
  *     LTTNG_KERNEL_TRACER_ABI_VERSION
  *             Returns the LTTng kernel tracer ABI version
+ *     LTTNG_KERNEL_EVENT_NOTIFIER_GROUP_CREATE
+ *             Returns a LTTng event notifier group file descriptor
  *
  * The returned session will be deleted when its file descriptor is closed.
  */
@@ -316,6 +378,8 @@ long lttng_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        case LTTNG_KERNEL_OLD_SESSION:
        case LTTNG_KERNEL_SESSION:
                return lttng_abi_create_session();
+       case LTTNG_KERNEL_EVENT_NOTIFIER_GROUP_CREATE:
+               return lttng_abi_create_event_notifier_group();
        case LTTNG_KERNEL_OLD_TRACER_VERSION:
        {
                struct lttng_kernel_tracer_version v;
@@ -400,7 +464,7 @@ long lttng_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        }
 }
 
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0))
+#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,6,0))
 static const struct proc_ops lttng_proc_ops = {
        .proc_ioctl = lttng_ioctl,
 #ifdef CONFIG_COMPAT
@@ -426,6 +490,7 @@ int lttng_abi_create_channel(struct file *session_file,
        const struct file_operations *fops = NULL;
        const char *transport_name;
        struct lttng_channel *chan;
+       struct lttng_event_container *container;
        struct file *chan_file;
        int chan_fd;
        int ret = 0;
@@ -493,7 +558,8 @@ int lttng_abi_create_channel(struct file *session_file,
                ret = -EINVAL;
                goto chan_error;
        }
-       chan->file = chan_file;
+       container = lttng_channel_get_event_container(chan);
+       container->file = chan_file;
        chan_file->private_data = chan;
        fd_install(chan_fd, chan_file);
 
@@ -543,6 +609,493 @@ int lttng_abi_session_set_creation_time(struct lttng_session *session,
        return 0;
 }
 
+static
+int lttng_abi_validate_event_param(struct lttng_kernel_event *event_param)
+{
+       /* Limit ABI to implemented features. */
+       switch (event_param->instrumentation) {
+       case LTTNG_KERNEL_SYSCALL:
+               switch (event_param->u.syscall.entryexit) {
+               case LTTNG_KERNEL_SYSCALL_ENTRY:
+               case LTTNG_KERNEL_SYSCALL_EXIT:
+               case LTTNG_KERNEL_SYSCALL_ENTRYEXIT:
+                       break;
+               default:
+                       return -EINVAL;
+               }
+               switch (event_param->u.syscall.abi) {
+               case LTTNG_KERNEL_SYSCALL_ABI_ALL:
+                       break;
+               default:
+                       return -EINVAL;
+               }
+               switch (event_param->u.syscall.match) {
+               case LTTNG_KERNEL_SYSCALL_MATCH_NAME:
+                       break;
+               default:
+                       return -EINVAL;
+               }
+               break;
+
+       case LTTNG_KERNEL_TRACEPOINT:   /* Fallthrough */
+       case LTTNG_KERNEL_KPROBE:       /* Fallthrough */
+       case LTTNG_KERNEL_KRETPROBE:    /* Fallthrough */
+       case LTTNG_KERNEL_NOOP:         /* Fallthrough */
+       case LTTNG_KERNEL_UPROBE:
+               break;
+
+       case LTTNG_KERNEL_FUNCTION:     /* Fallthrough */
+       default:
+               return -EINVAL;
+       }
+       return 0;
+}
+
+static
+int lttng_abi_create_event(struct file *event_container_file,
+                          struct lttng_event_container *container,
+                          struct lttng_kernel_event *event_param,
+                          const struct lttng_counter_key *key)
+{
+       int event_fd, ret;
+       struct file *event_file;
+       void *priv;
+
+       event_param->name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
+       switch (event_param->instrumentation) {
+       case LTTNG_KERNEL_KRETPROBE:
+               event_param->u.kretprobe.symbol_name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
+               break;
+       case LTTNG_KERNEL_KPROBE:
+               event_param->u.kprobe.symbol_name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
+               break;
+       case LTTNG_KERNEL_FUNCTION:
+               WARN_ON_ONCE(1);
+               /* Not implemented. */
+               break;
+       default:
+               break;
+       }
+       event_fd = lttng_get_unused_fd();
+       if (event_fd < 0) {
+               ret = event_fd;
+               goto fd_error;
+       }
+       event_file = anon_inode_getfile("[lttng_event]",
+                                       &lttng_event_fops,
+                                       NULL, O_RDWR);
+       if (IS_ERR(event_file)) {
+               ret = PTR_ERR(event_file);
+               goto file_error;
+       }
+       /* The event holds a reference on the container */
+       if (!atomic_long_add_unless(&event_container_file->f_count, 1, LONG_MAX)) {
+               ret = -EOVERFLOW;
+               goto refcount_error;
+       }
+       ret = lttng_abi_validate_event_param(event_param);
+       if (ret)
+               goto event_error;
+       if (event_param->instrumentation == LTTNG_KERNEL_TRACEPOINT
+                       || event_param->instrumentation == LTTNG_KERNEL_SYSCALL) {
+               struct lttng_event_enabler *event_enabler;
+
+               if (strutils_is_star_glob_pattern(event_param->name)) {
+                       /*
+                        * If the event name is a star globbing pattern,
+                        * we create the special star globbing enabler.
+                        */
+                       event_enabler = lttng_event_enabler_create(LTTNG_ENABLER_FORMAT_STAR_GLOB,
+                               event_param, key, container);
+               } else {
+                       event_enabler = lttng_event_enabler_create(LTTNG_ENABLER_FORMAT_NAME,
+                               event_param, key, container);
+               }
+               priv = event_enabler;
+       } else {
+               struct lttng_event *event;
+
+               /*
+                * We tolerate no failure path after event creation. It
+                * will stay invariant for the rest of the session.
+                */
+               event = lttng_event_create(container, event_param, key,
+                               NULL, NULL,
+                               event_param->instrumentation, event_param->token);
+               if (IS_ERR(event)) {
+                       ret = PTR_ERR(event);
+                       goto event_error;
+               }
+               priv = event;
+       }
+       event_file->private_data = priv;
+       fd_install(event_fd, event_file);
+       return event_fd;
+
+event_error:
+       atomic_long_dec(&event_container_file->f_count);
+refcount_error:
+       fput(event_file);
+file_error:
+       put_unused_fd(event_fd);
+fd_error:
+       return ret;
+}
+
+static
+int lttng_counter_release(struct inode *inode, struct file *file)
+{
+       struct lttng_counter *counter = file->private_data;
+
+       if (counter) {
+               /*
+                * Do not destroy the counter itself. Wait of the owner
+                * (event_notifier group) to be destroyed.
+                */
+               fput(counter->owner);
+       }
+
+       return 0;
+}
+
+static
+int copy_counter_key(struct lttng_counter_key *key,
+                    const struct lttng_kernel_counter_key *ukey)
+{
+       size_t i, j, nr_dimensions;
+
+       nr_dimensions = ukey->nr_dimensions;
+       if (nr_dimensions > LTTNG_COUNTER_DIMENSION_MAX)
+               return -EINVAL;
+       key->nr_dimensions = nr_dimensions;
+       for (i = 0; i < nr_dimensions; i++) {
+               const struct lttng_kernel_counter_key_dimension *udim =
+                       &ukey->key_dimensions[i];
+               struct lttng_counter_key_dimension *dim =
+                       &key->key_dimensions[i];
+               size_t nr_key_tokens;
+
+               nr_key_tokens = udim->nr_key_tokens;
+               if (!nr_key_tokens || nr_key_tokens > LTTNG_NR_KEY_TOKEN)
+                       return -EINVAL;
+               dim->nr_key_tokens = nr_key_tokens;
+               for (j = 0; j < nr_key_tokens; j++) {
+                       const struct lttng_kernel_key_token *utoken =
+                               &udim->key_tokens[j];
+                       struct lttng_key_token *token =
+                               &dim->key_tokens[j];
+
+                       switch (utoken->type) {
+                       case LTTNG_KERNEL_KEY_TOKEN_STRING:
+                       {
+                               long ret;
+
+                               token->type = LTTNG_KEY_TOKEN_STRING;
+                               ret = strncpy_from_user(token->arg.string,
+                                       (char __user *)(unsigned long)utoken->arg.string_ptr,
+                                       LTTNG_KEY_TOKEN_STRING_LEN_MAX);
+                               if (ret < 0)
+                                       return -EFAULT;
+                               if (!ret || ret == LTTNG_KEY_TOKEN_STRING_LEN_MAX)
+                                       return -EINVAL;
+                               break;
+                       }
+                       case LTTNG_KERNEL_KEY_TOKEN_EVENT_NAME:
+                               token->type = LTTNG_KEY_TOKEN_EVENT_NAME;
+                               break;
+                       case LTTNG_KERNEL_KEY_TOKEN_PROVIDER_NAME:
+                               printk(KERN_ERR "LTTng: Provider name token not supported.\n");
+                               /* Fallthrough */
+                       default:
+                               return -EINVAL;
+                       }
+               }
+       }
+       return 0;
+}
+
+static
+long lttng_counter_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
+{
+       struct lttng_counter *counter = file->private_data;
+       struct lttng_event_container *container = lttng_counter_get_event_container(counter);
+       size_t indexes[LTTNG_KERNEL_COUNTER_DIMENSION_MAX] = { 0 };
+       int i;
+
+       switch (cmd) {
+       case LTTNG_KERNEL_COUNTER_READ:
+       {
+               struct lttng_kernel_counter_read local_counter_read;
+               struct lttng_kernel_counter_read __user *ucounter_read =
+                               (struct lttng_kernel_counter_read __user *) arg;
+               bool overflow, underflow;
+               int64_t value;
+               int32_t cpu;
+               int ret;
+
+               if (copy_from_user(&local_counter_read, ucounter_read,
+                                       sizeof(local_counter_read)))
+                       return -EFAULT;
+               if (validate_zeroed_padding(local_counter_read.padding,
+                               sizeof(local_counter_read.padding)))
+                       return -EINVAL;
+
+               /* Cast all indexes into size_t. */
+               for (i = 0; i < local_counter_read.index.number_dimensions; i++)
+                       indexes[i] = (size_t) local_counter_read.index.dimension_indexes[i];
+               cpu = local_counter_read.cpu;
+
+               ret = lttng_kernel_counter_read(counter, indexes, cpu, &value,
+                               &overflow, &underflow);
+               if (ret)
+                       return ret;
+               local_counter_read.value.value = value;
+               local_counter_read.value.overflow = overflow;
+               local_counter_read.value.underflow = underflow;
+
+               if (copy_to_user(&ucounter_read->value, &local_counter_read.value,
+                                       sizeof(local_counter_read.value)))
+                       return -EFAULT;
+
+               return 0;
+       }
+       case LTTNG_KERNEL_COUNTER_AGGREGATE:
+       {
+               struct lttng_kernel_counter_aggregate local_counter_aggregate;
+               struct lttng_kernel_counter_aggregate __user *ucounter_aggregate =
+                               (struct lttng_kernel_counter_aggregate __user *) arg;
+               bool overflow, underflow;
+               int64_t value;
+               int ret;
+
+               if (copy_from_user(&local_counter_aggregate, ucounter_aggregate,
+                                       sizeof(local_counter_aggregate)))
+                       return -EFAULT;
+               if (validate_zeroed_padding(local_counter_aggregate.padding,
+                               sizeof(local_counter_aggregate.padding)))
+                       return -EINVAL;
+
+               /* Cast all indexes into size_t. */
+               for (i = 0; i < local_counter_aggregate.index.number_dimensions; i++)
+                       indexes[i] = (size_t) local_counter_aggregate.index.dimension_indexes[i];
+
+               ret = lttng_kernel_counter_aggregate(counter, indexes, &value,
+                               &overflow, &underflow);
+               if (ret)
+                       return ret;
+               local_counter_aggregate.value.value = value;
+               local_counter_aggregate.value.overflow = overflow;
+               local_counter_aggregate.value.underflow = underflow;
+
+               if (copy_to_user(&ucounter_aggregate->value, &local_counter_aggregate.value,
+                                       sizeof(local_counter_aggregate.value)))
+                       return -EFAULT;
+
+               return 0;
+       }
+       case LTTNG_KERNEL_COUNTER_CLEAR:
+       {
+               struct lttng_kernel_counter_clear local_counter_clear;
+               struct lttng_kernel_counter_clear __user *ucounter_clear =
+                               (struct lttng_kernel_counter_clear __user *) arg;
+
+               if (copy_from_user(&local_counter_clear, ucounter_clear,
+                                       sizeof(local_counter_clear)))
+                       return -EFAULT;
+               if (validate_zeroed_padding(local_counter_clear.padding,
+                               sizeof(local_counter_clear.padding)))
+                       return -EINVAL;
+
+               /* Cast all indexes into size_t. */
+               for (i = 0; i < local_counter_clear.index.number_dimensions; i++)
+                       indexes[i] = (size_t) local_counter_clear.index.dimension_indexes[i];
+
+               return lttng_kernel_counter_clear(counter, indexes);
+       }
+       case LTTNG_KERNEL_COUNTER_EVENT:
+       {
+               struct lttng_kernel_counter_event *ucounter_event_param;
+               struct lttng_counter_key *key;
+               int ret;
+
+               key = kzalloc(sizeof(*key), GFP_KERNEL);
+               if (!key)
+                       return -ENOMEM;
+               ucounter_event_param = kzalloc(sizeof(*ucounter_event_param), GFP_KERNEL);
+               if (!ucounter_event_param) {
+                       ret = -ENOMEM;
+                       goto free_key;
+               }
+               if (copy_from_user(ucounter_event_param,
+                               (struct lttng_kernel_counter_event __user *) arg,
+                               sizeof(*ucounter_event_param))) {
+                       ret = -EFAULT;
+                       goto free_param;
+               }
+               ret = copy_counter_key(key, &ucounter_event_param->key);
+               if (ret)
+                       goto free_param;
+               ret = lttng_abi_create_event(file, container, &ucounter_event_param->event, key);
+       free_param:
+               kfree(ucounter_event_param);
+       free_key:
+               kfree(key);
+               return ret;
+       }
+       case LTTNG_KERNEL_ENABLE:
+               return lttng_event_container_enable(container);
+       case LTTNG_KERNEL_DISABLE:
+               return lttng_event_container_disable(container);
+       case LTTNG_KERNEL_SYSCALL_MASK:
+               return lttng_event_container_syscall_mask(container,
+                       (struct lttng_kernel_syscall_mask __user *) arg);
+       case LTTNG_KERNEL_COUNTER_MAP_NR_DESCRIPTORS:
+       {
+               uint64_t __user *user_nr_descriptors = (uint64_t __user *) arg;
+               uint64_t nr_descriptors;
+
+               mutex_lock(&counter->map.lock);
+               nr_descriptors = counter->map.nr_descriptors;
+               mutex_unlock(&counter->map.lock);
+               return put_user(nr_descriptors, user_nr_descriptors);
+       }
+       case LTTNG_KERNEL_COUNTER_MAP_DESCRIPTOR:
+       {
+               struct lttng_kernel_counter_map_descriptor __user *user_descriptor =
+                       (struct lttng_kernel_counter_map_descriptor __user *) arg;
+               struct lttng_kernel_counter_map_descriptor local_descriptor;
+               struct lttng_counter_map_descriptor *kernel_descriptor;
+               int ret;
+
+               if (copy_from_user(&local_descriptor, user_descriptor,
+                                       sizeof(local_descriptor)))
+                       return -EFAULT;
+               if (validate_zeroed_padding(local_descriptor.padding,
+                               sizeof(local_descriptor.padding)))
+                       return -EINVAL;
+
+               mutex_lock(&counter->map.lock);
+               if (local_descriptor.descriptor_index >= counter->map.nr_descriptors) {
+                       ret = -EOVERFLOW;
+                       goto map_descriptor_error_unlock;
+               }
+               kernel_descriptor = &counter->map.descriptors[local_descriptor.descriptor_index];
+               local_descriptor.user_token = kernel_descriptor->user_token;
+               local_descriptor.array_index = kernel_descriptor->array_index;
+               memcpy(local_descriptor.key, kernel_descriptor->key, LTTNG_KERNEL_COUNTER_KEY_LEN);
+               mutex_unlock(&counter->map.lock);
+
+               if (copy_to_user(user_descriptor, &local_descriptor,
+                                       sizeof(local_descriptor)))
+                       return -EFAULT;
+
+               return 0;
+
+       map_descriptor_error_unlock:
+               mutex_unlock(&counter->map.lock);
+               return ret;
+       }
+       default:
+               WARN_ON_ONCE(1);
+               return -ENOSYS;
+       }
+}
+
+static const struct file_operations lttng_counter_fops = {
+       .owner = THIS_MODULE,
+       .release = lttng_counter_release,
+       .unlocked_ioctl = lttng_counter_ioctl,
+#ifdef CONFIG_COMPAT
+       .compat_ioctl = lttng_counter_ioctl,
+#endif
+};
+
+static
+long lttng_abi_session_create_counter(
+               struct lttng_session *session,
+               const struct lttng_kernel_counter_conf *counter_conf)
+{
+       int counter_fd, ret, i;
+       char *counter_transport_name;
+       struct lttng_event_container *container;
+       struct lttng_counter *counter;
+       struct file *counter_file;
+       size_t dimension_sizes[LTTNG_KERNEL_COUNTER_DIMENSION_MAX] = { 0 };
+       size_t number_dimensions;
+
+       counter_fd = lttng_get_unused_fd();
+       if (counter_fd < 0) {
+               ret = counter_fd;
+               goto fd_error;
+       }
+
+       counter_file = anon_inode_getfile("[lttng_counter]",
+                                      &lttng_counter_fops,
+                                      NULL, O_RDONLY);
+       if (IS_ERR(counter_file)) {
+               ret = PTR_ERR(counter_file);
+               goto file_error;
+       }
+
+       if (counter_conf->arithmetic != LTTNG_KERNEL_COUNTER_ARITHMETIC_MODULAR) {
+               printk(KERN_ERR "LTTng: Map: Error counter of the wrong type.\n");
+               return -EINVAL;
+       }
+
+       switch (counter_conf->bitness) {
+       case LTTNG_KERNEL_COUNTER_BITNESS_64:
+               counter_transport_name = "counter-per-cpu-64-modular";
+               break;
+       case LTTNG_KERNEL_COUNTER_BITNESS_32:
+               counter_transport_name = "counter-per-cpu-32-modular";
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       number_dimensions = (size_t) counter_conf->number_dimensions;
+
+       for (i = 0; i < counter_conf->number_dimensions; i++) {
+               if (counter_conf->dimensions[i].has_underflow)
+                       return -EINVAL;
+               if (counter_conf->dimensions[i].has_overflow)
+                       return -EINVAL;
+               dimension_sizes[i] = counter_conf->dimensions[i].size;
+       }
+
+       if (!atomic_long_add_unless(&session->file->f_count, 1, LONG_MAX)) {
+               ret = -EOVERFLOW;
+               goto refcount_error;
+       }
+
+       counter = lttng_session_create_counter(session,
+                       counter_transport_name,
+                       number_dimensions, dimension_sizes,
+                       counter_conf->coalesce_hits);
+       if (!counter) {
+               ret = -EINVAL;
+               goto counter_error;
+       }
+
+       counter->owner = session->file;
+       container = lttng_counter_get_event_container(counter);
+       container->file = counter_file;
+       counter_file->private_data = counter;
+
+       fd_install(counter_fd, counter_file);
+
+       return counter_fd;
+
+counter_error:
+       atomic_long_dec(&session->file->f_count);
+refcount_error:
+       fput(counter_file);
+file_error:
+       put_unused_fd(counter_fd);
+fd_error:
+       return ret;
+}
+
 static
 enum tracker_type get_tracker_type(struct lttng_kernel_tracker_args *tracker)
 {
@@ -732,36 +1285,270 @@ long lttng_session_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                        return -EFAULT;
                return lttng_abi_session_set_creation_time(session, &time);
        }
+       case LTTNG_KERNEL_COUNTER:
+       {
+               struct lttng_kernel_counter_conf ucounter_conf;
+
+               if (copy_from_user(&ucounter_conf,
+                               (struct lttng_kernel_counter_conf __user *) arg,
+                               sizeof(ucounter_conf)))
+                       return -EFAULT;
+               return lttng_abi_session_create_counter(session,
+                               &ucounter_conf);
+       }
        default:
                return -ENOIOCTLCMD;
        }
 }
 
-/*
- * Called when the last file reference is dropped.
+/*
+ * Called when the last file reference is dropped.
+ *
+ * Big fat note: channels and events are invariant for the whole session after
+ * their creation. So this session destruction also destroys all channel and
+ * event structures specific to this session (they are not destroyed when their
+ * individual file is released).
+ */
+static
+int lttng_session_release(struct inode *inode, struct file *file)
+{
+       struct lttng_session *session = file->private_data;
+
+       if (session)
+               lttng_session_destroy(session);
+       return 0;
+}
+
+static const struct file_operations lttng_session_fops = {
+       .owner = THIS_MODULE,
+       .release = lttng_session_release,
+       .unlocked_ioctl = lttng_session_ioctl,
+#ifdef CONFIG_COMPAT
+       .compat_ioctl = lttng_session_ioctl,
+#endif
+};
+
+/*
+ * When encountering empty buffer, flush current sub-buffer if non-empty
+ * and retry (if new data available to read after flush).
+ */
+static
+ssize_t lttng_event_notifier_group_notif_read(struct file *filp, char __user *user_buf,
+               size_t count, loff_t *ppos)
+{
+       struct lttng_event_notifier_group *event_notifier_group = filp->private_data;
+       struct channel *chan = event_notifier_group->chan;
+       struct lib_ring_buffer *buf = event_notifier_group->buf;
+       ssize_t read_count = 0, len;
+       size_t read_offset;
+
+       might_sleep();
+       if (!lttng_access_ok(VERIFY_WRITE, user_buf, count))
+               return -EFAULT;
+
+       /* Finish copy of previous record */
+       if (*ppos != 0) {
+               if (read_count < count) {
+                       len = chan->iter.len_left;
+                       read_offset = *ppos;
+                       goto skip_get_next;
+               }
+       }
+
+       while (read_count < count) {
+               size_t copy_len, space_left;
+
+               len = lib_ring_buffer_get_next_record(chan, buf);
+len_test:
+               if (len < 0) {
+                       /*
+                        * Check if buffer is finalized (end of file).
+                        */
+                       if (len == -ENODATA) {
+                               /* A 0 read_count will tell about end of file */
+                               goto nodata;
+                       }
+                       if (filp->f_flags & O_NONBLOCK) {
+                               if (!read_count)
+                                       read_count = -EAGAIN;
+                               goto nodata;
+                       } else {
+                               int error;
+
+                               /*
+                                * No data available at the moment, return what
+                                * we got.
+                                */
+                               if (read_count)
+                                       goto nodata;
+
+                               /*
+                                * Wait for returned len to be >= 0 or -ENODATA.
+                                */
+                               error = wait_event_interruptible(
+                                         event_notifier_group->read_wait,
+                                         ((len = lib_ring_buffer_get_next_record(
+                                                 chan, buf)), len != -EAGAIN));
+                               CHAN_WARN_ON(chan, len == -EBUSY);
+                               if (error) {
+                                       read_count = error;
+                                       goto nodata;
+                               }
+                               CHAN_WARN_ON(chan, len < 0 && len != -ENODATA);
+                               goto len_test;
+                       }
+               }
+               read_offset = buf->iter.read_offset;
+skip_get_next:
+               space_left = count - read_count;
+               if (len <= space_left) {
+                       copy_len = len;
+                       chan->iter.len_left = 0;
+                       *ppos = 0;
+               } else {
+                       copy_len = space_left;
+                       chan->iter.len_left = len - copy_len;
+                       *ppos = read_offset + copy_len;
+               }
+               if (__lib_ring_buffer_copy_to_user(&buf->backend, read_offset,
+                                              &user_buf[read_count],
+                                              copy_len)) {
+                       /*
+                        * Leave the len_left and ppos values at their current
+                        * state, as we currently have a valid event to read.
+                        */
+                       return -EFAULT;
+               }
+               read_count += copy_len;
+       }
+       goto put_record;
+
+nodata:
+       *ppos = 0;
+       chan->iter.len_left = 0;
+
+put_record:
+       lib_ring_buffer_put_current_record(buf);
+       return read_count;
+}
+
+/*
+ * If the ring buffer is non empty (even just a partial subbuffer), return that
+ * there is data available. Perform a ring buffer flush if we encounter a
+ * non-empty ring buffer which does not have any consumeable subbuffer available.
+ */
+static
+unsigned int lttng_event_notifier_group_notif_poll(struct file *filp,
+               poll_table *wait)
+{
+       unsigned int mask = 0;
+       struct lttng_event_notifier_group *event_notifier_group = filp->private_data;
+       struct channel *chan = event_notifier_group->chan;
+       struct lib_ring_buffer *buf = event_notifier_group->buf;
+       const struct lib_ring_buffer_config *config = &chan->backend.config;
+       int finalized, disabled;
+       unsigned long consumed, offset;
+       size_t subbuffer_header_size = config->cb.subbuffer_header_size();
+
+       if (filp->f_mode & FMODE_READ) {
+               poll_wait_set_exclusive(wait);
+               poll_wait(filp, &event_notifier_group->read_wait, wait);
+
+               finalized = lib_ring_buffer_is_finalized(config, buf);
+               disabled = lib_ring_buffer_channel_is_disabled(chan);
+
+               /*
+                * lib_ring_buffer_is_finalized() contains a smp_rmb() ordering
+                * finalized load before offsets loads.
+                */
+               WARN_ON(atomic_long_read(&buf->active_readers) != 1);
+retry:
+               if (disabled)
+                       return POLLERR;
+
+               offset = lib_ring_buffer_get_offset(config, buf);
+               consumed = lib_ring_buffer_get_consumed(config, buf);
+
+               /*
+                * If there is no buffer available to consume.
+                */
+               if (subbuf_trunc(offset, chan) - subbuf_trunc(consumed, chan) == 0) {
+                       /*
+                        * If there is a non-empty subbuffer, flush and try again.
+                        */
+                       if (subbuf_offset(offset, chan) > subbuffer_header_size) {
+                               lib_ring_buffer_switch_remote(buf);
+                               goto retry;
+                       }
+
+                       if (finalized)
+                               return POLLHUP;
+                       else {
+                               /*
+                                * The memory barriers
+                                * __wait_event()/wake_up_interruptible() take
+                                * care of "raw_spin_is_locked" memory ordering.
+                                */
+                               if (raw_spin_is_locked(&buf->raw_tick_nohz_spinlock))
+                                       goto retry;
+                               else
+                                       return 0;
+                       }
+               } else {
+                       if (subbuf_trunc(offset, chan) - subbuf_trunc(consumed, chan)
+                                       >= chan->backend.buf_size)
+                               return POLLPRI | POLLRDBAND;
+                       else
+                               return POLLIN | POLLRDNORM;
+               }
+       }
+
+       return mask;
+}
+
+/**
+ *     lttng_event_notifier_group_notif_open - event_notifier ring buffer open file operation
+ *     @inode: opened inode
+ *     @file: opened file
  *
- * Big fat note: channels and events are invariant for the whole session after
- * their creation. So this session destruction also destroys all channel and
- * event structures specific to this session (they are not destroyed when their
- * individual file is released).
+ *     Open implementation. Makes sure only one open instance of a buffer is
+ *     done at a given moment.
  */
-static
-int lttng_session_release(struct inode *inode, struct file *file)
+static int lttng_event_notifier_group_notif_open(struct inode *inode, struct file *file)
 {
-       struct lttng_session *session = file->private_data;
+       struct lttng_event_notifier_group *event_notifier_group = inode->i_private;
+       struct lib_ring_buffer *buf = event_notifier_group->buf;
 
-       if (session)
-               lttng_session_destroy(session);
+       file->private_data = event_notifier_group;
+       return lib_ring_buffer_open(inode, file, buf);
+}
+
+/**
+ *     lttng_event_notifier_group_notif_release - event_notifier ring buffer release file operation
+ *     @inode: opened inode
+ *     @file: opened file
+ *
+ *     Release implementation.
+ */
+static int lttng_event_notifier_group_notif_release(struct inode *inode, struct file *file)
+{
+       struct lttng_event_notifier_group *event_notifier_group = file->private_data;
+       struct lib_ring_buffer *buf = event_notifier_group->buf;
+       int ret;
+
+       ret = lib_ring_buffer_release(inode, file, buf);
+       if (ret)
+               return ret;
+       fput(event_notifier_group->file);
        return 0;
 }
 
-static const struct file_operations lttng_session_fops = {
+static const struct file_operations lttng_event_notifier_group_notif_fops = {
        .owner = THIS_MODULE,
-       .release = lttng_session_release,
-       .unlocked_ioctl = lttng_session_ioctl,
-#ifdef CONFIG_COMPAT
-       .compat_ioctl = lttng_session_ioctl,
-#endif
+       .open = lttng_event_notifier_group_notif_open,
+       .release = lttng_event_notifier_group_notif_release,
+       .read = lttng_event_notifier_group_notif_read,
+       .poll = lttng_event_notifier_group_notif_poll,
 };
 
 /**
@@ -1080,7 +1867,7 @@ int lttng_metadata_ring_buffer_open(struct inode *inode, struct file *file)
         * session, we need to keep our own reference on the transport.
         */
        if (!try_module_get(stream->transport->owner)) {
-               printk(KERN_WARNING "LTT : Can't lock transport module.\n");
+               printk(KERN_WARNING "LTTng: Can't lock transport module.\n");
                return -EBUSY;
        }
        return lib_ring_buffer_open(inode, file, buf);
@@ -1139,8 +1926,8 @@ const struct file_operations lttng_metadata_ring_buffer_file_operations = {
 };
 
 static
-int lttng_abi_create_stream_fd(struct file *channel_file, void *stream_priv,
-               const struct file_operations *fops)
+int lttng_abi_create_stream_fd(struct file *file, void *stream_priv,
+               const struct file_operations *fops, const char *name)
 {
        int stream_fd, ret;
        struct file *stream_file;
@@ -1150,8 +1937,7 @@ int lttng_abi_create_stream_fd(struct file *channel_file, void *stream_priv,
                ret = stream_fd;
                goto fd_error;
        }
-       stream_file = anon_inode_getfile("[lttng_stream]", fops,
-                       stream_priv, O_RDWR);
+       stream_file = anon_inode_getfile(name, fops, stream_priv, O_RDWR);
        if (IS_ERR(stream_file)) {
                ret = PTR_ERR(stream_file);
                goto file_error;
@@ -1177,9 +1963,9 @@ fd_error:
 }
 
 static
-int lttng_abi_open_stream(struct file *channel_file)
+int lttng_abi_open_stream(struct file *file)
 {
-       struct lttng_channel *channel = channel_file->private_data;
+       struct lttng_channel *channel = file->private_data;
        struct lib_ring_buffer *buf;
        int ret;
        void *stream_priv;
@@ -1189,8 +1975,9 @@ int lttng_abi_open_stream(struct file *channel_file)
                return -ENOENT;
 
        stream_priv = buf;
-       ret = lttng_abi_create_stream_fd(channel_file, stream_priv,
-                       &lttng_stream_ring_buffer_file_operations);
+       ret = lttng_abi_create_stream_fd(file, stream_priv,
+                       &lttng_stream_ring_buffer_file_operations,
+                       "[lttng_stream]");
        if (ret < 0)
                goto fd_error;
 
@@ -1202,10 +1989,11 @@ fd_error:
 }
 
 static
-int lttng_abi_open_metadata_stream(struct file *channel_file)
+int lttng_abi_open_metadata_stream(struct file *file)
 {
-       struct lttng_channel *channel = channel_file->private_data;
-       struct lttng_session *session = channel->session;
+       struct lttng_channel *channel = file->private_data;
+       struct lttng_event_container *container = lttng_channel_get_event_container(channel);
+       struct lttng_session *session = container->session;
        struct lib_ring_buffer *buf;
        int ret;
        struct lttng_metadata_stream *metadata_stream;
@@ -1234,7 +2022,7 @@ int lttng_abi_open_metadata_stream(struct file *channel_file)
         * session, we need to keep our own reference on the transport.
         */
        if (!try_module_get(metadata_stream->transport->owner)) {
-               printk(KERN_WARNING "LTT : Can't lock transport module.\n");
+               printk(KERN_WARNING "LTTng: Can't lock transport module.\n");
                ret = -EINVAL;
                goto notransport;
        }
@@ -1244,8 +2032,9 @@ int lttng_abi_open_metadata_stream(struct file *channel_file)
                goto kref_error;
        }
 
-       ret = lttng_abi_create_stream_fd(channel_file, stream_priv,
-                       &lttng_metadata_ring_buffer_file_operations);
+       ret = lttng_abi_create_stream_fd(file, stream_priv,
+                       &lttng_metadata_ring_buffer_file_operations,
+                       "[lttng_metadata_stream]");
        if (ret < 0)
                goto fd_error;
 
@@ -1267,93 +2056,396 @@ nomem:
 }
 
 static
-int lttng_abi_create_event(struct file *channel_file,
-                          struct lttng_kernel_event *event_param)
+int lttng_abi_open_event_notifier_group_stream(struct file *notif_file)
 {
-       struct lttng_channel *channel = channel_file->private_data;
-       int event_fd, ret;
-       struct file *event_file;
+       struct lttng_event_notifier_group *event_notifier_group = notif_file->private_data;
+       struct channel *chan = event_notifier_group->chan;
+       struct lib_ring_buffer *buf;
+       int ret;
+       void *stream_priv;
+
+       buf = event_notifier_group->ops->buffer_read_open(chan);
+       if (!buf)
+               return -ENOENT;
+
+       /* The event_notifier notification fd holds a reference on the event_notifier group */
+       if (!atomic_long_add_unless(&notif_file->f_count, 1, LONG_MAX)) {
+               ret = -EOVERFLOW;
+               goto refcount_error;
+       }
+       event_notifier_group->buf = buf;
+       stream_priv = event_notifier_group;
+       ret = lttng_abi_create_stream_fd(notif_file, stream_priv,
+                       &lttng_event_notifier_group_notif_fops,
+                       "[lttng_event_notifier_stream]");
+       if (ret < 0)
+               goto fd_error;
+
+       return ret;
+
+fd_error:
+       atomic_long_dec(&notif_file->f_count);
+refcount_error:
+       event_notifier_group->ops->buffer_read_close(buf);
+       return ret;
+}
+
+static
+long lttng_event_notifier_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
+{
+       struct lttng_event_notifier *event_notifier;
+       struct lttng_event_notifier_enabler *event_notifier_enabler;
+       enum lttng_event_type *evtype = file->private_data;
+
+       switch (cmd) {
+       case LTTNG_KERNEL_ENABLE:
+               switch (*evtype) {
+               case LTTNG_TYPE_EVENT:
+                       event_notifier = file->private_data;
+                       return lttng_event_notifier_enable(event_notifier);
+               case LTTNG_TYPE_ENABLER:
+                       event_notifier_enabler = file->private_data;
+                       return lttng_event_notifier_enabler_enable(event_notifier_enabler);
+               default:
+                       WARN_ON_ONCE(1);
+                       return -ENOSYS;
+               }
+       case LTTNG_KERNEL_DISABLE:
+               switch (*evtype) {
+               case LTTNG_TYPE_EVENT:
+                       event_notifier = file->private_data;
+                       return lttng_event_notifier_disable(event_notifier);
+               case LTTNG_TYPE_ENABLER:
+                       event_notifier_enabler = file->private_data;
+                       return lttng_event_notifier_enabler_disable(event_notifier_enabler);
+               default:
+                       WARN_ON_ONCE(1);
+                       return -ENOSYS;
+               }
+       case LTTNG_KERNEL_FILTER:
+               switch (*evtype) {
+               case LTTNG_TYPE_EVENT:
+                       return -EINVAL;
+               case LTTNG_TYPE_ENABLER:
+                       event_notifier_enabler = file->private_data;
+                       return lttng_event_notifier_enabler_attach_filter_bytecode(
+                                       event_notifier_enabler,
+                               (struct lttng_kernel_filter_bytecode __user *) arg);
+               default:
+                       WARN_ON_ONCE(1);
+                       return -ENOSYS;
+               }
+
+       case LTTNG_KERNEL_CAPTURE:
+               switch (*evtype) {
+               case LTTNG_TYPE_EVENT:
+                       return -EINVAL;
+               case LTTNG_TYPE_ENABLER:
+                       event_notifier_enabler = file->private_data;
+                       return lttng_event_notifier_enabler_attach_capture_bytecode(
+                               event_notifier_enabler,
+                               (struct lttng_kernel_capture_bytecode __user *) arg);
+               default:
+                       WARN_ON_ONCE(1);
+                       return -ENOSYS;
+               }
+       case LTTNG_KERNEL_ADD_CALLSITE:
+               switch (*evtype) {
+               case LTTNG_TYPE_EVENT:
+                       event_notifier = file->private_data;
+                       return lttng_event_notifier_add_callsite(event_notifier,
+                               (struct lttng_kernel_event_callsite __user *) arg);
+               case LTTNG_TYPE_ENABLER:
+                       return -EINVAL;
+               default:
+                       WARN_ON_ONCE(1);
+                       return -ENOSYS;
+               }
+       default:
+               return -ENOIOCTLCMD;
+       }
+}
+
+static
+int lttng_event_notifier_release(struct inode *inode, struct file *file)
+{
+       struct lttng_event_notifier *event_notifier;
+       struct lttng_event_notifier_enabler *event_notifier_enabler;
+       enum lttng_event_type *evtype = file->private_data;
+
+       if (!evtype)
+               return 0;
+
+       switch (*evtype) {
+       case LTTNG_TYPE_EVENT:
+               event_notifier = file->private_data;
+               if (event_notifier)
+                       fput(event_notifier->group->file);
+               break;
+       case LTTNG_TYPE_ENABLER:
+               event_notifier_enabler = file->private_data;
+               if (event_notifier_enabler)
+                       fput(event_notifier_enabler->group->file);
+               break;
+       default:
+               WARN_ON_ONCE(1);
+               break;
+       }
+
+       return 0;
+}
+
+static const struct file_operations lttng_event_notifier_fops = {
+       .owner = THIS_MODULE,
+       .release = lttng_event_notifier_release,
+       .unlocked_ioctl = lttng_event_notifier_ioctl,
+#ifdef CONFIG_COMPAT
+       .compat_ioctl = lttng_event_notifier_ioctl,
+#endif
+};
+
+static
+int lttng_abi_create_event_notifier(struct file *event_notifier_group_file,
+               struct lttng_kernel_event_notifier *event_notifier_param)
+{
+       struct lttng_event_notifier_group *event_notifier_group =
+                       event_notifier_group_file->private_data;
+       int event_notifier_fd, ret;
+       struct file *event_notifier_file;
        void *priv;
 
-       event_param->name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
-       switch (event_param->instrumentation) {
-       case LTTNG_KERNEL_KRETPROBE:
-               event_param->u.kretprobe.symbol_name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
+       switch (event_notifier_param->event.instrumentation) {
+       case LTTNG_KERNEL_TRACEPOINT:
+       case LTTNG_KERNEL_UPROBE:
                break;
        case LTTNG_KERNEL_KPROBE:
-               event_param->u.kprobe.symbol_name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
+               event_notifier_param->event.u.kprobe.symbol_name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
                break;
-       case LTTNG_KERNEL_FUNCTION:
-               WARN_ON_ONCE(1);
-               /* Not implemented. */
+       case LTTNG_KERNEL_SYSCALL:
                break;
+       case LTTNG_KERNEL_KRETPROBE:
+               /* Placing an event notifier on kretprobe is not supported. */
+       case LTTNG_KERNEL_FUNCTION:
+       case LTTNG_KERNEL_NOOP:
        default:
-               break;
+               ret = -EINVAL;
+               goto inval_instr;
        }
-       event_fd = lttng_get_unused_fd();
-       if (event_fd < 0) {
-               ret = event_fd;
+
+       event_notifier_param->event.name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
+
+       event_notifier_fd = lttng_get_unused_fd();
+       if (event_notifier_fd < 0) {
+               ret = event_notifier_fd;
                goto fd_error;
        }
-       event_file = anon_inode_getfile("[lttng_event]",
-                                       &lttng_event_fops,
+
+       event_notifier_file = anon_inode_getfile("[lttng_event_notifier]",
+                                       &lttng_event_notifier_fops,
                                        NULL, O_RDWR);
-       if (IS_ERR(event_file)) {
-               ret = PTR_ERR(event_file);
+       if (IS_ERR(event_notifier_file)) {
+               ret = PTR_ERR(event_notifier_file);
                goto file_error;
        }
-       /* The event holds a reference on the channel */
-       if (!atomic_long_add_unless(&channel_file->f_count, 1, LONG_MAX)) {
+
+       /* The event notifier holds a reference on the event notifier group. */
+       if (!atomic_long_add_unless(&event_notifier_group_file->f_count, 1, LONG_MAX)) {
                ret = -EOVERFLOW;
                goto refcount_error;
        }
-       if (event_param->instrumentation == LTTNG_KERNEL_TRACEPOINT
-                       || event_param->instrumentation == LTTNG_KERNEL_SYSCALL) {
-               struct lttng_enabler *enabler;
 
-               if (strutils_is_star_glob_pattern(event_param->name)) {
+       if (event_notifier_param->event.instrumentation == LTTNG_KERNEL_TRACEPOINT
+                       || event_notifier_param->event.instrumentation == LTTNG_KERNEL_SYSCALL) {
+               struct lttng_event_notifier_enabler *enabler;
+
+               if (strutils_is_star_glob_pattern(event_notifier_param->event.name)) {
                        /*
                         * If the event name is a star globbing pattern,
                         * we create the special star globbing enabler.
                         */
-                       enabler = lttng_enabler_create(LTTNG_ENABLER_STAR_GLOB,
-                               event_param, channel);
+                       enabler = lttng_event_notifier_enabler_create(
+                                       event_notifier_group,
+                                       LTTNG_ENABLER_FORMAT_STAR_GLOB,
+                                       event_notifier_param);
                } else {
-                       enabler = lttng_enabler_create(LTTNG_ENABLER_NAME,
-                               event_param, channel);
+                       enabler = lttng_event_notifier_enabler_create(
+                                       event_notifier_group,
+                                       LTTNG_ENABLER_FORMAT_NAME,
+                                       event_notifier_param);
                }
                priv = enabler;
        } else {
-               struct lttng_event *event;
+               struct lttng_event_notifier *event_notifier;
 
                /*
-                * We tolerate no failure path after event creation. It
-                * will stay invariant for the rest of the session.
+                * We tolerate no failure path after event notifier creation.
+                * It will stay invariant for the rest of the session.
                 */
-               event = lttng_event_create(channel, event_param,
-                               NULL, NULL,
-                               event_param->instrumentation);
-               WARN_ON_ONCE(!event);
-               if (IS_ERR(event)) {
-                       ret = PTR_ERR(event);
-                       goto event_error;
+               event_notifier = lttng_event_notifier_create(NULL,
+                               event_notifier_param->event.token,
+                               event_notifier_param->error_counter_index,
+                               event_notifier_group,
+                               event_notifier_param, NULL,
+                               event_notifier_param->event.instrumentation);
+               WARN_ON_ONCE(!event_notifier);
+               if (IS_ERR(event_notifier)) {
+                       ret = PTR_ERR(event_notifier);
+                       goto event_notifier_error;
                }
-               priv = event;
+               priv = event_notifier;
        }
-       event_file->private_data = priv;
-       fd_install(event_fd, event_file);
-       return event_fd;
+       event_notifier_file->private_data = priv;
+       fd_install(event_notifier_fd, event_notifier_file);
+       return event_notifier_fd;
 
-event_error:
-       atomic_long_dec(&channel_file->f_count);
+event_notifier_error:
+       atomic_long_dec(&event_notifier_group_file->f_count);
 refcount_error:
-       fput(event_file);
+       fput(event_notifier_file);
 file_error:
-       put_unused_fd(event_fd);
+       put_unused_fd(event_notifier_fd);
+fd_error:
+inval_instr:
+       return ret;
+}
+
+static
+long lttng_abi_event_notifier_group_create_error_counter(
+               struct file *event_notifier_group_file,
+               const struct lttng_kernel_counter_conf *error_counter_conf)
+{
+       int counter_fd, ret;
+       char *counter_transport_name;
+       size_t counter_len;
+       struct lttng_counter *counter;
+       struct lttng_event_container *container;
+       struct file *counter_file;
+       struct lttng_event_notifier_group *event_notifier_group =
+                       (struct lttng_event_notifier_group *) event_notifier_group_file->private_data;
+
+       if (error_counter_conf->arithmetic != LTTNG_KERNEL_COUNTER_ARITHMETIC_MODULAR) {
+               printk(KERN_ERR "LTTng: event_notifier: Error counter of the wrong arithmetic type.\n");
+               return -EINVAL;
+       }
+
+       if (error_counter_conf->number_dimensions != 1) {
+               printk(KERN_ERR "LTTng: event_notifier: Error counter has more than one dimension.\n");
+               return -EINVAL;
+       }
+
+       switch (error_counter_conf->bitness) {
+       case LTTNG_KERNEL_COUNTER_BITNESS_64:
+               counter_transport_name = "counter-per-cpu-64-modular";
+               break;
+       case LTTNG_KERNEL_COUNTER_BITNESS_32:
+               counter_transport_name = "counter-per-cpu-32-modular";
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       counter_fd = lttng_get_unused_fd();
+       if (counter_fd < 0) {
+               ret = counter_fd;
+               goto fd_error;
+       }
+
+       counter_file = anon_inode_getfile("[lttng_counter]",
+                                      &lttng_counter_fops,
+                                      NULL, O_RDONLY);
+       if (IS_ERR(counter_file)) {
+               ret = PTR_ERR(counter_file);
+               goto file_error;
+       }
+
+       counter_len = error_counter_conf->dimensions[0].size;
+
+       if (!atomic_long_add_unless(&event_notifier_group_file->f_count, 1, LONG_MAX)) {
+               ret = -EOVERFLOW;
+               goto refcount_error;
+       }
+
+       ret = lttng_event_notifier_group_set_error_counter(event_notifier_group,
+                       counter_transport_name, counter_len);
+       if (ret)
+               goto counter_error;
+
+       counter = event_notifier_group->error_counter;
+       container = lttng_counter_get_event_container(counter);
+       container->file = counter_file;
+       counter->owner = event_notifier_group->file;
+       counter_file->private_data = counter;
+
+       fd_install(counter_fd, counter_file);
+
+       return counter_fd;
+
+counter_error:
+       atomic_long_dec(&event_notifier_group_file->f_count);
+refcount_error:
+       fput(counter_file);
+file_error:
+       put_unused_fd(counter_fd);
 fd_error:
        return ret;
 }
 
+static
+long lttng_event_notifier_group_ioctl(struct file *file, unsigned int cmd,
+               unsigned long arg)
+{
+       switch (cmd) {
+       case LTTNG_KERNEL_EVENT_NOTIFIER_GROUP_NOTIFICATION_FD:
+       {
+               return lttng_abi_open_event_notifier_group_stream(file);
+       }
+       case LTTNG_KERNEL_EVENT_NOTIFIER_CREATE:
+       {
+               struct lttng_kernel_event_notifier uevent_notifier_param;
+
+               if (copy_from_user(&uevent_notifier_param,
+                               (struct lttng_kernel_event_notifier __user *) arg,
+                               sizeof(uevent_notifier_param)))
+                       return -EFAULT;
+               return lttng_abi_create_event_notifier(file, &uevent_notifier_param);
+       }
+       case LTTNG_KERNEL_COUNTER:
+       {
+               struct lttng_kernel_counter_conf uerror_counter_conf;
+
+               if (copy_from_user(&uerror_counter_conf,
+                               (struct lttng_kernel_counter_conf __user *) arg,
+                               sizeof(uerror_counter_conf)))
+                       return -EFAULT;
+               return lttng_abi_event_notifier_group_create_error_counter(file,
+                               &uerror_counter_conf);
+       }
+       default:
+               return -ENOIOCTLCMD;
+       }
+       return 0;
+}
+
+static
+int lttng_event_notifier_group_release(struct inode *inode, struct file *file)
+{
+       struct lttng_event_notifier_group *event_notifier_group =
+                       file->private_data;
+
+       if (event_notifier_group)
+               lttng_event_notifier_group_destroy(event_notifier_group);
+       return 0;
+}
+
+static const struct file_operations lttng_event_notifier_group_fops = {
+       .owner = THIS_MODULE,
+       .release = lttng_event_notifier_group_release,
+       .unlocked_ioctl = lttng_event_notifier_group_ioctl,
+#ifdef CONFIG_COMPAT
+       .compat_ioctl = lttng_event_notifier_group_ioctl,
+#endif
+};
+
 /**
  *     lttng_channel_ioctl - lttng syscall through ioctl
  *
@@ -1380,6 +2472,7 @@ static
 long lttng_channel_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
        struct lttng_channel *channel = file->private_data;
+       struct lttng_event_container *container = lttng_channel_get_event_container(channel);
 
        switch (cmd) {
        case LTTNG_KERNEL_OLD_STREAM:
@@ -1442,7 +2535,7 @@ long lttng_channel_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                default:
                        break;
                }
-               ret = lttng_abi_create_event(file, uevent_param);
+               ret = lttng_abi_create_event(file, container, uevent_param, NULL);
 
 old_event_error_free_old_param:
                kfree(old_uevent_param);
@@ -1459,7 +2552,7 @@ old_event_end:
                                (struct lttng_kernel_event __user *) arg,
                                sizeof(uevent_param)))
                        return -EFAULT;
-               return lttng_abi_create_event(file, &uevent_param);
+               return lttng_abi_create_event(file, container, &uevent_param, NULL);
        }
        case LTTNG_KERNEL_OLD_CONTEXT:
        {
@@ -1502,7 +2595,7 @@ old_event_end:
 
                ret = lttng_abi_add_context(file,
                                ucontext_param,
-                               &channel->ctx, channel->session);
+                               &channel->ctx, container->session);
 
 old_ctx_error_free_old_param:
                kfree(old_ucontext_param);
@@ -1521,16 +2614,16 @@ old_ctx_end:
                        return -EFAULT;
                return lttng_abi_add_context(file,
                                &ucontext_param,
-                               &channel->ctx, channel->session);
+                               &channel->ctx, container->session);
        }
        case LTTNG_KERNEL_OLD_ENABLE:
        case LTTNG_KERNEL_ENABLE:
-               return lttng_channel_enable(channel);
+               return lttng_event_container_enable(container);
        case LTTNG_KERNEL_OLD_DISABLE:
        case LTTNG_KERNEL_DISABLE:
-               return lttng_channel_disable(channel);
+               return lttng_event_container_disable(container);
        case LTTNG_KERNEL_SYSCALL_MASK:
-               return lttng_channel_syscall_mask(channel,
+               return lttng_event_container_syscall_mask(container,
                        (struct lttng_kernel_syscall_mask __user *) arg);
        default:
                return -ENOIOCTLCMD;
@@ -1593,21 +2686,26 @@ unsigned int lttng_channel_poll(struct file *file, poll_table *wait)
 static
 int lttng_channel_release(struct inode *inode, struct file *file)
 {
-       struct lttng_channel *channel = file->private_data;
+       struct lttng_channel *chan = file->private_data;
 
-       if (channel)
-               fput(channel->session->file);
+       if (chan) {
+               struct lttng_event_container *container = lttng_channel_get_event_container(chan);
+
+               fput(container->session->file);
+       }
        return 0;
 }
 
 static
 int lttng_metadata_channel_release(struct inode *inode, struct file *file)
 {
-       struct lttng_channel *channel = file->private_data;
+       struct lttng_channel *chan = file->private_data;
+
+       if (chan) {
+               struct lttng_event_container *container = lttng_channel_get_event_container(chan);
 
-       if (channel) {
-               fput(channel->session->file);
-               lttng_metadata_channel_destroy(channel);
+               fput(container->session->file);
+               lttng_metadata_channel_destroy(chan);
        }
 
        return 0;
@@ -1651,7 +2749,7 @@ static
 long lttng_event_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
        struct lttng_event *event;
-       struct lttng_enabler *enabler;
+       struct lttng_event_enabler *event_enabler;
        enum lttng_event_type *evtype = file->private_data;
 
        switch (cmd) {
@@ -1672,8 +2770,8 @@ long lttng_event_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                        event = file->private_data;
                        return lttng_event_enable(event);
                case LTTNG_TYPE_ENABLER:
-                       enabler = file->private_data;
-                       return lttng_enabler_enable(enabler);
+                       event_enabler = file->private_data;
+                       return lttng_event_enabler_enable(event_enabler);
                default:
                        WARN_ON_ONCE(1);
                        return -ENOSYS;
@@ -1685,8 +2783,8 @@ long lttng_event_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                        event = file->private_data;
                        return lttng_event_disable(event);
                case LTTNG_TYPE_ENABLER:
-                       enabler = file->private_data;
-                       return lttng_enabler_disable(enabler);
+                       event_enabler = file->private_data;
+                       return lttng_event_enabler_disable(event_enabler);
                default:
                        WARN_ON_ONCE(1);
                        return -ENOSYS;
@@ -1697,8 +2795,9 @@ long lttng_event_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                        return -EINVAL;
                case LTTNG_TYPE_ENABLER:
                {
-                       enabler = file->private_data;
-                       return lttng_enabler_attach_bytecode(enabler,
+                       event_enabler = file->private_data;
+                       return lttng_event_enabler_attach_filter_bytecode(
+                               event_enabler,
                                (struct lttng_kernel_filter_bytecode __user *) arg);
                }
                default:
@@ -1726,7 +2825,7 @@ static
 int lttng_event_release(struct inode *inode, struct file *file)
 {
        struct lttng_event *event;
-       struct lttng_enabler *enabler;
+       struct lttng_event_enabler *event_enabler;
        enum lttng_event_type *evtype = file->private_data;
 
        if (!evtype)
@@ -1736,12 +2835,12 @@ int lttng_event_release(struct inode *inode, struct file *file)
        case LTTNG_TYPE_EVENT:
                event = file->private_data;
                if (event)
-                       fput(event->chan->file);
+                       fput(event->container->file);
                break;
        case LTTNG_TYPE_ENABLER:
-               enabler = file->private_data;
-               if (enabler)
-                       fput(enabler->chan->file);
+               event_enabler = file->private_data;
+               if (event_enabler)
+                       fput(event_enabler->container->file);
                break;
        default:
                WARN_ON_ONCE(1);
@@ -2018,7 +3117,7 @@ int __init lttng_abi_init(void)
                                        &lttng_proc_ops, NULL);
 
        if (!lttng_proc_dentry) {
-               printk(KERN_ERR "Error creating LTTng control file\n");
+               printk(KERN_ERR "LTTng: Error creating control file\n");
                ret = -ENOMEM;
                goto error;
        }
This page took 0.043104 seconds and 5 git commands to generate.