From patchwork Sat May 20 00:00:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13249005 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 62442C77B7A for ; Sat, 20 May 2023 00:02:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A8850280011; Fri, 19 May 2023 20:02:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C440280001; Fri, 19 May 2023 20:02:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 81668280011; Fri, 19 May 2023 20:02:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 63995280001 for ; Fri, 19 May 2023 20:02:17 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 3EA0A12083C for ; Sat, 20 May 2023 00:02:17 +0000 (UTC) X-FDA: 80808681114.20.7E8B3A4 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 8A96816001F for ; Sat, 20 May 2023 00:02:14 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="Zol/mVEi"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.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=1684540934; 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=+ZeMoJ3W4+8Si0O+3M8rAaXW1eupuLZDs/fqA89KAPE=; b=2do0shLPbdcGaE/TAgoLiy7pV6Na8BdFxu2Gg8mNQ3T6FxU4rU1KSTjc6Z5XC5r0EZ3l14 n8ev97rTYFbZp8THb3aqB8qhnDWQFEXrgCLz+dKI6bf33rLdo0nmhvW4mIWnvddk+cRyEi h+7ptrLtSfvQ7yrYPpzau+mfVBPNxf0= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="Zol/mVEi"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684540934; a=rsa-sha256; cv=none; b=lSfUx/MJmMaBYgDvPGL+Ne9UJA5xuIZPDdnztUZQYDXAmtKHQ/xWGcV6VjWdFiZKXPrQBN pKWcMwpQruqCnnKCJBwwBM1dw/Qb+ln58zu3B+S927sxQ82WxK8Nf7hJIcx1emw6nzSP/1 S0Y8o+pZJEtfzKnTYGYUc8vIm6OM7yE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684540933; 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=+ZeMoJ3W4+8Si0O+3M8rAaXW1eupuLZDs/fqA89KAPE=; b=Zol/mVEiDADTmjnfvCryYdUK9m3cV8zkVhiISKvYPoxCCt5aEAhVKGvqH4VBIxdRNIMagn LluxyngyAytUhCXX66J4QwrAv7OP6iIK+GHJaGEl5doiwUzg5OioA8PDZx6417OgTgtCYF jdokBsNAvQV2N4TGcn3Tbwp6ZVPpFjA= 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-411-v3noG5lZOjuaP3G1f6efug-1; Fri, 19 May 2023 20:02:03 -0400 X-MC-Unique: v3noG5lZOjuaP3G1f6efug-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8752C38035AA; Sat, 20 May 2023 00:02:02 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id E0ED440C6CD3; Sat, 20 May 2023 00:01:59 +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 , Mark Fasheh , Joel Becker , Joseph Qi , ocfs2-devel@oss.oracle.com Subject: [PATCH v21 22/30] ocfs2: Provide a splice-read stub Date: Sat, 20 May 2023 01:00:41 +0100 Message-Id: <20230520000049.2226926-23-dhowells@redhat.com> In-Reply-To: <20230520000049.2226926-1-dhowells@redhat.com> References: <20230520000049.2226926-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Rspam-User: X-Stat-Signature: sijuhdtrptnz7gekjpuizqsu1jadeywf X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 8A96816001F X-HE-Tag: 1684540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xzauNLvn7OEJd/YhwHSAIvZIAD4D3Ora5z7nTZYoBW1YHb3yPZdtUEa/6aAy6Xac6Dmg2BVizudWdoSWHrW+PhSwu9ECNQIiNYI6TQYMGGGLtJXsZGUbXi+InxgwUjc7sDu4ABwtzY0ETOkog8khNpOXKTsGduiYIjuSVJCjp9o0gnVNNZI3zo1Kp46volnQ7mW44DTzwul8gzJv7ihG2t/532yjQj3BiPDIg0cK1gE3TTQcB0pe6T08n1ubNezYgN/Jz+SO96pTggvoXlkzMu/9TgFsHJ4w5xDaG7xeWC0eusQyEvqNbY74N+WUv+3Q8cLmhepUuwohvIZ0qQunDFtmBt6e8Pra2qQ8N1tei2sdngdaIpAtAyNKtwEH7gKt1XeZGlWqMtfnePDiD3Wk5c5VqJiYLJ658VE4J8FNCTzo/RT+Bmqc5Yeaz6v5Y= 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 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 cc: Christoph Hellwig cc: Al Viro cc: Jens Axboe cc: Mark Fasheh cc: Joel Becker cc: Joseph Qi cc: ocfs2-devel@oss.oracle.com cc: linux-fsdevel@vger.kernel.org cc: linux-block@vger.kernel.org cc: linux-mm@kvack.org Reviewed-by: Joseph Qi --- fs/ocfs2/file.c | 39 ++++++++++++++++++++++++++++++++++++++- fs/ocfs2/ocfs2_trace.h | 3 +++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c index efb09de4343d..f7e00b5689d5 100644 --- a/fs/ocfs2/file.c +++ b/fs/ocfs2/file.c @@ -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, + 0); + + /* + * 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 generic_file_splice_read() a + * chance of actually working. + */ + ret = ocfs2_inode_lock_atime(inode, in->f_path.mnt, &lock_level, true); + 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. */