cifs: add deprecation warnings to strictcache and forcedirectio
[GitHub/mt8127/android_kernel_alcatel_ttab.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;
04912d6a 59unsigned int global_secflags = CIFSSEC_DEF;
3979877e 60/* unsigned int ntlmv2_support = 0; */
1da177e4 61unsigned int sign_CIFS_PDUs = 1;
ee9b6d61 62static const struct super_operations cifs_super_ops;
1da177e4
LT
63unsigned int CIFSMaxBufSize = CIFS_MAX_MSGSIZE;
64module_param(CIFSMaxBufSize, int, 0);
63135e08
SF
65MODULE_PARM_DESC(CIFSMaxBufSize, "Network buffer size (not including header). "
66 "Default: 16384 Range: 8192 to 130048");
1da177e4
LT
67unsigned int cifs_min_rcv = CIFS_MIN_RCV_POOL;
68module_param(cifs_min_rcv, int, 0);
63135e08
SF
69MODULE_PARM_DESC(cifs_min_rcv, "Network buffers in pool. Default: 4 Range: "
70 "1 to 64");
1da177e4
LT
71unsigned int cifs_min_small = 30;
72module_param(cifs_min_small, int, 0);
63135e08
SF
73MODULE_PARM_DESC(cifs_min_small, "Small network buffers in pool. Default: 30 "
74 "Range: 2 to 256");
1da177e4 75unsigned int cifs_max_pending = CIFS_MAX_REQ;
fef33df8 76module_param(cifs_max_pending, int, 0444);
63135e08 77MODULE_PARM_DESC(cifs_max_pending, "Simultaneous requests to server. "
10b9b98e 78 "Default: 32767 Range: 2 to 32767.");
e7504734
SF
79module_param(enable_oplocks, bool, 0644);
80MODULE_PARM_DESC(enable_oplocks, "Enable or disable oplocks (bool). Default:"
81 "y/Y/1");
82
1da177e4
LT
83extern mempool_t *cifs_sm_req_poolp;
84extern mempool_t *cifs_req_poolp;
85extern mempool_t *cifs_mid_poolp;
86
da472fc8
JL
87struct workqueue_struct *cifsiod_wq;
88
1da177e4 89static int
97d1152a 90cifs_read_super(struct super_block *sb)
1da177e4
LT
91{
92 struct inode *inode;
b2e5cd33 93 struct cifs_sb_info *cifs_sb;
1da177e4 94 int rc = 0;
50c2f753 95
b2e5cd33 96 cifs_sb = CIFS_SB(sb);
1da177e4 97
2c6292ae
AV
98 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIXACL)
99 sb->s_flags |= MS_POSIXACL;
100
101 if (cifs_sb_master_tcon(cifs_sb)->ses->capabilities & CAP_LARGE_FILES)
102 sb->s_maxbytes = MAX_LFS_FILESIZE;
103 else
104 sb->s_maxbytes = MAX_NON_LFS;
105
106 /* BB FIXME fix time_gran to be larger for LANMAN sessions */
107 sb->s_time_gran = 100;
108
1da177e4
LT
109 sb->s_magic = CIFS_MAGIC_NUMBER;
110 sb->s_op = &cifs_super_ops;
8044f7f4 111 sb->s_bdi = &cifs_sb->bdi;
1da177e4
LT
112 sb->s_blocksize = CIFS_MAX_MSGSIZE;
113 sb->s_blocksize_bits = 14; /* default 2**14 = CIFS_MAX_MSGSIZE */
9b6763e0 114 inode = cifs_root_iget(sb);
1da177e4 115
ce634ab2
DH
116 if (IS_ERR(inode)) {
117 rc = PTR_ERR(inode);
1da177e4
LT
118 goto out_no_root;
119 }
120
48fde701 121 sb->s_root = d_make_root(inode);
1da177e4
LT
122 if (!sb->s_root) {
123 rc = -ENOMEM;
124 goto out_no_root;
125 }
50c2f753 126
1c929cfe
AV
127 /* do that *after* d_alloc_root() - we want NULL ->d_op for root here */
128 if (cifs_sb_master_tcon(cifs_sb)->nocase)
129 sb->s_d_op = &cifs_ci_dentry_ops;
130 else
131 sb->s_d_op = &cifs_dentry_ops;
132
f3a6a60e 133#ifdef CONFIG_CIFS_NFSD_EXPORT
7521a3c5 134 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) {
b6b38f70 135 cFYI(1, "export ops supported");
7521a3c5
SF
136 sb->s_export_op = &cifs_export_ops;
137 }
f3a6a60e 138#endif /* CONFIG_CIFS_NFSD_EXPORT */
1da177e4
LT
139
140 return 0;
141
142out_no_root:
b6b38f70 143 cERROR(1, "cifs_read_super: get root inode failed");
1da177e4
LT
144 return rc;
145}
146
6d686175
AV
147static void cifs_kill_sb(struct super_block *sb)
148{
149 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
150 kill_anon_super(sb);
98ab494d 151 cifs_umount(cifs_sb);
1da177e4
LT
152}
153
154static int
726c3342 155cifs_statfs(struct dentry *dentry, struct kstatfs *buf)
1da177e4 156{
726c3342 157 struct super_block *sb = dentry->d_sb;
39da9847 158 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
96daf2b0 159 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
c81156dd 160 int rc = -EOPNOTSUPP;
39da9847 161 int xid;
1da177e4
LT
162
163 xid = GetXid();
164
1da177e4
LT
165 buf->f_type = CIFS_MAGIC_NUMBER;
166
39da9847
SF
167 /*
168 * PATH_MAX may be too long - it would presumably be total path,
169 * but note that some servers (includinng Samba 3) have a shorter
170 * maximum path.
171 *
172 * Instead could get the real value via SMB_QUERY_FS_ATTRIBUTE_INFO.
173 */
174 buf->f_namelen = PATH_MAX;
1da177e4
LT
175 buf->f_files = 0; /* undefined */
176 buf->f_ffree = 0; /* unlimited */
177
39da9847
SF
178 /*
179 * We could add a second check for a QFS Unix capability bit
180 */
181 if ((tcon->ses->capabilities & CAP_UNIX) &&
182 (CIFS_POSIX_EXTENSIONS & le64_to_cpu(tcon->fsUnixInfo.Capability)))
183 rc = CIFSSMBQFSPosixInfo(xid, tcon, buf);
184
185 /*
186 * Only need to call the old QFSInfo if failed on newer one,
187 * e.g. by OS/2.
188 **/
189 if (rc && (tcon->ses->capabilities & CAP_NT_SMBS))
190 rc = CIFSSMBQFSInfo(xid, tcon, buf);
191
192 /*
193 * Some old Windows servers also do not support level 103, retry with
194 * older level one if old server failed the previous call or we
195 * bypassed it because we detected that this was an older LANMAN sess
196 */
4523cc30 197 if (rc)
39da9847
SF
198 rc = SMBOldQFSInfo(xid, tcon, buf);
199
1da177e4 200 FreeXid(xid);
39da9847 201 return 0;
1da177e4
LT
202}
203
10556cb2 204static int cifs_permission(struct inode *inode, int mask)
1da177e4
LT
205{
206 struct cifs_sb_info *cifs_sb;
207
208 cifs_sb = CIFS_SB(inode->i_sb);
209
f696a365
MS
210 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) {
211 if ((mask & MAY_EXEC) && !execute_ok(inode))
212 return -EACCES;
213 else
214 return 0;
215 } else /* file mode might have been restricted at mount time
50c2f753 216 on the client (above and beyond ACL on servers) for
1da177e4 217 servers which do not support setting and viewing mode bits,
50c2f753 218 so allowing client to check permissions is useful */
2830ba7f 219 return generic_permission(inode, mask);
1da177e4
LT
220}
221
e18b890b
CL
222static struct kmem_cache *cifs_inode_cachep;
223static struct kmem_cache *cifs_req_cachep;
224static struct kmem_cache *cifs_mid_cachep;
e18b890b 225static struct kmem_cache *cifs_sm_req_cachep;
1da177e4
LT
226mempool_t *cifs_sm_req_poolp;
227mempool_t *cifs_req_poolp;
228mempool_t *cifs_mid_poolp;
229
230static struct inode *
231cifs_alloc_inode(struct super_block *sb)
232{
233 struct cifsInodeInfo *cifs_inode;
e94b1766 234 cifs_inode = kmem_cache_alloc(cifs_inode_cachep, GFP_KERNEL);
1da177e4
LT
235 if (!cifs_inode)
236 return NULL;
237 cifs_inode->cifsAttrs = 0x20; /* default */
1da177e4
LT
238 cifs_inode->time = 0;
239 /* Until the file is open and we have gotten oplock
240 info back from the server, can not assume caching of
241 file data or metadata */
c6723628 242 cifs_set_oplock_level(cifs_inode, 0);
9a8165fc 243 cifs_inode->delete_pending = false;
df2cf170 244 cifs_inode->invalid_mapping = false;
1da177e4 245 cifs_inode->vfs_inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */
fbec9ab9 246 cifs_inode->server_eof = 0;
20054bd6
JL
247 cifs_inode->uniqueid = 0;
248 cifs_inode->createtime = 0;
50c2f753 249
1b2b2126
SF
250 /* Can not set i_flags here - they get immediately overwritten
251 to zero by the VFS */
252/* cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME;*/
1da177e4
LT
253 INIT_LIST_HEAD(&cifs_inode->openFileList);
254 return &cifs_inode->vfs_inode;
255}
256
fa0d7e3d
NP
257static void cifs_i_callback(struct rcu_head *head)
258{
259 struct inode *inode = container_of(head, struct inode, i_rcu);
260 INIT_LIST_HEAD(&inode->i_dentry);
261 kmem_cache_free(cifs_inode_cachep, CIFS_I(inode));
262}
263
1da177e4
LT
264static void
265cifs_destroy_inode(struct inode *inode)
266{
fa0d7e3d 267 call_rcu(&inode->i_rcu, cifs_i_callback);
1da177e4
LT
268}
269
9451a9a5 270static void
b57922d9 271cifs_evict_inode(struct inode *inode)
9451a9a5 272{
b57922d9
AV
273 truncate_inode_pages(&inode->i_data, 0);
274 end_writeback(inode);
9451a9a5
SJ
275 cifs_fscache_release_inode_cookie(inode);
276}
277
61f98ffd
JL
278static void
279cifs_show_address(struct seq_file *s, struct TCP_Server_Info *server)
280{
a9f1b85e
PS
281 struct sockaddr_in *sa = (struct sockaddr_in *) &server->dstaddr;
282 struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *) &server->dstaddr;
283
61f98ffd
JL
284 seq_printf(s, ",addr=");
285
a9f1b85e 286 switch (server->dstaddr.ss_family) {
61f98ffd 287 case AF_INET:
a9f1b85e 288 seq_printf(s, "%pI4", &sa->sin_addr.s_addr);
61f98ffd
JL
289 break;
290 case AF_INET6:
a9f1b85e
PS
291 seq_printf(s, "%pI6", &sa6->sin6_addr.s6_addr);
292 if (sa6->sin6_scope_id)
293 seq_printf(s, "%%%u", sa6->sin6_scope_id);
61f98ffd
JL
294 break;
295 default:
296 seq_printf(s, "(unknown)");
297 }
298}
299
3e715513
JL
300static void
301cifs_show_security(struct seq_file *s, struct TCP_Server_Info *server)
302{
303 seq_printf(s, ",sec=");
304
305 switch (server->secType) {
306 case LANMAN:
307 seq_printf(s, "lanman");
308 break;
309 case NTLMv2:
310 seq_printf(s, "ntlmv2");
311 break;
312 case NTLM:
313 seq_printf(s, "ntlm");
314 break;
315 case Kerberos:
316 seq_printf(s, "krb5");
317 break;
318 case RawNTLMSSP:
319 seq_printf(s, "ntlmssp");
320 break;
321 default:
322 /* shouldn't ever happen */
323 seq_printf(s, "unknown");
324 break;
325 }
326
327 if (server->sec_mode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
328 seq_printf(s, "i");
329}
330
1da177e4
LT
331/*
332 * cifs_show_options() is for displaying mount options in /proc/mounts.
333 * Not all settable options are displayed but most of the important
334 * ones are.
335 */
336static int
34c80b1d 337cifs_show_options(struct seq_file *s, struct dentry *root)
1da177e4 338{
34c80b1d 339 struct cifs_sb_info *cifs_sb = CIFS_SB(root->d_sb);
96daf2b0 340 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
3eb9a889
BG
341 struct sockaddr *srcaddr;
342 srcaddr = (struct sockaddr *)&tcon->ses->server->srcaddr;
8616e0fc 343
3e715513
JL
344 cifs_show_security(s, tcon->ses->server);
345
8e047d09 346 seq_printf(s, ",unc=%s", tcon->treeName);
29e07c82
JL
347
348 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER)
349 seq_printf(s, ",multiuser");
8727c8a8
SF
350 else if (tcon->ses->user_name)
351 seq_printf(s, ",username=%s", tcon->ses->user_name);
29e07c82 352
8616e0fc
JL
353 if (tcon->ses->domainName)
354 seq_printf(s, ",domain=%s", tcon->ses->domainName);
355
3eb9a889
BG
356 if (srcaddr->sa_family != AF_UNSPEC) {
357 struct sockaddr_in *saddr4;
358 struct sockaddr_in6 *saddr6;
359 saddr4 = (struct sockaddr_in *)srcaddr;
360 saddr6 = (struct sockaddr_in6 *)srcaddr;
361 if (srcaddr->sa_family == AF_INET6)
362 seq_printf(s, ",srcaddr=%pI6c",
363 &saddr6->sin6_addr);
364 else if (srcaddr->sa_family == AF_INET)
365 seq_printf(s, ",srcaddr=%pI4",
366 &saddr4->sin_addr.s_addr);
367 else
368 seq_printf(s, ",srcaddr=BAD-AF:%i",
369 (int)(srcaddr->sa_family));
370 }
371
28f88810 372 seq_printf(s, ",uid=%u", cifs_sb->mnt_uid);
340481a3
JL
373 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID)
374 seq_printf(s, ",forceuid");
4486d6ed
JL
375 else
376 seq_printf(s, ",noforceuid");
340481a3 377
28f88810 378 seq_printf(s, ",gid=%u", cifs_sb->mnt_gid);
340481a3
JL
379 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID)
380 seq_printf(s, ",forcegid");
4486d6ed
JL
381 else
382 seq_printf(s, ",noforcegid");
8616e0fc 383
61f98ffd 384 cifs_show_address(s, tcon->ses->server);
1da177e4 385
8616e0fc 386 if (!tcon->unix_ext)
5206efd6 387 seq_printf(s, ",file_mode=0%ho,dir_mode=0%ho",
2b280fab
SF
388 cifs_sb->mnt_file_mode,
389 cifs_sb->mnt_dir_mode);
8616e0fc
JL
390 if (tcon->seal)
391 seq_printf(s, ",seal");
392 if (tcon->nocase)
393 seq_printf(s, ",nocase");
394 if (tcon->retry)
395 seq_printf(s, ",hard");
d4ffff1f
PS
396 if (tcon->unix_ext)
397 seq_printf(s, ",unix");
398 else
399 seq_printf(s, ",nounix");
8616e0fc
JL
400 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)
401 seq_printf(s, ",posixpaths");
402 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID)
403 seq_printf(s, ",setuids");
404 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)
405 seq_printf(s, ",serverino");
d4ffff1f
PS
406 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD)
407 seq_printf(s, ",rwpidforward");
408 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL)
409 seq_printf(s, ",forcemand");
8616e0fc
JL
410 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO)
411 seq_printf(s, ",directio");
412 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
413 seq_printf(s, ",nouser_xattr");
414 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR)
415 seq_printf(s, ",mapchars");
416 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL)
417 seq_printf(s, ",sfu");
418 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
419 seq_printf(s, ",nobrl");
420 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL)
421 seq_printf(s, ",cifsacl");
422 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM)
423 seq_printf(s, ",dynperm");
34c80b1d 424 if (root->d_sb->s_flags & MS_POSIXACL)
8616e0fc 425 seq_printf(s, ",acl");
736a3320
SM
426 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS)
427 seq_printf(s, ",mfsymlinks");
476428f8
SJ
428 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_FSCACHE)
429 seq_printf(s, ",fsc");
71c424ba
SF
430 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC)
431 seq_printf(s, ",nostrictsync");
432 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM)
433 seq_printf(s, ",noperm");
875cd043
SP
434 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO)
435 seq_printf(s, ",strictcache");
3c7c87fd
SP
436 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_BACKUPUID)
437 seq_printf(s, ",backupuid=%u", cifs_sb->mnt_backupuid);
438 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_BACKUPGID)
439 seq_printf(s, ",backupgid=%u", cifs_sb->mnt_backupgid);
8616e0fc 440
28f88810
SP
441 seq_printf(s, ",rsize=%u", cifs_sb->rsize);
442 seq_printf(s, ",wsize=%u", cifs_sb->wsize);
6d20e840 443 /* convert actimeo and display it in seconds */
156d1790 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 */
48a5730e 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
da472fc8
JL
1119 cifsiod_wq = alloc_workqueue("cifsiod", WQ_FREEZABLE|WQ_MEM_RECLAIM, 0);
1120 if (!cifsiod_wq) {
1121 rc = -ENOMEM;
1122 goto out_clean_proc;
1123 }
1124
f579cf3c
SJ
1125 rc = cifs_fscache_register();
1126 if (rc)
da472fc8 1127 goto out_destroy_wq;
f579cf3c 1128
1da177e4 1129 rc = cifs_init_inodecache();
45af7a0f 1130 if (rc)
d3bf5221 1131 goto out_unreg_fscache;
45af7a0f
SF
1132
1133 rc = cifs_init_mids();
1134 if (rc)
1135 goto out_destroy_inodecache;
1136
1137 rc = cifs_init_request_bufs();
1138 if (rc)
1139 goto out_destroy_mids;
1140
84a15b93
JL
1141#ifdef CONFIG_CIFS_UPCALL
1142 rc = register_key_type(&cifs_spnego_key_type);
1143 if (rc)
4d79dba0
SP
1144 goto out_destroy_request_bufs;
1145#endif /* CONFIG_CIFS_UPCALL */
1146
1147#ifdef CONFIG_CIFS_ACL
1148 rc = init_cifs_idmap();
1149 if (rc)
c4aca0c0 1150 goto out_register_key_type;
4d79dba0
SP
1151#endif /* CONFIG_CIFS_ACL */
1152
1153 rc = register_filesystem(&cifs_fs_type);
1154 if (rc)
c4aca0c0 1155 goto out_init_cifs_idmap;
45af7a0f 1156
45af7a0f
SF
1157 return 0;
1158
c4aca0c0 1159out_init_cifs_idmap:
4d79dba0
SP
1160#ifdef CONFIG_CIFS_ACL
1161 exit_cifs_idmap();
c4aca0c0 1162out_register_key_type:
4d79dba0 1163#endif
84a15b93 1164#ifdef CONFIG_CIFS_UPCALL
4d79dba0 1165 unregister_key_type(&cifs_spnego_key_type);
c4aca0c0 1166out_destroy_request_bufs:
1fc7995d 1167#endif
45af7a0f 1168 cifs_destroy_request_bufs();
d3bf5221 1169out_destroy_mids:
45af7a0f 1170 cifs_destroy_mids();
d3bf5221 1171out_destroy_inodecache:
45af7a0f 1172 cifs_destroy_inodecache();
d3bf5221 1173out_unreg_fscache:
f579cf3c 1174 cifs_fscache_unregister();
da472fc8
JL
1175out_destroy_wq:
1176 destroy_workqueue(cifsiod_wq);
d3bf5221
SF
1177out_clean_proc:
1178 cifs_proc_clean();
1da177e4
LT
1179 return rc;
1180}
1181
1182static void __exit
1183exit_cifs(void)
1184{
b6b38f70 1185 cFYI(DBG2, "exit_cifs");
3dd93306 1186 unregister_filesystem(&cifs_fs_type);
78d31a3a 1187 cifs_dfs_release_automount_timer();
4d79dba0
SP
1188#ifdef CONFIG_CIFS_ACL
1189 cifs_destroy_idmaptrees();
1190 exit_cifs_idmap();
1191#endif
84a15b93
JL
1192#ifdef CONFIG_CIFS_UPCALL
1193 unregister_key_type(&cifs_spnego_key_type);
1da177e4 1194#endif
1da177e4 1195 cifs_destroy_request_bufs();
3dd93306
JL
1196 cifs_destroy_mids();
1197 cifs_destroy_inodecache();
1198 cifs_fscache_unregister();
da472fc8 1199 destroy_workqueue(cifsiod_wq);
3dd93306 1200 cifs_proc_clean();
1da177e4
LT
1201}
1202
1203MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>");
6dc0f87e 1204MODULE_LICENSE("GPL"); /* combination of LGPL + GPL source behaves as GPL */
1da177e4 1205MODULE_DESCRIPTION
63135e08
SF
1206 ("VFS to access servers complying with the SNIA CIFS Specification "
1207 "e.g. Samba and Windows");
1da177e4
LT
1208MODULE_VERSION(CIFS_VERSION);
1209module_init(init_cifs)
1210module_exit(exit_cifs)