accel/qaic: Add AIC200 support
[drm/drm-misc.git] / fs / netfs / main.c
blob6c7be1377ee0edd9e7b2855dea6ca0d4bf893a1a
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.
5 * Written by David Howells (dhowells@redhat.com)
6 */
8 #include <linux/module.h>
9 #include <linux/export.h>
10 #include <linux/mempool.h>
11 #include <linux/proc_fs.h>
12 #include <linux/seq_file.h>
13 #include "internal.h"
14 #define CREATE_TRACE_POINTS
15 #include <trace/events/netfs.h>
17 MODULE_DESCRIPTION("Network fs support");
18 MODULE_AUTHOR("Red Hat, Inc.");
19 MODULE_LICENSE("GPL");
21 EXPORT_TRACEPOINT_SYMBOL(netfs_sreq);
23 unsigned netfs_debug;
24 module_param_named(debug, netfs_debug, uint, S_IWUSR | S_IRUGO);
25 MODULE_PARM_DESC(netfs_debug, "Netfs support debugging mask");
27 static struct kmem_cache *netfs_request_slab;
28 static struct kmem_cache *netfs_subrequest_slab;
29 mempool_t netfs_request_pool;
30 mempool_t netfs_subrequest_pool;
32 #ifdef CONFIG_PROC_FS
33 LIST_HEAD(netfs_io_requests);
34 DEFINE_SPINLOCK(netfs_proc_lock);
36 static const char *netfs_origins[nr__netfs_io_origin] = {
37 [NETFS_READAHEAD] = "RA",
38 [NETFS_READPAGE] = "RP",
39 [NETFS_READ_GAPS] = "RG",
40 [NETFS_READ_FOR_WRITE] = "RW",
41 [NETFS_DIO_READ] = "DR",
42 [NETFS_WRITEBACK] = "WB",
43 [NETFS_WRITETHROUGH] = "WT",
44 [NETFS_UNBUFFERED_WRITE] = "UW",
45 [NETFS_DIO_WRITE] = "DW",
46 [NETFS_PGPRIV2_COPY_TO_CACHE] = "2C",
50 * Generate a list of I/O requests in /proc/fs/netfs/requests
52 static int netfs_requests_seq_show(struct seq_file *m, void *v)
54 struct netfs_io_request *rreq;
56 if (v == &netfs_io_requests) {
57 seq_puts(m,
58 "REQUEST OR REF FL ERR OPS COVERAGE\n"
59 "======== == === == ==== === =========\n"
61 return 0;
64 rreq = list_entry(v, struct netfs_io_request, proc_link);
65 seq_printf(m,
66 "%08x %s %3d %2lx %4ld %3d @%04llx %llx/%llx",
67 rreq->debug_id,
68 netfs_origins[rreq->origin],
69 refcount_read(&rreq->ref),
70 rreq->flags,
71 rreq->error,
72 atomic_read(&rreq->nr_outstanding),
73 rreq->start, rreq->submitted, rreq->len);
74 seq_putc(m, '\n');
75 return 0;
78 static void *netfs_requests_seq_start(struct seq_file *m, loff_t *_pos)
79 __acquires(rcu)
81 rcu_read_lock();
82 return seq_list_start_head(&netfs_io_requests, *_pos);
85 static void *netfs_requests_seq_next(struct seq_file *m, void *v, loff_t *_pos)
87 return seq_list_next(v, &netfs_io_requests, _pos);
90 static void netfs_requests_seq_stop(struct seq_file *m, void *v)
91 __releases(rcu)
93 rcu_read_unlock();
96 static const struct seq_operations netfs_requests_seq_ops = {
97 .start = netfs_requests_seq_start,
98 .next = netfs_requests_seq_next,
99 .stop = netfs_requests_seq_stop,
100 .show = netfs_requests_seq_show,
102 #endif /* CONFIG_PROC_FS */
104 static int __init netfs_init(void)
106 int ret = -ENOMEM;
108 netfs_request_slab = kmem_cache_create("netfs_request",
109 sizeof(struct netfs_io_request), 0,
110 SLAB_HWCACHE_ALIGN | SLAB_ACCOUNT,
111 NULL);
112 if (!netfs_request_slab)
113 goto error_req;
115 if (mempool_init_slab_pool(&netfs_request_pool, 100, netfs_request_slab) < 0)
116 goto error_reqpool;
118 netfs_subrequest_slab = kmem_cache_create("netfs_subrequest",
119 sizeof(struct netfs_io_subrequest), 0,
120 SLAB_HWCACHE_ALIGN | SLAB_ACCOUNT,
121 NULL);
122 if (!netfs_subrequest_slab)
123 goto error_subreq;
125 if (mempool_init_slab_pool(&netfs_subrequest_pool, 100, netfs_subrequest_slab) < 0)
126 goto error_subreqpool;
128 if (!proc_mkdir("fs/netfs", NULL))
129 goto error_proc;
130 if (!proc_create_seq("fs/netfs/requests", S_IFREG | 0444, NULL,
131 &netfs_requests_seq_ops))
132 goto error_procfile;
133 #ifdef CONFIG_FSCACHE_STATS
134 if (!proc_create_single("fs/netfs/stats", S_IFREG | 0444, NULL,
135 netfs_stats_show))
136 goto error_procfile;
137 #endif
139 ret = fscache_init();
140 if (ret < 0)
141 goto error_fscache;
142 return 0;
144 error_fscache:
145 error_procfile:
146 remove_proc_subtree("fs/netfs", NULL);
147 error_proc:
148 mempool_exit(&netfs_subrequest_pool);
149 error_subreqpool:
150 kmem_cache_destroy(netfs_subrequest_slab);
151 error_subreq:
152 mempool_exit(&netfs_request_pool);
153 error_reqpool:
154 kmem_cache_destroy(netfs_request_slab);
155 error_req:
156 return ret;
158 fs_initcall(netfs_init);
160 static void __exit netfs_exit(void)
162 fscache_exit();
163 remove_proc_subtree("fs/netfs", NULL);
164 mempool_exit(&netfs_subrequest_pool);
165 kmem_cache_destroy(netfs_subrequest_slab);
166 mempool_exit(&netfs_request_pool);
167 kmem_cache_destroy(netfs_request_slab);
169 module_exit(netfs_exit);