X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Flttng-abi.c;h=cc45389403df8301fe72cd142d22615e315bacc3;hb=758c244b6ef2113a475213f072826419585cc75a;hp=4e0003be6f8f0aabb6042ec084102d459288b163;hpb=606828e401c405619a0c7249e8c7e3291cc1cb45;p=lttng-modules.git diff --git a/src/lttng-abi.c b/src/lttng-abi.c index 4e0003be..cc453894 100644 --- a/src/lttng-abi.c +++ b/src/lttng-abi.c @@ -65,7 +65,8 @@ 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; +static const struct file_operations lttng_event_recorder_event_fops; +static const struct file_operations lttng_event_recorder_enabler_fops; static struct file_operations lttng_stream_ring_buffer_file_operations; static int put_u64(uint64_t val, unsigned long arg); @@ -90,7 +91,7 @@ static int validate_zeroed_padding(char *p, size_t len) static int lttng_abi_create_session(void) { - struct lttng_session *session; + struct lttng_kernel_session *session; struct file *session_file; int session_fd, ret; @@ -109,7 +110,7 @@ int lttng_abi_create_session(void) ret = PTR_ERR(session_file); goto file_error; } - session->file = session_file; + session->priv->file = session_file; fd_install(session_fd, session_file); return session_fd; @@ -258,10 +259,10 @@ void lttng_abi_tracer_abi_version(struct lttng_kernel_abi_tracer_abi_version *v) static long lttng_abi_add_context(struct file *file, struct lttng_kernel_abi_context *context_param, - struct lttng_kernel_ctx **ctx, struct lttng_session *session) + struct lttng_kernel_ctx **ctx, struct lttng_kernel_session *session) { - if (session->been_active) + if (session->priv->been_active) return -EPERM; switch (context_param->ctx) { @@ -487,10 +488,10 @@ int lttng_abi_create_channel(struct file *session_file, struct lttng_kernel_abi_channel *chan_param, enum channel_type channel_type) { - struct lttng_session *session = session_file->private_data; + struct lttng_kernel_session *session = session_file->private_data; const struct file_operations *fops = NULL; const char *transport_name; - struct lttng_channel *chan; + struct lttng_kernel_channel_buffer *chan; struct file *chan_file; int chan_fd; int ret = 0; @@ -558,7 +559,7 @@ int lttng_abi_create_channel(struct file *session_file, ret = -EINVAL; goto chan_error; } - chan->file = chan_file; + chan->priv->parent.file = chan_file; chan_file->private_data = chan; fd_install(chan_fd, chan_file); @@ -575,7 +576,7 @@ fd_error: } static -int lttng_abi_session_set_name(struct lttng_session *session, +int lttng_abi_session_set_name(struct lttng_kernel_session *session, struct lttng_kernel_abi_session_name *name) { size_t len; @@ -587,12 +588,12 @@ int lttng_abi_session_set_name(struct lttng_session *session, return -EINVAL; } - strcpy(session->name, name->name); + strcpy(session->priv->name, name->name); return 0; } static -int lttng_abi_session_set_creation_time(struct lttng_session *session, +int lttng_abi_session_set_creation_time(struct lttng_kernel_session *session, struct lttng_kernel_abi_session_creation_time *time) { size_t len; @@ -604,7 +605,7 @@ int lttng_abi_session_set_creation_time(struct lttng_session *session, return -EINVAL; } - strcpy(session->creation_time, time->iso8601); + strcpy(session->priv->creation_time, time->iso8601); return 0; } @@ -788,10 +789,41 @@ enum tracker_type get_tracker_type(struct lttng_kernel_abi_tracker_args *tracker static long lttng_session_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { - struct lttng_session *session = file->private_data; + struct lttng_kernel_session *session = file->private_data; struct lttng_kernel_abi_channel chan_param; struct lttng_kernel_abi_old_channel old_chan_param; + /* + * Handle backward compatibility. OLD commands have wrong + * directions, replace them by the correct direction. + */ + switch (cmd) { + case LTTNG_KERNEL_ABI_OLD_SESSION_TRACK_PID: + cmd = LTTNG_KERNEL_ABI_SESSION_TRACK_PID; + break; + case LTTNG_KERNEL_ABI_OLD_SESSION_UNTRACK_PID: + cmd = LTTNG_KERNEL_ABI_SESSION_UNTRACK_PID; + break; + case LTTNG_KERNEL_ABI_OLD_SESSION_TRACK_ID: + cmd = LTTNG_KERNEL_ABI_SESSION_TRACK_ID; + break; + case LTTNG_KERNEL_ABI_OLD_SESSION_UNTRACK_ID: + cmd = LTTNG_KERNEL_ABI_SESSION_UNTRACK_ID; + break; + case LTTNG_KERNEL_ABI_OLD_SESSION_LIST_TRACKER_IDS: + cmd = LTTNG_KERNEL_ABI_SESSION_LIST_TRACKER_IDS; + break; + case LTTNG_KERNEL_ABI_OLD_SESSION_SET_NAME: + cmd = LTTNG_KERNEL_ABI_SESSION_SET_NAME; + break; + case LTTNG_KERNEL_ABI_OLD_SESSION_SET_CREATION_TIME: + cmd = LTTNG_KERNEL_ABI_SESSION_SET_CREATION_TIME; + break; + default: + /* Nothing to do. */ + break; + } + switch (cmd) { case LTTNG_KERNEL_ABI_OLD_CHANNEL: { @@ -942,7 +974,7 @@ long lttng_session_ioctl(struct file *file, unsigned int cmd, unsigned long arg) static int lttng_session_release(struct inode *inode, struct file *file) { - struct lttng_session *session = file->private_data; + struct lttng_kernel_session *session = file->private_data; if (session) lttng_session_destroy(session); @@ -967,8 +999,8 @@ ssize_t lttng_event_notifier_group_notif_read(struct file *filp, char __user *us 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; + struct lttng_kernel_ring_buffer_channel *chan = event_notifier_group->chan; + struct lttng_kernel_ring_buffer *buf = event_notifier_group->buf; ssize_t read_count = 0, len; size_t read_offset; @@ -1073,9 +1105,9 @@ unsigned int lttng_event_notifier_group_notif_poll(struct file *filp, { 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; + struct lttng_kernel_ring_buffer_channel *chan = event_notifier_group->chan; + struct lttng_kernel_ring_buffer *buf = event_notifier_group->buf; + const struct lttng_kernel_ring_buffer_config *config = &chan->backend.config; int finalized, disabled; unsigned long consumed, offset; size_t subbuffer_header_size = config->cb.subbuffer_header_size(); @@ -1147,7 +1179,7 @@ retry: static int lttng_event_notifier_group_notif_open(struct inode *inode, struct file *file) { struct lttng_event_notifier_group *event_notifier_group = inode->i_private; - struct lib_ring_buffer *buf = event_notifier_group->buf; + struct lttng_kernel_ring_buffer *buf = event_notifier_group->buf; file->private_data = event_notifier_group; return lib_ring_buffer_open(inode, file, buf); @@ -1163,7 +1195,7 @@ static int lttng_event_notifier_group_notif_open(struct inode *inode, struct fil 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; + struct lttng_kernel_ring_buffer *buf = event_notifier_group->buf; int ret; ret = lib_ring_buffer_release(inode, file, buf); @@ -1193,7 +1225,7 @@ unsigned int lttng_metadata_ring_buffer_poll(struct file *filp, poll_table *wait) { struct lttng_metadata_stream *stream = filp->private_data; - struct lib_ring_buffer *buf = stream->priv; + struct lttng_kernel_ring_buffer *buf = stream->priv; int finalized; unsigned int mask = 0; @@ -1269,7 +1301,7 @@ long lttng_metadata_ring_buffer_ioctl(struct file *filp, { int ret; struct lttng_metadata_stream *stream = filp->private_data; - struct lib_ring_buffer *buf = stream->priv; + struct lttng_kernel_ring_buffer *buf = stream->priv; unsigned int rb_cmd; bool coherent; @@ -1282,8 +1314,8 @@ long lttng_metadata_ring_buffer_ioctl(struct file *filp, case LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF: { struct lttng_metadata_stream *stream = filp->private_data; - struct lib_ring_buffer *buf = stream->priv; - struct channel *chan = buf->backend.chan; + struct lttng_kernel_ring_buffer *buf = stream->priv; + struct lttng_kernel_ring_buffer_channel *chan = buf->backend.chan; ret = lttng_metadata_output_channel(stream, chan, NULL); if (ret > 0) { @@ -1304,8 +1336,8 @@ long lttng_metadata_ring_buffer_ioctl(struct file *filp, case LTTNG_KERNEL_ABI_RING_BUFFER_FLUSH: { struct lttng_metadata_stream *stream = filp->private_data; - struct lib_ring_buffer *buf = stream->priv; - struct channel *chan = buf->backend.chan; + struct lttng_kernel_ring_buffer *buf = stream->priv; + struct lttng_kernel_ring_buffer_channel *chan = buf->backend.chan; /* * Before doing the actual ring buffer flush, write up to one @@ -1331,8 +1363,8 @@ long lttng_metadata_ring_buffer_ioctl(struct file *filp, case LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK: { struct lttng_metadata_stream *stream = filp->private_data; - struct lib_ring_buffer *buf = stream->priv; - struct channel *chan = buf->backend.chan; + struct lttng_kernel_ring_buffer *buf = stream->priv; + struct lttng_kernel_ring_buffer_channel *chan = buf->backend.chan; ret = lttng_metadata_output_channel(stream, chan, &coherent); if (ret > 0) { @@ -1378,7 +1410,7 @@ long lttng_metadata_ring_buffer_compat_ioctl(struct file *filp, { int ret; struct lttng_metadata_stream *stream = filp->private_data; - struct lib_ring_buffer *buf = stream->priv; + struct lttng_kernel_ring_buffer *buf = stream->priv; unsigned int rb_cmd; bool coherent; @@ -1391,8 +1423,8 @@ long lttng_metadata_ring_buffer_compat_ioctl(struct file *filp, case LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF: { struct lttng_metadata_stream *stream = filp->private_data; - struct lib_ring_buffer *buf = stream->priv; - struct channel *chan = buf->backend.chan; + struct lttng_kernel_ring_buffer *buf = stream->priv; + struct lttng_kernel_ring_buffer_channel *chan = buf->backend.chan; ret = lttng_metadata_output_channel(stream, chan, NULL); if (ret > 0) { @@ -1413,8 +1445,8 @@ long lttng_metadata_ring_buffer_compat_ioctl(struct file *filp, case LTTNG_KERNEL_ABI_RING_BUFFER_FLUSH: { struct lttng_metadata_stream *stream = filp->private_data; - struct lib_ring_buffer *buf = stream->priv; - struct channel *chan = buf->backend.chan; + struct lttng_kernel_ring_buffer *buf = stream->priv; + struct lttng_kernel_ring_buffer_channel *chan = buf->backend.chan; /* * Before doing the actual ring buffer flush, write up to one @@ -1440,8 +1472,8 @@ long lttng_metadata_ring_buffer_compat_ioctl(struct file *filp, case LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK: { struct lttng_metadata_stream *stream = filp->private_data; - struct lib_ring_buffer *buf = stream->priv; - struct channel *chan = buf->backend.chan; + struct lttng_kernel_ring_buffer *buf = stream->priv; + struct lttng_kernel_ring_buffer_channel *chan = buf->backend.chan; ret = lttng_metadata_output_channel(stream, chan, &coherent); if (ret > 0) { @@ -1489,7 +1521,7 @@ static int lttng_metadata_ring_buffer_open(struct inode *inode, struct file *file) { struct lttng_metadata_stream *stream = inode->i_private; - struct lib_ring_buffer *buf = stream->priv; + struct lttng_kernel_ring_buffer *buf = stream->priv; file->private_data = buf; /* @@ -1507,7 +1539,7 @@ static int lttng_metadata_ring_buffer_release(struct inode *inode, struct file *file) { struct lttng_metadata_stream *stream = file->private_data; - struct lib_ring_buffer *buf = stream->priv; + struct lttng_kernel_ring_buffer *buf = stream->priv; mutex_lock(&stream->metadata_cache->lock); list_del(&stream->list); @@ -1524,7 +1556,7 @@ ssize_t lttng_metadata_ring_buffer_splice_read(struct file *in, loff_t *ppos, unsigned int flags) { struct lttng_metadata_stream *stream = in->private_data; - struct lib_ring_buffer *buf = stream->priv; + struct lttng_kernel_ring_buffer *buf = stream->priv; return lib_ring_buffer_splice_read(in, ppos, pipe, len, flags, buf); @@ -1535,7 +1567,7 @@ int lttng_metadata_ring_buffer_mmap(struct file *filp, struct vm_area_struct *vma) { struct lttng_metadata_stream *stream = filp->private_data; - struct lib_ring_buffer *buf = stream->priv; + struct lttng_kernel_ring_buffer *buf = stream->priv; return lib_ring_buffer_mmap(filp, vma, buf); } @@ -1595,12 +1627,12 @@ fd_error: static int lttng_abi_open_stream(struct file *channel_file) { - struct lttng_channel *channel = channel_file->private_data; - struct lib_ring_buffer *buf; + struct lttng_kernel_channel_buffer *channel = channel_file->private_data; + struct lttng_kernel_ring_buffer *buf; int ret; void *stream_priv; - buf = channel->ops->buffer_read_open(channel->chan); + buf = channel->ops->priv->buffer_read_open(channel->priv->rb_chan); if (!buf) return -ENOENT; @@ -1614,21 +1646,21 @@ int lttng_abi_open_stream(struct file *channel_file) return ret; fd_error: - channel->ops->buffer_read_close(buf); + channel->ops->priv->buffer_read_close(buf); return ret; } static int lttng_abi_open_metadata_stream(struct file *channel_file) { - struct lttng_channel *channel = channel_file->private_data; - struct lttng_session *session = channel->session; - struct lib_ring_buffer *buf; + struct lttng_kernel_channel_buffer *channel = channel_file->private_data; + struct lttng_kernel_session *session = channel->parent.session; + struct lttng_kernel_ring_buffer *buf; int ret; struct lttng_metadata_stream *metadata_stream; void *stream_priv; - buf = channel->ops->buffer_read_open(channel->chan); + buf = channel->ops->priv->buffer_read_open(channel->priv->rb_chan); if (!buf) return -ENOENT; @@ -1638,11 +1670,11 @@ int lttng_abi_open_metadata_stream(struct file *channel_file) ret = -ENOMEM; goto nomem; } - metadata_stream->metadata_cache = session->metadata_cache; + metadata_stream->metadata_cache = session->priv->metadata_cache; init_waitqueue_head(&metadata_stream->read_wait); metadata_stream->priv = buf; stream_priv = metadata_stream; - metadata_stream->transport = channel->transport; + metadata_stream->transport = channel->priv->transport; /* Initial state is an empty metadata, considered as incoherent. */ metadata_stream->coherent = false; @@ -1656,7 +1688,7 @@ int lttng_abi_open_metadata_stream(struct file *channel_file) goto notransport; } - if (!lttng_kref_get(&session->metadata_cache->refcount)) { + if (!lttng_kref_get(&session->priv->metadata_cache->refcount)) { ret = -EOVERFLOW; goto kref_error; } @@ -1667,20 +1699,20 @@ int lttng_abi_open_metadata_stream(struct file *channel_file) if (ret < 0) goto fd_error; - mutex_lock(&session->metadata_cache->lock); + mutex_lock(&session->priv->metadata_cache->lock); list_add(&metadata_stream->list, - &session->metadata_cache->metadata_stream); - mutex_unlock(&session->metadata_cache->lock); + &session->priv->metadata_cache->metadata_stream); + mutex_unlock(&session->priv->metadata_cache->lock); return ret; fd_error: - kref_put(&session->metadata_cache->refcount, metadata_cache_destroy); + kref_put(&session->priv->metadata_cache->refcount, metadata_cache_destroy); kref_error: module_put(metadata_stream->transport->owner); notransport: kfree(metadata_stream); nomem: - channel->ops->buffer_read_close(buf); + channel->ops->priv->buffer_read_close(buf); return ret; } @@ -1688,12 +1720,12 @@ static int lttng_abi_open_event_notifier_group_stream(struct file *notif_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; + struct lttng_kernel_ring_buffer_channel *chan = event_notifier_group->chan; + struct lttng_kernel_ring_buffer *buf; int ret; void *stream_priv; - buf = event_notifier_group->ops->buffer_read_open(chan); + buf = event_notifier_group->ops->priv->buffer_read_open(chan); if (!buf) return -ENOENT; @@ -1715,7 +1747,7 @@ int lttng_abi_open_event_notifier_group_stream(struct file *notif_file) fd_error: atomic_long_dec(¬if_file->f_count); refcount_error: - event_notifier_group->ops->buffer_read_close(buf); + event_notifier_group->ops->priv->buffer_read_close(buf); return ret; } @@ -1775,7 +1807,8 @@ static int lttng_abi_create_event(struct file *channel_file, struct lttng_kernel_abi_event *event_param) { - struct lttng_channel *channel = channel_file->private_data; + const struct file_operations *fops; + struct lttng_kernel_channel_buffer *channel = channel_file->private_data; int event_fd, ret; struct file *event_file; void *priv; @@ -1795,14 +1828,31 @@ int lttng_abi_create_event(struct file *channel_file, default: break; } + + switch (event_param->instrumentation) { + case LTTNG_KERNEL_ABI_TRACEPOINT: /* Fall-through */ + case LTTNG_KERNEL_ABI_SYSCALL: + fops = <tng_event_recorder_enabler_fops; + break; + case LTTNG_KERNEL_ABI_KPROBE: /* Fall-through */ + case LTTNG_KERNEL_ABI_KRETPROBE: /* Fall-through */ + case LTTNG_KERNEL_ABI_UPROBE: + fops = <tng_event_recorder_event_fops; + break; + + case LTTNG_KERNEL_ABI_FUNCTION: /* Fall-through */ + case LTTNG_KERNEL_ABI_NOOP: /* Fall-through */ + default: + return -EINVAL; + } + event_fd = lttng_get_unused_fd(); if (event_fd < 0) { ret = event_fd; goto fd_error; } event_file = anon_inode_getfile("[lttng_event]", - <tng_event_fops, - NULL, O_RDWR); + fops, NULL, O_RDWR); if (IS_ERR(event_file)) { ret = PTR_ERR(event_file); goto file_error; @@ -1837,19 +1887,18 @@ int lttng_abi_create_event(struct file *channel_file, break; } - case LTTNG_KERNEL_ABI_KPROBE: /* Fall-through */ + case LTTNG_KERNEL_ABI_KPROBE: /* Fall-through */ case LTTNG_KERNEL_ABI_KRETPROBE: /* Fall-through */ case LTTNG_KERNEL_ABI_UPROBE: { - struct lttng_event *event; + struct lttng_kernel_event_recorder *event; /* * We tolerate no failure path after event creation. It * will stay invariant for the rest of the session. */ - event = lttng_event_create(channel, event_param, - NULL, NULL, - event_param->instrumentation); + event = lttng_kernel_event_recorder_create(channel, event_param, + NULL, event_param->instrumentation); WARN_ON_ONCE(!event); if (IS_ERR(event)) { ret = PTR_ERR(event); @@ -1859,7 +1908,7 @@ int lttng_abi_create_event(struct file *channel_file, break; } - case LTTNG_KERNEL_ABI_FUNCTION: /* Fall-through */ + case LTTNG_KERNEL_ABI_FUNCTION: /* Fall-through */ case LTTNG_KERNEL_ABI_NOOP: /* Fall-through */ default: ret = -EINVAL; @@ -1880,116 +1929,87 @@ fd_error: } static -long lttng_event_notifier_ioctl(struct file *file, unsigned int cmd, unsigned long arg) +long lttng_event_notifier_event_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; + struct lttng_kernel_event_notifier *event_notifier = file->private_data; switch (cmd) { case LTTNG_KERNEL_ABI_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; - } + return lttng_event_enable(&event_notifier->parent); case LTTNG_KERNEL_ABI_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; - } + return lttng_event_disable(&event_notifier->parent); case LTTNG_KERNEL_ABI_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_abi_filter_bytecode __user *) arg); - default: - WARN_ON_ONCE(1); - return -ENOSYS; - } - + return -EINVAL; case LTTNG_KERNEL_ABI_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_abi_capture_bytecode __user *) arg); - default: - WARN_ON_ONCE(1); - return -ENOSYS; - } + return -EINVAL; case LTTNG_KERNEL_ABI_ADD_CALLSITE: - switch (*evtype) { - case LTTNG_TYPE_EVENT: - event_notifier = file->private_data; - return lttng_event_notifier_add_callsite(event_notifier, - (struct lttng_kernel_abi_event_callsite __user *) arg); - case LTTNG_TYPE_ENABLER: - return -EINVAL; - default: - WARN_ON_ONCE(1); - return -ENOSYS; - } + return lttng_event_add_callsite(&event_notifier->parent, + (struct lttng_kernel_abi_event_callsite __user *) arg); default: return -ENOIOCTLCMD; } } static -int lttng_event_notifier_release(struct inode *inode, struct file *file) +long lttng_event_notifier_enabler_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; - - if (!evtype) - return 0; + struct lttng_event_notifier_enabler *event_notifier_enabler = file->private_data; - 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; + switch (cmd) { + case LTTNG_KERNEL_ABI_ENABLE: + return lttng_event_notifier_enabler_enable(event_notifier_enabler); + case LTTNG_KERNEL_ABI_DISABLE: + return lttng_event_notifier_enabler_disable(event_notifier_enabler); + case LTTNG_KERNEL_ABI_FILTER: + return lttng_event_notifier_enabler_attach_filter_bytecode( + event_notifier_enabler, + (struct lttng_kernel_abi_filter_bytecode __user *) arg); + case LTTNG_KERNEL_ABI_CAPTURE: + return lttng_event_notifier_enabler_attach_capture_bytecode( + event_notifier_enabler, + (struct lttng_kernel_abi_capture_bytecode __user *) arg); + case LTTNG_KERNEL_ABI_ADD_CALLSITE: + return -EINVAL; default: - WARN_ON_ONCE(1); - break; + return -ENOIOCTLCMD; } +} + +static +int lttng_event_notifier_event_release(struct inode *inode, struct file *file) +{ + struct lttng_kernel_event_notifier *event_notifier = file->private_data; + + if (event_notifier) + fput(event_notifier->priv->group->file); + return 0; +} +static +int lttng_event_notifier_enabler_release(struct inode *inode, struct file *file) +{ + struct lttng_event_notifier_enabler *event_notifier_enabler = file->private_data; + + if (event_notifier_enabler) + fput(event_notifier_enabler->group->file); return 0; } -static const struct file_operations lttng_event_notifier_fops = { +static const struct file_operations lttng_event_notifier_event_fops = { + .owner = THIS_MODULE, + .release = lttng_event_notifier_event_release, + .unlocked_ioctl = lttng_event_notifier_event_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = lttng_event_notifier_event_ioctl, +#endif +}; + +static const struct file_operations lttng_event_notifier_enabler_fops = { .owner = THIS_MODULE, - .release = lttng_event_notifier_release, - .unlocked_ioctl = lttng_event_notifier_ioctl, + .release = lttng_event_notifier_enabler_release, + .unlocked_ioctl = lttng_event_notifier_enabler_ioctl, #ifdef CONFIG_COMPAT - .compat_ioctl = lttng_event_notifier_ioctl, + .compat_ioctl = lttng_event_notifier_enabler_ioctl, #endif }; @@ -1999,6 +2019,7 @@ int lttng_abi_create_event_notifier(struct file *event_notifier_group_file, { struct lttng_event_notifier_group *event_notifier_group = event_notifier_group_file->private_data; + const struct file_operations *fops; int event_notifier_fd, ret; struct file *event_notifier_file; void *priv; @@ -2021,6 +2042,24 @@ int lttng_abi_create_event_notifier(struct file *event_notifier_group_file, goto inval_instr; } + switch (event_notifier_param->event.instrumentation) { + case LTTNG_KERNEL_ABI_TRACEPOINT: /* Fall-through */ + case LTTNG_KERNEL_ABI_SYSCALL: + fops = <tng_event_notifier_enabler_fops; + break; + case LTTNG_KERNEL_ABI_KPROBE: /* Fall-through */ + case LTTNG_KERNEL_ABI_KRETPROBE: /* Fall-through */ + case LTTNG_KERNEL_ABI_UPROBE: + fops = <tng_event_notifier_event_fops; + break; + + case LTTNG_KERNEL_ABI_FUNCTION: /* Fall-through */ + case LTTNG_KERNEL_ABI_NOOP: /* Fall-through */ + default: + ret = -EINVAL; + goto inval_instr; + } + event_notifier_param->event.name[LTTNG_KERNEL_ABI_SYM_NAME_LEN - 1] = '\0'; event_notifier_fd = lttng_get_unused_fd(); @@ -2030,8 +2069,7 @@ int lttng_abi_create_event_notifier(struct file *event_notifier_group_file, } event_notifier_file = anon_inode_getfile("[lttng_event_notifier]", - <tng_event_notifier_fops, - NULL, O_RDWR); + fops, NULL, O_RDWR); if (IS_ERR(event_notifier_file)) { ret = PTR_ERR(event_notifier_file); goto file_error; @@ -2072,11 +2110,11 @@ int lttng_abi_create_event_notifier(struct file *event_notifier_group_file, break; } - case LTTNG_KERNEL_ABI_KPROBE: /* Fall-through */ + case LTTNG_KERNEL_ABI_KPROBE: /* Fall-through */ case LTTNG_KERNEL_ABI_KRETPROBE: /* Fall-through */ case LTTNG_KERNEL_ABI_UPROBE: { - struct lttng_event_notifier *event_notifier; + struct lttng_kernel_event_notifier *event_notifier; /* * We tolerate no failure path after event notifier creation. @@ -2086,7 +2124,7 @@ int lttng_abi_create_event_notifier(struct file *event_notifier_group_file, event_notifier_param->event.token, event_notifier_param->error_counter_index, event_notifier_group, - event_notifier_param, NULL, + event_notifier_param, event_notifier_param->event.instrumentation); WARN_ON_ONCE(!event_notifier); if (IS_ERR(event_notifier)) { @@ -2097,7 +2135,7 @@ int lttng_abi_create_event_notifier(struct file *event_notifier_group_file, break; } - case LTTNG_KERNEL_ABI_FUNCTION: /* Fall-through */ + case LTTNG_KERNEL_ABI_FUNCTION: /* Fall-through */ case LTTNG_KERNEL_ABI_NOOP: /* Fall-through */ default: ret = -EINVAL; @@ -2304,7 +2342,7 @@ static const struct file_operations lttng_event_notifier_group_fops = { static long lttng_channel_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { - struct lttng_channel *channel = file->private_data; + struct lttng_kernel_channel_buffer *channel = file->private_data; switch (cmd) { case LTTNG_KERNEL_ABI_OLD_STREAM: @@ -2427,7 +2465,7 @@ old_event_end: ret = lttng_abi_add_context(file, ucontext_param, - &channel->ctx, channel->session); + &channel->priv->ctx, channel->parent.session); old_ctx_error_free_old_param: kfree(old_ucontext_param); @@ -2446,7 +2484,7 @@ old_ctx_end: return -EFAULT; return lttng_abi_add_context(file, &ucontext_param, - &channel->ctx, channel->session); + &channel->priv->ctx, channel->parent.session); } case LTTNG_KERNEL_ABI_OLD_ENABLE: case LTTNG_KERNEL_ABI_ENABLE: @@ -2495,19 +2533,19 @@ long lttng_metadata_ioctl(struct file *file, unsigned int cmd, unsigned long arg */ unsigned int lttng_channel_poll(struct file *file, poll_table *wait) { - struct lttng_channel *channel = file->private_data; + struct lttng_kernel_channel_buffer *channel = file->private_data; unsigned int mask = 0; if (file->f_mode & FMODE_READ) { poll_wait_set_exclusive(wait); - poll_wait(file, channel->ops->get_hp_wait_queue(channel->chan), + poll_wait(file, channel->ops->priv->get_hp_wait_queue(channel->priv->rb_chan), wait); - if (channel->ops->is_disabled(channel->chan)) + if (channel->ops->priv->is_disabled(channel->priv->rb_chan)) return POLLERR; - if (channel->ops->is_finalized(channel->chan)) + if (channel->ops->priv->is_finalized(channel->priv->rb_chan)) return POLLHUP; - if (channel->ops->buffer_has_read_closed_stream(channel->chan)) + if (channel->ops->priv->buffer_has_read_closed_stream(channel->priv->rb_chan)) return POLLIN | POLLRDNORM; return 0; } @@ -2518,20 +2556,20 @@ 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_kernel_channel_buffer *channel = file->private_data; if (channel) - fput(channel->session->file); + fput(channel->parent.session->priv->file); return 0; } static int lttng_metadata_channel_release(struct inode *inode, struct file *file) { - struct lttng_channel *channel = file->private_data; + struct lttng_kernel_channel_buffer *channel = file->private_data; if (channel) { - fput(channel->session->file); + fput(channel->parent.session->priv->file); lttng_metadata_channel_destroy(channel); } @@ -2558,7 +2596,7 @@ static const struct file_operations lttng_metadata_fops = { }; /** - * lttng_event_ioctl - lttng syscall through ioctl + * lttng_event_recorder_event_ioctl - lttng syscall through ioctl * * @file: the file * @cmd: the command @@ -2573,11 +2611,9 @@ static const struct file_operations lttng_metadata_fops = { * Disable recording for this event (strong disable) */ static -long lttng_event_ioctl(struct file *file, unsigned int cmd, unsigned long arg) +long lttng_event_recorder_event_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { - struct lttng_event *event; - struct lttng_event_enabler *event_enabler; - enum lttng_event_type *evtype = file->private_data; + struct lttng_kernel_event_recorder *event_recorder = file->private_data; switch (cmd) { case LTTNG_KERNEL_ABI_OLD_CONTEXT: @@ -2592,98 +2628,103 @@ long lttng_event_ioctl(struct file *file, unsigned int cmd, unsigned long arg) } case LTTNG_KERNEL_ABI_OLD_ENABLE: case LTTNG_KERNEL_ABI_ENABLE: - switch (*evtype) { - case LTTNG_TYPE_EVENT: - event = file->private_data; - return lttng_event_enable(event); - case LTTNG_TYPE_ENABLER: - event_enabler = file->private_data; - return lttng_event_enabler_enable(event_enabler); - default: - WARN_ON_ONCE(1); - return -ENOSYS; - } + return lttng_event_enable(&event_recorder->parent); case LTTNG_KERNEL_ABI_OLD_DISABLE: case LTTNG_KERNEL_ABI_DISABLE: - switch (*evtype) { - case LTTNG_TYPE_EVENT: - event = file->private_data; - return lttng_event_disable(event); - case LTTNG_TYPE_ENABLER: - event_enabler = file->private_data; - return lttng_event_enabler_disable(event_enabler); - default: - WARN_ON_ONCE(1); - return -ENOSYS; - } + return lttng_event_disable(&event_recorder->parent); case LTTNG_KERNEL_ABI_FILTER: - switch (*evtype) { - case LTTNG_TYPE_EVENT: - return -EINVAL; - case LTTNG_TYPE_ENABLER: - { - event_enabler = file->private_data; - return lttng_event_enabler_attach_filter_bytecode( - event_enabler, - (struct lttng_kernel_abi_filter_bytecode __user *) arg); - } - default: - WARN_ON_ONCE(1); - return -ENOSYS; - } + return -EINVAL; case LTTNG_KERNEL_ABI_ADD_CALLSITE: - switch (*evtype) { - case LTTNG_TYPE_EVENT: - event = file->private_data; - return lttng_event_add_callsite(event, - (struct lttng_kernel_abi_event_callsite __user *) arg); - case LTTNG_TYPE_ENABLER: - return -EINVAL; - default: - WARN_ON_ONCE(1); - return -ENOSYS; - } + return lttng_event_add_callsite(&event_recorder->parent, + (struct lttng_kernel_abi_event_callsite __user *) arg); default: return -ENOIOCTLCMD; } } +/** + * lttng_event_recorder_enabler_ioctl - lttng syscall through ioctl + * + * @file: the file + * @cmd: the command + * @arg: command arg + * + * This ioctl implements lttng commands: + * LTTNG_KERNEL_ABI_CONTEXT + * Prepend a context field to each record of this event + * LTTNG_KERNEL_ABI_ENABLE + * Enable recording for this event (weak enable) + * LTTNG_KERNEL_ABI_DISABLE + * Disable recording for this event (strong disable) + */ static -int lttng_event_release(struct inode *inode, struct file *file) +long lttng_event_recorder_enabler_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { - struct lttng_event *event; - struct lttng_event_enabler *event_enabler; - enum lttng_event_type *evtype = file->private_data; - - if (!evtype) - return 0; + struct lttng_event_enabler *event_enabler = file->private_data; - switch (*evtype) { - case LTTNG_TYPE_EVENT: - event = file->private_data; - if (event) - fput(event->chan->file); - break; - case LTTNG_TYPE_ENABLER: - event_enabler = file->private_data; - if (event_enabler) - fput(event_enabler->chan->file); - break; + switch (cmd) { + case LTTNG_KERNEL_ABI_OLD_CONTEXT: + { + /* Not implemented */ + return -ENOSYS; + } + case LTTNG_KERNEL_ABI_CONTEXT: + { + /* Not implemented */ + return -ENOSYS; + } + case LTTNG_KERNEL_ABI_OLD_ENABLE: + case LTTNG_KERNEL_ABI_ENABLE: + return lttng_event_enabler_enable(event_enabler); + case LTTNG_KERNEL_ABI_OLD_DISABLE: + case LTTNG_KERNEL_ABI_DISABLE: + return lttng_event_enabler_disable(event_enabler); + case LTTNG_KERNEL_ABI_FILTER: + return lttng_event_enabler_attach_filter_bytecode( + event_enabler, + (struct lttng_kernel_abi_filter_bytecode __user *) arg); + case LTTNG_KERNEL_ABI_ADD_CALLSITE: + return -EINVAL; default: - WARN_ON_ONCE(1); - break; + return -ENOIOCTLCMD; } +} + +static +int lttng_event_recorder_event_release(struct inode *inode, struct file *file) +{ + struct lttng_kernel_event_recorder *event = file->private_data; + + if (event) + fput(event->chan->priv->parent.file); + return 0; +} + +static +int lttng_event_recorder_enabler_release(struct inode *inode, struct file *file) +{ + struct lttng_event_enabler *event_enabler = file->private_data; + if (event_enabler) + fput(event_enabler->chan->priv->parent.file); return 0; } -/* TODO: filter control ioctl */ -static const struct file_operations lttng_event_fops = { +static const struct file_operations lttng_event_recorder_event_fops = { + .owner = THIS_MODULE, + .release = lttng_event_recorder_event_release, + .unlocked_ioctl = lttng_event_recorder_event_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = lttng_event_recorder_event_ioctl, +#endif +}; + +static const struct file_operations lttng_event_recorder_enabler_fops = { .owner = THIS_MODULE, - .release = lttng_event_release, - .unlocked_ioctl = lttng_event_ioctl, + .release = lttng_event_recorder_enabler_release, + .unlocked_ioctl = lttng_event_recorder_enabler_ioctl, #ifdef CONFIG_COMPAT - .compat_ioctl = lttng_event_ioctl, + .compat_ioctl = lttng_event_recorder_enabler_ioctl, #endif }; @@ -2700,10 +2741,10 @@ static int put_u32(uint32_t val, unsigned long arg) static long lttng_stream_ring_buffer_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { - struct lib_ring_buffer *buf = filp->private_data; - struct channel *chan = buf->backend.chan; - const struct lib_ring_buffer_config *config = &chan->backend.config; - const struct lttng_channel_ops *ops = chan->backend.priv_ops; + struct lttng_kernel_ring_buffer *buf = filp->private_data; + struct lttng_kernel_ring_buffer_channel *chan = buf->backend.chan; + const struct lttng_kernel_ring_buffer_config *config = &chan->backend.config; + const struct lttng_kernel_channel_buffer_ops *ops = chan->backend.priv_ops; int ret; if (atomic_read(&chan->record_disabled)) @@ -2714,7 +2755,7 @@ static long lttng_stream_ring_buffer_ioctl(struct file *filp, { uint64_t ts; - ret = ops->timestamp_begin(config, buf, &ts); + ret = ops->priv->timestamp_begin(config, buf, &ts); if (ret < 0) goto error; return put_u64(ts, arg); @@ -2723,7 +2764,7 @@ static long lttng_stream_ring_buffer_ioctl(struct file *filp, { uint64_t ts; - ret = ops->timestamp_end(config, buf, &ts); + ret = ops->priv->timestamp_end(config, buf, &ts); if (ret < 0) goto error; return put_u64(ts, arg); @@ -2732,7 +2773,7 @@ static long lttng_stream_ring_buffer_ioctl(struct file *filp, { uint64_t ed; - ret = ops->events_discarded(config, buf, &ed); + ret = ops->priv->events_discarded(config, buf, &ed); if (ret < 0) goto error; return put_u64(ed, arg); @@ -2741,7 +2782,7 @@ static long lttng_stream_ring_buffer_ioctl(struct file *filp, { uint64_t cs; - ret = ops->content_size(config, buf, &cs); + ret = ops->priv->content_size(config, buf, &cs); if (ret < 0) goto error; return put_u64(cs, arg); @@ -2750,7 +2791,7 @@ static long lttng_stream_ring_buffer_ioctl(struct file *filp, { uint64_t ps; - ret = ops->packet_size(config, buf, &ps); + ret = ops->priv->packet_size(config, buf, &ps); if (ret < 0) goto error; return put_u64(ps, arg); @@ -2759,7 +2800,7 @@ static long lttng_stream_ring_buffer_ioctl(struct file *filp, { uint64_t si; - ret = ops->stream_id(config, buf, &si); + ret = ops->priv->stream_id(config, buf, &si); if (ret < 0) goto error; return put_u64(si, arg); @@ -2768,7 +2809,7 @@ static long lttng_stream_ring_buffer_ioctl(struct file *filp, { uint64_t ts; - ret = ops->current_timestamp(config, buf, &ts); + ret = ops->priv->current_timestamp(config, buf, &ts); if (ret < 0) goto error; return put_u64(ts, arg); @@ -2777,7 +2818,7 @@ static long lttng_stream_ring_buffer_ioctl(struct file *filp, { uint64_t seq; - ret = ops->sequence_number(config, buf, &seq); + ret = ops->priv->sequence_number(config, buf, &seq); if (ret < 0) goto error; return put_u64(seq, arg); @@ -2786,7 +2827,7 @@ static long lttng_stream_ring_buffer_ioctl(struct file *filp, { uint64_t id; - ret = ops->instance_id(config, buf, &id); + ret = ops->priv->instance_id(config, buf, &id); if (ret < 0) goto error; return put_u64(id, arg); @@ -2804,10 +2845,10 @@ error: static long lttng_stream_ring_buffer_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { - struct lib_ring_buffer *buf = filp->private_data; - struct channel *chan = buf->backend.chan; - const struct lib_ring_buffer_config *config = &chan->backend.config; - const struct lttng_channel_ops *ops = chan->backend.priv_ops; + struct lttng_kernel_ring_buffer *buf = filp->private_data; + struct lttng_kernel_ring_buffer_channel *chan = buf->backend.chan; + const struct lttng_kernel_ring_buffer_config *config = &chan->backend.config; + const struct lttng_kernel_channel_buffer_ops *ops = chan->backend.priv_ops; int ret; if (atomic_read(&chan->record_disabled)) @@ -2818,7 +2859,7 @@ static long lttng_stream_ring_buffer_compat_ioctl(struct file *filp, { uint64_t ts; - ret = ops->timestamp_begin(config, buf, &ts); + ret = ops->priv->timestamp_begin(config, buf, &ts); if (ret < 0) goto error; return put_u64(ts, arg); @@ -2827,7 +2868,7 @@ static long lttng_stream_ring_buffer_compat_ioctl(struct file *filp, { uint64_t ts; - ret = ops->timestamp_end(config, buf, &ts); + ret = ops->priv->timestamp_end(config, buf, &ts); if (ret < 0) goto error; return put_u64(ts, arg); @@ -2836,7 +2877,7 @@ static long lttng_stream_ring_buffer_compat_ioctl(struct file *filp, { uint64_t ed; - ret = ops->events_discarded(config, buf, &ed); + ret = ops->priv->events_discarded(config, buf, &ed); if (ret < 0) goto error; return put_u64(ed, arg); @@ -2845,7 +2886,7 @@ static long lttng_stream_ring_buffer_compat_ioctl(struct file *filp, { uint64_t cs; - ret = ops->content_size(config, buf, &cs); + ret = ops->priv->content_size(config, buf, &cs); if (ret < 0) goto error; return put_u64(cs, arg); @@ -2854,7 +2895,7 @@ static long lttng_stream_ring_buffer_compat_ioctl(struct file *filp, { uint64_t ps; - ret = ops->packet_size(config, buf, &ps); + ret = ops->priv->packet_size(config, buf, &ps); if (ret < 0) goto error; return put_u64(ps, arg); @@ -2863,7 +2904,7 @@ static long lttng_stream_ring_buffer_compat_ioctl(struct file *filp, { uint64_t si; - ret = ops->stream_id(config, buf, &si); + ret = ops->priv->stream_id(config, buf, &si); if (ret < 0) goto error; return put_u64(si, arg); @@ -2872,7 +2913,7 @@ static long lttng_stream_ring_buffer_compat_ioctl(struct file *filp, { uint64_t ts; - ret = ops->current_timestamp(config, buf, &ts); + ret = ops->priv->current_timestamp(config, buf, &ts); if (ret < 0) goto error; return put_u64(ts, arg); @@ -2881,7 +2922,7 @@ static long lttng_stream_ring_buffer_compat_ioctl(struct file *filp, { uint64_t seq; - ret = ops->sequence_number(config, buf, &seq); + ret = ops->priv->sequence_number(config, buf, &seq); if (ret < 0) goto error; return put_u64(seq, arg); @@ -2890,7 +2931,7 @@ static long lttng_stream_ring_buffer_compat_ioctl(struct file *filp, { uint64_t id; - ret = ops->instance_id(config, buf, &id); + ret = ops->priv->instance_id(config, buf, &id); if (ret < 0) goto error; return put_u64(id, arg);