4 * Copyright (C) International Business Machines Corp., 2002,2008
5 * Author(s): Steve French (sfrench@us.ibm.com)
7 * Common Internet FileSystem (CIFS) client
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.
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.
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
24 /* Note that BB means BUGBUG (ie something to fix eventually) */
26 #include <linux/module.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/smp_lock.h>
41 #define DECLARE_GLOBALS_HERE
43 #include "cifsproto.h"
44 #include "cifs_debug.h"
45 #include "cifs_fs_sb.h"
47 #include <linux/key-type.h>
48 #include "dns_resolve.h"
49 #include "cifs_spnego.h"
50 #define CIFS_MAGIC_NUMBER 0xFF534D42 /* the first four bytes of SMB PDUs */
55 unsigned int oplockEnabled = 1;
56 unsigned int experimEnabled = 0;
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: "
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 "
76 unsigned int cifs_max_pending = CIFS_MAX_REQ;
77 module_param(cifs_max_pending, int, 0);
78 MODULE_PARM_DESC(cifs_max_pending, "Simultaneous requests to server. "
79 "Default: 50 Range: 2 to 256");
81 extern mempool_t *cifs_sm_req_poolp;
82 extern mempool_t *cifs_req_poolp;
83 extern mempool_t *cifs_mid_poolp;
86 cifs_read_super(struct super_block *sb, void *data,
87 const char *devname, int silent)
90 struct cifs_sb_info *cifs_sb;
93 /* BB should we make this contingent on mount parm? */
94 sb->s_flags |= MS_NODIRATIME | MS_NOATIME;
95 sb->s_fs_info = kzalloc(sizeof(struct cifs_sb_info), GFP_KERNEL);
96 cifs_sb = CIFS_SB(sb);
100 #ifdef CONFIG_CIFS_DFS_UPCALL
101 /* copy mount params to sb for use in submounts */
102 /* BB: should we move this after the mount so we
103 * do not have to do the copy on failed mounts?
104 * BB: May be it is better to do simple copy before
105 * complex operation (mount), and in case of fail
106 * just exit instead of doing mount and attempting
107 * undo it if this copy fails?*/
109 int len = strlen(data);
110 cifs_sb->mountdata = kzalloc(len + 1, GFP_KERNEL);
111 if (cifs_sb->mountdata == NULL) {
112 kfree(sb->s_fs_info);
113 sb->s_fs_info = NULL;
116 strncpy(cifs_sb->mountdata, data, len + 1);
117 cifs_sb->mountdata[len] = '\0';
121 rc = cifs_mount(sb, cifs_sb, data, devname);
125 cERROR(1, "cifs_mount failed w/return code = %d", rc);
126 goto out_mount_failed;
129 sb->s_magic = CIFS_MAGIC_NUMBER;
130 sb->s_op = &cifs_super_ops;
131 /* if (cifs_sb->tcon->ses->server->maxBuf > MAX_CIFS_HDR_SIZE + 512)
133 cifs_sb->tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE; */
134 sb->s_blocksize = CIFS_MAX_MSGSIZE;
135 sb->s_blocksize_bits = 14; /* default 2**14 = CIFS_MAX_MSGSIZE */
136 inode = cifs_root_iget(sb, ROOT_I);
144 sb->s_root = d_alloc_root(inode);
151 #ifdef CONFIG_CIFS_EXPERIMENTAL
152 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) {
153 cFYI(1, "export ops supported");
154 sb->s_export_op = &cifs_export_ops;
156 #endif /* EXPERIMENTAL */
161 cERROR(1, "cifs_read_super: get root inode failed");
165 cifs_umount(sb, cifs_sb);
169 #ifdef CONFIG_CIFS_DFS_UPCALL
170 if (cifs_sb->mountdata) {
171 kfree(cifs_sb->mountdata);
172 cifs_sb->mountdata = NULL;
175 unload_nls(cifs_sb->local_nls);
182 cifs_put_super(struct super_block *sb)
185 struct cifs_sb_info *cifs_sb;
187 cFYI(1, "In cifs_put_super");
188 cifs_sb = CIFS_SB(sb);
189 if (cifs_sb == NULL) {
190 cFYI(1, "Empty cifs superblock info passed to unmount");
196 rc = cifs_umount(sb, cifs_sb);
198 cERROR(1, "cifs_umount failed with return code %d", rc);
199 #ifdef CONFIG_CIFS_DFS_UPCALL
200 if (cifs_sb->mountdata) {
201 kfree(cifs_sb->mountdata);
202 cifs_sb->mountdata = NULL;
206 unload_nls(cifs_sb->local_nls);
213 cifs_statfs(struct dentry *dentry, struct kstatfs *buf)
215 struct super_block *sb = dentry->d_sb;
216 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
217 struct cifsTconInfo *tcon = cifs_sb->tcon;
218 int rc = -EOPNOTSUPP;
223 buf->f_type = CIFS_MAGIC_NUMBER;
226 * PATH_MAX may be too long - it would presumably be total path,
227 * but note that some servers (includinng Samba 3) have a shorter
230 * Instead could get the real value via SMB_QUERY_FS_ATTRIBUTE_INFO.
232 buf->f_namelen = PATH_MAX;
233 buf->f_files = 0; /* undefined */
234 buf->f_ffree = 0; /* unlimited */
237 * We could add a second check for a QFS Unix capability bit
239 if ((tcon->ses->capabilities & CAP_UNIX) &&
240 (CIFS_POSIX_EXTENSIONS & le64_to_cpu(tcon->fsUnixInfo.Capability)))
241 rc = CIFSSMBQFSPosixInfo(xid, tcon, buf);
244 * Only need to call the old QFSInfo if failed on newer one,
247 if (rc && (tcon->ses->capabilities & CAP_NT_SMBS))
248 rc = CIFSSMBQFSInfo(xid, tcon, buf);
251 * Some old Windows servers also do not support level 103, retry with
252 * older level one if old server failed the previous call or we
253 * bypassed it because we detected that this was an older LANMAN sess
256 rc = SMBOldQFSInfo(xid, tcon, buf);
262 static int cifs_permission(struct inode *inode, int mask)
264 struct cifs_sb_info *cifs_sb;
266 cifs_sb = CIFS_SB(inode->i_sb);
268 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) {
269 if ((mask & MAY_EXEC) && !execute_ok(inode))
273 } else /* file mode might have been restricted at mount time
274 on the client (above and beyond ACL on servers) for
275 servers which do not support setting and viewing mode bits,
276 so allowing client to check permissions is useful */
277 return generic_permission(inode, mask, NULL);
280 static struct kmem_cache *cifs_inode_cachep;
281 static struct kmem_cache *cifs_req_cachep;
282 static struct kmem_cache *cifs_mid_cachep;
283 static struct kmem_cache *cifs_sm_req_cachep;
284 mempool_t *cifs_sm_req_poolp;
285 mempool_t *cifs_req_poolp;
286 mempool_t *cifs_mid_poolp;
288 static struct inode *
289 cifs_alloc_inode(struct super_block *sb)
291 struct cifsInodeInfo *cifs_inode;
292 cifs_inode = kmem_cache_alloc(cifs_inode_cachep, GFP_KERNEL);
295 cifs_inode->cifsAttrs = 0x20; /* default */
296 cifs_inode->time = 0;
297 cifs_inode->write_behind_rc = 0;
298 /* Until the file is open and we have gotten oplock
299 info back from the server, can not assume caching of
300 file data or metadata */
301 cifs_inode->clientCanCacheRead = false;
302 cifs_inode->clientCanCacheAll = false;
303 cifs_inode->delete_pending = false;
304 cifs_inode->invalid_mapping = false;
305 cifs_inode->vfs_inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */
306 cifs_inode->server_eof = 0;
308 /* Can not set i_flags here - they get immediately overwritten
309 to zero by the VFS */
310 /* cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME;*/
311 INIT_LIST_HEAD(&cifs_inode->openFileList);
312 return &cifs_inode->vfs_inode;
316 cifs_destroy_inode(struct inode *inode)
318 kmem_cache_free(cifs_inode_cachep, CIFS_I(inode));
322 cifs_show_address(struct seq_file *s, struct TCP_Server_Info *server)
324 seq_printf(s, ",addr=");
326 switch (server->addr.sockAddr.sin_family) {
328 seq_printf(s, "%pI4", &server->addr.sockAddr.sin_addr.s_addr);
331 seq_printf(s, "%pI6",
332 &server->addr.sockAddr6.sin6_addr.s6_addr);
333 if (server->addr.sockAddr6.sin6_scope_id)
334 seq_printf(s, "%%%u",
335 server->addr.sockAddr6.sin6_scope_id);
338 seq_printf(s, "(unknown)");
343 * cifs_show_options() is for displaying mount options in /proc/mounts.
344 * Not all settable options are displayed but most of the important
348 cifs_show_options(struct seq_file *s, struct vfsmount *m)
350 struct cifs_sb_info *cifs_sb = CIFS_SB(m->mnt_sb);
351 struct cifsTconInfo *tcon = cifs_sb->tcon;
353 seq_printf(s, ",unc=%s", tcon->treeName);
354 if (tcon->ses->userName)
355 seq_printf(s, ",username=%s", tcon->ses->userName);
356 if (tcon->ses->domainName)
357 seq_printf(s, ",domain=%s", tcon->ses->domainName);
359 seq_printf(s, ",uid=%d", cifs_sb->mnt_uid);
360 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID)
361 seq_printf(s, ",forceuid");
363 seq_printf(s, ",noforceuid");
365 seq_printf(s, ",gid=%d", cifs_sb->mnt_gid);
366 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID)
367 seq_printf(s, ",forcegid");
369 seq_printf(s, ",noforcegid");
371 cifs_show_address(s, tcon->ses->server);
374 seq_printf(s, ",file_mode=0%o,dir_mode=0%o",
375 cifs_sb->mnt_file_mode,
376 cifs_sb->mnt_dir_mode);
378 seq_printf(s, ",seal");
380 seq_printf(s, ",nocase");
382 seq_printf(s, ",hard");
383 if (cifs_sb->prepath)
384 seq_printf(s, ",prepath=%s", cifs_sb->prepath);
385 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)
386 seq_printf(s, ",posixpaths");
387 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID)
388 seq_printf(s, ",setuids");
389 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)
390 seq_printf(s, ",serverino");
391 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO)
392 seq_printf(s, ",directio");
393 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
394 seq_printf(s, ",nouser_xattr");
395 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR)
396 seq_printf(s, ",mapchars");
397 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL)
398 seq_printf(s, ",sfu");
399 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
400 seq_printf(s, ",nobrl");
401 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL)
402 seq_printf(s, ",cifsacl");
403 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM)
404 seq_printf(s, ",dynperm");
405 if (m->mnt_sb->s_flags & MS_POSIXACL)
406 seq_printf(s, ",acl");
408 seq_printf(s, ",rsize=%d", cifs_sb->rsize);
409 seq_printf(s, ",wsize=%d", cifs_sb->wsize);
414 static void cifs_umount_begin(struct super_block *sb)
416 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
417 struct cifsTconInfo *tcon;
422 tcon = cifs_sb->tcon;
426 read_lock(&cifs_tcp_ses_lock);
427 if ((tcon->tc_count > 1) || (tcon->tidStatus == CifsExiting)) {
428 /* we have other mounts to same share or we have
429 already tried to force umount this and woken up
430 all waiting network requests, nothing to do */
431 read_unlock(&cifs_tcp_ses_lock);
433 } else if (tcon->tc_count == 1)
434 tcon->tidStatus = CifsExiting;
435 read_unlock(&cifs_tcp_ses_lock);
437 /* cancel_brl_requests(tcon); */ /* BB mark all brl mids as exiting */
438 /* cancel_notify_requests(tcon); */
439 if (tcon->ses && tcon->ses->server) {
440 cFYI(1, "wake up tasks now - umount begin not complete");
441 wake_up_all(&tcon->ses->server->request_q);
442 wake_up_all(&tcon->ses->server->response_q);
443 msleep(1); /* yield */
444 /* we have to kick the requests once more */
445 wake_up_all(&tcon->ses->server->response_q);
452 #ifdef CONFIG_CIFS_STATS2
453 static int cifs_show_stats(struct seq_file *s, struct vfsmount *mnt)
460 static int cifs_remount(struct super_block *sb, int *flags, char *data)
462 *flags |= MS_NODIRATIME;
466 static const struct super_operations cifs_super_ops = {
467 .put_super = cifs_put_super,
468 .statfs = cifs_statfs,
469 .alloc_inode = cifs_alloc_inode,
470 .destroy_inode = cifs_destroy_inode,
471 /* .drop_inode = generic_delete_inode,
472 .delete_inode = cifs_delete_inode, */ /* Do not need above two
473 functions unless later we add lazy close of inodes or unless the
474 kernel forgets to call us with the same number of releases (closes)
476 .show_options = cifs_show_options,
477 .umount_begin = cifs_umount_begin,
478 .remount_fs = cifs_remount,
479 #ifdef CONFIG_CIFS_STATS2
480 .show_stats = cifs_show_stats,
485 cifs_get_sb(struct file_system_type *fs_type,
486 int flags, const char *dev_name, void *data, struct vfsmount *mnt)
489 struct super_block *sb = sget(fs_type, NULL, set_anon_super, NULL);
491 cFYI(1, "Devname: %s flags: %d ", dev_name, flags);
498 rc = cifs_read_super(sb, data, dev_name, flags & MS_SILENT ? 1 : 0);
500 deactivate_locked_super(sb);
503 sb->s_flags |= MS_ACTIVE;
504 simple_set_mnt(mnt, sb);
508 static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
509 unsigned long nr_segs, loff_t pos)
511 struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode;
514 written = generic_file_aio_write(iocb, iov, nr_segs, pos);
515 if (!CIFS_I(inode)->clientCanCacheAll)
516 filemap_fdatawrite(inode->i_mapping);
520 static loff_t cifs_llseek(struct file *file, loff_t offset, int origin)
522 /* origin == SEEK_END => we must revalidate the cached file length */
523 if (origin == SEEK_END) {
526 /* some applications poll for the file length in this strange
527 way so we must seek to end on non-oplocked files by
528 setting the revalidate time to zero */
529 CIFS_I(file->f_path.dentry->d_inode)->time = 0;
531 retval = cifs_revalidate_file(file);
533 return (loff_t)retval;
535 return generic_file_llseek_unlocked(file, offset, origin);
538 static int cifs_setlease(struct file *file, long arg, struct file_lock **lease)
540 /* note that this is called by vfs setlease with the BKL held
541 although I doubt that BKL is needed here in cifs */
542 struct inode *inode = file->f_path.dentry->d_inode;
544 if (!(S_ISREG(inode->i_mode)))
547 /* check if file is oplocked */
548 if (((arg == F_RDLCK) &&
549 (CIFS_I(inode)->clientCanCacheRead)) ||
551 (CIFS_I(inode)->clientCanCacheAll)))
552 return generic_setlease(file, arg, lease);
553 else if (CIFS_SB(inode->i_sb)->tcon->local_lease &&
554 !CIFS_I(inode)->clientCanCacheRead)
555 /* If the server claims to support oplock on this
556 file, then we still need to check oplock even
557 if the local_lease mount option is set, but there
558 are servers which do not support oplock for which
559 this mount option may be useful if the user
560 knows that the file won't be changed on the server
562 return generic_setlease(file, arg, lease);
567 struct file_system_type cifs_fs_type = {
568 .owner = THIS_MODULE,
570 .get_sb = cifs_get_sb,
571 .kill_sb = kill_anon_super,
574 const struct inode_operations cifs_dir_inode_ops = {
575 .create = cifs_create,
576 .lookup = cifs_lookup,
577 .getattr = cifs_getattr,
578 .unlink = cifs_unlink,
579 .link = cifs_hardlink,
582 .rename = cifs_rename,
583 .permission = cifs_permission,
584 /* revalidate:cifs_revalidate, */
585 .setattr = cifs_setattr,
586 .symlink = cifs_symlink,
588 #ifdef CONFIG_CIFS_XATTR
589 .setxattr = cifs_setxattr,
590 .getxattr = cifs_getxattr,
591 .listxattr = cifs_listxattr,
592 .removexattr = cifs_removexattr,
596 const struct inode_operations cifs_file_inode_ops = {
597 /* revalidate:cifs_revalidate, */
598 .setattr = cifs_setattr,
599 .getattr = cifs_getattr, /* do we need this anymore? */
600 .rename = cifs_rename,
601 .permission = cifs_permission,
602 #ifdef CONFIG_CIFS_XATTR
603 .setxattr = cifs_setxattr,
604 .getxattr = cifs_getxattr,
605 .listxattr = cifs_listxattr,
606 .removexattr = cifs_removexattr,
610 const struct inode_operations cifs_symlink_inode_ops = {
611 .readlink = generic_readlink,
612 .follow_link = cifs_follow_link,
613 .put_link = cifs_put_link,
614 .permission = cifs_permission,
615 /* BB add the following two eventually */
616 /* revalidate: cifs_revalidate,
617 setattr: cifs_notify_change, *//* BB do we need notify change */
618 #ifdef CONFIG_CIFS_XATTR
619 .setxattr = cifs_setxattr,
620 .getxattr = cifs_getxattr,
621 .listxattr = cifs_listxattr,
622 .removexattr = cifs_removexattr,
626 const struct file_operations cifs_file_ops = {
627 .read = do_sync_read,
628 .write = do_sync_write,
629 .aio_read = generic_file_aio_read,
630 .aio_write = cifs_file_aio_write,
632 .release = cifs_close,
636 .mmap = cifs_file_mmap,
637 .splice_read = generic_file_splice_read,
638 .llseek = cifs_llseek,
639 #ifdef CONFIG_CIFS_POSIX
640 .unlocked_ioctl = cifs_ioctl,
641 #endif /* CONFIG_CIFS_POSIX */
642 .setlease = cifs_setlease,
645 const struct file_operations cifs_file_direct_ops = {
646 /* no aio, no readv -
647 BB reevaluate whether they can be done with directio, no cache */
648 .read = cifs_user_read,
649 .write = cifs_user_write,
651 .release = cifs_close,
655 .mmap = cifs_file_mmap,
656 .splice_read = generic_file_splice_read,
657 #ifdef CONFIG_CIFS_POSIX
658 .unlocked_ioctl = cifs_ioctl,
659 #endif /* CONFIG_CIFS_POSIX */
660 .llseek = cifs_llseek,
661 .setlease = cifs_setlease,
663 const struct file_operations cifs_file_nobrl_ops = {
664 .read = do_sync_read,
665 .write = do_sync_write,
666 .aio_read = generic_file_aio_read,
667 .aio_write = cifs_file_aio_write,
669 .release = cifs_close,
672 .mmap = cifs_file_mmap,
673 .splice_read = generic_file_splice_read,
674 .llseek = cifs_llseek,
675 #ifdef CONFIG_CIFS_POSIX
676 .unlocked_ioctl = cifs_ioctl,
677 #endif /* CONFIG_CIFS_POSIX */
678 .setlease = cifs_setlease,
681 const struct file_operations cifs_file_direct_nobrl_ops = {
682 /* no mmap, no aio, no readv -
683 BB reevaluate whether they can be done with directio, no cache */
684 .read = cifs_user_read,
685 .write = cifs_user_write,
687 .release = cifs_close,
690 .mmap = cifs_file_mmap,
691 .splice_read = generic_file_splice_read,
692 #ifdef CONFIG_CIFS_POSIX
693 .unlocked_ioctl = cifs_ioctl,
694 #endif /* CONFIG_CIFS_POSIX */
695 .llseek = cifs_llseek,
696 .setlease = cifs_setlease,
699 const struct file_operations cifs_dir_ops = {
700 .readdir = cifs_readdir,
701 .release = cifs_closedir,
702 .read = generic_read_dir,
703 .unlocked_ioctl = cifs_ioctl,
704 .llseek = generic_file_llseek,
708 cifs_init_once(void *inode)
710 struct cifsInodeInfo *cifsi = inode;
712 inode_init_once(&cifsi->vfs_inode);
713 INIT_LIST_HEAD(&cifsi->lockList);
717 cifs_init_inodecache(void)
719 cifs_inode_cachep = kmem_cache_create("cifs_inode_cache",
720 sizeof(struct cifsInodeInfo),
721 0, (SLAB_RECLAIM_ACCOUNT|
724 if (cifs_inode_cachep == NULL)
731 cifs_destroy_inodecache(void)
733 kmem_cache_destroy(cifs_inode_cachep);
737 cifs_init_request_bufs(void)
739 if (CIFSMaxBufSize < 8192) {
740 /* Buffer size can not be smaller than 2 * PATH_MAX since maximum
741 Unicode path name has to fit in any SMB/CIFS path based frames */
742 CIFSMaxBufSize = 8192;
743 } else if (CIFSMaxBufSize > 1024*127) {
744 CIFSMaxBufSize = 1024 * 127;
746 CIFSMaxBufSize &= 0x1FE00; /* Round size to even 512 byte mult*/
748 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
749 cifs_req_cachep = kmem_cache_create("cifs_request",
751 MAX_CIFS_HDR_SIZE, 0,
752 SLAB_HWCACHE_ALIGN, NULL);
753 if (cifs_req_cachep == NULL)
756 if (cifs_min_rcv < 1)
758 else if (cifs_min_rcv > 64) {
760 cERROR(1, "cifs_min_rcv set to maximum (64)");
763 cifs_req_poolp = mempool_create_slab_pool(cifs_min_rcv,
766 if (cifs_req_poolp == NULL) {
767 kmem_cache_destroy(cifs_req_cachep);
770 /* MAX_CIFS_SMALL_BUFFER_SIZE bytes is enough for most SMB responses and
771 almost all handle based requests (but not write response, nor is it
772 sufficient for path based requests). A smaller size would have
773 been more efficient (compacting multiple slab items on one 4k page)
774 for the case in which debug was on, but this larger size allows
775 more SMBs to use small buffer alloc and is still much more
776 efficient to alloc 1 per page off the slab compared to 17K (5page)
777 alloc of large cifs buffers even when page debugging is on */
778 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
779 MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
781 if (cifs_sm_req_cachep == NULL) {
782 mempool_destroy(cifs_req_poolp);
783 kmem_cache_destroy(cifs_req_cachep);
787 if (cifs_min_small < 2)
789 else if (cifs_min_small > 256) {
790 cifs_min_small = 256;
791 cFYI(1, "cifs_min_small set to maximum (256)");
794 cifs_sm_req_poolp = mempool_create_slab_pool(cifs_min_small,
797 if (cifs_sm_req_poolp == NULL) {
798 mempool_destroy(cifs_req_poolp);
799 kmem_cache_destroy(cifs_req_cachep);
800 kmem_cache_destroy(cifs_sm_req_cachep);
808 cifs_destroy_request_bufs(void)
810 mempool_destroy(cifs_req_poolp);
811 kmem_cache_destroy(cifs_req_cachep);
812 mempool_destroy(cifs_sm_req_poolp);
813 kmem_cache_destroy(cifs_sm_req_cachep);
819 cifs_mid_cachep = kmem_cache_create("cifs_mpx_ids",
820 sizeof(struct mid_q_entry), 0,
821 SLAB_HWCACHE_ALIGN, NULL);
822 if (cifs_mid_cachep == NULL)
825 /* 3 is a reasonable minimum number of simultaneous operations */
826 cifs_mid_poolp = mempool_create_slab_pool(3, cifs_mid_cachep);
827 if (cifs_mid_poolp == NULL) {
828 kmem_cache_destroy(cifs_mid_cachep);
836 cifs_destroy_mids(void)
838 mempool_destroy(cifs_mid_poolp);
839 kmem_cache_destroy(cifs_mid_cachep);
847 INIT_LIST_HEAD(&cifs_tcp_ses_list);
848 #ifdef CONFIG_CIFS_EXPERIMENTAL
849 INIT_LIST_HEAD(&GlobalDnotifyReqList);
850 INIT_LIST_HEAD(&GlobalDnotifyRsp_Q);
853 * Initialize Global counters
855 atomic_set(&sesInfoAllocCount, 0);
856 atomic_set(&tconInfoAllocCount, 0);
857 atomic_set(&tcpSesAllocCount, 0);
858 atomic_set(&tcpSesReconnectCount, 0);
859 atomic_set(&tconInfoReconnectCount, 0);
861 atomic_set(&bufAllocCount, 0);
862 atomic_set(&smBufAllocCount, 0);
863 #ifdef CONFIG_CIFS_STATS2
864 atomic_set(&totBufAllocCount, 0);
865 atomic_set(&totSmBufAllocCount, 0);
866 #endif /* CONFIG_CIFS_STATS2 */
868 atomic_set(&midCount, 0);
869 GlobalCurrentXid = 0;
870 GlobalTotalActiveXid = 0;
871 GlobalMaxActiveXid = 0;
872 memset(Local_System_Name, 0, 15);
873 rwlock_init(&GlobalSMBSeslock);
874 rwlock_init(&cifs_tcp_ses_lock);
875 spin_lock_init(&GlobalMid_Lock);
877 if (cifs_max_pending < 2) {
878 cifs_max_pending = 2;
879 cFYI(1, "cifs_max_pending set to min of 2");
880 } else if (cifs_max_pending > 256) {
881 cifs_max_pending = 256;
882 cFYI(1, "cifs_max_pending set to max of 256");
885 rc = cifs_init_inodecache();
889 rc = cifs_init_mids();
891 goto out_destroy_inodecache;
893 rc = cifs_init_request_bufs();
895 goto out_destroy_mids;
897 rc = register_filesystem(&cifs_fs_type);
899 goto out_destroy_request_bufs;
900 #ifdef CONFIG_CIFS_UPCALL
901 rc = register_key_type(&cifs_spnego_key_type);
903 goto out_unregister_filesystem;
905 #ifdef CONFIG_CIFS_DFS_UPCALL
906 rc = register_key_type(&key_type_dns_resolver);
908 goto out_unregister_key_type;
910 rc = slow_work_register_user(THIS_MODULE);
912 goto out_unregister_resolver_key;
916 out_unregister_resolver_key:
917 #ifdef CONFIG_CIFS_DFS_UPCALL
918 unregister_key_type(&key_type_dns_resolver);
919 out_unregister_key_type:
921 #ifdef CONFIG_CIFS_UPCALL
922 unregister_key_type(&cifs_spnego_key_type);
923 out_unregister_filesystem:
925 unregister_filesystem(&cifs_fs_type);
926 out_destroy_request_bufs:
927 cifs_destroy_request_bufs();
930 out_destroy_inodecache:
931 cifs_destroy_inodecache();
940 cFYI(DBG2, "exit_cifs");
942 #ifdef CONFIG_CIFS_DFS_UPCALL
943 cifs_dfs_release_automount_timer();
944 unregister_key_type(&key_type_dns_resolver);
946 #ifdef CONFIG_CIFS_UPCALL
947 unregister_key_type(&cifs_spnego_key_type);
949 unregister_filesystem(&cifs_fs_type);
950 cifs_destroy_inodecache();
952 cifs_destroy_request_bufs();
955 MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>");
956 MODULE_LICENSE("GPL"); /* combination of LGPL + GPL source behaves as GPL */
958 ("VFS to access servers complying with the SNIA CIFS Specification "
959 "e.g. Samba and Windows");
960 MODULE_VERSION(CIFS_VERSION);
961 module_init(init_cifs)
962 module_exit(exit_cifs)