From nobody Wed Sep 10 11:01:39 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4209EC77B7F for ; Fri, 19 May 2023 07:43:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231437AbjESHnu (ORCPT ); Fri, 19 May 2023 03:43:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231329AbjESHnB (ORCPT ); Fri, 19 May 2023 03:43:01 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A680710DF for ; Fri, 19 May 2023 00:42:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482122; 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=r5qDgkT4BMNnpU06yXa6htF6MTIyeI5iJgctjYsdWto=; b=Y0ycKK5T6mVqGYUc5QLGVd2+jHvV9iK/dLjQ6P/eQEy6BptA3gjSe9YoDu/eeiIKtRMP5J /oCfVw2PqeEg/Ghg636pegW2kEwH9huZifPtyTFmsRjSeh76byiHrNb3nyz+K9P6J+JPhY kYZTG1EsfMXPmVpCBlTzerWxyi95Cm0= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-636-UwmqYBTZNaOSEg7543TOgw-1; Fri, 19 May 2023 03:41:56 -0400 X-MC-Unique: UwmqYBTZNaOSEg7543TOgw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ABE8E1C04B50; Fri, 19 May 2023 07:41:55 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 367671121314; Fri, 19 May 2023 07:41:53 +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 , Jaegeuk Kim , Chao Yu , linux-f2fs-devel@lists.sourceforge.net Subject: [PATCH v20 16/32] f2fs: Provide a splice-read stub Date: Fri, 19 May 2023 08:40:31 +0100 Message-Id: <20230519074047.1739879-17-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Provide a splice_read stub for f2fs. This does some checks and tracing before proceeding and will switch from direct-I/O to buffered I/O if forced or if misaligned. It also updates the iostats after doing a buffered I/O. [Note: I wonder if I should only do the tracing if I call filemap_splice_read() as direct_splice_read() will call f2fs_file_read_iter().] Signed-off-by: David Howells cc: Christoph Hellwig cc: Al Viro cc: Jens Axboe cc: Jaegeuk Kim cc: Chao Yu cc: linux-f2fs-devel@lists.sourceforge.net cc: linux-fsdevel@vger.kernel.org cc: linux-block@vger.kernel.org cc: linux-mm@kvack.org --- fs/f2fs/file.c | 68 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 8 deletions(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 5ac53d2627d2..3723387f4a87 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -4367,22 +4367,23 @@ static ssize_t f2fs_dio_read_iter(struct kiocb *ioc= b, struct iov_iter *to) return ret; } =20 -static void f2fs_trace_rw_file_path(struct kiocb *iocb, size_t count, int = rw) +static void f2fs_trace_rw_file_path(struct file *file, loff_t pos, size_t = count, + int rw) { - struct inode *inode =3D file_inode(iocb->ki_filp); + struct inode *inode =3D file_inode(file); char *buf, *path; =20 buf =3D f2fs_getname(F2FS_I_SB(inode)); if (!buf) return; - path =3D dentry_path_raw(file_dentry(iocb->ki_filp), buf, PATH_MAX); + path =3D dentry_path_raw(file_dentry(file), buf, PATH_MAX); if (IS_ERR(path)) goto free_buf; if (rw =3D=3D WRITE) - trace_f2fs_datawrite_start(inode, iocb->ki_pos, count, + trace_f2fs_datawrite_start(inode, pos, count, current->pid, path, current->comm); else - trace_f2fs_dataread_start(inode, iocb->ki_pos, count, + trace_f2fs_dataread_start(inode, pos, count, current->pid, path, current->comm); free_buf: f2fs_putname(buf); @@ -4398,7 +4399,8 @@ static ssize_t f2fs_file_read_iter(struct kiocb *iocb= , struct iov_iter *to) return -EOPNOTSUPP; =20 if (trace_f2fs_dataread_start_enabled()) - f2fs_trace_rw_file_path(iocb, iov_iter_count(to), READ); + f2fs_trace_rw_file_path(iocb->ki_filp, iocb->ki_pos, + iov_iter_count(to), READ); =20 if (f2fs_should_use_dio(inode, iocb, to)) { ret =3D f2fs_dio_read_iter(iocb, to); @@ -4413,6 +4415,55 @@ static ssize_t f2fs_file_read_iter(struct kiocb *ioc= b, struct iov_iter *to) return ret; } =20 +static ssize_t f2fs_file_splice_read(struct file *in, loff_t *ppos, + struct pipe_inode_info *pipe, + size_t len, unsigned int flags) +{ + struct inode *inode =3D file_inode(in); + const loff_t pos =3D *ppos; + ssize_t ret; + + if (!f2fs_is_compress_backend_ready(inode)) + return -EOPNOTSUPP; + + if (trace_f2fs_dataread_start_enabled()) + f2fs_trace_rw_file_path(in, pos, len, READ); + + if (in->f_flags & O_DIRECT) { + if (f2fs_force_buffered_io(inode, READ)) + goto buffered; + + /* + * Direct I/O not aligned to the disk's logical_block_size will + * be attempted, but will fail with -EINVAL. + * + * f2fs additionally requires that direct I/O be aligned to the + * filesystem block size, which is often a stricter + * requirement. However, f2fs traditionally falls back to + * buffered I/O on requests that are logical_block_size-aligned + * but not fs-block aligned. + * + * The below logic implements this behavior. + */ + if (!IS_ALIGNED(pos, i_blocksize(inode)) && + IS_ALIGNED(pos, bdev_logical_block_size(inode->i_sb->s_bdev))) + goto buffered; + ret =3D direct_splice_read(in, ppos, pipe, len, flags); + goto done; + } + +buffered: + ret =3D filemap_splice_read(in, ppos, pipe, len, flags); + if (ret > 0) + f2fs_update_iostat(F2FS_I_SB(inode), inode, + APP_BUFFERED_READ_IO, ret); + +done: + if (trace_f2fs_dataread_end_enabled()) + trace_f2fs_dataread_end(inode, pos, ret); + return ret; +} + static ssize_t f2fs_write_checks(struct kiocb *iocb, struct iov_iter *from) { struct file *file =3D iocb->ki_filp; @@ -4714,7 +4765,8 @@ static ssize_t f2fs_file_write_iter(struct kiocb *ioc= b, struct iov_iter *from) ret =3D preallocated; } else { if (trace_f2fs_datawrite_start_enabled()) - f2fs_trace_rw_file_path(iocb, orig_count, WRITE); + f2fs_trace_rw_file_path(iocb->ki_filp, iocb->ki_pos, + orig_count, WRITE); =20 /* Do the actual write. */ ret =3D dio ? @@ -4919,7 +4971,7 @@ const struct file_operations f2fs_file_operations =3D= { #ifdef CONFIG_COMPAT .compat_ioctl =3D f2fs_compat_ioctl, #endif - .splice_read =3D generic_file_splice_read, + .splice_read =3D f2fs_file_splice_read, .splice_write =3D iter_file_splice_write, .fadvise =3D f2fs_file_fadvise, };