Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2992157rwd; Mon, 22 May 2023 07:14:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ72hIwTHx889afdqsyabQzxX/SS0A3zCCADr0WRr2NGVpSqeMil/60GBFFcXL9WfaY0qniL X-Received: by 2002:a05:6a00:134c:b0:64d:277c:4a92 with SMTP id k12-20020a056a00134c00b0064d277c4a92mr14640058pfu.12.1684764863277; Mon, 22 May 2023 07:14:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684764863; cv=none; d=google.com; s=arc-20160816; b=Ems5EFXVeq1xkUUmAwm2StZT79RnVltcTuuO62zCdg6XeFuajal7X2QpRXG/19Zq/l MUGOLwA2mytgiRMrSAUSpQyo1Ux5gZ0S+DWBAv5q+m8fujUNVbnAi8RgI6qubnKsfSUt 5L3Jcz7ry+ZjHZa6GUvNy8kptc9OBwtqFphzxC3LZrTapSyQv0SS/RJl9aexEHtNcOg0 9NcQgl2lUboeeCHK8eKcGB25saSX+dMTwxw4MOBMFZDbsGfc6GncfDa3rSaa7kd7B/XJ Q/HxnpX3mpES+68CDZr4am5tVTKjFnGASof5hw+nrTDnKteEAIRaqJop+YWYEM6kAr94 lH4w== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a20-20020a637054000000b0053872f6398fsi4222249pgn.472.2023.05.22.07.14.08; Mon, 22 May 2023 07:14:23 -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 S234450AbjEVNzu (ORCPT + 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 ); 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 ; 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 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 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: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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, };