]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - fs/cifs/cifs_debug.c
cifs: reinstate sharing of SMB sessions sans races
[linux-2.6-omap-h63xx.git] / fs / cifs / cifs_debug.c
1 /*
2  *   fs/cifs_debug.c
3  *
4  *   Copyright (C) International Business Machines  Corp., 2000,2005
5  *
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
10  *   the Free Software Foundation; either version 2 of the License, or
11  *   (at your option) any later version.
12  *
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.
17  *
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
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"
32 #include "cifsfs.h"
33
34 void
35 cifs_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
42         printk(KERN_DEBUG "%s: dump of %d bytes of data at 0x%p\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);
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
60 #ifdef CONFIG_CIFS_DEBUG2
61 void cifs_dump_detail(struct smb_hdr *smb)
62 {
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)));
67 }
68
69
70 void cifs_dump_mids(struct TCP_Server_Info *server)
71 {
72         struct list_head *tmp;
73         struct mid_q_entry *mid_entry;
74
75         if (server == NULL)
76                 return;
77
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",
83                         mid_entry->midState,
84                         (int)mid_entry->command,
85                         mid_entry->pid,
86                         mid_entry->tsk,
87                         mid_entry->mid));
88 #ifdef CONFIG_CIFS_STATS2
89                 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));
94 #endif /* STATS2 */
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);
101                 }
102         }
103         spin_unlock(&GlobalMid_Lock);
104 }
105 #endif /* CONFIG_CIFS_DEBUG2 */
106
107 #ifdef CONFIG_PROC_FS
108 static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
109 {
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;
115         int i;
116
117         seq_puts(m,
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:");
123
124         i = 0;
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,
128                                     tcp_ses_list);
129                 i++;
130                 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,
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);
146                         }
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,
150                                    server->secMode,
151                                    atomic_read(&server->inFlight));
152
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));
157 #endif
158
159                         seq_puts(m, "\nMIDs:\n");
160
161                         spin_lock(&GlobalMid_Lock);
162                         list_for_each(tmp3, &server->pending_mid_q) {
163                                 mid_entry = list_entry(tmp3, struct
164                                         mid_q_entry,
165                                         qhead);
166                                 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);
173                         }
174                         spin_unlock(&GlobalMid_Lock);
175                 }
176         }
177         read_unlock(&cifs_tcp_ses_lock);
178         seq_putc(m, '\n');
179
180         seq_puts(m, "Shares:");
181
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);
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);
194                 }
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),
200                             tcon->tidStatus);
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 ");
205                 else
206                         seq_printf(m, " type: %d ", dev_type);
207
208                 if (tcon->need_reconnect)
209                         seq_puts(m, "\tDISCONNECTED ");
210         }
211         read_unlock(&GlobalSMBSeslock);
212
213         seq_putc(m, '\n');
214
215         /* BB add code to dump additional info such as TCP session info now */
216         return 0;
217 }
218
219 static 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 }
223
224 static 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
233 static ssize_t cifs_stats_proc_write(struct file *file,
234                 const char __user *buffer, size_t count, loff_t *ppos)
235 {
236         char c;
237         int rc;
238         struct list_head *tmp;
239         struct cifsTconInfo *tcon;
240
241         rc = get_user(c, buffer);
242         if (rc)
243                 return rc;
244
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,
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
275         return count;
276 }
277
278 static int cifs_stats_proc_show(struct seq_file *m, void *v)
279 {
280         int i;
281         struct list_head *tmp;
282         struct cifsTconInfo *tcon;
283
284         seq_printf(m,
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 */
299
300         seq_printf(m, "Operations (MIDs): %d\n", midCount.counter);
301         seq_printf(m,
302                 "\n%d session %d share reconnects\n",
303                 tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
304
305         seq_printf(m,
306                 "Total vfs operations: %d maximum at one time: %d\n",
307                 GlobalCurrentXid, GlobalMaxActiveXid);
308
309         i = 0;
310         read_lock(&GlobalSMBSeslock);
311         list_for_each(tmp, &GlobalTreeConnectionList) {
312                 i++;
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));
326                 seq_printf(m,
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));
331
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));
346         }
347         read_unlock(&GlobalSMBSeslock);
348
349         seq_putc(m, '\n');
350         return 0;
351 }
352
353 static int cifs_stats_proc_open(struct inode *inode, struct file *file)
354 {
355         return single_open(file, cifs_stats_proc_show, NULL);
356 }
357
358 static 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 };
366 #endif /* STATS */
367
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;
377
378 void
379 cifs_proc_init(void)
380 {
381         proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
382         if (proc_fs_cifs == NULL)
383                 return;
384
385         proc_fs_cifs->owner = THIS_MODULE;
386         proc_create("DebugData", 0, proc_fs_cifs, &cifs_debug_data_proc_fops);
387
388 #ifdef CONFIG_CIFS_STATS
389         proc_create("Stats", 0, proc_fs_cifs, &cifs_stats_proc_fops);
390 #endif /* STATS */
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);
404 }
405
406 void
407 cifs_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);
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);
425 }
426
427 static int cifsFYI_proc_show(struct seq_file *m, void *v)
428 {
429         seq_printf(m, "%d\n", cifsFYI);
430         return 0;
431 }
432
433 static int cifsFYI_proc_open(struct inode *inode, struct file *file)
434 {
435         return single_open(file, cifsFYI_proc_show, NULL);
436 }
437
438 static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
439                 size_t count, loff_t *ppos)
440 {
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;
451         else if ((c > '1') && (c <= '9'))
452                 cifsFYI = (int) (c - '0'); /* see cifs_debug.h for meanings */
453
454         return count;
455 }
456
457 static 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
466 static int cifs_oplock_proc_show(struct seq_file *m, void *v)
467 {
468         seq_printf(m, "%d\n", oplockEnabled);
469         return 0;
470 }
471
472 static int cifs_oplock_proc_open(struct inode *inode, struct file *file)
473 {
474         return single_open(file, cifs_oplock_proc_show, NULL);
475 }
476
477 static ssize_t cifs_oplock_proc_write(struct file *file,
478                 const char __user *buffer, size_t count, loff_t *ppos)
479 {
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
494 static 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
503 static int cifs_experimental_proc_show(struct seq_file *m, void *v)
504 {
505         seq_printf(m, "%d\n", experimEnabled);
506         return 0;
507 }
508
509 static int cifs_experimental_proc_open(struct inode *inode, struct file *file)
510 {
511         return single_open(file, cifs_experimental_proc_show, NULL);
512 }
513
514 static ssize_t cifs_experimental_proc_write(struct file *file,
515                 const char __user *buffer, size_t count, loff_t *ppos)
516 {
517         char c;
518         int rc;
519
520         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;
529
530         return count;
531 }
532
533 static 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
542 static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
543 {
544         seq_printf(m, "%d\n", linuxExtEnabled);
545         return 0;
546 }
547
548 static 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
553 static ssize_t cifs_linux_ext_proc_write(struct file *file,
554                 const char __user *buffer, size_t count, loff_t *ppos)
555 {
556         char c;
557         int rc;
558
559         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;
566
567         return count;
568 }
569
570 static 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 };
578
579 static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
580 {
581         seq_printf(m, "%d\n", lookupCacheEnabled);
582         return 0;
583 }
584
585 static 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
590 static ssize_t cifs_lookup_cache_proc_write(struct file *file,
591                 const char __user *buffer, size_t count, loff_t *ppos)
592 {
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 }
606
607 static 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
616 static int traceSMB_proc_show(struct seq_file *m, void *v)
617 {
618         seq_printf(m, "%d\n", traceSMB);
619         return 0;
620 }
621
622 static int traceSMB_proc_open(struct inode *inode, struct file *file)
623 {
624         return single_open(file, traceSMB_proc_show, NULL);
625 }
626
627 static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
628                 size_t count, loff_t *ppos)
629 {
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
644 static 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
653 static int cifs_multiuser_mount_proc_show(struct seq_file *m, void *v)
654 {
655         seq_printf(m, "%d\n", multiuser_mount);
656         return 0;
657 }
658
659 static int cifs_multiuser_mount_proc_open(struct inode *inode, struct file *fh)
660 {
661         return single_open(fh, cifs_multiuser_mount_proc_show, NULL);
662 }
663
664 static ssize_t cifs_multiuser_mount_proc_write(struct file *file,
665                 const char __user *buffer, size_t count, loff_t *ppos)
666 {
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
681 static 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
690 static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
691 {
692         seq_printf(m, "0x%x\n", extended_security);
693         return 0;
694 }
695
696 static 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
701 static ssize_t cifs_security_flags_proc_write(struct file *file,
702                 const char __user *buffer, size_t count, loff_t *ppos)
703 {
704         unsigned int flags;
705         char flags_string[12];
706         char c;
707
708         if ((count < 1) || (count > 11))
709                 return -EINVAL;
710
711         memset(flags_string, 0, 12);
712
713         if (copy_from_user(flags_string, buffer, count))
714                 return -EFAULT;
715
716         if (count < 3) {
717                 /* single char or single char followed by null */
718                 c = flags_string[0];
719                 if (c == '0' || c == 'n' || c == 'N') {
720                         extended_security = CIFSSEC_DEF; /* default */
721                         return count;
722                 } else if (c == '1' || c == 'y' || c == 'Y') {
723                         extended_security = CIFSSEC_MAX;
724                         return count;
725                 } else if (!isdigit(c)) {
726                         cERROR(1, ("invalid flag %c", c));
727                         return -EINVAL;
728                 }
729         }
730         /* else we have a number */
731
732         flags = simple_strtoul(flags_string, NULL, 0);
733
734         cFYI(1, ("sec flags 0x%x", flags));
735
736         if (flags <= 0)  {
737                 cERROR(1, ("invalid security flags %s", flags_string));
738                 return -EINVAL;
739         }
740
741         if (flags & ~CIFSSEC_MASK) {
742                 cERROR(1, ("attempt to set unsupported security flags 0x%x",
743                         flags & ~CIFSSEC_MASK));
744                 return -EINVAL;
745         }
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"));
754         }
755         /* BB should we turn on MAY flags for other MUST options? */
756         return count;
757 }
758
759 static 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 };
767 #else
768 inline void cifs_proc_init(void)
769 {
770 }
771
772 inline void cifs_proc_clean(void)
773 {
774 }
775 #endif /* PROC_FS */