4 * Copyright (C) International Business Machines Corp., 2002,2007
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>
40 #define DECLARE_GLOBALS_HERE
42 #include "cifsproto.h"
43 #include "cifs_debug.h"
44 #include "cifs_fs_sb.h"
46 #include <linux/key-type.h>
47 #define CIFS_MAGIC_NUMBER 0xFF534D42 /* the first four bytes of SMB PDUs */
49 #ifdef CONFIG_CIFS_QUOTA
50 static struct quotactl_ops cifs_quotactl_ops;
56 unsigned int oplockEnabled = 1;
57 unsigned int experimEnabled = 0;
58 unsigned int linuxExtEnabled = 1;
59 unsigned int lookupCacheEnabled = 1;
60 unsigned int multiuser_mount = 0;
61 unsigned int extended_security = CIFSSEC_DEF;
62 /* unsigned int ntlmv2_support = 0; */
63 unsigned int sign_CIFS_PDUs = 1;
64 extern struct task_struct *oplockThread; /* remove sparse warning */
65 struct task_struct *oplockThread = NULL;
66 /* extern struct task_struct * dnotifyThread; remove sparse warning */
67 static struct task_struct *dnotifyThread = NULL;
68 static const struct super_operations cifs_super_ops;
69 unsigned int CIFSMaxBufSize = CIFS_MAX_MSGSIZE;
70 module_param(CIFSMaxBufSize, int, 0);
71 MODULE_PARM_DESC(CIFSMaxBufSize, "Network buffer size (not including header). "
72 "Default: 16384 Range: 8192 to 130048");
73 unsigned int cifs_min_rcv = CIFS_MIN_RCV_POOL;
74 module_param(cifs_min_rcv, int, 0);
75 MODULE_PARM_DESC(cifs_min_rcv, "Network buffers in pool. Default: 4 Range: "
77 unsigned int cifs_min_small = 30;
78 module_param(cifs_min_small, int, 0);
79 MODULE_PARM_DESC(cifs_min_small, "Small network buffers in pool. Default: 30 "
81 unsigned int cifs_max_pending = CIFS_MAX_REQ;
82 module_param(cifs_max_pending, int, 0);
83 MODULE_PARM_DESC(cifs_max_pending, "Simultaneous requests to server. "
84 "Default: 50 Range: 2 to 256");
86 extern mempool_t *cifs_sm_req_poolp;
87 extern mempool_t *cifs_req_poolp;
88 extern mempool_t *cifs_mid_poolp;
90 extern struct kmem_cache *cifs_oplock_cachep;
93 cifs_read_super(struct super_block *sb, void *data,
94 const char *devname, int silent)
97 struct cifs_sb_info *cifs_sb;
100 /* BB should we make this contingent on mount parm? */
101 sb->s_flags |= MS_NODIRATIME | MS_NOATIME;
102 sb->s_fs_info = kzalloc(sizeof(struct cifs_sb_info), GFP_KERNEL);
103 cifs_sb = CIFS_SB(sb);
107 rc = cifs_mount(sb, cifs_sb, data, devname);
112 ("cifs_mount failed w/return code = %d", rc));
113 goto out_mount_failed;
116 sb->s_magic = CIFS_MAGIC_NUMBER;
117 sb->s_op = &cifs_super_ops;
118 /* if (cifs_sb->tcon->ses->server->maxBuf > MAX_CIFS_HDR_SIZE + 512)
120 cifs_sb->tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE; */
121 #ifdef CONFIG_CIFS_QUOTA
122 sb->s_qcop = &cifs_quotactl_ops;
124 sb->s_blocksize = CIFS_MAX_MSGSIZE;
125 sb->s_blocksize_bits = 14; /* default 2**14 = CIFS_MAX_MSGSIZE */
126 inode = iget(sb, ROOT_I);
133 sb->s_root = d_alloc_root(inode);
140 #ifdef CONFIG_CIFS_EXPERIMENTAL
141 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) {
142 cFYI(1, ("export ops supported"));
143 sb->s_export_op = &cifs_export_ops;
145 #endif /* EXPERIMENTAL */
150 cERROR(1, ("cifs_read_super: get root inode failed"));
156 if (cifs_sb->local_nls)
157 unload_nls(cifs_sb->local_nls);
164 cifs_put_super(struct super_block *sb)
167 struct cifs_sb_info *cifs_sb;
169 cFYI(1, ("In cifs_put_super"));
170 cifs_sb = CIFS_SB(sb);
171 if (cifs_sb == NULL) {
172 cFYI(1, ("Empty cifs superblock info passed to unmount"));
175 rc = cifs_umount(sb, cifs_sb);
177 cERROR(1, ("cifs_umount failed with return code %d", rc));
179 unload_nls(cifs_sb->local_nls);
185 cifs_statfs(struct dentry *dentry, struct kstatfs *buf)
187 struct super_block *sb = dentry->d_sb;
189 int rc = -EOPNOTSUPP;
190 struct cifs_sb_info *cifs_sb;
191 struct cifsTconInfo *pTcon;
195 cifs_sb = CIFS_SB(sb);
196 pTcon = cifs_sb->tcon;
198 buf->f_type = CIFS_MAGIC_NUMBER;
200 /* instead could get the real value via SMB_QUERY_FS_ATTRIBUTE_INFO */
201 buf->f_namelen = PATH_MAX; /* PATH_MAX may be too long - it would
202 presumably be total path, but note
203 that some servers (includinng Samba 3)
204 have a shorter maximum path */
205 buf->f_files = 0; /* undefined */
206 buf->f_ffree = 0; /* unlimited */
208 /* BB we could add a second check for a QFS Unix capability bit */
209 /* BB FIXME check CIFS_POSIX_EXTENSIONS Unix cap first FIXME BB */
210 if ((pTcon->ses->capabilities & CAP_UNIX) && (CIFS_POSIX_EXTENSIONS &
211 le64_to_cpu(pTcon->fsUnixInfo.Capability)))
212 rc = CIFSSMBQFSPosixInfo(xid, pTcon, buf);
214 /* Only need to call the old QFSInfo if failed
217 if (pTcon->ses->capabilities & CAP_NT_SMBS)
218 rc = CIFSSMBQFSInfo(xid, pTcon, buf); /* not supported by OS2 */
220 /* Some old Windows servers also do not support level 103, retry with
221 older level one if old server failed the previous call or we
222 bypassed it because we detected that this was an older LANMAN sess */
224 rc = SMBOldQFSInfo(xid, pTcon, buf);
228 /* BB get from info in tcon struct at mount time call to QFSAttrInfo */
230 return 0; /* always return success? what if volume is no
234 static int cifs_permission(struct inode *inode, int mask, struct nameidata *nd)
236 struct cifs_sb_info *cifs_sb;
238 cifs_sb = CIFS_SB(inode->i_sb);
240 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM)
242 else /* file mode might have been restricted at mount time
243 on the client (above and beyond ACL on servers) for
244 servers which do not support setting and viewing mode bits,
245 so allowing client to check permissions is useful */
246 return generic_permission(inode, mask, NULL);
249 static struct kmem_cache *cifs_inode_cachep;
250 static struct kmem_cache *cifs_req_cachep;
251 static struct kmem_cache *cifs_mid_cachep;
252 struct kmem_cache *cifs_oplock_cachep;
253 static struct kmem_cache *cifs_sm_req_cachep;
254 mempool_t *cifs_sm_req_poolp;
255 mempool_t *cifs_req_poolp;
256 mempool_t *cifs_mid_poolp;
258 static struct inode *
259 cifs_alloc_inode(struct super_block *sb)
261 struct cifsInodeInfo *cifs_inode;
262 cifs_inode = kmem_cache_alloc(cifs_inode_cachep, GFP_KERNEL);
265 cifs_inode->cifsAttrs = 0x20; /* default */
266 atomic_set(&cifs_inode->inUse, 0);
267 cifs_inode->time = 0;
268 /* Until the file is open and we have gotten oplock
269 info back from the server, can not assume caching of
270 file data or metadata */
271 cifs_inode->clientCanCacheRead = FALSE;
272 cifs_inode->clientCanCacheAll = FALSE;
273 cifs_inode->vfs_inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */
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;
283 cifs_destroy_inode(struct inode *inode)
285 kmem_cache_free(cifs_inode_cachep, CIFS_I(inode));
289 * cifs_show_options() is for displaying mount options in /proc/mounts.
290 * Not all settable options are displayed but most of the important
294 cifs_show_options(struct seq_file *s, struct vfsmount *m)
296 struct cifs_sb_info *cifs_sb;
298 cifs_sb = CIFS_SB(m->mnt_sb);
302 /* BB add prepath to mount options displayed */
303 seq_printf(s, ",unc=%s", cifs_sb->tcon->treeName);
304 if (cifs_sb->tcon->ses) {
305 if (cifs_sb->tcon->ses->userName)
306 seq_printf(s, ",username=%s",
307 cifs_sb->tcon->ses->userName);
308 if (cifs_sb->tcon->ses->domainName)
309 seq_printf(s, ",domain=%s",
310 cifs_sb->tcon->ses->domainName);
312 if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID) ||
313 !(cifs_sb->tcon->unix_ext))
314 seq_printf(s, ",uid=%d", cifs_sb->mnt_uid);
315 if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID) ||
316 !(cifs_sb->tcon->unix_ext))
317 seq_printf(s, ",gid=%d", cifs_sb->mnt_gid);
319 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)
320 seq_printf(s, ",posixpaths");
321 seq_printf(s, ",rsize=%d", cifs_sb->rsize);
322 seq_printf(s, ",wsize=%d", cifs_sb->wsize);
327 #ifdef CONFIG_CIFS_QUOTA
328 int cifs_xquota_set(struct super_block *sb, int quota_type, qid_t qid,
329 struct fs_disk_quota *pdquota)
333 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
334 struct cifsTconInfo *pTcon;
337 pTcon = cifs_sb->tcon;
344 cFYI(1, ("set type: 0x%x id: %d", quota_type, qid));
353 int cifs_xquota_get(struct super_block *sb, int quota_type, qid_t qid,
354 struct fs_disk_quota *pdquota)
358 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
359 struct cifsTconInfo *pTcon;
362 pTcon = cifs_sb->tcon;
368 cFYI(1, ("set type: 0x%x id: %d", quota_type, qid));
377 int cifs_xstate_set(struct super_block *sb, unsigned int flags, int operation)
381 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
382 struct cifsTconInfo *pTcon;
385 pTcon = cifs_sb->tcon;
391 cFYI(1, ("flags: 0x%x operation: 0x%x", flags, operation));
400 int cifs_xstate_get(struct super_block *sb, struct fs_quota_stat *qstats)
404 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
405 struct cifsTconInfo *pTcon;
408 pTcon = cifs_sb->tcon;
414 cFYI(1, ("pqstats %p", qstats));
423 static struct quotactl_ops cifs_quotactl_ops = {
424 .set_xquota = cifs_xquota_set,
425 .get_xquota = cifs_xquota_set,
426 .set_xstate = cifs_xstate_set,
427 .get_xstate = cifs_xstate_get,
431 static void cifs_umount_begin(struct vfsmount *vfsmnt, int flags)
433 struct cifs_sb_info *cifs_sb;
434 struct cifsTconInfo *tcon;
436 if (!(flags & MNT_FORCE))
438 cifs_sb = CIFS_SB(vfsmnt->mnt_sb);
442 tcon = cifs_sb->tcon;
445 down(&tcon->tconSem);
446 if (atomic_read(&tcon->useCount) == 1)
447 tcon->tidStatus = CifsExiting;
450 /* cancel_brl_requests(tcon); */ /* BB mark all brl mids as exiting */
451 /* cancel_notify_requests(tcon); */
452 if (tcon->ses && tcon->ses->server) {
453 cFYI(1, ("wake up tasks now - umount begin not complete"));
454 wake_up_all(&tcon->ses->server->request_q);
455 wake_up_all(&tcon->ses->server->response_q);
456 msleep(1); /* yield */
457 /* we have to kick the requests once more */
458 wake_up_all(&tcon->ses->server->response_q);
461 /* BB FIXME - finish add checks for tidStatus BB */
466 #ifdef CONFIG_CIFS_STATS2
467 static int cifs_show_stats(struct seq_file *s, struct vfsmount *mnt)
474 static int cifs_remount(struct super_block *sb, int *flags, char *data)
476 *flags |= MS_NODIRATIME;
480 static const struct super_operations cifs_super_ops = {
481 .read_inode = cifs_read_inode,
482 .put_super = cifs_put_super,
483 .statfs = cifs_statfs,
484 .alloc_inode = cifs_alloc_inode,
485 .destroy_inode = cifs_destroy_inode,
486 /* .drop_inode = generic_delete_inode,
487 .delete_inode = cifs_delete_inode, */ /* Do not need above two
488 functions unless later we add lazy close of inodes or unless the
489 kernel forgets to call us with the same number of releases (closes)
491 .show_options = cifs_show_options,
492 .umount_begin = cifs_umount_begin,
493 .remount_fs = cifs_remount,
494 #ifdef CONFIG_CIFS_STATS2
495 .show_stats = cifs_show_stats,
500 cifs_get_sb(struct file_system_type *fs_type,
501 int flags, const char *dev_name, void *data, struct vfsmount *mnt)
504 struct super_block *sb = sget(fs_type, NULL, set_anon_super, NULL);
506 cFYI(1, ("Devname: %s flags: %d ", dev_name, flags));
513 rc = cifs_read_super(sb, data, dev_name, flags & MS_SILENT ? 1 : 0);
515 up_write(&sb->s_umount);
516 deactivate_super(sb);
519 sb->s_flags |= MS_ACTIVE;
520 return simple_set_mnt(mnt, sb);
523 static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
524 unsigned long nr_segs, loff_t pos)
526 struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode;
529 written = generic_file_aio_write(iocb, iov, nr_segs, pos);
530 if (!CIFS_I(inode)->clientCanCacheAll)
531 filemap_fdatawrite(inode->i_mapping);
535 static loff_t cifs_llseek(struct file *file, loff_t offset, int origin)
537 /* origin == SEEK_END => we must revalidate the cached file length */
538 if (origin == SEEK_END) {
541 /* some applications poll for the file length in this strange
542 way so we must seek to end on non-oplocked files by
543 setting the revalidate time to zero */
544 CIFS_I(file->f_path.dentry->d_inode)->time = 0;
546 retval = cifs_revalidate(file->f_path.dentry);
548 return (loff_t)retval;
550 return remote_llseek(file, offset, origin);
553 static struct file_system_type cifs_fs_type = {
554 .owner = THIS_MODULE,
556 .get_sb = cifs_get_sb,
557 .kill_sb = kill_anon_super,
560 const struct inode_operations cifs_dir_inode_ops = {
561 .create = cifs_create,
562 .lookup = cifs_lookup,
563 .getattr = cifs_getattr,
564 .unlink = cifs_unlink,
565 .link = cifs_hardlink,
568 .rename = cifs_rename,
569 .permission = cifs_permission,
570 /* revalidate:cifs_revalidate, */
571 .setattr = cifs_setattr,
572 .symlink = cifs_symlink,
574 #ifdef CONFIG_CIFS_XATTR
575 .setxattr = cifs_setxattr,
576 .getxattr = cifs_getxattr,
577 .listxattr = cifs_listxattr,
578 .removexattr = cifs_removexattr,
582 const struct inode_operations cifs_file_inode_ops = {
583 /* revalidate:cifs_revalidate, */
584 .setattr = cifs_setattr,
585 .getattr = cifs_getattr, /* do we need this anymore? */
586 .rename = cifs_rename,
587 .permission = cifs_permission,
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_symlink_inode_ops = {
597 .readlink = generic_readlink,
598 .follow_link = cifs_follow_link,
599 .put_link = cifs_put_link,
600 .permission = cifs_permission,
601 /* BB add the following two eventually */
602 /* revalidate: cifs_revalidate,
603 setattr: cifs_notify_change, *//* BB do we need notify change */
604 #ifdef CONFIG_CIFS_XATTR
605 .setxattr = cifs_setxattr,
606 .getxattr = cifs_getxattr,
607 .listxattr = cifs_listxattr,
608 .removexattr = cifs_removexattr,
612 const struct file_operations cifs_file_ops = {
613 .read = do_sync_read,
614 .write = do_sync_write,
615 .aio_read = generic_file_aio_read,
616 .aio_write = cifs_file_aio_write,
618 .release = cifs_close,
622 .mmap = cifs_file_mmap,
623 .splice_read = generic_file_splice_read,
624 .llseek = cifs_llseek,
625 #ifdef CONFIG_CIFS_POSIX
627 #endif /* CONFIG_CIFS_POSIX */
629 #ifdef CONFIG_CIFS_EXPERIMENTAL
630 .dir_notify = cifs_dir_notify,
631 #endif /* CONFIG_CIFS_EXPERIMENTAL */
634 const struct file_operations cifs_file_direct_ops = {
635 /* no mmap, no aio, no readv -
636 BB reevaluate whether they can be done with directio, no cache */
637 .read = cifs_user_read,
638 .write = cifs_user_write,
640 .release = cifs_close,
644 .splice_read = generic_file_splice_read,
645 #ifdef CONFIG_CIFS_POSIX
647 #endif /* CONFIG_CIFS_POSIX */
648 .llseek = cifs_llseek,
649 #ifdef CONFIG_CIFS_EXPERIMENTAL
650 .dir_notify = cifs_dir_notify,
651 #endif /* CONFIG_CIFS_EXPERIMENTAL */
653 const struct file_operations cifs_file_nobrl_ops = {
654 .read = do_sync_read,
655 .write = do_sync_write,
656 .aio_read = generic_file_aio_read,
657 .aio_write = cifs_file_aio_write,
659 .release = cifs_close,
662 .mmap = cifs_file_mmap,
663 .splice_read = generic_file_splice_read,
664 .llseek = cifs_llseek,
665 #ifdef CONFIG_CIFS_POSIX
667 #endif /* CONFIG_CIFS_POSIX */
669 #ifdef CONFIG_CIFS_EXPERIMENTAL
670 .dir_notify = cifs_dir_notify,
671 #endif /* CONFIG_CIFS_EXPERIMENTAL */
674 const struct file_operations cifs_file_direct_nobrl_ops = {
675 /* no mmap, no aio, no readv -
676 BB reevaluate whether they can be done with directio, no cache */
677 .read = cifs_user_read,
678 .write = cifs_user_write,
680 .release = cifs_close,
683 .splice_read = generic_file_splice_read,
684 #ifdef CONFIG_CIFS_POSIX
686 #endif /* CONFIG_CIFS_POSIX */
687 .llseek = cifs_llseek,
688 #ifdef CONFIG_CIFS_EXPERIMENTAL
689 .dir_notify = cifs_dir_notify,
690 #endif /* CONFIG_CIFS_EXPERIMENTAL */
693 const struct file_operations cifs_dir_ops = {
694 .readdir = cifs_readdir,
695 .release = cifs_closedir,
696 .read = generic_read_dir,
697 #ifdef CONFIG_CIFS_EXPERIMENTAL
698 .dir_notify = cifs_dir_notify,
699 #endif /* CONFIG_CIFS_EXPERIMENTAL */
704 cifs_init_once(struct kmem_cache *cachep, void *inode)
706 struct cifsInodeInfo *cifsi = inode;
708 inode_init_once(&cifsi->vfs_inode);
709 INIT_LIST_HEAD(&cifsi->lockList);
713 cifs_init_inodecache(void)
715 cifs_inode_cachep = kmem_cache_create("cifs_inode_cache",
716 sizeof(struct cifsInodeInfo),
717 0, (SLAB_RECLAIM_ACCOUNT|
720 if (cifs_inode_cachep == NULL)
727 cifs_destroy_inodecache(void)
729 kmem_cache_destroy(cifs_inode_cachep);
733 cifs_init_request_bufs(void)
735 if (CIFSMaxBufSize < 8192) {
736 /* Buffer size can not be smaller than 2 * PATH_MAX since maximum
737 Unicode path name has to fit in any SMB/CIFS path based frames */
738 CIFSMaxBufSize = 8192;
739 } else if (CIFSMaxBufSize > 1024*127) {
740 CIFSMaxBufSize = 1024 * 127;
742 CIFSMaxBufSize &= 0x1FE00; /* Round size to even 512 byte mult*/
744 /* cERROR(1,("CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize)); */
745 cifs_req_cachep = kmem_cache_create("cifs_request",
747 MAX_CIFS_HDR_SIZE, 0,
748 SLAB_HWCACHE_ALIGN, NULL);
749 if (cifs_req_cachep == NULL)
752 if (cifs_min_rcv < 1)
754 else if (cifs_min_rcv > 64) {
756 cERROR(1, ("cifs_min_rcv set to maximum (64)"));
759 cifs_req_poolp = mempool_create_slab_pool(cifs_min_rcv,
762 if (cifs_req_poolp == NULL) {
763 kmem_cache_destroy(cifs_req_cachep);
766 /* MAX_CIFS_SMALL_BUFFER_SIZE bytes is enough for most SMB responses and
767 almost all handle based requests (but not write response, nor is it
768 sufficient for path based requests). A smaller size would have
769 been more efficient (compacting multiple slab items on one 4k page)
770 for the case in which debug was on, but this larger size allows
771 more SMBs to use small buffer alloc and is still much more
772 efficient to alloc 1 per page off the slab compared to 17K (5page)
773 alloc of large cifs buffers even when page debugging is on */
774 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
775 MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
777 if (cifs_sm_req_cachep == NULL) {
778 mempool_destroy(cifs_req_poolp);
779 kmem_cache_destroy(cifs_req_cachep);
783 if (cifs_min_small < 2)
785 else if (cifs_min_small > 256) {
786 cifs_min_small = 256;
787 cFYI(1, ("cifs_min_small set to maximum (256)"));
790 cifs_sm_req_poolp = mempool_create_slab_pool(cifs_min_small,
793 if (cifs_sm_req_poolp == NULL) {
794 mempool_destroy(cifs_req_poolp);
795 kmem_cache_destroy(cifs_req_cachep);
796 kmem_cache_destroy(cifs_sm_req_cachep);
804 cifs_destroy_request_bufs(void)
806 mempool_destroy(cifs_req_poolp);
807 kmem_cache_destroy(cifs_req_cachep);
808 mempool_destroy(cifs_sm_req_poolp);
809 kmem_cache_destroy(cifs_sm_req_cachep);
815 cifs_mid_cachep = kmem_cache_create("cifs_mpx_ids",
816 sizeof(struct mid_q_entry), 0,
817 SLAB_HWCACHE_ALIGN, NULL);
818 if (cifs_mid_cachep == NULL)
821 /* 3 is a reasonable minimum number of simultaneous operations */
822 cifs_mid_poolp = mempool_create_slab_pool(3, cifs_mid_cachep);
823 if (cifs_mid_poolp == NULL) {
824 kmem_cache_destroy(cifs_mid_cachep);
828 cifs_oplock_cachep = kmem_cache_create("cifs_oplock_structs",
829 sizeof(struct oplock_q_entry), 0,
830 SLAB_HWCACHE_ALIGN, NULL);
831 if (cifs_oplock_cachep == NULL) {
832 mempool_destroy(cifs_mid_poolp);
833 kmem_cache_destroy(cifs_mid_cachep);
841 cifs_destroy_mids(void)
843 mempool_destroy(cifs_mid_poolp);
844 kmem_cache_destroy(cifs_mid_cachep);
845 kmem_cache_destroy(cifs_oplock_cachep);
848 static int cifs_oplock_thread(void *dummyarg)
850 struct oplock_q_entry *oplock_item;
851 struct cifsTconInfo *pTcon;
861 spin_lock(&GlobalMid_Lock);
862 if (list_empty(&GlobalOplock_Q)) {
863 spin_unlock(&GlobalMid_Lock);
864 set_current_state(TASK_INTERRUPTIBLE);
865 schedule_timeout(39*HZ);
867 oplock_item = list_entry(GlobalOplock_Q.next,
868 struct oplock_q_entry, qhead);
870 cFYI(1, ("found oplock item to write out"));
871 pTcon = oplock_item->tcon;
872 inode = oplock_item->pinode;
873 netfid = oplock_item->netfid;
874 spin_unlock(&GlobalMid_Lock);
875 DeleteOplockQEntry(oplock_item);
876 /* can not grab inode sem here since it would
877 deadlock when oplock received on delete
878 since vfs_unlink holds the i_mutex across
880 /* mutex_lock(&inode->i_mutex);*/
881 if (S_ISREG(inode->i_mode)) {
883 filemap_fdatawrite(inode->i_mapping);
884 if (CIFS_I(inode)->clientCanCacheRead
886 filemap_fdatawait(inode->i_mapping);
887 invalidate_remote_inode(inode);
891 /* mutex_unlock(&inode->i_mutex);*/
893 CIFS_I(inode)->write_behind_rc = rc;
894 cFYI(1, ("Oplock flush inode %p rc %d",
897 /* releasing stale oplock after recent reconnect
898 of smb session using a now incorrect file
899 handle is not a data integrity issue but do
900 not bother sending an oplock release if session
901 to server still is disconnected since oplock
902 already released by the server in that case */
903 if (pTcon->tidStatus != CifsNeedReconnect) {
904 rc = CIFSSMBLock(0, pTcon, netfid,
905 0 /* len */ , 0 /* offset */, 0,
906 0, LOCKING_ANDX_OPLOCK_RELEASE,
908 cFYI(1, ("Oplock release rc = %d", rc));
911 spin_unlock(&GlobalMid_Lock);
912 set_current_state(TASK_INTERRUPTIBLE);
913 schedule_timeout(1); /* yield in case q were corrupt */
915 } while (!kthread_should_stop());
920 static int cifs_dnotify_thread(void *dummyarg)
922 struct list_head *tmp;
923 struct cifsSesInfo *ses;
928 set_current_state(TASK_INTERRUPTIBLE);
929 schedule_timeout(15*HZ);
930 read_lock(&GlobalSMBSeslock);
931 /* check if any stuck requests that need
932 to be woken up and wakeq so the
933 thread can wake up and error out */
934 list_for_each(tmp, &GlobalSMBSessionList) {
935 ses = list_entry(tmp, struct cifsSesInfo,
937 if (ses && ses->server &&
938 atomic_read(&ses->server->inFlight))
939 wake_up_all(&ses->server->response_q);
941 read_unlock(&GlobalSMBSeslock);
942 } while (!kthread_should_stop());
951 #ifdef CONFIG_PROC_FS
954 /* INIT_LIST_HEAD(&GlobalServerList);*/ /* BB not implemented yet */
955 INIT_LIST_HEAD(&GlobalSMBSessionList);
956 INIT_LIST_HEAD(&GlobalTreeConnectionList);
957 INIT_LIST_HEAD(&GlobalOplock_Q);
958 #ifdef CONFIG_CIFS_EXPERIMENTAL
959 INIT_LIST_HEAD(&GlobalDnotifyReqList);
960 INIT_LIST_HEAD(&GlobalDnotifyRsp_Q);
963 * Initialize Global counters
965 atomic_set(&sesInfoAllocCount, 0);
966 atomic_set(&tconInfoAllocCount, 0);
967 atomic_set(&tcpSesAllocCount, 0);
968 atomic_set(&tcpSesReconnectCount, 0);
969 atomic_set(&tconInfoReconnectCount, 0);
971 atomic_set(&bufAllocCount, 0);
972 atomic_set(&smBufAllocCount, 0);
973 #ifdef CONFIG_CIFS_STATS2
974 atomic_set(&totBufAllocCount, 0);
975 atomic_set(&totSmBufAllocCount, 0);
976 #endif /* CONFIG_CIFS_STATS2 */
978 atomic_set(&midCount, 0);
979 GlobalCurrentXid = 0;
980 GlobalTotalActiveXid = 0;
981 GlobalMaxActiveXid = 0;
982 memset(Local_System_Name, 0, 15);
983 rwlock_init(&GlobalSMBSeslock);
984 spin_lock_init(&GlobalMid_Lock);
986 if (cifs_max_pending < 2) {
987 cifs_max_pending = 2;
988 cFYI(1, ("cifs_max_pending set to min of 2"));
989 } else if (cifs_max_pending > 256) {
990 cifs_max_pending = 256;
991 cFYI(1, ("cifs_max_pending set to max of 256"));
994 rc = cifs_init_inodecache();
998 rc = cifs_init_mids();
1000 goto out_destroy_inodecache;
1002 rc = cifs_init_request_bufs();
1004 goto out_destroy_mids;
1006 rc = register_filesystem(&cifs_fs_type);
1008 goto out_destroy_request_bufs;
1009 #ifdef CONFIG_CIFS_UPCALL
1010 rc = register_key_type(&cifs_spnego_key_type);
1012 goto out_unregister_filesystem;
1014 oplockThread = kthread_run(cifs_oplock_thread, NULL, "cifsoplockd");
1015 if (IS_ERR(oplockThread)) {
1016 rc = PTR_ERR(oplockThread);
1017 cERROR(1, ("error %d create oplock thread", rc));
1018 goto out_unregister_key_type;
1021 dnotifyThread = kthread_run(cifs_dnotify_thread, NULL, "cifsdnotifyd");
1022 if (IS_ERR(dnotifyThread)) {
1023 rc = PTR_ERR(dnotifyThread);
1024 cERROR(1, ("error %d create dnotify thread", rc));
1025 goto out_stop_oplock_thread;
1030 out_stop_oplock_thread:
1031 kthread_stop(oplockThread);
1032 out_unregister_key_type:
1033 #ifdef CONFIG_CIFS_UPCALL
1034 unregister_key_type(&cifs_spnego_key_type);
1035 out_unregister_filesystem:
1037 unregister_filesystem(&cifs_fs_type);
1038 out_destroy_request_bufs:
1039 cifs_destroy_request_bufs();
1041 cifs_destroy_mids();
1042 out_destroy_inodecache:
1043 cifs_destroy_inodecache();
1045 #ifdef CONFIG_PROC_FS
1054 cFYI(0, ("exit_cifs"));
1055 #ifdef CONFIG_PROC_FS
1058 #ifdef CONFIG_CIFS_UPCALL
1059 unregister_key_type(&cifs_spnego_key_type);
1061 unregister_filesystem(&cifs_fs_type);
1062 cifs_destroy_inodecache();
1063 cifs_destroy_mids();
1064 cifs_destroy_request_bufs();
1065 kthread_stop(oplockThread);
1066 kthread_stop(dnotifyThread);
1069 MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>");
1070 MODULE_LICENSE("GPL"); /* combination of LGPL + GPL source behaves as GPL */
1072 ("VFS to access servers complying with the SNIA CIFS Specification "
1073 "e.g. Samba and Windows");
1074 MODULE_VERSION(CIFS_VERSION);
1075 module_init(init_cifs)
1076 module_exit(exit_cifs)