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
58 bool enable_oplocks
= true;
59 unsigned int linuxExtEnabled
= 1;
60 unsigned int lookupCacheEnabled
= 1;
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 module_param(enable_oplocks
, bool, 0644);
82 MODULE_PARM_DESC(enable_oplocks
, "Enable or disable oplocks (bool). Default:"
85 extern mempool_t
*cifs_sm_req_poolp
;
86 extern mempool_t
*cifs_req_poolp
;
87 extern mempool_t
*cifs_mid_poolp
;
89 struct workqueue_struct
*cifsiod_wq
;
92 DEFINE_MUTEX(cifs_kmap_mutex
);
96 cifs_read_super(struct super_block
*sb
)
99 struct cifs_sb_info
*cifs_sb
;
102 cifs_sb
= CIFS_SB(sb
);
104 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_POSIXACL
)
105 sb
->s_flags
|= MS_POSIXACL
;
107 if (cifs_sb_master_tcon(cifs_sb
)->ses
->capabilities
& CAP_LARGE_FILES
)
108 sb
->s_maxbytes
= MAX_LFS_FILESIZE
;
110 sb
->s_maxbytes
= MAX_NON_LFS
;
112 /* BB FIXME fix time_gran to be larger for LANMAN sessions */
113 sb
->s_time_gran
= 100;
115 sb
->s_magic
= CIFS_MAGIC_NUMBER
;
116 sb
->s_op
= &cifs_super_ops
;
117 sb
->s_bdi
= &cifs_sb
->bdi
;
118 sb
->s_blocksize
= CIFS_MAX_MSGSIZE
;
119 sb
->s_blocksize_bits
= 14; /* default 2**14 = CIFS_MAX_MSGSIZE */
120 inode
= cifs_root_iget(sb
);
127 sb
->s_root
= d_make_root(inode
);
133 /* do that *after* d_make_root() - we want NULL ->d_op for root here */
134 if (cifs_sb_master_tcon(cifs_sb
)->nocase
)
135 sb
->s_d_op
= &cifs_ci_dentry_ops
;
137 sb
->s_d_op
= &cifs_dentry_ops
;
139 #ifdef CONFIG_CIFS_NFSD_EXPORT
140 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_SERVER_INUM
) {
141 cFYI(1, "export ops supported");
142 sb
->s_export_op
= &cifs_export_ops
;
144 #endif /* CONFIG_CIFS_NFSD_EXPORT */
149 cERROR(1, "cifs_read_super: get root inode failed");
153 static void cifs_kill_sb(struct super_block
*sb
)
155 struct cifs_sb_info
*cifs_sb
= CIFS_SB(sb
);
157 cifs_umount(cifs_sb
);
161 cifs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
163 struct super_block
*sb
= dentry
->d_sb
;
164 struct cifs_sb_info
*cifs_sb
= CIFS_SB(sb
);
165 struct cifs_tcon
*tcon
= cifs_sb_master_tcon(cifs_sb
);
166 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
173 * PATH_MAX may be too long - it would presumably be total path,
174 * but note that some servers (includinng Samba 3) have a shorter
177 * Instead could get the real value via SMB_QUERY_FS_ATTRIBUTE_INFO.
179 buf
->f_namelen
= PATH_MAX
;
180 buf
->f_files
= 0; /* undefined */
181 buf
->f_ffree
= 0; /* unlimited */
183 if (server
->ops
->queryfs
)
184 rc
= server
->ops
->queryfs(xid
, tcon
, buf
);
190 static int cifs_permission(struct inode
*inode
, int mask
)
192 struct cifs_sb_info
*cifs_sb
;
194 cifs_sb
= CIFS_SB(inode
->i_sb
);
196 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_NO_PERM
) {
197 if ((mask
& MAY_EXEC
) && !execute_ok(inode
))
201 } else /* file mode might have been restricted at mount time
202 on the client (above and beyond ACL on servers) for
203 servers which do not support setting and viewing mode bits,
204 so allowing client to check permissions is useful */
205 return generic_permission(inode
, mask
);
208 static struct kmem_cache
*cifs_inode_cachep
;
209 static struct kmem_cache
*cifs_req_cachep
;
210 static struct kmem_cache
*cifs_mid_cachep
;
211 static struct kmem_cache
*cifs_sm_req_cachep
;
212 mempool_t
*cifs_sm_req_poolp
;
213 mempool_t
*cifs_req_poolp
;
214 mempool_t
*cifs_mid_poolp
;
216 static struct inode
*
217 cifs_alloc_inode(struct super_block
*sb
)
219 struct cifsInodeInfo
*cifs_inode
;
220 cifs_inode
= kmem_cache_alloc(cifs_inode_cachep
, GFP_KERNEL
);
223 cifs_inode
->cifsAttrs
= 0x20; /* default */
224 cifs_inode
->time
= 0;
225 /* Until the file is open and we have gotten oplock
226 info back from the server, can not assume caching of
227 file data or metadata */
228 cifs_set_oplock_level(cifs_inode
, 0);
229 cifs_inode
->delete_pending
= false;
230 cifs_inode
->invalid_mapping
= false;
231 cifs_inode
->vfs_inode
.i_blkbits
= 14; /* 2**14 = CIFS_MAX_MSGSIZE */
232 cifs_inode
->server_eof
= 0;
233 cifs_inode
->uniqueid
= 0;
234 cifs_inode
->createtime
= 0;
236 /* Can not set i_flags here - they get immediately overwritten
237 to zero by the VFS */
238 /* cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME;*/
239 INIT_LIST_HEAD(&cifs_inode
->openFileList
);
240 return &cifs_inode
->vfs_inode
;
243 static void cifs_i_callback(struct rcu_head
*head
)
245 struct inode
*inode
= container_of(head
, struct inode
, i_rcu
);
246 kmem_cache_free(cifs_inode_cachep
, CIFS_I(inode
));
250 cifs_destroy_inode(struct inode
*inode
)
252 call_rcu(&inode
->i_rcu
, cifs_i_callback
);
256 cifs_evict_inode(struct inode
*inode
)
258 truncate_inode_pages(&inode
->i_data
, 0);
260 cifs_fscache_release_inode_cookie(inode
);
264 cifs_show_address(struct seq_file
*s
, struct TCP_Server_Info
*server
)
266 struct sockaddr_in
*sa
= (struct sockaddr_in
*) &server
->dstaddr
;
267 struct sockaddr_in6
*sa6
= (struct sockaddr_in6
*) &server
->dstaddr
;
269 seq_printf(s
, ",addr=");
271 switch (server
->dstaddr
.ss_family
) {
273 seq_printf(s
, "%pI4", &sa
->sin_addr
.s_addr
);
276 seq_printf(s
, "%pI6", &sa6
->sin6_addr
.s6_addr
);
277 if (sa6
->sin6_scope_id
)
278 seq_printf(s
, "%%%u", sa6
->sin6_scope_id
);
281 seq_printf(s
, "(unknown)");
286 cifs_show_security(struct seq_file
*s
, struct TCP_Server_Info
*server
)
288 seq_printf(s
, ",sec=");
290 switch (server
->secType
) {
292 seq_printf(s
, "lanman");
295 seq_printf(s
, "ntlmv2");
298 seq_printf(s
, "ntlm");
301 seq_printf(s
, "krb5");
304 seq_printf(s
, "ntlmssp");
307 /* shouldn't ever happen */
308 seq_printf(s
, "unknown");
312 if (server
->sec_mode
& (SECMODE_SIGN_REQUIRED
| SECMODE_SIGN_ENABLED
))
317 cifs_show_cache_flavor(struct seq_file
*s
, struct cifs_sb_info
*cifs_sb
)
319 seq_printf(s
, ",cache=");
321 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_STRICT_IO
)
322 seq_printf(s
, "strict");
323 else if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_DIRECT_IO
)
324 seq_printf(s
, "none");
326 seq_printf(s
, "loose");
330 * cifs_show_options() is for displaying mount options in /proc/mounts.
331 * Not all settable options are displayed but most of the important
335 cifs_show_options(struct seq_file
*s
, struct dentry
*root
)
337 struct cifs_sb_info
*cifs_sb
= CIFS_SB(root
->d_sb
);
338 struct cifs_tcon
*tcon
= cifs_sb_master_tcon(cifs_sb
);
339 struct sockaddr
*srcaddr
;
340 srcaddr
= (struct sockaddr
*)&tcon
->ses
->server
->srcaddr
;
342 seq_printf(s
, ",vers=%s", tcon
->ses
->server
->vals
->version_string
);
343 cifs_show_security(s
, tcon
->ses
->server
);
344 cifs_show_cache_flavor(s
, cifs_sb
);
346 seq_printf(s
, ",unc=%s", tcon
->treeName
);
348 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_MULTIUSER
)
349 seq_printf(s
, ",multiuser");
350 else if (tcon
->ses
->user_name
)
351 seq_printf(s
, ",username=%s", tcon
->ses
->user_name
);
353 if (tcon
->ses
->domainName
)
354 seq_printf(s
, ",domain=%s", tcon
->ses
->domainName
);
356 if (srcaddr
->sa_family
!= AF_UNSPEC
) {
357 struct sockaddr_in
*saddr4
;
358 struct sockaddr_in6
*saddr6
;
359 saddr4
= (struct sockaddr_in
*)srcaddr
;
360 saddr6
= (struct sockaddr_in6
*)srcaddr
;
361 if (srcaddr
->sa_family
== AF_INET6
)
362 seq_printf(s
, ",srcaddr=%pI6c",
364 else if (srcaddr
->sa_family
== AF_INET
)
365 seq_printf(s
, ",srcaddr=%pI4",
366 &saddr4
->sin_addr
.s_addr
);
368 seq_printf(s
, ",srcaddr=BAD-AF:%i",
369 (int)(srcaddr
->sa_family
));
372 seq_printf(s
, ",uid=%u", cifs_sb
->mnt_uid
);
373 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_OVERR_UID
)
374 seq_printf(s
, ",forceuid");
376 seq_printf(s
, ",noforceuid");
378 seq_printf(s
, ",gid=%u", cifs_sb
->mnt_gid
);
379 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_OVERR_GID
)
380 seq_printf(s
, ",forcegid");
382 seq_printf(s
, ",noforcegid");
384 cifs_show_address(s
, tcon
->ses
->server
);
387 seq_printf(s
, ",file_mode=0%ho,dir_mode=0%ho",
388 cifs_sb
->mnt_file_mode
,
389 cifs_sb
->mnt_dir_mode
);
391 seq_printf(s
, ",seal");
393 seq_printf(s
, ",nocase");
395 seq_printf(s
, ",hard");
397 seq_printf(s
, ",unix");
399 seq_printf(s
, ",nounix");
400 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_POSIX_PATHS
)
401 seq_printf(s
, ",posixpaths");
402 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_SET_UID
)
403 seq_printf(s
, ",setuids");
404 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_SERVER_INUM
)
405 seq_printf(s
, ",serverino");
406 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_RWPIDFORWARD
)
407 seq_printf(s
, ",rwpidforward");
408 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_NOPOSIXBRL
)
409 seq_printf(s
, ",forcemand");
410 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_NO_XATTR
)
411 seq_printf(s
, ",nouser_xattr");
412 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_MAP_SPECIAL_CHR
)
413 seq_printf(s
, ",mapchars");
414 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_UNX_EMUL
)
415 seq_printf(s
, ",sfu");
416 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_NO_BRL
)
417 seq_printf(s
, ",nobrl");
418 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_CIFS_ACL
)
419 seq_printf(s
, ",cifsacl");
420 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_DYNPERM
)
421 seq_printf(s
, ",dynperm");
422 if (root
->d_sb
->s_flags
& MS_POSIXACL
)
423 seq_printf(s
, ",acl");
424 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_MF_SYMLINKS
)
425 seq_printf(s
, ",mfsymlinks");
426 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_FSCACHE
)
427 seq_printf(s
, ",fsc");
428 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_NOSSYNC
)
429 seq_printf(s
, ",nostrictsync");
430 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_NO_PERM
)
431 seq_printf(s
, ",noperm");
432 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_CIFS_BACKUPUID
)
433 seq_printf(s
, ",backupuid=%u", cifs_sb
->mnt_backupuid
);
434 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_CIFS_BACKUPGID
)
435 seq_printf(s
, ",backupgid=%u", cifs_sb
->mnt_backupgid
);
437 seq_printf(s
, ",rsize=%u", cifs_sb
->rsize
);
438 seq_printf(s
, ",wsize=%u", cifs_sb
->wsize
);
439 /* convert actimeo and display it in seconds */
440 seq_printf(s
, ",actimeo=%lu", cifs_sb
->actimeo
/ HZ
);
445 static void cifs_umount_begin(struct super_block
*sb
)
447 struct cifs_sb_info
*cifs_sb
= CIFS_SB(sb
);
448 struct cifs_tcon
*tcon
;
453 tcon
= cifs_sb_master_tcon(cifs_sb
);
455 spin_lock(&cifs_tcp_ses_lock
);
456 if ((tcon
->tc_count
> 1) || (tcon
->tidStatus
== CifsExiting
)) {
457 /* we have other mounts to same share or we have
458 already tried to force umount this and woken up
459 all waiting network requests, nothing to do */
460 spin_unlock(&cifs_tcp_ses_lock
);
462 } else if (tcon
->tc_count
== 1)
463 tcon
->tidStatus
= CifsExiting
;
464 spin_unlock(&cifs_tcp_ses_lock
);
466 /* cancel_brl_requests(tcon); */ /* BB mark all brl mids as exiting */
467 /* cancel_notify_requests(tcon); */
468 if (tcon
->ses
&& tcon
->ses
->server
) {
469 cFYI(1, "wake up tasks now - umount begin not complete");
470 wake_up_all(&tcon
->ses
->server
->request_q
);
471 wake_up_all(&tcon
->ses
->server
->response_q
);
472 msleep(1); /* yield */
473 /* we have to kick the requests once more */
474 wake_up_all(&tcon
->ses
->server
->response_q
);
481 #ifdef CONFIG_CIFS_STATS2
482 static int cifs_show_stats(struct seq_file
*s
, struct dentry
*root
)
489 static int cifs_remount(struct super_block
*sb
, int *flags
, char *data
)
491 *flags
|= MS_NODIRATIME
;
495 static int cifs_drop_inode(struct inode
*inode
)
497 struct cifs_sb_info
*cifs_sb
= CIFS_SB(inode
->i_sb
);
499 /* no serverino => unconditional eviction */
500 return !(cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_SERVER_INUM
) ||
501 generic_drop_inode(inode
);
504 static const struct super_operations cifs_super_ops
= {
505 .statfs
= cifs_statfs
,
506 .alloc_inode
= cifs_alloc_inode
,
507 .destroy_inode
= cifs_destroy_inode
,
508 .drop_inode
= cifs_drop_inode
,
509 .evict_inode
= cifs_evict_inode
,
510 /* .delete_inode = cifs_delete_inode, */ /* Do not need above
511 function unless later we add lazy close of inodes or unless the
512 kernel forgets to call us with the same number of releases (closes)
514 .show_options
= cifs_show_options
,
515 .umount_begin
= cifs_umount_begin
,
516 .remount_fs
= cifs_remount
,
517 #ifdef CONFIG_CIFS_STATS2
518 .show_stats
= cifs_show_stats
,
523 * Get root dentry from superblock according to prefix path mount option.
524 * Return dentry with refcount + 1 on success and NULL otherwise.
526 static struct dentry
*
527 cifs_get_root(struct smb_vol
*vol
, struct super_block
*sb
)
529 struct dentry
*dentry
;
530 struct cifs_sb_info
*cifs_sb
= CIFS_SB(sb
);
531 char *full_path
= NULL
;
535 full_path
= build_path_to_root(vol
, cifs_sb
,
536 cifs_sb_master_tcon(cifs_sb
));
537 if (full_path
== NULL
)
538 return ERR_PTR(-ENOMEM
);
540 cFYI(1, "Get root dentry for %s", full_path
);
542 sep
= CIFS_DIR_SEP(cifs_sb
);
543 dentry
= dget(sb
->s_root
);
547 struct inode
*dir
= dentry
->d_inode
;
548 struct dentry
*child
;
552 dentry
= ERR_PTR(-ENOENT
);
556 /* skip separators */
563 while (*s
&& *s
!= sep
)
566 mutex_lock(&dir
->i_mutex
);
567 child
= lookup_one_len(p
, dentry
, s
- p
);
568 mutex_unlock(&dir
->i_mutex
);
571 } while (!IS_ERR(dentry
));
576 static int cifs_set_super(struct super_block
*sb
, void *data
)
578 struct cifs_mnt_data
*mnt_data
= data
;
579 sb
->s_fs_info
= mnt_data
->cifs_sb
;
580 return set_anon_super(sb
, NULL
);
583 static struct dentry
*
584 cifs_do_mount(struct file_system_type
*fs_type
,
585 int flags
, const char *dev_name
, void *data
)
588 struct super_block
*sb
;
589 struct cifs_sb_info
*cifs_sb
;
590 struct smb_vol
*volume_info
;
591 struct cifs_mnt_data mnt_data
;
594 cFYI(1, "Devname: %s flags: %d ", dev_name
, flags
);
596 volume_info
= cifs_get_volume_info((char *)data
, dev_name
);
597 if (IS_ERR(volume_info
))
598 return ERR_CAST(volume_info
);
600 cifs_sb
= kzalloc(sizeof(struct cifs_sb_info
), GFP_KERNEL
);
601 if (cifs_sb
== NULL
) {
602 root
= ERR_PTR(-ENOMEM
);
606 cifs_sb
->mountdata
= kstrndup(data
, PAGE_SIZE
, GFP_KERNEL
);
607 if (cifs_sb
->mountdata
== NULL
) {
608 root
= ERR_PTR(-ENOMEM
);
612 cifs_setup_cifs_sb(volume_info
, cifs_sb
);
614 rc
= cifs_mount(cifs_sb
, volume_info
);
616 if (!(flags
& MS_SILENT
))
617 cERROR(1, "cifs_mount failed w/return code = %d", rc
);
622 mnt_data
.vol
= volume_info
;
623 mnt_data
.cifs_sb
= cifs_sb
;
624 mnt_data
.flags
= flags
;
626 /* BB should we make this contingent on mount parm? */
627 flags
|= MS_NODIRATIME
| MS_NOATIME
;
629 sb
= sget(fs_type
, cifs_match_super
, cifs_set_super
, flags
, &mnt_data
);
632 cifs_umount(cifs_sb
);
637 cFYI(1, "Use existing superblock");
638 cifs_umount(cifs_sb
);
640 rc
= cifs_read_super(sb
);
646 sb
->s_flags
|= MS_ACTIVE
;
649 root
= cifs_get_root(volume_info
, sb
);
653 cFYI(1, "dentry root is: %p", root
);
657 deactivate_locked_super(sb
);
659 cifs_cleanup_volume_info(volume_info
);
663 kfree(cifs_sb
->mountdata
);
667 unload_nls(volume_info
->local_nls
);
671 static ssize_t
cifs_file_aio_write(struct kiocb
*iocb
, const struct iovec
*iov
,
672 unsigned long nr_segs
, loff_t pos
)
674 struct inode
*inode
= iocb
->ki_filp
->f_path
.dentry
->d_inode
;
678 written
= generic_file_aio_write(iocb
, iov
, nr_segs
, pos
);
680 if (CIFS_I(inode
)->clientCanCacheAll
)
683 rc
= filemap_fdatawrite(inode
->i_mapping
);
685 cFYI(1, "cifs_file_aio_write: %d rc on %p inode", rc
, inode
);
690 static loff_t
cifs_llseek(struct file
*file
, loff_t offset
, int origin
)
693 * origin == SEEK_END || SEEK_DATA || SEEK_HOLE => we must revalidate
694 * the cached file length
696 if (origin
!= SEEK_SET
&& origin
!= SEEK_CUR
) {
698 struct inode
*inode
= file
->f_path
.dentry
->d_inode
;
701 * We need to be sure that all dirty pages are written and the
702 * server has the newest file length.
704 if (!CIFS_I(inode
)->clientCanCacheRead
&& inode
->i_mapping
&&
705 inode
->i_mapping
->nrpages
!= 0) {
706 rc
= filemap_fdatawait(inode
->i_mapping
);
708 mapping_set_error(inode
->i_mapping
, rc
);
713 * Some applications poll for the file length in this strange
714 * way so we must seek to end on non-oplocked files by
715 * setting the revalidate time to zero.
717 CIFS_I(inode
)->time
= 0;
719 rc
= cifs_revalidate_file_attr(file
);
723 return generic_file_llseek(file
, offset
, origin
);
726 static int cifs_setlease(struct file
*file
, long arg
, struct file_lock
**lease
)
728 /* note that this is called by vfs setlease with lock_flocks held
729 to protect *lease from going away */
730 struct inode
*inode
= file
->f_path
.dentry
->d_inode
;
731 struct cifsFileInfo
*cfile
= file
->private_data
;
733 if (!(S_ISREG(inode
->i_mode
)))
736 /* check if file is oplocked */
737 if (((arg
== F_RDLCK
) &&
738 (CIFS_I(inode
)->clientCanCacheRead
)) ||
740 (CIFS_I(inode
)->clientCanCacheAll
)))
741 return generic_setlease(file
, arg
, lease
);
742 else if (tlink_tcon(cfile
->tlink
)->local_lease
&&
743 !CIFS_I(inode
)->clientCanCacheRead
)
744 /* If the server claims to support oplock on this
745 file, then we still need to check oplock even
746 if the local_lease mount option is set, but there
747 are servers which do not support oplock for which
748 this mount option may be useful if the user
749 knows that the file won't be changed on the server
751 return generic_setlease(file
, arg
, lease
);
756 struct file_system_type cifs_fs_type
= {
757 .owner
= THIS_MODULE
,
759 .mount
= cifs_do_mount
,
760 .kill_sb
= cifs_kill_sb
,
763 const struct inode_operations cifs_dir_inode_ops
= {
764 .create
= cifs_create
,
765 .atomic_open
= cifs_atomic_open
,
766 .lookup
= cifs_lookup
,
767 .getattr
= cifs_getattr
,
768 .unlink
= cifs_unlink
,
769 .link
= cifs_hardlink
,
772 .rename
= cifs_rename
,
773 .permission
= cifs_permission
,
774 /* revalidate:cifs_revalidate, */
775 .setattr
= cifs_setattr
,
776 .symlink
= cifs_symlink
,
778 #ifdef CONFIG_CIFS_XATTR
779 .setxattr
= cifs_setxattr
,
780 .getxattr
= cifs_getxattr
,
781 .listxattr
= cifs_listxattr
,
782 .removexattr
= cifs_removexattr
,
786 const struct inode_operations cifs_file_inode_ops
= {
787 /* revalidate:cifs_revalidate, */
788 .setattr
= cifs_setattr
,
789 .getattr
= cifs_getattr
, /* do we need this anymore? */
790 .rename
= cifs_rename
,
791 .permission
= cifs_permission
,
792 #ifdef CONFIG_CIFS_XATTR
793 .setxattr
= cifs_setxattr
,
794 .getxattr
= cifs_getxattr
,
795 .listxattr
= cifs_listxattr
,
796 .removexattr
= cifs_removexattr
,
800 const struct inode_operations cifs_symlink_inode_ops
= {
801 .readlink
= generic_readlink
,
802 .follow_link
= cifs_follow_link
,
803 .put_link
= cifs_put_link
,
804 .permission
= cifs_permission
,
805 /* BB add the following two eventually */
806 /* revalidate: cifs_revalidate,
807 setattr: cifs_notify_change, *//* BB do we need notify change */
808 #ifdef CONFIG_CIFS_XATTR
809 .setxattr
= cifs_setxattr
,
810 .getxattr
= cifs_getxattr
,
811 .listxattr
= cifs_listxattr
,
812 .removexattr
= cifs_removexattr
,
816 const struct file_operations cifs_file_ops
= {
817 .read
= do_sync_read
,
818 .write
= do_sync_write
,
819 .aio_read
= generic_file_aio_read
,
820 .aio_write
= cifs_file_aio_write
,
822 .release
= cifs_close
,
826 .mmap
= cifs_file_mmap
,
827 .splice_read
= generic_file_splice_read
,
828 .llseek
= cifs_llseek
,
829 #ifdef CONFIG_CIFS_POSIX
830 .unlocked_ioctl
= cifs_ioctl
,
831 #endif /* CONFIG_CIFS_POSIX */
832 .setlease
= cifs_setlease
,
835 const struct file_operations cifs_file_strict_ops
= {
836 .read
= do_sync_read
,
837 .write
= do_sync_write
,
838 .aio_read
= cifs_strict_readv
,
839 .aio_write
= cifs_strict_writev
,
841 .release
= cifs_close
,
843 .fsync
= cifs_strict_fsync
,
845 .mmap
= cifs_file_strict_mmap
,
846 .splice_read
= generic_file_splice_read
,
847 .llseek
= cifs_llseek
,
848 #ifdef CONFIG_CIFS_POSIX
849 .unlocked_ioctl
= cifs_ioctl
,
850 #endif /* CONFIG_CIFS_POSIX */
851 .setlease
= cifs_setlease
,
854 const struct file_operations cifs_file_direct_ops
= {
855 /* BB reevaluate whether they can be done with directio, no cache */
856 .read
= do_sync_read
,
857 .write
= do_sync_write
,
858 .aio_read
= cifs_user_readv
,
859 .aio_write
= cifs_user_writev
,
861 .release
= cifs_close
,
865 .mmap
= cifs_file_mmap
,
866 .splice_read
= generic_file_splice_read
,
867 #ifdef CONFIG_CIFS_POSIX
868 .unlocked_ioctl
= cifs_ioctl
,
869 #endif /* CONFIG_CIFS_POSIX */
870 .llseek
= cifs_llseek
,
871 .setlease
= cifs_setlease
,
874 const struct file_operations cifs_file_nobrl_ops
= {
875 .read
= do_sync_read
,
876 .write
= do_sync_write
,
877 .aio_read
= generic_file_aio_read
,
878 .aio_write
= cifs_file_aio_write
,
880 .release
= cifs_close
,
883 .mmap
= cifs_file_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_strict_nobrl_ops
= {
893 .read
= do_sync_read
,
894 .write
= do_sync_write
,
895 .aio_read
= cifs_strict_readv
,
896 .aio_write
= cifs_strict_writev
,
898 .release
= cifs_close
,
899 .fsync
= cifs_strict_fsync
,
901 .mmap
= cifs_file_strict_mmap
,
902 .splice_read
= generic_file_splice_read
,
903 .llseek
= cifs_llseek
,
904 #ifdef CONFIG_CIFS_POSIX
905 .unlocked_ioctl
= cifs_ioctl
,
906 #endif /* CONFIG_CIFS_POSIX */
907 .setlease
= cifs_setlease
,
910 const struct file_operations cifs_file_direct_nobrl_ops
= {
911 /* BB reevaluate whether they can be done with directio, no cache */
912 .read
= do_sync_read
,
913 .write
= do_sync_write
,
914 .aio_read
= cifs_user_readv
,
915 .aio_write
= cifs_user_writev
,
917 .release
= cifs_close
,
920 .mmap
= cifs_file_mmap
,
921 .splice_read
= generic_file_splice_read
,
922 #ifdef CONFIG_CIFS_POSIX
923 .unlocked_ioctl
= cifs_ioctl
,
924 #endif /* CONFIG_CIFS_POSIX */
925 .llseek
= cifs_llseek
,
926 .setlease
= cifs_setlease
,
929 const struct file_operations cifs_dir_ops
= {
930 .readdir
= cifs_readdir
,
931 .release
= cifs_closedir
,
932 .read
= generic_read_dir
,
933 .unlocked_ioctl
= cifs_ioctl
,
934 .llseek
= generic_file_llseek
,
938 cifs_init_once(void *inode
)
940 struct cifsInodeInfo
*cifsi
= inode
;
942 inode_init_once(&cifsi
->vfs_inode
);
943 mutex_init(&cifsi
->lock_mutex
);
947 cifs_init_inodecache(void)
949 cifs_inode_cachep
= kmem_cache_create("cifs_inode_cache",
950 sizeof(struct cifsInodeInfo
),
951 0, (SLAB_RECLAIM_ACCOUNT
|
954 if (cifs_inode_cachep
== NULL
)
961 cifs_destroy_inodecache(void)
963 kmem_cache_destroy(cifs_inode_cachep
);
967 cifs_init_request_bufs(void)
969 size_t max_hdr_size
= MAX_CIFS_HDR_SIZE
;
970 #ifdef CONFIG_CIFS_SMB2
972 * SMB2 maximum header size is bigger than CIFS one - no problems to
973 * allocate some more bytes for CIFS.
975 max_hdr_size
= MAX_SMB2_HDR_SIZE
;
977 if (CIFSMaxBufSize
< 8192) {
978 /* Buffer size can not be smaller than 2 * PATH_MAX since maximum
979 Unicode path name has to fit in any SMB/CIFS path based frames */
980 CIFSMaxBufSize
= 8192;
981 } else if (CIFSMaxBufSize
> 1024*127) {
982 CIFSMaxBufSize
= 1024 * 127;
984 CIFSMaxBufSize
&= 0x1FE00; /* Round size to even 512 byte mult*/
986 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
987 cifs_req_cachep
= kmem_cache_create("cifs_request",
988 CIFSMaxBufSize
+ max_hdr_size
, 0,
989 SLAB_HWCACHE_ALIGN
, NULL
);
990 if (cifs_req_cachep
== NULL
)
993 if (cifs_min_rcv
< 1)
995 else if (cifs_min_rcv
> 64) {
997 cERROR(1, "cifs_min_rcv set to maximum (64)");
1000 cifs_req_poolp
= mempool_create_slab_pool(cifs_min_rcv
,
1003 if (cifs_req_poolp
== NULL
) {
1004 kmem_cache_destroy(cifs_req_cachep
);
1007 /* MAX_CIFS_SMALL_BUFFER_SIZE bytes is enough for most SMB responses and
1008 almost all handle based requests (but not write response, nor is it
1009 sufficient for path based requests). A smaller size would have
1010 been more efficient (compacting multiple slab items on one 4k page)
1011 for the case in which debug was on, but this larger size allows
1012 more SMBs to use small buffer alloc and is still much more
1013 efficient to alloc 1 per page off the slab compared to 17K (5page)
1014 alloc of large cifs buffers even when page debugging is on */
1015 cifs_sm_req_cachep
= kmem_cache_create("cifs_small_rq",
1016 MAX_CIFS_SMALL_BUFFER_SIZE
, 0, SLAB_HWCACHE_ALIGN
,
1018 if (cifs_sm_req_cachep
== NULL
) {
1019 mempool_destroy(cifs_req_poolp
);
1020 kmem_cache_destroy(cifs_req_cachep
);
1024 if (cifs_min_small
< 2)
1026 else if (cifs_min_small
> 256) {
1027 cifs_min_small
= 256;
1028 cFYI(1, "cifs_min_small set to maximum (256)");
1031 cifs_sm_req_poolp
= mempool_create_slab_pool(cifs_min_small
,
1032 cifs_sm_req_cachep
);
1034 if (cifs_sm_req_poolp
== NULL
) {
1035 mempool_destroy(cifs_req_poolp
);
1036 kmem_cache_destroy(cifs_req_cachep
);
1037 kmem_cache_destroy(cifs_sm_req_cachep
);
1045 cifs_destroy_request_bufs(void)
1047 mempool_destroy(cifs_req_poolp
);
1048 kmem_cache_destroy(cifs_req_cachep
);
1049 mempool_destroy(cifs_sm_req_poolp
);
1050 kmem_cache_destroy(cifs_sm_req_cachep
);
1054 cifs_init_mids(void)
1056 cifs_mid_cachep
= kmem_cache_create("cifs_mpx_ids",
1057 sizeof(struct mid_q_entry
), 0,
1058 SLAB_HWCACHE_ALIGN
, NULL
);
1059 if (cifs_mid_cachep
== NULL
)
1062 /* 3 is a reasonable minimum number of simultaneous operations */
1063 cifs_mid_poolp
= mempool_create_slab_pool(3, cifs_mid_cachep
);
1064 if (cifs_mid_poolp
== NULL
) {
1065 kmem_cache_destroy(cifs_mid_cachep
);
1073 cifs_destroy_mids(void)
1075 mempool_destroy(cifs_mid_poolp
);
1076 kmem_cache_destroy(cifs_mid_cachep
);
1084 INIT_LIST_HEAD(&cifs_tcp_ses_list
);
1085 #ifdef CONFIG_CIFS_DNOTIFY_EXPERIMENTAL /* unused temporarily */
1086 INIT_LIST_HEAD(&GlobalDnotifyReqList
);
1087 INIT_LIST_HEAD(&GlobalDnotifyRsp_Q
);
1088 #endif /* was needed for dnotify, and will be needed for inotify when VFS fix */
1090 * Initialize Global counters
1092 atomic_set(&sesInfoAllocCount
, 0);
1093 atomic_set(&tconInfoAllocCount
, 0);
1094 atomic_set(&tcpSesAllocCount
, 0);
1095 atomic_set(&tcpSesReconnectCount
, 0);
1096 atomic_set(&tconInfoReconnectCount
, 0);
1098 atomic_set(&bufAllocCount
, 0);
1099 atomic_set(&smBufAllocCount
, 0);
1100 #ifdef CONFIG_CIFS_STATS2
1101 atomic_set(&totBufAllocCount
, 0);
1102 atomic_set(&totSmBufAllocCount
, 0);
1103 #endif /* CONFIG_CIFS_STATS2 */
1105 atomic_set(&midCount
, 0);
1106 GlobalCurrentXid
= 0;
1107 GlobalTotalActiveXid
= 0;
1108 GlobalMaxActiveXid
= 0;
1109 spin_lock_init(&cifs_tcp_ses_lock
);
1110 spin_lock_init(&cifs_file_list_lock
);
1111 spin_lock_init(&GlobalMid_Lock
);
1113 if (cifs_max_pending
< 2) {
1114 cifs_max_pending
= 2;
1115 cFYI(1, "cifs_max_pending set to min of 2");
1116 } else if (cifs_max_pending
> CIFS_MAX_REQ
) {
1117 cifs_max_pending
= CIFS_MAX_REQ
;
1118 cFYI(1, "cifs_max_pending set to max of %u", CIFS_MAX_REQ
);
1121 cifsiod_wq
= alloc_workqueue("cifsiod", WQ_FREEZABLE
|WQ_MEM_RECLAIM
, 0);
1124 goto out_clean_proc
;
1127 rc
= cifs_fscache_register();
1129 goto out_destroy_wq
;
1131 rc
= cifs_init_inodecache();
1133 goto out_unreg_fscache
;
1135 rc
= cifs_init_mids();
1137 goto out_destroy_inodecache
;
1139 rc
= cifs_init_request_bufs();
1141 goto out_destroy_mids
;
1143 #ifdef CONFIG_CIFS_UPCALL
1144 rc
= register_key_type(&cifs_spnego_key_type
);
1146 goto out_destroy_request_bufs
;
1147 #endif /* CONFIG_CIFS_UPCALL */
1149 #ifdef CONFIG_CIFS_ACL
1150 rc
= init_cifs_idmap();
1152 goto out_register_key_type
;
1153 #endif /* CONFIG_CIFS_ACL */
1155 rc
= register_filesystem(&cifs_fs_type
);
1157 goto out_init_cifs_idmap
;
1161 out_init_cifs_idmap
:
1162 #ifdef CONFIG_CIFS_ACL
1164 out_register_key_type
:
1166 #ifdef CONFIG_CIFS_UPCALL
1167 unregister_key_type(&cifs_spnego_key_type
);
1168 out_destroy_request_bufs
:
1170 cifs_destroy_request_bufs();
1172 cifs_destroy_mids();
1173 out_destroy_inodecache
:
1174 cifs_destroy_inodecache();
1176 cifs_fscache_unregister();
1178 destroy_workqueue(cifsiod_wq
);
1187 cFYI(DBG2
, "exit_cifs");
1188 unregister_filesystem(&cifs_fs_type
);
1189 cifs_dfs_release_automount_timer();
1190 #ifdef CONFIG_CIFS_ACL
1191 cifs_destroy_idmaptrees();
1194 #ifdef CONFIG_CIFS_UPCALL
1195 unregister_key_type(&cifs_spnego_key_type
);
1197 cifs_destroy_request_bufs();
1198 cifs_destroy_mids();
1199 cifs_destroy_inodecache();
1200 cifs_fscache_unregister();
1201 destroy_workqueue(cifsiod_wq
);
1205 MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>");
1206 MODULE_LICENSE("GPL"); /* combination of LGPL + GPL source behaves as GPL */
1208 ("VFS to access servers complying with the SNIA CIFS Specification "
1209 "e.g. Samba and Windows");
1210 MODULE_VERSION(CIFS_VERSION
);
1211 module_init(init_cifs
)
1212 module_exit(exit_cifs
)