blob: 59841a68b0b672eb61f46a886046b2d012699d8f [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{
Steve French221601c2007-06-05 20:35:06 +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,
65 smb->Flags, smb->Flags2, smb->Mid, smb->Pid));
Steve French221601c2007-06-05 20:35:06 +000066 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
Steve French221601c2007-06-05 20:35:06 +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);
Steve Frenchad8b15f2008-08-08 21:10:16 +000082 cERROR(1, ("State: %d Cmd: %d Pid: %d Tsk: %p Mid %d",
83 mid_entry->midState,
84 (int)mid_entry->command,
85 mid_entry->pid,
86 mid_entry->tsk,
87 mid_entry->mid));
Steve French39798772006-05-31 22:40:51 +000088#ifdef CONFIG_CIFS_STATS2
Steve Frenchad8b15f2008-08-08 21:10:16 +000089 cERROR(1, ("IsLarge: %d buf: %p time rcv: %ld now: %ld",
90 mid_entry->largeBuf,
91 mid_entry->resp_buf,
92 mid_entry->when_received,
93 jiffies));
Steve French39798772006-05-31 22:40:51 +000094#endif /* STATS2 */
Steve Frenchad8b15f2008-08-08 21:10:16 +000095 cERROR(1, ("IsMult: %d IsEnd: %d", mid_entry->multiRsp,
96 mid_entry->multiEnd));
97 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 Layton14fbf502008-11-14 13:53:46 -0500110 struct list_head *tmp, *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;
115 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000117 seq_puts(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 "Display Internal CIFS Data Structures for Debugging\n"
119 "---------------------------------------------------\n");
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000120 seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
121 seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
122 seq_printf(m, "Servers:");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124 i = 0;
Jeff Layton14fbf502008-11-14 13:53:46 -0500125 read_lock(&cifs_tcp_ses_lock);
126 list_for_each(tmp, &cifs_tcp_ses_list) {
127 server = list_entry(tmp, struct TCP_Server_Info,
128 tcp_ses_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 i++;
Jeff Layton14fbf502008-11-14 13:53:46 -0500130 list_for_each(tmp2, &server->smb_ses_list) {
131 ses = list_entry(tmp2, struct cifsSesInfo,
132 smb_ses_list);
133 if ((ses->serverDomain == NULL) ||
134 (ses->serverOS == NULL) ||
135 (ses->serverNOS == NULL)) {
136 seq_printf(m, "\nentry for %s not fully "
137 "displayed\n\t", ses->serverName);
138 } else {
139 seq_printf(m,
Steve French221601c2007-06-05 20:35:06 +0000140 "\n%d) Name: %s Domain: %s Mounts: %d OS:"
141 " %s \n\tNOS: %s\tCapability: 0x%x\n\tSMB"
142 " session status: %d\t",
Steve Frenchb8643e12005-04-28 22:41:07 -0700143 i, ses->serverName, ses->serverDomain,
Jeff Layton14fbf502008-11-14 13:53:46 -0500144 ses->ses_count, ses->serverOS, ses->serverNOS,
Steve French221601c2007-06-05 20:35:06 +0000145 ses->capabilities, ses->status);
Jeff Layton14fbf502008-11-14 13:53:46 -0500146 }
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000147 seq_printf(m, "TCP status: %d\n\tLocal Users To "
Jeff Layton14fbf502008-11-14 13:53:46 -0500148 "Server: %d SecMode: 0x%x Req On Wire: %d",
149 server->tcpStatus, server->srv_count,
150 server->secMode,
151 atomic_read(&server->inFlight));
Steve French131afd0b2005-10-07 09:51:05 -0700152
153#ifdef CONFIG_CIFS_STATS2
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000154 seq_printf(m, " In Send: %d In MaxReq Wait: %d",
Jeff Layton14fbf502008-11-14 13:53:46 -0500155 atomic_read(&server->inSend),
156 atomic_read(&server->num_waiters));
Steve French131afd0b2005-10-07 09:51:05 -0700157#endif
158
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000159 seq_puts(m, "\nMIDs:\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
161 spin_lock(&GlobalMid_Lock);
Jeff Layton14fbf502008-11-14 13:53:46 -0500162 list_for_each(tmp3, &server->pending_mid_q) {
163 mid_entry = list_entry(tmp3, struct
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 mid_q_entry,
165 qhead);
Steve Frenchad8b15f2008-08-08 21:10:16 +0000166 seq_printf(m, "State: %d com: %d pid:"
167 " %d tsk: %p mid %d\n",
168 mid_entry->midState,
169 (int)mid_entry->command,
170 mid_entry->pid,
171 mid_entry->tsk,
172 mid_entry->mid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 }
Steve French221601c2007-06-05 20:35:06 +0000174 spin_unlock(&GlobalMid_Lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 }
Jeff Layton14fbf502008-11-14 13:53:46 -0500177 read_unlock(&cifs_tcp_ses_lock);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000178 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000180 seq_puts(m, "Shares:");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
182 i = 0;
183 read_lock(&GlobalSMBSeslock);
184 list_for_each(tmp, &GlobalTreeConnectionList) {
185 __u32 dev_type;
186 i++;
187 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
188 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000189 seq_printf(m, "\n%d) %s Uses: %d ", i,
Steve French88f370a2007-09-15 03:01:17 +0000190 tcon->treeName, atomic_read(&tcon->useCount));
Steve French88f370a2007-09-15 03:01:17 +0000191 if (tcon->nativeFileSystem) {
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000192 seq_printf(m, "Type: %s ",
Steve Frencha23d3062007-09-15 03:43:47 +0000193 tcon->nativeFileSystem);
Steve French88f370a2007-09-15 03:01:17 +0000194 }
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000195 seq_printf(m, "DevInfo: 0x%x Attributes: 0x%x"
Steve French88f370a2007-09-15 03:01:17 +0000196 "\nPathComponentMax: %d Status: %d",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
198 le32_to_cpu(tcon->fsAttrInfo.Attributes),
199 le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
200 tcon->tidStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 if (dev_type == FILE_DEVICE_DISK)
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000202 seq_puts(m, " type: DISK ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 else if (dev_type == FILE_DEVICE_CD_ROM)
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000204 seq_puts(m, " type: CDROM ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 else
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000206 seq_printf(m, " type: %d ", dev_type);
Shirish Pargaonkaref571ca2008-07-24 15:56:05 +0000207
Steve Frenchfb396012008-11-13 20:04:07 +0000208 if (tcon->need_reconnect)
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000209 seq_puts(m, "\tDISCONNECTED ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 }
211 read_unlock(&GlobalSMBSeslock);
212
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000213 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
215 /* BB add code to dump additional info such as TCP session info now */
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000216 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217}
218
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000219static int cifs_debug_data_proc_open(struct inode *inode, struct file *file)
220{
221 return single_open(file, cifs_debug_data_proc_show, NULL);
222}
Steve French1047abc2005-10-11 19:58:06 -0700223
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000224static const struct file_operations cifs_debug_data_proc_fops = {
225 .owner = THIS_MODULE,
226 .open = cifs_debug_data_proc_open,
227 .read = seq_read,
228 .llseek = seq_lseek,
229 .release = single_release,
230};
231
232#ifdef CONFIG_CIFS_STATS
233static ssize_t cifs_stats_proc_write(struct file *file,
234 const char __user *buffer, size_t count, loff_t *ppos)
Steve French1047abc2005-10-11 19:58:06 -0700235{
Steve French221601c2007-06-05 20:35:06 +0000236 char c;
237 int rc;
Steve French1047abc2005-10-11 19:58:06 -0700238 struct list_head *tmp;
239 struct cifsTconInfo *tcon;
240
Steve French221601c2007-06-05 20:35:06 +0000241 rc = get_user(c, buffer);
242 if (rc)
243 return rc;
Steve French1047abc2005-10-11 19:58:06 -0700244
Steve French221601c2007-06-05 20:35:06 +0000245 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
Steve French1047abc2005-10-11 19:58:06 -0700246 read_lock(&GlobalSMBSeslock);
Steve French4498eed52005-12-03 13:58:57 -0800247#ifdef CONFIG_CIFS_STATS2
248 atomic_set(&totBufAllocCount, 0);
249 atomic_set(&totSmBufAllocCount, 0);
250#endif /* CONFIG_CIFS_STATS2 */
Steve French1047abc2005-10-11 19:58:06 -0700251 list_for_each(tmp, &GlobalTreeConnectionList) {
252 tcon = list_entry(tmp, struct cifsTconInfo,
253 cifsConnectionList);
254 atomic_set(&tcon->num_smbs_sent, 0);
255 atomic_set(&tcon->num_writes, 0);
256 atomic_set(&tcon->num_reads, 0);
257 atomic_set(&tcon->num_oplock_brks, 0);
258 atomic_set(&tcon->num_opens, 0);
259 atomic_set(&tcon->num_closes, 0);
260 atomic_set(&tcon->num_deletes, 0);
261 atomic_set(&tcon->num_mkdirs, 0);
262 atomic_set(&tcon->num_rmdirs, 0);
263 atomic_set(&tcon->num_renames, 0);
264 atomic_set(&tcon->num_t2renames, 0);
265 atomic_set(&tcon->num_ffirst, 0);
266 atomic_set(&tcon->num_fnext, 0);
267 atomic_set(&tcon->num_fclose, 0);
268 atomic_set(&tcon->num_hardlinks, 0);
269 atomic_set(&tcon->num_symlinks, 0);
270 atomic_set(&tcon->num_locks, 0);
271 }
272 read_unlock(&GlobalSMBSeslock);
273 }
274
Steve French221601c2007-06-05 20:35:06 +0000275 return count;
Steve French1047abc2005-10-11 19:58:06 -0700276}
277
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000278static int cifs_stats_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000280 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 struct list_head *tmp;
282 struct cifsTconInfo *tcon;
283
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000284 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 "Resources in use\nCIFS Session: %d\n",
286 sesInfoAllocCount.counter);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000287 seq_printf(m, "Share (unique mount targets): %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 tconInfoAllocCount.counter);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000289 seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
Steve Frenchb8643e12005-04-28 22:41:07 -0700290 bufAllocCount.counter,
291 cifs_min_rcv + tcpSesAllocCount.counter);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000292 seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
Steve French221601c2007-06-05 20:35:06 +0000293 smBufAllocCount.counter, cifs_min_small);
Steve French07475ff2005-12-03 14:11:37 -0800294#ifdef CONFIG_CIFS_STATS2
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000295 seq_printf(m, "Total Large %d Small %d Allocations\n",
Steve French07475ff2005-12-03 14:11:37 -0800296 atomic_read(&totBufAllocCount),
Steve French221601c2007-06-05 20:35:06 +0000297 atomic_read(&totSmBufAllocCount));
Steve French07475ff2005-12-03 14:11:37 -0800298#endif /* CONFIG_CIFS_STATS2 */
299
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000300 seq_printf(m, "Operations (MIDs): %d\n", midCount.counter);
301 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 "\n%d session %d share reconnects\n",
Steve French221601c2007-06-05 20:35:06 +0000303 tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000305 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 "Total vfs operations: %d maximum at one time: %d\n",
Steve French221601c2007-06-05 20:35:06 +0000307 GlobalCurrentXid, GlobalMaxActiveXid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
309 i = 0;
310 read_lock(&GlobalSMBSeslock);
311 list_for_each(tmp, &GlobalTreeConnectionList) {
312 i++;
313 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000314 seq_printf(m, "\n%d) %s", i, tcon->treeName);
Steve Frenchfb396012008-11-13 20:04:07 +0000315 if (tcon->need_reconnect)
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000316 seq_puts(m, "\tDISCONNECTED ");
317 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 atomic_read(&tcon->num_smbs_sent),
319 atomic_read(&tcon->num_oplock_brks));
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000320 seq_printf(m, "\nReads: %d Bytes: %lld",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 atomic_read(&tcon->num_reads),
322 (long long)(tcon->bytes_read));
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000323 seq_printf(m, "\nWrites: %d Bytes: %lld",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 atomic_read(&tcon->num_writes),
325 (long long)(tcon->bytes_written));
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000326 seq_printf(m,
Steve Frencha5a2b482005-08-20 21:42:53 -0700327 "\nLocks: %d HardLinks: %d Symlinks: %d",
Steve French221601c2007-06-05 20:35:06 +0000328 atomic_read(&tcon->num_locks),
Steve Frencha5a2b482005-08-20 21:42:53 -0700329 atomic_read(&tcon->num_hardlinks),
330 atomic_read(&tcon->num_symlinks));
Steve Frencha5a2b482005-08-20 21:42:53 -0700331
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000332 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
Steve Frencha5a2b482005-08-20 21:42:53 -0700333 atomic_read(&tcon->num_opens),
334 atomic_read(&tcon->num_closes),
335 atomic_read(&tcon->num_deletes));
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000336 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 atomic_read(&tcon->num_mkdirs),
338 atomic_read(&tcon->num_rmdirs));
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000339 seq_printf(m, "\nRenames: %d T2 Renames %d",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 atomic_read(&tcon->num_renames),
341 atomic_read(&tcon->num_t2renames));
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000342 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
Steve French0c0ff092005-06-23 19:31:17 -0500343 atomic_read(&tcon->num_ffirst),
344 atomic_read(&tcon->num_fnext),
345 atomic_read(&tcon->num_fclose));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 }
347 read_unlock(&GlobalSMBSeslock);
348
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000349 seq_putc(m, '\n');
350 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000352
353static int cifs_stats_proc_open(struct inode *inode, struct file *file)
354{
355 return single_open(file, cifs_stats_proc_show, NULL);
356}
357
358static const struct file_operations cifs_stats_proc_fops = {
359 .owner = THIS_MODULE,
360 .open = cifs_stats_proc_open,
361 .read = seq_read,
362 .llseek = seq_lseek,
363 .release = single_release,
364 .write = cifs_stats_proc_write,
365};
Steve French90c81e02008-02-12 20:32:36 +0000366#endif /* STATS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
368static struct proc_dir_entry *proc_fs_cifs;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000369static const struct file_operations cifsFYI_proc_fops;
370static const struct file_operations cifs_oplock_proc_fops;
371static const struct file_operations cifs_lookup_cache_proc_fops;
372static const struct file_operations traceSMB_proc_fops;
373static const struct file_operations cifs_multiuser_mount_proc_fops;
374static const struct file_operations cifs_security_flags_proc_fops;
375static const struct file_operations cifs_experimental_proc_fops;
376static const struct file_operations cifs_linux_ext_proc_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
378void
379cifs_proc_init(void)
380{
Alexey Dobriyan36a5aeb2008-04-29 01:01:42 -0700381 proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 if (proc_fs_cifs == NULL)
383 return;
384
385 proc_fs_cifs->owner = THIS_MODULE;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000386 proc_create("DebugData", 0, proc_fs_cifs, &cifs_debug_data_proc_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
388#ifdef CONFIG_CIFS_STATS
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000389 proc_create("Stats", 0, proc_fs_cifs, &cifs_stats_proc_fops);
Steve French90c81e02008-02-12 20:32:36 +0000390#endif /* STATS */
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000391 proc_create("cifsFYI", 0, proc_fs_cifs, &cifsFYI_proc_fops);
392 proc_create("traceSMB", 0, proc_fs_cifs, &traceSMB_proc_fops);
393 proc_create("OplockEnabled", 0, proc_fs_cifs, &cifs_oplock_proc_fops);
Steve French99b1f5b2008-07-24 02:37:45 +0000394 proc_create("Experimental", 0, proc_fs_cifs,
395 &cifs_experimental_proc_fops);
396 proc_create("LinuxExtensionsEnabled", 0, proc_fs_cifs,
397 &cifs_linux_ext_proc_fops);
398 proc_create("MultiuserMount", 0, proc_fs_cifs,
399 &cifs_multiuser_mount_proc_fops);
400 proc_create("SecurityFlags", 0, proc_fs_cifs,
401 &cifs_security_flags_proc_fops);
402 proc_create("LookupCacheEnabled", 0, proc_fs_cifs,
403 &cifs_lookup_cache_proc_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404}
405
406void
407cifs_proc_clean(void)
408{
409 if (proc_fs_cifs == NULL)
410 return;
411
412 remove_proc_entry("DebugData", proc_fs_cifs);
413 remove_proc_entry("cifsFYI", proc_fs_cifs);
414 remove_proc_entry("traceSMB", proc_fs_cifs);
415#ifdef CONFIG_CIFS_STATS
416 remove_proc_entry("Stats", proc_fs_cifs);
417#endif
418 remove_proc_entry("MultiuserMount", proc_fs_cifs);
419 remove_proc_entry("OplockEnabled", proc_fs_cifs);
Steve French221601c2007-06-05 20:35:06 +0000420 remove_proc_entry("SecurityFlags", proc_fs_cifs);
Steve French221601c2007-06-05 20:35:06 +0000421 remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
422 remove_proc_entry("Experimental", proc_fs_cifs);
423 remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
Alexey Dobriyan36a5aeb2008-04-29 01:01:42 -0700424 remove_proc_entry("fs/cifs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425}
426
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000427static int cifsFYI_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000429 seq_printf(m, "%d\n", cifsFYI);
430 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000432
433static int cifsFYI_proc_open(struct inode *inode, struct file *file)
434{
435 return single_open(file, cifsFYI_proc_show, NULL);
436}
437
438static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
439 size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440{
441 char c;
442 int rc;
443
444 rc = get_user(c, buffer);
445 if (rc)
446 return rc;
447 if (c == '0' || c == 'n' || c == 'N')
448 cifsFYI = 0;
449 else if (c == '1' || c == 'y' || c == 'Y')
450 cifsFYI = 1;
Steve French221601c2007-06-05 20:35:06 +0000451 else if ((c > '1') && (c <= '9'))
Steve French1047abc2005-10-11 19:58:06 -0700452 cifsFYI = (int) (c - '0'); /* see cifs_debug.h for meanings */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
454 return count;
455}
456
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000457static const struct file_operations cifsFYI_proc_fops = {
458 .owner = THIS_MODULE,
459 .open = cifsFYI_proc_open,
460 .read = seq_read,
461 .llseek = seq_lseek,
462 .release = single_release,
463 .write = cifsFYI_proc_write,
464};
465
466static int cifs_oplock_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000468 seq_printf(m, "%d\n", oplockEnabled);
469 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000471
472static int cifs_oplock_proc_open(struct inode *inode, struct file *file)
473{
474 return single_open(file, cifs_oplock_proc_show, NULL);
475}
476
477static ssize_t cifs_oplock_proc_write(struct file *file,
478 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479{
480 char c;
481 int rc;
482
483 rc = get_user(c, buffer);
484 if (rc)
485 return rc;
486 if (c == '0' || c == 'n' || c == 'N')
487 oplockEnabled = 0;
488 else if (c == '1' || c == 'y' || c == 'Y')
489 oplockEnabled = 1;
490
491 return count;
492}
493
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000494static const struct file_operations cifs_oplock_proc_fops = {
495 .owner = THIS_MODULE,
496 .open = cifs_oplock_proc_open,
497 .read = seq_read,
498 .llseek = seq_lseek,
499 .release = single_release,
500 .write = cifs_oplock_proc_write,
501};
502
503static int cifs_experimental_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000505 seq_printf(m, "%d\n", experimEnabled);
506 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000508
509static int cifs_experimental_proc_open(struct inode *inode, struct file *file)
510{
511 return single_open(file, cifs_experimental_proc_show, NULL);
512}
513
514static ssize_t cifs_experimental_proc_write(struct file *file,
515 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516{
Steve Frenchec637e32005-12-12 20:53:18 -0800517 char c;
518 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
Steve Frenchec637e32005-12-12 20:53:18 -0800520 rc = get_user(c, buffer);
521 if (rc)
522 return rc;
523 if (c == '0' || c == 'n' || c == 'N')
524 experimEnabled = 0;
525 else if (c == '1' || c == 'y' || c == 'Y')
526 experimEnabled = 1;
527 else if (c == '2')
528 experimEnabled = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
Steve Frenchec637e32005-12-12 20:53:18 -0800530 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531}
532
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000533static const struct file_operations cifs_experimental_proc_fops = {
534 .owner = THIS_MODULE,
535 .open = cifs_experimental_proc_open,
536 .read = seq_read,
537 .llseek = seq_lseek,
538 .release = single_release,
539 .write = cifs_experimental_proc_write,
540};
541
542static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000544 seq_printf(m, "%d\n", linuxExtEnabled);
545 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000547
548static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
549{
550 return single_open(file, cifs_linux_ext_proc_show, NULL);
551}
552
553static ssize_t cifs_linux_ext_proc_write(struct file *file,
554 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555{
Steve French221601c2007-06-05 20:35:06 +0000556 char c;
557 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
Steve French221601c2007-06-05 20:35:06 +0000559 rc = get_user(c, buffer);
560 if (rc)
561 return rc;
562 if (c == '0' || c == 'n' || c == 'N')
563 linuxExtEnabled = 0;
564 else if (c == '1' || c == 'y' || c == 'Y')
565 linuxExtEnabled = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566
Steve French221601c2007-06-05 20:35:06 +0000567 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568}
569
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000570static const struct file_operations cifs_linux_ext_proc_fops = {
571 .owner = THIS_MODULE,
572 .open = cifs_linux_ext_proc_open,
573 .read = seq_read,
574 .llseek = seq_lseek,
575 .release = single_release,
576 .write = cifs_linux_ext_proc_write,
577};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000579static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000581 seq_printf(m, "%d\n", lookupCacheEnabled);
582 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000584
585static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
586{
587 return single_open(file, cifs_lookup_cache_proc_show, NULL);
588}
589
590static ssize_t cifs_lookup_cache_proc_write(struct file *file,
591 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592{
593 char c;
594 int rc;
595
596 rc = get_user(c, buffer);
597 if (rc)
598 return rc;
599 if (c == '0' || c == 'n' || c == 'N')
600 lookupCacheEnabled = 0;
601 else if (c == '1' || c == 'y' || c == 'Y')
602 lookupCacheEnabled = 1;
603
604 return count;
605}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000606
607static const struct file_operations cifs_lookup_cache_proc_fops = {
608 .owner = THIS_MODULE,
609 .open = cifs_lookup_cache_proc_open,
610 .read = seq_read,
611 .llseek = seq_lseek,
612 .release = single_release,
613 .write = cifs_lookup_cache_proc_write,
614};
615
616static int traceSMB_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000618 seq_printf(m, "%d\n", traceSMB);
619 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000621
622static int traceSMB_proc_open(struct inode *inode, struct file *file)
623{
624 return single_open(file, traceSMB_proc_show, NULL);
625}
626
627static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
628 size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629{
630 char c;
631 int rc;
632
633 rc = get_user(c, buffer);
634 if (rc)
635 return rc;
636 if (c == '0' || c == 'n' || c == 'N')
637 traceSMB = 0;
638 else if (c == '1' || c == 'y' || c == 'Y')
639 traceSMB = 1;
640
641 return count;
642}
643
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000644static const struct file_operations traceSMB_proc_fops = {
645 .owner = THIS_MODULE,
646 .open = traceSMB_proc_open,
647 .read = seq_read,
648 .llseek = seq_lseek,
649 .release = single_release,
650 .write = traceSMB_proc_write,
651};
652
653static int cifs_multiuser_mount_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000655 seq_printf(m, "%d\n", multiuser_mount);
656 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000658
Steve French99b1f5b2008-07-24 02:37:45 +0000659static int cifs_multiuser_mount_proc_open(struct inode *inode, struct file *fh)
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000660{
Steve French99b1f5b2008-07-24 02:37:45 +0000661 return single_open(fh, cifs_multiuser_mount_proc_show, NULL);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000662}
663
664static ssize_t cifs_multiuser_mount_proc_write(struct file *file,
665 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666{
667 char c;
668 int rc;
669
670 rc = get_user(c, buffer);
671 if (rc)
672 return rc;
673 if (c == '0' || c == 'n' || c == 'N')
674 multiuser_mount = 0;
675 else if (c == '1' || c == 'y' || c == 'Y')
676 multiuser_mount = 1;
677
678 return count;
679}
680
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000681static const struct file_operations cifs_multiuser_mount_proc_fops = {
682 .owner = THIS_MODULE,
683 .open = cifs_multiuser_mount_proc_open,
684 .read = seq_read,
685 .llseek = seq_lseek,
686 .release = single_release,
687 .write = cifs_multiuser_mount_proc_write,
688};
689
690static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000692 seq_printf(m, "0x%x\n", extended_security);
693 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000695
696static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
697{
698 return single_open(file, cifs_security_flags_proc_show, NULL);
699}
700
701static ssize_t cifs_security_flags_proc_write(struct file *file,
702 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703{
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000704 unsigned int flags;
705 char flags_string[12];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 char c;
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000707
Steve French221601c2007-06-05 20:35:06 +0000708 if ((count < 1) || (count > 11))
Steve French39798772006-05-31 22:40:51 +0000709 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000711 memset(flags_string, 0, 12);
Steve French39798772006-05-31 22:40:51 +0000712
Steve French221601c2007-06-05 20:35:06 +0000713 if (copy_from_user(flags_string, buffer, count))
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000714 return -EFAULT;
Steve French39798772006-05-31 22:40:51 +0000715
Steve French221601c2007-06-05 20:35:06 +0000716 if (count < 3) {
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000717 /* single char or single char followed by null */
718 c = flags_string[0];
Steve Frencha0136892007-10-04 20:05:09 +0000719 if (c == '0' || c == 'n' || c == 'N') {
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000720 extended_security = CIFSSEC_DEF; /* default */
Steve Frencha0136892007-10-04 20:05:09 +0000721 return count;
722 } else if (c == '1' || c == 'y' || c == 'Y') {
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000723 extended_security = CIFSSEC_MAX;
Steve Frencha0136892007-10-04 20:05:09 +0000724 return count;
725 } else if (!isdigit(c)) {
726 cERROR(1, ("invalid flag %c", c));
727 return -EINVAL;
728 }
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000729 }
730 /* else we have a number */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000732 flags = simple_strtoul(flags_string, NULL, 0);
733
Steve French221601c2007-06-05 20:35:06 +0000734 cFYI(1, ("sec flags 0x%x", flags));
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000735
Steve French221601c2007-06-05 20:35:06 +0000736 if (flags <= 0) {
737 cERROR(1, ("invalid security flags %s", flags_string));
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000738 return -EINVAL;
739 }
740
Steve French221601c2007-06-05 20:35:06 +0000741 if (flags & ~CIFSSEC_MASK) {
742 cERROR(1, ("attempt to set unsupported security flags 0x%x",
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000743 flags & ~CIFSSEC_MASK));
744 return -EINVAL;
745 }
746 /* flags look ok - update the global security flags for cifs module */
747 extended_security = flags;
Steve French762e5ab2007-06-28 18:41:42 +0000748 if (extended_security & CIFSSEC_MUST_SIGN) {
749 /* requiring signing implies signing is allowed */
750 extended_security |= CIFSSEC_MAY_SIGN;
751 cFYI(1, ("packet signing now required"));
752 } else if ((extended_security & CIFSSEC_MAY_SIGN) == 0) {
753 cFYI(1, ("packet signing disabled"));
754 }
755 /* BB should we turn on MAY flags for other MUST options? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 return count;
757}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000758
759static const struct file_operations cifs_security_flags_proc_fops = {
760 .owner = THIS_MODULE,
761 .open = cifs_security_flags_proc_open,
762 .read = seq_read,
763 .llseek = seq_lseek,
764 .release = single_release,
765 .write = cifs_security_flags_proc_write,
766};
Steve French90c81e02008-02-12 20:32:36 +0000767#else
Steve Frenche086fce2008-02-18 04:03:58 +0000768inline void cifs_proc_init(void)
Steve French90c81e02008-02-12 20:32:36 +0000769{
770}
771
Steve Frenche086fce2008-02-18 04:03:58 +0000772inline void cifs_proc_clean(void)
Steve French90c81e02008-02-12 20:32:36 +0000773{
774}
775#endif /* PROC_FS */