xref: /linux/fs/smb/client/cifs_debug.c (revision 42b16d3ac371a2fac9b6f08fd75f23f34ba3955a)
138c8a9a5SSteve French // SPDX-License-Identifier: GPL-2.0-or-later
238c8a9a5SSteve French /*
338c8a9a5SSteve French  *
438c8a9a5SSteve French  *   Copyright (C) International Business Machines  Corp., 2000,2005
538c8a9a5SSteve French  *
638c8a9a5SSteve French  *   Modified by Steve French (sfrench@us.ibm.com)
738c8a9a5SSteve French  */
838c8a9a5SSteve French #include <linux/fs.h>
938c8a9a5SSteve French #include <linux/string.h>
1038c8a9a5SSteve French #include <linux/ctype.h>
1138c8a9a5SSteve French #include <linux/kstrtox.h>
1238c8a9a5SSteve French #include <linux/module.h>
1338c8a9a5SSteve French #include <linux/proc_fs.h>
1438c8a9a5SSteve French #include <linux/uaccess.h>
1550e63d6dSEnzo Matsumiya #include <uapi/linux/ethtool.h>
1638c8a9a5SSteve French #include "cifspdu.h"
1738c8a9a5SSteve French #include "cifsglob.h"
1838c8a9a5SSteve French #include "cifsproto.h"
1938c8a9a5SSteve French #include "cifs_debug.h"
2038c8a9a5SSteve French #include "cifsfs.h"
2138c8a9a5SSteve French #include "fs_context.h"
2238c8a9a5SSteve French #ifdef CONFIG_CIFS_DFS_UPCALL
2338c8a9a5SSteve French #include "dfs_cache.h"
2438c8a9a5SSteve French #endif
2538c8a9a5SSteve French #ifdef CONFIG_CIFS_SMB_DIRECT
2638c8a9a5SSteve French #include "smbdirect.h"
2738c8a9a5SSteve French #endif
2838c8a9a5SSteve French #include "cifs_swn.h"
2938c8a9a5SSteve French 
3038c8a9a5SSteve French void
cifs_dump_mem(char * label,void * data,int length)3138c8a9a5SSteve French cifs_dump_mem(char *label, void *data, int length)
3238c8a9a5SSteve French {
3338c8a9a5SSteve French 	pr_debug("%s: dump of %d bytes of data at 0x%p\n", label, length, data);
3438c8a9a5SSteve French 	print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 4,
3538c8a9a5SSteve French 		       data, length, true);
3638c8a9a5SSteve French }
3738c8a9a5SSteve French 
cifs_dump_detail(void * buf,struct TCP_Server_Info * server)3838c8a9a5SSteve French void cifs_dump_detail(void *buf, struct TCP_Server_Info *server)
3938c8a9a5SSteve French {
4038c8a9a5SSteve French #ifdef CONFIG_CIFS_DEBUG2
4138c8a9a5SSteve French 	struct smb_hdr *smb = buf;
4238c8a9a5SSteve French 
43b50492b0SPaulo Alcantara 	cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d Wct: %d\n",
44b50492b0SPaulo Alcantara 		 smb->Command, smb->Status.CifsError, smb->Flags,
45b50492b0SPaulo Alcantara 		 smb->Flags2, smb->Mid, smb->Pid, smb->WordCount);
46b50492b0SPaulo Alcantara 	if (!server->ops->check_message(buf, server->total_read, server)) {
4738c8a9a5SSteve French 		cifs_dbg(VFS, "smb buf %p len %u\n", smb,
4838c8a9a5SSteve French 			 server->ops->calc_smb_size(smb));
49b50492b0SPaulo Alcantara 	}
5038c8a9a5SSteve French #endif /* CONFIG_CIFS_DEBUG2 */
5138c8a9a5SSteve French }
5238c8a9a5SSteve French 
cifs_dump_mids(struct TCP_Server_Info * server)5338c8a9a5SSteve French void cifs_dump_mids(struct TCP_Server_Info *server)
5438c8a9a5SSteve French {
5538c8a9a5SSteve French #ifdef CONFIG_CIFS_DEBUG2
5638c8a9a5SSteve French 	struct mid_q_entry *mid_entry;
5738c8a9a5SSteve French 
5838c8a9a5SSteve French 	if (server == NULL)
5938c8a9a5SSteve French 		return;
6038c8a9a5SSteve French 
6138c8a9a5SSteve French 	cifs_dbg(VFS, "Dump pending requests:\n");
6238c8a9a5SSteve French 	spin_lock(&server->mid_lock);
6338c8a9a5SSteve French 	list_for_each_entry(mid_entry, &server->pending_mid_q, qhead) {
6438c8a9a5SSteve French 		cifs_dbg(VFS, "State: %d Cmd: %d Pid: %d Cbdata: %p Mid %llu\n",
6538c8a9a5SSteve French 			 mid_entry->mid_state,
6638c8a9a5SSteve French 			 le16_to_cpu(mid_entry->command),
6738c8a9a5SSteve French 			 mid_entry->pid,
6838c8a9a5SSteve French 			 mid_entry->callback_data,
6938c8a9a5SSteve French 			 mid_entry->mid);
7038c8a9a5SSteve French #ifdef CONFIG_CIFS_STATS2
7138c8a9a5SSteve French 		cifs_dbg(VFS, "IsLarge: %d buf: %p time rcv: %ld now: %ld\n",
7238c8a9a5SSteve French 			 mid_entry->large_buf,
7338c8a9a5SSteve French 			 mid_entry->resp_buf,
7438c8a9a5SSteve French 			 mid_entry->when_received,
7538c8a9a5SSteve French 			 jiffies);
7638c8a9a5SSteve French #endif /* STATS2 */
7738c8a9a5SSteve French 		cifs_dbg(VFS, "IsMult: %d IsEnd: %d\n",
7838c8a9a5SSteve French 			 mid_entry->multiRsp, mid_entry->multiEnd);
7938c8a9a5SSteve French 		if (mid_entry->resp_buf) {
8038c8a9a5SSteve French 			cifs_dump_detail(mid_entry->resp_buf, server);
8138c8a9a5SSteve French 			cifs_dump_mem("existing buf: ",
8238c8a9a5SSteve French 				mid_entry->resp_buf, 62);
8338c8a9a5SSteve French 		}
8438c8a9a5SSteve French 	}
8538c8a9a5SSteve French 	spin_unlock(&server->mid_lock);
8638c8a9a5SSteve French #endif /* CONFIG_CIFS_DEBUG2 */
8738c8a9a5SSteve French }
8838c8a9a5SSteve French 
8938c8a9a5SSteve French #ifdef CONFIG_PROC_FS
cifs_debug_tcon(struct seq_file * m,struct cifs_tcon * tcon)9038c8a9a5SSteve French static void cifs_debug_tcon(struct seq_file *m, struct cifs_tcon *tcon)
9138c8a9a5SSteve French {
9238c8a9a5SSteve French 	__u32 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
9338c8a9a5SSteve French 
9438c8a9a5SSteve French 	seq_printf(m, "%s Mounts: %d ", tcon->tree_name, tcon->tc_count);
9538c8a9a5SSteve French 	if (tcon->nativeFileSystem)
9638c8a9a5SSteve French 		seq_printf(m, "Type: %s ", tcon->nativeFileSystem);
9738c8a9a5SSteve French 	seq_printf(m, "DevInfo: 0x%x Attributes: 0x%x\n\tPathComponentMax: %d Status: %d",
9838c8a9a5SSteve French 		   le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
9938c8a9a5SSteve French 		   le32_to_cpu(tcon->fsAttrInfo.Attributes),
10038c8a9a5SSteve French 		   le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
10138c8a9a5SSteve French 		   tcon->status);
10238c8a9a5SSteve French 	if (dev_type == FILE_DEVICE_DISK)
10338c8a9a5SSteve French 		seq_puts(m, " type: DISK ");
10438c8a9a5SSteve French 	else if (dev_type == FILE_DEVICE_CD_ROM)
10538c8a9a5SSteve French 		seq_puts(m, " type: CDROM ");
10638c8a9a5SSteve French 	else
10738c8a9a5SSteve French 		seq_printf(m, " type: %d ", dev_type);
10838c8a9a5SSteve French 
10938c8a9a5SSteve French 	seq_printf(m, "Serial Number: 0x%x", tcon->vol_serial_number);
11038c8a9a5SSteve French 
11138c8a9a5SSteve French 	if ((tcon->seal) ||
11238c8a9a5SSteve French 	    (tcon->ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA) ||
11338c8a9a5SSteve French 	    (tcon->share_flags & SHI1005_FLAGS_ENCRYPT_DATA))
11438c8a9a5SSteve French 		seq_puts(m, " encrypted");
11538c8a9a5SSteve French 	if (tcon->nocase)
11638c8a9a5SSteve French 		seq_printf(m, " nocase");
11738c8a9a5SSteve French 	if (tcon->unix_ext)
11838c8a9a5SSteve French 		seq_printf(m, " POSIX Extensions");
11938c8a9a5SSteve French 	if (tcon->ses->server->ops->dump_share_caps)
12038c8a9a5SSteve French 		tcon->ses->server->ops->dump_share_caps(m, tcon);
12138c8a9a5SSteve French 	if (tcon->use_witness)
12238c8a9a5SSteve French 		seq_puts(m, " Witness");
12338c8a9a5SSteve French 	if (tcon->broken_sparse_sup)
12438c8a9a5SSteve French 		seq_puts(m, " nosparse");
12538c8a9a5SSteve French 	if (tcon->need_reconnect)
12638c8a9a5SSteve French 		seq_puts(m, "\tDISCONNECTED ");
1273ae872deSPaulo Alcantara 	spin_lock(&tcon->tc_lock);
1283ae872deSPaulo Alcantara 	if (tcon->origin_fullpath) {
1293ae872deSPaulo Alcantara 		seq_printf(m, "\n\tDFS origin fullpath: %s",
1303ae872deSPaulo Alcantara 			   tcon->origin_fullpath);
1313ae872deSPaulo Alcantara 	}
1323ae872deSPaulo Alcantara 	spin_unlock(&tcon->tc_lock);
13338c8a9a5SSteve French 	seq_putc(m, '\n');
13438c8a9a5SSteve French }
13538c8a9a5SSteve French 
13638c8a9a5SSteve French static void
cifs_dump_channel(struct seq_file * m,int i,struct cifs_chan * chan)13738c8a9a5SSteve French cifs_dump_channel(struct seq_file *m, int i, struct cifs_chan *chan)
13838c8a9a5SSteve French {
13938c8a9a5SSteve French 	struct TCP_Server_Info *server = chan->server;
14038c8a9a5SSteve French 
1410c51cc6fSShyam Prasad N 	if (!server) {
1420c51cc6fSShyam Prasad N 		seq_printf(m, "\n\n\t\tChannel: %d DISABLED", i+1);
1430c51cc6fSShyam Prasad N 		return;
1440c51cc6fSShyam Prasad N 	}
1450c51cc6fSShyam Prasad N 
14638c8a9a5SSteve French 	seq_printf(m, "\n\n\t\tChannel: %d ConnectionId: 0x%llx"
1472a44b389SShyam Prasad N 		   "\n\t\tNumber of credits: %d,%d,%d Dialect 0x%x"
14838c8a9a5SSteve French 		   "\n\t\tTCP status: %d Instance: %d"
14938c8a9a5SSteve French 		   "\n\t\tLocal Users To Server: %d SecMode: 0x%x Req On Wire: %d"
15038c8a9a5SSteve French 		   "\n\t\tIn Send: %d In MaxReq Wait: %d",
15138c8a9a5SSteve French 		   i+1, server->conn_id,
15238c8a9a5SSteve French 		   server->credits,
1532a44b389SShyam Prasad N 		   server->echo_credits,
1542a44b389SShyam Prasad N 		   server->oplock_credits,
15538c8a9a5SSteve French 		   server->dialect,
15638c8a9a5SSteve French 		   server->tcpStatus,
15738c8a9a5SSteve French 		   server->reconnect_instance,
15838c8a9a5SSteve French 		   server->srv_count,
15938c8a9a5SSteve French 		   server->sec_mode,
16038c8a9a5SSteve French 		   in_flight(server),
16138c8a9a5SSteve French 		   atomic_read(&server->in_send),
16238c8a9a5SSteve French 		   atomic_read(&server->num_waiters));
1637b38f6ddSSteve French #ifdef CONFIG_NET_NS
1647b38f6ddSSteve French 	if (server->net)
1657b38f6ddSSteve French 		seq_printf(m, " Net namespace: %u ", server->net->ns.inum);
1667b38f6ddSSteve French #endif /* NET_NS */
1677b38f6ddSSteve French 
16838c8a9a5SSteve French }
16938c8a9a5SSteve French 
smb_speed_to_str(size_t bps)17050e63d6dSEnzo Matsumiya static inline const char *smb_speed_to_str(size_t bps)
17150e63d6dSEnzo Matsumiya {
17250e63d6dSEnzo Matsumiya 	size_t mbps = bps / 1000 / 1000;
17350e63d6dSEnzo Matsumiya 
17450e63d6dSEnzo Matsumiya 	switch (mbps) {
17550e63d6dSEnzo Matsumiya 	case SPEED_10:
17650e63d6dSEnzo Matsumiya 		return "10Mbps";
17750e63d6dSEnzo Matsumiya 	case SPEED_100:
17850e63d6dSEnzo Matsumiya 		return "100Mbps";
17950e63d6dSEnzo Matsumiya 	case SPEED_1000:
18050e63d6dSEnzo Matsumiya 		return "1Gbps";
18150e63d6dSEnzo Matsumiya 	case SPEED_2500:
18250e63d6dSEnzo Matsumiya 		return "2.5Gbps";
18350e63d6dSEnzo Matsumiya 	case SPEED_5000:
18450e63d6dSEnzo Matsumiya 		return "5Gbps";
18550e63d6dSEnzo Matsumiya 	case SPEED_10000:
18650e63d6dSEnzo Matsumiya 		return "10Gbps";
18750e63d6dSEnzo Matsumiya 	case SPEED_14000:
18850e63d6dSEnzo Matsumiya 		return "14Gbps";
18950e63d6dSEnzo Matsumiya 	case SPEED_20000:
19050e63d6dSEnzo Matsumiya 		return "20Gbps";
19150e63d6dSEnzo Matsumiya 	case SPEED_25000:
19250e63d6dSEnzo Matsumiya 		return "25Gbps";
19350e63d6dSEnzo Matsumiya 	case SPEED_40000:
19450e63d6dSEnzo Matsumiya 		return "40Gbps";
19550e63d6dSEnzo Matsumiya 	case SPEED_50000:
19650e63d6dSEnzo Matsumiya 		return "50Gbps";
19750e63d6dSEnzo Matsumiya 	case SPEED_56000:
19850e63d6dSEnzo Matsumiya 		return "56Gbps";
19950e63d6dSEnzo Matsumiya 	case SPEED_100000:
20050e63d6dSEnzo Matsumiya 		return "100Gbps";
20150e63d6dSEnzo Matsumiya 	case SPEED_200000:
20250e63d6dSEnzo Matsumiya 		return "200Gbps";
20350e63d6dSEnzo Matsumiya 	case SPEED_400000:
20450e63d6dSEnzo Matsumiya 		return "400Gbps";
20550e63d6dSEnzo Matsumiya 	case SPEED_800000:
20650e63d6dSEnzo Matsumiya 		return "800Gbps";
20750e63d6dSEnzo Matsumiya 	default:
20850e63d6dSEnzo Matsumiya 		return "Unknown";
20950e63d6dSEnzo Matsumiya 	}
21050e63d6dSEnzo Matsumiya }
21150e63d6dSEnzo Matsumiya 
21238c8a9a5SSteve French static void
cifs_dump_iface(struct seq_file * m,struct cifs_server_iface * iface)21338c8a9a5SSteve French cifs_dump_iface(struct seq_file *m, struct cifs_server_iface *iface)
21438c8a9a5SSteve French {
21538c8a9a5SSteve French 	struct sockaddr_in *ipv4 = (struct sockaddr_in *)&iface->sockaddr;
21638c8a9a5SSteve French 	struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)&iface->sockaddr;
21738c8a9a5SSteve French 
21850e63d6dSEnzo Matsumiya 	seq_printf(m, "\tSpeed: %s\n", smb_speed_to_str(iface->speed));
21938c8a9a5SSteve French 	seq_puts(m, "\t\tCapabilities: ");
22038c8a9a5SSteve French 	if (iface->rdma_capable)
22138c8a9a5SSteve French 		seq_puts(m, "rdma ");
22238c8a9a5SSteve French 	if (iface->rss_capable)
22338c8a9a5SSteve French 		seq_puts(m, "rss ");
22450e63d6dSEnzo Matsumiya 	if (!iface->rdma_capable && !iface->rss_capable)
22550e63d6dSEnzo Matsumiya 		seq_puts(m, "None");
22638c8a9a5SSteve French 	seq_putc(m, '\n');
22738c8a9a5SSteve French 	if (iface->sockaddr.ss_family == AF_INET)
22838c8a9a5SSteve French 		seq_printf(m, "\t\tIPv4: %pI4\n", &ipv4->sin_addr);
22938c8a9a5SSteve French 	else if (iface->sockaddr.ss_family == AF_INET6)
23038c8a9a5SSteve French 		seq_printf(m, "\t\tIPv6: %pI6\n", &ipv6->sin6_addr);
23138c8a9a5SSteve French 	if (!iface->is_active)
23238c8a9a5SSteve French 		seq_puts(m, "\t\t[for-cleanup]\n");
23338c8a9a5SSteve French }
23438c8a9a5SSteve French 
cifs_debug_files_proc_show(struct seq_file * m,void * v)23538c8a9a5SSteve French static int cifs_debug_files_proc_show(struct seq_file *m, void *v)
23638c8a9a5SSteve French {
23738c8a9a5SSteve French 	struct TCP_Server_Info *server;
23838c8a9a5SSteve French 	struct cifs_ses *ses;
23938c8a9a5SSteve French 	struct cifs_tcon *tcon;
24038c8a9a5SSteve French 	struct cifsFileInfo *cfile;
24138c8a9a5SSteve French 
24238c8a9a5SSteve French 	seq_puts(m, "# Version:1\n");
24338c8a9a5SSteve French 	seq_puts(m, "# Format:\n");
24438c8a9a5SSteve French 	seq_puts(m, "# <tree id> <ses id> <persistent fid> <flags> <count> <pid> <uid>");
24538c8a9a5SSteve French #ifdef CONFIG_CIFS_DEBUG2
24638c8a9a5SSteve French 	seq_printf(m, " <filename> <mid>\n");
24738c8a9a5SSteve French #else
24838c8a9a5SSteve French 	seq_printf(m, " <filename>\n");
24938c8a9a5SSteve French #endif /* CIFS_DEBUG2 */
25038c8a9a5SSteve French 	spin_lock(&cifs_tcp_ses_lock);
25138c8a9a5SSteve French 	list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
25238c8a9a5SSteve French 		list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
253ca545b7fSPaulo Alcantara 			if (cifs_ses_exiting(ses))
254ca545b7fSPaulo Alcantara 				continue;
25538c8a9a5SSteve French 			list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
25638c8a9a5SSteve French 				spin_lock(&tcon->open_file_lock);
25738c8a9a5SSteve French 				list_for_each_entry(cfile, &tcon->openFileList, tlist) {
25838c8a9a5SSteve French 					seq_printf(m,
25938c8a9a5SSteve French 						"0x%x 0x%llx 0x%llx 0x%x %d %d %d %pd",
26038c8a9a5SSteve French 						tcon->tid,
26138c8a9a5SSteve French 						ses->Suid,
26238c8a9a5SSteve French 						cfile->fid.persistent_fid,
26338c8a9a5SSteve French 						cfile->f_flags,
26438c8a9a5SSteve French 						cfile->count,
26538c8a9a5SSteve French 						cfile->pid,
26638c8a9a5SSteve French 						from_kuid(&init_user_ns, cfile->uid),
26738c8a9a5SSteve French 						cfile->dentry);
26838c8a9a5SSteve French #ifdef CONFIG_CIFS_DEBUG2
26938c8a9a5SSteve French 					seq_printf(m, " %llu\n", cfile->fid.mid);
27038c8a9a5SSteve French #else
27138c8a9a5SSteve French 					seq_printf(m, "\n");
27238c8a9a5SSteve French #endif /* CIFS_DEBUG2 */
27338c8a9a5SSteve French 				}
27438c8a9a5SSteve French 				spin_unlock(&tcon->open_file_lock);
27538c8a9a5SSteve French 			}
27638c8a9a5SSteve French 		}
27738c8a9a5SSteve French 	}
27838c8a9a5SSteve French 	spin_unlock(&cifs_tcp_ses_lock);
27938c8a9a5SSteve French 	seq_putc(m, '\n');
28038c8a9a5SSteve French 	return 0;
28138c8a9a5SSteve French }
28238c8a9a5SSteve French 
compression_alg_str(__le16 alg)2838fe7062bSEnzo Matsumiya static __always_inline const char *compression_alg_str(__le16 alg)
2848fe7062bSEnzo Matsumiya {
2858fe7062bSEnzo Matsumiya 	switch (alg) {
2868fe7062bSEnzo Matsumiya 	case SMB3_COMPRESS_NONE:
2878fe7062bSEnzo Matsumiya 		return "NONE";
2888fe7062bSEnzo Matsumiya 	case SMB3_COMPRESS_LZNT1:
2898fe7062bSEnzo Matsumiya 		return "LZNT1";
2908fe7062bSEnzo Matsumiya 	case SMB3_COMPRESS_LZ77:
2918fe7062bSEnzo Matsumiya 		return "LZ77";
2928fe7062bSEnzo Matsumiya 	case SMB3_COMPRESS_LZ77_HUFF:
2938fe7062bSEnzo Matsumiya 		return "LZ77-Huffman";
2948fe7062bSEnzo Matsumiya 	case SMB3_COMPRESS_PATTERN:
2958fe7062bSEnzo Matsumiya 		return "Pattern_V1";
2968fe7062bSEnzo Matsumiya 	default:
2978fe7062bSEnzo Matsumiya 		return "invalid";
2988fe7062bSEnzo Matsumiya 	}
2998fe7062bSEnzo Matsumiya }
3008fe7062bSEnzo Matsumiya 
cifs_debug_data_proc_show(struct seq_file * m,void * v)30138c8a9a5SSteve French static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
30238c8a9a5SSteve French {
30338c8a9a5SSteve French 	struct mid_q_entry *mid_entry;
30438c8a9a5SSteve French 	struct TCP_Server_Info *server;
30538c8a9a5SSteve French 	struct TCP_Server_Info *chan_server;
30638c8a9a5SSteve French 	struct cifs_ses *ses;
30738c8a9a5SSteve French 	struct cifs_tcon *tcon;
30838c8a9a5SSteve French 	struct cifs_server_iface *iface;
309a6d8fb54SShyam Prasad N 	size_t iface_weight = 0, iface_min_speed = 0;
310a6d8fb54SShyam Prasad N 	struct cifs_server_iface *last_iface = NULL;
31138c8a9a5SSteve French 	int c, i, j;
31238c8a9a5SSteve French 
31338c8a9a5SSteve French 	seq_puts(m,
31438c8a9a5SSteve French 		    "Display Internal CIFS Data Structures for Debugging\n"
31538c8a9a5SSteve French 		    "---------------------------------------------------\n");
31638c8a9a5SSteve French 	seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
31738c8a9a5SSteve French 	seq_printf(m, "Features:");
31838c8a9a5SSteve French #ifdef CONFIG_CIFS_DFS_UPCALL
31938c8a9a5SSteve French 	seq_printf(m, " DFS");
32038c8a9a5SSteve French #endif
32138c8a9a5SSteve French #ifdef CONFIG_CIFS_FSCACHE
32238c8a9a5SSteve French 	seq_printf(m, ",FSCACHE");
32338c8a9a5SSteve French #endif
32438c8a9a5SSteve French #ifdef CONFIG_CIFS_SMB_DIRECT
32538c8a9a5SSteve French 	seq_printf(m, ",SMB_DIRECT");
32638c8a9a5SSteve French #endif
32738c8a9a5SSteve French #ifdef CONFIG_CIFS_STATS2
32838c8a9a5SSteve French 	seq_printf(m, ",STATS2");
32938c8a9a5SSteve French #else
33038c8a9a5SSteve French 	seq_printf(m, ",STATS");
33138c8a9a5SSteve French #endif
33238c8a9a5SSteve French #ifdef CONFIG_CIFS_DEBUG2
33338c8a9a5SSteve French 	seq_printf(m, ",DEBUG2");
33438c8a9a5SSteve French #elif defined(CONFIG_CIFS_DEBUG)
33538c8a9a5SSteve French 	seq_printf(m, ",DEBUG");
33638c8a9a5SSteve French #endif
33738c8a9a5SSteve French #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
33838c8a9a5SSteve French 	seq_printf(m, ",ALLOW_INSECURE_LEGACY");
33938c8a9a5SSteve French #endif
34038c8a9a5SSteve French #ifdef CONFIG_CIFS_POSIX
34138c8a9a5SSteve French 	seq_printf(m, ",CIFS_POSIX");
34238c8a9a5SSteve French #endif
34338c8a9a5SSteve French #ifdef CONFIG_CIFS_UPCALL
34438c8a9a5SSteve French 	seq_printf(m, ",UPCALL(SPNEGO)");
34538c8a9a5SSteve French #endif
34638c8a9a5SSteve French #ifdef CONFIG_CIFS_XATTR
34738c8a9a5SSteve French 	seq_printf(m, ",XATTR");
34838c8a9a5SSteve French #endif
34938c8a9a5SSteve French 	seq_printf(m, ",ACL");
35038c8a9a5SSteve French #ifdef CONFIG_CIFS_SWN_UPCALL
35138c8a9a5SSteve French 	seq_puts(m, ",WITNESS");
35238c8a9a5SSteve French #endif
35338c8a9a5SSteve French #ifdef CONFIG_CIFS_COMPRESSION
35438c8a9a5SSteve French 	seq_puts(m, ",COMPRESSION");
35538c8a9a5SSteve French #endif
35638c8a9a5SSteve French 	seq_putc(m, '\n');
35738c8a9a5SSteve French 	seq_printf(m, "CIFSMaxBufSize: %d\n", CIFSMaxBufSize);
35838c8a9a5SSteve French 	seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
35938c8a9a5SSteve French 
36038c8a9a5SSteve French 	seq_printf(m, "\nServers: ");
36138c8a9a5SSteve French 
36238c8a9a5SSteve French 	c = 0;
363b3773b19SSteve French 	spin_lock(&cifs_tcp_ses_lock);
36438c8a9a5SSteve French 	list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
36538c8a9a5SSteve French 		/* channel info will be printed as a part of sessions below */
36638c8a9a5SSteve French 		if (SERVER_IS_CHAN(server))
36738c8a9a5SSteve French 			continue;
36838c8a9a5SSteve French 
36938c8a9a5SSteve French 		c++;
37038c8a9a5SSteve French 		seq_printf(m, "\n%d) ConnectionId: 0x%llx ",
37138c8a9a5SSteve French 			c, server->conn_id);
37238c8a9a5SSteve French 
373380958acSShyam Prasad N 		spin_lock(&server->srv_lock);
37438c8a9a5SSteve French 		if (server->hostname)
37538c8a9a5SSteve French 			seq_printf(m, "Hostname: %s ", server->hostname);
37638c8a9a5SSteve French 		seq_printf(m, "\nClientGUID: %pUL", server->client_guid);
37738c8a9a5SSteve French 		spin_unlock(&server->srv_lock);
37838c8a9a5SSteve French #ifdef CONFIG_CIFS_SMB_DIRECT
37938c8a9a5SSteve French 		if (!server->rdma)
38038c8a9a5SSteve French 			goto skip_rdma;
38138c8a9a5SSteve French 
38238c8a9a5SSteve French 		if (!server->smbd_conn) {
38338c8a9a5SSteve French 			seq_printf(m, "\nSMBDirect transport not available");
38438c8a9a5SSteve French 			goto skip_rdma;
38538c8a9a5SSteve French 		}
38638c8a9a5SSteve French 
38738c8a9a5SSteve French 		seq_printf(m, "\nSMBDirect (in hex) protocol version: %x "
38838c8a9a5SSteve French 			"transport status: %x",
38938c8a9a5SSteve French 			server->smbd_conn->protocol,
39038c8a9a5SSteve French 			server->smbd_conn->transport_status);
39138c8a9a5SSteve French 		seq_printf(m, "\nConn receive_credit_max: %x "
39238c8a9a5SSteve French 			"send_credit_target: %x max_send_size: %x",
39338c8a9a5SSteve French 			server->smbd_conn->receive_credit_max,
39438c8a9a5SSteve French 			server->smbd_conn->send_credit_target,
39538c8a9a5SSteve French 			server->smbd_conn->max_send_size);
39638c8a9a5SSteve French 		seq_printf(m, "\nConn max_fragmented_recv_size: %x "
39738c8a9a5SSteve French 			"max_fragmented_send_size: %x max_receive_size:%x",
39838c8a9a5SSteve French 			server->smbd_conn->max_fragmented_recv_size,
39938c8a9a5SSteve French 			server->smbd_conn->max_fragmented_send_size,
40038c8a9a5SSteve French 			server->smbd_conn->max_receive_size);
40138c8a9a5SSteve French 		seq_printf(m, "\nConn keep_alive_interval: %x "
40238c8a9a5SSteve French 			"max_readwrite_size: %x rdma_readwrite_threshold: %x",
40338c8a9a5SSteve French 			server->smbd_conn->keep_alive_interval,
40438c8a9a5SSteve French 			server->smbd_conn->max_readwrite_size,
40538c8a9a5SSteve French 			server->smbd_conn->rdma_readwrite_threshold);
40638c8a9a5SSteve French 		seq_printf(m, "\nDebug count_get_receive_buffer: %x "
40738c8a9a5SSteve French 			"count_put_receive_buffer: %x count_send_empty: %x",
40838c8a9a5SSteve French 			server->smbd_conn->count_get_receive_buffer,
40938c8a9a5SSteve French 			server->smbd_conn->count_put_receive_buffer,
41038c8a9a5SSteve French 			server->smbd_conn->count_send_empty);
41138c8a9a5SSteve French 		seq_printf(m, "\nRead Queue count_reassembly_queue: %x "
41238c8a9a5SSteve French 			"count_enqueue_reassembly_queue: %x "
41338c8a9a5SSteve French 			"count_dequeue_reassembly_queue: %x "
41438c8a9a5SSteve French 			"fragment_reassembly_remaining: %x "
41538c8a9a5SSteve French 			"reassembly_data_length: %x "
41638c8a9a5SSteve French 			"reassembly_queue_length: %x",
41738c8a9a5SSteve French 			server->smbd_conn->count_reassembly_queue,
41838c8a9a5SSteve French 			server->smbd_conn->count_enqueue_reassembly_queue,
41938c8a9a5SSteve French 			server->smbd_conn->count_dequeue_reassembly_queue,
42038c8a9a5SSteve French 			server->smbd_conn->fragment_reassembly_remaining,
42138c8a9a5SSteve French 			server->smbd_conn->reassembly_data_length,
42238c8a9a5SSteve French 			server->smbd_conn->reassembly_queue_length);
42338c8a9a5SSteve French 		seq_printf(m, "\nCurrent Credits send_credits: %x "
42438c8a9a5SSteve French 			"receive_credits: %x receive_credit_target: %x",
42538c8a9a5SSteve French 			atomic_read(&server->smbd_conn->send_credits),
42638c8a9a5SSteve French 			atomic_read(&server->smbd_conn->receive_credits),
42738c8a9a5SSteve French 			server->smbd_conn->receive_credit_target);
42838c8a9a5SSteve French 		seq_printf(m, "\nPending send_pending: %x ",
42938c8a9a5SSteve French 			atomic_read(&server->smbd_conn->send_pending));
43038c8a9a5SSteve French 		seq_printf(m, "\nReceive buffers count_receive_queue: %x "
43138c8a9a5SSteve French 			"count_empty_packet_queue: %x",
43238c8a9a5SSteve French 			server->smbd_conn->count_receive_queue,
43338c8a9a5SSteve French 			server->smbd_conn->count_empty_packet_queue);
43438c8a9a5SSteve French 		seq_printf(m, "\nMR responder_resources: %x "
43538c8a9a5SSteve French 			"max_frmr_depth: %x mr_type: %x",
43638c8a9a5SSteve French 			server->smbd_conn->responder_resources,
43738c8a9a5SSteve French 			server->smbd_conn->max_frmr_depth,
43838c8a9a5SSteve French 			server->smbd_conn->mr_type);
43938c8a9a5SSteve French 		seq_printf(m, "\nMR mr_ready_count: %x mr_used_count: %x",
44038c8a9a5SSteve French 			atomic_read(&server->smbd_conn->mr_ready_count),
4412a44b389SShyam Prasad N 			atomic_read(&server->smbd_conn->mr_used_count));
4422a44b389SShyam Prasad N skip_rdma:
4432a44b389SShyam Prasad N #endif
4442a44b389SShyam Prasad N 		seq_printf(m, "\nNumber of credits: %d,%d,%d Dialect 0x%x",
4452a44b389SShyam Prasad N 			server->credits,
44638c8a9a5SSteve French 			server->echo_credits,
44738c8a9a5SSteve French 			server->oplock_credits,
44838c8a9a5SSteve French 			server->dialect);
44938c8a9a5SSteve French 		if (server->sign)
45038c8a9a5SSteve French 			seq_printf(m, " signed");
45138c8a9a5SSteve French 		if (server->posix_ext_supported)
45238c8a9a5SSteve French 			seq_printf(m, " posix");
45352768695SShyam Prasad N 		if (server->nosharesock)
45452768695SShyam Prasad N 			seq_printf(m, " nosharesock");
45538c8a9a5SSteve French 
45638c8a9a5SSteve French 		seq_printf(m, "\nServer capabilities: 0x%x", server->capabilities);
45738c8a9a5SSteve French 
45838c8a9a5SSteve French 		if (server->rdma)
45938c8a9a5SSteve French 			seq_printf(m, "\nRDMA ");
46038c8a9a5SSteve French 		seq_printf(m, "\nTCP status: %d Instance: %d"
46138c8a9a5SSteve French 				"\nLocal Users To Server: %d SecMode: 0x%x Req On Wire: %d",
46238c8a9a5SSteve French 				server->tcpStatus,
4637b38f6ddSSteve French 				server->reconnect_instance,
4647b38f6ddSSteve French 				server->srv_count,
4657b38f6ddSSteve French 				server->sec_mode, in_flight(server));
4667b38f6ddSSteve French #ifdef CONFIG_NET_NS
46738c8a9a5SSteve French 		if (server->net)
46838c8a9a5SSteve French 			seq_printf(m, " Net namespace: %u ", server->net->ns.inum);
46938c8a9a5SSteve French #endif /* NET_NS */
47038c8a9a5SSteve French 
4717b38f6ddSSteve French 		seq_printf(m, "\nIn Send: %d In MaxReq Wait: %d",
4723ae872deSPaulo Alcantara 				atomic_read(&server->in_send),
47338c8a9a5SSteve French 				atomic_read(&server->num_waiters));
47438c8a9a5SSteve French 
47538c8a9a5SSteve French 		if (server->leaf_fullpath) {
47638c8a9a5SSteve French 			seq_printf(m, "\nDFS leaf full path: %s",
4778fe7062bSEnzo Matsumiya 				   server->leaf_fullpath);
4788fe7062bSEnzo Matsumiya 		}
4798fe7062bSEnzo Matsumiya 
4808fe7062bSEnzo Matsumiya 		seq_puts(m, "\nCompression: ");
4818fe7062bSEnzo Matsumiya 		if (!IS_ENABLED(CONFIG_CIFS_COMPRESSION))
4828fe7062bSEnzo Matsumiya 			seq_puts(m, "no built-in support");
4838fe7062bSEnzo Matsumiya 		else if (!server->compression.requested)
4848fe7062bSEnzo Matsumiya 			seq_puts(m, "disabled on mount");
48538c8a9a5SSteve French 		else if (server->compression.enabled)
48638c8a9a5SSteve French 			seq_printf(m, "enabled (%s)", compression_alg_str(server->compression.alg));
48738c8a9a5SSteve French 		else
488d328c09eSPaulo Alcantara 			seq_puts(m, "disabled (not supported by this server)");
489d328c09eSPaulo Alcantara 
490d328c09eSPaulo Alcantara 		seq_printf(m, "\n\n\tSessions: ");
491d328c09eSPaulo Alcantara 		i = 0;
492d328c09eSPaulo Alcantara 		list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
49338c8a9a5SSteve French 			spin_lock(&ses->ses_lock);
49438c8a9a5SSteve French 			if (ses->ses_status == SES_EXITING) {
49538c8a9a5SSteve French 				spin_unlock(&ses->ses_lock);
49638c8a9a5SSteve French 				continue;
49738c8a9a5SSteve French 			}
49838c8a9a5SSteve French 			i++;
49938c8a9a5SSteve French 			if ((ses->serverDomain == NULL) ||
50038c8a9a5SSteve French 				(ses->serverOS == NULL) ||
50138c8a9a5SSteve French 				(ses->serverNOS == NULL)) {
50238c8a9a5SSteve French 				seq_printf(m, "\n\t%d) Address: %s Uses: %d Capability: 0x%x\tSession Status: %d ",
50338c8a9a5SSteve French 					i, ses->ip_addr, ses->ses_count,
50438c8a9a5SSteve French 					ses->capabilities, ses->ses_status);
50538c8a9a5SSteve French 				if (ses->session_flags & SMB2_SESSION_FLAG_IS_GUEST)
50638c8a9a5SSteve French 					seq_printf(m, "Guest ");
50738c8a9a5SSteve French 				else if (ses->session_flags & SMB2_SESSION_FLAG_IS_NULL)
50838c8a9a5SSteve French 					seq_printf(m, "Anonymous ");
50938c8a9a5SSteve French 			} else {
51038c8a9a5SSteve French 				seq_printf(m,
51138c8a9a5SSteve French 				    "\n\t%d) Name: %s  Domain: %s Uses: %d OS: %s "
51238c8a9a5SSteve French 				    "\n\tNOS: %s\tCapability: 0x%x"
513c1eb537bSSteve French 					"\n\tSMB session status: %d ",
514c1eb537bSSteve French 				i, ses->ip_addr, ses->serverDomain,
515d328c09eSPaulo Alcantara 				ses->ses_count, ses->serverOS, ses->serverNOS,
51638c8a9a5SSteve French 				ses->capabilities, ses->ses_status);
51738c8a9a5SSteve French 			}
51838c8a9a5SSteve French 			if (ses->expired_pwd)
51938c8a9a5SSteve French 				seq_puts(m, "password no longer valid ");
52038c8a9a5SSteve French 			spin_unlock(&ses->ses_lock);
52138c8a9a5SSteve French 
52238c8a9a5SSteve French 			seq_printf(m, "\n\tSecurity type: %s ",
52338c8a9a5SSteve French 				get_security_type_str(server->ops->select_sectype(server, ses->sectype)));
52438c8a9a5SSteve French 
52538c8a9a5SSteve French 			/* dump session id helpful for use with network trace */
52638c8a9a5SSteve French 			seq_printf(m, " SessionId: 0x%llx", ses->Suid);
52738c8a9a5SSteve French 			if (ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA) {
52838c8a9a5SSteve French 				seq_puts(m, " encrypted");
52938c8a9a5SSteve French 				/* can help in debugging to show encryption type */
53038c8a9a5SSteve French 				if (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM)
53138c8a9a5SSteve French 					seq_puts(m, "(gcm256)");
53238c8a9a5SSteve French 			}
53338c8a9a5SSteve French 			if (ses->sign)
53438c8a9a5SSteve French 				seq_puts(m, " signed");
53538c8a9a5SSteve French 
53638c8a9a5SSteve French 			seq_printf(m, "\n\tUser: %d Cred User: %d",
53738c8a9a5SSteve French 				   from_kuid(&init_user_ns, ses->linux_uid),
53838c8a9a5SSteve French 				   from_kuid(&init_user_ns, ses->cred_uid));
53938c8a9a5SSteve French 
54038c8a9a5SSteve French 			if (ses->dfs_root_ses) {
54138c8a9a5SSteve French 				seq_printf(m, "\n\tDFS root session id: 0x%llx",
54238c8a9a5SSteve French 					   ses->dfs_root_ses->Suid);
54338c8a9a5SSteve French 			}
54438c8a9a5SSteve French 
54538c8a9a5SSteve French 			spin_lock(&ses->chan_lock);
54638c8a9a5SSteve French 			if (CIFS_CHAN_NEEDS_RECONNECT(ses, 0))
54738c8a9a5SSteve French 				seq_puts(m, "\tPrimary channel: DISCONNECTED ");
54838c8a9a5SSteve French 			if (CIFS_CHAN_IN_RECONNECT(ses, 0))
54938c8a9a5SSteve French 				seq_puts(m, "\t[RECONNECTING] ");
55038c8a9a5SSteve French 
55138c8a9a5SSteve French 			if (ses->chan_count > 1) {
55238c8a9a5SSteve French 				seq_printf(m, "\n\n\tExtra Channels: %zu ",
55338c8a9a5SSteve French 					   ses->chan_count-1);
55438c8a9a5SSteve French 				for (j = 1; j < ses->chan_count; j++) {
55538c8a9a5SSteve French 					cifs_dump_channel(m, j, &ses->chans[j]);
55638c8a9a5SSteve French 					if (CIFS_CHAN_NEEDS_RECONNECT(ses, j))
55738c8a9a5SSteve French 						seq_puts(m, "\tDISCONNECTED ");
55838c8a9a5SSteve French 					if (CIFS_CHAN_IN_RECONNECT(ses, j))
55938c8a9a5SSteve French 						seq_puts(m, "\t[RECONNECTING] ");
56038c8a9a5SSteve French 				}
56138c8a9a5SSteve French 			}
56238c8a9a5SSteve French 			spin_unlock(&ses->chan_lock);
56338c8a9a5SSteve French 
56438c8a9a5SSteve French 			seq_puts(m, "\n\n\tShares: ");
56538c8a9a5SSteve French 			j = 0;
56638c8a9a5SSteve French 
56738c8a9a5SSteve French 			seq_printf(m, "\n\t%d) IPC: ", j);
56838c8a9a5SSteve French 			if (ses->tcon_ipc)
56938c8a9a5SSteve French 				cifs_debug_tcon(m, ses->tcon_ipc);
57038c8a9a5SSteve French 			else
57138c8a9a5SSteve French 				seq_puts(m, "none\n");
57238c8a9a5SSteve French 
57338c8a9a5SSteve French 			list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
57438c8a9a5SSteve French 				++j;
57538c8a9a5SSteve French 				seq_printf(m, "\n\t%d) ", j);
57638c8a9a5SSteve French 				cifs_debug_tcon(m, tcon);
57738c8a9a5SSteve French 			}
57838c8a9a5SSteve French 
57938c8a9a5SSteve French 			spin_lock(&ses->iface_lock);
580a6d8fb54SShyam Prasad N 			if (ses->iface_count)
581a6d8fb54SShyam Prasad N 				seq_printf(m, "\n\n\tServer interfaces: %zu"
582a6d8fb54SShyam Prasad N 					   "\tLast updated: %lu seconds ago",
583a6d8fb54SShyam Prasad N 					   ses->iface_count,
584a6d8fb54SShyam Prasad N 					   (jiffies - ses->iface_last_update) / HZ);
585a6d8fb54SShyam Prasad N 
58638c8a9a5SSteve French 			last_iface = list_last_entry(&ses->iface_list,
58738c8a9a5SSteve French 						     struct cifs_server_iface,
58838c8a9a5SSteve French 						     iface_head);
58938c8a9a5SSteve French 			iface_min_speed = last_iface->speed;
59038c8a9a5SSteve French 
591a6d8fb54SShyam Prasad N 			j = 0;
592a6d8fb54SShyam Prasad N 			list_for_each_entry(iface, &ses->iface_list,
593a6d8fb54SShyam Prasad N 						 iface_head) {
594a6d8fb54SShyam Prasad N 				seq_printf(m, "\n\t%d)", ++j);
595a6d8fb54SShyam Prasad N 				cifs_dump_iface(m, iface);
596a6d8fb54SShyam Prasad N 
597a6d8fb54SShyam Prasad N 				iface_weight = iface->speed / iface_min_speed;
598a6d8fb54SShyam Prasad N 				seq_printf(m, "\t\tWeight (cur,total): (%zu,%zu)"
59938c8a9a5SSteve French 					   "\n\t\tAllocated channels: %u\n",
60038c8a9a5SSteve French 					   iface->weight_fulfilled,
60138c8a9a5SSteve French 					   iface_weight,
60238c8a9a5SSteve French 					   iface->num_channels);
60338c8a9a5SSteve French 
60438c8a9a5SSteve French 				if (is_ses_using_iface(ses, iface))
60538c8a9a5SSteve French 					seq_puts(m, "\t\t[CONNECTED]\n");
60638c8a9a5SSteve French 			}
60738c8a9a5SSteve French 			spin_unlock(&ses->iface_lock);
60838c8a9a5SSteve French 
60938c8a9a5SSteve French 			seq_puts(m, "\n\n\tMIDs: ");
61038c8a9a5SSteve French 			spin_lock(&ses->chan_lock);
61138c8a9a5SSteve French 			for (j = 0; j < ses->chan_count; j++) {
61238c8a9a5SSteve French 				chan_server = ses->chans[j].server;
61338c8a9a5SSteve French 				if (!chan_server)
61438c8a9a5SSteve French 					continue;
61538c8a9a5SSteve French 
61638c8a9a5SSteve French 				if (list_empty(&chan_server->pending_mid_q))
61738c8a9a5SSteve French 					continue;
61838c8a9a5SSteve French 
61938c8a9a5SSteve French 				seq_printf(m, "\n\tServer ConnectionId: 0x%llx",
62038c8a9a5SSteve French 					   chan_server->conn_id);
62138c8a9a5SSteve French 				spin_lock(&chan_server->mid_lock);
62238c8a9a5SSteve French 				list_for_each_entry(mid_entry, &chan_server->pending_mid_q, qhead) {
62338c8a9a5SSteve French 					seq_printf(m, "\n\t\tState: %d com: %d pid: %d cbdata: %p mid %llu",
62438c8a9a5SSteve French 						   mid_entry->mid_state,
62538c8a9a5SSteve French 						   le16_to_cpu(mid_entry->command),
62638c8a9a5SSteve French 						   mid_entry->pid,
62738c8a9a5SSteve French 						   mid_entry->callback_data,
62838c8a9a5SSteve French 						   mid_entry->mid);
62938c8a9a5SSteve French 				}
63038c8a9a5SSteve French 				spin_unlock(&chan_server->mid_lock);
63138c8a9a5SSteve French 			}
63238c8a9a5SSteve French 			spin_unlock(&ses->chan_lock);
63338c8a9a5SSteve French 			seq_puts(m, "\n--\n");
63438c8a9a5SSteve French 		}
63538c8a9a5SSteve French 		if (i == 0)
63638c8a9a5SSteve French 			seq_printf(m, "\n\t\t[NONE]");
63738c8a9a5SSteve French 	}
63838c8a9a5SSteve French 	if (c == 0)
63938c8a9a5SSteve French 		seq_printf(m, "\n\t[NONE]");
64038c8a9a5SSteve French 
64138c8a9a5SSteve French 	spin_unlock(&cifs_tcp_ses_lock);
64238c8a9a5SSteve French 	seq_putc(m, '\n');
64338c8a9a5SSteve French 	cifs_swn_dump(m);
64438c8a9a5SSteve French 
64538c8a9a5SSteve French 	/* BB add code to dump additional info such as TCP session info now */
64638c8a9a5SSteve French 	return 0;
64738c8a9a5SSteve French }
64838c8a9a5SSteve French 
cifs_stats_proc_write(struct file * file,const char __user * buffer,size_t count,loff_t * ppos)64938c8a9a5SSteve French static ssize_t cifs_stats_proc_write(struct file *file,
65038c8a9a5SSteve French 		const char __user *buffer, size_t count, loff_t *ppos)
65138c8a9a5SSteve French {
65238c8a9a5SSteve French 	bool bv;
65338c8a9a5SSteve French 	int rc;
65438c8a9a5SSteve French 	struct TCP_Server_Info *server;
65538c8a9a5SSteve French 	struct cifs_ses *ses;
65638c8a9a5SSteve French 	struct cifs_tcon *tcon;
65738c8a9a5SSteve French 
65838c8a9a5SSteve French 	rc = kstrtobool_from_user(buffer, count, &bv);
65938c8a9a5SSteve French 	if (rc == 0) {
66038c8a9a5SSteve French #ifdef CONFIG_CIFS_STATS2
66138c8a9a5SSteve French 		int i;
66238c8a9a5SSteve French 
66338c8a9a5SSteve French 		atomic_set(&total_buf_alloc_count, 0);
66438c8a9a5SSteve French 		atomic_set(&total_small_buf_alloc_count, 0);
66538c8a9a5SSteve French #endif /* CONFIG_CIFS_STATS2 */
66638c8a9a5SSteve French 		atomic_set(&tcpSesReconnectCount, 0);
66738c8a9a5SSteve French 		atomic_set(&tconInfoReconnectCount, 0);
66838c8a9a5SSteve French 
66938c8a9a5SSteve French 		spin_lock(&GlobalMid_Lock);
67038c8a9a5SSteve French 		GlobalMaxActiveXid = 0;
67138c8a9a5SSteve French 		GlobalCurrentXid = 0;
67238c8a9a5SSteve French 		spin_unlock(&GlobalMid_Lock);
67338c8a9a5SSteve French 		spin_lock(&cifs_tcp_ses_lock);
67438c8a9a5SSteve French 		list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
67538c8a9a5SSteve French 			server->max_in_flight = 0;
67638c8a9a5SSteve French #ifdef CONFIG_CIFS_STATS2
67738c8a9a5SSteve French 			for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
67838c8a9a5SSteve French 				atomic_set(&server->num_cmds[i], 0);
67938c8a9a5SSteve French 				atomic_set(&server->smb2slowcmd[i], 0);
68038c8a9a5SSteve French 				server->time_per_cmd[i] = 0;
681d3da25c5SPaulo Alcantara 				server->slowest_cmd[i] = 0;
682d3da25c5SPaulo Alcantara 				server->fastest_cmd[0] = 0;
68338c8a9a5SSteve French 			}
68438c8a9a5SSteve French #endif /* CONFIG_CIFS_STATS2 */
68538c8a9a5SSteve French 			list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
68638c8a9a5SSteve French 				if (cifs_ses_exiting(ses))
68738c8a9a5SSteve French 					continue;
688d8392c20SSteve French 				list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
68938c8a9a5SSteve French 					atomic_set(&tcon->num_smbs_sent, 0);
69038c8a9a5SSteve French 					spin_lock(&tcon->stat_lock);
69138c8a9a5SSteve French 					tcon->bytes_read = 0;
69238c8a9a5SSteve French 					tcon->bytes_written = 0;
69338c8a9a5SSteve French 					tcon->stats_from_time = ktime_get_real_seconds();
69438c8a9a5SSteve French 					spin_unlock(&tcon->stat_lock);
69538c8a9a5SSteve French 					if (server->ops->clear_stats)
69638c8a9a5SSteve French 						server->ops->clear_stats(tcon);
69738c8a9a5SSteve French 				}
69838c8a9a5SSteve French 			}
69938c8a9a5SSteve French 		}
70038c8a9a5SSteve French 		spin_unlock(&cifs_tcp_ses_lock);
70138c8a9a5SSteve French 	} else {
70238c8a9a5SSteve French 		return rc;
70338c8a9a5SSteve French 	}
70438c8a9a5SSteve French 
70538c8a9a5SSteve French 	return count;
70638c8a9a5SSteve French }
70738c8a9a5SSteve French 
cifs_stats_proc_show(struct seq_file * m,void * v)70838c8a9a5SSteve French static int cifs_stats_proc_show(struct seq_file *m, void *v)
70938c8a9a5SSteve French {
71038c8a9a5SSteve French 	int i;
71138c8a9a5SSteve French #ifdef CONFIG_CIFS_STATS2
71238c8a9a5SSteve French 	int j;
71338c8a9a5SSteve French #endif /* STATS2 */
71438c8a9a5SSteve French 	struct TCP_Server_Info *server;
71538c8a9a5SSteve French 	struct cifs_ses *ses;
71638c8a9a5SSteve French 	struct cifs_tcon *tcon;
71738c8a9a5SSteve French 
71838c8a9a5SSteve French 	seq_printf(m, "Resources in use\nCIFS Session: %d\n",
71938c8a9a5SSteve French 			sesInfoAllocCount.counter);
72038c8a9a5SSteve French 	seq_printf(m, "Share (unique mount targets): %d\n",
72138c8a9a5SSteve French 			tconInfoAllocCount.counter);
72238c8a9a5SSteve French 	seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
72338c8a9a5SSteve French 			buf_alloc_count.counter,
72438c8a9a5SSteve French 			cifs_min_rcv + tcpSesAllocCount.counter);
72538c8a9a5SSteve French 	seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
72638c8a9a5SSteve French 			small_buf_alloc_count.counter, cifs_min_small);
72738c8a9a5SSteve French #ifdef CONFIG_CIFS_STATS2
72838c8a9a5SSteve French 	seq_printf(m, "Total Large %d Small %d Allocations\n",
72938c8a9a5SSteve French 				atomic_read(&total_buf_alloc_count),
73038c8a9a5SSteve French 				atomic_read(&total_small_buf_alloc_count));
73138c8a9a5SSteve French #endif /* CONFIG_CIFS_STATS2 */
73238c8a9a5SSteve French 
73338c8a9a5SSteve French 	seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&mid_count));
73438c8a9a5SSteve French 	seq_printf(m,
73538c8a9a5SSteve French 		"\n%d session %d share reconnects\n",
73638c8a9a5SSteve French 		tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
73738c8a9a5SSteve French 
73838c8a9a5SSteve French 	seq_printf(m,
73938c8a9a5SSteve French 		"Total vfs operations: %d maximum at one time: %d\n",
74038c8a9a5SSteve French 		GlobalCurrentXid, GlobalMaxActiveXid);
74138c8a9a5SSteve French 
74238c8a9a5SSteve French 	i = 0;
74338c8a9a5SSteve French 	spin_lock(&cifs_tcp_ses_lock);
74438c8a9a5SSteve French 	list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
74538c8a9a5SSteve French 		seq_printf(m, "\nMax requests in flight: %d", server->max_in_flight);
74638c8a9a5SSteve French #ifdef CONFIG_CIFS_STATS2
74738c8a9a5SSteve French 		seq_puts(m, "\nTotal time spent processing by command. Time ");
74838c8a9a5SSteve French 		seq_printf(m, "units are jiffies (%d per second)\n", HZ);
74938c8a9a5SSteve French 		seq_puts(m, "  SMB3 CMD\tNumber\tTotal Time\tFastest\tSlowest\n");
75038c8a9a5SSteve French 		seq_puts(m, "  --------\t------\t----------\t-------\t-------\n");
75138c8a9a5SSteve French 		for (j = 0; j < NUMBER_OF_SMB2_COMMANDS; j++)
75238c8a9a5SSteve French 			seq_printf(m, "  %d\t\t%d\t%llu\t\t%u\t%u\n", j,
75338c8a9a5SSteve French 				atomic_read(&server->num_cmds[j]),
75438c8a9a5SSteve French 				server->time_per_cmd[j],
75538c8a9a5SSteve French 				server->fastest_cmd[j],
75638c8a9a5SSteve French 				server->slowest_cmd[j]);
75738c8a9a5SSteve French 		for (j = 0; j < NUMBER_OF_SMB2_COMMANDS; j++)
75838c8a9a5SSteve French 			if (atomic_read(&server->smb2slowcmd[j])) {
75938c8a9a5SSteve French 				spin_lock(&server->srv_lock);
76038c8a9a5SSteve French 				seq_printf(m, "  %d slow responses from %s for command %d\n",
76138c8a9a5SSteve French 					atomic_read(&server->smb2slowcmd[j]),
7620865ffefSPaulo Alcantara 					server->hostname, j);
7630865ffefSPaulo Alcantara 				spin_unlock(&server->srv_lock);
76438c8a9a5SSteve French 			}
76538c8a9a5SSteve French #endif /* STATS2 */
76638c8a9a5SSteve French 		list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
76738c8a9a5SSteve French 			if (cifs_ses_exiting(ses))
76838c8a9a5SSteve French 				continue;
769d8392c20SSteve French 			list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
770d8392c20SSteve French 				i++;
771d8392c20SSteve French 				seq_printf(m, "\n%d) %s", i, tcon->tree_name);
77238c8a9a5SSteve French 				if (tcon->need_reconnect)
77338c8a9a5SSteve French 					seq_puts(m, "\tDISCONNECTED ");
77438c8a9a5SSteve French 				seq_printf(m, "\nSMBs: %d since %ptTs UTC",
77538c8a9a5SSteve French 					   atomic_read(&tcon->num_smbs_sent),
77638c8a9a5SSteve French 					   &tcon->stats_from_time);
77738c8a9a5SSteve French 				if (server->ops->print_stats)
77838c8a9a5SSteve French 					server->ops->print_stats(m, tcon);
77938c8a9a5SSteve French 			}
78038c8a9a5SSteve French 		}
78138c8a9a5SSteve French 	}
78238c8a9a5SSteve French 	spin_unlock(&cifs_tcp_ses_lock);
78338c8a9a5SSteve French 
78438c8a9a5SSteve French 	seq_putc(m, '\n');
78538c8a9a5SSteve French 	return 0;
78638c8a9a5SSteve French }
78738c8a9a5SSteve French 
cifs_stats_proc_open(struct inode * inode,struct file * file)78838c8a9a5SSteve French static int cifs_stats_proc_open(struct inode *inode, struct file *file)
78938c8a9a5SSteve French {
79038c8a9a5SSteve French 	return single_open(file, cifs_stats_proc_show, NULL);
79138c8a9a5SSteve French }
79238c8a9a5SSteve French 
79338c8a9a5SSteve French static const struct proc_ops cifs_stats_proc_ops = {
79438c8a9a5SSteve French 	.proc_open	= cifs_stats_proc_open,
79538c8a9a5SSteve French 	.proc_read	= seq_read,
79638c8a9a5SSteve French 	.proc_lseek	= seq_lseek,
79738c8a9a5SSteve French 	.proc_release	= single_release,
79838c8a9a5SSteve French 	.proc_write	= cifs_stats_proc_write,
79938c8a9a5SSteve French };
80038c8a9a5SSteve French 
80138c8a9a5SSteve French #ifdef CONFIG_CIFS_SMB_DIRECT
80238c8a9a5SSteve French #define PROC_FILE_DEFINE(name) \
80338c8a9a5SSteve French static ssize_t name##_write(struct file *file, const char __user *buffer, \
80438c8a9a5SSteve French 	size_t count, loff_t *ppos) \
80538c8a9a5SSteve French { \
80638c8a9a5SSteve French 	int rc; \
80738c8a9a5SSteve French 	rc = kstrtoint_from_user(buffer, count, 10, &name); \
80838c8a9a5SSteve French 	if (rc) \
80938c8a9a5SSteve French 		return rc; \
81038c8a9a5SSteve French 	return count; \
81138c8a9a5SSteve French } \
81238c8a9a5SSteve French static int name##_proc_show(struct seq_file *m, void *v) \
81338c8a9a5SSteve French { \
81438c8a9a5SSteve French 	seq_printf(m, "%d\n", name); \
81538c8a9a5SSteve French 	return 0; \
81638c8a9a5SSteve French } \
81738c8a9a5SSteve French static int name##_open(struct inode *inode, struct file *file) \
81838c8a9a5SSteve French { \
81938c8a9a5SSteve French 	return single_open(file, name##_proc_show, NULL); \
82038c8a9a5SSteve French } \
82138c8a9a5SSteve French \
82238c8a9a5SSteve French static const struct proc_ops cifs_##name##_proc_fops = { \
82338c8a9a5SSteve French 	.proc_open	= name##_open, \
82438c8a9a5SSteve French 	.proc_read	= seq_read, \
82538c8a9a5SSteve French 	.proc_lseek	= seq_lseek, \
82638c8a9a5SSteve French 	.proc_release	= single_release, \
82738c8a9a5SSteve French 	.proc_write	= name##_write, \
82838c8a9a5SSteve French }
82938c8a9a5SSteve French 
83038c8a9a5SSteve French PROC_FILE_DEFINE(rdma_readwrite_threshold);
83138c8a9a5SSteve French PROC_FILE_DEFINE(smbd_max_frmr_depth);
83238c8a9a5SSteve French PROC_FILE_DEFINE(smbd_keep_alive_interval);
83338c8a9a5SSteve French PROC_FILE_DEFINE(smbd_max_receive_size);
83438c8a9a5SSteve French PROC_FILE_DEFINE(smbd_max_fragmented_recv_size);
83538c8a9a5SSteve French PROC_FILE_DEFINE(smbd_max_send_size);
83638c8a9a5SSteve French PROC_FILE_DEFINE(smbd_send_credit_target);
83738c8a9a5SSteve French PROC_FILE_DEFINE(smbd_receive_credit_max);
83838c8a9a5SSteve French #endif
83938c8a9a5SSteve French 
84038c8a9a5SSteve French static struct proc_dir_entry *proc_fs_cifs;
84138c8a9a5SSteve French static const struct proc_ops cifsFYI_proc_ops;
84238c8a9a5SSteve French static const struct proc_ops cifs_lookup_cache_proc_ops;
84338c8a9a5SSteve French static const struct proc_ops traceSMB_proc_ops;
84438c8a9a5SSteve French static const struct proc_ops cifs_security_flags_proc_ops;
84538c8a9a5SSteve French static const struct proc_ops cifs_linux_ext_proc_ops;
84638c8a9a5SSteve French static const struct proc_ops cifs_mount_params_proc_ops;
84738c8a9a5SSteve French 
84838c8a9a5SSteve French void
cifs_proc_init(void)84938c8a9a5SSteve French cifs_proc_init(void)
85038c8a9a5SSteve French {
85138c8a9a5SSteve French 	proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
85238c8a9a5SSteve French 	if (proc_fs_cifs == NULL)
85338c8a9a5SSteve French 		return;
85438c8a9a5SSteve French 
85538c8a9a5SSteve French 	proc_create_single("DebugData", 0, proc_fs_cifs,
85638c8a9a5SSteve French 			cifs_debug_data_proc_show);
85738c8a9a5SSteve French 
85838c8a9a5SSteve French 	proc_create_single("open_files", 0400, proc_fs_cifs,
85938c8a9a5SSteve French 			cifs_debug_files_proc_show);
86038c8a9a5SSteve French 
86138c8a9a5SSteve French 	proc_create("Stats", 0644, proc_fs_cifs, &cifs_stats_proc_ops);
86238c8a9a5SSteve French 	proc_create("cifsFYI", 0644, proc_fs_cifs, &cifsFYI_proc_ops);
86338c8a9a5SSteve French 	proc_create("traceSMB", 0644, proc_fs_cifs, &traceSMB_proc_ops);
86438c8a9a5SSteve French 	proc_create("LinuxExtensionsEnabled", 0644, proc_fs_cifs,
86538c8a9a5SSteve French 		    &cifs_linux_ext_proc_ops);
86638c8a9a5SSteve French 	proc_create("SecurityFlags", 0644, proc_fs_cifs,
86738c8a9a5SSteve French 		    &cifs_security_flags_proc_ops);
86838c8a9a5SSteve French 	proc_create("LookupCacheEnabled", 0644, proc_fs_cifs,
86938c8a9a5SSteve French 		    &cifs_lookup_cache_proc_ops);
87038c8a9a5SSteve French 
87138c8a9a5SSteve French 	proc_create("mount_params", 0444, proc_fs_cifs, &cifs_mount_params_proc_ops);
87238c8a9a5SSteve French 
87338c8a9a5SSteve French #ifdef CONFIG_CIFS_DFS_UPCALL
87438c8a9a5SSteve French 	proc_create("dfscache", 0644, proc_fs_cifs, &dfscache_proc_ops);
87538c8a9a5SSteve French #endif
87638c8a9a5SSteve French 
87738c8a9a5SSteve French #ifdef CONFIG_CIFS_SMB_DIRECT
87838c8a9a5SSteve French 	proc_create("rdma_readwrite_threshold", 0644, proc_fs_cifs,
87938c8a9a5SSteve French 		&cifs_rdma_readwrite_threshold_proc_fops);
88038c8a9a5SSteve French 	proc_create("smbd_max_frmr_depth", 0644, proc_fs_cifs,
88138c8a9a5SSteve French 		&cifs_smbd_max_frmr_depth_proc_fops);
88238c8a9a5SSteve French 	proc_create("smbd_keep_alive_interval", 0644, proc_fs_cifs,
88338c8a9a5SSteve French 		&cifs_smbd_keep_alive_interval_proc_fops);
88438c8a9a5SSteve French 	proc_create("smbd_max_receive_size", 0644, proc_fs_cifs,
88538c8a9a5SSteve French 		&cifs_smbd_max_receive_size_proc_fops);
88638c8a9a5SSteve French 	proc_create("smbd_max_fragmented_recv_size", 0644, proc_fs_cifs,
88738c8a9a5SSteve French 		&cifs_smbd_max_fragmented_recv_size_proc_fops);
88838c8a9a5SSteve French 	proc_create("smbd_max_send_size", 0644, proc_fs_cifs,
88938c8a9a5SSteve French 		&cifs_smbd_max_send_size_proc_fops);
89038c8a9a5SSteve French 	proc_create("smbd_send_credit_target", 0644, proc_fs_cifs,
89138c8a9a5SSteve French 		&cifs_smbd_send_credit_target_proc_fops);
89238c8a9a5SSteve French 	proc_create("smbd_receive_credit_max", 0644, proc_fs_cifs,
89338c8a9a5SSteve French 		&cifs_smbd_receive_credit_max_proc_fops);
89438c8a9a5SSteve French #endif
89538c8a9a5SSteve French }
89638c8a9a5SSteve French 
89738c8a9a5SSteve French void
cifs_proc_clean(void)89838c8a9a5SSteve French cifs_proc_clean(void)
89938c8a9a5SSteve French {
90038c8a9a5SSteve French 	if (proc_fs_cifs == NULL)
90138c8a9a5SSteve French 		return;
90238c8a9a5SSteve French 
90338c8a9a5SSteve French 	remove_proc_entry("DebugData", proc_fs_cifs);
90438c8a9a5SSteve French 	remove_proc_entry("open_files", proc_fs_cifs);
90538c8a9a5SSteve French 	remove_proc_entry("cifsFYI", proc_fs_cifs);
90638c8a9a5SSteve French 	remove_proc_entry("traceSMB", proc_fs_cifs);
90738c8a9a5SSteve French 	remove_proc_entry("Stats", proc_fs_cifs);
90838c8a9a5SSteve French 	remove_proc_entry("SecurityFlags", proc_fs_cifs);
90938c8a9a5SSteve French 	remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
91038c8a9a5SSteve French 	remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
91138c8a9a5SSteve French 	remove_proc_entry("mount_params", proc_fs_cifs);
91238c8a9a5SSteve French 
91338c8a9a5SSteve French #ifdef CONFIG_CIFS_DFS_UPCALL
91438c8a9a5SSteve French 	remove_proc_entry("dfscache", proc_fs_cifs);
91538c8a9a5SSteve French #endif
91638c8a9a5SSteve French #ifdef CONFIG_CIFS_SMB_DIRECT
91738c8a9a5SSteve French 	remove_proc_entry("rdma_readwrite_threshold", proc_fs_cifs);
91838c8a9a5SSteve French 	remove_proc_entry("smbd_max_frmr_depth", proc_fs_cifs);
91938c8a9a5SSteve French 	remove_proc_entry("smbd_keep_alive_interval", proc_fs_cifs);
92038c8a9a5SSteve French 	remove_proc_entry("smbd_max_receive_size", proc_fs_cifs);
92138c8a9a5SSteve French 	remove_proc_entry("smbd_max_fragmented_recv_size", proc_fs_cifs);
92238c8a9a5SSteve French 	remove_proc_entry("smbd_max_send_size", proc_fs_cifs);
92338c8a9a5SSteve French 	remove_proc_entry("smbd_send_credit_target", proc_fs_cifs);
92438c8a9a5SSteve French 	remove_proc_entry("smbd_receive_credit_max", proc_fs_cifs);
92538c8a9a5SSteve French #endif
92638c8a9a5SSteve French 	remove_proc_entry("fs/cifs", NULL);
92738c8a9a5SSteve French }
92838c8a9a5SSteve French 
cifsFYI_proc_show(struct seq_file * m,void * v)92938c8a9a5SSteve French static int cifsFYI_proc_show(struct seq_file *m, void *v)
93038c8a9a5SSteve French {
93138c8a9a5SSteve French 	seq_printf(m, "%d\n", cifsFYI);
93238c8a9a5SSteve French 	return 0;
93338c8a9a5SSteve French }
93438c8a9a5SSteve French 
cifsFYI_proc_open(struct inode * inode,struct file * file)93538c8a9a5SSteve French static int cifsFYI_proc_open(struct inode *inode, struct file *file)
93638c8a9a5SSteve French {
93738c8a9a5SSteve French 	return single_open(file, cifsFYI_proc_show, NULL);
93838c8a9a5SSteve French }
93938c8a9a5SSteve French 
cifsFYI_proc_write(struct file * file,const char __user * buffer,size_t count,loff_t * ppos)94038c8a9a5SSteve French static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
94138c8a9a5SSteve French 		size_t count, loff_t *ppos)
94238c8a9a5SSteve French {
94338c8a9a5SSteve French 	char c[2] = { '\0' };
94438c8a9a5SSteve French 	bool bv;
94538c8a9a5SSteve French 	int rc;
94638c8a9a5SSteve French 
94738c8a9a5SSteve French 	rc = get_user(c[0], buffer);
94838c8a9a5SSteve French 	if (rc)
94938c8a9a5SSteve French 		return rc;
95038c8a9a5SSteve French 	if (kstrtobool(c, &bv) == 0)
95138c8a9a5SSteve French 		cifsFYI = bv;
95238c8a9a5SSteve French 	else if ((c[0] > '1') && (c[0] <= '9'))
95338c8a9a5SSteve French 		cifsFYI = (int) (c[0] - '0'); /* see cifs_debug.h for meanings */
95438c8a9a5SSteve French 	else
95538c8a9a5SSteve French 		return -EINVAL;
95638c8a9a5SSteve French 
95738c8a9a5SSteve French 	return count;
95838c8a9a5SSteve French }
95938c8a9a5SSteve French 
96038c8a9a5SSteve French static const struct proc_ops cifsFYI_proc_ops = {
96138c8a9a5SSteve French 	.proc_open	= cifsFYI_proc_open,
96238c8a9a5SSteve French 	.proc_read	= seq_read,
96338c8a9a5SSteve French 	.proc_lseek	= seq_lseek,
96438c8a9a5SSteve French 	.proc_release	= single_release,
96538c8a9a5SSteve French 	.proc_write	= cifsFYI_proc_write,
96638c8a9a5SSteve French };
96738c8a9a5SSteve French 
cifs_linux_ext_proc_show(struct seq_file * m,void * v)96838c8a9a5SSteve French static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
96938c8a9a5SSteve French {
97038c8a9a5SSteve French 	seq_printf(m, "%d\n", linuxExtEnabled);
97138c8a9a5SSteve French 	return 0;
97238c8a9a5SSteve French }
97338c8a9a5SSteve French 
cifs_linux_ext_proc_open(struct inode * inode,struct file * file)97438c8a9a5SSteve French static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
97538c8a9a5SSteve French {
97638c8a9a5SSteve French 	return single_open(file, cifs_linux_ext_proc_show, NULL);
97738c8a9a5SSteve French }
97838c8a9a5SSteve French 
cifs_linux_ext_proc_write(struct file * file,const char __user * buffer,size_t count,loff_t * ppos)97938c8a9a5SSteve French static ssize_t cifs_linux_ext_proc_write(struct file *file,
98038c8a9a5SSteve French 		const char __user *buffer, size_t count, loff_t *ppos)
98138c8a9a5SSteve French {
98238c8a9a5SSteve French 	int rc;
98338c8a9a5SSteve French 
98438c8a9a5SSteve French 	rc = kstrtobool_from_user(buffer, count, &linuxExtEnabled);
98538c8a9a5SSteve French 	if (rc)
98638c8a9a5SSteve French 		return rc;
98738c8a9a5SSteve French 
98838c8a9a5SSteve French 	return count;
98938c8a9a5SSteve French }
99038c8a9a5SSteve French 
99138c8a9a5SSteve French static const struct proc_ops cifs_linux_ext_proc_ops = {
99238c8a9a5SSteve French 	.proc_open	= cifs_linux_ext_proc_open,
99338c8a9a5SSteve French 	.proc_read	= seq_read,
99438c8a9a5SSteve French 	.proc_lseek	= seq_lseek,
99538c8a9a5SSteve French 	.proc_release	= single_release,
99638c8a9a5SSteve French 	.proc_write	= cifs_linux_ext_proc_write,
99738c8a9a5SSteve French };
99838c8a9a5SSteve French 
cifs_lookup_cache_proc_show(struct seq_file * m,void * v)99938c8a9a5SSteve French static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
100038c8a9a5SSteve French {
100138c8a9a5SSteve French 	seq_printf(m, "%d\n", lookupCacheEnabled);
100238c8a9a5SSteve French 	return 0;
100338c8a9a5SSteve French }
100438c8a9a5SSteve French 
cifs_lookup_cache_proc_open(struct inode * inode,struct file * file)100538c8a9a5SSteve French static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
100638c8a9a5SSteve French {
100738c8a9a5SSteve French 	return single_open(file, cifs_lookup_cache_proc_show, NULL);
100838c8a9a5SSteve French }
100938c8a9a5SSteve French 
cifs_lookup_cache_proc_write(struct file * file,const char __user * buffer,size_t count,loff_t * ppos)101038c8a9a5SSteve French static ssize_t cifs_lookup_cache_proc_write(struct file *file,
101138c8a9a5SSteve French 		const char __user *buffer, size_t count, loff_t *ppos)
101238c8a9a5SSteve French {
101338c8a9a5SSteve French 	int rc;
101438c8a9a5SSteve French 
101538c8a9a5SSteve French 	rc = kstrtobool_from_user(buffer, count, &lookupCacheEnabled);
101638c8a9a5SSteve French 	if (rc)
101738c8a9a5SSteve French 		return rc;
101838c8a9a5SSteve French 
101938c8a9a5SSteve French 	return count;
102038c8a9a5SSteve French }
102138c8a9a5SSteve French 
102238c8a9a5SSteve French static const struct proc_ops cifs_lookup_cache_proc_ops = {
102338c8a9a5SSteve French 	.proc_open	= cifs_lookup_cache_proc_open,
102438c8a9a5SSteve French 	.proc_read	= seq_read,
102538c8a9a5SSteve French 	.proc_lseek	= seq_lseek,
102638c8a9a5SSteve French 	.proc_release	= single_release,
102738c8a9a5SSteve French 	.proc_write	= cifs_lookup_cache_proc_write,
102838c8a9a5SSteve French };
102938c8a9a5SSteve French 
traceSMB_proc_show(struct seq_file * m,void * v)103038c8a9a5SSteve French static int traceSMB_proc_show(struct seq_file *m, void *v)
103138c8a9a5SSteve French {
103238c8a9a5SSteve French 	seq_printf(m, "%d\n", traceSMB);
103338c8a9a5SSteve French 	return 0;
103438c8a9a5SSteve French }
103538c8a9a5SSteve French 
traceSMB_proc_open(struct inode * inode,struct file * file)103638c8a9a5SSteve French static int traceSMB_proc_open(struct inode *inode, struct file *file)
103738c8a9a5SSteve French {
103838c8a9a5SSteve French 	return single_open(file, traceSMB_proc_show, NULL);
103938c8a9a5SSteve French }
104038c8a9a5SSteve French 
traceSMB_proc_write(struct file * file,const char __user * buffer,size_t count,loff_t * ppos)104138c8a9a5SSteve French static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
104238c8a9a5SSteve French 		size_t count, loff_t *ppos)
104338c8a9a5SSteve French {
104438c8a9a5SSteve French 	int rc;
104538c8a9a5SSteve French 
104638c8a9a5SSteve French 	rc = kstrtobool_from_user(buffer, count, &traceSMB);
104738c8a9a5SSteve French 	if (rc)
104838c8a9a5SSteve French 		return rc;
104938c8a9a5SSteve French 
105038c8a9a5SSteve French 	return count;
105138c8a9a5SSteve French }
105238c8a9a5SSteve French 
105338c8a9a5SSteve French static const struct proc_ops traceSMB_proc_ops = {
105438c8a9a5SSteve French 	.proc_open	= traceSMB_proc_open,
105538c8a9a5SSteve French 	.proc_read	= seq_read,
105638c8a9a5SSteve French 	.proc_lseek	= seq_lseek,
105738c8a9a5SSteve French 	.proc_release	= single_release,
105838c8a9a5SSteve French 	.proc_write	= traceSMB_proc_write,
105938c8a9a5SSteve French };
106038c8a9a5SSteve French 
cifs_security_flags_proc_show(struct seq_file * m,void * v)106138c8a9a5SSteve French static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
106238c8a9a5SSteve French {
106338c8a9a5SSteve French 	seq_printf(m, "0x%x\n", global_secflags);
106438c8a9a5SSteve French 	return 0;
106538c8a9a5SSteve French }
106638c8a9a5SSteve French 
cifs_security_flags_proc_open(struct inode * inode,struct file * file)106738c8a9a5SSteve French static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
106838c8a9a5SSteve French {
106938c8a9a5SSteve French 	return single_open(file, cifs_security_flags_proc_show, NULL);
107038c8a9a5SSteve French }
107138c8a9a5SSteve French 
107238c8a9a5SSteve French /*
107338c8a9a5SSteve French  * Ensure that if someone sets a MUST flag, that we disable all other MAY
107438c8a9a5SSteve French  * flags except for the ones corresponding to the given MUST flag. If there are
1075*1b5487aeSSteve French  * multiple MUST flags, then try to prefer more secure ones.
107638c8a9a5SSteve French  */
107738c8a9a5SSteve French static void
cifs_security_flags_handle_must_flags(unsigned int * flags)107838c8a9a5SSteve French cifs_security_flags_handle_must_flags(unsigned int *flags)
107938c8a9a5SSteve French {
108038c8a9a5SSteve French 	unsigned int signflags = *flags & (CIFSSEC_MUST_SIGN | CIFSSEC_MUST_SEAL);
108138c8a9a5SSteve French 
108238c8a9a5SSteve French 	if ((*flags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5)
108338c8a9a5SSteve French 		*flags = CIFSSEC_MUST_KRB5;
108438c8a9a5SSteve French 	else if ((*flags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP)
108538c8a9a5SSteve French 		*flags = CIFSSEC_MUST_NTLMSSP;
108638c8a9a5SSteve French 	else if ((*flags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2)
108738c8a9a5SSteve French 		*flags = CIFSSEC_MUST_NTLMV2;
108838c8a9a5SSteve French 
108938c8a9a5SSteve French 	*flags |= signflags;
109038c8a9a5SSteve French }
109138c8a9a5SSteve French 
cifs_security_flags_proc_write(struct file * file,const char __user * buffer,size_t count,loff_t * ppos)109238c8a9a5SSteve French static ssize_t cifs_security_flags_proc_write(struct file *file,
109338c8a9a5SSteve French 		const char __user *buffer, size_t count, loff_t *ppos)
109438c8a9a5SSteve French {
109538c8a9a5SSteve French 	int rc;
109638c8a9a5SSteve French 	unsigned int flags;
109738c8a9a5SSteve French 	char flags_string[12];
109838c8a9a5SSteve French 	bool bv;
109938c8a9a5SSteve French 
110038c8a9a5SSteve French 	if ((count < 1) || (count > 11))
110138c8a9a5SSteve French 		return -EINVAL;
110238c8a9a5SSteve French 
110338c8a9a5SSteve French 	memset(flags_string, 0, 12);
110438c8a9a5SSteve French 
110538c8a9a5SSteve French 	if (copy_from_user(flags_string, buffer, count))
110638c8a9a5SSteve French 		return -EFAULT;
110738c8a9a5SSteve French 
110838c8a9a5SSteve French 	if (count < 3) {
110938c8a9a5SSteve French 		/* single char or single char followed by null */
111038c8a9a5SSteve French 		if (kstrtobool(flags_string, &bv) == 0) {
111138c8a9a5SSteve French 			global_secflags = bv ? CIFSSEC_MAX : CIFSSEC_DEF;
111238c8a9a5SSteve French 			return count;
111338c8a9a5SSteve French 		} else if (!isdigit(flags_string[0])) {
111438c8a9a5SSteve French 			cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
111538c8a9a5SSteve French 					flags_string);
111638c8a9a5SSteve French 			return -EINVAL;
111738c8a9a5SSteve French 		}
111838c8a9a5SSteve French 	}
111938c8a9a5SSteve French 
112038c8a9a5SSteve French 	/* else we have a number */
112138c8a9a5SSteve French 	rc = kstrtouint(flags_string, 0, &flags);
112238c8a9a5SSteve French 	if (rc) {
112338c8a9a5SSteve French 		cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
112438c8a9a5SSteve French 				flags_string);
112538c8a9a5SSteve French 		return rc;
112638c8a9a5SSteve French 	}
112738c8a9a5SSteve French 
112838c8a9a5SSteve French 	cifs_dbg(FYI, "sec flags 0x%x\n", flags);
112938c8a9a5SSteve French 
113038c8a9a5SSteve French 	if (flags == 0)  {
113138c8a9a5SSteve French 		cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", flags_string);
113238c8a9a5SSteve French 		return -EINVAL;
113338c8a9a5SSteve French 	}
113438c8a9a5SSteve French 
113538c8a9a5SSteve French 	if (flags & ~CIFSSEC_MASK) {
113638c8a9a5SSteve French 		cifs_dbg(VFS, "Unsupported security flags: 0x%x\n",
113738c8a9a5SSteve French 			 flags & ~CIFSSEC_MASK);
113838c8a9a5SSteve French 		return -EINVAL;
113938c8a9a5SSteve French 	}
114038c8a9a5SSteve French 
114138c8a9a5SSteve French 	cifs_security_flags_handle_must_flags(&flags);
114238c8a9a5SSteve French 
114338c8a9a5SSteve French 	/* flags look ok - update the global security flags for cifs module */
114438c8a9a5SSteve French 	global_secflags = flags;
114538c8a9a5SSteve French 	if (global_secflags & CIFSSEC_MUST_SIGN) {
114638c8a9a5SSteve French 		/* requiring signing implies signing is allowed */
114738c8a9a5SSteve French 		global_secflags |= CIFSSEC_MAY_SIGN;
114838c8a9a5SSteve French 		cifs_dbg(FYI, "packet signing now required\n");
114938c8a9a5SSteve French 	} else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) {
115038c8a9a5SSteve French 		cifs_dbg(FYI, "packet signing disabled\n");
115138c8a9a5SSteve French 	}
115238c8a9a5SSteve French 	/* BB should we turn on MAY flags for other MUST options? */
115338c8a9a5SSteve French 	return count;
115438c8a9a5SSteve French }
115538c8a9a5SSteve French 
115638c8a9a5SSteve French static const struct proc_ops cifs_security_flags_proc_ops = {
115738c8a9a5SSteve French 	.proc_open	= cifs_security_flags_proc_open,
115838c8a9a5SSteve French 	.proc_read	= seq_read,
115938c8a9a5SSteve French 	.proc_lseek	= seq_lseek,
116038c8a9a5SSteve French 	.proc_release	= single_release,
116138c8a9a5SSteve French 	.proc_write	= cifs_security_flags_proc_write,
116238c8a9a5SSteve French };
116338c8a9a5SSteve French 
116438c8a9a5SSteve French /* To make it easier to debug, can help to show mount params */
cifs_mount_params_proc_show(struct seq_file * m,void * v)116538c8a9a5SSteve French static int cifs_mount_params_proc_show(struct seq_file *m, void *v)
116638c8a9a5SSteve French {
116738c8a9a5SSteve French 	const struct fs_parameter_spec *p;
116838c8a9a5SSteve French 	const char *type;
116938c8a9a5SSteve French 
117038c8a9a5SSteve French 	for (p = smb3_fs_parameters; p->name; p++) {
117138c8a9a5SSteve French 		/* cannot use switch with pointers... */
117238c8a9a5SSteve French 		if (!p->type) {
117338c8a9a5SSteve French 			if (p->flags == fs_param_neg_with_no)
117438c8a9a5SSteve French 				type = "noflag";
117538c8a9a5SSteve French 			else
117638c8a9a5SSteve French 				type = "flag";
117738c8a9a5SSteve French 		} else if (p->type == fs_param_is_bool)
117838c8a9a5SSteve French 			type = "bool";
117938c8a9a5SSteve French 		else if (p->type == fs_param_is_u32)
118038c8a9a5SSteve French 			type = "u32";
118138c8a9a5SSteve French 		else if (p->type == fs_param_is_u64)
118238c8a9a5SSteve French 			type = "u64";
118338c8a9a5SSteve French 		else if (p->type == fs_param_is_string)
118438c8a9a5SSteve French 			type = "string";
118538c8a9a5SSteve French 		else
118638c8a9a5SSteve French 			type = "unknown";
118738c8a9a5SSteve French 
118838c8a9a5SSteve French 		seq_printf(m, "%s:%s\n", p->name, type);
118938c8a9a5SSteve French 	}
119038c8a9a5SSteve French 
119138c8a9a5SSteve French 	return 0;
119238c8a9a5SSteve French }
119338c8a9a5SSteve French 
cifs_mount_params_proc_open(struct inode * inode,struct file * file)119438c8a9a5SSteve French static int cifs_mount_params_proc_open(struct inode *inode, struct file *file)
119538c8a9a5SSteve French {
119638c8a9a5SSteve French 	return single_open(file, cifs_mount_params_proc_show, NULL);
119738c8a9a5SSteve French }
119838c8a9a5SSteve French 
119938c8a9a5SSteve French static const struct proc_ops cifs_mount_params_proc_ops = {
120038c8a9a5SSteve French 	.proc_open	= cifs_mount_params_proc_open,
120138c8a9a5SSteve French 	.proc_read	= seq_read,
120238c8a9a5SSteve French 	.proc_lseek	= seq_lseek,
120338c8a9a5SSteve French 	.proc_release	= single_release,
120438c8a9a5SSteve French 	/* No need for write for now */
120538c8a9a5SSteve French 	/* .proc_write	= cifs_mount_params_proc_write, */
120638c8a9a5SSteve French };
120738c8a9a5SSteve French 
120838c8a9a5SSteve French #else
cifs_proc_init(void)120938c8a9a5SSteve French inline void cifs_proc_init(void)
121038c8a9a5SSteve French {
121138c8a9a5SSteve French }
1212 
cifs_proc_clean(void)1213 inline void cifs_proc_clean(void)
1214 {
1215 }
1216 #endif /* PROC_FS */
1217