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