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