From mboxrd@z Thu Jan 1 00:00:00 1970 From: Changli Gao Subject: [PATCH 2/3] splice: allow non-block splice only when in file is seekable Date: Wed, 26 May 2010 17:56:08 +0800 Message-ID: <1274867768-3011-1-git-send-email-xiaosuo@gmail.com> Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Changli Gao To: Alexander Viro Return-path: Received: from mail-pv0-f174.google.com ([74.125.83.174]:53695 "EHLO mail-pv0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932728Ab0EZJ4u (ORCPT ); Wed, 26 May 2010 05:56:50 -0400 Sender: linux-fsdevel-owner@vger.kernel.org List-ID: allow non-block splice only when in file is seekable. do_splice_to() is split to two parts: read data from in file to spd, and move data from spd to pipe. If there isn't much space in pipe for the data in spd, and the splice is called with non-block flag, the data dropped due to non enough space in pipe will be lost forever when in file isn't seekable. Signed-off-by: Changli Gao ---- fs/splice.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/splice.c b/fs/splice.c index 9e52de5..8137e23 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -1346,8 +1346,12 @@ static long do_splice(struct file *in, loff_t __user *off_in, if (copy_from_user(&offset, off_in, sizeof(loff_t))) return -EFAULT; off = &offset; - } else + } else { + if ((flags & SPLICE_F_NONBLOCK) && + !(in->f_mode & FMODE_PREAD)) + return -EINVAL; off = &in->f_pos; + } ret = do_splice_to(in, off, opipe, len, flags);