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);
212 /* BB get from info in tcon struct at mount time call to QFSAttrInfo */
214 return 0; /* always return success? what if volume is no
218 static int cifs_permission(struct inode * inode, int mask, struct nameidata *nd)
220 struct cifs_sb_info *cifs_sb;
222 cifs_sb = CIFS_SB(inode->i_sb);
224 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) {
226 } else /* file mode might have been restricted at mount time
227 on the client (above and beyond ACL on servers) for
228 servers which do not support setting and viewing mode bits,
229 so allowing client to check permissions is useful */
230 return generic_permission(inode, mask, NULL);
233 static kmem_cache_t *cifs_inode_cachep;
234 static kmem_cache_t *cifs_req_cachep;
235 static kmem_cache_t *cifs_mid_cachep;
236 kmem_cache_t *cifs_oplock_cachep;
237 static kmem_cache_t *cifs_sm_req_cachep;
238 mempool_t *cifs_sm_req_poolp;
239 mempool_t *cifs_req_poolp;
240 mempool_t *cifs_mid_poolp;
242 static struct inode *
243 cifs_alloc_inode(struct super_block *sb)
245 struct cifsInodeInfo *cifs_inode;
246 cifs_inode = kmem_cache_alloc(cifs_inode_cachep, SLAB_KERNEL);
249 cifs_inode->cifsAttrs = 0x20; /* default */
250 atomic_set(&cifs_inode->inUse, 0);
251 cifs_inode->time = 0;
252 /* Until the file is open and we have gotten oplock
253 info back from the server, can not assume caching of
254 file data or metadata */
255 cifs_inode->clientCanCacheRead = FALSE;
256 cifs_inode->clientCanCacheAll = FALSE;
257 cifs_inode->vfs_inode.i_blksize = CIFS_MAX_MSGSIZE;
258 cifs_inode->vfs_inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */
260 INIT_LIST_HEAD(&cifs_inode->openFileList);
261 return &cifs_inode->vfs_inode;
265 cifs_destroy_inode(struct inode *inode)
267 kmem_cache_free(cifs_inode_cachep, CIFS_I(inode));
271 * cifs_show_options() is for displaying mount options in /proc/mounts.
272 * Not all settable options are displayed but most of the important
276 cifs_show_options(struct seq_file *s, struct vfsmount *m)
278 struct cifs_sb_info *cifs_sb;
280 cifs_sb = CIFS_SB(m->mnt_sb);
284 seq_printf(s, ",unc=%s", cifs_sb->tcon->treeName);
285 if (cifs_sb->tcon->ses) {
286 if (cifs_sb->tcon->ses->userName)
287 seq_printf(s, ",username=%s",
288 cifs_sb->tcon->ses->userName);
289 if(cifs_sb->tcon->ses->domainName)
290 seq_printf(s, ",domain=%s",
291 cifs_sb->tcon->ses->domainName);
294 seq_printf(s, ",rsize=%d",cifs_sb->rsize);
295 seq_printf(s, ",wsize=%d",cifs_sb->wsize);
300 #ifdef CONFIG_CIFS_QUOTA
301 int cifs_xquota_set(struct super_block * sb, int quota_type, qid_t qid,
302 struct fs_disk_quota * pdquota)
306 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
307 struct cifsTconInfo *pTcon;
310 pTcon = cifs_sb->tcon;
317 cFYI(1,("set type: 0x%x id: %d",quota_type,qid));
326 int cifs_xquota_get(struct super_block * sb, int quota_type, qid_t qid,
327 struct fs_disk_quota * pdquota)
331 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
332 struct cifsTconInfo *pTcon;
335 pTcon = cifs_sb->tcon;
341 cFYI(1,("set type: 0x%x id: %d",quota_type,qid));
350 int cifs_xstate_set(struct super_block * sb, unsigned int flags, int operation)
354 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
355 struct cifsTconInfo *pTcon;
358 pTcon = cifs_sb->tcon;
364 cFYI(1,("flags: 0x%x operation: 0x%x",flags,operation));
373 int cifs_xstate_get(struct super_block * sb, struct fs_quota_stat *qstats)
377 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
378 struct cifsTconInfo *pTcon;
381 pTcon = cifs_sb->tcon;
387 cFYI(1,("pqstats %p",qstats));
396 static struct quotactl_ops cifs_quotactl_ops = {
397 .set_xquota = cifs_xquota_set,
398 .get_xquota = cifs_xquota_set,
399 .set_xstate = cifs_xstate_set,
400 .get_xstate = cifs_xstate_get,
404 static int cifs_remount(struct super_block *sb, int *flags, char *data)
406 *flags |= MS_NODIRATIME;
410 struct super_operations cifs_super_ops = {
411 .read_inode = cifs_read_inode,
412 .put_super = cifs_put_super,
413 .statfs = cifs_statfs,
414 .alloc_inode = cifs_alloc_inode,
415 .destroy_inode = cifs_destroy_inode,
416 /* .drop_inode = generic_delete_inode,
417 .delete_inode = cifs_delete_inode, *//* Do not need the above two functions
418 unless later we add lazy close of inodes or unless the kernel forgets to call
419 us with the same number of releases (closes) as opens */
420 .show_options = cifs_show_options,
421 /* .umount_begin = cifs_umount_begin, *//* consider adding in the future */
422 .remount_fs = cifs_remount,
425 static struct super_block *
426 cifs_get_sb(struct file_system_type *fs_type,
427 int flags, const char *dev_name, void *data)
430 struct super_block *sb = sget(fs_type, NULL, set_anon_super, NULL);
432 cFYI(1, ("Devname: %s flags: %d ", dev_name, flags));
439 rc = cifs_read_super(sb, data, dev_name, flags & MS_VERBOSE ? 1 : 0);
441 up_write(&sb->s_umount);
442 deactivate_super(sb);
445 sb->s_flags |= MS_ACTIVE;
450 cifs_read_wrapper(struct file * file, char __user *read_data, size_t read_size,
453 if(file->f_dentry == NULL)
455 else if(file->f_dentry->d_inode == NULL)
458 cFYI(1,("In read_wrapper size %zd at %lld",read_size,*poffset));
460 if(CIFS_I(file->f_dentry->d_inode)->clientCanCacheRead) {
461 return generic_file_read(file,read_data,read_size,poffset);
463 /* BB do we need to lock inode from here until after invalidate? */
464 /* if(file->f_dentry->d_inode->i_mapping) {
465 filemap_fdatawrite(file->f_dentry->d_inode->i_mapping);
466 filemap_fdatawait(file->f_dentry->d_inode->i_mapping);
468 /* cifs_revalidate(file->f_dentry);*/ /* BB fixme */
470 /* BB we should make timer configurable - perhaps
471 by simply calling cifs_revalidate here */
472 /* invalidate_remote_inode(file->f_dentry->d_inode);*/
473 return generic_file_read(file,read_data,read_size,poffset);
478 cifs_write_wrapper(struct file * file, const char __user *write_data,
479 size_t write_size, loff_t * poffset)
483 if(file->f_dentry == NULL)
485 else if(file->f_dentry->d_inode == NULL)
488 cFYI(1,("In write_wrapper size %zd at %lld",write_size,*poffset));
490 written = generic_file_write(file,write_data,write_size,poffset);
491 if(!CIFS_I(file->f_dentry->d_inode)->clientCanCacheAll) {
492 if(file->f_dentry->d_inode->i_mapping) {
493 filemap_fdatawrite(file->f_dentry->d_inode->i_mapping);
500 static struct file_system_type cifs_fs_type = {
501 .owner = THIS_MODULE,
503 .get_sb = cifs_get_sb,
504 .kill_sb = kill_anon_super,
507 struct inode_operations cifs_dir_inode_ops = {
508 .create = cifs_create,
509 .lookup = cifs_lookup,
510 .getattr = cifs_getattr,
511 .unlink = cifs_unlink,
512 .link = cifs_hardlink,
515 .rename = cifs_rename,
516 .permission = cifs_permission,
517 /* revalidate:cifs_revalidate, */
518 .setattr = cifs_setattr,
519 .symlink = cifs_symlink,
521 #ifdef CONFIG_CIFS_XATTR
522 .setxattr = cifs_setxattr,
523 .getxattr = cifs_getxattr,
524 .listxattr = cifs_listxattr,
525 .removexattr = cifs_removexattr,
529 struct inode_operations cifs_file_inode_ops = {
530 /* revalidate:cifs_revalidate, */
531 .setattr = cifs_setattr,
532 .getattr = cifs_getattr, /* do we need this anymore? */
533 .rename = cifs_rename,
534 .permission = cifs_permission,
535 #ifdef CONFIG_CIFS_XATTR
536 .setxattr = cifs_setxattr,
537 .getxattr = cifs_getxattr,
538 .listxattr = cifs_listxattr,
539 .removexattr = cifs_removexattr,
543 struct inode_operations cifs_symlink_inode_ops = {
544 .readlink = generic_readlink,
545 .follow_link = cifs_follow_link,
546 .put_link = cifs_put_link,
547 .permission = cifs_permission,
548 /* BB add the following two eventually */
549 /* revalidate: cifs_revalidate,
550 setattr: cifs_notify_change, *//* BB do we need notify change */
551 #ifdef CONFIG_CIFS_XATTR
552 .setxattr = cifs_setxattr,
553 .getxattr = cifs_getxattr,
554 .listxattr = cifs_listxattr,
555 .removexattr = cifs_removexattr,
559 struct file_operations cifs_file_ops = {
560 .read = cifs_read_wrapper,
561 .write = cifs_write_wrapper,
563 .release = cifs_close,
567 .mmap = cifs_file_mmap,
568 .sendfile = generic_file_sendfile,
569 #ifdef CONFIG_CIFS_POSIX
571 #endif /* CONFIG_CIFS_POSIX */
573 #ifdef CONFIG_CIFS_EXPERIMENTAL
574 .readv = generic_file_readv,
575 .writev = generic_file_writev,
576 .aio_read = generic_file_aio_read,
577 .aio_write = generic_file_aio_write,
578 .dir_notify = cifs_dir_notify,
579 #endif /* CONFIG_CIFS_EXPERIMENTAL */
582 struct file_operations cifs_file_direct_ops = {
583 /* no mmap, no aio, no readv -
584 BB reevaluate whether they can be done with directio, no cache */
585 .read = cifs_user_read,
586 .write = cifs_user_write,
588 .release = cifs_close,
592 .sendfile = generic_file_sendfile, /* BB removeme BB */
593 #ifdef CONFIG_CIFS_POSIX
595 #endif /* CONFIG_CIFS_POSIX */
597 #ifdef CONFIG_CIFS_EXPERIMENTAL
598 .dir_notify = cifs_dir_notify,
599 #endif /* CONFIG_CIFS_EXPERIMENTAL */
602 struct file_operations cifs_dir_ops = {
603 .readdir = cifs_readdir,
604 .release = cifs_closedir,
605 .read = generic_read_dir,
606 #ifdef CONFIG_CIFS_EXPERIMENTAL
607 .dir_notify = cifs_dir_notify,
608 #endif /* CONFIG_CIFS_EXPERIMENTAL */
613 cifs_init_once(void *inode, kmem_cache_t * cachep, unsigned long flags)
615 struct cifsInodeInfo *cifsi = inode;
617 if ((flags & (SLAB_CTOR_VERIFY | SLAB_CTOR_CONSTRUCTOR)) ==
618 SLAB_CTOR_CONSTRUCTOR) {
619 inode_init_once(&cifsi->vfs_inode);
620 INIT_LIST_HEAD(&cifsi->lockList);
625 cifs_init_inodecache(void)
627 cifs_inode_cachep = kmem_cache_create("cifs_inode_cache",
628 sizeof (struct cifsInodeInfo),
629 0, SLAB_RECLAIM_ACCOUNT,
630 cifs_init_once, NULL);
631 if (cifs_inode_cachep == NULL)
638 cifs_destroy_inodecache(void)
640 if (kmem_cache_destroy(cifs_inode_cachep))
641 printk(KERN_WARNING "cifs_inode_cache: error freeing\n");
645 cifs_init_request_bufs(void)
647 if(CIFSMaxBufSize < 8192) {
648 /* Buffer size can not be smaller than 2 * PATH_MAX since maximum
649 Unicode path name has to fit in any SMB/CIFS path based frames */
650 CIFSMaxBufSize = 8192;
651 } else if (CIFSMaxBufSize > 1024*127) {
652 CIFSMaxBufSize = 1024 * 127;
654 CIFSMaxBufSize &= 0x1FE00; /* Round size to even 512 byte mult*/
656 /* cERROR(1,("CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize)); */
657 cifs_req_cachep = kmem_cache_create("cifs_request",
659 MAX_CIFS_HDR_SIZE, 0,
660 SLAB_HWCACHE_ALIGN, NULL, NULL);
661 if (cifs_req_cachep == NULL)
666 else if (cifs_min_rcv > 64) {
668 cERROR(1,("cifs_min_rcv set to maximum (64)"));
671 cifs_req_poolp = mempool_create(cifs_min_rcv,
676 if(cifs_req_poolp == NULL) {
677 kmem_cache_destroy(cifs_req_cachep);
680 /* 256 (MAX_CIFS_HDR_SIZE bytes is enough for most SMB responses and
681 almost all handle based requests (but not write response, nor is it
682 sufficient for path based requests). A smaller size would have
683 been more efficient (compacting multiple slab items on one 4k page)
684 for the case in which debug was on, but this larger size allows
685 more SMBs to use small buffer alloc and is still much more
686 efficient to alloc 1 per page off the slab compared to 17K (5page)
687 alloc of large cifs buffers even when page debugging is on */
688 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
689 MAX_CIFS_HDR_SIZE, 0, SLAB_HWCACHE_ALIGN, NULL, NULL);
690 if (cifs_sm_req_cachep == NULL) {
691 mempool_destroy(cifs_req_poolp);
692 kmem_cache_destroy(cifs_req_cachep);
696 if(cifs_min_small < 2)
698 else if (cifs_min_small > 256) {
699 cifs_min_small = 256;
700 cFYI(1,("cifs_min_small set to maximum (256)"));
703 cifs_sm_req_poolp = mempool_create(cifs_min_small,
708 if(cifs_sm_req_poolp == NULL) {
709 mempool_destroy(cifs_req_poolp);
710 kmem_cache_destroy(cifs_req_cachep);
711 kmem_cache_destroy(cifs_sm_req_cachep);
719 cifs_destroy_request_bufs(void)
721 mempool_destroy(cifs_req_poolp);
722 if (kmem_cache_destroy(cifs_req_cachep))
724 "cifs_destroy_request_cache: error not all structures were freed\n");
725 mempool_destroy(cifs_sm_req_poolp);
726 if (kmem_cache_destroy(cifs_sm_req_cachep))
728 "cifs_destroy_request_cache: cifs_small_rq free error\n");
734 cifs_mid_cachep = kmem_cache_create("cifs_mpx_ids",
735 sizeof (struct mid_q_entry), 0,
736 SLAB_HWCACHE_ALIGN, NULL, NULL);
737 if (cifs_mid_cachep == NULL)
740 cifs_mid_poolp = mempool_create(3 /* a reasonable min simultan opers */,
744 if(cifs_mid_poolp == NULL) {
745 kmem_cache_destroy(cifs_mid_cachep);
749 cifs_oplock_cachep = kmem_cache_create("cifs_oplock_structs",
750 sizeof (struct oplock_q_entry), 0,
751 SLAB_HWCACHE_ALIGN, NULL, NULL);
752 if (cifs_oplock_cachep == NULL) {
753 kmem_cache_destroy(cifs_mid_cachep);
754 mempool_destroy(cifs_mid_poolp);
762 cifs_destroy_mids(void)
764 mempool_destroy(cifs_mid_poolp);
765 if (kmem_cache_destroy(cifs_mid_cachep))
767 "cifs_destroy_mids: error not all structures were freed\n");
769 if (kmem_cache_destroy(cifs_oplock_cachep))
771 "error not all oplock structures were freed\n");
774 static int cifs_oplock_thread(void * dummyarg)
776 struct oplock_q_entry * oplock_item;
777 struct cifsTconInfo *pTcon;
778 struct inode * inode;
782 daemonize("cifsoplockd");
783 allow_signal(SIGTERM);
785 oplockThread = current;
789 set_current_state(TASK_INTERRUPTIBLE);
791 schedule_timeout(1*HZ);
792 spin_lock(&GlobalMid_Lock);
793 if(list_empty(&GlobalOplock_Q)) {
794 spin_unlock(&GlobalMid_Lock);
795 set_current_state(TASK_INTERRUPTIBLE);
796 schedule_timeout(39*HZ);
798 oplock_item = list_entry(GlobalOplock_Q.next,
799 struct oplock_q_entry, qhead);
801 cFYI(1,("found oplock item to write out"));
802 pTcon = oplock_item->tcon;
803 inode = oplock_item->pinode;
804 netfid = oplock_item->netfid;
805 spin_unlock(&GlobalMid_Lock);
806 DeleteOplockQEntry(oplock_item);
807 /* can not grab inode sem here since it would
808 deadlock when oplock received on delete
809 since vfs_unlink holds the i_sem across
811 /* down(&inode->i_sem);*/
812 if (S_ISREG(inode->i_mode)) {
813 rc = filemap_fdatawrite(inode->i_mapping);
814 if(CIFS_I(inode)->clientCanCacheRead == 0) {
815 filemap_fdatawait(inode->i_mapping);
816 invalidate_remote_inode(inode);
820 /* up(&inode->i_sem);*/
822 CIFS_I(inode)->write_behind_rc = rc;
823 cFYI(1,("Oplock flush inode %p rc %d",inode,rc));
825 /* releasing a stale oplock after recent reconnection
826 of smb session using a now incorrect file
827 handle is not a data integrity issue but do
828 not bother sending an oplock release if session
829 to server still is disconnected since oplock
830 already released by the server in that case */
831 if(pTcon->tidStatus != CifsNeedReconnect) {
832 rc = CIFSSMBLock(0, pTcon, netfid,
833 0 /* len */ , 0 /* offset */, 0,
834 0, LOCKING_ANDX_OPLOCK_RELEASE,
836 cFYI(1,("Oplock release rc = %d ",rc));
839 spin_unlock(&GlobalMid_Lock);
841 } while(!signal_pending(current));
843 complete_and_exit (&cifs_oplock_exited, 0);
846 static int cifs_dnotify_thread(void * dummyarg)
848 daemonize("cifsdnotifyd");
849 allow_signal(SIGTERM);
851 dnotifyThread = current;
855 set_current_state(TASK_INTERRUPTIBLE);
856 schedule_timeout(39*HZ);
857 } while(!signal_pending(current));
858 complete_and_exit (&cifs_dnotify_exited, 0);
865 #ifdef CONFIG_PROC_FS
868 INIT_LIST_HEAD(&GlobalServerList); /* BB not implemented yet */
869 INIT_LIST_HEAD(&GlobalSMBSessionList);
870 INIT_LIST_HEAD(&GlobalTreeConnectionList);
871 INIT_LIST_HEAD(&GlobalOplock_Q);
873 * Initialize Global counters
875 atomic_set(&sesInfoAllocCount, 0);
876 atomic_set(&tconInfoAllocCount, 0);
877 atomic_set(&tcpSesAllocCount,0);
878 atomic_set(&tcpSesReconnectCount, 0);
879 atomic_set(&tconInfoReconnectCount, 0);
881 atomic_set(&bufAllocCount, 0);
882 atomic_set(&midCount, 0);
883 GlobalCurrentXid = 0;
884 GlobalTotalActiveXid = 0;
885 GlobalMaxActiveXid = 0;
886 rwlock_init(&GlobalSMBSeslock);
887 spin_lock_init(&GlobalMid_Lock);
889 if(cifs_max_pending < 2) {
890 cifs_max_pending = 2;
891 cFYI(1,("cifs_max_pending set to min of 2"));
892 } else if(cifs_max_pending > 256) {
893 cifs_max_pending = 256;
894 cFYI(1,("cifs_max_pending set to max of 256"));
897 rc = cifs_init_inodecache();
899 rc = cifs_init_mids();
901 rc = cifs_init_request_bufs();
903 rc = register_filesystem(&cifs_fs_type);
905 rc = (int)kernel_thread(cifs_oplock_thread, NULL,
906 CLONE_FS | CLONE_FILES | CLONE_VM);
908 rc = (int)kernel_thread(cifs_dnotify_thread, NULL,
909 CLONE_FS | CLONE_FILES | CLONE_VM);
913 cERROR(1,("error %d create dnotify thread", rc));
915 cERROR(1,("error %d create oplock thread",rc));
918 cifs_destroy_request_bufs();
922 cifs_destroy_inodecache();
924 #ifdef CONFIG_PROC_FS
933 cFYI(0, ("In unregister ie exit_cifs"));
934 #ifdef CONFIG_PROC_FS
937 unregister_filesystem(&cifs_fs_type);
938 cifs_destroy_inodecache();
940 cifs_destroy_request_bufs();
942 send_sig(SIGTERM, oplockThread, 1);
943 wait_for_completion(&cifs_oplock_exited);
946 send_sig(SIGTERM, dnotifyThread, 1);
947 wait_for_completion(&cifs_dnotify_exited);
951 MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>");
952 MODULE_LICENSE("GPL"); /* combination of LGPL + GPL source behaves as GPL */
954 ("VFS to access servers complying with the SNIA CIFS Specification e.g. Samba and Windows");
955 MODULE_VERSION(CIFS_VERSION);
956 module_init(init_cifs)
957 module_exit(exit_cifs)