Received: by 10.223.164.202 with SMTP id h10csp1252473wrb; Sun, 26 Nov 2017 23:21:50 -0800 (PST) X-Google-Smtp-Source: AGs4zMZonaFD05Gc+fkaMN2S5n7saCgqvviiO6aJYInXiwnfZX9oszIGBfUdlHjBCp9Nen/cj6/F X-Received: by 10.99.166.18 with SMTP id t18mr35829033pge.252.1511767309967; Sun, 26 Nov 2017 23:21:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511767309; cv=none; d=google.com; s=arc-20160816; b=ekzEUWEbs+f8lFuaUHUytq5hFEexeqnp5XoKHACL879mVOBGKx28GGd+m+xCo7Qld9 a7jawgfdplf+5UhZ6haj963Qhb5awyPUdw89N9OOo9L3av5Q0FwQBkJe4r8/+wTw3YSX 41WuRLvgrCdjXK8EK7YWEOi6jS3P7P6qdBViN67lVZP0yoB7WPnMMT5vAgmEMTUPpX7J dP7yl68LXbHfTekEITTSwGeCJngfx6vlVCnta5rNOJct/KoPB4CkrKPsGcV+QXEnwGdO /IPFLCS1LWMPEiGAp78jHG9zPxiQCeNJydLNsiGdb+tdxwskFuDaAiPnGZs7xrZd7RrJ mUXA== 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=h+o6MZlTPTJbQnXm5s1/0tfc+8ZiXLB+k+sK8Vvw3BIgxEM/h1jeBFOX5CDVOm2I4G JQi8drzjyfxEg+nIg6MxRffffI7o7b4Iz1AZU48dbk03WG4/pvMz0NRAVMYRRVjLYWn5 1vK5uJAfJXVxrVBFKvx0E9YHzWRNySemh7bsftbNO1SikoZ4d+110qqAwaIBypw8bGwS tIYZ0c4mDkXxjwS5He6eCAPmdXXiS2y74Q5GXNYG4zAfOWgP2/M70SuoWTo2UxjpBU6L mqG7ErQ0TElHMJPamwEB+cvKs/ONakosyo+G2ZWj3xjubOLmdD+g8AvgHV89yDv7vEfa Rgkg== 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 q75si24642478pfg.61.2017.11.26.23.21.37; Sun, 26 Nov 2017 23:21:49 -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 S1751590AbdK0HUC (ORCPT + 78 others); Mon, 27 Nov 2017 02:20:02 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:50478 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751266AbdK0HT4 (ORCPT ); Mon, 27 Nov 2017 02:19:56 -0500 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAR7IlOl078291 for ; Mon, 27 Nov 2017 02:19:56 -0500 Received: from e06smtp12.uk.ibm.com (e06smtp12.uk.ibm.com [195.75.94.108]) by mx0a-001b2d01.pphosted.com with ESMTP id 2egawdftv6-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 27 Nov 2017 02:19:55 -0500 Received: from localhost by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 27 Nov 2017 07:19:53 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 27 Nov 2017 07:19:48 -0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAR7JmRg41549936; Mon, 27 Nov 2017 07:19:48 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BFFB1A4040; Mon, 27 Nov 2017 07:14:22 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A9BDBA4051; Mon, 27 Nov 2017 07:14:20 +0000 (GMT) Received: from rapoport-lnx (unknown [9.148.8.170]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Mon, 27 Nov 2017 07:14:20 +0000 (GMT) Received: by rapoport-lnx (sSMTP sendmail emulation); Mon, 27 Nov 2017 09:19:45 +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 , Greg KH , Andrei Vagin , Mike Rapoport Subject: [PATCH v4 1/4] fs/splice: introduce pages_to_pipe helper Date: Mon, 27 Nov 2017 09:19:38 +0200 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511767181-22793-1-git-send-email-rppt@linux.vnet.ibm.com> References: <1511767181-22793-1-git-send-email-rppt@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17112707-0008-0000-0000-000004AFDBAE X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17112707-0009-0000-0000-00001E42B226 Message-Id: <1511767181-22793-2-git-send-email-rppt@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-11-27_04:,, 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=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711270102 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 1585274259226834705@xxx Tue Nov 28 02:15:45 +0000 2017 X-GM-THRID: 1585274259226834705 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread