From patchwork Fri May 19 07:40:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 96235 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1061672vqo; Fri, 19 May 2023 01:01:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5z/xH5498Bw0otSPEwsras+VlEZwPlhE9ZV273biwBqK2disTtA1TAy5Qe/2e/vItaEBc2 X-Received: by 2002:a05:6a20:4429:b0:103:6f15:5b49 with SMTP id ce41-20020a056a20442900b001036f155b49mr1417785pzb.46.1684483304583; Fri, 19 May 2023 01:01:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684483304; cv=none; d=google.com; s=arc-20160816; b=btJ8FP8LdU/wkkXQ/c+Of4iXUyhhlxJUhRL303jiCCAXPbWOM7etM6+ANDZ3IQkIrt GLKEfKfZckO1kkXqhvny+PLdGC0ewZBz7mqTb1U27lEjn0gR0MEH2Hs1cRBN4UXdPiZo NRmHQega+lw/SQxPnS2FnxsWAUl39oZM7GH7IGu+xuXJc7UTv81kpS7bYPj1Ko+1LZT0 dxXim/8VTT58S5P6I0Hm89fPa9zZoKriYAdsakRp8f9VoEtJjgWxgOEjjiNWsNn+2Er4 +CjW/F3J7p0mVbCo8Wk4ovg5Y0b5sjU+iY+cJAZqM9cgTcVcayraEyCje0GwycGwHO6A BK1g== 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=pyQng7zN0KcMKuuU4UJQFoNAdqIUtbeSzOIbMt9WEc4=; b=lpcrDB50gOAjrI086k0+9boAEP5NRXY98q5Mv3zGRC1Jg2HoXWbIUTwSlTksAzk/87 XFjv+8ic4roKQKy+K7ST1LVtU5aHm7m9Yq1/Vboa2GNb3/GZYD3xobP93UF44bCVzzv8 y7S3nTahMCC4BQywwVpEMc7VrkjAvPG5gD9cZ6mhQNmqlt42RsLk4iDeYy6Nj6olei3f 2B3zKj/h2teZqDgkppVpSCV9iyZIbO3aVZ4g1+xUUJ3BbZsNfS75y6ZQlHTjq1q2afdA OwanWLP92CxtEgduWjz29vKZXoSNOnBZ72PEIG0+3DVAkufoaV2C4+1c7puKO1w7Ly2b milg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HQQrXhhO; 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 y64-20020a638a43000000b0053475d8615csi2871824pgd.32.2023.05.19.01.01.29; Fri, 19 May 2023 01:01:44 -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=HQQrXhhO; 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 S231462AbjESHqf (ORCPT + 99 others); Fri, 19 May 2023 03:46:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231136AbjESHqQ (ORCPT ); Fri, 19 May 2023 03:46:16 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8760F1BD5 for ; Fri, 19 May 2023 00:43:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482155; 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=pyQng7zN0KcMKuuU4UJQFoNAdqIUtbeSzOIbMt9WEc4=; b=HQQrXhhOQB8FLOlUifrSQjkfpWlY3c9ECqS7BXIJhUvcpac57Usvx/V/g3MTcb4C0KGTCS 23VzMU9Pio8qidzI10oGqaz/l55PaF246X5ILV26NOOerSiX+OVC8B8+JavZOo1k26XYlX cGTKv2leaipCT0IbuK83jJEvQp12MHU= 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-368-9SkW8NWEPuqdpOcKe74MkQ-1; Fri, 19 May 2023 03:42:16 -0400 X-MC-Unique: 9SkW8NWEPuqdpOcKe74MkQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CAF9738035B0; Fri, 19 May 2023 07:42:15 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id E84F4492B0A; Fri, 19 May 2023 07:42:12 +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 v20 22/32] zonefs: Provide a splice-read stub Date: Fri, 19 May 2023 08:40:37 +0100 Message-Id: <20230519074047.1739879-23-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766308765679330586?= X-GMAIL-MSGID: =?utf-8?q?1766308765679330586?= Provide a splice_read stub for zonefs. This does some checks before proceeding. For buffered I/O, it locks the inode across the call to filemap_splice_read() and does a size check in case of truncation. 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 | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/fs/zonefs/file.c b/fs/zonefs/file.c index 132f01d3461f..a8d7bae4910d 100644 --- a/fs/zonefs/file.c +++ b/fs/zonefs/file.c @@ -752,6 +752,47 @@ 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; + + if (in->f_flags & O_DIRECT) + return direct_splice_read(in, ppos, pipe, len, flags); + + 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 +937,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, };