hc
2024-02-19 151fecfb72a0d602dfe79790602ef64b4e241574
kernel/fs/cifs/cifs_debug.c
....@@ -1,23 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * fs/cifs_debug.c
34 *
45 * Copyright (C) International Business Machines Corp., 2000,2005
56 *
67 * 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
10
- * the Free Software Foundation; either version 2 of the License, or
11
- * (at your option) any later version.
12
- *
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
19
- * along with this program; if not, write to the Free Software
20
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
218 */
229 #include <linux/fs.h>
2310 #include <linux/string.h>
....@@ -30,6 +17,9 @@
3017 #include "cifsproto.h"
3118 #include "cifs_debug.h"
3219 #include "cifsfs.h"
20
+#ifdef CONFIG_CIFS_DFS_UPCALL
21
+#include "dfs_cache.h"
22
+#endif
3323 #ifdef CONFIG_CIFS_SMB_DIRECT
3424 #include "smbdirect.h"
3525 #endif
....@@ -112,7 +102,12 @@
112102 seq_puts(m, " type: CDROM ");
113103 else
114104 seq_printf(m, " type: %d ", dev_type);
115
- if (tcon->seal)
105
+
106
+ seq_printf(m, "Serial Number: 0x%x", tcon->vol_serial_number);
107
+
108
+ if ((tcon->seal) ||
109
+ (tcon->ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA) ||
110
+ (tcon->share_flags & SHI1005_FLAGS_ENCRYPT_DATA))
116111 seq_printf(m, " Encrypted");
117112 if (tcon->nocase)
118113 seq_printf(m, " nocase");
....@@ -127,12 +122,33 @@
127122 }
128123
129124 static void
125
+cifs_dump_channel(struct seq_file *m, int i, struct cifs_chan *chan)
126
+{
127
+ struct TCP_Server_Info *server = chan->server;
128
+
129
+ seq_printf(m, "\t\tChannel %d Number of credits: %d Dialect 0x%x "
130
+ "TCP status: %d Instance: %d Local Users To Server: %d "
131
+ "SecMode: 0x%x Req On Wire: %d In Send: %d "
132
+ "In MaxReq Wait: %d\n",
133
+ i+1,
134
+ server->credits,
135
+ server->dialect,
136
+ server->tcpStatus,
137
+ server->reconnect_instance,
138
+ server->srv_count,
139
+ server->sec_mode,
140
+ in_flight(server),
141
+ atomic_read(&server->in_send),
142
+ atomic_read(&server->num_waiters));
143
+}
144
+
145
+static void
130146 cifs_dump_iface(struct seq_file *m, struct cifs_server_iface *iface)
131147 {
132148 struct sockaddr_in *ipv4 = (struct sockaddr_in *)&iface->sockaddr;
133149 struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)&iface->sockaddr;
134150
135
- seq_printf(m, "\t\tSpeed: %zu bps\n", iface->speed);
151
+ seq_printf(m, "\tSpeed: %zu bps\n", iface->speed);
136152 seq_puts(m, "\t\tCapabilities: ");
137153 if (iface->rdma_capable)
138154 seq_puts(m, "rdma ");
....@@ -143,6 +159,58 @@
143159 seq_printf(m, "\t\tIPv4: %pI4\n", &ipv4->sin_addr);
144160 else if (iface->sockaddr.ss_family == AF_INET6)
145161 seq_printf(m, "\t\tIPv6: %pI6\n", &ipv6->sin6_addr);
162
+}
163
+
164
+static int cifs_debug_files_proc_show(struct seq_file *m, void *v)
165
+{
166
+ struct list_head *stmp, *tmp, *tmp1, *tmp2;
167
+ struct TCP_Server_Info *server;
168
+ struct cifs_ses *ses;
169
+ struct cifs_tcon *tcon;
170
+ struct cifsFileInfo *cfile;
171
+
172
+ seq_puts(m, "# Version:1\n");
173
+ seq_puts(m, "# Format:\n");
174
+ seq_puts(m, "# <tree id> <persistent fid> <flags> <count> <pid> <uid>");
175
+#ifdef CONFIG_CIFS_DEBUG2
176
+ seq_printf(m, " <filename> <mid>\n");
177
+#else
178
+ seq_printf(m, " <filename>\n");
179
+#endif /* CIFS_DEBUG2 */
180
+ spin_lock(&cifs_tcp_ses_lock);
181
+ list_for_each(stmp, &cifs_tcp_ses_list) {
182
+ server = list_entry(stmp, struct TCP_Server_Info,
183
+ tcp_ses_list);
184
+ list_for_each(tmp, &server->smb_ses_list) {
185
+ ses = list_entry(tmp, struct cifs_ses, smb_ses_list);
186
+ list_for_each(tmp1, &ses->tcon_list) {
187
+ tcon = list_entry(tmp1, struct cifs_tcon, tcon_list);
188
+ spin_lock(&tcon->open_file_lock);
189
+ list_for_each(tmp2, &tcon->openFileList) {
190
+ cfile = list_entry(tmp2, struct cifsFileInfo,
191
+ tlist);
192
+ seq_printf(m,
193
+ "0x%x 0x%llx 0x%x %d %d %d %s",
194
+ tcon->tid,
195
+ cfile->fid.persistent_fid,
196
+ cfile->f_flags,
197
+ cfile->count,
198
+ cfile->pid,
199
+ from_kuid(&init_user_ns, cfile->uid),
200
+ cfile->dentry->d_name.name);
201
+#ifdef CONFIG_CIFS_DEBUG2
202
+ seq_printf(m, " 0x%llx\n", cfile->fid.mid);
203
+#else
204
+ seq_printf(m, "\n");
205
+#endif /* CIFS_DEBUG2 */
206
+ }
207
+ spin_unlock(&tcon->open_file_lock);
208
+ }
209
+ }
210
+ }
211
+ spin_unlock(&cifs_tcp_ses_lock);
212
+ seq_putc(m, '\n');
213
+ return 0;
146214 }
147215
148216 static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
....@@ -193,10 +261,9 @@
193261 #ifdef CONFIG_CIFS_XATTR
194262 seq_printf(m, ",XATTR");
195263 #endif
196
-#ifdef CONFIG_CIFS_ACL
197264 seq_printf(m, ",ACL");
198
-#endif
199265 seq_putc(m, '\n');
266
+ seq_printf(m, "CIFSMaxBufSize: %d\n", CIFSMaxBufSize);
200267 seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
201268 seq_printf(m, "Servers:");
202269
....@@ -256,12 +323,8 @@
256323 atomic_read(&server->smbd_conn->send_credits),
257324 atomic_read(&server->smbd_conn->receive_credits),
258325 server->smbd_conn->receive_credit_target);
259
- seq_printf(m, "\nPending send_pending: %x send_payload_pending:"
260
- " %x smbd_send_pending: %x smbd_recv_pending: %x",
261
- atomic_read(&server->smbd_conn->send_pending),
262
- atomic_read(&server->smbd_conn->send_payload_pending),
263
- server->smbd_conn->smbd_send_pending,
264
- server->smbd_conn->smbd_recv_pending);
326
+ seq_printf(m, "\nPending send_pending: %x ",
327
+ atomic_read(&server->smbd_conn->send_pending));
265328 seq_printf(m, "\nReceive buffers count_receive_queue: %x "
266329 "count_empty_packet_queue: %x",
267330 server->smbd_conn->count_receive_queue,
....@@ -278,6 +341,12 @@
278341 #endif
279342 seq_printf(m, "\nNumber of credits: %d Dialect 0x%x",
280343 server->credits, server->dialect);
344
+ if (server->compress_algorithm == SMB3_COMPRESS_LZNT1)
345
+ seq_printf(m, " COMPRESS_LZNT1");
346
+ else if (server->compress_algorithm == SMB3_COMPRESS_LZ77)
347
+ seq_printf(m, " COMPRESS_LZ77");
348
+ else if (server->compress_algorithm == SMB3_COMPRESS_LZ77_HUFF)
349
+ seq_printf(m, " COMPRESS_LZ77_HUFF");
281350 if (server->sign)
282351 seq_printf(m, " signed");
283352 if (server->posix_ext_supported)
....@@ -290,7 +359,7 @@
290359 if ((ses->serverDomain == NULL) ||
291360 (ses->serverOS == NULL) ||
292361 (ses->serverNOS == NULL)) {
293
- seq_printf(m, "\n%d) Name: %s Uses: %d Capability: 0x%x\tSession Status: %d\t",
362
+ seq_printf(m, "\n%d) Name: %s Uses: %d Capability: 0x%x\tSession Status: %d ",
294363 i, ses->serverName, ses->ses_count,
295364 ses->capabilities, ses->status);
296365 if (ses->session_flags & SMB2_SESSION_FLAG_IS_GUEST)
....@@ -301,25 +370,47 @@
301370 seq_printf(m,
302371 "\n%d) Name: %s Domain: %s Uses: %d OS:"
303372 " %s\n\tNOS: %s\tCapability: 0x%x\n\tSMB"
304
- " session status: %d\t",
373
+ " session status: %d ",
305374 i, ses->serverName, ses->serverDomain,
306375 ses->ses_count, ses->serverOS, ses->serverNOS,
307376 ses->capabilities, ses->status);
308377 }
378
+
379
+ seq_printf(m,"Security type: %s\n",
380
+ get_security_type_str(server->ops->select_sectype(server, ses->sectype)));
381
+
309382 if (server->rdma)
310383 seq_printf(m, "RDMA\n\t");
311
- seq_printf(m, "TCP status: %d\n\tLocal Users To "
384
+ seq_printf(m, "TCP status: %d Instance: %d\n\tLocal Users To "
312385 "Server: %d SecMode: 0x%x Req On Wire: %d",
313
- server->tcpStatus, server->srv_count,
386
+ server->tcpStatus,
387
+ server->reconnect_instance,
388
+ server->srv_count,
314389 server->sec_mode, in_flight(server));
315390
316
-#ifdef CONFIG_CIFS_STATS2
317391 seq_printf(m, " In Send: %d In MaxReq Wait: %d",
318392 atomic_read(&server->in_send),
319393 atomic_read(&server->num_waiters));
320
-#endif
321394
322
- seq_puts(m, "\n\tShares:");
395
+ /* dump session id helpful for use with network trace */
396
+ seq_printf(m, " SessionId: 0x%llx", ses->Suid);
397
+ if (ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA)
398
+ seq_puts(m, " encrypted");
399
+ if (ses->sign)
400
+ seq_puts(m, " signed");
401
+
402
+ seq_printf(m, "\n\tUser: %d Cred User: %d",
403
+ from_kuid(&init_user_ns, ses->linux_uid),
404
+ from_kuid(&init_user_ns, ses->cred_uid));
405
+
406
+ if (ses->chan_count > 1) {
407
+ seq_printf(m, "\n\n\tExtra Channels: %zu\n",
408
+ ses->chan_count-1);
409
+ for (j = 1; j < ses->chan_count; j++)
410
+ cifs_dump_channel(m, j, &ses->chans[j]);
411
+ }
412
+
413
+ seq_puts(m, "\n\n\tShares:");
323414 j = 0;
324415
325416 seq_printf(m, "\n\t%d) IPC: ", j);
....@@ -357,8 +448,13 @@
357448 seq_printf(m, "\n\tServer interfaces: %zu\n",
358449 ses->iface_count);
359450 for (j = 0; j < ses->iface_count; j++) {
360
- seq_printf(m, "\t%d)\n", j);
361
- cifs_dump_iface(m, &ses->iface_list[j]);
451
+ struct cifs_server_iface *iface;
452
+
453
+ iface = &ses->iface_list[j];
454
+ seq_printf(m, "\t%d)", j);
455
+ cifs_dump_iface(m, iface);
456
+ if (is_ses_using_iface(ses, iface))
457
+ seq_puts(m, "\t\t[CONNECTED]\n");
362458 }
363459 spin_unlock(&ses->iface_lock);
364460 }
....@@ -399,9 +495,15 @@
399495 list_for_each(tmp1, &cifs_tcp_ses_list) {
400496 server = list_entry(tmp1, struct TCP_Server_Info,
401497 tcp_ses_list);
498
+ server->max_in_flight = 0;
402499 #ifdef CONFIG_CIFS_STATS2
403
- for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++)
500
+ for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
501
+ atomic_set(&server->num_cmds[i], 0);
404502 atomic_set(&server->smb2slowcmd[i], 0);
503
+ server->time_per_cmd[i] = 0;
504
+ server->slowest_cmd[i] = 0;
505
+ server->fastest_cmd[0] = 0;
506
+ }
405507 #endif /* CONFIG_CIFS_STATS2 */
406508 list_for_each(tmp2, &server->smb_ses_list) {
407509 ses = list_entry(tmp2, struct cifs_ses,
....@@ -468,10 +570,21 @@
468570 list_for_each(tmp1, &cifs_tcp_ses_list) {
469571 server = list_entry(tmp1, struct TCP_Server_Info,
470572 tcp_ses_list);
573
+ seq_printf(m, "\nMax requests in flight: %d", server->max_in_flight);
471574 #ifdef CONFIG_CIFS_STATS2
575
+ seq_puts(m, "\nTotal time spent processing by command. Time ");
576
+ seq_printf(m, "units are jiffies (%d per second)\n", HZ);
577
+ seq_puts(m, " SMB3 CMD\tNumber\tTotal Time\tFastest\tSlowest\n");
578
+ seq_puts(m, " --------\t------\t----------\t-------\t-------\n");
579
+ for (j = 0; j < NUMBER_OF_SMB2_COMMANDS; j++)
580
+ seq_printf(m, " %d\t\t%d\t%llu\t\t%u\t%u\n", j,
581
+ atomic_read(&server->num_cmds[j]),
582
+ server->time_per_cmd[j],
583
+ server->fastest_cmd[j],
584
+ server->slowest_cmd[j]);
472585 for (j = 0; j < NUMBER_OF_SMB2_COMMANDS; j++)
473586 if (atomic_read(&server->smb2slowcmd[j]))
474
- seq_printf(m, "%d slow responses from %s for command %d\n",
587
+ seq_printf(m, " %d slow responses from %s for command %d\n",
475588 atomic_read(&server->smb2slowcmd[j]),
476589 server->hostname, j);
477590 #endif /* STATS2 */
....@@ -504,12 +617,12 @@
504617 return single_open(file, cifs_stats_proc_show, NULL);
505618 }
506619
507
-static const struct file_operations cifs_stats_proc_fops = {
508
- .open = cifs_stats_proc_open,
509
- .read = seq_read,
510
- .llseek = seq_lseek,
511
- .release = single_release,
512
- .write = cifs_stats_proc_write,
620
+static const struct proc_ops cifs_stats_proc_ops = {
621
+ .proc_open = cifs_stats_proc_open,
622
+ .proc_read = seq_read,
623
+ .proc_lseek = seq_lseek,
624
+ .proc_release = single_release,
625
+ .proc_write = cifs_stats_proc_write,
513626 };
514627
515628 #ifdef CONFIG_CIFS_SMB_DIRECT
....@@ -533,12 +646,12 @@
533646 return single_open(file, name##_proc_show, NULL); \
534647 } \
535648 \
536
-static const struct file_operations cifs_##name##_proc_fops = { \
537
- .open = name##_open, \
538
- .read = seq_read, \
539
- .llseek = seq_lseek, \
540
- .release = single_release, \
541
- .write = name##_write, \
649
+static const struct proc_ops cifs_##name##_proc_fops = { \
650
+ .proc_open = name##_open, \
651
+ .proc_read = seq_read, \
652
+ .proc_lseek = seq_lseek, \
653
+ .proc_release = single_release, \
654
+ .proc_write = name##_write, \
542655 }
543656
544657 PROC_FILE_DEFINE(rdma_readwrite_threshold);
....@@ -552,11 +665,11 @@
552665 #endif
553666
554667 static struct proc_dir_entry *proc_fs_cifs;
555
-static const struct file_operations cifsFYI_proc_fops;
556
-static const struct file_operations cifs_lookup_cache_proc_fops;
557
-static const struct file_operations traceSMB_proc_fops;
558
-static const struct file_operations cifs_security_flags_proc_fops;
559
-static const struct file_operations cifs_linux_ext_proc_fops;
668
+static const struct proc_ops cifsFYI_proc_ops;
669
+static const struct proc_ops cifs_lookup_cache_proc_ops;
670
+static const struct proc_ops traceSMB_proc_ops;
671
+static const struct proc_ops cifs_security_flags_proc_ops;
672
+static const struct proc_ops cifs_linux_ext_proc_ops;
560673
561674 void
562675 cifs_proc_init(void)
....@@ -568,15 +681,23 @@
568681 proc_create_single("DebugData", 0, proc_fs_cifs,
569682 cifs_debug_data_proc_show);
570683
571
- proc_create("Stats", 0644, proc_fs_cifs, &cifs_stats_proc_fops);
572
- proc_create("cifsFYI", 0644, proc_fs_cifs, &cifsFYI_proc_fops);
573
- proc_create("traceSMB", 0644, proc_fs_cifs, &traceSMB_proc_fops);
684
+ proc_create_single("open_files", 0400, proc_fs_cifs,
685
+ cifs_debug_files_proc_show);
686
+
687
+ proc_create("Stats", 0644, proc_fs_cifs, &cifs_stats_proc_ops);
688
+ proc_create("cifsFYI", 0644, proc_fs_cifs, &cifsFYI_proc_ops);
689
+ proc_create("traceSMB", 0644, proc_fs_cifs, &traceSMB_proc_ops);
574690 proc_create("LinuxExtensionsEnabled", 0644, proc_fs_cifs,
575
- &cifs_linux_ext_proc_fops);
691
+ &cifs_linux_ext_proc_ops);
576692 proc_create("SecurityFlags", 0644, proc_fs_cifs,
577
- &cifs_security_flags_proc_fops);
693
+ &cifs_security_flags_proc_ops);
578694 proc_create("LookupCacheEnabled", 0644, proc_fs_cifs,
579
- &cifs_lookup_cache_proc_fops);
695
+ &cifs_lookup_cache_proc_ops);
696
+
697
+#ifdef CONFIG_CIFS_DFS_UPCALL
698
+ proc_create("dfscache", 0644, proc_fs_cifs, &dfscache_proc_ops);
699
+#endif
700
+
580701 #ifdef CONFIG_CIFS_SMB_DIRECT
581702 proc_create("rdma_readwrite_threshold", 0644, proc_fs_cifs,
582703 &cifs_rdma_readwrite_threshold_proc_fops);
....@@ -604,12 +725,17 @@
604725 return;
605726
606727 remove_proc_entry("DebugData", proc_fs_cifs);
728
+ remove_proc_entry("open_files", proc_fs_cifs);
607729 remove_proc_entry("cifsFYI", proc_fs_cifs);
608730 remove_proc_entry("traceSMB", proc_fs_cifs);
609731 remove_proc_entry("Stats", proc_fs_cifs);
610732 remove_proc_entry("SecurityFlags", proc_fs_cifs);
611733 remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
612734 remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
735
+
736
+#ifdef CONFIG_CIFS_DFS_UPCALL
737
+ remove_proc_entry("dfscache", proc_fs_cifs);
738
+#endif
613739 #ifdef CONFIG_CIFS_SMB_DIRECT
614740 remove_proc_entry("rdma_readwrite_threshold", proc_fs_cifs);
615741 remove_proc_entry("smbd_max_frmr_depth", proc_fs_cifs);
....@@ -654,12 +780,12 @@
654780 return count;
655781 }
656782
657
-static const struct file_operations cifsFYI_proc_fops = {
658
- .open = cifsFYI_proc_open,
659
- .read = seq_read,
660
- .llseek = seq_lseek,
661
- .release = single_release,
662
- .write = cifsFYI_proc_write,
783
+static const struct proc_ops cifsFYI_proc_ops = {
784
+ .proc_open = cifsFYI_proc_open,
785
+ .proc_read = seq_read,
786
+ .proc_lseek = seq_lseek,
787
+ .proc_release = single_release,
788
+ .proc_write = cifsFYI_proc_write,
663789 };
664790
665791 static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
....@@ -685,12 +811,12 @@
685811 return count;
686812 }
687813
688
-static const struct file_operations cifs_linux_ext_proc_fops = {
689
- .open = cifs_linux_ext_proc_open,
690
- .read = seq_read,
691
- .llseek = seq_lseek,
692
- .release = single_release,
693
- .write = cifs_linux_ext_proc_write,
814
+static const struct proc_ops cifs_linux_ext_proc_ops = {
815
+ .proc_open = cifs_linux_ext_proc_open,
816
+ .proc_read = seq_read,
817
+ .proc_lseek = seq_lseek,
818
+ .proc_release = single_release,
819
+ .proc_write = cifs_linux_ext_proc_write,
694820 };
695821
696822 static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
....@@ -716,12 +842,12 @@
716842 return count;
717843 }
718844
719
-static const struct file_operations cifs_lookup_cache_proc_fops = {
720
- .open = cifs_lookup_cache_proc_open,
721
- .read = seq_read,
722
- .llseek = seq_lseek,
723
- .release = single_release,
724
- .write = cifs_lookup_cache_proc_write,
845
+static const struct proc_ops cifs_lookup_cache_proc_ops = {
846
+ .proc_open = cifs_lookup_cache_proc_open,
847
+ .proc_read = seq_read,
848
+ .proc_lseek = seq_lseek,
849
+ .proc_release = single_release,
850
+ .proc_write = cifs_lookup_cache_proc_write,
725851 };
726852
727853 static int traceSMB_proc_show(struct seq_file *m, void *v)
....@@ -747,12 +873,12 @@
747873 return count;
748874 }
749875
750
-static const struct file_operations traceSMB_proc_fops = {
751
- .open = traceSMB_proc_open,
752
- .read = seq_read,
753
- .llseek = seq_lseek,
754
- .release = single_release,
755
- .write = traceSMB_proc_write,
876
+static const struct proc_ops traceSMB_proc_ops = {
877
+ .proc_open = traceSMB_proc_open,
878
+ .proc_read = seq_read,
879
+ .proc_lseek = seq_lseek,
880
+ .proc_release = single_release,
881
+ .proc_write = traceSMB_proc_write,
756882 };
757883
758884 static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
....@@ -858,12 +984,12 @@
858984 return count;
859985 }
860986
861
-static const struct file_operations cifs_security_flags_proc_fops = {
862
- .open = cifs_security_flags_proc_open,
863
- .read = seq_read,
864
- .llseek = seq_lseek,
865
- .release = single_release,
866
- .write = cifs_security_flags_proc_write,
987
+static const struct proc_ops cifs_security_flags_proc_ops = {
988
+ .proc_open = cifs_security_flags_proc_open,
989
+ .proc_read = seq_read,
990
+ .proc_lseek = seq_lseek,
991
+ .proc_release = single_release,
992
+ .proc_write = cifs_security_flags_proc_write,
867993 };
868994 #else
869995 inline void cifs_proc_init(void)