From patchwork Fri May 19 07:40:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13247778 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C207C77B7A for ; Fri, 19 May 2023 07:42:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C95A290001F; Fri, 19 May 2023 03:42:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C463B900003; Fri, 19 May 2023 03:42:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B0E8290001F; Fri, 19 May 2023 03:42:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 9ED19900003 for ; Fri, 19 May 2023 03:42:30 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 7569E409CF for ; Fri, 19 May 2023 07:42:30 +0000 (UTC) X-FDA: 80806212060.25.468E167 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf08.hostedemail.com (Postfix) with ESMTP id B09A2160016 for ; Fri, 19 May 2023 07:42:28 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ImHqwYuC; spf=pass (imf08.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684482148; a=rsa-sha256; cv=none; b=f5foa3udcfa0Ydx5t7KpX3IfG2WJ136ItgdsJpFMUS7FBxVcyupD6+QAOMClAz/qp2pjZR JnFGiYA+3Br40U5IXbYLaiSB8njs3u3CGTDnHdkPB5wE7q7s9ROKhIFEOwrB2hGecc5JqN rdL3giDtvBuRbqq5OxMF4FjTb2HmsbI= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ImHqwYuC; spf=pass (imf08.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684482148; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=KIPsbdoO43iq3tUvemirM6xG5g+su+9PgNJxpKHBcQ0=; b=taybhhOB26zgiswb2qcowbFHo4d1/N0uXnp+lMEROTmDi2aiWpg4M9EtNYdqiQIPENdXZv 0Sn4a1wrhXH8GcBAR2aprOC1+4lBwW52fGik7aQgTynN0AhskKDN76dZqHrbdAu0KqeWLt hDzxzpylZ4dnmm6kHKmnsKnxdYSxoHk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482148; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KIPsbdoO43iq3tUvemirM6xG5g+su+9PgNJxpKHBcQ0=; b=ImHqwYuCM6e61440x6M1EklX4wrAKsPqPDIuMT3wI5lpQf3Sy5kmLoYYQyjRk5Ll4iAyhT /dsKiYwzV4anogKQebCTP6vY54QO09vdEPs96SzJ09UzU9X1RDhhjNgMehqOpouWu2TOdL u0KaB8MDI5Tof498BWTgKpl3eGsDsiU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-581-aSvtV5ZQOk2ZrLbIVY_T4A-1; Fri, 19 May 2023 03:42:23 -0400 X-MC-Unique: aSvtV5ZQOk2ZrLbIVY_T4A-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 80C8380013A; Fri, 19 May 2023 07:42:22 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1CE32492B0A; Fri, 19 May 2023 07:42:20 +0000 (UTC) From: David Howells To: Jens Axboe , Al Viro , Christoph Hellwig Cc: David Howells , Matthew Wilcox , Jan Kara , Jeff Layton , David Hildenbrand , Jason Gunthorpe , Logan Gunthorpe , Hillf Danton , Christian Brauner , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , Steve French , John Hubbard , linux-cifs@vger.kernel.org Subject: [PATCH v20 24/32] splice: Do splice read from a file without using ITER_PIPE Date: Fri, 19 May 2023 08:40:39 +0100 Message-Id: <20230519074047.1739879-25-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: B09A2160016 X-Stat-Signature: bm64t1rnnagyhyqxh6xz7iwc8o1xn5o9 X-Rspam-User: X-HE-Tag: 1684482148-913325 X-HE-Meta: U2FsdGVkX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HspLlaRKE2OUhB8FNOLjMuLE+PAw/bUysVRr6ceM6+HOMid7Oux/dZOIrUoZ9RyGYj90QiqF/3+UPfAFskRSXRKysidH4cHXT1pewdEXEvSbG/U2SZQFUnmpA1m07e750QuERrwpgkVAGZ8Qp8yDhfrFVNuYeK8Ke5/6IMBKgDDw6Xh3hlKvj0yOF8H28k49r7RhDW5xXXxZYTuvT94xfwLB4Gx04rTR8lB+fY5fCNhK1buGBhAsdVN+ef/DvUSACwssksPg4GRpm2G38ZjwwcrlZR+lfNew0SGmICL7UOlOBn14ZoPe4ninbgcw8F2/cOYX3JBgN+tiEDYUL/v/uMJNjZs3ZL0sGfzUx4eE4ObgnZmhZ5C5I2jXlY2lskh6lw6l0hohljf5AKus7DOnVf4 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Make generic_file_splice_read() use filemap_splice_read() and direct_splice_read() rather than using an ITER_PIPE and call_read_iter(). With this, ITER_PIPE is no longer used. Signed-off-by: David Howells Reviewed-by: Christoph Hellwig cc: Jens Axboe cc: Steve French cc: Al Viro cc: David Hildenbrand cc: John Hubbard cc: linux-mm@kvack.org cc: linux-block@vger.kernel.org cc: linux-cifs@vger.kernel.org cc: linux-fsdevel@vger.kernel.org --- Notes: ver #20) - Use s_maxbytes from the backing store (in->f_mapping), not the front inode (especially for a blockdev). ver #18) - Split out the change to cifs to make it use generic_file_splice_read(). - Split out the unexport of filemap_splice_read() (still needed by cifs). fs/splice.c | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/fs/splice.c b/fs/splice.c index 7b818b5b18d4..56d9802729d0 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -417,34 +417,17 @@ ssize_t generic_file_splice_read(struct file *in, loff_t *ppos, struct pipe_inode_info *pipe, size_t len, unsigned int flags) { - struct iov_iter to; - struct kiocb kiocb; - int ret; - + if (unlikely(*ppos >= in->f_mapping->host->i_sb->s_maxbytes)) + return 0; + if (unlikely(!len)) + return 0; #ifdef CONFIG_FS_DAX if (IS_DAX(in->f_mapping->host)) return direct_splice_read(in, ppos, pipe, len, flags); #endif - - iov_iter_pipe(&to, ITER_DEST, pipe, len); - init_sync_kiocb(&kiocb, in); - kiocb.ki_pos = *ppos; - ret = call_read_iter(in, &kiocb, &to); - if (ret > 0) { - *ppos = kiocb.ki_pos; - file_accessed(in); - } else if (ret < 0) { - /* free what was emitted */ - pipe_discard_from(pipe, to.start_head); - /* - * callers of ->splice_read() expect -EAGAIN on - * "can't put anything in there", rather than -EFAULT. - */ - if (ret == -EFAULT) - ret = -EAGAIN; - } - - return ret; + if ((in->f_flags & O_DIRECT)) + return direct_splice_read(in, ppos, pipe, len, flags); + return filemap_splice_read(in, ppos, pipe, len, flags); } EXPORT_SYMBOL(generic_file_splice_read);