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>
36 #include <linux/kthread.h>
39 #define DECLARE_GLOBALS_HERE
41 #include "cifsproto.h"
42 #include "cifs_debug.h"
43 #include "cifs_fs_sb.h"
45 #define CIFS_MAGIC_NUMBER 0xFF534D42 /* the first four bytes of SMB PDUs */
47 #ifdef CONFIG_CIFS_QUOTA
48 static struct quotactl_ops cifs_quotactl_ops;
54 unsigned int oplockEnabled = 1;
55 unsigned int experimEnabled = 0;
56 unsigned int linuxExtEnabled = 1;
57 unsigned int lookupCacheEnabled = 1;
58 unsigned int multiuser_mount = 0;
59 unsigned int extended_security = CIFSSEC_DEF;
60 /* unsigned int ntlmv2_support = 0; */
61 unsigned int sign_CIFS_PDUs = 1;
62 extern struct task_struct * oplockThread; /* remove sparse warning */
63 struct task_struct * oplockThread = NULL;
64 extern struct task_struct * dnotifyThread; /* remove sparse warning */
65 struct task_struct * dnotifyThread = NULL;
66 static struct super_operations cifs_super_ops;
67 unsigned int CIFSMaxBufSize = CIFS_MAX_MSGSIZE;
68 module_param(CIFSMaxBufSize, int, 0);
69 MODULE_PARM_DESC(CIFSMaxBufSize,"Network buffer size (not including header). Default: 16384 Range: 8192 to 130048");
70 unsigned int cifs_min_rcv = CIFS_MIN_RCV_POOL;
71 module_param(cifs_min_rcv, int, 0);
72 MODULE_PARM_DESC(cifs_min_rcv,"Network buffers in pool. Default: 4 Range: 1 to 64");
73 unsigned int cifs_min_small = 30;
74 module_param(cifs_min_small, int, 0);
75 MODULE_PARM_DESC(cifs_min_small,"Small network buffers in pool. Default: 30 Range: 2 to 256");
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. Default: 50 Range: 2 to 256");
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 = kzalloc(sizeof(struct cifs_sb_info),GFP_KERNEL);
96 cifs_sb = CIFS_SB(sb);
100 rc = cifs_mount(sb, cifs_sb, data, devname);
105 ("cifs_mount failed w/return code = %d", rc));
106 goto out_mount_failed;
109 sb->s_magic = CIFS_MAGIC_NUMBER;
110 sb->s_op = &cifs_super_ops;
111 /* if(cifs_sb->tcon->ses->server->maxBuf > MAX_CIFS_HDR_SIZE + 512)
112 sb->s_blocksize = cifs_sb->tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE; */
113 #ifdef CONFIG_CIFS_QUOTA
114 sb->s_qcop = &cifs_quotactl_ops;
116 sb->s_blocksize = CIFS_MAX_MSGSIZE;
117 sb->s_blocksize_bits = 14; /* default 2**14 = CIFS_MAX_MSGSIZE */
118 inode = iget(sb, ROOT_I);
125 sb->s_root = d_alloc_root(inode);
135 cERROR(1, ("cifs_read_super: get root inode failed"));
141 if(cifs_sb->local_nls)
142 unload_nls(cifs_sb->local_nls);
149 cifs_put_super(struct super_block *sb)
152 struct cifs_sb_info *cifs_sb;
154 cFYI(1, ("In cifs_put_super"));
155 cifs_sb = CIFS_SB(sb);
156 if(cifs_sb == NULL) {
157 cFYI(1,("Empty cifs superblock info passed to unmount"));
160 rc = cifs_umount(sb, cifs_sb);
162 cERROR(1, ("cifs_umount failed with return code %d", rc));
164 unload_nls(cifs_sb->local_nls);
170 cifs_statfs(struct dentry *dentry, struct kstatfs *buf)
172 struct super_block *sb = dentry->d_sb;
174 int rc = -EOPNOTSUPP;
175 struct cifs_sb_info *cifs_sb;
176 struct cifsTconInfo *pTcon;
180 cifs_sb = CIFS_SB(sb);
181 pTcon = cifs_sb->tcon;
183 buf->f_type = CIFS_MAGIC_NUMBER;
185 /* instead could get the real value via SMB_QUERY_FS_ATTRIBUTE_INFO */
186 buf->f_namelen = PATH_MAX; /* PATH_MAX may be too long - it would
187 presumably be total path, but note
188 that some servers (includinng Samba 3)
189 have a shorter maximum path */
190 buf->f_files = 0; /* undefined */
191 buf->f_ffree = 0; /* unlimited */
193 /* BB we could add a second check for a QFS Unix capability bit */
194 /* BB FIXME check CIFS_POSIX_EXTENSIONS Unix cap first FIXME BB */
195 if ((pTcon->ses->capabilities & CAP_UNIX) && (CIFS_POSIX_EXTENSIONS &
196 le64_to_cpu(pTcon->fsUnixInfo.Capability)))
197 rc = CIFSSMBQFSPosixInfo(xid, pTcon, buf);
199 /* Only need to call the old QFSInfo if failed
202 if((pTcon->ses->flags & CIFS_SES_LANMAN) == 0)
203 rc = CIFSSMBQFSInfo(xid, pTcon, buf); /* not supported by OS2 */
205 /* Some old Windows servers also do not support level 103, retry with
206 older level one if old server failed the previous call or we
207 bypassed it because we detected that this was an older LANMAN sess */
209 rc = SMBOldQFSInfo(xid, pTcon, buf);
214 /* BB get from info in tcon struct at mount time call to QFSAttrInfo */
216 return 0; /* always return success? what if volume is no
220 static int cifs_permission(struct inode * inode, int mask, struct nameidata *nd)
222 struct cifs_sb_info *cifs_sb;
224 cifs_sb = CIFS_SB(inode->i_sb);
226 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) {
228 } else /* file mode might have been restricted at mount time
229 on the client (above and beyond ACL on servers) for
230 servers which do not support setting and viewing mode bits,
231 so allowing client to check permissions is useful */
232 return generic_permission(inode, mask, NULL);
235 static kmem_cache_t *cifs_inode_cachep;
236 static kmem_cache_t *cifs_req_cachep;
237 static kmem_cache_t *cifs_mid_cachep;
238 kmem_cache_t *cifs_oplock_cachep;
239 static kmem_cache_t *cifs_sm_req_cachep;
240 mempool_t *cifs_sm_req_poolp;
241 mempool_t *cifs_req_poolp;
242 mempool_t *cifs_mid_poolp;
244 static struct inode *
245 cifs_alloc_inode(struct super_block *sb)
247 struct cifsInodeInfo *cifs_inode;
248 cifs_inode = kmem_cache_alloc(cifs_inode_cachep, SLAB_KERNEL);
251 cifs_inode->cifsAttrs = 0x20; /* default */
252 atomic_set(&cifs_inode->inUse, 0);
253 cifs_inode->time = 0;
254 /* Until the file is open and we have gotten oplock
255 info back from the server, can not assume caching of
256 file data or metadata */
257 cifs_inode->clientCanCacheRead = FALSE;
258 cifs_inode->clientCanCacheAll = FALSE;
259 cifs_inode->vfs_inode.i_blksize = CIFS_MAX_MSGSIZE;
260 cifs_inode->vfs_inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */
261 cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME;
262 INIT_LIST_HEAD(&cifs_inode->openFileList);
263 return &cifs_inode->vfs_inode;
267 cifs_destroy_inode(struct inode *inode)
269 kmem_cache_free(cifs_inode_cachep, CIFS_I(inode));
273 * cifs_show_options() is for displaying mount options in /proc/mounts.
274 * Not all settable options are displayed but most of the important
278 cifs_show_options(struct seq_file *s, struct vfsmount *m)
280 struct cifs_sb_info *cifs_sb;
282 cifs_sb = CIFS_SB(m->mnt_sb);
286 seq_printf(s, ",unc=%s", cifs_sb->tcon->treeName);
287 if (cifs_sb->tcon->ses) {
288 if (cifs_sb->tcon->ses->userName)
289 seq_printf(s, ",username=%s",
290 cifs_sb->tcon->ses->userName);
291 if(cifs_sb->tcon->ses->domainName)
292 seq_printf(s, ",domain=%s",
293 cifs_sb->tcon->ses->domainName);
296 seq_printf(s, ",rsize=%d",cifs_sb->rsize);
297 seq_printf(s, ",wsize=%d",cifs_sb->wsize);
302 #ifdef CONFIG_CIFS_QUOTA
303 int cifs_xquota_set(struct super_block * sb, int quota_type, qid_t qid,
304 struct fs_disk_quota * pdquota)
308 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
309 struct cifsTconInfo *pTcon;
312 pTcon = cifs_sb->tcon;
319 cFYI(1,("set type: 0x%x id: %d",quota_type,qid));
328 int cifs_xquota_get(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;
343 cFYI(1,("set type: 0x%x id: %d",quota_type,qid));
352 int cifs_xstate_set(struct super_block * sb, unsigned int flags, int operation)
356 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
357 struct cifsTconInfo *pTcon;
360 pTcon = cifs_sb->tcon;
366 cFYI(1,("flags: 0x%x operation: 0x%x",flags,operation));
375 int cifs_xstate_get(struct super_block * sb, struct fs_quota_stat *qstats)
379 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
380 struct cifsTconInfo *pTcon;
383 pTcon = cifs_sb->tcon;
389 cFYI(1,("pqstats %p",qstats));
398 static struct quotactl_ops cifs_quotactl_ops = {
399 .set_xquota = cifs_xquota_set,
400 .get_xquota = cifs_xquota_set,
401 .set_xstate = cifs_xstate_set,
402 .get_xstate = cifs_xstate_get,
406 static void cifs_umount_begin(struct vfsmount * vfsmnt, int flags)
408 struct cifs_sb_info *cifs_sb;
409 struct cifsTconInfo * tcon;
411 if (!(flags & MNT_FORCE))
413 cifs_sb = CIFS_SB(vfsmnt->mnt_sb);
417 tcon = cifs_sb->tcon;
420 down(&tcon->tconSem);
421 if (atomic_read(&tcon->useCount) == 1)
422 tcon->tidStatus = CifsExiting;
425 /* cancel_brl_requests(tcon); */ /* BB mark all brl mids as exiting */
426 /* cancel_notify_requests(tcon); */
427 if(tcon->ses && tcon->ses->server)
429 cFYI(1,("wake up tasks now - umount begin not complete"));
430 wake_up_all(&tcon->ses->server->request_q);
431 wake_up_all(&tcon->ses->server->response_q);
432 msleep(1); /* yield */
433 /* we have to kick the requests once more */
434 wake_up_all(&tcon->ses->server->response_q);
437 /* BB FIXME - finish add checks for tidStatus BB */
442 #ifdef CONFIG_CIFS_STATS2
443 static int cifs_show_stats(struct seq_file *s, struct vfsmount *mnt)
450 static int cifs_remount(struct super_block *sb, int *flags, char *data)
452 *flags |= MS_NODIRATIME;
456 static struct super_operations cifs_super_ops = {
457 .read_inode = cifs_read_inode,
458 .put_super = cifs_put_super,
459 .statfs = cifs_statfs,
460 .alloc_inode = cifs_alloc_inode,
461 .destroy_inode = cifs_destroy_inode,
462 /* .drop_inode = generic_delete_inode,
463 .delete_inode = cifs_delete_inode, *//* Do not need the above two functions
464 unless later we add lazy close of inodes or unless the kernel forgets to call
465 us with the same number of releases (closes) as opens */
466 .show_options = cifs_show_options,
467 .umount_begin = cifs_umount_begin,
468 .remount_fs = cifs_remount,
469 #ifdef CONFIG_CIFS_STATS2
470 .show_stats = cifs_show_stats,
475 cifs_get_sb(struct file_system_type *fs_type,
476 int flags, const char *dev_name, void *data, struct vfsmount *mnt)
479 struct super_block *sb = sget(fs_type, NULL, set_anon_super, NULL);
481 cFYI(1, ("Devname: %s flags: %d ", dev_name, flags));
488 rc = cifs_read_super(sb, data, dev_name, flags & MS_SILENT ? 1 : 0);
490 up_write(&sb->s_umount);
491 deactivate_super(sb);
494 sb->s_flags |= MS_ACTIVE;
495 return simple_set_mnt(mnt, sb);
498 static ssize_t cifs_file_writev(struct file *file, const struct iovec *iov,
499 unsigned long nr_segs, loff_t *ppos)
501 struct inode *inode = file->f_dentry->d_inode;
504 written = generic_file_writev(file, iov, nr_segs, ppos);
505 if (!CIFS_I(inode)->clientCanCacheAll)
506 filemap_fdatawrite(inode->i_mapping);
510 static ssize_t cifs_file_aio_write(struct kiocb *iocb, const char __user *buf,
511 size_t count, loff_t pos)
513 struct inode *inode = iocb->ki_filp->f_dentry->d_inode;
516 written = generic_file_aio_write(iocb, buf, count, pos);
517 if (!CIFS_I(inode)->clientCanCacheAll)
518 filemap_fdatawrite(inode->i_mapping);
522 static loff_t cifs_llseek(struct file *file, loff_t offset, int origin)
524 /* origin == SEEK_END => we must revalidate the cached file length */
525 if (origin == SEEK_END) {
526 int retval = cifs_revalidate(file->f_dentry);
528 return (loff_t)retval;
530 return remote_llseek(file, offset, origin);
533 static struct file_system_type cifs_fs_type = {
534 .owner = THIS_MODULE,
536 .get_sb = cifs_get_sb,
537 .kill_sb = kill_anon_super,
540 struct inode_operations cifs_dir_inode_ops = {
541 .create = cifs_create,
542 .lookup = cifs_lookup,
543 .getattr = cifs_getattr,
544 .unlink = cifs_unlink,
545 .link = cifs_hardlink,
548 .rename = cifs_rename,
549 .permission = cifs_permission,
550 /* revalidate:cifs_revalidate, */
551 .setattr = cifs_setattr,
552 .symlink = cifs_symlink,
554 #ifdef CONFIG_CIFS_XATTR
555 .setxattr = cifs_setxattr,
556 .getxattr = cifs_getxattr,
557 .listxattr = cifs_listxattr,
558 .removexattr = cifs_removexattr,
562 struct inode_operations cifs_file_inode_ops = {
563 /* revalidate:cifs_revalidate, */
564 .setattr = cifs_setattr,
565 .getattr = cifs_getattr, /* do we need this anymore? */
566 .rename = cifs_rename,
567 .permission = cifs_permission,
568 #ifdef CONFIG_CIFS_XATTR
569 .setxattr = cifs_setxattr,
570 .getxattr = cifs_getxattr,
571 .listxattr = cifs_listxattr,
572 .removexattr = cifs_removexattr,
576 struct inode_operations cifs_symlink_inode_ops = {
577 .readlink = generic_readlink,
578 .follow_link = cifs_follow_link,
579 .put_link = cifs_put_link,
580 .permission = cifs_permission,
581 /* BB add the following two eventually */
582 /* revalidate: cifs_revalidate,
583 setattr: cifs_notify_change, *//* BB do we need notify change */
584 #ifdef CONFIG_CIFS_XATTR
585 .setxattr = cifs_setxattr,
586 .getxattr = cifs_getxattr,
587 .listxattr = cifs_listxattr,
588 .removexattr = cifs_removexattr,
592 const struct file_operations cifs_file_ops = {
593 .read = do_sync_read,
594 .write = do_sync_write,
595 .readv = generic_file_readv,
596 .writev = cifs_file_writev,
597 .aio_read = generic_file_aio_read,
598 .aio_write = cifs_file_aio_write,
600 .release = cifs_close,
604 .mmap = cifs_file_mmap,
605 .sendfile = generic_file_sendfile,
606 .llseek = cifs_llseek,
607 #ifdef CONFIG_CIFS_POSIX
609 #endif /* CONFIG_CIFS_POSIX */
611 #ifdef CONFIG_CIFS_EXPERIMENTAL
612 .dir_notify = cifs_dir_notify,
613 #endif /* CONFIG_CIFS_EXPERIMENTAL */
616 const struct file_operations cifs_file_direct_ops = {
617 /* no mmap, no aio, no readv -
618 BB reevaluate whether they can be done with directio, no cache */
619 .read = cifs_user_read,
620 .write = cifs_user_write,
622 .release = cifs_close,
626 .sendfile = generic_file_sendfile, /* BB removeme BB */
627 #ifdef CONFIG_CIFS_POSIX
629 #endif /* CONFIG_CIFS_POSIX */
630 .llseek = cifs_llseek,
631 #ifdef CONFIG_CIFS_EXPERIMENTAL
632 .dir_notify = cifs_dir_notify,
633 #endif /* CONFIG_CIFS_EXPERIMENTAL */
635 const struct file_operations cifs_file_nobrl_ops = {
636 .read = do_sync_read,
637 .write = do_sync_write,
638 .readv = generic_file_readv,
639 .writev = cifs_file_writev,
640 .aio_read = generic_file_aio_read,
641 .aio_write = cifs_file_aio_write,
643 .release = cifs_close,
646 .mmap = cifs_file_mmap,
647 .sendfile = generic_file_sendfile,
648 .llseek = cifs_llseek,
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 const struct file_operations cifs_file_direct_nobrl_ops = {
659 /* no mmap, no aio, no readv -
660 BB reevaluate whether they can be done with directio, no cache */
661 .read = cifs_user_read,
662 .write = cifs_user_write,
664 .release = cifs_close,
667 .sendfile = generic_file_sendfile, /* BB removeme BB */
668 #ifdef CONFIG_CIFS_POSIX
670 #endif /* CONFIG_CIFS_POSIX */
671 .llseek = cifs_llseek,
672 #ifdef CONFIG_CIFS_EXPERIMENTAL
673 .dir_notify = cifs_dir_notify,
674 #endif /* CONFIG_CIFS_EXPERIMENTAL */
677 const struct file_operations cifs_dir_ops = {
678 .readdir = cifs_readdir,
679 .release = cifs_closedir,
680 .read = generic_read_dir,
681 #ifdef CONFIG_CIFS_EXPERIMENTAL
682 .dir_notify = cifs_dir_notify,
683 #endif /* CONFIG_CIFS_EXPERIMENTAL */
688 cifs_init_once(void *inode, kmem_cache_t * cachep, unsigned long flags)
690 struct cifsInodeInfo *cifsi = inode;
692 if ((flags & (SLAB_CTOR_VERIFY | SLAB_CTOR_CONSTRUCTOR)) ==
693 SLAB_CTOR_CONSTRUCTOR) {
694 inode_init_once(&cifsi->vfs_inode);
695 INIT_LIST_HEAD(&cifsi->lockList);
700 cifs_init_inodecache(void)
702 cifs_inode_cachep = kmem_cache_create("cifs_inode_cache",
703 sizeof (struct cifsInodeInfo),
704 0, (SLAB_RECLAIM_ACCOUNT|
706 cifs_init_once, NULL);
707 if (cifs_inode_cachep == NULL)
714 cifs_destroy_inodecache(void)
716 if (kmem_cache_destroy(cifs_inode_cachep))
717 printk(KERN_WARNING "cifs_inode_cache: error freeing\n");
721 cifs_init_request_bufs(void)
723 if(CIFSMaxBufSize < 8192) {
724 /* Buffer size can not be smaller than 2 * PATH_MAX since maximum
725 Unicode path name has to fit in any SMB/CIFS path based frames */
726 CIFSMaxBufSize = 8192;
727 } else if (CIFSMaxBufSize > 1024*127) {
728 CIFSMaxBufSize = 1024 * 127;
730 CIFSMaxBufSize &= 0x1FE00; /* Round size to even 512 byte mult*/
732 /* cERROR(1,("CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize)); */
733 cifs_req_cachep = kmem_cache_create("cifs_request",
735 MAX_CIFS_HDR_SIZE, 0,
736 SLAB_HWCACHE_ALIGN, NULL, NULL);
737 if (cifs_req_cachep == NULL)
742 else if (cifs_min_rcv > 64) {
744 cERROR(1,("cifs_min_rcv set to maximum (64)"));
747 cifs_req_poolp = mempool_create_slab_pool(cifs_min_rcv,
750 if(cifs_req_poolp == NULL) {
751 kmem_cache_destroy(cifs_req_cachep);
754 /* MAX_CIFS_SMALL_BUFFER_SIZE bytes is enough for most SMB responses and
755 almost all handle based requests (but not write response, nor is it
756 sufficient for path based requests). A smaller size would have
757 been more efficient (compacting multiple slab items on one 4k page)
758 for the case in which debug was on, but this larger size allows
759 more SMBs to use small buffer alloc and is still much more
760 efficient to alloc 1 per page off the slab compared to 17K (5page)
761 alloc of large cifs buffers even when page debugging is on */
762 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
763 MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
765 if (cifs_sm_req_cachep == NULL) {
766 mempool_destroy(cifs_req_poolp);
767 kmem_cache_destroy(cifs_req_cachep);
771 if(cifs_min_small < 2)
773 else if (cifs_min_small > 256) {
774 cifs_min_small = 256;
775 cFYI(1,("cifs_min_small set to maximum (256)"));
778 cifs_sm_req_poolp = mempool_create_slab_pool(cifs_min_small,
781 if(cifs_sm_req_poolp == NULL) {
782 mempool_destroy(cifs_req_poolp);
783 kmem_cache_destroy(cifs_req_cachep);
784 kmem_cache_destroy(cifs_sm_req_cachep);
792 cifs_destroy_request_bufs(void)
794 mempool_destroy(cifs_req_poolp);
795 if (kmem_cache_destroy(cifs_req_cachep))
797 "cifs_destroy_request_cache: error not all structures were freed\n");
798 mempool_destroy(cifs_sm_req_poolp);
799 if (kmem_cache_destroy(cifs_sm_req_cachep))
801 "cifs_destroy_request_cache: cifs_small_rq free error\n");
807 cifs_mid_cachep = kmem_cache_create("cifs_mpx_ids",
808 sizeof (struct mid_q_entry), 0,
809 SLAB_HWCACHE_ALIGN, NULL, NULL);
810 if (cifs_mid_cachep == NULL)
813 /* 3 is a reasonable minimum number of simultaneous operations */
814 cifs_mid_poolp = mempool_create_slab_pool(3, cifs_mid_cachep);
815 if(cifs_mid_poolp == NULL) {
816 kmem_cache_destroy(cifs_mid_cachep);
820 cifs_oplock_cachep = kmem_cache_create("cifs_oplock_structs",
821 sizeof (struct oplock_q_entry), 0,
822 SLAB_HWCACHE_ALIGN, NULL, NULL);
823 if (cifs_oplock_cachep == NULL) {
824 kmem_cache_destroy(cifs_mid_cachep);
825 mempool_destroy(cifs_mid_poolp);
833 cifs_destroy_mids(void)
835 mempool_destroy(cifs_mid_poolp);
836 if (kmem_cache_destroy(cifs_mid_cachep))
838 "cifs_destroy_mids: error not all structures were freed\n");
840 if (kmem_cache_destroy(cifs_oplock_cachep))
842 "error not all oplock structures were freed\n");
845 static int cifs_oplock_thread(void * dummyarg)
847 struct oplock_q_entry * oplock_item;
848 struct cifsTconInfo *pTcon;
849 struct inode * inode;
857 spin_lock(&GlobalMid_Lock);
858 if(list_empty(&GlobalOplock_Q)) {
859 spin_unlock(&GlobalMid_Lock);
860 set_current_state(TASK_INTERRUPTIBLE);
861 schedule_timeout(39*HZ);
863 oplock_item = list_entry(GlobalOplock_Q.next,
864 struct oplock_q_entry, qhead);
866 cFYI(1,("found oplock item to write out"));
867 pTcon = oplock_item->tcon;
868 inode = oplock_item->pinode;
869 netfid = oplock_item->netfid;
870 spin_unlock(&GlobalMid_Lock);
871 DeleteOplockQEntry(oplock_item);
872 /* can not grab inode sem here since it would
873 deadlock when oplock received on delete
874 since vfs_unlink holds the i_mutex across
876 /* mutex_lock(&inode->i_mutex);*/
877 if (S_ISREG(inode->i_mode)) {
878 rc = filemap_fdatawrite(inode->i_mapping);
879 if(CIFS_I(inode)->clientCanCacheRead == 0) {
880 filemap_fdatawait(inode->i_mapping);
881 invalidate_remote_inode(inode);
885 /* mutex_unlock(&inode->i_mutex);*/
887 CIFS_I(inode)->write_behind_rc = rc;
888 cFYI(1,("Oplock flush inode %p rc %d",inode,rc));
890 /* releasing a stale oplock after recent reconnection
891 of smb session using a now incorrect file
892 handle is not a data integrity issue but do
893 not bother sending an oplock release if session
894 to server still is disconnected since oplock
895 already released by the server in that case */
896 if(pTcon->tidStatus != CifsNeedReconnect) {
897 rc = CIFSSMBLock(0, pTcon, netfid,
898 0 /* len */ , 0 /* offset */, 0,
899 0, LOCKING_ANDX_OPLOCK_RELEASE,
901 cFYI(1,("Oplock release rc = %d ",rc));
904 spin_unlock(&GlobalMid_Lock);
905 set_current_state(TASK_INTERRUPTIBLE);
906 schedule_timeout(1); /* yield in case q were corrupt */
908 } while (!kthread_should_stop());
913 static int cifs_dnotify_thread(void * dummyarg)
915 struct list_head *tmp;
916 struct cifsSesInfo *ses;
921 set_current_state(TASK_INTERRUPTIBLE);
922 schedule_timeout(15*HZ);
923 read_lock(&GlobalSMBSeslock);
924 /* check if any stuck requests that need
925 to be woken up and wakeq so the
926 thread can wake up and error out */
927 list_for_each(tmp, &GlobalSMBSessionList) {
928 ses = list_entry(tmp, struct cifsSesInfo,
930 if(ses && ses->server &&
931 atomic_read(&ses->server->inFlight))
932 wake_up_all(&ses->server->response_q);
934 read_unlock(&GlobalSMBSeslock);
935 } while (!kthread_should_stop());
944 #ifdef CONFIG_PROC_FS
947 /* INIT_LIST_HEAD(&GlobalServerList);*/ /* BB not implemented yet */
948 INIT_LIST_HEAD(&GlobalSMBSessionList);
949 INIT_LIST_HEAD(&GlobalTreeConnectionList);
950 INIT_LIST_HEAD(&GlobalOplock_Q);
951 #ifdef CONFIG_CIFS_EXPERIMENTAL
952 INIT_LIST_HEAD(&GlobalDnotifyReqList);
953 INIT_LIST_HEAD(&GlobalDnotifyRsp_Q);
956 * Initialize Global counters
958 atomic_set(&sesInfoAllocCount, 0);
959 atomic_set(&tconInfoAllocCount, 0);
960 atomic_set(&tcpSesAllocCount,0);
961 atomic_set(&tcpSesReconnectCount, 0);
962 atomic_set(&tconInfoReconnectCount, 0);
964 atomic_set(&bufAllocCount, 0);
965 atomic_set(&smBufAllocCount, 0);
966 #ifdef CONFIG_CIFS_STATS2
967 atomic_set(&totBufAllocCount, 0);
968 atomic_set(&totSmBufAllocCount, 0);
969 #endif /* CONFIG_CIFS_STATS2 */
971 atomic_set(&midCount, 0);
972 GlobalCurrentXid = 0;
973 GlobalTotalActiveXid = 0;
974 GlobalMaxActiveXid = 0;
975 memset(Local_System_Name, 0, 15);
976 rwlock_init(&GlobalSMBSeslock);
977 spin_lock_init(&GlobalMid_Lock);
979 if(cifs_max_pending < 2) {
980 cifs_max_pending = 2;
981 cFYI(1,("cifs_max_pending set to min of 2"));
982 } else if(cifs_max_pending > 256) {
983 cifs_max_pending = 256;
984 cFYI(1,("cifs_max_pending set to max of 256"));
987 rc = cifs_init_inodecache();
991 rc = cifs_init_mids();
993 goto out_destroy_inodecache;
995 rc = cifs_init_request_bufs();
997 goto out_destroy_mids;
999 rc = register_filesystem(&cifs_fs_type);
1001 goto out_destroy_request_bufs;
1003 oplockThread = kthread_run(cifs_oplock_thread, NULL, "cifsoplockd");
1004 if (IS_ERR(oplockThread)) {
1005 rc = PTR_ERR(oplockThread);
1006 cERROR(1,("error %d create oplock thread", rc));
1007 goto out_unregister_filesystem;
1010 dnotifyThread = kthread_run(cifs_dnotify_thread, NULL, "cifsdnotifyd");
1011 if (IS_ERR(dnotifyThread)) {
1012 rc = PTR_ERR(dnotifyThread);
1013 cERROR(1,("error %d create dnotify thread", rc));
1014 goto out_stop_oplock_thread;
1019 out_stop_oplock_thread:
1020 kthread_stop(oplockThread);
1021 out_unregister_filesystem:
1022 unregister_filesystem(&cifs_fs_type);
1023 out_destroy_request_bufs:
1024 cifs_destroy_request_bufs();
1026 cifs_destroy_mids();
1027 out_destroy_inodecache:
1028 cifs_destroy_inodecache();
1030 #ifdef CONFIG_PROC_FS
1039 cFYI(0, ("In unregister ie exit_cifs"));
1040 #ifdef CONFIG_PROC_FS
1043 unregister_filesystem(&cifs_fs_type);
1044 cifs_destroy_inodecache();
1045 cifs_destroy_mids();
1046 cifs_destroy_request_bufs();
1047 kthread_stop(oplockThread);
1048 kthread_stop(dnotifyThread);
1051 MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>");
1052 MODULE_LICENSE("GPL"); /* combination of LGPL + GPL source behaves as GPL */
1054 ("VFS to access servers complying with the SNIA CIFS Specification e.g. Samba and Windows");
1055 MODULE_VERSION(CIFS_VERSION);
1056 module_init(init_cifs)
1057 module_exit(exit_cifs)