Merge master.kernel.org:/pub/scm/linux/kernel/git/paulus/powerpc
[powerpc.git] / fs / splice.c
index 4a026f9..6081cf7 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/pipe_fs_i.h>
 #include <linux/mm_inline.h>
 #include <linux/swap.h>
+#include <linux/module.h>
 
 /*
  * Passed to the actors
@@ -105,7 +106,7 @@ static struct pipe_buf_operations page_cache_pipe_buf_ops = {
 
 static ssize_t move_to_pipe(struct inode *inode, struct page **pages,
                            int nr_pages, unsigned long offset,
-                           unsigned long len)
+                           unsigned long len, unsigned int flags)
 {
        struct pipe_inode_info *info;
        int ret, do_wakeup, i;
@@ -158,6 +159,12 @@ static ssize_t move_to_pipe(struct inode *inode, struct page **pages,
                        break;
                }
 
+               if (flags & SPLICE_F_NONBLOCK) {
+                       if (!ret)
+                               ret = -EAGAIN;
+                       break;
+               }
+
                if (signal_pending(current)) {
                        if (!ret)
                                ret = -ERESTARTSYS;
@@ -190,7 +197,7 @@ static ssize_t move_to_pipe(struct inode *inode, struct page **pages,
 }
 
 static int __generic_file_splice_read(struct file *in, struct inode *pipe,
-                                     size_t len)
+                                     size_t len, unsigned int flags)
 {
        struct address_space *mapping = in->f_mapping;
        unsigned int offset, nr_pages;
@@ -278,7 +285,7 @@ static int __generic_file_splice_read(struct file *in, struct inode *pipe,
         * Now we splice them into the pipe..
         */
 splice_them:
-       return move_to_pipe(pipe, pages, i, offset, len);
+       return move_to_pipe(pipe, pages, i, offset, len, flags);
 }
 
 ssize_t generic_file_splice_read(struct file *in, struct inode *pipe,
@@ -290,7 +297,7 @@ ssize_t generic_file_splice_read(struct file *in, struct inode *pipe,
        ret = 0;
        spliced = 0;
        while (len) {
-               ret = __generic_file_splice_read(in, pipe, len);
+               ret = __generic_file_splice_read(in, pipe, len, flags);
 
                if (ret <= 0)
                        break;
@@ -298,6 +305,11 @@ ssize_t generic_file_splice_read(struct file *in, struct inode *pipe,
                in->f_pos += ret;
                len -= ret;
                spliced += ret;
+
+               if (!(flags & SPLICE_F_NONBLOCK))
+                       continue;
+               ret = -EAGAIN;
+               break;
        }
 
        if (spliced)
@@ -526,6 +538,12 @@ static ssize_t move_from_pipe(struct inode *inode, struct file *out,
                                break;
                }
 
+               if (flags & SPLICE_F_NONBLOCK) {
+                       if (!ret)
+                               ret = -EAGAIN;
+                       break;
+               }
+
                if (signal_pending(current)) {
                        if (!ret)
                                ret = -ERESTARTSYS;
@@ -567,6 +585,9 @@ ssize_t generic_splice_sendpage(struct inode *inode, struct file *out,
        return move_from_pipe(inode, out, len, flags, pipe_to_sendpage);
 }
 
+EXPORT_SYMBOL(generic_file_splice_write);
+EXPORT_SYMBOL(generic_file_splice_read);
+
 static long do_splice_from(struct inode *pipe, struct file *out, size_t len,
                           unsigned int flags)
 {