Rename "tsc" to "timestamp"
[lttng-modules.git] / src / lttng-abi.c
index cc45389403df8301fe72cd142d22615e315bacc3..caec803fe51e018f470ce03bb7003fbbaa73517f 100644 (file)
@@ -23,6 +23,7 @@
  *     - Takes instrumentation source specific arguments.
  */
 
+#include <asm/barrier.h>
 #include <linux/module.h>
 #include <linux/proc_fs.h>
 #include <linux/anon_inodes.h>
 #include <ringbuffer/vfs.h>
 #include <ringbuffer/backend.h>
 #include <ringbuffer/frontend.h>
+#include <wrapper/compiler_attributes.h>
 #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>
@@ -98,7 +98,7 @@ int lttng_abi_create_session(void)
        session = lttng_session_create();
        if (!session)
                return -ENOMEM;
-       session_fd = lttng_get_unused_fd();
+       session_fd = get_unused_fd_flags(0);
        if (session_fd < 0) {
                ret = session_fd;
                goto fd_error;
@@ -140,7 +140,7 @@ int lttng_abi_create_event_notifier_group(void)
        if (!event_notifier_group)
                return -ENOMEM;
 
-       event_notifier_group_fd = lttng_get_unused_fd();
+       event_notifier_group_fd = get_unused_fd_flags(0);
        if (event_notifier_group_fd < 0) {
                ret = event_notifier_group_fd;
                goto fd_error;
@@ -173,7 +173,7 @@ int lttng_abi_tracepoint_list(void)
        struct file *tracepoint_list_file;
        int file_fd, ret;
 
-       file_fd = lttng_get_unused_fd();
+       file_fd = get_unused_fd_flags(0);
        if (file_fd < 0) {
                ret = file_fd;
                goto fd_error;
@@ -213,7 +213,7 @@ int lttng_abi_syscall_list(void)
        struct file *syscall_list_file;
        int file_fd, ret;
 
-       file_fd = lttng_get_unused_fd();
+       file_fd = get_unused_fd_flags(0);
        if (file_fd < 0) {
                ret = file_fd;
                goto fd_error;
@@ -496,7 +496,7 @@ int lttng_abi_create_channel(struct file *session_file,
        int chan_fd;
        int ret = 0;
 
-       chan_fd = lttng_get_unused_fd();
+       chan_fd = get_unused_fd_flags(0);
        if (chan_fd < 0) {
                ret = chan_fd;
                goto fd_error;
@@ -549,7 +549,7 @@ int lttng_abi_create_channel(struct file *session_file,
         * We tolerate no failure path after channel creation. It will stay
         * invariant for the rest of the session.
         */
-       chan = lttng_channel_create(session, transport_name, NULL,
+       chan = lttng_channel_buffer_create(session, transport_name, NULL,
                                  chan_param->subbuf_size,
                                  chan_param->num_subbuf,
                                  chan_param->switch_timer_interval,
@@ -649,6 +649,8 @@ long lttng_counter_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                if (validate_zeroed_padding(local_counter_read.padding,
                                sizeof(local_counter_read.padding)))
                        return -EINVAL;
+               if (local_counter_read.index.number_dimensions > LTTNG_KERNEL_ABI_COUNTER_DIMENSION_MAX)
+                       return -EINVAL;
 
                /* Cast all indexes into size_t. */
                for (i = 0; i < local_counter_read.index.number_dimensions; i++)
@@ -684,6 +686,8 @@ long lttng_counter_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                if (validate_zeroed_padding(local_counter_aggregate.padding,
                                sizeof(local_counter_aggregate.padding)))
                        return -EINVAL;
+               if (local_counter_aggregate.index.number_dimensions > LTTNG_KERNEL_ABI_COUNTER_DIMENSION_MAX)
+                       return -EINVAL;
 
                /* Cast all indexes into size_t. */
                for (i = 0; i < local_counter_aggregate.index.number_dimensions; i++)
@@ -715,6 +719,8 @@ long lttng_counter_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                if (validate_zeroed_padding(local_counter_clear.padding,
                                sizeof(local_counter_clear.padding)))
                        return -EINVAL;
+               if (local_counter_clear.index.number_dimensions > LTTNG_KERNEL_ABI_COUNTER_DIMENSION_MAX)
+                       return -EINVAL;
 
                /* Cast all indexes into size_t. */
                for (i = 0; i < local_counter_clear.index.number_dimensions; i++)
@@ -723,7 +729,6 @@ long lttng_counter_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                return lttng_kernel_counter_clear(counter, indexes);
        }
        default:
-               WARN_ON_ONCE(1);
                return -ENOSYS;
        }
 }
@@ -1010,7 +1015,7 @@ ssize_t lttng_event_notifier_group_notif_read(struct file *filp, char __user *us
 
        /* Finish copy of previous record */
        if (*ppos != 0) {
-               if (read_count < count) {
+               if (count != 0) {
                        len = chan->iter.len_left;
                        read_offset = *ppos;
                        goto skip_get_next;
@@ -1090,7 +1095,8 @@ nodata:
        chan->iter.len_left = 0;
 
 put_record:
-       lib_ring_buffer_put_current_record(buf);
+       if (*ppos == 0)
+               lib_ring_buffer_put_current_record(buf);
        return read_count;
 }
 
@@ -1332,7 +1338,8 @@ long lttng_metadata_ring_buffer_ioctl(struct file *filp,
                 */
                return -ENOSYS;
        }
-       case LTTNG_KERNEL_ABI_RING_BUFFER_FLUSH_EMPTY:  /* Fall-through. */
+       case LTTNG_KERNEL_ABI_RING_BUFFER_FLUSH_EMPTY:
+               lttng_fallthrough;
        case LTTNG_KERNEL_ABI_RING_BUFFER_FLUSH:
        {
                struct lttng_metadata_stream *stream = filp->private_data;
@@ -1441,7 +1448,8 @@ long lttng_metadata_ring_buffer_compat_ioctl(struct file *filp,
                 */
                return -ENOSYS;
        }
-       case LTTNG_KERNEL_ABI_RING_BUFFER_FLUSH_EMPTY:  /* Fall-through. */
+       case LTTNG_KERNEL_ABI_RING_BUFFER_FLUSH_EMPTY:
+               lttng_fallthrough;
        case LTTNG_KERNEL_ABI_RING_BUFFER_FLUSH:
        {
                struct lttng_metadata_stream *stream = filp->private_data;
@@ -1594,7 +1602,7 @@ int lttng_abi_create_stream_fd(struct file *channel_file, void *stream_priv,
        int stream_fd, ret;
        struct file *stream_file;
 
-       stream_fd = lttng_get_unused_fd();
+       stream_fd = get_unused_fd_flags(0);
        if (stream_fd < 0) {
                ret = stream_fd;
                goto fd_error;
@@ -1758,8 +1766,10 @@ int lttng_abi_validate_event_param(struct lttng_kernel_abi_event *event_param)
        switch (event_param->instrumentation) {
        case LTTNG_KERNEL_ABI_SYSCALL:
                switch (event_param->u.syscall.entryexit) {
-               case LTTNG_KERNEL_ABI_SYSCALL_ENTRY:    /* Fall-through */
-               case LTTNG_KERNEL_ABI_SYSCALL_EXIT:             /* Fall-through */
+               case LTTNG_KERNEL_ABI_SYSCALL_ENTRY:
+                       lttng_fallthrough;
+               case LTTNG_KERNEL_ABI_SYSCALL_EXIT:
+                       lttng_fallthrough;
                case LTTNG_KERNEL_ABI_SYSCALL_ENTRYEXIT:
                        break;
                default:
@@ -1783,20 +1793,26 @@ int lttng_abi_validate_event_param(struct lttng_kernel_abi_event *event_param)
                switch (event_param->u.kretprobe.entryexit) {
                case LTTNG_KERNEL_ABI_SYSCALL_ENTRYEXIT:
                        break;
-               case LTTNG_KERNEL_ABI_SYSCALL_ENTRY:    /* Fall-through */
-               case LTTNG_KERNEL_ABI_SYSCALL_EXIT:             /* Fall-through */
+               case LTTNG_KERNEL_ABI_SYSCALL_ENTRY:
+                       lttng_fallthrough;
+               case LTTNG_KERNEL_ABI_SYSCALL_EXIT:
+                       lttng_fallthrough;
                default:
                        return -EINVAL;
                }
                break;
 
-       case LTTNG_KERNEL_ABI_TRACEPOINT:       /* Fall-through */
-       case LTTNG_KERNEL_ABI_KPROBE:   /* Fall-through */
+       case LTTNG_KERNEL_ABI_TRACEPOINT:
+               lttng_fallthrough;
+       case LTTNG_KERNEL_ABI_KPROBE:
+               lttng_fallthrough;
        case LTTNG_KERNEL_ABI_UPROBE:
                break;
 
-       case LTTNG_KERNEL_ABI_FUNCTION: /* Fall-through */
-       case LTTNG_KERNEL_ABI_NOOP:             /* Fall-through */
+       case LTTNG_KERNEL_ABI_FUNCTION:
+               lttng_fallthrough;
+       case LTTNG_KERNEL_ABI_NOOP:
+               lttng_fallthrough;
        default:
                return -EINVAL;
        }
@@ -1830,23 +1846,28 @@ int lttng_abi_create_event(struct file *channel_file,
        }
 
        switch (event_param->instrumentation) {
-       case LTTNG_KERNEL_ABI_TRACEPOINT:               /* Fall-through */
+       case LTTNG_KERNEL_ABI_TRACEPOINT:
+               lttng_fallthrough;
        case LTTNG_KERNEL_ABI_SYSCALL:
                fops = &lttng_event_recorder_enabler_fops;
                break;
-       case LTTNG_KERNEL_ABI_KPROBE:                   /* Fall-through */
-       case LTTNG_KERNEL_ABI_KRETPROBE:                /* Fall-through */
+       case LTTNG_KERNEL_ABI_KPROBE:
+               lttng_fallthrough;
+       case LTTNG_KERNEL_ABI_KRETPROBE:
+               lttng_fallthrough;
        case LTTNG_KERNEL_ABI_UPROBE:
                fops = &lttng_event_recorder_event_fops;
                break;
 
-       case LTTNG_KERNEL_ABI_FUNCTION:                 /* Fall-through */
-       case LTTNG_KERNEL_ABI_NOOP:                     /* Fall-through */
+       case LTTNG_KERNEL_ABI_FUNCTION:
+               lttng_fallthrough;
+       case LTTNG_KERNEL_ABI_NOOP:
+               lttng_fallthrough;
        default:
                return -EINVAL;
        }
 
-       event_fd = lttng_get_unused_fd();
+       event_fd = get_unused_fd_flags(0);
        if (event_fd < 0) {
                ret = event_fd;
                goto fd_error;
@@ -1867,49 +1888,63 @@ int lttng_abi_create_event(struct file *channel_file,
                goto event_error;
 
        switch (event_param->instrumentation) {
-       case LTTNG_KERNEL_ABI_TRACEPOINT:               /* Fall-through */
+       case LTTNG_KERNEL_ABI_TRACEPOINT:
+               lttng_fallthrough;
        case LTTNG_KERNEL_ABI_SYSCALL:
        {
-               struct lttng_event_enabler *event_enabler;
+               struct lttng_event_recorder_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_enabler = lttng_event_recorder_enabler_create(LTTNG_ENABLER_FORMAT_STAR_GLOB,
                                event_param, channel);
                } else {
-                       event_enabler = lttng_event_enabler_create(LTTNG_ENABLER_FORMAT_NAME,
+                       event_enabler = lttng_event_recorder_enabler_create(LTTNG_ENABLER_FORMAT_NAME,
                                event_param, channel);
                }
+               if (event_enabler)
+                       lttng_event_enabler_session_add(channel->parent.session, event_enabler);
                priv = event_enabler;
                break;
        }
 
-       case LTTNG_KERNEL_ABI_KPROBE:                   /* Fall-through */
-       case LTTNG_KERNEL_ABI_KRETPROBE:                /* Fall-through */
+       case LTTNG_KERNEL_ABI_KPROBE:
+               lttng_fallthrough;
+       case LTTNG_KERNEL_ABI_KRETPROBE:
+               lttng_fallthrough;
        case LTTNG_KERNEL_ABI_UPROBE:
        {
-               struct lttng_kernel_event_recorder *event;
+               struct lttng_kernel_event_common *event;
+               struct lttng_event_recorder_enabler *event_enabler;
 
+               event_enabler = lttng_event_recorder_enabler_create(LTTNG_ENABLER_FORMAT_NAME,
+                               event_param, channel);
+               if (!event_enabler) {
+                       ret = -ENOMEM;
+                       goto event_error;
+               }
                /*
                 * We tolerate no failure path after event creation. It
                 * will stay invariant for the rest of the session.
                 */
-               event = lttng_kernel_event_recorder_create(channel, event_param,
-                               NULL, event_param->instrumentation);
-               WARN_ON_ONCE(!event);
+               event = lttng_kernel_event_create(&event_enabler->parent, NULL);
+               WARN_ON_ONCE(IS_ERR(event));
+               lttng_event_enabler_destroy(&event_enabler->parent);
                if (IS_ERR(event)) {
                        ret = PTR_ERR(event);
                        goto event_error;
                }
-               priv = event;
+               priv = container_of(event, struct lttng_kernel_event_recorder, parent);
                break;
        }
 
-       case LTTNG_KERNEL_ABI_FUNCTION:                 /* Fall-through */
-       case LTTNG_KERNEL_ABI_NOOP:                     /* Fall-through */
+       case LTTNG_KERNEL_ABI_FUNCTION:
+               lttng_fallthrough;
+       case LTTNG_KERNEL_ABI_NOOP:
+               lttng_fallthrough;
        default:
                ret = -EINVAL;
                goto event_error;
@@ -1957,12 +1992,11 @@ long lttng_event_notifier_enabler_ioctl(struct file *file, unsigned int cmd, uns
 
        switch (cmd) {
        case LTTNG_KERNEL_ABI_ENABLE:
-               return lttng_event_notifier_enabler_enable(event_notifier_enabler);
+               return lttng_event_enabler_enable(&event_notifier_enabler->parent);
        case LTTNG_KERNEL_ABI_DISABLE:
-               return lttng_event_notifier_enabler_disable(event_notifier_enabler);
+               return lttng_event_enabler_disable(&event_notifier_enabler->parent);
        case LTTNG_KERNEL_ABI_FILTER:
-               return lttng_event_notifier_enabler_attach_filter_bytecode(
-                               event_notifier_enabler,
+               return lttng_event_enabler_attach_filter_bytecode(&event_notifier_enabler->parent,
                        (struct lttng_kernel_abi_filter_bytecode __user *) arg);
        case LTTNG_KERNEL_ABI_CAPTURE:
                return lttng_event_notifier_enabler_attach_capture_bytecode(
@@ -2043,18 +2077,23 @@ int lttng_abi_create_event_notifier(struct file *event_notifier_group_file,
        }
 
        switch (event_notifier_param->event.instrumentation) {
-       case LTTNG_KERNEL_ABI_TRACEPOINT:               /* Fall-through */
+       case LTTNG_KERNEL_ABI_TRACEPOINT:
+               lttng_fallthrough;
        case LTTNG_KERNEL_ABI_SYSCALL:
                fops = &lttng_event_notifier_enabler_fops;
                break;
-       case LTTNG_KERNEL_ABI_KPROBE:                   /* Fall-through */
-       case LTTNG_KERNEL_ABI_KRETPROBE:                /* Fall-through */
+       case LTTNG_KERNEL_ABI_KPROBE:
+               lttng_fallthrough;
+       case LTTNG_KERNEL_ABI_KRETPROBE:
+               lttng_fallthrough;
        case LTTNG_KERNEL_ABI_UPROBE:
                fops = &lttng_event_notifier_event_fops;
                break;
 
-       case LTTNG_KERNEL_ABI_FUNCTION:                 /* Fall-through */
-       case LTTNG_KERNEL_ABI_NOOP:                     /* Fall-through */
+       case LTTNG_KERNEL_ABI_FUNCTION:
+               lttng_fallthrough;
+       case LTTNG_KERNEL_ABI_NOOP:
+               lttng_fallthrough;
        default:
                ret = -EINVAL;
                goto inval_instr;
@@ -2062,7 +2101,7 @@ int lttng_abi_create_event_notifier(struct file *event_notifier_group_file,
 
        event_notifier_param->event.name[LTTNG_KERNEL_ABI_SYM_NAME_LEN - 1] = '\0';
 
-       event_notifier_fd = lttng_get_unused_fd();
+       event_notifier_fd = get_unused_fd_flags(0);
        if (event_notifier_fd < 0) {
                ret = event_notifier_fd;
                goto fd_error;
@@ -2086,7 +2125,8 @@ int lttng_abi_create_event_notifier(struct file *event_notifier_group_file,
                goto event_notifier_error;
 
        switch (event_notifier_param->event.instrumentation) {
-       case LTTNG_KERNEL_ABI_TRACEPOINT:               /* Fall-through */
+       case LTTNG_KERNEL_ABI_TRACEPOINT:
+               lttng_fallthrough;
        case LTTNG_KERNEL_ABI_SYSCALL:
        {
                struct lttng_event_notifier_enabler *enabler;
@@ -2097,46 +2137,51 @@ int lttng_abi_create_event_notifier(struct file *event_notifier_group_file,
                         * we create the special star globbing enabler.
                         */
                        enabler = lttng_event_notifier_enabler_create(
-                                       event_notifier_group,
                                        LTTNG_ENABLER_FORMAT_STAR_GLOB,
-                                       event_notifier_param);
+                                       event_notifier_param,
+                                       event_notifier_group);
                } else {
                        enabler = lttng_event_notifier_enabler_create(
-                                       event_notifier_group,
                                        LTTNG_ENABLER_FORMAT_NAME,
-                                       event_notifier_param);
+                                       event_notifier_param,
+                                       event_notifier_group);
                }
+               if (enabler)
+                       lttng_event_notifier_enabler_group_add(event_notifier_group, enabler);
                priv = enabler;
                break;
        }
 
-       case LTTNG_KERNEL_ABI_KPROBE:                   /* Fall-through */
-       case LTTNG_KERNEL_ABI_KRETPROBE:                /* Fall-through */
+       case LTTNG_KERNEL_ABI_KPROBE:
+               lttng_fallthrough;
+       case LTTNG_KERNEL_ABI_KRETPROBE:
+               lttng_fallthrough;
        case LTTNG_KERNEL_ABI_UPROBE:
        {
-               struct lttng_kernel_event_notifier *event_notifier;
+               struct lttng_kernel_event_common *event;
+               struct lttng_event_notifier_enabler *event_notifier_enabler;
 
-               /*
-                * We tolerate no failure path after event notifier creation.
-                * It will stay invariant for the rest of the session.
-                */
-               event_notifier = lttng_event_notifier_create(NULL,
-                               event_notifier_param->event.token,
-                               event_notifier_param->error_counter_index,
-                               event_notifier_group,
-                               event_notifier_param,
-                               event_notifier_param->event.instrumentation);
-               WARN_ON_ONCE(!event_notifier);
-               if (IS_ERR(event_notifier)) {
-                       ret = PTR_ERR(event_notifier);
+               event_notifier_enabler = lttng_event_notifier_enabler_create(LTTNG_ENABLER_FORMAT_NAME,
+                               event_notifier_param, event_notifier_group);
+               if (!event_notifier_enabler) {
+                       ret = -ENOMEM;
                        goto event_notifier_error;
                }
-               priv = event_notifier;
+               event = lttng_kernel_event_create(&event_notifier_enabler->parent, NULL);
+               WARN_ON_ONCE(IS_ERR(event));
+               lttng_event_enabler_destroy(&event_notifier_enabler->parent);
+               if (IS_ERR(event)) {
+                       ret = PTR_ERR(event);
+                       goto event_notifier_error;
+               }
+               priv = container_of(event, struct lttng_kernel_event_notifier, parent);
                break;
        }
 
-       case LTTNG_KERNEL_ABI_FUNCTION:                 /* Fall-through */
-       case LTTNG_KERNEL_ABI_NOOP:                     /* Fall-through */
+       case LTTNG_KERNEL_ABI_FUNCTION:
+               lttng_fallthrough;
+       case LTTNG_KERNEL_ABI_NOOP:
+               lttng_fallthrough;
        default:
                ret = -EINVAL;
                goto event_notifier_error;
@@ -2203,7 +2248,7 @@ long lttng_abi_event_notifier_group_create_error_counter(
                goto fd_error;
        }
 
-       counter_fd = lttng_get_unused_fd();
+       counter_fd = get_unused_fd_flags(0);
        if (counter_fd < 0) {
                ret = counter_fd;
                goto fd_error;
@@ -2237,7 +2282,7 @@ long lttng_abi_event_notifier_group_create_error_counter(
         * in record_error. Ensures the counter is created and the
         * error_counter_len is set before they are used.
         */
-       lttng_smp_store_release(&event_notifier_group->error_counter, counter);
+       smp_store_release(&event_notifier_group->error_counter, counter);
 
        counter->file = counter_file;
        counter->owner = event_notifier_group->file;
@@ -2488,12 +2533,12 @@ old_ctx_end:
        }
        case LTTNG_KERNEL_ABI_OLD_ENABLE:
        case LTTNG_KERNEL_ABI_ENABLE:
-               return lttng_channel_enable(channel);
+               return lttng_channel_enable(&channel->parent);
        case LTTNG_KERNEL_ABI_OLD_DISABLE:
        case LTTNG_KERNEL_ABI_DISABLE:
-               return lttng_channel_disable(channel);
+               return lttng_channel_disable(&channel->parent);
        case LTTNG_KERNEL_ABI_SYSCALL_MASK:
-               return lttng_channel_syscall_mask(channel,
+               return lttng_syscall_table_get_active_mask(&channel->priv->parent.syscall_table,
                        (struct lttng_kernel_abi_syscall_mask __user *) arg);
        default:
                return -ENOIOCTLCMD;
@@ -2660,7 +2705,7 @@ long lttng_event_recorder_event_ioctl(struct file *file, unsigned int cmd, unsig
 static
 long lttng_event_recorder_enabler_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
-       struct lttng_event_enabler *event_enabler = file->private_data;
+       struct lttng_event_recorder_enabler *event_enabler = file->private_data;
 
        switch (cmd) {
        case LTTNG_KERNEL_ABI_OLD_CONTEXT:
@@ -2675,13 +2720,12 @@ long lttng_event_recorder_enabler_ioctl(struct file *file, unsigned int cmd, uns
        }
        case LTTNG_KERNEL_ABI_OLD_ENABLE:
        case LTTNG_KERNEL_ABI_ENABLE:
-               return lttng_event_enabler_enable(event_enabler);
+               return lttng_event_enabler_enable(&event_enabler->parent);
        case LTTNG_KERNEL_ABI_OLD_DISABLE:
        case LTTNG_KERNEL_ABI_DISABLE:
-               return lttng_event_enabler_disable(event_enabler);
+               return lttng_event_enabler_disable(&event_enabler->parent);
        case LTTNG_KERNEL_ABI_FILTER:
-               return lttng_event_enabler_attach_filter_bytecode(
-                       event_enabler,
+               return lttng_event_enabler_attach_filter_bytecode(&event_enabler->parent,
                        (struct lttng_kernel_abi_filter_bytecode __user *) arg);
        case LTTNG_KERNEL_ABI_ADD_CALLSITE:
                return -EINVAL;
@@ -2703,7 +2747,7 @@ int lttng_event_recorder_event_release(struct inode *inode, struct file *file)
 static
 int lttng_event_recorder_enabler_release(struct inode *inode, struct file *file)
 {
-       struct lttng_event_enabler *event_enabler = file->private_data;
+       struct lttng_event_recorder_enabler *event_enabler = file->private_data;
 
        if (event_enabler)
                fput(event_enabler->chan->priv->parent.file);
This page took 0.031742 seconds and 4 git commands to generate.