From patchwork Sat May 20 00:00:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13248997 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 F2E9CC7EE23 for ; Sat, 20 May 2023 00:01:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8DA7428000D; Fri, 19 May 2023 20:01:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 88A8F280001; Fri, 19 May 2023 20:01:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7044728000D; Fri, 19 May 2023 20:01:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 5A7A8280001 for ; Fri, 19 May 2023 20:01:53 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 38E2AA02FB for ; Sat, 20 May 2023 00:01:53 +0000 (UTC) X-FDA: 80808680106.11.785DC90 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf06.hostedemail.com (Postfix) with ESMTP id 8783F18001B for ; Sat, 20 May 2023 00:01:51 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=XXwp6s99; spf=pass (imf06.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.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=1684540911; a=rsa-sha256; cv=none; b=w7EUCVKMyn6LZk0kuM7Gv5XAb8mRxVbYWijIxmiGTetLrwb+XC+mrYhnfd/lTkDhaKtOOQ z0eW6fBjkQYoVDelNp2IvM+GVGbj6Xag/wLZa8/3Zg/Ao9MtpFEV2TjiKu5/2daIAEfXuI PiL8Rft9jNBr3XFKE78Y1BT5z34h+78= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=XXwp6s99; spf=pass (imf06.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.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=1684540911; 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=Cum1S+7gn4EZ2bOhEKX0VsfuPYHKWsPejiTdFi4FGTE=; b=294oYK8bOP6oaydoiwr06ZhGa00zPJXRgA13sbbZPZM7m3bcny2haNQPRDwzDh5JSeDiwm oJuqxulv7r8QmYOD93wcdaIUJB7jVG5Nd4ET1QzPB5aixsGJYIOKwtHRzU3sxsbAHNEFED CWfQWWW7FwUkvd4p+qhEreHAHwNBg2Y= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684540910; 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=Cum1S+7gn4EZ2bOhEKX0VsfuPYHKWsPejiTdFi4FGTE=; b=XXwp6s99ARRTNY170wej4Sk4gq7j7nFpp8k4lWUseLmRfH8MAEBDfqiEhHU0Q9ABUWmlyo /Eko/nytmDUCTwODQdbb5apyerSiufWCYNnlpuSPpMbud138j5mHn/dboj86j1UFXmGavn eA1xjT2VUx8E1Jtw7gYV0Bsoi+K+3H0= 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-665-z6HIEepYPKSALy6n0W2a0g-1; Fri, 19 May 2023 20:01:45 -0400 X-MC-Unique: z6HIEepYPKSALy6n0W2a0g-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5A1BE8032F5; Sat, 20 May 2023 00:01:44 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 077812166B25; Sat, 20 May 2023 00:01:41 +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 , Xiubo Li , Ilya Dryomov , ceph-devel@vger.kernel.org Subject: [PATCH v21 16/30] ceph: Provide a splice-read stub Date: Sat, 20 May 2023 01:00:35 +0100 Message-Id: <20230520000049.2226926-17-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.6 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 8783F18001B X-Stat-Signature: 553e7uzjhzityrhd1d4uaj6bg5nj4wtz X-Rspam-User: X-HE-Tag: 1684540911-592252 X-HE-Meta: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EihSEPvFlW30q0sTJKz0PAjZ/CVxWkVhxxPuF0ai2VVhVnLgogzSPxF9d5jXgYAWWym/kjr3MFOeYwJ+rgigaDoF0s3AOf/vKuh5C79ZoRHyUVqGAu9jop5xODf22iBqM76y5r76y4eXXJWeXEe4DBwPtKVBGQEolJGY6C2dKpDa4oDb4OYsZPdOSHqpsL3B2Pkh/zxQWaW1AMxjSAT+Huz7gR+a55k1qFEgN/wXvk9DTtsAq4sIXD4tsNO1pGicFfF1llPh+2FlH+8pi7kCjZNfz0TFw== 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 Ceph. This does the inode shutdown check before proceeding and jumps to copy_splice_read() if the file has inline data or is a synchronous file. We try and get FILE_RD and either FILE_CACHE and/or FILE_LAZYIO caps and hold them across filemap_splice_read(). If we fail to get FILE_CACHE or FILE_LAZYIO capabilities, we use copy_splice_read() instead. Signed-off-by: David Howells cc: Christoph Hellwig cc: Al Viro cc: Jens Axboe cc: Xiubo Li cc: Ilya Dryomov cc: Jeff Layton cc: ceph-devel@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-block@vger.kernel.org cc: linux-mm@kvack.org Reviewed-by: Xiubo Li --- Notes: ver #21) - Need to drop the caps ref. - O_DIRECT is handled by the caller. fs/ceph/file.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/fs/ceph/file.c b/fs/ceph/file.c index f4d8bf7dec88..4285f6cb5d3b 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -1745,6 +1745,69 @@ static ssize_t ceph_read_iter(struct kiocb *iocb, struct iov_iter *to) return ret; } +/* + * Wrap filemap_splice_read with checks for cap bits on the inode. + * Atomically grab references, so that those bits are not released + * back to the MDS mid-read. + */ +static ssize_t ceph_splice_read(struct file *in, loff_t *ppos, + struct pipe_inode_info *pipe, + size_t len, unsigned int flags) +{ + struct ceph_file_info *fi = in->private_data; + struct inode *inode = file_inode(in); + struct ceph_inode_info *ci = ceph_inode(inode); + ssize_t ret; + int want = 0, got = 0; + CEPH_DEFINE_RW_CONTEXT(rw_ctx, 0); + + dout("splice_read %p %llx.%llx %llu~%zu trying to get caps on %p\n", + inode, ceph_vinop(inode), *ppos, len, inode); + + if (ceph_inode_is_shutdown(inode)) + return -ESTALE; + + if (ceph_has_inline_data(ci) || + (fi->flags & CEPH_F_SYNC)) + return copy_splice_read(in, ppos, pipe, len, flags); + + ceph_start_io_read(inode); + + want = CEPH_CAP_FILE_CACHE; + if (fi->fmode & CEPH_FILE_MODE_LAZY) + want |= CEPH_CAP_FILE_LAZYIO; + + ret = ceph_get_caps(in, CEPH_CAP_FILE_RD, want, -1, &got); + if (ret < 0) + goto out_end; + + if ((got & (CEPH_CAP_FILE_CACHE | CEPH_CAP_FILE_LAZYIO)) == 0) { + dout("splice_read/sync %p %llx.%llx %llu~%zu got cap refs on %s\n", + inode, ceph_vinop(inode), *ppos, len, + ceph_cap_string(got)); + + ceph_put_cap_refs(ci, got); + ceph_end_io_read(inode); + return copy_splice_read(in, ppos, pipe, len, flags); + } + + dout("splice_read %p %llx.%llx %llu~%zu got cap refs on %s\n", + inode, ceph_vinop(inode), *ppos, len, ceph_cap_string(got)); + + rw_ctx.caps = got; + ceph_add_rw_context(fi, &rw_ctx); + ret = filemap_splice_read(in, ppos, pipe, len, flags); + ceph_del_rw_context(fi, &rw_ctx); + + dout("splice_read %p %llx.%llx dropping cap refs on %s = %zd\n", + inode, ceph_vinop(inode), ceph_cap_string(got), ret); + + ceph_put_cap_refs(ci, got); +out_end: + ceph_end_io_read(inode); + return ret; +} + /* * Take cap references to avoid releasing caps to MDS mid-write. * @@ -2593,7 +2656,7 @@ const struct file_operations ceph_file_fops = { .lock = ceph_lock, .setlease = simple_nosetlease, .flock = ceph_flock, - .splice_read = generic_file_splice_read, + .splice_read = ceph_splice_read, .splice_write = iter_file_splice_write, .unlocked_ioctl = ceph_ioctl, .compat_ioctl = compat_ptr_ioctl,