@@ -342,89 +342,6 @@ const struct pipe_buf_operations nosteal_pipe_buf_ops = {
342342};
343343EXPORT_SYMBOL (nosteal_pipe_buf_ops );
344344
345- static ssize_t kernel_readv (struct file * file , const struct kvec * vec ,
346- unsigned long vlen , loff_t offset )
347- {
348- mm_segment_t old_fs ;
349- loff_t pos = offset ;
350- ssize_t res ;
351-
352- old_fs = get_fs ();
353- set_fs (KERNEL_DS );
354- /* The cast to a user pointer is valid due to the set_fs() */
355- res = vfs_readv (file , (const struct iovec __user * )vec , vlen , & pos , 0 );
356- set_fs (old_fs );
357-
358- return res ;
359- }
360-
361- static ssize_t default_file_splice_read (struct file * in , loff_t * ppos ,
362- struct pipe_inode_info * pipe , size_t len ,
363- unsigned int flags )
364- {
365- struct kvec * vec , __vec [PIPE_DEF_BUFFERS ];
366- struct iov_iter to ;
367- struct page * * pages ;
368- unsigned int nr_pages ;
369- unsigned int mask ;
370- size_t offset , base , copied = 0 ;
371- ssize_t res ;
372- int i ;
373-
374- if (pipe_full (pipe -> head , pipe -> tail , pipe -> max_usage ))
375- return - EAGAIN ;
376-
377- /*
378- * Try to keep page boundaries matching to source pagecache ones -
379- * it probably won't be much help, but...
380- */
381- offset = * ppos & ~PAGE_MASK ;
382-
383- iov_iter_pipe (& to , READ , pipe , len + offset );
384-
385- res = iov_iter_get_pages_alloc (& to , & pages , len + offset , & base );
386- if (res <= 0 )
387- return - ENOMEM ;
388-
389- nr_pages = DIV_ROUND_UP (res + base , PAGE_SIZE );
390-
391- vec = __vec ;
392- if (nr_pages > PIPE_DEF_BUFFERS ) {
393- vec = kmalloc_array (nr_pages , sizeof (struct kvec ), GFP_KERNEL );
394- if (unlikely (!vec )) {
395- res = - ENOMEM ;
396- goto out ;
397- }
398- }
399-
400- mask = pipe -> ring_size - 1 ;
401- pipe -> bufs [to .head & mask ].offset = offset ;
402- pipe -> bufs [to .head & mask ].len -= offset ;
403-
404- for (i = 0 ; i < nr_pages ; i ++ ) {
405- size_t this_len = min_t (size_t , len , PAGE_SIZE - offset );
406- vec [i ].iov_base = page_address (pages [i ]) + offset ;
407- vec [i ].iov_len = this_len ;
408- len -= this_len ;
409- offset = 0 ;
410- }
411-
412- res = kernel_readv (in , vec , nr_pages , * ppos );
413- if (res > 0 ) {
414- copied = res ;
415- * ppos += res ;
416- }
417-
418- if (vec != __vec )
419- kfree (vec );
420- out :
421- for (i = 0 ; i < nr_pages ; i ++ )
422- put_page (pages [i ]);
423- kvfree (pages );
424- iov_iter_advance (& to , copied ); /* truncates and discards */
425- return res ;
426- }
427-
428345/*
429346 * Send 'sd->len' bytes to socket from 'sd->file' at position 'sd->pos'
430347 * using sendpage(). Return the number of bytes sent.
@@ -788,33 +705,6 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
788705
789706EXPORT_SYMBOL (iter_file_splice_write );
790707
791- static int write_pipe_buf (struct pipe_inode_info * pipe , struct pipe_buffer * buf ,
792- struct splice_desc * sd )
793- {
794- int ret ;
795- void * data ;
796- loff_t tmp = sd -> pos ;
797-
798- data = kmap (buf -> page );
799- ret = __kernel_write (sd -> u .file , data + buf -> offset , sd -> len , & tmp );
800- kunmap (buf -> page );
801-
802- return ret ;
803- }
804-
805- static ssize_t default_file_splice_write (struct pipe_inode_info * pipe ,
806- struct file * out , loff_t * ppos ,
807- size_t len , unsigned int flags )
808- {
809- ssize_t ret ;
810-
811- ret = splice_from_pipe (pipe , out , ppos , len , flags , write_pipe_buf );
812- if (ret > 0 )
813- * ppos += ret ;
814-
815- return ret ;
816- }
817-
818708/**
819709 * generic_splice_sendpage - splice data from a pipe to a socket
820710 * @pipe: pipe to splice from
@@ -836,15 +726,23 @@ ssize_t generic_splice_sendpage(struct pipe_inode_info *pipe, struct file *out,
836726
837727EXPORT_SYMBOL (generic_splice_sendpage );
838728
729+ static int warn_unsupported (struct file * file , const char * op )
730+ {
731+ pr_debug_ratelimited (
732+ "splice %s not supported for file %pD4 (pid: %d comm: %.20s)\n" ,
733+ op , file , current -> pid , current -> comm );
734+ return - EINVAL ;
735+ }
736+
839737/*
840738 * Attempt to initiate a splice from pipe to file.
841739 */
842740static long do_splice_from (struct pipe_inode_info * pipe , struct file * out ,
843741 loff_t * ppos , size_t len , unsigned int flags )
844742{
845- if (out -> f_op -> splice_write )
846- return out -> f_op -> splice_write ( pipe , out , ppos , len , flags );
847- return default_file_splice_write (pipe , out , ppos , len , flags );
743+ if (unlikely (! out -> f_op -> splice_write ) )
744+ return warn_unsupported ( out , "write" );
745+ return out -> f_op -> splice_write (pipe , out , ppos , len , flags );
848746}
849747
850748/*
@@ -866,9 +764,9 @@ static long do_splice_to(struct file *in, loff_t *ppos,
866764 if (unlikely (len > MAX_RW_COUNT ))
867765 len = MAX_RW_COUNT ;
868766
869- if (in -> f_op -> splice_read )
870- return in -> f_op -> splice_read (in , ppos , pipe , len , flags );
871- return default_file_splice_read (in , ppos , pipe , len , flags );
767+ if (unlikely (! in -> f_op -> splice_read ) )
768+ return warn_unsupported (in , "read" );
769+ return in -> f_op -> splice_read (in , ppos , pipe , len , flags );
872770}
873771
874772/**
0 commit comments