From patchwork Mon Oct 18 15:03:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 12567207 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89DF5C433F5 for ; Mon, 18 Oct 2021 15:04:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 70D5E60E0C for ; Mon, 18 Oct 2021 15:04:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232772AbhJRPGx (ORCPT ); Mon, 18 Oct 2021 11:06:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:32341 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232684AbhJRPF5 (ORCPT ); Mon, 18 Oct 2021 11:05:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634569425; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K6n7Lxx/u+7TeXaM45gQ3O34r9vcGaUxwGu9AnBokAQ=; b=dGZzg8+oxaFJNbjjnIzZfchWt4jRFNvwnG+iI502HsYFS6VArkgfCI0xSHsqS/onmQSuQ8 b3vWnJNXprO7i/UzqP4M9toL1fQDmS5YNWS6suLr+vnSJt1m5WaUsUyfOlf5Ogc+QhJoLD BFvcpCposJ1MdXrUH/5uOvv3JwlMCro= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-276-3SzqldG0NTe8vAbqLe2UXg-1; Mon, 18 Oct 2021 11:03:43 -0400 X-MC-Unique: 3SzqldG0NTe8vAbqLe2UXg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 85B2710168DE; Mon, 18 Oct 2021 15:03:41 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7723A60CCC; Mon, 18 Oct 2021 15:03:23 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 50/67] fscache: Make fscache_clear_page_bits() conditional on cookie From: David Howells To: linux-cachefs@redhat.com Cc: dhowells@redhat.com, Trond Myklebust , Anna Schumaker , Steve French , Dominique Martinet , Jeff Layton , Matthew Wilcox , Alexander Viro , Omar Sandoval , Linus Torvalds , linux-afs@lists.infradead.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, ceph-devel@vger.kernel.org, v9fs-developer@lists.sourceforge.net, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Mon, 18 Oct 2021 16:03:22 +0100 Message-ID: <163456940271.2614702.17009440990784553871.stgit@warthog.procyon.org.uk> In-Reply-To: <163456861570.2614702.14754548462706508617.stgit@warthog.procyon.org.uk> References: <163456861570.2614702.14754548462706508617.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.23 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org Make fscache_clear_page_bits() conditional on cookie not being NULL, rather than merely conditional on CONFIG_FSCACHE=[ym]. The problem with the latter is if a filesystem, say afs, has CONFIG_AFS_FSCACHE=n but calls into this function - in which it linkage will fail if CONFIG_FSCACHE is less than CONFIG_AFS. Analogous problems can affect other filesystems, e.g. 9p. Making fscache_clear_page_bits() conditional on the cookie achieves two things: (1) If cookie optimised down to constant NULL, the rest of the function is thrown away and the slow path is never called. (2) __fscache_clear_page_bits() isn't called if there's no cookie - and so, in such a case, the pages won't iterated over attempting to clear PG_fscache bits that haven't been set. Signed-off-by: David Howells --- fs/fscache/io.c | 5 +++-- include/linux/fscache.h | 8 +++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/fs/fscache/io.c b/fs/fscache/io.c index 3910cba65545..bc8d1ac0e85c 100644 --- a/fs/fscache/io.c +++ b/fs/fscache/io.c @@ -316,7 +316,8 @@ static void fscache_wreq_done(void *priv, ssize_t transferred_or_error, { struct fscache_write_request *wreq = priv; - fscache_clear_page_bits(wreq->mapping, wreq->start, wreq->len); + fscache_clear_page_bits(fscache_cres_cookie(&wreq->cache_resources), + wreq->mapping, wreq->start, wreq->len); if (wreq->term_func) wreq->term_func(wreq->term_func_priv, transferred_or_error, @@ -373,7 +374,7 @@ void __fscache_write_to_cache(struct fscache_cookie *cookie, abandon_free: kfree(wreq); abandon: - fscache_clear_page_bits(mapping, start, len); + fscache_clear_page_bits(cookie, mapping, start, len); if (term_func) term_func(term_func_priv, ret, false); } diff --git a/include/linux/fscache.h b/include/linux/fscache.h index fe4d588641da..847c076d05a6 100644 --- a/include/linux/fscache.h +++ b/include/linux/fscache.h @@ -549,6 +549,7 @@ int fscache_write(struct netfs_cache_resources *cres, /** * fscache_clear_page_bits - Clear the PG_fscache bits from a set of pages + * @cookie: The cookie representing the cache object * @mapping: The netfs inode to use as the source * @start: The start position in @mapping * @len: The amount of data to unlock @@ -556,10 +557,11 @@ int fscache_write(struct netfs_cache_resources *cres, * Clear the PG_fscache flag from a sequence of pages and wake up anyone who's * waiting. */ -static inline void fscache_clear_page_bits(struct address_space *mapping, +static inline void fscache_clear_page_bits(struct fscache_cookie *cookie, + struct address_space *mapping, loff_t start, size_t len) { - if (fscache_available()) + if (fscache_cookie_valid(cookie)) __fscache_clear_page_bits(mapping, start, len); } @@ -595,7 +597,7 @@ static inline void fscache_write_to_cache(struct fscache_cookie *cookie, __fscache_write_to_cache(cookie, mapping, start, len, i_size, term_func, term_func_priv); } else { - fscache_clear_page_bits(mapping, start, len); + fscache_clear_page_bits(cookie, mapping, start, len); if (term_func) term_func(term_func_priv, -ENOBUFS, false); }