4 * Copyright (C) International Business Machines Corp., 2002,2004
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>
37 #define DECLARE_GLOBALS_HERE
39 #include "cifsproto.h"
40 #include "cifs_debug.h"
41 #include "cifs_fs_sb.h"
43 #define CIFS_MAGIC_NUMBER 0xFF534D42 /* the first four bytes of SMB PDUs */
45 #ifdef CONFIG_CIFS_QUOTA
46 static struct quotactl_ops cifs_quotactl_ops;
52 unsigned int oplockEnabled = 1;
53 unsigned int experimEnabled = 0;
54 unsigned int linuxExtEnabled = 1;
55 unsigned int lookupCacheEnabled = 1;
56 unsigned int multiuser_mount = 0;
57 unsigned int extended_security = 0;
58 unsigned int ntlmv2_support = 0;
59 unsigned int sign_CIFS_PDUs = 1;
60 extern struct task_struct * oplockThread; /* remove sparse warning */
61 struct task_struct * oplockThread = NULL;
62 extern struct task_struct * dnotifyThread; /* remove sparse warning */
63 struct task_struct * dnotifyThread = NULL;
64 unsigned int CIFSMaxBufSize = CIFS_MAX_MSGSIZE;
65 module_param(CIFSMaxBufSize, int, 0);
66 MODULE_PARM_DESC(CIFSMaxBufSize,"Network buffer size (not including header). Default: 16384 Range: 8192 to 130048");
67 unsigned int cifs_min_rcv = CIFS_MIN_RCV_POOL;
68 module_param(cifs_min_rcv, int, 0);
69 MODULE_PARM_DESC(cifs_min_rcv,"Network buffers in pool. Default: 4 Range: 1 to 64");
70 unsigned int cifs_min_small = 30;
71 module_param(cifs_min_small, int, 0);
72 MODULE_PARM_DESC(cifs_min_small,"Small network buffers in pool. Default: 30 Range: 2 to 256");
73 unsigned int cifs_max_pending = CIFS_MAX_REQ;
74 module_param(cifs_max_pending, int, 0);
75 MODULE_PARM_DESC(cifs_max_pending,"Simultaneous requests to server. Default: 50 Range: 2 to 256");
77 static DECLARE_COMPLETION(cifs_oplock_exited);
78 static DECLARE_COMPLETION(cifs_dnotify_exited);
80 extern mempool_t *cifs_sm_req_poolp;
81 extern mempool_t *cifs_req_poolp;
82 extern mempool_t *cifs_mid_poolp;
84 extern kmem_cache_t *cifs_oplock_cachep;
87 cifs_read_super(struct super_block *sb, void *data,
88 const char *devname, int silent)
91 struct cifs_sb_info *cifs_sb;
94 sb->s_flags |= MS_NODIRATIME; /* and probably even noatime */
95 sb->s_fs_info = kmalloc(sizeof(struct cifs_sb_info),GFP_KERNEL);
96 cifs_sb = CIFS_SB(sb);
100 memset(cifs_sb,0,sizeof(struct cifs_sb_info));
103 rc = cifs_mount(sb, cifs_sb, data, devname);
108 ("cifs_mount failed w/return code = %d", rc));
109 goto out_mount_failed;
112 sb->s_magic = CIFS_MAGIC_NUMBER;
113 sb->s_op = &cifs_super_ops;
114 /* if(cifs_sb->tcon->ses->server->maxBuf > MAX_CIFS_HDR_SIZE + 512)
115 sb->s_blocksize = cifs_sb->tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE; */
116 #ifdef CONFIG_CIFS_QUOTA
117 sb->s_qcop = &cifs_quotactl_ops;
119 sb->s_blocksize = CIFS_MAX_MSGSIZE;
120 sb->s_blocksize_bits = 14; /* default 2**14 = CIFS_MAX_MSGSIZE */
121 inode = iget(sb, ROOT_I);
128 sb->s_root = d_alloc_root(inode);
138 cERROR(1, ("cifs_read_super: get root inode failed"));
144 if(cifs_sb->local_nls)
145 unload_nls(cifs_sb->local_nls);
152 cifs_put_super(struct super_block *sb)
155 struct cifs_sb_info *cifs_sb;
157 cFYI(1, ("In cifs_put_super"));
158 cifs_sb = CIFS_SB(sb);
159 if(cifs_sb == NULL) {
160 cFYI(1,("Empty cifs superblock info passed to unmount"));
163 rc = cifs_umount(sb, cifs_sb);
165 cERROR(1, ("cifs_umount failed with return code %d", rc));
167 unload_nls(cifs_sb->local_nls);
173 cifs_statfs(struct super_block *sb, struct kstatfs *buf)
176 int rc = -EOPNOTSUPP;
177 struct cifs_sb_info *cifs_sb;
178 struct cifsTconInfo *pTcon;
182 cifs_sb = CIFS_SB(sb);
183 pTcon = cifs_sb->tcon;
185 buf->f_type = CIFS_MAGIC_NUMBER;
187 /* instead could get the real value via SMB_QUERY_FS_ATTRIBUTE_INFO */
188 buf->f_namelen = PATH_MAX; /* PATH_MAX may be too long - it would
189 presumably be total path, but note
190 that some servers (includinng Samba 3)
191 have a shorter maximum path */
192 buf->f_files = 0; /* undefined */
193 buf->f_ffree = 0; /* unlimited */
195 #ifdef CONFIG_CIFS_EXPERIMENTAL
196 /* BB we could add a second check for a QFS Unix capability bit */
197 /* BB FIXME check CIFS_POSIX_EXTENSIONS Unix cap first FIXME BB */
198 if ((pTcon->ses->capabilities & CAP_UNIX) && (CIFS_POSIX_EXTENSIONS &
199 le64_to_cpu(pTcon->fsUnixInfo.Capability)))
200 rc = CIFSSMBQFSPosixInfo(xid, pTcon, buf);
202 /* Only need to call the old QFSInfo if failed
205 #endif /* CIFS_EXPERIMENTAL */
206 rc = CIFSSMBQFSInfo(xid, pTcon, buf);
208 /* Old Windows servers do not support level 103, retry with level
209 one if old server failed the previous call */
211 rc = SMBOldQFSInfo(xid, pTcon, buf);
216 /* BB get from info in tcon struct at mount time call to QFSAttrInfo */
218 return 0; /* always return success? what if volume is no
222 static int cifs_permission(struct inode * inode, int mask, struct nameidata *nd)
224 struct cifs_sb_info *cifs_sb;
226 cifs_sb = CIFS_SB(inode->i_sb);
228 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) {
230 } else /* file mode might have been restricted at mount time
231 on the client (above and beyond ACL on servers) for
232 servers which do not support setting and viewing mode bits,
233 so allowing client to check permissions is useful */
234 return generic_permission(inode, mask, NULL);
237 static kmem_cache_t *cifs_inode_cachep;
238 static kmem_cache_t *cifs_req_cachep;
239 static kmem_cache_t *cifs_mid_cachep;
240 kmem_cache_t *cifs_oplock_cachep;
241 static kmem_cache_t *cifs_sm_req_cachep;
242 mempool_t *cifs_sm_req_poolp;
243 mempool_t *cifs_req_poolp;
244 mempool_t *cifs_mid_poolp;
246 static struct inode *
247 cifs_alloc_inode(struct super_block *sb)
249 struct cifsInodeInfo *cifs_inode;
250 cifs_inode = kmem_cache_alloc(cifs_inode_cachep, SLAB_KERNEL);
253 cifs_inode->cifsAttrs = 0x20; /* default */
254 atomic_set(&cifs_inode->inUse, 0);
255 cifs_inode->time = 0;
256 /* Until the file is open and we have gotten oplock
257 info back from the server, can not assume caching of
258 file data or metadata */
259 cifs_inode->clientCanCacheRead = FALSE;
260 cifs_inode->clientCanCacheAll = FALSE;
261 cifs_inode->vfs_inode.i_blksize = CIFS_MAX_MSGSIZE;
262 cifs_inode->vfs_inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */
263 cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME;
264 INIT_LIST_HEAD(&cifs_inode->openFileList);
265 return &cifs_inode->vfs_inode;
269 cifs_destroy_inode(struct inode *inode)
271 kmem_cache_free(cifs_inode_cachep, CIFS_I(inode));
275 * cifs_show_options() is for displaying mount options in /proc/mounts.
276 * Not all settable options are displayed but most of the important
280 cifs_show_options(struct seq_file *s, struct vfsmount *m)
282 struct cifs_sb_info *cifs_sb;
284 cifs_sb = CIFS_SB(m->mnt_sb);
288 seq_printf(s, ",unc=%s", cifs_sb->tcon->treeName);
289 if (cifs_sb->tcon->ses) {
290 if (cifs_sb->tcon->ses->userName)
291 seq_printf(s, ",username=%s",
292 cifs_sb->tcon->ses->userName);
293 if(cifs_sb->tcon->ses->domainName)
294 seq_printf(s, ",domain=%s",
295 cifs_sb->tcon->ses->domainName);
298 seq_printf(s, ",rsize=%d",cifs_sb->rsize);
299 seq_printf(s, ",wsize=%d",cifs_sb->wsize);
304 #ifdef CONFIG_CIFS_QUOTA
305 int cifs_xquota_set(struct super_block * sb, int quota_type, qid_t qid,
306 struct fs_disk_quota * pdquota)
310 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
311 struct cifsTconInfo *pTcon;
314 pTcon = cifs_sb->tcon;
321 cFYI(1,("set type: 0x%x id: %d",quota_type,qid));
330 int cifs_xquota_get(struct super_block * sb, int quota_type, qid_t qid,
331 struct fs_disk_quota * pdquota)
335 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
336 struct cifsTconInfo *pTcon;
339 pTcon = cifs_sb->tcon;
345 cFYI(1,("set type: 0x%x id: %d",quota_type,qid));
354 int cifs_xstate_set(struct super_block * sb, unsigned int flags, int operation)
358 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
359 struct cifsTconInfo *pTcon;
362 pTcon = cifs_sb->tcon;
368 cFYI(1,("flags: 0x%x operation: 0x%x",flags,operation));
377 int cifs_xstate_get(struct super_block * sb, struct fs_quota_stat *qstats)
381 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
382 struct cifsTconInfo *pTcon;
385 pTcon = cifs_sb->tcon;
391 cFYI(1,("pqstats %p",qstats));
400 static struct quotactl_ops cifs_quotactl_ops = {
401 .set_xquota = cifs_xquota_set,
402 .get_xquota = cifs_xquota_set,
403 .set_xstate = cifs_xstate_set,
404 .get_xstate = cifs_xstate_get,
408 #ifdef CONFIG_CIFS_EXPERIMENTAL
409 static void cifs_umount_begin(struct super_block * sblock)
411 struct cifs_sb_info *cifs_sb;
412 struct cifsTconInfo * tcon;
414 cifs_sb = CIFS_SB(sblock);
418 tcon = cifs_sb->tcon;
421 down(&tcon->tconSem);
422 if (atomic_read(&tcon->useCount) == 1)
423 tcon->tidStatus = CifsExiting;
426 /* cancel_brl_requests(tcon); */
427 /* cancel_notify_requests(tcon); */
428 if(tcon->ses && tcon->ses->server)
430 cFYI(1,("wake up tasks now - umount begin not complete"));
431 wake_up_all(&tcon->ses->server->request_q);
433 /* BB FIXME - finish add checks for tidStatus BB */
439 static int cifs_remount(struct super_block *sb, int *flags, char *data)
441 *flags |= MS_NODIRATIME;
445 struct super_operations cifs_super_ops = {
446 .read_inode = cifs_read_inode,
447 .put_super = cifs_put_super,
448 .statfs = cifs_statfs,
449 .alloc_inode = cifs_alloc_inode,
450 .destroy_inode = cifs_destroy_inode,
451 /* .drop_inode = generic_delete_inode,
452 .delete_inode = cifs_delete_inode, *//* Do not need the above two functions
453 unless later we add lazy close of inodes or unless the kernel forgets to call
454 us with the same number of releases (closes) as opens */
455 .show_options = cifs_show_options,
456 #ifdef CONFIG_CIFS_EXPERIMENTAL
457 .umount_begin = cifs_umount_begin,
459 .remount_fs = cifs_remount,
462 static struct super_block *
463 cifs_get_sb(struct file_system_type *fs_type,
464 int flags, const char *dev_name, void *data)
467 struct super_block *sb = sget(fs_type, NULL, set_anon_super, NULL);
469 cFYI(1, ("Devname: %s flags: %d ", dev_name, flags));
476 rc = cifs_read_super(sb, data, dev_name, flags & MS_VERBOSE ? 1 : 0);
478 up_write(&sb->s_umount);
479 deactivate_super(sb);
482 sb->s_flags |= MS_ACTIVE;
486 static ssize_t cifs_file_writev(struct file *file, const struct iovec *iov,
487 unsigned long nr_segs, loff_t *ppos)
489 struct inode *inode = file->f_dentry->d_inode;
492 written = generic_file_writev(file, iov, nr_segs, ppos);
493 if (!CIFS_I(inode)->clientCanCacheAll)
494 filemap_fdatawrite(inode->i_mapping);
498 static ssize_t cifs_file_aio_write(struct kiocb *iocb, const char __user *buf,
499 size_t count, loff_t pos)
501 struct inode *inode = iocb->ki_filp->f_dentry->d_inode;
504 written = generic_file_aio_write(iocb, buf, count, pos);
505 if (!CIFS_I(inode)->clientCanCacheAll)
506 filemap_fdatawrite(inode->i_mapping);
510 static struct file_system_type cifs_fs_type = {
511 .owner = THIS_MODULE,
513 .get_sb = cifs_get_sb,
514 .kill_sb = kill_anon_super,
517 struct inode_operations cifs_dir_inode_ops = {
518 .create = cifs_create,
519 .lookup = cifs_lookup,
520 .getattr = cifs_getattr,
521 .unlink = cifs_unlink,
522 .link = cifs_hardlink,
525 .rename = cifs_rename,
526 .permission = cifs_permission,
527 /* revalidate:cifs_revalidate, */
528 .setattr = cifs_setattr,
529 .symlink = cifs_symlink,
531 #ifdef CONFIG_CIFS_XATTR
532 .setxattr = cifs_setxattr,
533 .getxattr = cifs_getxattr,
534 .listxattr = cifs_listxattr,
535 .removexattr = cifs_removexattr,
539 struct inode_operations cifs_file_inode_ops = {
540 /* revalidate:cifs_revalidate, */
541 .setattr = cifs_setattr,
542 .getattr = cifs_getattr, /* do we need this anymore? */
543 .rename = cifs_rename,
544 .permission = cifs_permission,
545 #ifdef CONFIG_CIFS_XATTR
546 .setxattr = cifs_setxattr,
547 .getxattr = cifs_getxattr,
548 .listxattr = cifs_listxattr,
549 .removexattr = cifs_removexattr,
553 struct inode_operations cifs_symlink_inode_ops = {
554 .readlink = generic_readlink,
555 .follow_link = cifs_follow_link,
556 .put_link = cifs_put_link,
557 .permission = cifs_permission,
558 /* BB add the following two eventually */
559 /* revalidate: cifs_revalidate,
560 setattr: cifs_notify_change, *//* BB do we need notify change */
561 #ifdef CONFIG_CIFS_XATTR
562 .setxattr = cifs_setxattr,
563 .getxattr = cifs_getxattr,
564 .listxattr = cifs_listxattr,
565 .removexattr = cifs_removexattr,
569 struct file_operations cifs_file_ops = {
570 .read = do_sync_read,
571 .write = do_sync_write,
572 .readv = generic_file_readv,
573 .writev = cifs_file_writev,
574 .aio_read = generic_file_aio_read,
575 .aio_write = cifs_file_aio_write,
577 .release = cifs_close,
581 .mmap = cifs_file_mmap,
582 .sendfile = generic_file_sendfile,
583 #ifdef CONFIG_CIFS_POSIX
585 #endif /* CONFIG_CIFS_POSIX */
587 #ifdef CONFIG_CIFS_EXPERIMENTAL
588 .dir_notify = cifs_dir_notify,
589 #endif /* CONFIG_CIFS_EXPERIMENTAL */
592 struct file_operations cifs_file_direct_ops = {
593 /* no mmap, no aio, no readv -
594 BB reevaluate whether they can be done with directio, no cache */
595 .read = cifs_user_read,
596 .write = cifs_user_write,
598 .release = cifs_close,
602 .sendfile = generic_file_sendfile, /* BB removeme BB */
603 #ifdef CONFIG_CIFS_POSIX
605 #endif /* CONFIG_CIFS_POSIX */
607 #ifdef CONFIG_CIFS_EXPERIMENTAL
608 .dir_notify = cifs_dir_notify,
609 #endif /* CONFIG_CIFS_EXPERIMENTAL */
611 struct file_operations cifs_file_nobrl_ops = {
612 .read = do_sync_read,
613 .write = do_sync_write,
614 .readv = generic_file_readv,
615 .writev = cifs_file_writev,
616 .aio_read = generic_file_aio_read,
617 .aio_write = cifs_file_aio_write,
619 .release = cifs_close,
622 .mmap = cifs_file_mmap,
623 .sendfile = generic_file_sendfile,
624 #ifdef CONFIG_CIFS_POSIX
626 #endif /* CONFIG_CIFS_POSIX */
628 #ifdef CONFIG_CIFS_EXPERIMENTAL
629 .dir_notify = cifs_dir_notify,
630 #endif /* CONFIG_CIFS_EXPERIMENTAL */
633 struct file_operations cifs_file_direct_nobrl_ops = {
634 /* no mmap, no aio, no readv -
635 BB reevaluate whether they can be done with directio, no cache */
636 .read = cifs_user_read,
637 .write = cifs_user_write,
639 .release = cifs_close,
642 .sendfile = generic_file_sendfile, /* BB removeme BB */
643 #ifdef CONFIG_CIFS_POSIX
645 #endif /* CONFIG_CIFS_POSIX */
647 #ifdef CONFIG_CIFS_EXPERIMENTAL
648 .dir_notify = cifs_dir_notify,
649 #endif /* CONFIG_CIFS_EXPERIMENTAL */
652 struct file_operations cifs_dir_ops = {
653 .readdir = cifs_readdir,
654 .release = cifs_closedir,
655 .read = generic_read_dir,
656 #ifdef CONFIG_CIFS_EXPERIMENTAL
657 .dir_notify = cifs_dir_notify,
658 #endif /* CONFIG_CIFS_EXPERIMENTAL */
663 cifs_init_once(void *inode, kmem_cache_t * cachep, unsigned long flags)
665 struct cifsInodeInfo *cifsi = inode;
667 if ((flags & (SLAB_CTOR_VERIFY | SLAB_CTOR_CONSTRUCTOR)) ==
668 SLAB_CTOR_CONSTRUCTOR) {
669 inode_init_once(&cifsi->vfs_inode);
670 INIT_LIST_HEAD(&cifsi->lockList);
675 cifs_init_inodecache(void)
677 cifs_inode_cachep = kmem_cache_create("cifs_inode_cache",
678 sizeof (struct cifsInodeInfo),
679 0, SLAB_RECLAIM_ACCOUNT,
680 cifs_init_once, NULL);
681 if (cifs_inode_cachep == NULL)
688 cifs_destroy_inodecache(void)
690 if (kmem_cache_destroy(cifs_inode_cachep))
691 printk(KERN_WARNING "cifs_inode_cache: error freeing\n");
695 cifs_init_request_bufs(void)
697 if(CIFSMaxBufSize < 8192) {
698 /* Buffer size can not be smaller than 2 * PATH_MAX since maximum
699 Unicode path name has to fit in any SMB/CIFS path based frames */
700 CIFSMaxBufSize = 8192;
701 } else if (CIFSMaxBufSize > 1024*127) {
702 CIFSMaxBufSize = 1024 * 127;
704 CIFSMaxBufSize &= 0x1FE00; /* Round size to even 512 byte mult*/
706 /* cERROR(1,("CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize)); */
707 cifs_req_cachep = kmem_cache_create("cifs_request",
709 MAX_CIFS_HDR_SIZE, 0,
710 SLAB_HWCACHE_ALIGN, NULL, NULL);
711 if (cifs_req_cachep == NULL)
716 else if (cifs_min_rcv > 64) {
718 cERROR(1,("cifs_min_rcv set to maximum (64)"));
721 cifs_req_poolp = mempool_create(cifs_min_rcv,
726 if(cifs_req_poolp == NULL) {
727 kmem_cache_destroy(cifs_req_cachep);
730 /* 256 (MAX_CIFS_HDR_SIZE bytes is enough for most SMB responses and
731 almost all handle based requests (but not write response, nor is it
732 sufficient for path based requests). A smaller size would have
733 been more efficient (compacting multiple slab items on one 4k page)
734 for the case in which debug was on, but this larger size allows
735 more SMBs to use small buffer alloc and is still much more
736 efficient to alloc 1 per page off the slab compared to 17K (5page)
737 alloc of large cifs buffers even when page debugging is on */
738 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
739 MAX_CIFS_HDR_SIZE, 0, SLAB_HWCACHE_ALIGN, NULL, NULL);
740 if (cifs_sm_req_cachep == NULL) {
741 mempool_destroy(cifs_req_poolp);
742 kmem_cache_destroy(cifs_req_cachep);
746 if(cifs_min_small < 2)
748 else if (cifs_min_small > 256) {
749 cifs_min_small = 256;
750 cFYI(1,("cifs_min_small set to maximum (256)"));
753 cifs_sm_req_poolp = mempool_create(cifs_min_small,
758 if(cifs_sm_req_poolp == NULL) {
759 mempool_destroy(cifs_req_poolp);
760 kmem_cache_destroy(cifs_req_cachep);
761 kmem_cache_destroy(cifs_sm_req_cachep);
769 cifs_destroy_request_bufs(void)
771 mempool_destroy(cifs_req_poolp);
772 if (kmem_cache_destroy(cifs_req_cachep))
774 "cifs_destroy_request_cache: error not all structures were freed\n");
775 mempool_destroy(cifs_sm_req_poolp);
776 if (kmem_cache_destroy(cifs_sm_req_cachep))
778 "cifs_destroy_request_cache: cifs_small_rq free error\n");
784 cifs_mid_cachep = kmem_cache_create("cifs_mpx_ids",
785 sizeof (struct mid_q_entry), 0,
786 SLAB_HWCACHE_ALIGN, NULL, NULL);
787 if (cifs_mid_cachep == NULL)
790 cifs_mid_poolp = mempool_create(3 /* a reasonable min simultan opers */,
794 if(cifs_mid_poolp == NULL) {
795 kmem_cache_destroy(cifs_mid_cachep);
799 cifs_oplock_cachep = kmem_cache_create("cifs_oplock_structs",
800 sizeof (struct oplock_q_entry), 0,
801 SLAB_HWCACHE_ALIGN, NULL, NULL);
802 if (cifs_oplock_cachep == NULL) {
803 kmem_cache_destroy(cifs_mid_cachep);
804 mempool_destroy(cifs_mid_poolp);
812 cifs_destroy_mids(void)
814 mempool_destroy(cifs_mid_poolp);
815 if (kmem_cache_destroy(cifs_mid_cachep))
817 "cifs_destroy_mids: error not all structures were freed\n");
819 if (kmem_cache_destroy(cifs_oplock_cachep))
821 "error not all oplock structures were freed\n");
824 static int cifs_oplock_thread(void * dummyarg)
826 struct oplock_q_entry * oplock_item;
827 struct cifsTconInfo *pTcon;
828 struct inode * inode;
832 daemonize("cifsoplockd");
833 allow_signal(SIGTERM);
835 oplockThread = current;
840 spin_lock(&GlobalMid_Lock);
841 if(list_empty(&GlobalOplock_Q)) {
842 spin_unlock(&GlobalMid_Lock);
843 set_current_state(TASK_INTERRUPTIBLE);
844 schedule_timeout(39*HZ);
846 oplock_item = list_entry(GlobalOplock_Q.next,
847 struct oplock_q_entry, qhead);
849 cFYI(1,("found oplock item to write out"));
850 pTcon = oplock_item->tcon;
851 inode = oplock_item->pinode;
852 netfid = oplock_item->netfid;
853 spin_unlock(&GlobalMid_Lock);
854 DeleteOplockQEntry(oplock_item);
855 /* can not grab inode sem here since it would
856 deadlock when oplock received on delete
857 since vfs_unlink holds the i_sem across
859 /* down(&inode->i_sem);*/
860 if (S_ISREG(inode->i_mode)) {
861 rc = filemap_fdatawrite(inode->i_mapping);
862 if(CIFS_I(inode)->clientCanCacheRead == 0) {
863 filemap_fdatawait(inode->i_mapping);
864 invalidate_remote_inode(inode);
868 /* up(&inode->i_sem);*/
870 CIFS_I(inode)->write_behind_rc = rc;
871 cFYI(1,("Oplock flush inode %p rc %d",inode,rc));
873 /* releasing a stale oplock after recent reconnection
874 of smb session using a now incorrect file
875 handle is not a data integrity issue but do
876 not bother sending an oplock release if session
877 to server still is disconnected since oplock
878 already released by the server in that case */
879 if(pTcon->tidStatus != CifsNeedReconnect) {
880 rc = CIFSSMBLock(0, pTcon, netfid,
881 0 /* len */ , 0 /* offset */, 0,
882 0, LOCKING_ANDX_OPLOCK_RELEASE,
884 cFYI(1,("Oplock release rc = %d ",rc));
887 spin_unlock(&GlobalMid_Lock);
888 set_current_state(TASK_INTERRUPTIBLE);
889 schedule_timeout(1); /* yield in case q were corrupt */
891 } while(!signal_pending(current));
893 complete_and_exit (&cifs_oplock_exited, 0);
896 static int cifs_dnotify_thread(void * dummyarg)
898 daemonize("cifsdnotifyd");
899 allow_signal(SIGTERM);
901 dnotifyThread = current;
905 set_current_state(TASK_INTERRUPTIBLE);
906 schedule_timeout(39*HZ);
907 } while(!signal_pending(current));
908 complete_and_exit (&cifs_dnotify_exited, 0);
915 #ifdef CONFIG_PROC_FS
918 INIT_LIST_HEAD(&GlobalServerList); /* BB not implemented yet */
919 INIT_LIST_HEAD(&GlobalSMBSessionList);
920 INIT_LIST_HEAD(&GlobalTreeConnectionList);
921 INIT_LIST_HEAD(&GlobalOplock_Q);
922 #ifdef CONFIG_CIFS_EXPERIMENTAL
923 INIT_LIST_HEAD(&GlobalDnotifyReqList);
924 INIT_LIST_HEAD(&GlobalDnotifyRsp_Q);
927 * Initialize Global counters
929 atomic_set(&sesInfoAllocCount, 0);
930 atomic_set(&tconInfoAllocCount, 0);
931 atomic_set(&tcpSesAllocCount,0);
932 atomic_set(&tcpSesReconnectCount, 0);
933 atomic_set(&tconInfoReconnectCount, 0);
935 atomic_set(&bufAllocCount, 0);
936 atomic_set(&midCount, 0);
937 GlobalCurrentXid = 0;
938 GlobalTotalActiveXid = 0;
939 GlobalMaxActiveXid = 0;
940 rwlock_init(&GlobalSMBSeslock);
941 spin_lock_init(&GlobalMid_Lock);
943 if(cifs_max_pending < 2) {
944 cifs_max_pending = 2;
945 cFYI(1,("cifs_max_pending set to min of 2"));
946 } else if(cifs_max_pending > 256) {
947 cifs_max_pending = 256;
948 cFYI(1,("cifs_max_pending set to max of 256"));
951 rc = cifs_init_inodecache();
953 rc = cifs_init_mids();
955 rc = cifs_init_request_bufs();
957 rc = register_filesystem(&cifs_fs_type);
959 rc = (int)kernel_thread(cifs_oplock_thread, NULL,
960 CLONE_FS | CLONE_FILES | CLONE_VM);
962 rc = (int)kernel_thread(cifs_dnotify_thread, NULL,
963 CLONE_FS | CLONE_FILES | CLONE_VM);
967 cERROR(1,("error %d create dnotify thread", rc));
969 cERROR(1,("error %d create oplock thread",rc));
972 cifs_destroy_request_bufs();
976 cifs_destroy_inodecache();
978 #ifdef CONFIG_PROC_FS
987 cFYI(0, ("In unregister ie exit_cifs"));
988 #ifdef CONFIG_PROC_FS
991 unregister_filesystem(&cifs_fs_type);
992 cifs_destroy_inodecache();
994 cifs_destroy_request_bufs();
996 send_sig(SIGTERM, oplockThread, 1);
997 wait_for_completion(&cifs_oplock_exited);
1000 send_sig(SIGTERM, dnotifyThread, 1);
1001 wait_for_completion(&cifs_dnotify_exited);
1005 MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>");
1006 MODULE_LICENSE("GPL"); /* combination of LGPL + GPL source behaves as GPL */
1008 ("VFS to access servers complying with the SNIA CIFS Specification e.g. Samba and Windows");
1009 MODULE_VERSION(CIFS_VERSION);
1010 module_init(init_cifs)
1011 module_exit(exit_cifs)