blob: a38d796f5ffeee838d912fd3201a0fa83d424d2c [file] [log] [blame]
Thomas Gleixner1a59d1b82019-05-27 08:55:05 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * fs/cifs_debug.c
4 *
Steve Frenchb8643e12005-04-28 22:41:07 -07005 * Copyright (C) International Business Machines Corp., 2000,2005
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
7 * Modified by Steve French (sfrench@us.ibm.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 */
9#include <linux/fs.h>
10#include <linux/string.h>
11#include <linux/ctype.h>
12#include <linux/module.h>
13#include <linux/proc_fs.h>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080014#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include "cifspdu.h"
16#include "cifsglob.h"
17#include "cifsproto.h"
18#include "cifs_debug.h"
Steve French6c91d362005-04-28 22:41:06 -070019#include "cifsfs.h"
Paulo Alcantara54be1f62018-11-14 16:01:21 -020020#ifdef CONFIG_CIFS_DFS_UPCALL
21#include "dfs_cache.h"
22#endif
Long Lid8ec9132017-11-07 01:54:58 -070023#ifdef CONFIG_CIFS_SMB_DIRECT
24#include "smbdirect.h"
25#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27void
28cifs_dump_mem(char *label, void *data, int length)
29{
Andy Shevchenko0b456f02014-08-27 16:49:44 +030030 pr_debug("%s: dump of %d bytes of data at 0x%p\n", label, length, data);
Andy Shevchenko55d83e02014-08-27 16:49:43 +030031 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 4,
32 data, length, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -070033}
34
Ronnie Sahlberg14547f72018-04-22 14:45:53 -060035void cifs_dump_detail(void *buf, struct TCP_Server_Info *server)
Steve French39798772006-05-31 22:40:51 +000036{
Pavel Shilovsky8aa26f32012-05-17 13:25:35 +040037#ifdef CONFIG_CIFS_DEBUG2
Pavel Shilovskyd4e48542012-03-23 14:28:02 -040038 struct smb_hdr *smb = (struct smb_hdr *)buf;
39
Joe Perchesf96637b2013-05-04 22:12:25 -050040 cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d\n",
41 smb->Command, smb->Status.CifsError,
42 smb->Flags, smb->Flags2, smb->Mid, smb->Pid);
Ronnie Sahlberg14547f72018-04-22 14:45:53 -060043 cifs_dbg(VFS, "smb buf %p len %u\n", smb,
Steve French71992e622018-05-06 15:58:51 -050044 server->ops->calc_smb_size(smb, server));
Pavel Shilovsky8aa26f32012-05-17 13:25:35 +040045#endif /* CONFIG_CIFS_DEBUG2 */
Steve French39798772006-05-31 22:40:51 +000046}
47
Steve Frenchffdd6e42007-06-24 21:15:44 +000048void cifs_dump_mids(struct TCP_Server_Info *server)
Steve French39798772006-05-31 22:40:51 +000049{
Pavel Shilovsky8aa26f32012-05-17 13:25:35 +040050#ifdef CONFIG_CIFS_DEBUG2
Steve French39798772006-05-31 22:40:51 +000051 struct list_head *tmp;
Steve Frenchffdd6e42007-06-24 21:15:44 +000052 struct mid_q_entry *mid_entry;
Steve French39798772006-05-31 22:40:51 +000053
Steve French221601c2007-06-05 20:35:06 +000054 if (server == NULL)
Steve French39798772006-05-31 22:40:51 +000055 return;
56
Joe Perchesf96637b2013-05-04 22:12:25 -050057 cifs_dbg(VFS, "Dump pending requests:\n");
Steve French39798772006-05-31 22:40:51 +000058 spin_lock(&GlobalMid_Lock);
59 list_for_each(tmp, &server->pending_mid_q) {
60 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
Joe Perchesf96637b2013-05-04 22:12:25 -050061 cifs_dbg(VFS, "State: %d Cmd: %d Pid: %d Cbdata: %p Mid %llu\n",
62 mid_entry->mid_state,
63 le16_to_cpu(mid_entry->command),
64 mid_entry->pid,
65 mid_entry->callback_data,
66 mid_entry->mid);
Steve French39798772006-05-31 22:40:51 +000067#ifdef CONFIG_CIFS_STATS2
Joe Perchesf96637b2013-05-04 22:12:25 -050068 cifs_dbg(VFS, "IsLarge: %d buf: %p time rcv: %ld now: %ld\n",
69 mid_entry->large_buf,
70 mid_entry->resp_buf,
71 mid_entry->when_received,
72 jiffies);
Steve French39798772006-05-31 22:40:51 +000073#endif /* STATS2 */
Joe Perchesf96637b2013-05-04 22:12:25 -050074 cifs_dbg(VFS, "IsMult: %d IsEnd: %d\n",
75 mid_entry->multiRsp, mid_entry->multiEnd);
Steve Frenchad8b15f2008-08-08 21:10:16 +000076 if (mid_entry->resp_buf) {
Steve French71992e622018-05-06 15:58:51 -050077 cifs_dump_detail(mid_entry->resp_buf, server);
Steve Frenchad8b15f2008-08-08 21:10:16 +000078 cifs_dump_mem("existing buf: ",
79 mid_entry->resp_buf, 62);
Steve French39798772006-05-31 22:40:51 +000080 }
81 }
82 spin_unlock(&GlobalMid_Lock);
Steve French39798772006-05-31 22:40:51 +000083#endif /* CONFIG_CIFS_DEBUG2 */
Pavel Shilovsky8aa26f32012-05-17 13:25:35 +040084}
Steve French39798772006-05-31 22:40:51 +000085
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#ifdef CONFIG_PROC_FS
Aurelien Aptel02cf5902018-01-24 13:46:12 +010087static void cifs_debug_tcon(struct seq_file *m, struct cifs_tcon *tcon)
88{
89 __u32 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
90
91 seq_printf(m, "%s Mounts: %d ", tcon->treeName, tcon->tc_count);
92 if (tcon->nativeFileSystem)
93 seq_printf(m, "Type: %s ", tcon->nativeFileSystem);
94 seq_printf(m, "DevInfo: 0x%x Attributes: 0x%x\n\tPathComponentMax: %d Status: %d",
95 le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
96 le32_to_cpu(tcon->fsAttrInfo.Attributes),
97 le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
98 tcon->tidStatus);
99 if (dev_type == FILE_DEVICE_DISK)
100 seq_puts(m, " type: DISK ");
101 else if (dev_type == FILE_DEVICE_CD_ROM)
102 seq_puts(m, " type: CDROM ");
103 else
104 seq_printf(m, " type: %d ", dev_type);
Steve Frenchab7b10c2019-03-12 01:29:03 -0500105
106 seq_printf(m, "Serial Number: 0x%x", tcon->vol_serial_number);
107
Steve Frenchffd1ef12019-03-09 18:12:18 -0600108 if ((tcon->seal) ||
109 (tcon->ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA) ||
110 (tcon->share_flags & SHI1005_FLAGS_ENCRYPT_DATA))
Steve Frenchede2e522018-01-31 14:34:37 -0600111 seq_printf(m, " Encrypted");
Steve French5c5a41b2018-05-30 17:11:55 -0500112 if (tcon->nocase)
113 seq_printf(m, " nocase");
Steve Frenchede2e522018-01-31 14:34:37 -0600114 if (tcon->unix_ext)
115 seq_printf(m, " POSIX Extensions");
Aurelien Aptel02cf5902018-01-24 13:46:12 +0100116 if (tcon->ses->server->ops->dump_share_caps)
117 tcon->ses->server->ops->dump_share_caps(m, tcon);
118
119 if (tcon->need_reconnect)
120 seq_puts(m, "\tDISCONNECTED ");
121 seq_putc(m, '\n');
122}
123
Aurelien Aptelbc0fe8b2018-06-14 15:43:20 +0200124static void
125cifs_dump_iface(struct seq_file *m, struct cifs_server_iface *iface)
126{
127 struct sockaddr_in *ipv4 = (struct sockaddr_in *)&iface->sockaddr;
128 struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)&iface->sockaddr;
129
Steve French35a90802018-10-19 21:21:37 -0500130 seq_printf(m, "\tSpeed: %zu bps\n", iface->speed);
Aurelien Aptelbc0fe8b2018-06-14 15:43:20 +0200131 seq_puts(m, "\t\tCapabilities: ");
132 if (iface->rdma_capable)
133 seq_puts(m, "rdma ");
134 if (iface->rss_capable)
135 seq_puts(m, "rss ");
136 seq_putc(m, '\n');
137 if (iface->sockaddr.ss_family == AF_INET)
138 seq_printf(m, "\t\tIPv4: %pI4\n", &ipv4->sin_addr);
139 else if (iface->sockaddr.ss_family == AF_INET6)
140 seq_printf(m, "\t\tIPv6: %pI6\n", &ipv6->sin6_addr);
141}
142
Steve Frenchdfe33f92018-10-30 19:50:31 -0500143static int cifs_debug_files_proc_show(struct seq_file *m, void *v)
144{
145 struct list_head *stmp, *tmp, *tmp1, *tmp2;
146 struct TCP_Server_Info *server;
147 struct cifs_ses *ses;
148 struct cifs_tcon *tcon;
149 struct cifsFileInfo *cfile;
150
151 seq_puts(m, "# Version:1\n");
152 seq_puts(m, "# Format:\n");
153 seq_puts(m, "# <tree id> <persistent fid> <flags> <count> <pid> <uid>");
154#ifdef CONFIG_CIFS_DEBUG2
155 seq_printf(m, " <filename> <mid>\n");
156#else
157 seq_printf(m, " <filename>\n");
158#endif /* CIFS_DEBUG2 */
159 spin_lock(&cifs_tcp_ses_lock);
160 list_for_each(stmp, &cifs_tcp_ses_list) {
161 server = list_entry(stmp, struct TCP_Server_Info,
162 tcp_ses_list);
163 list_for_each(tmp, &server->smb_ses_list) {
164 ses = list_entry(tmp, struct cifs_ses, smb_ses_list);
165 list_for_each(tmp1, &ses->tcon_list) {
166 tcon = list_entry(tmp1, struct cifs_tcon, tcon_list);
167 spin_lock(&tcon->open_file_lock);
168 list_for_each(tmp2, &tcon->openFileList) {
169 cfile = list_entry(tmp2, struct cifsFileInfo,
170 tlist);
171 seq_printf(m,
172 "0x%x 0x%llx 0x%x %d %d %d %s",
173 tcon->tid,
174 cfile->fid.persistent_fid,
175 cfile->f_flags,
176 cfile->count,
177 cfile->pid,
178 from_kuid(&init_user_ns, cfile->uid),
179 cfile->dentry->d_name.name);
180#ifdef CONFIG_CIFS_DEBUG2
181 seq_printf(m, " 0x%llx\n", cfile->fid.mid);
182#else
183 seq_printf(m, "\n");
184#endif /* CIFS_DEBUG2 */
185 }
186 spin_unlock(&tcon->open_file_lock);
187 }
188 }
189 }
190 spin_unlock(&cifs_tcp_ses_lock);
191 seq_putc(m, '\n');
192 return 0;
193}
194
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000195static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196{
Jeff Laytonf1987b42008-11-15 11:12:47 -0500197 struct list_head *tmp1, *tmp2, *tmp3;
Steve Frenchffdd6e42007-06-24 21:15:44 +0000198 struct mid_q_entry *mid_entry;
Jeff Layton14fbf502008-11-14 13:53:46 -0500199 struct TCP_Server_Info *server;
Steve French96daf2b2011-05-27 04:34:02 +0000200 struct cifs_ses *ses;
201 struct cifs_tcon *tcon;
Jeff Laytonf1987b42008-11-15 11:12:47 -0500202 int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000204 seq_puts(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 "Display Internal CIFS Data Structures for Debugging\n"
206 "---------------------------------------------------\n");
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000207 seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
Jeff Laytonca40b712011-01-07 11:30:29 -0500208 seq_printf(m, "Features:");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530209#ifdef CONFIG_CIFS_DFS_UPCALL
Steve French950132a2018-06-28 18:46:40 -0500210 seq_printf(m, " DFS");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530211#endif
212#ifdef CONFIG_CIFS_FSCACHE
Steve French950132a2018-06-28 18:46:40 -0500213 seq_printf(m, ",FSCACHE");
214#endif
215#ifdef CONFIG_CIFS_SMB_DIRECT
216 seq_printf(m, ",SMB_DIRECT");
217#endif
218#ifdef CONFIG_CIFS_STATS2
219 seq_printf(m, ",STATS2");
Steve Frenchd2586502018-08-01 22:34:04 -0500220#else
Steve French950132a2018-06-28 18:46:40 -0500221 seq_printf(m, ",STATS");
222#endif
223#ifdef CONFIG_CIFS_DEBUG2
224 seq_printf(m, ",DEBUG2");
225#elif defined(CONFIG_CIFS_DEBUG)
226 seq_printf(m, ",DEBUG");
227#endif
228#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
229 seq_printf(m, ",ALLOW_INSECURE_LEGACY");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530230#endif
231#ifdef CONFIG_CIFS_WEAK_PW_HASH
Steve French950132a2018-06-28 18:46:40 -0500232 seq_printf(m, ",WEAK_PW_HASH");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530233#endif
234#ifdef CONFIG_CIFS_POSIX
Steve French950132a2018-06-28 18:46:40 -0500235 seq_printf(m, ",CIFS_POSIX");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530236#endif
237#ifdef CONFIG_CIFS_UPCALL
Steve French950132a2018-06-28 18:46:40 -0500238 seq_printf(m, ",UPCALL(SPNEGO)");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530239#endif
240#ifdef CONFIG_CIFS_XATTR
Steve French950132a2018-06-28 18:46:40 -0500241 seq_printf(m, ",XATTR");
Jeff Laytonca40b712011-01-07 11:30:29 -0500242#endif
Steve French950132a2018-06-28 18:46:40 -0500243 seq_printf(m, ",ACL");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530244 seq_putc(m, '\n');
Ronnie Sahlberga5f1a812019-01-24 16:19:31 +1000245 seq_printf(m, "CIFSMaxBufSize: %d\n", CIFSMaxBufSize);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000246 seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
247 seq_printf(m, "Servers:");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
249 i = 0;
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530250 spin_lock(&cifs_tcp_ses_lock);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500251 list_for_each(tmp1, &cifs_tcp_ses_list) {
252 server = list_entry(tmp1, struct TCP_Server_Info,
Jeff Layton14fbf502008-11-14 13:53:46 -0500253 tcp_ses_list);
Long Li08a3b962017-11-22 17:38:48 -0700254
255#ifdef CONFIG_CIFS_SMB_DIRECT
256 if (!server->rdma)
257 goto skip_rdma;
258
259 seq_printf(m, "\nSMBDirect (in hex) protocol version: %x "
260 "transport status: %x",
261 server->smbd_conn->protocol,
262 server->smbd_conn->transport_status);
263 seq_printf(m, "\nConn receive_credit_max: %x "
264 "send_credit_target: %x max_send_size: %x",
265 server->smbd_conn->receive_credit_max,
266 server->smbd_conn->send_credit_target,
267 server->smbd_conn->max_send_size);
268 seq_printf(m, "\nConn max_fragmented_recv_size: %x "
269 "max_fragmented_send_size: %x max_receive_size:%x",
270 server->smbd_conn->max_fragmented_recv_size,
271 server->smbd_conn->max_fragmented_send_size,
272 server->smbd_conn->max_receive_size);
273 seq_printf(m, "\nConn keep_alive_interval: %x "
274 "max_readwrite_size: %x rdma_readwrite_threshold: %x",
275 server->smbd_conn->keep_alive_interval,
276 server->smbd_conn->max_readwrite_size,
277 server->smbd_conn->rdma_readwrite_threshold);
278 seq_printf(m, "\nDebug count_get_receive_buffer: %x "
279 "count_put_receive_buffer: %x count_send_empty: %x",
280 server->smbd_conn->count_get_receive_buffer,
281 server->smbd_conn->count_put_receive_buffer,
282 server->smbd_conn->count_send_empty);
283 seq_printf(m, "\nRead Queue count_reassembly_queue: %x "
284 "count_enqueue_reassembly_queue: %x "
285 "count_dequeue_reassembly_queue: %x "
286 "fragment_reassembly_remaining: %x "
287 "reassembly_data_length: %x "
288 "reassembly_queue_length: %x",
289 server->smbd_conn->count_reassembly_queue,
290 server->smbd_conn->count_enqueue_reassembly_queue,
291 server->smbd_conn->count_dequeue_reassembly_queue,
292 server->smbd_conn->fragment_reassembly_remaining,
293 server->smbd_conn->reassembly_data_length,
294 server->smbd_conn->reassembly_queue_length);
295 seq_printf(m, "\nCurrent Credits send_credits: %x "
296 "receive_credits: %x receive_credit_target: %x",
297 atomic_read(&server->smbd_conn->send_credits),
298 atomic_read(&server->smbd_conn->receive_credits),
299 server->smbd_conn->receive_credit_target);
Long Lie8b3bfe2019-04-05 21:36:31 +0000300 seq_printf(m, "\nPending send_pending: %x "
301 "send_payload_pending: %x",
Long Li08a3b962017-11-22 17:38:48 -0700302 atomic_read(&server->smbd_conn->send_pending),
Long Lie8b3bfe2019-04-05 21:36:31 +0000303 atomic_read(&server->smbd_conn->send_payload_pending));
Long Li08a3b962017-11-22 17:38:48 -0700304 seq_printf(m, "\nReceive buffers count_receive_queue: %x "
305 "count_empty_packet_queue: %x",
306 server->smbd_conn->count_receive_queue,
307 server->smbd_conn->count_empty_packet_queue);
308 seq_printf(m, "\nMR responder_resources: %x "
309 "max_frmr_depth: %x mr_type: %x",
310 server->smbd_conn->responder_resources,
311 server->smbd_conn->max_frmr_depth,
312 server->smbd_conn->mr_type);
313 seq_printf(m, "\nMR mr_ready_count: %x mr_used_count: %x",
314 atomic_read(&server->smbd_conn->mr_ready_count),
315 atomic_read(&server->smbd_conn->mr_used_count));
316skip_rdma:
317#endif
Steve Frenchede2e522018-01-31 14:34:37 -0600318 seq_printf(m, "\nNumber of credits: %d Dialect 0x%x",
319 server->credits, server->dialect);
Steve French26ea8882019-04-26 20:36:08 -0700320 if (server->compress_algorithm == SMB3_COMPRESS_LZNT1)
321 seq_printf(m, " COMPRESS_LZNT1");
322 else if (server->compress_algorithm == SMB3_COMPRESS_LZ77)
323 seq_printf(m, " COMPRESS_LZ77");
324 else if (server->compress_algorithm == SMB3_COMPRESS_LZ77_HUFF)
325 seq_printf(m, " COMPRESS_LZ77_HUFF");
Steve Frenchede2e522018-01-31 14:34:37 -0600326 if (server->sign)
327 seq_printf(m, " signed");
Steve Frenchfcef0db2018-05-19 20:45:27 -0500328 if (server->posix_ext_supported)
329 seq_printf(m, " posix");
Steve French0fdfef92018-06-28 19:30:23 -0500330
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 i++;
Jeff Layton14fbf502008-11-14 13:53:46 -0500332 list_for_each(tmp2, &server->smb_ses_list) {
Steve French96daf2b2011-05-27 04:34:02 +0000333 ses = list_entry(tmp2, struct cifs_ses,
Jeff Layton14fbf502008-11-14 13:53:46 -0500334 smb_ses_list);
335 if ((ses->serverDomain == NULL) ||
336 (ses->serverOS == NULL) ||
337 (ses->serverNOS == NULL)) {
Steve French9e1a37d2018-09-19 02:38:17 -0500338 seq_printf(m, "\n%d) Name: %s Uses: %d Capability: 0x%x\tSession Status: %d ",
Steve French1fa089e2017-09-20 16:46:49 -0500339 i, ses->serverName, ses->ses_count,
340 ses->capabilities, ses->status);
341 if (ses->session_flags & SMB2_SESSION_FLAG_IS_GUEST)
342 seq_printf(m, "Guest\t");
343 else if (ses->session_flags & SMB2_SESSION_FLAG_IS_NULL)
344 seq_printf(m, "Anonymous\t");
Jeff Layton14fbf502008-11-14 13:53:46 -0500345 } else {
346 seq_printf(m,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500347 "\n%d) Name: %s Domain: %s Uses: %d OS:"
348 " %s\n\tNOS: %s\tCapability: 0x%x\n\tSMB"
Steve French9e1a37d2018-09-19 02:38:17 -0500349 " session status: %d ",
Steve Frenchb8643e12005-04-28 22:41:07 -0700350 i, ses->serverName, ses->serverDomain,
Jeff Layton14fbf502008-11-14 13:53:46 -0500351 ses->ses_count, ses->serverOS, ses->serverNOS,
Steve French221601c2007-06-05 20:35:06 +0000352 ses->capabilities, ses->status);
Jeff Layton14fbf502008-11-14 13:53:46 -0500353 }
Long Li8339dd32017-11-07 01:54:55 -0700354 if (server->rdma)
355 seq_printf(m, "RDMA\n\t");
Steve French9e1a37d2018-09-19 02:38:17 -0500356 seq_printf(m, "TCP status: %d Instance: %d\n\tLocal Users To "
Jeff Layton14fbf502008-11-14 13:53:46 -0500357 "Server: %d SecMode: 0x%x Req On Wire: %d",
Steve French9e1a37d2018-09-19 02:38:17 -0500358 server->tcpStatus,
359 server->reconnect_instance,
360 server->srv_count,
Pavel Shilovskyfc40f9c2012-02-17 17:09:12 +0300361 server->sec_mode, in_flight(server));
Steve French131afd0b2005-10-07 09:51:05 -0700362
363#ifdef CONFIG_CIFS_STATS2
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000364 seq_printf(m, " In Send: %d In MaxReq Wait: %d",
Steve French789e6662011-08-09 18:44:44 +0000365 atomic_read(&server->in_send),
Jeff Layton14fbf502008-11-14 13:53:46 -0500366 atomic_read(&server->num_waiters));
Steve French131afd0b2005-10-07 09:51:05 -0700367#endif
Steve Frenchb63a9de2019-05-08 22:41:37 -0500368 /* dump session id helpful for use with network trace */
369 seq_printf(m, " SessionId: 0x%llx", ses->Suid);
Steve Frenchffd1ef12019-03-09 18:12:18 -0600370 if (ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA)
371 seq_puts(m, " encrypted");
372 if (ses->sign)
373 seq_puts(m, " signed");
Steve French131afd0b2005-10-07 09:51:05 -0700374
Jeff Laytonf1987b42008-11-15 11:12:47 -0500375 seq_puts(m, "\n\tShares:");
376 j = 0;
Aurelien Aptel02cf5902018-01-24 13:46:12 +0100377
378 seq_printf(m, "\n\t%d) IPC: ", j);
379 if (ses->tcon_ipc)
380 cifs_debug_tcon(m, ses->tcon_ipc);
381 else
382 seq_puts(m, "none\n");
383
Jeff Laytonf1987b42008-11-15 11:12:47 -0500384 list_for_each(tmp3, &ses->tcon_list) {
Steve French96daf2b2011-05-27 04:34:02 +0000385 tcon = list_entry(tmp3, struct cifs_tcon,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500386 tcon_list);
387 ++j;
Aurelien Aptel02cf5902018-01-24 13:46:12 +0100388 seq_printf(m, "\n\t%d) ", j);
389 cifs_debug_tcon(m, tcon);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500390 }
391
392 seq_puts(m, "\n\tMIDs:\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
394 spin_lock(&GlobalMid_Lock);
Jeff Layton14fbf502008-11-14 13:53:46 -0500395 list_for_each(tmp3, &server->pending_mid_q) {
Jeff Laytonf1987b42008-11-15 11:12:47 -0500396 mid_entry = list_entry(tmp3, struct mid_q_entry,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 qhead);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500398 seq_printf(m, "\tState: %d com: %d pid:"
Pavel Shilovsky7c9421e2012-03-23 14:28:03 -0400399 " %d cbdata: %p mid %llu\n",
400 mid_entry->mid_state,
401 le16_to_cpu(mid_entry->command),
402 mid_entry->pid,
403 mid_entry->callback_data,
404 mid_entry->mid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 }
Steve French221601c2007-06-05 20:35:06 +0000406 spin_unlock(&GlobalMid_Lock);
Aurelien Aptelbc0fe8b2018-06-14 15:43:20 +0200407
408 spin_lock(&ses->iface_lock);
Steve French115d5d22018-06-14 21:59:31 -0500409 if (ses->iface_count)
410 seq_printf(m, "\n\tServer interfaces: %zu\n",
411 ses->iface_count);
Aurelien Aptelbc0fe8b2018-06-14 15:43:20 +0200412 for (j = 0; j < ses->iface_count; j++) {
Steve French35a90802018-10-19 21:21:37 -0500413 seq_printf(m, "\t%d)", j);
Aurelien Aptelbc0fe8b2018-06-14 15:43:20 +0200414 cifs_dump_iface(m, &ses->iface_list[j]);
415 }
416 spin_unlock(&ses->iface_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 }
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530419 spin_unlock(&cifs_tcp_ses_lock);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000420 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 /* BB add code to dump additional info such as TCP session info now */
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000423 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424}
425
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000426static ssize_t cifs_stats_proc_write(struct file *file,
427 const char __user *buffer, size_t count, loff_t *ppos)
Steve French1047abc2005-10-11 19:58:06 -0700428{
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300429 bool bv;
Steve French221601c2007-06-05 20:35:06 +0000430 int rc;
Jeff Laytonf1987b42008-11-15 11:12:47 -0500431 struct list_head *tmp1, *tmp2, *tmp3;
432 struct TCP_Server_Info *server;
Steve French96daf2b2011-05-27 04:34:02 +0000433 struct cifs_ses *ses;
434 struct cifs_tcon *tcon;
Steve French1047abc2005-10-11 19:58:06 -0700435
Kees Cook14042972016-03-17 14:22:54 -0700436 rc = kstrtobool_from_user(buffer, count, &bv);
437 if (rc == 0) {
Steve French4498eed52005-12-03 13:58:57 -0800438#ifdef CONFIG_CIFS_STATS2
Steve French468d6772018-08-04 05:24:34 -0500439 int i;
440
Steve French4498eed52005-12-03 13:58:57 -0800441 atomic_set(&totBufAllocCount, 0);
442 atomic_set(&totSmBufAllocCount, 0);
443#endif /* CONFIG_CIFS_STATS2 */
Steve French2c8876352018-09-15 23:04:41 -0500444 atomic_set(&tcpSesReconnectCount, 0);
445 atomic_set(&tconInfoReconnectCount, 0);
446
Steve Frenchc281bc02018-08-01 00:56:12 -0500447 spin_lock(&GlobalMid_Lock);
448 GlobalMaxActiveXid = 0;
449 GlobalCurrentXid = 0;
450 spin_unlock(&GlobalMid_Lock);
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530451 spin_lock(&cifs_tcp_ses_lock);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500452 list_for_each(tmp1, &cifs_tcp_ses_list) {
453 server = list_entry(tmp1, struct TCP_Server_Info,
454 tcp_ses_list);
Steve French468d6772018-08-04 05:24:34 -0500455#ifdef CONFIG_CIFS_STATS2
Steve French433b8dd2019-03-26 13:53:21 -0500456 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
457 atomic_set(&server->num_cmds[i], 0);
Steve French468d6772018-08-04 05:24:34 -0500458 atomic_set(&server->smb2slowcmd[i], 0);
Steve French433b8dd2019-03-26 13:53:21 -0500459 server->time_per_cmd[i] = 0;
460 server->slowest_cmd[i] = 0;
461 server->fastest_cmd[0] = 0;
462 }
Steve French468d6772018-08-04 05:24:34 -0500463#endif /* CONFIG_CIFS_STATS2 */
Steve Frenchc2b33822008-11-17 03:57:13 +0000464 list_for_each(tmp2, &server->smb_ses_list) {
Steve French96daf2b2011-05-27 04:34:02 +0000465 ses = list_entry(tmp2, struct cifs_ses,
Steve Frenchc2b33822008-11-17 03:57:13 +0000466 smb_ses_list);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500467 list_for_each(tmp3, &ses->tcon_list) {
468 tcon = list_entry(tmp3,
Steve French96daf2b2011-05-27 04:34:02 +0000469 struct cifs_tcon,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500470 tcon_list);
471 atomic_set(&tcon->num_smbs_sent, 0);
Steve Frenchc281bc02018-08-01 00:56:12 -0500472 spin_lock(&tcon->stat_lock);
473 tcon->bytes_read = 0;
474 tcon->bytes_written = 0;
475 spin_unlock(&tcon->stat_lock);
Pavel Shilovsky44c58182012-05-28 14:16:31 +0400476 if (server->ops->clear_stats)
477 server->ops->clear_stats(tcon);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500478 }
479 }
Steve French1047abc2005-10-11 19:58:06 -0700480 }
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530481 spin_unlock(&cifs_tcp_ses_lock);
Kees Cook14042972016-03-17 14:22:54 -0700482 } else {
483 return rc;
Steve French1047abc2005-10-11 19:58:06 -0700484 }
485
Steve French221601c2007-06-05 20:35:06 +0000486 return count;
Steve French1047abc2005-10-11 19:58:06 -0700487}
488
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000489static int cifs_stats_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000491 int i;
Steve French468d6772018-08-04 05:24:34 -0500492#ifdef CONFIG_CIFS_STATS2
493 int j;
494#endif /* STATS2 */
Jeff Laytonf1987b42008-11-15 11:12:47 -0500495 struct list_head *tmp1, *tmp2, *tmp3;
496 struct TCP_Server_Info *server;
Steve French96daf2b2011-05-27 04:34:02 +0000497 struct cifs_ses *ses;
498 struct cifs_tcon *tcon;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
Steve French468d6772018-08-04 05:24:34 -0500500 seq_printf(m, "Resources in use\nCIFS Session: %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 sesInfoAllocCount.counter);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000502 seq_printf(m, "Share (unique mount targets): %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 tconInfoAllocCount.counter);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000504 seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
Steve Frenchb8643e12005-04-28 22:41:07 -0700505 bufAllocCount.counter,
506 cifs_min_rcv + tcpSesAllocCount.counter);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000507 seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
Steve French221601c2007-06-05 20:35:06 +0000508 smBufAllocCount.counter, cifs_min_small);
Steve French07475ff2005-12-03 14:11:37 -0800509#ifdef CONFIG_CIFS_STATS2
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000510 seq_printf(m, "Total Large %d Small %d Allocations\n",
Steve French07475ff2005-12-03 14:11:37 -0800511 atomic_read(&totBufAllocCount),
Steve French221601c2007-06-05 20:35:06 +0000512 atomic_read(&totSmBufAllocCount));
Steve French07475ff2005-12-03 14:11:37 -0800513#endif /* CONFIG_CIFS_STATS2 */
514
Jeff Layton80975312011-01-11 07:24:02 -0500515 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000516 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 "\n%d session %d share reconnects\n",
Steve French221601c2007-06-05 20:35:06 +0000518 tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000520 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 "Total vfs operations: %d maximum at one time: %d\n",
Steve French221601c2007-06-05 20:35:06 +0000522 GlobalCurrentXid, GlobalMaxActiveXid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
524 i = 0;
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530525 spin_lock(&cifs_tcp_ses_lock);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500526 list_for_each(tmp1, &cifs_tcp_ses_list) {
527 server = list_entry(tmp1, struct TCP_Server_Info,
528 tcp_ses_list);
Steve French468d6772018-08-04 05:24:34 -0500529#ifdef CONFIG_CIFS_STATS2
Steve French433b8dd2019-03-26 13:53:21 -0500530 seq_puts(m, "\nTotal time spent processing by command. Time ");
531 seq_printf(m, "units are jiffies (%d per second)\n", HZ);
532 seq_puts(m, " SMB3 CMD\tNumber\tTotal Time\tFastest\tSlowest\n");
533 seq_puts(m, " --------\t------\t----------\t-------\t-------\n");
534 for (j = 0; j < NUMBER_OF_SMB2_COMMANDS; j++)
535 seq_printf(m, " %d\t\t%d\t%llu\t\t%u\t%u\n", j,
536 atomic_read(&server->num_cmds[j]),
537 server->time_per_cmd[j],
538 server->fastest_cmd[j],
539 server->slowest_cmd[j]);
Steve French468d6772018-08-04 05:24:34 -0500540 for (j = 0; j < NUMBER_OF_SMB2_COMMANDS; j++)
541 if (atomic_read(&server->smb2slowcmd[j]))
Steve French433b8dd2019-03-26 13:53:21 -0500542 seq_printf(m, " %d slow responses from %s for command %d\n",
Steve French468d6772018-08-04 05:24:34 -0500543 atomic_read(&server->smb2slowcmd[j]),
544 server->hostname, j);
545#endif /* STATS2 */
Jeff Laytonf1987b42008-11-15 11:12:47 -0500546 list_for_each(tmp2, &server->smb_ses_list) {
Steve French96daf2b2011-05-27 04:34:02 +0000547 ses = list_entry(tmp2, struct cifs_ses,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500548 smb_ses_list);
549 list_for_each(tmp3, &ses->tcon_list) {
550 tcon = list_entry(tmp3,
Steve French96daf2b2011-05-27 04:34:02 +0000551 struct cifs_tcon,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500552 tcon_list);
553 i++;
554 seq_printf(m, "\n%d) %s", i, tcon->treeName);
555 if (tcon->need_reconnect)
556 seq_puts(m, "\tDISCONNECTED ");
Pavel Shilovsky44c58182012-05-28 14:16:31 +0400557 seq_printf(m, "\nSMBs: %d",
558 atomic_read(&tcon->num_smbs_sent));
559 if (server->ops->print_stats)
560 server->ops->print_stats(m, tcon);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500561 }
562 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 }
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530564 spin_unlock(&cifs_tcp_ses_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000566 seq_putc(m, '\n');
567 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000569
570static int cifs_stats_proc_open(struct inode *inode, struct file *file)
571{
572 return single_open(file, cifs_stats_proc_show, NULL);
573}
574
575static const struct file_operations cifs_stats_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000576 .open = cifs_stats_proc_open,
577 .read = seq_read,
578 .llseek = seq_lseek,
579 .release = single_release,
580 .write = cifs_stats_proc_write,
581};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
Long Lid8ec9132017-11-07 01:54:58 -0700583#ifdef CONFIG_CIFS_SMB_DIRECT
584#define PROC_FILE_DEFINE(name) \
585static ssize_t name##_write(struct file *file, const char __user *buffer, \
586 size_t count, loff_t *ppos) \
587{ \
588 int rc; \
589 rc = kstrtoint_from_user(buffer, count, 10, & name); \
590 if (rc) \
591 return rc; \
592 return count; \
593} \
594static int name##_proc_show(struct seq_file *m, void *v) \
595{ \
596 seq_printf(m, "%d\n", name ); \
597 return 0; \
598} \
599static int name##_open(struct inode *inode, struct file *file) \
600{ \
601 return single_open(file, name##_proc_show, NULL); \
602} \
603\
604static const struct file_operations cifs_##name##_proc_fops = { \
605 .open = name##_open, \
606 .read = seq_read, \
607 .llseek = seq_lseek, \
608 .release = single_release, \
609 .write = name##_write, \
610}
611
Long Lid8ec9132017-11-07 01:54:58 -0700612PROC_FILE_DEFINE(rdma_readwrite_threshold);
613PROC_FILE_DEFINE(smbd_max_frmr_depth);
614PROC_FILE_DEFINE(smbd_keep_alive_interval);
615PROC_FILE_DEFINE(smbd_max_receive_size);
616PROC_FILE_DEFINE(smbd_max_fragmented_recv_size);
617PROC_FILE_DEFINE(smbd_max_send_size);
618PROC_FILE_DEFINE(smbd_send_credit_target);
619PROC_FILE_DEFINE(smbd_receive_credit_max);
620#endif
621
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622static struct proc_dir_entry *proc_fs_cifs;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000623static const struct file_operations cifsFYI_proc_fops;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000624static const struct file_operations cifs_lookup_cache_proc_fops;
625static const struct file_operations traceSMB_proc_fops;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000626static const struct file_operations cifs_security_flags_proc_fops;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000627static const struct file_operations cifs_linux_ext_proc_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
629void
630cifs_proc_init(void)
631{
Alexey Dobriyan36a5aeb2008-04-29 01:01:42 -0700632 proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 if (proc_fs_cifs == NULL)
634 return;
635
Christoph Hellwig3f3942a2018-05-15 15:57:23 +0200636 proc_create_single("DebugData", 0, proc_fs_cifs,
637 cifs_debug_data_proc_show);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
Steve Frenchdfe33f92018-10-30 19:50:31 -0500639 proc_create_single("open_files", 0400, proc_fs_cifs,
640 cifs_debug_files_proc_show);
641
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000642 proc_create("Stats", 0644, proc_fs_cifs, &cifs_stats_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000643 proc_create("cifsFYI", 0644, proc_fs_cifs, &cifsFYI_proc_fops);
644 proc_create("traceSMB", 0644, proc_fs_cifs, &traceSMB_proc_fops);
645 proc_create("LinuxExtensionsEnabled", 0644, proc_fs_cifs,
Steve French99b1f5b2008-07-24 02:37:45 +0000646 &cifs_linux_ext_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000647 proc_create("SecurityFlags", 0644, proc_fs_cifs,
Steve French99b1f5b2008-07-24 02:37:45 +0000648 &cifs_security_flags_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000649 proc_create("LookupCacheEnabled", 0644, proc_fs_cifs,
Steve French99b1f5b2008-07-24 02:37:45 +0000650 &cifs_lookup_cache_proc_fops);
Paulo Alcantara54be1f62018-11-14 16:01:21 -0200651
652#ifdef CONFIG_CIFS_DFS_UPCALL
653 proc_create("dfscache", 0644, proc_fs_cifs, &dfscache_proc_fops);
654#endif
655
Long Lid8ec9132017-11-07 01:54:58 -0700656#ifdef CONFIG_CIFS_SMB_DIRECT
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000657 proc_create("rdma_readwrite_threshold", 0644, proc_fs_cifs,
Long Lid8ec9132017-11-07 01:54:58 -0700658 &cifs_rdma_readwrite_threshold_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000659 proc_create("smbd_max_frmr_depth", 0644, proc_fs_cifs,
Long Lid8ec9132017-11-07 01:54:58 -0700660 &cifs_smbd_max_frmr_depth_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000661 proc_create("smbd_keep_alive_interval", 0644, proc_fs_cifs,
Long Lid8ec9132017-11-07 01:54:58 -0700662 &cifs_smbd_keep_alive_interval_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000663 proc_create("smbd_max_receive_size", 0644, proc_fs_cifs,
Long Lid8ec9132017-11-07 01:54:58 -0700664 &cifs_smbd_max_receive_size_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000665 proc_create("smbd_max_fragmented_recv_size", 0644, proc_fs_cifs,
Long Lid8ec9132017-11-07 01:54:58 -0700666 &cifs_smbd_max_fragmented_recv_size_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000667 proc_create("smbd_max_send_size", 0644, proc_fs_cifs,
Long Lid8ec9132017-11-07 01:54:58 -0700668 &cifs_smbd_max_send_size_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000669 proc_create("smbd_send_credit_target", 0644, proc_fs_cifs,
Long Lid8ec9132017-11-07 01:54:58 -0700670 &cifs_smbd_send_credit_target_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000671 proc_create("smbd_receive_credit_max", 0644, proc_fs_cifs,
Long Lid8ec9132017-11-07 01:54:58 -0700672 &cifs_smbd_receive_credit_max_proc_fops);
673#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674}
675
676void
677cifs_proc_clean(void)
678{
679 if (proc_fs_cifs == NULL)
680 return;
681
682 remove_proc_entry("DebugData", proc_fs_cifs);
Steve Frenchdfe33f92018-10-30 19:50:31 -0500683 remove_proc_entry("open_files", proc_fs_cifs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 remove_proc_entry("cifsFYI", proc_fs_cifs);
685 remove_proc_entry("traceSMB", proc_fs_cifs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 remove_proc_entry("Stats", proc_fs_cifs);
Steve French221601c2007-06-05 20:35:06 +0000687 remove_proc_entry("SecurityFlags", proc_fs_cifs);
Steve French221601c2007-06-05 20:35:06 +0000688 remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
Steve French221601c2007-06-05 20:35:06 +0000689 remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
Paulo Alcantara54be1f62018-11-14 16:01:21 -0200690
691#ifdef CONFIG_CIFS_DFS_UPCALL
692 remove_proc_entry("dfscache", proc_fs_cifs);
693#endif
Long Lid8ec9132017-11-07 01:54:58 -0700694#ifdef CONFIG_CIFS_SMB_DIRECT
695 remove_proc_entry("rdma_readwrite_threshold", proc_fs_cifs);
696 remove_proc_entry("smbd_max_frmr_depth", proc_fs_cifs);
697 remove_proc_entry("smbd_keep_alive_interval", proc_fs_cifs);
698 remove_proc_entry("smbd_max_receive_size", proc_fs_cifs);
699 remove_proc_entry("smbd_max_fragmented_recv_size", proc_fs_cifs);
700 remove_proc_entry("smbd_max_send_size", proc_fs_cifs);
701 remove_proc_entry("smbd_send_credit_target", proc_fs_cifs);
702 remove_proc_entry("smbd_receive_credit_max", proc_fs_cifs);
703#endif
Alexey Dobriyan36a5aeb2008-04-29 01:01:42 -0700704 remove_proc_entry("fs/cifs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705}
706
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000707static int cifsFYI_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000709 seq_printf(m, "%d\n", cifsFYI);
710 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000712
713static int cifsFYI_proc_open(struct inode *inode, struct file *file)
714{
715 return single_open(file, cifsFYI_proc_show, NULL);
716}
717
718static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
719 size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720{
Kees Cook14042972016-03-17 14:22:54 -0700721 char c[2] = { '\0' };
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300722 bool bv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 int rc;
724
Kees Cook14042972016-03-17 14:22:54 -0700725 rc = get_user(c[0], buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 if (rc)
727 return rc;
Kees Cook14042972016-03-17 14:22:54 -0700728 if (strtobool(c, &bv) == 0)
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300729 cifsFYI = bv;
Kees Cook14042972016-03-17 14:22:54 -0700730 else if ((c[0] > '1') && (c[0] <= '9'))
731 cifsFYI = (int) (c[0] - '0'); /* see cifs_debug.h for meanings */
Ronnie Sahlberg25ad1cb2018-05-24 09:53:39 +1000732 else
733 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734
735 return count;
736}
737
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000738static const struct file_operations cifsFYI_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000739 .open = cifsFYI_proc_open,
740 .read = seq_read,
741 .llseek = seq_lseek,
742 .release = single_release,
743 .write = cifsFYI_proc_write,
744};
745
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000746static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000748 seq_printf(m, "%d\n", linuxExtEnabled);
749 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000751
752static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
753{
754 return single_open(file, cifs_linux_ext_proc_show, NULL);
755}
756
757static ssize_t cifs_linux_ext_proc_write(struct file *file,
758 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759{
Steve French221601c2007-06-05 20:35:06 +0000760 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
Kees Cook14042972016-03-17 14:22:54 -0700762 rc = kstrtobool_from_user(buffer, count, &linuxExtEnabled);
Steve French221601c2007-06-05 20:35:06 +0000763 if (rc)
764 return rc;
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300765
Steve French221601c2007-06-05 20:35:06 +0000766 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767}
768
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000769static const struct file_operations cifs_linux_ext_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000770 .open = cifs_linux_ext_proc_open,
771 .read = seq_read,
772 .llseek = seq_lseek,
773 .release = single_release,
774 .write = cifs_linux_ext_proc_write,
775};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000777static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000779 seq_printf(m, "%d\n", lookupCacheEnabled);
780 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000782
783static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
784{
785 return single_open(file, cifs_lookup_cache_proc_show, NULL);
786}
787
788static ssize_t cifs_lookup_cache_proc_write(struct file *file,
789 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 int rc;
792
Kees Cook14042972016-03-17 14:22:54 -0700793 rc = kstrtobool_from_user(buffer, count, &lookupCacheEnabled);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 if (rc)
795 return rc;
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300796
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 return count;
798}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000799
800static const struct file_operations cifs_lookup_cache_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000801 .open = cifs_lookup_cache_proc_open,
802 .read = seq_read,
803 .llseek = seq_lseek,
804 .release = single_release,
805 .write = cifs_lookup_cache_proc_write,
806};
807
808static int traceSMB_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000810 seq_printf(m, "%d\n", traceSMB);
811 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000813
814static int traceSMB_proc_open(struct inode *inode, struct file *file)
815{
816 return single_open(file, traceSMB_proc_show, NULL);
817}
818
819static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
820 size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 int rc;
823
Kees Cook14042972016-03-17 14:22:54 -0700824 rc = kstrtobool_from_user(buffer, count, &traceSMB);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 if (rc)
826 return rc;
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300827
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 return count;
829}
830
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000831static const struct file_operations traceSMB_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000832 .open = traceSMB_proc_open,
833 .read = seq_read,
834 .llseek = seq_lseek,
835 .release = single_release,
836 .write = traceSMB_proc_write,
837};
838
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000839static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840{
Jeff Layton04912d62010-04-24 07:57:45 -0400841 seq_printf(m, "0x%x\n", global_secflags);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000842 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000844
845static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
846{
847 return single_open(file, cifs_security_flags_proc_show, NULL);
848}
849
Jeff Layton52dfb442013-05-26 07:01:02 -0400850/*
851 * Ensure that if someone sets a MUST flag, that we disable all other MAY
852 * flags except for the ones corresponding to the given MUST flag. If there are
853 * multiple MUST flags, then try to prefer more secure ones.
854 */
855static void
856cifs_security_flags_handle_must_flags(unsigned int *flags)
857{
858 unsigned int signflags = *flags & CIFSSEC_MUST_SIGN;
859
860 if ((*flags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5)
861 *flags = CIFSSEC_MUST_KRB5;
862 else if ((*flags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP)
863 *flags = CIFSSEC_MUST_NTLMSSP;
864 else if ((*flags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2)
865 *flags = CIFSSEC_MUST_NTLMV2;
866 else if ((*flags & CIFSSEC_MUST_NTLM) == CIFSSEC_MUST_NTLM)
867 *flags = CIFSSEC_MUST_NTLM;
Niklas Cassel7a1ceba2015-01-22 14:16:34 +0100868 else if (CIFSSEC_MUST_LANMAN &&
869 (*flags & CIFSSEC_MUST_LANMAN) == CIFSSEC_MUST_LANMAN)
Jeff Layton52dfb442013-05-26 07:01:02 -0400870 *flags = CIFSSEC_MUST_LANMAN;
Niklas Cassel7a1ceba2015-01-22 14:16:34 +0100871 else if (CIFSSEC_MUST_PLNTXT &&
872 (*flags & CIFSSEC_MUST_PLNTXT) == CIFSSEC_MUST_PLNTXT)
Jeff Layton52dfb442013-05-26 07:01:02 -0400873 *flags = CIFSSEC_MUST_PLNTXT;
874
875 *flags |= signflags;
876}
877
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000878static ssize_t cifs_security_flags_proc_write(struct file *file,
879 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880{
Jeff Layton7715dad2013-05-26 07:01:01 -0400881 int rc;
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000882 unsigned int flags;
883 char flags_string[12];
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300884 bool bv;
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000885
Steve French221601c2007-06-05 20:35:06 +0000886 if ((count < 1) || (count > 11))
Steve French39798772006-05-31 22:40:51 +0000887 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000889 memset(flags_string, 0, 12);
Steve French39798772006-05-31 22:40:51 +0000890
Steve French221601c2007-06-05 20:35:06 +0000891 if (copy_from_user(flags_string, buffer, count))
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000892 return -EFAULT;
Steve French39798772006-05-31 22:40:51 +0000893
Steve French221601c2007-06-05 20:35:06 +0000894 if (count < 3) {
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000895 /* single char or single char followed by null */
Kees Cook14042972016-03-17 14:22:54 -0700896 if (strtobool(flags_string, &bv) == 0) {
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300897 global_secflags = bv ? CIFSSEC_MAX : CIFSSEC_DEF;
Steve Frencha0136892007-10-04 20:05:09 +0000898 return count;
Kees Cook14042972016-03-17 14:22:54 -0700899 } else if (!isdigit(flags_string[0])) {
Jeff Layton7715dad2013-05-26 07:01:01 -0400900 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
901 flags_string);
Steve Frencha0136892007-10-04 20:05:09 +0000902 return -EINVAL;
903 }
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000904 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905
Jeff Layton7715dad2013-05-26 07:01:01 -0400906 /* else we have a number */
907 rc = kstrtouint(flags_string, 0, &flags);
908 if (rc) {
909 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
910 flags_string);
911 return rc;
912 }
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000913
Joe Perchesf96637b2013-05-04 22:12:25 -0500914 cifs_dbg(FYI, "sec flags 0x%x\n", flags);
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000915
Jeff Layton7715dad2013-05-26 07:01:01 -0400916 if (flags == 0) {
917 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", flags_string);
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000918 return -EINVAL;
919 }
920
Steve French221601c2007-06-05 20:35:06 +0000921 if (flags & ~CIFSSEC_MASK) {
Jeff Layton7715dad2013-05-26 07:01:01 -0400922 cifs_dbg(VFS, "Unsupported security flags: 0x%x\n",
Joe Perchesf96637b2013-05-04 22:12:25 -0500923 flags & ~CIFSSEC_MASK);
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000924 return -EINVAL;
925 }
Jeff Layton7715dad2013-05-26 07:01:01 -0400926
Jeff Layton52dfb442013-05-26 07:01:02 -0400927 cifs_security_flags_handle_must_flags(&flags);
928
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000929 /* flags look ok - update the global security flags for cifs module */
Jeff Layton04912d62010-04-24 07:57:45 -0400930 global_secflags = flags;
931 if (global_secflags & CIFSSEC_MUST_SIGN) {
Steve French762e5ab2007-06-28 18:41:42 +0000932 /* requiring signing implies signing is allowed */
Jeff Layton04912d62010-04-24 07:57:45 -0400933 global_secflags |= CIFSSEC_MAY_SIGN;
Joe Perchesf96637b2013-05-04 22:12:25 -0500934 cifs_dbg(FYI, "packet signing now required\n");
Jeff Layton04912d62010-04-24 07:57:45 -0400935 } else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500936 cifs_dbg(FYI, "packet signing disabled\n");
Steve French762e5ab2007-06-28 18:41:42 +0000937 }
938 /* BB should we turn on MAY flags for other MUST options? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 return count;
940}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000941
942static const struct file_operations cifs_security_flags_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000943 .open = cifs_security_flags_proc_open,
944 .read = seq_read,
945 .llseek = seq_lseek,
946 .release = single_release,
947 .write = cifs_security_flags_proc_write,
948};
Steve French90c81e02008-02-12 20:32:36 +0000949#else
Steve Frenche086fce2008-02-18 04:03:58 +0000950inline void cifs_proc_init(void)
Steve French90c81e02008-02-12 20:32:36 +0000951{
952}
953
Steve Frenche086fce2008-02-18 04:03:58 +0000954inline void cifs_proc_clean(void)
Steve French90c81e02008-02-12 20:32:36 +0000955{
956}
957#endif /* PROC_FS */