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