Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/cifs_debug.c |
| 3 | * |
Steve French | b8643e1 | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 4 | * Copyright (C) International Business Machines Corp., 2000,2005 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
Steve French | 221601c | 2007-06-05 20:35:06 +0000 | [diff] [blame] | 10 | * the Free Software Foundation; either version 2 of the License, or |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * (at your option) any later version. |
Steve French | 221601c | 2007-06-05 20:35:06 +0000 | [diff] [blame] | 12 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
Steve French | 221601c | 2007-06-05 20:35:06 +0000 | [diff] [blame] | 19 | * along with this program; if not, write to the Free Software |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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" |
Steve French | 6c91d36 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 32 | #include "cifsfs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Steve French | 221601c | 2007-06-05 20:35:06 +0000 | [diff] [blame] | 42 | printk(KERN_DEBUG "%s: dump of %d bytes of data at 0x%p\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 60 | #ifdef CONFIG_CIFS_DEBUG |
| 61 | void 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 Shilovsky | d4e4854 | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 77 | void cifs_dump_detail(void *buf) |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 78 | { |
Pavel Shilovsky | 8aa26f3 | 2012-05-17 13:25:35 +0400 | [diff] [blame] | 79 | #ifdef CONFIG_CIFS_DEBUG2 |
Pavel Shilovsky | d4e4854 | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 80 | struct smb_hdr *smb = (struct smb_hdr *)buf; |
| 81 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 82 | 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 Shilovsky | 8aa26f3 | 2012-05-17 13:25:35 +0400 | [diff] [blame] | 86 | #endif /* CONFIG_CIFS_DEBUG2 */ |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 87 | } |
| 88 | |
Steve French | ffdd6e4 | 2007-06-24 21:15:44 +0000 | [diff] [blame] | 89 | void cifs_dump_mids(struct TCP_Server_Info *server) |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 90 | { |
Pavel Shilovsky | 8aa26f3 | 2012-05-17 13:25:35 +0400 | [diff] [blame] | 91 | #ifdef CONFIG_CIFS_DEBUG2 |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 92 | struct list_head *tmp; |
Steve French | ffdd6e4 | 2007-06-24 21:15:44 +0000 | [diff] [blame] | 93 | struct mid_q_entry *mid_entry; |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 94 | |
Steve French | 221601c | 2007-06-05 20:35:06 +0000 | [diff] [blame] | 95 | if (server == NULL) |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 96 | return; |
| 97 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 98 | cifs_dbg(VFS, "Dump pending requests:\n"); |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 99 | 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 Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 102 | 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 French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 108 | #ifdef CONFIG_CIFS_STATS2 |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 109 | 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 French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 114 | #endif /* STATS2 */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 115 | cifs_dbg(VFS, "IsMult: %d IsEnd: %d\n", |
| 116 | mid_entry->multiRsp, mid_entry->multiEnd); |
Steve French | ad8b15f | 2008-08-08 21:10:16 +0000 | [diff] [blame] | 117 | 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 French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 121 | } |
| 122 | } |
| 123 | spin_unlock(&GlobalMid_Lock); |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 124 | #endif /* CONFIG_CIFS_DEBUG2 */ |
Pavel Shilovsky | 8aa26f3 | 2012-05-17 13:25:35 +0400 | [diff] [blame] | 125 | } |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | #ifdef CONFIG_PROC_FS |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 128 | static int cifs_debug_data_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | { |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 130 | struct list_head *tmp1, *tmp2, *tmp3; |
Steve French | ffdd6e4 | 2007-06-24 21:15:44 +0000 | [diff] [blame] | 131 | struct mid_q_entry *mid_entry; |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 132 | struct TCP_Server_Info *server; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 133 | struct cifs_ses *ses; |
| 134 | struct cifs_tcon *tcon; |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 135 | int i, j; |
| 136 | __u32 dev_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 138 | seq_puts(m, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | "Display Internal CIFS Data Structures for Debugging\n" |
| 140 | "---------------------------------------------------\n"); |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 141 | seq_printf(m, "CIFS Version %s\n", CIFS_VERSION); |
Jeff Layton | ca40b71 | 2011-01-07 11:30:29 -0500 | [diff] [blame] | 142 | seq_printf(m, "Features:"); |
Suresh Jayaraman | f579903 | 2010-07-30 18:25:56 +0530 | [diff] [blame] | 143 | #ifdef CONFIG_CIFS_DFS_UPCALL |
Jeff Layton | ca40b71 | 2011-01-07 11:30:29 -0500 | [diff] [blame] | 144 | seq_printf(m, " dfs"); |
Suresh Jayaraman | f579903 | 2010-07-30 18:25:56 +0530 | [diff] [blame] | 145 | #endif |
| 146 | #ifdef CONFIG_CIFS_FSCACHE |
Jeff Layton | ca40b71 | 2011-01-07 11:30:29 -0500 | [diff] [blame] | 147 | seq_printf(m, " fscache"); |
Suresh Jayaraman | f579903 | 2010-07-30 18:25:56 +0530 | [diff] [blame] | 148 | #endif |
| 149 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Jeff Layton | ca40b71 | 2011-01-07 11:30:29 -0500 | [diff] [blame] | 150 | seq_printf(m, " lanman"); |
Suresh Jayaraman | f579903 | 2010-07-30 18:25:56 +0530 | [diff] [blame] | 151 | #endif |
| 152 | #ifdef CONFIG_CIFS_POSIX |
Jeff Layton | ca40b71 | 2011-01-07 11:30:29 -0500 | [diff] [blame] | 153 | seq_printf(m, " posix"); |
Suresh Jayaraman | f579903 | 2010-07-30 18:25:56 +0530 | [diff] [blame] | 154 | #endif |
| 155 | #ifdef CONFIG_CIFS_UPCALL |
Jeff Layton | ca40b71 | 2011-01-07 11:30:29 -0500 | [diff] [blame] | 156 | seq_printf(m, " spnego"); |
Suresh Jayaraman | f579903 | 2010-07-30 18:25:56 +0530 | [diff] [blame] | 157 | #endif |
| 158 | #ifdef CONFIG_CIFS_XATTR |
Jeff Layton | ca40b71 | 2011-01-07 11:30:29 -0500 | [diff] [blame] | 159 | seq_printf(m, " xattr"); |
| 160 | #endif |
| 161 | #ifdef CONFIG_CIFS_ACL |
| 162 | seq_printf(m, " acl"); |
Suresh Jayaraman | f579903 | 2010-07-30 18:25:56 +0530 | [diff] [blame] | 163 | #endif |
| 164 | seq_putc(m, '\n'); |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 165 | seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid); |
| 166 | seq_printf(m, "Servers:"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
| 168 | i = 0; |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 169 | spin_lock(&cifs_tcp_ses_lock); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 170 | list_for_each(tmp1, &cifs_tcp_ses_list) { |
| 171 | server = list_entry(tmp1, struct TCP_Server_Info, |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 172 | tcp_ses_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | i++; |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 174 | list_for_each(tmp2, &server->smb_ses_list) { |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 175 | ses = list_entry(tmp2, struct cifs_ses, |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 176 | smb_ses_list); |
| 177 | if ((ses->serverDomain == NULL) || |
| 178 | (ses->serverOS == NULL) || |
| 179 | (ses->serverNOS == NULL)) { |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 180 | seq_printf(m, "\n%d) entry for %s not fully " |
| 181 | "displayed\n\t", i, ses->serverName); |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 182 | } else { |
| 183 | seq_printf(m, |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 184 | "\n%d) Name: %s Domain: %s Uses: %d OS:" |
| 185 | " %s\n\tNOS: %s\tCapability: 0x%x\n\tSMB" |
Steve French | 221601c | 2007-06-05 20:35:06 +0000 | [diff] [blame] | 186 | " session status: %d\t", |
Steve French | b8643e1 | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 187 | i, ses->serverName, ses->serverDomain, |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 188 | ses->ses_count, ses->serverOS, ses->serverNOS, |
Steve French | 221601c | 2007-06-05 20:35:06 +0000 | [diff] [blame] | 189 | ses->capabilities, ses->status); |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 190 | } |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 191 | seq_printf(m, "TCP status: %d\n\tLocal Users To " |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 192 | "Server: %d SecMode: 0x%x Req On Wire: %d", |
| 193 | server->tcpStatus, server->srv_count, |
Pavel Shilovsky | fc40f9c | 2012-02-17 17:09:12 +0300 | [diff] [blame] | 194 | server->sec_mode, in_flight(server)); |
Steve French | 131afd0b | 2005-10-07 09:51:05 -0700 | [diff] [blame] | 195 | |
| 196 | #ifdef CONFIG_CIFS_STATS2 |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 197 | seq_printf(m, " In Send: %d In MaxReq Wait: %d", |
Steve French | 789e666 | 2011-08-09 18:44:44 +0000 | [diff] [blame] | 198 | atomic_read(&server->in_send), |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 199 | atomic_read(&server->num_waiters)); |
Steve French | 131afd0b | 2005-10-07 09:51:05 -0700 | [diff] [blame] | 200 | #endif |
| 201 | |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 202 | seq_puts(m, "\n\tShares:"); |
| 203 | j = 0; |
| 204 | list_for_each(tmp3, &ses->tcon_list) { |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 205 | tcon = list_entry(tmp3, struct cifs_tcon, |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 206 | 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 French | 59b04c5 | 2014-08-02 21:16:48 -0500 | [diff] [blame] | 216 | "\n\tPathComponentMax: %d Status: %d", |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 217 | 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 French | 769ee6a | 2013-06-19 14:15:30 -0500 | [diff] [blame] | 227 | if (server->ops->dump_share_caps) |
| 228 | server->ops->dump_share_caps(m, tcon); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 229 | |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
| 237 | spin_lock(&GlobalMid_Lock); |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 238 | list_for_each(tmp3, &server->pending_mid_q) { |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 239 | mid_entry = list_entry(tmp3, struct mid_q_entry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | qhead); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 241 | seq_printf(m, "\tState: %d com: %d pid:" |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 242 | " %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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | } |
Steve French | 221601c | 2007-06-05 20:35:06 +0000 | [diff] [blame] | 249 | spin_unlock(&GlobalMid_Lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | } |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 252 | spin_unlock(&cifs_tcp_ses_lock); |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 253 | seq_putc(m, '\n'); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | /* BB add code to dump additional info such as TCP session info now */ |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 256 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 259 | static 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 French | 1047abc | 2005-10-11 19:58:06 -0700 | [diff] [blame] | 263 | |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 264 | static 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 |
| 273 | static ssize_t cifs_stats_proc_write(struct file *file, |
| 274 | const char __user *buffer, size_t count, loff_t *ppos) |
Steve French | 1047abc | 2005-10-11 19:58:06 -0700 | [diff] [blame] | 275 | { |
Steve French | 221601c | 2007-06-05 20:35:06 +0000 | [diff] [blame] | 276 | char c; |
| 277 | int rc; |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 278 | struct list_head *tmp1, *tmp2, *tmp3; |
| 279 | struct TCP_Server_Info *server; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 280 | struct cifs_ses *ses; |
| 281 | struct cifs_tcon *tcon; |
Steve French | 1047abc | 2005-10-11 19:58:06 -0700 | [diff] [blame] | 282 | |
Steve French | 221601c | 2007-06-05 20:35:06 +0000 | [diff] [blame] | 283 | rc = get_user(c, buffer); |
| 284 | if (rc) |
| 285 | return rc; |
Steve French | 1047abc | 2005-10-11 19:58:06 -0700 | [diff] [blame] | 286 | |
Steve French | 221601c | 2007-06-05 20:35:06 +0000 | [diff] [blame] | 287 | if (c == '1' || c == 'y' || c == 'Y' || c == '0') { |
Steve French | 4498eed5 | 2005-12-03 13:58:57 -0800 | [diff] [blame] | 288 | #ifdef CONFIG_CIFS_STATS2 |
| 289 | atomic_set(&totBufAllocCount, 0); |
| 290 | atomic_set(&totSmBufAllocCount, 0); |
| 291 | #endif /* CONFIG_CIFS_STATS2 */ |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 292 | spin_lock(&cifs_tcp_ses_lock); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 293 | list_for_each(tmp1, &cifs_tcp_ses_list) { |
| 294 | server = list_entry(tmp1, struct TCP_Server_Info, |
| 295 | tcp_ses_list); |
Steve French | c2b3382 | 2008-11-17 03:57:13 +0000 | [diff] [blame] | 296 | list_for_each(tmp2, &server->smb_ses_list) { |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 297 | ses = list_entry(tmp2, struct cifs_ses, |
Steve French | c2b3382 | 2008-11-17 03:57:13 +0000 | [diff] [blame] | 298 | smb_ses_list); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 299 | list_for_each(tmp3, &ses->tcon_list) { |
| 300 | tcon = list_entry(tmp3, |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 301 | struct cifs_tcon, |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 302 | tcon_list); |
| 303 | atomic_set(&tcon->num_smbs_sent, 0); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 304 | if (server->ops->clear_stats) |
| 305 | server->ops->clear_stats(tcon); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 306 | } |
| 307 | } |
Steve French | 1047abc | 2005-10-11 19:58:06 -0700 | [diff] [blame] | 308 | } |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 309 | spin_unlock(&cifs_tcp_ses_lock); |
Steve French | 1047abc | 2005-10-11 19:58:06 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Steve French | 221601c | 2007-06-05 20:35:06 +0000 | [diff] [blame] | 312 | return count; |
Steve French | 1047abc | 2005-10-11 19:58:06 -0700 | [diff] [blame] | 313 | } |
| 314 | |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 315 | static int cifs_stats_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | { |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 317 | int i; |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 318 | struct list_head *tmp1, *tmp2, *tmp3; |
| 319 | struct TCP_Server_Info *server; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 320 | struct cifs_ses *ses; |
| 321 | struct cifs_tcon *tcon; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 323 | seq_printf(m, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | "Resources in use\nCIFS Session: %d\n", |
| 325 | sesInfoAllocCount.counter); |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 326 | seq_printf(m, "Share (unique mount targets): %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | tconInfoAllocCount.counter); |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 328 | seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n", |
Steve French | b8643e1 | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 329 | bufAllocCount.counter, |
| 330 | cifs_min_rcv + tcpSesAllocCount.counter); |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 331 | seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n", |
Steve French | 221601c | 2007-06-05 20:35:06 +0000 | [diff] [blame] | 332 | smBufAllocCount.counter, cifs_min_small); |
Steve French | 07475ff | 2005-12-03 14:11:37 -0800 | [diff] [blame] | 333 | #ifdef CONFIG_CIFS_STATS2 |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 334 | seq_printf(m, "Total Large %d Small %d Allocations\n", |
Steve French | 07475ff | 2005-12-03 14:11:37 -0800 | [diff] [blame] | 335 | atomic_read(&totBufAllocCount), |
Steve French | 221601c | 2007-06-05 20:35:06 +0000 | [diff] [blame] | 336 | atomic_read(&totSmBufAllocCount)); |
Steve French | 07475ff | 2005-12-03 14:11:37 -0800 | [diff] [blame] | 337 | #endif /* CONFIG_CIFS_STATS2 */ |
| 338 | |
Jeff Layton | 8097531 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 339 | seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount)); |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 340 | seq_printf(m, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | "\n%d session %d share reconnects\n", |
Steve French | 221601c | 2007-06-05 20:35:06 +0000 | [diff] [blame] | 342 | tcpSesReconnectCount.counter, tconInfoReconnectCount.counter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 344 | seq_printf(m, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | "Total vfs operations: %d maximum at one time: %d\n", |
Steve French | 221601c | 2007-06-05 20:35:06 +0000 | [diff] [blame] | 346 | GlobalCurrentXid, GlobalMaxActiveXid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | |
| 348 | i = 0; |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 349 | spin_lock(&cifs_tcp_ses_lock); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 350 | list_for_each(tmp1, &cifs_tcp_ses_list) { |
| 351 | server = list_entry(tmp1, struct TCP_Server_Info, |
| 352 | tcp_ses_list); |
| 353 | list_for_each(tmp2, &server->smb_ses_list) { |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 354 | ses = list_entry(tmp2, struct cifs_ses, |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 355 | smb_ses_list); |
| 356 | list_for_each(tmp3, &ses->tcon_list) { |
| 357 | tcon = list_entry(tmp3, |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 358 | struct cifs_tcon, |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 359 | tcon_list); |
| 360 | i++; |
| 361 | seq_printf(m, "\n%d) %s", i, tcon->treeName); |
| 362 | if (tcon->need_reconnect) |
| 363 | seq_puts(m, "\tDISCONNECTED "); |
Pavel Shilovsky | 44c5818 | 2012-05-28 14:16:31 +0400 | [diff] [blame] | 364 | seq_printf(m, "\nSMBs: %d", |
| 365 | atomic_read(&tcon->num_smbs_sent)); |
| 366 | if (server->ops->print_stats) |
| 367 | server->ops->print_stats(m, tcon); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 368 | } |
| 369 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | } |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 371 | spin_unlock(&cifs_tcp_ses_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 373 | seq_putc(m, '\n'); |
| 374 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | } |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 376 | |
| 377 | static int cifs_stats_proc_open(struct inode *inode, struct file *file) |
| 378 | { |
| 379 | return single_open(file, cifs_stats_proc_show, NULL); |
| 380 | } |
| 381 | |
| 382 | static const struct file_operations cifs_stats_proc_fops = { |
| 383 | .owner = THIS_MODULE, |
| 384 | .open = cifs_stats_proc_open, |
| 385 | .read = seq_read, |
| 386 | .llseek = seq_lseek, |
| 387 | .release = single_release, |
| 388 | .write = cifs_stats_proc_write, |
| 389 | }; |
Steve French | 90c81e0 | 2008-02-12 20:32:36 +0000 | [diff] [blame] | 390 | #endif /* STATS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | |
| 392 | static struct proc_dir_entry *proc_fs_cifs; |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 393 | static const struct file_operations cifsFYI_proc_fops; |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 394 | static const struct file_operations cifs_lookup_cache_proc_fops; |
| 395 | static const struct file_operations traceSMB_proc_fops; |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 396 | static const struct file_operations cifs_security_flags_proc_fops; |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 397 | static const struct file_operations cifs_linux_ext_proc_fops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | |
| 399 | void |
| 400 | cifs_proc_init(void) |
| 401 | { |
Alexey Dobriyan | 36a5aeb | 2008-04-29 01:01:42 -0700 | [diff] [blame] | 402 | proc_fs_cifs = proc_mkdir("fs/cifs", NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | if (proc_fs_cifs == NULL) |
| 404 | return; |
| 405 | |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 406 | proc_create("DebugData", 0, proc_fs_cifs, &cifs_debug_data_proc_fops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | |
| 408 | #ifdef CONFIG_CIFS_STATS |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 409 | proc_create("Stats", 0, proc_fs_cifs, &cifs_stats_proc_fops); |
Steve French | 90c81e0 | 2008-02-12 20:32:36 +0000 | [diff] [blame] | 410 | #endif /* STATS */ |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 411 | proc_create("cifsFYI", 0, proc_fs_cifs, &cifsFYI_proc_fops); |
| 412 | proc_create("traceSMB", 0, proc_fs_cifs, &traceSMB_proc_fops); |
Steve French | 99b1f5b | 2008-07-24 02:37:45 +0000 | [diff] [blame] | 413 | proc_create("LinuxExtensionsEnabled", 0, proc_fs_cifs, |
| 414 | &cifs_linux_ext_proc_fops); |
Steve French | 99b1f5b | 2008-07-24 02:37:45 +0000 | [diff] [blame] | 415 | proc_create("SecurityFlags", 0, proc_fs_cifs, |
| 416 | &cifs_security_flags_proc_fops); |
| 417 | proc_create("LookupCacheEnabled", 0, proc_fs_cifs, |
| 418 | &cifs_lookup_cache_proc_fops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | void |
| 422 | cifs_proc_clean(void) |
| 423 | { |
| 424 | if (proc_fs_cifs == NULL) |
| 425 | return; |
| 426 | |
| 427 | remove_proc_entry("DebugData", proc_fs_cifs); |
| 428 | remove_proc_entry("cifsFYI", proc_fs_cifs); |
| 429 | remove_proc_entry("traceSMB", proc_fs_cifs); |
| 430 | #ifdef CONFIG_CIFS_STATS |
| 431 | remove_proc_entry("Stats", proc_fs_cifs); |
| 432 | #endif |
Steve French | 221601c | 2007-06-05 20:35:06 +0000 | [diff] [blame] | 433 | remove_proc_entry("SecurityFlags", proc_fs_cifs); |
Steve French | 221601c | 2007-06-05 20:35:06 +0000 | [diff] [blame] | 434 | remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs); |
Steve French | 221601c | 2007-06-05 20:35:06 +0000 | [diff] [blame] | 435 | remove_proc_entry("LookupCacheEnabled", proc_fs_cifs); |
Alexey Dobriyan | 36a5aeb | 2008-04-29 01:01:42 -0700 | [diff] [blame] | 436 | remove_proc_entry("fs/cifs", NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | } |
| 438 | |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 439 | static int cifsFYI_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | { |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 441 | seq_printf(m, "%d\n", cifsFYI); |
| 442 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | } |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 444 | |
| 445 | static int cifsFYI_proc_open(struct inode *inode, struct file *file) |
| 446 | { |
| 447 | return single_open(file, cifsFYI_proc_show, NULL); |
| 448 | } |
| 449 | |
| 450 | static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer, |
| 451 | size_t count, loff_t *ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | { |
| 453 | char c; |
| 454 | int rc; |
| 455 | |
| 456 | rc = get_user(c, buffer); |
| 457 | if (rc) |
| 458 | return rc; |
| 459 | if (c == '0' || c == 'n' || c == 'N') |
| 460 | cifsFYI = 0; |
| 461 | else if (c == '1' || c == 'y' || c == 'Y') |
| 462 | cifsFYI = 1; |
Steve French | 221601c | 2007-06-05 20:35:06 +0000 | [diff] [blame] | 463 | else if ((c > '1') && (c <= '9')) |
Steve French | 1047abc | 2005-10-11 19:58:06 -0700 | [diff] [blame] | 464 | cifsFYI = (int) (c - '0'); /* see cifs_debug.h for meanings */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | |
| 466 | return count; |
| 467 | } |
| 468 | |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 469 | static 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 Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 478 | static int cifs_linux_ext_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | { |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 480 | seq_printf(m, "%d\n", linuxExtEnabled); |
| 481 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | } |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 483 | |
| 484 | static 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 | |
| 489 | static ssize_t cifs_linux_ext_proc_write(struct file *file, |
| 490 | const char __user *buffer, size_t count, loff_t *ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | { |
Steve French | 221601c | 2007-06-05 20:35:06 +0000 | [diff] [blame] | 492 | char c; |
| 493 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | |
Steve French | 221601c | 2007-06-05 20:35:06 +0000 | [diff] [blame] | 495 | rc = get_user(c, buffer); |
| 496 | if (rc) |
| 497 | return rc; |
| 498 | if (c == '0' || c == 'n' || c == 'N') |
| 499 | linuxExtEnabled = 0; |
| 500 | else if (c == '1' || c == 'y' || c == 'Y') |
| 501 | linuxExtEnabled = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | |
Steve French | 221601c | 2007-06-05 20:35:06 +0000 | [diff] [blame] | 503 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | } |
| 505 | |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 506 | static const struct file_operations cifs_linux_ext_proc_fops = { |
| 507 | .owner = THIS_MODULE, |
| 508 | .open = cifs_linux_ext_proc_open, |
| 509 | .read = seq_read, |
| 510 | .llseek = seq_lseek, |
| 511 | .release = single_release, |
| 512 | .write = cifs_linux_ext_proc_write, |
| 513 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 515 | static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | { |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 517 | seq_printf(m, "%d\n", lookupCacheEnabled); |
| 518 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | } |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 520 | |
| 521 | static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file) |
| 522 | { |
| 523 | return single_open(file, cifs_lookup_cache_proc_show, NULL); |
| 524 | } |
| 525 | |
| 526 | static ssize_t cifs_lookup_cache_proc_write(struct file *file, |
| 527 | const char __user *buffer, size_t count, loff_t *ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | { |
| 529 | char c; |
| 530 | int rc; |
| 531 | |
| 532 | rc = get_user(c, buffer); |
| 533 | if (rc) |
| 534 | return rc; |
| 535 | if (c == '0' || c == 'n' || c == 'N') |
| 536 | lookupCacheEnabled = 0; |
| 537 | else if (c == '1' || c == 'y' || c == 'Y') |
| 538 | lookupCacheEnabled = 1; |
| 539 | |
| 540 | return count; |
| 541 | } |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 542 | |
| 543 | static const struct file_operations cifs_lookup_cache_proc_fops = { |
| 544 | .owner = THIS_MODULE, |
| 545 | .open = cifs_lookup_cache_proc_open, |
| 546 | .read = seq_read, |
| 547 | .llseek = seq_lseek, |
| 548 | .release = single_release, |
| 549 | .write = cifs_lookup_cache_proc_write, |
| 550 | }; |
| 551 | |
| 552 | static int traceSMB_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | { |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 554 | seq_printf(m, "%d\n", traceSMB); |
| 555 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | } |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 557 | |
| 558 | static int traceSMB_proc_open(struct inode *inode, struct file *file) |
| 559 | { |
| 560 | return single_open(file, traceSMB_proc_show, NULL); |
| 561 | } |
| 562 | |
| 563 | static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer, |
| 564 | size_t count, loff_t *ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | { |
| 566 | char c; |
| 567 | int rc; |
| 568 | |
| 569 | rc = get_user(c, buffer); |
| 570 | if (rc) |
| 571 | return rc; |
| 572 | if (c == '0' || c == 'n' || c == 'N') |
| 573 | traceSMB = 0; |
| 574 | else if (c == '1' || c == 'y' || c == 'Y') |
| 575 | traceSMB = 1; |
| 576 | |
| 577 | return count; |
| 578 | } |
| 579 | |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 580 | static const struct file_operations traceSMB_proc_fops = { |
| 581 | .owner = THIS_MODULE, |
| 582 | .open = traceSMB_proc_open, |
| 583 | .read = seq_read, |
| 584 | .llseek = seq_lseek, |
| 585 | .release = single_release, |
| 586 | .write = traceSMB_proc_write, |
| 587 | }; |
| 588 | |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 589 | static int cifs_security_flags_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | { |
Jeff Layton | 04912d6 | 2010-04-24 07:57:45 -0400 | [diff] [blame] | 591 | seq_printf(m, "0x%x\n", global_secflags); |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 592 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | } |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 594 | |
| 595 | static int cifs_security_flags_proc_open(struct inode *inode, struct file *file) |
| 596 | { |
| 597 | return single_open(file, cifs_security_flags_proc_show, NULL); |
| 598 | } |
| 599 | |
Jeff Layton | 52dfb44 | 2013-05-26 07:01:02 -0400 | [diff] [blame] | 600 | /* |
| 601 | * Ensure that if someone sets a MUST flag, that we disable all other MAY |
| 602 | * flags except for the ones corresponding to the given MUST flag. If there are |
| 603 | * multiple MUST flags, then try to prefer more secure ones. |
| 604 | */ |
| 605 | static void |
| 606 | cifs_security_flags_handle_must_flags(unsigned int *flags) |
| 607 | { |
| 608 | unsigned int signflags = *flags & CIFSSEC_MUST_SIGN; |
| 609 | |
| 610 | if ((*flags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5) |
| 611 | *flags = CIFSSEC_MUST_KRB5; |
| 612 | else if ((*flags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP) |
| 613 | *flags = CIFSSEC_MUST_NTLMSSP; |
| 614 | else if ((*flags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2) |
| 615 | *flags = CIFSSEC_MUST_NTLMV2; |
| 616 | else if ((*flags & CIFSSEC_MUST_NTLM) == CIFSSEC_MUST_NTLM) |
| 617 | *flags = CIFSSEC_MUST_NTLM; |
| 618 | else if ((*flags & CIFSSEC_MUST_LANMAN) == CIFSSEC_MUST_LANMAN) |
| 619 | *flags = CIFSSEC_MUST_LANMAN; |
| 620 | else if ((*flags & CIFSSEC_MUST_PLNTXT) == CIFSSEC_MUST_PLNTXT) |
| 621 | *flags = CIFSSEC_MUST_PLNTXT; |
| 622 | |
| 623 | *flags |= signflags; |
| 624 | } |
| 625 | |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 626 | static ssize_t cifs_security_flags_proc_write(struct file *file, |
| 627 | const char __user *buffer, size_t count, loff_t *ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | { |
Jeff Layton | 7715dad | 2013-05-26 07:01:01 -0400 | [diff] [blame] | 629 | int rc; |
Steve French | bdc4bf6e | 2006-06-02 22:57:13 +0000 | [diff] [blame] | 630 | unsigned int flags; |
| 631 | char flags_string[12]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | char c; |
Steve French | bdc4bf6e | 2006-06-02 22:57:13 +0000 | [diff] [blame] | 633 | |
Steve French | 221601c | 2007-06-05 20:35:06 +0000 | [diff] [blame] | 634 | if ((count < 1) || (count > 11)) |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 635 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | |
Steve French | bdc4bf6e | 2006-06-02 22:57:13 +0000 | [diff] [blame] | 637 | memset(flags_string, 0, 12); |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 638 | |
Steve French | 221601c | 2007-06-05 20:35:06 +0000 | [diff] [blame] | 639 | if (copy_from_user(flags_string, buffer, count)) |
Steve French | bdc4bf6e | 2006-06-02 22:57:13 +0000 | [diff] [blame] | 640 | return -EFAULT; |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 641 | |
Steve French | 221601c | 2007-06-05 20:35:06 +0000 | [diff] [blame] | 642 | if (count < 3) { |
Steve French | bdc4bf6e | 2006-06-02 22:57:13 +0000 | [diff] [blame] | 643 | /* single char or single char followed by null */ |
| 644 | c = flags_string[0]; |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 645 | if (c == '0' || c == 'n' || c == 'N') { |
Jeff Layton | 04912d6 | 2010-04-24 07:57:45 -0400 | [diff] [blame] | 646 | global_secflags = CIFSSEC_DEF; /* default */ |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 647 | return count; |
| 648 | } else if (c == '1' || c == 'y' || c == 'Y') { |
Jeff Layton | 04912d6 | 2010-04-24 07:57:45 -0400 | [diff] [blame] | 649 | global_secflags = CIFSSEC_MAX; |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 650 | return count; |
| 651 | } else if (!isdigit(c)) { |
Jeff Layton | 7715dad | 2013-05-26 07:01:01 -0400 | [diff] [blame] | 652 | cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", |
| 653 | flags_string); |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 654 | return -EINVAL; |
| 655 | } |
Steve French | bdc4bf6e | 2006-06-02 22:57:13 +0000 | [diff] [blame] | 656 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | |
Jeff Layton | 7715dad | 2013-05-26 07:01:01 -0400 | [diff] [blame] | 658 | /* else we have a number */ |
| 659 | rc = kstrtouint(flags_string, 0, &flags); |
| 660 | if (rc) { |
| 661 | cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", |
| 662 | flags_string); |
| 663 | return rc; |
| 664 | } |
Steve French | bdc4bf6e | 2006-06-02 22:57:13 +0000 | [diff] [blame] | 665 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 666 | cifs_dbg(FYI, "sec flags 0x%x\n", flags); |
Steve French | bdc4bf6e | 2006-06-02 22:57:13 +0000 | [diff] [blame] | 667 | |
Jeff Layton | 7715dad | 2013-05-26 07:01:01 -0400 | [diff] [blame] | 668 | if (flags == 0) { |
| 669 | cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", flags_string); |
Steve French | bdc4bf6e | 2006-06-02 22:57:13 +0000 | [diff] [blame] | 670 | return -EINVAL; |
| 671 | } |
| 672 | |
Steve French | 221601c | 2007-06-05 20:35:06 +0000 | [diff] [blame] | 673 | if (flags & ~CIFSSEC_MASK) { |
Jeff Layton | 7715dad | 2013-05-26 07:01:01 -0400 | [diff] [blame] | 674 | cifs_dbg(VFS, "Unsupported security flags: 0x%x\n", |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 675 | flags & ~CIFSSEC_MASK); |
Steve French | bdc4bf6e | 2006-06-02 22:57:13 +0000 | [diff] [blame] | 676 | return -EINVAL; |
| 677 | } |
Jeff Layton | 7715dad | 2013-05-26 07:01:01 -0400 | [diff] [blame] | 678 | |
Jeff Layton | 52dfb44 | 2013-05-26 07:01:02 -0400 | [diff] [blame] | 679 | cifs_security_flags_handle_must_flags(&flags); |
| 680 | |
Steve French | bdc4bf6e | 2006-06-02 22:57:13 +0000 | [diff] [blame] | 681 | /* flags look ok - update the global security flags for cifs module */ |
Jeff Layton | 04912d6 | 2010-04-24 07:57:45 -0400 | [diff] [blame] | 682 | global_secflags = flags; |
| 683 | if (global_secflags & CIFSSEC_MUST_SIGN) { |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 684 | /* requiring signing implies signing is allowed */ |
Jeff Layton | 04912d6 | 2010-04-24 07:57:45 -0400 | [diff] [blame] | 685 | global_secflags |= CIFSSEC_MAY_SIGN; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 686 | cifs_dbg(FYI, "packet signing now required\n"); |
Jeff Layton | 04912d6 | 2010-04-24 07:57:45 -0400 | [diff] [blame] | 687 | } else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 688 | cifs_dbg(FYI, "packet signing disabled\n"); |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 689 | } |
| 690 | /* BB should we turn on MAY flags for other MUST options? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | return count; |
| 692 | } |
Alexey Dobriyan | f984c7b | 2008-07-24 02:34:24 +0000 | [diff] [blame] | 693 | |
| 694 | static const struct file_operations cifs_security_flags_proc_fops = { |
| 695 | .owner = THIS_MODULE, |
| 696 | .open = cifs_security_flags_proc_open, |
| 697 | .read = seq_read, |
| 698 | .llseek = seq_lseek, |
| 699 | .release = single_release, |
| 700 | .write = cifs_security_flags_proc_write, |
| 701 | }; |
Steve French | 90c81e0 | 2008-02-12 20:32:36 +0000 | [diff] [blame] | 702 | #else |
Steve French | e086fce | 2008-02-18 04:03:58 +0000 | [diff] [blame] | 703 | inline void cifs_proc_init(void) |
Steve French | 90c81e0 | 2008-02-12 20:32:36 +0000 | [diff] [blame] | 704 | { |
| 705 | } |
| 706 | |
Steve French | e086fce | 2008-02-18 04:03:58 +0000 | [diff] [blame] | 707 | inline void cifs_proc_clean(void) |
Steve French | 90c81e0 | 2008-02-12 20:32:36 +0000 | [diff] [blame] | 708 | { |
| 709 | } |
| 710 | #endif /* PROC_FS */ |