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