2874c5fd28426 (Thomas Gleixner 2019-05-27 08:55:01 +0200 1) /* SPDX-License-Identifier: GPL-2.0-or-later */
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 2) /* Internal definitions for FS-Cache
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 3) *
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 4) * Copyright (C) 2004-2007 Red Hat, Inc. All Rights Reserved.
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 5) * Written by David Howells (dhowells@redhat.com)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 6) */
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 7)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 8) /*
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 9) * Lock order, in the order in which multiple locks should be obtained:
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 10) * - fscache_addremove_sem
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 11) * - cookie->lock
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 12) * - cookie->parent->lock
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 13) * - cache->object_list_lock
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 14) * - object->lock
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 15) * - object->parent->lock
1bccf513ac49d (David Howells 2009-11-19 18:11:25 +0000 16) * - cookie->stores_lock
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 17) * - fscache_thread_lock
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 18) *
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 19) */
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 20)
36dfd116edd48 (Fabian Frederick 2014-06-04 16:05:38 -0700 21) #ifdef pr_fmt
36dfd116edd48 (Fabian Frederick 2014-06-04 16:05:38 -0700 22) #undef pr_fmt
36dfd116edd48 (Fabian Frederick 2014-06-04 16:05:38 -0700 23) #endif
36dfd116edd48 (Fabian Frederick 2014-06-04 16:05:38 -0700 24)
36dfd116edd48 (Fabian Frederick 2014-06-04 16:05:38 -0700 25) #define pr_fmt(fmt) "FS-Cache: " fmt
36dfd116edd48 (Fabian Frederick 2014-06-04 16:05:38 -0700 26)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 27) #include <linux/fscache-cache.h>
a18feb55769b7 (David Howells 2018-04-04 13:41:27 +0100 28) #include <trace/events/fscache.h>
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 29) #include <linux/sched.h>
fddda2b7b5211 (Christoph Hellwig 2018-04-13 19:44:18 +0200 30) #include <linux/seq_file.h>
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 31)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 32) #define FSCACHE_MIN_THREADS 4
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 33) #define FSCACHE_MAX_THREADS 32
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 34)
0e04d4cefcf4d (David Howells 2009-04-03 16:42:37 +0100 35) /*
348ca1029e8ba (David Howells 2009-05-27 15:46:50 +0100 36) * cache.c
0e04d4cefcf4d (David Howells 2009-04-03 16:42:37 +0100 37) */
0e04d4cefcf4d (David Howells 2009-04-03 16:42:37 +0100 38) extern struct list_head fscache_cache_list;
0e04d4cefcf4d (David Howells 2009-04-03 16:42:37 +0100 39) extern struct rw_semaphore fscache_addremove_sem;
0e04d4cefcf4d (David Howells 2009-04-03 16:42:37 +0100 40)
0e04d4cefcf4d (David Howells 2009-04-03 16:42:37 +0100 41) extern struct fscache_cache *fscache_select_cache_for_object(
0e04d4cefcf4d (David Howells 2009-04-03 16:42:37 +0100 42) struct fscache_cookie *);
0e04d4cefcf4d (David Howells 2009-04-03 16:42:37 +0100 43)
955d00917f0c0 (David Howells 2009-04-03 16:42:38 +0100 44) /*
348ca1029e8ba (David Howells 2009-05-27 15:46:50 +0100 45) * cookie.c
955d00917f0c0 (David Howells 2009-04-03 16:42:38 +0100 46) */
955d00917f0c0 (David Howells 2009-04-03 16:42:38 +0100 47) extern struct kmem_cache *fscache_cookie_jar;
955d00917f0c0 (David Howells 2009-04-03 16:42:38 +0100 48)
ec0328e46d6e5 (David Howells 2018-04-04 13:41:28 +0100 49) extern void fscache_free_cookie(struct fscache_cookie *);
ec0328e46d6e5 (David Howells 2018-04-04 13:41:28 +0100 50) extern struct fscache_cookie *fscache_alloc_cookie(struct fscache_cookie *,
ec0328e46d6e5 (David Howells 2018-04-04 13:41:28 +0100 51) const struct fscache_cookie_def *,
ec0328e46d6e5 (David Howells 2018-04-04 13:41:28 +0100 52) const void *, size_t,
ec0328e46d6e5 (David Howells 2018-04-04 13:41:28 +0100 53) const void *, size_t,
ec0328e46d6e5 (David Howells 2018-04-04 13:41:28 +0100 54) void *, loff_t);
ec0328e46d6e5 (David Howells 2018-04-04 13:41:28 +0100 55) extern struct fscache_cookie *fscache_hash_cookie(struct fscache_cookie *);
a18feb55769b7 (David Howells 2018-04-04 13:41:27 +0100 56) extern void fscache_cookie_put(struct fscache_cookie *,
a18feb55769b7 (David Howells 2018-04-04 13:41:27 +0100 57) enum fscache_cookie_trace);
955d00917f0c0 (David Howells 2009-04-03 16:42:38 +0100 58)
a6891645cf2dd (David Howells 2009-04-03 16:42:37 +0100 59) /*
348ca1029e8ba (David Howells 2009-05-27 15:46:50 +0100 60) * fsdef.c
a6891645cf2dd (David Howells 2009-04-03 16:42:37 +0100 61) */
a6891645cf2dd (David Howells 2009-04-03 16:42:37 +0100 62) extern struct fscache_cookie fscache_fsdef_index;
a6891645cf2dd (David Howells 2009-04-03 16:42:37 +0100 63) extern struct fscache_cookie_def fscache_fsdef_netfs_def;
a6891645cf2dd (David Howells 2009-04-03 16:42:37 +0100 64)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 65) /*
348ca1029e8ba (David Howells 2009-05-27 15:46:50 +0100 66) * histogram.c
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 67) */
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 68) #ifdef CONFIG_FSCACHE_HISTOGRAM
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 69) extern atomic_t fscache_obj_instantiate_histogram[HZ];
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 70) extern atomic_t fscache_objs_histogram[HZ];
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 71) extern atomic_t fscache_ops_histogram[HZ];
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 72) extern atomic_t fscache_retrieval_delay_histogram[HZ];
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 73) extern atomic_t fscache_retrieval_histogram[HZ];
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 74)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 75) static inline void fscache_hist(atomic_t histogram[], unsigned long start_jif)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 76) {
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 77) unsigned long jif = jiffies - start_jif;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 78) if (jif >= HZ)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 79) jif = HZ - 1;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 80) atomic_inc(&histogram[jif]);
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 81) }
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 82)
fddda2b7b5211 (Christoph Hellwig 2018-04-13 19:44:18 +0200 83) extern const struct seq_operations fscache_histogram_ops;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 84)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 85) #else
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 86) #define fscache_hist(hist, start_jif) do {} while (0)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 87) #endif
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 88)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 89) /*
348ca1029e8ba (David Howells 2009-05-27 15:46:50 +0100 90) * main.c
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 91) */
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 92) extern unsigned fscache_defer_lookup;
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 93) extern unsigned fscache_defer_create;
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 94) extern unsigned fscache_debug;
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 95) extern struct kobject *fscache_root;
8b8edefa2fffb (Tejun Heo 2010-07-20 22:09:01 +0200 96) extern struct workqueue_struct *fscache_object_wq;
8af7c12436803 (Tejun Heo 2010-07-20 22:09:01 +0200 97) extern struct workqueue_struct *fscache_op_wq;
8b8edefa2fffb (Tejun Heo 2010-07-20 22:09:01 +0200 98) DECLARE_PER_CPU(wait_queue_head_t, fscache_object_cong_wait);
8b8edefa2fffb (Tejun Heo 2010-07-20 22:09:01 +0200 99)
8b8edefa2fffb (Tejun Heo 2010-07-20 22:09:01 +0200 100) static inline bool fscache_object_congested(void)
8b8edefa2fffb (Tejun Heo 2010-07-20 22:09:01 +0200 101) {
8b8edefa2fffb (Tejun Heo 2010-07-20 22:09:01 +0200 102) return workqueue_congested(WORK_CPU_UNBOUND, fscache_object_wq);
8b8edefa2fffb (Tejun Heo 2010-07-20 22:09:01 +0200 103) }
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 104)
36c9559022850 (David Howells 2009-04-03 16:42:38 +0100 105) /*
348ca1029e8ba (David Howells 2009-05-27 15:46:50 +0100 106) * object.c
36c9559022850 (David Howells 2009-04-03 16:42:38 +0100 107) */
36c9559022850 (David Howells 2009-04-03 16:42:38 +0100 108) extern void fscache_enqueue_object(struct fscache_object *);
36c9559022850 (David Howells 2009-04-03 16:42:38 +0100 109)
4fbf4291aa159 (David Howells 2009-11-19 18:11:04 +0000 110) /*
4fbf4291aa159 (David Howells 2009-11-19 18:11:04 +0000 111) * object-list.c
4fbf4291aa159 (David Howells 2009-11-19 18:11:04 +0000 112) */
4fbf4291aa159 (David Howells 2009-11-19 18:11:04 +0000 113) #ifdef CONFIG_FSCACHE_OBJECT_LIST
97a32539b9568 (Alexey Dobriyan 2020-02-03 17:37:17 -0800 114) extern const struct proc_ops fscache_objlist_proc_ops;
4fbf4291aa159 (David Howells 2009-11-19 18:11:04 +0000 115)
4fbf4291aa159 (David Howells 2009-11-19 18:11:04 +0000 116) extern void fscache_objlist_add(struct fscache_object *);
1362729b169b7 (David Howells 2013-05-10 19:50:26 +0100 117) extern void fscache_objlist_remove(struct fscache_object *);
4fbf4291aa159 (David Howells 2009-11-19 18:11:04 +0000 118) #else
4fbf4291aa159 (David Howells 2009-11-19 18:11:04 +0000 119) #define fscache_objlist_add(object) do {} while(0)
1362729b169b7 (David Howells 2013-05-10 19:50:26 +0100 120) #define fscache_objlist_remove(object) do {} while(0)
4fbf4291aa159 (David Howells 2009-11-19 18:11:04 +0000 121) #endif
4fbf4291aa159 (David Howells 2009-11-19 18:11:04 +0000 122)
36c9559022850 (David Howells 2009-04-03 16:42:38 +0100 123) /*
348ca1029e8ba (David Howells 2009-05-27 15:46:50 +0100 124) * operation.c
36c9559022850 (David Howells 2009-04-03 16:42:38 +0100 125) */
952efe7b7840e (David Howells 2009-04-03 16:42:39 +0100 126) extern int fscache_submit_exclusive_op(struct fscache_object *,
952efe7b7840e (David Howells 2009-04-03 16:42:39 +0100 127) struct fscache_operation *);
952efe7b7840e (David Howells 2009-04-03 16:42:39 +0100 128) extern int fscache_submit_op(struct fscache_object *,
952efe7b7840e (David Howells 2009-04-03 16:42:39 +0100 129) struct fscache_operation *);
d3b97ca4a99e4 (David Howells 2015-02-24 10:05:29 +0000 130) extern int fscache_cancel_op(struct fscache_operation *, bool);
ef778e7ae67cd (David Howells 2012-12-20 21:52:36 +0000 131) extern void fscache_cancel_all_ops(struct fscache_object *);
952efe7b7840e (David Howells 2009-04-03 16:42:39 +0100 132) extern void fscache_abort_object(struct fscache_object *);
952efe7b7840e (David Howells 2009-04-03 16:42:39 +0100 133) extern void fscache_start_operations(struct fscache_object *);
952efe7b7840e (David Howells 2009-04-03 16:42:39 +0100 134) extern void fscache_operation_gc(struct work_struct *);
36c9559022850 (David Howells 2009-04-03 16:42:38 +0100 135)
ef778e7ae67cd (David Howells 2012-12-20 21:52:36 +0000 136) /*
ef778e7ae67cd (David Howells 2012-12-20 21:52:36 +0000 137) * page.c
ef778e7ae67cd (David Howells 2012-12-20 21:52:36 +0000 138) */
da9803bc8812f (David Howells 2013-08-21 17:29:38 -0400 139) extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
da9803bc8812f (David Howells 2013-08-21 17:29:38 -0400 140) extern int fscache_wait_for_operation_activation(struct fscache_object *,
da9803bc8812f (David Howells 2013-08-21 17:29:38 -0400 141) struct fscache_operation *,
da9803bc8812f (David Howells 2013-08-21 17:29:38 -0400 142) atomic_t *,
d3b97ca4a99e4 (David Howells 2015-02-24 10:05:29 +0000 143) atomic_t *);
ef778e7ae67cd (David Howells 2012-12-20 21:52:36 +0000 144) extern void fscache_invalidate_writes(struct fscache_cookie *);
26aaeffcafe6c (David Howells 2021-02-22 11:39:47 +0000 145) struct fscache_retrieval *fscache_alloc_retrieval(struct fscache_cookie *cookie,
26aaeffcafe6c (David Howells 2021-02-22 11:39:47 +0000 146) struct address_space *mapping,
26aaeffcafe6c (David Howells 2021-02-22 11:39:47 +0000 147) fscache_rw_complete_t end_io_func,
26aaeffcafe6c (David Howells 2021-02-22 11:39:47 +0000 148) void *context);
ef778e7ae67cd (David Howells 2012-12-20 21:52:36 +0000 149)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 150) /*
348ca1029e8ba (David Howells 2009-05-27 15:46:50 +0100 151) * proc.c
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 152) */
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 153) #ifdef CONFIG_PROC_FS
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 154) extern int __init fscache_proc_init(void);
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 155) extern void fscache_proc_cleanup(void);
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 156) #else
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 157) #define fscache_proc_init() (0)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 158) #define fscache_proc_cleanup() do {} while (0)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 159) #endif
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 160)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 161) /*
348ca1029e8ba (David Howells 2009-05-27 15:46:50 +0100 162) * stats.c
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 163) */
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 164) #ifdef CONFIG_FSCACHE_STATS
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 165) extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 166) extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 167)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 168) extern atomic_t fscache_n_op_pend;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 169) extern atomic_t fscache_n_op_run;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 170) extern atomic_t fscache_n_op_enqueue;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 171) extern atomic_t fscache_n_op_deferred_release;
03cdd0e4b9a98 (David Howells 2015-02-25 13:21:15 +0000 172) extern atomic_t fscache_n_op_initialised;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 173) extern atomic_t fscache_n_op_release;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 174) extern atomic_t fscache_n_op_gc;
5753c44188925 (David Howells 2009-11-19 18:11:19 +0000 175) extern atomic_t fscache_n_op_cancelled;
e3d4d28b1c8cc (David Howells 2009-11-19 18:11:32 +0000 176) extern atomic_t fscache_n_op_rejected;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 177)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 178) extern atomic_t fscache_n_attr_changed;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 179) extern atomic_t fscache_n_attr_changed_ok;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 180) extern atomic_t fscache_n_attr_changed_nobufs;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 181) extern atomic_t fscache_n_attr_changed_nomem;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 182) extern atomic_t fscache_n_attr_changed_calls;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 183)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 184) extern atomic_t fscache_n_allocs;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 185) extern atomic_t fscache_n_allocs_ok;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 186) extern atomic_t fscache_n_allocs_wait;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 187) extern atomic_t fscache_n_allocs_nobufs;
5753c44188925 (David Howells 2009-11-19 18:11:19 +0000 188) extern atomic_t fscache_n_allocs_intr;
60d543ca724be (David Howells 2009-11-19 18:11:45 +0000 189) extern atomic_t fscache_n_allocs_object_dead;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 190) extern atomic_t fscache_n_alloc_ops;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 191) extern atomic_t fscache_n_alloc_op_waits;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 192)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 193) extern atomic_t fscache_n_retrievals;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 194) extern atomic_t fscache_n_retrievals_ok;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 195) extern atomic_t fscache_n_retrievals_wait;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 196) extern atomic_t fscache_n_retrievals_nodata;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 197) extern atomic_t fscache_n_retrievals_nobufs;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 198) extern atomic_t fscache_n_retrievals_intr;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 199) extern atomic_t fscache_n_retrievals_nomem;
60d543ca724be (David Howells 2009-11-19 18:11:45 +0000 200) extern atomic_t fscache_n_retrievals_object_dead;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 201) extern atomic_t fscache_n_retrieval_ops;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 202) extern atomic_t fscache_n_retrieval_op_waits;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 203)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 204) extern atomic_t fscache_n_stores;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 205) extern atomic_t fscache_n_stores_ok;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 206) extern atomic_t fscache_n_stores_again;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 207) extern atomic_t fscache_n_stores_nobufs;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 208) extern atomic_t fscache_n_stores_oom;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 209) extern atomic_t fscache_n_store_ops;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 210) extern atomic_t fscache_n_store_calls;
1bccf513ac49d (David Howells 2009-11-19 18:11:25 +0000 211) extern atomic_t fscache_n_store_pages;
1bccf513ac49d (David Howells 2009-11-19 18:11:25 +0000 212) extern atomic_t fscache_n_store_radix_deletes;
1bccf513ac49d (David Howells 2009-11-19 18:11:25 +0000 213) extern atomic_t fscache_n_store_pages_over_limit;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 214)
201a15428bd54 (David Howells 2009-11-19 18:11:35 +0000 215) extern atomic_t fscache_n_store_vmscan_not_storing;
201a15428bd54 (David Howells 2009-11-19 18:11:35 +0000 216) extern atomic_t fscache_n_store_vmscan_gone;
201a15428bd54 (David Howells 2009-11-19 18:11:35 +0000 217) extern atomic_t fscache_n_store_vmscan_busy;
201a15428bd54 (David Howells 2009-11-19 18:11:35 +0000 218) extern atomic_t fscache_n_store_vmscan_cancelled;
8c209ce721444 (David Howells 2012-12-05 13:34:49 +0000 219) extern atomic_t fscache_n_store_vmscan_wait;
201a15428bd54 (David Howells 2009-11-19 18:11:35 +0000 220)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 221) extern atomic_t fscache_n_marks;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 222) extern atomic_t fscache_n_uncaches;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 223)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 224) extern atomic_t fscache_n_acquires;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 225) extern atomic_t fscache_n_acquires_null;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 226) extern atomic_t fscache_n_acquires_no_cache;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 227) extern atomic_t fscache_n_acquires_ok;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 228) extern atomic_t fscache_n_acquires_nobufs;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 229) extern atomic_t fscache_n_acquires_oom;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 230)
ef778e7ae67cd (David Howells 2012-12-20 21:52:36 +0000 231) extern atomic_t fscache_n_invalidates;
ef778e7ae67cd (David Howells 2012-12-20 21:52:36 +0000 232) extern atomic_t fscache_n_invalidates_run;
ef778e7ae67cd (David Howells 2012-12-20 21:52:36 +0000 233)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 234) extern atomic_t fscache_n_updates;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 235) extern atomic_t fscache_n_updates_null;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 236) extern atomic_t fscache_n_updates_run;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 237)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 238) extern atomic_t fscache_n_relinquishes;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 239) extern atomic_t fscache_n_relinquishes_null;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 240) extern atomic_t fscache_n_relinquishes_waitcrt;
2175bb06dc6cf (David Howells 2009-11-19 18:11:38 +0000 241) extern atomic_t fscache_n_relinquishes_retire;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 242)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 243) extern atomic_t fscache_n_cookie_index;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 244) extern atomic_t fscache_n_cookie_data;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 245) extern atomic_t fscache_n_cookie_special;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 246)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 247) extern atomic_t fscache_n_object_alloc;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 248) extern atomic_t fscache_n_object_no_alloc;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 249) extern atomic_t fscache_n_object_lookups;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 250) extern atomic_t fscache_n_object_lookups_negative;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 251) extern atomic_t fscache_n_object_lookups_positive;
fee096deb4f33 (David Howells 2009-11-19 18:12:05 +0000 252) extern atomic_t fscache_n_object_lookups_timed_out;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 253) extern atomic_t fscache_n_object_created;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 254) extern atomic_t fscache_n_object_avail;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 255) extern atomic_t fscache_n_object_dead;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 256)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 257) extern atomic_t fscache_n_checkaux_none;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 258) extern atomic_t fscache_n_checkaux_okay;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 259) extern atomic_t fscache_n_checkaux_update;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 260) extern atomic_t fscache_n_checkaux_obsolete;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 261)
52bd75fdb135d (David Howells 2009-11-19 18:11:08 +0000 262) extern atomic_t fscache_n_cop_alloc_object;
52bd75fdb135d (David Howells 2009-11-19 18:11:08 +0000 263) extern atomic_t fscache_n_cop_lookup_object;
52bd75fdb135d (David Howells 2009-11-19 18:11:08 +0000 264) extern atomic_t fscache_n_cop_lookup_complete;
52bd75fdb135d (David Howells 2009-11-19 18:11:08 +0000 265) extern atomic_t fscache_n_cop_grab_object;
ef778e7ae67cd (David Howells 2012-12-20 21:52:36 +0000 266) extern atomic_t fscache_n_cop_invalidate_object;
52bd75fdb135d (David Howells 2009-11-19 18:11:08 +0000 267) extern atomic_t fscache_n_cop_update_object;
52bd75fdb135d (David Howells 2009-11-19 18:11:08 +0000 268) extern atomic_t fscache_n_cop_drop_object;
52bd75fdb135d (David Howells 2009-11-19 18:11:08 +0000 269) extern atomic_t fscache_n_cop_put_object;
52bd75fdb135d (David Howells 2009-11-19 18:11:08 +0000 270) extern atomic_t fscache_n_cop_sync_cache;
52bd75fdb135d (David Howells 2009-11-19 18:11:08 +0000 271) extern atomic_t fscache_n_cop_attr_changed;
52bd75fdb135d (David Howells 2009-11-19 18:11:08 +0000 272) extern atomic_t fscache_n_cop_read_or_alloc_page;
52bd75fdb135d (David Howells 2009-11-19 18:11:08 +0000 273) extern atomic_t fscache_n_cop_read_or_alloc_pages;
52bd75fdb135d (David Howells 2009-11-19 18:11:08 +0000 274) extern atomic_t fscache_n_cop_allocate_page;
52bd75fdb135d (David Howells 2009-11-19 18:11:08 +0000 275) extern atomic_t fscache_n_cop_allocate_pages;
52bd75fdb135d (David Howells 2009-11-19 18:11:08 +0000 276) extern atomic_t fscache_n_cop_write_page;
52bd75fdb135d (David Howells 2009-11-19 18:11:08 +0000 277) extern atomic_t fscache_n_cop_uncache_page;
52bd75fdb135d (David Howells 2009-11-19 18:11:08 +0000 278) extern atomic_t fscache_n_cop_dissociate_pages;
52bd75fdb135d (David Howells 2009-11-19 18:11:08 +0000 279)
182d919b84902 (David Howells 2015-02-19 23:47:31 +0000 280) extern atomic_t fscache_n_cache_no_space_reject;
182d919b84902 (David Howells 2015-02-19 23:47:31 +0000 281) extern atomic_t fscache_n_cache_stale_objects;
182d919b84902 (David Howells 2015-02-19 23:47:31 +0000 282) extern atomic_t fscache_n_cache_retired_objects;
182d919b84902 (David Howells 2015-02-19 23:47:31 +0000 283) extern atomic_t fscache_n_cache_culled_objects;
182d919b84902 (David Howells 2015-02-19 23:47:31 +0000 284)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 285) static inline void fscache_stat(atomic_t *stat)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 286) {
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 287) atomic_inc(stat);
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 288) }
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 289)
52bd75fdb135d (David Howells 2009-11-19 18:11:08 +0000 290) static inline void fscache_stat_d(atomic_t *stat)
52bd75fdb135d (David Howells 2009-11-19 18:11:08 +0000 291) {
52bd75fdb135d (David Howells 2009-11-19 18:11:08 +0000 292) atomic_dec(stat);
52bd75fdb135d (David Howells 2009-11-19 18:11:08 +0000 293) }
52bd75fdb135d (David Howells 2009-11-19 18:11:08 +0000 294)
60d543ca724be (David Howells 2009-11-19 18:11:45 +0000 295) #define __fscache_stat(stat) (stat)
60d543ca724be (David Howells 2009-11-19 18:11:45 +0000 296)
3f3942aca6da3 (Christoph Hellwig 2018-05-15 15:57:23 +0200 297) int fscache_stats_show(struct seq_file *m, void *v);
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 298) #else
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 299)
60d543ca724be (David Howells 2009-11-19 18:11:45 +0000 300) #define __fscache_stat(stat) (NULL)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 301) #define fscache_stat(stat) do {} while (0)
4fa9f4ede88b4 (David Howells 2009-11-20 21:50:44 +0000 302) #define fscache_stat_d(stat) do {} while (0)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 303) #endif
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 304)
0e04d4cefcf4d (David Howells 2009-04-03 16:42:37 +0100 305) /*
0e04d4cefcf4d (David Howells 2009-04-03 16:42:37 +0100 306) * raise an event on an object
0e04d4cefcf4d (David Howells 2009-04-03 16:42:37 +0100 307) * - if the event is not masked for that object, then the object is
0e04d4cefcf4d (David Howells 2009-04-03 16:42:37 +0100 308) * queued for attention by the thread pool.
0e04d4cefcf4d (David Howells 2009-04-03 16:42:37 +0100 309) */
0e04d4cefcf4d (David Howells 2009-04-03 16:42:37 +0100 310) static inline void fscache_raise_event(struct fscache_object *object,
0e04d4cefcf4d (David Howells 2009-04-03 16:42:37 +0100 311) unsigned event)
0e04d4cefcf4d (David Howells 2009-04-03 16:42:37 +0100 312) {
8d76349d35906 (David Howells 2012-12-05 13:34:48 +0000 313) BUG_ON(event >= NR_FSCACHE_OBJECT_EVENTS);
caaef6900befb (David Howells 2013-05-10 19:50:26 +0100 314) #if 0
caaef6900befb (David Howells 2013-05-10 19:50:26 +0100 315) printk("*** fscache_raise_event(OBJ%d{%lx},%x)\n",
caaef6900befb (David Howells 2013-05-10 19:50:26 +0100 316) object->debug_id, object->event_mask, (1 << event));
caaef6900befb (David Howells 2013-05-10 19:50:26 +0100 317) #endif
36c9559022850 (David Howells 2009-04-03 16:42:38 +0100 318) if (!test_and_set_bit(event, &object->events) &&
36c9559022850 (David Howells 2009-04-03 16:42:38 +0100 319) test_bit(event, &object->event_mask))
36c9559022850 (David Howells 2009-04-03 16:42:38 +0100 320) fscache_enqueue_object(object);
36c9559022850 (David Howells 2009-04-03 16:42:38 +0100 321) }
36c9559022850 (David Howells 2009-04-03 16:42:38 +0100 322)
a18feb55769b7 (David Howells 2018-04-04 13:41:27 +0100 323) static inline void fscache_cookie_get(struct fscache_cookie *cookie,
a18feb55769b7 (David Howells 2018-04-04 13:41:27 +0100 324) enum fscache_cookie_trace where)
36c9559022850 (David Howells 2009-04-03 16:42:38 +0100 325) {
a18feb55769b7 (David Howells 2018-04-04 13:41:27 +0100 326) int usage = atomic_inc_return(&cookie->usage);
a18feb55769b7 (David Howells 2018-04-04 13:41:27 +0100 327)
a18feb55769b7 (David Howells 2018-04-04 13:41:27 +0100 328) trace_fscache_cookie(cookie, where, usage);
0e04d4cefcf4d (David Howells 2009-04-03 16:42:37 +0100 329) }
0e04d4cefcf4d (David Howells 2009-04-03 16:42:37 +0100 330)
b510882281d56 (David Howells 2009-04-03 16:42:39 +0100 331) /*
b510882281d56 (David Howells 2009-04-03 16:42:39 +0100 332) * get an extra reference to a netfs retrieval context
b510882281d56 (David Howells 2009-04-03 16:42:39 +0100 333) */
b510882281d56 (David Howells 2009-04-03 16:42:39 +0100 334) static inline
b510882281d56 (David Howells 2009-04-03 16:42:39 +0100 335) void *fscache_get_context(struct fscache_cookie *cookie, void *context)
b510882281d56 (David Howells 2009-04-03 16:42:39 +0100 336) {
b510882281d56 (David Howells 2009-04-03 16:42:39 +0100 337) if (cookie->def->get_context)
b510882281d56 (David Howells 2009-04-03 16:42:39 +0100 338) cookie->def->get_context(cookie->netfs_data, context);
b510882281d56 (David Howells 2009-04-03 16:42:39 +0100 339) return context;
b510882281d56 (David Howells 2009-04-03 16:42:39 +0100 340) }
b510882281d56 (David Howells 2009-04-03 16:42:39 +0100 341)
b510882281d56 (David Howells 2009-04-03 16:42:39 +0100 342) /*
b510882281d56 (David Howells 2009-04-03 16:42:39 +0100 343) * release a reference to a netfs retrieval context
b510882281d56 (David Howells 2009-04-03 16:42:39 +0100 344) */
b510882281d56 (David Howells 2009-04-03 16:42:39 +0100 345) static inline
b510882281d56 (David Howells 2009-04-03 16:42:39 +0100 346) void fscache_put_context(struct fscache_cookie *cookie, void *context)
b510882281d56 (David Howells 2009-04-03 16:42:39 +0100 347) {
b510882281d56 (David Howells 2009-04-03 16:42:39 +0100 348) if (cookie->def->put_context)
b510882281d56 (David Howells 2009-04-03 16:42:39 +0100 349) cookie->def->put_context(cookie->netfs_data, context);
b510882281d56 (David Howells 2009-04-03 16:42:39 +0100 350) }
b510882281d56 (David Howells 2009-04-03 16:42:39 +0100 351)
402cb8dda949d (David Howells 2018-04-04 13:41:28 +0100 352) /*
402cb8dda949d (David Howells 2018-04-04 13:41:28 +0100 353) * Update the auxiliary data on a cookie.
402cb8dda949d (David Howells 2018-04-04 13:41:28 +0100 354) */
402cb8dda949d (David Howells 2018-04-04 13:41:28 +0100 355) static inline
402cb8dda949d (David Howells 2018-04-04 13:41:28 +0100 356) void fscache_update_aux(struct fscache_cookie *cookie, const void *aux_data)
402cb8dda949d (David Howells 2018-04-04 13:41:28 +0100 357) {
402cb8dda949d (David Howells 2018-04-04 13:41:28 +0100 358) void *p;
402cb8dda949d (David Howells 2018-04-04 13:41:28 +0100 359)
402cb8dda949d (David Howells 2018-04-04 13:41:28 +0100 360) if (!aux_data)
402cb8dda949d (David Howells 2018-04-04 13:41:28 +0100 361) return;
402cb8dda949d (David Howells 2018-04-04 13:41:28 +0100 362) if (cookie->aux_len <= sizeof(cookie->inline_aux))
402cb8dda949d (David Howells 2018-04-04 13:41:28 +0100 363) p = cookie->inline_aux;
402cb8dda949d (David Howells 2018-04-04 13:41:28 +0100 364) else
402cb8dda949d (David Howells 2018-04-04 13:41:28 +0100 365) p = cookie->aux;
402cb8dda949d (David Howells 2018-04-04 13:41:28 +0100 366)
402cb8dda949d (David Howells 2018-04-04 13:41:28 +0100 367) if (memcmp(p, aux_data, cookie->aux_len) != 0) {
402cb8dda949d (David Howells 2018-04-04 13:41:28 +0100 368) memcpy(p, aux_data, cookie->aux_len);
402cb8dda949d (David Howells 2018-04-04 13:41:28 +0100 369) set_bit(FSCACHE_COOKIE_AUX_UPDATED, &cookie->flags);
402cb8dda949d (David Howells 2018-04-04 13:41:28 +0100 370) }
402cb8dda949d (David Howells 2018-04-04 13:41:28 +0100 371) }
402cb8dda949d (David Howells 2018-04-04 13:41:28 +0100 372)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 373) /*****************************************************************************/
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 374) /*
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 375) * debug tracing
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 376) */
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 377) #define dbgprintk(FMT, ...) \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 378) printk(KERN_DEBUG "[%-6.6s] "FMT"\n", current->comm, ##__VA_ARGS__)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 379)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 380) #define kenter(FMT, ...) dbgprintk("==> %s("FMT")", __func__, ##__VA_ARGS__)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 381) #define kleave(FMT, ...) dbgprintk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 382) #define kdebug(FMT, ...) dbgprintk(FMT, ##__VA_ARGS__)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 383)
12fdff3fc2483 (David Howells 2010-08-12 16:54:57 +0100 384) #define kjournal(FMT, ...) no_printk(FMT, ##__VA_ARGS__)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 385)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 386) #ifdef __KDEBUG
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 387) #define _enter(FMT, ...) kenter(FMT, ##__VA_ARGS__)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 388) #define _leave(FMT, ...) kleave(FMT, ##__VA_ARGS__)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 389) #define _debug(FMT, ...) kdebug(FMT, ##__VA_ARGS__)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 390)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 391) #elif defined(CONFIG_FSCACHE_DEBUG)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 392) #define _enter(FMT, ...) \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 393) do { \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 394) if (__do_kdebug(ENTER)) \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 395) kenter(FMT, ##__VA_ARGS__); \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 396) } while (0)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 397)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 398) #define _leave(FMT, ...) \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 399) do { \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 400) if (__do_kdebug(LEAVE)) \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 401) kleave(FMT, ##__VA_ARGS__); \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 402) } while (0)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 403)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 404) #define _debug(FMT, ...) \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 405) do { \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 406) if (__do_kdebug(DEBUG)) \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 407) kdebug(FMT, ##__VA_ARGS__); \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 408) } while (0)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 409)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 410) #else
12fdff3fc2483 (David Howells 2010-08-12 16:54:57 +0100 411) #define _enter(FMT, ...) no_printk("==> %s("FMT")", __func__, ##__VA_ARGS__)
12fdff3fc2483 (David Howells 2010-08-12 16:54:57 +0100 412) #define _leave(FMT, ...) no_printk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
12fdff3fc2483 (David Howells 2010-08-12 16:54:57 +0100 413) #define _debug(FMT, ...) no_printk(FMT, ##__VA_ARGS__)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 414) #endif
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 415)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 416) /*
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 417) * determine whether a particular optional debugging point should be logged
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 418) * - we need to go through three steps to persuade cpp to correctly join the
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 419) * shorthand in FSCACHE_DEBUG_LEVEL with its prefix
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 420) */
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 421) #define ____do_kdebug(LEVEL, POINT) \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 422) unlikely((fscache_debug & \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 423) (FSCACHE_POINT_##POINT << (FSCACHE_DEBUG_ ## LEVEL * 3))))
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 424) #define ___do_kdebug(LEVEL, POINT) \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 425) ____do_kdebug(LEVEL, POINT)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 426) #define __do_kdebug(POINT) \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 427) ___do_kdebug(FSCACHE_DEBUG_LEVEL, POINT)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 428)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 429) #define FSCACHE_DEBUG_CACHE 0
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 430) #define FSCACHE_DEBUG_COOKIE 1
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 431) #define FSCACHE_DEBUG_PAGE 2
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 432) #define FSCACHE_DEBUG_OPERATION 3
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 433)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 434) #define FSCACHE_POINT_ENTER 1
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 435) #define FSCACHE_POINT_LEAVE 2
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 436) #define FSCACHE_POINT_DEBUG 4
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 437)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 438) #ifndef FSCACHE_DEBUG_LEVEL
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 439) #define FSCACHE_DEBUG_LEVEL CACHE
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 440) #endif
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 441)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 442) /*
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 443) * assertions
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 444) */
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 445) #if 1 /* defined(__KDEBUGALL) */
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 446)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 447) #define ASSERT(X) \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 448) do { \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 449) if (unlikely(!(X))) { \
36dfd116edd48 (Fabian Frederick 2014-06-04 16:05:38 -0700 450) pr_err("\n"); \
36dfd116edd48 (Fabian Frederick 2014-06-04 16:05:38 -0700 451) pr_err("Assertion failed\n"); \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 452) BUG(); \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 453) } \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 454) } while (0)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 455)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 456) #define ASSERTCMP(X, OP, Y) \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 457) do { \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 458) if (unlikely(!((X) OP (Y)))) { \
36dfd116edd48 (Fabian Frederick 2014-06-04 16:05:38 -0700 459) pr_err("\n"); \
36dfd116edd48 (Fabian Frederick 2014-06-04 16:05:38 -0700 460) pr_err("Assertion failed\n"); \
36dfd116edd48 (Fabian Frederick 2014-06-04 16:05:38 -0700 461) pr_err("%lx " #OP " %lx is false\n", \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 462) (unsigned long)(X), (unsigned long)(Y)); \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 463) BUG(); \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 464) } \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 465) } while (0)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 466)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 467) #define ASSERTIF(C, X) \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 468) do { \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 469) if (unlikely((C) && !(X))) { \
36dfd116edd48 (Fabian Frederick 2014-06-04 16:05:38 -0700 470) pr_err("\n"); \
36dfd116edd48 (Fabian Frederick 2014-06-04 16:05:38 -0700 471) pr_err("Assertion failed\n"); \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 472) BUG(); \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 473) } \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 474) } while (0)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 475)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 476) #define ASSERTIFCMP(C, X, OP, Y) \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 477) do { \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 478) if (unlikely((C) && !((X) OP (Y)))) { \
36dfd116edd48 (Fabian Frederick 2014-06-04 16:05:38 -0700 479) pr_err("\n"); \
36dfd116edd48 (Fabian Frederick 2014-06-04 16:05:38 -0700 480) pr_err("Assertion failed\n"); \
36dfd116edd48 (Fabian Frederick 2014-06-04 16:05:38 -0700 481) pr_err("%lx " #OP " %lx is false\n", \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 482) (unsigned long)(X), (unsigned long)(Y)); \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 483) BUG(); \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 484) } \
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 485) } while (0)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 486)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 487) #else
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 488)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 489) #define ASSERT(X) do {} while (0)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 490) #define ASSERTCMP(X, OP, Y) do {} while (0)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 491) #define ASSERTIF(C, X) do {} while (0)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 492) #define ASSERTIFCMP(C, X, OP, Y) do {} while (0)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 493)
06b3db1b9bccd (David Howells 2009-04-03 16:42:36 +0100 494) #endif /* assert or not */