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