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