[CPUFREQ] Allow ondemand stepping to be changed by user.
[linux-2.6/mini2440.git] / fs / cifs / cifs_debug.c
blob4061e43471c1a1dc1822fcae3dca02c4406794f0
1 /*
2 * fs/cifs_debug.c
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
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"
32 #include "cifsfs.h"
34 void
35 cifs_dump_mem(char *label, void *data, int length)
37 int i, j;
38 int *intptr = data;
39 char *charptr = data;
40 char buf[10], line[80];
42 printk(KERN_DEBUG "%s: dump of %d bytes of data at 0x%p\n\n",
43 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);
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);
56 printk(KERN_DEBUG "%s\n", line);
60 #ifdef CONFIG_PROC_FS
61 static int
62 cifs_debug_data_read(char *buf, char **beginBuffer, off_t offset,
63 int count, int *eof, void *data)
65 struct list_head *tmp;
66 struct list_head *tmp1;
67 struct mid_q_entry * mid_entry;
68 struct cifsSesInfo *ses;
69 struct cifsTconInfo *tcon;
70 int i;
71 int length = 0;
72 char * original_buf = buf;
74 *beginBuffer = buf + offset;
77 length =
78 sprintf(buf,
79 "Display Internal CIFS Data Structures for Debugging\n"
80 "---------------------------------------------------\n");
81 buf += length;
82 length = sprintf(buf,"CIFS Version %s\n",CIFS_VERSION);
83 buf += length;
84 length = sprintf(buf, "Servers:");
85 buf += length;
87 i = 0;
88 read_lock(&GlobalSMBSeslock);
89 list_for_each(tmp, &GlobalSMBSessionList) {
90 i++;
91 ses = list_entry(tmp, struct cifsSesInfo, cifsSessionList);
92 if((ses->serverDomain == NULL) || (ses->serverOS == NULL) ||
93 (ses->serverNOS == NULL)) {
94 buf += sprintf("\nentry for %s not fully displayed\n\t",
95 ses->serverName);
97 } else {
98 length =
99 sprintf(buf,
100 "\n%d) Name: %s Domain: %s Mounts: %d ServerOS: %s \n\tServerNOS: %s\tCapabilities: 0x%x\n\tSMB session status: %d\t",
101 i, ses->serverName, ses->serverDomain,
102 atomic_read(&ses->inUse),
103 ses->serverOS, ses->serverNOS,
104 ses->capabilities,ses->status);
105 buf += length;
107 if(ses->server) {
108 buf += sprintf(buf, "TCP status: %d\n\tLocal Users To Server: %d SecMode: 0x%x Req Active: %d",
109 ses->server->tcpStatus,
110 atomic_read(&ses->server->socketUseCount),
111 ses->server->secMode,
112 atomic_read(&ses->server->inFlight));
114 length = sprintf(buf, "\nMIDs:\n");
115 buf += length;
117 spin_lock(&GlobalMid_Lock);
118 list_for_each(tmp1, &ses->server->pending_mid_q) {
119 mid_entry = list_entry(tmp1, struct
120 mid_q_entry,
121 qhead);
122 if(mid_entry) {
123 length = sprintf(buf,"State: %d com: %d pid: %d tsk: %p mid %d\n",
124 mid_entry->midState,
125 (int)mid_entry->command,
126 mid_entry->pid,
127 mid_entry->tsk,
128 mid_entry->mid);
129 buf += length;
132 spin_unlock(&GlobalMid_Lock);
136 read_unlock(&GlobalSMBSeslock);
137 sprintf(buf, "\n");
138 buf++;
140 length = sprintf(buf, "Shares:");
141 buf += length;
143 i = 0;
144 read_lock(&GlobalSMBSeslock);
145 list_for_each(tmp, &GlobalTreeConnectionList) {
146 __u32 dev_type;
147 i++;
148 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
149 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
150 length =
151 sprintf(buf,
152 "\n%d) %s Uses: %d Type: %s Characteristics: 0x%x Attributes: 0x%x\nPathComponentMax: %d Status: %d",
153 i, tcon->treeName,
154 atomic_read(&tcon->useCount),
155 tcon->nativeFileSystem,
156 le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
157 le32_to_cpu(tcon->fsAttrInfo.Attributes),
158 le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
159 tcon->tidStatus);
160 buf += length;
161 if (dev_type == FILE_DEVICE_DISK)
162 length = sprintf(buf, " type: DISK ");
163 else if (dev_type == FILE_DEVICE_CD_ROM)
164 length = sprintf(buf, " type: CDROM ");
165 else
166 length =
167 sprintf(buf, " type: %d ", dev_type);
168 buf += length;
169 if(tcon->tidStatus == CifsNeedReconnect) {
170 buf += sprintf(buf, "\tDISCONNECTED ");
171 length += 14;
174 read_unlock(&GlobalSMBSeslock);
176 length = sprintf(buf, "\n");
177 buf += length;
179 /* BB add code to dump additional info such as TCP session info now */
180 /* Now calculate total size of returned data */
181 length = buf - original_buf;
183 if(offset + count >= length)
184 *eof = 1;
185 if(length < offset) {
186 *eof = 1;
187 return 0;
188 } else {
189 length = length - offset;
191 if (length > count)
192 length = count;
194 return length;
197 #ifdef CONFIG_CIFS_STATS
198 static int
199 cifs_stats_read(char *buf, char **beginBuffer, off_t offset,
200 int count, int *eof, void *data)
202 int item_length,i,length;
203 struct list_head *tmp;
204 struct cifsTconInfo *tcon;
206 *beginBuffer = buf + offset;
208 length = sprintf(buf,
209 "Resources in use\nCIFS Session: %d\n",
210 sesInfoAllocCount.counter);
211 buf += length;
212 item_length =
213 sprintf(buf,"Share (unique mount targets): %d\n",
214 tconInfoAllocCount.counter);
215 length += item_length;
216 buf += item_length;
217 item_length =
218 sprintf(buf,"SMB Request/Response Buffer: %d Pool size: %d\n",
219 bufAllocCount.counter,
220 cifs_min_rcv + tcpSesAllocCount.counter);
221 length += item_length;
222 buf += item_length;
223 item_length =
224 sprintf(buf,"SMB Small Req/Resp Buffer: %d Pool size: %d\n",
225 smBufAllocCount.counter,cifs_min_small);
226 length += item_length;
227 buf += item_length;
228 item_length =
229 sprintf(buf,"Operations (MIDs): %d\n",
230 midCount.counter);
231 length += item_length;
232 buf += item_length;
233 item_length = sprintf(buf,
234 "\n%d session %d share reconnects\n",
235 tcpSesReconnectCount.counter,tconInfoReconnectCount.counter);
236 length += item_length;
237 buf += item_length;
239 item_length = sprintf(buf,
240 "Total vfs operations: %d maximum at one time: %d\n",
241 GlobalCurrentXid,GlobalMaxActiveXid);
242 length += item_length;
243 buf += item_length;
245 i = 0;
246 read_lock(&GlobalSMBSeslock);
247 list_for_each(tmp, &GlobalTreeConnectionList) {
248 i++;
249 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
250 item_length = sprintf(buf,"\n%d) %s",i, tcon->treeName);
251 buf += item_length;
252 length += item_length;
253 if(tcon->tidStatus == CifsNeedReconnect) {
254 buf += sprintf(buf, "\tDISCONNECTED ");
255 length += 14;
257 item_length = sprintf(buf,"\nSMBs: %d Oplock Breaks: %d",
258 atomic_read(&tcon->num_smbs_sent),
259 atomic_read(&tcon->num_oplock_brks));
260 buf += item_length;
261 length += item_length;
262 item_length = sprintf(buf,"\nReads: %d Bytes %lld",
263 atomic_read(&tcon->num_reads),
264 (long long)(tcon->bytes_read));
265 buf += item_length;
266 length += item_length;
267 item_length = sprintf(buf,"\nWrites: %d Bytes: %lld",
268 atomic_read(&tcon->num_writes),
269 (long long)(tcon->bytes_written));
270 buf += item_length;
271 length += item_length;
272 item_length = sprintf(buf,
273 "\nOpens: %d Deletes: %d\nMkdirs: %d Rmdirs: %d",
274 atomic_read(&tcon->num_opens),
275 atomic_read(&tcon->num_deletes),
276 atomic_read(&tcon->num_mkdirs),
277 atomic_read(&tcon->num_rmdirs));
278 buf += item_length;
279 length += item_length;
280 item_length = sprintf(buf,
281 "\nRenames: %d T2 Renames %d",
282 atomic_read(&tcon->num_renames),
283 atomic_read(&tcon->num_t2renames));
284 buf += item_length;
285 length += item_length;
287 read_unlock(&GlobalSMBSeslock);
289 buf += sprintf(buf,"\n");
290 length++;
292 if(offset + count >= length)
293 *eof = 1;
294 if(length < offset) {
295 *eof = 1;
296 return 0;
297 } else {
298 length = length - offset;
300 if (length > count)
301 length = count;
303 return length;
305 #endif
307 static struct proc_dir_entry *proc_fs_cifs;
308 read_proc_t cifs_txanchor_read;
309 static read_proc_t cifsFYI_read;
310 static write_proc_t cifsFYI_write;
311 static read_proc_t oplockEnabled_read;
312 static write_proc_t oplockEnabled_write;
313 static read_proc_t lookupFlag_read;
314 static write_proc_t lookupFlag_write;
315 static read_proc_t traceSMB_read;
316 static write_proc_t traceSMB_write;
317 static read_proc_t multiuser_mount_read;
318 static write_proc_t multiuser_mount_write;
319 static read_proc_t extended_security_read;
320 static write_proc_t extended_security_write;
321 static read_proc_t ntlmv2_enabled_read;
322 static write_proc_t ntlmv2_enabled_write;
323 static read_proc_t packet_signing_enabled_read;
324 static write_proc_t packet_signing_enabled_write;
325 static read_proc_t quotaEnabled_read;
326 static write_proc_t quotaEnabled_write;
327 static read_proc_t linuxExtensionsEnabled_read;
328 static write_proc_t linuxExtensionsEnabled_write;
330 void
331 cifs_proc_init(void)
333 struct proc_dir_entry *pde;
335 proc_fs_cifs = proc_mkdir("cifs", proc_root_fs);
336 if (proc_fs_cifs == NULL)
337 return;
339 proc_fs_cifs->owner = THIS_MODULE;
340 create_proc_read_entry("DebugData", 0, proc_fs_cifs,
341 cifs_debug_data_read, NULL);
343 #ifdef CONFIG_CIFS_STATS
344 create_proc_read_entry("Stats", 0, proc_fs_cifs,
345 cifs_stats_read, NULL);
346 #endif
347 pde = create_proc_read_entry("cifsFYI", 0, proc_fs_cifs,
348 cifsFYI_read, NULL);
349 if (pde)
350 pde->write_proc = cifsFYI_write;
352 pde =
353 create_proc_read_entry("traceSMB", 0, proc_fs_cifs,
354 traceSMB_read, NULL);
355 if (pde)
356 pde->write_proc = traceSMB_write;
358 pde = create_proc_read_entry("OplockEnabled", 0, proc_fs_cifs,
359 oplockEnabled_read, NULL);
360 if (pde)
361 pde->write_proc = oplockEnabled_write;
363 pde = create_proc_read_entry("ReenableOldCifsReaddirCode", 0, proc_fs_cifs,
364 quotaEnabled_read, NULL);
365 if (pde)
366 pde->write_proc = quotaEnabled_write;
368 pde = create_proc_read_entry("LinuxExtensionsEnabled", 0, proc_fs_cifs,
369 linuxExtensionsEnabled_read, NULL);
370 if (pde)
371 pde->write_proc = linuxExtensionsEnabled_write;
373 pde =
374 create_proc_read_entry("MultiuserMount", 0, proc_fs_cifs,
375 multiuser_mount_read, NULL);
376 if (pde)
377 pde->write_proc = multiuser_mount_write;
379 pde =
380 create_proc_read_entry("ExtendedSecurity", 0, proc_fs_cifs,
381 extended_security_read, NULL);
382 if (pde)
383 pde->write_proc = extended_security_write;
385 pde =
386 create_proc_read_entry("LookupCacheEnabled", 0, proc_fs_cifs,
387 lookupFlag_read, NULL);
388 if (pde)
389 pde->write_proc = lookupFlag_write;
391 pde =
392 create_proc_read_entry("NTLMV2Enabled", 0, proc_fs_cifs,
393 ntlmv2_enabled_read, NULL);
394 if (pde)
395 pde->write_proc = ntlmv2_enabled_write;
397 pde =
398 create_proc_read_entry("PacketSigningEnabled", 0, proc_fs_cifs,
399 packet_signing_enabled_read, NULL);
400 if (pde)
401 pde->write_proc = packet_signing_enabled_write;
404 void
405 cifs_proc_clean(void)
407 if (proc_fs_cifs == NULL)
408 return;
410 remove_proc_entry("DebugData", proc_fs_cifs);
411 remove_proc_entry("cifsFYI", proc_fs_cifs);
412 remove_proc_entry("traceSMB", proc_fs_cifs);
413 #ifdef CONFIG_CIFS_STATS
414 remove_proc_entry("Stats", proc_fs_cifs);
415 #endif
416 remove_proc_entry("MultiuserMount", proc_fs_cifs);
417 remove_proc_entry("OplockEnabled", proc_fs_cifs);
418 remove_proc_entry("NTLMV2Enabled",proc_fs_cifs);
419 remove_proc_entry("ExtendedSecurity",proc_fs_cifs);
420 remove_proc_entry("PacketSigningEnabled",proc_fs_cifs);
421 remove_proc_entry("LinuxExtensionsEnabled",proc_fs_cifs);
422 remove_proc_entry("ReenableOldCifsReaddirCode",proc_fs_cifs);
423 remove_proc_entry("LookupCacheEnabled",proc_fs_cifs);
424 remove_proc_entry("cifs", proc_root_fs);
427 static int
428 cifsFYI_read(char *page, char **start, off_t off, int count,
429 int *eof, void *data)
431 int len;
433 len = sprintf(page, "%d\n", cifsFYI);
435 len -= off;
436 *start = page + off;
438 if (len > count)
439 len = count;
440 else
441 *eof = 1;
443 if (len < 0)
444 len = 0;
446 return len;
448 static int
449 cifsFYI_write(struct file *file, const char __user *buffer,
450 unsigned long count, void *data)
452 char c;
453 int rc;
455 rc = get_user(c, buffer);
456 if (rc)
457 return rc;
458 if (c == '0' || c == 'n' || c == 'N')
459 cifsFYI = 0;
460 else if (c == '1' || c == 'y' || c == 'Y')
461 cifsFYI = 1;
463 return count;
466 static int
467 oplockEnabled_read(char *page, char **start, off_t off,
468 int count, int *eof, void *data)
470 int len;
472 len = sprintf(page, "%d\n", oplockEnabled);
474 len -= off;
475 *start = page + off;
477 if (len > count)
478 len = count;
479 else
480 *eof = 1;
482 if (len < 0)
483 len = 0;
485 return len;
487 static int
488 oplockEnabled_write(struct file *file, const char __user *buffer,
489 unsigned long count, void *data)
491 char c;
492 int rc;
494 rc = get_user(c, buffer);
495 if (rc)
496 return rc;
497 if (c == '0' || c == 'n' || c == 'N')
498 oplockEnabled = 0;
499 else if (c == '1' || c == 'y' || c == 'Y')
500 oplockEnabled = 1;
502 return count;
505 static int
506 quotaEnabled_read(char *page, char **start, off_t off,
507 int count, int *eof, void *data)
509 int len;
511 len = sprintf(page, "%d\n", experimEnabled);
512 /* could also check if quotas are enabled in kernel
513 as a whole first */
514 len -= off;
515 *start = page + off;
517 if (len > count)
518 len = count;
519 else
520 *eof = 1;
522 if (len < 0)
523 len = 0;
525 return len;
527 static int
528 quotaEnabled_write(struct file *file, const char __user *buffer,
529 unsigned long count, void *data)
531 char c;
532 int rc;
534 rc = get_user(c, buffer);
535 if (rc)
536 return rc;
537 if (c == '0' || c == 'n' || c == 'N')
538 experimEnabled = 0;
539 else if (c == '1' || c == 'y' || c == 'Y')
540 experimEnabled = 1;
542 return count;
545 static int
546 linuxExtensionsEnabled_read(char *page, char **start, off_t off,
547 int count, int *eof, void *data)
549 int len;
551 len = sprintf(page, "%d\n", linuxExtEnabled);
552 /* could also check if quotas are enabled in kernel
553 as a whole first */
554 len -= off;
555 *start = page + off;
557 if (len > count)
558 len = count;
559 else
560 *eof = 1;
562 if (len < 0)
563 len = 0;
565 return len;
567 static int
568 linuxExtensionsEnabled_write(struct file *file, const char __user *buffer,
569 unsigned long count, void *data)
571 char c;
572 int rc;
574 rc = get_user(c, buffer);
575 if (rc)
576 return rc;
577 if (c == '0' || c == 'n' || c == 'N')
578 linuxExtEnabled = 0;
579 else if (c == '1' || c == 'y' || c == 'Y')
580 linuxExtEnabled = 1;
582 return count;
586 static int
587 lookupFlag_read(char *page, char **start, off_t off,
588 int count, int *eof, void *data)
590 int len;
592 len = sprintf(page, "%d\n", lookupCacheEnabled);
594 len -= off;
595 *start = page + off;
597 if (len > count)
598 len = count;
599 else
600 *eof = 1;
602 if (len < 0)
603 len = 0;
605 return len;
607 static int
608 lookupFlag_write(struct file *file, const char __user *buffer,
609 unsigned long count, void *data)
611 char c;
612 int rc;
614 rc = get_user(c, buffer);
615 if (rc)
616 return rc;
617 if (c == '0' || c == 'n' || c == 'N')
618 lookupCacheEnabled = 0;
619 else if (c == '1' || c == 'y' || c == 'Y')
620 lookupCacheEnabled = 1;
622 return count;
624 static int
625 traceSMB_read(char *page, char **start, off_t off, int count,
626 int *eof, void *data)
628 int len;
630 len = sprintf(page, "%d\n", traceSMB);
632 len -= off;
633 *start = page + off;
635 if (len > count)
636 len = count;
637 else
638 *eof = 1;
640 if (len < 0)
641 len = 0;
643 return len;
645 static int
646 traceSMB_write(struct file *file, const char __user *buffer,
647 unsigned long count, void *data)
649 char c;
650 int rc;
652 rc = get_user(c, buffer);
653 if (rc)
654 return rc;
655 if (c == '0' || c == 'n' || c == 'N')
656 traceSMB = 0;
657 else if (c == '1' || c == 'y' || c == 'Y')
658 traceSMB = 1;
660 return count;
663 static int
664 multiuser_mount_read(char *page, char **start, off_t off,
665 int count, int *eof, void *data)
667 int len;
669 len = sprintf(page, "%d\n", multiuser_mount);
671 len -= off;
672 *start = page + off;
674 if (len > count)
675 len = count;
676 else
677 *eof = 1;
679 if (len < 0)
680 len = 0;
682 return len;
684 static int
685 multiuser_mount_write(struct file *file, const char __user *buffer,
686 unsigned long count, void *data)
688 char c;
689 int rc;
691 rc = get_user(c, buffer);
692 if (rc)
693 return rc;
694 if (c == '0' || c == 'n' || c == 'N')
695 multiuser_mount = 0;
696 else if (c == '1' || c == 'y' || c == 'Y')
697 multiuser_mount = 1;
699 return count;
702 static int
703 extended_security_read(char *page, char **start, off_t off,
704 int count, int *eof, void *data)
706 int len;
708 len = sprintf(page, "%d\n", extended_security);
710 len -= off;
711 *start = page + off;
713 if (len > count)
714 len = count;
715 else
716 *eof = 1;
718 if (len < 0)
719 len = 0;
721 return len;
723 static int
724 extended_security_write(struct file *file, const char __user *buffer,
725 unsigned long count, void *data)
727 char c;
728 int rc;
730 rc = get_user(c, buffer);
731 if (rc)
732 return rc;
733 if (c == '0' || c == 'n' || c == 'N')
734 extended_security = 0;
735 else if (c == '1' || c == 'y' || c == 'Y')
736 extended_security = 1;
738 return count;
741 static int
742 ntlmv2_enabled_read(char *page, char **start, off_t off,
743 int count, int *eof, void *data)
745 int len;
747 len = sprintf(page, "%d\n", ntlmv2_support);
749 len -= off;
750 *start = page + off;
752 if (len > count)
753 len = count;
754 else
755 *eof = 1;
757 if (len < 0)
758 len = 0;
760 return len;
762 static int
763 ntlmv2_enabled_write(struct file *file, const char __user *buffer,
764 unsigned long count, void *data)
766 char c;
767 int rc;
769 rc = get_user(c, buffer);
770 if (rc)
771 return rc;
772 if (c == '0' || c == 'n' || c == 'N')
773 ntlmv2_support = 0;
774 else if (c == '1' || c == 'y' || c == 'Y')
775 ntlmv2_support = 1;
777 return count;
780 static int
781 packet_signing_enabled_read(char *page, char **start, off_t off,
782 int count, int *eof, void *data)
784 int len;
786 len = sprintf(page, "%d\n", sign_CIFS_PDUs);
788 len -= off;
789 *start = page + off;
791 if (len > count)
792 len = count;
793 else
794 *eof = 1;
796 if (len < 0)
797 len = 0;
799 return len;
801 static int
802 packet_signing_enabled_write(struct file *file, const char __user *buffer,
803 unsigned long count, void *data)
805 char c;
806 int rc;
808 rc = get_user(c, buffer);
809 if (rc)
810 return rc;
811 if (c == '0' || c == 'n' || c == 'N')
812 sign_CIFS_PDUs = 0;
813 else if (c == '1' || c == 'y' || c == 'Y')
814 sign_CIFS_PDUs = 1;
815 else if (c == '2')
816 sign_CIFS_PDUs = 2;
818 return count;
822 #endif