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