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