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