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