Fix: Add f_dentry wrapper for 3.19+ kernels
[lttng-modules.git] / lib / ringbuffer / ring_buffer_iterator.c
index e8b042b025cd3ca0ff0e164de4699a1f31045991..24e3dbb36a39882eeae8a53011f5ebd3303271ab 100644 (file)
@@ -1,19 +1,32 @@
 /*
  * ring_buffer_iterator.c
  *
- * (C) Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
  * Ring buffer and channel iterators. Get each event of a channel in order. Uses
  * a prio heap for per-cpu buffers, giving a O(log(NR_CPUS)) algorithmic
  * complexity for the "get next event" operation.
  *
+ * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; only
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
  * Author:
  *     Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * Dual LGPL v2.1/GPL v2 license.
  */
 
 #include "../../wrapper/ringbuffer/iterator.h"
+#include "../../wrapper/file.h"
 #include <linux/jiffies.h>
 #include <linux/delay.h>
 #include <linux/module.h>
@@ -40,7 +53,7 @@
 ssize_t lib_ring_buffer_get_next_record(struct channel *chan,
                                        struct lib_ring_buffer *buf)
 {
-       const struct lib_ring_buffer_config *config = chan->backend.config;
+       const struct lib_ring_buffer_config *config = &chan->backend.config;
        struct lib_ring_buffer_iter *iter = &buf->iter;
        int ret;
 
@@ -120,7 +133,7 @@ static
 void lib_ring_buffer_get_empty_buf_records(const struct lib_ring_buffer_config *config,
                                           struct channel *chan)
 {
-       struct ptr_heap *heap = &chan->iter.heap;
+       struct lttng_ptr_heap *heap = &chan->iter.heap;
        struct lib_ring_buffer *buf, *tmp;
        ssize_t len;
 
@@ -151,11 +164,11 @@ void lib_ring_buffer_get_empty_buf_records(const struct lib_ring_buffer_config *
                default:
                        /*
                         * Insert buffer into the heap, remove from empty buffer
-                        * list. The heap should never overflow.
+                        * list.
                         */
                        CHAN_WARN_ON(chan, len < 0);
                        list_del(&buf->iter.empty_node);
-                       CHAN_WARN_ON(chan, heap_insert(heap, buf) != NULL);
+                       CHAN_WARN_ON(chan, lttng_heap_insert(heap, buf));
                }
        }
 }
