4 * Copyright (C) International Business Machines Corp., 2000,2005
6 * Modified by Steve French (sfrench@us.ibm.com)
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
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
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.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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>
30 #include "cifsproto.h"
31 #include "cifs_debug.h"
35 cifs_dump_mem(char *label, void *data, int length)
40 char buf[10], line[80];
42 printk(KERN_DEBUG "%s: dump of %d bytes of data at 0x%p\n",
44 for (i = 0; i < length; i += 16) {
46 for (j = 0; (j < 4) && (i + j * 4 < length); j++) {
47 sprintf(buf, " %08x", intptr[i / 4 + j]);
52 for (j = 0; (j < 16) && (i + j < length); j++) {
53 buf[1] = isprint(charptr[i + j]) ? charptr[i + j] : '.';
56 printk(KERN_DEBUG "%s\n", line);
60 #ifdef CONFIG_CIFS_DEBUG2
61 void cifs_dump_detail(struct smb_hdr *smb)
63 cERROR(1, ("Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d",
64 smb->Command, smb->Status.CifsError,
65 smb->Flags, smb->Flags2, smb->Mid, smb->Pid));
66 cERROR(1, ("smb buf %p len %d", smb, smbCalcSize_LE(smb)));
70 void cifs_dump_mids(struct TCP_Server_Info *server)
72 struct list_head *tmp;
73 struct mid_q_entry *mid_entry;
78 cERROR(1, ("Dump pending requests:"));
79 spin_lock(&GlobalMid_Lock);
80 list_for_each(tmp, &server->pending_mid_q) {
81 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
82 cERROR(1, ("State: %d Cmd: %d Pid: %d Tsk: %p Mid %d",
84 (int)mid_entry->command,
88 #ifdef CONFIG_CIFS_STATS2
89 cERROR(1, ("IsLarge: %d buf: %p time rcv: %ld now: %ld",
92 mid_entry->when_received,
95 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);
103 spin_unlock(&GlobalMid_Lock);
105 #endif /* CONFIG_CIFS_DEBUG2 */
107 #ifdef CONFIG_PROC_FS
108 static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
110 struct list_head *tmp, *tmp2, *tmp3;
111 struct mid_q_entry *mid_entry;
112 struct TCP_Server_Info *server;
113 struct cifsSesInfo *ses;
114 struct cifsTconInfo *tcon;
118 "Display Internal CIFS Data Structures for Debugging\n"
119 "---------------------------------------------------\n");
120 seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
121 seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
122 seq_printf(m, "Servers:");
125 read_lock(&cifs_tcp_ses_lock);
126 list_for_each(tmp, &cifs_tcp_ses_list) {
127 server = list_entry(tmp, struct TCP_Server_Info,
130 list_for_each(tmp2, &server->smb_ses_list) {
131 ses = list_entry(tmp2, struct cifsSesInfo,
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);
140 "\n%d) Name: %s Domain: %s Mounts: %d OS:"
141 " %s \n\tNOS: %s\tCapability: 0x%x\n\tSMB"
142 " session status: %d\t",
143 i, ses->serverName, ses->serverDomain,
144 ses->ses_count, ses->serverOS, ses->serverNOS,
145 ses->capabilities, ses->status);
147 seq_printf(m, "TCP status: %d\n\tLocal Users To "
148 "Server: %d SecMode: 0x%x Req On Wire: %d",
149 server->tcpStatus, server->srv_count,
151 atomic_read(&server->inFlight));
153 #ifdef CONFIG_CIFS_STATS2
154 seq_printf(m, " In Send: %d In MaxReq Wait: %d",
155 atomic_read(&server->inSend),
156 atomic_read(&server->num_waiters));
159 seq_puts(m, "\nMIDs:\n");
161 spin_lock(&GlobalMid_Lock);
162 list_for_each(tmp3, &server->pending_mid_q) {
163 mid_entry = list_entry(tmp3, struct
166 seq_printf(m, "State: %d com: %d pid:"
167 " %d tsk: %p mid %d\n",
169 (int)mid_entry->command,
174 spin_unlock(&GlobalMid_Lock);
177 read_unlock(&cifs_tcp_ses_lock);
180 seq_puts(m, "Shares:");
183 read_lock(&GlobalSMBSeslock);
184 list_for_each(tmp, &GlobalTreeConnectionList) {
187 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
188 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
189 seq_printf(m, "\n%d) %s Uses: %d ", i,
190 tcon->treeName, atomic_read(&tcon->useCount));
191 if (tcon->nativeFileSystem) {
192 seq_printf(m, "Type: %s ",
193 tcon->nativeFileSystem);
195 seq_printf(m, "DevInfo: 0x%x Attributes: 0x%x"
196 "\nPathComponentMax: %d Status: %d",
197 le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
198 le32_to_cpu(tcon->fsAttrInfo.Attributes),
199 le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
201 if (dev_type == FILE_DEVICE_DISK)
202 seq_puts(m, " type: DISK ");
203 else if (dev_type == FILE_DEVICE_CD_ROM)
204 seq_puts(m, " type: CDROM ");
206 seq_printf(m, " type: %d ", dev_type);
208 if (tcon->need_reconnect)
209 seq_puts(m, "\tDISCONNECTED ");
211 read_unlock(&GlobalSMBSeslock);
215 /* BB add code to dump additional info such as TCP session info now */
219 static int cifs_debug_data_proc_open(struct inode *inode, struct file *file)
221 return single_open(file, cifs_debug_data_proc_show, NULL);
224 static const struct file_operations cifs_debug_data_proc_fops = {
225 .owner = THIS_MODULE,
226 .open = cifs_debug_data_proc_open,
229 .release = single_release,
232 #ifdef CONFIG_CIFS_STATS
233 static ssize_t cifs_stats_proc_write(struct file *file,
234 const char __user *buffer, size_t count, loff_t *ppos)
238 struct list_head *tmp;
239 struct cifsTconInfo *tcon;
241 rc = get_user(c, buffer);
245 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
246 read_lock(&GlobalSMBSeslock);
247 #ifdef CONFIG_CIFS_STATS2
248 atomic_set(&totBufAllocCount, 0);
249 atomic_set(&totSmBufAllocCount, 0);
250 #endif /* CONFIG_CIFS_STATS2 */
251 list_for_each(tmp, &GlobalTreeConnectionList) {
252 tcon = list_entry(tmp, struct cifsTconInfo,
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);
272 read_unlock(&GlobalSMBSeslock);
278 static int cifs_stats_proc_show(struct seq_file *m, void *v)
281 struct list_head *tmp;
282 struct cifsTconInfo *tcon;
285 "Resources in use\nCIFS Session: %d\n",
286 sesInfoAllocCount.counter);
287 seq_printf(m, "Share (unique mount targets): %d\n",
288 tconInfoAllocCount.counter);
289 seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
290 bufAllocCount.counter,
291 cifs_min_rcv + tcpSesAllocCount.counter);
292 seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
293 smBufAllocCount.counter, cifs_min_small);
294 #ifdef CONFIG_CIFS_STATS2
295 seq_printf(m, "Total Large %d Small %d Allocations\n",
296 atomic_read(&totBufAllocCount),
297 atomic_read(&totSmBufAllocCount));
298 #endif /* CONFIG_CIFS_STATS2 */
300 seq_printf(m, "Operations (MIDs): %d\n", midCount.counter);
302 "\n%d session %d share reconnects\n",
303 tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
306 "Total vfs operations: %d maximum at one time: %d\n",
307 GlobalCurrentXid, GlobalMaxActiveXid);
310 read_lock(&GlobalSMBSeslock);
311 list_for_each(tmp, &GlobalTreeConnectionList) {
313 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
314 seq_printf(m, "\n%d) %s", i, tcon->treeName);
315 if (tcon->need_reconnect)
316 seq_puts(m, "\tDISCONNECTED ");
317 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
318 atomic_read(&tcon->num_smbs_sent),
319 atomic_read(&tcon->num_oplock_brks));
320 seq_printf(m, "\nReads: %d Bytes: %lld",
321 atomic_read(&tcon->num_reads),
322 (long long)(tcon->bytes_read));
323 seq_printf(m, "\nWrites: %d Bytes: %lld",
324 atomic_read(&tcon->num_writes),
325 (long long)(tcon->bytes_written));
327 "\nLocks: %d HardLinks: %d Symlinks: %d",
328 atomic_read(&tcon->num_locks),
329 atomic_read(&tcon->num_hardlinks),
330 atomic_read(&tcon->num_symlinks));
332 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
333 atomic_read(&tcon->num_opens),
334 atomic_read(&tcon->num_closes),
335 atomic_read(&tcon->num_deletes));
336 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
337 atomic_read(&tcon->num_mkdirs),
338 atomic_read(&tcon->num_rmdirs));
339 seq_printf(m, "\nRenames: %d T2 Renames %d",
340 atomic_read(&tcon->num_renames),
341 atomic_read(&tcon->num_t2renames));
342 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
343 atomic_read(&tcon->num_ffirst),
344 atomic_read(&tcon->num_fnext),
345 atomic_read(&tcon->num_fclose));
347 read_unlock(&GlobalSMBSeslock);
353 static int cifs_stats_proc_open(struct inode *inode, struct file *file)
355 return single_open(file, cifs_stats_proc_show, NULL);
358 static const struct file_operations cifs_stats_proc_fops = {
359 .owner = THIS_MODULE,
360 .open = cifs_stats_proc_open,
363 .release = single_release,
364 .write = cifs_stats_proc_write,
368 static struct proc_dir_entry *proc_fs_cifs;
369 static const struct file_operations cifsFYI_proc_fops;
370 static const struct file_operations cifs_oplock_proc_fops;
371 static const struct file_operations cifs_lookup_cache_proc_fops;
372 static const struct file_operations traceSMB_proc_fops;
373 static const struct file_operations cifs_multiuser_mount_proc_fops;
374 static const struct file_operations cifs_security_flags_proc_fops;
375 static const struct file_operations cifs_experimental_proc_fops;
376 static const struct file_operations cifs_linux_ext_proc_fops;
381 proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
382 if (proc_fs_cifs == NULL)
385 proc_fs_cifs->owner = THIS_MODULE;
386 proc_create("DebugData", 0, proc_fs_cifs, &cifs_debug_data_proc_fops);
388 #ifdef CONFIG_CIFS_STATS
389 proc_create("Stats", 0, proc_fs_cifs, &cifs_stats_proc_fops);
391 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);
394 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);
407 cifs_proc_clean(void)
409 if (proc_fs_cifs == NULL)
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);
418 remove_proc_entry("MultiuserMount", proc_fs_cifs);
419 remove_proc_entry("OplockEnabled", proc_fs_cifs);
420 remove_proc_entry("SecurityFlags", proc_fs_cifs);
421 remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
422 remove_proc_entry("Experimental", proc_fs_cifs);
423 remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
424 remove_proc_entry("fs/cifs", NULL);
427 static int cifsFYI_proc_show(struct seq_file *m, void *v)
429 seq_printf(m, "%d\n", cifsFYI);
433 static int cifsFYI_proc_open(struct inode *inode, struct file *file)
435 return single_open(file, cifsFYI_proc_show, NULL);
438 static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
439 size_t count, loff_t *ppos)
444 rc = get_user(c, buffer);
447 if (c == '0' || c == 'n' || c == 'N')
449 else if (c == '1' || c == 'y' || c == 'Y')
451 else if ((c > '1') && (c <= '9'))
452 cifsFYI = (int) (c - '0'); /* see cifs_debug.h for meanings */
457 static const struct file_operations cifsFYI_proc_fops = {
458 .owner = THIS_MODULE,
459 .open = cifsFYI_proc_open,
462 .release = single_release,
463 .write = cifsFYI_proc_write,
466 static int cifs_oplock_proc_show(struct seq_file *m, void *v)
468 seq_printf(m, "%d\n", oplockEnabled);
472 static int cifs_oplock_proc_open(struct inode *inode, struct file *file)
474 return single_open(file, cifs_oplock_proc_show, NULL);
477 static ssize_t cifs_oplock_proc_write(struct file *file,
478 const char __user *buffer, size_t count, loff_t *ppos)
483 rc = get_user(c, buffer);
486 if (c == '0' || c == 'n' || c == 'N')
488 else if (c == '1' || c == 'y' || c == 'Y')
494 static const struct file_operations cifs_oplock_proc_fops = {
495 .owner = THIS_MODULE,
496 .open = cifs_oplock_proc_open,
499 .release = single_release,
500 .write = cifs_oplock_proc_write,
503 static int cifs_experimental_proc_show(struct seq_file *m, void *v)
505 seq_printf(m, "%d\n", experimEnabled);
509 static int cifs_experimental_proc_open(struct inode *inode, struct file *file)
511 return single_open(file, cifs_experimental_proc_show, NULL);
514 static ssize_t cifs_experimental_proc_write(struct file *file,
515 const char __user *buffer, size_t count, loff_t *ppos)
520 rc = get_user(c, buffer);
523 if (c == '0' || c == 'n' || c == 'N')
525 else if (c == '1' || c == 'y' || c == 'Y')
533 static const struct file_operations cifs_experimental_proc_fops = {
534 .owner = THIS_MODULE,
535 .open = cifs_experimental_proc_open,
538 .release = single_release,
539 .write = cifs_experimental_proc_write,
542 static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
544 seq_printf(m, "%d\n", linuxExtEnabled);
548 static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
550 return single_open(file, cifs_linux_ext_proc_show, NULL);
553 static ssize_t cifs_linux_ext_proc_write(struct file *file,
554 const char __user *buffer, size_t count, loff_t *ppos)
559 rc = get_user(c, buffer);
562 if (c == '0' || c == 'n' || c == 'N')
564 else if (c == '1' || c == 'y' || c == 'Y')
570 static const struct file_operations cifs_linux_ext_proc_fops = {
571 .owner = THIS_MODULE,
572 .open = cifs_linux_ext_proc_open,
575 .release = single_release,
576 .write = cifs_linux_ext_proc_write,
579 static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
581 seq_printf(m, "%d\n", lookupCacheEnabled);
585 static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
587 return single_open(file, cifs_lookup_cache_proc_show, NULL);
590 static ssize_t cifs_lookup_cache_proc_write(struct file *file,
591 const char __user *buffer, size_t count, loff_t *ppos)
596 rc = get_user(c, buffer);
599 if (c == '0' || c == 'n' || c == 'N')
600 lookupCacheEnabled = 0;
601 else if (c == '1' || c == 'y' || c == 'Y')
602 lookupCacheEnabled = 1;
607 static const struct file_operations cifs_lookup_cache_proc_fops = {
608 .owner = THIS_MODULE,
609 .open = cifs_lookup_cache_proc_open,
612 .release = single_release,
613 .write = cifs_lookup_cache_proc_write,
616 static int traceSMB_proc_show(struct seq_file *m, void *v)
618 seq_printf(m, "%d\n", traceSMB);
622 static int traceSMB_proc_open(struct inode *inode, struct file *file)
624 return single_open(file, traceSMB_proc_show, NULL);
627 static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
628 size_t count, loff_t *ppos)
633 rc = get_user(c, buffer);
636 if (c == '0' || c == 'n' || c == 'N')
638 else if (c == '1' || c == 'y' || c == 'Y')
644 static const struct file_operations traceSMB_proc_fops = {
645 .owner = THIS_MODULE,
646 .open = traceSMB_proc_open,
649 .release = single_release,
650 .write = traceSMB_proc_write,
653 static int cifs_multiuser_mount_proc_show(struct seq_file *m, void *v)
655 seq_printf(m, "%d\n", multiuser_mount);
659 static int cifs_multiuser_mount_proc_open(struct inode *inode, struct file *fh)
661 return single_open(fh, cifs_multiuser_mount_proc_show, NULL);
664 static ssize_t cifs_multiuser_mount_proc_write(struct file *file,
665 const char __user *buffer, size_t count, loff_t *ppos)
670 rc = get_user(c, buffer);
673 if (c == '0' || c == 'n' || c == 'N')
675 else if (c == '1' || c == 'y' || c == 'Y')
681 static const struct file_operations cifs_multiuser_mount_proc_fops = {
682 .owner = THIS_MODULE,
683 .open = cifs_multiuser_mount_proc_open,
686 .release = single_release,
687 .write = cifs_multiuser_mount_proc_write,
690 static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
692 seq_printf(m, "0x%x\n", extended_security);
696 static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
698 return single_open(file, cifs_security_flags_proc_show, NULL);
701 static ssize_t cifs_security_flags_proc_write(struct file *file,
702 const char __user *buffer, size_t count, loff_t *ppos)
705 char flags_string[12];
708 if ((count < 1) || (count > 11))
711 memset(flags_string, 0, 12);
713 if (copy_from_user(flags_string, buffer, count))
717 /* single char or single char followed by null */
719 if (c == '0' || c == 'n' || c == 'N') {
720 extended_security = CIFSSEC_DEF; /* default */
722 } else if (c == '1' || c == 'y' || c == 'Y') {
723 extended_security = CIFSSEC_MAX;
725 } else if (!isdigit(c)) {
726 cERROR(1, ("invalid flag %c", c));
730 /* else we have a number */
732 flags = simple_strtoul(flags_string, NULL, 0);
734 cFYI(1, ("sec flags 0x%x", flags));
737 cERROR(1, ("invalid security flags %s", flags_string));
741 if (flags & ~CIFSSEC_MASK) {
742 cERROR(1, ("attempt to set unsupported security flags 0x%x",
743 flags & ~CIFSSEC_MASK));
746 /* flags look ok - update the global security flags for cifs module */
747 extended_security = flags;
748 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"));
755 /* BB should we turn on MAY flags for other MUST options? */
759 static const struct file_operations cifs_security_flags_proc_fops = {
760 .owner = THIS_MODULE,
761 .open = cifs_security_flags_proc_open,
764 .release = single_release,
765 .write = cifs_security_flags_proc_write,
768 inline void cifs_proc_init(void)
772 inline void cifs_proc_clean(void)