13d3c9504SDavid Howells/* SPDX-License-Identifier: GPL-2.0-or-later */
23d3c9504SDavid Howells/* Internal definitions for network filesystem support
33d3c9504SDavid Howells *
43d3c9504SDavid Howells * Copyright (C) 2021 Red Hat, Inc. All Rights Reserved.
53d3c9504SDavid Howells * Written by David Howells (dhowells@redhat.com)
63d3c9504SDavid Howells */
73d3c9504SDavid Howells
83d3c9504SDavid Howells#ifdef pr_fmt
93d3c9504SDavid Howells#undef pr_fmt
103d3c9504SDavid Howells#endif
113d3c9504SDavid Howells
123d3c9504SDavid Howells#define pr_fmt(fmt) "netfs: " fmt
133d3c9504SDavid Howells
143d3c9504SDavid Howells/*
153d3c9504SDavid Howells * read_helper.c
163d3c9504SDavid Howells */
173d3c9504SDavid Howellsextern unsigned int netfs_debug;
183d3c9504SDavid Howells
19289af54cSDavid Howells/*
20289af54cSDavid Howells * stats.c
21289af54cSDavid Howells */
22289af54cSDavid Howells#ifdef CONFIG_NETFS_STATS
23289af54cSDavid Howellsextern atomic_t netfs_n_rh_readahead;
24289af54cSDavid Howellsextern atomic_t netfs_n_rh_readpage;
25289af54cSDavid Howellsextern atomic_t netfs_n_rh_rreq;
26289af54cSDavid Howellsextern atomic_t netfs_n_rh_sreq;
27289af54cSDavid Howellsextern atomic_t netfs_n_rh_download;
28289af54cSDavid Howellsextern atomic_t netfs_n_rh_download_done;
29289af54cSDavid Howellsextern atomic_t netfs_n_rh_download_failed;
30289af54cSDavid Howellsextern atomic_t netfs_n_rh_download_instead;
31289af54cSDavid Howellsextern atomic_t netfs_n_rh_read;
32289af54cSDavid Howellsextern atomic_t netfs_n_rh_read_done;
33289af54cSDavid Howellsextern atomic_t netfs_n_rh_read_failed;
34289af54cSDavid Howellsextern atomic_t netfs_n_rh_zero;
35289af54cSDavid Howellsextern atomic_t netfs_n_rh_short_read;
36289af54cSDavid Howellsextern atomic_t netfs_n_rh_write;
37e1b1240cSDavid Howellsextern atomic_t netfs_n_rh_write_begin;
38289af54cSDavid Howellsextern atomic_t netfs_n_rh_write_done;
39289af54cSDavid Howellsextern atomic_t netfs_n_rh_write_failed;
40e1b1240cSDavid Howellsextern atomic_t netfs_n_rh_write_zskip;
41289af54cSDavid Howells
42289af54cSDavid Howells
43289af54cSDavid Howellsstatic inline void netfs_stat(atomic_t *stat)
44289af54cSDavid Howells{
45289af54cSDavid Howells	atomic_inc(stat);
46289af54cSDavid Howells}
47289af54cSDavid Howells
48289af54cSDavid Howellsstatic inline void netfs_stat_d(atomic_t *stat)
49289af54cSDavid Howells{
50289af54cSDavid Howells	atomic_dec(stat);
51289af54cSDavid Howells}
52289af54cSDavid Howells
53289af54cSDavid Howells#else
543d3c9504SDavid Howells#define netfs_stat(x) do {} while(0)
553d3c9504SDavid Howells#define netfs_stat_d(x) do {} while(0)
56289af54cSDavid Howells#endif
573d3c9504SDavid Howells
583d3c9504SDavid Howells/*****************************************************************************/
593d3c9504SDavid Howells/*
603d3c9504SDavid Howells * debug tracing
613d3c9504SDavid Howells */
623d3c9504SDavid Howells#define dbgprintk(FMT, ...) \
633d3c9504SDavid Howells	printk("[%-6.6s] "FMT"\n", current->comm, ##__VA_ARGS__)
643d3c9504SDavid Howells
653d3c9504SDavid Howells#define kenter(FMT, ...) dbgprintk("==> %s("FMT")", __func__, ##__VA_ARGS__)
663d3c9504SDavid Howells#define kleave(FMT, ...) dbgprintk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
673d3c9504SDavid Howells#define kdebug(FMT, ...) dbgprintk(FMT, ##__VA_ARGS__)
683d3c9504SDavid Howells
693d3c9504SDavid Howells#ifdef __KDEBUG
703d3c9504SDavid Howells#define _enter(FMT, ...) kenter(FMT, ##__VA_ARGS__)
713d3c9504SDavid Howells#define _leave(FMT, ...) kleave(FMT, ##__VA_ARGS__)
723d3c9504SDavid Howells#define _debug(FMT, ...) kdebug(FMT, ##__VA_ARGS__)
733d3c9504SDavid Howells
743d3c9504SDavid Howells#elif defined(CONFIG_NETFS_DEBUG)
753d3c9504SDavid Howells#define _enter(FMT, ...)			\
763d3c9504SDavid Howellsdo {						\
773d3c9504SDavid Howells	if (netfs_debug)			\
783d3c9504SDavid Howells		kenter(FMT, ##__VA_ARGS__);	\
793d3c9504SDavid Howells} while (0)
803d3c9504SDavid Howells
813d3c9504SDavid Howells#define _leave(FMT, ...)			\
823d3c9504SDavid Howellsdo {						\
833d3c9504SDavid Howells	if (netfs_debug)			\
843d3c9504SDavid Howells		kleave(FMT, ##__VA_ARGS__);	\
853d3c9504SDavid Howells} while (0)
863d3c9504SDavid Howells
873d3c9504SDavid Howells#define _debug(FMT, ...)			\
883d3c9504SDavid Howellsdo {						\
893d3c9504SDavid Howells	if (netfs_debug)			\
903d3c9504SDavid Howells		kdebug(FMT, ##__VA_ARGS__);	\
913d3c9504SDavid Howells} while (0)
923d3c9504SDavid Howells
933d3c9504SDavid Howells#else
943d3c9504SDavid Howells#define _enter(FMT, ...) no_printk("==> %s("FMT")", __func__, ##__VA_ARGS__)
953d3c9504SDavid Howells#define _leave(FMT, ...) no_printk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
963d3c9504SDavid Howells#define _debug(FMT, ...) no_printk(FMT, ##__VA_ARGS__)
973d3c9504SDavid Howells#endif
98