4 * Copyright (C) International Business Machines Corp., 2002,2008
5 * Author(s): Steve French (sfrench@us.ibm.com)
7 * Common Internet FileSystem (CIFS) client
9 * This library is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published
11 * by the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
17 * the GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 /* Note that BB means BUGBUG (ie something to fix eventually) */
26 #include <linux/module.h>
28 #include <linux/mount.h>
29 #include <linux/slab.h>
30 #include <linux/init.h>
31 #include <linux/list.h>
32 #include <linux/seq_file.h>
33 #include <linux/vfs.h>
34 #include <linux/mempool.h>
35 #include <linux/delay.h>
36 #include <linux/kthread.h>
37 #include <linux/freezer.h>
40 #define DECLARE_GLOBALS_HERE
42 #include "cifsproto.h"
43 #include "cifs_debug.h"
44 #include "cifs_fs_sb.h"
46 #include <linux/key-type.h>
47 #include "dns_resolve.h"
48 #include "cifs_spnego.h"
49 #define CIFS_MAGIC_NUMBER 0xFF534D42 /* the first four bytes of SMB PDUs */
51 #ifdef CONFIG_CIFS_QUOTA
52 static struct quotactl_ops cifs_quotactl_ops;
58 unsigned int oplockEnabled = 1;
59 unsigned int experimEnabled = 0;
60 unsigned int linuxExtEnabled = 1;
61 unsigned int lookupCacheEnabled = 1;
62 unsigned int multiuser_mount = 0;
63 unsigned int extended_security = CIFSSEC_DEF;
64 /* unsigned int ntlmv2_support = 0; */
65 unsigned int sign_CIFS_PDUs = 1;
66 extern struct task_struct *oplockThread; /* remove sparse warning */
67 struct task_struct *oplockThread = NULL;
68 /* extern struct task_struct * dnotifyThread; remove sparse warning */
69 static const struct super_operations cifs_super_ops;
70 unsigned int CIFSMaxBufSize = CIFS_MAX_MSGSIZE;
71 module_param(CIFSMaxBufSize, int, 0);
72 MODULE_PARM_DESC(CIFSMaxBufSize, "Network buffer size (not including header). "
73 "Default: 16384 Range: 8192 to 130048");
74 unsigned int cifs_min_rcv = CIFS_MIN_RCV_POOL;
75 module_param(cifs_min_rcv, int, 0);
76 MODULE_PARM_DESC(cifs_min_rcv, "Network buffers in pool. Default: 4 Range: "
78 unsigned int cifs_min_small = 30;
79 module_param(cifs_min_small, int, 0);
80 MODULE_PARM_DESC(cifs_min_small, "Small network buffers in pool. Default: 30 "
82 unsigned int cifs_max_pending = CIFS_MAX_REQ;
83 module_param(cifs_max_pending, int, 0);
84 MODULE_PARM_DESC(cifs_max_pending, "Simultaneous requests to server. "
85 "Default: 50 Range: 2 to 256");
87 extern mempool_t *cifs_sm_req_poolp;
88 extern mempool_t *cifs_req_poolp;
89 extern mempool_t *cifs_mid_poolp;
91 extern struct kmem_cache *cifs_oplock_cachep;
94 cifs_read_super(struct super_block *sb, void *data,
95 const char *devname, int silent)
98 struct cifs_sb_info *cifs_sb;
101 /* BB should we make this contingent on mount parm? */
102 sb->s_flags |= MS_NODIRATIME | MS_NOATIME;
103 sb->s_fs_info = kzalloc(sizeof(struct cifs_sb_info), GFP_KERNEL);
104 cifs_sb = CIFS_SB(sb);
108 #ifdef CONFIG_CIFS_DFS_UPCALL
109 /* copy mount params to sb for use in submounts */
110 /* BB: should we move this after the mount so we
111 * do not have to do the copy on failed mounts?
112 * BB: May be it is better to do simple copy before
113 * complex operation (mount), and in case of fail
114 * just exit instead of doing mount and attempting
115 * undo it if this copy fails?*/
117 int len = strlen(data);
118 cifs_sb->mountdata = kzalloc(len + 1, GFP_KERNEL);
119 if (cifs_sb->mountdata == NULL) {
120 kfree(sb->s_fs_info);
121 sb->s_fs_info = NULL;
124 strncpy(cifs_sb->mountdata, data, len + 1);
125 cifs_sb->mountdata[len] = '\0';
129 rc = cifs_mount(sb, cifs_sb, data, devname);
134 ("cifs_mount failed w/return code = %d", rc));
135 goto out_mount_failed;
138 sb->s_magic = CIFS_MAGIC_NUMBER;
139 sb->s_op = &cifs_super_ops;
140 /* if (cifs_sb->tcon->ses->server->maxBuf > MAX_CIFS_HDR_SIZE + 512)
142 cifs_sb->tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE; */
143 #ifdef CONFIG_CIFS_QUOTA
144 sb->s_qcop = &cifs_quotactl_ops;
146 sb->s_blocksize = CIFS_MAX_MSGSIZE;
147 sb->s_blocksize_bits = 14; /* default 2**14 = CIFS_MAX_MSGSIZE */
148 inode = cifs_iget(sb, ROOT_I);
156 sb->s_root = d_alloc_root(inode);
163 #ifdef CONFIG_CIFS_EXPERIMENTAL
164 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) {
165 cFYI(1, ("export ops supported"));
166 sb->s_export_op = &cifs_export_ops;
168 #endif /* EXPERIMENTAL */
173 cERROR(1, ("cifs_read_super: get root inode failed"));
177 cifs_umount(sb, cifs_sb);
181 #ifdef CONFIG_CIFS_DFS_UPCALL
182 if (cifs_sb->mountdata) {
183 kfree(cifs_sb->mountdata);
184 cifs_sb->mountdata = NULL;
187 if (cifs_sb->local_nls)
188 unload_nls(cifs_sb->local_nls);
195 cifs_put_super(struct super_block *sb)
198 struct cifs_sb_info *cifs_sb;
200 cFYI(1, ("In cifs_put_super"));
201 cifs_sb = CIFS_SB(sb);
202 if (cifs_sb == NULL) {
203 cFYI(1, ("Empty cifs superblock info passed to unmount"));
206 rc = cifs_umount(sb, cifs_sb);
208 cERROR(1, ("cifs_umount failed with return code %d", rc));
209 #ifdef CONFIG_CIFS_DFS_UPCALL
210 if (cifs_sb->mountdata) {
211 kfree(cifs_sb->mountdata);
212 cifs_sb->mountdata = NULL;
216 unload_nls(cifs_sb->local_nls);
222 cifs_statfs(struct dentry *dentry, struct kstatfs *buf)
224 struct super_block *sb = dentry->d_sb;
225 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
226 struct cifsTconInfo *tcon = cifs_sb->tcon;
227 int rc = -EOPNOTSUPP;
232 buf->f_type = CIFS_MAGIC_NUMBER;
235 * PATH_MAX may be too long - it would presumably be total path,
236 * but note that some servers (includinng Samba 3) have a shorter
239 * Instead could get the real value via SMB_QUERY_FS_ATTRIBUTE_INFO.
241 buf->f_namelen = PATH_MAX;
242 buf->f_files = 0; /* undefined */
243 buf->f_ffree = 0; /* unlimited */
246 * We could add a second check for a QFS Unix capability bit
248 if ((tcon->ses->capabilities & CAP_UNIX) &&
249 (CIFS_POSIX_EXTENSIONS & le64_to_cpu(tcon->fsUnixInfo.Capability)))
250 rc = CIFSSMBQFSPosixInfo(xid, tcon, buf);
253 * Only need to call the old QFSInfo if failed on newer one,
256 if (rc && (tcon->ses->capabilities & CAP_NT_SMBS))
257 rc = CIFSSMBQFSInfo(xid, tcon, buf);
260 * Some old Windows servers also do not support level 103, retry with
261 * older level one if old server failed the previous call or we
262 * bypassed it because we detected that this was an older LANMAN sess
265 rc = SMBOldQFSInfo(xid, tcon, buf);
271 static int cifs_permission(struct inode *inode, int mask)
273 struct cifs_sb_info *cifs_sb;
275 cifs_sb = CIFS_SB(inode->i_sb);
277 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) {
278 if ((mask & MAY_EXEC) && !execute_ok(inode))
282 } else /* file mode might have been restricted at mount time
283 on the client (above and beyond ACL on servers) for
284 servers which do not support setting and viewing mode bits,
285 so allowing client to check permissions is useful */
286 return generic_permission(inode, mask, NULL);
289 static struct kmem_cache *cifs_inode_cachep;
290 static struct kmem_cache *cifs_req_cachep;
291 static struct kmem_cache *cifs_mid_cachep;
292 struct kmem_cache *cifs_oplock_cachep;
293 static struct kmem_cache *cifs_sm_req_cachep;
294 mempool_t *cifs_sm_req_poolp;
295 mempool_t *cifs_req_poolp;
296 mempool_t *cifs_mid_poolp;
298 static struct inode *
299 cifs_alloc_inode(struct super_block *sb)
301 struct cifsInodeInfo *cifs_inode;
302 cifs_inode = kmem_cache_alloc(cifs_inode_cachep, GFP_KERNEL);
305 cifs_inode->cifsAttrs = 0x20; /* default */
306 atomic_set(&cifs_inode->inUse, 0);
307 cifs_inode->time = 0;
308 cifs_inode->write_behind_rc = 0;
309 /* Until the file is open and we have gotten oplock
310 info back from the server, can not assume caching of
311 file data or metadata */
312 cifs_inode->clientCanCacheRead = false;
313 cifs_inode->clientCanCacheAll = false;
314 cifs_inode->delete_pending = false;
315 cifs_inode->vfs_inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */
316 cifs_inode->server_eof = 0;
318 /* Can not set i_flags here - they get immediately overwritten
319 to zero by the VFS */
320 /* cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME;*/
321 INIT_LIST_HEAD(&cifs_inode->openFileList);
322 return &cifs_inode->vfs_inode;
326 cifs_destroy_inode(struct inode *inode)
328 kmem_cache_free(cifs_inode_cachep, CIFS_I(inode));
332 * cifs_show_options() is for displaying mount options in /proc/mounts.
333 * Not all settable options are displayed but most of the important
337 cifs_show_options(struct seq_file *s, struct vfsmount *m)
339 struct cifs_sb_info *cifs_sb;
340 struct cifsTconInfo *tcon;
341 struct TCP_Server_Info *server;
343 cifs_sb = CIFS_SB(m->mnt_sb);
346 tcon = cifs_sb->tcon;
348 seq_printf(s, ",unc=%s", cifs_sb->tcon->treeName);
350 if (tcon->ses->userName)
351 seq_printf(s, ",username=%s",
352 tcon->ses->userName);
353 if (tcon->ses->domainName)
354 seq_printf(s, ",domain=%s",
355 tcon->ses->domainName);
356 server = tcon->ses->server;
358 seq_printf(s, ",addr=");
359 switch (server->addr.sockAddr6.
362 seq_printf(s, "%pI6",
363 &server->addr.sockAddr6.sin6_addr);
366 seq_printf(s, "%pI4",
367 &server->addr.sockAddr.sin_addr.s_addr);
372 if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID) ||
374 seq_printf(s, ",uid=%d", cifs_sb->mnt_uid);
375 if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID) ||
377 seq_printf(s, ",gid=%d", cifs_sb->mnt_gid);
378 if (!tcon->unix_ext) {
379 seq_printf(s, ",file_mode=0%o,dir_mode=0%o",
380 cifs_sb->mnt_file_mode,
381 cifs_sb->mnt_dir_mode);
384 seq_printf(s, ",seal");
386 seq_printf(s, ",nocase");
388 seq_printf(s, ",hard");
390 if (cifs_sb->prepath)
391 seq_printf(s, ",prepath=%s", cifs_sb->prepath);
392 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)
393 seq_printf(s, ",posixpaths");
394 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID)
395 seq_printf(s, ",setuids");
396 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)
397 seq_printf(s, ",serverino");
398 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO)
399 seq_printf(s, ",directio");
400 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
401 seq_printf(s, ",nouser_xattr");
402 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR)
403 seq_printf(s, ",mapchars");
404 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL)
405 seq_printf(s, ",sfu");
406 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
407 seq_printf(s, ",nobrl");
408 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL)
409 seq_printf(s, ",cifsacl");
410 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM)
411 seq_printf(s, ",dynperm");
412 if (m->mnt_sb->s_flags & MS_POSIXACL)
413 seq_printf(s, ",acl");
415 seq_printf(s, ",rsize=%d", cifs_sb->rsize);
416 seq_printf(s, ",wsize=%d", cifs_sb->wsize);
421 #ifdef CONFIG_CIFS_QUOTA
422 int cifs_xquota_set(struct super_block *sb, int quota_type, qid_t qid,
423 struct fs_disk_quota *pdquota)
427 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
428 struct cifsTconInfo *pTcon;
431 pTcon = cifs_sb->tcon;
438 cFYI(1, ("set type: 0x%x id: %d", quota_type, qid));
446 int cifs_xquota_get(struct super_block *sb, int quota_type, qid_t qid,
447 struct fs_disk_quota *pdquota)
451 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
452 struct cifsTconInfo *pTcon;
455 pTcon = cifs_sb->tcon;
461 cFYI(1, ("set type: 0x%x id: %d", quota_type, qid));
469 int cifs_xstate_set(struct super_block *sb, unsigned int flags, int operation)
473 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
474 struct cifsTconInfo *pTcon;
477 pTcon = cifs_sb->tcon;
483 cFYI(1, ("flags: 0x%x operation: 0x%x", flags, operation));
491 int cifs_xstate_get(struct super_block *sb, struct fs_quota_stat *qstats)
495 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
496 struct cifsTconInfo *pTcon;
499 pTcon = cifs_sb->tcon;
505 cFYI(1, ("pqstats %p", qstats));
513 static struct quotactl_ops cifs_quotactl_ops = {
514 .set_xquota = cifs_xquota_set,
515 .get_xquota = cifs_xquota_get,
516 .set_xstate = cifs_xstate_set,
517 .get_xstate = cifs_xstate_get,
521 static void cifs_umount_begin(struct super_block *sb)
523 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
524 struct cifsTconInfo *tcon;
529 tcon = cifs_sb->tcon;
533 read_lock(&cifs_tcp_ses_lock);
534 if (tcon->tc_count == 1)
535 tcon->tidStatus = CifsExiting;
536 read_unlock(&cifs_tcp_ses_lock);
538 /* cancel_brl_requests(tcon); */ /* BB mark all brl mids as exiting */
539 /* cancel_notify_requests(tcon); */
540 if (tcon->ses && tcon->ses->server) {
541 cFYI(1, ("wake up tasks now - umount begin not complete"));
542 wake_up_all(&tcon->ses->server->request_q);
543 wake_up_all(&tcon->ses->server->response_q);
544 msleep(1); /* yield */
545 /* we have to kick the requests once more */
546 wake_up_all(&tcon->ses->server->response_q);
549 /* BB FIXME - finish add checks for tidStatus BB */
554 #ifdef CONFIG_CIFS_STATS2
555 static int cifs_show_stats(struct seq_file *s, struct vfsmount *mnt)
562 static int cifs_remount(struct super_block *sb, int *flags, char *data)
564 *flags |= MS_NODIRATIME;
568 static const struct super_operations cifs_super_ops = {
569 .put_super = cifs_put_super,
570 .statfs = cifs_statfs,
571 .alloc_inode = cifs_alloc_inode,
572 .destroy_inode = cifs_destroy_inode,
573 /* .drop_inode = generic_delete_inode,
574 .delete_inode = cifs_delete_inode, */ /* Do not need above two
575 functions unless later we add lazy close of inodes or unless the
576 kernel forgets to call us with the same number of releases (closes)
578 .show_options = cifs_show_options,
579 .umount_begin = cifs_umount_begin,
580 .remount_fs = cifs_remount,
581 #ifdef CONFIG_CIFS_STATS2
582 .show_stats = cifs_show_stats,
587 cifs_get_sb(struct file_system_type *fs_type,
588 int flags, const char *dev_name, void *data, struct vfsmount *mnt)
591 struct super_block *sb = sget(fs_type, NULL, set_anon_super, NULL);
593 cFYI(1, ("Devname: %s flags: %d ", dev_name, flags));
600 rc = cifs_read_super(sb, data, dev_name, flags & MS_SILENT ? 1 : 0);
602 up_write(&sb->s_umount);
603 deactivate_super(sb);
606 sb->s_flags |= MS_ACTIVE;
607 simple_set_mnt(mnt, sb);
611 static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
612 unsigned long nr_segs, loff_t pos)
614 struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode;
617 written = generic_file_aio_write(iocb, iov, nr_segs, pos);
618 if (!CIFS_I(inode)->clientCanCacheAll)
619 filemap_fdatawrite(inode->i_mapping);
623 static loff_t cifs_llseek(struct file *file, loff_t offset, int origin)
625 /* origin == SEEK_END => we must revalidate the cached file length */
626 if (origin == SEEK_END) {
629 /* some applications poll for the file length in this strange
630 way so we must seek to end on non-oplocked files by
631 setting the revalidate time to zero */
632 CIFS_I(file->f_path.dentry->d_inode)->time = 0;
634 retval = cifs_revalidate(file->f_path.dentry);
636 return (loff_t)retval;
638 return generic_file_llseek_unlocked(file, offset, origin);
641 #ifdef CONFIG_CIFS_EXPERIMENTAL
642 static int cifs_setlease(struct file *file, long arg, struct file_lock **lease)
644 /* note that this is called by vfs setlease with the BKL held
645 although I doubt that BKL is needed here in cifs */
646 struct inode *inode = file->f_path.dentry->d_inode;
648 if (!(S_ISREG(inode->i_mode)))
651 /* check if file is oplocked */
652 if (((arg == F_RDLCK) &&
653 (CIFS_I(inode)->clientCanCacheRead)) ||
655 (CIFS_I(inode)->clientCanCacheAll)))
656 return generic_setlease(file, arg, lease);
657 else if (CIFS_SB(inode->i_sb)->tcon->local_lease &&
658 !CIFS_I(inode)->clientCanCacheRead)
659 /* If the server claims to support oplock on this
660 file, then we still need to check oplock even
661 if the local_lease mount option is set, but there
662 are servers which do not support oplock for which
663 this mount option may be useful if the user
664 knows that the file won't be changed on the server
666 return generic_setlease(file, arg, lease);
672 struct file_system_type cifs_fs_type = {
673 .owner = THIS_MODULE,
675 .get_sb = cifs_get_sb,
676 .kill_sb = kill_anon_super,
679 const struct inode_operations cifs_dir_inode_ops = {
680 .create = cifs_create,
681 .lookup = cifs_lookup,
682 .getattr = cifs_getattr,
683 .unlink = cifs_unlink,
684 .link = cifs_hardlink,
687 .rename = cifs_rename,
688 .permission = cifs_permission,
689 /* revalidate:cifs_revalidate, */
690 .setattr = cifs_setattr,
691 .symlink = cifs_symlink,
693 #ifdef CONFIG_CIFS_XATTR
694 .setxattr = cifs_setxattr,
695 .getxattr = cifs_getxattr,
696 .listxattr = cifs_listxattr,
697 .removexattr = cifs_removexattr,
701 const struct inode_operations cifs_file_inode_ops = {
702 /* revalidate:cifs_revalidate, */
703 .setattr = cifs_setattr,
704 .getattr = cifs_getattr, /* do we need this anymore? */
705 .rename = cifs_rename,
706 .permission = cifs_permission,
707 #ifdef CONFIG_CIFS_XATTR
708 .setxattr = cifs_setxattr,
709 .getxattr = cifs_getxattr,
710 .listxattr = cifs_listxattr,
711 .removexattr = cifs_removexattr,
715 const struct inode_operations cifs_symlink_inode_ops = {
716 .readlink = generic_readlink,
717 .follow_link = cifs_follow_link,
718 .put_link = cifs_put_link,
719 .permission = cifs_permission,
720 /* BB add the following two eventually */
721 /* revalidate: cifs_revalidate,
722 setattr: cifs_notify_change, *//* BB do we need notify change */
723 #ifdef CONFIG_CIFS_XATTR
724 .setxattr = cifs_setxattr,
725 .getxattr = cifs_getxattr,
726 .listxattr = cifs_listxattr,
727 .removexattr = cifs_removexattr,
731 const struct file_operations cifs_file_ops = {
732 .read = do_sync_read,
733 .write = do_sync_write,
734 .aio_read = generic_file_aio_read,
735 .aio_write = cifs_file_aio_write,
737 .release = cifs_close,
741 .mmap = cifs_file_mmap,
742 .splice_read = generic_file_splice_read,
743 .llseek = cifs_llseek,
744 #ifdef CONFIG_CIFS_POSIX
745 .unlocked_ioctl = cifs_ioctl,
746 #endif /* CONFIG_CIFS_POSIX */
748 #ifdef CONFIG_CIFS_EXPERIMENTAL
749 .setlease = cifs_setlease,
750 #endif /* CONFIG_CIFS_EXPERIMENTAL */
753 const struct file_operations cifs_file_direct_ops = {
754 /* no mmap, no aio, no readv -
755 BB reevaluate whether they can be done with directio, no cache */
756 .read = cifs_user_read,
757 .write = cifs_user_write,
759 .release = cifs_close,
763 .splice_read = generic_file_splice_read,
764 #ifdef CONFIG_CIFS_POSIX
765 .unlocked_ioctl = cifs_ioctl,
766 #endif /* CONFIG_CIFS_POSIX */
767 .llseek = cifs_llseek,
768 #ifdef CONFIG_CIFS_EXPERIMENTAL
769 .setlease = cifs_setlease,
770 #endif /* CONFIG_CIFS_EXPERIMENTAL */
772 const struct file_operations cifs_file_nobrl_ops = {
773 .read = do_sync_read,
774 .write = do_sync_write,
775 .aio_read = generic_file_aio_read,
776 .aio_write = cifs_file_aio_write,
778 .release = cifs_close,
781 .mmap = cifs_file_mmap,
782 .splice_read = generic_file_splice_read,
783 .llseek = cifs_llseek,
784 #ifdef CONFIG_CIFS_POSIX
785 .unlocked_ioctl = cifs_ioctl,
786 #endif /* CONFIG_CIFS_POSIX */
788 #ifdef CONFIG_CIFS_EXPERIMENTAL
789 .setlease = cifs_setlease,
790 #endif /* CONFIG_CIFS_EXPERIMENTAL */
793 const struct file_operations cifs_file_direct_nobrl_ops = {
794 /* no mmap, no aio, no readv -
795 BB reevaluate whether they can be done with directio, no cache */
796 .read = cifs_user_read,
797 .write = cifs_user_write,
799 .release = cifs_close,
802 .splice_read = generic_file_splice_read,
803 #ifdef CONFIG_CIFS_POSIX
804 .unlocked_ioctl = cifs_ioctl,
805 #endif /* CONFIG_CIFS_POSIX */
806 .llseek = cifs_llseek,
807 #ifdef CONFIG_CIFS_EXPERIMENTAL
808 .setlease = cifs_setlease,
809 #endif /* CONFIG_CIFS_EXPERIMENTAL */
812 const struct file_operations cifs_dir_ops = {
813 .readdir = cifs_readdir,
814 .release = cifs_closedir,
815 .read = generic_read_dir,
816 .unlocked_ioctl = cifs_ioctl,
817 .llseek = generic_file_llseek,
821 cifs_init_once(void *inode)
823 struct cifsInodeInfo *cifsi = inode;
825 inode_init_once(&cifsi->vfs_inode);
826 INIT_LIST_HEAD(&cifsi->lockList);
830 cifs_init_inodecache(void)
832 cifs_inode_cachep = kmem_cache_create("cifs_inode_cache",
833 sizeof(struct cifsInodeInfo),
834 0, (SLAB_RECLAIM_ACCOUNT|
837 if (cifs_inode_cachep == NULL)
844 cifs_destroy_inodecache(void)
846 kmem_cache_destroy(cifs_inode_cachep);
850 cifs_init_request_bufs(void)
852 if (CIFSMaxBufSize < 8192) {
853 /* Buffer size can not be smaller than 2 * PATH_MAX since maximum
854 Unicode path name has to fit in any SMB/CIFS path based frames */
855 CIFSMaxBufSize = 8192;
856 } else if (CIFSMaxBufSize > 1024*127) {
857 CIFSMaxBufSize = 1024 * 127;
859 CIFSMaxBufSize &= 0x1FE00; /* Round size to even 512 byte mult*/
861 /* cERROR(1,("CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize)); */
862 cifs_req_cachep = kmem_cache_create("cifs_request",
864 MAX_CIFS_HDR_SIZE, 0,
865 SLAB_HWCACHE_ALIGN, NULL);
866 if (cifs_req_cachep == NULL)
869 if (cifs_min_rcv < 1)
871 else if (cifs_min_rcv > 64) {
873 cERROR(1, ("cifs_min_rcv set to maximum (64)"));
876 cifs_req_poolp = mempool_create_slab_pool(cifs_min_rcv,
879 if (cifs_req_poolp == NULL) {
880 kmem_cache_destroy(cifs_req_cachep);
883 /* MAX_CIFS_SMALL_BUFFER_SIZE bytes is enough for most SMB responses and
884 almost all handle based requests (but not write response, nor is it
885 sufficient for path based requests). A smaller size would have
886 been more efficient (compacting multiple slab items on one 4k page)
887 for the case in which debug was on, but this larger size allows
888 more SMBs to use small buffer alloc and is still much more
889 efficient to alloc 1 per page off the slab compared to 17K (5page)
890 alloc of large cifs buffers even when page debugging is on */
891 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
892 MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
894 if (cifs_sm_req_cachep == NULL) {
895 mempool_destroy(cifs_req_poolp);
896 kmem_cache_destroy(cifs_req_cachep);
900 if (cifs_min_small < 2)
902 else if (cifs_min_small > 256) {
903 cifs_min_small = 256;
904 cFYI(1, ("cifs_min_small set to maximum (256)"));
907 cifs_sm_req_poolp = mempool_create_slab_pool(cifs_min_small,
910 if (cifs_sm_req_poolp == NULL) {
911 mempool_destroy(cifs_req_poolp);
912 kmem_cache_destroy(cifs_req_cachep);
913 kmem_cache_destroy(cifs_sm_req_cachep);
921 cifs_destroy_request_bufs(void)
923 mempool_destroy(cifs_req_poolp);
924 kmem_cache_destroy(cifs_req_cachep);
925 mempool_destroy(cifs_sm_req_poolp);
926 kmem_cache_destroy(cifs_sm_req_cachep);
932 cifs_mid_cachep = kmem_cache_create("cifs_mpx_ids",
933 sizeof(struct mid_q_entry), 0,
934 SLAB_HWCACHE_ALIGN, NULL);
935 if (cifs_mid_cachep == NULL)
938 /* 3 is a reasonable minimum number of simultaneous operations */
939 cifs_mid_poolp = mempool_create_slab_pool(3, cifs_mid_cachep);
940 if (cifs_mid_poolp == NULL) {
941 kmem_cache_destroy(cifs_mid_cachep);
945 cifs_oplock_cachep = kmem_cache_create("cifs_oplock_structs",
946 sizeof(struct oplock_q_entry), 0,
947 SLAB_HWCACHE_ALIGN, NULL);
948 if (cifs_oplock_cachep == NULL) {
949 mempool_destroy(cifs_mid_poolp);
950 kmem_cache_destroy(cifs_mid_cachep);
958 cifs_destroy_mids(void)
960 mempool_destroy(cifs_mid_poolp);
961 kmem_cache_destroy(cifs_mid_cachep);
962 kmem_cache_destroy(cifs_oplock_cachep);
965 static int cifs_oplock_thread(void *dummyarg)
967 struct oplock_q_entry *oplock_item;
968 struct cifsTconInfo *pTcon;
978 spin_lock(&GlobalMid_Lock);
979 if (list_empty(&GlobalOplock_Q)) {
980 spin_unlock(&GlobalMid_Lock);
981 set_current_state(TASK_INTERRUPTIBLE);
982 schedule_timeout(39*HZ);
984 oplock_item = list_entry(GlobalOplock_Q.next,
985 struct oplock_q_entry, qhead);
986 cFYI(1, ("found oplock item to write out"));
987 pTcon = oplock_item->tcon;
988 inode = oplock_item->pinode;
989 netfid = oplock_item->netfid;
990 spin_unlock(&GlobalMid_Lock);
991 DeleteOplockQEntry(oplock_item);
992 /* can not grab inode sem here since it would
993 deadlock when oplock received on delete
994 since vfs_unlink holds the i_mutex across
996 /* mutex_lock(&inode->i_mutex);*/
997 if (S_ISREG(inode->i_mode)) {
998 #ifdef CONFIG_CIFS_EXPERIMENTAL
999 if (CIFS_I(inode)->clientCanCacheAll == 0)
1000 break_lease(inode, FMODE_READ);
1001 else if (CIFS_I(inode)->clientCanCacheRead == 0)
1002 break_lease(inode, FMODE_WRITE);
1004 rc = filemap_fdatawrite(inode->i_mapping);
1005 if (CIFS_I(inode)->clientCanCacheRead == 0) {
1006 waitrc = filemap_fdatawait(
1008 invalidate_remote_inode(inode);
1014 /* mutex_unlock(&inode->i_mutex);*/
1016 CIFS_I(inode)->write_behind_rc = rc;
1017 cFYI(1, ("Oplock flush inode %p rc %d",
1020 /* releasing stale oplock after recent reconnect
1021 of smb session using a now incorrect file
1022 handle is not a data integrity issue but do
1023 not bother sending an oplock release if session
1024 to server still is disconnected since oplock
1025 already released by the server in that case */
1026 if (!pTcon->need_reconnect) {
1027 rc = CIFSSMBLock(0, pTcon, netfid,
1028 0 /* len */ , 0 /* offset */, 0,
1029 0, LOCKING_ANDX_OPLOCK_RELEASE,
1030 false /* wait flag */);
1031 cFYI(1, ("Oplock release rc = %d", rc));
1033 set_current_state(TASK_INTERRUPTIBLE);
1034 schedule_timeout(1); /* yield in case q were corrupt */
1036 } while (!kthread_should_stop());
1046 INIT_LIST_HEAD(&cifs_tcp_ses_list);
1047 INIT_LIST_HEAD(&GlobalOplock_Q);
1048 #ifdef CONFIG_CIFS_EXPERIMENTAL
1049 INIT_LIST_HEAD(&GlobalDnotifyReqList);
1050 INIT_LIST_HEAD(&GlobalDnotifyRsp_Q);
1053 * Initialize Global counters
1055 atomic_set(&sesInfoAllocCount, 0);
1056 atomic_set(&tconInfoAllocCount, 0);
1057 atomic_set(&tcpSesAllocCount, 0);
1058 atomic_set(&tcpSesReconnectCount, 0);
1059 atomic_set(&tconInfoReconnectCount, 0);
1061 atomic_set(&bufAllocCount, 0);
1062 atomic_set(&smBufAllocCount, 0);
1063 #ifdef CONFIG_CIFS_STATS2
1064 atomic_set(&totBufAllocCount, 0);
1065 atomic_set(&totSmBufAllocCount, 0);
1066 #endif /* CONFIG_CIFS_STATS2 */
1068 atomic_set(&midCount, 0);
1069 GlobalCurrentXid = 0;
1070 GlobalTotalActiveXid = 0;
1071 GlobalMaxActiveXid = 0;
1072 memset(Local_System_Name, 0, 15);
1073 rwlock_init(&GlobalSMBSeslock);
1074 rwlock_init(&cifs_tcp_ses_lock);
1075 spin_lock_init(&GlobalMid_Lock);
1077 if (cifs_max_pending < 2) {
1078 cifs_max_pending = 2;
1079 cFYI(1, ("cifs_max_pending set to min of 2"));
1080 } else if (cifs_max_pending > 256) {
1081 cifs_max_pending = 256;
1082 cFYI(1, ("cifs_max_pending set to max of 256"));
1085 rc = cifs_init_inodecache();
1087 goto out_clean_proc;
1089 rc = cifs_init_mids();
1091 goto out_destroy_inodecache;
1093 rc = cifs_init_request_bufs();
1095 goto out_destroy_mids;
1097 rc = register_filesystem(&cifs_fs_type);
1099 goto out_destroy_request_bufs;
1100 #ifdef CONFIG_CIFS_UPCALL
1101 rc = register_key_type(&cifs_spnego_key_type);
1103 goto out_unregister_filesystem;
1105 #ifdef CONFIG_CIFS_DFS_UPCALL
1106 rc = register_key_type(&key_type_dns_resolver);
1108 goto out_unregister_key_type;
1110 oplockThread = kthread_run(cifs_oplock_thread, NULL, "cifsoplockd");
1111 if (IS_ERR(oplockThread)) {
1112 rc = PTR_ERR(oplockThread);
1113 cERROR(1, ("error %d create oplock thread", rc));
1114 goto out_unregister_dfs_key_type;
1119 out_unregister_dfs_key_type:
1120 #ifdef CONFIG_CIFS_DFS_UPCALL
1121 unregister_key_type(&key_type_dns_resolver);
1122 out_unregister_key_type:
1124 #ifdef CONFIG_CIFS_UPCALL
1125 unregister_key_type(&cifs_spnego_key_type);
1126 out_unregister_filesystem:
1128 unregister_filesystem(&cifs_fs_type);
1129 out_destroy_request_bufs:
1130 cifs_destroy_request_bufs();
1132 cifs_destroy_mids();
1133 out_destroy_inodecache:
1134 cifs_destroy_inodecache();
1143 cFYI(DBG2, ("exit_cifs"));
1145 #ifdef CONFIG_CIFS_DFS_UPCALL
1146 cifs_dfs_release_automount_timer();
1147 unregister_key_type(&key_type_dns_resolver);
1149 #ifdef CONFIG_CIFS_UPCALL
1150 unregister_key_type(&cifs_spnego_key_type);
1152 unregister_filesystem(&cifs_fs_type);
1153 cifs_destroy_inodecache();
1154 cifs_destroy_mids();
1155 cifs_destroy_request_bufs();
1156 kthread_stop(oplockThread);
1159 MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>");
1160 MODULE_LICENSE("GPL"); /* combination of LGPL + GPL source behaves as GPL */
1162 ("VFS to access servers complying with the SNIA CIFS Specification "
1163 "e.g. Samba and Windows");
1164 MODULE_VERSION(CIFS_VERSION);
1165 module_init(init_cifs)
1166 module_exit(exit_cifs)