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>
38 #include <linux/namei.h>
42 #define DECLARE_GLOBALS_HERE
44 #include "cifsproto.h"
45 #include "cifs_debug.h"
46 #include "cifs_fs_sb.h"
48 #include <linux/key-type.h>
49 #include "cifs_spnego.h"
51 #define CIFS_MAGIC_NUMBER 0xFF534D42 /* the first four bytes of SMB PDUs */
56 bool enable_oplocks = true;
57 bool no_serverino_autodisable = false;
58 unsigned int linuxExtEnabled = 1;
59 unsigned int lookupCacheEnabled = 1;
60 unsigned int multiuser_mount = 0;
61 unsigned int global_secflags = CIFSSEC_DEF;
62 /* unsigned int ntlmv2_support = 0; */
63 unsigned int sign_CIFS_PDUs = 1;
64 static const struct super_operations cifs_super_ops;
65 unsigned int CIFSMaxBufSize = CIFS_MAX_MSGSIZE;
66 module_param(CIFSMaxBufSize, int, 0);
67 MODULE_PARM_DESC(CIFSMaxBufSize, "Network buffer size (not including header). "
68 "Default: 16384 Range: 8192 to 130048");
69 unsigned int cifs_min_rcv = CIFS_MIN_RCV_POOL;
70 module_param(cifs_min_rcv, int, 0);
71 MODULE_PARM_DESC(cifs_min_rcv, "Network buffers in pool. Default: 4 Range: "
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 "
77 unsigned int cifs_max_pending = CIFS_MAX_REQ;
78 module_param(cifs_max_pending, int, 0444);
79 MODULE_PARM_DESC(cifs_max_pending, "Simultaneous requests to server. "
80 "Default: 32767 Range: 2 to 32767.");
81 unsigned short echo_retries = 5;
82 module_param(echo_retries, ushort, 0644);
83 MODULE_PARM_DESC(echo_retries, "Number of echo attempts before giving up and "
84 "reconnecting server. Default: 5. 0 means "
86 module_param(enable_oplocks, bool, 0644);
87 MODULE_PARM_DESC(enable_oplocks, "Enable or disable oplocks (bool). Default:"
89 module_param(no_serverino_autodisable, bool, 0644);
91 extern mempool_t *cifs_sm_req_poolp;
92 extern mempool_t *cifs_req_poolp;
93 extern mempool_t *cifs_mid_poolp;
96 cifs_read_super(struct super_block *sb)
99 struct cifs_sb_info *cifs_sb;
102 cifs_sb = CIFS_SB(sb);
104 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIXACL)
105 sb->s_flags |= MS_POSIXACL;
107 if (cifs_sb_master_tcon(cifs_sb)->ses->capabilities & CAP_LARGE_FILES)
108 sb->s_maxbytes = MAX_LFS_FILESIZE;
110 sb->s_maxbytes = MAX_NON_LFS;
112 /* BB FIXME fix time_gran to be larger for LANMAN sessions */
113 sb->s_time_gran = 100;
115 sb->s_magic = CIFS_MAGIC_NUMBER;
116 sb->s_op = &cifs_super_ops;
117 sb->s_bdi = &cifs_sb->bdi;
118 sb->s_blocksize = CIFS_MAX_MSGSIZE;
119 sb->s_blocksize_bits = 14; /* default 2**14 = CIFS_MAX_MSGSIZE */
120 inode = cifs_root_iget(sb);
128 sb->s_root = d_alloc_root(inode);
135 /* do that *after* d_alloc_root() - we want NULL ->d_op for root here */
136 if (cifs_sb_master_tcon(cifs_sb)->nocase)
137 sb->s_d_op = &cifs_ci_dentry_ops;
139 sb->s_d_op = &cifs_dentry_ops;
141 #ifdef CONFIG_CIFS_NFSD_EXPORT
142 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) {
143 cFYI(1, "export ops supported");
144 sb->s_export_op = &cifs_export_ops;
146 #endif /* CONFIG_CIFS_NFSD_EXPORT */
151 cERROR(1, "cifs_read_super: get root inode failed");
158 static void cifs_kill_sb(struct super_block *sb)
160 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
162 cifs_umount(cifs_sb);
166 cifs_statfs(struct dentry *dentry, struct kstatfs *buf)
168 struct super_block *sb = dentry->d_sb;
169 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
170 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
171 int rc = -EOPNOTSUPP;
176 buf->f_type = CIFS_MAGIC_NUMBER;
179 * PATH_MAX may be too long - it would presumably be total path,
180 * but note that some servers (includinng Samba 3) have a shorter
183 * Instead could get the real value via SMB_QUERY_FS_ATTRIBUTE_INFO.
185 buf->f_namelen = PATH_MAX;
186 buf->f_files = 0; /* undefined */
187 buf->f_ffree = 0; /* unlimited */
190 * We could add a second check for a QFS Unix capability bit
192 if ((tcon->ses->capabilities & CAP_UNIX) &&
193 (CIFS_POSIX_EXTENSIONS & le64_to_cpu(tcon->fsUnixInfo.Capability)))
194 rc = CIFSSMBQFSPosixInfo(xid, tcon, buf);
197 * Only need to call the old QFSInfo if failed on newer one,
200 if (rc && (tcon->ses->capabilities & CAP_NT_SMBS))
201 rc = CIFSSMBQFSInfo(xid, tcon, buf);
204 * Some old Windows servers also do not support level 103, retry with
205 * older level one if old server failed the previous call or we
206 * bypassed it because we detected that this was an older LANMAN sess
209 rc = SMBOldQFSInfo(xid, tcon, buf);
215 static int cifs_permission(struct inode *inode, int mask)
217 struct cifs_sb_info *cifs_sb;
219 cifs_sb = CIFS_SB(inode->i_sb);
221 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) {
222 if ((mask & MAY_EXEC) && !execute_ok(inode))
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);
233 static struct kmem_cache *cifs_inode_cachep;
234 static struct kmem_cache *cifs_req_cachep;
235 static struct kmem_cache *cifs_mid_cachep;
236 static struct kmem_cache *cifs_sm_req_cachep;
237 mempool_t *cifs_sm_req_poolp;
238 mempool_t *cifs_req_poolp;
239 mempool_t *cifs_mid_poolp;
241 static struct inode *
242 cifs_alloc_inode(struct super_block *sb)
244 struct cifsInodeInfo *cifs_inode;
245 cifs_inode = kmem_cache_alloc(cifs_inode_cachep, GFP_KERNEL);
248 cifs_inode->cifsAttrs = 0x20; /* default */
249 cifs_inode->time = 0;
250 /* Until the file is open and we have gotten oplock
251 info back from the server, can not assume caching of
252 file data or metadata */
253 cifs_set_oplock_level(cifs_inode, 0);
254 cifs_inode->delete_pending = false;
255 cifs_inode->invalid_mapping = false;
256 cifs_inode->vfs_inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */
257 cifs_inode->server_eof = 0;
258 cifs_inode->uniqueid = 0;
259 cifs_inode->createtime = 0;
261 /* Can not set i_flags here - they get immediately overwritten
262 to zero by the VFS */
263 /* cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME;*/
264 INIT_LIST_HEAD(&cifs_inode->openFileList);
265 return &cifs_inode->vfs_inode;
268 static void cifs_i_callback(struct rcu_head *head)
270 struct inode *inode = container_of(head, struct inode, i_rcu);
271 INIT_LIST_HEAD(&inode->i_dentry);
272 kmem_cache_free(cifs_inode_cachep, CIFS_I(inode));
276 cifs_destroy_inode(struct inode *inode)
278 call_rcu(&inode->i_rcu, cifs_i_callback);
282 cifs_evict_inode(struct inode *inode)
284 truncate_inode_pages(&inode->i_data, 0);
285 end_writeback(inode);
286 cifs_fscache_release_inode_cookie(inode);
290 cifs_show_address(struct seq_file *s, struct TCP_Server_Info *server)
292 struct sockaddr_in *sa = (struct sockaddr_in *) &server->dstaddr;
293 struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *) &server->dstaddr;
295 seq_printf(s, ",addr=");
297 switch (server->dstaddr.ss_family) {
299 seq_printf(s, "%pI4", &sa->sin_addr.s_addr);
302 seq_printf(s, "%pI6", &sa6->sin6_addr.s6_addr);
303 if (sa6->sin6_scope_id)
304 seq_printf(s, "%%%u", sa6->sin6_scope_id);
307 seq_printf(s, "(unknown)");
312 cifs_show_security(struct seq_file *s, struct TCP_Server_Info *server)
314 seq_printf(s, ",sec=");
316 switch (server->secType) {
318 seq_printf(s, "lanman");
321 seq_printf(s, "ntlmv2");
324 seq_printf(s, "ntlm");
327 seq_printf(s, "krb5");
330 seq_printf(s, "ntlmssp");
333 /* shouldn't ever happen */
334 seq_printf(s, "unknown");
338 if (server->sec_mode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
343 * cifs_show_options() is for displaying mount options in /proc/mounts.
344 * Not all settable options are displayed but most of the important
348 cifs_show_options(struct seq_file *s, struct vfsmount *m)
350 struct cifs_sb_info *cifs_sb = CIFS_SB(m->mnt_sb);
351 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
352 struct sockaddr *srcaddr;
353 srcaddr = (struct sockaddr *)&tcon->ses->server->srcaddr;
355 cifs_show_security(s, tcon->ses->server);
357 seq_printf(s, ",unc=%s", tcon->treeName);
359 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER)
360 seq_printf(s, ",multiuser");
361 else if (tcon->ses->user_name)
362 seq_printf(s, ",username=%s", tcon->ses->user_name);
364 if (tcon->ses->domainName)
365 seq_printf(s, ",domain=%s", tcon->ses->domainName);
367 if (srcaddr->sa_family != AF_UNSPEC) {
368 struct sockaddr_in *saddr4;
369 struct sockaddr_in6 *saddr6;
370 saddr4 = (struct sockaddr_in *)srcaddr;
371 saddr6 = (struct sockaddr_in6 *)srcaddr;
372 if (srcaddr->sa_family == AF_INET6)
373 seq_printf(s, ",srcaddr=%pI6c",
375 else if (srcaddr->sa_family == AF_INET)
376 seq_printf(s, ",srcaddr=%pI4",
377 &saddr4->sin_addr.s_addr);
379 seq_printf(s, ",srcaddr=BAD-AF:%i",
380 (int)(srcaddr->sa_family));
383 seq_printf(s, ",uid=%d", cifs_sb->mnt_uid);
384 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID)
385 seq_printf(s, ",forceuid");
387 seq_printf(s, ",noforceuid");
389 seq_printf(s, ",gid=%d", cifs_sb->mnt_gid);
390 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID)
391 seq_printf(s, ",forcegid");
393 seq_printf(s, ",noforcegid");
395 cifs_show_address(s, tcon->ses->server);
398 seq_printf(s, ",file_mode=0%o,dir_mode=0%o",
399 cifs_sb->mnt_file_mode,
400 cifs_sb->mnt_dir_mode);
402 seq_printf(s, ",seal");
404 seq_printf(s, ",nocase");
406 seq_printf(s, ",hard");
408 seq_printf(s, ",unix");
410 seq_printf(s, ",nounix");
411 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)
412 seq_printf(s, ",posixpaths");
413 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID)
414 seq_printf(s, ",setuids");
415 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)
416 seq_printf(s, ",serverino");
417 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD)
418 seq_printf(s, ",rwpidforward");
419 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL)
420 seq_printf(s, ",forcemand");
421 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO)
422 seq_printf(s, ",directio");
423 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
424 seq_printf(s, ",nouser_xattr");
425 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR)
426 seq_printf(s, ",mapchars");
427 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL)
428 seq_printf(s, ",sfu");
429 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
430 seq_printf(s, ",nobrl");
431 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL)
432 seq_printf(s, ",cifsacl");
433 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM)
434 seq_printf(s, ",dynperm");
435 if (m->mnt_sb->s_flags & MS_POSIXACL)
436 seq_printf(s, ",acl");
437 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS)
438 seq_printf(s, ",mfsymlinks");
439 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_FSCACHE)
440 seq_printf(s, ",fsc");
441 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC)
442 seq_printf(s, ",nostrictsync");
443 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM)
444 seq_printf(s, ",noperm");
445 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO)
446 seq_printf(s, ",strictcache");
448 seq_printf(s, ",rsize=%d", cifs_sb->rsize);
449 seq_printf(s, ",wsize=%d", cifs_sb->wsize);
450 /* convert actimeo and display it in seconds */
451 seq_printf(s, ",actimeo=%lu", cifs_sb->actimeo / HZ);
456 static void cifs_umount_begin(struct super_block *sb)
458 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
459 struct cifs_tcon *tcon;
464 tcon = cifs_sb_master_tcon(cifs_sb);
466 spin_lock(&cifs_tcp_ses_lock);
467 if ((tcon->tc_count > 1) || (tcon->tidStatus == CifsExiting)) {
468 /* we have other mounts to same share or we have
469 already tried to force umount this and woken up
470 all waiting network requests, nothing to do */
471 spin_unlock(&cifs_tcp_ses_lock);
473 } else if (tcon->tc_count == 1)
474 tcon->tidStatus = CifsExiting;
475 spin_unlock(&cifs_tcp_ses_lock);
477 /* cancel_brl_requests(tcon); */ /* BB mark all brl mids as exiting */
478 /* cancel_notify_requests(tcon); */
479 if (tcon->ses && tcon->ses->server) {
480 cFYI(1, "wake up tasks now - umount begin not complete");
481 wake_up_all(&tcon->ses->server->request_q);
482 wake_up_all(&tcon->ses->server->response_q);
483 msleep(1); /* yield */
484 /* we have to kick the requests once more */
485 wake_up_all(&tcon->ses->server->response_q);
492 #ifdef CONFIG_CIFS_STATS2
493 static int cifs_show_stats(struct seq_file *s, struct vfsmount *mnt)
500 static int cifs_remount(struct super_block *sb, int *flags, char *data)
502 *flags |= MS_NODIRATIME;
506 static int cifs_drop_inode(struct inode *inode)
508 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
510 /* no serverino => unconditional eviction */
511 return !(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) ||
512 generic_drop_inode(inode);
515 static const struct super_operations cifs_super_ops = {
516 .statfs = cifs_statfs,
517 .alloc_inode = cifs_alloc_inode,
518 .destroy_inode = cifs_destroy_inode,
519 .drop_inode = cifs_drop_inode,
520 .evict_inode = cifs_evict_inode,
521 /* .delete_inode = cifs_delete_inode, */ /* Do not need above
522 function unless later we add lazy close of inodes or unless the
523 kernel forgets to call us with the same number of releases (closes)
525 .show_options = cifs_show_options,
526 .umount_begin = cifs_umount_begin,
527 .remount_fs = cifs_remount,
528 #ifdef CONFIG_CIFS_STATS2
529 .show_stats = cifs_show_stats,
534 * Get root dentry from superblock according to prefix path mount option.
535 * Return dentry with refcount + 1 on success and NULL otherwise.
537 static struct dentry *
538 cifs_get_root(struct smb_vol *vol, struct super_block *sb)
540 struct dentry *dentry;
541 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
542 char *full_path = NULL;
546 full_path = cifs_build_path_to_root(vol, cifs_sb,
547 cifs_sb_master_tcon(cifs_sb));
548 if (full_path == NULL)
549 return ERR_PTR(-ENOMEM);
551 cFYI(1, "Get root dentry for %s", full_path);
553 sep = CIFS_DIR_SEP(cifs_sb);
554 dentry = dget(sb->s_root);
558 struct inode *dir = dentry->d_inode;
559 struct dentry *child;
563 dentry = ERR_PTR(-ENOENT);
567 /* skip separators */
574 while (*s && *s != sep)
577 mutex_lock(&dir->i_mutex);
578 child = lookup_one_len(p, dentry, s - p);
579 mutex_unlock(&dir->i_mutex);
582 } while (!IS_ERR(dentry));
587 static int cifs_set_super(struct super_block *sb, void *data)
589 struct cifs_mnt_data *mnt_data = data;
590 sb->s_fs_info = mnt_data->cifs_sb;
591 return set_anon_super(sb, NULL);
594 static struct dentry *
595 cifs_do_mount(struct file_system_type *fs_type,
596 int flags, const char *dev_name, void *data)
599 struct super_block *sb;
600 struct cifs_sb_info *cifs_sb;
601 struct smb_vol *volume_info;
602 struct cifs_mnt_data mnt_data;
605 cFYI(1, "Devname: %s flags: %d ", dev_name, flags);
607 volume_info = cifs_get_volume_info((char *)data, dev_name);
608 if (IS_ERR(volume_info))
609 return ERR_CAST(volume_info);
611 cifs_sb = kzalloc(sizeof(struct cifs_sb_info), GFP_KERNEL);
612 if (cifs_sb == NULL) {
613 root = ERR_PTR(-ENOMEM);
617 cifs_sb->mountdata = kstrndup(data, PAGE_SIZE, GFP_KERNEL);
618 if (cifs_sb->mountdata == NULL) {
619 root = ERR_PTR(-ENOMEM);
623 cifs_setup_cifs_sb(volume_info, cifs_sb);
625 rc = cifs_mount(cifs_sb, volume_info);
627 if (!(flags & MS_SILENT))
628 cERROR(1, "cifs_mount failed w/return code = %d", rc);
633 mnt_data.vol = volume_info;
634 mnt_data.cifs_sb = cifs_sb;
635 mnt_data.flags = flags;
637 sb = sget(fs_type, cifs_match_super, cifs_set_super, &mnt_data);
640 cifs_umount(cifs_sb);
645 cFYI(1, "Use existing superblock");
646 cifs_umount(cifs_sb);
649 /* BB should we make this contingent on mount parm? */
650 sb->s_flags |= MS_NODIRATIME | MS_NOATIME;
652 rc = cifs_read_super(sb);
658 sb->s_flags |= MS_ACTIVE;
661 root = cifs_get_root(volume_info, sb);
665 cFYI(1, "dentry root is: %p", root);
669 deactivate_locked_super(sb);
671 cifs_cleanup_volume_info(volume_info);
675 kfree(cifs_sb->mountdata);
679 unload_nls(volume_info->local_nls);
683 static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
684 unsigned long nr_segs, loff_t pos)
686 struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode;
690 written = generic_file_aio_write(iocb, iov, nr_segs, pos);
692 if (CIFS_I(inode)->clientCanCacheAll)
695 rc = filemap_fdatawrite(inode->i_mapping);
697 cFYI(1, "cifs_file_aio_write: %d rc on %p inode", rc, inode);
702 static loff_t cifs_llseek(struct file *file, loff_t offset, int origin)
705 * origin == SEEK_END || SEEK_DATA || SEEK_HOLE => we must revalidate
706 * the cached file length
708 if (origin != SEEK_SET && origin != SEEK_CUR) {
710 struct inode *inode = file->f_path.dentry->d_inode;
713 * We need to be sure that all dirty pages are written and the
714 * server has the newest file length.
716 if (!CIFS_I(inode)->clientCanCacheRead && inode->i_mapping &&
717 inode->i_mapping->nrpages != 0) {
718 rc = filemap_fdatawait(inode->i_mapping);
720 mapping_set_error(inode->i_mapping, rc);
725 * Some applications poll for the file length in this strange
726 * way so we must seek to end on non-oplocked files by
727 * setting the revalidate time to zero.
729 CIFS_I(inode)->time = 0;
731 rc = cifs_revalidate_file_attr(file);
735 return generic_file_llseek(file, offset, origin);
738 static int cifs_setlease(struct file *file, long arg, struct file_lock **lease)
740 /* note that this is called by vfs setlease with lock_flocks held
741 to protect *lease from going away */
742 struct inode *inode = file->f_path.dentry->d_inode;
743 struct cifsFileInfo *cfile = file->private_data;
745 if (!(S_ISREG(inode->i_mode)))
748 /* check if file is oplocked */
749 if (((arg == F_RDLCK) &&
750 (CIFS_I(inode)->clientCanCacheRead)) ||
752 (CIFS_I(inode)->clientCanCacheAll)))
753 return generic_setlease(file, arg, lease);
754 else if (tlink_tcon(cfile->tlink)->local_lease &&
755 !CIFS_I(inode)->clientCanCacheRead)
756 /* If the server claims to support oplock on this
757 file, then we still need to check oplock even
758 if the local_lease mount option is set, but there
759 are servers which do not support oplock for which
760 this mount option may be useful if the user
761 knows that the file won't be changed on the server
763 return generic_setlease(file, arg, lease);
768 struct file_system_type cifs_fs_type = {
769 .owner = THIS_MODULE,
771 .mount = cifs_do_mount,
772 .kill_sb = cifs_kill_sb,
775 const struct inode_operations cifs_dir_inode_ops = {
776 .create = cifs_create,
777 .lookup = cifs_lookup,
778 .getattr = cifs_getattr,
779 .unlink = cifs_unlink,
780 .link = cifs_hardlink,
783 .rename = cifs_rename,
784 .permission = cifs_permission,
785 /* revalidate:cifs_revalidate, */
786 .setattr = cifs_setattr,
787 .symlink = cifs_symlink,
789 #ifdef CONFIG_CIFS_XATTR
790 .setxattr = cifs_setxattr,
791 .getxattr = cifs_getxattr,
792 .listxattr = cifs_listxattr,
793 .removexattr = cifs_removexattr,
797 const struct inode_operations cifs_file_inode_ops = {
798 /* revalidate:cifs_revalidate, */
799 .setattr = cifs_setattr,
800 .getattr = cifs_getattr, /* do we need this anymore? */
801 .rename = cifs_rename,
802 .permission = cifs_permission,
803 #ifdef CONFIG_CIFS_XATTR
804 .setxattr = cifs_setxattr,
805 .getxattr = cifs_getxattr,
806 .listxattr = cifs_listxattr,
807 .removexattr = cifs_removexattr,
811 const struct inode_operations cifs_symlink_inode_ops = {
812 .readlink = generic_readlink,
813 .follow_link = cifs_follow_link,
814 .put_link = cifs_put_link,
815 .permission = cifs_permission,
816 /* BB add the following two eventually */
817 /* revalidate: cifs_revalidate,
818 setattr: cifs_notify_change, *//* BB do we need notify change */
819 #ifdef CONFIG_CIFS_XATTR
820 .setxattr = cifs_setxattr,
821 .getxattr = cifs_getxattr,
822 .listxattr = cifs_listxattr,
823 .removexattr = cifs_removexattr,
827 const struct file_operations cifs_file_ops = {
828 .read = do_sync_read,
829 .write = do_sync_write,
830 .aio_read = generic_file_aio_read,
831 .aio_write = cifs_file_aio_write,
833 .release = cifs_close,
837 .mmap = cifs_file_mmap,
838 .splice_read = generic_file_splice_read,
839 .llseek = cifs_llseek,
840 #ifdef CONFIG_CIFS_POSIX
841 .unlocked_ioctl = cifs_ioctl,
842 #endif /* CONFIG_CIFS_POSIX */
843 .setlease = cifs_setlease,
846 const struct file_operations cifs_file_strict_ops = {
847 .read = do_sync_read,
848 .write = do_sync_write,
849 .aio_read = cifs_strict_readv,
850 .aio_write = cifs_strict_writev,
852 .release = cifs_close,
854 .fsync = cifs_strict_fsync,
856 .mmap = cifs_file_strict_mmap,
857 .splice_read = generic_file_splice_read,
858 .llseek = cifs_llseek,
859 #ifdef CONFIG_CIFS_POSIX
860 .unlocked_ioctl = cifs_ioctl,
861 #endif /* CONFIG_CIFS_POSIX */
862 .setlease = cifs_setlease,
865 const struct file_operations cifs_file_direct_ops = {
866 /* BB reevaluate whether they can be done with directio, no cache */
867 .read = do_sync_read,
868 .write = do_sync_write,
869 .aio_read = cifs_user_readv,
870 .aio_write = cifs_user_writev,
872 .release = cifs_close,
876 .mmap = cifs_file_mmap,
877 .splice_read = generic_file_splice_read,
878 #ifdef CONFIG_CIFS_POSIX
879 .unlocked_ioctl = cifs_ioctl,
880 #endif /* CONFIG_CIFS_POSIX */
881 .llseek = cifs_llseek,
882 .setlease = cifs_setlease,
885 const struct file_operations cifs_file_nobrl_ops = {
886 .read = do_sync_read,
887 .write = do_sync_write,
888 .aio_read = generic_file_aio_read,
889 .aio_write = cifs_file_aio_write,
891 .release = cifs_close,
894 .mmap = cifs_file_mmap,
895 .splice_read = generic_file_splice_read,
896 .llseek = cifs_llseek,
897 #ifdef CONFIG_CIFS_POSIX
898 .unlocked_ioctl = cifs_ioctl,
899 #endif /* CONFIG_CIFS_POSIX */
900 .setlease = cifs_setlease,
903 const struct file_operations cifs_file_strict_nobrl_ops = {
904 .read = do_sync_read,
905 .write = do_sync_write,
906 .aio_read = cifs_strict_readv,
907 .aio_write = cifs_strict_writev,
909 .release = cifs_close,
910 .fsync = cifs_strict_fsync,
912 .mmap = cifs_file_strict_mmap,
913 .splice_read = generic_file_splice_read,
914 .llseek = cifs_llseek,
915 #ifdef CONFIG_CIFS_POSIX
916 .unlocked_ioctl = cifs_ioctl,
917 #endif /* CONFIG_CIFS_POSIX */
918 .setlease = cifs_setlease,
921 const struct file_operations cifs_file_direct_nobrl_ops = {
922 /* BB reevaluate whether they can be done with directio, no cache */
923 .read = do_sync_read,
924 .write = do_sync_write,
925 .aio_read = cifs_user_readv,
926 .aio_write = cifs_user_writev,
928 .release = cifs_close,
931 .mmap = cifs_file_mmap,
932 .splice_read = generic_file_splice_read,
933 #ifdef CONFIG_CIFS_POSIX
934 .unlocked_ioctl = cifs_ioctl,
935 #endif /* CONFIG_CIFS_POSIX */
936 .llseek = cifs_llseek,
937 .setlease = cifs_setlease,
940 const struct file_operations cifs_dir_ops = {
941 .readdir = cifs_readdir,
942 .release = cifs_closedir,
943 .read = generic_read_dir,
944 .unlocked_ioctl = cifs_ioctl,
945 .llseek = generic_file_llseek,
949 cifs_init_once(void *inode)
951 struct cifsInodeInfo *cifsi = inode;
953 inode_init_once(&cifsi->vfs_inode);
954 INIT_LIST_HEAD(&cifsi->llist);
955 mutex_init(&cifsi->lock_mutex);
959 cifs_init_inodecache(void)
961 cifs_inode_cachep = kmem_cache_create("cifs_inode_cache",
962 sizeof(struct cifsInodeInfo),
963 0, (SLAB_RECLAIM_ACCOUNT|
966 if (cifs_inode_cachep == NULL)
973 cifs_destroy_inodecache(void)
975 kmem_cache_destroy(cifs_inode_cachep);
979 cifs_init_request_bufs(void)
981 if (CIFSMaxBufSize < 8192) {
982 /* Buffer size can not be smaller than 2 * PATH_MAX since maximum
983 Unicode path name has to fit in any SMB/CIFS path based frames */
984 CIFSMaxBufSize = 8192;
985 } else if (CIFSMaxBufSize > 1024*127) {
986 CIFSMaxBufSize = 1024 * 127;
988 CIFSMaxBufSize &= 0x1FE00; /* Round size to even 512 byte mult*/
990 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
991 cifs_req_cachep = kmem_cache_create("cifs_request",
993 MAX_CIFS_HDR_SIZE, 0,
994 SLAB_HWCACHE_ALIGN, NULL);
995 if (cifs_req_cachep == NULL)
998 if (cifs_min_rcv < 1)
1000 else if (cifs_min_rcv > 64) {
1002 cERROR(1, "cifs_min_rcv set to maximum (64)");
1005 cifs_req_poolp = mempool_create_slab_pool(cifs_min_rcv,
1008 if (cifs_req_poolp == NULL) {
1009 kmem_cache_destroy(cifs_req_cachep);
1012 /* MAX_CIFS_SMALL_BUFFER_SIZE bytes is enough for most SMB responses and
1013 almost all handle based requests (but not write response, nor is it
1014 sufficient for path based requests). A smaller size would have
1015 been more efficient (compacting multiple slab items on one 4k page)
1016 for the case in which debug was on, but this larger size allows
1017 more SMBs to use small buffer alloc and is still much more
1018 efficient to alloc 1 per page off the slab compared to 17K (5page)
1019 alloc of large cifs buffers even when page debugging is on */
1020 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
1021 MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
1023 if (cifs_sm_req_cachep == NULL) {
1024 mempool_destroy(cifs_req_poolp);
1025 kmem_cache_destroy(cifs_req_cachep);
1029 if (cifs_min_small < 2)
1031 else if (cifs_min_small > 256) {
1032 cifs_min_small = 256;
1033 cFYI(1, "cifs_min_small set to maximum (256)");
1036 cifs_sm_req_poolp = mempool_create_slab_pool(cifs_min_small,
1037 cifs_sm_req_cachep);
1039 if (cifs_sm_req_poolp == NULL) {
1040 mempool_destroy(cifs_req_poolp);
1041 kmem_cache_destroy(cifs_req_cachep);
1042 kmem_cache_destroy(cifs_sm_req_cachep);
1050 cifs_destroy_request_bufs(void)
1052 mempool_destroy(cifs_req_poolp);
1053 kmem_cache_destroy(cifs_req_cachep);
1054 mempool_destroy(cifs_sm_req_poolp);
1055 kmem_cache_destroy(cifs_sm_req_cachep);
1059 cifs_init_mids(void)
1061 cifs_mid_cachep = kmem_cache_create("cifs_mpx_ids",
1062 sizeof(struct mid_q_entry), 0,
1063 SLAB_HWCACHE_ALIGN, NULL);
1064 if (cifs_mid_cachep == NULL)
1067 /* 3 is a reasonable minimum number of simultaneous operations */
1068 cifs_mid_poolp = mempool_create_slab_pool(3, cifs_mid_cachep);
1069 if (cifs_mid_poolp == NULL) {
1070 kmem_cache_destroy(cifs_mid_cachep);
1078 cifs_destroy_mids(void)
1080 mempool_destroy(cifs_mid_poolp);
1081 kmem_cache_destroy(cifs_mid_cachep);
1089 INIT_LIST_HEAD(&cifs_tcp_ses_list);
1090 #ifdef CONFIG_CIFS_DNOTIFY_EXPERIMENTAL /* unused temporarily */
1091 INIT_LIST_HEAD(&GlobalDnotifyReqList);
1092 INIT_LIST_HEAD(&GlobalDnotifyRsp_Q);
1093 #endif /* was needed for dnotify, and will be needed for inotify when VFS fix */
1095 * Initialize Global counters
1097 atomic_set(&sesInfoAllocCount, 0);
1098 atomic_set(&tconInfoAllocCount, 0);
1099 atomic_set(&tcpSesAllocCount, 0);
1100 atomic_set(&tcpSesReconnectCount, 0);
1101 atomic_set(&tconInfoReconnectCount, 0);
1103 atomic_set(&bufAllocCount, 0);
1104 atomic_set(&smBufAllocCount, 0);
1105 #ifdef CONFIG_CIFS_STATS2
1106 atomic_set(&totBufAllocCount, 0);
1107 atomic_set(&totSmBufAllocCount, 0);
1108 #endif /* CONFIG_CIFS_STATS2 */
1110 atomic_set(&midCount, 0);
1111 GlobalCurrentXid = 0;
1112 GlobalTotalActiveXid = 0;
1113 GlobalMaxActiveXid = 0;
1114 spin_lock_init(&cifs_tcp_ses_lock);
1115 spin_lock_init(&cifs_file_list_lock);
1116 spin_lock_init(&GlobalMid_Lock);
1118 if (cifs_max_pending < 2) {
1119 cifs_max_pending = 2;
1120 cFYI(1, "cifs_max_pending set to min of 2");
1121 } else if (cifs_max_pending > CIFS_MAX_REQ) {
1122 cifs_max_pending = CIFS_MAX_REQ;
1123 cFYI(1, "cifs_max_pending set to max of %u", CIFS_MAX_REQ);
1126 rc = cifs_fscache_register();
1128 goto out_clean_proc;
1130 rc = cifs_init_inodecache();
1132 goto out_unreg_fscache;
1134 rc = cifs_init_mids();
1136 goto out_destroy_inodecache;
1138 rc = cifs_init_request_bufs();
1140 goto out_destroy_mids;
1142 #ifdef CONFIG_CIFS_UPCALL
1143 rc = register_key_type(&cifs_spnego_key_type);
1145 goto out_destroy_request_bufs;
1146 #endif /* CONFIG_CIFS_UPCALL */
1148 #ifdef CONFIG_CIFS_ACL
1149 rc = init_cifs_idmap();
1151 goto out_register_key_type;
1152 #endif /* CONFIG_CIFS_ACL */
1154 rc = register_filesystem(&cifs_fs_type);
1156 goto out_init_cifs_idmap;
1160 out_init_cifs_idmap:
1161 #ifdef CONFIG_CIFS_ACL
1163 out_register_key_type:
1165 #ifdef CONFIG_CIFS_UPCALL
1166 unregister_key_type(&cifs_spnego_key_type);
1167 out_destroy_request_bufs:
1169 cifs_destroy_request_bufs();
1171 cifs_destroy_mids();
1172 out_destroy_inodecache:
1173 cifs_destroy_inodecache();
1175 cifs_fscache_unregister();
1184 cFYI(DBG2, "exit_cifs");
1186 cifs_fscache_unregister();
1187 #ifdef CONFIG_CIFS_DFS_UPCALL
1188 cifs_dfs_release_automount_timer();
1190 #ifdef CONFIG_CIFS_ACL
1191 cifs_destroy_idmaptrees();
1194 #ifdef CONFIG_CIFS_UPCALL
1195 unregister_key_type(&cifs_spnego_key_type);
1197 unregister_filesystem(&cifs_fs_type);
1198 cifs_destroy_inodecache();
1199 cifs_destroy_mids();
1200 cifs_destroy_request_bufs();
1203 MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>");
1204 MODULE_LICENSE("GPL"); /* combination of LGPL + GPL source behaves as GPL */
1206 ("VFS to access servers complying with the SNIA CIFS Specification "
1207 "e.g. Samba and Windows");
1208 MODULE_VERSION(CIFS_VERSION);
1209 module_init(init_cifs)
1210 module_exit(exit_cifs)