Linux-2.6.12-rc2
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / fs / cifs / cifs_debug.c
blobdb28b561cd4b54b0723e582ce81daba56f3ccb73
1 /*
2 * fs/cifs_debug.c
4 * Copyright (C) International Business Machines Corp., 2000,2003
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
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"
33 void
34 cifs_dump_mem(char *label, void *data, int length)
36 int i, j;
37 int *intptr = data;
38 char *charptr = data;
39 char buf[10], line[80];
41 printk(KERN_DEBUG "%s: dump of %d bytes of data at 0x%p\n\n",
42 label, length, data);
43 for (i = 0; i < length; i += 16) {
44 line[0] = 0;
45 for (j = 0; (j < 4) && (i + j * 4 < length); j++) {
46 sprintf(buf, " %08x", intptr[i / 4 + j]);
47 strcat(line, buf);
49 buf[0] = ' ';
50 buf[2] = 0;
51 for (j = 0; (j < 16) && (i + j < length); j++) {
52 buf[1] = isprint(charptr[i + j]) ? charptr[i + j] : '.';
53 strcat(line, buf);
55 printk(KERN_DEBUG "%s\n", line);
59 #ifdef CONFIG_PROC_FS
60 static int
61 cifs_debug_data_read(char *buf, char **beginBuffer, off_t offset,
62 int count, int *eof, void *data)
64 struct list_head *tmp;
65 struct list_head *tmp1;
66 struct mid_q_entry * mid_entry;
67 struct cifsSesInfo *ses;
68 struct cifsTconInfo *tcon;
69 int i;
70 int length = 0;
71 char * original_buf = buf;
73 *beginBuffer = buf + offset;
76 length =
77 sprintf(buf,
78 "Display Internal CIFS Data Structures for Debugging\n"
79 "---------------------------------------------------\n");
80 buf += length;
82 length = sprintf(buf, "Servers:\n");
83 buf += length;
85 i = 0;
86 read_lock(&GlobalSMBSeslock);
87 list_for_each(tmp, &GlobalSMBSessionList) {
88 i++;
89 ses = list_entry(tmp, struct cifsSesInfo, cifsSessionList);
90 length =
91 sprintf(buf,
92 "\n%d) Name: %s Domain: %s Mounts: %d ServerOS: %s \n\tServerNOS: %s\tCapabilities: 0x%x\n\tSMB session status: %d\t",
93 i, ses->serverName, ses->serverDomain, atomic_read(&ses->inUse),
94 ses->serverOS, ses->serverNOS, ses->capabilities,ses->status);
95 buf += length;
96 if(ses->server) {
97 buf += sprintf(buf, "TCP status: %d\n\tLocal Users To Server: %d SecMode: 0x%x Req Active: %d",
98 ses->server->tcpStatus,
99 atomic_read(&ses->server->socketUseCount),
100 ses->server->secMode,
101 atomic_read(&ses->server->inFlight));
103 length = sprintf(buf, "\nMIDs: \n");
104 buf += length;
106 spin_lock(&GlobalMid_Lock);
107 list_for_each(tmp1, &ses->server->pending_mid_q) {
108 mid_entry = list_entry(tmp1, struct
109 mid_q_entry,
110 qhead);
111 if(mid_entry) {
112 length = sprintf(buf,"State: %d com: %d pid: %d tsk: %p mid %d\n",mid_entry->midState,mid_entry->command,mid_entry->pid,mid_entry->tsk,mid_entry->mid);
113 buf += length;
116 spin_unlock(&GlobalMid_Lock);
120 read_unlock(&GlobalSMBSeslock);
121 sprintf(buf, "\n");
122 buf++;
124 length = sprintf(buf, "\nShares:\n");
125 buf += length;
127 i = 0;
128 read_lock(&GlobalSMBSeslock);
129 list_for_each(tmp, &GlobalTreeConnectionList) {
130 __u32 dev_type;
131 i++;
132 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
133 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
134 length =
135 sprintf(buf,
136 "\n%d) %s Uses: %d Type: %s Characteristics: 0x%x Attributes: 0x%x\nPathComponentMax: %d Status: %d",
137 i, tcon->treeName,
138 atomic_read(&tcon->useCount),
139 tcon->nativeFileSystem,
140 le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
141 le32_to_cpu(tcon->fsAttrInfo.Attributes),
142 le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
143 tcon->tidStatus);
144 buf += length;
145 if (dev_type == FILE_DEVICE_DISK)
146 length = sprintf(buf, " type: DISK ");
147 else if (dev_type == FILE_DEVICE_CD_ROM)
148 length = sprintf(buf, " type: CDROM ");
149 else
150 length =
151 sprintf(buf, " type: %d ", dev_type);
152 buf += length;
153 if(tcon->tidStatus == CifsNeedReconnect) {
154 buf += sprintf(buf, "\tDISCONNECTED ");
155 length += 14;
158 read_unlock(&GlobalSMBSeslock);
160 length = sprintf(buf, "\n");
161 buf += length;
163 /* BB add code to dump additional info such as TCP session info now */
164 /* Now calculate total size of returned data */
165 length = buf - original_buf;
167 if(offset + count >= length)
168 *eof = 1;
169 if(length < offset) {
170 *eof = 1;
171 return 0;
172 } else {
173 length = length - offset;
175 if (length > count)
176 length = count;
178 return length;
181 #ifdef CONFIG_CIFS_STATS
182 static int
183 cifs_stats_read(char *buf, char **beginBuffer, off_t offset,
184 int count, int *eof, void *data)
186 int item_length,i,length;
187 struct list_head *tmp;
188 struct cifsTconInfo *tcon;
190 *beginBuffer = buf + offset;
192 length = sprintf(buf,
193 "Resources in use\nCIFS Session: %d\n",
194 sesInfoAllocCount.counter);
195 buf += length;
196 item_length =
197 sprintf(buf,"Share (unique mount targets): %d\n",
198 tconInfoAllocCount.counter);
199 length += item_length;
200 buf += item_length;
201 item_length =
202 sprintf(buf,"SMB Request/Response Buffer: %d Pool size: %d\n",
203 bufAllocCount.counter,cifs_min_rcv + tcpSesAllocCount.counter);
204 length += item_length;
205 buf += item_length;
206 item_length =
207 sprintf(buf,"SMB Small Req/Resp Buffer: %d Pool size: %d\n",
208 smBufAllocCount.counter,cifs_min_small);
209 length += item_length;
210 buf += item_length;
211 item_length =
212 sprintf(buf,"Operations (MIDs): %d\n",
213 midCount.counter);
214 length += item_length;
215 buf += item_length;
216 item_length = sprintf(buf,
217 "\n%d session %d share reconnects\n",
218 tcpSesReconnectCount.counter,tconInfoReconnectCount.counter);
219 length += item_length;
220 buf += item_length;
222 item_length = sprintf(buf,
223 "Total vfs operations: %d maximum at one time: %d\n",
224 GlobalCurrentXid,GlobalMaxActiveXid);
225 length += item_length;
226 buf += item_length;
228 i = 0;
229 read_lock(&GlobalSMBSeslock);
230 list_for_each(tmp, &GlobalTreeConnectionList) {
231 i++;
232 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
233 item_length = sprintf(buf,"\n%d) %s",i, tcon->treeName);
234 buf += item_length;
235 length += item_length;
236 if(tcon->tidStatus == CifsNeedReconnect) {
237 buf += sprintf(buf, "\tDISCONNECTED ");
238 length += 14;
240 item_length = sprintf(buf,"\nSMBs: %d Oplock Breaks: %d",
241 atomic_read(&tcon->num_smbs_sent),
242 atomic_read(&tcon->num_oplock_brks));
243 buf += item_length;
244 length += item_length;
245 item_length = sprintf(buf,"\nReads: %d Bytes %lld",
246 atomic_read(&tcon->num_reads),
247 (long long)(tcon->bytes_read));
248 buf += item_length;
249 length += item_length;
250 item_length = sprintf(buf,"\nWrites: %d Bytes: %lld",
251 atomic_read(&tcon->num_writes),
252 (long long)(tcon->bytes_written));
253 buf += item_length;
254 length += item_length;
255 item_length = sprintf(buf,
256 "\nOpens: %d Deletes: %d\nMkdirs: %d Rmdirs: %d",
257 atomic_read(&tcon->num_opens),
258 atomic_read(&tcon->num_deletes),
259 atomic_read(&tcon->num_mkdirs),
260 atomic_read(&tcon->num_rmdirs));
261 buf += item_length;
262 length += item_length;
263 item_length = sprintf(buf,
264 "\nRenames: %d T2 Renames %d",
265 atomic_read(&tcon->num_renames),
266 atomic_read(&tcon->num_t2renames));
267 buf += item_length;
268 length += item_length;
270 read_unlock(&GlobalSMBSeslock);
272 buf += sprintf(buf,"\n");
273 length++;
275 if(offset + count >= length)
276 *eof = 1;
277 if(length < offset) {
278 *eof = 1;
279 return 0;
280 } else {
281 length = length - offset;
283 if (length > count)
284 length = count;
286 return length;
288 #endif
290 static struct proc_dir_entry *proc_fs_cifs;
291 read_proc_t cifs_txanchor_read;
292 static read_proc_t cifsFYI_read;
293 static write_proc_t cifsFYI_write;
294 static read_proc_t oplockEnabled_read;
295 static write_proc_t oplockEnabled_write;
296 static read_proc_t lookupFlag_read;
297 static write_proc_t lookupFlag_write;
298 static read_proc_t traceSMB_read;
299 static write_proc_t traceSMB_write;
300 static read_proc_t multiuser_mount_read;
301 static write_proc_t multiuser_mount_write;
302 static read_proc_t extended_security_read;
303 static write_proc_t extended_security_write;
304 static read_proc_t ntlmv2_enabled_read;
305 static write_proc_t ntlmv2_enabled_write;
306 static read_proc_t packet_signing_enabled_read;
307 static write_proc_t packet_signing_enabled_write;
308 static read_proc_t quotaEnabled_read;
309 static write_proc_t quotaEnabled_write;
310 static read_proc_t linuxExtensionsEnabled_read;
311 static write_proc_t linuxExtensionsEnabled_write;
313 void
314 cifs_proc_init(void)
316 struct proc_dir_entry *pde;
318 proc_fs_cifs = proc_mkdir("cifs", proc_root_fs);
319 if (proc_fs_cifs == NULL)
320 return;
322 proc_fs_cifs->owner = THIS_MODULE;
323 create_proc_read_entry("DebugData", 0, proc_fs_cifs,
324 cifs_debug_data_read, NULL);
326 #ifdef CONFIG_CIFS_STATS
327 create_proc_read_entry("Stats", 0, proc_fs_cifs,
328 cifs_stats_read, NULL);
329 #endif
330 pde = create_proc_read_entry("cifsFYI", 0, proc_fs_cifs,
331 cifsFYI_read, NULL);
332 if (pde)
333 pde->write_proc = cifsFYI_write;
335 pde =
336 create_proc_read_entry("traceSMB", 0, proc_fs_cifs,
337 traceSMB_read, NULL);
338 if (pde)
339 pde->write_proc = traceSMB_write;
341 pde = create_proc_read_entry("OplockEnabled", 0, proc_fs_cifs,
342 oplockEnabled_read, NULL);
343 if (pde)
344 pde->write_proc = oplockEnabled_write;
346 pde = create_proc_read_entry("ReenableOldCifsReaddirCode", 0, proc_fs_cifs,
347 quotaEnabled_read, NULL);
348 if (pde)
349 pde->write_proc = quotaEnabled_write;
351 pde = create_proc_read_entry("LinuxExtensionsEnabled", 0, proc_fs_cifs,
352 linuxExtensionsEnabled_read, NULL);
353 if (pde)
354 pde->write_proc = linuxExtensionsEnabled_write;
356 pde =
357 create_proc_read_entry("MultiuserMount", 0, proc_fs_cifs,
358 multiuser_mount_read, NULL);
359 if (pde)
360 pde->write_proc = multiuser_mount_write;
362 pde =
363 create_proc_read_entry("ExtendedSecurity", 0, proc_fs_cifs,
364 extended_security_read, NULL);
365 if (pde)
366 pde->write_proc = extended_security_write;
368 pde =
369 create_proc_read_entry("LookupCacheEnabled", 0, proc_fs_cifs,
370 lookupFlag_read, NULL);
371 if (pde)
372 pde->write_proc = lookupFlag_write;
374 pde =
375 create_proc_read_entry("NTLMV2Enabled", 0, proc_fs_cifs,
376 ntlmv2_enabled_read, NULL);
377 if (pde)
378 pde->write_proc = ntlmv2_enabled_write;
380 pde =
381 create_proc_read_entry("PacketSigningEnabled", 0, proc_fs_cifs,
382 packet_signing_enabled_read, NULL);
383 if (pde)
384 pde->write_proc = packet_signing_enabled_write;
387 void
388 cifs_proc_clean(void)
390 if (proc_fs_cifs == NULL)
391 return;
393 remove_proc_entry("DebugData", proc_fs_cifs);
394 remove_proc_entry("cifsFYI", proc_fs_cifs);
395 remove_proc_entry("traceSMB", proc_fs_cifs);
396 #ifdef CONFIG_CIFS_STATS
397 remove_proc_entry("Stats", proc_fs_cifs);
398 #endif
399 remove_proc_entry("MultiuserMount", proc_fs_cifs);
400 remove_proc_entry("OplockEnabled", proc_fs_cifs);
401 remove_proc_entry("NTLMV2Enabled",proc_fs_cifs);
402 remove_proc_entry("ExtendedSecurity",proc_fs_cifs);
403 remove_proc_entry("PacketSigningEnabled",proc_fs_cifs);
404 remove_proc_entry("LinuxExtensionsEnabled",proc_fs_cifs);
405 remove_proc_entry("ReenableOldCifsReaddirCode",proc_fs_cifs);
406 remove_proc_entry("LookupCacheEnabled",proc_fs_cifs);
407 remove_proc_entry("cifs", proc_root_fs);
410 static int
411 cifsFYI_read(char *page, char **start, off_t off, int count,
412 int *eof, void *data)
414 int len;
416 len = sprintf(page, "%d\n", cifsFYI);
418 len -= off;
419 *start = page + off;
421 if (len > count)
422 len = count;
423 else
424 *eof = 1;
426 if (len < 0)
427 len = 0;
429 return len;
431 static int
432 cifsFYI_write(struct file *file, const char __user *buffer,
433 unsigned long count, void *data)
435 char c;
436 int rc;
438 rc = get_user(c, buffer);
439 if (rc)
440 return rc;
441 if (c == '0' || c == 'n' || c == 'N')
442 cifsFYI = 0;
443 else if (c == '1' || c == 'y' || c == 'Y')
444 cifsFYI = 1;
446 return count;
449 static int
450 oplockEnabled_read(char *page, char **start, off_t off,
451 int count, int *eof, void *data)
453 int len;
455 len = sprintf(page, "%d\n", oplockEnabled);
457 len -= off;
458 *start = page + off;
460 if (len > count)
461 len = count;
462 else
463 *eof = 1;
465 if (len < 0)
466 len = 0;
468 return len;
470 static int
471 oplockEnabled_write(struct file *file, const char __user *buffer,
472 unsigned long count, void *data)
474 char c;
475 int rc;
477 rc = get_user(c, buffer);
478 if (rc)
479 return rc;
480 if (c == '0' || c == 'n' || c == 'N')
481 oplockEnabled = 0;
482 else if (c == '1' || c == 'y' || c == 'Y')
483 oplockEnabled = 1;
485 return count;
488 static int
489 quotaEnabled_read(char *page, char **start, off_t off,
490 int count, int *eof, void *data)
492 int len;
494 len = sprintf(page, "%d\n", experimEnabled);
495 /* could also check if quotas are enabled in kernel
496 as a whole first */
497 len -= off;
498 *start = page + off;
500 if (len > count)
501 len = count;
502 else
503 *eof = 1;
505 if (len < 0)
506 len = 0;
508 return len;
510 static int
511 quotaEnabled_write(struct file *file, const char __user *buffer,
512 unsigned long count, void *data)
514 char c;
515 int rc;
517 rc = get_user(c, buffer);
518 if (rc)
519 return rc;
520 if (c == '0' || c == 'n' || c == 'N')
521 experimEnabled = 0;
522 else if (c == '1' || c == 'y' || c == 'Y')
523 experimEnabled = 1;
525 return count;
528 static int
529 linuxExtensionsEnabled_read(char *page, char **start, off_t off,
530 int count, int *eof, void *data)
532 int len;
534 len = sprintf(page, "%d\n", linuxExtEnabled);
535 /* could also check if quotas are enabled in kernel
536 as a whole first */
537 len -= off;
538 *start = page + off;
540 if (len > count)
541 len = count;
542 else
543 *eof = 1;
545 if (len < 0)
546 len = 0;
548 return len;
550 static int
551 linuxExtensionsEnabled_write(struct file *file, const char __user *buffer,
552 unsigned long count, void *data)
554 char c;
555 int rc;
557 rc = get_user(c, buffer);
558 if (rc)
559 return rc;
560 if (c == '0' || c == 'n' || c == 'N')
561 linuxExtEnabled = 0;
562 else if (c == '1' || c == 'y' || c == 'Y')
563 linuxExtEnabled = 1;
565 return count;
569 static int
570 lookupFlag_read(char *page, char **start, off_t off,
571 int count, int *eof, void *data)
573 int len;
575 len = sprintf(page, "%d\n", lookupCacheEnabled);
577 len -= off;
578 *start = page + off;
580 if (len > count)
581 len = count;
582 else
583 *eof = 1;
585 if (len < 0)
586 len = 0;
588 return len;
590 static int
591 lookupFlag_write(struct file *file, const char __user *buffer,
592 unsigned long count, void *data)
594 char c;
595 int rc;
597 rc = get_user(c, buffer);
598 if (rc)
599 return rc;
600 if (c == '0' || c == 'n' || c == 'N')
601 lookupCacheEnabled = 0;
602 else if (c == '1' || c == 'y' || c == 'Y')
603 lookupCacheEnabled = 1;
605 return count;
607 static int
608 traceSMB_read(char *page, char **start, off_t off, int count,
609 int *eof, void *data)
611 int len;
613 len = sprintf(page, "%d\n", traceSMB);
615 len -= off;
616 *start = page + off;
618 if (len > count)
619 len = count;
620 else
621 *eof = 1;
623 if (len < 0)
624 len = 0;
626 return len;
628 static int
629 traceSMB_write(struct file *file, const char __user *buffer,
630 unsigned long count, void *data)
632 char c;
633 int rc;
635 rc = get_user(c, buffer);
636 if (rc)
637 return rc;
638 if (c == '0' || c == 'n' || c == 'N')
639 traceSMB = 0;
640 else if (c == '1' || c == 'y' || c == 'Y')
641 traceSMB = 1;
643 return count;
646 static int
647 multiuser_mount_read(char *page, char **start, off_t off,
648 int count, int *eof, void *data)
650 int len;
652 len = sprintf(page, "%d\n", multiuser_mount);
654 len -= off;
655 *start = page + off;
657 if (len > count)
658 len = count;
659 else
660 *eof = 1;
662 if (len < 0)
663 len = 0;
665 return len;
667 static int
668 multiuser_mount_write(struct file *file, const char __user *buffer,
669 unsigned long count, void *data)
671 char c;
672 int rc;
674 rc = get_user(c, buffer);
675 if (rc)
676 return rc;
677 if (c == '0' || c == 'n' || c == 'N')
678 multiuser_mount = 0;
679 else if (c == '1' || c == 'y' || c == 'Y')
680 multiuser_mount = 1;
682 return count;
685 static int
686 extended_security_read(char *page, char **start, off_t off,
687 int count, int *eof, void *data)
689 int len;
691 len = sprintf(page, "%d\n", extended_security);
693 len -= off;
694 *start = page + off;
696 if (len > count)
697 len = count;
698 else
699 *eof = 1;
701 if (len < 0)
702 len = 0;
704 return len;
706 static int
707 extended_security_write(struct file *file, const char __user *buffer,
708 unsigned long count, void *data)
710 char c;
711 int rc;
713 rc = get_user(c, buffer);
714 if (rc)
715 return rc;
716 if (c == '0' || c == 'n' || c == 'N')
717 extended_security = 0;
718 else if (c == '1' || c == 'y' || c == 'Y')
719 extended_security = 1;
721 return count;
724 static int
725 ntlmv2_enabled_read(char *page, char **start, off_t off,
726 int count, int *eof, void *data)
728 int len;
730 len = sprintf(page, "%d\n", ntlmv2_support);
732 len -= off;
733 *start = page + off;
735 if (len > count)
736 len = count;
737 else
738 *eof = 1;
740 if (len < 0)
741 len = 0;
743 return len;
745 static int
746 ntlmv2_enabled_write(struct file *file, const char __user *buffer,
747 unsigned long count, void *data)
749 char c;
750 int rc;
752 rc = get_user(c, buffer);
753 if (rc)
754 return rc;
755 if (c == '0' || c == 'n' || c == 'N')
756 ntlmv2_support = 0;
757 else if (c == '1' || c == 'y' || c == 'Y')
758 ntlmv2_support = 1;
760 return count;
763 static int
764 packet_signing_enabled_read(char *page, char **start, off_t off,
765 int count, int *eof, void *data)
767 int len;
769 len = sprintf(page, "%d\n", sign_CIFS_PDUs);
771 len -= off;
772 *start = page + off;
774 if (len > count)
775 len = count;
776 else
777 *eof = 1;
779 if (len < 0)
780 len = 0;
782 return len;
784 static int
785 packet_signing_enabled_write(struct file *file, const char __user *buffer,
786 unsigned long count, void *data)
788 char c;
789 int rc;
791 rc = get_user(c, buffer);
792 if (rc)
793 return rc;
794 if (c == '0' || c == 'n' || c == 'N')
795 sign_CIFS_PDUs = 0;
796 else if (c == '1' || c == 'y' || c == 'Y')
797 sign_CIFS_PDUs = 1;
798 else if (c == '2')
799 sign_CIFS_PDUs = 2;
801 return count;
805 #endif