1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /* Internal definitions for network filesystem support
4 * Copyright (C) 2021 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
8 #include <linux/netfs.h>
9 #include <linux/fscache.h>
10 #include <trace/events/netfs.h>
16 #define pr_fmt(fmt) "netfs: " fmt
21 void netfs_rreq_unlock_folios(struct netfs_io_request *rreq);
26 int netfs_begin_read(struct netfs_io_request *rreq, bool sync);
31 extern unsigned int netfs_debug;
36 struct netfs_io_request *netfs_alloc_request(struct address_space *mapping,
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);
46 static inline void netfs_see_request(struct netfs_io_request *rreq,
47 enum netfs_rreq_ref_trace what)
49 trace_netfs_rreq_ref(rreq->debug_id, refcount_read(&rreq->ref), what);
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;
76 static inline void netfs_stat(atomic_t *stat)
81 static inline void netfs_stat_d(atomic_t *stat)
87 #define netfs_stat(x) do {} while(0)
88 #define netfs_stat_d(x) do {} while(0)
92 * Miscellaneous functions.
94 static inline bool netfs_is_cache_enabled(struct netfs_i_context *ctx)
96 #if IS_ENABLED(CONFIG_FSCACHE)
97 struct fscache_cookie *cookie = ctx->cache;
99 return fscache_cookie_valid(cookie) && cookie->cache_priv &&
100 fscache_cookie_enabled(cookie);
106 /*****************************************************************************/
110 #define dbgprintk(FMT, ...) \
111 printk("[%-6.6s] "FMT"\n", current->comm, ##__VA_ARGS__)
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__)
118 #define _enter(FMT, ...) kenter(FMT, ##__VA_ARGS__)
119 #define _leave(FMT, ...) kleave(FMT, ##__VA_ARGS__)
120 #define _debug(FMT, ...) kdebug(FMT, ##__VA_ARGS__)
122 #elif defined(CONFIG_NETFS_DEBUG)
123 #define _enter(FMT, ...) \
126 kenter(FMT, ##__VA_ARGS__); \
129 #define _leave(FMT, ...) \
132 kleave(FMT, ##__VA_ARGS__); \
135 #define _debug(FMT, ...) \
138 kdebug(FMT, ##__VA_ARGS__); \
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__)