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>
35 #include <linux/delay.h>
38 #define DECLARE_GLOBALS_HERE
40 #include "cifsproto.h"
41 #include "cifs_debug.h"
42 #include "cifs_fs_sb.h"
44 #define CIFS_MAGIC_NUMBER 0xFF534D42 /* the first four bytes of SMB PDUs */
46 #ifdef CONFIG_CIFS_QUOTA
47 static struct quotactl_ops cifs_quotactl_ops;
53 unsigned int oplockEnabled = 1;
54 unsigned int experimEnabled = 0;
55 unsigned int linuxExtEnabled = 1;
56 unsigned int lookupCacheEnabled = 1;
57 unsigned int multiuser_mount = 0;
58 unsigned int extended_security = 0;
59 unsigned int ntlmv2_support = 0;
60 unsigned int sign_CIFS_PDUs = 1;
61 extern struct task_struct * oplockThread; /* remove sparse warning */
62 struct task_struct * oplockThread = NULL;
63 extern struct task_struct * dnotifyThread; /* remove sparse warning */
64 struct task_struct * dnotifyThread = NULL;
65 unsigned int CIFSMaxBufSize = CIFS_MAX_MSGSIZE;
66 module_param(CIFSMaxBufSize, int, 0);
67 MODULE_PARM_DESC(CIFSMaxBufSize,"Network buffer size (not including header). 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: 1 to 64");
71 unsigned int cifs_min_small = 30;
72 module_param(cifs_min_small, int, 0);
73 MODULE_PARM_DESC(cifs_min_small,"Small network buffers in pool. Default: 30 Range: 2 to 256");
74 unsigned int cifs_max_pending = CIFS_MAX_REQ;
75 module_param(cifs_max_pending, int, 0);
76 MODULE_PARM_DESC(cifs_max_pending,"Simultaneous requests to server. Default: 50 Range: 2 to 256");
78 static DECLARE_COMPLETION(cifs_oplock_exited);
79 static DECLARE_COMPLETION(cifs_dnotify_exited);
81 extern mempool_t *cifs_sm_req_poolp;
82 extern mempool_t *cifs_req_poolp;
83 extern mempool_t *cifs_mid_poolp;
85 extern kmem_cache_t *cifs_oplock_cachep;
88 cifs_read_super(struct super_block *sb, void *data,
89 const char *devname, int silent)
92 struct cifs_sb_info *cifs_sb;
95 sb->s_flags |= MS_NODIRATIME; /* and probably even noatime */
96 sb->s_fs_info = kmalloc(sizeof(struct cifs_sb_info),GFP_KERNEL);
97 cifs_sb = CIFS_SB(sb);
101 memset(cifs_sb,0,sizeof(struct cifs_sb_info));
104 rc = cifs_mount(sb, cifs_sb, data, devname);
109 ("cifs_mount failed w/return code = %d", rc));
110 goto out_mount_failed;
113 sb->s_magic = CIFS_MAGIC_NUMBER;
114 sb->s_op = &cifs_super_ops;
115 /* if(cifs_sb->tcon->ses->server->maxBuf > MAX_CIFS_HDR_SIZE + 512)
116 sb->s_blocksize = cifs_sb->tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE; */
117 #ifdef CONFIG_CIFS_QUOTA
118 sb->s_qcop = &cifs_quotactl_ops;
120 sb->s_blocksize = CIFS_MAX_MSGSIZE;
121 sb->s_blocksize_bits = 14; /* default 2**14 = CIFS_MAX_MSGSIZE */
122 inode = iget(sb, ROOT_I);
129 sb->s_root = d_alloc_root(inode);
139 cERROR(1, ("cifs_read_super: get root inode failed"));
145 if(cifs_sb->local_nls)
146 unload_nls(cifs_sb->local_nls);
153 cifs_put_super(struct super_block *sb)
156 struct cifs_sb_info *cifs_sb;
158 cFYI(1, ("In cifs_put_super"));
159 cifs_sb = CIFS_SB(sb);
160 if(cifs_sb == NULL) {
161 cFYI(1,("Empty cifs superblock info passed to unmount"));
164 rc = cifs_umount(sb, cifs_sb);
166 cERROR(1, ("cifs_umount failed with return code %d", rc));
168 unload_nls(cifs_sb->local_nls);
174 cifs_statfs(struct super_block *sb, struct kstatfs *buf)
177 int rc = -EOPNOTSUPP;
178 struct cifs_sb_info *cifs_sb;
179 struct cifsTconInfo *pTcon;
183 cifs_sb = CIFS_SB(sb);
184 pTcon = cifs_sb->tcon;
186 buf->f_type = CIFS_MAGIC_NUMBER;
188 /* instead could get the real value via SMB_QUERY_FS_ATTRIBUTE_INFO */
189 buf->f_namelen = PATH_MAX; /* PATH_MAX may be too long - it would
190 presumably be total path, but note
191 that some servers (includinng Samba 3)
192 have a shorter maximum path */
193 buf->f_files = 0; /* undefined */
194 buf->f_ffree = 0; /* unlimited */
196 #ifdef CONFIG_CIFS_EXPERIMENTAL
197 /* BB we could add a second check for a QFS Unix capability bit */
198 /* BB FIXME check CIFS_POSIX_EXTENSIONS Unix cap first FIXME BB */
199 if ((pTcon->ses->capabilities & CAP_UNIX) && (CIFS_POSIX_EXTENSIONS &
200 le64_to_cpu(pTcon->fsUnixInfo.Capability)))
201 rc = CIFSSMBQFSPosixInfo(xid, pTcon, buf);
203 /* Only need to call the old QFSInfo if failed
206 #endif /* CIFS_EXPERIMENTAL */
207 rc = CIFSSMBQFSInfo(xid, pTcon, buf);
209 /* Old Windows servers do not support level 103, retry with level
210 one if old server failed the previous call */
212 rc = SMBOldQFSInfo(xid, pTcon, buf);
217 /* BB get from info in tcon struct at mount time call to QFSAttrInfo */
219 return 0; /* always return success? what if volume is no
223 static int cifs_permission(struct inode * inode, int mask, struct nameidata *nd)
225 struct cifs_sb_info *cifs_sb;
227 cifs_sb = CIFS_SB(inode->i_sb);
229 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) {
231 } else /* file mode might have been restricted at mount time
232 on the client (above and beyond ACL on servers) for
233 servers which do not support setting and viewing mode bits,
234 so allowing client to check permissions is useful */
235 return generic_permission(inode, mask, NULL);
238 static kmem_cache_t *cifs_inode_cachep;
239 static kmem_cache_t *cifs_req_cachep;
240 static kmem_cache_t *cifs_mid_cachep;
241 kmem_cache_t *cifs_oplock_cachep;
242 static kmem_cache_t *cifs_sm_req_cachep;
243 mempool_t *cifs_sm_req_poolp;
244 mempool_t *cifs_req_poolp;
245 mempool_t *cifs_mid_poolp;
247 static struct inode *
248 cifs_alloc_inode(struct super_block *sb)
250 struct cifsInodeInfo *cifs_inode;
251 cifs_inode = kmem_cache_alloc(cifs_inode_cachep, SLAB_KERNEL);
254 cifs_inode->cifsAttrs = 0x20; /* default */
255 atomic_set(&cifs_inode->inUse, 0);
256 cifs_inode->time = 0;
257 /* Until the file is open and we have gotten oplock
258 info back from the server, can not assume caching of
259 file data or metadata */
260 cifs_inode->clientCanCacheRead = FALSE;
261 cifs_inode->clientCanCacheAll = FALSE;
262 cifs_inode->vfs_inode.i_blksize = CIFS_MAX_MSGSIZE;
263 cifs_inode->vfs_inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */
264 cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME;
265 INIT_LIST_HEAD(&cifs_inode->openFileList);
266 return &cifs_inode->vfs_inode;
270 cifs_destroy_inode(struct inode *inode)
272 kmem_cache_free(cifs_inode_cachep, CIFS_I(inode));
276 * cifs_show_options() is for displaying mount options in /proc/mounts.
277 * Not all settable options are displayed but most of the important
281 cifs_show_options(struct seq_file *s, struct vfsmount *m)
283 struct cifs_sb_info *cifs_sb;
285 cifs_sb = CIFS_SB(m->mnt_sb);
289 seq_printf(s, ",unc=%s", cifs_sb->tcon->treeName);
290 if (cifs_sb->tcon->ses) {
291 if (cifs_sb->tcon->ses->userName)
292 seq_printf(s, ",username=%s",
293 cifs_sb->tcon->ses->userName);
294 if(cifs_sb->tcon->ses->domainName)
295 seq_printf(s, ",domain=%s",
296 cifs_sb->tcon->ses->domainName);
299 seq_printf(s, ",rsize=%d",cifs_sb->rsize);
300 seq_printf(s, ",wsize=%d",cifs_sb->wsize);
305 #ifdef CONFIG_CIFS_QUOTA
306 int cifs_xquota_set(struct super_block * sb, int quota_type, qid_t qid,
307 struct fs_disk_quota * pdquota)
311 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
312 struct cifsTconInfo *pTcon;
315 pTcon = cifs_sb->tcon;
322 cFYI(1,("set type: 0x%x id: %d",quota_type,qid));
331 int cifs_xquota_get(struct super_block * sb, int quota_type, qid_t qid,
332 struct fs_disk_quota * pdquota)
336 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
337 struct cifsTconInfo *pTcon;
340 pTcon = cifs_sb->tcon;
346 cFYI(1,("set type: 0x%x id: %d",quota_type,qid));
355 int cifs_xstate_set(struct super_block * sb, unsigned int flags, int operation)
359 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
360 struct cifsTconInfo *pTcon;
363 pTcon = cifs_sb->tcon;
369 cFYI(1,("flags: 0x%x operation: 0x%x",flags,operation));
378 int cifs_xstate_get(struct super_block * sb, struct fs_quota_stat *qstats)
382 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
383 struct cifsTconInfo *pTcon;
386 pTcon = cifs_sb->tcon;
392 cFYI(1,("pqstats %p",qstats));
401 static struct quotactl_ops cifs_quotactl_ops = {
402 .set_xquota = cifs_xquota_set,
403 .get_xquota = cifs_xquota_set,
404 .set_xstate = cifs_xstate_set,
405 .get_xstate = cifs_xstate_get,
409 #ifdef CONFIG_CIFS_EXPERIMENTAL
410 static void cifs_umount_begin(struct super_block * sblock)
412 struct cifs_sb_info *cifs_sb;
413 struct cifsTconInfo * tcon;
415 cifs_sb = CIFS_SB(sblock);
419 tcon = cifs_sb->tcon;
422 down(&tcon->tconSem);
423 if (atomic_read(&tcon->useCount) == 1)
424 tcon->tidStatus = CifsExiting;
427 /* cancel_brl_requests(tcon); */
428 /* cancel_notify_requests(tcon); */
429 if(tcon->ses && tcon->ses->server)
431 cFYI(1,("wake up tasks now - umount begin not complete"));
432 wake_up_all(&tcon->ses->server->request_q);
433 wake_up_all(&tcon->ses->server->response_q);
434 msleep(1); /* yield */
435 /* we have to kick the requests once more */
436 wake_up_all(&tcon->ses->server->response_q);
439 /* BB FIXME - finish add checks for tidStatus BB */
445 static int cifs_remount(struct super_block *sb, int *flags, char *data)
447 *flags |= MS_NODIRATIME;
451 struct super_operations cifs_super_ops = {
452 .read_inode = cifs_read_inode,
453 .put_super = cifs_put_super,
454 .statfs = cifs_statfs,
455 .alloc_inode = cifs_alloc_inode,
456 .destroy_inode = cifs_destroy_inode,
457 /* .drop_inode = generic_delete_inode,
458 .delete_inode = cifs_delete_inode, *//* Do not need the above two functions
459 unless later we add lazy close of inodes or unless the kernel forgets to call
460 us with the same number of releases (closes) as opens */
461 .show_options = cifs_show_options,
462 #ifdef CONFIG_CIFS_EXPERIMENTAL
463 .umount_begin = cifs_umount_begin,
465 .remount_fs = cifs_remount,
468 static struct super_block *
469 cifs_get_sb(struct file_system_type *fs_type,
470 int flags, const char *dev_name, void *data)
473 struct super_block *sb = sget(fs_type, NULL, set_anon_super, NULL);
475 cFYI(1, ("Devname: %s flags: %d ", dev_name, flags));
482 rc = cifs_read_super(sb, data, dev_name, flags & MS_VERBOSE ? 1 : 0);
484 up_write(&sb->s_umount);
485 deactivate_super(sb);
488 sb->s_flags |= MS_ACTIVE;
492 static ssize_t cifs_file_writev(struct file *file, const struct iovec *iov,
493 unsigned long nr_segs, loff_t *ppos)
495 struct inode *inode = file->f_dentry->d_inode;
498 written = generic_file_writev(file, iov, nr_segs, ppos);
499 if (!CIFS_I(inode)->clientCanCacheAll)
500 filemap_fdatawrite(inode->i_mapping);
504 static ssize_t cifs_file_aio_write(struct kiocb *iocb, const char __user *buf,
505 size_t count, loff_t pos)
507 struct inode *inode = iocb->ki_filp->f_dentry->d_inode;
510 written = generic_file_aio_write(iocb, buf, count, pos);
511 if (!CIFS_I(inode)->clientCanCacheAll)
512 filemap_fdatawrite(inode->i_mapping);
516 static struct file_system_type cifs_fs_type = {
517 .owner = THIS_MODULE,
519 .get_sb = cifs_get_sb,
520 .kill_sb = kill_anon_super,
523 struct inode_operations cifs_dir_inode_ops = {
524 .create = cifs_create,
525 .lookup = cifs_lookup,
526 .getattr = cifs_getattr,
527 .unlink = cifs_unlink,
528 .link = cifs_hardlink,
531 .rename = cifs_rename,
532 .permission = cifs_permission,
533 /* revalidate:cifs_revalidate, */
534 .setattr = cifs_setattr,
535 .symlink = cifs_symlink,
537 #ifdef CONFIG_CIFS_XATTR
538 .setxattr = cifs_setxattr,
539 .getxattr = cifs_getxattr,
540 .listxattr = cifs_listxattr,
541 .removexattr = cifs_removexattr,
545 struct inode_operations cifs_file_inode_ops = {
546 /* revalidate:cifs_revalidate, */
547 .setattr = cifs_setattr,
548 .getattr = cifs_getattr, /* do we need this anymore? */
549 .rename = cifs_rename,
550 .permission = cifs_permission,
551 #ifdef CONFIG_CIFS_XATTR
552 .setxattr = cifs_setxattr,
553 .getxattr = cifs_getxattr,
554 .listxattr = cifs_listxattr,
555 .removexattr = cifs_removexattr,
559 struct inode_operations cifs_symlink_inode_ops = {
560 .readlink = generic_readlink,
561 .follow_link = cifs_follow_link,
562 .put_link = cifs_put_link,
563 .permission = cifs_permission,
564 /* BB add the following two eventually */
565 /* revalidate: cifs_revalidate,
566 setattr: cifs_notify_change, *//* BB do we need notify change */
567 #ifdef CONFIG_CIFS_XATTR
568 .setxattr = cifs_setxattr,
569 .getxattr = cifs_getxattr,
570 .listxattr = cifs_listxattr,
571 .removexattr = cifs_removexattr,
575 struct file_operations cifs_file_ops = {
576 .read = do_sync_read,
577 .write = do_sync_write,
578 .readv = generic_file_readv,
579 .writev = cifs_file_writev,
580 .aio_read = generic_file_aio_read,
581 .aio_write = cifs_file_aio_write,
583 .release = cifs_close,
587 .mmap = cifs_file_mmap,
588 .sendfile = generic_file_sendfile,
589 #ifdef CONFIG_CIFS_POSIX
591 #endif /* CONFIG_CIFS_POSIX */
593 #ifdef CONFIG_CIFS_EXPERIMENTAL
594 .dir_notify = cifs_dir_notify,
595 #endif /* CONFIG_CIFS_EXPERIMENTAL */
598 struct file_operations cifs_file_direct_ops = {
599 /* no mmap, no aio, no readv -
600 BB reevaluate whether they can be done with directio, no cache */
601 .read = cifs_user_read,
602 .write = cifs_user_write,
604 .release = cifs_close,
608 .sendfile = generic_file_sendfile, /* BB removeme BB */
609 #ifdef CONFIG_CIFS_POSIX
611 #endif /* CONFIG_CIFS_POSIX */
613 #ifdef CONFIG_CIFS_EXPERIMENTAL
614 .dir_notify = cifs_dir_notify,
615 #endif /* CONFIG_CIFS_EXPERIMENTAL */
617 struct file_operations cifs_file_nobrl_ops = {
618 .read = do_sync_read,
619 .write = do_sync_write,
620 .readv = generic_file_readv,
621 .writev = cifs_file_writev,
622 .aio_read = generic_file_aio_read,
623 .aio_write = cifs_file_aio_write,
625 .release = cifs_close,
628 .mmap = cifs_file_mmap,
629 .sendfile = generic_file_sendfile,
630 #ifdef CONFIG_CIFS_POSIX
632 #endif /* CONFIG_CIFS_POSIX */
634 #ifdef CONFIG_CIFS_EXPERIMENTAL
635 .dir_notify = cifs_dir_notify,
636 #endif /* CONFIG_CIFS_EXPERIMENTAL */
639 struct file_operations cifs_file_direct_nobrl_ops = {
640 /* no mmap, no aio, no readv -
641 BB reevaluate whether they can be done with directio, no cache */
642 .read = cifs_user_read,
643 .write = cifs_user_write,
645 .release = cifs_close,
648 .sendfile = generic_file_sendfile, /* BB removeme BB */
649 #ifdef CONFIG_CIFS_POSIX
651 #endif /* CONFIG_CIFS_POSIX */
653 #ifdef CONFIG_CIFS_EXPERIMENTAL
654 .dir_notify = cifs_dir_notify,
655 #endif /* CONFIG_CIFS_EXPERIMENTAL */
658 struct file_operations cifs_dir_ops = {
659 .readdir = cifs_readdir,
660 .release = cifs_closedir,
661 .read = generic_read_dir,
662 #ifdef CONFIG_CIFS_EXPERIMENTAL
663 .dir_notify = cifs_dir_notify,
664 #endif /* CONFIG_CIFS_EXPERIMENTAL */
669 cifs_init_once(void *inode, kmem_cache_t * cachep, unsigned long flags)
671 struct cifsInodeInfo *cifsi = inode;
673 if ((flags & (SLAB_CTOR_VERIFY | SLAB_CTOR_CONSTRUCTOR)) ==
674 SLAB_CTOR_CONSTRUCTOR) {
675 inode_init_once(&cifsi->vfs_inode);
676 INIT_LIST_HEAD(&cifsi->lockList);
681 cifs_init_inodecache(void)
683 cifs_inode_cachep = kmem_cache_create("cifs_inode_cache",
684 sizeof (struct cifsInodeInfo),
685 0, SLAB_RECLAIM_ACCOUNT,
686 cifs_init_once, NULL);
687 if (cifs_inode_cachep == NULL)
694 cifs_destroy_inodecache(void)
696 if (kmem_cache_destroy(cifs_inode_cachep))
697 printk(KERN_WARNING "cifs_inode_cache: error freeing\n");
701 cifs_init_request_bufs(void)
703 if(CIFSMaxBufSize < 8192) {
704 /* Buffer size can not be smaller than 2 * PATH_MAX since maximum
705 Unicode path name has to fit in any SMB/CIFS path based frames */
706 CIFSMaxBufSize = 8192;
707 } else if (CIFSMaxBufSize > 1024*127) {
708 CIFSMaxBufSize = 1024 * 127;
710 CIFSMaxBufSize &= 0x1FE00; /* Round size to even 512 byte mult*/
712 /* cERROR(1,("CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize)); */
713 cifs_req_cachep = kmem_cache_create("cifs_request",
715 MAX_CIFS_HDR_SIZE, 0,
716 SLAB_HWCACHE_ALIGN, NULL, NULL);
717 if (cifs_req_cachep == NULL)
722 else if (cifs_min_rcv > 64) {
724 cERROR(1,("cifs_min_rcv set to maximum (64)"));
727 cifs_req_poolp = mempool_create(cifs_min_rcv,
732 if(cifs_req_poolp == NULL) {
733 kmem_cache_destroy(cifs_req_cachep);
736 /* MAX_CIFS_SMALL_BUFFER_SIZE bytes is enough for most SMB responses and
737 almost all handle based requests (but not write response, nor is it
738 sufficient for path based requests). A smaller size would have
739 been more efficient (compacting multiple slab items on one 4k page)
740 for the case in which debug was on, but this larger size allows
741 more SMBs to use small buffer alloc and is still much more
742 efficient to alloc 1 per page off the slab compared to 17K (5page)
743 alloc of large cifs buffers even when page debugging is on */
744 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
745 MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
747 if (cifs_sm_req_cachep == NULL) {
748 mempool_destroy(cifs_req_poolp);
749 kmem_cache_destroy(cifs_req_cachep);
753 if(cifs_min_small < 2)
755 else if (cifs_min_small > 256) {
756 cifs_min_small = 256;
757 cFYI(1,("cifs_min_small set to maximum (256)"));
760 cifs_sm_req_poolp = mempool_create(cifs_min_small,
765 if(cifs_sm_req_poolp == NULL) {
766 mempool_destroy(cifs_req_poolp);
767 kmem_cache_destroy(cifs_req_cachep);
768 kmem_cache_destroy(cifs_sm_req_cachep);
776 cifs_destroy_request_bufs(void)
778 mempool_destroy(cifs_req_poolp);
779 if (kmem_cache_destroy(cifs_req_cachep))
781 "cifs_destroy_request_cache: error not all structures were freed\n");
782 mempool_destroy(cifs_sm_req_poolp);
783 if (kmem_cache_destroy(cifs_sm_req_cachep))
785 "cifs_destroy_request_cache: cifs_small_rq free error\n");
791 cifs_mid_cachep = kmem_cache_create("cifs_mpx_ids",
792 sizeof (struct mid_q_entry), 0,
793 SLAB_HWCACHE_ALIGN, NULL, NULL);
794 if (cifs_mid_cachep == NULL)
797 cifs_mid_poolp = mempool_create(3 /* a reasonable min simultan opers */,
801 if(cifs_mid_poolp == NULL) {
802 kmem_cache_destroy(cifs_mid_cachep);
806 cifs_oplock_cachep = kmem_cache_create("cifs_oplock_structs",
807 sizeof (struct oplock_q_entry), 0,
808 SLAB_HWCACHE_ALIGN, NULL, NULL);
809 if (cifs_oplock_cachep == NULL) {
810 kmem_cache_destroy(cifs_mid_cachep);
811 mempool_destroy(cifs_mid_poolp);
819 cifs_destroy_mids(void)
821 mempool_destroy(cifs_mid_poolp);
822 if (kmem_cache_destroy(cifs_mid_cachep))
824 "cifs_destroy_mids: error not all structures were freed\n");
826 if (kmem_cache_destroy(cifs_oplock_cachep))
828 "error not all oplock structures were freed\n");
831 static int cifs_oplock_thread(void * dummyarg)
833 struct oplock_q_entry * oplock_item;
834 struct cifsTconInfo *pTcon;
835 struct inode * inode;
839 daemonize("cifsoplockd");
840 allow_signal(SIGTERM);
842 oplockThread = current;
847 spin_lock(&GlobalMid_Lock);
848 if(list_empty(&GlobalOplock_Q)) {
849 spin_unlock(&GlobalMid_Lock);
850 set_current_state(TASK_INTERRUPTIBLE);
851 schedule_timeout(39*HZ);
853 oplock_item = list_entry(GlobalOplock_Q.next,
854 struct oplock_q_entry, qhead);
856 cFYI(1,("found oplock item to write out"));
857 pTcon = oplock_item->tcon;
858 inode = oplock_item->pinode;
859 netfid = oplock_item->netfid;
860 spin_unlock(&GlobalMid_Lock);
861 DeleteOplockQEntry(oplock_item);
862 /* can not grab inode sem here since it would
863 deadlock when oplock received on delete
864 since vfs_unlink holds the i_sem across
866 /* down(&inode->i_sem);*/
867 if (S_ISREG(inode->i_mode)) {
868 rc = filemap_fdatawrite(inode->i_mapping);
869 if(CIFS_I(inode)->clientCanCacheRead == 0) {
870 filemap_fdatawait(inode->i_mapping);
871 invalidate_remote_inode(inode);
875 /* up(&inode->i_sem);*/
877 CIFS_I(inode)->write_behind_rc = rc;
878 cFYI(1,("Oplock flush inode %p rc %d",inode,rc));
880 /* releasing a stale oplock after recent reconnection
881 of smb session using a now incorrect file
882 handle is not a data integrity issue but do
883 not bother sending an oplock release if session
884 to server still is disconnected since oplock
885 already released by the server in that case */
886 if(pTcon->tidStatus != CifsNeedReconnect) {
887 rc = CIFSSMBLock(0, pTcon, netfid,
888 0 /* len */ , 0 /* offset */, 0,
889 0, LOCKING_ANDX_OPLOCK_RELEASE,
891 cFYI(1,("Oplock release rc = %d ",rc));
894 spin_unlock(&GlobalMid_Lock);
895 set_current_state(TASK_INTERRUPTIBLE);
896 schedule_timeout(1); /* yield in case q were corrupt */
898 } while(!signal_pending(current));
900 complete_and_exit (&cifs_oplock_exited, 0);
903 static int cifs_dnotify_thread(void * dummyarg)
905 struct list_head *tmp;
906 struct cifsSesInfo *ses;
908 daemonize("cifsdnotifyd");
909 allow_signal(SIGTERM);
911 dnotifyThread = current;
915 set_current_state(TASK_INTERRUPTIBLE);
916 schedule_timeout(15*HZ);
917 read_lock(&GlobalSMBSeslock);
918 /* check if any stuck requests that need
919 to be woken up and wakeq so the
920 thread can wake up and error out */
921 list_for_each(tmp, &GlobalSMBSessionList) {
922 ses = list_entry(tmp, struct cifsSesInfo,
924 if(ses && ses->server &&
925 atomic_read(&ses->server->inFlight))
926 wake_up_all(&ses->server->response_q);
928 read_unlock(&GlobalSMBSeslock);
929 } while(!signal_pending(current));
930 complete_and_exit (&cifs_dnotify_exited, 0);
937 #ifdef CONFIG_PROC_FS
940 INIT_LIST_HEAD(&GlobalServerList); /* BB not implemented yet */
941 INIT_LIST_HEAD(&GlobalSMBSessionList);
942 INIT_LIST_HEAD(&GlobalTreeConnectionList);
943 INIT_LIST_HEAD(&GlobalOplock_Q);
944 #ifdef CONFIG_CIFS_EXPERIMENTAL
945 INIT_LIST_HEAD(&GlobalDnotifyReqList);
946 INIT_LIST_HEAD(&GlobalDnotifyRsp_Q);
949 * Initialize Global counters
951 atomic_set(&sesInfoAllocCount, 0);
952 atomic_set(&tconInfoAllocCount, 0);
953 atomic_set(&tcpSesAllocCount,0);
954 atomic_set(&tcpSesReconnectCount, 0);
955 atomic_set(&tconInfoReconnectCount, 0);
957 atomic_set(&bufAllocCount, 0);
958 atomic_set(&smBufAllocCount, 0);
959 #ifdef CONFIG_CIFS_STATS2
960 atomic_set(&totBufAllocCount, 0);
961 atomic_set(&totSmBufAllocCount, 0);
962 #endif /* CONFIG_CIFS_STATS2 */
964 atomic_set(&midCount, 0);
965 GlobalCurrentXid = 0;
966 GlobalTotalActiveXid = 0;
967 GlobalMaxActiveXid = 0;
968 rwlock_init(&GlobalSMBSeslock);
969 spin_lock_init(&GlobalMid_Lock);
971 if(cifs_max_pending < 2) {
972 cifs_max_pending = 2;
973 cFYI(1,("cifs_max_pending set to min of 2"));
974 } else if(cifs_max_pending > 256) {
975 cifs_max_pending = 256;
976 cFYI(1,("cifs_max_pending set to max of 256"));
979 rc = cifs_init_inodecache();
981 rc = cifs_init_mids();
983 rc = cifs_init_request_bufs();
985 rc = register_filesystem(&cifs_fs_type);
987 rc = (int)kernel_thread(cifs_oplock_thread, NULL,
988 CLONE_FS | CLONE_FILES | CLONE_VM);
990 rc = (int)kernel_thread(cifs_dnotify_thread, NULL,
991 CLONE_FS | CLONE_FILES | CLONE_VM);
995 cERROR(1,("error %d create dnotify thread", rc));
997 cERROR(1,("error %d create oplock thread",rc));
1000 cifs_destroy_request_bufs();
1002 cifs_destroy_mids();
1004 cifs_destroy_inodecache();
1006 #ifdef CONFIG_PROC_FS
1015 cFYI(0, ("In unregister ie exit_cifs"));
1016 #ifdef CONFIG_PROC_FS
1019 unregister_filesystem(&cifs_fs_type);
1020 cifs_destroy_inodecache();
1021 cifs_destroy_mids();
1022 cifs_destroy_request_bufs();
1024 send_sig(SIGTERM, oplockThread, 1);
1025 wait_for_completion(&cifs_oplock_exited);
1028 send_sig(SIGTERM, dnotifyThread, 1);
1029 wait_for_completion(&cifs_dnotify_exited);
1033 MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>");
1034 MODULE_LICENSE("GPL"); /* combination of LGPL + GPL source behaves as GPL */
1036 ("VFS to access servers complying with the SNIA CIFS Specification e.g. Samba and Windows");
1037 MODULE_VERSION(CIFS_VERSION);
1038 module_init(init_cifs)
1039 module_exit(exit_cifs)