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