From patchwork Fri May 19 07:40:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13247768 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 71B98C77B7A for ; Fri, 19 May 2023 07:41:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EE095900015; Fri, 19 May 2023 03:41:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E693A900003; Fri, 19 May 2023 03:41:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D0960900015; Fri, 19 May 2023 03:41: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 BDDE8900003 for ; Fri, 19 May 2023 03:41:53 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 946C41209D7 for ; Fri, 19 May 2023 07:41:53 +0000 (UTC) X-FDA: 80806210506.06.5BDC812 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf19.hostedemail.com (Postfix) with ESMTP id CF4371A0014 for ; Fri, 19 May 2023 07:41:51 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=alQPVGHa; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf19.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684482111; a=rsa-sha256; cv=none; b=KK6nfJgNkis0lsB20ClCKwQh9yI8Bn4qAKhwcv9HxxJ6OfkW97a8fFZCTxEhrzxmJpjm2H RRXcPST1U64tHYt8/eFzDcSZf9fsyYOCMgz/IZ1JD50OcO+mmd3XYfYbJtWpleAAtJ1De0 0hq6yOg6UlNGFcDCFk7SSxj4gTumZoA= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=alQPVGHa; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf19.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684482111; 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=ul54+Rfc7Xx/QmGKIvy0/Dk3iAPI5N6ujIbh8BdRPD4=; b=INizpurw4A8mu/qzvGZt8g5TKa6YFX+B8fZneryUrdvKYhIWt/5nbPTbvjwT4SSxPaj0jT noX05MS5h61igXTGHb2eAK9zuSJcylJKMIW9Lc0m+fB37czsO/O7mpmxLZhCmM/cyujoc/ PjX+udxe9YoNDGS//ahZAasyGHLLXn8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482111; 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=ul54+Rfc7Xx/QmGKIvy0/Dk3iAPI5N6ujIbh8BdRPD4=; b=alQPVGHazrC4pQCWsQAtVhkqcugywhpxOr478yBOxrIk+FTfKzF84bFaSbeCGVldrO7USD dp6JCBS8USHlNd8MbZtZBbtzGFV8fpgtfX8CUf4K9Yu4shRZVP+55y91lER2POjM7YvRN5 QsfO58Zx+0P3aSzZy3wIyu5z2l5KD0Q= 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-542-yZVFR8FJO82q_4bbCE1uzg-1; Fri, 19 May 2023 03:41:46 -0400 X-MC-Unique: yZVFR8FJO82q_4bbCE1uzg-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 B75B6185A78E; Fri, 19 May 2023 07:41:45 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D4D04F2DDE; Fri, 19 May 2023 07:41:43 +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 v20 13/32] ceph: Provide a splice-read stub Date: Fri, 19 May 2023 08:40:28 +0100 Message-Id: <20230519074047.1739879-14-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.9 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: CF4371A0014 X-Stat-Signature: q9akf5nuz3mfq96mr9ry96exrktx388o X-HE-Tag: 1684482111-221042 X-HE-Meta: U2FsdGVk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KTamPFA4tutSRzdS4hbIUieMiCf7/xq6sN3YSDk9srtM0gHhW1Vkdtlp9UMzg6V9IjVLGuq5CEcw1slnSWZ/H9IMkPpiL525KWWRxkJuoB8OhyYR0neimiRNLd7WDa+fXrviHhHGzlXDGhACpc/Jp4giqtair0gP4kxxCuSA92nyV+4JEifYswXxWRIc+fcVIkDnJJURhD00ndBnWqp13tKKuVoVOXFhSZecYERBNPeF6DyhzZXhy0RYSUoCC9JKMqwSat3hoiqE4ho7iRWVIA== 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 direct_splice_read() if O_DIRECT is set, 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 direct_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 --- fs/ceph/file.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/fs/ceph/file.c b/fs/ceph/file.c index f4d8bf7dec88..382dd5901748 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -1745,6 +1745,70 @@ 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 ((in->f_flags & O_DIRECT) || + ceph_has_inline_data(ci) || + (fi->flags & CEPH_F_SYNC)) + return direct_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) { + ceph_end_io_read(inode); + return ret; + } + + 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_end_io_read(inode); + return direct_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); + + ceph_end_io_read(inode); + return ret; +} + /* * Take cap references to avoid releasing caps to MDS mid-write. * @@ -2593,7 +2657,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,