Rename struct channel to struct lttng_kernel_ring_buffer_channel
[lttng-modules.git] / src / lib / ringbuffer / ring_buffer_iterator.c
index a136a8faa5658ed316c5336eafe162cd0fc63f66..53ce6b44dd54faacf2d33ef05152242b93e7082f 100644 (file)
@@ -35,7 +35,7 @@
  * Returns the size of the event read, -EAGAIN if buffer is empty, -ENODATA if
  * buffer is empty and finalized. The buffer must already be opened for reading.
  */
-ssize_t lib_ring_buffer_get_next_record(struct channel *chan,
+ssize_t lib_ring_buffer_get_next_record(struct lttng_kernel_ring_buffer_channel *chan,
                                        struct lib_ring_buffer *buf)
 {
        const struct lib_ring_buffer_config *config = &chan->backend.config;
@@ -105,6 +105,24 @@ restart:
 }
 EXPORT_SYMBOL_GPL(lib_ring_buffer_get_next_record);
 
+void lib_ring_buffer_put_current_record(struct lib_ring_buffer *buf)
+{
+       struct lib_ring_buffer_iter *iter;
+
+       if (!buf)
+               return;
+       iter = &buf->iter;
+       if (iter->state != ITER_NEXT_RECORD)
+               return;
+       iter->read_offset += iter->payload_len;
+       iter->state = ITER_TEST_RECORD;
+       if (iter->read_offset - iter->consumed >= iter->data_size) {
+               lib_ring_buffer_put_next_subbuf(buf);
+               iter->state = ITER_GET_SUBBUF;
+       }
+}
+EXPORT_SYMBOL_GPL(lib_ring_buffer_put_current_record);
+
 static int buf_is_higher(void *a, void *b)
 {
        struct lib_ring_buffer *bufa = a;
@@ -116,7 +134,7 @@ static int buf_is_higher(void *a, void *b)
 
 static
 void lib_ring_buffer_get_empty_buf_records(const struct lib_ring_buffer_config *config,
-                                          struct channel *chan)
+                                          struct lttng_kernel_ring_buffer_channel *chan)
 {
        struct lttng_ptr_heap *heap = &chan->iter.heap;
        struct lib_ring_buffer *buf, *tmp;
@@ -160,7 +178,7 @@ void lib_ring_buffer_get_empty_buf_records(const struct lib_ring_buffer_config *
 
 static
 void lib_ring_buffer_wait_for_qs(const struct lib_ring_buffer_config *config,
-                                struct channel *chan)
+                                struct lttng_kernel_ring_buffer_channel *chan)
 {
        u64 timestamp_qs;
        unsigned long wait_msecs;
@@ -220,7 +238,7 @@ void lib_ring_buffer_wait_for_qs(const struct lib_ring_buffer_config *config,
  * opened for reading.
  */
 
-ssize_t channel_get_next_record(struct channel *chan,
+ssize_t channel_get_next_record(struct lttng_kernel_ring_buffer_channel *chan,
                                struct lib_ring_buffer **ret_buf)
 {
        const struct lib_ring_buffer_config *config = &chan->backend.config;
@@ -319,7 +337,7 @@ ssize_t channel_get_next_record(struct channel *chan,
 EXPORT_SYMBOL_GPL(channel_get_next_record);
 
 static
-void lib_ring_buffer_iterator_init(struct channel *chan, struct lib_ring_buffer *buf)
+void lib_ring_buffer_iterator_init(struct lttng_kernel_ring_buffer_channel *chan, struct lib_ring_buffer *buf)
 {
        if (buf->iter.allocated)
                return;
@@ -335,12 +353,12 @@ void lib_ring_buffer_iterator_init(struct channel *chan, struct lib_ring_buffer
                list_add(&buf->iter.empty_node, &chan->iter.empty_head);
 }
 
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0))
+#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0))
 
 int lttng_cpuhp_rb_iter_online(unsigned int cpu,
                struct lttng_cpuhp_node *node)
 {
-       struct channel *chan = container_of(node, struct channel,
+       struct lttng_kernel_ring_buffer_channel *chan = container_of(node, struct lttng_kernel_ring_buffer_channel,
                                            cpuhp_iter_online);
        struct lib_ring_buffer *buf = per_cpu_ptr(chan->backend.buf, cpu);
        const struct lib_ring_buffer_config *config = &chan->backend.config;
@@ -352,7 +370,7 @@ int lttng_cpuhp_rb_iter_online(unsigned int cpu,
 }
 EXPORT_SYMBOL_GPL(lttng_cpuhp_rb_iter_online);
 
-#else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */
+#else /* #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0)) */
 
 #ifdef CONFIG_HOTPLUG_CPU
 static
@@ -361,7 +379,7 @@ int channel_iterator_cpu_hotplug(struct notifier_block *nb,
                                           void *hcpu)
 {
        unsigned int cpu = (unsigned long)hcpu;
-       struct channel *chan = container_of(nb, struct channel,
+       struct lttng_kernel_ring_buffer_channel *chan = container_of(nb, struct lttng_kernel_ring_buffer_channel,
                                            hp_iter_notifier);
        struct lib_ring_buffer *buf = per_cpu_ptr(chan->backend.buf, cpu);
        const struct lib_ring_buffer_config *config = &chan->backend.config;
@@ -384,9 +402,9 @@ int channel_iterator_cpu_hotplug(struct notifier_block *nb,
 }
 #endif
 
-#endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */
+#endif /* #else #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0)) */
 
-int channel_iterator_init(struct channel *chan)
+int channel_iterator_init(struct lttng_kernel_ring_buffer_channel *chan)
 {
        const struct lib_ring_buffer_config *config = &chan->backend.config;
        struct lib_ring_buffer *buf;
@@ -401,13 +419,13 @@ int channel_iterator_init(struct channel *chan)
                if (ret)
                        return ret;
 
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0))
+#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0))
                chan->cpuhp_iter_online.component = LTTNG_RING_BUFFER_ITER;
                ret = cpuhp_state_add_instance(lttng_rb_hp_online,
                        &chan->cpuhp_iter_online.node);
                if (ret)
                        return ret;
-#else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */
+#else /* #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0)) */
                {
                        int cpu;
 
@@ -436,7 +454,7 @@ int channel_iterator_init(struct channel *chan)
                        }
 #endif
                }
-#endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */
+#endif /* #else #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0)) */
        } else {
                buf = channel_get_ring_buffer(config, chan, 0);
                lib_ring_buffer_iterator_init(chan, buf);
@@ -444,12 +462,12 @@ int channel_iterator_init(struct channel *chan)
        return 0;
 }
 
-void channel_iterator_unregister_notifiers(struct channel *chan)
+void channel_iterator_unregister_notifiers(struct lttng_kernel_ring_buffer_channel *chan)
 {
        const struct lib_ring_buffer_config *config = &chan->backend.config;
 
        if (config->alloc == RING_BUFFER_ALLOC_PER_CPU) {
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0))
+#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0))
                {
                        int ret;
 
@@ -457,14 +475,14 @@ void channel_iterator_unregister_notifiers(struct channel *chan)
                                &chan->cpuhp_iter_online.node);
                        WARN_ON(ret);
                }
-#else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */
+#else /* #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0)) */
                chan->hp_iter_enable = 0;
                unregister_cpu_notifier(&chan->hp_iter_notifier);
-#endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */
+#endif /* #else #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0)) */
        }
 }
 
-void channel_iterator_free(struct channel *chan)
+void channel_iterator_free(struct lttng_kernel_ring_buffer_channel *chan)
 {
        const struct lib_ring_buffer_config *config = &chan->backend.config;
 
@@ -474,7 +492,7 @@ void channel_iterator_free(struct channel *chan)
 
 int lib_ring_buffer_iterator_open(struct lib_ring_buffer *buf)
 {
-       struct channel *chan = buf->backend.chan;
+       struct lttng_kernel_ring_buffer_channel *chan = buf->backend.chan;
        const struct lib_ring_buffer_config *config = &chan->backend.config;
        CHAN_WARN_ON(chan, config->output != RING_BUFFER_ITERATOR);
        return lib_ring_buffer_open_read(buf);
@@ -492,7 +510,7 @@ void lib_ring_buffer_iterator_release(struct lib_ring_buffer *buf)
 }
 EXPORT_SYMBOL_GPL(lib_ring_buffer_iterator_release);
 
-int channel_iterator_open(struct channel *chan)
+int channel_iterator_open(struct lttng_kernel_ring_buffer_channel *chan)
 {
        const struct lib_ring_buffer_config *config = &chan->backend.config;
        struct lib_ring_buffer *buf;
@@ -525,7 +543,7 @@ error:
 }
 EXPORT_SYMBOL_GPL(channel_iterator_open);
 
-void channel_iterator_release(struct channel *chan)
+void channel_iterator_release(struct lttng_kernel_ring_buffer_channel *chan)
 {
        const struct lib_ring_buffer_config *config = &chan->backend.config;
        struct lib_ring_buffer *buf;
@@ -551,7 +569,7 @@ EXPORT_SYMBOL_GPL(channel_iterator_release);
 
 void lib_ring_buffer_iterator_reset(struct lib_ring_buffer *buf)
 {
-       struct channel *chan = buf->backend.chan;
+       struct lttng_kernel_ring_buffer_channel *chan = buf->backend.chan;
 
        if (buf->iter.state != ITER_GET_SUBBUF)
                lib_ring_buffer_put_next_subbuf(buf);
@@ -568,7 +586,7 @@ void lib_ring_buffer_iterator_reset(struct lib_ring_buffer *buf)
        /* Don't reset allocated and read_open */
 }
 
-void channel_iterator_reset(struct channel *chan)
+void channel_iterator_reset(struct lttng_kernel_ring_buffer_channel *chan)
 {
        const struct lib_ring_buffer_config *config = &chan->backend.config;
        struct lib_ring_buffer *buf;
@@ -597,7 +615,7 @@ ssize_t channel_ring_buffer_file_read(struct file *filp,
                                      char __user *user_buf,
                                      size_t count,
                                      loff_t *ppos,
-                                     struct channel *chan,
+                                     struct lttng_kernel_ring_buffer_channel *chan,
                                      struct lib_ring_buffer *buf,
                                      int fusionmerge)
 {
@@ -696,12 +714,14 @@ skip_get_next:
                        return -EFAULT;
                }
                read_count += copy_len;
-       };
-       return read_count;
+       }
+       goto put_record;
 
 nodata:
        *ppos = 0;
        chan->iter.len_left = 0;
+put_record:
+       lib_ring_buffer_put_current_record(buf);
        return read_count;
 }
 
@@ -724,7 +744,7 @@ ssize_t lib_ring_buffer_file_read(struct file *filp,
 {
        struct inode *inode = filp->lttng_f_dentry->d_inode;
        struct lib_ring_buffer *buf = inode->i_private;
-       struct channel *chan = buf->backend.chan;
+       struct lttng_kernel_ring_buffer_channel *chan = buf->backend.chan;
 
        return channel_ring_buffer_file_read(filp, user_buf, count, ppos,
                                             chan, buf, 0);
@@ -748,7 +768,7 @@ ssize_t channel_file_read(struct file *filp,
                          loff_t *ppos)
 {
        struct inode *inode = filp->lttng_f_dentry->d_inode;
-       struct channel *chan = inode->i_private;
+       struct lttng_kernel_ring_buffer_channel *chan = inode->i_private;
        const struct lib_ring_buffer_config *config = &chan->backend.config;
 
        if (config->alloc == RING_BUFFER_ALLOC_PER_CPU)
@@ -795,7 +815,7 @@ int lib_ring_buffer_file_release(struct inode *inode, struct file *file)
 static
 int channel_file_open(struct inode *inode, struct file *file)
 {
-       struct channel *chan = inode->i_private;
+       struct lttng_kernel_ring_buffer_channel *chan = inode->i_private;
        int ret;
 
        ret = channel_iterator_open(chan);
@@ -816,7 +836,7 @@ release_iter:
 static
 int channel_file_release(struct inode *inode, struct file *file)
 {
-       struct channel *chan = inode->i_private;
+       struct lttng_kernel_ring_buffer_channel *chan = inode->i_private;
 
        channel_iterator_release(chan);
        return 0;
This page took 0.027616 seconds and 4 git commands to generate.