From patchwork Tue Feb 14 17:13:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13140604 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 5B601C61DA4 for ; Tue, 14 Feb 2023 17:14:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EDA4E6B0080; Tue, 14 Feb 2023 12:14:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E8A336B0081; Tue, 14 Feb 2023 12:14:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D79356B0082; Tue, 14 Feb 2023 12:14:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C81816B0080 for ; Tue, 14 Feb 2023 12:14:06 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 9E7F8C0E4E for ; Tue, 14 Feb 2023 17:14:06 +0000 (UTC) X-FDA: 80466545292.03.4C8F44D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf18.hostedemail.com (Postfix) with ESMTP id DAD651C0029 for ; Tue, 14 Feb 2023 17:14:03 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=MA2Tp0y4; spf=pass (imf18.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676394844; a=rsa-sha256; cv=none; b=qxlxXO+5kWlZVgneytXyl4Aiy7aUCpJcTF/aJxHrowlqPZYVV1z2xwm0TJHyYU/gbDGfgn 8dIAObkxEjIJpW5kD8ioltMslGQ+a7+mr5KXD5BAZL7TSeRWbtWx37focxa7rNwazMtV2S BOLARWVHqPT/Pkz+mLpyCckKPwqfGHI= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=MA2Tp0y4; spf=pass (imf18.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.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=1676394844; 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=LVjIujk8d1N0k6RGniY3UP+0o4vFHY30HdwwNIbIhak=; b=euZFv6WBM6JchXkz4Jgbv0CGrGVTU8XX281ytRagfsMZRBdIWf9u1Af46KFCBN8+776BYS rUCrfAT/+oVRudMezu0tPT894lA1tr82xq+QZWuTMAuPgaWZxCyB2YP48bBEpWBRb06nJJ pbYcyXrmYOOw3MrtT6KcWxo79ZNdZXI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676394843; 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=LVjIujk8d1N0k6RGniY3UP+0o4vFHY30HdwwNIbIhak=; b=MA2Tp0y4F6kIgwUR6MJz0HS9ffds8A1m3jEaav9Jj+wqi2zJd/v719q2TeR3tm8nKY50Ut HhvvM/2V3IkPs0zUVv4+Q17Ev0X1hJefoF8cCFLzO4MOKRShGH59LtNBlRTErsH8ZlBdCA e/X3QsjeoH7S1U0rjAZD9p+SOljZF9A= 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-608-VwTllVNdOty5IfHcJbDwmw-1; Tue, 14 Feb 2023 12:14:00 -0500 X-MC-Unique: VwTllVNdOty5IfHcJbDwmw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4BBF285CCE0; Tue, 14 Feb 2023 17:13:59 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0784C40C10FA; Tue, 14 Feb 2023 17:13:46 +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 , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , John Hubbard , Miklos Szeredi , linux-unionfs@vger.kernel.org Subject: [PATCH v14 05/17] overlayfs: Implement splice-read Date: Tue, 14 Feb 2023 17:13:18 +0000 Message-Id: <20230214171330.2722188-6-dhowells@redhat.com> In-Reply-To: <20230214171330.2722188-1-dhowells@redhat.com> References: <20230214171330.2722188-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Rspam-User: X-Rspamd-Queue-Id: DAD651C0029 X-Rspamd-Server: rspam01 X-Stat-Signature: uaeib3d95opiabegiqt61zgf6gqrodby X-HE-Tag: 1676394843-372679 X-HE-Meta: U2F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lDe7yeH+OMyj9xh97/HLI8ID49FSCQsIINmQMmCP0Pv5cc8KeyhChwhxzhIk2aA3+5azRuTd4TJh0kcvEVzDdgNZSwCwFg1TEPmeTjsx1OdFlI1ZcKfnDTFwlrE4G50djsLsqv3RFR/OqVIZPXAGQk8d/8W1qfRErSJVuqwpc64Z3Eio3b7oxIhrnNB6rCBjI5v/ztjPaXxcAN2tkHnx2MJIhOz2q6aX3sdXLMBj4SGqhmAYRF1eVMzE5YObxibXrLqPQsYyXct/hVxQE1sdwyd1XcndH9w6LihIw7A0NH2fAi/OuJpADVGYzxql08quzMvzpomPdZiCJZ/EpDXhGRZaCAW/v48pO0T0fNhIDQTFB3 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: Implement splice-read for overlayfs by passing the request down a layer rather than going through generic_file_splice_read() which is going to be changed to assume that ->read_folio() is present on buffered files. Signed-off-by: David Howells cc: Christoph Hellwig cc: Jens Axboe cc: Al Viro cc: John Hubbard cc: David Hildenbrand cc: Matthew Wilcox cc: Miklos Szeredi cc: linux-unionfs@vger.kernel.org cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org --- fs/overlayfs/file.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c index c9d0c362c7ef..267b61df6fcd 100644 --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c @@ -419,6 +419,40 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter) return ret; } +static ssize_t ovl_splice_read(struct file *in, loff_t *ppos, + struct pipe_inode_info *pipe, size_t len, + unsigned int flags) +{ + const struct cred *old_cred; + struct fd real; + ssize_t ret; + + ret = ovl_real_fdget(in, &real); + if (ret) + return ret; + + ret = -EINVAL; + if (in->f_flags & O_DIRECT && + !(real.file->f_mode & FMODE_CAN_ODIRECT)) + goto out_fdput; + if (!real.file->f_op->splice_read) + goto out_fdput; + + ret = rw_verify_area(READ, in, ppos, len); + if (unlikely(ret < 0)) + return ret; + + old_cred = ovl_override_creds(file_inode(in)->i_sb); + ret = real.file->f_op->splice_read(real.file, ppos, pipe, len, flags); + + revert_creds(old_cred); + ovl_file_accessed(in); +out_fdput: + fdput(real); + + return ret; +} + /* * Calling iter_file_splice_write() directly from overlay's f_op may deadlock * due to lock order inversion between pipe->mutex in iter_file_splice_write() @@ -695,7 +729,7 @@ const struct file_operations ovl_file_operations = { .fallocate = ovl_fallocate, .fadvise = ovl_fadvise, .flush = ovl_flush, - .splice_read = generic_file_splice_read, + .splice_read = ovl_splice_read, .splice_write = ovl_splice_write, .copy_file_range = ovl_copy_file_range,