From patchwork Fri May 19 07:40:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13247775 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 49716C77B7A for ; Fri, 19 May 2023 07:42:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CBD6490001C; Fri, 19 May 2023 03:42:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C457B900003; Fri, 19 May 2023 03:42:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A4B1490001C; Fri, 19 May 2023 03:42:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 909B1900003 for ; Fri, 19 May 2023 03:42:17 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 71105140955 for ; Fri, 19 May 2023 07:42:17 +0000 (UTC) X-FDA: 80806211514.14.823D61D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf03.hostedemail.com (Postfix) with ESMTP id B450B20013 for ; Fri, 19 May 2023 07:42:15 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GmMBN4ke; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf03.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684482135; 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=xmbbe/+Pf//AKyGpf7irbs4+/+24QQIbTBxvLgLUtSY=; b=Hkk1YlU7l4u5KDKkQRJoRhASGHTeyELDVXduD8A8T79pwJZ8egjsxc2R3UZkzis0gbvQi3 tbC2XVeqOQq8T1fgkuFczJbWLpXNaIZL5h4OKASURmcYrow72cJ0r4PBvVwXCKpJTLqMHs 6FAH0ZEJJKZubC66VXclnlmRsNKWOMs= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GmMBN4ke; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf03.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684482135; a=rsa-sha256; cv=none; b=al1t4Xhm0VufPL+z09C6ZZ+F/+7JKyBVUSES77cd6QNw46NBaNBQsD5K6AIqN88xrjuvdg PElNY6Tl+A2hnjzGl4n9rpntQtR58ndFf6qzDxkKnDvnu0zbg0QMtok60Nk3xGebmjEltX PQYg1JJLVIsXWz7vlnBpfhxUUXQDeWY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482134; 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=xmbbe/+Pf//AKyGpf7irbs4+/+24QQIbTBxvLgLUtSY=; b=GmMBN4kecnjlKfmwIz82ZBWaSD5LCcyCDe9H5JpTob09PSAjuCLkmZOlQmKo2zbnMqUuiJ I1ktkcPds7CM0//BOsSSYmMiBUepQp5HJrIFaTOtXwqFIe8lpc998lpveTKQ85WiLmqJiO r7sVQxIyklV8iWDwxvGhtHzfLCfhg6M= 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-498-MoZDh_T_MgiO891JIsJM_g-1; Fri, 19 May 2023 03:42:13 -0400 X-MC-Unique: MoZDh_T_MgiO891JIsJM_g-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 337F7101A55C; Fri, 19 May 2023 07:42:12 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id D137B492B0A; Fri, 19 May 2023 07:42:09 +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 , "Darrick J . Wong" , linux-xfs@vger.kernel.org Subject: [PATCH v20 21/32] xfs: Provide a splice-read stub Date: Fri, 19 May 2023 08:40:36 +0100 Message-Id: <20230519074047.1739879-22-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-Rspam-User: X-Stat-Signature: gawttsoyc5iye47jj3skhck5etoeziao X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: B450B20013 X-HE-Tag: 1684482135-964277 X-HE-Meta: U2FsdGVkX1/vHjh/pW5IzdwZ8ACLr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0i66rercJHEeYaOSnBqoGvrepROx7Qks5lvcLPpb5GVxKM6s32fsDD4UCZe0MZ4kHnmlas1xzV9nMq2kB8K8yqMQ46Gl/RdbKtpZLRHioSfHJNZORY2tCf/MG4QmQeSly36rgJ+eBetuRT4jS4MmpkD6EOYkZZ1zM5d5g+ukftdSCvfDviR2BRk1WjF7/pHzxpiuldBvK520smI6e/DqZv/aoWEIs0WACn2h+sV7h5s3iwJM4a 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: Provide a splice_read stub for XFS. This does a stat count and a shutdown check before proceeding. For buffered I/O, it emits a new trace line and locks the inode across the call to filemap_splice_read() and adds to the stats afterwards. Splicing from DAX files either copies the data into a buffer (DIO) or splices from the pagecache. Signed-off-by: David Howells cc: Christoph Hellwig cc: Al Viro cc: Jens Axboe cc: Darrick J. Wong cc: linux-xfs@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-block@vger.kernel.org cc: linux-mm@kvack.org --- fs/xfs/xfs_file.c | 33 ++++++++++++++++++++++++++++++++- fs/xfs/xfs_trace.h | 2 +- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index aede746541f8..bb1ec755a709 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -306,6 +306,37 @@ xfs_file_read_iter( return ret; } +STATIC ssize_t +xfs_file_splice_read( + struct file *in, + loff_t *ppos, + struct pipe_inode_info *pipe, + size_t len, + unsigned int flags) +{ + struct inode *inode = file_inode(in); + struct xfs_inode *ip = XFS_I(inode); + struct xfs_mount *mp = ip->i_mount; + ssize_t ret = 0; + + XFS_STATS_INC(mp, xs_read_calls); + + if (xfs_is_shutdown(mp)) + return -EIO; + + if (in->f_flags & O_DIRECT) + return direct_splice_read(in, ppos, pipe, len, flags); + + trace_xfs_file_splice_read(ip, *ppos, len); + + xfs_ilock(ip, XFS_IOLOCK_SHARED); + ret = filemap_splice_read(in, ppos, pipe, len, flags); + xfs_iunlock(ip, XFS_IOLOCK_SHARED); + if (ret > 0) + XFS_STATS_ADD(mp, xs_read_bytes, ret); + return ret; +} + /* * Common pre-write limit and setup checks. * @@ -1423,7 +1454,7 @@ const struct file_operations xfs_file_operations = { .llseek = xfs_file_llseek, .read_iter = xfs_file_read_iter, .write_iter = xfs_file_write_iter, - .splice_read = generic_file_splice_read, + .splice_read = xfs_file_splice_read, .splice_write = iter_file_splice_write, .iopoll = iocb_bio_iopoll, .unlocked_ioctl = xfs_file_ioctl, diff --git a/fs/xfs/xfs_trace.h b/fs/xfs/xfs_trace.h index cd4ca5b1fcb0..4db669203149 100644 --- a/fs/xfs/xfs_trace.h +++ b/fs/xfs/xfs_trace.h @@ -1445,7 +1445,6 @@ DEFINE_RW_EVENT(xfs_file_direct_write); DEFINE_RW_EVENT(xfs_file_dax_write); DEFINE_RW_EVENT(xfs_reflink_bounce_dio_write); - DECLARE_EVENT_CLASS(xfs_imap_class, TP_PROTO(struct xfs_inode *ip, xfs_off_t offset, ssize_t count, int whichfork, struct xfs_bmbt_irec *irec), @@ -1535,6 +1534,7 @@ DEFINE_SIMPLE_IO_EVENT(xfs_zero_eof); DEFINE_SIMPLE_IO_EVENT(xfs_end_io_direct_write); DEFINE_SIMPLE_IO_EVENT(xfs_end_io_direct_write_unwritten); DEFINE_SIMPLE_IO_EVENT(xfs_end_io_direct_write_append); +DEFINE_SIMPLE_IO_EVENT(xfs_file_splice_read); DECLARE_EVENT_CLASS(xfs_itrunc_class, TP_PROTO(struct xfs_inode *ip, xfs_fsize_t new_size),