Received: by 10.223.164.202 with SMTP id h10csp574057wrb; Wed, 22 Nov 2017 11:40:26 -0800 (PST) X-Google-Smtp-Source: AGs4zMYZWEMWmahEx9co/a8H4plVKrHdtMNrUr5f57XMCqYeUPUPKgw8jcwsVSm6eDpW3s1dXUBD X-Received: by 10.99.126.93 with SMTP id o29mr21826287pgn.304.1511379626513; Wed, 22 Nov 2017 11:40:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511379626; cv=none; d=google.com; s=arc-20160816; b=ENGG1mkdVev6k3n4uizOJFXqV6f7x4hJwMrVf4aGkvzTOwdPmu5ckdw/jtbUh8ZVK0 sb1Lb8UbmGJHBb8loxHwa9Xa9a9QC+At6U7D1ee33WSno7DNdYh3aAnWwJP5KcUHY5Hj y6ueE/5iK6CszAutYjoPoDDwDaiQV3T/3RQRsoI9Iu/sdzkvy/3nUgNI6vL0CIcY5pgY oU0UD6/3Ruh0llZsmqqRxCma+kW1m3zly5fZ5yskSTumXHUvj7cpiV9r06Qft7hcFt+i +3nVe9Xv5kV5O1X+OZqnNFPmSKjtBsUGCJQf643gCFm1j570XNcnLWtCv1dPeICzh4ph EYxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from:arc-authentication-results; bh=2JorBFIxOGycBie9+q6pZbI0pknRyRTNUhyBowpx0cQ=; b=DxVyl5pCAJgwx1rEWBsSkj95zoNhjgfojcDBjwJRI2XqywM28IrrGAp+DjrpniJAW3 qW2SNnqM0k/HucCIyyPLVOiNA69XaWjWA8K2khYHIcw71JkqRsE90huPH59rNzqYP4E+ 2y9mVbS8UuMqsJd2YS+gcZ34epJQF+bDjD2fImPJCijeDYG21KV/EfDJhrFAX2Bet/Qd sIDo7BwnoczwGIv36MIszQi3a7+haw7pxdnR/2j8gA6G/O2xIAMQptYa3IUXBbua5+pf 5hAXDBSDtHbCXqf1280YlGlq1sXGqw1z/gMpJLj06cKYChoMj5w55ExTyScbvMWhVss+ nWTg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f5si14274533pgn.126.2017.11.22.11.40.15; Wed, 22 Nov 2017 11:40:26 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751797AbdKVThs (ORCPT + 77 others); Wed, 22 Nov 2017 14:37:48 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:42322 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751755AbdKVThq (ORCPT ); Wed, 22 Nov 2017 14:37:46 -0500 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAMJZMEH026223 for ; Wed, 22 Nov 2017 14:37:46 -0500 Received: from e06smtp14.uk.ibm.com (e06smtp14.uk.ibm.com [195.75.94.110]) by mx0a-001b2d01.pphosted.com with ESMTP id 2edcwugm84-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 22 Nov 2017 14:37:46 -0500 Received: from localhost by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 22 Nov 2017 19:37:43 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp14.uk.ibm.com (192.168.101.144) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 22 Nov 2017 19:37:38 -0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAMJbbF428246138; Wed, 22 Nov 2017 19:37:37 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A45054C04E; Wed, 22 Nov 2017 19:32:41 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 582034C040; Wed, 22 Nov 2017 19:32:39 +0000 (GMT) Received: from rapoport-lnx (unknown [9.148.204.194]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Wed, 22 Nov 2017 19:32:39 +0000 (GMT) Received: by rapoport-lnx (sSMTP sendmail emulation); Wed, 22 Nov 2017 21:37:34 +0200 From: Mike Rapoport To: Andrew Morton , Alexander Viro Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, criu@openvz.org, Arnd Bergmann , Pavel Emelyanov , Michael Kerrisk , Thomas Gleixner , Josh Triplett , Jann Horn , Mike Rapoport Subject: [PATCH v3 1/4] fs/splice: introduce pages_to_pipe helper Date: Wed, 22 Nov 2017 21:36:28 +0200 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511379391-988-1-git-send-email-rppt@linux.vnet.ibm.com> References: <1511379391-988-1-git-send-email-rppt@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17112219-0016-0000-0000-000005047AE5 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17112219-0017-0000-0000-000028404D14 Message-Id: <1511379391-988-2-git-send-email-rppt@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-11-22_05:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711220258 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Mike Rapoport --- fs/splice.c | 57 ++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/fs/splice.c b/fs/splice.c index 39e2dc0..7f1ffc5 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -1185,6 +1185,36 @@ static long do_splice(struct file *in, loff_t __user *off_in, return -EINVAL; } +static int pages_to_pipe(struct page **pages, struct pipe_inode_info *pipe, + struct pipe_buffer *buf, size_t *total, + ssize_t copied, size_t start) +{ + bool failed = false; + size_t len = 0; + int ret = 0; + int n; + + for (n = 0; copied; n++, start = 0) { + int size = min_t(int, copied, PAGE_SIZE - start); + if (!failed) { + buf->page = pages[n]; + buf->offset = start; + buf->len = size; + ret = add_to_pipe(pipe, buf); + if (unlikely(ret < 0)) + failed = true; + else + len += ret; + } else { + put_page(pages[n]); + } + copied -= size; + } + + *total += len; + return failed ? ret : len; +} + static int iter_to_pipe(struct iov_iter *from, struct pipe_inode_info *pipe, unsigned flags) @@ -1195,13 +1225,11 @@ static int iter_to_pipe(struct iov_iter *from, }; size_t total = 0; int ret = 0; - bool failed = false; - while (iov_iter_count(from) && !failed) { + while (iov_iter_count(from)) { struct page *pages[16]; ssize_t copied; size_t start; - int n; copied = iov_iter_get_pages(from, pages, ~0UL, 16, &start); if (copied <= 0) { @@ -1209,24 +1237,11 @@ static int iter_to_pipe(struct iov_iter *from, break; } - for (n = 0; copied; n++, start = 0) { - int size = min_t(int, copied, PAGE_SIZE - start); - if (!failed) { - buf.page = pages[n]; - buf.offset = start; - buf.len = size; - ret = add_to_pipe(pipe, &buf); - if (unlikely(ret < 0)) { - failed = true; - } else { - iov_iter_advance(from, ret); - total += ret; - } - } else { - put_page(pages[n]); - } - copied -= size; - } + ret = pages_to_pipe(pages, pipe, &buf, &total, copied, start); + if (unlikely(ret < 0)) + break; + + iov_iter_advance(from, ret); } return total ? total : ret; } -- 2.7.4 From 1584809245880816893@xxx Wed Nov 22 23:04:34 +0000 2017 X-GM-THRID: 1584809245880816893 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread