4 * Copyright (C) International Business Machines Corp., 2002,2008
5 * Author(s): Steve French (sfrench@us.ibm.com)
7 * Common Internet FileSystem (CIFS) client
9 * This library is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published
11 * by the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
17 * the GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 /* Note that BB means BUGBUG (ie something to fix eventually) */
26 #include <linux/module.h>
28 #include <linux/mount.h>
29 #include <linux/slab.h>
30 #include <linux/init.h>
31 #include <linux/list.h>
32 #include <linux/seq_file.h>
33 #include <linux/vfs.h>
34 #include <linux/mempool.h>
35 #include <linux/delay.h>
36 #include <linux/kthread.h>
37 #include <linux/freezer.h>
38 #include <linux/namei.h>
42 #define DECLARE_GLOBALS_HERE
44 #include "cifsproto.h"
45 #include "cifs_debug.h"
46 #include "cifs_fs_sb.h"
48 #include <linux/key-type.h>
49 #include "cifs_spnego.h"
51 #define CIFS_MAGIC_NUMBER 0xFF534D42 /* the first four bytes of SMB PDUs */
56 bool enable_oplocks = true;
57 unsigned int linuxExtEnabled = 1;
58 unsigned int lookupCacheEnabled = 1;
59 unsigned int multiuser_mount = 0;
60 unsigned int global_secflags = CIFSSEC_DEF;
61 /* unsigned int ntlmv2_support = 0; */
62 unsigned int sign_CIFS_PDUs = 1;
63 static const struct super_operations cifs_super_ops;
64 unsigned int CIFSMaxBufSize = CIFS_MAX_MSGSIZE;
65 module_param(CIFSMaxBufSize, int, 0);
66 MODULE_PARM_DESC(CIFSMaxBufSize, "Network buffer size (not including header). "
67 "Default: 16384 Range: 8192 to 130048");
68 unsigned int cifs_min_rcv = CIFS_MIN_RCV_POOL;
69 module_param(cifs_min_rcv, int, 0);
70 MODULE_PARM_DESC(cifs_min_rcv, "Network buffers in pool. Default: 4 Range: "
72 unsigned int cifs_min_small = 30;
73 module_param(cifs_min_small, int, 0);
74 MODULE_PARM_DESC(cifs_min_small, "Small network buffers in pool. Default: 30 "
76 unsigned int cifs_max_pending = CIFS_MAX_REQ;
77 module_param(cifs_max_pending, int, 0444);
78 MODULE_PARM_DESC(cifs_max_pending, "Simultaneous requests to server. "
79 "Default: 32767 Range: 2 to 32767.");
80 unsigned short echo_retries = 5;
81 module_param(echo_retries, ushort, 0644);
82 MODULE_PARM_DESC(echo_retries, "Number of echo attempts before giving up and "
83 "reconnecting server. Default: 5. 0 means "
85 module_param(enable_oplocks, bool, 0644);
86 MODULE_PARM_DESC(enable_oplocks, "Enable or disable oplocks (bool). Default:"
89 extern mempool_t *cifs_sm_req_poolp;
90 extern mempool_t *cifs_req_poolp;
91 extern mempool_t *cifs_mid_poolp;
94 * Bumps refcount for cifs super block.
95 * Note that it should be only called if a referece to VFS super block is
96 * already held, e.g. in open-type syscalls context. Otherwise it can race with
97 * atomic_dec_and_test in deactivate_locked_super.
100 cifs_sb_active(struct super_block *sb)
102 struct cifs_sb_info *server = CIFS_SB(sb);
104 if (atomic_inc_return(&server->active) == 1)
105 atomic_inc(&sb->s_active);
109 cifs_sb_deactive(struct super_block *sb)
111 struct cifs_sb_info *server = CIFS_SB(sb);
113 if (atomic_dec_and_test(&server->active))
114 deactivate_super(sb);
118 cifs_read_super(struct super_block *sb)
121 struct cifs_sb_info *cifs_sb;
124 cifs_sb = CIFS_SB(sb);
126 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIXACL)
127 sb->s_flags |= MS_POSIXACL;
129 if (cifs_sb_master_tcon(cifs_sb)->ses->capabilities & CAP_LARGE_FILES)
130 sb->s_maxbytes = MAX_LFS_FILESIZE;
132 sb->s_maxbytes = MAX_NON_LFS;
134 /* BB FIXME fix time_gran to be larger for LANMAN sessions */
135 sb->s_time_gran = 100;
137 sb->s_magic = CIFS_MAGIC_NUMBER;
138 sb->s_op = &cifs_super_ops;
139 sb->s_bdi = &cifs_sb->bdi;
140 sb->s_blocksize = CIFS_MAX_MSGSIZE;
141 sb->s_blocksize_bits = 14; /* default 2**14 = CIFS_MAX_MSGSIZE */
142 inode = cifs_root_iget(sb);
150 sb->s_root = d_alloc_root(inode);
157 /* do that *after* d_alloc_root() - we want NULL ->d_op for root here */
158 if (cifs_sb_master_tcon(cifs_sb)->nocase)
159 sb->s_d_op = &cifs_ci_dentry_ops;
161 sb->s_d_op = &cifs_dentry_ops;
163 #ifdef CONFIG_CIFS_NFSD_EXPORT
164 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) {
165 cFYI(1, "export ops supported");
166 sb->s_export_op = &cifs_export_ops;
168 #endif /* CONFIG_CIFS_NFSD_EXPORT */
173 cERROR(1, "cifs_read_super: get root inode failed");
180 static void cifs_kill_sb(struct super_block *sb)
182 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
184 cifs_umount(cifs_sb);
188 cifs_statfs(struct dentry *dentry, struct kstatfs *buf)
190 struct super_block *sb = dentry->d_sb;
191 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
192 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
193 int rc = -EOPNOTSUPP;
198 buf->f_type = CIFS_MAGIC_NUMBER;
201 * PATH_MAX may be too long - it would presumably be total path,
202 * but note that some servers (includinng Samba 3) have a shorter
205 * Instead could get the real value via SMB_QUERY_FS_ATTRIBUTE_INFO.
207 buf->f_namelen = PATH_MAX;
208 buf->f_files = 0; /* undefined */
209 buf->f_ffree = 0; /* unlimited */
212 * We could add a second check for a QFS Unix capability bit
214 if ((tcon->ses->capabilities & CAP_UNIX) &&
215 (CIFS_POSIX_EXTENSIONS & le64_to_cpu(tcon->fsUnixInfo.Capability)))
216 rc = CIFSSMBQFSPosixInfo(xid, tcon, buf);
219 * Only need to call the old QFSInfo if failed on newer one,
222 if (rc && (tcon->ses->capabilities & CAP_NT_SMBS))
223 rc = CIFSSMBQFSInfo(xid, tcon, buf);
226 * Some old Windows servers also do not support level 103, retry with
227 * older level one if old server failed the previous call or we
228 * bypassed it because we detected that this was an older LANMAN sess
231 rc = SMBOldQFSInfo(xid, tcon, buf);
237 static int cifs_permission(struct inode *inode, int mask)
239 struct cifs_sb_info *cifs_sb;
241 cifs_sb = CIFS_SB(inode->i_sb);
243 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) {
244 if ((mask & MAY_EXEC) && !execute_ok(inode))
248 } else /* file mode might have been restricted at mount time
249 on the client (above and beyond ACL on servers) for
250 servers which do not support setting and viewing mode bits,
251 so allowing client to check permissions is useful */
252 return generic_permission(inode, mask);
255 static struct kmem_cache *cifs_inode_cachep;
256 static struct kmem_cache *cifs_req_cachep;
257 static struct kmem_cache *cifs_mid_cachep;
258 static struct kmem_cache *cifs_sm_req_cachep;
259 mempool_t *cifs_sm_req_poolp;
260 mempool_t *cifs_req_poolp;
261 mempool_t *cifs_mid_poolp;
263 static struct inode *
264 cifs_alloc_inode(struct super_block *sb)
266 struct cifsInodeInfo *cifs_inode;
267 cifs_inode = kmem_cache_alloc(cifs_inode_cachep, GFP_KERNEL);
270 cifs_inode->cifsAttrs = 0x20; /* default */
271 cifs_inode->time = 0;
272 /* Until the file is open and we have gotten oplock
273 info back from the server, can not assume caching of
274 file data or metadata */
275 cifs_set_oplock_level(cifs_inode, 0);
276 cifs_inode->delete_pending = false;
277 cifs_inode->invalid_mapping = false;
278 cifs_inode->vfs_inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */
279 cifs_inode->server_eof = 0;
280 cifs_inode->uniqueid = 0;
281 cifs_inode->createtime = 0;
283 /* Can not set i_flags here - they get immediately overwritten
284 to zero by the VFS */
285 /* cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME;*/
286 INIT_LIST_HEAD(&cifs_inode->openFileList);
287 return &cifs_inode->vfs_inode;
290 static void cifs_i_callback(struct rcu_head *head)
292 struct inode *inode = container_of(head, struct inode, i_rcu);
293 INIT_LIST_HEAD(&inode->i_dentry);
294 kmem_cache_free(cifs_inode_cachep, CIFS_I(inode));
298 cifs_destroy_inode(struct inode *inode)
300 call_rcu(&inode->i_rcu, cifs_i_callback);
304 cifs_evict_inode(struct inode *inode)
306 truncate_inode_pages(&inode->i_data, 0);
307 end_writeback(inode);
308 cifs_fscache_release_inode_cookie(inode);
312 cifs_show_address(struct seq_file *s, struct TCP_Server_Info *server)
314 struct sockaddr_in *sa = (struct sockaddr_in *) &server->dstaddr;
315 struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *) &server->dstaddr;
317 seq_printf(s, ",addr=");
319 switch (server->dstaddr.ss_family) {
321 seq_printf(s, "%pI4", &sa->sin_addr.s_addr);
324 seq_printf(s, "%pI6", &sa6->sin6_addr.s6_addr);
325 if (sa6->sin6_scope_id)
326 seq_printf(s, "%%%u", sa6->sin6_scope_id);
329 seq_printf(s, "(unknown)");
334 cifs_show_security(struct seq_file *s, struct TCP_Server_Info *server)
336 seq_printf(s, ",sec=");
338 switch (server->secType) {
340 seq_printf(s, "lanman");
343 seq_printf(s, "ntlmv2");
346 seq_printf(s, "ntlm");
349 seq_printf(s, "krb5");
352 seq_printf(s, "ntlmssp");
355 /* shouldn't ever happen */
356 seq_printf(s, "unknown");
360 if (server->sec_mode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
365 * cifs_show_options() is for displaying mount options in /proc/mounts.
366 * Not all settable options are displayed but most of the important
370 cifs_show_options(struct seq_file *s, struct vfsmount *m)
372 struct cifs_sb_info *cifs_sb = CIFS_SB(m->mnt_sb);
373 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
374 struct sockaddr *srcaddr;
375 srcaddr = (struct sockaddr *)&tcon->ses->server->srcaddr;
377 cifs_show_security(s, tcon->ses->server);
379 seq_printf(s, ",unc=%s", tcon->treeName);
381 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER)
382 seq_printf(s, ",multiuser");
383 else if (tcon->ses->user_name)
384 seq_show_option(s, "username", tcon->ses->user_name);
386 if (tcon->ses->domainName)
387 seq_show_option(s, "domain", tcon->ses->domainName);
389 if (srcaddr->sa_family != AF_UNSPEC) {
390 struct sockaddr_in *saddr4;
391 struct sockaddr_in6 *saddr6;
392 saddr4 = (struct sockaddr_in *)srcaddr;
393 saddr6 = (struct sockaddr_in6 *)srcaddr;
394 if (srcaddr->sa_family == AF_INET6)
395 seq_printf(s, ",srcaddr=%pI6c",
397 else if (srcaddr->sa_family == AF_INET)
398 seq_printf(s, ",srcaddr=%pI4",
399 &saddr4->sin_addr.s_addr);
401 seq_printf(s, ",srcaddr=BAD-AF:%i",
402 (int)(srcaddr->sa_family));
405 seq_printf(s, ",uid=%d", cifs_sb->mnt_uid);
406 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID)
407 seq_printf(s, ",forceuid");
409 seq_printf(s, ",noforceuid");
411 seq_printf(s, ",gid=%d", cifs_sb->mnt_gid);
412 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID)
413 seq_printf(s, ",forcegid");
415 seq_printf(s, ",noforcegid");
417 cifs_show_address(s, tcon->ses->server);
420 seq_printf(s, ",file_mode=0%o,dir_mode=0%o",
421 cifs_sb->mnt_file_mode,
422 cifs_sb->mnt_dir_mode);
424 seq_printf(s, ",seal");
426 seq_printf(s, ",nocase");
428 seq_printf(s, ",hard");
430 seq_printf(s, ",unix");
432 seq_printf(s, ",nounix");
433 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)
434 seq_printf(s, ",posixpaths");
435 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID)
436 seq_printf(s, ",setuids");
437 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)
438 seq_printf(s, ",serverino");
439 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD)
440 seq_printf(s, ",rwpidforward");
441 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL)
442 seq_printf(s, ",forcemand");
443 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO)
444 seq_printf(s, ",directio");
445 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
446 seq_printf(s, ",nouser_xattr");
447 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR)
448 seq_printf(s, ",mapchars");
449 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL)
450 seq_printf(s, ",sfu");
451 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
452 seq_printf(s, ",nobrl");
453 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL)
454 seq_printf(s, ",cifsacl");
455 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM)
456 seq_printf(s, ",dynperm");
457 if (m->mnt_sb->s_flags & MS_POSIXACL)
458 seq_printf(s, ",acl");
459 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS)
460 seq_printf(s, ",mfsymlinks");
461 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_FSCACHE)
462 seq_printf(s, ",fsc");
463 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC)
464 seq_printf(s, ",nostrictsync");
465 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM)
466 seq_printf(s, ",noperm");
467 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO)
468 seq_printf(s, ",strictcache");
470 seq_printf(s, ",rsize=%d", cifs_sb->rsize);
471 seq_printf(s, ",wsize=%d", cifs_sb->wsize);
472 /* convert actimeo and display it in seconds */
473 seq_printf(s, ",actimeo=%lu", cifs_sb->actimeo / HZ);
478 static void cifs_umount_begin(struct super_block *sb)
480 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
481 struct cifs_tcon *tcon;
486 tcon = cifs_sb_master_tcon(cifs_sb);
488 spin_lock(&cifs_tcp_ses_lock);
489 if ((tcon->tc_count > 1) || (tcon->tidStatus == CifsExiting)) {
490 /* we have other mounts to same share or we have
491 already tried to force umount this and woken up
492 all waiting network requests, nothing to do */
493 spin_unlock(&cifs_tcp_ses_lock);
495 } else if (tcon->tc_count == 1)
496 tcon->tidStatus = CifsExiting;
497 spin_unlock(&cifs_tcp_ses_lock);
499 /* cancel_brl_requests(tcon); */ /* BB mark all brl mids as exiting */
500 /* cancel_notify_requests(tcon); */
501 if (tcon->ses && tcon->ses->server) {
502 cFYI(1, "wake up tasks now - umount begin not complete");
503 wake_up_all(&tcon->ses->server->request_q);
504 wake_up_all(&tcon->ses->server->response_q);
505 msleep(1); /* yield */
506 /* we have to kick the requests once more */
507 wake_up_all(&tcon->ses->server->response_q);
514 #ifdef CONFIG_CIFS_STATS2
515 static int cifs_show_stats(struct seq_file *s, struct vfsmount *mnt)
522 static int cifs_remount(struct super_block *sb, int *flags, char *data)
524 *flags |= MS_NODIRATIME;
528 static int cifs_drop_inode(struct inode *inode)
530 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
532 /* no serverino => unconditional eviction */
533 return !(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) ||
534 generic_drop_inode(inode);
537 static const struct super_operations cifs_super_ops = {
538 .statfs = cifs_statfs,
539 .alloc_inode = cifs_alloc_inode,
540 .destroy_inode = cifs_destroy_inode,
541 .drop_inode = cifs_drop_inode,
542 .evict_inode = cifs_evict_inode,
543 /* .delete_inode = cifs_delete_inode, */ /* Do not need above
544 function unless later we add lazy close of inodes or unless the
545 kernel forgets to call us with the same number of releases (closes)
547 .show_options = cifs_show_options,
548 .umount_begin = cifs_umount_begin,
549 .remount_fs = cifs_remount,
550 #ifdef CONFIG_CIFS_STATS2
551 .show_stats = cifs_show_stats,
556 * Get root dentry from superblock according to prefix path mount option.
557 * Return dentry with refcount + 1 on success and NULL otherwise.
559 static struct dentry *
560 cifs_get_root(struct smb_vol *vol, struct super_block *sb)
562 struct dentry *dentry;
563 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
564 char *full_path = NULL;
568 full_path = cifs_build_path_to_root(vol, cifs_sb,
569 cifs_sb_master_tcon(cifs_sb));
570 if (full_path == NULL)
571 return ERR_PTR(-ENOMEM);
573 cFYI(1, "Get root dentry for %s", full_path);
575 sep = CIFS_DIR_SEP(cifs_sb);
576 dentry = dget(sb->s_root);
580 struct inode *dir = dentry->d_inode;
581 struct dentry *child;
585 dentry = ERR_PTR(-ENOENT);
588 if (!S_ISDIR(dir->i_mode)) {
590 dentry = ERR_PTR(-ENOTDIR);
594 /* skip separators */
601 while (*s && *s != sep)
604 mutex_lock(&dir->i_mutex);
605 child = lookup_one_len(p, dentry, s - p);
606 mutex_unlock(&dir->i_mutex);
609 } while (!IS_ERR(dentry));
614 static int cifs_set_super(struct super_block *sb, void *data)
616 struct cifs_mnt_data *mnt_data = data;
617 sb->s_fs_info = mnt_data->cifs_sb;
618 return set_anon_super(sb, NULL);
621 static struct dentry *
622 cifs_do_mount(struct file_system_type *fs_type,
623 int flags, const char *dev_name, void *data)
626 struct super_block *sb;
627 struct cifs_sb_info *cifs_sb;
628 struct smb_vol *volume_info;
629 struct cifs_mnt_data mnt_data;
632 cFYI(1, "Devname: %s flags: %d ", dev_name, flags);
634 volume_info = cifs_get_volume_info((char *)data, dev_name);
635 if (IS_ERR(volume_info))
636 return ERR_CAST(volume_info);
638 cifs_sb = kzalloc(sizeof(struct cifs_sb_info), GFP_KERNEL);
639 if (cifs_sb == NULL) {
640 root = ERR_PTR(-ENOMEM);
644 cifs_sb->mountdata = kstrndup(data, PAGE_SIZE, GFP_KERNEL);
645 if (cifs_sb->mountdata == NULL) {
646 root = ERR_PTR(-ENOMEM);
650 cifs_setup_cifs_sb(volume_info, cifs_sb);
652 rc = cifs_mount(cifs_sb, volume_info);
654 if (!(flags & MS_SILENT))
655 cERROR(1, "cifs_mount failed w/return code = %d", rc);
660 mnt_data.vol = volume_info;
661 mnt_data.cifs_sb = cifs_sb;
662 mnt_data.flags = flags;
664 sb = sget(fs_type, cifs_match_super, cifs_set_super, &mnt_data);
667 cifs_umount(cifs_sb);
672 cFYI(1, "Use existing superblock");
673 cifs_umount(cifs_sb);
676 /* BB should we make this contingent on mount parm? */
677 sb->s_flags |= MS_NODIRATIME | MS_NOATIME;
679 rc = cifs_read_super(sb);
685 sb->s_flags |= MS_ACTIVE;
688 root = cifs_get_root(volume_info, sb);
692 cFYI(1, "dentry root is: %p", root);
696 deactivate_locked_super(sb);
698 cifs_cleanup_volume_info(volume_info);
702 kfree(cifs_sb->mountdata);
706 unload_nls(volume_info->local_nls);
710 static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
711 unsigned long nr_segs, loff_t pos)
713 struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode;
717 written = generic_file_aio_write(iocb, iov, nr_segs, pos);
719 if (CIFS_I(inode)->clientCanCacheAll)
722 rc = filemap_fdatawrite(inode->i_mapping);
724 cFYI(1, "cifs_file_aio_write: %d rc on %p inode", rc, inode);
729 static loff_t cifs_llseek(struct file *file, loff_t offset, int origin)
732 * origin == SEEK_END || SEEK_DATA || SEEK_HOLE => we must revalidate
733 * the cached file length
735 if (origin != SEEK_SET && origin != SEEK_CUR) {
737 struct inode *inode = file->f_path.dentry->d_inode;
740 * We need to be sure that all dirty pages are written and the
741 * server has the newest file length.
743 if (!CIFS_I(inode)->clientCanCacheRead && inode->i_mapping &&
744 inode->i_mapping->nrpages != 0) {
745 rc = filemap_fdatawait(inode->i_mapping);
747 mapping_set_error(inode->i_mapping, rc);
752 * Some applications poll for the file length in this strange
753 * way so we must seek to end on non-oplocked files by
754 * setting the revalidate time to zero.
756 CIFS_I(inode)->time = 0;
758 rc = cifs_revalidate_file_attr(file);
762 return generic_file_llseek(file, offset, origin);
765 static int cifs_setlease(struct file *file, long arg, struct file_lock **lease)
767 /* note that this is called by vfs setlease with lock_flocks held
768 to protect *lease from going away */
769 struct inode *inode = file->f_path.dentry->d_inode;
770 struct cifsFileInfo *cfile = file->private_data;
772 if (!(S_ISREG(inode->i_mode)))
775 /* check if file is oplocked */
776 if (((arg == F_RDLCK) &&
777 (CIFS_I(inode)->clientCanCacheRead)) ||
779 (CIFS_I(inode)->clientCanCacheAll)))
780 return generic_setlease(file, arg, lease);
781 else if (tlink_tcon(cfile->tlink)->local_lease &&
782 !CIFS_I(inode)->clientCanCacheRead)
783 /* If the server claims to support oplock on this
784 file, then we still need to check oplock even
785 if the local_lease mount option is set, but there
786 are servers which do not support oplock for which
787 this mount option may be useful if the user
788 knows that the file won't be changed on the server
790 return generic_setlease(file, arg, lease);
795 struct file_system_type cifs_fs_type = {
796 .owner = THIS_MODULE,
798 .mount = cifs_do_mount,
799 .kill_sb = cifs_kill_sb,
802 const struct inode_operations cifs_dir_inode_ops = {
803 .create = cifs_create,
804 .lookup = cifs_lookup,
805 .getattr = cifs_getattr,
806 .unlink = cifs_unlink,
807 .link = cifs_hardlink,
810 .rename = cifs_rename,
811 .permission = cifs_permission,
812 /* revalidate:cifs_revalidate, */
813 .setattr = cifs_setattr,
814 .symlink = cifs_symlink,
816 #ifdef CONFIG_CIFS_XATTR
817 .setxattr = cifs_setxattr,
818 .getxattr = cifs_getxattr,
819 .listxattr = cifs_listxattr,
820 .removexattr = cifs_removexattr,
824 const struct inode_operations cifs_file_inode_ops = {
825 /* revalidate:cifs_revalidate, */
826 .setattr = cifs_setattr,
827 .getattr = cifs_getattr, /* do we need this anymore? */
828 .rename = cifs_rename,
829 .permission = cifs_permission,
830 #ifdef CONFIG_CIFS_XATTR
831 .setxattr = cifs_setxattr,
832 .getxattr = cifs_getxattr,
833 .listxattr = cifs_listxattr,
834 .removexattr = cifs_removexattr,
838 const struct inode_operations cifs_symlink_inode_ops = {
839 .readlink = generic_readlink,
840 .follow_link = cifs_follow_link,
841 .put_link = cifs_put_link,
842 .permission = cifs_permission,
843 /* BB add the following two eventually */
844 /* revalidate: cifs_revalidate,
845 setattr: cifs_notify_change, *//* BB do we need notify change */
846 #ifdef CONFIG_CIFS_XATTR
847 .setxattr = cifs_setxattr,
848 .getxattr = cifs_getxattr,
849 .listxattr = cifs_listxattr,
850 .removexattr = cifs_removexattr,
854 const struct file_operations cifs_file_ops = {
855 .read = do_sync_read,
856 .write = do_sync_write,
857 .aio_read = generic_file_aio_read,
858 .aio_write = cifs_file_aio_write,
860 .release = cifs_close,
864 .mmap = cifs_file_mmap,
865 .splice_read = generic_file_splice_read,
866 .llseek = cifs_llseek,
867 #ifdef CONFIG_CIFS_POSIX
868 .unlocked_ioctl = cifs_ioctl,
869 #endif /* CONFIG_CIFS_POSIX */
870 .setlease = cifs_setlease,
873 const struct file_operations cifs_file_strict_ops = {
874 .read = do_sync_read,
875 .write = do_sync_write,
876 .aio_read = cifs_strict_readv,
877 .aio_write = cifs_strict_writev,
879 .release = cifs_close,
881 .fsync = cifs_strict_fsync,
883 .mmap = cifs_file_strict_mmap,
884 .splice_read = generic_file_splice_read,
885 .llseek = cifs_llseek,
886 #ifdef CONFIG_CIFS_POSIX
887 .unlocked_ioctl = cifs_ioctl,
888 #endif /* CONFIG_CIFS_POSIX */
889 .setlease = cifs_setlease,
892 const struct file_operations cifs_file_direct_ops = {
893 /* BB reevaluate whether they can be done with directio, no cache */
894 .read = do_sync_read,
895 .write = do_sync_write,
896 .aio_read = cifs_user_readv,
897 .aio_write = cifs_user_writev,
899 .release = cifs_close,
903 .mmap = cifs_file_mmap,
904 .splice_read = generic_file_splice_read,
905 #ifdef CONFIG_CIFS_POSIX
906 .unlocked_ioctl = cifs_ioctl,
907 #endif /* CONFIG_CIFS_POSIX */
908 .llseek = cifs_llseek,
909 .setlease = cifs_setlease,
912 const struct file_operations cifs_file_nobrl_ops = {
913 .read = do_sync_read,
914 .write = do_sync_write,
915 .aio_read = generic_file_aio_read,
916 .aio_write = cifs_file_aio_write,
918 .release = cifs_close,
921 .mmap = cifs_file_mmap,
922 .splice_read = generic_file_splice_read,
923 .llseek = cifs_llseek,
924 #ifdef CONFIG_CIFS_POSIX
925 .unlocked_ioctl = cifs_ioctl,
926 #endif /* CONFIG_CIFS_POSIX */
927 .setlease = cifs_setlease,
930 const struct file_operations cifs_file_strict_nobrl_ops = {
931 .read = do_sync_read,
932 .write = do_sync_write,
933 .aio_read = cifs_strict_readv,
934 .aio_write = cifs_strict_writev,
936 .release = cifs_close,
937 .fsync = cifs_strict_fsync,
939 .mmap = cifs_file_strict_mmap,
940 .splice_read = generic_file_splice_read,
941 .llseek = cifs_llseek,
942 #ifdef CONFIG_CIFS_POSIX
943 .unlocked_ioctl = cifs_ioctl,
944 #endif /* CONFIG_CIFS_POSIX */
945 .setlease = cifs_setlease,
948 const struct file_operations cifs_file_direct_nobrl_ops = {
949 /* BB reevaluate whether they can be done with directio, no cache */
950 .read = do_sync_read,
951 .write = do_sync_write,
952 .aio_read = cifs_user_readv,
953 .aio_write = cifs_user_writev,
955 .release = cifs_close,
958 .mmap = cifs_file_mmap,
959 .splice_read = generic_file_splice_read,
960 #ifdef CONFIG_CIFS_POSIX
961 .unlocked_ioctl = cifs_ioctl,
962 #endif /* CONFIG_CIFS_POSIX */
963 .llseek = cifs_llseek,
964 .setlease = cifs_setlease,
967 const struct file_operations cifs_dir_ops = {
968 .readdir = cifs_readdir,
969 .release = cifs_closedir,
970 .read = generic_read_dir,
971 .unlocked_ioctl = cifs_ioctl,
972 .llseek = generic_file_llseek,
976 cifs_init_once(void *inode)
978 struct cifsInodeInfo *cifsi = inode;
980 inode_init_once(&cifsi->vfs_inode);
981 INIT_LIST_HEAD(&cifsi->llist);
982 mutex_init(&cifsi->lock_mutex);
986 cifs_init_inodecache(void)
988 cifs_inode_cachep = kmem_cache_create("cifs_inode_cache",
989 sizeof(struct cifsInodeInfo),
990 0, (SLAB_RECLAIM_ACCOUNT|
993 if (cifs_inode_cachep == NULL)
1000 cifs_destroy_inodecache(void)
1002 kmem_cache_destroy(cifs_inode_cachep);
1006 cifs_init_request_bufs(void)
1008 if (CIFSMaxBufSize < 8192) {
1009 /* Buffer size can not be smaller than 2 * PATH_MAX since maximum
1010 Unicode path name has to fit in any SMB/CIFS path based frames */
1011 CIFSMaxBufSize = 8192;
1012 } else if (CIFSMaxBufSize > 1024*127) {
1013 CIFSMaxBufSize = 1024 * 127;
1015 CIFSMaxBufSize &= 0x1FE00; /* Round size to even 512 byte mult*/
1017 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
1018 cifs_req_cachep = kmem_cache_create("cifs_request",
1020 MAX_CIFS_HDR_SIZE, 0,
1021 SLAB_HWCACHE_ALIGN, NULL);
1022 if (cifs_req_cachep == NULL)
1025 if (cifs_min_rcv < 1)
1027 else if (cifs_min_rcv > 64) {
1029 cERROR(1, "cifs_min_rcv set to maximum (64)");
1032 cifs_req_poolp = mempool_create_slab_pool(cifs_min_rcv,
1035 if (cifs_req_poolp == NULL) {
1036 kmem_cache_destroy(cifs_req_cachep);
1039 /* MAX_CIFS_SMALL_BUFFER_SIZE bytes is enough for most SMB responses and
1040 almost all handle based requests (but not write response, nor is it
1041 sufficient for path based requests). A smaller size would have
1042 been more efficient (compacting multiple slab items on one 4k page)
1043 for the case in which debug was on, but this larger size allows
1044 more SMBs to use small buffer alloc and is still much more
1045 efficient to alloc 1 per page off the slab compared to 17K (5page)
1046 alloc of large cifs buffers even when page debugging is on */
1047 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
1048 MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
1050 if (cifs_sm_req_cachep == NULL) {
1051 mempool_destroy(cifs_req_poolp);
1052 kmem_cache_destroy(cifs_req_cachep);
1056 if (cifs_min_small < 2)
1058 else if (cifs_min_small > 256) {
1059 cifs_min_small = 256;
1060 cFYI(1, "cifs_min_small set to maximum (256)");
1063 cifs_sm_req_poolp = mempool_create_slab_pool(cifs_min_small,
1064 cifs_sm_req_cachep);
1066 if (cifs_sm_req_poolp == NULL) {
1067 mempool_destroy(cifs_req_poolp);
1068 kmem_cache_destroy(cifs_req_cachep);
1069 kmem_cache_destroy(cifs_sm_req_cachep);
1077 cifs_destroy_request_bufs(void)
1079 mempool_destroy(cifs_req_poolp);
1080 kmem_cache_destroy(cifs_req_cachep);
1081 mempool_destroy(cifs_sm_req_poolp);
1082 kmem_cache_destroy(cifs_sm_req_cachep);
1086 cifs_init_mids(void)
1088 cifs_mid_cachep = kmem_cache_create("cifs_mpx_ids",
1089 sizeof(struct mid_q_entry), 0,
1090 SLAB_HWCACHE_ALIGN, NULL);
1091 if (cifs_mid_cachep == NULL)
1094 /* 3 is a reasonable minimum number of simultaneous operations */
1095 cifs_mid_poolp = mempool_create_slab_pool(3, cifs_mid_cachep);
1096 if (cifs_mid_poolp == NULL) {
1097 kmem_cache_destroy(cifs_mid_cachep);
1105 cifs_destroy_mids(void)
1107 mempool_destroy(cifs_mid_poolp);
1108 kmem_cache_destroy(cifs_mid_cachep);
1116 INIT_LIST_HEAD(&cifs_tcp_ses_list);
1117 #ifdef CONFIG_CIFS_DNOTIFY_EXPERIMENTAL /* unused temporarily */
1118 INIT_LIST_HEAD(&GlobalDnotifyReqList);
1119 INIT_LIST_HEAD(&GlobalDnotifyRsp_Q);
1120 #endif /* was needed for dnotify, and will be needed for inotify when VFS fix */
1122 * Initialize Global counters
1124 atomic_set(&sesInfoAllocCount, 0);
1125 atomic_set(&tconInfoAllocCount, 0);
1126 atomic_set(&tcpSesAllocCount, 0);
1127 atomic_set(&tcpSesReconnectCount, 0);
1128 atomic_set(&tconInfoReconnectCount, 0);
1130 atomic_set(&bufAllocCount, 0);
1131 atomic_set(&smBufAllocCount, 0);
1132 #ifdef CONFIG_CIFS_STATS2
1133 atomic_set(&totBufAllocCount, 0);
1134 atomic_set(&totSmBufAllocCount, 0);
1135 #endif /* CONFIG_CIFS_STATS2 */
1137 atomic_set(&midCount, 0);
1138 GlobalCurrentXid = 0;
1139 GlobalTotalActiveXid = 0;
1140 GlobalMaxActiveXid = 0;
1141 spin_lock_init(&cifs_tcp_ses_lock);
1142 spin_lock_init(&cifs_file_list_lock);
1143 spin_lock_init(&GlobalMid_Lock);
1145 if (cifs_max_pending < 2) {
1146 cifs_max_pending = 2;
1147 cFYI(1, "cifs_max_pending set to min of 2");
1148 } else if (cifs_max_pending > CIFS_MAX_REQ) {
1149 cifs_max_pending = CIFS_MAX_REQ;
1150 cFYI(1, "cifs_max_pending set to max of %u", CIFS_MAX_REQ);
1153 rc = cifs_fscache_register();
1155 goto out_clean_proc;
1157 rc = cifs_init_inodecache();
1159 goto out_unreg_fscache;
1161 rc = cifs_init_mids();
1163 goto out_destroy_inodecache;
1165 rc = cifs_init_request_bufs();
1167 goto out_destroy_mids;
1169 #ifdef CONFIG_CIFS_UPCALL
1170 rc = register_key_type(&cifs_spnego_key_type);
1172 goto out_destroy_request_bufs;
1173 #endif /* CONFIG_CIFS_UPCALL */
1175 #ifdef CONFIG_CIFS_ACL
1176 rc = init_cifs_idmap();
1178 goto out_register_key_type;
1179 #endif /* CONFIG_CIFS_ACL */
1181 rc = register_filesystem(&cifs_fs_type);
1183 goto out_init_cifs_idmap;
1187 out_init_cifs_idmap:
1188 #ifdef CONFIG_CIFS_ACL
1190 out_register_key_type:
1192 #ifdef CONFIG_CIFS_UPCALL
1193 unregister_key_type(&cifs_spnego_key_type);
1194 out_destroy_request_bufs:
1196 cifs_destroy_request_bufs();
1198 cifs_destroy_mids();
1199 out_destroy_inodecache:
1200 cifs_destroy_inodecache();
1202 cifs_fscache_unregister();
1211 cFYI(DBG2, "exit_cifs");
1213 cifs_fscache_unregister();
1214 #ifdef CONFIG_CIFS_DFS_UPCALL
1215 cifs_dfs_release_automount_timer();
1217 #ifdef CONFIG_CIFS_ACL
1218 cifs_destroy_idmaptrees();
1221 #ifdef CONFIG_CIFS_UPCALL
1222 unregister_key_type(&cifs_spnego_key_type);
1224 unregister_filesystem(&cifs_fs_type);
1225 cifs_destroy_inodecache();
1226 cifs_destroy_mids();
1227 cifs_destroy_request_bufs();
1230 MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>");
1231 MODULE_LICENSE("GPL"); /* combination of LGPL + GPL source behaves as GPL */
1233 ("VFS to access servers complying with the SNIA CIFS Specification "
1234 "e.g. Samba and Windows");
1235 MODULE_VERSION(CIFS_VERSION);
1236 module_init(init_cifs)
1237 module_exit(exit_cifs)