1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright (C) International Business Machines Corp., 2000,2005
6 * Modified by Steve French (sfrench@us.ibm.com)
9 #include <linux/string.h>
10 #include <linux/ctype.h>
11 #include <linux/kstrtox.h>
12 #include <linux/module.h>
13 #include <linux/proc_fs.h>
14 #include <linux/uaccess.h>
15 #include <uapi/linux/ethtool.h>
18 #include "cifsproto.h"
19 #include "cifs_debug.h"
21 #include "fs_context.h"
22 #ifdef CONFIG_CIFS_DFS_UPCALL
23 #include "dfs_cache.h"
25 #ifdef CONFIG_CIFS_SMB_DIRECT
26 #include "smbdirect.h"
31 cifs_dump_mem(char *label, void *data, int length)
33 pr_debug("%s: dump of %d bytes of data at 0x%p\n", label, length, data);
34 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 4,
38 void cifs_dump_detail(void *buf, struct TCP_Server_Info *server)
40 #ifdef CONFIG_CIFS_DEBUG2
41 struct smb_hdr *smb = buf;
43 cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d\n",
44 smb->Command, smb->Status.CifsError,
45 smb->Flags, smb->Flags2, smb->Mid, smb->Pid);
46 cifs_dbg(VFS, "smb buf %p len %u\n", smb,
47 server->ops->calc_smb_size(smb));
48 #endif /* CONFIG_CIFS_DEBUG2 */
51 void cifs_dump_mids(struct TCP_Server_Info *server)
53 #ifdef CONFIG_CIFS_DEBUG2
54 struct mid_q_entry *mid_entry;
59 cifs_dbg(VFS, "Dump pending requests:\n");
60 spin_lock(&server->mid_lock);
61 list_for_each_entry(mid_entry, &server->pending_mid_q, qhead) {
62 cifs_dbg(VFS, "State: %d Cmd: %d Pid: %d Cbdata: %p Mid %llu\n",
64 le16_to_cpu(mid_entry->command),
66 mid_entry->callback_data,
68 #ifdef CONFIG_CIFS_STATS2
69 cifs_dbg(VFS, "IsLarge: %d buf: %p time rcv: %ld now: %ld\n",
72 mid_entry->when_received,
75 cifs_dbg(VFS, "IsMult: %d IsEnd: %d\n",
76 mid_entry->multiRsp, mid_entry->multiEnd);
77 if (mid_entry->resp_buf) {
78 cifs_dump_detail(mid_entry->resp_buf, server);
79 cifs_dump_mem("existing buf: ",
80 mid_entry->resp_buf, 62);
83 spin_unlock(&server->mid_lock);
84 #endif /* CONFIG_CIFS_DEBUG2 */
88 static void cifs_debug_tcon(struct seq_file *m, struct cifs_tcon *tcon)
90 __u32 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
92 seq_printf(m, "%s Mounts: %d ", tcon->tree_name, tcon->tc_count);
93 if (tcon->nativeFileSystem)
94 seq_printf(m, "Type: %s ", tcon->nativeFileSystem);
95 seq_printf(m, "DevInfo: 0x%x Attributes: 0x%x\n\tPathComponentMax: %d Status: %d",
96 le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
97 le32_to_cpu(tcon->fsAttrInfo.Attributes),
98 le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
100 if (dev_type == FILE_DEVICE_DISK)
101 seq_puts(m, " type: DISK ");
102 else if (dev_type == FILE_DEVICE_CD_ROM)
103 seq_puts(m, " type: CDROM ");
105 seq_printf(m, " type: %d ", dev_type);
107 seq_printf(m, "Serial Number: 0x%x", tcon->vol_serial_number);
110 (tcon->ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA) ||
111 (tcon->share_flags & SHI1005_FLAGS_ENCRYPT_DATA))
112 seq_puts(m, " encrypted");
114 seq_printf(m, " nocase");
116 seq_printf(m, " POSIX Extensions");
117 if (tcon->ses->server->ops->dump_share_caps)
118 tcon->ses->server->ops->dump_share_caps(m, tcon);
119 if (tcon->use_witness)
120 seq_puts(m, " Witness");
121 if (tcon->broken_sparse_sup)
122 seq_puts(m, " nosparse");
123 if (tcon->need_reconnect)
124 seq_puts(m, "\tDISCONNECTED ");
125 spin_lock(&tcon->tc_lock);
126 if (tcon->origin_fullpath) {
127 seq_printf(m, "\n\tDFS origin fullpath: %s",
128 tcon->origin_fullpath);
130 spin_unlock(&tcon->tc_lock);
135 cifs_dump_channel(struct seq_file *m, int i, struct cifs_chan *chan)
137 struct TCP_Server_Info *server = chan->server;
139 seq_printf(m, "\n\n\t\tChannel: %d ConnectionId: 0x%llx"
140 "\n\t\tNumber of credits: %d,%d,%d Dialect 0x%x"
141 "\n\t\tTCP status: %d Instance: %d"
142 "\n\t\tLocal Users To Server: %d SecMode: 0x%x Req On Wire: %d"
143 "\n\t\tIn Send: %d In MaxReq Wait: %d",
144 i+1, server->conn_id,
146 server->echo_credits,
147 server->oplock_credits,
150 server->reconnect_instance,
154 atomic_read(&server->in_send),
155 atomic_read(&server->num_waiters));
158 static inline const char *smb_speed_to_str(size_t bps)
160 size_t mbps = bps / 1000 / 1000;
201 cifs_dump_iface(struct seq_file *m, struct cifs_server_iface *iface)
203 struct sockaddr_in *ipv4 = (struct sockaddr_in *)&iface->sockaddr;
204 struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)&iface->sockaddr;
206 seq_printf(m, "\tSpeed: %s\n", smb_speed_to_str(iface->speed));
207 seq_puts(m, "\t\tCapabilities: ");
208 if (iface->rdma_capable)
209 seq_puts(m, "rdma ");
210 if (iface->rss_capable)
212 if (!iface->rdma_capable && !iface->rss_capable)
215 if (iface->sockaddr.ss_family == AF_INET)
216 seq_printf(m, "\t\tIPv4: %pI4\n", &ipv4->sin_addr);
217 else if (iface->sockaddr.ss_family == AF_INET6)
218 seq_printf(m, "\t\tIPv6: %pI6\n", &ipv6->sin6_addr);
219 if (!iface->is_active)
220 seq_puts(m, "\t\t[for-cleanup]\n");
223 static int cifs_debug_files_proc_show(struct seq_file *m, void *v)
225 struct TCP_Server_Info *server;
226 struct cifs_ses *ses;
227 struct cifs_tcon *tcon;
228 struct cifsFileInfo *cfile;
230 seq_puts(m, "# Version:1\n");
231 seq_puts(m, "# Format:\n");
232 seq_puts(m, "# <tree id> <ses id> <persistent fid> <flags> <count> <pid> <uid>");
233 #ifdef CONFIG_CIFS_DEBUG2
234 seq_printf(m, " <filename> <mid>\n");
236 seq_printf(m, " <filename>\n");
237 #endif /* CIFS_DEBUG2 */
238 spin_lock(&cifs_tcp_ses_lock);
239 list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
240 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
241 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
242 spin_lock(&tcon->open_file_lock);
243 list_for_each_entry(cfile, &tcon->openFileList, tlist) {
245 "0x%x 0x%llx 0x%llx 0x%x %d %d %d %pd",
248 cfile->fid.persistent_fid,
252 from_kuid(&init_user_ns, cfile->uid),
254 #ifdef CONFIG_CIFS_DEBUG2
255 seq_printf(m, " %llu\n", cfile->fid.mid);
258 #endif /* CIFS_DEBUG2 */
260 spin_unlock(&tcon->open_file_lock);
264 spin_unlock(&cifs_tcp_ses_lock);
269 static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
271 struct mid_q_entry *mid_entry;
272 struct TCP_Server_Info *server;
273 struct TCP_Server_Info *chan_server;
274 struct cifs_ses *ses;
275 struct cifs_tcon *tcon;
276 struct cifs_server_iface *iface;
280 "Display Internal CIFS Data Structures for Debugging\n"
281 "---------------------------------------------------\n");
282 seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
283 seq_printf(m, "Features:");
284 #ifdef CONFIG_CIFS_DFS_UPCALL
285 seq_printf(m, " DFS");
287 #ifdef CONFIG_CIFS_FSCACHE
288 seq_printf(m, ",FSCACHE");
290 #ifdef CONFIG_CIFS_SMB_DIRECT
291 seq_printf(m, ",SMB_DIRECT");
293 #ifdef CONFIG_CIFS_STATS2
294 seq_printf(m, ",STATS2");
296 seq_printf(m, ",STATS");
298 #ifdef CONFIG_CIFS_DEBUG2
299 seq_printf(m, ",DEBUG2");
300 #elif defined(CONFIG_CIFS_DEBUG)
301 seq_printf(m, ",DEBUG");
303 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
304 seq_printf(m, ",ALLOW_INSECURE_LEGACY");
306 #ifdef CONFIG_CIFS_POSIX
307 seq_printf(m, ",CIFS_POSIX");
309 #ifdef CONFIG_CIFS_UPCALL
310 seq_printf(m, ",UPCALL(SPNEGO)");
312 #ifdef CONFIG_CIFS_XATTR
313 seq_printf(m, ",XATTR");
315 seq_printf(m, ",ACL");
316 #ifdef CONFIG_CIFS_SWN_UPCALL
317 seq_puts(m, ",WITNESS");
320 seq_printf(m, "CIFSMaxBufSize: %d\n", CIFSMaxBufSize);
321 seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
323 seq_printf(m, "\nServers: ");
326 spin_lock(&cifs_tcp_ses_lock);
327 list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
328 /* channel info will be printed as a part of sessions below */
329 if (CIFS_SERVER_IS_CHAN(server))
333 seq_printf(m, "\n%d) ConnectionId: 0x%llx ",
336 spin_lock(&server->srv_lock);
337 if (server->hostname)
338 seq_printf(m, "Hostname: %s ", server->hostname);
339 seq_printf(m, "\nClientGUID: %pUL", server->client_guid);
340 spin_unlock(&server->srv_lock);
341 #ifdef CONFIG_CIFS_SMB_DIRECT
345 if (!server->smbd_conn) {
346 seq_printf(m, "\nSMBDirect transport not available");
350 seq_printf(m, "\nSMBDirect (in hex) protocol version: %x "
351 "transport status: %x",
352 server->smbd_conn->protocol,
353 server->smbd_conn->transport_status);
354 seq_printf(m, "\nConn receive_credit_max: %x "
355 "send_credit_target: %x max_send_size: %x",
356 server->smbd_conn->receive_credit_max,
357 server->smbd_conn->send_credit_target,
358 server->smbd_conn->max_send_size);
359 seq_printf(m, "\nConn max_fragmented_recv_size: %x "
360 "max_fragmented_send_size: %x max_receive_size:%x",
361 server->smbd_conn->max_fragmented_recv_size,
362 server->smbd_conn->max_fragmented_send_size,
363 server->smbd_conn->max_receive_size);
364 seq_printf(m, "\nConn keep_alive_interval: %x "
365 "max_readwrite_size: %x rdma_readwrite_threshold: %x",
366 server->smbd_conn->keep_alive_interval,
367 server->smbd_conn->max_readwrite_size,
368 server->smbd_conn->rdma_readwrite_threshold);
369 seq_printf(m, "\nDebug count_get_receive_buffer: %x "
370 "count_put_receive_buffer: %x count_send_empty: %x",
371 server->smbd_conn->count_get_receive_buffer,
372 server->smbd_conn->count_put_receive_buffer,
373 server->smbd_conn->count_send_empty);
374 seq_printf(m, "\nRead Queue count_reassembly_queue: %x "
375 "count_enqueue_reassembly_queue: %x "
376 "count_dequeue_reassembly_queue: %x "
377 "fragment_reassembly_remaining: %x "
378 "reassembly_data_length: %x "
379 "reassembly_queue_length: %x",
380 server->smbd_conn->count_reassembly_queue,
381 server->smbd_conn->count_enqueue_reassembly_queue,
382 server->smbd_conn->count_dequeue_reassembly_queue,
383 server->smbd_conn->fragment_reassembly_remaining,
384 server->smbd_conn->reassembly_data_length,
385 server->smbd_conn->reassembly_queue_length);
386 seq_printf(m, "\nCurrent Credits send_credits: %x "
387 "receive_credits: %x receive_credit_target: %x",
388 atomic_read(&server->smbd_conn->send_credits),
389 atomic_read(&server->smbd_conn->receive_credits),
390 server->smbd_conn->receive_credit_target);
391 seq_printf(m, "\nPending send_pending: %x ",
392 atomic_read(&server->smbd_conn->send_pending));
393 seq_printf(m, "\nReceive buffers count_receive_queue: %x "
394 "count_empty_packet_queue: %x",
395 server->smbd_conn->count_receive_queue,
396 server->smbd_conn->count_empty_packet_queue);
397 seq_printf(m, "\nMR responder_resources: %x "
398 "max_frmr_depth: %x mr_type: %x",
399 server->smbd_conn->responder_resources,
400 server->smbd_conn->max_frmr_depth,
401 server->smbd_conn->mr_type);
402 seq_printf(m, "\nMR mr_ready_count: %x mr_used_count: %x",
403 atomic_read(&server->smbd_conn->mr_ready_count),
404 atomic_read(&server->smbd_conn->mr_used_count));
407 seq_printf(m, "\nNumber of credits: %d,%d,%d Dialect 0x%x",
409 server->echo_credits,
410 server->oplock_credits,
412 if (server->compress_algorithm == SMB3_COMPRESS_LZNT1)
413 seq_printf(m, " COMPRESS_LZNT1");
414 else if (server->compress_algorithm == SMB3_COMPRESS_LZ77)
415 seq_printf(m, " COMPRESS_LZ77");
416 else if (server->compress_algorithm == SMB3_COMPRESS_LZ77_HUFF)
417 seq_printf(m, " COMPRESS_LZ77_HUFF");
419 seq_printf(m, " signed");
420 if (server->posix_ext_supported)
421 seq_printf(m, " posix");
422 if (server->nosharesock)
423 seq_printf(m, " nosharesock");
426 seq_printf(m, "\nRDMA ");
427 seq_printf(m, "\nTCP status: %d Instance: %d"
428 "\nLocal Users To Server: %d SecMode: 0x%x Req On Wire: %d",
430 server->reconnect_instance,
432 server->sec_mode, in_flight(server));
434 seq_printf(m, "\nIn Send: %d In MaxReq Wait: %d",
435 atomic_read(&server->in_send),
436 atomic_read(&server->num_waiters));
437 if (server->leaf_fullpath) {
438 seq_printf(m, "\nDFS leaf full path: %s",
439 server->leaf_fullpath);
442 seq_printf(m, "\n\n\tSessions: ");
444 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
446 if ((ses->serverDomain == NULL) ||
447 (ses->serverOS == NULL) ||
448 (ses->serverNOS == NULL)) {
449 seq_printf(m, "\n\t%d) Address: %s Uses: %d Capability: 0x%x\tSession Status: %d ",
450 i, ses->ip_addr, ses->ses_count,
451 ses->capabilities, ses->ses_status);
452 if (ses->session_flags & SMB2_SESSION_FLAG_IS_GUEST)
453 seq_printf(m, "Guest ");
454 else if (ses->session_flags & SMB2_SESSION_FLAG_IS_NULL)
455 seq_printf(m, "Anonymous ");
458 "\n\t%d) Name: %s Domain: %s Uses: %d OS: %s "
459 "\n\tNOS: %s\tCapability: 0x%x"
460 "\n\tSMB session status: %d ",
461 i, ses->ip_addr, ses->serverDomain,
462 ses->ses_count, ses->serverOS, ses->serverNOS,
463 ses->capabilities, ses->ses_status);
466 seq_printf(m, "\n\tSecurity type: %s ",
467 get_security_type_str(server->ops->select_sectype(server, ses->sectype)));
469 /* dump session id helpful for use with network trace */
470 seq_printf(m, " SessionId: 0x%llx", ses->Suid);
471 if (ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA) {
472 seq_puts(m, " encrypted");
473 /* can help in debugging to show encryption type */
474 if (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM)
475 seq_puts(m, "(gcm256)");
478 seq_puts(m, " signed");
480 seq_printf(m, "\n\tUser: %d Cred User: %d",
481 from_kuid(&init_user_ns, ses->linux_uid),
482 from_kuid(&init_user_ns, ses->cred_uid));
484 if (ses->dfs_root_ses) {
485 seq_printf(m, "\n\tDFS root session id: 0x%llx",
486 ses->dfs_root_ses->Suid);
489 spin_lock(&ses->chan_lock);
490 if (CIFS_CHAN_NEEDS_RECONNECT(ses, 0))
491 seq_puts(m, "\tPrimary channel: DISCONNECTED ");
492 if (CIFS_CHAN_IN_RECONNECT(ses, 0))
493 seq_puts(m, "\t[RECONNECTING] ");
495 if (ses->chan_count > 1) {
496 seq_printf(m, "\n\n\tExtra Channels: %zu ",
498 for (j = 1; j < ses->chan_count; j++) {
499 cifs_dump_channel(m, j, &ses->chans[j]);
500 if (CIFS_CHAN_NEEDS_RECONNECT(ses, j))
501 seq_puts(m, "\tDISCONNECTED ");
502 if (CIFS_CHAN_IN_RECONNECT(ses, j))
503 seq_puts(m, "\t[RECONNECTING] ");
506 spin_unlock(&ses->chan_lock);
508 seq_puts(m, "\n\n\tShares: ");
511 seq_printf(m, "\n\t%d) IPC: ", j);
513 cifs_debug_tcon(m, ses->tcon_ipc);
515 seq_puts(m, "none\n");
517 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
519 seq_printf(m, "\n\t%d) ", j);
520 cifs_debug_tcon(m, tcon);
523 spin_lock(&ses->iface_lock);
524 if (ses->iface_count)
525 seq_printf(m, "\n\n\tServer interfaces: %zu"
526 "\tLast updated: %lu seconds ago",
528 (jiffies - ses->iface_last_update) / HZ);
530 list_for_each_entry(iface, &ses->iface_list,
532 seq_printf(m, "\n\t%d)", ++j);
533 cifs_dump_iface(m, iface);
534 if (is_ses_using_iface(ses, iface))
535 seq_puts(m, "\t\t[CONNECTED]\n");
537 spin_unlock(&ses->iface_lock);
539 seq_puts(m, "\n\n\tMIDs: ");
540 spin_lock(&ses->chan_lock);
541 for (j = 0; j < ses->chan_count; j++) {
542 chan_server = ses->chans[j].server;
546 if (list_empty(&chan_server->pending_mid_q))
549 seq_printf(m, "\n\tServer ConnectionId: 0x%llx",
550 chan_server->conn_id);
551 spin_lock(&chan_server->mid_lock);
552 list_for_each_entry(mid_entry, &chan_server->pending_mid_q, qhead) {
553 seq_printf(m, "\n\t\tState: %d com: %d pid: %d cbdata: %p mid %llu",
554 mid_entry->mid_state,
555 le16_to_cpu(mid_entry->command),
557 mid_entry->callback_data,
560 spin_unlock(&chan_server->mid_lock);
562 spin_unlock(&ses->chan_lock);
563 seq_puts(m, "\n--\n");
566 seq_printf(m, "\n\t\t[NONE]");
569 seq_printf(m, "\n\t[NONE]");
571 spin_unlock(&cifs_tcp_ses_lock);
575 /* BB add code to dump additional info such as TCP session info now */
579 static ssize_t cifs_stats_proc_write(struct file *file,
580 const char __user *buffer, size_t count, loff_t *ppos)
584 struct TCP_Server_Info *server;
585 struct cifs_ses *ses;
586 struct cifs_tcon *tcon;
588 rc = kstrtobool_from_user(buffer, count, &bv);
590 #ifdef CONFIG_CIFS_STATS2
593 atomic_set(&total_buf_alloc_count, 0);
594 atomic_set(&total_small_buf_alloc_count, 0);
595 #endif /* CONFIG_CIFS_STATS2 */
596 atomic_set(&tcpSesReconnectCount, 0);
597 atomic_set(&tconInfoReconnectCount, 0);
599 spin_lock(&GlobalMid_Lock);
600 GlobalMaxActiveXid = 0;
601 GlobalCurrentXid = 0;
602 spin_unlock(&GlobalMid_Lock);
603 spin_lock(&cifs_tcp_ses_lock);
604 list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
605 server->max_in_flight = 0;
606 #ifdef CONFIG_CIFS_STATS2
607 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
608 atomic_set(&server->num_cmds[i], 0);
609 atomic_set(&server->smb2slowcmd[i], 0);
610 server->time_per_cmd[i] = 0;
611 server->slowest_cmd[i] = 0;
612 server->fastest_cmd[0] = 0;
614 #endif /* CONFIG_CIFS_STATS2 */
615 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
616 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
617 atomic_set(&tcon->num_smbs_sent, 0);
618 spin_lock(&tcon->stat_lock);
619 tcon->bytes_read = 0;
620 tcon->bytes_written = 0;
621 spin_unlock(&tcon->stat_lock);
622 if (server->ops->clear_stats)
623 server->ops->clear_stats(tcon);
627 spin_unlock(&cifs_tcp_ses_lock);
635 static int cifs_stats_proc_show(struct seq_file *m, void *v)
638 #ifdef CONFIG_CIFS_STATS2
641 struct TCP_Server_Info *server;
642 struct cifs_ses *ses;
643 struct cifs_tcon *tcon;
645 seq_printf(m, "Resources in use\nCIFS Session: %d\n",
646 sesInfoAllocCount.counter);
647 seq_printf(m, "Share (unique mount targets): %d\n",
648 tconInfoAllocCount.counter);
649 seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
650 buf_alloc_count.counter,
651 cifs_min_rcv + tcpSesAllocCount.counter);
652 seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
653 small_buf_alloc_count.counter, cifs_min_small);
654 #ifdef CONFIG_CIFS_STATS2
655 seq_printf(m, "Total Large %d Small %d Allocations\n",
656 atomic_read(&total_buf_alloc_count),
657 atomic_read(&total_small_buf_alloc_count));
658 #endif /* CONFIG_CIFS_STATS2 */
660 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&mid_count));
662 "\n%d session %d share reconnects\n",
663 tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
666 "Total vfs operations: %d maximum at one time: %d\n",
667 GlobalCurrentXid, GlobalMaxActiveXid);
670 spin_lock(&cifs_tcp_ses_lock);
671 list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
672 seq_printf(m, "\nMax requests in flight: %d", server->max_in_flight);
673 #ifdef CONFIG_CIFS_STATS2
674 seq_puts(m, "\nTotal time spent processing by command. Time ");
675 seq_printf(m, "units are jiffies (%d per second)\n", HZ);
676 seq_puts(m, " SMB3 CMD\tNumber\tTotal Time\tFastest\tSlowest\n");
677 seq_puts(m, " --------\t------\t----------\t-------\t-------\n");
678 for (j = 0; j < NUMBER_OF_SMB2_COMMANDS; j++)
679 seq_printf(m, " %d\t\t%d\t%llu\t\t%u\t%u\n", j,
680 atomic_read(&server->num_cmds[j]),
681 server->time_per_cmd[j],
682 server->fastest_cmd[j],
683 server->slowest_cmd[j]);
684 for (j = 0; j < NUMBER_OF_SMB2_COMMANDS; j++)
685 if (atomic_read(&server->smb2slowcmd[j])) {
686 spin_lock(&server->srv_lock);
687 seq_printf(m, " %d slow responses from %s for command %d\n",
688 atomic_read(&server->smb2slowcmd[j]),
689 server->hostname, j);
690 spin_unlock(&server->srv_lock);
693 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
694 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
696 seq_printf(m, "\n%d) %s", i, tcon->tree_name);
697 if (tcon->need_reconnect)
698 seq_puts(m, "\tDISCONNECTED ");
699 seq_printf(m, "\nSMBs: %d",
700 atomic_read(&tcon->num_smbs_sent));
701 if (server->ops->print_stats)
702 server->ops->print_stats(m, tcon);
706 spin_unlock(&cifs_tcp_ses_lock);
712 static int cifs_stats_proc_open(struct inode *inode, struct file *file)
714 return single_open(file, cifs_stats_proc_show, NULL);
717 static const struct proc_ops cifs_stats_proc_ops = {
718 .proc_open = cifs_stats_proc_open,
719 .proc_read = seq_read,
720 .proc_lseek = seq_lseek,
721 .proc_release = single_release,
722 .proc_write = cifs_stats_proc_write,
725 #ifdef CONFIG_CIFS_SMB_DIRECT
726 #define PROC_FILE_DEFINE(name) \
727 static ssize_t name##_write(struct file *file, const char __user *buffer, \
728 size_t count, loff_t *ppos) \
731 rc = kstrtoint_from_user(buffer, count, 10, & name); \
736 static int name##_proc_show(struct seq_file *m, void *v) \
738 seq_printf(m, "%d\n", name ); \
741 static int name##_open(struct inode *inode, struct file *file) \
743 return single_open(file, name##_proc_show, NULL); \
746 static const struct proc_ops cifs_##name##_proc_fops = { \
747 .proc_open = name##_open, \
748 .proc_read = seq_read, \
749 .proc_lseek = seq_lseek, \
750 .proc_release = single_release, \
751 .proc_write = name##_write, \
754 PROC_FILE_DEFINE(rdma_readwrite_threshold);
755 PROC_FILE_DEFINE(smbd_max_frmr_depth);
756 PROC_FILE_DEFINE(smbd_keep_alive_interval);
757 PROC_FILE_DEFINE(smbd_max_receive_size);
758 PROC_FILE_DEFINE(smbd_max_fragmented_recv_size);
759 PROC_FILE_DEFINE(smbd_max_send_size);
760 PROC_FILE_DEFINE(smbd_send_credit_target);
761 PROC_FILE_DEFINE(smbd_receive_credit_max);
764 static struct proc_dir_entry *proc_fs_cifs;
765 static const struct proc_ops cifsFYI_proc_ops;
766 static const struct proc_ops cifs_lookup_cache_proc_ops;
767 static const struct proc_ops traceSMB_proc_ops;
768 static const struct proc_ops cifs_security_flags_proc_ops;
769 static const struct proc_ops cifs_linux_ext_proc_ops;
770 static const struct proc_ops cifs_mount_params_proc_ops;
775 proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
776 if (proc_fs_cifs == NULL)
779 proc_create_single("DebugData", 0, proc_fs_cifs,
780 cifs_debug_data_proc_show);
782 proc_create_single("open_files", 0400, proc_fs_cifs,
783 cifs_debug_files_proc_show);
785 proc_create("Stats", 0644, proc_fs_cifs, &cifs_stats_proc_ops);
786 proc_create("cifsFYI", 0644, proc_fs_cifs, &cifsFYI_proc_ops);
787 proc_create("traceSMB", 0644, proc_fs_cifs, &traceSMB_proc_ops);
788 proc_create("LinuxExtensionsEnabled", 0644, proc_fs_cifs,
789 &cifs_linux_ext_proc_ops);
790 proc_create("SecurityFlags", 0644, proc_fs_cifs,
791 &cifs_security_flags_proc_ops);
792 proc_create("LookupCacheEnabled", 0644, proc_fs_cifs,
793 &cifs_lookup_cache_proc_ops);
795 proc_create("mount_params", 0444, proc_fs_cifs, &cifs_mount_params_proc_ops);
797 #ifdef CONFIG_CIFS_DFS_UPCALL
798 proc_create("dfscache", 0644, proc_fs_cifs, &dfscache_proc_ops);
801 #ifdef CONFIG_CIFS_SMB_DIRECT
802 proc_create("rdma_readwrite_threshold", 0644, proc_fs_cifs,
803 &cifs_rdma_readwrite_threshold_proc_fops);
804 proc_create("smbd_max_frmr_depth", 0644, proc_fs_cifs,
805 &cifs_smbd_max_frmr_depth_proc_fops);
806 proc_create("smbd_keep_alive_interval", 0644, proc_fs_cifs,
807 &cifs_smbd_keep_alive_interval_proc_fops);
808 proc_create("smbd_max_receive_size", 0644, proc_fs_cifs,
809 &cifs_smbd_max_receive_size_proc_fops);
810 proc_create("smbd_max_fragmented_recv_size", 0644, proc_fs_cifs,
811 &cifs_smbd_max_fragmented_recv_size_proc_fops);
812 proc_create("smbd_max_send_size", 0644, proc_fs_cifs,
813 &cifs_smbd_max_send_size_proc_fops);
814 proc_create("smbd_send_credit_target", 0644, proc_fs_cifs,
815 &cifs_smbd_send_credit_target_proc_fops);
816 proc_create("smbd_receive_credit_max", 0644, proc_fs_cifs,
817 &cifs_smbd_receive_credit_max_proc_fops);
822 cifs_proc_clean(void)
824 if (proc_fs_cifs == NULL)
827 remove_proc_entry("DebugData", proc_fs_cifs);
828 remove_proc_entry("open_files", proc_fs_cifs);
829 remove_proc_entry("cifsFYI", proc_fs_cifs);
830 remove_proc_entry("traceSMB", proc_fs_cifs);
831 remove_proc_entry("Stats", proc_fs_cifs);
832 remove_proc_entry("SecurityFlags", proc_fs_cifs);
833 remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
834 remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
835 remove_proc_entry("mount_params", proc_fs_cifs);
837 #ifdef CONFIG_CIFS_DFS_UPCALL
838 remove_proc_entry("dfscache", proc_fs_cifs);
840 #ifdef CONFIG_CIFS_SMB_DIRECT
841 remove_proc_entry("rdma_readwrite_threshold", proc_fs_cifs);
842 remove_proc_entry("smbd_max_frmr_depth", proc_fs_cifs);
843 remove_proc_entry("smbd_keep_alive_interval", proc_fs_cifs);
844 remove_proc_entry("smbd_max_receive_size", proc_fs_cifs);
845 remove_proc_entry("smbd_max_fragmented_recv_size", proc_fs_cifs);
846 remove_proc_entry("smbd_max_send_size", proc_fs_cifs);
847 remove_proc_entry("smbd_send_credit_target", proc_fs_cifs);
848 remove_proc_entry("smbd_receive_credit_max", proc_fs_cifs);
850 remove_proc_entry("fs/cifs", NULL);
853 static int cifsFYI_proc_show(struct seq_file *m, void *v)
855 seq_printf(m, "%d\n", cifsFYI);
859 static int cifsFYI_proc_open(struct inode *inode, struct file *file)
861 return single_open(file, cifsFYI_proc_show, NULL);
864 static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
865 size_t count, loff_t *ppos)
867 char c[2] = { '\0' };
871 rc = get_user(c[0], buffer);
874 if (kstrtobool(c, &bv) == 0)
876 else if ((c[0] > '1') && (c[0] <= '9'))
877 cifsFYI = (int) (c[0] - '0'); /* see cifs_debug.h for meanings */
884 static const struct proc_ops cifsFYI_proc_ops = {
885 .proc_open = cifsFYI_proc_open,
886 .proc_read = seq_read,
887 .proc_lseek = seq_lseek,
888 .proc_release = single_release,
889 .proc_write = cifsFYI_proc_write,
892 static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
894 seq_printf(m, "%d\n", linuxExtEnabled);
898 static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
900 return single_open(file, cifs_linux_ext_proc_show, NULL);
903 static ssize_t cifs_linux_ext_proc_write(struct file *file,
904 const char __user *buffer, size_t count, loff_t *ppos)
908 rc = kstrtobool_from_user(buffer, count, &linuxExtEnabled);
915 static const struct proc_ops cifs_linux_ext_proc_ops = {
916 .proc_open = cifs_linux_ext_proc_open,
917 .proc_read = seq_read,
918 .proc_lseek = seq_lseek,
919 .proc_release = single_release,
920 .proc_write = cifs_linux_ext_proc_write,
923 static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
925 seq_printf(m, "%d\n", lookupCacheEnabled);
929 static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
931 return single_open(file, cifs_lookup_cache_proc_show, NULL);
934 static ssize_t cifs_lookup_cache_proc_write(struct file *file,
935 const char __user *buffer, size_t count, loff_t *ppos)
939 rc = kstrtobool_from_user(buffer, count, &lookupCacheEnabled);
946 static const struct proc_ops cifs_lookup_cache_proc_ops = {
947 .proc_open = cifs_lookup_cache_proc_open,
948 .proc_read = seq_read,
949 .proc_lseek = seq_lseek,
950 .proc_release = single_release,
951 .proc_write = cifs_lookup_cache_proc_write,
954 static int traceSMB_proc_show(struct seq_file *m, void *v)
956 seq_printf(m, "%d\n", traceSMB);
960 static int traceSMB_proc_open(struct inode *inode, struct file *file)
962 return single_open(file, traceSMB_proc_show, NULL);
965 static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
966 size_t count, loff_t *ppos)
970 rc = kstrtobool_from_user(buffer, count, &traceSMB);
977 static const struct proc_ops traceSMB_proc_ops = {
978 .proc_open = traceSMB_proc_open,
979 .proc_read = seq_read,
980 .proc_lseek = seq_lseek,
981 .proc_release = single_release,
982 .proc_write = traceSMB_proc_write,
985 static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
987 seq_printf(m, "0x%x\n", global_secflags);
991 static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
993 return single_open(file, cifs_security_flags_proc_show, NULL);
997 * Ensure that if someone sets a MUST flag, that we disable all other MAY
998 * flags except for the ones corresponding to the given MUST flag. If there are
999 * multiple MUST flags, then try to prefer more secure ones.
1002 cifs_security_flags_handle_must_flags(unsigned int *flags)
1004 unsigned int signflags = *flags & CIFSSEC_MUST_SIGN;
1006 if ((*flags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5)
1007 *flags = CIFSSEC_MUST_KRB5;
1008 else if ((*flags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP)
1009 *flags = CIFSSEC_MUST_NTLMSSP;
1010 else if ((*flags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2)
1011 *flags = CIFSSEC_MUST_NTLMV2;
1013 *flags |= signflags;
1016 static ssize_t cifs_security_flags_proc_write(struct file *file,
1017 const char __user *buffer, size_t count, loff_t *ppos)
1021 char flags_string[12];
1024 if ((count < 1) || (count > 11))
1027 memset(flags_string, 0, 12);
1029 if (copy_from_user(flags_string, buffer, count))
1033 /* single char or single char followed by null */
1034 if (kstrtobool(flags_string, &bv) == 0) {
1035 global_secflags = bv ? CIFSSEC_MAX : CIFSSEC_DEF;
1037 } else if (!isdigit(flags_string[0])) {
1038 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
1044 /* else we have a number */
1045 rc = kstrtouint(flags_string, 0, &flags);
1047 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
1052 cifs_dbg(FYI, "sec flags 0x%x\n", flags);
1055 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", flags_string);
1059 if (flags & ~CIFSSEC_MASK) {
1060 cifs_dbg(VFS, "Unsupported security flags: 0x%x\n",
1061 flags & ~CIFSSEC_MASK);
1065 cifs_security_flags_handle_must_flags(&flags);
1067 /* flags look ok - update the global security flags for cifs module */
1068 global_secflags = flags;
1069 if (global_secflags & CIFSSEC_MUST_SIGN) {
1070 /* requiring signing implies signing is allowed */
1071 global_secflags |= CIFSSEC_MAY_SIGN;
1072 cifs_dbg(FYI, "packet signing now required\n");
1073 } else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) {
1074 cifs_dbg(FYI, "packet signing disabled\n");
1076 /* BB should we turn on MAY flags for other MUST options? */
1080 static const struct proc_ops cifs_security_flags_proc_ops = {
1081 .proc_open = cifs_security_flags_proc_open,
1082 .proc_read = seq_read,
1083 .proc_lseek = seq_lseek,
1084 .proc_release = single_release,
1085 .proc_write = cifs_security_flags_proc_write,
1088 /* To make it easier to debug, can help to show mount params */
1089 static int cifs_mount_params_proc_show(struct seq_file *m, void *v)
1091 const struct fs_parameter_spec *p;
1094 for (p = smb3_fs_parameters; p->name; p++) {
1095 /* cannot use switch with pointers... */
1097 if (p->flags == fs_param_neg_with_no)
1101 } else if (p->type == fs_param_is_bool)
1103 else if (p->type == fs_param_is_u32)
1105 else if (p->type == fs_param_is_u64)
1107 else if (p->type == fs_param_is_string)
1112 seq_printf(m, "%s:%s\n", p->name, type);
1118 static int cifs_mount_params_proc_open(struct inode *inode, struct file *file)
1120 return single_open(file, cifs_mount_params_proc_show, NULL);
1123 static const struct proc_ops cifs_mount_params_proc_ops = {
1124 .proc_open = cifs_mount_params_proc_open,
1125 .proc_read = seq_read,
1126 .proc_lseek = seq_lseek,
1127 .proc_release = single_release,
1128 /* No need for write for now */
1129 /* .proc_write = cifs_mount_params_proc_write, */
1133 inline void cifs_proc_init(void)
1137 inline void cifs_proc_clean(void)
1140 #endif /* PROC_FS */