From patchwork Mon May 22 13:50:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13250606 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 6947FC77B73 for ; Mon, 22 May 2023 13:52:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5B8AE90000A; Mon, 22 May 2023 09:52:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 567D5900009; Mon, 22 May 2023 09:52:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 42EFD90000A; Mon, 22 May 2023 09:52:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 32F4B900009 for ; Mon, 22 May 2023 09:52:12 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 0F858160339 for ; Mon, 22 May 2023 13:52:12 +0000 (UTC) X-FDA: 80818030104.04.6A148E3 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf04.hostedemail.com (Postfix) with ESMTP id 42CEB40002 for ; Mon, 22 May 2023 13:52:10 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JnhAUDcZ; spf=pass (imf04.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=1684763530; 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=OLusLo/oJVdzYA8d4lrkdkImz1Qgxj15rb4H8i/2VAY=; b=OaclAwgnDnhF6VfFNT1wvc229iZPTVWwVudCTb01NPgboKd8I6DI/GpDq3BgXGvfCj7orp hKULJtbFaMPKaLrtvuT2gdGMS/s3lF4+iPrgDx53VNdWWLG94xlsRnW01MKW8B/DWsMnwE dIDSKf9jPmBSyMc1RrYwrGYPI2MzplA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684763530; a=rsa-sha256; cv=none; b=NyYM8Si/q0OdUaK+RB0cBzpoNLaL4AqqznhFg4sWb5fnWG0QdCVR27a59uhmQNFua8rxkp CDu5n6+SZmR1oOJYZsiRRQ6VRH6cRcO/UIeDCH90GqqrzbUeM+aMvdjcSedNypohD8yZw7 slfOTQvJw+I+Y2cRMTmKKJiFW3howvQ= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JnhAUDcZ; spf=pass (imf04.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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684763529; 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=OLusLo/oJVdzYA8d4lrkdkImz1Qgxj15rb4H8i/2VAY=; b=JnhAUDcZxuLinwN/Wu5OgsbgAzvh13nZCRWb4tB3oU/ClCKf3yHNz4/LQIc1vN/tFHBWOS 6GEAnSqcHm71m9etSdymI5HOtJrE9y9XkLewxdvAd0i/0pveUtgC/CmNNCnpOa6sjODLop QuTbNJFA80ykdyv+7t1Mf+1CEdAHiR4= 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-339-o_R015-QO0ynOKyBDFSucg-1; Mon, 22 May 2023 09:52:04 -0400 X-MC-Unique: o_R015-QO0ynOKyBDFSucg-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 324E22811BCA; Mon, 22 May 2023 13:52:03 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 58841400F17; Mon, 22 May 2023 13:52:00 +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 v22 25/31] zonefs: Provide a splice-read wrapper Date: Mon, 22 May 2023 14:50:12 +0100 Message-Id: <20230522135018.2742245-26-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-Stat-Signature: ke4nr64wehk1o3qqhk8uzsfceb76k4xd X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 42CEB40002 X-Rspam-User: X-HE-Tag: 1684763530-414350 X-HE-Meta: U2FsdGVkX1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acnnrfd3t6FCK0kjp3qqsiP+EE6+2nRfA85CiyLD6lEMPJ/DGyRWXcYYcvyDxEgJMCj5sqgDQjZU8d4kT8UQMx2mNKv57umFckhurMatBQR0gxIsHZyy44ThH1XEey+GkgFQQzSwZvGLu1GtuTdrxfe0sN7Pn176spfnmpmDxJIpXwfg4yoUHxNwM06nCRC1oAY1/1EzxpmmswUb9G9iYMVNiSNVLWzz9EVqJ7cQigjjQTwipbq9YpKa 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 zonefs. This does some checks before proceeding and locks the inode across the call to filemap_splice_read() and a size check in case of truncation. Splicing from direct I/O is handled by the caller. 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 Acked-by: Damien Le Moal --- fs/zonefs/file.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/fs/zonefs/file.c b/fs/zonefs/file.c index 132f01d3461f..65d4c4fe6364 100644 --- a/fs/zonefs/file.c +++ b/fs/zonefs/file.c @@ -752,6 +752,44 @@ static ssize_t zonefs_file_read_iter(struct kiocb *iocb, struct iov_iter *to) return ret; } +static ssize_t zonefs_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 zonefs_inode_info *zi = ZONEFS_I(inode); + struct zonefs_zone *z = zonefs_inode_zone(inode); + loff_t isize; + ssize_t ret = 0; + + /* Offline zones cannot be read */ + if (unlikely(IS_IMMUTABLE(inode) && !(inode->i_mode & 0777))) + return -EPERM; + + if (*ppos >= z->z_capacity) + return 0; + + inode_lock_shared(inode); + + /* Limit read operations to written data */ + mutex_lock(&zi->i_truncate_mutex); + isize = i_size_read(inode); + if (*ppos >= isize) + len = 0; + else + len = min_t(loff_t, len, isize - *ppos); + mutex_unlock(&zi->i_truncate_mutex); + + if (len > 0) { + ret = filemap_splice_read(in, ppos, pipe, len, flags); + if (ret == -EIO) + zonefs_io_error(inode, false); + } + + inode_unlock_shared(inode); + return ret; +} + /* * Write open accounting is done only for sequential files. */ @@ -896,7 +934,7 @@ const struct file_operations zonefs_file_operations = { .llseek = zonefs_file_llseek, .read_iter = zonefs_file_read_iter, .write_iter = zonefs_file_write_iter, - .splice_read = generic_file_splice_read, + .splice_read = zonefs_file_splice_read, .splice_write = iter_file_splice_write, .iopoll = iocb_bio_iopoll, };