Linux Audio

Check our new training course

Loading...
v6.13.7
  1/* SPDX-License-Identifier: GPL-2.0-or-later */
  2/* Internal definitions for network filesystem support
  3 *
  4 * Copyright (C) 2021 Red Hat, Inc. All Rights Reserved.
  5 * Written by David Howells (dhowells@redhat.com)
  6 */
  7
  8#include <linux/slab.h>
  9#include <linux/seq_file.h>
 10#include <linux/folio_queue.h>
 11#include <linux/netfs.h>
 12#include <linux/fscache.h>
 13#include <linux/fscache-cache.h>
 14#include <trace/events/netfs.h>
 15#include <trace/events/fscache.h>
 16
 17#ifdef pr_fmt
 18#undef pr_fmt
 19#endif
 20
 21#define pr_fmt(fmt) "netfs: " fmt
 22
 23/*
 24 * buffered_read.c
 25 */
 
 26int netfs_prefetch_for_write(struct file *file, struct folio *folio,
 27			     size_t offset, size_t len);
 28
 29/*
 
 
 
 
 
 30 * main.c
 31 */
 32extern unsigned int netfs_debug;
 33extern struct list_head netfs_io_requests;
 34extern spinlock_t netfs_proc_lock;
 35extern mempool_t netfs_request_pool;
 36extern mempool_t netfs_subrequest_pool;
 37
 38#ifdef CONFIG_PROC_FS
 39static inline void netfs_proc_add_rreq(struct netfs_io_request *rreq)
 40{
 41	spin_lock(&netfs_proc_lock);
 42	list_add_tail_rcu(&rreq->proc_link, &netfs_io_requests);
 43	spin_unlock(&netfs_proc_lock);
 44}
 45static inline void netfs_proc_del_rreq(struct netfs_io_request *rreq)
 46{
 47	if (!list_empty(&rreq->proc_link)) {
 48		spin_lock(&netfs_proc_lock);
 49		list_del_rcu(&rreq->proc_link);
 50		spin_unlock(&netfs_proc_lock);
 51	}
 52}
 53#else
 54static inline void netfs_proc_add_rreq(struct netfs_io_request *rreq) {}
 55static inline void netfs_proc_del_rreq(struct netfs_io_request *rreq) {}
 56#endif
 57
 58/*
 59 * misc.c
 60 */
 61struct folio_queue *netfs_buffer_make_space(struct netfs_io_request *rreq);
 62int netfs_buffer_append_folio(struct netfs_io_request *rreq, struct folio *folio,
 63			      bool needs_put);
 64struct folio_queue *netfs_delete_buffer_head(struct netfs_io_request *wreq);
 65void netfs_clear_buffer(struct netfs_io_request *rreq);
 66void netfs_reset_iter(struct netfs_io_subrequest *subreq);
 
 
 
 67
 68/*
 69 * objects.c
 70 */
 71struct netfs_io_request *netfs_alloc_request(struct address_space *mapping,
 72					     struct file *file,
 73					     loff_t start, size_t len,
 74					     enum netfs_io_origin origin);
 75void netfs_get_request(struct netfs_io_request *rreq, enum netfs_rreq_ref_trace what);
 76void netfs_clear_subrequests(struct netfs_io_request *rreq, bool was_async);
 77void netfs_put_request(struct netfs_io_request *rreq, bool was_async,
 78		       enum netfs_rreq_ref_trace what);
 79struct netfs_io_subrequest *netfs_alloc_subrequest(struct netfs_io_request *rreq);
 80
 81static inline void netfs_see_request(struct netfs_io_request *rreq,
 82				     enum netfs_rreq_ref_trace what)
 83{
 84	trace_netfs_rreq_ref(rreq->debug_id, refcount_read(&rreq->ref), what);
 85}
 86
 87/*
 88 * read_collect.c
 89 */
 90void netfs_read_termination_worker(struct work_struct *work);
 91void netfs_rreq_terminated(struct netfs_io_request *rreq, bool was_async);
 92
 93/*
 94 * read_pgpriv2.c
 95 */
 96void netfs_pgpriv2_mark_copy_to_cache(struct netfs_io_subrequest *subreq,
 97				      struct netfs_io_request *rreq,
 98				      struct folio_queue *folioq,
 99				      int slot);
