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>
39 #include <linux/random.h>
43 #define DECLARE_GLOBALS_HERE
45 #include "cifsproto.h"
46 #include "cifs_debug.h"
47 #include "cifs_fs_sb.h"
49 #include <linux/key-type.h>
50 #include "cifs_spnego.h"
52 #ifdef CONFIG_CIFS_SMB2
59 bool enable_oplocks = true;
60 unsigned int linuxExtEnabled = 1;
61 unsigned int lookupCacheEnabled = 1;
62 unsigned int global_secflags = CIFSSEC_DEF;
63 /* unsigned int ntlmv2_support = 0; */
64 unsigned int sign_CIFS_PDUs = 1;
65 static const struct super_operations cifs_super_ops;
66 unsigned int CIFSMaxBufSize = CIFS_MAX_MSGSIZE;
67 module_param(CIFSMaxBufSize, int, 0);
68 MODULE_PARM_DESC(CIFSMaxBufSize, "Network buffer size (not including header). "
69 "Default: 16384 Range: 8192 to 130048");
70 unsigned int cifs_min_rcv = CIFS_MIN_RCV_POOL;
71 module_param(cifs_min_rcv, int, 0);
72 MODULE_PARM_DESC(cifs_min_rcv, "Network buffers in pool. Default: 4 Range: "
74 unsigned int cifs_min_small = 30;
75 module_param(cifs_min_small, int, 0);
76 MODULE_PARM_DESC(cifs_min_small, "Small network buffers in pool. Default: 30 "
78 unsigned int cifs_max_pending = CIFS_MAX_REQ;
79 module_param(cifs_max_pending, int, 0444);
80 MODULE_PARM_DESC(cifs_max_pending, "Simultaneous requests to server. "
81 "Default: 32767 Range: 2 to 32767.");
82 module_param(enable_oplocks, bool, 0644);
83 MODULE_PARM_DESC(enable_oplocks, "Enable or disable oplocks (bool). Default:"
86 extern mempool_t *cifs_sm_req_poolp;
87 extern mempool_t *cifs_req_poolp;
88 extern mempool_t *cifs_mid_poolp;
90 struct workqueue_struct *cifsiod_wq;
92 #ifdef CONFIG_CIFS_SMB2
93 __u8 cifs_client_guid[SMB2_CLIENT_GUID_SIZE];
97 cifs_read_super(struct super_block *sb)
100 struct cifs_sb_info *cifs_sb;
103 cifs_sb = CIFS_SB(sb);
105 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIXACL)
106 sb->s_flags |= MS_POSIXACL;
108 if (cifs_sb_master_tcon(cifs_sb)->ses->capabilities & CAP_LARGE_FILES)
109 sb->s_maxbytes = MAX_LFS_FILESIZE;
111 sb->s_maxbytes = MAX_NON_LFS;
113 /* BB FIXME fix time_gran to be larger for LANMAN sessions */
114 sb->s_time_gran = 100;
116 sb->s_magic = CIFS_MAGIC_NUMBER;
117 sb->s_op = &cifs_super_ops;
118 sb->s_bdi = &cifs_sb->bdi;
119 sb->s_blocksize = CIFS_MAX_MSGSIZE;
120 sb->s_blocksize_bits = 14; /* default 2**14 = CIFS_MAX_MSGSIZE */
121 inode = cifs_root_iget(sb);
128 sb->s_root = d_make_root(inode);
134 /* do that *after* d_make_root() - we want NULL ->d_op for root here */
135 if (cifs_sb_master_tcon(cifs_sb)->nocase)
136 sb->s_d_op = &cifs_ci_dentry_ops;
138 sb->s_d_op = &cifs_dentry_ops;
140 #ifdef CONFIG_CIFS_NFSD_EXPORT
141 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) {
142 cFYI(1, "export ops supported");
143 sb->s_export_op = &cifs_export_ops;
145 #endif /* CONFIG_CIFS_NFSD_EXPORT */
150 cERROR(1, "cifs_read_super: get root inode failed");
154 static void cifs_kill_sb(struct super_block *sb)
156 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
158 cifs_umount(cifs_sb);
162 cifs_statfs(struct dentry *dentry, struct kstatfs *buf)
164 struct super_block *sb = dentry->d_sb;
165 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
166 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
167 struct TCP_Server_Info *server = tcon->ses->server;
174 * PATH_MAX may be too long - it would presumably be total path,
175 * but note that some servers (includinng Samba 3) have a shorter
178 * Instead could get the real value via SMB_QUERY_FS_ATTRIBUTE_INFO.
180 buf->f_namelen = PATH_MAX;
181 buf->f_files = 0; /* undefined */
182 buf->f_ffree = 0; /* unlimited */
184 if (server->ops->queryfs)
185 rc = server->ops->queryfs(xid, tcon, buf);
191 static int cifs_permission(struct inode *inode, int mask)
193 struct cifs_sb_info *cifs_sb;
195 cifs_sb = CIFS_SB(inode->i_sb);
197 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) {
198 if ((mask & MAY_EXEC) && !execute_ok(inode))
202 } else /* file mode might have been restricted at mount time
203 on the client (above and beyond ACL on servers) for
204 servers which do not support setting and viewing mode bits,
205 so allowing client to check permissions is useful */
206 return generic_permission(inode, mask);
209 static struct kmem_cache *cifs_inode_cachep;
210 static struct kmem_cache *cifs_req_cachep;
211 static struct kmem_cache *cifs_mid_cachep;
212 static struct kmem_cache *cifs_sm_req_cachep;
213 mempool_t *cifs_sm_req_poolp;
214 mempool_t *cifs_req_poolp;
215 mempool_t *cifs_mid_poolp;
217 static struct inode *
218 cifs_alloc_inode(struct super_block *sb)
220 struct cifsInodeInfo *cifs_inode;
221 cifs_inode = kmem_cache_alloc(cifs_inode_cachep, GFP_KERNEL);
224 cifs_inode->cifsAttrs = 0x20; /* default */
225 cifs_inode->time = 0;
227 * Until the file is open and we have gotten oplock info back from the
228 * server, can not assume caching of file data or metadata.
230 cifs_set_oplock_level(cifs_inode, 0);
231 cifs_inode->delete_pending = false;
232 cifs_inode->invalid_mapping = false;
233 cifs_inode->vfs_inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */
234 cifs_inode->server_eof = 0;
235 cifs_inode->uniqueid = 0;
236 cifs_inode->createtime = 0;
237 #ifdef CONFIG_CIFS_SMB2
238 get_random_bytes(cifs_inode->lease_key, SMB2_LEASE_KEY_SIZE);
241 * Can not set i_flags here - they get immediately overwritten to zero
244 /* cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME; */
245 INIT_LIST_HEAD(&cifs_inode->openFileList);
246 INIT_LIST_HEAD(&cifs_inode->llist);
247 return &cifs_inode->vfs_inode;
250 static void cifs_i_callback(struct rcu_head *head)
252 struct inode *inode = container_of(head, struct inode, i_rcu);
253 kmem_cache_free(cifs_inode_cachep, CIFS_I(inode));
257 cifs_destroy_inode(struct inode *inode)
259 call_rcu(&inode->i_rcu, cifs_i_callback);
263 cifs_evict_inode(struct inode *inode)
265 truncate_inode_pages(&inode->i_data, 0);
267 cifs_fscache_release_inode_cookie(inode);
271 cifs_show_address(struct seq_file *s, struct TCP_Server_Info *server)
273 struct sockaddr_in *sa = (struct sockaddr_in *) &server->dstaddr;
274 struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *) &server->dstaddr;
276 seq_printf(s, ",addr=");
278 switch (server->dstaddr.ss_family) {
280 seq_printf(s, "%pI4", &sa->sin_addr.s_addr);
283 seq_printf(s, "%pI6", &sa6->sin6_addr.s6_addr);
284 if (sa6->sin6_scope_id)
285 seq_printf(s, "%%%u", sa6->sin6_scope_id);
288 seq_printf(s, "(unknown)");
293 cifs_show_security(struct seq_file *s, struct TCP_Server_Info *server)
295 seq_printf(s, ",sec=");
297 switch (server->secType) {
299 seq_printf(s, "lanman");
302 seq_printf(s, "ntlmv2");
305 seq_printf(s, "ntlm");
308 seq_printf(s, "krb5");
311 seq_printf(s, "ntlmssp");
314 /* shouldn't ever happen */
315 seq_printf(s, "unknown");
319 if (server->sec_mode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
324 cifs_show_cache_flavor(struct seq_file *s, struct cifs_sb_info *cifs_sb)
326 seq_printf(s, ",cache=");
328 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO)
329 seq_printf(s, "strict");
330 else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO)
331 seq_printf(s, "none");
333 seq_printf(s, "loose");
337 * cifs_show_options() is for displaying mount options in /proc/mounts.
338 * Not all settable options are displayed but most of the important
342 cifs_show_options(struct seq_file *s, struct dentry *root)
344 struct cifs_sb_info *cifs_sb = CIFS_SB(root->d_sb);
345 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
346 struct sockaddr *srcaddr;
347 srcaddr = (struct sockaddr *)&tcon->ses->server->srcaddr;
349 seq_printf(s, ",vers=%s", tcon->ses->server->vals->version_string);
350 cifs_show_security(s, tcon->ses->server);
351 cifs_show_cache_flavor(s, cifs_sb);
353 seq_printf(s, ",unc=%s", tcon->treeName);
355 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER)
356 seq_printf(s, ",multiuser");
357 else if (tcon->ses->user_name)
358 seq_printf(s, ",username=%s", tcon->ses->user_name);
360 if (tcon->ses->domainName)
361 seq_printf(s, ",domain=%s", tcon->ses->domainName);
363 if (srcaddr->sa_family != AF_UNSPEC) {
364 struct sockaddr_in *saddr4;
365 struct sockaddr_in6 *saddr6;
366 saddr4 = (struct sockaddr_in *)srcaddr;
367 saddr6 = (struct sockaddr_in6 *)srcaddr;
368 if (srcaddr->sa_family == AF_INET6)
369 seq_printf(s, ",srcaddr=%pI6c",
371 else if (srcaddr->sa_family == AF_INET)
372 seq_printf(s, ",srcaddr=%pI4",
373 &saddr4->sin_addr.s_addr);
375 seq_printf(s, ",srcaddr=BAD-AF:%i",
376 (int)(srcaddr->sa_family));
379 seq_printf(s, ",uid=%u", cifs_sb->mnt_uid);
380 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID)
381 seq_printf(s, ",forceuid");
383 seq_printf(s, ",noforceuid");
385 seq_printf(s, ",gid=%u", cifs_sb->mnt_gid);
386 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID)
387 seq_printf(s, ",forcegid");
389 seq_printf(s, ",noforcegid");
391 cifs_show_address(s, tcon->ses->server);
394 seq_printf(s, ",file_mode=0%ho,dir_mode=0%ho",
395 cifs_sb->mnt_file_mode,
396 cifs_sb->mnt_dir_mode);
398 seq_printf(s, ",seal");
400 seq_printf(s, ",nocase");
402 seq_printf(s, ",hard");
404 seq_printf(s, ",unix");
406 seq_printf(s, ",nounix");
407 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)
408 seq_printf(s, ",posixpaths");
409 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID)
410 seq_printf(s, ",setuids");
411 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)
412 seq_printf(s, ",serverino");
413 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD)
414 seq_printf(s, ",rwpidforward");
415 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL)
416 seq_printf(s, ",forcemand");
417 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
418 seq_printf(s, ",nouser_xattr");
419 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR)
420 seq_printf(s, ",mapchars");
421 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL)
422 seq_printf(s, ",sfu");
423 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
424 seq_printf(s, ",nobrl");
425 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL)
426 seq_printf(s, ",cifsacl");
427 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM)
428 seq_printf(s, ",dynperm");
429 if (root->d_sb->s_flags & MS_POSIXACL)
430 seq_printf(s, ",acl");
431 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS)
432 seq_printf(s, ",mfsymlinks");
433 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_FSCACHE)
434 seq_printf(s, ",fsc");
435 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC)
436 seq_printf(s, ",nostrictsync");
437 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM)
438 seq_printf(s, ",noperm");
439 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_BACKUPUID)
440 seq_printf(s, ",backupuid=%u", cifs_sb->mnt_backupuid);
441 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_BACKUPGID)
442 seq_printf(s, ",backupgid=%u", cifs_sb->mnt_backupgid);
444 seq_printf(s, ",rsize=%u", cifs_sb->rsize);
445 seq_printf(s, ",wsize=%u", cifs_sb->wsize);
446 /* convert actimeo and display it in seconds */
447 seq_printf(s, ",actimeo=%lu", cifs_sb->actimeo / HZ);
452 static void cifs_umount_begin(struct super_block *sb)
454 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
455 struct cifs_tcon *tcon;
460 tcon = cifs_sb_master_tcon(cifs_sb);
462 spin_lock(&cifs_tcp_ses_lock);
463 if ((tcon->tc_count > 1) || (tcon->tidStatus == CifsExiting)) {
464 /* we have other mounts to same share or we have
465 already tried to force umount this and woken up
466 all waiting network requests, nothing to do */
467 spin_unlock(&cifs_tcp_ses_lock);
469 } else if (tcon->tc_count == 1)
470 tcon->tidStatus = CifsExiting;
471 spin_unlock(&cifs_tcp_ses_lock);
473 /* cancel_brl_requests(tcon); */ /* BB mark all brl mids as exiting */
474 /* cancel_notify_requests(tcon); */
475 if (tcon->ses && tcon->ses->server) {
476 cFYI(1, "wake up tasks now - umount begin not complete");
477 wake_up_all(&tcon->ses->server->request_q);
478 wake_up_all(&tcon->ses->server->response_q);
479 msleep(1); /* yield */
480 /* we have to kick the requests once more */
481 wake_up_all(&tcon->ses->server->response_q);
488 #ifdef CONFIG_CIFS_STATS2
489 static int cifs_show_stats(struct seq_file *s, struct dentry *root)
496 static int cifs_remount(struct super_block *sb, int *flags, char *data)
498 *flags |= MS_NODIRATIME;
502 static int cifs_drop_inode(struct inode *inode)
504 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
506 /* no serverino => unconditional eviction */
507 return !(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) ||
508 generic_drop_inode(inode);
511 static const struct super_operations cifs_super_ops = {
512 .statfs = cifs_statfs,
513 .alloc_inode = cifs_alloc_inode,
514 .destroy_inode = cifs_destroy_inode,
515 .drop_inode = cifs_drop_inode,
516 .evict_inode = cifs_evict_inode,
517 /* .delete_inode = cifs_delete_inode, */ /* Do not need above
518 function unless later we add lazy close of inodes or unless the
519 kernel forgets to call us with the same number of releases (closes)
521 .show_options = cifs_show_options,
522 .umount_begin = cifs_umount_begin,
523 .remount_fs = cifs_remount,
524 #ifdef CONFIG_CIFS_STATS2
525 .show_stats = cifs_show_stats,
530 * Get root dentry from superblock according to prefix path mount option.
531 * Return dentry with refcount + 1 on success and NULL otherwise.
533 static struct dentry *
534 cifs_get_root(struct smb_vol *vol, struct super_block *sb)
536 struct dentry *dentry;
537 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
538 char *full_path = NULL;
542 full_path = build_path_to_root(vol, cifs_sb,
543 cifs_sb_master_tcon(cifs_sb));
544 if (full_path == NULL)
545 return ERR_PTR(-ENOMEM);
547 cFYI(1, "Get root dentry for %s", full_path);
549 sep = CIFS_DIR_SEP(cifs_sb);
550 dentry = dget(sb->s_root);
554 struct inode *dir = dentry->d_inode;
555 struct dentry *child;
559 dentry = ERR_PTR(-ENOENT);
563 /* skip separators */
570 while (*s && *s != sep)
573 mutex_lock(&dir->i_mutex);
574 child = lookup_one_len(p, dentry, s - p);
575 mutex_unlock(&dir->i_mutex);
578 } while (!IS_ERR(dentry));
583 static int cifs_set_super(struct super_block *sb, void *data)
585 struct cifs_mnt_data *mnt_data = data;
586 sb->s_fs_info = mnt_data->cifs_sb;
587 return set_anon_super(sb, NULL);
590 static struct dentry *
591 cifs_do_mount(struct file_system_type *fs_type,
592 int flags, const char *dev_name, void *data)
595 struct super_block *sb;
596 struct cifs_sb_info *cifs_sb;
597 struct smb_vol *volume_info;
598 struct cifs_mnt_data mnt_data;
601 cFYI(1, "Devname: %s flags: %d ", dev_name, flags);
603 volume_info = cifs_get_volume_info((char *)data, dev_name);
604 if (IS_ERR(volume_info))
605 return ERR_CAST(volume_info);
607 cifs_sb = kzalloc(sizeof(struct cifs_sb_info), GFP_KERNEL);
608 if (cifs_sb == NULL) {
609 root = ERR_PTR(-ENOMEM);
613 cifs_sb->mountdata = kstrndup(data, PAGE_SIZE, GFP_KERNEL);
614 if (cifs_sb->mountdata == NULL) {
615 root = ERR_PTR(-ENOMEM);
619 cifs_setup_cifs_sb(volume_info, cifs_sb);
621 rc = cifs_mount(cifs_sb, volume_info);
623 if (!(flags & MS_SILENT))
624 cERROR(1, "cifs_mount failed w/return code = %d", rc);
629 mnt_data.vol = volume_info;
630 mnt_data.cifs_sb = cifs_sb;
631 mnt_data.flags = flags;
633 /* BB should we make this contingent on mount parm? */
634 flags |= MS_NODIRATIME | MS_NOATIME;
636 sb = sget(fs_type, cifs_match_super, cifs_set_super, flags, &mnt_data);
639 cifs_umount(cifs_sb);
644 cFYI(1, "Use existing superblock");
645 cifs_umount(cifs_sb);
647 rc = cifs_read_super(sb);
653 sb->s_flags |= MS_ACTIVE;
656 root = cifs_get_root(volume_info, sb);
660 cFYI(1, "dentry root is: %p", root);
664 deactivate_locked_super(sb);
666 cifs_cleanup_volume_info(volume_info);
670 kfree(cifs_sb->mountdata);
674 unload_nls(volume_info->local_nls);
678 static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
679 unsigned long nr_segs, loff_t pos)
681 struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode;
685 written = generic_file_aio_write(iocb, iov, nr_segs, pos);
687 if (CIFS_I(inode)->clientCanCacheAll)
690 rc = filemap_fdatawrite(inode->i_mapping);
692 cFYI(1, "cifs_file_aio_write: %d rc on %p inode", rc, inode);
697 static loff_t cifs_llseek(struct file *file, loff_t offset, int origin)
700 * origin == SEEK_END || SEEK_DATA || SEEK_HOLE => we must revalidate
701 * the cached file length
703 if (origin != SEEK_SET && origin != SEEK_CUR) {
705 struct inode *inode = file->f_path.dentry->d_inode;
708 * We need to be sure that all dirty pages are written and the
709 * server has the newest file length.
711 if (!CIFS_I(inode)->clientCanCacheRead && inode->i_mapping &&
712 inode->i_mapping->nrpages != 0) {
713 rc = filemap_fdatawait(inode->i_mapping);
715 mapping_set_error(inode->i_mapping, rc);
720 * Some applications poll for the file length in this strange
721 * way so we must seek to end on non-oplocked files by
722 * setting the revalidate time to zero.
724 CIFS_I(inode)->time = 0;
726 rc = cifs_revalidate_file_attr(file);
730 return generic_file_llseek(file, offset, origin);
733 static int cifs_setlease(struct file *file, long arg, struct file_lock **lease)
735 /* note that this is called by vfs setlease with lock_flocks held
736 to protect *lease from going away */
737 struct inode *inode = file->f_path.dentry->d_inode;
738 struct cifsFileInfo *cfile = file->private_data;
740 if (!(S_ISREG(inode->i_mode)))
743 /* check if file is oplocked */
744 if (((arg == F_RDLCK) &&
745 (CIFS_I(inode)->clientCanCacheRead)) ||
747 (CIFS_I(inode)->clientCanCacheAll)))
748 return generic_setlease(file, arg, lease);
749 else if (tlink_tcon(cfile->tlink)->local_lease &&
750 !CIFS_I(inode)->clientCanCacheRead)
751 /* If the server claims to support oplock on this
752 file, then we still need to check oplock even
753 if the local_lease mount option is set, but there
754 are servers which do not support oplock for which
755 this mount option may be useful if the user
756 knows that the file won't be changed on the server
758 return generic_setlease(file, arg, lease);
763 struct file_system_type cifs_fs_type = {
764 .owner = THIS_MODULE,
766 .mount = cifs_do_mount,
767 .kill_sb = cifs_kill_sb,
770 const struct inode_operations cifs_dir_inode_ops = {
771 .create = cifs_create,
772 .atomic_open = cifs_atomic_open,
773 .lookup = cifs_lookup,
774 .getattr = cifs_getattr,
775 .unlink = cifs_unlink,
776 .link = cifs_hardlink,
779 .rename = cifs_rename,
780 .permission = cifs_permission,
781 /* revalidate:cifs_revalidate, */
782 .setattr = cifs_setattr,
783 .symlink = cifs_symlink,
785 #ifdef CONFIG_CIFS_XATTR
786 .setxattr = cifs_setxattr,
787 .getxattr = cifs_getxattr,
788 .listxattr = cifs_listxattr,
789 .removexattr = cifs_removexattr,
793 const struct inode_operations cifs_file_inode_ops = {
794 /* revalidate:cifs_revalidate, */
795 .setattr = cifs_setattr,
796 .getattr = cifs_getattr, /* do we need this anymore? */
797 .rename = cifs_rename,
798 .permission = cifs_permission,
799 #ifdef CONFIG_CIFS_XATTR
800 .setxattr = cifs_setxattr,
801 .getxattr = cifs_getxattr,
802 .listxattr = cifs_listxattr,
803 .removexattr = cifs_removexattr,
807 const struct inode_operations cifs_symlink_inode_ops = {
808 .readlink = generic_readlink,
809 .follow_link = cifs_follow_link,
810 .put_link = cifs_put_link,
811 .permission = cifs_permission,
812 /* BB add the following two eventually */
813 /* revalidate: cifs_revalidate,
814 setattr: cifs_notify_change, *//* BB do we need notify change */
815 #ifdef CONFIG_CIFS_XATTR
816 .setxattr = cifs_setxattr,
817 .getxattr = cifs_getxattr,
818 .listxattr = cifs_listxattr,
819 .removexattr = cifs_removexattr,
823 const struct file_operations cifs_file_ops = {
824 .read = do_sync_read,
825 .write = do_sync_write,
826 .aio_read = generic_file_aio_read,
827 .aio_write = cifs_file_aio_write,
829 .release = cifs_close,
833 .mmap = cifs_file_mmap,
834 .splice_read = generic_file_splice_read,
835 .llseek = cifs_llseek,
836 #ifdef CONFIG_CIFS_POSIX
837 .unlocked_ioctl = cifs_ioctl,
838 #endif /* CONFIG_CIFS_POSIX */
839 .setlease = cifs_setlease,
842 const struct file_operations cifs_file_strict_ops = {
843 .read = do_sync_read,
844 .write = do_sync_write,
845 .aio_read = cifs_strict_readv,
846 .aio_write = cifs_strict_writev,
848 .release = cifs_close,
850 .fsync = cifs_strict_fsync,
852 .mmap = cifs_file_strict_mmap,
853 .splice_read = generic_file_splice_read,
854 .llseek = cifs_llseek,
855 #ifdef CONFIG_CIFS_POSIX
856 .unlocked_ioctl = cifs_ioctl,
857 #endif /* CONFIG_CIFS_POSIX */
858 .setlease = cifs_setlease,
861 const struct file_operations cifs_file_direct_ops = {
862 /* BB reevaluate whether they can be done with directio, no cache */
863 .read = do_sync_read,
864 .write = do_sync_write,
865 .aio_read = cifs_user_readv,
866 .aio_write = cifs_user_writev,
868 .release = cifs_close,
872 .mmap = cifs_file_mmap,
873 .splice_read = generic_file_splice_read,
874 #ifdef CONFIG_CIFS_POSIX
875 .unlocked_ioctl = cifs_ioctl,
876 #endif /* CONFIG_CIFS_POSIX */
877 .llseek = cifs_llseek,
878 .setlease = cifs_setlease,
881 const struct file_operations cifs_file_nobrl_ops = {
882 .read = do_sync_read,
883 .write = do_sync_write,
884 .aio_read = generic_file_aio_read,
885 .aio_write = cifs_file_aio_write,
887 .release = cifs_close,
890 .mmap = cifs_file_mmap,
891 .splice_read = generic_file_splice_read,
892 .llseek = cifs_llseek,
893 #ifdef CONFIG_CIFS_POSIX
894 .unlocked_ioctl = cifs_ioctl,
895 #endif /* CONFIG_CIFS_POSIX */
896 .setlease = cifs_setlease,
899 const struct file_operations cifs_file_strict_nobrl_ops = {
900 .read = do_sync_read,
901 .write = do_sync_write,
902 .aio_read = cifs_strict_readv,
903 .aio_write = cifs_strict_writev,
905 .release = cifs_close,
906 .fsync = cifs_strict_fsync,
908 .mmap = cifs_file_strict_mmap,
909 .splice_read = generic_file_splice_read,
910 .llseek = cifs_llseek,
911 #ifdef CONFIG_CIFS_POSIX
912 .unlocked_ioctl = cifs_ioctl,
913 #endif /* CONFIG_CIFS_POSIX */
914 .setlease = cifs_setlease,
917 const struct file_operations cifs_file_direct_nobrl_ops = {
918 /* BB reevaluate whether they can be done with directio, no cache */
919 .read = do_sync_read,
920 .write = do_sync_write,
921 .aio_read = cifs_user_readv,
922 .aio_write = cifs_user_writev,
924 .release = cifs_close,
927 .mmap = cifs_file_mmap,
928 .splice_read = generic_file_splice_read,
929 #ifdef CONFIG_CIFS_POSIX
930 .unlocked_ioctl = cifs_ioctl,
931 #endif /* CONFIG_CIFS_POSIX */
932 .llseek = cifs_llseek,
933 .setlease = cifs_setlease,
936 const struct file_operations cifs_dir_ops = {
937 .readdir = cifs_readdir,
938 .release = cifs_closedir,
939 .read = generic_read_dir,
940 .unlocked_ioctl = cifs_ioctl,
941 .llseek = generic_file_llseek,
945 cifs_init_once(void *inode)
947 struct cifsInodeInfo *cifsi = inode;
949 inode_init_once(&cifsi->vfs_inode);
950 init_rwsem(&cifsi->lock_sem);
954 cifs_init_inodecache(void)
956 cifs_inode_cachep = kmem_cache_create("cifs_inode_cache",
957 sizeof(struct cifsInodeInfo),
958 0, (SLAB_RECLAIM_ACCOUNT|
961 if (cifs_inode_cachep == NULL)
968 cifs_destroy_inodecache(void)
970 kmem_cache_destroy(cifs_inode_cachep);
974 cifs_init_request_bufs(void)
976 size_t max_hdr_size = MAX_CIFS_HDR_SIZE;
977 #ifdef CONFIG_CIFS_SMB2
979 * SMB2 maximum header size is bigger than CIFS one - no problems to
980 * allocate some more bytes for CIFS.
982 max_hdr_size = MAX_SMB2_HDR_SIZE;
984 if (CIFSMaxBufSize < 8192) {
985 /* Buffer size can not be smaller than 2 * PATH_MAX since maximum
986 Unicode path name has to fit in any SMB/CIFS path based frames */
987 CIFSMaxBufSize = 8192;
988 } else if (CIFSMaxBufSize > 1024*127) {
989 CIFSMaxBufSize = 1024 * 127;
991 CIFSMaxBufSize &= 0x1FE00; /* Round size to even 512 byte mult*/
993 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
994 cifs_req_cachep = kmem_cache_create("cifs_request",
995 CIFSMaxBufSize + max_hdr_size, 0,
996 SLAB_HWCACHE_ALIGN, NULL);
997 if (cifs_req_cachep == NULL)
1000 if (cifs_min_rcv < 1)
1002 else if (cifs_min_rcv > 64) {
1004 cERROR(1, "cifs_min_rcv set to maximum (64)");
1007 cifs_req_poolp = mempool_create_slab_pool(cifs_min_rcv,
1010 if (cifs_req_poolp == NULL) {
1011 kmem_cache_destroy(cifs_req_cachep);
1014 /* MAX_CIFS_SMALL_BUFFER_SIZE bytes is enough for most SMB responses and
1015 almost all handle based requests (but not write response, nor is it
1016 sufficient for path based requests). A smaller size would have
1017 been more efficient (compacting multiple slab items on one 4k page)
1018 for the case in which debug was on, but this larger size allows
1019 more SMBs to use small buffer alloc and is still much more
1020 efficient to alloc 1 per page off the slab compared to 17K (5page)
1021 alloc of large cifs buffers even when page debugging is on */
1022 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
1023 MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
1025 if (cifs_sm_req_cachep == NULL) {
1026 mempool_destroy(cifs_req_poolp);
1027 kmem_cache_destroy(cifs_req_cachep);
1031 if (cifs_min_small < 2)
1033 else if (cifs_min_small > 256) {
1034 cifs_min_small = 256;
1035 cFYI(1, "cifs_min_small set to maximum (256)");
1038 cifs_sm_req_poolp = mempool_create_slab_pool(cifs_min_small,
1039 cifs_sm_req_cachep);
1041 if (cifs_sm_req_poolp == NULL) {
1042 mempool_destroy(cifs_req_poolp);
1043 kmem_cache_destroy(cifs_req_cachep);
1044 kmem_cache_destroy(cifs_sm_req_cachep);
1052 cifs_destroy_request_bufs(void)
1054 mempool_destroy(cifs_req_poolp);
1055 kmem_cache_destroy(cifs_req_cachep);
1056 mempool_destroy(cifs_sm_req_poolp);
1057 kmem_cache_destroy(cifs_sm_req_cachep);
1061 cifs_init_mids(void)
1063 cifs_mid_cachep = kmem_cache_create("cifs_mpx_ids",
1064 sizeof(struct mid_q_entry), 0,
1065 SLAB_HWCACHE_ALIGN, NULL);
1066 if (cifs_mid_cachep == NULL)
1069 /* 3 is a reasonable minimum number of simultaneous operations */
1070 cifs_mid_poolp = mempool_create_slab_pool(3, cifs_mid_cachep);
1071 if (cifs_mid_poolp == NULL) {
1072 kmem_cache_destroy(cifs_mid_cachep);
1080 cifs_destroy_mids(void)
1082 mempool_destroy(cifs_mid_poolp);
1083 kmem_cache_destroy(cifs_mid_cachep);
1091 INIT_LIST_HEAD(&cifs_tcp_ses_list);
1092 #ifdef CONFIG_CIFS_DNOTIFY_EXPERIMENTAL /* unused temporarily */
1093 INIT_LIST_HEAD(&GlobalDnotifyReqList);
1094 INIT_LIST_HEAD(&GlobalDnotifyRsp_Q);
1095 #endif /* was needed for dnotify, and will be needed for inotify when VFS fix */
1097 * Initialize Global counters
1099 atomic_set(&sesInfoAllocCount, 0);
1100 atomic_set(&tconInfoAllocCount, 0);
1101 atomic_set(&tcpSesAllocCount, 0);
1102 atomic_set(&tcpSesReconnectCount, 0);
1103 atomic_set(&tconInfoReconnectCount, 0);
1105 atomic_set(&bufAllocCount, 0);
1106 atomic_set(&smBufAllocCount, 0);
1107 #ifdef CONFIG_CIFS_STATS2
1108 atomic_set(&totBufAllocCount, 0);
1109 atomic_set(&totSmBufAllocCount, 0);
1110 #endif /* CONFIG_CIFS_STATS2 */
1112 atomic_set(&midCount, 0);
1113 GlobalCurrentXid = 0;
1114 GlobalTotalActiveXid = 0;
1115 GlobalMaxActiveXid = 0;
1116 spin_lock_init(&cifs_tcp_ses_lock);
1117 spin_lock_init(&cifs_file_list_lock);
1118 spin_lock_init(&GlobalMid_Lock);
1120 #ifdef CONFIG_CIFS_SMB2
1121 get_random_bytes(cifs_client_guid, SMB2_CLIENT_GUID_SIZE);
1124 if (cifs_max_pending < 2) {
1125 cifs_max_pending = 2;
1126 cFYI(1, "cifs_max_pending set to min of 2");
1127 } else if (cifs_max_pending > CIFS_MAX_REQ) {
1128 cifs_max_pending = CIFS_MAX_REQ;
1129 cFYI(1, "cifs_max_pending set to max of %u", CIFS_MAX_REQ);
1132 cifsiod_wq = alloc_workqueue("cifsiod", WQ_FREEZABLE|WQ_MEM_RECLAIM, 0);
1135 goto out_clean_proc;
1138 rc = cifs_fscache_register();
1140 goto out_destroy_wq;
1142 rc = cifs_init_inodecache();
1144 goto out_unreg_fscache;
1146 rc = cifs_init_mids();
1148 goto out_destroy_inodecache;
1150 rc = cifs_init_request_bufs();
1152 goto out_destroy_mids;
1154 #ifdef CONFIG_CIFS_UPCALL
1155 rc = register_key_type(&cifs_spnego_key_type);
1157 goto out_destroy_request_bufs;
1158 #endif /* CONFIG_CIFS_UPCALL */
1160 #ifdef CONFIG_CIFS_ACL
1161 rc = init_cifs_idmap();
1163 goto out_register_key_type;
1164 #endif /* CONFIG_CIFS_ACL */
1166 rc = register_filesystem(&cifs_fs_type);
1168 goto out_init_cifs_idmap;
1172 out_init_cifs_idmap:
1173 #ifdef CONFIG_CIFS_ACL
1175 out_register_key_type:
1177 #ifdef CONFIG_CIFS_UPCALL
1178 unregister_key_type(&cifs_spnego_key_type);
1179 out_destroy_request_bufs:
1181 cifs_destroy_request_bufs();
1183 cifs_destroy_mids();
1184 out_destroy_inodecache:
1185 cifs_destroy_inodecache();
1187 cifs_fscache_unregister();
1189 destroy_workqueue(cifsiod_wq);
1198 cFYI(DBG2, "exit_cifs");
1199 unregister_filesystem(&cifs_fs_type);
1200 cifs_dfs_release_automount_timer();
1201 #ifdef CONFIG_CIFS_ACL
1202 cifs_destroy_idmaptrees();
1205 #ifdef CONFIG_CIFS_UPCALL
1206 unregister_key_type(&cifs_spnego_key_type);
1208 cifs_destroy_request_bufs();
1209 cifs_destroy_mids();
1210 cifs_destroy_inodecache();
1211 cifs_fscache_unregister();
1212 destroy_workqueue(cifsiod_wq);
1216 MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>");
1217 MODULE_LICENSE("GPL"); /* combination of LGPL + GPL source behaves as GPL */
1219 ("VFS to access servers complying with the SNIA CIFS Specification "
1220 "e.g. Samba and Windows");
1221 MODULE_VERSION(CIFS_VERSION);
1222 module_init(init_cifs)
1223 module_exit(exit_cifs)