Message ID | 20230522135018.2742245-26-dhowells@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1474600vqo; Mon, 22 May 2023 07:05:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7J46Nhzny5F/1aoC11ePRaSY7w+0oF5BcTPCVeaIIbrqvZiKl8noY2LdxTlVqL8MH3fnwi X-Received: by 2002:a05:6a00:a21:b0:644:ad29:fd37 with SMTP id p33-20020a056a000a2100b00644ad29fd37mr13830860pfh.28.1684764338070; Mon, 22 May 2023 07:05:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684764338; cv=none; d=google.com; s=arc-20160816; b=QbjL5hlOsvMznyYMWdhMHWJ/iMR77nisMjRYerDehE3B4ehGHjFAAC0uctxoJmihsB zyY5+tUrieD6PHqFsLb1q/1dn0lUDknhwcN6pAJo8mzVltIZ7CpW247o/4FfrkrzX/YL zIZHATySyYLeUjMbGEd0ANcdnv+1iUUNb9zrOtcBajFNf4c3A8dJMJD7xTvZZWo+fkWE kaz6FglTU2kQ4BtwGjwpnX50srVoY6QcxskO2yRbW5vJWITFEtYFO1tbMd/sQXqXcbIz qOd4ttp63pK7/Jydp2ZA0v78/2qmlapsvJL7boXYO7ah6Kv48hYiKOiQiCGSNl/WBjPR ucFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=OLusLo/oJVdzYA8d4lrkdkImz1Qgxj15rb4H8i/2VAY=; b=ZqgiUaQ4kI3VHRyElMLulkn4dIwIv+DJZLqkBDKmpwQzKuY0XZldVeF1gipC7FSrFU 6MC9q17qLXAXnxKAAleB7QKZq2N6LaBn6c0YqA7EHTsDm62NpuQJOLKymk7dzDECIuH4 /rLCkOrVXbNRcR00bfE1DWfrz84bQmzNWie6gXLb4qbyTOneCk9GZMPd9kdo7ZJe1C1B Zt3i0U/cngGtKLyMV8FRnV9eqHHRUN3QtfLYOVoToB0qUojaU5rk8R47NtER31fffuQI /5WMlfyLFHOVB8hIfe9ubH9DMoHFELd1gjQeOLKNQElschKsV9/OnhvWg+rXfvoVTiuW pY9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=b0ogLFFa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a2-20020aa79702000000b0064122441638si4667986pfg.276.2023.05.22.07.05.22; Mon, 22 May 2023 07:05:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=b0ogLFFa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234127AbjEVNzu (ORCPT <rfc822;wlfightup@gmail.com> + 99 others); Mon, 22 May 2023 09:55:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233886AbjEVNzM (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 22 May 2023 09:55:12 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 681B21A5 for <linux-kernel@vger.kernel.org>; Mon, 22 May 2023 06:52:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684763530; 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=b0ogLFFaeRJ6BchBe32knzd9yuC9P+HteKymtMzHF8tO2cxEKCkYYnNEm2kY3WzXDcIxHe THFxX2TPRFR44B061YTBg1Ib0kyQexwxOyzcr6TXWZTGYjyuIEy859epss57nZuKSG1/+8 bjpw8MFpeK+qU8NP13PDw+IUflsH+tA= 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 <dhowells@redhat.com> To: Jens Axboe <axboe@kernel.dk>, Al Viro <viro@zeniv.linux.org.uk>, Christoph Hellwig <hch@infradead.org> Cc: David Howells <dhowells@redhat.com>, Matthew Wilcox <willy@infradead.org>, Jan Kara <jack@suse.cz>, Jeff Layton <jlayton@kernel.org>, David Hildenbrand <david@redhat.com>, Jason Gunthorpe <jgg@nvidia.com>, Logan Gunthorpe <logang@deltatee.com>, Hillf Danton <hdanton@sina.com>, Christian Brauner <brauner@kernel.org>, Linus Torvalds <torvalds@linux-foundation.org>, linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig <hch@lst.de>, "Darrick J . Wong" <djwong@kernel.org>, 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 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766603450547646068?= X-GMAIL-MSGID: =?utf-8?q?1766603450547646068?= |
Series |
splice: Kill ITER_PIPE
|
|
Commit Message
David Howells
May 22, 2023, 1:50 p.m. UTC
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 <dhowells@redhat.com>
cc: Christoph Hellwig <hch@lst.de>
cc: Al Viro <viro@zeniv.linux.org.uk>
cc: Jens Axboe <axboe@kernel.dk>
cc: Darrick J. Wong <djwong@kernel.org>
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(-)
Comments
On 5/22/23 22:50, David Howells wrote: > 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 <dhowells@redhat.com> > cc: Christoph Hellwig <hch@lst.de> > cc: Al Viro <viro@zeniv.linux.org.uk> > cc: Jens Axboe <axboe@kernel.dk> > cc: Darrick J. Wong <djwong@kernel.org> > cc: linux-xfs@vger.kernel.org > cc: linux-fsdevel@vger.kernel.org > cc: linux-block@vger.kernel.org > cc: linux-mm@kvack.org One comment below but otherwise looks OK. Acked-by: Damien Le Moal <dlemoal@kernel.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) Is -EIO the only error that filemap_splice_read() may return ? There are other IO error codes that we could get from the block layer, e.g. -ETIMEDOUT etc. So "if (ret < 0)" may be better here ? > + 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, > }; >
Damien Le Moal <dlemoal@kernel.org> wrote: > > + if (len > 0) { > > + ret = filemap_splice_read(in, ppos, pipe, len, flags); > > + if (ret == -EIO) > > Is -EIO the only error that filemap_splice_read() may return ? There are other > IO error codes that we could get from the block layer, e.g. -ETIMEDOUT etc. So > "if (ret < 0)" may be better here ? It can return -ENOMEM, -EINTR and -EAGAIN at least, none of which really count as I/O errors. I based the splice function on what zonefs_file_read_iter() does: } else { ret = generic_file_read_iter(iocb, to); if (ret == -EIO) zonefs_io_error(inode, false); } David
On 5/24/23 05:43, David Howells wrote: > Damien Le Moal <dlemoal@kernel.org> wrote: > >>> + if (len > 0) { >>> + ret = filemap_splice_read(in, ppos, pipe, len, flags); >>> + if (ret == -EIO) >> >> Is -EIO the only error that filemap_splice_read() may return ? There are other >> IO error codes that we could get from the block layer, e.g. -ETIMEDOUT etc. So >> "if (ret < 0)" may be better here ? > > It can return -ENOMEM, -EINTR and -EAGAIN at least, none of which really count > as I/O errors. I based the splice function on what zonefs_file_read_iter() > does: > > } else { > ret = generic_file_read_iter(iocb, to); > if (ret == -EIO) > zonefs_io_error(inode, false); > } Fair point. But checking again zonefs_io_error(), it will do nothing is nothing bad is detected for the zone that was used for the failed IO. So calling zonefs_io_error() for all error codes is actually fine, and likely much safer. I will change that in zonefs_file_read_iter(). Please use "if (ret < 0)" in your patch.
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, };