Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/cifs/cifsfs.c |
| 3 | * |
Steve French | 35c11fd | 2007-02-27 05:09:35 +0000 | [diff] [blame] | 4 | * Copyright (C) International Business Machines Corp., 2002,2007 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Author(s): Steve French (sfrench@us.ibm.com) |
| 6 | * |
| 7 | * Common Internet FileSystem (CIFS) client |
| 8 | * |
| 9 | * This library is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU Lesser General Public License as published |
| 11 | * by the Free Software Foundation; either version 2.1 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This library is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 17 | * the GNU Lesser General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU Lesser General Public License |
| 20 | * along with this library; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | /* Note that BB means BUGBUG (ie something to fix eventually) */ |
| 25 | |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/fs.h> |
| 28 | #include <linux/mount.h> |
| 29 | #include <linux/slab.h> |
| 30 | #include <linux/init.h> |
| 31 | #include <linux/list.h> |
| 32 | #include <linux/seq_file.h> |
| 33 | #include <linux/vfs.h> |
| 34 | #include <linux/mempool.h> |
Steve French | 6ab16d2 | 2005-11-29 20:55:11 -0800 | [diff] [blame] | 35 | #include <linux/delay.h> |
Steve French | 45af7a0 | 2006-04-21 22:52:25 +0000 | [diff] [blame] | 36 | #include <linux/kthread.h> |
Nigel Cunningham | 7dfb710 | 2006-12-06 20:34:23 -0800 | [diff] [blame] | 37 | #include <linux/freezer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include "cifsfs.h" |
| 39 | #include "cifspdu.h" |
| 40 | #define DECLARE_GLOBALS_HERE |
| 41 | #include "cifsglob.h" |
| 42 | #include "cifsproto.h" |
| 43 | #include "cifs_debug.h" |
| 44 | #include "cifs_fs_sb.h" |
| 45 | #include <linux/mm.h> |
Jeff Layton | 84a15b9 | 2007-11-03 05:02:24 +0000 | [diff] [blame] | 46 | #include <linux/key-type.h> |
Jeff Layton | e545937 | 2007-11-03 05:11:06 +0000 | [diff] [blame^] | 47 | #include "cifs_spnego.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #define CIFS_MAGIC_NUMBER 0xFF534D42 /* the first four bytes of SMB PDUs */ |
| 49 | |
| 50 | #ifdef CONFIG_CIFS_QUOTA |
| 51 | static struct quotactl_ops cifs_quotactl_ops; |
Steve French | 35c11fd | 2007-02-27 05:09:35 +0000 | [diff] [blame] | 52 | #endif /* QUOTA */ |
| 53 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | int cifsFYI = 0; |
| 55 | int cifsERROR = 1; |
| 56 | int traceSMB = 0; |
| 57 | unsigned int oplockEnabled = 1; |
| 58 | unsigned int experimEnabled = 0; |
| 59 | unsigned int linuxExtEnabled = 1; |
| 60 | unsigned int lookupCacheEnabled = 1; |
| 61 | unsigned int multiuser_mount = 0; |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 62 | unsigned int extended_security = CIFSSEC_DEF; |
| 63 | /* unsigned int ntlmv2_support = 0; */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | unsigned int sign_CIFS_PDUs = 1; |
Steve French | 6dc0f87 | 2007-07-06 23:13:06 +0000 | [diff] [blame] | 65 | extern struct task_struct *oplockThread; /* remove sparse warning */ |
| 66 | struct task_struct *oplockThread = NULL; |
Steve French | 99ee4db | 2007-02-27 05:35:17 +0000 | [diff] [blame] | 67 | /* extern struct task_struct * dnotifyThread; remove sparse warning */ |
Steve French | 6dc0f87 | 2007-07-06 23:13:06 +0000 | [diff] [blame] | 68 | static struct task_struct *dnotifyThread = NULL; |
Josef 'Jeff' Sipek | ee9b6d6 | 2007-02-12 00:55:41 -0800 | [diff] [blame] | 69 | static const struct super_operations cifs_super_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | unsigned int CIFSMaxBufSize = CIFS_MAX_MSGSIZE; |
| 71 | module_param(CIFSMaxBufSize, int, 0); |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame] | 72 | MODULE_PARM_DESC(CIFSMaxBufSize, "Network buffer size (not including header). " |
| 73 | "Default: 16384 Range: 8192 to 130048"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | unsigned int cifs_min_rcv = CIFS_MIN_RCV_POOL; |
| 75 | module_param(cifs_min_rcv, int, 0); |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame] | 76 | MODULE_PARM_DESC(cifs_min_rcv, "Network buffers in pool. Default: 4 Range: " |
| 77 | "1 to 64"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | unsigned int cifs_min_small = 30; |
| 79 | module_param(cifs_min_small, int, 0); |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame] | 80 | MODULE_PARM_DESC(cifs_min_small, "Small network buffers in pool. Default: 30 " |
| 81 | "Range: 2 to 256"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | unsigned int cifs_max_pending = CIFS_MAX_REQ; |
| 83 | module_param(cifs_max_pending, int, 0); |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame] | 84 | MODULE_PARM_DESC(cifs_max_pending, "Simultaneous requests to server. " |
| 85 | "Default: 50 Range: 2 to 256"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | extern mempool_t *cifs_sm_req_poolp; |
| 88 | extern mempool_t *cifs_req_poolp; |
| 89 | extern mempool_t *cifs_mid_poolp; |
| 90 | |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 91 | extern struct kmem_cache *cifs_oplock_cachep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
| 93 | static int |
| 94 | cifs_read_super(struct super_block *sb, void *data, |
| 95 | const char *devname, int silent) |
| 96 | { |
| 97 | struct inode *inode; |
| 98 | struct cifs_sb_info *cifs_sb; |
| 99 | int rc = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 100 | |
Steve French | 1b2b212 | 2007-02-17 04:30:54 +0000 | [diff] [blame] | 101 | /* BB should we make this contingent on mount parm? */ |
| 102 | sb->s_flags |= MS_NODIRATIME | MS_NOATIME; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 103 | sb->s_fs_info = kzalloc(sizeof(struct cifs_sb_info), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | cifs_sb = CIFS_SB(sb); |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 105 | if (cifs_sb == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
| 108 | rc = cifs_mount(sb, cifs_sb, data, devname); |
| 109 | |
| 110 | if (rc) { |
| 111 | if (!silent) |
| 112 | cERROR(1, |
| 113 | ("cifs_mount failed w/return code = %d", rc)); |
| 114 | goto out_mount_failed; |
| 115 | } |
| 116 | |
| 117 | sb->s_magic = CIFS_MAGIC_NUMBER; |
| 118 | sb->s_op = &cifs_super_ops; |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 119 | /* if (cifs_sb->tcon->ses->server->maxBuf > MAX_CIFS_HDR_SIZE + 512) |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 120 | sb->s_blocksize = |
| 121 | cifs_sb->tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE; */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | #ifdef CONFIG_CIFS_QUOTA |
| 123 | sb->s_qcop = &cifs_quotactl_ops; |
| 124 | #endif |
| 125 | sb->s_blocksize = CIFS_MAX_MSGSIZE; |
| 126 | sb->s_blocksize_bits = 14; /* default 2**14 = CIFS_MAX_MSGSIZE */ |
| 127 | inode = iget(sb, ROOT_I); |
| 128 | |
| 129 | if (!inode) { |
| 130 | rc = -ENOMEM; |
| 131 | goto out_no_root; |
| 132 | } |
| 133 | |
| 134 | sb->s_root = d_alloc_root(inode); |
| 135 | |
| 136 | if (!sb->s_root) { |
| 137 | rc = -ENOMEM; |
| 138 | goto out_no_root; |
| 139 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 140 | |
Steve French | 7521a3c | 2007-07-11 18:30:34 +0000 | [diff] [blame] | 141 | #ifdef CONFIG_CIFS_EXPERIMENTAL |
| 142 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) { |
| 143 | cFYI(1, ("export ops supported")); |
| 144 | sb->s_export_op = &cifs_export_ops; |
| 145 | } |
| 146 | #endif /* EXPERIMENTAL */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
| 148 | return 0; |
| 149 | |
| 150 | out_no_root: |
| 151 | cERROR(1, ("cifs_read_super: get root inode failed")); |
| 152 | if (inode) |
| 153 | iput(inode); |
| 154 | |
| 155 | out_mount_failed: |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 156 | if (cifs_sb) { |
| 157 | if (cifs_sb->local_nls) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 158 | unload_nls(cifs_sb->local_nls); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | kfree(cifs_sb); |
| 160 | } |
| 161 | return rc; |
| 162 | } |
| 163 | |
| 164 | static void |
| 165 | cifs_put_super(struct super_block *sb) |
| 166 | { |
| 167 | int rc = 0; |
| 168 | struct cifs_sb_info *cifs_sb; |
| 169 | |
| 170 | cFYI(1, ("In cifs_put_super")); |
| 171 | cifs_sb = CIFS_SB(sb); |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 172 | if (cifs_sb == NULL) { |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 173 | cFYI(1, ("Empty cifs superblock info passed to unmount")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | return; |
| 175 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 176 | rc = cifs_umount(sb, cifs_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | if (rc) { |
| 178 | cERROR(1, ("cifs_umount failed with return code %d", rc)); |
| 179 | } |
| 180 | unload_nls(cifs_sb->local_nls); |
| 181 | kfree(cifs_sb); |
| 182 | return; |
| 183 | } |
| 184 | |
| 185 | static int |
David Howells | 726c334 | 2006-06-23 02:02:58 -0700 | [diff] [blame] | 186 | cifs_statfs(struct dentry *dentry, struct kstatfs *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | { |
David Howells | 726c334 | 2006-06-23 02:02:58 -0700 | [diff] [blame] | 188 | struct super_block *sb = dentry->d_sb; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 189 | int xid; |
Steve French | c81156d | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 190 | int rc = -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | struct cifs_sb_info *cifs_sb; |
| 192 | struct cifsTconInfo *pTcon; |
| 193 | |
| 194 | xid = GetXid(); |
| 195 | |
| 196 | cifs_sb = CIFS_SB(sb); |
| 197 | pTcon = cifs_sb->tcon; |
| 198 | |
| 199 | buf->f_type = CIFS_MAGIC_NUMBER; |
| 200 | |
| 201 | /* instead could get the real value via SMB_QUERY_FS_ATTRIBUTE_INFO */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 202 | buf->f_namelen = PATH_MAX; /* PATH_MAX may be too long - it would |
Steve French | c81156d | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 203 | presumably be total path, but note |
| 204 | that some servers (includinng Samba 3) |
| 205 | have a shorter maximum path */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | buf->f_files = 0; /* undefined */ |
| 207 | buf->f_ffree = 0; /* unlimited */ |
| 208 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | /* BB we could add a second check for a QFS Unix capability bit */ |
Steve French | f28ac91 | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 210 | /* BB FIXME check CIFS_POSIX_EXTENSIONS Unix cap first FIXME BB */ |
Steve French | c81156d | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 211 | if ((pTcon->ses->capabilities & CAP_UNIX) && (CIFS_POSIX_EXTENSIONS & |
| 212 | le64_to_cpu(pTcon->fsUnixInfo.Capability))) |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 213 | rc = CIFSSMBQFSPosixInfo(xid, pTcon, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
| 215 | /* Only need to call the old QFSInfo if failed |
| 216 | on newer one */ |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 217 | if (rc) |
| 218 | if (pTcon->ses->capabilities & CAP_NT_SMBS) |
Steve French | 9ac00b7 | 2006-09-30 04:13:17 +0000 | [diff] [blame] | 219 | rc = CIFSSMBQFSInfo(xid, pTcon, buf); /* not supported by OS2 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
Steve French | 9ac00b7 | 2006-09-30 04:13:17 +0000 | [diff] [blame] | 221 | /* Some old Windows servers also do not support level 103, retry with |
| 222 | older level one if old server failed the previous call or we |
| 223 | bypassed it because we detected that this was an older LANMAN sess */ |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 224 | if (rc) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 225 | rc = SMBOldQFSInfo(xid, pTcon, buf); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 226 | /* int f_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | __fsid_t f_fsid; |
| 228 | int f_namelen; */ |
Steve French | c81156d | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 229 | /* BB get from info in tcon struct at mount time call to QFSAttrInfo */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | FreeXid(xid); |
Steve French | c81156d | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 231 | return 0; /* always return success? what if volume is no |
| 232 | longer available? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | } |
| 234 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 235 | static int cifs_permission(struct inode *inode, int mask, struct nameidata *nd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | { |
| 237 | struct cifs_sb_info *cifs_sb; |
| 238 | |
| 239 | cifs_sb = CIFS_SB(inode->i_sb); |
| 240 | |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 241 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | return 0; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 243 | else /* file mode might have been restricted at mount time |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 244 | on the client (above and beyond ACL on servers) for |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | servers which do not support setting and viewing mode bits, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 246 | so allowing client to check permissions is useful */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | return generic_permission(inode, mask, NULL); |
| 248 | } |
| 249 | |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 250 | static struct kmem_cache *cifs_inode_cachep; |
| 251 | static struct kmem_cache *cifs_req_cachep; |
| 252 | static struct kmem_cache *cifs_mid_cachep; |
| 253 | struct kmem_cache *cifs_oplock_cachep; |
| 254 | static struct kmem_cache *cifs_sm_req_cachep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | mempool_t *cifs_sm_req_poolp; |
| 256 | mempool_t *cifs_req_poolp; |
| 257 | mempool_t *cifs_mid_poolp; |
| 258 | |
| 259 | static struct inode * |
| 260 | cifs_alloc_inode(struct super_block *sb) |
| 261 | { |
| 262 | struct cifsInodeInfo *cifs_inode; |
Christoph Lameter | e94b176 | 2006-12-06 20:33:17 -0800 | [diff] [blame] | 263 | cifs_inode = kmem_cache_alloc(cifs_inode_cachep, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | if (!cifs_inode) |
| 265 | return NULL; |
| 266 | cifs_inode->cifsAttrs = 0x20; /* default */ |
| 267 | atomic_set(&cifs_inode->inUse, 0); |
| 268 | cifs_inode->time = 0; |
| 269 | /* Until the file is open and we have gotten oplock |
| 270 | info back from the server, can not assume caching of |
| 271 | file data or metadata */ |
| 272 | cifs_inode->clientCanCacheRead = FALSE; |
| 273 | cifs_inode->clientCanCacheAll = FALSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | cifs_inode->vfs_inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 275 | |
Steve French | 1b2b212 | 2007-02-17 04:30:54 +0000 | [diff] [blame] | 276 | /* Can not set i_flags here - they get immediately overwritten |
| 277 | to zero by the VFS */ |
| 278 | /* cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME;*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | INIT_LIST_HEAD(&cifs_inode->openFileList); |
| 280 | return &cifs_inode->vfs_inode; |
| 281 | } |
| 282 | |
| 283 | static void |
| 284 | cifs_destroy_inode(struct inode *inode) |
| 285 | { |
| 286 | kmem_cache_free(cifs_inode_cachep, CIFS_I(inode)); |
| 287 | } |
| 288 | |
| 289 | /* |
| 290 | * cifs_show_options() is for displaying mount options in /proc/mounts. |
| 291 | * Not all settable options are displayed but most of the important |
| 292 | * ones are. |
| 293 | */ |
| 294 | static int |
| 295 | cifs_show_options(struct seq_file *s, struct vfsmount *m) |
| 296 | { |
| 297 | struct cifs_sb_info *cifs_sb; |
| 298 | |
| 299 | cifs_sb = CIFS_SB(m->mnt_sb); |
| 300 | |
| 301 | if (cifs_sb) { |
| 302 | if (cifs_sb->tcon) { |
Steve French | 004c46b | 2007-02-17 04:34:13 +0000 | [diff] [blame] | 303 | /* BB add prepath to mount options displayed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | seq_printf(s, ",unc=%s", cifs_sb->tcon->treeName); |
| 305 | if (cifs_sb->tcon->ses) { |
| 306 | if (cifs_sb->tcon->ses->userName) |
| 307 | seq_printf(s, ",username=%s", |
| 308 | cifs_sb->tcon->ses->userName); |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 309 | if (cifs_sb->tcon->ses->domainName) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | seq_printf(s, ",domain=%s", |
| 311 | cifs_sb->tcon->ses->domainName); |
| 312 | } |
Steve French | d5d1850 | 2007-10-17 21:31:52 +0000 | [diff] [blame] | 313 | if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID) || |
| 314 | !(cifs_sb->tcon->unix_ext)) |
| 315 | seq_printf(s, ",uid=%d", cifs_sb->mnt_uid); |
| 316 | if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID) || |
| 317 | !(cifs_sb->tcon->unix_ext)) |
| 318 | seq_printf(s, ",gid=%d", cifs_sb->mnt_gid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | } |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 320 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS) |
| 321 | seq_printf(s, ",posixpaths"); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 322 | seq_printf(s, ",rsize=%d", cifs_sb->rsize); |
| 323 | seq_printf(s, ",wsize=%d", cifs_sb->wsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | } |
| 325 | return 0; |
| 326 | } |
| 327 | |
| 328 | #ifdef CONFIG_CIFS_QUOTA |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 329 | int cifs_xquota_set(struct super_block *sb, int quota_type, qid_t qid, |
| 330 | struct fs_disk_quota *pdquota) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | { |
| 332 | int xid; |
| 333 | int rc = 0; |
| 334 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); |
| 335 | struct cifsTconInfo *pTcon; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 336 | |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 337 | if (cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | pTcon = cifs_sb->tcon; |
| 339 | else |
| 340 | return -EIO; |
| 341 | |
| 342 | |
| 343 | xid = GetXid(); |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 344 | if (pTcon) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 345 | cFYI(1, ("set type: 0x%x id: %d", quota_type, qid)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | } else { |
Cyrill Gorcunov | 95ba736 | 2007-08-24 00:23:36 +0000 | [diff] [blame] | 347 | rc = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | FreeXid(xid); |
| 351 | return rc; |
| 352 | } |
| 353 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 354 | int cifs_xquota_get(struct super_block *sb, int quota_type, qid_t qid, |
| 355 | struct fs_disk_quota *pdquota) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | { |
| 357 | int xid; |
| 358 | int rc = 0; |
| 359 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); |
| 360 | struct cifsTconInfo *pTcon; |
| 361 | |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 362 | if (cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | pTcon = cifs_sb->tcon; |
| 364 | else |
| 365 | return -EIO; |
| 366 | |
| 367 | xid = GetXid(); |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 368 | if (pTcon) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 369 | cFYI(1, ("set type: 0x%x id: %d", quota_type, qid)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | } else { |
| 371 | rc = -EIO; |
| 372 | } |
| 373 | |
| 374 | FreeXid(xid); |
| 375 | return rc; |
| 376 | } |
| 377 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 378 | int cifs_xstate_set(struct super_block *sb, unsigned int flags, int operation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 380 | int xid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | int rc = 0; |
| 382 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); |
| 383 | struct cifsTconInfo *pTcon; |
| 384 | |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 385 | if (cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | pTcon = cifs_sb->tcon; |
| 387 | else |
| 388 | return -EIO; |
| 389 | |
| 390 | xid = GetXid(); |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 391 | if (pTcon) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 392 | cFYI(1, ("flags: 0x%x operation: 0x%x", flags, operation)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | } else { |
| 394 | rc = -EIO; |
| 395 | } |
| 396 | |
| 397 | FreeXid(xid); |
| 398 | return rc; |
| 399 | } |
| 400 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 401 | int cifs_xstate_get(struct super_block *sb, struct fs_quota_stat *qstats) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | { |
| 403 | int xid; |
| 404 | int rc = 0; |
| 405 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); |
| 406 | struct cifsTconInfo *pTcon; |
| 407 | |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 408 | if (cifs_sb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | pTcon = cifs_sb->tcon; |
| 410 | } else { |
| 411 | return -EIO; |
| 412 | } |
| 413 | xid = GetXid(); |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 414 | if (pTcon) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 415 | cFYI(1, ("pqstats %p", qstats)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | } else { |
| 417 | rc = -EIO; |
| 418 | } |
| 419 | |
| 420 | FreeXid(xid); |
| 421 | return rc; |
| 422 | } |
| 423 | |
| 424 | static struct quotactl_ops cifs_quotactl_ops = { |
| 425 | .set_xquota = cifs_xquota_set, |
| 426 | .get_xquota = cifs_xquota_set, |
| 427 | .set_xstate = cifs_xstate_set, |
| 428 | .get_xstate = cifs_xstate_get, |
| 429 | }; |
| 430 | #endif |
| 431 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 432 | static void cifs_umount_begin(struct vfsmount *vfsmnt, int flags) |
Steve French | 68058e7 | 2005-10-10 10:34:22 -0700 | [diff] [blame] | 433 | { |
Steve French | 5e1253b | 2005-10-10 14:06:37 -0700 | [diff] [blame] | 434 | struct cifs_sb_info *cifs_sb; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 435 | struct cifsTconInfo *tcon; |
Steve French | 68058e7 | 2005-10-10 10:34:22 -0700 | [diff] [blame] | 436 | |
Trond Myklebust | 8b512d9 | 2006-06-09 09:34:18 -0400 | [diff] [blame] | 437 | if (!(flags & MNT_FORCE)) |
| 438 | return; |
| 439 | cifs_sb = CIFS_SB(vfsmnt->mnt_sb); |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 440 | if (cifs_sb == NULL) |
Steve French | 9e2e85f | 2005-10-10 14:28:38 -0700 | [diff] [blame] | 441 | return; |
| 442 | |
| 443 | tcon = cifs_sb->tcon; |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 444 | if (tcon == NULL) |
Steve French | 9e2e85f | 2005-10-10 14:28:38 -0700 | [diff] [blame] | 445 | return; |
Steve French | 5e1253b | 2005-10-10 14:06:37 -0700 | [diff] [blame] | 446 | down(&tcon->tconSem); |
| 447 | if (atomic_read(&tcon->useCount) == 1) |
| 448 | tcon->tidStatus = CifsExiting; |
| 449 | up(&tcon->tconSem); |
| 450 | |
Steve French | 3a5ff61 | 2006-07-14 22:37:11 +0000 | [diff] [blame] | 451 | /* cancel_brl_requests(tcon); */ /* BB mark all brl mids as exiting */ |
Steve French | 7b7abfe | 2005-11-09 15:21:09 -0800 | [diff] [blame] | 452 | /* cancel_notify_requests(tcon); */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 453 | if (tcon->ses && tcon->ses->server) { |
| 454 | cFYI(1, ("wake up tasks now - umount begin not complete")); |
Steve French | 9e2e85f | 2005-10-10 14:28:38 -0700 | [diff] [blame] | 455 | wake_up_all(&tcon->ses->server->request_q); |
Steve French | 6ab16d2 | 2005-11-29 20:55:11 -0800 | [diff] [blame] | 456 | wake_up_all(&tcon->ses->server->response_q); |
| 457 | msleep(1); /* yield */ |
| 458 | /* we have to kick the requests once more */ |
| 459 | wake_up_all(&tcon->ses->server->response_q); |
| 460 | msleep(1); |
Steve French | 5e1253b | 2005-10-10 14:06:37 -0700 | [diff] [blame] | 461 | } |
| 462 | /* BB FIXME - finish add checks for tidStatus BB */ |
Steve French | 68058e7 | 2005-10-10 10:34:22 -0700 | [diff] [blame] | 463 | |
| 464 | return; |
| 465 | } |
Steve French | 68058e7 | 2005-10-10 10:34:22 -0700 | [diff] [blame] | 466 | |
Steve French | bf97d28 | 2006-09-28 21:34:06 +0000 | [diff] [blame] | 467 | #ifdef CONFIG_CIFS_STATS2 |
| 468 | static int cifs_show_stats(struct seq_file *s, struct vfsmount *mnt) |
| 469 | { |
| 470 | /* BB FIXME */ |
| 471 | return 0; |
| 472 | } |
| 473 | #endif |
| 474 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | static int cifs_remount(struct super_block *sb, int *flags, char *data) |
| 476 | { |
| 477 | *flags |= MS_NODIRATIME; |
| 478 | return 0; |
| 479 | } |
| 480 | |
Josef 'Jeff' Sipek | ee9b6d6 | 2007-02-12 00:55:41 -0800 | [diff] [blame] | 481 | static const struct super_operations cifs_super_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | .read_inode = cifs_read_inode, |
| 483 | .put_super = cifs_put_super, |
| 484 | .statfs = cifs_statfs, |
| 485 | .alloc_inode = cifs_alloc_inode, |
| 486 | .destroy_inode = cifs_destroy_inode, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 487 | /* .drop_inode = generic_delete_inode, |
| 488 | .delete_inode = cifs_delete_inode, */ /* Do not need above two |
| 489 | functions unless later we add lazy close of inodes or unless the |
| 490 | kernel forgets to call us with the same number of releases (closes) |
| 491 | as opens */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | .show_options = cifs_show_options, |
Steve French | 7b7abfe | 2005-11-09 15:21:09 -0800 | [diff] [blame] | 493 | .umount_begin = cifs_umount_begin, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | .remount_fs = cifs_remount, |
Steve French | bf97d28 | 2006-09-28 21:34:06 +0000 | [diff] [blame] | 495 | #ifdef CONFIG_CIFS_STATS2 |
Steve French | f46d3e1 | 2006-09-30 01:08:55 +0000 | [diff] [blame] | 496 | .show_stats = cifs_show_stats, |
Steve French | bf97d28 | 2006-09-28 21:34:06 +0000 | [diff] [blame] | 497 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | }; |
| 499 | |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 500 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | cifs_get_sb(struct file_system_type *fs_type, |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 502 | int flags, const char *dev_name, void *data, struct vfsmount *mnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | { |
| 504 | int rc; |
| 505 | struct super_block *sb = sget(fs_type, NULL, set_anon_super, NULL); |
| 506 | |
| 507 | cFYI(1, ("Devname: %s flags: %d ", dev_name, flags)); |
| 508 | |
| 509 | if (IS_ERR(sb)) |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 510 | return PTR_ERR(sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | |
| 512 | sb->s_flags = flags; |
| 513 | |
Theodore Ts'o | 9b04c99 | 2006-03-24 03:15:10 -0800 | [diff] [blame] | 514 | rc = cifs_read_super(sb, data, dev_name, flags & MS_SILENT ? 1 : 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | if (rc) { |
| 516 | up_write(&sb->s_umount); |
| 517 | deactivate_super(sb); |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 518 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | } |
| 520 | sb->s_flags |= MS_ACTIVE; |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 521 | return simple_set_mnt(mnt, sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | } |
| 523 | |
Badari Pulavarty | 027445c | 2006-09-30 23:28:46 -0700 | [diff] [blame] | 524 | static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov, |
| 525 | unsigned long nr_segs, loff_t pos) |
Steve French | 87c89dd | 2005-11-17 17:03:00 -0800 | [diff] [blame] | 526 | { |
Josef "Jeff" Sipek | e6a0029 | 2006-12-08 02:36:48 -0800 | [diff] [blame] | 527 | struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode; |
Steve French | 87c89dd | 2005-11-17 17:03:00 -0800 | [diff] [blame] | 528 | ssize_t written; |
| 529 | |
Badari Pulavarty | 027445c | 2006-09-30 23:28:46 -0700 | [diff] [blame] | 530 | written = generic_file_aio_write(iocb, iov, nr_segs, pos); |
Steve French | 87c89dd | 2005-11-17 17:03:00 -0800 | [diff] [blame] | 531 | if (!CIFS_I(inode)->clientCanCacheAll) |
| 532 | filemap_fdatawrite(inode->i_mapping); |
| 533 | return written; |
| 534 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | |
Steve French | c32a0b6 | 2006-01-12 14:41:28 -0800 | [diff] [blame] | 536 | static loff_t cifs_llseek(struct file *file, loff_t offset, int origin) |
| 537 | { |
| 538 | /* origin == SEEK_END => we must revalidate the cached file length */ |
Steve French | 0889a94 | 2006-09-23 22:11:07 +0000 | [diff] [blame] | 539 | if (origin == SEEK_END) { |
Steve French | 030e9d8 | 2007-02-01 04:27:59 +0000 | [diff] [blame] | 540 | int retval; |
| 541 | |
| 542 | /* some applications poll for the file length in this strange |
| 543 | way so we must seek to end on non-oplocked files by |
| 544 | setting the revalidate time to zero */ |
Christoph Hellwig | c33f8d3 | 2007-04-02 18:47:20 +0000 | [diff] [blame] | 545 | CIFS_I(file->f_path.dentry->d_inode)->time = 0; |
Steve French | 030e9d8 | 2007-02-01 04:27:59 +0000 | [diff] [blame] | 546 | |
| 547 | retval = cifs_revalidate(file->f_path.dentry); |
Steve French | c32a0b6 | 2006-01-12 14:41:28 -0800 | [diff] [blame] | 548 | if (retval < 0) |
| 549 | return (loff_t)retval; |
| 550 | } |
| 551 | return remote_llseek(file, offset, origin); |
| 552 | } |
| 553 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | static struct file_system_type cifs_fs_type = { |
| 555 | .owner = THIS_MODULE, |
| 556 | .name = "cifs", |
| 557 | .get_sb = cifs_get_sb, |
| 558 | .kill_sb = kill_anon_super, |
| 559 | /* .fs_flags */ |
| 560 | }; |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 561 | const struct inode_operations cifs_dir_inode_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | .create = cifs_create, |
| 563 | .lookup = cifs_lookup, |
| 564 | .getattr = cifs_getattr, |
| 565 | .unlink = cifs_unlink, |
| 566 | .link = cifs_hardlink, |
| 567 | .mkdir = cifs_mkdir, |
| 568 | .rmdir = cifs_rmdir, |
| 569 | .rename = cifs_rename, |
| 570 | .permission = cifs_permission, |
| 571 | /* revalidate:cifs_revalidate, */ |
| 572 | .setattr = cifs_setattr, |
| 573 | .symlink = cifs_symlink, |
| 574 | .mknod = cifs_mknod, |
| 575 | #ifdef CONFIG_CIFS_XATTR |
| 576 | .setxattr = cifs_setxattr, |
| 577 | .getxattr = cifs_getxattr, |
| 578 | .listxattr = cifs_listxattr, |
| 579 | .removexattr = cifs_removexattr, |
| 580 | #endif |
| 581 | }; |
| 582 | |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 583 | const struct inode_operations cifs_file_inode_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | /* revalidate:cifs_revalidate, */ |
| 585 | .setattr = cifs_setattr, |
| 586 | .getattr = cifs_getattr, /* do we need this anymore? */ |
| 587 | .rename = cifs_rename, |
| 588 | .permission = cifs_permission, |
| 589 | #ifdef CONFIG_CIFS_XATTR |
| 590 | .setxattr = cifs_setxattr, |
| 591 | .getxattr = cifs_getxattr, |
| 592 | .listxattr = cifs_listxattr, |
| 593 | .removexattr = cifs_removexattr, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 594 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | }; |
| 596 | |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 597 | const struct inode_operations cifs_symlink_inode_ops = { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 598 | .readlink = generic_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | .follow_link = cifs_follow_link, |
| 600 | .put_link = cifs_put_link, |
| 601 | .permission = cifs_permission, |
| 602 | /* BB add the following two eventually */ |
| 603 | /* revalidate: cifs_revalidate, |
| 604 | setattr: cifs_notify_change, *//* BB do we need notify change */ |
| 605 | #ifdef CONFIG_CIFS_XATTR |
| 606 | .setxattr = cifs_setxattr, |
| 607 | .getxattr = cifs_getxattr, |
| 608 | .listxattr = cifs_listxattr, |
| 609 | .removexattr = cifs_removexattr, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 610 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | }; |
| 612 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 613 | const struct file_operations cifs_file_ops = { |
Steve French | 87c89dd | 2005-11-17 17:03:00 -0800 | [diff] [blame] | 614 | .read = do_sync_read, |
| 615 | .write = do_sync_write, |
Steve French | 87c89dd | 2005-11-17 17:03:00 -0800 | [diff] [blame] | 616 | .aio_read = generic_file_aio_read, |
| 617 | .aio_write = cifs_file_aio_write, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | .open = cifs_open, |
| 619 | .release = cifs_close, |
| 620 | .lock = cifs_lock, |
| 621 | .fsync = cifs_fsync, |
| 622 | .flush = cifs_flush, |
| 623 | .mmap = cifs_file_mmap, |
Jens Axboe | 5ffc4ef | 2007-06-01 11:49:19 +0200 | [diff] [blame] | 624 | .splice_read = generic_file_splice_read, |
Steve French | c32a0b6 | 2006-01-12 14:41:28 -0800 | [diff] [blame] | 625 | .llseek = cifs_llseek, |
Steve French | c67593a | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 626 | #ifdef CONFIG_CIFS_POSIX |
| 627 | .ioctl = cifs_ioctl, |
| 628 | #endif /* CONFIG_CIFS_POSIX */ |
| 629 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | #ifdef CONFIG_CIFS_EXPERIMENTAL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | .dir_notify = cifs_dir_notify, |
| 632 | #endif /* CONFIG_CIFS_EXPERIMENTAL */ |
| 633 | }; |
| 634 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 635 | const struct file_operations cifs_file_direct_ops = { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 636 | /* no mmap, no aio, no readv - |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | BB reevaluate whether they can be done with directio, no cache */ |
| 638 | .read = cifs_user_read, |
| 639 | .write = cifs_user_write, |
| 640 | .open = cifs_open, |
| 641 | .release = cifs_close, |
| 642 | .lock = cifs_lock, |
| 643 | .fsync = cifs_fsync, |
| 644 | .flush = cifs_flush, |
Jens Axboe | 5ffc4ef | 2007-06-01 11:49:19 +0200 | [diff] [blame] | 645 | .splice_read = generic_file_splice_read, |
Steve French | c67593a | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 646 | #ifdef CONFIG_CIFS_POSIX |
| 647 | .ioctl = cifs_ioctl, |
| 648 | #endif /* CONFIG_CIFS_POSIX */ |
Steve French | c32a0b6 | 2006-01-12 14:41:28 -0800 | [diff] [blame] | 649 | .llseek = cifs_llseek, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | #ifdef CONFIG_CIFS_EXPERIMENTAL |
| 651 | .dir_notify = cifs_dir_notify, |
| 652 | #endif /* CONFIG_CIFS_EXPERIMENTAL */ |
| 653 | }; |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 654 | const struct file_operations cifs_file_nobrl_ops = { |
Steve French | 87c89dd | 2005-11-17 17:03:00 -0800 | [diff] [blame] | 655 | .read = do_sync_read, |
| 656 | .write = do_sync_write, |
Steve French | 87c89dd | 2005-11-17 17:03:00 -0800 | [diff] [blame] | 657 | .aio_read = generic_file_aio_read, |
| 658 | .aio_write = cifs_file_aio_write, |
| 659 | .open = cifs_open, |
| 660 | .release = cifs_close, |
| 661 | .fsync = cifs_fsync, |
| 662 | .flush = cifs_flush, |
| 663 | .mmap = cifs_file_mmap, |
Jens Axboe | 5ffc4ef | 2007-06-01 11:49:19 +0200 | [diff] [blame] | 664 | .splice_read = generic_file_splice_read, |
Steve French | c32a0b6 | 2006-01-12 14:41:28 -0800 | [diff] [blame] | 665 | .llseek = cifs_llseek, |
Steve French | 8b94bcb | 2005-11-11 11:41:00 -0800 | [diff] [blame] | 666 | #ifdef CONFIG_CIFS_POSIX |
Steve French | 87c89dd | 2005-11-17 17:03:00 -0800 | [diff] [blame] | 667 | .ioctl = cifs_ioctl, |
Steve French | 8b94bcb | 2005-11-11 11:41:00 -0800 | [diff] [blame] | 668 | #endif /* CONFIG_CIFS_POSIX */ |
| 669 | |
| 670 | #ifdef CONFIG_CIFS_EXPERIMENTAL |
Steve French | 87c89dd | 2005-11-17 17:03:00 -0800 | [diff] [blame] | 671 | .dir_notify = cifs_dir_notify, |
Steve French | 8b94bcb | 2005-11-11 11:41:00 -0800 | [diff] [blame] | 672 | #endif /* CONFIG_CIFS_EXPERIMENTAL */ |
| 673 | }; |
| 674 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 675 | const struct file_operations cifs_file_direct_nobrl_ops = { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 676 | /* no mmap, no aio, no readv - |
Steve French | 87c89dd | 2005-11-17 17:03:00 -0800 | [diff] [blame] | 677 | BB reevaluate whether they can be done with directio, no cache */ |
| 678 | .read = cifs_user_read, |
| 679 | .write = cifs_user_write, |
| 680 | .open = cifs_open, |
| 681 | .release = cifs_close, |
| 682 | .fsync = cifs_fsync, |
| 683 | .flush = cifs_flush, |
Jens Axboe | 5ffc4ef | 2007-06-01 11:49:19 +0200 | [diff] [blame] | 684 | .splice_read = generic_file_splice_read, |
Steve French | 8b94bcb | 2005-11-11 11:41:00 -0800 | [diff] [blame] | 685 | #ifdef CONFIG_CIFS_POSIX |
Steve French | 87c89dd | 2005-11-17 17:03:00 -0800 | [diff] [blame] | 686 | .ioctl = cifs_ioctl, |
Steve French | 8b94bcb | 2005-11-11 11:41:00 -0800 | [diff] [blame] | 687 | #endif /* CONFIG_CIFS_POSIX */ |
Steve French | c32a0b6 | 2006-01-12 14:41:28 -0800 | [diff] [blame] | 688 | .llseek = cifs_llseek, |
Steve French | 8b94bcb | 2005-11-11 11:41:00 -0800 | [diff] [blame] | 689 | #ifdef CONFIG_CIFS_EXPERIMENTAL |
Steve French | 87c89dd | 2005-11-17 17:03:00 -0800 | [diff] [blame] | 690 | .dir_notify = cifs_dir_notify, |
Steve French | 8b94bcb | 2005-11-11 11:41:00 -0800 | [diff] [blame] | 691 | #endif /* CONFIG_CIFS_EXPERIMENTAL */ |
| 692 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 694 | const struct file_operations cifs_dir_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | .readdir = cifs_readdir, |
| 696 | .release = cifs_closedir, |
| 697 | .read = generic_read_dir, |
| 698 | #ifdef CONFIG_CIFS_EXPERIMENTAL |
| 699 | .dir_notify = cifs_dir_notify, |
| 700 | #endif /* CONFIG_CIFS_EXPERIMENTAL */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 701 | .ioctl = cifs_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | }; |
| 703 | |
| 704 | static void |
Christoph Lameter | 4ba9b9d | 2007-10-16 23:25:51 -0700 | [diff] [blame] | 705 | cifs_init_once(struct kmem_cache *cachep, void *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | { |
| 707 | struct cifsInodeInfo *cifsi = inode; |
| 708 | |
Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 709 | inode_init_once(&cifsi->vfs_inode); |
| 710 | INIT_LIST_HEAD(&cifsi->lockList); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | static int |
| 714 | cifs_init_inodecache(void) |
| 715 | { |
| 716 | cifs_inode_cachep = kmem_cache_create("cifs_inode_cache", |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 717 | sizeof(struct cifsInodeInfo), |
Paul Jackson | fffb60f | 2006-03-24 03:16:06 -0800 | [diff] [blame] | 718 | 0, (SLAB_RECLAIM_ACCOUNT| |
| 719 | SLAB_MEM_SPREAD), |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 720 | cifs_init_once); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | if (cifs_inode_cachep == NULL) |
| 722 | return -ENOMEM; |
| 723 | |
| 724 | return 0; |
| 725 | } |
| 726 | |
| 727 | static void |
| 728 | cifs_destroy_inodecache(void) |
| 729 | { |
Alexey Dobriyan | 1a1d92c | 2006-09-27 01:49:40 -0700 | [diff] [blame] | 730 | kmem_cache_destroy(cifs_inode_cachep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | static int |
| 734 | cifs_init_request_bufs(void) |
| 735 | { |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 736 | if (CIFSMaxBufSize < 8192) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | /* Buffer size can not be smaller than 2 * PATH_MAX since maximum |
| 738 | Unicode path name has to fit in any SMB/CIFS path based frames */ |
| 739 | CIFSMaxBufSize = 8192; |
| 740 | } else if (CIFSMaxBufSize > 1024*127) { |
| 741 | CIFSMaxBufSize = 1024 * 127; |
| 742 | } else { |
| 743 | CIFSMaxBufSize &= 0x1FE00; /* Round size to even 512 byte mult*/ |
| 744 | } |
| 745 | /* cERROR(1,("CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize)); */ |
| 746 | cifs_req_cachep = kmem_cache_create("cifs_request", |
| 747 | CIFSMaxBufSize + |
| 748 | MAX_CIFS_HDR_SIZE, 0, |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 749 | SLAB_HWCACHE_ALIGN, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | if (cifs_req_cachep == NULL) |
| 751 | return -ENOMEM; |
| 752 | |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 753 | if (cifs_min_rcv < 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | cifs_min_rcv = 1; |
| 755 | else if (cifs_min_rcv > 64) { |
| 756 | cifs_min_rcv = 64; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 757 | cERROR(1, ("cifs_min_rcv set to maximum (64)")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | } |
| 759 | |
Matthew Dobson | 93d2341 | 2006-03-26 01:37:50 -0800 | [diff] [blame] | 760 | cifs_req_poolp = mempool_create_slab_pool(cifs_min_rcv, |
| 761 | cifs_req_cachep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 763 | if (cifs_req_poolp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | kmem_cache_destroy(cifs_req_cachep); |
| 765 | return -ENOMEM; |
| 766 | } |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 767 | /* MAX_CIFS_SMALL_BUFFER_SIZE bytes is enough for most SMB responses and |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | almost all handle based requests (but not write response, nor is it |
| 769 | sufficient for path based requests). A smaller size would have |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 770 | been more efficient (compacting multiple slab items on one 4k page) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | for the case in which debug was on, but this larger size allows |
| 772 | more SMBs to use small buffer alloc and is still much more |
Steve French | 6dc0f87 | 2007-07-06 23:13:06 +0000 | [diff] [blame] | 773 | efficient to alloc 1 per page off the slab compared to 17K (5page) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | alloc of large cifs buffers even when page debugging is on */ |
| 775 | cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq", |
Steve French | 6dc0f87 | 2007-07-06 23:13:06 +0000 | [diff] [blame] | 776 | MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN, |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 777 | NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | if (cifs_sm_req_cachep == NULL) { |
| 779 | mempool_destroy(cifs_req_poolp); |
| 780 | kmem_cache_destroy(cifs_req_cachep); |
Steve French | 6dc0f87 | 2007-07-06 23:13:06 +0000 | [diff] [blame] | 781 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | } |
| 783 | |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 784 | if (cifs_min_small < 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | cifs_min_small = 2; |
| 786 | else if (cifs_min_small > 256) { |
| 787 | cifs_min_small = 256; |
Steve French | 6dc0f87 | 2007-07-06 23:13:06 +0000 | [diff] [blame] | 788 | cFYI(1, ("cifs_min_small set to maximum (256)")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | } |
| 790 | |
Matthew Dobson | 93d2341 | 2006-03-26 01:37:50 -0800 | [diff] [blame] | 791 | cifs_sm_req_poolp = mempool_create_slab_pool(cifs_min_small, |
| 792 | cifs_sm_req_cachep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 794 | if (cifs_sm_req_poolp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | mempool_destroy(cifs_req_poolp); |
| 796 | kmem_cache_destroy(cifs_req_cachep); |
| 797 | kmem_cache_destroy(cifs_sm_req_cachep); |
| 798 | return -ENOMEM; |
| 799 | } |
| 800 | |
| 801 | return 0; |
| 802 | } |
| 803 | |
| 804 | static void |
| 805 | cifs_destroy_request_bufs(void) |
| 806 | { |
| 807 | mempool_destroy(cifs_req_poolp); |
Alexey Dobriyan | 1a1d92c | 2006-09-27 01:49:40 -0700 | [diff] [blame] | 808 | kmem_cache_destroy(cifs_req_cachep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | mempool_destroy(cifs_sm_req_poolp); |
Alexey Dobriyan | 1a1d92c | 2006-09-27 01:49:40 -0700 | [diff] [blame] | 810 | kmem_cache_destroy(cifs_sm_req_cachep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | static int |
| 814 | cifs_init_mids(void) |
| 815 | { |
| 816 | cifs_mid_cachep = kmem_cache_create("cifs_mpx_ids", |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 817 | sizeof(struct mid_q_entry), 0, |
| 818 | SLAB_HWCACHE_ALIGN, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | if (cifs_mid_cachep == NULL) |
| 820 | return -ENOMEM; |
| 821 | |
Matthew Dobson | 93d2341 | 2006-03-26 01:37:50 -0800 | [diff] [blame] | 822 | /* 3 is a reasonable minimum number of simultaneous operations */ |
| 823 | cifs_mid_poolp = mempool_create_slab_pool(3, cifs_mid_cachep); |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 824 | if (cifs_mid_poolp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | kmem_cache_destroy(cifs_mid_cachep); |
| 826 | return -ENOMEM; |
| 827 | } |
| 828 | |
| 829 | cifs_oplock_cachep = kmem_cache_create("cifs_oplock_structs", |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 830 | sizeof(struct oplock_q_entry), 0, |
| 831 | SLAB_HWCACHE_ALIGN, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | if (cifs_oplock_cachep == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | mempool_destroy(cifs_mid_poolp); |
Akinobu Mita | e6985c7 | 2007-06-04 16:14:59 +0000 | [diff] [blame] | 834 | kmem_cache_destroy(cifs_mid_cachep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | return -ENOMEM; |
| 836 | } |
| 837 | |
| 838 | return 0; |
| 839 | } |
| 840 | |
| 841 | static void |
| 842 | cifs_destroy_mids(void) |
| 843 | { |
| 844 | mempool_destroy(cifs_mid_poolp); |
Alexey Dobriyan | 1a1d92c | 2006-09-27 01:49:40 -0700 | [diff] [blame] | 845 | kmem_cache_destroy(cifs_mid_cachep); |
| 846 | kmem_cache_destroy(cifs_oplock_cachep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | } |
| 848 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 849 | static int cifs_oplock_thread(void *dummyarg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | { |
Steve French | 6dc0f87 | 2007-07-06 23:13:06 +0000 | [diff] [blame] | 851 | struct oplock_q_entry *oplock_item; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | struct cifsTconInfo *pTcon; |
Steve French | 6dc0f87 | 2007-07-06 23:13:06 +0000 | [diff] [blame] | 853 | struct inode *inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | __u16 netfid; |
| 855 | int rc; |
| 856 | |
Rafael J. Wysocki | 8314418 | 2007-07-17 04:03:35 -0700 | [diff] [blame] | 857 | set_freezable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | do { |
Steve French | 6dc0f87 | 2007-07-06 23:13:06 +0000 | [diff] [blame] | 859 | if (try_to_freeze()) |
Steve French | ede1327 | 2005-08-30 20:10:14 -0700 | [diff] [blame] | 860 | continue; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 861 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | spin_lock(&GlobalMid_Lock); |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 863 | if (list_empty(&GlobalOplock_Q)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | spin_unlock(&GlobalMid_Lock); |
| 865 | set_current_state(TASK_INTERRUPTIBLE); |
| 866 | schedule_timeout(39*HZ); |
| 867 | } else { |
Steve French | 6dc0f87 | 2007-07-06 23:13:06 +0000 | [diff] [blame] | 868 | oplock_item = list_entry(GlobalOplock_Q.next, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | struct oplock_q_entry, qhead); |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 870 | if (oplock_item) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 871 | cFYI(1, ("found oplock item to write out")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | pTcon = oplock_item->tcon; |
| 873 | inode = oplock_item->pinode; |
| 874 | netfid = oplock_item->netfid; |
| 875 | spin_unlock(&GlobalMid_Lock); |
| 876 | DeleteOplockQEntry(oplock_item); |
| 877 | /* can not grab inode sem here since it would |
Steve French | 6dc0f87 | 2007-07-06 23:13:06 +0000 | [diff] [blame] | 878 | deadlock when oplock received on delete |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 879 | since vfs_unlink holds the i_mutex across |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | the call */ |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 881 | /* mutex_lock(&inode->i_mutex);*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | if (S_ISREG(inode->i_mode)) { |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 883 | rc = |
| 884 | filemap_fdatawrite(inode->i_mapping); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 885 | if (CIFS_I(inode)->clientCanCacheRead |
| 886 | == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | filemap_fdatawait(inode->i_mapping); |
| 888 | invalidate_remote_inode(inode); |
| 889 | } |
| 890 | } else |
| 891 | rc = 0; |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 892 | /* mutex_unlock(&inode->i_mutex);*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | if (rc) |
| 894 | CIFS_I(inode)->write_behind_rc = rc; |
Steve French | 6dc0f87 | 2007-07-06 23:13:06 +0000 | [diff] [blame] | 895 | cFYI(1, ("Oplock flush inode %p rc %d", |
| 896 | inode, rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | |
Steve French | 6dc0f87 | 2007-07-06 23:13:06 +0000 | [diff] [blame] | 898 | /* releasing stale oplock after recent reconnect |
| 899 | of smb session using a now incorrect file |
| 900 | handle is not a data integrity issue but do |
| 901 | not bother sending an oplock release if session |
| 902 | to server still is disconnected since oplock |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | already released by the server in that case */ |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 904 | if (pTcon->tidStatus != CifsNeedReconnect) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | rc = CIFSSMBLock(0, pTcon, netfid, |
Steve French | 6dc0f87 | 2007-07-06 23:13:06 +0000 | [diff] [blame] | 906 | 0 /* len */ , 0 /* offset */, 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | 0, LOCKING_ANDX_OPLOCK_RELEASE, |
| 908 | 0 /* wait flag */); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 909 | cFYI(1, ("Oplock release rc = %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | } |
| 911 | } else |
| 912 | spin_unlock(&GlobalMid_Lock); |
Steve French | 68058e7 | 2005-10-10 10:34:22 -0700 | [diff] [blame] | 913 | set_current_state(TASK_INTERRUPTIBLE); |
| 914 | schedule_timeout(1); /* yield in case q were corrupt */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | } |
Steve French | 45af7a0 | 2006-04-21 22:52:25 +0000 | [diff] [blame] | 916 | } while (!kthread_should_stop()); |
| 917 | |
| 918 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | } |
| 920 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 921 | static int cifs_dnotify_thread(void *dummyarg) |
Steve French | 8d0d509 | 2005-08-18 09:41:43 -0700 | [diff] [blame] | 922 | { |
Steve French | 6ab16d2 | 2005-11-29 20:55:11 -0800 | [diff] [blame] | 923 | struct list_head *tmp; |
| 924 | struct cifsSesInfo *ses; |
| 925 | |
Steve French | 8d0d509 | 2005-08-18 09:41:43 -0700 | [diff] [blame] | 926 | do { |
Pavel Machek | 0fd1ffe | 2006-06-13 21:31:39 +0000 | [diff] [blame] | 927 | if (try_to_freeze()) |
Steve French | 16abbec | 2005-08-30 13:10:14 -0700 | [diff] [blame] | 928 | continue; |
Steve French | 8d0d509 | 2005-08-18 09:41:43 -0700 | [diff] [blame] | 929 | set_current_state(TASK_INTERRUPTIBLE); |
Steve French | 6ab16d2 | 2005-11-29 20:55:11 -0800 | [diff] [blame] | 930 | schedule_timeout(15*HZ); |
| 931 | read_lock(&GlobalSMBSeslock); |
| 932 | /* check if any stuck requests that need |
| 933 | to be woken up and wakeq so the |
| 934 | thread can wake up and error out */ |
| 935 | list_for_each(tmp, &GlobalSMBSessionList) { |
Steve French | 6dc0f87 | 2007-07-06 23:13:06 +0000 | [diff] [blame] | 936 | ses = list_entry(tmp, struct cifsSesInfo, |
Steve French | 6ab16d2 | 2005-11-29 20:55:11 -0800 | [diff] [blame] | 937 | cifsSessionList); |
Steve French | 6dc0f87 | 2007-07-06 23:13:06 +0000 | [diff] [blame] | 938 | if (ses && ses->server && |
Steve French | 2a138ebb | 2005-11-29 21:22:19 -0800 | [diff] [blame] | 939 | atomic_read(&ses->server->inFlight)) |
Steve French | 6ab16d2 | 2005-11-29 20:55:11 -0800 | [diff] [blame] | 940 | wake_up_all(&ses->server->response_q); |
| 941 | } |
| 942 | read_unlock(&GlobalSMBSeslock); |
Steve French | 45af7a0 | 2006-04-21 22:52:25 +0000 | [diff] [blame] | 943 | } while (!kthread_should_stop()); |
| 944 | |
| 945 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | static int __init |
| 949 | init_cifs(void) |
| 950 | { |
| 951 | int rc = 0; |
| 952 | #ifdef CONFIG_PROC_FS |
| 953 | cifs_proc_init(); |
| 954 | #endif |
Steve French | 2cd646a | 2006-09-28 19:43:08 +0000 | [diff] [blame] | 955 | /* INIT_LIST_HEAD(&GlobalServerList);*/ /* BB not implemented yet */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | INIT_LIST_HEAD(&GlobalSMBSessionList); |
| 957 | INIT_LIST_HEAD(&GlobalTreeConnectionList); |
| 958 | INIT_LIST_HEAD(&GlobalOplock_Q); |
Steve French | 4ca9c19 | 2005-10-10 19:52:13 -0700 | [diff] [blame] | 959 | #ifdef CONFIG_CIFS_EXPERIMENTAL |
| 960 | INIT_LIST_HEAD(&GlobalDnotifyReqList); |
| 961 | INIT_LIST_HEAD(&GlobalDnotifyRsp_Q); |
Steve French | 6dc0f87 | 2007-07-06 23:13:06 +0000 | [diff] [blame] | 962 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | /* |
| 964 | * Initialize Global counters |
| 965 | */ |
| 966 | atomic_set(&sesInfoAllocCount, 0); |
| 967 | atomic_set(&tconInfoAllocCount, 0); |
Steve French | 6dc0f87 | 2007-07-06 23:13:06 +0000 | [diff] [blame] | 968 | atomic_set(&tcpSesAllocCount, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | atomic_set(&tcpSesReconnectCount, 0); |
| 970 | atomic_set(&tconInfoReconnectCount, 0); |
| 971 | |
| 972 | atomic_set(&bufAllocCount, 0); |
Steve French | 4498eed | 2005-12-03 13:58:57 -0800 | [diff] [blame] | 973 | atomic_set(&smBufAllocCount, 0); |
| 974 | #ifdef CONFIG_CIFS_STATS2 |
| 975 | atomic_set(&totBufAllocCount, 0); |
| 976 | atomic_set(&totSmBufAllocCount, 0); |
| 977 | #endif /* CONFIG_CIFS_STATS2 */ |
| 978 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | atomic_set(&midCount, 0); |
| 980 | GlobalCurrentXid = 0; |
| 981 | GlobalTotalActiveXid = 0; |
| 982 | GlobalMaxActiveXid = 0; |
Steve French | 2cd646a | 2006-09-28 19:43:08 +0000 | [diff] [blame] | 983 | memset(Local_System_Name, 0, 15); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | rwlock_init(&GlobalSMBSeslock); |
| 985 | spin_lock_init(&GlobalMid_Lock); |
| 986 | |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 987 | if (cifs_max_pending < 2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | cifs_max_pending = 2; |
Steve French | 6dc0f87 | 2007-07-06 23:13:06 +0000 | [diff] [blame] | 989 | cFYI(1, ("cifs_max_pending set to min of 2")); |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 990 | } else if (cifs_max_pending > 256) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | cifs_max_pending = 256; |
Steve French | 6dc0f87 | 2007-07-06 23:13:06 +0000 | [diff] [blame] | 992 | cFYI(1, ("cifs_max_pending set to max of 256")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | rc = cifs_init_inodecache(); |
Steve French | 45af7a0 | 2006-04-21 22:52:25 +0000 | [diff] [blame] | 996 | if (rc) |
| 997 | goto out_clean_proc; |
| 998 | |
| 999 | rc = cifs_init_mids(); |
| 1000 | if (rc) |
| 1001 | goto out_destroy_inodecache; |
| 1002 | |
| 1003 | rc = cifs_init_request_bufs(); |
| 1004 | if (rc) |
| 1005 | goto out_destroy_mids; |
| 1006 | |
| 1007 | rc = register_filesystem(&cifs_fs_type); |
| 1008 | if (rc) |
| 1009 | goto out_destroy_request_bufs; |
Jeff Layton | 84a15b9 | 2007-11-03 05:02:24 +0000 | [diff] [blame] | 1010 | #ifdef CONFIG_CIFS_UPCALL |
| 1011 | rc = register_key_type(&cifs_spnego_key_type); |
| 1012 | if (rc) |
| 1013 | goto out_unregister_filesystem; |
| 1014 | #endif |
Steve French | 45af7a0 | 2006-04-21 22:52:25 +0000 | [diff] [blame] | 1015 | oplockThread = kthread_run(cifs_oplock_thread, NULL, "cifsoplockd"); |
| 1016 | if (IS_ERR(oplockThread)) { |
| 1017 | rc = PTR_ERR(oplockThread); |
Steve French | 6dc0f87 | 2007-07-06 23:13:06 +0000 | [diff] [blame] | 1018 | cERROR(1, ("error %d create oplock thread", rc)); |
Jeff Layton | 84a15b9 | 2007-11-03 05:02:24 +0000 | [diff] [blame] | 1019 | goto out_unregister_key_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | } |
Steve French | 45af7a0 | 2006-04-21 22:52:25 +0000 | [diff] [blame] | 1021 | |
| 1022 | dnotifyThread = kthread_run(cifs_dnotify_thread, NULL, "cifsdnotifyd"); |
| 1023 | if (IS_ERR(dnotifyThread)) { |
| 1024 | rc = PTR_ERR(dnotifyThread); |
Steve French | 6dc0f87 | 2007-07-06 23:13:06 +0000 | [diff] [blame] | 1025 | cERROR(1, ("error %d create dnotify thread", rc)); |
Steve French | 45af7a0 | 2006-04-21 22:52:25 +0000 | [diff] [blame] | 1026 | goto out_stop_oplock_thread; |
| 1027 | } |
| 1028 | |
| 1029 | return 0; |
| 1030 | |
| 1031 | out_stop_oplock_thread: |
| 1032 | kthread_stop(oplockThread); |
Jeff Layton | 84a15b9 | 2007-11-03 05:02:24 +0000 | [diff] [blame] | 1033 | out_unregister_key_type: |
| 1034 | #ifdef CONFIG_CIFS_UPCALL |
| 1035 | unregister_key_type(&cifs_spnego_key_type); |
Steve French | 45af7a0 | 2006-04-21 22:52:25 +0000 | [diff] [blame] | 1036 | out_unregister_filesystem: |
Jeff Layton | 84a15b9 | 2007-11-03 05:02:24 +0000 | [diff] [blame] | 1037 | #endif |
Steve French | 45af7a0 | 2006-04-21 22:52:25 +0000 | [diff] [blame] | 1038 | unregister_filesystem(&cifs_fs_type); |
| 1039 | out_destroy_request_bufs: |
| 1040 | cifs_destroy_request_bufs(); |
| 1041 | out_destroy_mids: |
| 1042 | cifs_destroy_mids(); |
| 1043 | out_destroy_inodecache: |
| 1044 | cifs_destroy_inodecache(); |
| 1045 | out_clean_proc: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | #ifdef CONFIG_PROC_FS |
| 1047 | cifs_proc_clean(); |
| 1048 | #endif |
| 1049 | return rc; |
| 1050 | } |
| 1051 | |
| 1052 | static void __exit |
| 1053 | exit_cifs(void) |
| 1054 | { |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame] | 1055 | cFYI(0, ("exit_cifs")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | #ifdef CONFIG_PROC_FS |
| 1057 | cifs_proc_clean(); |
| 1058 | #endif |
Jeff Layton | 84a15b9 | 2007-11-03 05:02:24 +0000 | [diff] [blame] | 1059 | #ifdef CONFIG_CIFS_UPCALL |
| 1060 | unregister_key_type(&cifs_spnego_key_type); |
| 1061 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | unregister_filesystem(&cifs_fs_type); |
| 1063 | cifs_destroy_inodecache(); |
| 1064 | cifs_destroy_mids(); |
| 1065 | cifs_destroy_request_bufs(); |
Steve French | 45af7a0 | 2006-04-21 22:52:25 +0000 | [diff] [blame] | 1066 | kthread_stop(oplockThread); |
| 1067 | kthread_stop(dnotifyThread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>"); |
Steve French | 6dc0f87 | 2007-07-06 23:13:06 +0000 | [diff] [blame] | 1071 | MODULE_LICENSE("GPL"); /* combination of LGPL + GPL source behaves as GPL */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | MODULE_DESCRIPTION |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame] | 1073 | ("VFS to access servers complying with the SNIA CIFS Specification " |
| 1074 | "e.g. Samba and Windows"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | MODULE_VERSION(CIFS_VERSION); |
| 1076 | module_init(init_cifs) |
| 1077 | module_exit(exit_cifs) |