From patchwork Sat May 20 00:00:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13249006 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 8CE76C77B7F for ; Sat, 20 May 2023 00:02:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 24DAA280012; Fri, 19 May 2023 20:02:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1E2D6280001; Fri, 19 May 2023 20:02:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F1A7B280012; Fri, 19 May 2023 20:02:20 -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 D84A6280001 for ; Fri, 19 May 2023 20:02:20 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id A6EF8120BCD for ; Sat, 20 May 2023 00:02:20 +0000 (UTC) X-FDA: 80808681240.14.9241AC9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf05.hostedemail.com (Postfix) with ESMTP id E061010000A for ; Sat, 20 May 2023 00:02:18 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ittkGr+e; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf05.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=1684540939; 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=fg25eeUYeYYdZ/6VEaLafGCYFAO2kBY9m762euh7YIo=; b=nEMMCbYLwp67p05y2DAc4zJndmyCvbp7BLWhWgDT354vRgjWlg8Xm3djFhE4HoJVH1ObLc LwjN681vwrGocHwDbSUWZiraRYHac3bpotPIDW4AMcFZWXwFZEuQP9fPxfNaWaR8D7mqL+ SUkxbVXmZow+XwCNIgExVXdRpEgVSIM= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ittkGr+e; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf05.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=1684540939; a=rsa-sha256; cv=none; b=qfGP3zA4mA7o35xtNlPpftHsz59xzOgBfe98BXmrdqcj79VZh/25YH4wuZHFbo2j4MMKRu 0vMniTxpJNee1Aetat/eyZ8+VerCkU2dW79kRKFB6Iv8WJEzIS+yZlUWXdBud0vQEHCqRz cy4rDKXzl5g0Rh6eDZ6wLHjypjZEja8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684540938; 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=fg25eeUYeYYdZ/6VEaLafGCYFAO2kBY9m762euh7YIo=; b=ittkGr+eqDit6O3SHoFqk8Be6YScrmwzYWPofvkZJOi0N1h8IWsCw/9RiO1ULukICqrtoj ll8JeBAz9Kobwc6O/h1VwuGyRPVW+lruAh+GxhHwhpS0t9ctgHs4LzsUNpx9seVb/n+JKo yaXuLvzMd5RNc+RZVLl6XmSTBoxam2g= 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-54-C8zFKqYaNZCOViPhzBCcFA-1; Fri, 19 May 2023 20:02:12 -0400 X-MC-Unique: C8zFKqYaNZCOViPhzBCcFA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 368B3800969; Sat, 20 May 2023 00:02:11 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 142E040CFD46; Sat, 20 May 2023 00:02:08 +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 v21 25/30] zonefs: Provide a splice-read stub Date: Sat, 20 May 2023 01:00:44 +0100 Message-Id: <20230520000049.2226926-26-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.1 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: E061010000A X-Stat-Signature: os6e4os84qx6gbsq68mntm5ayb3t6rzh X-HE-Tag: 1684540938-458097 X-HE-Meta: U2FsdGVkX18O02vgmNKxrfI6Ft9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/7IAGbibo1AL+GcSe2yfElmp3GUNRx4rpWRbbtHyHq4mYPNuDDgNyTUfb4d0jeHsGYpV6qno+9TDwvSF5bqzNqDHYNaPbscGLba2wS8ceGsB97S04puSlhjrUftCmCIyi25Qn63MgKlOkZu6ONGXFj4BBg/Jm4WWcG9TduYkpq7Oi0+vi7dHyal7Sl648VN+3j4v60LqlvJtTFX8dpcMDxS5GBzMxx9DR5w7DtWPq5bJtHXmQj/q1f8v9 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 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 --- 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, };