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/netfs.h> 9 #include <linux/fscache.h> 10 #include <trace/events/netfs.h> 11 12 #ifdef pr_fmt 13 #undef pr_fmt 14 #endif 15 16 #define pr_fmt(fmt) "netfs: " fmt 17 18 /* 19 * buffered_read.c 20 */ 21 void netfs_rreq_unlock_folios(struct netfs_io_request *rreq); 22 23 /* 24 * io.c 25 */ 26 int netfs_begin_read(struct netfs_io_request *rreq, bool sync); 27 28 /* 29 * main.c 30 */ 31 extern unsigned int netfs_debug; 32 33 /* 34 * objects.c 35 */ 36 struct netfs_io_request *netfs_alloc_request(struct address_space *mapping, 37 struct file *file, 38 loff_t start, size_t len, 39 enum netfs_io_origin origin); 40 void netfs_get_request(struct netfs_io_request *rreq, enum netfs_rreq_ref_trace what); 41 void netfs_clear_subrequests(struct netfs_io_request *rreq, bool was_async); 42 void netfs_put_request(struct netfs_io_request *rreq, bool was_async, 43 enum netfs_rreq_ref_trace what); 44 struct netfs_io_subrequest *netfs_alloc_subrequest(struct netfs_io_request *rreq); 45 46 static inline void netfs_see_request(struct netfs_io_request *rreq, 47 enum netfs_rreq_ref_trace what) 48 { 49 trace_netfs_rreq_ref(rreq->debug_id, refcount_read(&rreq->ref), what); 50 } 51 52 /* 53 * stats.c 54 */ 55 #ifdef CONFIG_NETFS_STATS 56 extern atomic_t netfs_n_rh_readahead; 57 extern atomic_t netfs_n_rh_readpage; 58 extern atomic_t netfs_n_rh_rreq; 59 extern atomic_t netfs_n_rh_sreq; 60 extern atomic_t netfs_n_rh_download; 61 extern atomic_t netfs_n_rh_download_done; 62 extern atomic_t netfs_n_rh_download_failed; 63 extern atomic_t netfs_n_rh_download_instead; 64 extern atomic_t netfs_n_rh_read; 65 extern atomic_t netfs_n_rh_read_done; 66 extern atomic_t netfs_n_rh_read_failed; 67 extern atomic_t netfs_n_rh_zero; 68 extern atomic_t netfs_n_rh_short_read; 69 extern atomic_t netfs_n_rh_write; 70 extern atomic_t netfs_n_rh_write_begin; 71 extern atomic_t netfs_n_rh_write_done; 72 extern atomic_t netfs_n_rh_write_failed; 73 extern atomic_t netfs_n_rh_write_zskip; 74 75 76 static inline void netfs_stat(atomic_t *stat) 77 { 78 atomic_inc(stat); 79 } 80 81 static inline void netfs_stat_d(atomic_t *stat) 82 { 83 atomic_dec(stat); 84 } 85 86 #else 87 #define netfs_stat(x) do {} while(0) 88 #define netfs_stat_d(x) do {} while(0) 89 #endif 90 91 /* 92 * Miscellaneous functions. 93 */ 94 static inline bool netfs_is_cache_enabled(struct netfs_inode *ctx) 95 { 96 #if IS_ENABLED(CONFIG_FSCACHE) 97 struct fscache_cookie *cookie = ctx->cache; 98 99 return fscache_cookie_valid(cookie) && cookie->cache_priv && 100 fscache_cookie_enabled(cookie); 101 #else 102 return false; 103 #endif 104 } 105 106 /*****************************************************************************/ 107 /* 108 * debug tracing 109 */ 110 #define dbgprintk(FMT, ...) \ 111 printk("[%-6.6s] "FMT"\n", current->comm, ##__VA_ARGS__) 112 113 #define kenter(FMT, ...) dbgprintk("==> %s("FMT")", __func__, ##__VA_ARGS__) 114 #define kleave(FMT, ...) dbgprintk("<== %s()"FMT"", __func__, ##__VA_ARGS__) 115 #define kdebug(FMT, ...) dbgprintk(FMT, ##__VA_ARGS__) 116 117 #ifdef __KDEBUG 118 #define _enter(FMT, ...) kenter(FMT, ##__VA_ARGS__) 119 #define _leave(FMT, ...) kleave(FMT, ##__VA_ARGS__) 120 #define _debug(FMT, ...) kdebug(FMT, ##__VA_ARGS__) 121 122 #elif defined(CONFIG_NETFS_DEBUG) 123 #define _enter(FMT, ...) \ 124 do { \ 125 if (netfs_debug) \ 126 kenter(FMT, ##__VA_ARGS__); \ 127 } while (0) 128 129 #define _leave(FMT, ...) \ 130 do { \ 131 if (netfs_debug) \ 132 kleave(FMT, ##__VA_ARGS__); \ 133 } while (0) 134 135 #define _debug(FMT, ...) \ 136 do { \ 137 if (netfs_debug) \ 138 kdebug(FMT, ##__VA_ARGS__); \ 139 } while (0) 140 141 #else 142 #define _enter(FMT, ...) no_printk("==> %s("FMT")", __func__, ##__VA_ARGS__) 143 #define _leave(FMT, ...) no_printk("<== %s()"FMT"", __func__, ##__VA_ARGS__) 144 #define _debug(FMT, ...) no_printk(FMT, ##__VA_ARGS__) 145 #endif 146