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 * Bumps refcount for cifs super block.
97 * Note that it should be only called if a referece to VFS super block is
98 * already held, e.g. in open-type syscalls context. Otherwise it can race with
99 * atomic_dec_and_test in deactivate_locked_super.
102 cifs_sb_active(struct super_block *sb)
104 struct cifs_sb_info *server = CIFS_SB(sb);
106 if (atomic_inc_return(&server->active) == 1)
107 atomic_inc(&sb->s_active);
111 cifs_sb_deactive(struct super_block *sb)
113 struct cifs_sb_info *server = CIFS_SB(sb);
115 if (atomic_dec_and_test(&server->active))
116 deactivate_super(sb);
120 cifs_read_super(struct super_block *sb)
123 struct cifs_sb_info *cifs_sb;
126 cifs_sb = CIFS_SB(sb);
128 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIXACL)
129 sb->s_flags |= MS_POSIXACL;
131 if (cifs_sb_master_tcon(cifs_sb)->ses->capabilities & CAP_LARGE_FILES)
132 sb->s_maxbytes = MAX_LFS_FILESIZE;
134 sb->s_maxbytes = MAX_NON_LFS;
136 /* BB FIXME fix time_gran to be larger for LANMAN sessions */
137 sb->s_time_gran = 100;
139 sb->s_magic = CIFS_MAGIC_NUMBER;
140 sb->s_op = &cifs_super_ops;
141 sb->s_bdi = &cifs_sb->bdi;
142 sb->s_blocksize = CIFS_MAX_MSGSIZE;
143 sb->s_blocksize_bits = 14; /* default 2**14 = CIFS_MAX_MSGSIZE */
144 inode = cifs_root_iget(sb);
152 sb->s_root = d_alloc_root(inode);
159 /* do that *after* d_alloc_root() - we want NULL ->d_op for root here */
160 if (cifs_sb_master_tcon(cifs_sb)->nocase)
161 sb->s_d_op = &cifs_ci_dentry_ops;
163 sb->s_d_op = &cifs_dentry_ops;
165 #ifdef CONFIG_CIFS_NFSD_EXPORT
166 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) {
167 cFYI(1, "export ops supported");
168 sb->s_export_op = &cifs_export_ops;
170 #endif /* CONFIG_CIFS_NFSD_EXPORT */
175 cERROR(1, "cifs_read_super: get root inode failed");
182 static void cifs_kill_sb(struct super_block *sb)
184 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
186 cifs_umount(cifs_sb);
190 cifs_statfs(struct dentry *dentry, struct kstatfs *buf)
192 struct super_block *sb = dentry->d_sb;
193 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
194 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
195 int rc = -EOPNOTSUPP;
200 buf->f_type = CIFS_MAGIC_NUMBER;
203 * PATH_MAX may be too long - it would presumably be total path,
204 * but note that some servers (includinng Samba 3) have a shorter
207 * Instead could get the real value via SMB_QUERY_FS_ATTRIBUTE_INFO.
209 buf->f_namelen = PATH_MAX;
210 buf->f_files = 0; /* undefined */
211 buf->f_ffree = 0; /* unlimited */
214 * We could add a second check for a QFS Unix capability bit
216 if ((tcon->ses->capabilities & CAP_UNIX) &&
217 (CIFS_POSIX_EXTENSIONS & le64_to_cpu(tcon->fsUnixInfo.Capability)))
218 rc = CIFSSMBQFSPosixInfo(xid, tcon, buf);
221 * Only need to call the old QFSInfo if failed on newer one,
224 if (rc && (tcon->ses->capabilities & CAP_NT_SMBS))
225 rc = CIFSSMBQFSInfo(xid, tcon, buf);
228 * Some old Windows servers also do not support level 103, retry with
229 * older level one if old server failed the previous call or we
230 * bypassed it because we detected that this was an older LANMAN sess
233 rc = SMBOldQFSInfo(xid, tcon, buf);
239 static int cifs_permission(struct inode *inode, int mask)
241 struct cifs_sb_info *cifs_sb;
243 cifs_sb = CIFS_SB(inode->i_sb);
245 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) {
246 if ((mask & MAY_EXEC) && !execute_ok(inode))
250 } else /* file mode might have been restricted at mount time
251 on the client (above and beyond ACL on servers) for
252 servers which do not support setting and viewing mode bits,
253 so allowing client to check permissions is useful */
254 return generic_permission(inode, mask);
257 static struct kmem_cache *cifs_inode_cachep;
258 static struct kmem_cache *cifs_req_cachep;
259 static struct kmem_cache *cifs_mid_cachep;
260 static struct kmem_cache *cifs_sm_req_cachep;
261 mempool_t *cifs_sm_req_poolp;
262 mempool_t *cifs_req_poolp;
263 mempool_t *cifs_mid_poolp;
265 static struct inode *
266 cifs_alloc_inode(struct super_block *sb)
268 struct cifsInodeInfo *cifs_inode;
269 cifs_inode = kmem_cache_alloc(cifs_inode_cachep, GFP_KERNEL);
272 cifs_inode->cifsAttrs = 0x20; /* default */
273 cifs_inode->time = 0;
274 /* Until the file is open and we have gotten oplock
275 info back from the server, can not assume caching of
276 file data or metadata */
277 cifs_set_oplock_level(cifs_inode, 0);
278 cifs_inode->delete_pending = false;
279 cifs_inode->invalid_mapping = false;
280 cifs_inode->vfs_inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */
281 cifs_inode->server_eof = 0;
282 cifs_inode->uniqueid = 0;
283 cifs_inode->createtime = 0;
285 /* Can not set i_flags here - they get immediately overwritten
286 to zero by the VFS */
287 /* cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME;*/
288 INIT_LIST_HEAD(&cifs_inode->openFileList);
289 return &cifs_inode->vfs_inode;
292 static void cifs_i_callback(struct rcu_head *head)
294 struct inode *inode = container_of(head, struct inode, i_rcu);
295 INIT_LIST_HEAD(&inode->i_dentry);
296 kmem_cache_free(cifs_inode_cachep, CIFS_I(inode));
300 cifs_destroy_inode(struct inode *inode)
302 call_rcu(&inode->i_rcu, cifs_i_callback);
306 cifs_evict_inode(struct inode *inode)
308 truncate_inode_pages(&inode->i_data, 0);
309 end_writeback(inode);
310 cifs_fscache_release_inode_cookie(inode);
314 cifs_show_address(struct seq_file *s, struct TCP_Server_Info *server)
316 struct sockaddr_in *sa = (struct sockaddr_in *) &server->dstaddr;
317 struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *) &server->dstaddr;
319 seq_printf(s, ",addr=");
321 switch (server->dstaddr.ss_family) {
323 seq_printf(s, "%pI4", &sa->sin_addr.s_addr);
326 seq_printf(s, "%pI6", &sa6->sin6_addr.s6_addr);
327 if (sa6->sin6_scope_id)
328 seq_printf(s, "%%%u", sa6->sin6_scope_id);
331 seq_printf(s, "(unknown)");
336 cifs_show_security(struct seq_file *s, struct TCP_Server_Info *server)
338 seq_printf(s, ",sec=");
340 switch (server->secType) {
342 seq_printf(s, "lanman");
345 seq_printf(s, "ntlmv2");
348 seq_printf(s, "ntlm");
351 seq_printf(s, "krb5");
354 seq_printf(s, "ntlmssp");
357 /* shouldn't ever happen */
358 seq_printf(s, "unknown");
362 if (server->sec_mode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
367 * cifs_show_options() is for displaying mount options in /proc/mounts.
368 * Not all settable options are displayed but most of the important
372 cifs_show_options(struct seq_file *s, struct vfsmount *m)
374 struct cifs_sb_info *cifs_sb = CIFS_SB(m->mnt_sb);
375 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
376 struct sockaddr *srcaddr;
377 srcaddr = (struct sockaddr *)&tcon->ses->server->srcaddr;
379 cifs_show_security(s, tcon->ses->server);
381 seq_printf(s, ",unc=%s", tcon->treeName);
383 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER)
384 seq_printf(s, ",multiuser");
385 else if (tcon->ses->user_name)
386 seq_printf(s, ",username=%s", tcon->ses->user_name);
388 if (tcon->ses->domainName)
389 seq_printf(s, ",domain=%s", tcon->ses->domainName);
391 if (srcaddr->sa_family != AF_UNSPEC) {
392 struct sockaddr_in *saddr4;
393 struct sockaddr_in6 *saddr6;
394 saddr4 = (struct sockaddr_in *)srcaddr;
395 saddr6 = (struct sockaddr_in6 *)srcaddr;
396 if (srcaddr->sa_family == AF_INET6)
397 seq_printf(s, ",srcaddr=%pI6c",
399 else if (srcaddr->sa_family == AF_INET)
400 seq_printf(s, ",srcaddr=%pI4",
401 &saddr4->sin_addr.s_addr);
403 seq_printf(s, ",srcaddr=BAD-AF:%i",
404 (int)(srcaddr->sa_family));
407 seq_printf(s, ",uid=%d", cifs_sb->mnt_uid);
408 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID)
409 seq_printf(s, ",forceuid");
411 seq_printf(s, ",noforceuid");
413 seq_printf(s, ",gid=%d", cifs_sb->mnt_gid);
414 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID)
415 seq_printf(s, ",forcegid");
417 seq_printf(s, ",noforcegid");
419 cifs_show_address(s, tcon->ses->server);
422 seq_printf(s, ",file_mode=0%o,dir_mode=0%o",
423 cifs_sb->mnt_file_mode,
424 cifs_sb->mnt_dir_mode);
426 seq_printf(s, ",seal");
428 seq_printf(s, ",nocase");
430 seq_printf(s, ",hard");
432 seq_printf(s, ",unix");
434 seq_printf(s, ",nounix");
435 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)
436 seq_printf(s, ",posixpaths");
437 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID)
438 seq_printf(s, ",setuids");
439 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)
440 seq_printf(s, ",serverino");
441 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD)
442 seq_printf(s, ",rwpidforward");
443 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL)
444 seq_printf(s, ",forcemand");
445 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO)
446 seq_printf(s, ",directio");
447 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
448 seq_printf(s, ",nouser_xattr");
449 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR)
450 seq_printf(s, ",mapchars");
451 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL)
452 seq_printf(s, ",sfu");
453 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
454 seq_printf(s, ",nobrl");
455 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL)
456 seq_printf(s, ",cifsacl");
457 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM)
458 seq_printf(s, ",dynperm");
459 if (m->mnt_sb->s_flags & MS_POSIXACL)
460 seq_printf(s, ",acl");
461 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS)
462 seq_printf(s, ",mfsymlinks");
463 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_FSCACHE)
464 seq_printf(s, ",fsc");
465 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC)
466 seq_printf(s, ",nostrictsync");
467 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM)
468 seq_printf(s, ",noperm");
469 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO)
470 seq_printf(s, ",strictcache");
472 seq_printf(s, ",rsize=%d", cifs_sb->rsize);
473 seq_printf(s, ",wsize=%d", cifs_sb->wsize);
474 /* convert actimeo and display it in seconds */
475 seq_printf(s, ",actimeo=%lu", cifs_sb->actimeo / HZ);
480 static void cifs_umount_begin(struct super_block *sb)
482 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
483 struct cifs_tcon *tcon;
488 tcon = cifs_sb_master_tcon(cifs_sb);
490 spin_lock(&cifs_tcp_ses_lock);
491 if ((tcon->tc_count > 1) || (tcon->tidStatus == CifsExiting)) {
492 /* we have other mounts to same share or we have
493 already tried to force umount this and woken up
494 all waiting network requests, nothing to do */
495 spin_unlock(&cifs_tcp_ses_lock);
497 } else if (tcon->tc_count == 1)
498 tcon->tidStatus = CifsExiting;
499 spin_unlock(&cifs_tcp_ses_lock);
501 /* cancel_brl_requests(tcon); */ /* BB mark all brl mids as exiting */
502 /* cancel_notify_requests(tcon); */
503 if (tcon->ses && tcon->ses->server) {
504 cFYI(1, "wake up tasks now - umount begin not complete");
505 wake_up_all(&tcon->ses->server->request_q);
506 wake_up_all(&tcon->ses->server->response_q);
507 msleep(1); /* yield */
508 /* we have to kick the requests once more */
509 wake_up_all(&tcon->ses->server->response_q);
516 #ifdef CONFIG_CIFS_STATS2
517 static int cifs_show_stats(struct seq_file *s, struct vfsmount *mnt)
524 static int cifs_remount(struct super_block *sb, int *flags, char *data)
526 *flags |= MS_NODIRATIME;
530 static int cifs_drop_inode(struct inode *inode)
532 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
534 /* no serverino => unconditional eviction */
535 return !(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) ||
536 generic_drop_inode(inode);
539 static const struct super_operations cifs_super_ops = {
540 .statfs = cifs_statfs,
541 .alloc_inode = cifs_alloc_inode,
542 .destroy_inode = cifs_destroy_inode,
543 .drop_inode = cifs_drop_inode,
544 .evict_inode = cifs_evict_inode,
545 /* .delete_inode = cifs_delete_inode, */ /* Do not need above
546 function unless later we add lazy close of inodes or unless the
547 kernel forgets to call us with the same number of releases (closes)
549 .show_options = cifs_show_options,
550 .umount_begin = cifs_umount_begin,
551 .remount_fs = cifs_remount,
552 #ifdef CONFIG_CIFS_STATS2
553 .show_stats = cifs_show_stats,
558 * Get root dentry from superblock according to prefix path mount option.
559 * Return dentry with refcount + 1 on success and NULL otherwise.
561 static struct dentry *
562 cifs_get_root(struct smb_vol *vol, struct super_block *sb)
564 struct dentry *dentry;
565 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
566 char *full_path = NULL;
570 full_path = cifs_build_path_to_root(vol, cifs_sb,
571 cifs_sb_master_tcon(cifs_sb));
572 if (full_path == NULL)
573 return ERR_PTR(-ENOMEM);
575 cFYI(1, "Get root dentry for %s", full_path);
577 sep = CIFS_DIR_SEP(cifs_sb);
578 dentry = dget(sb->s_root);
582 struct inode *dir = dentry->d_inode;
583 struct dentry *child;
587 dentry = ERR_PTR(-ENOENT);
590 if (!S_ISDIR(dir->i_mode)) {
592 dentry = ERR_PTR(-ENOTDIR);
596 /* skip separators */
603 while (*s && *s != sep)
606 mutex_lock(&dir->i_mutex);
607 child = lookup_one_len(p, dentry, s - p);
608 mutex_unlock(&dir->i_mutex);
611 } while (!IS_ERR(dentry));
616 static int cifs_set_super(struct super_block *sb, void *data)
618 struct cifs_mnt_data *mnt_data = data;
619 sb->s_fs_info = mnt_data->cifs_sb;
620 return set_anon_super(sb, NULL);
623 static struct dentry *
624 cifs_do_mount(struct file_system_type *fs_type,
625 int flags, const char *dev_name, void *data)
628 struct super_block *sb;
629 struct cifs_sb_info *cifs_sb;
630 struct smb_vol *volume_info;
631 struct cifs_mnt_data mnt_data;
634 cFYI(1, "Devname: %s flags: %d ", dev_name, flags);
636 volume_info = cifs_get_volume_info((char *)data, dev_name);
637 if (IS_ERR(volume_info))
638 return ERR_CAST(volume_info);
640 cifs_sb = kzalloc(sizeof(struct cifs_sb_info), GFP_KERNEL);
641 if (cifs_sb == NULL) {
642 root = ERR_PTR(-ENOMEM);
646 cifs_sb->mountdata = kstrndup(data, PAGE_SIZE, GFP_KERNEL);
647 if (cifs_sb->mountdata == NULL) {
648 root = ERR_PTR(-ENOMEM);
652 cifs_setup_cifs_sb(volume_info, cifs_sb);
654 rc = cifs_mount(cifs_sb, volume_info);
656 if (!(flags & MS_SILENT))
657 cERROR(1, "cifs_mount failed w/return code = %d", rc);
662 mnt_data.vol = volume_info;
663 mnt_data.cifs_sb = cifs_sb;
664 mnt_data.flags = flags;
666 sb = sget(fs_type, cifs_match_super, cifs_set_super, &mnt_data);
669 cifs_umount(cifs_sb);
674 cFYI(1, "Use existing superblock");
675 cifs_umount(cifs_sb);
678 /* BB should we make this contingent on mount parm? */
679 sb->s_flags |= MS_NODIRATIME | MS_NOATIME;
681 rc = cifs_read_super(sb);
687 sb->s_flags |= MS_ACTIVE;
690 root = cifs_get_root(volume_info, sb);
694 cFYI(1, "dentry root is: %p", root);
698 deactivate_locked_super(sb);
700 cifs_cleanup_volume_info(volume_info);
704 kfree(cifs_sb->mountdata);
708 unload_nls(volume_info->local_nls);
712 static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
713 unsigned long nr_segs, loff_t pos)
715 struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode;
719 written = generic_file_aio_write(iocb, iov, nr_segs, pos);
721 if (CIFS_I(inode)->clientCanCacheAll)
724 rc = filemap_fdatawrite(inode->i_mapping);
726 cFYI(1, "cifs_file_aio_write: %d rc on %p inode", rc, inode);
731 static loff_t cifs_llseek(struct file *file, loff_t offset, int origin)
734 * origin == SEEK_END || SEEK_DATA || SEEK_HOLE => we must revalidate
735 * the cached file length
737 if (origin != SEEK_SET && origin != SEEK_CUR) {
739 struct inode *inode = file->f_path.dentry->d_inode;
742 * We need to be sure that all dirty pages are written and the
743 * server has the newest file length.
745 if (!CIFS_I(inode)->clientCanCacheRead && inode->i_mapping &&
746 inode->i_mapping->nrpages != 0) {
747 rc = filemap_fdatawait(inode->i_mapping);
749 mapping_set_error(inode->i_mapping, rc);
754 * Some applications poll for the file length in this strange
755 * way so we must seek to end on non-oplocked files by
756 * setting the revalidate time to zero.
758 CIFS_I(inode)->time = 0;
760 rc = cifs_revalidate_file_attr(file);
764 return generic_file_llseek(file, offset, origin);
767 static int cifs_setlease(struct file *file, long arg, struct file_lock **lease)
769 /* note that this is called by vfs setlease with lock_flocks held
770 to protect *lease from going away */
771 struct inode *inode = file->f_path.dentry->d_inode;
772 struct cifsFileInfo *cfile = file->private_data;
774 if (!(S_ISREG(inode->i_mode)))
777 /* check if file is oplocked */
778 if (((arg == F_RDLCK) &&
779 (CIFS_I(inode)->clientCanCacheRead)) ||
781 (CIFS_I(inode)->clientCanCacheAll)))
782 return generic_setlease(file, arg, lease);
783 else if (tlink_tcon(cfile->tlink)->local_lease &&
784 !CIFS_I(inode)->clientCanCacheRead)
785 /* If the server claims to support oplock on this
786 file, then we still need to check oplock even
787 if the local_lease mount option is set, but there
788 are servers which do not support oplock for which
789 this mount option may be useful if the user
790 knows that the file won't be changed on the server
792 return generic_setlease(file, arg, lease);
797 struct file_system_type cifs_fs_type = {
798 .owner = THIS_MODULE,
800 .mount = cifs_do_mount,
801 .kill_sb = cifs_kill_sb,
804 const struct inode_operations cifs_dir_inode_ops = {
805 .create = cifs_create,
806 .lookup = cifs_lookup,
807 .getattr = cifs_getattr,
808 .unlink = cifs_unlink,
809 .link = cifs_hardlink,
812 .rename = cifs_rename,
813 .permission = cifs_permission,
814 /* revalidate:cifs_revalidate, */
815 .setattr = cifs_setattr,
816 .symlink = cifs_symlink,
818 #ifdef CONFIG_CIFS_XATTR
819 .setxattr = cifs_setxattr,
820 .getxattr = cifs_getxattr,
821 .listxattr = cifs_listxattr,
822 .removexattr = cifs_removexattr,
826 const struct inode_operations cifs_file_inode_ops = {
827 /* revalidate:cifs_revalidate, */
828 .setattr = cifs_setattr,
829 .getattr = cifs_getattr, /* do we need this anymore? */
830 .rename = cifs_rename,
831 .permission = cifs_permission,
832 #ifdef CONFIG_CIFS_XATTR
833 .setxattr = cifs_setxattr,
834 .getxattr = cifs_getxattr,
835 .listxattr = cifs_listxattr,
836 .removexattr = cifs_removexattr,
840 const struct inode_operations cifs_symlink_inode_ops = {
841 .readlink = generic_readlink,
842 .follow_link = cifs_follow_link,
843 .put_link = cifs_put_link,
844 .permission = cifs_permission,
845 /* BB add the following two eventually */
846 /* revalidate: cifs_revalidate,
847 setattr: cifs_notify_change, *//* BB do we need notify change */
848 #ifdef CONFIG_CIFS_XATTR
849 .setxattr = cifs_setxattr,
850 .getxattr = cifs_getxattr,
851 .listxattr = cifs_listxattr,
852 .removexattr = cifs_removexattr,
856 const struct file_operations cifs_file_ops = {
857 .read = do_sync_read,
858 .write = do_sync_write,
859 .aio_read = generic_file_aio_read,
860 .aio_write = cifs_file_aio_write,
862 .release = cifs_close,
866 .mmap = cifs_file_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_strict_ops = {
876 .read = do_sync_read,
877 .write = do_sync_write,
878 .aio_read = cifs_strict_readv,
879 .aio_write = cifs_strict_writev,
881 .release = cifs_close,
883 .fsync = cifs_strict_fsync,
885 .mmap = cifs_file_strict_mmap,
886 .splice_read = generic_file_splice_read,
887 .llseek = cifs_llseek,
888 #ifdef CONFIG_CIFS_POSIX
889 .unlocked_ioctl = cifs_ioctl,
890 #endif /* CONFIG_CIFS_POSIX */
891 .setlease = cifs_setlease,
894 const struct file_operations cifs_file_direct_ops = {
895 /* BB reevaluate whether they can be done with directio, no cache */
896 .read = do_sync_read,
897 .write = do_sync_write,
898 .aio_read = cifs_user_readv,
899 .aio_write = cifs_user_writev,
901 .release = cifs_close,
905 .mmap = cifs_file_mmap,
906 .splice_read = generic_file_splice_read,
907 #ifdef CONFIG_CIFS_POSIX
908 .unlocked_ioctl = cifs_ioctl,
909 #endif /* CONFIG_CIFS_POSIX */
910 .llseek = cifs_llseek,
911 .setlease = cifs_setlease,
914 const struct file_operations cifs_file_nobrl_ops = {
915 .read = do_sync_read,
916 .write = do_sync_write,
917 .aio_read = generic_file_aio_read,
918 .aio_write = cifs_file_aio_write,
920 .release = cifs_close,
923 .mmap = cifs_file_mmap,
924 .splice_read = generic_file_splice_read,
925 .llseek = cifs_llseek,
926 #ifdef CONFIG_CIFS_POSIX
927 .unlocked_ioctl = cifs_ioctl,
928 #endif /* CONFIG_CIFS_POSIX */
929 .setlease = cifs_setlease,
932 const struct file_operations cifs_file_strict_nobrl_ops = {
933 .read = do_sync_read,
934 .write = do_sync_write,
935 .aio_read = cifs_strict_readv,
936 .aio_write = cifs_strict_writev,
938 .release = cifs_close,
939 .fsync = cifs_strict_fsync,
941 .mmap = cifs_file_strict_mmap,
942 .splice_read = generic_file_splice_read,
943 .llseek = cifs_llseek,
944 #ifdef CONFIG_CIFS_POSIX
945 .unlocked_ioctl = cifs_ioctl,
946 #endif /* CONFIG_CIFS_POSIX */
947 .setlease = cifs_setlease,
950 const struct file_operations cifs_file_direct_nobrl_ops = {
951 /* BB reevaluate whether they can be done with directio, no cache */
952 .read = do_sync_read,
953 .write = do_sync_write,
954 .aio_read = cifs_user_readv,
955 .aio_write = cifs_user_writev,
957 .release = cifs_close,
960 .mmap = cifs_file_mmap,
961 .splice_read = generic_file_splice_read,
962 #ifdef CONFIG_CIFS_POSIX
963 .unlocked_ioctl = cifs_ioctl,
964 #endif /* CONFIG_CIFS_POSIX */
965 .llseek = cifs_llseek,
966 .setlease = cifs_setlease,
969 const struct file_operations cifs_dir_ops = {
970 .readdir = cifs_readdir,
971 .release = cifs_closedir,
972 .read = generic_read_dir,
973 .unlocked_ioctl = cifs_ioctl,
974 .llseek = generic_file_llseek,
978 cifs_init_once(void *inode)
980 struct cifsInodeInfo *cifsi = inode;
982 inode_init_once(&cifsi->vfs_inode);
983 INIT_LIST_HEAD(&cifsi->llist);
984 mutex_init(&cifsi->lock_mutex);
988 cifs_init_inodecache(void)
990 cifs_inode_cachep = kmem_cache_create("cifs_inode_cache",
991 sizeof(struct cifsInodeInfo),
992 0, (SLAB_RECLAIM_ACCOUNT|
995 if (cifs_inode_cachep == NULL)
1002 cifs_destroy_inodecache(void)
1004 kmem_cache_destroy(cifs_inode_cachep);
1008 cifs_init_request_bufs(void)
1010 if (CIFSMaxBufSize < 8192) {
1011 /* Buffer size can not be smaller than 2 * PATH_MAX since maximum
1012 Unicode path name has to fit in any SMB/CIFS path based frames */
1013 CIFSMaxBufSize = 8192;
1014 } else if (CIFSMaxBufSize > 1024*127) {
1015 CIFSMaxBufSize = 1024 * 127;
1017 CIFSMaxBufSize &= 0x1FE00; /* Round size to even 512 byte mult*/
1019 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
1020 cifs_req_cachep = kmem_cache_create("cifs_request",
1022 MAX_CIFS_HDR_SIZE, 0,
1023 SLAB_HWCACHE_ALIGN, NULL);
1024 if (cifs_req_cachep == NULL)
1027 if (cifs_min_rcv < 1)
1029 else if (cifs_min_rcv > 64) {
1031 cERROR(1, "cifs_min_rcv set to maximum (64)");
1034 cifs_req_poolp = mempool_create_slab_pool(cifs_min_rcv,
1037 if (cifs_req_poolp == NULL) {
1038 kmem_cache_destroy(cifs_req_cachep);
1041 /* MAX_CIFS_SMALL_BUFFER_SIZE bytes is enough for most SMB responses and
1042 almost all handle based requests (but not write response, nor is it
1043 sufficient for path based requests). A smaller size would have
1044 been more efficient (compacting multiple slab items on one 4k page)
1045 for the case in which debug was on, but this larger size allows
1046 more SMBs to use small buffer alloc and is still much more
1047 efficient to alloc 1 per page off the slab compared to 17K (5page)
1048 alloc of large cifs buffers even when page debugging is on */
1049 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
1050 MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
1052 if (cifs_sm_req_cachep == NULL) {
1053 mempool_destroy(cifs_req_poolp);
1054 kmem_cache_destroy(cifs_req_cachep);
1058 if (cifs_min_small < 2)
1060 else if (cifs_min_small > 256) {
1061 cifs_min_small = 256;
1062 cFYI(1, "cifs_min_small set to maximum (256)");
1065 cifs_sm_req_poolp = mempool_create_slab_pool(cifs_min_small,
1066 cifs_sm_req_cachep);
1068 if (cifs_sm_req_poolp == NULL) {
1069 mempool_destroy(cifs_req_poolp);
1070 kmem_cache_destroy(cifs_req_cachep);
1071 kmem_cache_destroy(cifs_sm_req_cachep);
1079 cifs_destroy_request_bufs(void)
1081 mempool_destroy(cifs_req_poolp);
1082 kmem_cache_destroy(cifs_req_cachep);
1083 mempool_destroy(cifs_sm_req_poolp);
1084 kmem_cache_destroy(cifs_sm_req_cachep);
1088 cifs_init_mids(void)
1090 cifs_mid_cachep = kmem_cache_create("cifs_mpx_ids",
1091 sizeof(struct mid_q_entry), 0,
1092 SLAB_HWCACHE_ALIGN, NULL);
1093 if (cifs_mid_cachep == NULL)
1096 /* 3 is a reasonable minimum number of simultaneous operations */
1097 cifs_mid_poolp = mempool_create_slab_pool(3, cifs_mid_cachep);
1098 if (cifs_mid_poolp == NULL) {
1099 kmem_cache_destroy(cifs_mid_cachep);
1107 cifs_destroy_mids(void)
1109 mempool_destroy(cifs_mid_poolp);
1110 kmem_cache_destroy(cifs_mid_cachep);
1118 INIT_LIST_HEAD(&cifs_tcp_ses_list);
1119 #ifdef CONFIG_CIFS_DNOTIFY_EXPERIMENTAL /* unused temporarily */
1120 INIT_LIST_HEAD(&GlobalDnotifyReqList);
1121 INIT_LIST_HEAD(&GlobalDnotifyRsp_Q);
1122 #endif /* was needed for dnotify, and will be needed for inotify when VFS fix */
1124 * Initialize Global counters
1126 atomic_set(&sesInfoAllocCount, 0);
1127 atomic_set(&tconInfoAllocCount, 0);
1128 atomic_set(&tcpSesAllocCount, 0);
1129 atomic_set(&tcpSesReconnectCount, 0);
1130 atomic_set(&tconInfoReconnectCount, 0);
1132 atomic_set(&bufAllocCount, 0);
1133 atomic_set(&smBufAllocCount, 0);
1134 #ifdef CONFIG_CIFS_STATS2
1135 atomic_set(&totBufAllocCount, 0);
1136 atomic_set(&totSmBufAllocCount, 0);
1137 #endif /* CONFIG_CIFS_STATS2 */
1139 atomic_set(&midCount, 0);
1140 GlobalCurrentXid = 0;
1141 GlobalTotalActiveXid = 0;
1142 GlobalMaxActiveXid = 0;
1143 spin_lock_init(&cifs_tcp_ses_lock);
1144 spin_lock_init(&cifs_file_list_lock);
1145 spin_lock_init(&GlobalMid_Lock);
1147 if (cifs_max_pending < 2) {
1148 cifs_max_pending = 2;
1149 cFYI(1, "cifs_max_pending set to min of 2");
1150 } else if (cifs_max_pending > CIFS_MAX_REQ) {
1151 cifs_max_pending = CIFS_MAX_REQ;
1152 cFYI(1, "cifs_max_pending set to max of %u", CIFS_MAX_REQ);
1155 rc = cifs_fscache_register();
1157 goto out_clean_proc;
1159 rc = cifs_init_inodecache();
1161 goto out_unreg_fscache;
1163 rc = cifs_init_mids();
1165 goto out_destroy_inodecache;
1167 rc = cifs_init_request_bufs();
1169 goto out_destroy_mids;
1171 #ifdef CONFIG_CIFS_UPCALL
1172 rc = register_key_type(&cifs_spnego_key_type);
1174 goto out_destroy_request_bufs;
1175 #endif /* CONFIG_CIFS_UPCALL */
1177 #ifdef CONFIG_CIFS_ACL
1178 rc = init_cifs_idmap();
1180 goto out_register_key_type;
1181 #endif /* CONFIG_CIFS_ACL */
1183 rc = register_filesystem(&cifs_fs_type);
1185 goto out_init_cifs_idmap;
1189 out_init_cifs_idmap:
1190 #ifdef CONFIG_CIFS_ACL
1192 out_register_key_type:
1194 #ifdef CONFIG_CIFS_UPCALL
1195 unregister_key_type(&cifs_spnego_key_type);
1196 out_destroy_request_bufs:
1198 cifs_destroy_request_bufs();
1200 cifs_destroy_mids();
1201 out_destroy_inodecache:
1202 cifs_destroy_inodecache();
1204 cifs_fscache_unregister();
1213 cFYI(DBG2, "exit_cifs");
1215 cifs_fscache_unregister();
1216 #ifdef CONFIG_CIFS_DFS_UPCALL
1217 cifs_dfs_release_automount_timer();
1219 #ifdef CONFIG_CIFS_ACL
1220 cifs_destroy_idmaptrees();
1223 #ifdef CONFIG_CIFS_UPCALL
1224 unregister_key_type(&cifs_spnego_key_type);
1226 unregister_filesystem(&cifs_fs_type);
1227 cifs_destroy_inodecache();
1228 cifs_destroy_mids();
1229 cifs_destroy_request_bufs();
1232 MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>");
1233 MODULE_LICENSE("GPL"); /* combination of LGPL + GPL source behaves as GPL */
1235 ("VFS to access servers complying with the SNIA CIFS Specification "
1236 "e.g. Samba and Windows");
1237 MODULE_VERSION(CIFS_VERSION);
1238 module_init(init_cifs)
1239 module_exit(exit_cifs)