1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (C) International Business Machines Corp., 2000,2005
7 * Modified by Steve French (sfrench@us.ibm.com)
10 #include <linux/string.h>
11 #include <linux/ctype.h>
12 #include <linux/module.h>
13 #include <linux/proc_fs.h>
14 #include <linux/uaccess.h>
17 #include "cifsproto.h"
18 #include "cifs_debug.h"
20 #include "fs_context.h"
21 #ifdef CONFIG_CIFS_DFS_UPCALL
22 #include "dfs_cache.h"
24 #ifdef CONFIG_CIFS_SMB_DIRECT
25 #include "smbdirect.h"
30 cifs_dump_mem(char *label, void *data, int length)
32 pr_debug("%s: dump of %d bytes of data at 0x%p\n", label, length, data);
33 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 4,
37 void cifs_dump_detail(void *buf, struct TCP_Server_Info *server)
39 #ifdef CONFIG_CIFS_DEBUG2
40 struct smb_hdr *smb = (struct smb_hdr *)buf;
42 cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d\n",
43 smb->Command, smb->Status.CifsError,
44 smb->Flags, smb->Flags2, smb->Mid, smb->Pid);
45 cifs_dbg(VFS, "smb buf %p len %u\n", smb,
46 server->ops->calc_smb_size(smb, server));
47 #endif /* CONFIG_CIFS_DEBUG2 */
50 void cifs_dump_mids(struct TCP_Server_Info *server)
52 #ifdef CONFIG_CIFS_DEBUG2
53 struct list_head *tmp;
54 struct mid_q_entry *mid_entry;
59 cifs_dbg(VFS, "Dump pending requests:\n");
60 spin_lock(&GlobalMid_Lock);
61 list_for_each(tmp, &server->pending_mid_q) {
62 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
63 cifs_dbg(VFS, "State: %d Cmd: %d Pid: %d Cbdata: %p Mid %llu\n",
65 le16_to_cpu(mid_entry->command),
67 mid_entry->callback_data,
69 #ifdef CONFIG_CIFS_STATS2
70 cifs_dbg(VFS, "IsLarge: %d buf: %p time rcv: %ld now: %ld\n",
73 mid_entry->when_received,
76 cifs_dbg(VFS, "IsMult: %d IsEnd: %d\n",
77 mid_entry->multiRsp, mid_entry->multiEnd);
78 if (mid_entry->resp_buf) {
79 cifs_dump_detail(mid_entry->resp_buf, server);
80 cifs_dump_mem("existing buf: ",
81 mid_entry->resp_buf, 62);
84 spin_unlock(&GlobalMid_Lock);
85 #endif /* CONFIG_CIFS_DEBUG2 */
89 static void cifs_debug_tcon(struct seq_file *m, struct cifs_tcon *tcon)
91 __u32 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
93 seq_printf(m, "%s Mounts: %d ", tcon->treeName, tcon->tc_count);
94 if (tcon->nativeFileSystem)
95 seq_printf(m, "Type: %s ", tcon->nativeFileSystem);
96 seq_printf(m, "DevInfo: 0x%x Attributes: 0x%x\n\tPathComponentMax: %d Status: %d",
97 le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
98 le32_to_cpu(tcon->fsAttrInfo.Attributes),
99 le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
101 if (dev_type == FILE_DEVICE_DISK)
102 seq_puts(m, " type: DISK ");
103 else if (dev_type == FILE_DEVICE_CD_ROM)
104 seq_puts(m, " type: CDROM ");
106 seq_printf(m, " type: %d ", dev_type);
108 seq_printf(m, "Serial Number: 0x%x", tcon->vol_serial_number);
111 (tcon->ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA) ||
112 (tcon->share_flags & SHI1005_FLAGS_ENCRYPT_DATA))
113 seq_printf(m, " Encrypted");
115 seq_printf(m, " nocase");
117 seq_printf(m, " POSIX Extensions");
118 if (tcon->ses->server->ops->dump_share_caps)
119 tcon->ses->server->ops->dump_share_caps(m, tcon);
120 if (tcon->use_witness)
121 seq_puts(m, " Witness");
123 if (tcon->need_reconnect)
124 seq_puts(m, "\tDISCONNECTED ");
129 cifs_dump_channel(struct seq_file *m, int i, struct cifs_chan *chan)
131 struct TCP_Server_Info *server = chan->server;
133 seq_printf(m, "\n\n\t\tChannel: %d ConnectionId: 0x%llx"
134 "\n\t\tNumber of credits: %d Dialect 0x%x"
135 "\n\t\tTCP status: %d Instance: %d"
136 "\n\t\tLocal Users To Server: %d SecMode: 0x%x Req On Wire: %d"
137 "\n\t\tIn Send: %d In MaxReq Wait: %d",
138 i+1, server->conn_id,
142 server->reconnect_instance,
146 atomic_read(&server->in_send),
147 atomic_read(&server->num_waiters));
151 cifs_dump_iface(struct seq_file *m, struct cifs_server_iface *iface)
153 struct sockaddr_in *ipv4 = (struct sockaddr_in *)&iface->sockaddr;
154 struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)&iface->sockaddr;
156 seq_printf(m, "\tSpeed: %zu bps\n", iface->speed);
157 seq_puts(m, "\t\tCapabilities: ");
158 if (iface->rdma_capable)
159 seq_puts(m, "rdma ");
160 if (iface->rss_capable)
163 if (iface->sockaddr.ss_family == AF_INET)
164 seq_printf(m, "\t\tIPv4: %pI4\n", &ipv4->sin_addr);
165 else if (iface->sockaddr.ss_family == AF_INET6)
166 seq_printf(m, "\t\tIPv6: %pI6\n", &ipv6->sin6_addr);
169 static int cifs_debug_files_proc_show(struct seq_file *m, void *v)
171 struct list_head *stmp, *tmp, *tmp1, *tmp2;
172 struct TCP_Server_Info *server;
173 struct cifs_ses *ses;
174 struct cifs_tcon *tcon;
175 struct cifsFileInfo *cfile;
177 seq_puts(m, "# Version:1\n");
178 seq_puts(m, "# Format:\n");
179 seq_puts(m, "# <tree id> <persistent fid> <flags> <count> <pid> <uid>");
180 #ifdef CONFIG_CIFS_DEBUG2
181 seq_printf(m, " <filename> <mid>\n");
183 seq_printf(m, " <filename>\n");
184 #endif /* CIFS_DEBUG2 */
185 spin_lock(&cifs_tcp_ses_lock);
186 list_for_each(stmp, &cifs_tcp_ses_list) {
187 server = list_entry(stmp, struct TCP_Server_Info,
189 list_for_each(tmp, &server->smb_ses_list) {
190 ses = list_entry(tmp, struct cifs_ses, smb_ses_list);
191 list_for_each(tmp1, &ses->tcon_list) {
192 tcon = list_entry(tmp1, struct cifs_tcon, tcon_list);
193 spin_lock(&tcon->open_file_lock);
194 list_for_each(tmp2, &tcon->openFileList) {
195 cfile = list_entry(tmp2, struct cifsFileInfo,
198 "0x%x 0x%llx 0x%x %d %d %d %pd",
200 cfile->fid.persistent_fid,
204 from_kuid(&init_user_ns, cfile->uid),
206 #ifdef CONFIG_CIFS_DEBUG2
207 seq_printf(m, " %llu\n", cfile->fid.mid);
210 #endif /* CIFS_DEBUG2 */
212 spin_unlock(&tcon->open_file_lock);
216 spin_unlock(&cifs_tcp_ses_lock);
221 static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
223 struct list_head *tmp1, *tmp2, *tmp3;
224 struct mid_q_entry *mid_entry;
225 struct TCP_Server_Info *server;
226 struct cifs_ses *ses;
227 struct cifs_tcon *tcon;
231 "Display Internal CIFS Data Structures for Debugging\n"
232 "---------------------------------------------------\n");
233 seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
234 seq_printf(m, "Features:");
235 #ifdef CONFIG_CIFS_DFS_UPCALL
236 seq_printf(m, " DFS");
238 #ifdef CONFIG_CIFS_FSCACHE
239 seq_printf(m, ",FSCACHE");
241 #ifdef CONFIG_CIFS_SMB_DIRECT
242 seq_printf(m, ",SMB_DIRECT");
244 #ifdef CONFIG_CIFS_STATS2
245 seq_printf(m, ",STATS2");
247 seq_printf(m, ",STATS");
249 #ifdef CONFIG_CIFS_DEBUG2
250 seq_printf(m, ",DEBUG2");
251 #elif defined(CONFIG_CIFS_DEBUG)
252 seq_printf(m, ",DEBUG");
254 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
255 seq_printf(m, ",ALLOW_INSECURE_LEGACY");
257 #ifdef CONFIG_CIFS_WEAK_PW_HASH
258 seq_printf(m, ",WEAK_PW_HASH");
260 #ifdef CONFIG_CIFS_POSIX
261 seq_printf(m, ",CIFS_POSIX");
263 #ifdef CONFIG_CIFS_UPCALL
264 seq_printf(m, ",UPCALL(SPNEGO)");
266 #ifdef CONFIG_CIFS_XATTR
267 seq_printf(m, ",XATTR");
269 seq_printf(m, ",ACL");
270 #ifdef CONFIG_CIFS_SWN_UPCALL
271 seq_puts(m, ",WITNESS");
274 seq_printf(m, "CIFSMaxBufSize: %d\n", CIFSMaxBufSize);
275 seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
277 seq_printf(m, "\nServers: ");
280 spin_lock(&cifs_tcp_ses_lock);
281 list_for_each(tmp1, &cifs_tcp_ses_list) {
282 server = list_entry(tmp1, struct TCP_Server_Info,
285 /* channel info will be printed as a part of sessions below */
286 if (server->is_channel)
290 seq_printf(m, "\n%d) ConnectionId: 0x%llx ",
293 if (server->hostname)
294 seq_printf(m, "Hostname: %s ", server->hostname);
295 #ifdef CONFIG_CIFS_SMB_DIRECT
299 if (!server->smbd_conn) {
300 seq_printf(m, "\nSMBDirect transport not available");
304 seq_printf(m, "\nSMBDirect (in hex) protocol version: %x "
305 "transport status: %x",
306 server->smbd_conn->protocol,
307 server->smbd_conn->transport_status);
308 seq_printf(m, "\nConn receive_credit_max: %x "
309 "send_credit_target: %x max_send_size: %x",
310 server->smbd_conn->receive_credit_max,
311 server->smbd_conn->send_credit_target,
312 server->smbd_conn->max_send_size);
313 seq_printf(m, "\nConn max_fragmented_recv_size: %x "
314 "max_fragmented_send_size: %x max_receive_size:%x",
315 server->smbd_conn->max_fragmented_recv_size,
316 server->smbd_conn->max_fragmented_send_size,
317 server->smbd_conn->max_receive_size);
318 seq_printf(m, "\nConn keep_alive_interval: %x "
319 "max_readwrite_size: %x rdma_readwrite_threshold: %x",
320 server->smbd_conn->keep_alive_interval,
321 server->smbd_conn->max_readwrite_size,
322 server->smbd_conn->rdma_readwrite_threshold);
323 seq_printf(m, "\nDebug count_get_receive_buffer: %x "
324 "count_put_receive_buffer: %x count_send_empty: %x",
325 server->smbd_conn->count_get_receive_buffer,
326 server->smbd_conn->count_put_receive_buffer,
327 server->smbd_conn->count_send_empty);
328 seq_printf(m, "\nRead Queue count_reassembly_queue: %x "
329 "count_enqueue_reassembly_queue: %x "
330 "count_dequeue_reassembly_queue: %x "
331 "fragment_reassembly_remaining: %x "
332 "reassembly_data_length: %x "
333 "reassembly_queue_length: %x",
334 server->smbd_conn->count_reassembly_queue,
335 server->smbd_conn->count_enqueue_reassembly_queue,
336 server->smbd_conn->count_dequeue_reassembly_queue,
337 server->smbd_conn->fragment_reassembly_remaining,
338 server->smbd_conn->reassembly_data_length,
339 server->smbd_conn->reassembly_queue_length);
340 seq_printf(m, "\nCurrent Credits send_credits: %x "
341 "receive_credits: %x receive_credit_target: %x",
342 atomic_read(&server->smbd_conn->send_credits),
343 atomic_read(&server->smbd_conn->receive_credits),
344 server->smbd_conn->receive_credit_target);
345 seq_printf(m, "\nPending send_pending: %x ",
346 atomic_read(&server->smbd_conn->send_pending));
347 seq_printf(m, "\nReceive buffers count_receive_queue: %x "
348 "count_empty_packet_queue: %x",
349 server->smbd_conn->count_receive_queue,
350 server->smbd_conn->count_empty_packet_queue);
351 seq_printf(m, "\nMR responder_resources: %x "
352 "max_frmr_depth: %x mr_type: %x",
353 server->smbd_conn->responder_resources,
354 server->smbd_conn->max_frmr_depth,
355 server->smbd_conn->mr_type);
356 seq_printf(m, "\nMR mr_ready_count: %x mr_used_count: %x",
357 atomic_read(&server->smbd_conn->mr_ready_count),
358 atomic_read(&server->smbd_conn->mr_used_count));
361 seq_printf(m, "\nNumber of credits: %d Dialect 0x%x",
362 server->credits, server->dialect);
363 if (server->compress_algorithm == SMB3_COMPRESS_LZNT1)
364 seq_printf(m, " COMPRESS_LZNT1");
365 else if (server->compress_algorithm == SMB3_COMPRESS_LZ77)
366 seq_printf(m, " COMPRESS_LZ77");
367 else if (server->compress_algorithm == SMB3_COMPRESS_LZ77_HUFF)
368 seq_printf(m, " COMPRESS_LZ77_HUFF");
370 seq_printf(m, " signed");
371 if (server->posix_ext_supported)
372 seq_printf(m, " posix");
375 seq_printf(m, "\nRDMA ");
376 seq_printf(m, "\nTCP status: %d Instance: %d"
377 "\nLocal Users To Server: %d SecMode: 0x%x Req On Wire: %d",
379 server->reconnect_instance,
381 server->sec_mode, in_flight(server));
383 seq_printf(m, "\nIn Send: %d In MaxReq Wait: %d",
384 atomic_read(&server->in_send),
385 atomic_read(&server->num_waiters));
387 seq_printf(m, "\n\n\tSessions: ");
389 list_for_each(tmp2, &server->smb_ses_list) {
390 ses = list_entry(tmp2, struct cifs_ses,
393 if ((ses->serverDomain == NULL) ||
394 (ses->serverOS == NULL) ||
395 (ses->serverNOS == NULL)) {
396 seq_printf(m, "\n\t%d) Address: %s Uses: %d Capability: 0x%x\tSession Status: %d ",
397 i, ses->ip_addr, ses->ses_count,
398 ses->capabilities, ses->status);
399 if (ses->session_flags & SMB2_SESSION_FLAG_IS_GUEST)
400 seq_printf(m, "Guest ");
401 else if (ses->session_flags & SMB2_SESSION_FLAG_IS_NULL)
402 seq_printf(m, "Anonymous ");
405 "\n\t%d) Name: %s Domain: %s Uses: %d OS: %s "
406 "\n\tNOS: %s\tCapability: 0x%x"
407 "\n\tSMB session status: %d ",
408 i, ses->ip_addr, ses->serverDomain,
409 ses->ses_count, ses->serverOS, ses->serverNOS,
410 ses->capabilities, ses->status);
413 seq_printf(m, "\n\tSecurity type: %s ",
414 get_security_type_str(server->ops->select_sectype(server, ses->sectype)));
416 /* dump session id helpful for use with network trace */
417 seq_printf(m, " SessionId: 0x%llx", ses->Suid);
418 if (ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA)
419 seq_puts(m, " encrypted");
421 seq_puts(m, " signed");
423 seq_printf(m, "\n\tUser: %d Cred User: %d",
424 from_kuid(&init_user_ns, ses->linux_uid),
425 from_kuid(&init_user_ns, ses->cred_uid));
427 if (ses->chan_count > 1) {
428 seq_printf(m, "\n\n\tExtra Channels: %zu ",
430 for (j = 1; j < ses->chan_count; j++)
431 cifs_dump_channel(m, j, &ses->chans[j]);
434 seq_puts(m, "\n\n\tShares: ");
437 seq_printf(m, "\n\t%d) IPC: ", j);
439 cifs_debug_tcon(m, ses->tcon_ipc);
441 seq_puts(m, "none\n");
443 list_for_each(tmp3, &ses->tcon_list) {
444 tcon = list_entry(tmp3, struct cifs_tcon,
447 seq_printf(m, "\n\t%d) ", j);
448 cifs_debug_tcon(m, tcon);
451 spin_lock(&ses->iface_lock);
452 if (ses->iface_count)
453 seq_printf(m, "\n\n\tServer interfaces: %zu",
455 for (j = 0; j < ses->iface_count; j++) {
456 struct cifs_server_iface *iface;
458 iface = &ses->iface_list[j];
459 seq_printf(m, "\n\t%d)", j+1);
460 cifs_dump_iface(m, iface);
461 if (is_ses_using_iface(ses, iface))
462 seq_puts(m, "\t\t[CONNECTED]\n");
464 spin_unlock(&ses->iface_lock);
467 seq_printf(m, "\n\t\t[NONE]");
469 seq_puts(m, "\n\n\tMIDs: ");
470 spin_lock(&GlobalMid_Lock);
471 list_for_each(tmp3, &server->pending_mid_q) {
472 mid_entry = list_entry(tmp3, struct mid_q_entry,
474 seq_printf(m, "\n\tState: %d com: %d pid:"
475 " %d cbdata: %p mid %llu\n",
476 mid_entry->mid_state,
477 le16_to_cpu(mid_entry->command),
479 mid_entry->callback_data,
482 spin_unlock(&GlobalMid_Lock);
483 seq_printf(m, "\n--\n");
486 seq_printf(m, "\n\t[NONE]");
488 spin_unlock(&cifs_tcp_ses_lock);
492 /* BB add code to dump additional info such as TCP session info now */
496 static ssize_t cifs_stats_proc_write(struct file *file,
497 const char __user *buffer, size_t count, loff_t *ppos)
501 struct list_head *tmp1, *tmp2, *tmp3;
502 struct TCP_Server_Info *server;
503 struct cifs_ses *ses;
504 struct cifs_tcon *tcon;
506 rc = kstrtobool_from_user(buffer, count, &bv);
508 #ifdef CONFIG_CIFS_STATS2
511 atomic_set(&totBufAllocCount, 0);
512 atomic_set(&totSmBufAllocCount, 0);
513 #endif /* CONFIG_CIFS_STATS2 */
514 atomic_set(&tcpSesReconnectCount, 0);
515 atomic_set(&tconInfoReconnectCount, 0);
517 spin_lock(&GlobalMid_Lock);
518 GlobalMaxActiveXid = 0;
519 GlobalCurrentXid = 0;
520 spin_unlock(&GlobalMid_Lock);
521 spin_lock(&cifs_tcp_ses_lock);
522 list_for_each(tmp1, &cifs_tcp_ses_list) {
523 server = list_entry(tmp1, struct TCP_Server_Info,
525 server->max_in_flight = 0;
526 #ifdef CONFIG_CIFS_STATS2
527 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
528 atomic_set(&server->num_cmds[i], 0);
529 atomic_set(&server->smb2slowcmd[i], 0);
530 server->time_per_cmd[i] = 0;
531 server->slowest_cmd[i] = 0;
532 server->fastest_cmd[0] = 0;
534 #endif /* CONFIG_CIFS_STATS2 */
535 list_for_each(tmp2, &server->smb_ses_list) {
536 ses = list_entry(tmp2, struct cifs_ses,
538 list_for_each(tmp3, &ses->tcon_list) {
539 tcon = list_entry(tmp3,
542 atomic_set(&tcon->num_smbs_sent, 0);
543 spin_lock(&tcon->stat_lock);
544 tcon->bytes_read = 0;
545 tcon->bytes_written = 0;
546 spin_unlock(&tcon->stat_lock);
547 if (server->ops->clear_stats)
548 server->ops->clear_stats(tcon);
552 spin_unlock(&cifs_tcp_ses_lock);
560 static int cifs_stats_proc_show(struct seq_file *m, void *v)
563 #ifdef CONFIG_CIFS_STATS2
566 struct list_head *tmp1, *tmp2, *tmp3;
567 struct TCP_Server_Info *server;
568 struct cifs_ses *ses;
569 struct cifs_tcon *tcon;
571 seq_printf(m, "Resources in use\nCIFS Session: %d\n",
572 sesInfoAllocCount.counter);
573 seq_printf(m, "Share (unique mount targets): %d\n",
574 tconInfoAllocCount.counter);
575 seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
576 bufAllocCount.counter,
577 cifs_min_rcv + tcpSesAllocCount.counter);
578 seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
579 smBufAllocCount.counter, cifs_min_small);
580 #ifdef CONFIG_CIFS_STATS2
581 seq_printf(m, "Total Large %d Small %d Allocations\n",
582 atomic_read(&totBufAllocCount),
583 atomic_read(&totSmBufAllocCount));
584 #endif /* CONFIG_CIFS_STATS2 */
586 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
588 "\n%d session %d share reconnects\n",
589 tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
592 "Total vfs operations: %d maximum at one time: %d\n",
593 GlobalCurrentXid, GlobalMaxActiveXid);
596 spin_lock(&cifs_tcp_ses_lock);
597 list_for_each(tmp1, &cifs_tcp_ses_list) {
598 server = list_entry(tmp1, struct TCP_Server_Info,
600 seq_printf(m, "\nMax requests in flight: %d", server->max_in_flight);
601 #ifdef CONFIG_CIFS_STATS2
602 seq_puts(m, "\nTotal time spent processing by command. Time ");
603 seq_printf(m, "units are jiffies (%d per second)\n", HZ);
604 seq_puts(m, " SMB3 CMD\tNumber\tTotal Time\tFastest\tSlowest\n");
605 seq_puts(m, " --------\t------\t----------\t-------\t-------\n");
606 for (j = 0; j < NUMBER_OF_SMB2_COMMANDS; j++)
607 seq_printf(m, " %d\t\t%d\t%llu\t\t%u\t%u\n", j,
608 atomic_read(&server->num_cmds[j]),
609 server->time_per_cmd[j],
610 server->fastest_cmd[j],
611 server->slowest_cmd[j]);
612 for (j = 0; j < NUMBER_OF_SMB2_COMMANDS; j++)
613 if (atomic_read(&server->smb2slowcmd[j]))
614 seq_printf(m, " %d slow responses from %s for command %d\n",
615 atomic_read(&server->smb2slowcmd[j]),
616 server->hostname, j);
618 list_for_each(tmp2, &server->smb_ses_list) {
619 ses = list_entry(tmp2, struct cifs_ses,
621 list_for_each(tmp3, &ses->tcon_list) {
622 tcon = list_entry(tmp3,
626 seq_printf(m, "\n%d) %s", i, tcon->treeName);
627 if (tcon->need_reconnect)
628 seq_puts(m, "\tDISCONNECTED ");
629 seq_printf(m, "\nSMBs: %d",
630 atomic_read(&tcon->num_smbs_sent));
631 if (server->ops->print_stats)
632 server->ops->print_stats(m, tcon);
636 spin_unlock(&cifs_tcp_ses_lock);
642 static int cifs_stats_proc_open(struct inode *inode, struct file *file)
644 return single_open(file, cifs_stats_proc_show, NULL);
647 static const struct proc_ops cifs_stats_proc_ops = {
648 .proc_open = cifs_stats_proc_open,
649 .proc_read = seq_read,
650 .proc_lseek = seq_lseek,
651 .proc_release = single_release,
652 .proc_write = cifs_stats_proc_write,
655 #ifdef CONFIG_CIFS_SMB_DIRECT
656 #define PROC_FILE_DEFINE(name) \
657 static ssize_t name##_write(struct file *file, const char __user *buffer, \
658 size_t count, loff_t *ppos) \
661 rc = kstrtoint_from_user(buffer, count, 10, & name); \
666 static int name##_proc_show(struct seq_file *m, void *v) \
668 seq_printf(m, "%d\n", name ); \
671 static int name##_open(struct inode *inode, struct file *file) \
673 return single_open(file, name##_proc_show, NULL); \
676 static const struct proc_ops cifs_##name##_proc_fops = { \
677 .proc_open = name##_open, \
678 .proc_read = seq_read, \
679 .proc_lseek = seq_lseek, \
680 .proc_release = single_release, \
681 .proc_write = name##_write, \
684 PROC_FILE_DEFINE(rdma_readwrite_threshold);
685 PROC_FILE_DEFINE(smbd_max_frmr_depth);
686 PROC_FILE_DEFINE(smbd_keep_alive_interval);
687 PROC_FILE_DEFINE(smbd_max_receive_size);
688 PROC_FILE_DEFINE(smbd_max_fragmented_recv_size);
689 PROC_FILE_DEFINE(smbd_max_send_size);
690 PROC_FILE_DEFINE(smbd_send_credit_target);
691 PROC_FILE_DEFINE(smbd_receive_credit_max);
694 static struct proc_dir_entry *proc_fs_cifs;
695 static const struct proc_ops cifsFYI_proc_ops;
696 static const struct proc_ops cifs_lookup_cache_proc_ops;
697 static const struct proc_ops traceSMB_proc_ops;
698 static const struct proc_ops cifs_security_flags_proc_ops;
699 static const struct proc_ops cifs_linux_ext_proc_ops;
700 static const struct proc_ops cifs_mount_params_proc_ops;
705 proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
706 if (proc_fs_cifs == NULL)
709 proc_create_single("DebugData", 0, proc_fs_cifs,
710 cifs_debug_data_proc_show);
712 proc_create_single("open_files", 0400, proc_fs_cifs,
713 cifs_debug_files_proc_show);
715 proc_create("Stats", 0644, proc_fs_cifs, &cifs_stats_proc_ops);
716 proc_create("cifsFYI", 0644, proc_fs_cifs, &cifsFYI_proc_ops);
717 proc_create("traceSMB", 0644, proc_fs_cifs, &traceSMB_proc_ops);
718 proc_create("LinuxExtensionsEnabled", 0644, proc_fs_cifs,
719 &cifs_linux_ext_proc_ops);
720 proc_create("SecurityFlags", 0644, proc_fs_cifs,
721 &cifs_security_flags_proc_ops);
722 proc_create("LookupCacheEnabled", 0644, proc_fs_cifs,
723 &cifs_lookup_cache_proc_ops);
725 proc_create("mount_params", 0444, proc_fs_cifs, &cifs_mount_params_proc_ops);
727 #ifdef CONFIG_CIFS_DFS_UPCALL
728 proc_create("dfscache", 0644, proc_fs_cifs, &dfscache_proc_ops);
731 #ifdef CONFIG_CIFS_SMB_DIRECT
732 proc_create("rdma_readwrite_threshold", 0644, proc_fs_cifs,
733 &cifs_rdma_readwrite_threshold_proc_fops);
734 proc_create("smbd_max_frmr_depth", 0644, proc_fs_cifs,
735 &cifs_smbd_max_frmr_depth_proc_fops);
736 proc_create("smbd_keep_alive_interval", 0644, proc_fs_cifs,
737 &cifs_smbd_keep_alive_interval_proc_fops);
738 proc_create("smbd_max_receive_size", 0644, proc_fs_cifs,
739 &cifs_smbd_max_receive_size_proc_fops);
740 proc_create("smbd_max_fragmented_recv_size", 0644, proc_fs_cifs,
741 &cifs_smbd_max_fragmented_recv_size_proc_fops);
742 proc_create("smbd_max_send_size", 0644, proc_fs_cifs,
743 &cifs_smbd_max_send_size_proc_fops);
744 proc_create("smbd_send_credit_target", 0644, proc_fs_cifs,
745 &cifs_smbd_send_credit_target_proc_fops);
746 proc_create("smbd_receive_credit_max", 0644, proc_fs_cifs,
747 &cifs_smbd_receive_credit_max_proc_fops);
752 cifs_proc_clean(void)
754 if (proc_fs_cifs == NULL)
757 remove_proc_entry("DebugData", proc_fs_cifs);
758 remove_proc_entry("open_files", proc_fs_cifs);
759 remove_proc_entry("cifsFYI", proc_fs_cifs);
760 remove_proc_entry("traceSMB", proc_fs_cifs);
761 remove_proc_entry("Stats", proc_fs_cifs);
762 remove_proc_entry("SecurityFlags", proc_fs_cifs);
763 remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
764 remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
765 remove_proc_entry("mount_params", proc_fs_cifs);
767 #ifdef CONFIG_CIFS_DFS_UPCALL
768 remove_proc_entry("dfscache", proc_fs_cifs);
770 #ifdef CONFIG_CIFS_SMB_DIRECT
771 remove_proc_entry("rdma_readwrite_threshold", proc_fs_cifs);
772 remove_proc_entry("smbd_max_frmr_depth", proc_fs_cifs);
773 remove_proc_entry("smbd_keep_alive_interval", proc_fs_cifs);
774 remove_proc_entry("smbd_max_receive_size", proc_fs_cifs);
775 remove_proc_entry("smbd_max_fragmented_recv_size", proc_fs_cifs);
776 remove_proc_entry("smbd_max_send_size", proc_fs_cifs);
777 remove_proc_entry("smbd_send_credit_target", proc_fs_cifs);
778 remove_proc_entry("smbd_receive_credit_max", proc_fs_cifs);
780 remove_proc_entry("fs/cifs", NULL);
783 static int cifsFYI_proc_show(struct seq_file *m, void *v)
785 seq_printf(m, "%d\n", cifsFYI);
789 static int cifsFYI_proc_open(struct inode *inode, struct file *file)
791 return single_open(file, cifsFYI_proc_show, NULL);
794 static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
795 size_t count, loff_t *ppos)
797 char c[2] = { '\0' };
801 rc = get_user(c[0], buffer);
804 if (strtobool(c, &bv) == 0)
806 else if ((c[0] > '1') && (c[0] <= '9'))
807 cifsFYI = (int) (c[0] - '0'); /* see cifs_debug.h for meanings */
814 static const struct proc_ops cifsFYI_proc_ops = {
815 .proc_open = cifsFYI_proc_open,
816 .proc_read = seq_read,
817 .proc_lseek = seq_lseek,
818 .proc_release = single_release,
819 .proc_write = cifsFYI_proc_write,
822 static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
824 seq_printf(m, "%d\n", linuxExtEnabled);
828 static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
830 return single_open(file, cifs_linux_ext_proc_show, NULL);
833 static ssize_t cifs_linux_ext_proc_write(struct file *file,
834 const char __user *buffer, size_t count, loff_t *ppos)
838 rc = kstrtobool_from_user(buffer, count, &linuxExtEnabled);
845 static const struct proc_ops cifs_linux_ext_proc_ops = {
846 .proc_open = cifs_linux_ext_proc_open,
847 .proc_read = seq_read,
848 .proc_lseek = seq_lseek,
849 .proc_release = single_release,
850 .proc_write = cifs_linux_ext_proc_write,
853 static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
855 seq_printf(m, "%d\n", lookupCacheEnabled);
859 static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
861 return single_open(file, cifs_lookup_cache_proc_show, NULL);
864 static ssize_t cifs_lookup_cache_proc_write(struct file *file,
865 const char __user *buffer, size_t count, loff_t *ppos)
869 rc = kstrtobool_from_user(buffer, count, &lookupCacheEnabled);
876 static const struct proc_ops cifs_lookup_cache_proc_ops = {
877 .proc_open = cifs_lookup_cache_proc_open,
878 .proc_read = seq_read,
879 .proc_lseek = seq_lseek,
880 .proc_release = single_release,
881 .proc_write = cifs_lookup_cache_proc_write,
884 static int traceSMB_proc_show(struct seq_file *m, void *v)
886 seq_printf(m, "%d\n", traceSMB);
890 static int traceSMB_proc_open(struct inode *inode, struct file *file)
892 return single_open(file, traceSMB_proc_show, NULL);
895 static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
896 size_t count, loff_t *ppos)
900 rc = kstrtobool_from_user(buffer, count, &traceSMB);
907 static const struct proc_ops traceSMB_proc_ops = {
908 .proc_open = traceSMB_proc_open,
909 .proc_read = seq_read,
910 .proc_lseek = seq_lseek,
911 .proc_release = single_release,
912 .proc_write = traceSMB_proc_write,
915 static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
917 seq_printf(m, "0x%x\n", global_secflags);
921 static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
923 return single_open(file, cifs_security_flags_proc_show, NULL);
927 * Ensure that if someone sets a MUST flag, that we disable all other MAY
928 * flags except for the ones corresponding to the given MUST flag. If there are
929 * multiple MUST flags, then try to prefer more secure ones.
932 cifs_security_flags_handle_must_flags(unsigned int *flags)
934 unsigned int signflags = *flags & CIFSSEC_MUST_SIGN;
936 if ((*flags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5)
937 *flags = CIFSSEC_MUST_KRB5;
938 else if ((*flags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP)
939 *flags = CIFSSEC_MUST_NTLMSSP;
940 else if ((*flags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2)
941 *flags = CIFSSEC_MUST_NTLMV2;
942 else if ((*flags & CIFSSEC_MUST_NTLM) == CIFSSEC_MUST_NTLM)
943 *flags = CIFSSEC_MUST_NTLM;
944 else if (CIFSSEC_MUST_LANMAN &&
945 (*flags & CIFSSEC_MUST_LANMAN) == CIFSSEC_MUST_LANMAN)
946 *flags = CIFSSEC_MUST_LANMAN;
947 else if (CIFSSEC_MUST_PLNTXT &&
948 (*flags & CIFSSEC_MUST_PLNTXT) == CIFSSEC_MUST_PLNTXT)
949 *flags = CIFSSEC_MUST_PLNTXT;
954 static ssize_t cifs_security_flags_proc_write(struct file *file,
955 const char __user *buffer, size_t count, loff_t *ppos)
959 char flags_string[12];
962 if ((count < 1) || (count > 11))
965 memset(flags_string, 0, 12);
967 if (copy_from_user(flags_string, buffer, count))
971 /* single char or single char followed by null */
972 if (strtobool(flags_string, &bv) == 0) {
973 global_secflags = bv ? CIFSSEC_MAX : CIFSSEC_DEF;
975 } else if (!isdigit(flags_string[0])) {
976 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
982 /* else we have a number */
983 rc = kstrtouint(flags_string, 0, &flags);
985 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
990 cifs_dbg(FYI, "sec flags 0x%x\n", flags);
993 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", flags_string);
997 if (flags & ~CIFSSEC_MASK) {
998 cifs_dbg(VFS, "Unsupported security flags: 0x%x\n",
999 flags & ~CIFSSEC_MASK);
1003 cifs_security_flags_handle_must_flags(&flags);
1005 /* flags look ok - update the global security flags for cifs module */
1006 global_secflags = flags;
1007 if (global_secflags & CIFSSEC_MUST_SIGN) {
1008 /* requiring signing implies signing is allowed */
1009 global_secflags |= CIFSSEC_MAY_SIGN;
1010 cifs_dbg(FYI, "packet signing now required\n");
1011 } else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) {
1012 cifs_dbg(FYI, "packet signing disabled\n");
1014 /* BB should we turn on MAY flags for other MUST options? */
1018 static const struct proc_ops cifs_security_flags_proc_ops = {
1019 .proc_open = cifs_security_flags_proc_open,
1020 .proc_read = seq_read,
1021 .proc_lseek = seq_lseek,
1022 .proc_release = single_release,
1023 .proc_write = cifs_security_flags_proc_write,
1026 /* To make it easier to debug, can help to show mount params */
1027 static int cifs_mount_params_proc_show(struct seq_file *m, void *v)
1029 const struct fs_parameter_spec *p;
1032 for (p = smb3_fs_parameters; p->name; p++) {
1033 /* cannot use switch with pointers... */
1035 if (p->flags == fs_param_neg_with_no)
1039 } else if (p->type == fs_param_is_bool)
1041 else if (p->type == fs_param_is_u32)
1043 else if (p->type == fs_param_is_u64)
1045 else if (p->type == fs_param_is_string)
1050 seq_printf(m, "%s:%s\n", p->name, type);
1056 static int cifs_mount_params_proc_open(struct inode *inode, struct file *file)
1058 return single_open(file, cifs_mount_params_proc_show, NULL);
1061 static const struct proc_ops cifs_mount_params_proc_ops = {
1062 .proc_open = cifs_mount_params_proc_open,
1063 .proc_read = seq_read,
1064 .proc_lseek = seq_lseek,
1065 .proc_release = single_release,
1066 /* No need for write for now */
1067 /* .proc_write = cifs_mount_params_proc_write, */
1071 inline void cifs_proc_init(void)
1075 inline void cifs_proc_clean(void)
1078 #endif /* PROC_FS */