]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * fs/cifs/cifsfs.c | |
3 | * | |
2b280fab | 4 | * Copyright (C) International Business Machines Corp., 2002,2008 |
1da177e4 LT |
5 | * Author(s): Steve French ([email protected]) |
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> | |
6ab16d24 | 35 | #include <linux/delay.h> |
45af7a0f | 36 | #include <linux/kthread.h> |
7dfb7103 | 37 | #include <linux/freezer.h> |
fec11dd9 | 38 | #include <linux/namei.h> |
3eb9a889 | 39 | #include <net/ipv6.h> |
1da177e4 LT |
40 | #include "cifsfs.h" |
41 | #include "cifspdu.h" | |
42 | #define DECLARE_GLOBALS_HERE | |
43 | #include "cifsglob.h" | |
44 | #include "cifsproto.h" | |
45 | #include "cifs_debug.h" | |
46 | #include "cifs_fs_sb.h" | |
47 | #include <linux/mm.h> | |
84a15b93 | 48 | #include <linux/key-type.h> |
e545937a | 49 | #include "cifs_spnego.h" |
f579cf3c | 50 | #include "fscache.h" |
1da177e4 LT |
51 | #define CIFS_MAGIC_NUMBER 0xFF534D42 /* the first four bytes of SMB PDUs */ |
52 | ||
1da177e4 LT |
53 | int cifsFYI = 0; |
54 | int cifsERROR = 1; | |
55 | int traceSMB = 0; | |
e7504734 | 56 | bool enable_oplocks = true; |
1da177e4 LT |
57 | unsigned int linuxExtEnabled = 1; |
58 | unsigned int lookupCacheEnabled = 1; | |
59 | unsigned int multiuser_mount = 0; | |
04912d6a | 60 | unsigned int global_secflags = CIFSSEC_DEF; |
3979877e | 61 | /* unsigned int ntlmv2_support = 0; */ |
1da177e4 | 62 | unsigned int sign_CIFS_PDUs = 1; |
ee9b6d61 | 63 | static const struct super_operations cifs_super_ops; |
1da177e4 LT |
64 | unsigned int CIFSMaxBufSize = CIFS_MAX_MSGSIZE; |
65 | module_param(CIFSMaxBufSize, int, 0); | |
63135e08 SF |
66 | MODULE_PARM_DESC(CIFSMaxBufSize, "Network buffer size (not including header). " |
67 | "Default: 16384 Range: 8192 to 130048"); | |
1da177e4 LT |
68 | unsigned int cifs_min_rcv = CIFS_MIN_RCV_POOL; |
69 | module_param(cifs_min_rcv, int, 0); | |
63135e08 SF |
70 | MODULE_PARM_DESC(cifs_min_rcv, "Network buffers in pool. Default: 4 Range: " |
71 | "1 to 64"); | |
1da177e4 LT |
72 | unsigned int cifs_min_small = 30; |
73 | module_param(cifs_min_small, int, 0); | |
63135e08 SF |
74 | MODULE_PARM_DESC(cifs_min_small, "Small network buffers in pool. Default: 30 " |
75 | "Range: 2 to 256"); | |
1da177e4 | 76 | unsigned int cifs_max_pending = CIFS_MAX_REQ; |
fef33df8 | 77 | module_param(cifs_max_pending, int, 0444); |
63135e08 SF |
78 | MODULE_PARM_DESC(cifs_max_pending, "Simultaneous requests to server. " |
79 | "Default: 50 Range: 2 to 256"); | |
fda35943 SF |
80 | unsigned short echo_retries = 5; |
81 | module_param(echo_retries, ushort, 0644); | |
82 | MODULE_PARM_DESC(echo_retries, "Number of echo attempts before giving up and " | |
83 | "reconnecting server. Default: 5. 0 means " | |
84 | "never reconnect."); | |
e7504734 SF |
85 | module_param(enable_oplocks, bool, 0644); |
86 | MODULE_PARM_DESC(enable_oplocks, "Enable or disable oplocks (bool). Default:" | |
87 | "y/Y/1"); | |
88 | ||
1da177e4 LT |
89 | extern mempool_t *cifs_sm_req_poolp; |
90 | extern mempool_t *cifs_req_poolp; | |
91 | extern mempool_t *cifs_mid_poolp; | |
92 | ||
1da177e4 | 93 | static int |
97d1152a | 94 | cifs_read_super(struct super_block *sb) |
1da177e4 LT |
95 | { |
96 | struct inode *inode; | |
b2e5cd33 | 97 | struct cifs_sb_info *cifs_sb; |
1da177e4 | 98 | int rc = 0; |
50c2f753 | 99 | |
b2e5cd33 | 100 | cifs_sb = CIFS_SB(sb); |
1da177e4 | 101 | |
2c6292ae AV |
102 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIXACL) |
103 | sb->s_flags |= MS_POSIXACL; | |
104 | ||
105 | if (cifs_sb_master_tcon(cifs_sb)->ses->capabilities & CAP_LARGE_FILES) | |
106 | sb->s_maxbytes = MAX_LFS_FILESIZE; | |
107 | else | |
108 | sb->s_maxbytes = MAX_NON_LFS; | |
109 | ||
110 | /* BB FIXME fix time_gran to be larger for LANMAN sessions */ | |
111 | sb->s_time_gran = 100; | |
112 | ||
1da177e4 LT |
113 | sb->s_magic = CIFS_MAGIC_NUMBER; |
114 | sb->s_op = &cifs_super_ops; | |
8044f7f4 | 115 | sb->s_bdi = &cifs_sb->bdi; |
1da177e4 LT |
116 | sb->s_blocksize = CIFS_MAX_MSGSIZE; |
117 | sb->s_blocksize_bits = 14; /* default 2**14 = CIFS_MAX_MSGSIZE */ | |
9b6763e0 | 118 | inode = cifs_root_iget(sb); |
1da177e4 | 119 | |
ce634ab2 DH |
120 | if (IS_ERR(inode)) { |
121 | rc = PTR_ERR(inode); | |
1da177e4 LT |
122 | goto out_no_root; |
123 | } | |
124 | ||
125 | sb->s_root = d_alloc_root(inode); | |
126 | ||
127 | if (!sb->s_root) { | |
128 | rc = -ENOMEM; | |
064326c0 | 129 | iput(inode); |
1da177e4 LT |
130 | goto out_no_root; |
131 | } | |
50c2f753 | 132 | |
1c929cfe AV |
133 | /* do that *after* d_alloc_root() - we want NULL ->d_op for root here */ |
134 | if (cifs_sb_master_tcon(cifs_sb)->nocase) | |
135 | sb->s_d_op = &cifs_ci_dentry_ops; | |
136 | else | |
137 | sb->s_d_op = &cifs_dentry_ops; | |
138 | ||
f3a6a60e | 139 | #ifdef CONFIG_CIFS_NFSD_EXPORT |
7521a3c5 | 140 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) { |
b6b38f70 | 141 | cFYI(1, "export ops supported"); |
7521a3c5 SF |
142 | sb->s_export_op = &cifs_export_ops; |
143 | } | |
f3a6a60e | 144 | #endif /* CONFIG_CIFS_NFSD_EXPORT */ |
1da177e4 LT |
145 | |
146 | return 0; | |
147 | ||
148 | out_no_root: | |
b6b38f70 | 149 | cERROR(1, "cifs_read_super: get root inode failed"); |
1da177e4 LT |
150 | return rc; |
151 | } | |
152 | ||
6d686175 AV |
153 | static void cifs_kill_sb(struct super_block *sb) |
154 | { | |
155 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); | |
156 | kill_anon_super(sb); | |
98ab494d | 157 | cifs_umount(cifs_sb); |
1da177e4 LT |
158 | } |
159 | ||
160 | static int | |
726c3342 | 161 | cifs_statfs(struct dentry *dentry, struct kstatfs *buf) |
1da177e4 | 162 | { |
726c3342 | 163 | struct super_block *sb = dentry->d_sb; |
39da9847 | 164 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); |
96daf2b0 | 165 | struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb); |
c81156dd | 166 | int rc = -EOPNOTSUPP; |
39da9847 | 167 | int xid; |
1da177e4 LT |
168 | |
169 | xid = GetXid(); | |
170 | ||
1da177e4 LT |
171 | buf->f_type = CIFS_MAGIC_NUMBER; |
172 | ||
39da9847 SF |
173 | /* |
174 | * PATH_MAX may be too long - it would presumably be total path, | |
175 | * but note that some servers (includinng Samba 3) have a shorter | |
176 | * maximum path. | |
177 | * | |
178 | * Instead could get the real value via SMB_QUERY_FS_ATTRIBUTE_INFO. | |
179 | */ | |
180 | buf->f_namelen = PATH_MAX; | |
1da177e4 LT |
181 | buf->f_files = 0; /* undefined */ |
182 | buf->f_ffree = 0; /* unlimited */ | |
183 | ||
39da9847 SF |
184 | /* |
185 | * We could add a second check for a QFS Unix capability bit | |
186 | */ | |
187 | if ((tcon->ses->capabilities & CAP_UNIX) && | |
188 | (CIFS_POSIX_EXTENSIONS & le64_to_cpu(tcon->fsUnixInfo.Capability))) | |
189 | rc = CIFSSMBQFSPosixInfo(xid, tcon, buf); | |
190 | ||
191 | /* | |
192 | * Only need to call the old QFSInfo if failed on newer one, | |
193 | * e.g. by OS/2. | |
194 | **/ | |
195 | if (rc && (tcon->ses->capabilities & CAP_NT_SMBS)) | |
196 | rc = CIFSSMBQFSInfo(xid, tcon, buf); | |
197 | ||
198 | /* | |
199 | * Some old Windows servers also do not support level 103, retry with | |
200 | * older level one if old server failed the previous call or we | |
201 | * bypassed it because we detected that this was an older LANMAN sess | |
202 | */ | |
4523cc30 | 203 | if (rc) |
39da9847 SF |
204 | rc = SMBOldQFSInfo(xid, tcon, buf); |
205 | ||
1da177e4 | 206 | FreeXid(xid); |
39da9847 | 207 | return 0; |
1da177e4 LT |
208 | } |
209 | ||
10556cb2 | 210 | static int cifs_permission(struct inode *inode, int mask) |
1da177e4 LT |
211 | { |
212 | struct cifs_sb_info *cifs_sb; | |
213 | ||
214 | cifs_sb = CIFS_SB(inode->i_sb); | |
215 | ||
f696a365 MS |
216 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) { |
217 | if ((mask & MAY_EXEC) && !execute_ok(inode)) | |
218 | return -EACCES; | |
219 | else | |
220 | return 0; | |
221 | } else /* file mode might have been restricted at mount time | |
50c2f753 | 222 | on the client (above and beyond ACL on servers) for |
1da177e4 | 223 | servers which do not support setting and viewing mode bits, |
50c2f753 | 224 | so allowing client to check permissions is useful */ |
2830ba7f | 225 | return generic_permission(inode, mask); |
1da177e4 LT |
226 | } |
227 | ||
e18b890b CL |
228 | static struct kmem_cache *cifs_inode_cachep; |
229 | static struct kmem_cache *cifs_req_cachep; | |
230 | static struct kmem_cache *cifs_mid_cachep; | |
e18b890b | 231 | static struct kmem_cache *cifs_sm_req_cachep; |
1da177e4 LT |
232 | mempool_t *cifs_sm_req_poolp; |
233 | mempool_t *cifs_req_poolp; | |
234 | mempool_t *cifs_mid_poolp; | |
235 | ||
236 | static struct inode * | |
237 | cifs_alloc_inode(struct super_block *sb) | |
238 | { | |
239 | struct cifsInodeInfo *cifs_inode; | |
e94b1766 | 240 | cifs_inode = kmem_cache_alloc(cifs_inode_cachep, GFP_KERNEL); |
1da177e4 LT |
241 | if (!cifs_inode) |
242 | return NULL; | |
243 | cifs_inode->cifsAttrs = 0x20; /* default */ | |
1da177e4 LT |
244 | cifs_inode->time = 0; |
245 | /* Until the file is open and we have gotten oplock | |
246 | info back from the server, can not assume caching of | |
247 | file data or metadata */ | |
c6723628 | 248 | cifs_set_oplock_level(cifs_inode, 0); |
9a8165fc | 249 | cifs_inode->delete_pending = false; |
df2cf170 | 250 | cifs_inode->invalid_mapping = false; |
1da177e4 | 251 | cifs_inode->vfs_inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */ |
fbec9ab9 | 252 | cifs_inode->server_eof = 0; |
20054bd6 JL |
253 | cifs_inode->uniqueid = 0; |
254 | cifs_inode->createtime = 0; | |
50c2f753 | 255 | |
1b2b2126 SF |
256 | /* Can not set i_flags here - they get immediately overwritten |
257 | to zero by the VFS */ | |
258 | /* cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME;*/ | |
1da177e4 LT |
259 | INIT_LIST_HEAD(&cifs_inode->openFileList); |
260 | return &cifs_inode->vfs_inode; | |
261 | } | |
262 | ||
fa0d7e3d NP |
263 | static void cifs_i_callback(struct rcu_head *head) |
264 | { | |
265 | struct inode *inode = container_of(head, struct inode, i_rcu); | |
266 | INIT_LIST_HEAD(&inode->i_dentry); | |
267 | kmem_cache_free(cifs_inode_cachep, CIFS_I(inode)); | |
268 | } | |
269 | ||
1da177e4 LT |
270 | static void |
271 | cifs_destroy_inode(struct inode *inode) | |
272 | { | |
fa0d7e3d | 273 | call_rcu(&inode->i_rcu, cifs_i_callback); |
1da177e4 LT |
274 | } |
275 | ||
9451a9a5 | 276 | static void |
b57922d9 | 277 | cifs_evict_inode(struct inode *inode) |
9451a9a5 | 278 | { |
b57922d9 AV |
279 | truncate_inode_pages(&inode->i_data, 0); |
280 | end_writeback(inode); | |
9451a9a5 SJ |
281 | cifs_fscache_release_inode_cookie(inode); |
282 | } | |
283 | ||
61f98ffd JL |
284 | static void |
285 | cifs_show_address(struct seq_file *s, struct TCP_Server_Info *server) | |
286 | { | |
a9f1b85e PS |
287 | struct sockaddr_in *sa = (struct sockaddr_in *) &server->dstaddr; |
288 | struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *) &server->dstaddr; | |
289 | ||
61f98ffd JL |
290 | seq_printf(s, ",addr="); |
291 | ||
a9f1b85e | 292 | switch (server->dstaddr.ss_family) { |
61f98ffd | 293 | case AF_INET: |
a9f1b85e | 294 | seq_printf(s, "%pI4", &sa->sin_addr.s_addr); |
61f98ffd JL |
295 | break; |
296 | case AF_INET6: | |
a9f1b85e PS |
297 | seq_printf(s, "%pI6", &sa6->sin6_addr.s6_addr); |
298 | if (sa6->sin6_scope_id) | |
299 | seq_printf(s, "%%%u", sa6->sin6_scope_id); | |
61f98ffd JL |
300 | break; |
301 | default: | |
302 | seq_printf(s, "(unknown)"); | |
303 | } | |
304 | } | |
305 | ||
3e715513 JL |
306 | static void |
307 | cifs_show_security(struct seq_file *s, struct TCP_Server_Info *server) | |
308 | { | |
309 | seq_printf(s, ",sec="); | |
310 | ||
311 | switch (server->secType) { | |
312 | case LANMAN: | |
313 | seq_printf(s, "lanman"); | |
314 | break; | |
315 | case NTLMv2: | |
316 | seq_printf(s, "ntlmv2"); | |
317 | break; | |
318 | case NTLM: | |
319 | seq_printf(s, "ntlm"); | |
320 | break; | |
321 | case Kerberos: | |
322 | seq_printf(s, "krb5"); | |
323 | break; | |
324 | case RawNTLMSSP: | |
325 | seq_printf(s, "ntlmssp"); | |
326 | break; | |
327 | default: | |
328 | /* shouldn't ever happen */ | |
329 | seq_printf(s, "unknown"); | |
330 | break; | |
331 | } | |
332 | ||
333 | if (server->sec_mode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) | |
334 | seq_printf(s, "i"); | |
335 | } | |
336 | ||
1da177e4 LT |
337 | /* |
338 | * cifs_show_options() is for displaying mount options in /proc/mounts. | |
339 | * Not all settable options are displayed but most of the important | |
340 | * ones are. | |
341 | */ | |
342 | static int | |
34c80b1d | 343 | cifs_show_options(struct seq_file *s, struct dentry *root) |
1da177e4 | 344 | { |
34c80b1d | 345 | struct cifs_sb_info *cifs_sb = CIFS_SB(root->d_sb); |
96daf2b0 | 346 | struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb); |
3eb9a889 BG |
347 | struct sockaddr *srcaddr; |
348 | srcaddr = (struct sockaddr *)&tcon->ses->server->srcaddr; | |
8616e0fc | 349 | |
3e715513 JL |
350 | cifs_show_security(s, tcon->ses->server); |
351 | ||
8e047d09 | 352 | seq_printf(s, ",unc=%s", tcon->treeName); |
29e07c82 JL |
353 | |
354 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER) | |
355 | seq_printf(s, ",multiuser"); | |
8727c8a8 SF |
356 | else if (tcon->ses->user_name) |
357 | seq_printf(s, ",username=%s", tcon->ses->user_name); | |
29e07c82 | 358 | |
8616e0fc JL |
359 | if (tcon->ses->domainName) |
360 | seq_printf(s, ",domain=%s", tcon->ses->domainName); | |
361 | ||
3eb9a889 BG |
362 | if (srcaddr->sa_family != AF_UNSPEC) { |
363 | struct sockaddr_in *saddr4; | |
364 | struct sockaddr_in6 *saddr6; | |
365 | saddr4 = (struct sockaddr_in *)srcaddr; | |
366 | saddr6 = (struct sockaddr_in6 *)srcaddr; | |
367 | if (srcaddr->sa_family == AF_INET6) | |
368 | seq_printf(s, ",srcaddr=%pI6c", | |
369 | &saddr6->sin6_addr); | |
370 | else if (srcaddr->sa_family == AF_INET) | |
371 | seq_printf(s, ",srcaddr=%pI4", | |
372 | &saddr4->sin_addr.s_addr); | |
373 | else | |
374 | seq_printf(s, ",srcaddr=BAD-AF:%i", | |
375 | (int)(srcaddr->sa_family)); | |
376 | } | |
377 | ||
8616e0fc | 378 | seq_printf(s, ",uid=%d", cifs_sb->mnt_uid); |
340481a3 JL |
379 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID) |
380 | seq_printf(s, ",forceuid"); | |
4486d6ed JL |
381 | else |
382 | seq_printf(s, ",noforceuid"); | |
340481a3 | 383 | |
8616e0fc | 384 | seq_printf(s, ",gid=%d", cifs_sb->mnt_gid); |
340481a3 JL |
385 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID) |
386 | seq_printf(s, ",forcegid"); | |
4486d6ed JL |
387 | else |
388 | seq_printf(s, ",noforcegid"); | |
8616e0fc | 389 | |
61f98ffd | 390 | cifs_show_address(s, tcon->ses->server); |
1da177e4 | 391 | |
8616e0fc | 392 | if (!tcon->unix_ext) |
5206efd6 | 393 | seq_printf(s, ",file_mode=0%ho,dir_mode=0%ho", |
2b280fab SF |
394 | cifs_sb->mnt_file_mode, |
395 | cifs_sb->mnt_dir_mode); | |
8616e0fc JL |
396 | if (tcon->seal) |
397 | seq_printf(s, ",seal"); | |
398 | if (tcon->nocase) | |
399 | seq_printf(s, ",nocase"); | |
400 | if (tcon->retry) | |
401 | seq_printf(s, ",hard"); | |
d4ffff1f PS |
402 | if (tcon->unix_ext) |
403 | seq_printf(s, ",unix"); | |
404 | else | |
405 | seq_printf(s, ",nounix"); | |
8616e0fc JL |
406 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS) |
407 | seq_printf(s, ",posixpaths"); | |
408 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) | |
409 | seq_printf(s, ",setuids"); | |
410 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) | |
411 | seq_printf(s, ",serverino"); | |
d4ffff1f PS |
412 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD) |
413 | seq_printf(s, ",rwpidforward"); | |
414 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) | |
415 | seq_printf(s, ",forcemand"); | |
8616e0fc JL |
416 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO) |
417 | seq_printf(s, ",directio"); | |
418 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR) | |
419 | seq_printf(s, ",nouser_xattr"); | |
420 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR) | |
421 | seq_printf(s, ",mapchars"); | |
422 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) | |
423 | seq_printf(s, ",sfu"); | |
424 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL) | |
425 | seq_printf(s, ",nobrl"); | |
426 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) | |
427 | seq_printf(s, ",cifsacl"); | |
428 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM) | |
429 | seq_printf(s, ",dynperm"); | |
34c80b1d | 430 | if (root->d_sb->s_flags & MS_POSIXACL) |
8616e0fc | 431 | seq_printf(s, ",acl"); |
736a3320 SM |
432 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS) |
433 | seq_printf(s, ",mfsymlinks"); | |
476428f8 SJ |
434 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_FSCACHE) |
435 | seq_printf(s, ",fsc"); | |
71c424ba SF |
436 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC) |
437 | seq_printf(s, ",nostrictsync"); | |
438 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) | |
439 | seq_printf(s, ",noperm"); | |
875cd043 SP |
440 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) |
441 | seq_printf(s, ",strictcache"); | |
8616e0fc JL |
442 | |
443 | seq_printf(s, ",rsize=%d", cifs_sb->rsize); | |
444 | seq_printf(s, ",wsize=%d", cifs_sb->wsize); | |
6d20e840 SJ |
445 | /* convert actimeo and display it in seconds */ |
446 | seq_printf(s, ",actimeo=%lu", cifs_sb->actimeo / HZ); | |
8616e0fc | 447 | |
1da177e4 LT |
448 | return 0; |
449 | } | |
450 | ||
42faad99 | 451 | static void cifs_umount_begin(struct super_block *sb) |
68058e75 | 452 | { |
42faad99 | 453 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); |
96daf2b0 | 454 | struct cifs_tcon *tcon; |
68058e75 | 455 | |
4523cc30 | 456 | if (cifs_sb == NULL) |
9e2e85f8 SF |
457 | return; |
458 | ||
0d424ad0 | 459 | tcon = cifs_sb_master_tcon(cifs_sb); |
f1987b44 | 460 | |
3f9bcca7 | 461 | spin_lock(&cifs_tcp_ses_lock); |
ad8034f1 SF |
462 | if ((tcon->tc_count > 1) || (tcon->tidStatus == CifsExiting)) { |
463 | /* we have other mounts to same share or we have | |
464 | already tried to force umount this and woken up | |
465 | all waiting network requests, nothing to do */ | |
3f9bcca7 | 466 | spin_unlock(&cifs_tcp_ses_lock); |
ad8034f1 SF |
467 | return; |
468 | } else if (tcon->tc_count == 1) | |
5e1253b5 | 469 | tcon->tidStatus = CifsExiting; |
3f9bcca7 | 470 | spin_unlock(&cifs_tcp_ses_lock); |
5e1253b5 | 471 | |
3a5ff61c | 472 | /* cancel_brl_requests(tcon); */ /* BB mark all brl mids as exiting */ |
7b7abfe3 | 473 | /* cancel_notify_requests(tcon); */ |
50c2f753 | 474 | if (tcon->ses && tcon->ses->server) { |
b6b38f70 | 475 | cFYI(1, "wake up tasks now - umount begin not complete"); |
9e2e85f8 | 476 | wake_up_all(&tcon->ses->server->request_q); |
6ab16d24 SF |
477 | wake_up_all(&tcon->ses->server->response_q); |
478 | msleep(1); /* yield */ | |
479 | /* we have to kick the requests once more */ | |
480 | wake_up_all(&tcon->ses->server->response_q); | |
481 | msleep(1); | |
5e1253b5 | 482 | } |
68058e75 SF |
483 | |
484 | return; | |
485 | } | |
68058e75 | 486 | |
bf97d287 | 487 | #ifdef CONFIG_CIFS_STATS2 |
64132379 | 488 | static int cifs_show_stats(struct seq_file *s, struct dentry *root) |
bf97d287 SF |
489 | { |
490 | /* BB FIXME */ | |
491 | return 0; | |
492 | } | |
493 | #endif | |
494 | ||
1da177e4 LT |
495 | static int cifs_remount(struct super_block *sb, int *flags, char *data) |
496 | { | |
497 | *flags |= MS_NODIRATIME; | |
498 | return 0; | |
499 | } | |
500 | ||
45321ac5 | 501 | static int cifs_drop_inode(struct inode *inode) |
12420ac3 JL |
502 | { |
503 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); | |
504 | ||
45321ac5 AV |
505 | /* no serverino => unconditional eviction */ |
506 | return !(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) || | |
507 | generic_drop_inode(inode); | |
12420ac3 JL |
508 | } |
509 | ||
ee9b6d61 | 510 | static const struct super_operations cifs_super_ops = { |
1da177e4 LT |
511 | .statfs = cifs_statfs, |
512 | .alloc_inode = cifs_alloc_inode, | |
513 | .destroy_inode = cifs_destroy_inode, | |
12420ac3 | 514 | .drop_inode = cifs_drop_inode, |
b57922d9 | 515 | .evict_inode = cifs_evict_inode, |
12420ac3 JL |
516 | /* .delete_inode = cifs_delete_inode, */ /* Do not need above |
517 | function unless later we add lazy close of inodes or unless the | |
50c2f753 SF |
518 | kernel forgets to call us with the same number of releases (closes) |
519 | as opens */ | |
1da177e4 | 520 | .show_options = cifs_show_options, |
7b7abfe3 | 521 | .umount_begin = cifs_umount_begin, |
1da177e4 | 522 | .remount_fs = cifs_remount, |
bf97d287 | 523 | #ifdef CONFIG_CIFS_STATS2 |
f46d3e11 | 524 | .show_stats = cifs_show_stats, |
bf97d287 | 525 | #endif |
1da177e4 LT |
526 | }; |
527 | ||
f87d39d9 SF |
528 | /* |
529 | * Get root dentry from superblock according to prefix path mount option. | |
530 | * Return dentry with refcount + 1 on success and NULL otherwise. | |
531 | */ | |
532 | static struct dentry * | |
533 | cifs_get_root(struct smb_vol *vol, struct super_block *sb) | |
534 | { | |
fec11dd9 | 535 | struct dentry *dentry; |
f87d39d9 | 536 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); |
fec11dd9 AV |
537 | char *full_path = NULL; |
538 | char *s, *p; | |
f87d39d9 SF |
539 | char sep; |
540 | ||
541 | full_path = cifs_build_path_to_root(vol, cifs_sb, | |
542 | cifs_sb_master_tcon(cifs_sb)); | |
543 | if (full_path == NULL) | |
9403c9c5 | 544 | return ERR_PTR(-ENOMEM); |
f87d39d9 SF |
545 | |
546 | cFYI(1, "Get root dentry for %s", full_path); | |
547 | ||
f87d39d9 | 548 | sep = CIFS_DIR_SEP(cifs_sb); |
fec11dd9 AV |
549 | dentry = dget(sb->s_root); |
550 | p = s = full_path; | |
551 | ||
552 | do { | |
553 | struct inode *dir = dentry->d_inode; | |
554 | struct dentry *child; | |
555 | ||
5b980b01 PS |
556 | if (!dir) { |
557 | dput(dentry); | |
558 | dentry = ERR_PTR(-ENOENT); | |
559 | break; | |
560 | } | |
561 | ||
fec11dd9 AV |
562 | /* skip separators */ |
563 | while (*s == sep) | |
564 | s++; | |
565 | if (!*s) | |
566 | break; | |
567 | p = s++; | |
568 | /* next separator */ | |
569 | while (*s && *s != sep) | |
570 | s++; | |
571 | ||
572 | mutex_lock(&dir->i_mutex); | |
573 | child = lookup_one_len(p, dentry, s - p); | |
574 | mutex_unlock(&dir->i_mutex); | |
575 | dput(dentry); | |
576 | dentry = child; | |
577 | } while (!IS_ERR(dentry)); | |
f87d39d9 | 578 | kfree(full_path); |
fec11dd9 | 579 | return dentry; |
f87d39d9 SF |
580 | } |
581 | ||
ee01a14d AV |
582 | static int cifs_set_super(struct super_block *sb, void *data) |
583 | { | |
584 | struct cifs_mnt_data *mnt_data = data; | |
585 | sb->s_fs_info = mnt_data->cifs_sb; | |
586 | return set_anon_super(sb, NULL); | |
587 | } | |
588 | ||
d753ed97 AV |
589 | static struct dentry * |
590 | cifs_do_mount(struct file_system_type *fs_type, | |
724d9f1c | 591 | int flags, const char *dev_name, void *data) |
1da177e4 LT |
592 | { |
593 | int rc; | |
db719222 | 594 | struct super_block *sb; |
724d9f1c PS |
595 | struct cifs_sb_info *cifs_sb; |
596 | struct smb_vol *volume_info; | |
25c7f41e | 597 | struct cifs_mnt_data mnt_data; |
724d9f1c | 598 | struct dentry *root; |
1da177e4 | 599 | |
b6b38f70 | 600 | cFYI(1, "Devname: %s flags: %d ", dev_name, flags); |
1da177e4 | 601 | |
04db79b0 JL |
602 | volume_info = cifs_get_volume_info((char *)data, dev_name); |
603 | if (IS_ERR(volume_info)) | |
604 | return ERR_CAST(volume_info); | |
724d9f1c PS |
605 | |
606 | cifs_sb = kzalloc(sizeof(struct cifs_sb_info), GFP_KERNEL); | |
607 | if (cifs_sb == NULL) { | |
608 | root = ERR_PTR(-ENOMEM); | |
5c4f1ad7 | 609 | goto out_nls; |
724d9f1c PS |
610 | } |
611 | ||
5d3bc605 AV |
612 | cifs_sb->mountdata = kstrndup(data, PAGE_SIZE, GFP_KERNEL); |
613 | if (cifs_sb->mountdata == NULL) { | |
614 | root = ERR_PTR(-ENOMEM); | |
5c4f1ad7 | 615 | goto out_cifs_sb; |
5d3bc605 AV |
616 | } |
617 | ||
724d9f1c PS |
618 | cifs_setup_cifs_sb(volume_info, cifs_sb); |
619 | ||
97d1152a AV |
620 | rc = cifs_mount(cifs_sb, volume_info); |
621 | if (rc) { | |
622 | if (!(flags & MS_SILENT)) | |
623 | cERROR(1, "cifs_mount failed w/return code = %d", rc); | |
624 | root = ERR_PTR(rc); | |
5c4f1ad7 | 625 | goto out_mountdata; |
97d1152a AV |
626 | } |
627 | ||
25c7f41e PS |
628 | mnt_data.vol = volume_info; |
629 | mnt_data.cifs_sb = cifs_sb; | |
630 | mnt_data.flags = flags; | |
631 | ||
ee01a14d | 632 | sb = sget(fs_type, cifs_match_super, cifs_set_super, &mnt_data); |
724d9f1c | 633 | if (IS_ERR(sb)) { |
724d9f1c | 634 | root = ERR_CAST(sb); |
97d1152a | 635 | cifs_umount(cifs_sb); |
d757d71b | 636 | goto out; |
724d9f1c | 637 | } |
1da177e4 | 638 | |
ee01a14d | 639 | if (sb->s_root) { |
25c7f41e | 640 | cFYI(1, "Use existing superblock"); |
97d1152a | 641 | cifs_umount(cifs_sb); |
5c4f1ad7 AV |
642 | } else { |
643 | sb->s_flags = flags; | |
644 | /* BB should we make this contingent on mount parm? */ | |
645 | sb->s_flags |= MS_NODIRATIME | MS_NOATIME; | |
646 | ||
647 | rc = cifs_read_super(sb); | |
648 | if (rc) { | |
649 | root = ERR_PTR(rc); | |
650 | goto out_super; | |
651 | } | |
b2e5cd33 | 652 | |
5c4f1ad7 | 653 | sb->s_flags |= MS_ACTIVE; |
1da177e4 | 654 | } |
724d9f1c | 655 | |
f87d39d9 | 656 | root = cifs_get_root(volume_info, sb); |
9403c9c5 | 657 | if (IS_ERR(root)) |
f87d39d9 | 658 | goto out_super; |
25c7f41e | 659 | |
f87d39d9 | 660 | cFYI(1, "dentry root is: %p", root); |
641a58d6 | 661 | goto out; |
724d9f1c | 662 | |
641a58d6 | 663 | out_super: |
641a58d6 | 664 | deactivate_locked_super(sb); |
641a58d6 | 665 | out: |
f9e59bcb | 666 | cifs_cleanup_volume_info(volume_info); |
724d9f1c | 667 | return root; |
5c4f1ad7 AV |
668 | |
669 | out_mountdata: | |
670 | kfree(cifs_sb->mountdata); | |
671 | out_cifs_sb: | |
672 | kfree(cifs_sb); | |
673 | out_nls: | |
674 | unload_nls(volume_info->local_nls); | |
675 | goto out; | |
1da177e4 LT |
676 | } |
677 | ||
027445c3 BP |
678 | static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov, |
679 | unsigned long nr_segs, loff_t pos) | |
1da177e4 | 680 | { |
e6a00296 | 681 | struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode; |
1da177e4 | 682 | ssize_t written; |
72432ffc | 683 | int rc; |
1da177e4 | 684 | |
027445c3 | 685 | written = generic_file_aio_write(iocb, iov, nr_segs, pos); |
72432ffc PS |
686 | |
687 | if (CIFS_I(inode)->clientCanCacheAll) | |
688 | return written; | |
689 | ||
690 | rc = filemap_fdatawrite(inode->i_mapping); | |
691 | if (rc) | |
692 | cFYI(1, "cifs_file_aio_write: %d rc on %p inode", rc, inode); | |
693 | ||
1da177e4 LT |
694 | return written; |
695 | } | |
696 | ||
c32a0b68 SF |
697 | static loff_t cifs_llseek(struct file *file, loff_t offset, int origin) |
698 | { | |
06222e49 JB |
699 | /* |
700 | * origin == SEEK_END || SEEK_DATA || SEEK_HOLE => we must revalidate | |
701 | * the cached file length | |
702 | */ | |
703 | if (origin != SEEK_SET || origin != SEEK_CUR) { | |
6feb9891 PS |
704 | int rc; |
705 | struct inode *inode = file->f_path.dentry->d_inode; | |
706 | ||
707 | /* | |
708 | * We need to be sure that all dirty pages are written and the | |
709 | * server has the newest file length. | |
710 | */ | |
711 | if (!CIFS_I(inode)->clientCanCacheRead && inode->i_mapping && | |
712 | inode->i_mapping->nrpages != 0) { | |
713 | rc = filemap_fdatawait(inode->i_mapping); | |
156ecb2d SF |
714 | if (rc) { |
715 | mapping_set_error(inode->i_mapping, rc); | |
716 | return rc; | |
717 | } | |
6feb9891 PS |
718 | } |
719 | /* | |
720 | * Some applications poll for the file length in this strange | |
721 | * way so we must seek to end on non-oplocked files by | |
722 | * setting the revalidate time to zero. | |
723 | */ | |
724 | CIFS_I(inode)->time = 0; | |
725 | ||
726 | rc = cifs_revalidate_file_attr(file); | |
727 | if (rc < 0) | |
728 | return (loff_t)rc; | |
c32a0b68 | 729 | } |
ef3d0fd2 | 730 | return generic_file_llseek(file, offset, origin); |
c32a0b68 SF |
731 | } |
732 | ||
84210e91 SF |
733 | static int cifs_setlease(struct file *file, long arg, struct file_lock **lease) |
734 | { | |
b89f4321 AB |
735 | /* note that this is called by vfs setlease with lock_flocks held |
736 | to protect *lease from going away */ | |
84210e91 | 737 | struct inode *inode = file->f_path.dentry->d_inode; |
ba00ba64 | 738 | struct cifsFileInfo *cfile = file->private_data; |
84210e91 SF |
739 | |
740 | if (!(S_ISREG(inode->i_mode))) | |
741 | return -EINVAL; | |
742 | ||
743 | /* check if file is oplocked */ | |
744 | if (((arg == F_RDLCK) && | |
745 | (CIFS_I(inode)->clientCanCacheRead)) || | |
746 | ((arg == F_WRLCK) && | |
747 | (CIFS_I(inode)->clientCanCacheAll))) | |
748 | return generic_setlease(file, arg, lease); | |
13cfb733 JL |
749 | else if (tlink_tcon(cfile->tlink)->local_lease && |
750 | !CIFS_I(inode)->clientCanCacheRead) | |
84210e91 SF |
751 | /* If the server claims to support oplock on this |
752 | file, then we still need to check oplock even | |
753 | if the local_lease mount option is set, but there | |
754 | are servers which do not support oplock for which | |
755 | this mount option may be useful if the user | |
756 | knows that the file won't be changed on the server | |
757 | by anyone else */ | |
758 | return generic_setlease(file, arg, lease); | |
51ee4b84 | 759 | else |
84210e91 SF |
760 | return -EAGAIN; |
761 | } | |
84210e91 | 762 | |
e6ab1582 | 763 | struct file_system_type cifs_fs_type = { |
1da177e4 LT |
764 | .owner = THIS_MODULE, |
765 | .name = "cifs", | |
d753ed97 | 766 | .mount = cifs_do_mount, |
6d686175 | 767 | .kill_sb = cifs_kill_sb, |
1da177e4 LT |
768 | /* .fs_flags */ |
769 | }; | |
754661f1 | 770 | const struct inode_operations cifs_dir_inode_ops = { |
1da177e4 LT |
771 | .create = cifs_create, |
772 | .lookup = cifs_lookup, | |
773 | .getattr = cifs_getattr, | |
774 | .unlink = cifs_unlink, | |
775 | .link = cifs_hardlink, | |
776 | .mkdir = cifs_mkdir, | |
777 | .rmdir = cifs_rmdir, | |
778 | .rename = cifs_rename, | |
779 | .permission = cifs_permission, | |
780 | /* revalidate:cifs_revalidate, */ | |
781 | .setattr = cifs_setattr, | |
782 | .symlink = cifs_symlink, | |
783 | .mknod = cifs_mknod, | |
784 | #ifdef CONFIG_CIFS_XATTR | |
785 | .setxattr = cifs_setxattr, | |
786 | .getxattr = cifs_getxattr, | |
787 | .listxattr = cifs_listxattr, | |
788 | .removexattr = cifs_removexattr, | |
789 | #endif | |
790 | }; | |
791 | ||
754661f1 | 792 | const struct inode_operations cifs_file_inode_ops = { |
1da177e4 LT |
793 | /* revalidate:cifs_revalidate, */ |
794 | .setattr = cifs_setattr, | |
795 | .getattr = cifs_getattr, /* do we need this anymore? */ | |
796 | .rename = cifs_rename, | |
797 | .permission = cifs_permission, | |
798 | #ifdef CONFIG_CIFS_XATTR | |
799 | .setxattr = cifs_setxattr, | |
800 | .getxattr = cifs_getxattr, | |
801 | .listxattr = cifs_listxattr, | |
802 | .removexattr = cifs_removexattr, | |
50c2f753 | 803 | #endif |
1da177e4 LT |
804 | }; |
805 | ||
754661f1 | 806 | const struct inode_operations cifs_symlink_inode_ops = { |
50c2f753 | 807 | .readlink = generic_readlink, |
1da177e4 LT |
808 | .follow_link = cifs_follow_link, |
809 | .put_link = cifs_put_link, | |
810 | .permission = cifs_permission, | |
811 | /* BB add the following two eventually */ | |
812 | /* revalidate: cifs_revalidate, | |
813 | setattr: cifs_notify_change, *//* BB do we need notify change */ | |
814 | #ifdef CONFIG_CIFS_XATTR | |
815 | .setxattr = cifs_setxattr, | |
816 | .getxattr = cifs_getxattr, | |
817 | .listxattr = cifs_listxattr, | |
818 | .removexattr = cifs_removexattr, | |
50c2f753 | 819 | #endif |
1da177e4 LT |
820 | }; |
821 | ||
4b6f5d20 | 822 | const struct file_operations cifs_file_ops = { |
87c89dd7 SF |
823 | .read = do_sync_read, |
824 | .write = do_sync_write, | |
87c89dd7 SF |
825 | .aio_read = generic_file_aio_read, |
826 | .aio_write = cifs_file_aio_write, | |
1da177e4 LT |
827 | .open = cifs_open, |
828 | .release = cifs_close, | |
829 | .lock = cifs_lock, | |
830 | .fsync = cifs_fsync, | |
831 | .flush = cifs_flush, | |
832 | .mmap = cifs_file_mmap, | |
5ffc4ef4 | 833 | .splice_read = generic_file_splice_read, |
c32a0b68 | 834 | .llseek = cifs_llseek, |
c67593a0 | 835 | #ifdef CONFIG_CIFS_POSIX |
f9ddcca4 | 836 | .unlocked_ioctl = cifs_ioctl, |
c67593a0 | 837 | #endif /* CONFIG_CIFS_POSIX */ |
84210e91 | 838 | .setlease = cifs_setlease, |
1da177e4 LT |
839 | }; |
840 | ||
8be7e6ba PS |
841 | const struct file_operations cifs_file_strict_ops = { |
842 | .read = do_sync_read, | |
843 | .write = do_sync_write, | |
a70307ee | 844 | .aio_read = cifs_strict_readv, |
72432ffc | 845 | .aio_write = cifs_strict_writev, |
8be7e6ba PS |
846 | .open = cifs_open, |
847 | .release = cifs_close, | |
848 | .lock = cifs_lock, | |
849 | .fsync = cifs_strict_fsync, | |
850 | .flush = cifs_flush, | |
7a6a19b1 | 851 | .mmap = cifs_file_strict_mmap, |
8be7e6ba PS |
852 | .splice_read = generic_file_splice_read, |
853 | .llseek = cifs_llseek, | |
854 | #ifdef CONFIG_CIFS_POSIX | |
855 | .unlocked_ioctl = cifs_ioctl, | |
856 | #endif /* CONFIG_CIFS_POSIX */ | |
857 | .setlease = cifs_setlease, | |
858 | }; | |
859 | ||
4b6f5d20 | 860 | const struct file_operations cifs_file_direct_ops = { |
0b81c1c4 PS |
861 | /* BB reevaluate whether they can be done with directio, no cache */ |
862 | .read = do_sync_read, | |
863 | .write = do_sync_write, | |
864 | .aio_read = cifs_user_readv, | |
865 | .aio_write = cifs_user_writev, | |
1da177e4 LT |
866 | .open = cifs_open, |
867 | .release = cifs_close, | |
868 | .lock = cifs_lock, | |
869 | .fsync = cifs_fsync, | |
870 | .flush = cifs_flush, | |
a994b8fa | 871 | .mmap = cifs_file_mmap, |
5ffc4ef4 | 872 | .splice_read = generic_file_splice_read, |
c67593a0 | 873 | #ifdef CONFIG_CIFS_POSIX |
f9ddcca4 | 874 | .unlocked_ioctl = cifs_ioctl, |
c67593a0 | 875 | #endif /* CONFIG_CIFS_POSIX */ |
c32a0b68 | 876 | .llseek = cifs_llseek, |
84210e91 | 877 | .setlease = cifs_setlease, |
1da177e4 | 878 | }; |
8be7e6ba | 879 | |
4b6f5d20 | 880 | const struct file_operations cifs_file_nobrl_ops = { |
87c89dd7 SF |
881 | .read = do_sync_read, |
882 | .write = do_sync_write, | |
87c89dd7 SF |
883 | .aio_read = generic_file_aio_read, |
884 | .aio_write = cifs_file_aio_write, | |
885 | .open = cifs_open, | |
886 | .release = cifs_close, | |
887 | .fsync = cifs_fsync, | |
888 | .flush = cifs_flush, | |
889 | .mmap = cifs_file_mmap, | |
5ffc4ef4 | 890 | .splice_read = generic_file_splice_read, |
c32a0b68 | 891 | .llseek = cifs_llseek, |
8b94bcb9 | 892 | #ifdef CONFIG_CIFS_POSIX |
f9ddcca4 | 893 | .unlocked_ioctl = cifs_ioctl, |
8b94bcb9 | 894 | #endif /* CONFIG_CIFS_POSIX */ |
84210e91 | 895 | .setlease = cifs_setlease, |
8b94bcb9 SF |
896 | }; |
897 | ||
8be7e6ba PS |
898 | const struct file_operations cifs_file_strict_nobrl_ops = { |
899 | .read = do_sync_read, | |
900 | .write = do_sync_write, | |
a70307ee | 901 | .aio_read = cifs_strict_readv, |
72432ffc | 902 | .aio_write = cifs_strict_writev, |
8be7e6ba PS |
903 | .open = cifs_open, |
904 | .release = cifs_close, | |
905 | .fsync = cifs_strict_fsync, | |
906 | .flush = cifs_flush, | |
7a6a19b1 | 907 | .mmap = cifs_file_strict_mmap, |
8be7e6ba PS |
908 | .splice_read = generic_file_splice_read, |
909 | .llseek = cifs_llseek, | |
910 | #ifdef CONFIG_CIFS_POSIX | |
911 | .unlocked_ioctl = cifs_ioctl, | |
912 | #endif /* CONFIG_CIFS_POSIX */ | |
913 | .setlease = cifs_setlease, | |
914 | }; | |
915 | ||
4b6f5d20 | 916 | const struct file_operations cifs_file_direct_nobrl_ops = { |
0b81c1c4 PS |
917 | /* BB reevaluate whether they can be done with directio, no cache */ |
918 | .read = do_sync_read, | |
919 | .write = do_sync_write, | |
920 | .aio_read = cifs_user_readv, | |
921 | .aio_write = cifs_user_writev, | |
87c89dd7 SF |
922 | .open = cifs_open, |
923 | .release = cifs_close, | |
924 | .fsync = cifs_fsync, | |
925 | .flush = cifs_flush, | |
810627a0 | 926 | .mmap = cifs_file_mmap, |
5ffc4ef4 | 927 | .splice_read = generic_file_splice_read, |
8b94bcb9 | 928 | #ifdef CONFIG_CIFS_POSIX |
f9ddcca4 | 929 | .unlocked_ioctl = cifs_ioctl, |
8b94bcb9 | 930 | #endif /* CONFIG_CIFS_POSIX */ |
c32a0b68 | 931 | .llseek = cifs_llseek, |
84210e91 | 932 | .setlease = cifs_setlease, |
8b94bcb9 | 933 | }; |
1da177e4 | 934 | |
4b6f5d20 | 935 | const struct file_operations cifs_dir_ops = { |
1da177e4 LT |
936 | .readdir = cifs_readdir, |
937 | .release = cifs_closedir, | |
938 | .read = generic_read_dir, | |
f9ddcca4 | 939 | .unlocked_ioctl = cifs_ioctl, |
3222a3e5 | 940 | .llseek = generic_file_llseek, |
1da177e4 LT |
941 | }; |
942 | ||
943 | static void | |
51cc5068 | 944 | cifs_init_once(void *inode) |
1da177e4 LT |
945 | { |
946 | struct cifsInodeInfo *cifsi = inode; | |
947 | ||
a35afb83 | 948 | inode_init_once(&cifsi->vfs_inode); |
d59dad2b PS |
949 | INIT_LIST_HEAD(&cifsi->llist); |
950 | mutex_init(&cifsi->lock_mutex); | |
1da177e4 LT |
951 | } |
952 | ||
953 | static int | |
954 | cifs_init_inodecache(void) | |
955 | { | |
956 | cifs_inode_cachep = kmem_cache_create("cifs_inode_cache", | |
26f57364 | 957 | sizeof(struct cifsInodeInfo), |
fffb60f9 PJ |
958 | 0, (SLAB_RECLAIM_ACCOUNT| |
959 | SLAB_MEM_SPREAD), | |
20c2df83 | 960 | cifs_init_once); |
1da177e4 LT |
961 | if (cifs_inode_cachep == NULL) |
962 | return -ENOMEM; | |
963 | ||
964 | return 0; | |
965 | } | |
966 | ||
967 | static void | |
968 | cifs_destroy_inodecache(void) | |
969 | { | |
1a1d92c1 | 970 | kmem_cache_destroy(cifs_inode_cachep); |
1da177e4 LT |
971 | } |
972 | ||
973 | static int | |
974 | cifs_init_request_bufs(void) | |
975 | { | |
4523cc30 | 976 | if (CIFSMaxBufSize < 8192) { |
1da177e4 LT |
977 | /* Buffer size can not be smaller than 2 * PATH_MAX since maximum |
978 | Unicode path name has to fit in any SMB/CIFS path based frames */ | |
979 | CIFSMaxBufSize = 8192; | |
980 | } else if (CIFSMaxBufSize > 1024*127) { | |
981 | CIFSMaxBufSize = 1024 * 127; | |
982 | } else { | |
983 | CIFSMaxBufSize &= 0x1FE00; /* Round size to even 512 byte mult*/ | |
984 | } | |
b6b38f70 | 985 | /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */ |
1da177e4 LT |
986 | cifs_req_cachep = kmem_cache_create("cifs_request", |
987 | CIFSMaxBufSize + | |
988 | MAX_CIFS_HDR_SIZE, 0, | |
20c2df83 | 989 | SLAB_HWCACHE_ALIGN, NULL); |
1da177e4 LT |
990 | if (cifs_req_cachep == NULL) |
991 | return -ENOMEM; | |
992 | ||
4523cc30 | 993 | if (cifs_min_rcv < 1) |
1da177e4 LT |
994 | cifs_min_rcv = 1; |
995 | else if (cifs_min_rcv > 64) { | |
996 | cifs_min_rcv = 64; | |
b6b38f70 | 997 | cERROR(1, "cifs_min_rcv set to maximum (64)"); |
1da177e4 LT |
998 | } |
999 | ||
93d2341c MD |
1000 | cifs_req_poolp = mempool_create_slab_pool(cifs_min_rcv, |
1001 | cifs_req_cachep); | |
1da177e4 | 1002 | |
4523cc30 | 1003 | if (cifs_req_poolp == NULL) { |
1da177e4 LT |
1004 | kmem_cache_destroy(cifs_req_cachep); |
1005 | return -ENOMEM; | |
1006 | } | |
ec637e3f | 1007 | /* MAX_CIFS_SMALL_BUFFER_SIZE bytes is enough for most SMB responses and |
1da177e4 LT |
1008 | almost all handle based requests (but not write response, nor is it |
1009 | sufficient for path based requests). A smaller size would have | |
50c2f753 | 1010 | been more efficient (compacting multiple slab items on one 4k page) |
1da177e4 LT |
1011 | for the case in which debug was on, but this larger size allows |
1012 | more SMBs to use small buffer alloc and is still much more | |
6dc0f87e | 1013 | efficient to alloc 1 per page off the slab compared to 17K (5page) |
1da177e4 LT |
1014 | alloc of large cifs buffers even when page debugging is on */ |
1015 | cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq", | |
6dc0f87e | 1016 | MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN, |
20c2df83 | 1017 | NULL); |
1da177e4 LT |
1018 | if (cifs_sm_req_cachep == NULL) { |
1019 | mempool_destroy(cifs_req_poolp); | |
1020 | kmem_cache_destroy(cifs_req_cachep); | |
6dc0f87e | 1021 | return -ENOMEM; |
1da177e4 LT |
1022 | } |
1023 | ||
4523cc30 | 1024 | if (cifs_min_small < 2) |
1da177e4 LT |
1025 | cifs_min_small = 2; |
1026 | else if (cifs_min_small > 256) { | |
1027 | cifs_min_small = 256; | |
b6b38f70 | 1028 | cFYI(1, "cifs_min_small set to maximum (256)"); |
1da177e4 LT |
1029 | } |
1030 | ||
93d2341c MD |
1031 | cifs_sm_req_poolp = mempool_create_slab_pool(cifs_min_small, |
1032 | cifs_sm_req_cachep); | |
1da177e4 | 1033 | |
4523cc30 | 1034 | if (cifs_sm_req_poolp == NULL) { |
1da177e4 LT |
1035 | mempool_destroy(cifs_req_poolp); |
1036 | kmem_cache_destroy(cifs_req_cachep); | |
1037 | kmem_cache_destroy(cifs_sm_req_cachep); | |
1038 | return -ENOMEM; | |
1039 | } | |
1040 | ||
1041 | return 0; | |
1042 | } | |
1043 | ||
1044 | static void | |
1045 | cifs_destroy_request_bufs(void) | |
1046 | { | |
1047 | mempool_destroy(cifs_req_poolp); | |
1a1d92c1 | 1048 | kmem_cache_destroy(cifs_req_cachep); |
1da177e4 | 1049 | mempool_destroy(cifs_sm_req_poolp); |
1a1d92c1 | 1050 | kmem_cache_destroy(cifs_sm_req_cachep); |
1da177e4 LT |
1051 | } |
1052 | ||
1053 | static int | |
1054 | cifs_init_mids(void) | |
1055 | { | |
1056 | cifs_mid_cachep = kmem_cache_create("cifs_mpx_ids", | |
26f57364 SF |
1057 | sizeof(struct mid_q_entry), 0, |
1058 | SLAB_HWCACHE_ALIGN, NULL); | |
1da177e4 LT |
1059 | if (cifs_mid_cachep == NULL) |
1060 | return -ENOMEM; | |
1061 | ||
93d2341c MD |
1062 | /* 3 is a reasonable minimum number of simultaneous operations */ |
1063 | cifs_mid_poolp = mempool_create_slab_pool(3, cifs_mid_cachep); | |
4523cc30 | 1064 | if (cifs_mid_poolp == NULL) { |
1da177e4 LT |
1065 | kmem_cache_destroy(cifs_mid_cachep); |
1066 | return -ENOMEM; | |
1067 | } | |
1068 | ||
1da177e4 LT |
1069 | return 0; |
1070 | } | |
1071 | ||
1072 | static void | |
1073 | cifs_destroy_mids(void) | |
1074 | { | |
1075 | mempool_destroy(cifs_mid_poolp); | |
1a1d92c1 | 1076 | kmem_cache_destroy(cifs_mid_cachep); |
1da177e4 LT |
1077 | } |
1078 | ||
1da177e4 LT |
1079 | static int __init |
1080 | init_cifs(void) | |
1081 | { | |
1082 | int rc = 0; | |
1da177e4 | 1083 | cifs_proc_init(); |
e7ddee90 | 1084 | INIT_LIST_HEAD(&cifs_tcp_ses_list); |
0eff0e26 | 1085 | #ifdef CONFIG_CIFS_DNOTIFY_EXPERIMENTAL /* unused temporarily */ |
4ca9c190 SF |
1086 | INIT_LIST_HEAD(&GlobalDnotifyReqList); |
1087 | INIT_LIST_HEAD(&GlobalDnotifyRsp_Q); | |
0eff0e26 | 1088 | #endif /* was needed for dnotify, and will be needed for inotify when VFS fix */ |
1da177e4 LT |
1089 | /* |
1090 | * Initialize Global counters | |
1091 | */ | |
1092 | atomic_set(&sesInfoAllocCount, 0); | |
1093 | atomic_set(&tconInfoAllocCount, 0); | |
6dc0f87e | 1094 | atomic_set(&tcpSesAllocCount, 0); |
1da177e4 LT |
1095 | atomic_set(&tcpSesReconnectCount, 0); |
1096 | atomic_set(&tconInfoReconnectCount, 0); | |
1097 | ||
1098 | atomic_set(&bufAllocCount, 0); | |
4498eed5 SF |
1099 | atomic_set(&smBufAllocCount, 0); |
1100 | #ifdef CONFIG_CIFS_STATS2 | |
1101 | atomic_set(&totBufAllocCount, 0); | |
1102 | atomic_set(&totSmBufAllocCount, 0); | |
1103 | #endif /* CONFIG_CIFS_STATS2 */ | |
1104 | ||
1da177e4 LT |
1105 | atomic_set(&midCount, 0); |
1106 | GlobalCurrentXid = 0; | |
1107 | GlobalTotalActiveXid = 0; | |
1108 | GlobalMaxActiveXid = 0; | |
3f9bcca7 | 1109 | spin_lock_init(&cifs_tcp_ses_lock); |
4477288a | 1110 | spin_lock_init(&cifs_file_list_lock); |
1da177e4 LT |
1111 | spin_lock_init(&GlobalMid_Lock); |
1112 | ||
4523cc30 | 1113 | if (cifs_max_pending < 2) { |
1da177e4 | 1114 | cifs_max_pending = 2; |
b6b38f70 | 1115 | cFYI(1, "cifs_max_pending set to min of 2"); |
4523cc30 | 1116 | } else if (cifs_max_pending > 256) { |
1da177e4 | 1117 | cifs_max_pending = 256; |
b6b38f70 | 1118 | cFYI(1, "cifs_max_pending set to max of 256"); |
1da177e4 LT |
1119 | } |
1120 | ||
f579cf3c SJ |
1121 | rc = cifs_fscache_register(); |
1122 | if (rc) | |
d3bf5221 | 1123 | goto out_clean_proc; |
f579cf3c | 1124 | |
1da177e4 | 1125 | rc = cifs_init_inodecache(); |
45af7a0f | 1126 | if (rc) |
d3bf5221 | 1127 | goto out_unreg_fscache; |
45af7a0f SF |
1128 | |
1129 | rc = cifs_init_mids(); | |
1130 | if (rc) | |
1131 | goto out_destroy_inodecache; | |
1132 | ||
1133 | rc = cifs_init_request_bufs(); | |
1134 | if (rc) | |
1135 | goto out_destroy_mids; | |
1136 | ||
84a15b93 JL |
1137 | #ifdef CONFIG_CIFS_UPCALL |
1138 | rc = register_key_type(&cifs_spnego_key_type); | |
1139 | if (rc) | |
4d79dba0 SP |
1140 | goto out_destroy_request_bufs; |
1141 | #endif /* CONFIG_CIFS_UPCALL */ | |
1142 | ||
1143 | #ifdef CONFIG_CIFS_ACL | |
1144 | rc = init_cifs_idmap(); | |
1145 | if (rc) | |
c4aca0c0 | 1146 | goto out_register_key_type; |
4d79dba0 SP |
1147 | #endif /* CONFIG_CIFS_ACL */ |
1148 | ||
1149 | rc = register_filesystem(&cifs_fs_type); | |
1150 | if (rc) | |
c4aca0c0 | 1151 | goto out_init_cifs_idmap; |
45af7a0f | 1152 | |
45af7a0f SF |
1153 | return 0; |
1154 | ||
c4aca0c0 | 1155 | out_init_cifs_idmap: |
4d79dba0 SP |
1156 | #ifdef CONFIG_CIFS_ACL |
1157 | exit_cifs_idmap(); | |
c4aca0c0 | 1158 | out_register_key_type: |
4d79dba0 | 1159 | #endif |
84a15b93 | 1160 | #ifdef CONFIG_CIFS_UPCALL |
4d79dba0 | 1161 | unregister_key_type(&cifs_spnego_key_type); |
c4aca0c0 | 1162 | out_destroy_request_bufs: |
1fc7995d | 1163 | #endif |
45af7a0f | 1164 | cifs_destroy_request_bufs(); |
d3bf5221 | 1165 | out_destroy_mids: |
45af7a0f | 1166 | cifs_destroy_mids(); |
d3bf5221 | 1167 | out_destroy_inodecache: |
45af7a0f | 1168 | cifs_destroy_inodecache(); |
d3bf5221 | 1169 | out_unreg_fscache: |
f579cf3c | 1170 | cifs_fscache_unregister(); |
d3bf5221 SF |
1171 | out_clean_proc: |
1172 | cifs_proc_clean(); | |
1da177e4 LT |
1173 | return rc; |
1174 | } | |
1175 | ||
1176 | static void __exit | |
1177 | exit_cifs(void) | |
1178 | { | |
b6b38f70 | 1179 | cFYI(DBG2, "exit_cifs"); |
1da177e4 | 1180 | cifs_proc_clean(); |
f579cf3c | 1181 | cifs_fscache_unregister(); |
6103335d | 1182 | #ifdef CONFIG_CIFS_DFS_UPCALL |
78d31a3a | 1183 | cifs_dfs_release_automount_timer(); |
6103335d | 1184 | #endif |
4d79dba0 SP |
1185 | #ifdef CONFIG_CIFS_ACL |
1186 | cifs_destroy_idmaptrees(); | |
1187 | exit_cifs_idmap(); | |
1188 | #endif | |
84a15b93 JL |
1189 | #ifdef CONFIG_CIFS_UPCALL |
1190 | unregister_key_type(&cifs_spnego_key_type); | |
1da177e4 LT |
1191 | #endif |
1192 | unregister_filesystem(&cifs_fs_type); | |
1193 | cifs_destroy_inodecache(); | |
1194 | cifs_destroy_mids(); | |
1195 | cifs_destroy_request_bufs(); | |
1da177e4 LT |
1196 | } |
1197 | ||
1198 | MODULE_AUTHOR("Steve French <[email protected]>"); | |
6dc0f87e | 1199 | MODULE_LICENSE("GPL"); /* combination of LGPL + GPL source behaves as GPL */ |
1da177e4 | 1200 | MODULE_DESCRIPTION |
63135e08 SF |
1201 | ("VFS to access servers complying with the SNIA CIFS Specification " |
1202 | "e.g. Samba and Windows"); | |
1da177e4 LT |
1203 | MODULE_VERSION(CIFS_VERSION); |
1204 | module_init(init_cifs) | |
1205 | module_exit(exit_cifs) |