Merge branch 'tracing/urgent' into tracing/core
[linux-2.6.git] / kernel / trace / trace.c
index 0615751a3ed7a43f24c7e324562296070e12b54c..4865459f609f94c8cc42601d6f1e8c245582594c 100644 (file)
@@ -3268,19 +3268,13 @@ static int tracing_buffers_open(struct inode *inode, struct file *filp)
 
        info->tr        = &global_trace;
        info->cpu       = cpu;
-       info->spare     = ring_buffer_alloc_read_page(info->tr->buffer);
+       info->spare     = NULL;
        /* Force reading ring buffer for first read */
        info->read      = (unsigned int)-1;
-       if (!info->spare)
-               goto out;
 
        filp->private_data = info;
 
-       return 0;
-
- out:
-       kfree(info);
-       return -ENOMEM;
+       return nonseekable_open(inode, filp);
 }
 
 static ssize_t
@@ -3295,6 +3289,11 @@ tracing_buffers_read(struct file *filp, char __user *ubuf,
        if (!count)
                return 0;
 
+       if (!info->spare)
+               info->spare = ring_buffer_alloc_read_page(info->tr->buffer);
+       if (!info->spare)
+               return -ENOMEM;
+
        /* Do we have previous read data to read? */
        if (info->read < PAGE_SIZE)
                goto read;
@@ -3333,7 +3332,8 @@ static int tracing_buffers_release(struct inode *inode, struct file *file)
 {
        struct ftrace_buffer_info *info = file->private_data;
 
-       ring_buffer_free_read_page(info->tr->buffer, info->spare);
+       if (info->spare)
+               ring_buffer_free_read_page(info->tr->buffer, info->spare);
        kfree(info);
 
        return 0;
@@ -3419,14 +3419,19 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,
        int size, i;
        size_t ret;
 
-       /*
-        * We can't seek on a buffer input
-        */
-       if (unlikely(*ppos))
-               return -ESPIPE;
+       if (*ppos & (PAGE_SIZE - 1)) {
+               WARN_ONCE(1, "Ftrace: previous read must page-align\n");
+               return -EINVAL;
+       }
 
+       if (len & (PAGE_SIZE - 1)) {
+               WARN_ONCE(1, "Ftrace: splice_read should page-align\n");
+               if (len < PAGE_SIZE)
+                       return -EINVAL;
+               len &= PAGE_MASK;
+       }
 
-       for (i = 0; i < PIPE_BUFFERS && len; i++, len -= size) {
+       for (i = 0; i < PIPE_BUFFERS && len; i++, len -= PAGE_SIZE) {
                struct page *page;
                int r;
 
@@ -3465,6 +3470,7 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,
                spd.partial[i].offset = 0;
                spd.partial[i].private = (unsigned long)ref;
                spd.nr_pages++;
+               *ppos += PAGE_SIZE;
        }
 
        spd.nr_pages = i;