]>
Commit | Line | Data |
---|---|---|
1a59d1b8 | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
1da177e4 LT |
2 | /* |
3 | * fs/cifs_debug.c | |
4 | * | |
b8643e1b | 5 | * Copyright (C) International Business Machines Corp., 2000,2005 |
1da177e4 LT |
6 | * |
7 | * Modified by Steve French (sfrench@us.ibm.com) | |
1da177e4 LT |
8 | */ |
9 | #include <linux/fs.h> | |
10 | #include <linux/string.h> | |
11 | #include <linux/ctype.h> | |
12 | #include <linux/module.h> | |
13 | #include <linux/proc_fs.h> | |
7c0f6ba6 | 14 | #include <linux/uaccess.h> |
1da177e4 LT |
15 | #include "cifspdu.h" |
16 | #include "cifsglob.h" | |
17 | #include "cifsproto.h" | |
18 | #include "cifs_debug.h" | |
6c91d362 | 19 | #include "cifsfs.h" |
94b0595a | 20 | #include "fs_context.h" |
54be1f6c PA |
21 | #ifdef CONFIG_CIFS_DFS_UPCALL |
22 | #include "dfs_cache.h" | |
23 | #endif | |
d8ec913b LL |
24 | #ifdef CONFIG_CIFS_SMB_DIRECT |
25 | #include "smbdirect.h" | |
26 | #endif | |
20fab0da | 27 | #include "cifs_swn.h" |
1da177e4 LT |
28 | |
29 | void | |
30 | cifs_dump_mem(char *label, void *data, int length) | |
31 | { | |
0b456f04 | 32 | pr_debug("%s: dump of %d bytes of data at 0x%p\n", label, length, data); |
55d83e0d AS |
33 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 4, |
34 | data, length, true); | |
1da177e4 LT |
35 | } |
36 | ||
14547f7d | 37 | void cifs_dump_detail(void *buf, struct TCP_Server_Info *server) |
3979877e | 38 | { |
8aa26f3e | 39 | #ifdef CONFIG_CIFS_DEBUG2 |
d4e4854f PS |
40 | struct smb_hdr *smb = (struct smb_hdr *)buf; |
41 | ||
f96637be JP |
42 | cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d\n", |
43 | smb->Command, smb->Status.CifsError, | |
44 | smb->Flags, smb->Flags2, smb->Mid, smb->Pid); | |
14547f7d | 45 | cifs_dbg(VFS, "smb buf %p len %u\n", smb, |
71992e62 | 46 | server->ops->calc_smb_size(smb, server)); |
8aa26f3e | 47 | #endif /* CONFIG_CIFS_DEBUG2 */ |
3979877e SF |
48 | } |
49 | ||
ffdd6e4d | 50 | void cifs_dump_mids(struct TCP_Server_Info *server) |
3979877e | 51 | { |
8aa26f3e | 52 | #ifdef CONFIG_CIFS_DEBUG2 |
3979877e | 53 | struct list_head *tmp; |
ffdd6e4d | 54 | struct mid_q_entry *mid_entry; |
3979877e | 55 | |
221601c3 | 56 | if (server == NULL) |
3979877e SF |
57 | return; |
58 | ||
f96637be | 59 | cifs_dbg(VFS, "Dump pending requests:\n"); |
3979877e SF |
60 | spin_lock(&GlobalMid_Lock); |
61 | list_for_each(tmp, &server->pending_mid_q) { | |
62 | mid_entry = list_entry(tmp, struct mid_q_entry, qhead); | |
f96637be JP |
63 | cifs_dbg(VFS, "State: %d Cmd: %d Pid: %d Cbdata: %p Mid %llu\n", |
64 | mid_entry->mid_state, | |
65 | le16_to_cpu(mid_entry->command), | |
66 | mid_entry->pid, | |
67 | mid_entry->callback_data, | |
68 | mid_entry->mid); | |
3979877e | 69 | #ifdef CONFIG_CIFS_STATS2 |
f96637be JP |
70 | cifs_dbg(VFS, "IsLarge: %d buf: %p time rcv: %ld now: %ld\n", |
71 | mid_entry->large_buf, | |
72 | mid_entry->resp_buf, | |
73 | mid_entry->when_received, | |
74 | jiffies); | |
3979877e | 75 | #endif /* STATS2 */ |
f96637be JP |
76 | cifs_dbg(VFS, "IsMult: %d IsEnd: %d\n", |
77 | mid_entry->multiRsp, mid_entry->multiEnd); | |
ad8b15f0 | 78 | if (mid_entry->resp_buf) { |
71992e62 | 79 | cifs_dump_detail(mid_entry->resp_buf, server); |
ad8b15f0 SF |
80 | cifs_dump_mem("existing buf: ", |
81 | mid_entry->resp_buf, 62); | |
3979877e SF |
82 | } |
83 | } | |
84 | spin_unlock(&GlobalMid_Lock); | |
3979877e | 85 | #endif /* CONFIG_CIFS_DEBUG2 */ |
8aa26f3e | 86 | } |
3979877e | 87 | |
1da177e4 | 88 | #ifdef CONFIG_PROC_FS |
02cf5905 AA |
89 | static void cifs_debug_tcon(struct seq_file *m, struct cifs_tcon *tcon) |
90 | { | |
91 | __u32 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType); | |
92 | ||
93 | seq_printf(m, "%s Mounts: %d ", tcon->treeName, tcon->tc_count); | |
94 | if (tcon->nativeFileSystem) | |
95 | seq_printf(m, "Type: %s ", tcon->nativeFileSystem); | |
96 | seq_printf(m, "DevInfo: 0x%x Attributes: 0x%x\n\tPathComponentMax: %d Status: %d", | |
97 | le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics), | |
98 | le32_to_cpu(tcon->fsAttrInfo.Attributes), | |
99 | le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength), | |
100 | tcon->tidStatus); | |
101 | if (dev_type == FILE_DEVICE_DISK) | |
102 | seq_puts(m, " type: DISK "); | |
103 | else if (dev_type == FILE_DEVICE_CD_ROM) | |
104 | seq_puts(m, " type: CDROM "); | |
105 | else | |
106 | seq_printf(m, " type: %d ", dev_type); | |
ab7b10cf SF |
107 | |
108 | seq_printf(m, "Serial Number: 0x%x", tcon->vol_serial_number); | |
109 | ||
ffd1ef1e SF |
110 | if ((tcon->seal) || |
111 | (tcon->ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA) || | |
112 | (tcon->share_flags & SHI1005_FLAGS_ENCRYPT_DATA)) | |
ede2e520 | 113 | seq_printf(m, " Encrypted"); |
5c5a41be SF |
114 | if (tcon->nocase) |
115 | seq_printf(m, " nocase"); | |
ede2e520 SF |
116 | if (tcon->unix_ext) |
117 | seq_printf(m, " POSIX Extensions"); | |
02cf5905 AA |
118 | if (tcon->ses->server->ops->dump_share_caps) |
119 | tcon->ses->server->ops->dump_share_caps(m, tcon); | |
20fab0da SC |
120 | if (tcon->use_witness) |
121 | seq_puts(m, " Witness"); | |
02cf5905 AA |
122 | |
123 | if (tcon->need_reconnect) | |
124 | seq_puts(m, "\tDISCONNECTED "); | |
125 | seq_putc(m, '\n'); | |
126 | } | |
127 | ||
85150929 AA |
128 | static void |
129 | cifs_dump_channel(struct seq_file *m, int i, struct cifs_chan *chan) | |
130 | { | |
131 | struct TCP_Server_Info *server = chan->server; | |
132 | ||
03e9bb1a SP |
133 | seq_printf(m, "\n\n\t\tChannel: %d ConnectionId: 0x%llx" |
134 | "\n\t\tNumber of credits: %d Dialect 0x%x" | |
135 | "\n\t\tTCP status: %d Instance: %d" | |
136 | "\n\t\tLocal Users To Server: %d SecMode: 0x%x Req On Wire: %d" | |
137 | "\n\t\tIn Send: %d In MaxReq Wait: %d", | |
138 | i+1, server->conn_id, | |
85150929 AA |
139 | server->credits, |
140 | server->dialect, | |
141 | server->tcpStatus, | |
142 | server->reconnect_instance, | |
143 | server->srv_count, | |
144 | server->sec_mode, | |
145 | in_flight(server), | |
146 | atomic_read(&server->in_send), | |
147 | atomic_read(&server->num_waiters)); | |
148 | } | |
149 | ||
bc0fe8b2 AA |
150 | static void |
151 | cifs_dump_iface(struct seq_file *m, struct cifs_server_iface *iface) | |
152 | { | |
153 | struct sockaddr_in *ipv4 = (struct sockaddr_in *)&iface->sockaddr; | |
154 | struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)&iface->sockaddr; | |
155 | ||
35a90807 | 156 | seq_printf(m, "\tSpeed: %zu bps\n", iface->speed); |
bc0fe8b2 AA |
157 | seq_puts(m, "\t\tCapabilities: "); |
158 | if (iface->rdma_capable) | |
159 | seq_puts(m, "rdma "); | |
160 | if (iface->rss_capable) | |
161 | seq_puts(m, "rss "); | |
162 | seq_putc(m, '\n'); | |
163 | if (iface->sockaddr.ss_family == AF_INET) | |
164 | seq_printf(m, "\t\tIPv4: %pI4\n", &ipv4->sin_addr); | |
165 | else if (iface->sockaddr.ss_family == AF_INET6) | |
166 | seq_printf(m, "\t\tIPv6: %pI6\n", &ipv6->sin6_addr); | |
167 | } | |
168 | ||
dfe33f9a SF |
169 | static int cifs_debug_files_proc_show(struct seq_file *m, void *v) |
170 | { | |
171 | struct list_head *stmp, *tmp, *tmp1, *tmp2; | |
172 | struct TCP_Server_Info *server; | |
173 | struct cifs_ses *ses; | |
174 | struct cifs_tcon *tcon; | |
175 | struct cifsFileInfo *cfile; | |
176 | ||
177 | seq_puts(m, "# Version:1\n"); | |
178 | seq_puts(m, "# Format:\n"); | |
179 | seq_puts(m, "# <tree id> <persistent fid> <flags> <count> <pid> <uid>"); | |
180 | #ifdef CONFIG_CIFS_DEBUG2 | |
181 | seq_printf(m, " <filename> <mid>\n"); | |
182 | #else | |
183 | seq_printf(m, " <filename>\n"); | |
184 | #endif /* CIFS_DEBUG2 */ | |
185 | spin_lock(&cifs_tcp_ses_lock); | |
186 | list_for_each(stmp, &cifs_tcp_ses_list) { | |
187 | server = list_entry(stmp, struct TCP_Server_Info, | |
188 | tcp_ses_list); | |
189 | list_for_each(tmp, &server->smb_ses_list) { | |
190 | ses = list_entry(tmp, struct cifs_ses, smb_ses_list); | |
191 | list_for_each(tmp1, &ses->tcon_list) { | |
192 | tcon = list_entry(tmp1, struct cifs_tcon, tcon_list); | |
193 | spin_lock(&tcon->open_file_lock); | |
194 | list_for_each(tmp2, &tcon->openFileList) { | |
195 | cfile = list_entry(tmp2, struct cifsFileInfo, | |
196 | tlist); | |
197 | seq_printf(m, | |
b9e4666f | 198 | "0x%x 0x%llx 0x%x %d %d %d %pd", |
dfe33f9a SF |
199 | tcon->tid, |
200 | cfile->fid.persistent_fid, | |
201 | cfile->f_flags, | |
202 | cfile->count, | |
203 | cfile->pid, | |
204 | from_kuid(&init_user_ns, cfile->uid), | |
b9e4666f | 205 | cfile->dentry); |
dfe33f9a | 206 | #ifdef CONFIG_CIFS_DEBUG2 |
bf1bc694 | 207 | seq_printf(m, " %llu\n", cfile->fid.mid); |
dfe33f9a SF |
208 | #else |
209 | seq_printf(m, "\n"); | |
210 | #endif /* CIFS_DEBUG2 */ | |
211 | } | |
212 | spin_unlock(&tcon->open_file_lock); | |
213 | } | |
214 | } | |
215 | } | |
216 | spin_unlock(&cifs_tcp_ses_lock); | |
217 | seq_putc(m, '\n'); | |
218 | return 0; | |
219 | } | |
220 | ||
f984c7b9 | 221 | static int cifs_debug_data_proc_show(struct seq_file *m, void *v) |
1da177e4 | 222 | { |
f1987b44 | 223 | struct list_head *tmp1, *tmp2, *tmp3; |
ffdd6e4d | 224 | struct mid_q_entry *mid_entry; |
14fbf50d | 225 | struct TCP_Server_Info *server; |
96daf2b0 SF |
226 | struct cifs_ses *ses; |
227 | struct cifs_tcon *tcon; | |
03e9bb1a | 228 | int c, i, j; |
1da177e4 | 229 | |
f984c7b9 | 230 | seq_puts(m, |
1da177e4 LT |
231 | "Display Internal CIFS Data Structures for Debugging\n" |
232 | "---------------------------------------------------\n"); | |
f984c7b9 | 233 | seq_printf(m, "CIFS Version %s\n", CIFS_VERSION); |
ca40b714 | 234 | seq_printf(m, "Features:"); |
f579903e | 235 | #ifdef CONFIG_CIFS_DFS_UPCALL |
950132af | 236 | seq_printf(m, " DFS"); |
f579903e SJ |
237 | #endif |
238 | #ifdef CONFIG_CIFS_FSCACHE | |
950132af SF |
239 | seq_printf(m, ",FSCACHE"); |
240 | #endif | |
241 | #ifdef CONFIG_CIFS_SMB_DIRECT | |
242 | seq_printf(m, ",SMB_DIRECT"); | |
243 | #endif | |
244 | #ifdef CONFIG_CIFS_STATS2 | |
245 | seq_printf(m, ",STATS2"); | |
d2586500 | 246 | #else |
950132af SF |
247 | seq_printf(m, ",STATS"); |
248 | #endif | |
249 | #ifdef CONFIG_CIFS_DEBUG2 | |
250 | seq_printf(m, ",DEBUG2"); | |
251 | #elif defined(CONFIG_CIFS_DEBUG) | |
252 | seq_printf(m, ",DEBUG"); | |
253 | #endif | |
254 | #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY | |
255 | seq_printf(m, ",ALLOW_INSECURE_LEGACY"); | |
f579903e SJ |
256 | #endif |
257 | #ifdef CONFIG_CIFS_WEAK_PW_HASH | |
950132af | 258 | seq_printf(m, ",WEAK_PW_HASH"); |
f579903e SJ |
259 | #endif |
260 | #ifdef CONFIG_CIFS_POSIX | |
950132af | 261 | seq_printf(m, ",CIFS_POSIX"); |
f579903e SJ |
262 | #endif |
263 | #ifdef CONFIG_CIFS_UPCALL | |
950132af | 264 | seq_printf(m, ",UPCALL(SPNEGO)"); |
f579903e SJ |
265 | #endif |
266 | #ifdef CONFIG_CIFS_XATTR | |
950132af | 267 | seq_printf(m, ",XATTR"); |
ca40b714 | 268 | #endif |
950132af | 269 | seq_printf(m, ",ACL"); |
20fab0da SC |
270 | #ifdef CONFIG_CIFS_SWN_UPCALL |
271 | seq_puts(m, ",WITNESS"); | |
272 | #endif | |
f579903e | 273 | seq_putc(m, '\n'); |
a5f1a81f | 274 | seq_printf(m, "CIFSMaxBufSize: %d\n", CIFSMaxBufSize); |
f984c7b9 | 275 | seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid); |
1da177e4 | 276 | |
03e9bb1a SP |
277 | seq_printf(m, "\nServers: "); |
278 | ||
279 | c = 0; | |
3f9bcca7 | 280 | spin_lock(&cifs_tcp_ses_lock); |
f1987b44 JL |
281 | list_for_each(tmp1, &cifs_tcp_ses_list) { |
282 | server = list_entry(tmp1, struct TCP_Server_Info, | |
14fbf50d | 283 | tcp_ses_list); |
08a3b969 | 284 | |
03e9bb1a SP |
285 | /* channel info will be printed as a part of sessions below */ |
286 | if (server->is_channel) | |
287 | continue; | |
288 | ||
289 | c++; | |
290 | seq_printf(m, "\n%d) ConnectionId: 0x%llx ", | |
291 | c, server->conn_id); | |
292 | ||
40f077a0 SF |
293 | if (server->hostname) |
294 | seq_printf(m, "Hostname: %s ", server->hostname); | |
08a3b969 LL |
295 | #ifdef CONFIG_CIFS_SMB_DIRECT |
296 | if (!server->rdma) | |
297 | goto skip_rdma; | |
298 | ||
14cc639c LL |
299 | if (!server->smbd_conn) { |
300 | seq_printf(m, "\nSMBDirect transport not available"); | |
301 | goto skip_rdma; | |
302 | } | |
303 | ||
08a3b969 LL |
304 | seq_printf(m, "\nSMBDirect (in hex) protocol version: %x " |
305 | "transport status: %x", | |
306 | server->smbd_conn->protocol, | |
307 | server->smbd_conn->transport_status); | |
308 | seq_printf(m, "\nConn receive_credit_max: %x " | |
309 | "send_credit_target: %x max_send_size: %x", | |
310 | server->smbd_conn->receive_credit_max, | |
311 | server->smbd_conn->send_credit_target, | |
312 | server->smbd_conn->max_send_size); | |
313 | seq_printf(m, "\nConn max_fragmented_recv_size: %x " | |
314 | "max_fragmented_send_size: %x max_receive_size:%x", | |
315 | server->smbd_conn->max_fragmented_recv_size, | |
316 | server->smbd_conn->max_fragmented_send_size, | |
317 | server->smbd_conn->max_receive_size); | |
318 | seq_printf(m, "\nConn keep_alive_interval: %x " | |
319 | "max_readwrite_size: %x rdma_readwrite_threshold: %x", | |
320 | server->smbd_conn->keep_alive_interval, | |
321 | server->smbd_conn->max_readwrite_size, | |
322 | server->smbd_conn->rdma_readwrite_threshold); | |
323 | seq_printf(m, "\nDebug count_get_receive_buffer: %x " | |
324 | "count_put_receive_buffer: %x count_send_empty: %x", | |
325 | server->smbd_conn->count_get_receive_buffer, | |
326 | server->smbd_conn->count_put_receive_buffer, | |
327 | server->smbd_conn->count_send_empty); | |
328 | seq_printf(m, "\nRead Queue count_reassembly_queue: %x " | |
329 | "count_enqueue_reassembly_queue: %x " | |
330 | "count_dequeue_reassembly_queue: %x " | |
331 | "fragment_reassembly_remaining: %x " | |
332 | "reassembly_data_length: %x " | |
333 | "reassembly_queue_length: %x", | |
334 | server->smbd_conn->count_reassembly_queue, | |
335 | server->smbd_conn->count_enqueue_reassembly_queue, | |
336 | server->smbd_conn->count_dequeue_reassembly_queue, | |
337 | server->smbd_conn->fragment_reassembly_remaining, | |
338 | server->smbd_conn->reassembly_data_length, | |
339 | server->smbd_conn->reassembly_queue_length); | |
340 | seq_printf(m, "\nCurrent Credits send_credits: %x " | |
341 | "receive_credits: %x receive_credit_target: %x", | |
342 | atomic_read(&server->smbd_conn->send_credits), | |
343 | atomic_read(&server->smbd_conn->receive_credits), | |
344 | server->smbd_conn->receive_credit_target); | |
072a14ec LL |
345 | seq_printf(m, "\nPending send_pending: %x ", |
346 | atomic_read(&server->smbd_conn->send_pending)); | |
08a3b969 LL |
347 | seq_printf(m, "\nReceive buffers count_receive_queue: %x " |
348 | "count_empty_packet_queue: %x", | |
349 | server->smbd_conn->count_receive_queue, | |
350 | server->smbd_conn->count_empty_packet_queue); | |
351 | seq_printf(m, "\nMR responder_resources: %x " | |
352 | "max_frmr_depth: %x mr_type: %x", | |
353 | server->smbd_conn->responder_resources, | |
354 | server->smbd_conn->max_frmr_depth, | |
355 | server->smbd_conn->mr_type); | |
356 | seq_printf(m, "\nMR mr_ready_count: %x mr_used_count: %x", | |
357 | atomic_read(&server->smbd_conn->mr_ready_count), | |
358 | atomic_read(&server->smbd_conn->mr_used_count)); | |
359 | skip_rdma: | |
360 | #endif | |
ede2e520 SF |
361 | seq_printf(m, "\nNumber of credits: %d Dialect 0x%x", |
362 | server->credits, server->dialect); | |
26ea888f SF |
363 | if (server->compress_algorithm == SMB3_COMPRESS_LZNT1) |
364 | seq_printf(m, " COMPRESS_LZNT1"); | |
365 | else if (server->compress_algorithm == SMB3_COMPRESS_LZ77) | |
366 | seq_printf(m, " COMPRESS_LZ77"); | |
367 | else if (server->compress_algorithm == SMB3_COMPRESS_LZ77_HUFF) | |
368 | seq_printf(m, " COMPRESS_LZ77_HUFF"); | |
ede2e520 SF |
369 | if (server->sign) |
370 | seq_printf(m, " signed"); | |
fcef0db6 SF |
371 | if (server->posix_ext_supported) |
372 | seq_printf(m, " posix"); | |
0fdfef9a | 373 | |
03e9bb1a SP |
374 | if (server->rdma) |
375 | seq_printf(m, "\nRDMA "); | |
376 | seq_printf(m, "\nTCP status: %d Instance: %d" | |
377 | "\nLocal Users To Server: %d SecMode: 0x%x Req On Wire: %d", | |
378 | server->tcpStatus, | |
379 | server->reconnect_instance, | |
380 | server->srv_count, | |
381 | server->sec_mode, in_flight(server)); | |
382 | ||
383 | seq_printf(m, "\nIn Send: %d In MaxReq Wait: %d", | |
384 | atomic_read(&server->in_send), | |
385 | atomic_read(&server->num_waiters)); | |
386 | ||
387 | seq_printf(m, "\n\n\tSessions: "); | |
388 | i = 0; | |
14fbf50d | 389 | list_for_each(tmp2, &server->smb_ses_list) { |
96daf2b0 | 390 | ses = list_entry(tmp2, struct cifs_ses, |
14fbf50d | 391 | smb_ses_list); |
03e9bb1a | 392 | i++; |
14fbf50d JL |
393 | if ((ses->serverDomain == NULL) || |
394 | (ses->serverOS == NULL) || | |
395 | (ses->serverNOS == NULL)) { | |
40f077a0 | 396 | seq_printf(m, "\n\t%d) Address: %s Uses: %d Capability: 0x%x\tSession Status: %d ", |
b438fcf1 | 397 | i, ses->ip_addr, ses->ses_count, |
1fa089ec SF |
398 | ses->capabilities, ses->status); |
399 | if (ses->session_flags & SMB2_SESSION_FLAG_IS_GUEST) | |
03e9bb1a | 400 | seq_printf(m, "Guest "); |
1fa089ec | 401 | else if (ses->session_flags & SMB2_SESSION_FLAG_IS_NULL) |
03e9bb1a | 402 | seq_printf(m, "Anonymous "); |
14fbf50d JL |
403 | } else { |
404 | seq_printf(m, | |
03e9bb1a SP |
405 | "\n\t%d) Name: %s Domain: %s Uses: %d OS: %s " |
406 | "\n\tNOS: %s\tCapability: 0x%x" | |
407 | "\n\tSMB session status: %d ", | |
b438fcf1 | 408 | i, ses->ip_addr, ses->serverDomain, |
14fbf50d | 409 | ses->ses_count, ses->serverOS, ses->serverNOS, |
221601c3 | 410 | ses->capabilities, ses->status); |
14fbf50d | 411 | } |
8e84a61a | 412 | |
03e9bb1a | 413 | seq_printf(m, "\n\tSecurity type: %s ", |
0b0430c6 | 414 | get_security_type_str(server->ops->select_sectype(server, ses->sectype))); |
8e84a61a | 415 | |
b63a9de0 SF |
416 | /* dump session id helpful for use with network trace */ |
417 | seq_printf(m, " SessionId: 0x%llx", ses->Suid); | |
ffd1ef1e SF |
418 | if (ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA) |
419 | seq_puts(m, " encrypted"); | |
420 | if (ses->sign) | |
421 | seq_puts(m, " signed"); | |
131afd0b | 422 | |
aadd69ca PA |
423 | seq_printf(m, "\n\tUser: %d Cred User: %d", |
424 | from_kuid(&init_user_ns, ses->linux_uid), | |
425 | from_kuid(&init_user_ns, ses->cred_uid)); | |
426 | ||
85150929 | 427 | if (ses->chan_count > 1) { |
03e9bb1a | 428 | seq_printf(m, "\n\n\tExtra Channels: %zu ", |
85150929 AA |
429 | ses->chan_count-1); |
430 | for (j = 1; j < ses->chan_count; j++) | |
431 | cifs_dump_channel(m, j, &ses->chans[j]); | |
432 | } | |
433 | ||
03e9bb1a | 434 | seq_puts(m, "\n\n\tShares: "); |
f1987b44 | 435 | j = 0; |
02cf5905 AA |
436 | |
437 | seq_printf(m, "\n\t%d) IPC: ", j); | |
438 | if (ses->tcon_ipc) | |
439 | cifs_debug_tcon(m, ses->tcon_ipc); | |
440 | else | |
441 | seq_puts(m, "none\n"); | |
442 | ||
f1987b44 | 443 | list_for_each(tmp3, &ses->tcon_list) { |
96daf2b0 | 444 | tcon = list_entry(tmp3, struct cifs_tcon, |
f1987b44 JL |
445 | tcon_list); |
446 | ++j; | |
02cf5905 AA |
447 | seq_printf(m, "\n\t%d) ", j); |
448 | cifs_debug_tcon(m, tcon); | |
f1987b44 JL |
449 | } |
450 | ||
bc0fe8b2 | 451 | spin_lock(&ses->iface_lock); |
115d5d28 | 452 | if (ses->iface_count) |
03e9bb1a | 453 | seq_printf(m, "\n\n\tServer interfaces: %zu", |
115d5d28 | 454 | ses->iface_count); |
bc0fe8b2 | 455 | for (j = 0; j < ses->iface_count; j++) { |
85150929 AA |
456 | struct cifs_server_iface *iface; |
457 | ||
458 | iface = &ses->iface_list[j]; | |
03e9bb1a | 459 | seq_printf(m, "\n\t%d)", j+1); |
85150929 AA |
460 | cifs_dump_iface(m, iface); |
461 | if (is_ses_using_iface(ses, iface)) | |
462 | seq_puts(m, "\t\t[CONNECTED]\n"); | |
bc0fe8b2 AA |
463 | } |
464 | spin_unlock(&ses->iface_lock); | |
1da177e4 | 465 | } |
03e9bb1a SP |
466 | if (i == 0) |
467 | seq_printf(m, "\n\t\t[NONE]"); | |
468 | ||
469 | seq_puts(m, "\n\n\tMIDs: "); | |
470 | spin_lock(&GlobalMid_Lock); | |
471 | list_for_each(tmp3, &server->pending_mid_q) { | |
472 | mid_entry = list_entry(tmp3, struct mid_q_entry, | |
473 | qhead); | |
474 | seq_printf(m, "\n\tState: %d com: %d pid:" | |
475 | " %d cbdata: %p mid %llu\n", | |
476 | mid_entry->mid_state, | |
477 | le16_to_cpu(mid_entry->command), | |
478 | mid_entry->pid, | |
479 | mid_entry->callback_data, | |
480 | mid_entry->mid); | |
481 | } | |
482 | spin_unlock(&GlobalMid_Lock); | |
483 | seq_printf(m, "\n--\n"); | |
1da177e4 | 484 | } |
03e9bb1a SP |
485 | if (c == 0) |
486 | seq_printf(m, "\n\t[NONE]"); | |
487 | ||
3f9bcca7 | 488 | spin_unlock(&cifs_tcp_ses_lock); |
f984c7b9 | 489 | seq_putc(m, '\n'); |
20fab0da | 490 | cifs_swn_dump(m); |
b7fd0fa0 | 491 | |
1da177e4 | 492 | /* BB add code to dump additional info such as TCP session info now */ |
f984c7b9 AD |
493 | return 0; |
494 | } | |
1da177e4 | 495 | |
f984c7b9 AD |
496 | static ssize_t cifs_stats_proc_write(struct file *file, |
497 | const char __user *buffer, size_t count, loff_t *ppos) | |
1047abc1 | 498 | { |
28e2aed2 | 499 | bool bv; |
221601c3 | 500 | int rc; |
f1987b44 JL |
501 | struct list_head *tmp1, *tmp2, *tmp3; |
502 | struct TCP_Server_Info *server; | |
96daf2b0 SF |
503 | struct cifs_ses *ses; |
504 | struct cifs_tcon *tcon; | |
1047abc1 | 505 | |
1404297e KC |
506 | rc = kstrtobool_from_user(buffer, count, &bv); |
507 | if (rc == 0) { | |
4498eed5 | 508 | #ifdef CONFIG_CIFS_STATS2 |
468d6779 SF |
509 | int i; |
510 | ||
4498eed5 SF |
511 | atomic_set(&totBufAllocCount, 0); |
512 | atomic_set(&totSmBufAllocCount, 0); | |
513 | #endif /* CONFIG_CIFS_STATS2 */ | |
2c887635 SF |
514 | atomic_set(&tcpSesReconnectCount, 0); |
515 | atomic_set(&tconInfoReconnectCount, 0); | |
516 | ||
c281bc0c SF |
517 | spin_lock(&GlobalMid_Lock); |
518 | GlobalMaxActiveXid = 0; | |
519 | GlobalCurrentXid = 0; | |
520 | spin_unlock(&GlobalMid_Lock); | |
3f9bcca7 | 521 | spin_lock(&cifs_tcp_ses_lock); |
f1987b44 JL |
522 | list_for_each(tmp1, &cifs_tcp_ses_list) { |
523 | server = list_entry(tmp1, struct TCP_Server_Info, | |
524 | tcp_ses_list); | |
1b63f184 | 525 | server->max_in_flight = 0; |
468d6779 | 526 | #ifdef CONFIG_CIFS_STATS2 |
433b8dd7 SF |
527 | for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) { |
528 | atomic_set(&server->num_cmds[i], 0); | |
468d6779 | 529 | atomic_set(&server->smb2slowcmd[i], 0); |
433b8dd7 SF |
530 | server->time_per_cmd[i] = 0; |
531 | server->slowest_cmd[i] = 0; | |
532 | server->fastest_cmd[0] = 0; | |
533 | } | |
468d6779 | 534 | #endif /* CONFIG_CIFS_STATS2 */ |
c2b3382c | 535 | list_for_each(tmp2, &server->smb_ses_list) { |
96daf2b0 | 536 | ses = list_entry(tmp2, struct cifs_ses, |
c2b3382c | 537 | smb_ses_list); |
f1987b44 JL |
538 | list_for_each(tmp3, &ses->tcon_list) { |
539 | tcon = list_entry(tmp3, | |
96daf2b0 | 540 | struct cifs_tcon, |
f1987b44 JL |
541 | tcon_list); |
542 | atomic_set(&tcon->num_smbs_sent, 0); | |
c281bc0c SF |
543 | spin_lock(&tcon->stat_lock); |
544 | tcon->bytes_read = 0; | |
545 | tcon->bytes_written = 0; | |
546 | spin_unlock(&tcon->stat_lock); | |
44c58186 PS |
547 | if (server->ops->clear_stats) |
548 | server->ops->clear_stats(tcon); | |
f1987b44 JL |
549 | } |
550 | } | |
1047abc1 | 551 | } |
3f9bcca7 | 552 | spin_unlock(&cifs_tcp_ses_lock); |
1404297e KC |
553 | } else { |
554 | return rc; | |
1047abc1 SF |
555 | } |
556 | ||
221601c3 | 557 | return count; |
1047abc1 SF |
558 | } |
559 | ||
f984c7b9 | 560 | static int cifs_stats_proc_show(struct seq_file *m, void *v) |
1da177e4 | 561 | { |
f984c7b9 | 562 | int i; |
468d6779 SF |
563 | #ifdef CONFIG_CIFS_STATS2 |
564 | int j; | |
565 | #endif /* STATS2 */ | |
f1987b44 JL |
566 | struct list_head *tmp1, *tmp2, *tmp3; |
567 | struct TCP_Server_Info *server; | |
96daf2b0 SF |
568 | struct cifs_ses *ses; |
569 | struct cifs_tcon *tcon; | |
1da177e4 | 570 | |
468d6779 | 571 | seq_printf(m, "Resources in use\nCIFS Session: %d\n", |
1da177e4 | 572 | sesInfoAllocCount.counter); |
f984c7b9 | 573 | seq_printf(m, "Share (unique mount targets): %d\n", |
1da177e4 | 574 | tconInfoAllocCount.counter); |
f984c7b9 | 575 | seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n", |
b8643e1b SF |
576 | bufAllocCount.counter, |
577 | cifs_min_rcv + tcpSesAllocCount.counter); | |
f984c7b9 | 578 | seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n", |
221601c3 | 579 | smBufAllocCount.counter, cifs_min_small); |
07475ffb | 580 | #ifdef CONFIG_CIFS_STATS2 |
f984c7b9 | 581 | seq_printf(m, "Total Large %d Small %d Allocations\n", |
07475ffb | 582 | atomic_read(&totBufAllocCount), |
221601c3 | 583 | atomic_read(&totSmBufAllocCount)); |
07475ffb SF |
584 | #endif /* CONFIG_CIFS_STATS2 */ |
585 | ||
8097531a | 586 | seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount)); |
f984c7b9 | 587 | seq_printf(m, |
1da177e4 | 588 | "\n%d session %d share reconnects\n", |
221601c3 | 589 | tcpSesReconnectCount.counter, tconInfoReconnectCount.counter); |
1da177e4 | 590 | |
f984c7b9 | 591 | seq_printf(m, |
1da177e4 | 592 | "Total vfs operations: %d maximum at one time: %d\n", |
221601c3 | 593 | GlobalCurrentXid, GlobalMaxActiveXid); |
1da177e4 LT |
594 | |
595 | i = 0; | |
3f9bcca7 | 596 | spin_lock(&cifs_tcp_ses_lock); |
f1987b44 JL |
597 | list_for_each(tmp1, &cifs_tcp_ses_list) { |
598 | server = list_entry(tmp1, struct TCP_Server_Info, | |
599 | tcp_ses_list); | |
1b63f184 | 600 | seq_printf(m, "\nMax requests in flight: %d", server->max_in_flight); |
468d6779 | 601 | #ifdef CONFIG_CIFS_STATS2 |
433b8dd7 SF |
602 | seq_puts(m, "\nTotal time spent processing by command. Time "); |
603 | seq_printf(m, "units are jiffies (%d per second)\n", HZ); | |
604 | seq_puts(m, " SMB3 CMD\tNumber\tTotal Time\tFastest\tSlowest\n"); | |
605 | seq_puts(m, " --------\t------\t----------\t-------\t-------\n"); | |
606 | for (j = 0; j < NUMBER_OF_SMB2_COMMANDS; j++) | |
607 | seq_printf(m, " %d\t\t%d\t%llu\t\t%u\t%u\n", j, | |
608 | atomic_read(&server->num_cmds[j]), | |
609 | server->time_per_cmd[j], | |
610 | server->fastest_cmd[j], | |
611 | server->slowest_cmd[j]); | |
468d6779 SF |
612 | for (j = 0; j < NUMBER_OF_SMB2_COMMANDS; j++) |
613 | if (atomic_read(&server->smb2slowcmd[j])) | |
433b8dd7 | 614 | seq_printf(m, " %d slow responses from %s for command %d\n", |
468d6779 SF |
615 | atomic_read(&server->smb2slowcmd[j]), |
616 | server->hostname, j); | |
617 | #endif /* STATS2 */ | |
f1987b44 | 618 | list_for_each(tmp2, &server->smb_ses_list) { |
96daf2b0 | 619 | ses = list_entry(tmp2, struct cifs_ses, |
f1987b44 JL |
620 | smb_ses_list); |
621 | list_for_each(tmp3, &ses->tcon_list) { | |
622 | tcon = list_entry(tmp3, | |
96daf2b0 | 623 | struct cifs_tcon, |
f1987b44 JL |
624 | tcon_list); |
625 | i++; | |
626 | seq_printf(m, "\n%d) %s", i, tcon->treeName); | |
627 | if (tcon->need_reconnect) | |
628 | seq_puts(m, "\tDISCONNECTED "); | |
44c58186 PS |
629 | seq_printf(m, "\nSMBs: %d", |
630 | atomic_read(&tcon->num_smbs_sent)); | |
631 | if (server->ops->print_stats) | |
632 | server->ops->print_stats(m, tcon); | |
f1987b44 JL |
633 | } |
634 | } | |
1da177e4 | 635 | } |
3f9bcca7 | 636 | spin_unlock(&cifs_tcp_ses_lock); |
1da177e4 | 637 | |
f984c7b9 AD |
638 | seq_putc(m, '\n'); |
639 | return 0; | |
640 | } | |
221601c3 | 641 | |
f984c7b9 AD |
642 | static int cifs_stats_proc_open(struct inode *inode, struct file *file) |
643 | { | |
644 | return single_open(file, cifs_stats_proc_show, NULL); | |
1da177e4 | 645 | } |
f984c7b9 | 646 | |
97a32539 AD |
647 | static const struct proc_ops cifs_stats_proc_ops = { |
648 | .proc_open = cifs_stats_proc_open, | |
649 | .proc_read = seq_read, | |
650 | .proc_lseek = seq_lseek, | |
651 | .proc_release = single_release, | |
652 | .proc_write = cifs_stats_proc_write, | |
f984c7b9 | 653 | }; |
1da177e4 | 654 | |
d8ec913b LL |
655 | #ifdef CONFIG_CIFS_SMB_DIRECT |
656 | #define PROC_FILE_DEFINE(name) \ | |
657 | static ssize_t name##_write(struct file *file, const char __user *buffer, \ | |
658 | size_t count, loff_t *ppos) \ | |
659 | { \ | |
660 | int rc; \ | |
661 | rc = kstrtoint_from_user(buffer, count, 10, & name); \ | |
662 | if (rc) \ | |
663 | return rc; \ | |
664 | return count; \ | |
665 | } \ | |
666 | static int name##_proc_show(struct seq_file *m, void *v) \ | |
667 | { \ | |
668 | seq_printf(m, "%d\n", name ); \ | |
669 | return 0; \ | |
670 | } \ | |
671 | static int name##_open(struct inode *inode, struct file *file) \ | |
672 | { \ | |
673 | return single_open(file, name##_proc_show, NULL); \ | |
674 | } \ | |
675 | \ | |
97a32539 AD |
676 | static const struct proc_ops cifs_##name##_proc_fops = { \ |
677 | .proc_open = name##_open, \ | |
678 | .proc_read = seq_read, \ | |
679 | .proc_lseek = seq_lseek, \ | |
680 | .proc_release = single_release, \ | |
681 | .proc_write = name##_write, \ | |
d8ec913b LL |
682 | } |
683 | ||
d8ec913b LL |
684 | PROC_FILE_DEFINE(rdma_readwrite_threshold); |
685 | PROC_FILE_DEFINE(smbd_max_frmr_depth); | |
686 | PROC_FILE_DEFINE(smbd_keep_alive_interval); | |
687 | PROC_FILE_DEFINE(smbd_max_receive_size); | |
688 | PROC_FILE_DEFINE(smbd_max_fragmented_recv_size); | |
689 | PROC_FILE_DEFINE(smbd_max_send_size); | |
690 | PROC_FILE_DEFINE(smbd_send_credit_target); | |
691 | PROC_FILE_DEFINE(smbd_receive_credit_max); | |
692 | #endif | |
693 | ||
1da177e4 | 694 | static struct proc_dir_entry *proc_fs_cifs; |
97a32539 AD |
695 | static const struct proc_ops cifsFYI_proc_ops; |
696 | static const struct proc_ops cifs_lookup_cache_proc_ops; | |
697 | static const struct proc_ops traceSMB_proc_ops; | |
698 | static const struct proc_ops cifs_security_flags_proc_ops; | |
699 | static const struct proc_ops cifs_linux_ext_proc_ops; | |
94b0595a | 700 | static const struct proc_ops cifs_mount_params_proc_ops; |
1da177e4 LT |
701 | |
702 | void | |
703 | cifs_proc_init(void) | |
704 | { | |
36a5aeb8 | 705 | proc_fs_cifs = proc_mkdir("fs/cifs", NULL); |
1da177e4 LT |
706 | if (proc_fs_cifs == NULL) |
707 | return; | |
708 | ||
3f3942ac CH |
709 | proc_create_single("DebugData", 0, proc_fs_cifs, |
710 | cifs_debug_data_proc_show); | |
1da177e4 | 711 | |
dfe33f9a SF |
712 | proc_create_single("open_files", 0400, proc_fs_cifs, |
713 | cifs_debug_files_proc_show); | |
714 | ||
97a32539 AD |
715 | proc_create("Stats", 0644, proc_fs_cifs, &cifs_stats_proc_ops); |
716 | proc_create("cifsFYI", 0644, proc_fs_cifs, &cifsFYI_proc_ops); | |
717 | proc_create("traceSMB", 0644, proc_fs_cifs, &traceSMB_proc_ops); | |
6539e7f3 | 718 | proc_create("LinuxExtensionsEnabled", 0644, proc_fs_cifs, |
97a32539 | 719 | &cifs_linux_ext_proc_ops); |
6539e7f3 | 720 | proc_create("SecurityFlags", 0644, proc_fs_cifs, |
97a32539 | 721 | &cifs_security_flags_proc_ops); |
6539e7f3 | 722 | proc_create("LookupCacheEnabled", 0644, proc_fs_cifs, |
97a32539 | 723 | &cifs_lookup_cache_proc_ops); |
54be1f6c | 724 | |
94b0595a AA |
725 | proc_create("mount_params", 0444, proc_fs_cifs, &cifs_mount_params_proc_ops); |
726 | ||
54be1f6c | 727 | #ifdef CONFIG_CIFS_DFS_UPCALL |
97a32539 | 728 | proc_create("dfscache", 0644, proc_fs_cifs, &dfscache_proc_ops); |
54be1f6c PA |
729 | #endif |
730 | ||
d8ec913b | 731 | #ifdef CONFIG_CIFS_SMB_DIRECT |
6539e7f3 | 732 | proc_create("rdma_readwrite_threshold", 0644, proc_fs_cifs, |
d8ec913b | 733 | &cifs_rdma_readwrite_threshold_proc_fops); |
6539e7f3 | 734 | proc_create("smbd_max_frmr_depth", 0644, proc_fs_cifs, |
d8ec913b | 735 | &cifs_smbd_max_frmr_depth_proc_fops); |
6539e7f3 | 736 | proc_create("smbd_keep_alive_interval", 0644, proc_fs_cifs, |
d8ec913b | 737 | &cifs_smbd_keep_alive_interval_proc_fops); |
6539e7f3 | 738 | proc_create("smbd_max_receive_size", 0644, proc_fs_cifs, |
d8ec913b | 739 | &cifs_smbd_max_receive_size_proc_fops); |
6539e7f3 | 740 | proc_create("smbd_max_fragmented_recv_size", 0644, proc_fs_cifs, |
d8ec913b | 741 | &cifs_smbd_max_fragmented_recv_size_proc_fops); |
6539e7f3 | 742 | proc_create("smbd_max_send_size", 0644, proc_fs_cifs, |
d8ec913b | 743 | &cifs_smbd_max_send_size_proc_fops); |
6539e7f3 | 744 | proc_create("smbd_send_credit_target", 0644, proc_fs_cifs, |
d8ec913b | 745 | &cifs_smbd_send_credit_target_proc_fops); |
6539e7f3 | 746 | proc_create("smbd_receive_credit_max", 0644, proc_fs_cifs, |
d8ec913b LL |
747 | &cifs_smbd_receive_credit_max_proc_fops); |
748 | #endif | |
1da177e4 LT |
749 | } |
750 | ||
751 | void | |
752 | cifs_proc_clean(void) | |
753 | { | |
754 | if (proc_fs_cifs == NULL) | |
755 | return; | |
756 | ||
757 | remove_proc_entry("DebugData", proc_fs_cifs); | |
dfe33f9a | 758 | remove_proc_entry("open_files", proc_fs_cifs); |
1da177e4 LT |
759 | remove_proc_entry("cifsFYI", proc_fs_cifs); |
760 | remove_proc_entry("traceSMB", proc_fs_cifs); | |
1da177e4 | 761 | remove_proc_entry("Stats", proc_fs_cifs); |
221601c3 | 762 | remove_proc_entry("SecurityFlags", proc_fs_cifs); |
221601c3 | 763 | remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs); |
221601c3 | 764 | remove_proc_entry("LookupCacheEnabled", proc_fs_cifs); |
94b0595a | 765 | remove_proc_entry("mount_params", proc_fs_cifs); |
54be1f6c PA |
766 | |
767 | #ifdef CONFIG_CIFS_DFS_UPCALL | |
768 | remove_proc_entry("dfscache", proc_fs_cifs); | |
769 | #endif | |
d8ec913b LL |
770 | #ifdef CONFIG_CIFS_SMB_DIRECT |
771 | remove_proc_entry("rdma_readwrite_threshold", proc_fs_cifs); | |
772 | remove_proc_entry("smbd_max_frmr_depth", proc_fs_cifs); | |
773 | remove_proc_entry("smbd_keep_alive_interval", proc_fs_cifs); | |
774 | remove_proc_entry("smbd_max_receive_size", proc_fs_cifs); | |
775 | remove_proc_entry("smbd_max_fragmented_recv_size", proc_fs_cifs); | |
776 | remove_proc_entry("smbd_max_send_size", proc_fs_cifs); | |
777 | remove_proc_entry("smbd_send_credit_target", proc_fs_cifs); | |
778 | remove_proc_entry("smbd_receive_credit_max", proc_fs_cifs); | |
779 | #endif | |
36a5aeb8 | 780 | remove_proc_entry("fs/cifs", NULL); |
1da177e4 LT |
781 | } |
782 | ||
f984c7b9 | 783 | static int cifsFYI_proc_show(struct seq_file *m, void *v) |
1da177e4 | 784 | { |
f984c7b9 AD |
785 | seq_printf(m, "%d\n", cifsFYI); |
786 | return 0; | |
787 | } | |
1da177e4 | 788 | |
f984c7b9 AD |
789 | static int cifsFYI_proc_open(struct inode *inode, struct file *file) |
790 | { | |
791 | return single_open(file, cifsFYI_proc_show, NULL); | |
1da177e4 | 792 | } |
f984c7b9 AD |
793 | |
794 | static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer, | |
795 | size_t count, loff_t *ppos) | |
1da177e4 | 796 | { |
1404297e | 797 | char c[2] = { '\0' }; |
28e2aed2 | 798 | bool bv; |
1da177e4 LT |
799 | int rc; |
800 | ||
1404297e | 801 | rc = get_user(c[0], buffer); |
1da177e4 LT |
802 | if (rc) |
803 | return rc; | |
1404297e | 804 | if (strtobool(c, &bv) == 0) |
28e2aed2 | 805 | cifsFYI = bv; |
1404297e KC |
806 | else if ((c[0] > '1') && (c[0] <= '9')) |
807 | cifsFYI = (int) (c[0] - '0'); /* see cifs_debug.h for meanings */ | |
25ad1cbd RS |
808 | else |
809 | return -EINVAL; | |
1da177e4 LT |
810 | |
811 | return count; | |
812 | } | |
813 | ||
97a32539 AD |
814 | static const struct proc_ops cifsFYI_proc_ops = { |
815 | .proc_open = cifsFYI_proc_open, | |
816 | .proc_read = seq_read, | |
817 | .proc_lseek = seq_lseek, | |
818 | .proc_release = single_release, | |
819 | .proc_write = cifsFYI_proc_write, | |
f984c7b9 | 820 | }; |
1da177e4 | 821 | |
f984c7b9 AD |
822 | static int cifs_linux_ext_proc_show(struct seq_file *m, void *v) |
823 | { | |
824 | seq_printf(m, "%d\n", linuxExtEnabled); | |
825 | return 0; | |
826 | } | |
1da177e4 | 827 | |
f984c7b9 AD |
828 | static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file) |
829 | { | |
830 | return single_open(file, cifs_linux_ext_proc_show, NULL); | |
1da177e4 | 831 | } |
f984c7b9 AD |
832 | |
833 | static ssize_t cifs_linux_ext_proc_write(struct file *file, | |
834 | const char __user *buffer, size_t count, loff_t *ppos) | |
1da177e4 | 835 | { |
221601c3 SF |
836 | int rc; |
837 | ||
1404297e | 838 | rc = kstrtobool_from_user(buffer, count, &linuxExtEnabled); |
221601c3 SF |
839 | if (rc) |
840 | return rc; | |
28e2aed2 | 841 | |
221601c3 | 842 | return count; |
1da177e4 LT |
843 | } |
844 | ||
97a32539 AD |
845 | static const struct proc_ops cifs_linux_ext_proc_ops = { |
846 | .proc_open = cifs_linux_ext_proc_open, | |
847 | .proc_read = seq_read, | |
848 | .proc_lseek = seq_lseek, | |
849 | .proc_release = single_release, | |
850 | .proc_write = cifs_linux_ext_proc_write, | |
f984c7b9 | 851 | }; |
1da177e4 | 852 | |
f984c7b9 | 853 | static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v) |
1da177e4 | 854 | { |
f984c7b9 AD |
855 | seq_printf(m, "%d\n", lookupCacheEnabled); |
856 | return 0; | |
857 | } | |
1da177e4 | 858 | |
f984c7b9 AD |
859 | static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file) |
860 | { | |
861 | return single_open(file, cifs_lookup_cache_proc_show, NULL); | |
1da177e4 | 862 | } |
f984c7b9 AD |
863 | |
864 | static ssize_t cifs_lookup_cache_proc_write(struct file *file, | |
865 | const char __user *buffer, size_t count, loff_t *ppos) | |
1da177e4 | 866 | { |
1da177e4 LT |
867 | int rc; |
868 | ||
1404297e | 869 | rc = kstrtobool_from_user(buffer, count, &lookupCacheEnabled); |
1da177e4 LT |
870 | if (rc) |
871 | return rc; | |
28e2aed2 | 872 | |
1da177e4 LT |
873 | return count; |
874 | } | |
1da177e4 | 875 | |
97a32539 AD |
876 | static const struct proc_ops cifs_lookup_cache_proc_ops = { |
877 | .proc_open = cifs_lookup_cache_proc_open, | |
878 | .proc_read = seq_read, | |
879 | .proc_lseek = seq_lseek, | |
880 | .proc_release = single_release, | |
881 | .proc_write = cifs_lookup_cache_proc_write, | |
f984c7b9 | 882 | }; |
1da177e4 | 883 | |
f984c7b9 AD |
884 | static int traceSMB_proc_show(struct seq_file *m, void *v) |
885 | { | |
886 | seq_printf(m, "%d\n", traceSMB); | |
887 | return 0; | |
888 | } | |
1da177e4 | 889 | |
f984c7b9 AD |
890 | static int traceSMB_proc_open(struct inode *inode, struct file *file) |
891 | { | |
892 | return single_open(file, traceSMB_proc_show, NULL); | |
1da177e4 | 893 | } |
f984c7b9 AD |
894 | |
895 | static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer, | |
896 | size_t count, loff_t *ppos) | |
1da177e4 | 897 | { |
1da177e4 LT |
898 | int rc; |
899 | ||
1404297e | 900 | rc = kstrtobool_from_user(buffer, count, &traceSMB); |
1da177e4 LT |
901 | if (rc) |
902 | return rc; | |
28e2aed2 | 903 | |
1da177e4 LT |
904 | return count; |
905 | } | |
906 | ||
97a32539 AD |
907 | static const struct proc_ops traceSMB_proc_ops = { |
908 | .proc_open = traceSMB_proc_open, | |
909 | .proc_read = seq_read, | |
910 | .proc_lseek = seq_lseek, | |
911 | .proc_release = single_release, | |
912 | .proc_write = traceSMB_proc_write, | |
f984c7b9 | 913 | }; |
1da177e4 | 914 | |
f984c7b9 AD |
915 | static int cifs_security_flags_proc_show(struct seq_file *m, void *v) |
916 | { | |
04912d6a | 917 | seq_printf(m, "0x%x\n", global_secflags); |
f984c7b9 AD |
918 | return 0; |
919 | } | |
1da177e4 | 920 | |
f984c7b9 AD |
921 | static int cifs_security_flags_proc_open(struct inode *inode, struct file *file) |
922 | { | |
923 | return single_open(file, cifs_security_flags_proc_show, NULL); | |
1da177e4 | 924 | } |
f984c7b9 | 925 | |
52dfb446 JL |
926 | /* |
927 | * Ensure that if someone sets a MUST flag, that we disable all other MAY | |
928 | * flags except for the ones corresponding to the given MUST flag. If there are | |
929 | * multiple MUST flags, then try to prefer more secure ones. | |
930 | */ | |
931 | static void | |
932 | cifs_security_flags_handle_must_flags(unsigned int *flags) | |
933 | { | |
934 | unsigned int signflags = *flags & CIFSSEC_MUST_SIGN; | |
935 | ||
936 | if ((*flags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5) | |
937 | *flags = CIFSSEC_MUST_KRB5; | |
938 | else if ((*flags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP) | |
939 | *flags = CIFSSEC_MUST_NTLMSSP; | |
940 | else if ((*flags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2) | |
941 | *flags = CIFSSEC_MUST_NTLMV2; | |
942 | else if ((*flags & CIFSSEC_MUST_NTLM) == CIFSSEC_MUST_NTLM) | |
943 | *flags = CIFSSEC_MUST_NTLM; | |
7a1ceba0 NC |
944 | else if (CIFSSEC_MUST_LANMAN && |
945 | (*flags & CIFSSEC_MUST_LANMAN) == CIFSSEC_MUST_LANMAN) | |
52dfb446 | 946 | *flags = CIFSSEC_MUST_LANMAN; |
7a1ceba0 NC |
947 | else if (CIFSSEC_MUST_PLNTXT && |
948 | (*flags & CIFSSEC_MUST_PLNTXT) == CIFSSEC_MUST_PLNTXT) | |
52dfb446 JL |
949 | *flags = CIFSSEC_MUST_PLNTXT; |
950 | ||
951 | *flags |= signflags; | |
952 | } | |
953 | ||
f984c7b9 AD |
954 | static ssize_t cifs_security_flags_proc_write(struct file *file, |
955 | const char __user *buffer, size_t count, loff_t *ppos) | |
1da177e4 | 956 | { |
7715dad8 | 957 | int rc; |
bdc4bf6e SF |
958 | unsigned int flags; |
959 | char flags_string[12]; | |
28e2aed2 | 960 | bool bv; |
bdc4bf6e | 961 | |
221601c3 | 962 | if ((count < 1) || (count > 11)) |
3979877e | 963 | return -EINVAL; |
1da177e4 | 964 | |
bdc4bf6e | 965 | memset(flags_string, 0, 12); |
3979877e | 966 | |
221601c3 | 967 | if (copy_from_user(flags_string, buffer, count)) |
bdc4bf6e | 968 | return -EFAULT; |
3979877e | 969 | |
221601c3 | 970 | if (count < 3) { |
bdc4bf6e | 971 | /* single char or single char followed by null */ |
1404297e | 972 | if (strtobool(flags_string, &bv) == 0) { |
28e2aed2 | 973 | global_secflags = bv ? CIFSSEC_MAX : CIFSSEC_DEF; |
a013689d | 974 | return count; |
1404297e | 975 | } else if (!isdigit(flags_string[0])) { |
7715dad8 JL |
976 | cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", |
977 | flags_string); | |
a013689d SF |
978 | return -EINVAL; |
979 | } | |
bdc4bf6e | 980 | } |
bdc4bf6e | 981 | |
7715dad8 JL |
982 | /* else we have a number */ |
983 | rc = kstrtouint(flags_string, 0, &flags); | |
984 | if (rc) { | |
985 | cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", | |
986 | flags_string); | |
987 | return rc; | |
988 | } | |
bdc4bf6e | 989 | |
f96637be | 990 | cifs_dbg(FYI, "sec flags 0x%x\n", flags); |
bdc4bf6e | 991 | |
7715dad8 JL |
992 | if (flags == 0) { |
993 | cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", flags_string); | |
bdc4bf6e SF |
994 | return -EINVAL; |
995 | } | |
1da177e4 | 996 | |
221601c3 | 997 | if (flags & ~CIFSSEC_MASK) { |
7715dad8 | 998 | cifs_dbg(VFS, "Unsupported security flags: 0x%x\n", |
f96637be | 999 | flags & ~CIFSSEC_MASK); |
bdc4bf6e SF |
1000 | return -EINVAL; |
1001 | } | |
7715dad8 | 1002 | |
52dfb446 JL |
1003 | cifs_security_flags_handle_must_flags(&flags); |
1004 | ||
bdc4bf6e | 1005 | /* flags look ok - update the global security flags for cifs module */ |
04912d6a JL |
1006 | global_secflags = flags; |
1007 | if (global_secflags & CIFSSEC_MUST_SIGN) { | |
762e5ab7 | 1008 | /* requiring signing implies signing is allowed */ |
04912d6a | 1009 | global_secflags |= CIFSSEC_MAY_SIGN; |
f96637be | 1010 | cifs_dbg(FYI, "packet signing now required\n"); |
04912d6a | 1011 | } else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) { |
f96637be | 1012 | cifs_dbg(FYI, "packet signing disabled\n"); |
762e5ab7 SF |
1013 | } |
1014 | /* BB should we turn on MAY flags for other MUST options? */ | |
1da177e4 LT |
1015 | return count; |
1016 | } | |
f984c7b9 | 1017 | |
97a32539 AD |
1018 | static const struct proc_ops cifs_security_flags_proc_ops = { |
1019 | .proc_open = cifs_security_flags_proc_open, | |
1020 | .proc_read = seq_read, | |
1021 | .proc_lseek = seq_lseek, | |
1022 | .proc_release = single_release, | |
1023 | .proc_write = cifs_security_flags_proc_write, | |
f984c7b9 | 1024 | }; |
94b0595a AA |
1025 | |
1026 | /* To make it easier to debug, can help to show mount params */ | |
1027 | static int cifs_mount_params_proc_show(struct seq_file *m, void *v) | |
1028 | { | |
1029 | const struct fs_parameter_spec *p; | |
1030 | const char *type; | |
1031 | ||
1032 | for (p = smb3_fs_parameters; p->name; p++) { | |
1033 | /* cannot use switch with pointers... */ | |
1034 | if (!p->type) { | |
1035 | if (p->flags == fs_param_neg_with_no) | |
1036 | type = "noflag"; | |
1037 | else | |
1038 | type = "flag"; | |
1039 | } else if (p->type == fs_param_is_bool) | |
1040 | type = "bool"; | |
1041 | else if (p->type == fs_param_is_u32) | |
1042 | type = "u32"; | |
1043 | else if (p->type == fs_param_is_u64) | |
1044 | type = "u64"; | |
1045 | else if (p->type == fs_param_is_string) | |
1046 | type = "string"; | |
1047 | else | |
1048 | type = "unknown"; | |
1049 | ||
1050 | seq_printf(m, "%s:%s\n", p->name, type); | |
1051 | } | |
1052 | ||
1053 | return 0; | |
1054 | } | |
1055 | ||
1056 | static int cifs_mount_params_proc_open(struct inode *inode, struct file *file) | |
1057 | { | |
1058 | return single_open(file, cifs_mount_params_proc_show, NULL); | |
1059 | } | |
1060 | ||
1061 | static const struct proc_ops cifs_mount_params_proc_ops = { | |
1062 | .proc_open = cifs_mount_params_proc_open, | |
1063 | .proc_read = seq_read, | |
1064 | .proc_lseek = seq_lseek, | |
1065 | .proc_release = single_release, | |
1066 | /* No need for write for now */ | |
1067 | /* .proc_write = cifs_mount_params_proc_write, */ | |
1068 | }; | |
1069 | ||
90c81e0b | 1070 | #else |
e086fcea | 1071 | inline void cifs_proc_init(void) |
90c81e0b SF |
1072 | { |
1073 | } | |
1074 | ||
e086fcea | 1075 | inline void cifs_proc_clean(void) |
90c81e0b SF |
1076 | { |
1077 | } | |
1078 | #endif /* PROC_FS */ |