X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=lttng-abi.c;h=7cc4b5201f45a790d9cf842efd15d4f28def4248;hb=ed8d02d6a3d1dae8e7ecbda764202a0316b5ea6f;hp=26a456ece13f7ed0a62b5e3b3e92d2cff942c17c;hpb=d4d4b9c765362750b023ac23161573113189620d;p=lttng-modules.git diff --git a/lttng-abi.c b/lttng-abi.c index 26a456ec..7cc4b520 100644 --- a/lttng-abi.c +++ b/lttng-abi.c @@ -64,6 +64,7 @@ static const struct file_operations lttng_session_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 struct file_operations lttng_stream_ring_buffer_file_operations; /* * Teardown management: opened file descriptors keep a refcount on the module, @@ -553,10 +554,9 @@ int lttng_metadata_ring_buffer_ioctl_get_next_subbuf(struct file *filp, struct lttng_metadata_stream *stream = filp->private_data; struct lib_ring_buffer *buf = stream->priv; struct channel *chan = buf->backend.chan; - struct lttng_channel *lttng_chan = channel_get_private(chan); int ret; - ret = lttng_metadata_output_channel(lttng_chan, stream); + ret = lttng_metadata_output_channel(stream, chan); if (ret > 0) { lib_ring_buffer_switch_slow(buf, SWITCH_ACTIVE); ret = 0; @@ -671,6 +671,10 @@ err: } #endif +/* + * This is not used by anonymous file descriptors. This code is left + * there if we ever want to implement an inode with open() operation. + */ static int lttng_metadata_ring_buffer_open(struct inode *inode, struct file *file) { @@ -678,6 +682,14 @@ int lttng_metadata_ring_buffer_open(struct inode *inode, struct file *file) struct lib_ring_buffer *buf = stream->priv; file->private_data = buf; + /* + * Since life-time of metadata cache differs from that of + * 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"); + return -EBUSY; + } return lib_ring_buffer_open(inode, file, buf); } @@ -686,12 +698,9 @@ 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 channel *chan = buf->backend.chan; - struct lttng_channel *lttng_chan = channel_get_private(chan); kref_put(&stream->metadata_cache->refcount, metadata_cache_destroy); - fput(lttng_chan->file); - + module_put(stream->transport->owner); return lib_ring_buffer_release(inode, file, buf); } @@ -784,7 +793,7 @@ int lttng_abi_open_stream(struct file *channel_file) stream_priv = buf; ret = lttng_abi_create_stream_fd(channel_file, stream_priv, - &lib_ring_buffer_file_operations); + <tng_stream_ring_buffer_file_operations); if (ret < 0) goto fd_error; @@ -811,24 +820,41 @@ int lttng_abi_open_metadata_stream(struct file *channel_file) metadata_stream = kzalloc(sizeof(struct lttng_metadata_stream), GFP_KERNEL); - if (!metadata_stream) - return -ENOMEM; + if (!metadata_stream) { + ret = -ENOMEM; + goto nomem; + } metadata_stream->metadata_cache = session->metadata_cache; init_waitqueue_head(&metadata_stream->read_wait); metadata_stream->priv = buf; stream_priv = metadata_stream; + metadata_stream->transport = channel->transport; + + /* + * Since life-time of metadata cache differs from that of + * 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"); + ret = -EINVAL; + goto notransport; + } + ret = lttng_abi_create_stream_fd(channel_file, stream_priv, <tng_metadata_ring_buffer_file_operations); if (ret < 0) goto fd_error; - atomic_long_inc(&channel_file->f_count); kref_get(&session->metadata_cache->refcount); list_add(&metadata_stream->list, &session->metadata_cache->metadata_stream); return ret; fd_error: + module_put(metadata_stream->transport->owner); +notransport: + kfree(metadata_stream); +nomem: channel->ops->buffer_read_close(buf); return ret; } @@ -1297,6 +1323,51 @@ static const struct file_operations lttng_event_fops = { #endif }; +static long lttng_stream_ring_buffer_ioctl(struct file *filp, + unsigned int cmd, unsigned long arg) +{ + switch (cmd) { + default: + return lib_ring_buffer_file_operations.unlocked_ioctl(filp, + cmd, arg); + } +} + +#ifdef CONFIG_COMPAT +static long lttng_stream_ring_buffer_compat_ioctl(struct file *filp, + unsigned int cmd, unsigned long arg) +{ + switch (cmd) { + default: + return lib_ring_buffer_file_operations.compat_ioctl(filp, + cmd, arg); + } +} +#endif /* CONFIG_COMPAT */ + +static void lttng_stream_override_ring_buffer_fops(void) +{ + lttng_stream_ring_buffer_file_operations.owner = THIS_MODULE; + lttng_stream_ring_buffer_file_operations.open = + lib_ring_buffer_file_operations.open; + lttng_stream_ring_buffer_file_operations.release = + lib_ring_buffer_file_operations.release; + lttng_stream_ring_buffer_file_operations.poll = + lib_ring_buffer_file_operations.poll; + lttng_stream_ring_buffer_file_operations.splice_read = + lib_ring_buffer_file_operations.splice_read; + lttng_stream_ring_buffer_file_operations.mmap = + lib_ring_buffer_file_operations.mmap; + lttng_stream_ring_buffer_file_operations.unlocked_ioctl = + lttng_stream_ring_buffer_ioctl; + lttng_stream_ring_buffer_file_operations.llseek = + lib_ring_buffer_file_operations.llseek; +#ifdef CONFIG_COMPAT + lttng_stream_ring_buffer_file_operations.compat_ioctl = + lttng_stream_ring_buffer_compat_ioctl; +#endif +} + int __init lttng_abi_init(void) { int ret = 0; @@ -1310,6 +1381,8 @@ int __init lttng_abi_init(void) ret = -ENOMEM; goto error; } + lttng_stream_override_ring_buffer_fops(); + error: return ret; }