From patchwork Wed Sep 14 08:37:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 9330891 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AC1336077F for ; Wed, 14 Sep 2016 08:38:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D24829B67 for ; Wed, 14 Sep 2016 08:38:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9226F29B6B; Wed, 14 Sep 2016 08:38:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3B7C229B67 for ; Wed, 14 Sep 2016 08:38:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761226AbcINIig (ORCPT ); Wed, 14 Sep 2016 04:38:36 -0400 Received: from mail-wm0-f44.google.com ([74.125.82.44]:34955 "EHLO mail-wm0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761223AbcINIhg (ORCPT ); Wed, 14 Sep 2016 04:37:36 -0400 Received: by mail-wm0-f44.google.com with SMTP id i130so35538319wmf.0 for ; Wed, 14 Sep 2016 01:37:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=HvH+gKz7/t7VJb2y8CO64rxSsrEJ2+jSWOWtgYSdwqY=; b=eXPtg+KjZTlAzjTm59bUVP0caDn3q96HgssU2yRHn760aIVGRTtzExP3yrTnYjWtwQ ZtY6ss/4vZIZYHukepUQjjEUnFnsDQqYmSgRWSSIvdhdJMW8I4j+PUYkIEzV/Iw3fXlk g5COTx5ShYxjhSqQUKCVn8tu1OS1wrJB2UonCoK8Y0hd/6ToUu0jRAkFXZwyi1ETQXOr 233NyXu8m4+6iImUZEJGSAWizq3tsOCnhMSzEwrGzYoZ2S179CvqsnZ73BN80MHty94Y bRynLEK9Z6Qp4OszgtAQXXgFK6tKZ4K0Ls89ZhJDbLpf6ctx73rmpibDRSR3AL7YCUpq FIDA== X-Gm-Message-State: AE9vXwOnseNQ2M0Rc5aQyhvkYJGC0/XWMg8YgWo5/5OTzMK5tmDZJ8TK9j7BNdCXmzXhT87Q X-Received: by 10.28.234.16 with SMTP id i16mr8854469wmh.76.1473842254769; Wed, 14 Sep 2016 01:37:34 -0700 (PDT) Received: from veci.piliscsaba.szeredi.hu (pool-dsl-2c-0018.externet.hu. [217.173.44.24]) by smtp.gmail.com with ESMTPSA id g184sm9533889wme.15.2016.09.14.01.37.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Sep 2016 01:37:33 -0700 (PDT) From: Miklos Szeredi To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Al Viro Subject: [PATCH 11/11] splice: fold __generic_file_splice_read() into caller Date: Wed, 14 Sep 2016 10:37:16 +0200 Message-Id: <1473842236-28655-12-git-send-email-mszeredi@redhat.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1473842236-28655-1-git-send-email-mszeredi@redhat.com> References: <1473842236-28655-1-git-send-email-mszeredi@redhat.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP generic_file_splice_read() does so little that it makes no sense to keep __generic_file_splice_read() a separate function. Signed-off-by: Miklos Szeredi --- fs/splice.c | 70 +++++++++++++++++++++++++------------------------------------ 1 file changed, 29 insertions(+), 41 deletions(-) diff --git a/fs/splice.c b/fs/splice.c index bee282803ccf..395cbb6b4926 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -260,17 +260,30 @@ void splice_shrink_spd(struct splice_pipe_desc *spd) kfree(spd->partial); } -static int -__generic_file_splice_read(struct file *in, loff_t *ppos, - struct pipe_inode_info *pipe, size_t len, - unsigned int flags) +/** + * generic_file_splice_read - splice data from file to a pipe + * @in: file to splice from + * @ppos: position in @in + * @pipe: pipe to splice to + * @len: number of bytes to splice + * @flags: splice modifier flags + * + * Description: + * Will read pages from given file and fill them into a pipe. Can be + * used as long as the address_space operations for the source implements + * a readpage() hook. + * + */ +ssize_t generic_file_splice_read(struct file *in, loff_t *ppos, + struct pipe_inode_info *pipe, size_t len, + unsigned int flags) { unsigned int loff, nr_pages, req_pages; struct page *pages[PIPE_DEF_BUFFERS]; struct partial_page partial[PIPE_DEF_BUFFERS]; struct page *page; pgoff_t index; - int error; + int ret = 0; struct splice_pipe_desc spd = { .pages = pages, .partial = partial, @@ -280,6 +293,9 @@ __generic_file_splice_read(struct file *in, loff_t *ppos, .spd_release = spd_release_page, }; + if (IS_DAX(in->f_mapping->host)) + return default_file_splice_read(in, ppos, pipe, len, flags); + if (splice_grow_spd(pipe, &spd)) return -ENOMEM; @@ -288,62 +304,34 @@ __generic_file_splice_read(struct file *in, loff_t *ppos, req_pages = (len + loff + PAGE_SIZE - 1) >> PAGE_SHIFT; nr_pages = min(req_pages, spd.nr_pages_max); - error = 0; while (spd.nr_pages < nr_pages && len) { - long ret; + int nr; - ret = get_page_for_read(in, loff, len, index, &page); - if (ret <= 0) { - error = ret; + nr = get_page_for_read(in, loff, len, index, &page); + if (nr <= 0) { + ret = nr; break; } spd.pages[spd.nr_pages] = page; spd.partial[spd.nr_pages].offset = loff; - spd.partial[spd.nr_pages].len = ret; + spd.partial[spd.nr_pages].len = nr; spd.nr_pages++; index++; - len -= ret; + len -= nr; loff = 0; } in->f_ra.prev_pos = (loff_t)index << PAGE_SHIFT; if (spd.nr_pages) - error = splice_to_pipe(pipe, &spd); - - splice_shrink_spd(&spd); - return error; -} - -/** - * generic_file_splice_read - splice data from file to a pipe - * @in: file to splice from - * @ppos: position in @in - * @pipe: pipe to splice to - * @len: number of bytes to splice - * @flags: splice modifier flags - * - * Description: - * Will read pages from given file and fill them into a pipe. Can be - * used as long as the address_space operations for the source implements - * a readpage() hook. - * - */ -ssize_t generic_file_splice_read(struct file *in, loff_t *ppos, - struct pipe_inode_info *pipe, size_t len, - unsigned int flags) -{ - int ret; - - if (IS_DAX(in->f_mapping->host)) - return default_file_splice_read(in, ppos, pipe, len, flags); + ret = splice_to_pipe(pipe, &spd); - ret = __generic_file_splice_read(in, ppos, pipe, len, flags); if (ret > 0) { *ppos += ret; file_accessed(in); } + splice_shrink_spd(&spd); return ret; }