blob: f1fbea947fef6ddedcefe1c9f1c1dd4224f33618 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/cifs_debug.c
3 *
Steve Frenchb8643e12005-04-28 22:41:07 -07004 * Copyright (C) International Business Machines Corp., 2000,2005
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
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
Steve French221601c2007-06-05 20:35:06 +000010 * the Free Software Foundation; either version 2 of the License, or
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 * (at your option) any later version.
Steve French221601c2007-06-05 20:35:06 +000012 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 * 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
Steve French221601c2007-06-05 20:35:06 +000019 * along with this program; if not, write to the Free Software
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 * 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>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080027#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include "cifspdu.h"
29#include "cifsglob.h"
30#include "cifsproto.h"
31#include "cifs_debug.h"
Steve French6c91d362005-04-28 22:41:06 -070032#include "cifsfs.h"
Long Lid8ec9132017-11-07 01:54:58 -070033#ifdef CONFIG_CIFS_SMB_DIRECT
34#include "smbdirect.h"
35#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37void
38cifs_dump_mem(char *label, void *data, int length)
39{
Andy Shevchenko0b456f02014-08-27 16:49:44 +030040 pr_debug("%s: dump of %d bytes of data at 0x%p\n", label, length, data);
Andy Shevchenko55d83e02014-08-27 16:49:43 +030041 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 4,
42 data, length, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043}
44
Ronnie Sahlberg14547f72018-04-22 14:45:53 -060045void cifs_dump_detail(void *buf, struct TCP_Server_Info *server)
Steve French39798772006-05-31 22:40:51 +000046{
Pavel Shilovsky8aa26f32012-05-17 13:25:35 +040047#ifdef CONFIG_CIFS_DEBUG2
Pavel Shilovskyd4e48542012-03-23 14:28:02 -040048 struct smb_hdr *smb = (struct smb_hdr *)buf;
49
Joe Perchesf96637b2013-05-04 22:12:25 -050050 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);
Ronnie Sahlberg14547f72018-04-22 14:45:53 -060053 cifs_dbg(VFS, "smb buf %p len %u\n", smb,
Steve French71992e622018-05-06 15:58:51 -050054 server->ops->calc_smb_size(smb, server));
Pavel Shilovsky8aa26f32012-05-17 13:25:35 +040055#endif /* CONFIG_CIFS_DEBUG2 */
Steve French39798772006-05-31 22:40:51 +000056}
57
Steve Frenchffdd6e42007-06-24 21:15:44 +000058void cifs_dump_mids(struct TCP_Server_Info *server)
Steve French39798772006-05-31 22:40:51 +000059{
Pavel Shilovsky8aa26f32012-05-17 13:25:35 +040060#ifdef CONFIG_CIFS_DEBUG2
Steve French39798772006-05-31 22:40:51 +000061 struct list_head *tmp;
Steve Frenchffdd6e42007-06-24 21:15:44 +000062 struct mid_q_entry *mid_entry;
Steve French39798772006-05-31 22:40:51 +000063
Steve French221601c2007-06-05 20:35:06 +000064 if (server == NULL)
Steve French39798772006-05-31 22:40:51 +000065 return;
66
Joe Perchesf96637b2013-05-04 22:12:25 -050067 cifs_dbg(VFS, "Dump pending requests:\n");
Steve French39798772006-05-31 22:40:51 +000068 spin_lock(&GlobalMid_Lock);
69 list_for_each(tmp, &server->pending_mid_q) {
70 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
Joe Perchesf96637b2013-05-04 22:12:25 -050071 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);
Steve French39798772006-05-31 22:40:51 +000077#ifdef CONFIG_CIFS_STATS2
Joe Perchesf96637b2013-05-04 22:12:25 -050078 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);
Steve French39798772006-05-31 22:40:51 +000083#endif /* STATS2 */
Joe Perchesf96637b2013-05-04 22:12:25 -050084 cifs_dbg(VFS, "IsMult: %d IsEnd: %d\n",
85 mid_entry->multiRsp, mid_entry->multiEnd);
Steve Frenchad8b15f2008-08-08 21:10:16 +000086 if (mid_entry->resp_buf) {
Steve French71992e622018-05-06 15:58:51 -050087 cifs_dump_detail(mid_entry->resp_buf, server);
Steve Frenchad8b15f2008-08-08 21:10:16 +000088 cifs_dump_mem("existing buf: ",
89 mid_entry->resp_buf, 62);
Steve French39798772006-05-31 22:40:51 +000090 }
91 }
92 spin_unlock(&GlobalMid_Lock);
Steve French39798772006-05-31 22:40:51 +000093#endif /* CONFIG_CIFS_DEBUG2 */
Pavel Shilovsky8aa26f32012-05-17 13:25:35 +040094}
Steve French39798772006-05-31 22:40:51 +000095
Linus Torvalds1da177e2005-04-16 15:20:36 -070096#ifdef CONFIG_PROC_FS
Aurelien Aptel02cf5902018-01-24 13:46:12 +010097static 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);
Steve Frenchede2e522018-01-31 14:34:37 -0600115 if (tcon->seal)
116 seq_printf(m, " Encrypted");
Steve French5c5a41b2018-05-30 17:11:55 -0500117 if (tcon->nocase)
118 seq_printf(m, " nocase");
Steve Frenchede2e522018-01-31 14:34:37 -0600119 if (tcon->unix_ext)
120 seq_printf(m, " POSIX Extensions");
Aurelien Aptel02cf5902018-01-24 13:46:12 +0100121 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
Aurelien Aptelbc0fe8b2018-06-14 15:43:20 +0200129static 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
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000148static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149{
Jeff Laytonf1987b42008-11-15 11:12:47 -0500150 struct list_head *tmp1, *tmp2, *tmp3;
Steve Frenchffdd6e42007-06-24 21:15:44 +0000151 struct mid_q_entry *mid_entry;
Jeff Layton14fbf502008-11-14 13:53:46 -0500152 struct TCP_Server_Info *server;
Steve French96daf2b2011-05-27 04:34:02 +0000153 struct cifs_ses *ses;
154 struct cifs_tcon *tcon;
Jeff Laytonf1987b42008-11-15 11:12:47 -0500155 int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000157 seq_puts(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 "Display Internal CIFS Data Structures for Debugging\n"
159 "---------------------------------------------------\n");
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000160 seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
Jeff Laytonca40b712011-01-07 11:30:29 -0500161 seq_printf(m, "Features:");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530162#ifdef CONFIG_CIFS_DFS_UPCALL
Steve French950132a2018-06-28 18:46:40 -0500163 seq_printf(m, " DFS");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530164#endif
165#ifdef CONFIG_CIFS_FSCACHE
Steve French950132a2018-06-28 18:46:40 -0500166 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");
Steve Frenchd2586502018-08-01 22:34:04 -0500173#else
Steve French950132a2018-06-28 18:46:40 -0500174 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");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530183#endif
184#ifdef CONFIG_CIFS_WEAK_PW_HASH
Steve French950132a2018-06-28 18:46:40 -0500185 seq_printf(m, ",WEAK_PW_HASH");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530186#endif
187#ifdef CONFIG_CIFS_POSIX
Steve French950132a2018-06-28 18:46:40 -0500188 seq_printf(m, ",CIFS_POSIX");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530189#endif
190#ifdef CONFIG_CIFS_UPCALL
Steve French950132a2018-06-28 18:46:40 -0500191 seq_printf(m, ",UPCALL(SPNEGO)");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530192#endif
193#ifdef CONFIG_CIFS_XATTR
Steve French950132a2018-06-28 18:46:40 -0500194 seq_printf(m, ",XATTR");
Jeff Laytonca40b712011-01-07 11:30:29 -0500195#endif
196#ifdef CONFIG_CIFS_ACL
Steve French950132a2018-06-28 18:46:40 -0500197 seq_printf(m, ",ACL");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530198#endif
199 seq_putc(m, '\n');
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000200 seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
201 seq_printf(m, "Servers:");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
203 i = 0;
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530204 spin_lock(&cifs_tcp_ses_lock);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500205 list_for_each(tmp1, &cifs_tcp_ses_list) {
206 server = list_entry(tmp1, struct TCP_Server_Info,
Jeff Layton14fbf502008-11-14 13:53:46 -0500207 tcp_ses_list);
Long Li08a3b962017-11-22 17:38:48 -0700208
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
Steve Frenchede2e522018-01-31 14:34:37 -0600274 seq_printf(m, "\nNumber of credits: %d Dialect 0x%x",
275 server->credits, server->dialect);
276 if (server->sign)
277 seq_printf(m, " signed");
Steve Frenchfcef0db2018-05-19 20:45:27 -0500278 if (server->posix_ext_supported)
279 seq_printf(m, " posix");
Steve French0fdfef92018-06-28 19:30:23 -0500280
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 i++;
Jeff Layton14fbf502008-11-14 13:53:46 -0500282 list_for_each(tmp2, &server->smb_ses_list) {
Steve French96daf2b2011-05-27 04:34:02 +0000283 ses = list_entry(tmp2, struct cifs_ses,
Jeff Layton14fbf502008-11-14 13:53:46 -0500284 smb_ses_list);
285 if ((ses->serverDomain == NULL) ||
286 (ses->serverOS == NULL) ||
287 (ses->serverNOS == NULL)) {
Steve French1fa089e2017-09-20 16:46:49 -0500288 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");
Jeff Layton14fbf502008-11-14 13:53:46 -0500295 } else {
296 seq_printf(m,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500297 "\n%d) Name: %s Domain: %s Uses: %d OS:"
298 " %s\n\tNOS: %s\tCapability: 0x%x\n\tSMB"
Steve French221601c2007-06-05 20:35:06 +0000299 " session status: %d\t",
Steve Frenchb8643e12005-04-28 22:41:07 -0700300 i, ses->serverName, ses->serverDomain,
Jeff Layton14fbf502008-11-14 13:53:46 -0500301 ses->ses_count, ses->serverOS, ses->serverNOS,
Steve French221601c2007-06-05 20:35:06 +0000302 ses->capabilities, ses->status);
Jeff Layton14fbf502008-11-14 13:53:46 -0500303 }
Long Li8339dd32017-11-07 01:54:55 -0700304 if (server->rdma)
305 seq_printf(m, "RDMA\n\t");
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000306 seq_printf(m, "TCP status: %d\n\tLocal Users To "
Jeff Layton14fbf502008-11-14 13:53:46 -0500307 "Server: %d SecMode: 0x%x Req On Wire: %d",
308 server->tcpStatus, server->srv_count,
Pavel Shilovskyfc40f9c2012-02-17 17:09:12 +0300309 server->sec_mode, in_flight(server));
Steve French131afd0b2005-10-07 09:51:05 -0700310
311#ifdef CONFIG_CIFS_STATS2
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000312 seq_printf(m, " In Send: %d In MaxReq Wait: %d",
Steve French789e6662011-08-09 18:44:44 +0000313 atomic_read(&server->in_send),
Jeff Layton14fbf502008-11-14 13:53:46 -0500314 atomic_read(&server->num_waiters));
Steve French131afd0b2005-10-07 09:51:05 -0700315#endif
316
Jeff Laytonf1987b42008-11-15 11:12:47 -0500317 seq_puts(m, "\n\tShares:");
318 j = 0;
Aurelien Aptel02cf5902018-01-24 13:46:12 +0100319
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
Jeff Laytonf1987b42008-11-15 11:12:47 -0500326 list_for_each(tmp3, &ses->tcon_list) {
Steve French96daf2b2011-05-27 04:34:02 +0000327 tcon = list_entry(tmp3, struct cifs_tcon,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500328 tcon_list);
329 ++j;
Aurelien Aptel02cf5902018-01-24 13:46:12 +0100330 seq_printf(m, "\n\t%d) ", j);
331 cifs_debug_tcon(m, tcon);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500332 }
333
334 seq_puts(m, "\n\tMIDs:\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
336 spin_lock(&GlobalMid_Lock);
Jeff Layton14fbf502008-11-14 13:53:46 -0500337 list_for_each(tmp3, &server->pending_mid_q) {
Jeff Laytonf1987b42008-11-15 11:12:47 -0500338 mid_entry = list_entry(tmp3, struct mid_q_entry,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 qhead);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500340 seq_printf(m, "\tState: %d com: %d pid:"
Pavel Shilovsky7c9421e2012-03-23 14:28:03 -0400341 " %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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 }
Steve French221601c2007-06-05 20:35:06 +0000348 spin_unlock(&GlobalMid_Lock);
Aurelien Aptelbc0fe8b2018-06-14 15:43:20 +0200349
350 spin_lock(&ses->iface_lock);
Steve French115d5d22018-06-14 21:59:31 -0500351 if (ses->iface_count)
352 seq_printf(m, "\n\tServer interfaces: %zu\n",
353 ses->iface_count);
Aurelien Aptelbc0fe8b2018-06-14 15:43:20 +0200354 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 }
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530361 spin_unlock(&cifs_tcp_ses_lock);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000362 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 /* BB add code to dump additional info such as TCP session info now */
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000365 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366}
367
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000368static ssize_t cifs_stats_proc_write(struct file *file,
369 const char __user *buffer, size_t count, loff_t *ppos)
Steve French1047abc2005-10-11 19:58:06 -0700370{
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300371 bool bv;
Steve French221601c2007-06-05 20:35:06 +0000372 int rc;
Jeff Laytonf1987b42008-11-15 11:12:47 -0500373 struct list_head *tmp1, *tmp2, *tmp3;
374 struct TCP_Server_Info *server;
Steve French96daf2b2011-05-27 04:34:02 +0000375 struct cifs_ses *ses;
376 struct cifs_tcon *tcon;
Steve French1047abc2005-10-11 19:58:06 -0700377
Kees Cook14042972016-03-17 14:22:54 -0700378 rc = kstrtobool_from_user(buffer, count, &bv);
379 if (rc == 0) {
Steve French4498eed52005-12-03 13:58:57 -0800380#ifdef CONFIG_CIFS_STATS2
Steve French468d6772018-08-04 05:24:34 -0500381 int i;
382
Steve French4498eed52005-12-03 13:58:57 -0800383 atomic_set(&totBufAllocCount, 0);
384 atomic_set(&totSmBufAllocCount, 0);
385#endif /* CONFIG_CIFS_STATS2 */
Steve Frenchc281bc02018-08-01 00:56:12 -0500386 spin_lock(&GlobalMid_Lock);
387 GlobalMaxActiveXid = 0;
388 GlobalCurrentXid = 0;
389 spin_unlock(&GlobalMid_Lock);
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530390 spin_lock(&cifs_tcp_ses_lock);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500391 list_for_each(tmp1, &cifs_tcp_ses_list) {
392 server = list_entry(tmp1, struct TCP_Server_Info,
393 tcp_ses_list);
Steve French468d6772018-08-04 05:24:34 -0500394#ifdef CONFIG_CIFS_STATS2
395 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++)
396 atomic_set(&server->smb2slowcmd[i], 0);
397#endif /* CONFIG_CIFS_STATS2 */
Steve Frenchc2b33822008-11-17 03:57:13 +0000398 list_for_each(tmp2, &server->smb_ses_list) {
Steve French96daf2b2011-05-27 04:34:02 +0000399 ses = list_entry(tmp2, struct cifs_ses,
Steve Frenchc2b33822008-11-17 03:57:13 +0000400 smb_ses_list);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500401 list_for_each(tmp3, &ses->tcon_list) {
402 tcon = list_entry(tmp3,
Steve French96daf2b2011-05-27 04:34:02 +0000403 struct cifs_tcon,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500404 tcon_list);
405 atomic_set(&tcon->num_smbs_sent, 0);
Steve Frenchc281bc02018-08-01 00:56:12 -0500406 spin_lock(&tcon->stat_lock);
407 tcon->bytes_read = 0;
408 tcon->bytes_written = 0;
409 spin_unlock(&tcon->stat_lock);
Pavel Shilovsky44c58182012-05-28 14:16:31 +0400410 if (server->ops->clear_stats)
411 server->ops->clear_stats(tcon);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500412 }
413 }
Steve French1047abc2005-10-11 19:58:06 -0700414 }
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530415 spin_unlock(&cifs_tcp_ses_lock);
Kees Cook14042972016-03-17 14:22:54 -0700416 } else {
417 return rc;
Steve French1047abc2005-10-11 19:58:06 -0700418 }
419
Steve French221601c2007-06-05 20:35:06 +0000420 return count;
Steve French1047abc2005-10-11 19:58:06 -0700421}
422
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000423static int cifs_stats_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000425 int i;
Steve French468d6772018-08-04 05:24:34 -0500426#ifdef CONFIG_CIFS_STATS2
427 int j;
428#endif /* STATS2 */
Jeff Laytonf1987b42008-11-15 11:12:47 -0500429 struct list_head *tmp1, *tmp2, *tmp3;
430 struct TCP_Server_Info *server;
Steve French96daf2b2011-05-27 04:34:02 +0000431 struct cifs_ses *ses;
432 struct cifs_tcon *tcon;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
Steve French468d6772018-08-04 05:24:34 -0500434 seq_printf(m, "Resources in use\nCIFS Session: %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 sesInfoAllocCount.counter);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000436 seq_printf(m, "Share (unique mount targets): %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 tconInfoAllocCount.counter);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000438 seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
Steve Frenchb8643e12005-04-28 22:41:07 -0700439 bufAllocCount.counter,
440 cifs_min_rcv + tcpSesAllocCount.counter);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000441 seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
Steve French221601c2007-06-05 20:35:06 +0000442 smBufAllocCount.counter, cifs_min_small);
Steve French07475ff2005-12-03 14:11:37 -0800443#ifdef CONFIG_CIFS_STATS2
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000444 seq_printf(m, "Total Large %d Small %d Allocations\n",
Steve French07475ff2005-12-03 14:11:37 -0800445 atomic_read(&totBufAllocCount),
Steve French221601c2007-06-05 20:35:06 +0000446 atomic_read(&totSmBufAllocCount));
Steve French07475ff2005-12-03 14:11:37 -0800447#endif /* CONFIG_CIFS_STATS2 */
448
Jeff Layton80975312011-01-11 07:24:02 -0500449 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000450 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 "\n%d session %d share reconnects\n",
Steve French221601c2007-06-05 20:35:06 +0000452 tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000454 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 "Total vfs operations: %d maximum at one time: %d\n",
Steve French221601c2007-06-05 20:35:06 +0000456 GlobalCurrentXid, GlobalMaxActiveXid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
458 i = 0;
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530459 spin_lock(&cifs_tcp_ses_lock);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500460 list_for_each(tmp1, &cifs_tcp_ses_list) {
461 server = list_entry(tmp1, struct TCP_Server_Info,
462 tcp_ses_list);
Steve French468d6772018-08-04 05:24:34 -0500463#ifdef CONFIG_CIFS_STATS2
464 for (j = 0; j < NUMBER_OF_SMB2_COMMANDS; j++)
465 if (atomic_read(&server->smb2slowcmd[j]))
466 seq_printf(m, "%d slow responses from %s for command %d\n",
467 atomic_read(&server->smb2slowcmd[j]),
468 server->hostname, j);
469#endif /* STATS2 */
Jeff Laytonf1987b42008-11-15 11:12:47 -0500470 list_for_each(tmp2, &server->smb_ses_list) {
Steve French96daf2b2011-05-27 04:34:02 +0000471 ses = list_entry(tmp2, struct cifs_ses,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500472 smb_ses_list);
473 list_for_each(tmp3, &ses->tcon_list) {
474 tcon = list_entry(tmp3,
Steve French96daf2b2011-05-27 04:34:02 +0000475 struct cifs_tcon,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500476 tcon_list);
477 i++;
478 seq_printf(m, "\n%d) %s", i, tcon->treeName);
479 if (tcon->need_reconnect)
480 seq_puts(m, "\tDISCONNECTED ");
Pavel Shilovsky44c58182012-05-28 14:16:31 +0400481 seq_printf(m, "\nSMBs: %d",
482 atomic_read(&tcon->num_smbs_sent));
483 if (server->ops->print_stats)
484 server->ops->print_stats(m, tcon);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500485 }
486 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 }
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530488 spin_unlock(&cifs_tcp_ses_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000490 seq_putc(m, '\n');
491 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000493
494static int cifs_stats_proc_open(struct inode *inode, struct file *file)
495{
496 return single_open(file, cifs_stats_proc_show, NULL);
497}
498
499static const struct file_operations cifs_stats_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000500 .open = cifs_stats_proc_open,
501 .read = seq_read,
502 .llseek = seq_lseek,
503 .release = single_release,
504 .write = cifs_stats_proc_write,
505};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
Long Lid8ec9132017-11-07 01:54:58 -0700507#ifdef CONFIG_CIFS_SMB_DIRECT
508#define PROC_FILE_DEFINE(name) \
509static ssize_t name##_write(struct file *file, const char __user *buffer, \
510 size_t count, loff_t *ppos) \
511{ \
512 int rc; \
513 rc = kstrtoint_from_user(buffer, count, 10, & name); \
514 if (rc) \
515 return rc; \
516 return count; \
517} \
518static int name##_proc_show(struct seq_file *m, void *v) \
519{ \
520 seq_printf(m, "%d\n", name ); \
521 return 0; \
522} \
523static int name##_open(struct inode *inode, struct file *file) \
524{ \
525 return single_open(file, name##_proc_show, NULL); \
526} \
527\
528static const struct file_operations cifs_##name##_proc_fops = { \
529 .open = name##_open, \
530 .read = seq_read, \
531 .llseek = seq_lseek, \
532 .release = single_release, \
533 .write = name##_write, \
534}
535
Long Lid8ec9132017-11-07 01:54:58 -0700536PROC_FILE_DEFINE(rdma_readwrite_threshold);
537PROC_FILE_DEFINE(smbd_max_frmr_depth);
538PROC_FILE_DEFINE(smbd_keep_alive_interval);
539PROC_FILE_DEFINE(smbd_max_receive_size);
540PROC_FILE_DEFINE(smbd_max_fragmented_recv_size);
541PROC_FILE_DEFINE(smbd_max_send_size);
542PROC_FILE_DEFINE(smbd_send_credit_target);
543PROC_FILE_DEFINE(smbd_receive_credit_max);
544#endif
545
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546static struct proc_dir_entry *proc_fs_cifs;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000547static const struct file_operations cifsFYI_proc_fops;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000548static const struct file_operations cifs_lookup_cache_proc_fops;
549static const struct file_operations traceSMB_proc_fops;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000550static const struct file_operations cifs_security_flags_proc_fops;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000551static const struct file_operations cifs_linux_ext_proc_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
553void
554cifs_proc_init(void)
555{
Alexey Dobriyan36a5aeb2008-04-29 01:01:42 -0700556 proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 if (proc_fs_cifs == NULL)
558 return;
559
Christoph Hellwig3f3942a2018-05-15 15:57:23 +0200560 proc_create_single("DebugData", 0, proc_fs_cifs,
561 cifs_debug_data_proc_show);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000563 proc_create("Stats", 0644, proc_fs_cifs, &cifs_stats_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000564 proc_create("cifsFYI", 0644, proc_fs_cifs, &cifsFYI_proc_fops);
565 proc_create("traceSMB", 0644, proc_fs_cifs, &traceSMB_proc_fops);
566 proc_create("LinuxExtensionsEnabled", 0644, proc_fs_cifs,
Steve French99b1f5b2008-07-24 02:37:45 +0000567 &cifs_linux_ext_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000568 proc_create("SecurityFlags", 0644, proc_fs_cifs,
Steve French99b1f5b2008-07-24 02:37:45 +0000569 &cifs_security_flags_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000570 proc_create("LookupCacheEnabled", 0644, proc_fs_cifs,
Steve French99b1f5b2008-07-24 02:37:45 +0000571 &cifs_lookup_cache_proc_fops);
Long Lid8ec9132017-11-07 01:54:58 -0700572#ifdef CONFIG_CIFS_SMB_DIRECT
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000573 proc_create("rdma_readwrite_threshold", 0644, proc_fs_cifs,
Long Lid8ec9132017-11-07 01:54:58 -0700574 &cifs_rdma_readwrite_threshold_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000575 proc_create("smbd_max_frmr_depth", 0644, proc_fs_cifs,
Long Lid8ec9132017-11-07 01:54:58 -0700576 &cifs_smbd_max_frmr_depth_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000577 proc_create("smbd_keep_alive_interval", 0644, proc_fs_cifs,
Long Lid8ec9132017-11-07 01:54:58 -0700578 &cifs_smbd_keep_alive_interval_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000579 proc_create("smbd_max_receive_size", 0644, proc_fs_cifs,
Long Lid8ec9132017-11-07 01:54:58 -0700580 &cifs_smbd_max_receive_size_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000581 proc_create("smbd_max_fragmented_recv_size", 0644, proc_fs_cifs,
Long Lid8ec9132017-11-07 01:54:58 -0700582 &cifs_smbd_max_fragmented_recv_size_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000583 proc_create("smbd_max_send_size", 0644, proc_fs_cifs,
Long Lid8ec9132017-11-07 01:54:58 -0700584 &cifs_smbd_max_send_size_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000585 proc_create("smbd_send_credit_target", 0644, proc_fs_cifs,
Long Lid8ec9132017-11-07 01:54:58 -0700586 &cifs_smbd_send_credit_target_proc_fops);
Ronnie Sahlberg6539e7f2018-05-24 14:18:05 +1000587 proc_create("smbd_receive_credit_max", 0644, proc_fs_cifs,
Long Lid8ec9132017-11-07 01:54:58 -0700588 &cifs_smbd_receive_credit_max_proc_fops);
589#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590}
591
592void
593cifs_proc_clean(void)
594{
595 if (proc_fs_cifs == NULL)
596 return;
597
598 remove_proc_entry("DebugData", proc_fs_cifs);
599 remove_proc_entry("cifsFYI", proc_fs_cifs);
600 remove_proc_entry("traceSMB", proc_fs_cifs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 remove_proc_entry("Stats", proc_fs_cifs);
Steve French221601c2007-06-05 20:35:06 +0000602 remove_proc_entry("SecurityFlags", proc_fs_cifs);
Steve French221601c2007-06-05 20:35:06 +0000603 remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
Steve French221601c2007-06-05 20:35:06 +0000604 remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
Long Lid8ec9132017-11-07 01:54:58 -0700605#ifdef CONFIG_CIFS_SMB_DIRECT
606 remove_proc_entry("rdma_readwrite_threshold", proc_fs_cifs);
607 remove_proc_entry("smbd_max_frmr_depth", proc_fs_cifs);
608 remove_proc_entry("smbd_keep_alive_interval", proc_fs_cifs);
609 remove_proc_entry("smbd_max_receive_size", proc_fs_cifs);
610 remove_proc_entry("smbd_max_fragmented_recv_size", proc_fs_cifs);
611 remove_proc_entry("smbd_max_send_size", proc_fs_cifs);
612 remove_proc_entry("smbd_send_credit_target", proc_fs_cifs);
613 remove_proc_entry("smbd_receive_credit_max", proc_fs_cifs);
614#endif
Alexey Dobriyan36a5aeb2008-04-29 01:01:42 -0700615 remove_proc_entry("fs/cifs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616}
617
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000618static int cifsFYI_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000620 seq_printf(m, "%d\n", cifsFYI);
621 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000623
624static int cifsFYI_proc_open(struct inode *inode, struct file *file)
625{
626 return single_open(file, cifsFYI_proc_show, NULL);
627}
628
629static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
630 size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631{
Kees Cook14042972016-03-17 14:22:54 -0700632 char c[2] = { '\0' };
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300633 bool bv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 int rc;
635
Kees Cook14042972016-03-17 14:22:54 -0700636 rc = get_user(c[0], buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 if (rc)
638 return rc;
Kees Cook14042972016-03-17 14:22:54 -0700639 if (strtobool(c, &bv) == 0)
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300640 cifsFYI = bv;
Kees Cook14042972016-03-17 14:22:54 -0700641 else if ((c[0] > '1') && (c[0] <= '9'))
642 cifsFYI = (int) (c[0] - '0'); /* see cifs_debug.h for meanings */
Ronnie Sahlberg25ad1cb2018-05-24 09:53:39 +1000643 else
644 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
646 return count;
647}
648
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000649static const struct file_operations cifsFYI_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000650 .open = cifsFYI_proc_open,
651 .read = seq_read,
652 .llseek = seq_lseek,
653 .release = single_release,
654 .write = cifsFYI_proc_write,
655};
656
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000657static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000659 seq_printf(m, "%d\n", linuxExtEnabled);
660 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000662
663static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
664{
665 return single_open(file, cifs_linux_ext_proc_show, NULL);
666}
667
668static ssize_t cifs_linux_ext_proc_write(struct file *file,
669 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670{
Steve French221601c2007-06-05 20:35:06 +0000671 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
Kees Cook14042972016-03-17 14:22:54 -0700673 rc = kstrtobool_from_user(buffer, count, &linuxExtEnabled);
Steve French221601c2007-06-05 20:35:06 +0000674 if (rc)
675 return rc;
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300676
Steve French221601c2007-06-05 20:35:06 +0000677 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678}
679
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000680static const struct file_operations cifs_linux_ext_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000681 .open = cifs_linux_ext_proc_open,
682 .read = seq_read,
683 .llseek = seq_lseek,
684 .release = single_release,
685 .write = cifs_linux_ext_proc_write,
686};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000688static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000690 seq_printf(m, "%d\n", lookupCacheEnabled);
691 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000693
694static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
695{
696 return single_open(file, cifs_lookup_cache_proc_show, NULL);
697}
698
699static ssize_t cifs_lookup_cache_proc_write(struct file *file,
700 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 int rc;
703
Kees Cook14042972016-03-17 14:22:54 -0700704 rc = kstrtobool_from_user(buffer, count, &lookupCacheEnabled);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 if (rc)
706 return rc;
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300707
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 return count;
709}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000710
711static const struct file_operations cifs_lookup_cache_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000712 .open = cifs_lookup_cache_proc_open,
713 .read = seq_read,
714 .llseek = seq_lseek,
715 .release = single_release,
716 .write = cifs_lookup_cache_proc_write,
717};
718
719static int traceSMB_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000721 seq_printf(m, "%d\n", traceSMB);
722 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000724
725static int traceSMB_proc_open(struct inode *inode, struct file *file)
726{
727 return single_open(file, traceSMB_proc_show, NULL);
728}
729
730static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
731 size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 int rc;
734
Kees Cook14042972016-03-17 14:22:54 -0700735 rc = kstrtobool_from_user(buffer, count, &traceSMB);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 if (rc)
737 return rc;
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300738
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 return count;
740}
741
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000742static const struct file_operations traceSMB_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000743 .open = traceSMB_proc_open,
744 .read = seq_read,
745 .llseek = seq_lseek,
746 .release = single_release,
747 .write = traceSMB_proc_write,
748};
749
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000750static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751{
Jeff Layton04912d62010-04-24 07:57:45 -0400752 seq_printf(m, "0x%x\n", global_secflags);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000753 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000755
756static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
757{
758 return single_open(file, cifs_security_flags_proc_show, NULL);
759}
760
Jeff Layton52dfb442013-05-26 07:01:02 -0400761/*
762 * Ensure that if someone sets a MUST flag, that we disable all other MAY
763 * flags except for the ones corresponding to the given MUST flag. If there are
764 * multiple MUST flags, then try to prefer more secure ones.
765 */
766static void
767cifs_security_flags_handle_must_flags(unsigned int *flags)
768{
769 unsigned int signflags = *flags & CIFSSEC_MUST_SIGN;
770
771 if ((*flags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5)
772 *flags = CIFSSEC_MUST_KRB5;
773 else if ((*flags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP)
774 *flags = CIFSSEC_MUST_NTLMSSP;
775 else if ((*flags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2)
776 *flags = CIFSSEC_MUST_NTLMV2;
777 else if ((*flags & CIFSSEC_MUST_NTLM) == CIFSSEC_MUST_NTLM)
778 *flags = CIFSSEC_MUST_NTLM;
Niklas Cassel7a1ceba2015-01-22 14:16:34 +0100779 else if (CIFSSEC_MUST_LANMAN &&
780 (*flags & CIFSSEC_MUST_LANMAN) == CIFSSEC_MUST_LANMAN)
Jeff Layton52dfb442013-05-26 07:01:02 -0400781 *flags = CIFSSEC_MUST_LANMAN;
Niklas Cassel7a1ceba2015-01-22 14:16:34 +0100782 else if (CIFSSEC_MUST_PLNTXT &&
783 (*flags & CIFSSEC_MUST_PLNTXT) == CIFSSEC_MUST_PLNTXT)
Jeff Layton52dfb442013-05-26 07:01:02 -0400784 *flags = CIFSSEC_MUST_PLNTXT;
785
786 *flags |= signflags;
787}
788
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000789static ssize_t cifs_security_flags_proc_write(struct file *file,
790 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791{
Jeff Layton7715dad2013-05-26 07:01:01 -0400792 int rc;
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000793 unsigned int flags;
794 char flags_string[12];
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300795 bool bv;
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000796
Steve French221601c2007-06-05 20:35:06 +0000797 if ((count < 1) || (count > 11))
Steve French39798772006-05-31 22:40:51 +0000798 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000800 memset(flags_string, 0, 12);
Steve French39798772006-05-31 22:40:51 +0000801
Steve French221601c2007-06-05 20:35:06 +0000802 if (copy_from_user(flags_string, buffer, count))
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000803 return -EFAULT;
Steve French39798772006-05-31 22:40:51 +0000804
Steve French221601c2007-06-05 20:35:06 +0000805 if (count < 3) {
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000806 /* single char or single char followed by null */
Kees Cook14042972016-03-17 14:22:54 -0700807 if (strtobool(flags_string, &bv) == 0) {
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300808 global_secflags = bv ? CIFSSEC_MAX : CIFSSEC_DEF;
Steve Frencha0136892007-10-04 20:05:09 +0000809 return count;
Kees Cook14042972016-03-17 14:22:54 -0700810 } else if (!isdigit(flags_string[0])) {
Jeff Layton7715dad2013-05-26 07:01:01 -0400811 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
812 flags_string);
Steve Frencha0136892007-10-04 20:05:09 +0000813 return -EINVAL;
814 }
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000815 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
Jeff Layton7715dad2013-05-26 07:01:01 -0400817 /* else we have a number */
818 rc = kstrtouint(flags_string, 0, &flags);
819 if (rc) {
820 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
821 flags_string);
822 return rc;
823 }
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000824
Joe Perchesf96637b2013-05-04 22:12:25 -0500825 cifs_dbg(FYI, "sec flags 0x%x\n", flags);
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000826
Jeff Layton7715dad2013-05-26 07:01:01 -0400827 if (flags == 0) {
828 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", flags_string);
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000829 return -EINVAL;
830 }
831
Steve French221601c2007-06-05 20:35:06 +0000832 if (flags & ~CIFSSEC_MASK) {
Jeff Layton7715dad2013-05-26 07:01:01 -0400833 cifs_dbg(VFS, "Unsupported security flags: 0x%x\n",
Joe Perchesf96637b2013-05-04 22:12:25 -0500834 flags & ~CIFSSEC_MASK);
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000835 return -EINVAL;
836 }
Jeff Layton7715dad2013-05-26 07:01:01 -0400837
Jeff Layton52dfb442013-05-26 07:01:02 -0400838 cifs_security_flags_handle_must_flags(&flags);
839
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000840 /* flags look ok - update the global security flags for cifs module */
Jeff Layton04912d62010-04-24 07:57:45 -0400841 global_secflags = flags;
842 if (global_secflags & CIFSSEC_MUST_SIGN) {
Steve French762e5ab2007-06-28 18:41:42 +0000843 /* requiring signing implies signing is allowed */
Jeff Layton04912d62010-04-24 07:57:45 -0400844 global_secflags |= CIFSSEC_MAY_SIGN;
Joe Perchesf96637b2013-05-04 22:12:25 -0500845 cifs_dbg(FYI, "packet signing now required\n");
Jeff Layton04912d62010-04-24 07:57:45 -0400846 } else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500847 cifs_dbg(FYI, "packet signing disabled\n");
Steve French762e5ab2007-06-28 18:41:42 +0000848 }
849 /* BB should we turn on MAY flags for other MUST options? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 return count;
851}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000852
853static const struct file_operations cifs_security_flags_proc_fops = {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000854 .open = cifs_security_flags_proc_open,
855 .read = seq_read,
856 .llseek = seq_lseek,
857 .release = single_release,
858 .write = cifs_security_flags_proc_write,
859};
Steve French90c81e02008-02-12 20:32:36 +0000860#else
Steve Frenche086fce2008-02-18 04:03:58 +0000861inline void cifs_proc_init(void)
Steve French90c81e02008-02-12 20:32:36 +0000862{
863}
864
Steve Frenche086fce2008-02-18 04:03:58 +0000865inline void cifs_proc_clean(void)
Steve French90c81e02008-02-12 20:32:36 +0000866{
867}
868#endif /* PROC_FS */