From nobody Tue Sep 9 22:46:26 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09DD6C61DA3 for ; Tue, 21 Feb 2023 10:33:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233748AbjBUKd1 (ORCPT ); Tue, 21 Feb 2023 05:33:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233364AbjBUKdV (ORCPT ); Tue, 21 Feb 2023 05:33:21 -0500 Received: from out30-119.freemail.mail.aliyun.com (out30-119.freemail.mail.aliyun.com [115.124.30.119]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7EA383C4 for ; Tue, 21 Feb 2023 02:33:18 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046051;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=3;SR=0;TI=SMTPD_---0VcC7r-U_1676975595; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VcC7r-U_1676975595) by smtp.aliyun-inc.com; Tue, 21 Feb 2023 18:33:15 +0800 From: Jingbo Xu To: dhowells@redhat.com, linux-cachefs@redhat.com Cc: linux-kernel@vger.kernel.org Subject: [PATCH 2/2] fscache: introduce fscache_begin_wait_operation() helper Date: Tue, 21 Feb 2023 18:33:13 +0800 Message-Id: <20230221103313.120834-3-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230221103313.120834-1-jefflexu@linux.alibaba.com> References: <20230221103313.120834-1-jefflexu@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This is a variant of fscache_wait_for_operation() except that it's exported for users of FsCache, and thus cookie->lock is held when checking cookie's state. Exporting fscache_begin_operation() directly is not acceptable as it would introduce dependency of for users of FsCache. Signed-off-by: Jingbo Xu --- fs/fscache/io.c | 9 +++++++++ include/linux/fscache.h | 22 ++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/fs/fscache/io.c b/fs/fscache/io.c index 0d2b8dec8f82..6ccc5aadf151 100644 --- a/fs/fscache/io.c +++ b/fs/fscache/io.c @@ -158,6 +158,15 @@ int __fscache_begin_write_operation(struct netfs_cache= _resources *cres, } EXPORT_SYMBOL(__fscache_begin_write_operation); =20 +int __fscache_begin_wait_operation(struct netfs_cache_resources *cres, + struct fscache_cookie *cookie, + enum fscache_want_state want_state) +{ + return fscache_begin_operation(cres, cookie, want_state, + fscache_access_io_wait); +} +EXPORT_SYMBOL(__fscache_begin_wait_operation); + /** * fscache_dirty_folio - Mark folio dirty and pin a cache object for write= back * @mapping: The mapping the folio belongs to. diff --git a/include/linux/fscache.h b/include/linux/fscache.h index 8e312c8323a8..708cf8db7f46 100644 --- a/include/linux/fscache.h +++ b/include/linux/fscache.h @@ -171,6 +171,8 @@ extern void __fscache_resize_cookie(struct fscache_cook= ie *, loff_t); extern void __fscache_invalidate(struct fscache_cookie *, const void *, lo= ff_t, unsigned int); extern int __fscache_begin_read_operation(struct netfs_cache_resources *, = struct fscache_cookie *); extern int __fscache_begin_write_operation(struct netfs_cache_resources *,= struct fscache_cookie *); +extern int __fscache_begin_wait_operation(struct netfs_cache_resources *, = struct fscache_cookie *, + enum fscache_want_state want_state); =20 extern void __fscache_write_to_cache(struct fscache_cookie *, struct addre= ss_space *, loff_t, size_t, loff_t, netfs_io_terminated_t, void *, @@ -543,6 +545,26 @@ int fscache_begin_write_operation(struct netfs_cache_r= esources *cres, return -ENOBUFS; } =20 +/** + * fscache_begin_wait_operation - Wait for an object become accessible + * @cres: The cache resources for the operation being performed + * @cookie: The cookie representing the cache object + * + * Returns: + * * 0 - Success + * * -ENOBUFS - No caching available + * * Other error code from the cache, such as -ENOMEM. + */ +static inline +int fscache_begin_wait_operation(struct netfs_cache_resources *cres, + struct fscache_cookie *cookie, + enum fscache_want_state want_state) +{ + if (fscache_cookie_enabled(cookie)) + return __fscache_begin_wait_operation(cres, cookie, want_state); + return -ENOBUFS; +} + /** * fscache_write - Start a write to the cache. * @cres: The cache resources to use --=20 2.19.1.6.gb485710b