Commit | Line | Data |
---|---|---|
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 | |
37 | void | |
38 | cifs_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 |
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 | ||
ec7147a9 | 56 | pr_err_ratelimited("CIFS VFS: %pV", &vaf); |
f96637be JP |
57 | |
58 | va_end(args); | |
59 | } | |
60 | #endif | |
61 | ||
d4e4854f | 62 | void 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 | 74 | void 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 |
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); | |
ede2e520 SF |
131 | if (tcon->seal) |
132 | seq_printf(m, " Encrypted"); | |
133 | if (tcon->unix_ext) | |
134 | seq_printf(m, " POSIX Extensions"); | |
02cf5905 AA |
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 | ||
f984c7b9 | 143 | static int cifs_debug_data_proc_show(struct seq_file *m, void *v) |
1da177e4 | 144 | { |
f1987b44 | 145 | struct list_head *tmp1, *tmp2, *tmp3; |
ffdd6e4d | 146 | struct mid_q_entry *mid_entry; |
14fbf50d | 147 | struct TCP_Server_Info *server; |
96daf2b0 SF |
148 | struct cifs_ses *ses; |
149 | struct cifs_tcon *tcon; | |
f1987b44 | 150 | int i, j; |
1da177e4 | 151 | |
f984c7b9 | 152 | seq_puts(m, |
1da177e4 LT |
153 | "Display Internal CIFS Data Structures for Debugging\n" |
154 | "---------------------------------------------------\n"); | |
f984c7b9 | 155 | seq_printf(m, "CIFS Version %s\n", CIFS_VERSION); |
ca40b714 | 156 | seq_printf(m, "Features:"); |
f579903e | 157 | #ifdef CONFIG_CIFS_DFS_UPCALL |
ca40b714 | 158 | seq_printf(m, " dfs"); |
f579903e SJ |
159 | #endif |
160 | #ifdef CONFIG_CIFS_FSCACHE | |
ca40b714 | 161 | seq_printf(m, " fscache"); |
f579903e SJ |
162 | #endif |
163 | #ifdef CONFIG_CIFS_WEAK_PW_HASH | |
ca40b714 | 164 | seq_printf(m, " lanman"); |
f579903e SJ |
165 | #endif |
166 | #ifdef CONFIG_CIFS_POSIX | |
ca40b714 | 167 | seq_printf(m, " posix"); |
f579903e SJ |
168 | #endif |
169 | #ifdef CONFIG_CIFS_UPCALL | |
ca40b714 | 170 | seq_printf(m, " spnego"); |
f579903e SJ |
171 | #endif |
172 | #ifdef CONFIG_CIFS_XATTR | |
ca40b714 JL |
173 | seq_printf(m, " xattr"); |
174 | #endif | |
175 | #ifdef CONFIG_CIFS_ACL | |
176 | seq_printf(m, " acl"); | |
f579903e SJ |
177 | #endif |
178 | seq_putc(m, '\n'); | |
f984c7b9 AD |
179 | seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid); |
180 | seq_printf(m, "Servers:"); | |
1da177e4 LT |
181 | |
182 | i = 0; | |
3f9bcca7 | 183 | spin_lock(&cifs_tcp_ses_lock); |
f1987b44 JL |
184 | list_for_each(tmp1, &cifs_tcp_ses_list) { |
185 | server = list_entry(tmp1, struct TCP_Server_Info, | |
14fbf50d | 186 | tcp_ses_list); |
08a3b969 LL |
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 | |
ede2e520 SF |
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"); | |
1da177e4 | 257 | i++; |
14fbf50d | 258 | list_for_each(tmp2, &server->smb_ses_list) { |
96daf2b0 | 259 | ses = list_entry(tmp2, struct cifs_ses, |
14fbf50d JL |
260 | smb_ses_list); |
261 | if ((ses->serverDomain == NULL) || | |
262 | (ses->serverOS == NULL) || | |
263 | (ses->serverNOS == NULL)) { | |
1fa089ec SF |
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"); | |
14fbf50d JL |
271 | } else { |
272 | seq_printf(m, | |
f1987b44 JL |
273 | "\n%d) Name: %s Domain: %s Uses: %d OS:" |
274 | " %s\n\tNOS: %s\tCapability: 0x%x\n\tSMB" | |
221601c3 | 275 | " session status: %d\t", |
b8643e1b | 276 | i, ses->serverName, ses->serverDomain, |
14fbf50d | 277 | ses->ses_count, ses->serverOS, ses->serverNOS, |
221601c3 | 278 | ses->capabilities, ses->status); |
14fbf50d | 279 | } |
8339dd32 LL |
280 | if (server->rdma) |
281 | seq_printf(m, "RDMA\n\t"); | |
f984c7b9 | 282 | seq_printf(m, "TCP status: %d\n\tLocal Users To " |
14fbf50d JL |
283 | "Server: %d SecMode: 0x%x Req On Wire: %d", |
284 | server->tcpStatus, server->srv_count, | |
fc40f9cf | 285 | server->sec_mode, in_flight(server)); |
131afd0b SF |
286 | |
287 | #ifdef CONFIG_CIFS_STATS2 | |
f984c7b9 | 288 | seq_printf(m, " In Send: %d In MaxReq Wait: %d", |
789e6661 | 289 | atomic_read(&server->in_send), |
14fbf50d | 290 | atomic_read(&server->num_waiters)); |
131afd0b SF |
291 | #endif |
292 | ||
f1987b44 JL |
293 | seq_puts(m, "\n\tShares:"); |
294 | j = 0; | |
02cf5905 AA |
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 | ||
f1987b44 | 302 | list_for_each(tmp3, &ses->tcon_list) { |
96daf2b0 | 303 | tcon = list_entry(tmp3, struct cifs_tcon, |
f1987b44 JL |
304 | tcon_list); |
305 | ++j; | |
02cf5905 AA |
306 | seq_printf(m, "\n\t%d) ", j); |
307 | cifs_debug_tcon(m, tcon); | |
f1987b44 JL |
308 | } |
309 | ||
310 | seq_puts(m, "\n\tMIDs:\n"); | |
1da177e4 LT |
311 | |
312 | spin_lock(&GlobalMid_Lock); | |
14fbf50d | 313 | list_for_each(tmp3, &server->pending_mid_q) { |
f1987b44 | 314 | mid_entry = list_entry(tmp3, struct mid_q_entry, |
1da177e4 | 315 | qhead); |
f1987b44 | 316 | seq_printf(m, "\tState: %d com: %d pid:" |
7c9421e1 PS |
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); | |
1da177e4 | 323 | } |
221601c3 | 324 | spin_unlock(&GlobalMid_Lock); |
1da177e4 | 325 | } |
1da177e4 | 326 | } |
3f9bcca7 | 327 | spin_unlock(&cifs_tcp_ses_lock); |
f984c7b9 | 328 | seq_putc(m, '\n'); |
1da177e4 | 329 | |
1da177e4 | 330 | /* BB add code to dump additional info such as TCP session info now */ |
f984c7b9 AD |
331 | return 0; |
332 | } | |
1da177e4 | 333 | |
f984c7b9 AD |
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); | |
1da177e4 LT |
337 | } |
338 | ||
f984c7b9 | 339 | static const struct file_operations cifs_debug_data_proc_fops = { |
f984c7b9 AD |
340 | .open = cifs_debug_data_proc_open, |
341 | .read = seq_read, | |
342 | .llseek = seq_lseek, | |
343 | .release = single_release, | |
344 | }; | |
1047abc1 | 345 | |
f984c7b9 AD |
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) | |
1047abc1 | 349 | { |
28e2aed2 | 350 | bool bv; |
221601c3 | 351 | int rc; |
f1987b44 JL |
352 | struct list_head *tmp1, *tmp2, *tmp3; |
353 | struct TCP_Server_Info *server; | |
96daf2b0 SF |
354 | struct cifs_ses *ses; |
355 | struct cifs_tcon *tcon; | |
1047abc1 | 356 | |
1404297e KC |
357 | rc = kstrtobool_from_user(buffer, count, &bv); |
358 | if (rc == 0) { | |
4498eed5 SF |
359 | #ifdef CONFIG_CIFS_STATS2 |
360 | atomic_set(&totBufAllocCount, 0); | |
361 | atomic_set(&totSmBufAllocCount, 0); | |
362 | #endif /* CONFIG_CIFS_STATS2 */ | |
3f9bcca7 | 363 | spin_lock(&cifs_tcp_ses_lock); |
f1987b44 JL |
364 | list_for_each(tmp1, &cifs_tcp_ses_list) { |
365 | server = list_entry(tmp1, struct TCP_Server_Info, | |
366 | tcp_ses_list); | |
c2b3382c | 367 | list_for_each(tmp2, &server->smb_ses_list) { |
96daf2b0 | 368 | ses = list_entry(tmp2, struct cifs_ses, |
c2b3382c | 369 | smb_ses_list); |
f1987b44 JL |
370 | list_for_each(tmp3, &ses->tcon_list) { |
371 | tcon = list_entry(tmp3, | |
96daf2b0 | 372 | struct cifs_tcon, |
f1987b44 JL |
373 | tcon_list); |
374 | atomic_set(&tcon->num_smbs_sent, 0); | |
44c58186 PS |
375 | if (server->ops->clear_stats) |
376 | server->ops->clear_stats(tcon); | |
f1987b44 JL |
377 | } |
378 | } | |
1047abc1 | 379 | } |
3f9bcca7 | 380 | spin_unlock(&cifs_tcp_ses_lock); |
1404297e KC |
381 | } else { |
382 | return rc; | |
1047abc1 SF |
383 | } |
384 | ||
221601c3 | 385 | return count; |
1047abc1 SF |
386 | } |
387 | ||
f984c7b9 | 388 | static int cifs_stats_proc_show(struct seq_file *m, void *v) |
1da177e4 | 389 | { |
f984c7b9 | 390 | int i; |
f1987b44 JL |
391 | struct list_head *tmp1, *tmp2, *tmp3; |
392 | struct TCP_Server_Info *server; | |
96daf2b0 SF |
393 | struct cifs_ses *ses; |
394 | struct cifs_tcon *tcon; | |
1da177e4 | 395 | |
f984c7b9 | 396 | seq_printf(m, |
1da177e4 LT |
397 | "Resources in use\nCIFS Session: %d\n", |
398 | sesInfoAllocCount.counter); | |
f984c7b9 | 399 | seq_printf(m, "Share (unique mount targets): %d\n", |
1da177e4 | 400 | tconInfoAllocCount.counter); |
f984c7b9 | 401 | seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n", |
b8643e1b SF |
402 | bufAllocCount.counter, |
403 | cifs_min_rcv + tcpSesAllocCount.counter); | |
f984c7b9 | 404 | seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n", |
221601c3 | 405 | smBufAllocCount.counter, cifs_min_small); |
07475ffb | 406 | #ifdef CONFIG_CIFS_STATS2 |
f984c7b9 | 407 | seq_printf(m, "Total Large %d Small %d Allocations\n", |
07475ffb | 408 | atomic_read(&totBufAllocCount), |
221601c3 | 409 | atomic_read(&totSmBufAllocCount)); |
07475ffb SF |
410 | #endif /* CONFIG_CIFS_STATS2 */ |
411 | ||
8097531a | 412 | seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount)); |
f984c7b9 | 413 | seq_printf(m, |
1da177e4 | 414 | "\n%d session %d share reconnects\n", |
221601c3 | 415 | tcpSesReconnectCount.counter, tconInfoReconnectCount.counter); |
1da177e4 | 416 | |
f984c7b9 | 417 | seq_printf(m, |
1da177e4 | 418 | "Total vfs operations: %d maximum at one time: %d\n", |
221601c3 | 419 | GlobalCurrentXid, GlobalMaxActiveXid); |
1da177e4 LT |
420 | |
421 | i = 0; | |
3f9bcca7 | 422 | spin_lock(&cifs_tcp_ses_lock); |
f1987b44 JL |
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) { | |
96daf2b0 | 427 | ses = list_entry(tmp2, struct cifs_ses, |
f1987b44 JL |
428 | smb_ses_list); |
429 | list_for_each(tmp3, &ses->tcon_list) { | |
430 | tcon = list_entry(tmp3, | |
96daf2b0 | 431 | struct cifs_tcon, |
f1987b44 JL |
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 "); | |
44c58186 PS |
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); | |
f1987b44 JL |
441 | } |
442 | } | |
1da177e4 | 443 | } |
3f9bcca7 | 444 | spin_unlock(&cifs_tcp_ses_lock); |
1da177e4 | 445 | |
f984c7b9 AD |
446 | seq_putc(m, '\n'); |
447 | return 0; | |
448 | } | |
221601c3 | 449 | |
f984c7b9 AD |
450 | static int cifs_stats_proc_open(struct inode *inode, struct file *file) |
451 | { | |
452 | return single_open(file, cifs_stats_proc_show, NULL); | |
1da177e4 | 453 | } |
f984c7b9 AD |
454 | |
455 | static const struct file_operations cifs_stats_proc_fops = { | |
f984c7b9 AD |
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 | }; | |
90c81e0b | 462 | #endif /* STATS */ |
1da177e4 | 463 | |
d8ec913b LL |
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 | ||
d8ec913b LL |
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 | ||
1da177e4 | 503 | static struct proc_dir_entry *proc_fs_cifs; |
f984c7b9 | 504 | static const struct file_operations cifsFYI_proc_fops; |
f984c7b9 AD |
505 | static const struct file_operations cifs_lookup_cache_proc_fops; |
506 | static const struct file_operations traceSMB_proc_fops; | |
f984c7b9 | 507 | static const struct file_operations cifs_security_flags_proc_fops; |
f984c7b9 | 508 | static const struct file_operations cifs_linux_ext_proc_fops; |
1da177e4 LT |
509 | |
510 | void | |
511 | cifs_proc_init(void) | |
512 | { | |
36a5aeb8 | 513 | proc_fs_cifs = proc_mkdir("fs/cifs", NULL); |
1da177e4 LT |
514 | if (proc_fs_cifs == NULL) |
515 | return; | |
516 | ||
f984c7b9 | 517 | proc_create("DebugData", 0, proc_fs_cifs, &cifs_debug_data_proc_fops); |
1da177e4 LT |
518 | |
519 | #ifdef CONFIG_CIFS_STATS | |
f984c7b9 | 520 | proc_create("Stats", 0, proc_fs_cifs, &cifs_stats_proc_fops); |
90c81e0b | 521 | #endif /* STATS */ |
f984c7b9 AD |
522 | proc_create("cifsFYI", 0, proc_fs_cifs, &cifsFYI_proc_fops); |
523 | proc_create("traceSMB", 0, proc_fs_cifs, &traceSMB_proc_fops); | |
99b1f5b2 SF |
524 | proc_create("LinuxExtensionsEnabled", 0, proc_fs_cifs, |
525 | &cifs_linux_ext_proc_fops); | |
99b1f5b2 SF |
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); | |
d8ec913b LL |
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 | |
1da177e4 LT |
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 | |
221601c3 | 562 | remove_proc_entry("SecurityFlags", proc_fs_cifs); |
221601c3 | 563 | remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs); |
221601c3 | 564 | remove_proc_entry("LookupCacheEnabled", proc_fs_cifs); |
d8ec913b LL |
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 | |
36a5aeb8 | 575 | remove_proc_entry("fs/cifs", NULL); |
1da177e4 LT |
576 | } |
577 | ||
f984c7b9 | 578 | static int cifsFYI_proc_show(struct seq_file *m, void *v) |
1da177e4 | 579 | { |
f984c7b9 AD |
580 | seq_printf(m, "%d\n", cifsFYI); |
581 | return 0; | |
582 | } | |
1da177e4 | 583 | |
f984c7b9 AD |
584 | static int cifsFYI_proc_open(struct inode *inode, struct file *file) |
585 | { | |
586 | return single_open(file, cifsFYI_proc_show, NULL); | |
1da177e4 | 587 | } |
f984c7b9 AD |
588 | |
589 | static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer, | |
590 | size_t count, loff_t *ppos) | |
1da177e4 | 591 | { |
1404297e | 592 | char c[2] = { '\0' }; |
28e2aed2 | 593 | bool bv; |
1da177e4 LT |
594 | int rc; |
595 | ||
1404297e | 596 | rc = get_user(c[0], buffer); |
1da177e4 LT |
597 | if (rc) |
598 | return rc; | |
1404297e | 599 | if (strtobool(c, &bv) == 0) |
28e2aed2 | 600 | cifsFYI = bv; |
1404297e KC |
601 | else if ((c[0] > '1') && (c[0] <= '9')) |
602 | cifsFYI = (int) (c[0] - '0'); /* see cifs_debug.h for meanings */ | |
1da177e4 LT |
603 | |
604 | return count; | |
605 | } | |
606 | ||
f984c7b9 | 607 | static const struct file_operations cifsFYI_proc_fops = { |
f984c7b9 AD |
608 | .open = cifsFYI_proc_open, |
609 | .read = seq_read, | |
610 | .llseek = seq_lseek, | |
611 | .release = single_release, | |
612 | .write = cifsFYI_proc_write, | |
613 | }; | |
1da177e4 | 614 | |
f984c7b9 AD |
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 | } | |
1da177e4 | 620 | |
f984c7b9 AD |
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); | |
1da177e4 | 624 | } |
f984c7b9 AD |
625 | |
626 | static ssize_t cifs_linux_ext_proc_write(struct file *file, | |
627 | const char __user *buffer, size_t count, loff_t *ppos) | |
1da177e4 | 628 | { |
221601c3 SF |
629 | int rc; |
630 | ||
1404297e | 631 | rc = kstrtobool_from_user(buffer, count, &linuxExtEnabled); |
221601c3 SF |
632 | if (rc) |
633 | return rc; | |
28e2aed2 | 634 | |
221601c3 | 635 | return count; |
1da177e4 LT |
636 | } |
637 | ||
f984c7b9 | 638 | static const struct file_operations cifs_linux_ext_proc_fops = { |
f984c7b9 AD |
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 | }; | |
1da177e4 | 645 | |
f984c7b9 | 646 | static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v) |
1da177e4 | 647 | { |
f984c7b9 AD |
648 | seq_printf(m, "%d\n", lookupCacheEnabled); |
649 | return 0; | |
650 | } | |
1da177e4 | 651 | |
f984c7b9 AD |
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); | |
1da177e4 | 655 | } |
f984c7b9 AD |
656 | |
657 | static ssize_t cifs_lookup_cache_proc_write(struct file *file, | |
658 | const char __user *buffer, size_t count, loff_t *ppos) | |
1da177e4 | 659 | { |
1da177e4 LT |
660 | int rc; |
661 | ||
1404297e | 662 | rc = kstrtobool_from_user(buffer, count, &lookupCacheEnabled); |
1da177e4 LT |
663 | if (rc) |
664 | return rc; | |
28e2aed2 | 665 | |
1da177e4 LT |
666 | return count; |
667 | } | |
1da177e4 | 668 | |
f984c7b9 | 669 | static const struct file_operations cifs_lookup_cache_proc_fops = { |
f984c7b9 AD |
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 | }; | |
1da177e4 | 676 | |
f984c7b9 AD |
677 | static int traceSMB_proc_show(struct seq_file *m, void *v) |
678 | { | |
679 | seq_printf(m, "%d\n", traceSMB); | |
680 | return 0; | |
681 | } | |
1da177e4 | 682 | |
f984c7b9 AD |
683 | static int traceSMB_proc_open(struct inode *inode, struct file *file) |
684 | { | |
685 | return single_open(file, traceSMB_proc_show, NULL); | |
1da177e4 | 686 | } |
f984c7b9 AD |
687 | |
688 | static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer, | |
689 | size_t count, loff_t *ppos) | |
1da177e4 | 690 | { |
1da177e4 LT |
691 | int rc; |
692 | ||
1404297e | 693 | rc = kstrtobool_from_user(buffer, count, &traceSMB); |
1da177e4 LT |
694 | if (rc) |
695 | return rc; | |
28e2aed2 | 696 | |
1da177e4 LT |
697 | return count; |
698 | } | |
699 | ||
f984c7b9 | 700 | static const struct file_operations traceSMB_proc_fops = { |
f984c7b9 AD |
701 | .open = traceSMB_proc_open, |
702 | .read = seq_read, | |
703 | .llseek = seq_lseek, | |
704 | .release = single_release, | |
705 | .write = traceSMB_proc_write, | |
706 | }; | |
1da177e4 | 707 | |
f984c7b9 AD |
708 | static int cifs_security_flags_proc_show(struct seq_file *m, void *v) |
709 | { | |
04912d6a | 710 | seq_printf(m, "0x%x\n", global_secflags); |
f984c7b9 AD |
711 | return 0; |
712 | } | |
1da177e4 | 713 | |
f984c7b9 AD |
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); | |
1da177e4 | 717 | } |
f984c7b9 | 718 | |
52dfb446 JL |
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; | |
7a1ceba0 NC |
737 | else if (CIFSSEC_MUST_LANMAN && |
738 | (*flags & CIFSSEC_MUST_LANMAN) == CIFSSEC_MUST_LANMAN) | |
52dfb446 | 739 | *flags = CIFSSEC_MUST_LANMAN; |
7a1ceba0 NC |
740 | else if (CIFSSEC_MUST_PLNTXT && |
741 | (*flags & CIFSSEC_MUST_PLNTXT) == CIFSSEC_MUST_PLNTXT) | |
52dfb446 JL |
742 | *flags = CIFSSEC_MUST_PLNTXT; |
743 | ||
744 | *flags |= signflags; | |
745 | } | |
746 | ||
f984c7b9 AD |
747 | static ssize_t cifs_security_flags_proc_write(struct file *file, |
748 | const char __user *buffer, size_t count, loff_t *ppos) | |
1da177e4 | 749 | { |
7715dad8 | 750 | int rc; |
bdc4bf6e SF |
751 | unsigned int flags; |
752 | char flags_string[12]; | |
28e2aed2 | 753 | bool bv; |
bdc4bf6e | 754 | |
221601c3 | 755 | if ((count < 1) || (count > 11)) |
3979877e | 756 | return -EINVAL; |
1da177e4 | 757 | |
bdc4bf6e | 758 | memset(flags_string, 0, 12); |
3979877e | 759 | |
221601c3 | 760 | if (copy_from_user(flags_string, buffer, count)) |
bdc4bf6e | 761 | return -EFAULT; |
3979877e | 762 | |
221601c3 | 763 | if (count < 3) { |
bdc4bf6e | 764 | /* single char or single char followed by null */ |
1404297e | 765 | if (strtobool(flags_string, &bv) == 0) { |
28e2aed2 | 766 | global_secflags = bv ? CIFSSEC_MAX : CIFSSEC_DEF; |
a013689d | 767 | return count; |
1404297e | 768 | } else if (!isdigit(flags_string[0])) { |
7715dad8 JL |
769 | cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", |
770 | flags_string); | |
a013689d SF |
771 | return -EINVAL; |
772 | } | |
bdc4bf6e | 773 | } |
bdc4bf6e | 774 | |
7715dad8 JL |
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 | } | |
bdc4bf6e | 782 | |
f96637be | 783 | cifs_dbg(FYI, "sec flags 0x%x\n", flags); |
bdc4bf6e | 784 | |
7715dad8 JL |
785 | if (flags == 0) { |
786 | cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", flags_string); | |
bdc4bf6e SF |
787 | return -EINVAL; |
788 | } | |
1da177e4 | 789 | |
221601c3 | 790 | if (flags & ~CIFSSEC_MASK) { |
7715dad8 | 791 | cifs_dbg(VFS, "Unsupported security flags: 0x%x\n", |
f96637be | 792 | flags & ~CIFSSEC_MASK); |
bdc4bf6e SF |
793 | return -EINVAL; |
794 | } | |
7715dad8 | 795 | |
52dfb446 JL |
796 | cifs_security_flags_handle_must_flags(&flags); |
797 | ||
bdc4bf6e | 798 | /* flags look ok - update the global security flags for cifs module */ |
04912d6a JL |
799 | global_secflags = flags; |
800 | if (global_secflags & CIFSSEC_MUST_SIGN) { | |
762e5ab7 | 801 | /* requiring signing implies signing is allowed */ |
04912d6a | 802 | global_secflags |= CIFSSEC_MAY_SIGN; |
f96637be | 803 | cifs_dbg(FYI, "packet signing now required\n"); |
04912d6a | 804 | } else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) { |
f96637be | 805 | cifs_dbg(FYI, "packet signing disabled\n"); |
762e5ab7 SF |
806 | } |
807 | /* BB should we turn on MAY flags for other MUST options? */ | |
1da177e4 LT |
808 | return count; |
809 | } | |
f984c7b9 AD |
810 | |
811 | static const struct file_operations cifs_security_flags_proc_fops = { | |
f984c7b9 AD |
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 | }; | |
90c81e0b | 818 | #else |
e086fcea | 819 | inline void cifs_proc_init(void) |
90c81e0b SF |
820 | { |
821 | } | |
822 | ||
e086fcea | 823 | inline void cifs_proc_clean(void) |
90c81e0b SF |
824 | { |
825 | } | |
826 | #endif /* PROC_FS */ |