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