1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Miscellaneous bits for the netfs support library.
4 * Copyright (C) 2022 Red Hat, Inc. All Rights Reserved.
8 #include <linux/module.h>
9 #include <linux/export.h>
10 #include <linux/proc_fs.h>
11 #include <linux/seq_file.h>
13 #define CREATE_TRACE_POINTS
14 #include <trace/events/netfs.h>
16 MODULE_DESCRIPTION("Network fs support");
17 MODULE_AUTHOR("Red Hat, Inc.");
18 MODULE_LICENSE("GPL");
20 EXPORT_TRACEPOINT_SYMBOL(netfs_sreq);
23 module_param_named(debug, netfs_debug, uint, S_IWUSR | S_IRUGO);
24 MODULE_PARM_DESC(netfs_debug, "Netfs support debugging mask");
27 LIST_HEAD(netfs_io_requests);
28 DEFINE_SPINLOCK(netfs_proc_lock);
30 static const char *netfs_origins[nr__netfs_io_origin] = {
31 [NETFS_READAHEAD] = "RA",
32 [NETFS_READPAGE] = "RP",
33 [NETFS_READ_FOR_WRITE] = "RW",
34 [NETFS_WRITEBACK] = "WB",
35 [NETFS_WRITETHROUGH] = "WT",
36 [NETFS_LAUNDER_WRITE] = "LW",
37 [NETFS_UNBUFFERED_WRITE] = "UW",
38 [NETFS_DIO_READ] = "DR",
39 [NETFS_DIO_WRITE] = "DW",
43 * Generate a list of I/O requests in /proc/fs/netfs/requests
45 static int netfs_requests_seq_show(struct seq_file *m, void *v)
47 struct netfs_io_request *rreq;
49 if (v == &netfs_io_requests) {
51 "REQUEST OR REF FL ERR OPS COVERAGE\n"
52 "======== == === == ==== === =========\n"
57 rreq = list_entry(v, struct netfs_io_request, proc_link);
59 "%08x %s %3d %2lx %4d %3d @%04llx %zx/%zx",
61 netfs_origins[rreq->origin],
62 refcount_read(&rreq->ref),
65 atomic_read(&rreq->nr_outstanding),
66 rreq->start, rreq->submitted, rreq->len);
71 static void *netfs_requests_seq_start(struct seq_file *m, loff_t *_pos)
75 return seq_list_start_head(&netfs_io_requests, *_pos);
78 static void *netfs_requests_seq_next(struct seq_file *m, void *v, loff_t *_pos)
80 return seq_list_next(v, &netfs_io_requests, _pos);
83 static void netfs_requests_seq_stop(struct seq_file *m, void *v)
89 static const struct seq_operations netfs_requests_seq_ops = {
90 .start = netfs_requests_seq_start,
91 .next = netfs_requests_seq_next,
92 .stop = netfs_requests_seq_stop,
93 .show = netfs_requests_seq_show,
95 #endif /* CONFIG_PROC_FS */
97 static int __init netfs_init(void)
101 if (!proc_mkdir("fs/netfs", NULL))
103 if (!proc_create_seq("fs/netfs/requests", S_IFREG | 0444, NULL,
104 &netfs_requests_seq_ops))
106 #ifdef CONFIG_FSCACHE_STATS
107 if (!proc_create_single("fs/netfs/stats", S_IFREG | 0444, NULL,
112 ret = fscache_init();
118 remove_proc_entry("fs/netfs", NULL);
122 fs_initcall(netfs_init);
124 static void __exit netfs_exit(void)
127 remove_proc_entry("fs/netfs", NULL);
129 module_exit(netfs_exit);