blob: 7c50bfa9c438a1c7342e1f8e21291a8b1dd98187 [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
Joe Perchesf96637b2013-05-04 22:12:25 -050060#ifdef CONFIG_CIFS_DEBUG
61void cifs_vfs_err(const char *fmt, ...)
62{
63 struct va_format vaf;
64 va_list args;
65
66 va_start(args, fmt);
67
68 vaf.fmt = fmt;
69 vaf.va = &args;
70
71 printk(KERN_ERR "CIFS VFS: %pV", &vaf);
72
73 va_end(args);
74}
75#endif
76
Pavel Shilovskyd4e48542012-03-23 14:28:02 -040077void cifs_dump_detail(void *buf)
Steve French39798772006-05-31 22:40:51 +000078{
Pavel Shilovsky8aa26f32012-05-17 13:25:35 +040079#ifdef CONFIG_CIFS_DEBUG2
Pavel Shilovskyd4e48542012-03-23 14:28:02 -040080 struct smb_hdr *smb = (struct smb_hdr *)buf;
81
Joe Perchesf96637b2013-05-04 22:12:25 -050082 cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d\n",
83 smb->Command, smb->Status.CifsError,
84 smb->Flags, smb->Flags2, smb->Mid, smb->Pid);
85 cifs_dbg(VFS, "smb buf %p len %u\n", smb, smbCalcSize(smb));
Pavel Shilovsky8aa26f32012-05-17 13:25:35 +040086#endif /* CONFIG_CIFS_DEBUG2 */
Steve French39798772006-05-31 22:40:51 +000087}
88
Steve Frenchffdd6e42007-06-24 21:15:44 +000089void cifs_dump_mids(struct TCP_Server_Info *server)
Steve French39798772006-05-31 22:40:51 +000090{
Pavel Shilovsky8aa26f32012-05-17 13:25:35 +040091#ifdef CONFIG_CIFS_DEBUG2
Steve French39798772006-05-31 22:40:51 +000092 struct list_head *tmp;
Steve Frenchffdd6e42007-06-24 21:15:44 +000093 struct mid_q_entry *mid_entry;
Steve French39798772006-05-31 22:40:51 +000094
Steve French221601c2007-06-05 20:35:06 +000095 if (server == NULL)
Steve French39798772006-05-31 22:40:51 +000096 return;
97
Joe Perchesf96637b2013-05-04 22:12:25 -050098 cifs_dbg(VFS, "Dump pending requests:\n");
Steve French39798772006-05-31 22:40:51 +000099 spin_lock(&GlobalMid_Lock);
100 list_for_each(tmp, &server->pending_mid_q) {
101 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
Joe Perchesf96637b2013-05-04 22:12:25 -0500102 cifs_dbg(VFS, "State: %d Cmd: %d Pid: %d Cbdata: %p Mid %llu\n",
103 mid_entry->mid_state,
104 le16_to_cpu(mid_entry->command),
105 mid_entry->pid,
106 mid_entry->callback_data,
107 mid_entry->mid);
Steve French39798772006-05-31 22:40:51 +0000108#ifdef CONFIG_CIFS_STATS2
Joe Perchesf96637b2013-05-04 22:12:25 -0500109 cifs_dbg(VFS, "IsLarge: %d buf: %p time rcv: %ld now: %ld\n",
110 mid_entry->large_buf,
111 mid_entry->resp_buf,
112 mid_entry->when_received,
113 jiffies);
Steve French39798772006-05-31 22:40:51 +0000114#endif /* STATS2 */
Joe Perchesf96637b2013-05-04 22:12:25 -0500115 cifs_dbg(VFS, "IsMult: %d IsEnd: %d\n",
116 mid_entry->multiRsp, mid_entry->multiEnd);
Steve Frenchad8b15f2008-08-08 21:10:16 +0000117 if (mid_entry->resp_buf) {
118 cifs_dump_detail(mid_entry->resp_buf);
119 cifs_dump_mem("existing buf: ",
120 mid_entry->resp_buf, 62);
Steve French39798772006-05-31 22:40:51 +0000121 }
122 }
123 spin_unlock(&GlobalMid_Lock);
Steve French39798772006-05-31 22:40:51 +0000124#endif /* CONFIG_CIFS_DEBUG2 */
Pavel Shilovsky8aa26f32012-05-17 13:25:35 +0400125}
Steve French39798772006-05-31 22:40:51 +0000126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#ifdef CONFIG_PROC_FS
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000128static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129{
Jeff Laytonf1987b42008-11-15 11:12:47 -0500130 struct list_head *tmp1, *tmp2, *tmp3;
Steve Frenchffdd6e42007-06-24 21:15:44 +0000131 struct mid_q_entry *mid_entry;
Jeff Layton14fbf502008-11-14 13:53:46 -0500132 struct TCP_Server_Info *server;
Steve French96daf2b2011-05-27 04:34:02 +0000133 struct cifs_ses *ses;
134 struct cifs_tcon *tcon;
Jeff Laytonf1987b42008-11-15 11:12:47 -0500135 int i, j;
136 __u32 dev_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000138 seq_puts(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 "Display Internal CIFS Data Structures for Debugging\n"
140 "---------------------------------------------------\n");
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000141 seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
Jeff Laytonca40b712011-01-07 11:30:29 -0500142 seq_printf(m, "Features:");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530143#ifdef CONFIG_CIFS_DFS_UPCALL
Jeff Laytonca40b712011-01-07 11:30:29 -0500144 seq_printf(m, " dfs");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530145#endif
146#ifdef CONFIG_CIFS_FSCACHE
Jeff Laytonca40b712011-01-07 11:30:29 -0500147 seq_printf(m, " fscache");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530148#endif
149#ifdef CONFIG_CIFS_WEAK_PW_HASH
Jeff Laytonca40b712011-01-07 11:30:29 -0500150 seq_printf(m, " lanman");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530151#endif
152#ifdef CONFIG_CIFS_POSIX
Jeff Laytonca40b712011-01-07 11:30:29 -0500153 seq_printf(m, " posix");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530154#endif
155#ifdef CONFIG_CIFS_UPCALL
Jeff Laytonca40b712011-01-07 11:30:29 -0500156 seq_printf(m, " spnego");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530157#endif
158#ifdef CONFIG_CIFS_XATTR
Jeff Laytonca40b712011-01-07 11:30:29 -0500159 seq_printf(m, " xattr");
160#endif
161#ifdef CONFIG_CIFS_ACL
162 seq_printf(m, " acl");
Suresh Jayaramanf5799032010-07-30 18:25:56 +0530163#endif
164 seq_putc(m, '\n');
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000165 seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
166 seq_printf(m, "Servers:");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
168 i = 0;
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530169 spin_lock(&cifs_tcp_ses_lock);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500170 list_for_each(tmp1, &cifs_tcp_ses_list) {
171 server = list_entry(tmp1, struct TCP_Server_Info,
Jeff Layton14fbf502008-11-14 13:53:46 -0500172 tcp_ses_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 i++;
Jeff Layton14fbf502008-11-14 13:53:46 -0500174 list_for_each(tmp2, &server->smb_ses_list) {
Steve French96daf2b2011-05-27 04:34:02 +0000175 ses = list_entry(tmp2, struct cifs_ses,
Jeff Layton14fbf502008-11-14 13:53:46 -0500176 smb_ses_list);
177 if ((ses->serverDomain == NULL) ||
178 (ses->serverOS == NULL) ||
179 (ses->serverNOS == NULL)) {
Jeff Laytonf1987b42008-11-15 11:12:47 -0500180 seq_printf(m, "\n%d) entry for %s not fully "
181 "displayed\n\t", i, ses->serverName);
Jeff Layton14fbf502008-11-14 13:53:46 -0500182 } else {
183 seq_printf(m,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500184 "\n%d) Name: %s Domain: %s Uses: %d OS:"
185 " %s\n\tNOS: %s\tCapability: 0x%x\n\tSMB"
Steve French221601c2007-06-05 20:35:06 +0000186 " session status: %d\t",
Steve Frenchb8643e12005-04-28 22:41:07 -0700187 i, ses->serverName, ses->serverDomain,
Jeff Layton14fbf502008-11-14 13:53:46 -0500188 ses->ses_count, ses->serverOS, ses->serverNOS,
Steve French221601c2007-06-05 20:35:06 +0000189 ses->capabilities, ses->status);
Jeff Layton14fbf502008-11-14 13:53:46 -0500190 }
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000191 seq_printf(m, "TCP status: %d\n\tLocal Users To "
Jeff Layton14fbf502008-11-14 13:53:46 -0500192 "Server: %d SecMode: 0x%x Req On Wire: %d",
193 server->tcpStatus, server->srv_count,
Pavel Shilovskyfc40f9c2012-02-17 17:09:12 +0300194 server->sec_mode, in_flight(server));
Steve French131afd0b2005-10-07 09:51:05 -0700195
196#ifdef CONFIG_CIFS_STATS2
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000197 seq_printf(m, " In Send: %d In MaxReq Wait: %d",
Steve French789e6662011-08-09 18:44:44 +0000198 atomic_read(&server->in_send),
Jeff Layton14fbf502008-11-14 13:53:46 -0500199 atomic_read(&server->num_waiters));
Steve French131afd0b2005-10-07 09:51:05 -0700200#endif
201
Jeff Laytonf1987b42008-11-15 11:12:47 -0500202 seq_puts(m, "\n\tShares:");
203 j = 0;
204 list_for_each(tmp3, &ses->tcon_list) {
Steve French96daf2b2011-05-27 04:34:02 +0000205 tcon = list_entry(tmp3, struct cifs_tcon,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500206 tcon_list);
207 ++j;
208 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
209 seq_printf(m, "\n\t%d) %s Mounts: %d ", j,
210 tcon->treeName, tcon->tc_count);
211 if (tcon->nativeFileSystem) {
212 seq_printf(m, "Type: %s ",
213 tcon->nativeFileSystem);
214 }
215 seq_printf(m, "DevInfo: 0x%x Attributes: 0x%x"
Steve French59b04c52014-08-02 21:16:48 -0500216 "\n\tPathComponentMax: %d Status: %d",
Jeff Laytonf1987b42008-11-15 11:12:47 -0500217 le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
218 le32_to_cpu(tcon->fsAttrInfo.Attributes),
219 le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
220 tcon->tidStatus);
221 if (dev_type == FILE_DEVICE_DISK)
222 seq_puts(m, " type: DISK ");
223 else if (dev_type == FILE_DEVICE_CD_ROM)
224 seq_puts(m, " type: CDROM ");
225 else
226 seq_printf(m, " type: %d ", dev_type);
Steve French769ee6a2013-06-19 14:15:30 -0500227 if (server->ops->dump_share_caps)
228 server->ops->dump_share_caps(m, tcon);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500229
230 if (tcon->need_reconnect)
231 seq_puts(m, "\tDISCONNECTED ");
232 seq_putc(m, '\n');
233 }
234
235 seq_puts(m, "\n\tMIDs:\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
237 spin_lock(&GlobalMid_Lock);
Jeff Layton14fbf502008-11-14 13:53:46 -0500238 list_for_each(tmp3, &server->pending_mid_q) {
Jeff Laytonf1987b42008-11-15 11:12:47 -0500239 mid_entry = list_entry(tmp3, struct mid_q_entry,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 qhead);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500241 seq_printf(m, "\tState: %d com: %d pid:"
Pavel Shilovsky7c9421e2012-03-23 14:28:03 -0400242 " %d cbdata: %p mid %llu\n",
243 mid_entry->mid_state,
244 le16_to_cpu(mid_entry->command),
245 mid_entry->pid,
246 mid_entry->callback_data,
247 mid_entry->mid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 }
Steve French221601c2007-06-05 20:35:06 +0000249 spin_unlock(&GlobalMid_Lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 }
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530252 spin_unlock(&cifs_tcp_ses_lock);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000253 seq_putc(m, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 /* BB add code to dump additional info such as TCP session info now */
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000256 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257}
258
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000259static int cifs_debug_data_proc_open(struct inode *inode, struct file *file)
260{
261 return single_open(file, cifs_debug_data_proc_show, NULL);
262}
Steve French1047abc2005-10-11 19:58:06 -0700263
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000264static const struct file_operations cifs_debug_data_proc_fops = {
265 .owner = THIS_MODULE,
266 .open = cifs_debug_data_proc_open,
267 .read = seq_read,
268 .llseek = seq_lseek,
269 .release = single_release,
270};
271
272#ifdef CONFIG_CIFS_STATS
273static ssize_t cifs_stats_proc_write(struct file *file,
274 const char __user *buffer, size_t count, loff_t *ppos)
Steve French1047abc2005-10-11 19:58:06 -0700275{
Steve French221601c2007-06-05 20:35:06 +0000276 char c;
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300277 bool bv;
Steve French221601c2007-06-05 20:35:06 +0000278 int rc;
Jeff Laytonf1987b42008-11-15 11:12:47 -0500279 struct list_head *tmp1, *tmp2, *tmp3;
280 struct TCP_Server_Info *server;
Steve French96daf2b2011-05-27 04:34:02 +0000281 struct cifs_ses *ses;
282 struct cifs_tcon *tcon;
Steve French1047abc2005-10-11 19:58:06 -0700283
Steve French221601c2007-06-05 20:35:06 +0000284 rc = get_user(c, buffer);
285 if (rc)
286 return rc;
Steve French1047abc2005-10-11 19:58:06 -0700287
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300288 if (strtobool(&c, &bv) == 0) {
Steve French4498eed52005-12-03 13:58:57 -0800289#ifdef CONFIG_CIFS_STATS2
290 atomic_set(&totBufAllocCount, 0);
291 atomic_set(&totSmBufAllocCount, 0);
292#endif /* CONFIG_CIFS_STATS2 */
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530293 spin_lock(&cifs_tcp_ses_lock);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500294 list_for_each(tmp1, &cifs_tcp_ses_list) {
295 server = list_entry(tmp1, struct TCP_Server_Info,
296 tcp_ses_list);
Steve Frenchc2b33822008-11-17 03:57:13 +0000297 list_for_each(tmp2, &server->smb_ses_list) {
Steve French96daf2b2011-05-27 04:34:02 +0000298 ses = list_entry(tmp2, struct cifs_ses,
Steve Frenchc2b33822008-11-17 03:57:13 +0000299 smb_ses_list);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500300 list_for_each(tmp3, &ses->tcon_list) {
301 tcon = list_entry(tmp3,
Steve French96daf2b2011-05-27 04:34:02 +0000302 struct cifs_tcon,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500303 tcon_list);
304 atomic_set(&tcon->num_smbs_sent, 0);
Pavel Shilovsky44c58182012-05-28 14:16:31 +0400305 if (server->ops->clear_stats)
306 server->ops->clear_stats(tcon);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500307 }
308 }
Steve French1047abc2005-10-11 19:58:06 -0700309 }
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530310 spin_unlock(&cifs_tcp_ses_lock);
Steve French1047abc2005-10-11 19:58:06 -0700311 }
312
Steve French221601c2007-06-05 20:35:06 +0000313 return count;
Steve French1047abc2005-10-11 19:58:06 -0700314}
315
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000316static int cifs_stats_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000318 int i;
Jeff Laytonf1987b42008-11-15 11:12:47 -0500319 struct list_head *tmp1, *tmp2, *tmp3;
320 struct TCP_Server_Info *server;
Steve French96daf2b2011-05-27 04:34:02 +0000321 struct cifs_ses *ses;
322 struct cifs_tcon *tcon;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000324 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 "Resources in use\nCIFS Session: %d\n",
326 sesInfoAllocCount.counter);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000327 seq_printf(m, "Share (unique mount targets): %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 tconInfoAllocCount.counter);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000329 seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
Steve Frenchb8643e12005-04-28 22:41:07 -0700330 bufAllocCount.counter,
331 cifs_min_rcv + tcpSesAllocCount.counter);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000332 seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
Steve French221601c2007-06-05 20:35:06 +0000333 smBufAllocCount.counter, cifs_min_small);
Steve French07475ff2005-12-03 14:11:37 -0800334#ifdef CONFIG_CIFS_STATS2
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000335 seq_printf(m, "Total Large %d Small %d Allocations\n",
Steve French07475ff2005-12-03 14:11:37 -0800336 atomic_read(&totBufAllocCount),
Steve French221601c2007-06-05 20:35:06 +0000337 atomic_read(&totSmBufAllocCount));
Steve French07475ff2005-12-03 14:11:37 -0800338#endif /* CONFIG_CIFS_STATS2 */
339
Jeff Layton80975312011-01-11 07:24:02 -0500340 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000341 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 "\n%d session %d share reconnects\n",
Steve French221601c2007-06-05 20:35:06 +0000343 tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000345 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 "Total vfs operations: %d maximum at one time: %d\n",
Steve French221601c2007-06-05 20:35:06 +0000347 GlobalCurrentXid, GlobalMaxActiveXid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
349 i = 0;
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530350 spin_lock(&cifs_tcp_ses_lock);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500351 list_for_each(tmp1, &cifs_tcp_ses_list) {
352 server = list_entry(tmp1, struct TCP_Server_Info,
353 tcp_ses_list);
354 list_for_each(tmp2, &server->smb_ses_list) {
Steve French96daf2b2011-05-27 04:34:02 +0000355 ses = list_entry(tmp2, struct cifs_ses,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500356 smb_ses_list);
357 list_for_each(tmp3, &ses->tcon_list) {
358 tcon = list_entry(tmp3,
Steve French96daf2b2011-05-27 04:34:02 +0000359 struct cifs_tcon,
Jeff Laytonf1987b42008-11-15 11:12:47 -0500360 tcon_list);
361 i++;
362 seq_printf(m, "\n%d) %s", i, tcon->treeName);
363 if (tcon->need_reconnect)
364 seq_puts(m, "\tDISCONNECTED ");
Pavel Shilovsky44c58182012-05-28 14:16:31 +0400365 seq_printf(m, "\nSMBs: %d",
366 atomic_read(&tcon->num_smbs_sent));
367 if (server->ops->print_stats)
368 server->ops->print_stats(m, tcon);
Jeff Laytonf1987b42008-11-15 11:12:47 -0500369 }
370 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 }
Suresh Jayaraman3f9bcca2010-10-18 23:29:37 +0530372 spin_unlock(&cifs_tcp_ses_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000374 seq_putc(m, '\n');
375 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000377
378static int cifs_stats_proc_open(struct inode *inode, struct file *file)
379{
380 return single_open(file, cifs_stats_proc_show, NULL);
381}
382
383static const struct file_operations cifs_stats_proc_fops = {
384 .owner = THIS_MODULE,
385 .open = cifs_stats_proc_open,
386 .read = seq_read,
387 .llseek = seq_lseek,
388 .release = single_release,
389 .write = cifs_stats_proc_write,
390};
Steve French90c81e02008-02-12 20:32:36 +0000391#endif /* STATS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
393static struct proc_dir_entry *proc_fs_cifs;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000394static const struct file_operations cifsFYI_proc_fops;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000395static const struct file_operations cifs_lookup_cache_proc_fops;
396static const struct file_operations traceSMB_proc_fops;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000397static const struct file_operations cifs_security_flags_proc_fops;
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000398static const struct file_operations cifs_linux_ext_proc_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
400void
401cifs_proc_init(void)
402{
Alexey Dobriyan36a5aeb2008-04-29 01:01:42 -0700403 proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 if (proc_fs_cifs == NULL)
405 return;
406
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000407 proc_create("DebugData", 0, proc_fs_cifs, &cifs_debug_data_proc_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
409#ifdef CONFIG_CIFS_STATS
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000410 proc_create("Stats", 0, proc_fs_cifs, &cifs_stats_proc_fops);
Steve French90c81e02008-02-12 20:32:36 +0000411#endif /* STATS */
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000412 proc_create("cifsFYI", 0, proc_fs_cifs, &cifsFYI_proc_fops);
413 proc_create("traceSMB", 0, proc_fs_cifs, &traceSMB_proc_fops);
Steve French99b1f5b2008-07-24 02:37:45 +0000414 proc_create("LinuxExtensionsEnabled", 0, proc_fs_cifs,
415 &cifs_linux_ext_proc_fops);
Steve French99b1f5b2008-07-24 02:37:45 +0000416 proc_create("SecurityFlags", 0, proc_fs_cifs,
417 &cifs_security_flags_proc_fops);
418 proc_create("LookupCacheEnabled", 0, proc_fs_cifs,
419 &cifs_lookup_cache_proc_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420}
421
422void
423cifs_proc_clean(void)
424{
425 if (proc_fs_cifs == NULL)
426 return;
427
428 remove_proc_entry("DebugData", proc_fs_cifs);
429 remove_proc_entry("cifsFYI", proc_fs_cifs);
430 remove_proc_entry("traceSMB", proc_fs_cifs);
431#ifdef CONFIG_CIFS_STATS
432 remove_proc_entry("Stats", proc_fs_cifs);
433#endif
Steve French221601c2007-06-05 20:35:06 +0000434 remove_proc_entry("SecurityFlags", proc_fs_cifs);
Steve French221601c2007-06-05 20:35:06 +0000435 remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
Steve French221601c2007-06-05 20:35:06 +0000436 remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
Alexey Dobriyan36a5aeb2008-04-29 01:01:42 -0700437 remove_proc_entry("fs/cifs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438}
439
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000440static int cifsFYI_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000442 seq_printf(m, "%d\n", cifsFYI);
443 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000445
446static int cifsFYI_proc_open(struct inode *inode, struct file *file)
447{
448 return single_open(file, cifsFYI_proc_show, NULL);
449}
450
451static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
452 size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453{
454 char c;
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300455 bool bv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 int rc;
457
458 rc = get_user(c, buffer);
459 if (rc)
460 return rc;
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300461 if (strtobool(&c, &bv) == 0)
462 cifsFYI = bv;
Steve French221601c2007-06-05 20:35:06 +0000463 else if ((c > '1') && (c <= '9'))
Steve French1047abc2005-10-11 19:58:06 -0700464 cifsFYI = (int) (c - '0'); /* see cifs_debug.h for meanings */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
466 return count;
467}
468
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000469static const struct file_operations cifsFYI_proc_fops = {
470 .owner = THIS_MODULE,
471 .open = cifsFYI_proc_open,
472 .read = seq_read,
473 .llseek = seq_lseek,
474 .release = single_release,
475 .write = cifsFYI_proc_write,
476};
477
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000478static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000480 seq_printf(m, "%d\n", linuxExtEnabled);
481 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000483
484static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
485{
486 return single_open(file, cifs_linux_ext_proc_show, NULL);
487}
488
489static ssize_t cifs_linux_ext_proc_write(struct file *file,
490 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491{
Steve French221601c2007-06-05 20:35:06 +0000492 char c;
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300493 bool bv;
Steve French221601c2007-06-05 20:35:06 +0000494 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
Steve French221601c2007-06-05 20:35:06 +0000496 rc = get_user(c, buffer);
497 if (rc)
498 return rc;
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300499
500 rc = strtobool(&c, &bv);
501 if (rc)
502 return rc;
503
504 linuxExtEnabled = bv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
Steve French221601c2007-06-05 20:35:06 +0000506 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507}
508
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000509static const struct file_operations cifs_linux_ext_proc_fops = {
510 .owner = THIS_MODULE,
511 .open = cifs_linux_ext_proc_open,
512 .read = seq_read,
513 .llseek = seq_lseek,
514 .release = single_release,
515 .write = cifs_linux_ext_proc_write,
516};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000518static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000520 seq_printf(m, "%d\n", lookupCacheEnabled);
521 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000523
524static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
525{
526 return single_open(file, cifs_lookup_cache_proc_show, NULL);
527}
528
529static ssize_t cifs_lookup_cache_proc_write(struct file *file,
530 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531{
532 char c;
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300533 bool bv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 int rc;
535
536 rc = get_user(c, buffer);
537 if (rc)
538 return rc;
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300539
540 rc = strtobool(&c, &bv);
541 if (rc)
542 return rc;
543
544 lookupCacheEnabled = bv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
546 return count;
547}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000548
549static const struct file_operations cifs_lookup_cache_proc_fops = {
550 .owner = THIS_MODULE,
551 .open = cifs_lookup_cache_proc_open,
552 .read = seq_read,
553 .llseek = seq_lseek,
554 .release = single_release,
555 .write = cifs_lookup_cache_proc_write,
556};
557
558static int traceSMB_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559{
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000560 seq_printf(m, "%d\n", traceSMB);
561 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000563
564static int traceSMB_proc_open(struct inode *inode, struct file *file)
565{
566 return single_open(file, traceSMB_proc_show, NULL);
567}
568
569static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
570 size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571{
572 char c;
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300573 bool bv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 int rc;
575
576 rc = get_user(c, buffer);
577 if (rc)
578 return rc;
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300579
580 rc = strtobool(&c, &bv);
581 if (rc)
582 return rc;
583
584 traceSMB = bv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
586 return count;
587}
588
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000589static const struct file_operations traceSMB_proc_fops = {
590 .owner = THIS_MODULE,
591 .open = traceSMB_proc_open,
592 .read = seq_read,
593 .llseek = seq_lseek,
594 .release = single_release,
595 .write = traceSMB_proc_write,
596};
597
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000598static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599{
Jeff Layton04912d62010-04-24 07:57:45 -0400600 seq_printf(m, "0x%x\n", global_secflags);
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000601 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000603
604static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
605{
606 return single_open(file, cifs_security_flags_proc_show, NULL);
607}
608
Jeff Layton52dfb442013-05-26 07:01:02 -0400609/*
610 * Ensure that if someone sets a MUST flag, that we disable all other MAY
611 * flags except for the ones corresponding to the given MUST flag. If there are
612 * multiple MUST flags, then try to prefer more secure ones.
613 */
614static void
615cifs_security_flags_handle_must_flags(unsigned int *flags)
616{
617 unsigned int signflags = *flags & CIFSSEC_MUST_SIGN;
618
619 if ((*flags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5)
620 *flags = CIFSSEC_MUST_KRB5;
621 else if ((*flags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP)
622 *flags = CIFSSEC_MUST_NTLMSSP;
623 else if ((*flags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2)
624 *flags = CIFSSEC_MUST_NTLMV2;
625 else if ((*flags & CIFSSEC_MUST_NTLM) == CIFSSEC_MUST_NTLM)
626 *flags = CIFSSEC_MUST_NTLM;
627 else if ((*flags & CIFSSEC_MUST_LANMAN) == CIFSSEC_MUST_LANMAN)
628 *flags = CIFSSEC_MUST_LANMAN;
629 else if ((*flags & CIFSSEC_MUST_PLNTXT) == CIFSSEC_MUST_PLNTXT)
630 *flags = CIFSSEC_MUST_PLNTXT;
631
632 *flags |= signflags;
633}
634
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000635static ssize_t cifs_security_flags_proc_write(struct file *file,
636 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637{
Jeff Layton7715dad2013-05-26 07:01:01 -0400638 int rc;
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000639 unsigned int flags;
640 char flags_string[12];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 char c;
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300642 bool bv;
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000643
Steve French221601c2007-06-05 20:35:06 +0000644 if ((count < 1) || (count > 11))
Steve French39798772006-05-31 22:40:51 +0000645 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000647 memset(flags_string, 0, 12);
Steve French39798772006-05-31 22:40:51 +0000648
Steve French221601c2007-06-05 20:35:06 +0000649 if (copy_from_user(flags_string, buffer, count))
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000650 return -EFAULT;
Steve French39798772006-05-31 22:40:51 +0000651
Steve French221601c2007-06-05 20:35:06 +0000652 if (count < 3) {
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000653 /* single char or single char followed by null */
654 c = flags_string[0];
Andy Shevchenko28e2aed2014-08-27 16:49:42 +0300655 if (strtobool(&c, &bv) == 0) {
656 global_secflags = bv ? CIFSSEC_MAX : CIFSSEC_DEF;
Steve Frencha0136892007-10-04 20:05:09 +0000657 return count;
658 } else if (!isdigit(c)) {
Jeff Layton7715dad2013-05-26 07:01:01 -0400659 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
660 flags_string);
Steve Frencha0136892007-10-04 20:05:09 +0000661 return -EINVAL;
662 }
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000663 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664
Jeff Layton7715dad2013-05-26 07:01:01 -0400665 /* else we have a number */
666 rc = kstrtouint(flags_string, 0, &flags);
667 if (rc) {
668 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
669 flags_string);
670 return rc;
671 }
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000672
Joe Perchesf96637b2013-05-04 22:12:25 -0500673 cifs_dbg(FYI, "sec flags 0x%x\n", flags);
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000674
Jeff Layton7715dad2013-05-26 07:01:01 -0400675 if (flags == 0) {
676 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", flags_string);
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000677 return -EINVAL;
678 }
679
Steve French221601c2007-06-05 20:35:06 +0000680 if (flags & ~CIFSSEC_MASK) {
Jeff Layton7715dad2013-05-26 07:01:01 -0400681 cifs_dbg(VFS, "Unsupported security flags: 0x%x\n",
Joe Perchesf96637b2013-05-04 22:12:25 -0500682 flags & ~CIFSSEC_MASK);
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000683 return -EINVAL;
684 }
Jeff Layton7715dad2013-05-26 07:01:01 -0400685
Jeff Layton52dfb442013-05-26 07:01:02 -0400686 cifs_security_flags_handle_must_flags(&flags);
687
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000688 /* flags look ok - update the global security flags for cifs module */
Jeff Layton04912d62010-04-24 07:57:45 -0400689 global_secflags = flags;
690 if (global_secflags & CIFSSEC_MUST_SIGN) {
Steve French762e5ab2007-06-28 18:41:42 +0000691 /* requiring signing implies signing is allowed */
Jeff Layton04912d62010-04-24 07:57:45 -0400692 global_secflags |= CIFSSEC_MAY_SIGN;
Joe Perchesf96637b2013-05-04 22:12:25 -0500693 cifs_dbg(FYI, "packet signing now required\n");
Jeff Layton04912d62010-04-24 07:57:45 -0400694 } else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500695 cifs_dbg(FYI, "packet signing disabled\n");
Steve French762e5ab2007-06-28 18:41:42 +0000696 }
697 /* BB should we turn on MAY flags for other MUST options? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 return count;
699}
Alexey Dobriyanf984c7b2008-07-24 02:34:24 +0000700
701static const struct file_operations cifs_security_flags_proc_fops = {
702 .owner = THIS_MODULE,
703 .open = cifs_security_flags_proc_open,
704 .read = seq_read,
705 .llseek = seq_lseek,
706 .release = single_release,
707 .write = cifs_security_flags_proc_write,
708};
Steve French90c81e02008-02-12 20:32:36 +0000709#else
Steve Frenche086fce2008-02-18 04:03:58 +0000710inline void cifs_proc_init(void)
Steve French90c81e02008-02-12 20:32:36 +0000711{
712}
713
Steve Frenche086fce2008-02-18 04:03:58 +0000714inline void cifs_proc_clean(void)
Steve French90c81e02008-02-12 20:32:36 +0000715{
716}
717#endif /* PROC_FS */