@@ -225,9 +238,9 @@ void lib_ring_buffer_wait_for_qs(const struct lib_ring_buffer_config *config,
 ssize_t channel_get_next_record(struct channel *chan,
                                struct lib_ring_buffer **ret_buf)
 {
-       const struct lib_ring_buffer_config *config = chan->backend.config;
+       const struct lib_ring_buffer_config *config = &chan->backend.config;
        struct lib_ring_buffer *buf;
-       struct ptr_heap *heap;
+       struct lttng_ptr_heap *heap;
        ssize_t len;
 
        if (config->alloc == RING_BUFFER_ALLOC_GLOBAL) {
@@ -240,7 +253,7 @@ ssize_t channel_get_next_record(struct channel *chan,
        /*
         * get next record for topmost buffer.
         */
-       buf = heap_maximum(heap);
+       buf = lttng_heap_maximum(heap);
        if (buf) {
                len = lib_ring_buffer_get_next_record(chan, buf);
                /*
@@ -252,7 +265,7 @@ ssize_t channel_get_next_record(struct channel *chan,
                        buf->iter.timestamp = 0;
                        list_add(&buf->iter.empty_node, &chan->iter.empty_head);
                        /* Remove topmost buffer from the heap */
-                       CHAN_WARN_ON(chan, heap_remove(heap) != buf);
+                       CHAN_WARN_ON(chan, lttng_heap_remove(heap) != buf);
                        break;
                case -ENODATA:
                        /*
@@ -260,7 +273,7 @@ ssize_t channel_get_next_record(struct channel *chan,
                         * don't add to list of empty buffer, because it has no
                         * more data to provide, ever.
                         */
-                       CHAN_WARN_ON(chan, heap_remove(heap) != buf);
+                       CHAN_WARN_ON(chan, lttng_heap_remove(heap) != buf);
                        break;
                case -EBUSY:
                        CHAN_WARN_ON(chan, 1);
@@ -269,15 +282,15 @@ ssize_t channel_get_next_record(struct channel *chan,
                        /*
                         * Reinsert buffer into the heap. Note that heap can be
                         * partially empty, so we need to use
-                        * heap_replace_max().
+                        * lttng_heap_replace_max().
                         */
                        CHAN_WARN_ON(chan, len < 0);
-                       CHAN_WARN_ON(chan, heap_replace_max(heap, buf) != buf);
+                       CHAN_WARN_ON(chan, lttng_heap_replace_max(heap, buf) != buf);
                        break;
                }
        }
 
-       buf = heap_maximum(heap);
+       buf = lttng_heap_maximum(heap);
        if (!buf || buf->iter.timestamp > chan->iter.last_qs) {
                /*
                 * Deal with buffers previously showing no data.
@@ -287,7 +300,7 @@ ssize_t channel_get_next_record(struct channel *chan,
                lib_ring_buffer_wait_for_qs(config, chan);
        }
 
-       *ret_buf = buf = heap_maximum(heap);
+       *ret_buf = buf = lttng_heap_maximum(heap);
        if (buf) {
                /*
                 * If this warning triggers, you probably need to check your
@@ -333,13 +346,13 @@ void lib_ring_buffer_iterator_init(struct channel *chan, struct lib_ring_buffer
        }
 
        /* Add to list of buffers without any current record */
-       if (chan->backend.config->alloc == RING_BUFFER_ALLOC_PER_CPU)
+       if (chan->backend.config.alloc == RING_BUFFER_ALLOC_PER_CPU)
                list_add(&buf->iter.empty_node, &chan->iter.empty_head);
 }
 
 #ifdef CONFIG_HOTPLUG_CPU
 static
-int __cpuinit channel_iterator_cpu_hotplug(struct notifier_block *nb,
+int channel_iterator_cpu_hotplug(struct notifier_block *nb,
                                           unsigned long action,
                                           void *hcpu)
 {
@@ -347,7 +360,7 @@ int __cpuinit channel_iterator_cpu_hotplug(struct notifier_block *nb,
        struct channel *chan = container_of(nb, struct 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;
+       const struct lib_ring_buffer_config *config = &chan->backend.config;
 
        if (!chan->hp_iter_enable)
                return NOTIFY_DONE;
@@ -369,16 +382,15 @@ int __cpuinit channel_iterator_cpu_hotplug(struct notifier_block *nb,
 
 int channel_iterator_init(struct channel *chan)
 {
-       const struct lib_ring_buffer_config *config = chan->backend.config;
+       const struct lib_ring_buffer_config *config = &chan->backend.config;
        struct lib_ring_buffer *buf;
 
        if (config->alloc == RING_BUFFER_ALLOC_PER_CPU) {
                int cpu, ret;
 
                INIT_LIST_HEAD(&chan->iter.empty_head);
-               ret = heap_init(&chan->iter.heap,
-                               num_possible_cpus()
-                               * sizeof(struct lib_ring_buffer *),
+               ret = lttng_heap_init(&chan->iter.heap,
+                               num_possible_cpus(),
                                GFP_KERNEL, buf_is_higher);
                if (ret)
                        return ret;
@@ -414,7 +426,7 @@ int channel_iterator_init(struct channel *chan)
 
 void channel_iterator_unregister_notifiers(struct channel *chan)
 {
-       const struct lib_ring_buffer_config *config = chan->backend.config;
+       const struct lib_ring_buffer_config *config = &chan->backend.config;
 
        if (config->alloc == RING_BUFFER_ALLOC_PER_CPU) {
                chan->hp_iter_enable = 0;
@@ -424,16 +436,16 @@ void channel_iterator_unregister_notifiers(struct channel *chan)
 
 void channel_iterator_free(struct channel *chan)
 {
-       const struct lib_ring_buffer_config *config = chan->backend.config;
+       const struct lib_ring_buffer_config *config = &chan->backend.config;
 
        if (config->alloc == RING_BUFFER_ALLOC_PER_CPU)
-               heap_free(&chan->iter.heap);
+               lttng_heap_free(&chan->iter.heap);
 }
 
 int lib_ring_buffer_iterator_open(struct lib_ring_buffer *buf)
 {
        struct channel *chan = buf->backend.chan;
-       const struct lib_ring_buffer_config *config = chan->backend.config;
+       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);
 }
@@ -452,7 +464,7 @@ EXPORT_SYMBOL_GPL(lib_ring_buffer_iterator_release);
 
 int channel_iterator_open(struct channel *chan)
 {
-       const struct lib_ring_buffer_config *config = chan->backend.config;
+       const struct lib_ring_buffer_config *config = &chan->backend.config;
        struct lib_ring_buffer *buf;
        int ret = 0, cpu;
 
@@ -485,7 +497,7 @@ EXPORT_SYMBOL_GPL(channel_iterator_open);
 
 void channel_iterator_release(struct channel *chan)
 {
-       const struct lib_ring_buffer_config *config = chan->backend.config;
+       const struct lib_ring_buffer_config *config = &chan->backend.config;
        struct lib_ring_buffer *buf;
        int cpu;
 
@@ -515,7 +527,7 @@ void lib_ring_buffer_iterator_reset(struct lib_ring_buffer *buf)
                lib_ring_buffer_put_next_subbuf(buf);
        buf->iter.state = ITER_GET_SUBBUF;
        /* Remove from heap (if present). */
-       if (heap_cherrypick(&chan->iter.heap, buf))
+       if (lttng_heap_cherrypick(&chan->iter.heap, buf))
                list_add(&buf->iter.empty_node, &chan->iter.empty_head);
        buf->iter.timestamp = 0;
        buf->iter.header_len = 0;
@@ -528,12 +540,12 @@ void lib_ring_buffer_iterator_reset(struct lib_ring_buffer *buf)
 
 void channel_iterator_reset(struct channel *chan)
 {
-       const struct lib_ring_buffer_config *config = chan->backend.config;
+       const struct lib_ring_buffer_config *config = &chan->backend.config;
        struct lib_ring_buffer *buf;
        int cpu;
 
        /* Empty heap, put into empty_head */
-       while ((buf = heap_remove(&chan->iter.heap)) != NULL)
+       while ((buf = lttng_heap_remove(&chan->iter.heap)) != NULL)
                list_add(&buf->iter.empty_node, &chan->iter.empty_head);
 
        for_each_channel_cpu(cpu, chan) {
@@ -559,7 +571,7 @@ ssize_t channel_ring_buffer_file_read(struct file *filp,
                                      struct lib_ring_buffer *buf,
                                      int fusionmerge)
 {
-       const struct lib_ring_buffer_config *config = chan->backend.config;
+       const struct lib_ring_buffer_config *config = &chan->backend.config;
        size_t read_count = 0, read_offset;
        ssize_t len;
 
@@ -574,7 +586,7 @@ ssize_t channel_ring_buffer_file_read(struct file *filp,
                        read_offset = *ppos;
                        if (config->alloc == RING_BUFFER_ALLOC_PER_CPU
                            && fusionmerge)
-                               buf = heap_maximum(&chan->iter.heap);
+                               buf = lttng_heap_maximum(&chan->iter.heap);
                        CHAN_WARN_ON(chan, !buf);
                        goto skip_get_next;
                }
@@ -680,7 +692,7 @@ ssize_t lib_ring_buffer_file_read(struct file *filp,
                                  size_t count,
                                  loff_t *ppos)
 {
-       struct inode *inode = filp->f_dentry->d_inode;
+       struct inode *inode = filp->lttng_f_dentry->d_inode;
        struct lib_ring_buffer *buf = inode->i_private;
        struct channel *chan = buf->backend.chan;
 
@@ -705,9 +717,9 @@ ssize_t channel_file_read(struct file *filp,
                          size_t count,
                          loff_t *ppos)
 {
-       struct inode *inode = filp->f_dentry->d_inode;
+       struct inode *inode = filp->lttng_f_dentry->d_inode;
        struct channel *chan = inode->i_private;
-       const struct lib_ring_buffer_config *config = chan->backend.config;
+       const struct lib_ring_buffer_config *config = &chan->backend.config;
 
        if (config->alloc == RING_BUFFER_ALLOC_PER_CPU)
                return channel_ring_buffer_file_read(filp, user_buf, count,
@@ -781,17 +793,19 @@ int channel_file_release(struct inode *inode, struct file *file)
 }
 
 const struct file_operations channel_payload_file_operations = {
+       .owner = THIS_MODULE,
        .open = channel_file_open,
        .release = channel_file_release,
        .read = channel_file_read,
-       .llseek = lib_ring_buffer_no_llseek,
+       .llseek = vfs_lib_ring_buffer_no_llseek,
 };
 EXPORT_SYMBOL_GPL(channel_payload_file_operations);
 
 const struct file_operations lib_ring_buffer_payload_file_operations = {
+       .owner = THIS_MODULE,
        .open = lib_ring_buffer_file_open,
        .release = lib_ring_buffer_file_release,
        .read = lib_ring_buffer_file_read,
-       .llseek = lib_ring_buffer_no_llseek,
+       .llseek = vfs_lib_ring_buffer_no_llseek,
 };
 EXPORT_SYMBOL_GPL(lib_ring_buffer_payload_file_operations);
This page took 0.028717 seconds and 4 git commands to generate.