100void netfs_pgpriv2_write_to_the_cache(struct netfs_io_request *rreq);
101bool netfs_pgpriv2_unlock_copied_folios(struct netfs_io_request *wreq);
102
103/*
104 * read_retry.c
105 */
106void netfs_retry_reads(struct netfs_io_request *rreq);
107void netfs_unlock_abandoned_read_pages(struct netfs_io_request *rreq);
 
 
 
108
109/*
110 * stats.c
111 */
112#ifdef CONFIG_NETFS_STATS
113extern atomic_t netfs_n_rh_dio_read;
 
114extern atomic_t netfs_n_rh_readahead;
115extern atomic_t netfs_n_rh_read_folio;
116extern atomic_t netfs_n_rh_rreq;
117extern atomic_t netfs_n_rh_sreq;
118extern atomic_t netfs_n_rh_download;
119extern atomic_t netfs_n_rh_download_done;
120extern atomic_t netfs_n_rh_download_failed;
121extern atomic_t netfs_n_rh_download_instead;
122extern atomic_t netfs_n_rh_read;
123extern atomic_t netfs_n_rh_read_done;
124extern atomic_t netfs_n_rh_read_failed;
125extern atomic_t netfs_n_rh_zero;
126extern atomic_t netfs_n_rh_short_read;
127extern atomic_t netfs_n_rh_write;
128extern atomic_t netfs_n_rh_write_begin;
129extern atomic_t netfs_n_rh_write_done;
130extern atomic_t netfs_n_rh_write_failed;
131extern atomic_t netfs_n_rh_write_zskip;
132extern atomic_t netfs_n_wh_buffered_write;
133extern atomic_t netfs_n_wh_writethrough;
134extern atomic_t netfs_n_wh_dio_write;
135extern atomic_t netfs_n_wh_writepages;
136extern atomic_t netfs_n_wh_copy_to_cache;
137extern atomic_t netfs_n_wh_wstream_conflict;
138extern atomic_t netfs_n_wh_upload;
139extern atomic_t netfs_n_wh_upload_done;
140extern atomic_t netfs_n_wh_upload_failed;
141extern atomic_t netfs_n_wh_write;
142extern atomic_t netfs_n_wh_write_done;
143extern atomic_t netfs_n_wh_write_failed;
144extern atomic_t netfs_n_wb_lock_skip;
145extern atomic_t netfs_n_wb_lock_wait;
146extern atomic_t netfs_n_folioq;
147
148int netfs_stats_show(struct seq_file *m, void *v);
149
150static inline void netfs_stat(atomic_t *stat)
151{
152	atomic_inc(stat);
153}
154
155static inline void netfs_stat_d(atomic_t *stat)
156{
157	atomic_dec(stat);
158}
159
160#else
161#define netfs_stat(x) do {} while(0)
162#define netfs_stat_d(x) do {} while(0)
163#endif
164
165/*
166 * write_collect.c
167 */
168int netfs_folio_written_back(struct folio *folio);
169void netfs_write_collection_worker(struct work_struct *work);
170void netfs_wake_write_collector(struct netfs_io_request *wreq, bool was_async);
171
172/*
173 * write_issue.c
174 */
175struct netfs_io_request *netfs_create_write_req(struct address_space *mapping,
176						struct file *file,
177						loff_t start,
178						enum netfs_io_origin origin);
179void netfs_reissue_write(struct netfs_io_stream *stream,
180			 struct netfs_io_subrequest *subreq,
181			 struct iov_iter *source);
182void netfs_issue_write(struct netfs_io_request *wreq,
183		       struct netfs_io_stream *stream);
184int netfs_advance_write(struct netfs_io_request *wreq,
185			struct netfs_io_stream *stream,
186			loff_t start, size_t len, bool to_eof);
187struct netfs_io_request *netfs_begin_writethrough(struct kiocb *iocb, size_t len);
188int netfs_advance_writethrough(struct netfs_io_request *wreq, struct writeback_control *wbc,
189			       struct folio *folio, size_t copied, bool to_page_end,
190			       struct folio **writethrough_cache);
191int netfs_end_writethrough(struct netfs_io_request *wreq, struct writeback_control *wbc,
192			   struct folio *writethrough_cache);
193int netfs_unbuffered_write(struct netfs_io_request *wreq, bool may_wait, size_t len);
194
195/*
196 * Miscellaneous functions.
197 */
198static inline bool netfs_is_cache_enabled(struct netfs_inode *ctx)
199{
200#if IS_ENABLED(CONFIG_FSCACHE)
201	struct fscache_cookie *cookie = ctx->cache;
202
203	return fscache_cookie_valid(cookie) && cookie->cache_priv &&
204		fscache_cookie_enabled(cookie);
205#else
206	return false;
207#endif
208}
209
210/*
211 * Get a ref on a netfs group attached to a dirty page (e.g. a ceph snap).
212 */
213static inline struct netfs_group *netfs_get_group(struct netfs_group *netfs_group)
214{
215	if (netfs_group && netfs_group != NETFS_FOLIO_COPY_TO_CACHE)
216		refcount_inc(&netfs_group->ref);
217	return netfs_group;
218}
219
220/*
221 * Dispose of a netfs group attached to a dirty page (e.g. a ceph snap).
222 */
223static inline void netfs_put_group(struct netfs_group *netfs_group)
224{
225	if (netfs_group &&
226	    netfs_group != NETFS_FOLIO_COPY_TO_CACHE &&
227	    refcount_dec_and_test(&netfs_group->ref))
228		netfs_group->free(netfs_group);
229}
230
231/*
232 * Dispose of a netfs group attached to a dirty page (e.g. a ceph snap).
233 */
234static inline void netfs_put_group_many(struct netfs_group *netfs_group, int nr)
235{
236	if (netfs_group &&
237	    netfs_group != NETFS_FOLIO_COPY_TO_CACHE &&
238	    refcount_sub_and_test(nr, &netfs_group->ref))
239		netfs_group->free(netfs_group);
240}
241
242/*
243 * fscache-cache.c
244 */
245#ifdef CONFIG_PROC_FS
246extern const struct seq_operations fscache_caches_seq_ops;
247#endif
248bool fscache_begin_cache_access(struct fscache_cache *cache, enum fscache_access_trace why);
249void fscache_end_cache_access(struct fscache_cache *cache, enum fscache_access_trace why);
250struct fscache_cache *fscache_lookup_cache(const char *name, bool is_cache);
251void fscache_put_cache(struct fscache_cache *cache, enum fscache_cache_trace where);
252
253static inline enum fscache_cache_state fscache_cache_state(const struct fscache_cache *cache)
254{
255	return smp_load_acquire(&cache->state);
256}
257
258static inline bool fscache_cache_is_live(const struct fscache_cache *cache)
259{
260	return fscache_cache_state(cache) == FSCACHE_CACHE_IS_ACTIVE;
261}
262
263static inline void fscache_set_cache_state(struct fscache_cache *cache,
264					   enum fscache_cache_state new_state)
265{
266	smp_store_release(&cache->state, new_state);
267
268}
269
270static inline bool fscache_set_cache_state_maybe(struct fscache_cache *cache,
271						 enum fscache_cache_state old_state,
272						 enum fscache_cache_state new_state)
273{
274	return try_cmpxchg_release(&cache->state, &old_state, new_state);
275}
276
277/*
278 * fscache-cookie.c
279 */
280extern struct kmem_cache *fscache_cookie_jar;
281#ifdef CONFIG_PROC_FS
282extern const struct seq_operations fscache_cookies_seq_ops;
283#endif
284extern struct timer_list fscache_cookie_lru_timer;
285
286extern void fscache_print_cookie(struct fscache_cookie *cookie, char prefix);
287extern bool fscache_begin_cookie_access(struct fscache_cookie *cookie,
288					enum fscache_access_trace why);
289
290static inline void fscache_see_cookie(struct fscache_cookie *cookie,
291				      enum fscache_cookie_trace where)
292{
293	trace_fscache_cookie(cookie->debug_id, refcount_read(&cookie->ref),
294			     where);
295}
296
297/*
298 * fscache-main.c
299 */
300extern unsigned int fscache_hash(unsigned int salt, const void *data, size_t len);
301#ifdef CONFIG_FSCACHE
302int __init fscache_init(void);
303void __exit fscache_exit(void);
304#else
305static inline int fscache_init(void) { return 0; }
306static inline void fscache_exit(void) {}
307#endif
308
309/*
310 * fscache-proc.c
311 */
312#ifdef CONFIG_PROC_FS
313extern int __init fscache_proc_init(void);
314extern void fscache_proc_cleanup(void);
315#else
316#define fscache_proc_init()	(0)
317#define fscache_proc_cleanup()	do {} while (0)
318#endif
319
320/*
321 * fscache-stats.c
322 */
323#ifdef CONFIG_FSCACHE_STATS
324extern atomic_t fscache_n_volumes;
325extern atomic_t fscache_n_volumes_collision;
326extern atomic_t fscache_n_volumes_nomem;
327extern atomic_t fscache_n_cookies;
328extern atomic_t fscache_n_cookies_lru;
329extern atomic_t fscache_n_cookies_lru_expired;
330extern atomic_t fscache_n_cookies_lru_removed;
331extern atomic_t fscache_n_cookies_lru_dropped;
332
333extern atomic_t fscache_n_acquires;
334extern atomic_t fscache_n_acquires_ok;
335extern atomic_t fscache_n_acquires_oom;
336
337extern atomic_t fscache_n_invalidates;
338
339extern atomic_t fscache_n_relinquishes;
340extern atomic_t fscache_n_relinquishes_retire;
341extern atomic_t fscache_n_relinquishes_dropped;
342
343extern atomic_t fscache_n_resizes;
344extern atomic_t fscache_n_resizes_null;
345
346static inline void fscache_stat(atomic_t *stat)
347{
348	atomic_inc(stat);
349}
350
351static inline void fscache_stat_d(atomic_t *stat)
352{
353	atomic_dec(stat);
354}
355
356#define __fscache_stat(stat) (stat)
357
358int fscache_stats_show(struct seq_file *m);
359#else
360
361#define __fscache_stat(stat) (NULL)
362#define fscache_stat(stat) do {} while (0)
363#define fscache_stat_d(stat) do {} while (0)
364
365static inline int fscache_stats_show(struct seq_file *m) { return 0; }
366#endif
367
368/*
369 * fscache-volume.c
370 */
371#ifdef CONFIG_PROC_FS
372extern const struct seq_operations fscache_volumes_seq_ops;
373#endif
374
375struct fscache_volume *fscache_get_volume(struct fscache_volume *volume,
376					  enum fscache_volume_trace where);
 
 
377bool fscache_begin_volume_access(struct fscache_volume *volume,
378				 struct fscache_cookie *cookie,
379				 enum fscache_access_trace why);
380void fscache_create_volume(struct fscache_volume *volume, bool wait);
381
382/*****************************************************************************/
383/*
384 * debug tracing
385 */
386#define dbgprintk(FMT, ...) \
387	printk("[%-6.6s] "FMT"\n", current->comm, ##__VA_ARGS__)
388
389#define kenter(FMT, ...) dbgprintk("==> %s("FMT")", __func__, ##__VA_ARGS__)
390#define kleave(FMT, ...) dbgprintk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
391#define kdebug(FMT, ...) dbgprintk(FMT, ##__VA_ARGS__)
392
393#ifdef __KDEBUG
394#define _enter(FMT, ...) kenter(FMT, ##__VA_ARGS__)
395#define _leave(FMT, ...) kleave(FMT, ##__VA_ARGS__)
396#define _debug(FMT, ...) kdebug(FMT, ##__VA_ARGS__)
397
398#elif defined(CONFIG_NETFS_DEBUG)
399#define _enter(FMT, ...)			\
400do {						\
401	if (netfs_debug)			\
402		kenter(FMT, ##__VA_ARGS__);	\
403} while (0)
404
405#define _leave(FMT, ...)			\
406do {						\
407	if (netfs_debug)			\
408		kleave(FMT, ##__VA_ARGS__);	\
409} while (0)
410
411#define _debug(FMT, ...)			\
412do {						\
413	if (netfs_debug)			\
414		kdebug(FMT, ##__VA_ARGS__);	\
415} while (0)
416
417#else
418#define _enter(FMT, ...) no_printk("==> %s("FMT")", __func__, ##__VA_ARGS__)
419#define _leave(FMT, ...) no_printk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
420#define _debug(FMT, ...) no_printk(FMT, ##__VA_ARGS__)
421#endif
422
423/*
424 * assertions
425 */
426#if 1 /* defined(__KDEBUGALL) */
427
428#define ASSERT(X)							\
429do {									\
430	if (unlikely(!(X))) {						\
431		pr_err("\n");					\
432		pr_err("Assertion failed\n");	\
433		BUG();							\
434	}								\
435} while (0)
436
437#define ASSERTCMP(X, OP, Y)						\
438do {									\
439	if (unlikely(!((X) OP (Y)))) {					\
440		pr_err("\n");					\
441		pr_err("Assertion failed\n");	\
442		pr_err("%lx " #OP " %lx is false\n",		\
443		       (unsigned long)(X), (unsigned long)(Y));		\
444		BUG();							\
445	}								\
446} while (0)
447
448#define ASSERTIF(C, X)							\
449do {									\
450	if (unlikely((C) && !(X))) {					\
451		pr_err("\n");					\
452		pr_err("Assertion failed\n");	\
453		BUG();							\
454	}								\
455} while (0)
456
457#define ASSERTIFCMP(C, X, OP, Y)					\
458do {									\
459	if (unlikely((C) && !((X) OP (Y)))) {				\
460		pr_err("\n");					\
461		pr_err("Assertion failed\n");	\
462		pr_err("%lx " #OP " %lx is false\n",		\
463		       (unsigned long)(X), (unsigned long)(Y));		\
464		BUG();							\
465	}								\
466} while (0)
467
468#else
469
470#define ASSERT(X)			do {} while (0)
471#define ASSERTCMP(X, OP, Y)		do {} while (0)
472#define ASSERTIF(C, X)			do {} while (0)
473#define ASSERTIFCMP(C, X, OP, Y)	do {} while (0)
474
475#endif /* assert or not */
v6.9.4
  1/* SPDX-License-Identifier: GPL-2.0-or-later */
  2/* Internal definitions for network filesystem support
  3 *
  4 * Copyright (C) 2021 Red Hat, Inc. All Rights Reserved.
  5 * Written by David Howells (dhowells@redhat.com)
  6 */
  7
  8#include <linux/slab.h>
  9#include <linux/seq_file.h>
 
 10#include <linux/netfs.h>
 11#include <linux/fscache.h>
 12#include <linux/fscache-cache.h>
 13#include <trace/events/netfs.h>
 14#include <trace/events/fscache.h>
 15
 16#ifdef pr_fmt
 17#undef pr_fmt
 18#endif
 19
 20#define pr_fmt(fmt) "netfs: " fmt
 21
 22/*
 23 * buffered_read.c
 24 */
 25void netfs_rreq_unlock_folios(struct netfs_io_request *rreq);
 26int netfs_prefetch_for_write(struct file *file, struct folio *folio,
 27			     size_t offset, size_t len);
 28
 29/*
 30 * io.c
 31 */
 32int netfs_begin_read(struct netfs_io_request *rreq, bool sync);
 33
 34/*
 35 * main.c
 36 */
 37extern unsigned int netfs_debug;
 38extern struct list_head netfs_io_requests;
 39extern spinlock_t netfs_proc_lock;
 
 
 40
 41#ifdef CONFIG_PROC_FS
 42static inline void netfs_proc_add_rreq(struct netfs_io_request *rreq)
 43{
 44	spin_lock(&netfs_proc_lock);
 45	list_add_tail_rcu(&rreq->proc_link, &netfs_io_requests);
 46	spin_unlock(&netfs_proc_lock);
 47}
 48static inline void netfs_proc_del_rreq(struct netfs_io_request *rreq)
 49{
 50	if (!list_empty(&rreq->proc_link)) {
 51		spin_lock(&netfs_proc_lock);
 52		list_del_rcu(&rreq->proc_link);
 53		spin_unlock(&netfs_proc_lock);
 54	}
 55}
 56#else
 57static inline void netfs_proc_add_rreq(struct netfs_io_request *rreq) {}
 58static inline void netfs_proc_del_rreq(struct netfs_io_request *rreq) {}
 59#endif
 60
 61/*
 62 * misc.c
 63 */
 64#define NETFS_FLAG_PUT_MARK		BIT(0)
 65#define NETFS_FLAG_PAGECACHE_MARK	BIT(1)
 66int netfs_xa_store_and_mark(struct xarray *xa, unsigned long index,
 67			    struct folio *folio, unsigned int flags,
 68			    gfp_t gfp_mask);
 69int netfs_add_folios_to_buffer(struct xarray *buffer,
 70			       struct address_space *mapping,
 71			       pgoff_t index, pgoff_t to, gfp_t gfp_mask);
 72void netfs_clear_buffer(struct xarray *buffer);
 73
 74/*
 75 * objects.c
 76 */
 77struct netfs_io_request *netfs_alloc_request(struct address_space *mapping,
 78					     struct file *file,
 79					     loff_t start, size_t len,
 80					     enum netfs_io_origin origin);
 81void netfs_get_request(struct netfs_io_request *rreq, enum netfs_rreq_ref_trace what);
 82void netfs_clear_subrequests(struct netfs_io_request *rreq, bool was_async);
 83void netfs_put_request(struct netfs_io_request *rreq, bool was_async,
 84		       enum netfs_rreq_ref_trace what);
 85struct netfs_io_subrequest *netfs_alloc_subrequest(struct netfs_io_request *rreq);
 86
 87static inline void netfs_see_request(struct netfs_io_request *rreq,
 88				     enum netfs_rreq_ref_trace what)
 89{
 90	trace_netfs_rreq_ref(rreq->debug_id, refcount_read(&rreq->ref), what);
 91}
 92
 93/*
 94 * output.c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 95 */
 96int netfs_begin_write(struct netfs_io_request *wreq, bool may_wait,
 97		      enum netfs_write_trace what);
 98struct netfs_io_request *netfs_begin_writethrough(struct kiocb *iocb, size_t len);
 99int netfs_advance_writethrough(struct netfs_io_request *wreq, size_t copied, bool to_page_end);
100int netfs_end_writethrough(struct netfs_io_request *wreq, struct kiocb *iocb);
101
102/*
103 * stats.c
104 */
105#ifdef CONFIG_NETFS_STATS
106extern atomic_t netfs_n_rh_dio_read;
107extern atomic_t netfs_n_rh_dio_write;
108extern atomic_t netfs_n_rh_readahead;
109extern atomic_t netfs_n_rh_readpage;
110extern atomic_t netfs_n_rh_rreq;
111extern atomic_t netfs_n_rh_sreq;
112extern atomic_t netfs_n_rh_download;
113extern atomic_t netfs_n_rh_download_done;
114extern atomic_t netfs_n_rh_download_failed;
115extern atomic_t netfs_n_rh_download_instead;
116extern atomic_t netfs_n_rh_read;
117extern atomic_t netfs_n_rh_read_done;
118extern atomic_t netfs_n_rh_read_failed;
119extern atomic_t netfs_n_rh_zero;
120extern atomic_t netfs_n_rh_short_read;
121extern atomic_t netfs_n_rh_write;
122extern atomic_t netfs_n_rh_write_begin;
123extern atomic_t netfs_n_rh_write_done;
124extern atomic_t netfs_n_rh_write_failed;
125extern atomic_t netfs_n_rh_write_zskip;
 
 
 
 
 
126extern atomic_t netfs_n_wh_wstream_conflict;
127extern atomic_t netfs_n_wh_upload;
128extern atomic_t netfs_n_wh_upload_done;
129extern atomic_t netfs_n_wh_upload_failed;
130extern atomic_t netfs_n_wh_write;
131extern atomic_t netfs_n_wh_write_done;
132extern atomic_t netfs_n_wh_write_failed;
 
 
 
133
134int netfs_stats_show(struct seq_file *m, void *v);
135
136static inline void netfs_stat(atomic_t *stat)
137{
138	atomic_inc(stat);
139}
140
141static inline void netfs_stat_d(atomic_t *stat)
142{
143	atomic_dec(stat);
144}
145
146#else
147#define netfs_stat(x) do {} while(0)
148#define netfs_stat_d(x) do {} while(0)
149#endif
150
151/*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152 * Miscellaneous functions.
153 */
154static inline bool netfs_is_cache_enabled(struct netfs_inode *ctx)
155{
156#if IS_ENABLED(CONFIG_FSCACHE)
157	struct fscache_cookie *cookie = ctx->cache;
158
159	return fscache_cookie_valid(cookie) && cookie->cache_priv &&
160		fscache_cookie_enabled(cookie);
161#else
162	return false;
163#endif
164}
165
166/*
167 * Get a ref on a netfs group attached to a dirty page (e.g. a ceph snap).
168 */
169static inline struct netfs_group *netfs_get_group(struct netfs_group *netfs_group)
170{
171	if (netfs_group)
172		refcount_inc(&netfs_group->ref);
173	return netfs_group;
174}
175
176/*
177 * Dispose of a netfs group attached to a dirty page (e.g. a ceph snap).
178 */
179static inline void netfs_put_group(struct netfs_group *netfs_group)
180{
181	if (netfs_group && refcount_dec_and_test(&netfs_group->ref))
 
 
182		netfs_group->free(netfs_group);
183}
184
185/*
186 * Dispose of a netfs group attached to a dirty page (e.g. a ceph snap).
187 */
188static inline void netfs_put_group_many(struct netfs_group *netfs_group, int nr)
189{
190	if (netfs_group && refcount_sub_and_test(nr, &netfs_group->ref))
 
 
191		netfs_group->free(netfs_group);
192}
193
194/*
195 * fscache-cache.c
196 */
197#ifdef CONFIG_PROC_FS
198extern const struct seq_operations fscache_caches_seq_ops;
199#endif
200bool fscache_begin_cache_access(struct fscache_cache *cache, enum fscache_access_trace why);
201void fscache_end_cache_access(struct fscache_cache *cache, enum fscache_access_trace why);
202struct fscache_cache *fscache_lookup_cache(const char *name, bool is_cache);
203void fscache_put_cache(struct fscache_cache *cache, enum fscache_cache_trace where);
204
205static inline enum fscache_cache_state fscache_cache_state(const struct fscache_cache *cache)
206{
207	return smp_load_acquire(&cache->state);
208}
209
210static inline bool fscache_cache_is_live(const struct fscache_cache *cache)
211{
212	return fscache_cache_state(cache) == FSCACHE_CACHE_IS_ACTIVE;
213}
214
215static inline void fscache_set_cache_state(struct fscache_cache *cache,
216					   enum fscache_cache_state new_state)
217{
218	smp_store_release(&cache->state, new_state);
219
220}
221
222static inline bool fscache_set_cache_state_maybe(struct fscache_cache *cache,
223						 enum fscache_cache_state old_state,
224						 enum fscache_cache_state new_state)
225{
226	return try_cmpxchg_release(&cache->state, &old_state, new_state);
227}
228
229/*
230 * fscache-cookie.c
231 */
232extern struct kmem_cache *fscache_cookie_jar;
233#ifdef CONFIG_PROC_FS
234extern const struct seq_operations fscache_cookies_seq_ops;
235#endif
236extern struct timer_list fscache_cookie_lru_timer;
237
238extern void fscache_print_cookie(struct fscache_cookie *cookie, char prefix);
239extern bool fscache_begin_cookie_access(struct fscache_cookie *cookie,
240					enum fscache_access_trace why);
241
242static inline void fscache_see_cookie(struct fscache_cookie *cookie,
243				      enum fscache_cookie_trace where)
244{
245	trace_fscache_cookie(cookie->debug_id, refcount_read(&cookie->ref),
246			     where);
247}
248
249/*
250 * fscache-main.c
251 */
252extern unsigned int fscache_hash(unsigned int salt, const void *data, size_t len);
253#ifdef CONFIG_FSCACHE
254int __init fscache_init(void);
255void __exit fscache_exit(void);
256#else
257static inline int fscache_init(void) { return 0; }
258static inline void fscache_exit(void) {}
259#endif
260
261/*
262 * fscache-proc.c
263 */
264#ifdef CONFIG_PROC_FS
265extern int __init fscache_proc_init(void);
266extern void fscache_proc_cleanup(void);
267#else
268#define fscache_proc_init()	(0)
269#define fscache_proc_cleanup()	do {} while (0)
270#endif
271
272/*
273 * fscache-stats.c
274 */
275#ifdef CONFIG_FSCACHE_STATS
276extern atomic_t fscache_n_volumes;
277extern atomic_t fscache_n_volumes_collision;
278extern atomic_t fscache_n_volumes_nomem;
279extern atomic_t fscache_n_cookies;
280extern atomic_t fscache_n_cookies_lru;
281extern atomic_t fscache_n_cookies_lru_expired;
282extern atomic_t fscache_n_cookies_lru_removed;
283extern atomic_t fscache_n_cookies_lru_dropped;
284
285extern atomic_t fscache_n_acquires;
286extern atomic_t fscache_n_acquires_ok;
287extern atomic_t fscache_n_acquires_oom;
288
289extern atomic_t fscache_n_invalidates;
290
291extern atomic_t fscache_n_relinquishes;
292extern atomic_t fscache_n_relinquishes_retire;
293extern atomic_t fscache_n_relinquishes_dropped;
294
295extern atomic_t fscache_n_resizes;
296extern atomic_t fscache_n_resizes_null;
297
298static inline void fscache_stat(atomic_t *stat)
299{
300	atomic_inc(stat);
301}
302
303static inline void fscache_stat_d(atomic_t *stat)
304{
305	atomic_dec(stat);
306}
307
308#define __fscache_stat(stat) (stat)
309
310int fscache_stats_show(struct seq_file *m);
311#else
312
313#define __fscache_stat(stat) (NULL)
314#define fscache_stat(stat) do {} while (0)
315#define fscache_stat_d(stat) do {} while (0)
316
317static inline int fscache_stats_show(struct seq_file *m) { return 0; }
318#endif
319
320/*
321 * fscache-volume.c
322 */
323#ifdef CONFIG_PROC_FS
324extern const struct seq_operations fscache_volumes_seq_ops;
325#endif
326
327struct fscache_volume *fscache_get_volume(struct fscache_volume *volume,
328					  enum fscache_volume_trace where);
329void fscache_put_volume(struct fscache_volume *volume,
330			enum fscache_volume_trace where);
331bool fscache_begin_volume_access(struct fscache_volume *volume,
332				 struct fscache_cookie *cookie,
333				 enum fscache_access_trace why);
334void fscache_create_volume(struct fscache_volume *volume, bool wait);
335
336/*****************************************************************************/
337/*
338 * debug tracing
339 */
340#define dbgprintk(FMT, ...) \
341	printk("[%-6.6s] "FMT"\n", current->comm, ##__VA_ARGS__)
342
343#define kenter(FMT, ...) dbgprintk("==> %s("FMT")", __func__, ##__VA_ARGS__)
344#define kleave(FMT, ...) dbgprintk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
345#define kdebug(FMT, ...) dbgprintk(FMT, ##__VA_ARGS__)
346
347#ifdef __KDEBUG
348#define _enter(FMT, ...) kenter(FMT, ##__VA_ARGS__)
349#define _leave(FMT, ...) kleave(FMT, ##__VA_ARGS__)
350#define _debug(FMT, ...) kdebug(FMT, ##__VA_ARGS__)
351
352#elif defined(CONFIG_NETFS_DEBUG)
353#define _enter(FMT, ...)			\
354do {						\
355	if (netfs_debug)			\
356		kenter(FMT, ##__VA_ARGS__);	\
357} while (0)
358
359#define _leave(FMT, ...)			\
360do {						\
361	if (netfs_debug)			\
362		kleave(FMT, ##__VA_ARGS__);	\
363} while (0)
364
365#define _debug(FMT, ...)			\
366do {						\
367	if (netfs_debug)			\
368		kdebug(FMT, ##__VA_ARGS__);	\
369} while (0)
370
371#else
372#define _enter(FMT, ...) no_printk("==> %s("FMT")", __func__, ##__VA_ARGS__)
373#define _leave(FMT, ...) no_printk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
374#define _debug(FMT, ...) no_printk(FMT, ##__VA_ARGS__)
375#endif
376
377/*
378 * assertions
379 */
380#if 1 /* defined(__KDEBUGALL) */
381
382#define ASSERT(X)							\
383do {									\
384	if (unlikely(!(X))) {						\
385		pr_err("\n");					\
386		pr_err("Assertion failed\n");	\
387		BUG();							\
388	}								\
389} while (0)
390
391#define ASSERTCMP(X, OP, Y)						\
392do {									\
393	if (unlikely(!((X) OP (Y)))) {					\
394		pr_err("\n");					\
395		pr_err("Assertion failed\n");	\
396		pr_err("%lx " #OP " %lx is false\n",		\
397		       (unsigned long)(X), (unsigned long)(Y));		\
398		BUG();							\
399	}								\
400} while (0)
401
402#define ASSERTIF(C, X)							\
403do {									\
404	if (unlikely((C) && !(X))) {					\
405		pr_err("\n");					\
406		pr_err("Assertion failed\n");	\
407		BUG();							\
408	}								\
409} while (0)
410
411#define ASSERTIFCMP(C, X, OP, Y)					\
412do {									\
413	if (unlikely((C) && !((X) OP (Y)))) {				\
414		pr_err("\n");					\
415		pr_err("Assertion failed\n");	\
416		pr_err("%lx " #OP " %lx is false\n",		\
417		       (unsigned long)(X), (unsigned long)(Y));		\
418		BUG();							\
419	}								\
420} while (0)
421
422#else
423
424#define ASSERT(X)			do {} while (0)
425#define ASSERTCMP(X, OP, Y)		do {} while (0)
426#define ASSERTIF(C, X)			do {} while (0)
427#define ASSERTIFCMP(C, X, OP, Y)	do {} while (0)
428
429#endif /* assert or not */