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 unsigned int linuxExtEnabled = 1;
58 unsigned int lookupCacheEnabled = 1;
59 unsigned int multiuser_mount = 0;
60 unsigned int global_secflags = CIFSSEC_DEF;
61 /* unsigned int ntlmv2_support = 0; */
62 unsigned int sign_CIFS_PDUs = 1;
63 static const struct super_operations cifs_super_ops;
64 unsigned int CIFSMaxBufSize = CIFS_MAX_MSGSIZE;
65 module_param(CIFSMaxBufSize, int, 0);
66 MODULE_PARM_DESC(CIFSMaxBufSize, "Network buffer size (not including header). "
67 "Default: 16384 Range: 8192 to 130048");
68 unsigned int cifs_min_rcv = CIFS_MIN_RCV_POOL;
69 module_param(cifs_min_rcv, int, 0);
70 MODULE_PARM_DESC(cifs_min_rcv, "Network buffers in pool. Default: 4 Range: "
72 unsigned int cifs_min_small = 30;
73 module_param(cifs_min_small, int, 0);
74 MODULE_PARM_DESC(cifs_min_small, "Small network buffers in pool. Default: 30 "
76 unsigned int cifs_max_pending = CIFS_MAX_REQ;
77 module_param(cifs_max_pending, int, 0444);
78 MODULE_PARM_DESC(cifs_max_pending, "Simultaneous requests to server. "
79 "Default: 32767 Range: 2 to 32767.");
80 module_param(enable_oplocks, bool, 0644);
81 MODULE_PARM_DESC(enable_oplocks, "Enable or disable oplocks (bool). Default:"
84 extern mempool_t *cifs_sm_req_poolp;
85 extern mempool_t *cifs_req_poolp;
86 extern mempool_t *cifs_mid_poolp;
89 cifs_read_super(struct super_block *sb)
92 struct cifs_sb_info *cifs_sb;
95 cifs_sb = CIFS_SB(sb);
97 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIXACL)
98 sb->s_flags |= MS_POSIXACL;
100 if (cifs_sb_master_tcon(cifs_sb)->ses->capabilities & CAP_LARGE_FILES)
101 sb->s_maxbytes = MAX_LFS_FILESIZE;
103 sb->s_maxbytes = MAX_NON_LFS;
105 /* BB FIXME fix time_gran to be larger for LANMAN sessions */
106 sb->s_time_gran = 100;
108 sb->s_magic = CIFS_MAGIC_NUMBER;
109 sb->s_op = &cifs_super_ops;
110 sb->s_bdi = &cifs_sb->bdi;
111 sb->s_blocksize = CIFS_MAX_MSGSIZE;
112 sb->s_blocksize_bits = 14; /* default 2**14 = CIFS_MAX_MSGSIZE */
113 inode = cifs_root_iget(sb);
120 sb->s_root = d_make_root(inode);
126 /* do that *after* d_alloc_root() - we want NULL ->d_op for root here */
127 if (cifs_sb_master_tcon(cifs_sb)->nocase)
128 sb->s_d_op = &cifs_ci_dentry_ops;
130 sb->s_d_op = &cifs_dentry_ops;
132 #ifdef CONFIG_CIFS_NFSD_EXPORT
133 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) {
134 cFYI(1, "export ops supported");
135 sb->s_export_op = &cifs_export_ops;
137 #endif /* CONFIG_CIFS_NFSD_EXPORT */
142 cERROR(1, "cifs_read_super: get root inode failed");
146 static void cifs_kill_sb(struct super_block *sb)
148 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
150 cifs_umount(cifs_sb);
154 cifs_statfs(struct dentry *dentry, struct kstatfs *buf)
156 struct super_block *sb = dentry->d_sb;
157 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
158 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
159 int rc = -EOPNOTSUPP;
164 buf->f_type = CIFS_MAGIC_NUMBER;
167 * PATH_MAX may be too long - it would presumably be total path,
168 * but note that some servers (includinng Samba 3) have a shorter
171 * Instead could get the real value via SMB_QUERY_FS_ATTRIBUTE_INFO.
173 buf->f_namelen = PATH_MAX;
174 buf->f_files = 0; /* undefined */
175 buf->f_ffree = 0; /* unlimited */
178 * We could add a second check for a QFS Unix capability bit
180 if ((tcon->ses->capabilities & CAP_UNIX) &&
181 (CIFS_POSIX_EXTENSIONS & le64_to_cpu(tcon->fsUnixInfo.Capability)))
182 rc = CIFSSMBQFSPosixInfo(xid, tcon, buf);
185 * Only need to call the old QFSInfo if failed on newer one,
188 if (rc && (tcon->ses->capabilities & CAP_NT_SMBS))
189 rc = CIFSSMBQFSInfo(xid, tcon, buf);
192 * Some old Windows servers also do not support level 103, retry with
193 * older level one if old server failed the previous call or we
194 * bypassed it because we detected that this was an older LANMAN sess
197 rc = SMBOldQFSInfo(xid, tcon, buf);
203 static int cifs_permission(struct inode *inode, int mask)
205 struct cifs_sb_info *cifs_sb;
207 cifs_sb = CIFS_SB(inode->i_sb);
209 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) {
210 if ((mask & MAY_EXEC) && !execute_ok(inode))
214 } else /* file mode might have been restricted at mount time
215 on the client (above and beyond ACL on servers) for
216 servers which do not support setting and viewing mode bits,
217 so allowing client to check permissions is useful */
218 return generic_permission(inode, mask);
221 static struct kmem_cache *cifs_inode_cachep;
222 static struct kmem_cache *cifs_req_cachep;
223 static struct kmem_cache *cifs_mid_cachep;
224 static struct kmem_cache *cifs_sm_req_cachep;
225 mempool_t *cifs_sm_req_poolp;
226 mempool_t *cifs_req_poolp;
227 mempool_t *cifs_mid_poolp;
229 static struct inode *
230 cifs_alloc_inode(struct super_block *sb)
232 struct cifsInodeInfo *cifs_inode;
233 cifs_inode = kmem_cache_alloc(cifs_inode_cachep, GFP_KERNEL);
236 cifs_inode->cifsAttrs = 0x20; /* default */
237 cifs_inode->time = 0;
238 /* Until the file is open and we have gotten oplock
239 info back from the server, can not assume caching of
240 file data or metadata */
241 cifs_set_oplock_level(cifs_inode, 0);
242 cifs_inode->delete_pending = false;
243 cifs_inode->invalid_mapping = false;
244 cifs_inode->vfs_inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */
245 cifs_inode->server_eof = 0;
246 cifs_inode->uniqueid = 0;
247 cifs_inode->createtime = 0;
249 /* Can not set i_flags here - they get immediately overwritten
250 to zero by the VFS */
251 /* cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME;*/
252 INIT_LIST_HEAD(&cifs_inode->openFileList);
253 return &cifs_inode->vfs_inode;
256 static void cifs_i_callback(struct rcu_head *head)
258 struct inode *inode = container_of(head, struct inode, i_rcu);
259 INIT_LIST_HEAD(&inode->i_dentry);
260 kmem_cache_free(cifs_inode_cachep, CIFS_I(inode));
264 cifs_destroy_inode(struct inode *inode)
266 call_rcu(&inode->i_rcu, cifs_i_callback);
270 cifs_evict_inode(struct inode *inode)
272 truncate_inode_pages(&inode->i_data, 0);
273 end_writeback(inode);
274 cifs_fscache_release_inode_cookie(inode);
278 cifs_show_address(struct seq_file *s, struct TCP_Server_Info *server)
280 struct sockaddr_in *sa = (struct sockaddr_in *) &server->dstaddr;
281 struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *) &server->dstaddr;
283 seq_printf(s, ",addr=");
285 switch (server->dstaddr.ss_family) {
287 seq_printf(s, "%pI4", &sa->sin_addr.s_addr);
290 seq_printf(s, "%pI6", &sa6->sin6_addr.s6_addr);
291 if (sa6->sin6_scope_id)
292 seq_printf(s, "%%%u", sa6->sin6_scope_id);
295 seq_printf(s, "(unknown)");
300 cifs_show_security(struct seq_file *s, struct TCP_Server_Info *server)
302 seq_printf(s, ",sec=");
304 switch (server->secType) {
306 seq_printf(s, "lanman");
309 seq_printf(s, "ntlmv2");
312 seq_printf(s, "ntlm");
315 seq_printf(s, "krb5");
318 seq_printf(s, "ntlmssp");
321 /* shouldn't ever happen */
322 seq_printf(s, "unknown");
326 if (server->sec_mode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
331 * cifs_show_options() is for displaying mount options in /proc/mounts.
332 * Not all settable options are displayed but most of the important
336 cifs_show_options(struct seq_file *s, struct dentry *root)
338 struct cifs_sb_info *cifs_sb = CIFS_SB(root->d_sb);
339 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
340 struct sockaddr *srcaddr;
341 srcaddr = (struct sockaddr *)&tcon->ses->server->srcaddr;
343 cifs_show_security(s, tcon->ses->server);
345 seq_printf(s, ",unc=%s", tcon->treeName);
347 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER)
348 seq_printf(s, ",multiuser");
349 else if (tcon->ses->user_name)
350 seq_printf(s, ",username=%s", tcon->ses->user_name);
352 if (tcon->ses->domainName)
353 seq_printf(s, ",domain=%s", tcon->ses->domainName);
355 if (srcaddr->sa_family != AF_UNSPEC) {
356 struct sockaddr_in *saddr4;
357 struct sockaddr_in6 *saddr6;
358 saddr4 = (struct sockaddr_in *)srcaddr;
359 saddr6 = (struct sockaddr_in6 *)srcaddr;
360 if (srcaddr->sa_family == AF_INET6)
361 seq_printf(s, ",srcaddr=%pI6c",
363 else if (srcaddr->sa_family == AF_INET)
364 seq_printf(s, ",srcaddr=%pI4",
365 &saddr4->sin_addr.s_addr);
367 seq_printf(s, ",srcaddr=BAD-AF:%i",
368 (int)(srcaddr->sa_family));
371 seq_printf(s, ",uid=%d", cifs_sb->mnt_uid);
372 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID)
373 seq_printf(s, ",forceuid");
375 seq_printf(s, ",noforceuid");
377 seq_printf(s, ",gid=%d", cifs_sb->mnt_gid);
378 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID)
379 seq_printf(s, ",forcegid");
381 seq_printf(s, ",noforcegid");
383 cifs_show_address(s, tcon->ses->server);
386 seq_printf(s, ",file_mode=0%ho,dir_mode=0%ho",
387 cifs_sb->mnt_file_mode,
388 cifs_sb->mnt_dir_mode);
390 seq_printf(s, ",seal");
392 seq_printf(s, ",nocase");
394 seq_printf(s, ",hard");
396 seq_printf(s, ",unix");
398 seq_printf(s, ",nounix");
399 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)
400 seq_printf(s, ",posixpaths");
401 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID)
402 seq_printf(s, ",setuids");
403 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)
404 seq_printf(s, ",serverino");
405 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD)
406 seq_printf(s, ",rwpidforward");
407 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL)
408 seq_printf(s, ",forcemand");
409 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO)
410 seq_printf(s, ",directio");
411 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
412 seq_printf(s, ",nouser_xattr");
413 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR)
414 seq_printf(s, ",mapchars");
415 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL)
416 seq_printf(s, ",sfu");
417 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
418 seq_printf(s, ",nobrl");
419 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL)
420 seq_printf(s, ",cifsacl");
421 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM)
422 seq_printf(s, ",dynperm");
423 if (root->d_sb->s_flags & MS_POSIXACL)
424 seq_printf(s, ",acl");
425 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS)
426 seq_printf(s, ",mfsymlinks");
427 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_FSCACHE)
428 seq_printf(s, ",fsc");
429 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC)
430 seq_printf(s, ",nostrictsync");
431 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM)
432 seq_printf(s, ",noperm");
433 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO)
434 seq_printf(s, ",strictcache");
436 seq_printf(s, ",rsize=%d", cifs_sb->rsize);
437 seq_printf(s, ",wsize=%d", cifs_sb->wsize);
438 /* convert actimeo and display it in seconds */
439 seq_printf(s, ",actimeo=%lu", cifs_sb->actimeo / HZ);
444 static void cifs_umount_begin(struct super_block *sb)
446 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
447 struct cifs_tcon *tcon;
452 tcon = cifs_sb_master_tcon(cifs_sb);
454 spin_lock(&cifs_tcp_ses_lock);
455 if ((tcon->tc_count > 1) || (tcon->tidStatus == CifsExiting)) {
456 /* we have other mounts to same share or we have
457 already tried to force umount this and woken up
458 all waiting network requests, nothing to do */
459 spin_unlock(&cifs_tcp_ses_lock);
461 } else if (tcon->tc_count == 1)
462 tcon->tidStatus = CifsExiting;
463 spin_unlock(&cifs_tcp_ses_lock);
465 /* cancel_brl_requests(tcon); */ /* BB mark all brl mids as exiting */
466 /* cancel_notify_requests(tcon); */
467 if (tcon->ses && tcon->ses->server) {
468 cFYI(1, "wake up tasks now - umount begin not complete");
469 wake_up_all(&tcon->ses->server->request_q);
470 wake_up_all(&tcon->ses->server->response_q);
471 msleep(1); /* yield */
472 /* we have to kick the requests once more */
473 wake_up_all(&tcon->ses->server->response_q);
480 #ifdef CONFIG_CIFS_STATS2
481 static int cifs_show_stats(struct seq_file *s, struct dentry *root)
488 static int cifs_remount(struct super_block *sb, int *flags, char *data)
490 *flags |= MS_NODIRATIME;
494 static int cifs_drop_inode(struct inode *inode)
496 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
498 /* no serverino => unconditional eviction */
499 return !(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) ||
500 generic_drop_inode(inode);
503 static const struct super_operations cifs_super_ops = {
504 .statfs = cifs_statfs,
505 .alloc_inode = cifs_alloc_inode,
506 .destroy_inode = cifs_destroy_inode,
507 .drop_inode = cifs_drop_inode,
508 .evict_inode = cifs_evict_inode,
509 /* .delete_inode = cifs_delete_inode, */ /* Do not need above
510 function unless later we add lazy close of inodes or unless the
511 kernel forgets to call us with the same number of releases (closes)
513 .show_options = cifs_show_options,
514 .umount_begin = cifs_umount_begin,
515 .remount_fs = cifs_remount,
516 #ifdef CONFIG_CIFS_STATS2
517 .show_stats = cifs_show_stats,
522 * Get root dentry from superblock according to prefix path mount option.
523 * Return dentry with refcount + 1 on success and NULL otherwise.
525 static struct dentry *
526 cifs_get_root(struct smb_vol *vol, struct super_block *sb)
528 struct dentry *dentry;
529 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
530 char *full_path = NULL;
534 full_path = cifs_build_path_to_root(vol, cifs_sb,
535 cifs_sb_master_tcon(cifs_sb));
536 if (full_path == NULL)
537 return ERR_PTR(-ENOMEM);
539 cFYI(1, "Get root dentry for %s", full_path);
541 sep = CIFS_DIR_SEP(cifs_sb);
542 dentry = dget(sb->s_root);
546 struct inode *dir = dentry->d_inode;
547 struct dentry *child;
551 dentry = ERR_PTR(-ENOENT);
555 /* skip separators */
562 while (*s && *s != sep)
565 mutex_lock(&dir->i_mutex);
566 child = lookup_one_len(p, dentry, s - p);
567 mutex_unlock(&dir->i_mutex);
570 } while (!IS_ERR(dentry));
575 static int cifs_set_super(struct super_block *sb, void *data)
577 struct cifs_mnt_data *mnt_data = data;
578 sb->s_fs_info = mnt_data->cifs_sb;
579 return set_anon_super(sb, NULL);
582 static struct dentry *
583 cifs_do_mount(struct file_system_type *fs_type,
584 int flags, const char *dev_name, void *data)
587 struct super_block *sb;
588 struct cifs_sb_info *cifs_sb;
589 struct smb_vol *volume_info;
590 struct cifs_mnt_data mnt_data;
593 cFYI(1, "Devname: %s flags: %d ", dev_name, flags);
595 volume_info = cifs_get_volume_info((char *)data, dev_name);
596 if (IS_ERR(volume_info))
597 return ERR_CAST(volume_info);
599 cifs_sb = kzalloc(sizeof(struct cifs_sb_info), GFP_KERNEL);
600 if (cifs_sb == NULL) {
601 root = ERR_PTR(-ENOMEM);
605 cifs_sb->mountdata = kstrndup(data, PAGE_SIZE, GFP_KERNEL);
606 if (cifs_sb->mountdata == NULL) {
607 root = ERR_PTR(-ENOMEM);
611 cifs_setup_cifs_sb(volume_info, cifs_sb);
613 rc = cifs_mount(cifs_sb, volume_info);
615 if (!(flags & MS_SILENT))
616 cERROR(1, "cifs_mount failed w/return code = %d", rc);
621 mnt_data.vol = volume_info;
622 mnt_data.cifs_sb = cifs_sb;
623 mnt_data.flags = flags;
625 sb = sget(fs_type, cifs_match_super, cifs_set_super, &mnt_data);
628 cifs_umount(cifs_sb);
633 cFYI(1, "Use existing superblock");
634 cifs_umount(cifs_sb);
637 /* BB should we make this contingent on mount parm? */
638 sb->s_flags |= MS_NODIRATIME | MS_NOATIME;
640 rc = cifs_read_super(sb);
646 sb->s_flags |= MS_ACTIVE;
649 root = cifs_get_root(volume_info, sb);
653 cFYI(1, "dentry root is: %p", root);
657 deactivate_locked_super(sb);
659 cifs_cleanup_volume_info(volume_info);
663 kfree(cifs_sb->mountdata);
667 unload_nls(volume_info->local_nls);
671 static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
672 unsigned long nr_segs, loff_t pos)
674 struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode;
678 written = generic_file_aio_write(iocb, iov, nr_segs, pos);
680 if (CIFS_I(inode)->clientCanCacheAll)
683 rc = filemap_fdatawrite(inode->i_mapping);
685 cFYI(1, "cifs_file_aio_write: %d rc on %p inode", rc, inode);
690 static loff_t cifs_llseek(struct file *file, loff_t offset, int origin)
693 * origin == SEEK_END || SEEK_DATA || SEEK_HOLE => we must revalidate
694 * the cached file length
696 if (origin != SEEK_SET || origin != SEEK_CUR) {
698 struct inode *inode = file->f_path.dentry->d_inode;
701 * We need to be sure that all dirty pages are written and the
702 * server has the newest file length.
704 if (!CIFS_I(inode)->clientCanCacheRead && inode->i_mapping &&
705 inode->i_mapping->nrpages != 0) {
706 rc = filemap_fdatawait(inode->i_mapping);
708 mapping_set_error(inode->i_mapping, rc);
713 * Some applications poll for the file length in this strange
714 * way so we must seek to end on non-oplocked files by
715 * setting the revalidate time to zero.
717 CIFS_I(inode)->time = 0;
719 rc = cifs_revalidate_file_attr(file);
723 return generic_file_llseek(file, offset, origin);
726 static int cifs_setlease(struct file *file, long arg, struct file_lock **lease)
728 /* note that this is called by vfs setlease with lock_flocks held
729 to protect *lease from going away */
730 struct inode *inode = file->f_path.dentry->d_inode;
731 struct cifsFileInfo *cfile = file->private_data;
733 if (!(S_ISREG(inode->i_mode)))
736 /* check if file is oplocked */
737 if (((arg == F_RDLCK) &&
738 (CIFS_I(inode)->clientCanCacheRead)) ||
740 (CIFS_I(inode)->clientCanCacheAll)))
741 return generic_setlease(file, arg, lease);
742 else if (tlink_tcon(cfile->tlink)->local_lease &&
743 !CIFS_I(inode)->clientCanCacheRead)
744 /* If the server claims to support oplock on this
745 file, then we still need to check oplock even
746 if the local_lease mount option is set, but there
747 are servers which do not support oplock for which
748 this mount option may be useful if the user
749 knows that the file won't be changed on the server
751 return generic_setlease(file, arg, lease);
756 struct file_system_type cifs_fs_type = {
757 .owner = THIS_MODULE,
759 .mount = cifs_do_mount,
760 .kill_sb = cifs_kill_sb,
763 const struct inode_operations cifs_dir_inode_ops = {
764 .create = cifs_create,
765 .lookup = cifs_lookup,
766 .getattr = cifs_getattr,
767 .unlink = cifs_unlink,
768 .link = cifs_hardlink,
771 .rename = cifs_rename,
772 .permission = cifs_permission,
773 /* revalidate:cifs_revalidate, */
774 .setattr = cifs_setattr,
775 .symlink = cifs_symlink,
777 #ifdef CONFIG_CIFS_XATTR
778 .setxattr = cifs_setxattr,
779 .getxattr = cifs_getxattr,
780 .listxattr = cifs_listxattr,
781 .removexattr = cifs_removexattr,
785 const struct inode_operations cifs_file_inode_ops = {
786 /* revalidate:cifs_revalidate, */
787 .setattr = cifs_setattr,
788 .getattr = cifs_getattr, /* do we need this anymore? */
789 .rename = cifs_rename,
790 .permission = cifs_permission,
791 #ifdef CONFIG_CIFS_XATTR
792 .setxattr = cifs_setxattr,
793 .getxattr = cifs_getxattr,
794 .listxattr = cifs_listxattr,
795 .removexattr = cifs_removexattr,
799 const struct inode_operations cifs_symlink_inode_ops = {
800 .readlink = generic_readlink,
801 .follow_link = cifs_follow_link,
802 .put_link = cifs_put_link,
803 .permission = cifs_permission,
804 /* BB add the following two eventually */
805 /* revalidate: cifs_revalidate,
806 setattr: cifs_notify_change, *//* BB do we need notify change */
807 #ifdef CONFIG_CIFS_XATTR
808 .setxattr = cifs_setxattr,
809 .getxattr = cifs_getxattr,
810 .listxattr = cifs_listxattr,
811 .removexattr = cifs_removexattr,
815 const struct file_operations cifs_file_ops = {
816 .read = do_sync_read,
817 .write = do_sync_write,
818 .aio_read = generic_file_aio_read,
819 .aio_write = cifs_file_aio_write,
821 .release = cifs_close,
825 .mmap = cifs_file_mmap,
826 .splice_read = generic_file_splice_read,
827 .llseek = cifs_llseek,
828 #ifdef CONFIG_CIFS_POSIX
829 .unlocked_ioctl = cifs_ioctl,
830 #endif /* CONFIG_CIFS_POSIX */
831 .setlease = cifs_setlease,
834 const struct file_operations cifs_file_strict_ops = {
835 .read = do_sync_read,
836 .write = do_sync_write,
837 .aio_read = cifs_strict_readv,
838 .aio_write = cifs_strict_writev,
840 .release = cifs_close,
842 .fsync = cifs_strict_fsync,
844 .mmap = cifs_file_strict_mmap,
845 .splice_read = generic_file_splice_read,
846 .llseek = cifs_llseek,
847 #ifdef CONFIG_CIFS_POSIX
848 .unlocked_ioctl = cifs_ioctl,
849 #endif /* CONFIG_CIFS_POSIX */
850 .setlease = cifs_setlease,
853 const struct file_operations cifs_file_direct_ops = {
854 /* BB reevaluate whether they can be done with directio, no cache */
855 .read = do_sync_read,
856 .write = do_sync_write,
857 .aio_read = cifs_user_readv,
858 .aio_write = cifs_user_writev,
860 .release = cifs_close,
864 .mmap = cifs_file_mmap,
865 .splice_read = generic_file_splice_read,
866 #ifdef CONFIG_CIFS_POSIX
867 .unlocked_ioctl = cifs_ioctl,
868 #endif /* CONFIG_CIFS_POSIX */
869 .llseek = cifs_llseek,
870 .setlease = cifs_setlease,
873 const struct file_operations cifs_file_nobrl_ops = {
874 .read = do_sync_read,
875 .write = do_sync_write,
876 .aio_read = generic_file_aio_read,
877 .aio_write = cifs_file_aio_write,
879 .release = cifs_close,
882 .mmap = cifs_file_mmap,
883 .splice_read = generic_file_splice_read,
884 .llseek = cifs_llseek,
885 #ifdef CONFIG_CIFS_POSIX
886 .unlocked_ioctl = cifs_ioctl,
887 #endif /* CONFIG_CIFS_POSIX */
888 .setlease = cifs_setlease,
891 const struct file_operations cifs_file_strict_nobrl_ops = {
892 .read = do_sync_read,
893 .write = do_sync_write,
894 .aio_read = cifs_strict_readv,
895 .aio_write = cifs_strict_writev,
897 .release = cifs_close,
898 .fsync = cifs_strict_fsync,
900 .mmap = cifs_file_strict_mmap,
901 .splice_read = generic_file_splice_read,
902 .llseek = cifs_llseek,
903 #ifdef CONFIG_CIFS_POSIX
904 .unlocked_ioctl = cifs_ioctl,
905 #endif /* CONFIG_CIFS_POSIX */
906 .setlease = cifs_setlease,
909 const struct file_operations cifs_file_direct_nobrl_ops = {
910 /* BB reevaluate whether they can be done with directio, no cache */
911 .read = do_sync_read,
912 .write = do_sync_write,
913 .aio_read = cifs_user_readv,
914 .aio_write = cifs_user_writev,
916 .release = cifs_close,
919 .mmap = cifs_file_mmap,
920 .splice_read = generic_file_splice_read,
921 #ifdef CONFIG_CIFS_POSIX
922 .unlocked_ioctl = cifs_ioctl,
923 #endif /* CONFIG_CIFS_POSIX */
924 .llseek = cifs_llseek,
925 .setlease = cifs_setlease,
928 const struct file_operations cifs_dir_ops = {
929 .readdir = cifs_readdir,
930 .release = cifs_closedir,
931 .read = generic_read_dir,
932 .unlocked_ioctl = cifs_ioctl,
933 .llseek = generic_file_llseek,
937 cifs_init_once(void *inode)
939 struct cifsInodeInfo *cifsi = inode;
941 inode_init_once(&cifsi->vfs_inode);
942 INIT_LIST_HEAD(&cifsi->llist);
943 mutex_init(&cifsi->lock_mutex);
947 cifs_init_inodecache(void)
949 cifs_inode_cachep = kmem_cache_create("cifs_inode_cache",
950 sizeof(struct cifsInodeInfo),
951 0, (SLAB_RECLAIM_ACCOUNT|
954 if (cifs_inode_cachep == NULL)
961 cifs_destroy_inodecache(void)
963 kmem_cache_destroy(cifs_inode_cachep);
967 cifs_init_request_bufs(void)
969 if (CIFSMaxBufSize < 8192) {
970 /* Buffer size can not be smaller than 2 * PATH_MAX since maximum
971 Unicode path name has to fit in any SMB/CIFS path based frames */
972 CIFSMaxBufSize = 8192;
973 } else if (CIFSMaxBufSize > 1024*127) {
974 CIFSMaxBufSize = 1024 * 127;
976 CIFSMaxBufSize &= 0x1FE00; /* Round size to even 512 byte mult*/
978 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
979 cifs_req_cachep = kmem_cache_create("cifs_request",
981 MAX_CIFS_HDR_SIZE, 0,
982 SLAB_HWCACHE_ALIGN, NULL);
983 if (cifs_req_cachep == NULL)
986 if (cifs_min_rcv < 1)
988 else if (cifs_min_rcv > 64) {
990 cERROR(1, "cifs_min_rcv set to maximum (64)");
993 cifs_req_poolp = mempool_create_slab_pool(cifs_min_rcv,
996 if (cifs_req_poolp == NULL) {
997 kmem_cache_destroy(cifs_req_cachep);
1000 /* MAX_CIFS_SMALL_BUFFER_SIZE bytes is enough for most SMB responses and
1001 almost all handle based requests (but not write response, nor is it
1002 sufficient for path based requests). A smaller size would have
1003 been more efficient (compacting multiple slab items on one 4k page)
1004 for the case in which debug was on, but this larger size allows
1005 more SMBs to use small buffer alloc and is still much more
1006 efficient to alloc 1 per page off the slab compared to 17K (5page)
1007 alloc of large cifs buffers even when page debugging is on */
1008 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
1009 MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
1011 if (cifs_sm_req_cachep == NULL) {
1012 mempool_destroy(cifs_req_poolp);
1013 kmem_cache_destroy(cifs_req_cachep);
1017 if (cifs_min_small < 2)
1019 else if (cifs_min_small > 256) {
1020 cifs_min_small = 256;
1021 cFYI(1, "cifs_min_small set to maximum (256)");
1024 cifs_sm_req_poolp = mempool_create_slab_pool(cifs_min_small,
1025 cifs_sm_req_cachep);
1027 if (cifs_sm_req_poolp == NULL) {
1028 mempool_destroy(cifs_req_poolp);
1029 kmem_cache_destroy(cifs_req_cachep);
1030 kmem_cache_destroy(cifs_sm_req_cachep);
1038 cifs_destroy_request_bufs(void)
1040 mempool_destroy(cifs_req_poolp);
1041 kmem_cache_destroy(cifs_req_cachep);
1042 mempool_destroy(cifs_sm_req_poolp);
1043 kmem_cache_destroy(cifs_sm_req_cachep);
1047 cifs_init_mids(void)
1049 cifs_mid_cachep = kmem_cache_create("cifs_mpx_ids",
1050 sizeof(struct mid_q_entry), 0,
1051 SLAB_HWCACHE_ALIGN, NULL);
1052 if (cifs_mid_cachep == NULL)
1055 /* 3 is a reasonable minimum number of simultaneous operations */
1056 cifs_mid_poolp = mempool_create_slab_pool(3, cifs_mid_cachep);
1057 if (cifs_mid_poolp == NULL) {
1058 kmem_cache_destroy(cifs_mid_cachep);
1066 cifs_destroy_mids(void)
1068 mempool_destroy(cifs_mid_poolp);
1069 kmem_cache_destroy(cifs_mid_cachep);
1077 INIT_LIST_HEAD(&cifs_tcp_ses_list);
1078 #ifdef CONFIG_CIFS_DNOTIFY_EXPERIMENTAL /* unused temporarily */
1079 INIT_LIST_HEAD(&GlobalDnotifyReqList);
1080 INIT_LIST_HEAD(&GlobalDnotifyRsp_Q);
1081 #endif /* was needed for dnotify, and will be needed for inotify when VFS fix */
1083 * Initialize Global counters
1085 atomic_set(&sesInfoAllocCount, 0);
1086 atomic_set(&tconInfoAllocCount, 0);
1087 atomic_set(&tcpSesAllocCount, 0);
1088 atomic_set(&tcpSesReconnectCount, 0);
1089 atomic_set(&tconInfoReconnectCount, 0);
1091 atomic_set(&bufAllocCount, 0);
1092 atomic_set(&smBufAllocCount, 0);
1093 #ifdef CONFIG_CIFS_STATS2
1094 atomic_set(&totBufAllocCount, 0);
1095 atomic_set(&totSmBufAllocCount, 0);
1096 #endif /* CONFIG_CIFS_STATS2 */
1098 atomic_set(&midCount, 0);
1099 GlobalCurrentXid = 0;
1100 GlobalTotalActiveXid = 0;
1101 GlobalMaxActiveXid = 0;
1102 spin_lock_init(&cifs_tcp_ses_lock);
1103 spin_lock_init(&cifs_file_list_lock);
1104 spin_lock_init(&GlobalMid_Lock);
1106 if (cifs_max_pending < 2) {
1107 cifs_max_pending = 2;
1108 cFYI(1, "cifs_max_pending set to min of 2");
1109 } else if (cifs_max_pending > CIFS_MAX_REQ) {
1110 cifs_max_pending = CIFS_MAX_REQ;
1111 cFYI(1, "cifs_max_pending set to max of %u", CIFS_MAX_REQ);
1114 rc = cifs_fscache_register();
1116 goto out_clean_proc;
1118 rc = cifs_init_inodecache();
1120 goto out_unreg_fscache;
1122 rc = cifs_init_mids();
1124 goto out_destroy_inodecache;
1126 rc = cifs_init_request_bufs();
1128 goto out_destroy_mids;
1130 #ifdef CONFIG_CIFS_UPCALL
1131 rc = register_key_type(&cifs_spnego_key_type);
1133 goto out_destroy_request_bufs;
1134 #endif /* CONFIG_CIFS_UPCALL */
1136 #ifdef CONFIG_CIFS_ACL
1137 rc = init_cifs_idmap();
1139 goto out_register_key_type;
1140 #endif /* CONFIG_CIFS_ACL */
1142 rc = register_filesystem(&cifs_fs_type);
1144 goto out_init_cifs_idmap;
1148 out_init_cifs_idmap:
1149 #ifdef CONFIG_CIFS_ACL
1151 out_register_key_type:
1153 #ifdef CONFIG_CIFS_UPCALL
1154 unregister_key_type(&cifs_spnego_key_type);
1155 out_destroy_request_bufs:
1157 cifs_destroy_request_bufs();
1159 cifs_destroy_mids();
1160 out_destroy_inodecache:
1161 cifs_destroy_inodecache();
1163 cifs_fscache_unregister();
1172 cFYI(DBG2, "exit_cifs");
1173 unregister_filesystem(&cifs_fs_type);
1174 cifs_dfs_release_automount_timer();
1175 #ifdef CONFIG_CIFS_ACL
1176 cifs_destroy_idmaptrees();
1179 #ifdef CONFIG_CIFS_UPCALL
1180 unregister_key_type(&cifs_spnego_key_type);
1182 cifs_destroy_request_bufs();
1183 cifs_destroy_mids();
1184 cifs_destroy_inodecache();
1185 cifs_fscache_unregister();
1189 MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>");
1190 MODULE_LICENSE("GPL"); /* combination of LGPL + GPL source behaves as GPL */
1192 ("VFS to access servers complying with the SNIA CIFS Specification "
1193 "e.g. Samba and Windows");
1194 MODULE_VERSION(CIFS_VERSION);
1195 module_init(init_cifs)
1196 module_exit(exit_cifs)