From patchwork Mon May 22 13:50:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13250603 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 DC822C7EE29 for ; Mon, 22 May 2023 13:52:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B0DCF900006; Mon, 22 May 2023 09:52:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AC27D28000D; Mon, 22 May 2023 09:52:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7B301900006; Mon, 22 May 2023 09:52:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 6728428000D for ; Mon, 22 May 2023 09:52:02 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 436A3A01E5 for ; Mon, 22 May 2023 13:52:02 +0000 (UTC) X-FDA: 80818029684.16.595D960 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 657D3A000E for ; Mon, 22 May 2023 13:51:59 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NCpiZNvf; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf15.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=1684763519; 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=WTfdYshb2SEJ7i+Rhr+GK9rq0gZ3nIJZ8Q96oyv400s=; b=8N/6c5G5PgwZUMjvZ/8roWuPb0uXsqscN9JVnolziia6xKStPc1Sd6kjFtjYvcfJGuJHBk zu12XzLfqS9ff92Xz6j5m8EG1aKAhlATHBq6mL00Zec9g3uLI4MNZ79LkkLMaJVwQE7wxx qTgm58bVf45rJaYuboTjlvCAB4P670o= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NCpiZNvf; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf15.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=1684763519; a=rsa-sha256; cv=none; b=J4EYt9EbB1rFglyO4Sx29Smb/OzuUbU7RjsGzfvyI/Uje3Sw/hQ91Ei0rme2yRJGFw3Qab T3wATLTHiXD2XhXxNoAnGXoFhQ4TRFSlAz1dRLfZ1lvpo/7luLqiXq8C+knri8xKnXlB5J bZGAsPk6nhtQX/l1IVx1d3I2AC33uP8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684763518; 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=WTfdYshb2SEJ7i+Rhr+GK9rq0gZ3nIJZ8Q96oyv400s=; b=NCpiZNvfK/g2Wp6M5Wd2td/2uTMCV5f9UR1kRF9SbqG+lL0xSDuzR3N2DY72fZU9iupiDa 7j9zXPiMbyrRVKX0nhqRvkVx3tA9wI8XnjFPOnWtU5NVRwRlEE4fU9owXscHs5k9gSMZ1P I6TeE00ytsNmNXF+zah9w4Nl+2pqong= 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-610-VqXNS97OMu6rkAXf15s6Mg-1; Mon, 22 May 2023 09:51:53 -0400 X-MC-Unique: VqXNS97OMu6rkAXf15s6Mg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 684713C025AD; Mon, 22 May 2023 13:51:52 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 43402400F17; Mon, 22 May 2023 13:51:49 +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, Joseph Qi , Christoph Hellwig , Mark Fasheh , Joel Becker , ocfs2-devel@oss.oracle.com Subject: [PATCH v22 22/31] ocfs2: Provide a splice-read wrapper Date: Mon, 22 May 2023 14:50:09 +0100 Message-Id: <20230522135018.2742245-23-dhowells@redhat.com> In-Reply-To: <20230522135018.2742245-1-dhowells@redhat.com> References: <20230522135018.2742245-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Rspamd-Queue-Id: 657D3A000E X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 1ia9gyfe46i99ofcuqujoujob1bshnrs X-HE-Tag: 1684763519-723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2SfzVHgkjnny4Kps7L6kMUV0GdX4k9OG8DoPQ1xT3xbsfB8//JHyEgYKxlRS9i6ZsS/f+fJ7RF4eI+2XGxTyslBr6Sgt/0rUYG5PQawwl4A86KmGG8T3PukXqgLpdejXGPO8wbTZ9l5OJG5+gLKZHyupSaey5I+1/DvRb/L3s6WqjR1uw+dxGSx+qNqaKAXO1ASdCQsS1Oc0z7vRAQxX57J1uRJeYBGrGbn7wD2+AeenlCjRjeA45tGADzkmKtBdYiodbxgD+rs01A4LHF4HurYbIppOAYRKUR37LWOZSYx6ULOyswDQn4Qqm3YHiPE71JPwNfviRtClgeFZZDV8CZqh2qD31fb3all2cst+sNZOhE7OGgK4RnrNo55RlUKiMFclzAUAuRoK3agITleh9wa4rhsy+4cp3OhztRtcg2cl1WoPLiGrqUHATdQ= 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 wrapper for ocfs2. This emits trace lines and does an atime lock/update before calling filemap_splice_read(). Splicing from direct I/O is handled by the caller. A couple of new tracepoints are added for this purpose. Signed-off-by: David Howells Reviewed-by: Joseph Qi cc: Christoph Hellwig cc: Al Viro cc: Jens Axboe cc: Mark Fasheh cc: Joel Becker cc: ocfs2-devel@oss.oracle.com cc: linux-fsdevel@vger.kernel.org cc: linux-block@vger.kernel.org cc: linux-mm@kvack.org --- Notes: ver #22: - Adjust a couple of comments mentioning generic_file_splice_read(). - Pass 1 to ocfs2_inode_lock_atomic() rather than true. - Pass the splice flags into the tracepoint. fs/ocfs2/file.c | 41 +++++++++++++++++++++++++++++++++++++++-- fs/ocfs2/ocfs2_trace.h | 3 +++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c index efb09de4343d..86add13b5f23 100644 --- a/fs/ocfs2/file.c +++ b/fs/ocfs2/file.c @@ -2552,7 +2552,7 @@ static ssize_t ocfs2_file_read_iter(struct kiocb *iocb, * * Take and drop the meta data lock to update inode fields * like i_size. This allows the checks down below - * generic_file_read_iter() a chance of actually working. + * copy_splice_read() a chance of actually working. */ ret = ocfs2_inode_lock_atime(inode, filp->f_path.mnt, &lock_level, !nowait); @@ -2581,6 +2581,43 @@ static ssize_t ocfs2_file_read_iter(struct kiocb *iocb, return ret; } +static ssize_t ocfs2_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); + ssize_t ret = 0; + int lock_level = 0; + + trace_ocfs2_file_splice_read(inode, in, in->f_path.dentry, + (unsigned long long)OCFS2_I(inode)->ip_blkno, + in->f_path.dentry->d_name.len, + in->f_path.dentry->d_name.name, + flags); + + /* + * We're fine letting folks race truncates and extending writes with + * read across the cluster, just like they can locally. Hence no + * rw_lock during read. + * + * Take and drop the meta data lock to update inode fields like i_size. + * This allows the checks down below filemap_splice_read() a chance of + * actually working. + */ + ret = ocfs2_inode_lock_atime(inode, in->f_path.mnt, &lock_level, 1); + if (ret < 0) { + if (ret != -EAGAIN) + mlog_errno(ret); + goto bail; + } + ocfs2_inode_unlock(inode, lock_level); + + ret = filemap_splice_read(in, ppos, pipe, len, flags); + trace_filemap_splice_read_ret(ret); +bail: + return ret; +} + /* Refer generic_file_llseek_unlocked() */ static loff_t ocfs2_file_llseek(struct file *file, loff_t offset, int whence) { @@ -2744,7 +2781,7 @@ const struct file_operations ocfs2_fops = { #endif .lock = ocfs2_lock, .flock = ocfs2_flock, - .splice_read = generic_file_splice_read, + .splice_read = ocfs2_file_splice_read, .splice_write = iter_file_splice_write, .fallocate = ocfs2_fallocate, .remap_file_range = ocfs2_remap_file_range, diff --git a/fs/ocfs2/ocfs2_trace.h b/fs/ocfs2/ocfs2_trace.h index dc4bce1649c1..b8c3d1702076 100644 --- a/fs/ocfs2/ocfs2_trace.h +++ b/fs/ocfs2/ocfs2_trace.h @@ -1319,6 +1319,8 @@ DEFINE_OCFS2_FILE_OPS(ocfs2_file_splice_write); DEFINE_OCFS2_FILE_OPS(ocfs2_file_read_iter); +DEFINE_OCFS2_FILE_OPS(ocfs2_file_splice_read); + DEFINE_OCFS2_ULL_ULL_ULL_EVENT(ocfs2_truncate_file); DEFINE_OCFS2_ULL_ULL_EVENT(ocfs2_truncate_file_error); @@ -1470,6 +1472,7 @@ TRACE_EVENT(ocfs2_prepare_inode_for_write, ); DEFINE_OCFS2_INT_EVENT(generic_file_read_iter_ret); +DEFINE_OCFS2_INT_EVENT(filemap_splice_read_ret); /* End of trace events for fs/ocfs2/file.c. */