blob: 4fce6e61b34e9e889fae5fdbfbf938a7526b8ccb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/cifs_debug.c
3 *
Steve Frenchb8643e12005-04-28 22:41:07 -07004 * Copyright (C) International Business Machines Corp., 2000,2005
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
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
Steve French221601c2007-06-05 20:35:06 +000010 * the Free Software Foundation; either version 2 of the License, or
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 * (at your option) any later version.
Steve French221601c2007-06-05 20:35:06 +000012 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 * 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
Steve French221601c2007-06-05 20:35:06 +000019 * along with this program; if not, write to the Free Software
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 * 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>
27#include <asm/uaccess.h>
28#include "cifspdu.h"
29#include "cifsglob.h"
30#include "cifsproto.h"
31#include "cifs_debug.h"
Steve French6c91d362005-04-28 22:41:06 -070032#include "cifsfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
34void
35cifs_dump_mem(char *label, void *data, int length)
36{
37 int i, j;
38 int *intptr = data;
39 char *charptr = data;
40 char buf[10], line[80];
41
Steve French221601c2007-06-05 20:35:06 +000042 printk(KERN_DEBUG "%s: dump of %d bytes of data at 0x%p\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 label, length, data);
44 for (i = 0; i < length; i += 16) {
45 line[0] = 0;
46 for (j = 0; (j < 4) && (i + j * 4 < length); j++) {
47 sprintf(buf, " %08x", intptr[i / 4 + j]);
48 strcat(line, buf);
49 }
50 buf[0] = ' ';
51 buf[2] = 0;
52 for (j = 0; (j < 16) && (i + j < length); j++) {
53 buf[1] = isprint(charptr[i + j]) ? charptr[i + j] : '.';
54 strcat(line, buf);
55 }
56 printk(KERN_DEBUG "%s\n", line);
57 }
58}
59
Steve French39798772006-05-31 22:40:51 +000060#ifdef CONFIG_CIFS_DEBUG2
Steve Frenchffdd6e42007-06-24 21:15:44 +000061void cifs_dump_detail(struct smb_hdr *smb)
Steve French39798772006-05-31 22:40:51 +000062{
Joe Perchesb6b38f72010-04-21 03:50:45 +000063 cERROR(1, "Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d",
Steve French39798772006-05-31 22:40:51 +000064 smb->Command, smb->Status.CifsError,
Joe Perchesb6b38f72010-04-21 03:50:45 +000065 smb->Flags, smb->Flags2, smb->Mid, smb->Pid);
66 cERROR(1, "smb buf %p len %d", smb, smbCalcSize_LE(smb));
Steve French39798772006-05-31 22:40:51 +000067}
68
69
Steve Frenchffdd6e42007-06-24 21:15:44 +000070void cifs_dump_mids(struct TCP_Server_Info *server)
Steve French39798772006-05-31 22:40:51 +000071{
72 struct list_head *tmp;
Steve Frenchffdd6e42007-06-24 21:15:44 +000073 struct mid_q_entry *mid_entry;
Steve French39798772006-05-31 22:40:51 +000074
Steve French221601c2007-06-05 20:35:06 +000075 if (server == NULL)
Steve French39798772006-05-31 22:40:51 +000076 return;
77
Joe Perchesb6b38f72010-04-21 03:50:45 +000078 cERROR(1, "Dump pending requests:");
Steve French39798772006-05-31 22:40:51 +000079 spin_lock(&GlobalMid_Lock);
80 list_for_each(tmp, &server->pending_mid_q) {
81 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
Joe Perchesb6b38f72010-04-21 03:50:45 +000082 cERROR(1, "State: %d Cmd: %d Pid: %d Tsk: %p Mid %d",
Steve Frenchad8b15f2008-08-08 21:10:16 +000083 mid_entry->midState,
84 (int)mid_entry->command,
85 mid_entry->pid,
86 mid_entry->tsk,
Joe Perchesb6b38f72010-04-21 03:50:45 +000087 mid_entry->mid);
Steve French39798772006-05-31 22:40:51 +000088#ifdef CONFIG_CIFS_STATS2
Joe Perchesb6b38f72010-04-21 03:50:45 +000089 cERROR(1, "IsLarge: %d buf: %p time rcv: %ld now: %ld",
Steve Frenchad8b15f2008-08-08 21:10:16 +000090 mid_entry->largeBuf,
91 mid_entry->resp_buf,
92 mid_entry->when_received,
Joe Perchesb6b38f72010-04-21 03:50:45 +000093 jiffies);
Steve French39798772006-05-31 22:40:51 +000094#endif /* STATS2 */
Joe Perchesb6b38f72010-04-21 03:50:45 +000095 cERROR(1, "IsMult: %d IsEnd: %d", mid_entry->multiRsp,
96 mid_entry->multiEnd);
Steve Frenchad8b15f2008-08-08 21:10:16 +000097 if (mid_entry->resp_buf) {
98 cifs_dump_detail(mid_entry->resp_buf);
99 cifs_dump_mem("existing buf: ",
100 mid_entry->resp_buf, 62);
Steve French39798772006-05-31 22:40:51 +0000101 }
102 }
103 spin_unlock(&GlobalMid_Lock);
104}
105#endif /* CONFIG_CIFS_DEBUG2 */
106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107#ifdef CONFIG_PROC_FS
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000108static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109{
Jeff Laytonf1987b42008-11-15 11:12:47 -0500110 struct list_head *tmp1, *tmp2, *tmp3;
Steve Frenchffdd6e42007-06-24 21:15:44 +0000111 struct mid_q_entry *mid_entry;
Jeff Layton14fbf502008-11-14 13:53:46 -0500112 struct TCP_Server_Info *server;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 struct cifsSesInfo *ses;
114 struct cifsTconInfo *tcon;
Jeff Laytonf1987b42008-11-15 11:12:47 -0500115 int i, j;
116 __u32 dev_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000118 seq_puts(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 "Display Internal CIFS Data Structures for Debugging\n"
120 "---------------------------------------------------\n");
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000121 seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
122 seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
123 seq_printf(m, "Servers:");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
125 i = 0;
Jeff Layton14fbf502008-11-14 13:53:46 -0500126 read_lock(&cifs_tcp_ses_lock);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500127 list_for_each(tmp1, &cifs_tcp_ses_list) {
128 server = list_entry(tmp1, struct TCP_Server_Info,
Jeff Layton14fbf502008-11-14 13:53:46 -0500129 tcp_ses_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 i++;
Jeff Layton14fbf502008-11-14 13:53:46 -0500131 list_for_each(tmp2, &server->smb_ses_list) {
132 ses = list_entry(tmp2, struct cifsSesInfo,
133 smb_ses_list);
134 if ((ses->serverDomain == NULL) ||
135 (ses->serverOS == NULL) ||
136 (ses->serverNOS == NULL)) {
Jeff Laytonf1987b42008-11-15 11:12:47 -0500137 seq_printf(m, "\n%d) entry for %s not fully "
138 "displayed\n\t", i, ses->serverName);
Jeff Layton14fbf502008-11-14 13:53:46 -0500139 } else {
140 seq_printf(m,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500141 "\n%d) Name: %s Domain: %s Uses: %d OS:"
142 " %s\n\tNOS: %s\tCapability: 0x%x\n\tSMB"
Steve French221601c2007-06-05 20:35:06 +0000143 " session status: %d\t",
Steve Frenchb8643e12005-04-28 22:41:07 -0700144 i, ses->serverName, ses->serverDomain,
Jeff Layton14fbf502008-11-14 13:53:46 -0500145 ses->ses_count, ses->serverOS, ses->serverNOS,
Steve French221601c2007-06-05 20:35:06 +0000146 ses->capabilities, ses->status);
Jeff Layton14fbf502008-11-14 13:53:46 -0500147 }
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000148 seq_printf(m, "TCP status: %d\n\tLocal Users To "
Jeff Layton14fbf502008-11-14 13:53:46 -0500149 "Server: %d SecMode: 0x%x Req On Wire: %d",
150 server->tcpStatus, server->srv_count,
151 server->secMode,
152 atomic_read(&server->inFlight));
Steve French131afd0b2005-10-07 09:51:05 -0700153
154#ifdef CONFIG_CIFS_STATS2
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000155 seq_printf(m, " In Send: %d In MaxReq Wait: %d",
Jeff Layton14fbf502008-11-14 13:53:46 -0500156 atomic_read(&server->inSend),
157 atomic_read(&server->num_waiters));
Steve French131afd0b2005-10-07 09:51:05 -0700158#endif
159
Jeff Laytonf1987b42008-11-15 11:12:47 -0500160 seq_puts(m, "\n\tShares:");
161 j = 0;
162 list_for_each(tmp3, &ses->tcon_list) {
163 tcon = list_entry(tmp3, struct cifsTconInfo,
164 tcon_list);
165 ++j;
166 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
167 seq_printf(m, "\n\t%d) %s Mounts: %d ", j,
168 tcon->treeName, tcon->tc_count);
169 if (tcon->nativeFileSystem) {
170 seq_printf(m, "Type: %s ",
171 tcon->nativeFileSystem);
172 }
173 seq_printf(m, "DevInfo: 0x%x Attributes: 0x%x"
174 "\nPathComponentMax: %d Status: 0x%d",
175 le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
176 le32_to_cpu(tcon->fsAttrInfo.Attributes),
177 le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
178 tcon->tidStatus);
179 if (dev_type == FILE_DEVICE_DISK)
180 seq_puts(m, " type: DISK ");
181 else if (dev_type == FILE_DEVICE_CD_ROM)
182 seq_puts(m, " type: CDROM ");
183 else
184 seq_printf(m, " type: %d ", dev_type);
185
186 if (tcon->need_reconnect)
187 seq_puts(m, "\tDISCONNECTED ");
188 seq_putc(m, '\n');
189 }
190
191 seq_puts(m, "\n\tMIDs:\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
193 spin_lock(&GlobalMid_Lock);
Jeff Layton14fbf502008-11-14 13:53:46 -0500194 list_for_each(tmp3, &server->pending_mid_q) {
Jeff Laytonf1987b42008-11-15 11:12:47 -0500195 mid_entry = list_entry(tmp3, struct mid_q_entry,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 qhead);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500197 seq_printf(m, "\tState: %d com: %d pid:"
Steve Frenchad8b15f2008-08-08 21:10:16 +0000198 " %d tsk: %p mid %d\n",
199 mid_entry->midState,
200 (int)mid_entry->command,
201 mid_entry->pid,
202 mid_entry->tsk,
203 mid_entry->mid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 }
Steve French221601c2007-06-05 20:35:06 +0000205 spin_unlock(&GlobalMid_Lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 }
Jeff Layton14fbf502008-11-14 13:53:46 -0500208 read_unlock(&cifs_tcp_ses_lock);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000209 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 /* BB add code to dump additional info such as TCP session info now */
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000212 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213}
214
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000215static int cifs_debug_data_proc_open(struct inode *inode, struct file *file)
216{
217 return single_open(file, cifs_debug_data_proc_show, NULL);
218}
Steve French1047abc2005-10-11 19:58:06 -0700219
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000220static const struct file_operations cifs_debug_data_proc_fops = {
221 .owner = THIS_MODULE,
222 .open = cifs_debug_data_proc_open,
223 .read = seq_read,
224 .llseek = seq_lseek,
225 .release = single_release,
226};
227
228#ifdef CONFIG_CIFS_STATS
229static ssize_t cifs_stats_proc_write(struct file *file,
230 const char __user *buffer, size_t count, loff_t *ppos)
Steve French1047abc2005-10-11 19:58:06 -0700231{
Steve French221601c2007-06-05 20:35:06 +0000232 char c;
233 int rc;
Jeff Laytonf1987b42008-11-15 11:12:47 -0500234 struct list_head *tmp1, *tmp2, *tmp3;
235 struct TCP_Server_Info *server;
236 struct cifsSesInfo *ses;
Steve French1047abc2005-10-11 19:58:06 -0700237 struct cifsTconInfo *tcon;
238
Steve French221601c2007-06-05 20:35:06 +0000239 rc = get_user(c, buffer);
240 if (rc)
241 return rc;
Steve French1047abc2005-10-11 19:58:06 -0700242
Steve French221601c2007-06-05 20:35:06 +0000243 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
Steve French4498eed52005-12-03 13:58:57 -0800244#ifdef CONFIG_CIFS_STATS2
245 atomic_set(&totBufAllocCount, 0);
246 atomic_set(&totSmBufAllocCount, 0);
247#endif /* CONFIG_CIFS_STATS2 */
Jeff Laytonf1987b42008-11-15 11:12:47 -0500248 read_lock(&cifs_tcp_ses_lock);
249 list_for_each(tmp1, &cifs_tcp_ses_list) {
250 server = list_entry(tmp1, struct TCP_Server_Info,
251 tcp_ses_list);
Steve Frenchc2b33822008-11-17 03:57:13 +0000252 list_for_each(tmp2, &server->smb_ses_list) {
Jeff Laytonf1987b42008-11-15 11:12:47 -0500253 ses = list_entry(tmp2, struct cifsSesInfo,
Steve Frenchc2b33822008-11-17 03:57:13 +0000254 smb_ses_list);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500255 list_for_each(tmp3, &ses->tcon_list) {
256 tcon = list_entry(tmp3,
257 struct cifsTconInfo,
258 tcon_list);
259 atomic_set(&tcon->num_smbs_sent, 0);
260 atomic_set(&tcon->num_writes, 0);
261 atomic_set(&tcon->num_reads, 0);
262 atomic_set(&tcon->num_oplock_brks, 0);
263 atomic_set(&tcon->num_opens, 0);
Steve French65bc98b2009-07-10 15:27:25 +0000264 atomic_set(&tcon->num_posixopens, 0);
265 atomic_set(&tcon->num_posixmkdirs, 0);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500266 atomic_set(&tcon->num_closes, 0);
267 atomic_set(&tcon->num_deletes, 0);
268 atomic_set(&tcon->num_mkdirs, 0);
269 atomic_set(&tcon->num_rmdirs, 0);
270 atomic_set(&tcon->num_renames, 0);
271 atomic_set(&tcon->num_t2renames, 0);
272 atomic_set(&tcon->num_ffirst, 0);
273 atomic_set(&tcon->num_fnext, 0);
274 atomic_set(&tcon->num_fclose, 0);
275 atomic_set(&tcon->num_hardlinks, 0);
276 atomic_set(&tcon->num_symlinks, 0);
277 atomic_set(&tcon->num_locks, 0);
278 }
279 }
Steve French1047abc2005-10-11 19:58:06 -0700280 }
Jeff Laytonf1987b42008-11-15 11:12:47 -0500281 read_unlock(&cifs_tcp_ses_lock);
Steve French1047abc2005-10-11 19:58:06 -0700282 }
283
Steve French221601c2007-06-05 20:35:06 +0000284 return count;
Steve French1047abc2005-10-11 19:58:06 -0700285}
286
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000287static int cifs_stats_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000289 int i;
Jeff Laytonf1987b42008-11-15 11:12:47 -0500290 struct list_head *tmp1, *tmp2, *tmp3;
291 struct TCP_Server_Info *server;
292 struct cifsSesInfo *ses;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 struct cifsTconInfo *tcon;
294
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000295 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 "Resources in use\nCIFS Session: %d\n",
297 sesInfoAllocCount.counter);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000298 seq_printf(m, "Share (unique mount targets): %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 tconInfoAllocCount.counter);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000300 seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
Steve Frenchb8643e12005-04-28 22:41:07 -0700301 bufAllocCount.counter,
302 cifs_min_rcv + tcpSesAllocCount.counter);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000303 seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
Steve French221601c2007-06-05 20:35:06 +0000304 smBufAllocCount.counter, cifs_min_small);
Steve French07475ff2005-12-03 14:11:37 -0800305#ifdef CONFIG_CIFS_STATS2
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000306 seq_printf(m, "Total Large %d Small %d Allocations\n",
Steve French07475ff2005-12-03 14:11:37 -0800307 atomic_read(&totBufAllocCount),
Steve French221601c2007-06-05 20:35:06 +0000308 atomic_read(&totSmBufAllocCount));
Steve French07475ff2005-12-03 14:11:37 -0800309#endif /* CONFIG_CIFS_STATS2 */
310
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000311 seq_printf(m, "Operations (MIDs): %d\n", midCount.counter);
312 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 "\n%d session %d share reconnects\n",
Steve French221601c2007-06-05 20:35:06 +0000314 tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000316 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 "Total vfs operations: %d maximum at one time: %d\n",
Steve French221601c2007-06-05 20:35:06 +0000318 GlobalCurrentXid, GlobalMaxActiveXid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
320 i = 0;
Jeff Laytonf1987b42008-11-15 11:12:47 -0500321 read_lock(&cifs_tcp_ses_lock);
322 list_for_each(tmp1, &cifs_tcp_ses_list) {
323 server = list_entry(tmp1, struct TCP_Server_Info,
324 tcp_ses_list);
325 list_for_each(tmp2, &server->smb_ses_list) {
326 ses = list_entry(tmp2, struct cifsSesInfo,
327 smb_ses_list);
328 list_for_each(tmp3, &ses->tcon_list) {
329 tcon = list_entry(tmp3,
330 struct cifsTconInfo,
331 tcon_list);
332 i++;
333 seq_printf(m, "\n%d) %s", i, tcon->treeName);
334 if (tcon->need_reconnect)
335 seq_puts(m, "\tDISCONNECTED ");
336 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
337 atomic_read(&tcon->num_smbs_sent),
338 atomic_read(&tcon->num_oplock_brks));
339 seq_printf(m, "\nReads: %d Bytes: %lld",
340 atomic_read(&tcon->num_reads),
341 (long long)(tcon->bytes_read));
342 seq_printf(m, "\nWrites: %d Bytes: %lld",
343 atomic_read(&tcon->num_writes),
344 (long long)(tcon->bytes_written));
Steve Frenchb298f222009-02-21 21:17:43 +0000345 seq_printf(m, "\nFlushes: %d",
346 atomic_read(&tcon->num_flushes));
Jeff Laytonf1987b42008-11-15 11:12:47 -0500347 seq_printf(m, "\nLocks: %d HardLinks: %d "
348 "Symlinks: %d",
349 atomic_read(&tcon->num_locks),
350 atomic_read(&tcon->num_hardlinks),
351 atomic_read(&tcon->num_symlinks));
Steve French65bc98b2009-07-10 15:27:25 +0000352 seq_printf(m, "\nOpens: %d Closes: %d "
Jeff Laytonf1987b42008-11-15 11:12:47 -0500353 "Deletes: %d",
354 atomic_read(&tcon->num_opens),
355 atomic_read(&tcon->num_closes),
356 atomic_read(&tcon->num_deletes));
Steve French65bc98b2009-07-10 15:27:25 +0000357 seq_printf(m, "\nPosix Opens: %d "
358 "Posix Mkdirs: %d",
359 atomic_read(&tcon->num_posixopens),
360 atomic_read(&tcon->num_posixmkdirs));
Jeff Laytonf1987b42008-11-15 11:12:47 -0500361 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
362 atomic_read(&tcon->num_mkdirs),
363 atomic_read(&tcon->num_rmdirs));
364 seq_printf(m, "\nRenames: %d T2 Renames %d",
365 atomic_read(&tcon->num_renames),
366 atomic_read(&tcon->num_t2renames));
367 seq_printf(m, "\nFindFirst: %d FNext %d "
368 "FClose %d",
369 atomic_read(&tcon->num_ffirst),
370 atomic_read(&tcon->num_fnext),
371 atomic_read(&tcon->num_fclose));
372 }
373 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 }
Jeff Laytonf1987b42008-11-15 11:12:47 -0500375 read_unlock(&cifs_tcp_ses_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000377 seq_putc(m, '\n');
378 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000380
381static int cifs_stats_proc_open(struct inode *inode, struct file *file)
382{
383 return single_open(file, cifs_stats_proc_show, NULL);
384}
385
386static const struct file_operations cifs_stats_proc_fops = {
387 .owner = THIS_MODULE,
388 .open = cifs_stats_proc_open,
389 .read = seq_read,
390 .llseek = seq_lseek,
391 .release = single_release,
392 .write = cifs_stats_proc_write,
393};
Steve French90c81e02008-02-12 20:32:36 +0000394#endif /* STATS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
396static struct proc_dir_entry *proc_fs_cifs;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000397static const struct file_operations cifsFYI_proc_fops;
398static const struct file_operations cifs_oplock_proc_fops;
399static const struct file_operations cifs_lookup_cache_proc_fops;
400static const struct file_operations traceSMB_proc_fops;
401static const struct file_operations cifs_multiuser_mount_proc_fops;
402static const struct file_operations cifs_security_flags_proc_fops;
403static const struct file_operations cifs_experimental_proc_fops;
404static const struct file_operations cifs_linux_ext_proc_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
406void
407cifs_proc_init(void)
408{
Alexey Dobriyan36a5aeb2008-04-29 01:01:42 -0700409 proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 if (proc_fs_cifs == NULL)
411 return;
412
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000413 proc_create("DebugData", 0, proc_fs_cifs, &cifs_debug_data_proc_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
415#ifdef CONFIG_CIFS_STATS
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000416 proc_create("Stats", 0, proc_fs_cifs, &cifs_stats_proc_fops);
Steve French90c81e02008-02-12 20:32:36 +0000417#endif /* STATS */
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000418 proc_create("cifsFYI", 0, proc_fs_cifs, &cifsFYI_proc_fops);
419 proc_create("traceSMB", 0, proc_fs_cifs, &traceSMB_proc_fops);
420 proc_create("OplockEnabled", 0, proc_fs_cifs, &cifs_oplock_proc_fops);
Steve French99b1f5b2008-07-24 02:37:45 +0000421 proc_create("Experimental", 0, proc_fs_cifs,
422 &cifs_experimental_proc_fops);
423 proc_create("LinuxExtensionsEnabled", 0, proc_fs_cifs,
424 &cifs_linux_ext_proc_fops);
425 proc_create("MultiuserMount", 0, proc_fs_cifs,
426 &cifs_multiuser_mount_proc_fops);
427 proc_create("SecurityFlags", 0, proc_fs_cifs,
428 &cifs_security_flags_proc_fops);
429 proc_create("LookupCacheEnabled", 0, proc_fs_cifs,
430 &cifs_lookup_cache_proc_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431}
432
433void
434cifs_proc_clean(void)
435{
436 if (proc_fs_cifs == NULL)
437 return;
438
439 remove_proc_entry("DebugData", proc_fs_cifs);
440 remove_proc_entry("cifsFYI", proc_fs_cifs);
441 remove_proc_entry("traceSMB", proc_fs_cifs);
442#ifdef CONFIG_CIFS_STATS
443 remove_proc_entry("Stats", proc_fs_cifs);
444#endif
445 remove_proc_entry("MultiuserMount", proc_fs_cifs);
446 remove_proc_entry("OplockEnabled", proc_fs_cifs);
Steve French221601c2007-06-05 20:35:06 +0000447 remove_proc_entry("SecurityFlags", proc_fs_cifs);
Steve French221601c2007-06-05 20:35:06 +0000448 remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
449 remove_proc_entry("Experimental", proc_fs_cifs);
450 remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
Alexey Dobriyan36a5aeb2008-04-29 01:01:42 -0700451 remove_proc_entry("fs/cifs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452}
453
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000454static int cifsFYI_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000456 seq_printf(m, "%d\n", cifsFYI);
457 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000459
460static int cifsFYI_proc_open(struct inode *inode, struct file *file)
461{
462 return single_open(file, cifsFYI_proc_show, NULL);
463}
464
465static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
466 size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467{
468 char c;
469 int rc;
470
471 rc = get_user(c, buffer);
472 if (rc)
473 return rc;
474 if (c == '0' || c == 'n' || c == 'N')
475 cifsFYI = 0;
476 else if (c == '1' || c == 'y' || c == 'Y')
477 cifsFYI = 1;
Steve French221601c2007-06-05 20:35:06 +0000478 else if ((c > '1') && (c <= '9'))
Steve French1047abc2005-10-11 19:58:06 -0700479 cifsFYI = (int) (c - '0'); /* see cifs_debug.h for meanings */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
481 return count;
482}
483
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000484static const struct file_operations cifsFYI_proc_fops = {
485 .owner = THIS_MODULE,
486 .open = cifsFYI_proc_open,
487 .read = seq_read,
488 .llseek = seq_lseek,
489 .release = single_release,
490 .write = cifsFYI_proc_write,
491};
492
493static int cifs_oplock_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000495 seq_printf(m, "%d\n", oplockEnabled);
496 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000498
499static int cifs_oplock_proc_open(struct inode *inode, struct file *file)
500{
501 return single_open(file, cifs_oplock_proc_show, NULL);
502}
503
504static ssize_t cifs_oplock_proc_write(struct file *file,
505 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506{
507 char c;
508 int rc;
509
510 rc = get_user(c, buffer);
511 if (rc)
512 return rc;
513 if (c == '0' || c == 'n' || c == 'N')
514 oplockEnabled = 0;
515 else if (c == '1' || c == 'y' || c == 'Y')
516 oplockEnabled = 1;
517
518 return count;
519}
520
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000521static const struct file_operations cifs_oplock_proc_fops = {
522 .owner = THIS_MODULE,
523 .open = cifs_oplock_proc_open,
524 .read = seq_read,
525 .llseek = seq_lseek,
526 .release = single_release,
527 .write = cifs_oplock_proc_write,
528};
529
530static int cifs_experimental_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000532 seq_printf(m, "%d\n", experimEnabled);
533 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000535
536static int cifs_experimental_proc_open(struct inode *inode, struct file *file)
537{
538 return single_open(file, cifs_experimental_proc_show, NULL);
539}
540
541static ssize_t cifs_experimental_proc_write(struct file *file,
542 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543{
Steve Frenchec637e32005-12-12 20:53:18 -0800544 char c;
545 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
Steve Frenchec637e32005-12-12 20:53:18 -0800547 rc = get_user(c, buffer);
548 if (rc)
549 return rc;
550 if (c == '0' || c == 'n' || c == 'N')
551 experimEnabled = 0;
552 else if (c == '1' || c == 'y' || c == 'Y')
553 experimEnabled = 1;
554 else if (c == '2')
555 experimEnabled = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556
Steve Frenchec637e32005-12-12 20:53:18 -0800557 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558}
559
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000560static const struct file_operations cifs_experimental_proc_fops = {
561 .owner = THIS_MODULE,
562 .open = cifs_experimental_proc_open,
563 .read = seq_read,
564 .llseek = seq_lseek,
565 .release = single_release,
566 .write = cifs_experimental_proc_write,
567};
568
569static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000571 seq_printf(m, "%d\n", linuxExtEnabled);
572 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000574
575static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
576{
577 return single_open(file, cifs_linux_ext_proc_show, NULL);
578}
579
580static ssize_t cifs_linux_ext_proc_write(struct file *file,
581 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582{
Steve French221601c2007-06-05 20:35:06 +0000583 char c;
584 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
Steve French221601c2007-06-05 20:35:06 +0000586 rc = get_user(c, buffer);
587 if (rc)
588 return rc;
589 if (c == '0' || c == 'n' || c == 'N')
590 linuxExtEnabled = 0;
591 else if (c == '1' || c == 'y' || c == 'Y')
592 linuxExtEnabled = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593
Steve French221601c2007-06-05 20:35:06 +0000594 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595}
596
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000597static const struct file_operations cifs_linux_ext_proc_fops = {
598 .owner = THIS_MODULE,
599 .open = cifs_linux_ext_proc_open,
600 .read = seq_read,
601 .llseek = seq_lseek,
602 .release = single_release,
603 .write = cifs_linux_ext_proc_write,
604};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000606static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000608 seq_printf(m, "%d\n", lookupCacheEnabled);
609 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000611
612static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
613{
614 return single_open(file, cifs_lookup_cache_proc_show, NULL);
615}
616
617static ssize_t cifs_lookup_cache_proc_write(struct file *file,
618 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619{
620 char c;
621 int rc;
622
623 rc = get_user(c, buffer);
624 if (rc)
625 return rc;
626 if (c == '0' || c == 'n' || c == 'N')
627 lookupCacheEnabled = 0;
628 else if (c == '1' || c == 'y' || c == 'Y')
629 lookupCacheEnabled = 1;
630
631 return count;
632}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000633
634static const struct file_operations cifs_lookup_cache_proc_fops = {
635 .owner = THIS_MODULE,
636 .open = cifs_lookup_cache_proc_open,
637 .read = seq_read,
638 .llseek = seq_lseek,
639 .release = single_release,
640 .write = cifs_lookup_cache_proc_write,
641};
642
643static int traceSMB_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000645 seq_printf(m, "%d\n", traceSMB);
646 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000648
649static int traceSMB_proc_open(struct inode *inode, struct file *file)
650{
651 return single_open(file, traceSMB_proc_show, NULL);
652}
653
654static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
655 size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656{
657 char c;
658 int rc;
659
660 rc = get_user(c, buffer);
661 if (rc)
662 return rc;
663 if (c == '0' || c == 'n' || c == 'N')
664 traceSMB = 0;
665 else if (c == '1' || c == 'y' || c == 'Y')
666 traceSMB = 1;
667
668 return count;
669}
670
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000671static const struct file_operations traceSMB_proc_fops = {
672 .owner = THIS_MODULE,
673 .open = traceSMB_proc_open,
674 .read = seq_read,
675 .llseek = seq_lseek,
676 .release = single_release,
677 .write = traceSMB_proc_write,
678};
679
680static int cifs_multiuser_mount_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000682 seq_printf(m, "%d\n", multiuser_mount);
683 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000685
Steve French99b1f5b2008-07-24 02:37:45 +0000686static int cifs_multiuser_mount_proc_open(struct inode *inode, struct file *fh)
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000687{
Steve French99b1f5b2008-07-24 02:37:45 +0000688 return single_open(fh, cifs_multiuser_mount_proc_show, NULL);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000689}
690
691static ssize_t cifs_multiuser_mount_proc_write(struct file *file,
692 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693{
694 char c;
695 int rc;
696
697 rc = get_user(c, buffer);
698 if (rc)
699 return rc;
700 if (c == '0' || c == 'n' || c == 'N')
701 multiuser_mount = 0;
702 else if (c == '1' || c == 'y' || c == 'Y')
703 multiuser_mount = 1;
704
705 return count;
706}
707
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000708static const struct file_operations cifs_multiuser_mount_proc_fops = {
709 .owner = THIS_MODULE,
710 .open = cifs_multiuser_mount_proc_open,
711 .read = seq_read,
712 .llseek = seq_lseek,
713 .release = single_release,
714 .write = cifs_multiuser_mount_proc_write,
715};
716
717static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718{
Jeff Layton04912d62010-04-24 07:57:45 -0400719 seq_printf(m, "0x%x\n", global_secflags);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000720 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000722
723static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
724{
725 return single_open(file, cifs_security_flags_proc_show, NULL);
726}
727
728static ssize_t cifs_security_flags_proc_write(struct file *file,
729 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730{
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000731 unsigned int flags;
732 char flags_string[12];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 char c;
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000734
Steve French221601c2007-06-05 20:35:06 +0000735 if ((count < 1) || (count > 11))
Steve French39798772006-05-31 22:40:51 +0000736 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000738 memset(flags_string, 0, 12);
Steve French39798772006-05-31 22:40:51 +0000739
Steve French221601c2007-06-05 20:35:06 +0000740 if (copy_from_user(flags_string, buffer, count))
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000741 return -EFAULT;
Steve French39798772006-05-31 22:40:51 +0000742
Steve French221601c2007-06-05 20:35:06 +0000743 if (count < 3) {
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000744 /* single char or single char followed by null */
745 c = flags_string[0];
Steve Frencha0136892007-10-04 20:05:09 +0000746 if (c == '0' || c == 'n' || c == 'N') {
Jeff Layton04912d62010-04-24 07:57:45 -0400747 global_secflags = CIFSSEC_DEF; /* default */
Steve Frencha0136892007-10-04 20:05:09 +0000748 return count;
749 } else if (c == '1' || c == 'y' || c == 'Y') {
Jeff Layton04912d62010-04-24 07:57:45 -0400750 global_secflags = CIFSSEC_MAX;
Steve Frencha0136892007-10-04 20:05:09 +0000751 return count;
752 } else if (!isdigit(c)) {
Joe Perchesb6b38f72010-04-21 03:50:45 +0000753 cERROR(1, "invalid flag %c", c);
Steve Frencha0136892007-10-04 20:05:09 +0000754 return -EINVAL;
755 }
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000756 }
757 /* else we have a number */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000759 flags = simple_strtoul(flags_string, NULL, 0);
760
Joe Perchesb6b38f72010-04-21 03:50:45 +0000761 cFYI(1, "sec flags 0x%x", flags);
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000762
Steve French221601c2007-06-05 20:35:06 +0000763 if (flags <= 0) {
Joe Perchesb6b38f72010-04-21 03:50:45 +0000764 cERROR(1, "invalid security flags %s", flags_string);
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000765 return -EINVAL;
766 }
767
Steve French221601c2007-06-05 20:35:06 +0000768 if (flags & ~CIFSSEC_MASK) {
Joe Perchesb6b38f72010-04-21 03:50:45 +0000769 cERROR(1, "attempt to set unsupported security flags 0x%x",
770 flags & ~CIFSSEC_MASK);
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000771 return -EINVAL;
772 }
773 /* flags look ok - update the global security flags for cifs module */
Jeff Layton04912d62010-04-24 07:57:45 -0400774 global_secflags = flags;
775 if (global_secflags & CIFSSEC_MUST_SIGN) {
Steve French762e5ab2007-06-28 18:41:42 +0000776 /* requiring signing implies signing is allowed */
Jeff Layton04912d62010-04-24 07:57:45 -0400777 global_secflags |= CIFSSEC_MAY_SIGN;
Joe Perchesb6b38f72010-04-21 03:50:45 +0000778 cFYI(1, "packet signing now required");
Jeff Layton04912d62010-04-24 07:57:45 -0400779 } else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) {
Joe Perchesb6b38f72010-04-21 03:50:45 +0000780 cFYI(1, "packet signing disabled");
Steve French762e5ab2007-06-28 18:41:42 +0000781 }
782 /* BB should we turn on MAY flags for other MUST options? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 return count;
784}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000785
786static const struct file_operations cifs_security_flags_proc_fops = {
787 .owner = THIS_MODULE,
788 .open = cifs_security_flags_proc_open,
789 .read = seq_read,
790 .llseek = seq_lseek,
791 .release = single_release,
792 .write = cifs_security_flags_proc_write,
793};
Steve French90c81e02008-02-12 20:32:36 +0000794#else
Steve Frenche086fce2008-02-18 04:03:58 +0000795inline void cifs_proc_init(void)
Steve French90c81e02008-02-12 20:32:36 +0000796{
797}
798
Steve Frenche086fce2008-02-18 04:03:58 +0000799inline void cifs_proc_clean(void)
Steve French90c81e02008-02-12 20:32:36 +0000800{
801}
802#endif /* PROC_FS */