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 #ifdef CONFIG_CIFS_SMB2
54 #define CIFS_MAGIC_NUMBER 0xFF534D42 /* the first four bytes of SMB PDUs */
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;
93 DEFINE_MUTEX(cifs_kmap_mutex);
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 int rc = -EOPNOTSUPP;
172 buf->f_type = CIFS_MAGIC_NUMBER;
175 * PATH_MAX may be too long - it would presumably be total path,
176 * but note that some servers (includinng Samba 3) have a shorter
179 * Instead could get the real value via SMB_QUERY_FS_ATTRIBUTE_INFO.
181 buf->f_namelen = PATH_MAX;
182 buf->f_files = 0; /* undefined */
183 buf->f_ffree = 0; /* unlimited */
186 * We could add a second check for a QFS Unix capability bit
188 if ((tcon->ses->capabilities & CAP_UNIX) &&
189 (CIFS_POSIX_EXTENSIONS & le64_to_cpu(tcon->fsUnixInfo.Capability)))
190 rc = CIFSSMBQFSPosixInfo(xid, tcon, buf);
193 * Only need to call the old QFSInfo if failed on newer one,
196 if (rc && (tcon->ses->capabilities & CAP_NT_SMBS))
197 rc = CIFSSMBQFSInfo(xid, tcon, buf);
200 * Some old Windows servers also do not support level 103, retry with
201 * older level one if old server failed the previous call or we
202 * bypassed it because we detected that this was an older LANMAN sess
205 rc = SMBOldQFSInfo(xid, tcon, buf);
211 static int cifs_permission(struct inode *inode, int mask)
213 struct cifs_sb_info *cifs_sb;
215 cifs_sb = CIFS_SB(inode->i_sb);
217 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) {
218 if ((mask & MAY_EXEC) && !execute_ok(inode))
222 } else /* file mode might have been restricted at mount time
223 on the client (above and beyond ACL on servers) for
224 servers which do not support setting and viewing mode bits,
225 so allowing client to check permissions is useful */
226 return generic_permission(inode, mask);
229 static struct kmem_cache *cifs_inode_cachep;
230 static struct kmem_cache *cifs_req_cachep;
231 static struct kmem_cache *cifs_mid_cachep;
232 static struct kmem_cache *cifs_sm_req_cachep;
233 mempool_t *cifs_sm_req_poolp;
234 mempool_t *cifs_req_poolp;
235 mempool_t *cifs_mid_poolp;
237 static struct inode *
238 cifs_alloc_inode(struct super_block *sb)
240 struct cifsInodeInfo *cifs_inode;
241 cifs_inode = kmem_cache_alloc(cifs_inode_cachep, GFP_KERNEL);
244 cifs_inode->cifsAttrs = 0x20; /* default */
245 cifs_inode->time = 0;
246 /* Until the file is open and we have gotten oplock
247 info back from the server, can not assume caching of
248 file data or metadata */
249 cifs_set_oplock_level(cifs_inode, 0);
250 cifs_inode->delete_pending = false;
251 cifs_inode->invalid_mapping = false;
252 cifs_inode->vfs_inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */
253 cifs_inode->server_eof = 0;
254 cifs_inode->uniqueid = 0;
255 cifs_inode->createtime = 0;
257 /* Can not set i_flags here - they get immediately overwritten
258 to zero by the VFS */
259 /* cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME;*/
260 INIT_LIST_HEAD(&cifs_inode->openFileList);
261 return &cifs_inode->vfs_inode;
264 static void cifs_i_callback(struct rcu_head *head)
266 struct inode *inode = container_of(head, struct inode, i_rcu);
267 kmem_cache_free(cifs_inode_cachep, CIFS_I(inode));
271 cifs_destroy_inode(struct inode *inode)
273 call_rcu(&inode->i_rcu, cifs_i_callback);
277 cifs_evict_inode(struct inode *inode)
279 truncate_inode_pages(&inode->i_data, 0);
281 cifs_fscache_release_inode_cookie(inode);
285 cifs_show_address(struct seq_file *s, struct TCP_Server_Info *server)
287 struct sockaddr_in *sa = (struct sockaddr_in *) &server->dstaddr;
288 struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *) &server->dstaddr;
290 seq_printf(s, ",addr=");
292 switch (server->dstaddr.ss_family) {
294 seq_printf(s, "%pI4", &sa->sin_addr.s_addr);
297 seq_printf(s, "%pI6", &sa6->sin6_addr.s6_addr);
298 if (sa6->sin6_scope_id)
299 seq_printf(s, "%%%u", sa6->sin6_scope_id);
302 seq_printf(s, "(unknown)");
307 cifs_show_security(struct seq_file *s, struct TCP_Server_Info *server)
309 seq_printf(s, ",sec=");
311 switch (server->secType) {
313 seq_printf(s, "lanman");
316 seq_printf(s, "ntlmv2");
319 seq_printf(s, "ntlm");
322 seq_printf(s, "krb5");
325 seq_printf(s, "ntlmssp");
328 /* shouldn't ever happen */
329 seq_printf(s, "unknown");
333 if (server->sec_mode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
338 cifs_show_cache_flavor(struct seq_file *s, struct cifs_sb_info *cifs_sb)
340 seq_printf(s, ",cache=");
342 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO)
343 seq_printf(s, "strict");
344 else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO)
345 seq_printf(s, "none");
347 seq_printf(s, "loose");
351 * cifs_show_options() is for displaying mount options in /proc/mounts.
352 * Not all settable options are displayed but most of the important
356 cifs_show_options(struct seq_file *s, struct dentry *root)
358 struct cifs_sb_info *cifs_sb = CIFS_SB(root->d_sb);
359 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
360 struct sockaddr *srcaddr;
361 srcaddr = (struct sockaddr *)&tcon->ses->server->srcaddr;
363 seq_printf(s, ",vers=%s", tcon->ses->server->vals->version_string);
364 cifs_show_security(s, tcon->ses->server);
365 cifs_show_cache_flavor(s, cifs_sb);
367 seq_printf(s, ",unc=%s", tcon->treeName);
369 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER)
370 seq_printf(s, ",multiuser");
371 else if (tcon->ses->user_name)
372 seq_printf(s, ",username=%s", tcon->ses->user_name);
374 if (tcon->ses->domainName)
375 seq_printf(s, ",domain=%s", tcon->ses->domainName);
377 if (srcaddr->sa_family != AF_UNSPEC) {
378 struct sockaddr_in *saddr4;
379 struct sockaddr_in6 *saddr6;
380 saddr4 = (struct sockaddr_in *)srcaddr;
381 saddr6 = (struct sockaddr_in6 *)srcaddr;
382 if (srcaddr->sa_family == AF_INET6)
383 seq_printf(s, ",srcaddr=%pI6c",
385 else if (srcaddr->sa_family == AF_INET)
386 seq_printf(s, ",srcaddr=%pI4",
387 &saddr4->sin_addr.s_addr);
389 seq_printf(s, ",srcaddr=BAD-AF:%i",
390 (int)(srcaddr->sa_family));
393 seq_printf(s, ",uid=%u", cifs_sb->mnt_uid);
394 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID)
395 seq_printf(s, ",forceuid");
397 seq_printf(s, ",noforceuid");
399 seq_printf(s, ",gid=%u", cifs_sb->mnt_gid);
400 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID)
401 seq_printf(s, ",forcegid");
403 seq_printf(s, ",noforcegid");
405 cifs_show_address(s, tcon->ses->server);
408 seq_printf(s, ",file_mode=0%ho,dir_mode=0%ho",
409 cifs_sb->mnt_file_mode,
410 cifs_sb->mnt_dir_mode);
412 seq_printf(s, ",seal");
414 seq_printf(s, ",nocase");
416 seq_printf(s, ",hard");
418 seq_printf(s, ",unix");
420 seq_printf(s, ",nounix");
421 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)
422 seq_printf(s, ",posixpaths");
423 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID)
424 seq_printf(s, ",setuids");
425 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)
426 seq_printf(s, ",serverino");
427 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD)
428 seq_printf(s, ",rwpidforward");
429 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL)
430 seq_printf(s, ",forcemand");
431 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
432 seq_printf(s, ",nouser_xattr");
433 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR)
434 seq_printf(s, ",mapchars");
435 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL)
436 seq_printf(s, ",sfu");
437 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
438 seq_printf(s, ",nobrl");
439 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL)
440 seq_printf(s, ",cifsacl");
441 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM)
442 seq_printf(s, ",dynperm");
443 if (root->d_sb->s_flags & MS_POSIXACL)
444 seq_printf(s, ",acl");
445 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS)
446 seq_printf(s, ",mfsymlinks");
447 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_FSCACHE)
448 seq_printf(s, ",fsc");
449 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC)
450 seq_printf(s, ",nostrictsync");
451 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM)
452 seq_printf(s, ",noperm");
453 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_BACKUPUID)
454 seq_printf(s, ",backupuid=%u", cifs_sb->mnt_backupuid);
455 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_BACKUPGID)
456 seq_printf(s, ",backupgid=%u", cifs_sb->mnt_backupgid);
458 seq_printf(s, ",rsize=%u", cifs_sb->rsize);
459 seq_printf(s, ",wsize=%u", cifs_sb->wsize);
460 /* convert actimeo and display it in seconds */
461 seq_printf(s, ",actimeo=%lu", cifs_sb->actimeo / HZ);
466 static void cifs_umount_begin(struct super_block *sb)
468 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
469 struct cifs_tcon *tcon;
474 tcon = cifs_sb_master_tcon(cifs_sb);
476 spin_lock(&cifs_tcp_ses_lock);
477 if ((tcon->tc_count > 1) || (tcon->tidStatus == CifsExiting)) {
478 /* we have other mounts to same share or we have
479 already tried to force umount this and woken up
480 all waiting network requests, nothing to do */
481 spin_unlock(&cifs_tcp_ses_lock);
483 } else if (tcon->tc_count == 1)
484 tcon->tidStatus = CifsExiting;
485 spin_unlock(&cifs_tcp_ses_lock);
487 /* cancel_brl_requests(tcon); */ /* BB mark all brl mids as exiting */
488 /* cancel_notify_requests(tcon); */
489 if (tcon->ses && tcon->ses->server) {
490 cFYI(1, "wake up tasks now - umount begin not complete");
491 wake_up_all(&tcon->ses->server->request_q);
492 wake_up_all(&tcon->ses->server->response_q);
493 msleep(1); /* yield */
494 /* we have to kick the requests once more */
495 wake_up_all(&tcon->ses->server->response_q);
502 #ifdef CONFIG_CIFS_STATS2
503 static int cifs_show_stats(struct seq_file *s, struct dentry *root)
510 static int cifs_remount(struct super_block *sb, int *flags, char *data)
512 *flags |= MS_NODIRATIME;
516 static int cifs_drop_inode(struct inode *inode)
518 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
520 /* no serverino => unconditional eviction */
521 return !(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) ||
522 generic_drop_inode(inode);
525 static const struct super_operations cifs_super_ops = {
526 .statfs = cifs_statfs,
527 .alloc_inode = cifs_alloc_inode,
528 .destroy_inode = cifs_destroy_inode,
529 .drop_inode = cifs_drop_inode,
530 .evict_inode = cifs_evict_inode,
531 /* .delete_inode = cifs_delete_inode, */ /* Do not need above
532 function unless later we add lazy close of inodes or unless the
533 kernel forgets to call us with the same number of releases (closes)
535 .show_options = cifs_show_options,
536 .umount_begin = cifs_umount_begin,
537 .remount_fs = cifs_remount,
538 #ifdef CONFIG_CIFS_STATS2
539 .show_stats = cifs_show_stats,
544 * Get root dentry from superblock according to prefix path mount option.
545 * Return dentry with refcount + 1 on success and NULL otherwise.
547 static struct dentry *
548 cifs_get_root(struct smb_vol *vol, struct super_block *sb)
550 struct dentry *dentry;
551 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
552 char *full_path = NULL;
556 full_path = build_path_to_root(vol, cifs_sb,
557 cifs_sb_master_tcon(cifs_sb));
558 if (full_path == NULL)
559 return ERR_PTR(-ENOMEM);
561 cFYI(1, "Get root dentry for %s", full_path);
563 sep = CIFS_DIR_SEP(cifs_sb);
564 dentry = dget(sb->s_root);
568 struct inode *dir = dentry->d_inode;
569 struct dentry *child;
573 dentry = ERR_PTR(-ENOENT);
577 /* skip separators */
584 while (*s && *s != sep)
587 mutex_lock(&dir->i_mutex);
588 child = lookup_one_len(p, dentry, s - p);
589 mutex_unlock(&dir->i_mutex);
592 } while (!IS_ERR(dentry));
597 static int cifs_set_super(struct super_block *sb, void *data)
599 struct cifs_mnt_data *mnt_data = data;
600 sb->s_fs_info = mnt_data->cifs_sb;
601 return set_anon_super(sb, NULL);
604 static struct dentry *
605 cifs_do_mount(struct file_system_type *fs_type,
606 int flags, const char *dev_name, void *data)
609 struct super_block *sb;
610 struct cifs_sb_info *cifs_sb;
611 struct smb_vol *volume_info;
612 struct cifs_mnt_data mnt_data;
615 cFYI(1, "Devname: %s flags: %d ", dev_name, flags);
617 volume_info = cifs_get_volume_info((char *)data, dev_name);
618 if (IS_ERR(volume_info))
619 return ERR_CAST(volume_info);
621 cifs_sb = kzalloc(sizeof(struct cifs_sb_info), GFP_KERNEL);
622 if (cifs_sb == NULL) {
623 root = ERR_PTR(-ENOMEM);
627 cifs_sb->mountdata = kstrndup(data, PAGE_SIZE, GFP_KERNEL);
628 if (cifs_sb->mountdata == NULL) {
629 root = ERR_PTR(-ENOMEM);
633 cifs_setup_cifs_sb(volume_info, cifs_sb);
635 rc = cifs_mount(cifs_sb, volume_info);
637 if (!(flags & MS_SILENT))
638 cERROR(1, "cifs_mount failed w/return code = %d", rc);
643 mnt_data.vol = volume_info;
644 mnt_data.cifs_sb = cifs_sb;
645 mnt_data.flags = flags;
647 /* BB should we make this contingent on mount parm? */
648 flags |= MS_NODIRATIME | MS_NOATIME;
650 sb = sget(fs_type, cifs_match_super, cifs_set_super, flags, &mnt_data);
653 cifs_umount(cifs_sb);
658 cFYI(1, "Use existing superblock");
659 cifs_umount(cifs_sb);
661 rc = cifs_read_super(sb);
667 sb->s_flags |= MS_ACTIVE;
670 root = cifs_get_root(volume_info, sb);
674 cFYI(1, "dentry root is: %p", root);
678 deactivate_locked_super(sb);
680 cifs_cleanup_volume_info(volume_info);
684 kfree(cifs_sb->mountdata);
688 unload_nls(volume_info->local_nls);
692 static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
693 unsigned long nr_segs, loff_t pos)
695 struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode;
699 written = generic_file_aio_write(iocb, iov, nr_segs, pos);
701 if (CIFS_I(inode)->clientCanCacheAll)
704 rc = filemap_fdatawrite(inode->i_mapping);
706 cFYI(1, "cifs_file_aio_write: %d rc on %p inode", rc, inode);
711 static loff_t cifs_llseek(struct file *file, loff_t offset, int origin)
714 * origin == SEEK_END || SEEK_DATA || SEEK_HOLE => we must revalidate
715 * the cached file length
717 if (origin != SEEK_SET && origin != SEEK_CUR) {
719 struct inode *inode = file->f_path.dentry->d_inode;
722 * We need to be sure that all dirty pages are written and the
723 * server has the newest file length.
725 if (!CIFS_I(inode)->clientCanCacheRead && inode->i_mapping &&
726 inode->i_mapping->nrpages != 0) {
727 rc = filemap_fdatawait(inode->i_mapping);
729 mapping_set_error(inode->i_mapping, rc);
734 * Some applications poll for the file length in this strange
735 * way so we must seek to end on non-oplocked files by
736 * setting the revalidate time to zero.
738 CIFS_I(inode)->time = 0;
740 rc = cifs_revalidate_file_attr(file);
744 return generic_file_llseek(file, offset, origin);
747 static int cifs_setlease(struct file *file, long arg, struct file_lock **lease)
749 /* note that this is called by vfs setlease with lock_flocks held
750 to protect *lease from going away */
751 struct inode *inode = file->f_path.dentry->d_inode;
752 struct cifsFileInfo *cfile = file->private_data;
754 if (!(S_ISREG(inode->i_mode)))
757 /* check if file is oplocked */
758 if (((arg == F_RDLCK) &&
759 (CIFS_I(inode)->clientCanCacheRead)) ||
761 (CIFS_I(inode)->clientCanCacheAll)))
762 return generic_setlease(file, arg, lease);
763 else if (tlink_tcon(cfile->tlink)->local_lease &&
764 !CIFS_I(inode)->clientCanCacheRead)
765 /* If the server claims to support oplock on this
766 file, then we still need to check oplock even
767 if the local_lease mount option is set, but there
768 are servers which do not support oplock for which
769 this mount option may be useful if the user
770 knows that the file won't be changed on the server
772 return generic_setlease(file, arg, lease);
777 struct file_system_type cifs_fs_type = {
778 .owner = THIS_MODULE,
780 .mount = cifs_do_mount,
781 .kill_sb = cifs_kill_sb,
784 const struct inode_operations cifs_dir_inode_ops = {
785 .create = cifs_create,
786 .atomic_open = cifs_atomic_open,
787 .lookup = cifs_lookup,
788 .getattr = cifs_getattr,
789 .unlink = cifs_unlink,
790 .link = cifs_hardlink,
793 .rename = cifs_rename,
794 .permission = cifs_permission,
795 /* revalidate:cifs_revalidate, */
796 .setattr = cifs_setattr,
797 .symlink = cifs_symlink,
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_file_inode_ops = {
808 /* revalidate:cifs_revalidate, */
809 .setattr = cifs_setattr,
810 .getattr = cifs_getattr, /* do we need this anymore? */
811 .rename = cifs_rename,
812 .permission = cifs_permission,
813 #ifdef CONFIG_CIFS_XATTR
814 .setxattr = cifs_setxattr,
815 .getxattr = cifs_getxattr,
816 .listxattr = cifs_listxattr,
817 .removexattr = cifs_removexattr,
821 const struct inode_operations cifs_symlink_inode_ops = {
822 .readlink = generic_readlink,
823 .follow_link = cifs_follow_link,
824 .put_link = cifs_put_link,
825 .permission = cifs_permission,
826 /* BB add the following two eventually */
827 /* revalidate: cifs_revalidate,
828 setattr: cifs_notify_change, *//* BB do we need notify change */
829 #ifdef CONFIG_CIFS_XATTR
830 .setxattr = cifs_setxattr,
831 .getxattr = cifs_getxattr,
832 .listxattr = cifs_listxattr,
833 .removexattr = cifs_removexattr,
837 const struct file_operations cifs_file_ops = {
838 .read = do_sync_read,
839 .write = do_sync_write,
840 .aio_read = generic_file_aio_read,
841 .aio_write = cifs_file_aio_write,
843 .release = cifs_close,
847 .mmap = cifs_file_mmap,
848 .splice_read = generic_file_splice_read,
849 .llseek = cifs_llseek,
850 #ifdef CONFIG_CIFS_POSIX
851 .unlocked_ioctl = cifs_ioctl,
852 #endif /* CONFIG_CIFS_POSIX */
853 .setlease = cifs_setlease,
856 const struct file_operations cifs_file_strict_ops = {
857 .read = do_sync_read,
858 .write = do_sync_write,
859 .aio_read = cifs_strict_readv,
860 .aio_write = cifs_strict_writev,
862 .release = cifs_close,
864 .fsync = cifs_strict_fsync,
866 .mmap = cifs_file_strict_mmap,
867 .splice_read = generic_file_splice_read,
868 .llseek = cifs_llseek,
869 #ifdef CONFIG_CIFS_POSIX
870 .unlocked_ioctl = cifs_ioctl,
871 #endif /* CONFIG_CIFS_POSIX */
872 .setlease = cifs_setlease,
875 const struct file_operations cifs_file_direct_ops = {
876 /* BB reevaluate whether they can be done with directio, no cache */
877 .read = do_sync_read,
878 .write = do_sync_write,
879 .aio_read = cifs_user_readv,
880 .aio_write = cifs_user_writev,
882 .release = cifs_close,
886 .mmap = cifs_file_mmap,
887 .splice_read = generic_file_splice_read,
888 #ifdef CONFIG_CIFS_POSIX
889 .unlocked_ioctl = cifs_ioctl,
890 #endif /* CONFIG_CIFS_POSIX */
891 .llseek = cifs_llseek,
892 .setlease = cifs_setlease,
895 const struct file_operations cifs_file_nobrl_ops = {
896 .read = do_sync_read,
897 .write = do_sync_write,
898 .aio_read = generic_file_aio_read,
899 .aio_write = cifs_file_aio_write,
901 .release = cifs_close,
904 .mmap = cifs_file_mmap,
905 .splice_read = generic_file_splice_read,
906 .llseek = cifs_llseek,
907 #ifdef CONFIG_CIFS_POSIX
908 .unlocked_ioctl = cifs_ioctl,
909 #endif /* CONFIG_CIFS_POSIX */
910 .setlease = cifs_setlease,
913 const struct file_operations cifs_file_strict_nobrl_ops = {
914 .read = do_sync_read,
915 .write = do_sync_write,
916 .aio_read = cifs_strict_readv,
917 .aio_write = cifs_strict_writev,
919 .release = cifs_close,
920 .fsync = cifs_strict_fsync,
922 .mmap = cifs_file_strict_mmap,
923 .splice_read = generic_file_splice_read,
924 .llseek = cifs_llseek,
925 #ifdef CONFIG_CIFS_POSIX
926 .unlocked_ioctl = cifs_ioctl,
927 #endif /* CONFIG_CIFS_POSIX */
928 .setlease = cifs_setlease,
931 const struct file_operations cifs_file_direct_nobrl_ops = {
932 /* BB reevaluate whether they can be done with directio, no cache */
933 .read = do_sync_read,
934 .write = do_sync_write,
935 .aio_read = cifs_user_readv,
936 .aio_write = cifs_user_writev,
938 .release = cifs_close,
941 .mmap = cifs_file_mmap,
942 .splice_read = generic_file_splice_read,
943 #ifdef CONFIG_CIFS_POSIX
944 .unlocked_ioctl = cifs_ioctl,
945 #endif /* CONFIG_CIFS_POSIX */
946 .llseek = cifs_llseek,
947 .setlease = cifs_setlease,
950 const struct file_operations cifs_dir_ops = {
951 .readdir = cifs_readdir,
952 .release = cifs_closedir,
953 .read = generic_read_dir,
954 .unlocked_ioctl = cifs_ioctl,
955 .llseek = generic_file_llseek,
959 cifs_init_once(void *inode)
961 struct cifsInodeInfo *cifsi = inode;
963 inode_init_once(&cifsi->vfs_inode);
964 mutex_init(&cifsi->lock_mutex);
968 cifs_init_inodecache(void)
970 cifs_inode_cachep = kmem_cache_create("cifs_inode_cache",
971 sizeof(struct cifsInodeInfo),
972 0, (SLAB_RECLAIM_ACCOUNT|
975 if (cifs_inode_cachep == NULL)
982 cifs_destroy_inodecache(void)
984 kmem_cache_destroy(cifs_inode_cachep);
988 cifs_init_request_bufs(void)
990 size_t max_hdr_size = MAX_CIFS_HDR_SIZE;
991 #ifdef CONFIG_CIFS_SMB2
993 * SMB2 maximum header size is bigger than CIFS one - no problems to
994 * allocate some more bytes for CIFS.
996 max_hdr_size = MAX_SMB2_HDR_SIZE;
998 if (CIFSMaxBufSize < 8192) {
999 /* Buffer size can not be smaller than 2 * PATH_MAX since maximum
1000 Unicode path name has to fit in any SMB/CIFS path based frames */
1001 CIFSMaxBufSize = 8192;
1002 } else if (CIFSMaxBufSize > 1024*127) {
1003 CIFSMaxBufSize = 1024 * 127;
1005 CIFSMaxBufSize &= 0x1FE00; /* Round size to even 512 byte mult*/
1007 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
1008 cifs_req_cachep = kmem_cache_create("cifs_request",
1009 CIFSMaxBufSize + max_hdr_size, 0,
1010 SLAB_HWCACHE_ALIGN, NULL);
1011 if (cifs_req_cachep == NULL)
1014 if (cifs_min_rcv < 1)
1016 else if (cifs_min_rcv > 64) {
1018 cERROR(1, "cifs_min_rcv set to maximum (64)");
1021 cifs_req_poolp = mempool_create_slab_pool(cifs_min_rcv,
1024 if (cifs_req_poolp == NULL) {
1025 kmem_cache_destroy(cifs_req_cachep);
1028 /* MAX_CIFS_SMALL_BUFFER_SIZE bytes is enough for most SMB responses and
1029 almost all handle based requests (but not write response, nor is it
1030 sufficient for path based requests). A smaller size would have
1031 been more efficient (compacting multiple slab items on one 4k page)
1032 for the case in which debug was on, but this larger size allows
1033 more SMBs to use small buffer alloc and is still much more
1034 efficient to alloc 1 per page off the slab compared to 17K (5page)
1035 alloc of large cifs buffers even when page debugging is on */
1036 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
1037 MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
1039 if (cifs_sm_req_cachep == NULL) {
1040 mempool_destroy(cifs_req_poolp);
1041 kmem_cache_destroy(cifs_req_cachep);
1045 if (cifs_min_small < 2)
1047 else if (cifs_min_small > 256) {
1048 cifs_min_small = 256;
1049 cFYI(1, "cifs_min_small set to maximum (256)");
1052 cifs_sm_req_poolp = mempool_create_slab_pool(cifs_min_small,
1053 cifs_sm_req_cachep);
1055 if (cifs_sm_req_poolp == NULL) {
1056 mempool_destroy(cifs_req_poolp);
1057 kmem_cache_destroy(cifs_req_cachep);
1058 kmem_cache_destroy(cifs_sm_req_cachep);
1066 cifs_destroy_request_bufs(void)
1068 mempool_destroy(cifs_req_poolp);
1069 kmem_cache_destroy(cifs_req_cachep);
1070 mempool_destroy(cifs_sm_req_poolp);
1071 kmem_cache_destroy(cifs_sm_req_cachep);
1075 cifs_init_mids(void)
1077 cifs_mid_cachep = kmem_cache_create("cifs_mpx_ids",
1078 sizeof(struct mid_q_entry), 0,
1079 SLAB_HWCACHE_ALIGN, NULL);
1080 if (cifs_mid_cachep == NULL)
1083 /* 3 is a reasonable minimum number of simultaneous operations */
1084 cifs_mid_poolp = mempool_create_slab_pool(3, cifs_mid_cachep);
1085 if (cifs_mid_poolp == NULL) {
1086 kmem_cache_destroy(cifs_mid_cachep);
1094 cifs_destroy_mids(void)
1096 mempool_destroy(cifs_mid_poolp);
1097 kmem_cache_destroy(cifs_mid_cachep);
1105 INIT_LIST_HEAD(&cifs_tcp_ses_list);
1106 #ifdef CONFIG_CIFS_DNOTIFY_EXPERIMENTAL /* unused temporarily */
1107 INIT_LIST_HEAD(&GlobalDnotifyReqList);
1108 INIT_LIST_HEAD(&GlobalDnotifyRsp_Q);
1109 #endif /* was needed for dnotify, and will be needed for inotify when VFS fix */
1111 * Initialize Global counters
1113 atomic_set(&sesInfoAllocCount, 0);
1114 atomic_set(&tconInfoAllocCount, 0);
1115 atomic_set(&tcpSesAllocCount, 0);
1116 atomic_set(&tcpSesReconnectCount, 0);
1117 atomic_set(&tconInfoReconnectCount, 0);
1119 atomic_set(&bufAllocCount, 0);
1120 atomic_set(&smBufAllocCount, 0);
1121 #ifdef CONFIG_CIFS_STATS2
1122 atomic_set(&totBufAllocCount, 0);
1123 atomic_set(&totSmBufAllocCount, 0);
1124 #endif /* CONFIG_CIFS_STATS2 */
1126 atomic_set(&midCount, 0);
1127 GlobalCurrentXid = 0;
1128 GlobalTotalActiveXid = 0;
1129 GlobalMaxActiveXid = 0;
1130 spin_lock_init(&cifs_tcp_ses_lock);
1131 spin_lock_init(&cifs_file_list_lock);
1132 spin_lock_init(&GlobalMid_Lock);
1134 if (cifs_max_pending < 2) {
1135 cifs_max_pending = 2;
1136 cFYI(1, "cifs_max_pending set to min of 2");
1137 } else if (cifs_max_pending > CIFS_MAX_REQ) {
1138 cifs_max_pending = CIFS_MAX_REQ;
1139 cFYI(1, "cifs_max_pending set to max of %u", CIFS_MAX_REQ);
1142 cifsiod_wq = alloc_workqueue("cifsiod", WQ_FREEZABLE|WQ_MEM_RECLAIM, 0);
1145 goto out_clean_proc;
1148 rc = cifs_fscache_register();
1150 goto out_destroy_wq;
1152 rc = cifs_init_inodecache();
1154 goto out_unreg_fscache;
1156 rc = cifs_init_mids();
1158 goto out_destroy_inodecache;
1160 rc = cifs_init_request_bufs();
1162 goto out_destroy_mids;
1164 #ifdef CONFIG_CIFS_UPCALL
1165 rc = register_key_type(&cifs_spnego_key_type);
1167 goto out_destroy_request_bufs;
1168 #endif /* CONFIG_CIFS_UPCALL */
1170 #ifdef CONFIG_CIFS_ACL
1171 rc = init_cifs_idmap();
1173 goto out_register_key_type;
1174 #endif /* CONFIG_CIFS_ACL */
1176 rc = register_filesystem(&cifs_fs_type);
1178 goto out_init_cifs_idmap;
1182 out_init_cifs_idmap:
1183 #ifdef CONFIG_CIFS_ACL
1185 out_register_key_type:
1187 #ifdef CONFIG_CIFS_UPCALL
1188 unregister_key_type(&cifs_spnego_key_type);
1189 out_destroy_request_bufs:
1191 cifs_destroy_request_bufs();
1193 cifs_destroy_mids();
1194 out_destroy_inodecache:
1195 cifs_destroy_inodecache();
1197 cifs_fscache_unregister();
1199 destroy_workqueue(cifsiod_wq);
1208 cFYI(DBG2, "exit_cifs");
1209 unregister_filesystem(&cifs_fs_type);
1210 cifs_dfs_release_automount_timer();
1211 #ifdef CONFIG_CIFS_ACL
1212 cifs_destroy_idmaptrees();
1215 #ifdef CONFIG_CIFS_UPCALL
1216 unregister_key_type(&cifs_spnego_key_type);
1218 cifs_destroy_request_bufs();
1219 cifs_destroy_mids();
1220 cifs_destroy_inodecache();
1221 cifs_fscache_unregister();
1222 destroy_workqueue(cifsiod_wq);
1226 MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>");
1227 MODULE_LICENSE("GPL"); /* combination of LGPL + GPL source behaves as GPL */
1229 ("VFS to access servers complying with the SNIA CIFS Specification "
1230 "e.g. Samba and Windows");
1231 MODULE_VERSION(CIFS_VERSION);
1232 module_init(init_cifs)
1233 module_exit(exit_cifs)