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 cifs_read_super(struct super_block
*sb
)
95 struct cifs_sb_info
*cifs_sb
;
98 cifs_sb
= CIFS_SB(sb
);
100 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_POSIXACL
)
101 sb
->s_flags
|= MS_POSIXACL
;
103 if (cifs_sb_master_tcon(cifs_sb
)->ses
->capabilities
& CAP_LARGE_FILES
)
104 sb
->s_maxbytes
= MAX_LFS_FILESIZE
;
106 sb
->s_maxbytes
= MAX_NON_LFS
;
108 /* BB FIXME fix time_gran to be larger for LANMAN sessions */
109 sb
->s_time_gran
= 100;
111 sb
->s_magic
= CIFS_MAGIC_NUMBER
;
112 sb
->s_op
= &cifs_super_ops
;
113 sb
->s_bdi
= &cifs_sb
->bdi
;
114 sb
->s_blocksize
= CIFS_MAX_MSGSIZE
;
115 sb
->s_blocksize_bits
= 14; /* default 2**14 = CIFS_MAX_MSGSIZE */
116 inode
= cifs_root_iget(sb
);
123 sb
->s_root
= d_make_root(inode
);
129 /* do that *after* d_make_root() - we want NULL ->d_op for root here */
130 if (cifs_sb_master_tcon(cifs_sb
)->nocase
)
131 sb
->s_d_op
= &cifs_ci_dentry_ops
;
133 sb
->s_d_op
= &cifs_dentry_ops
;
135 #ifdef CONFIG_CIFS_NFSD_EXPORT
136 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_SERVER_INUM
) {
137 cFYI(1, "export ops supported");
138 sb
->s_export_op
= &cifs_export_ops
;
140 #endif /* CONFIG_CIFS_NFSD_EXPORT */
145 cERROR(1, "cifs_read_super: get root inode failed");
149 static void cifs_kill_sb(struct super_block
*sb
)
151 struct cifs_sb_info
*cifs_sb
= CIFS_SB(sb
);
153 cifs_umount(cifs_sb
);
157 cifs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
159 struct super_block
*sb
= dentry
->d_sb
;
160 struct cifs_sb_info
*cifs_sb
= CIFS_SB(sb
);
161 struct cifs_tcon
*tcon
= cifs_sb_master_tcon(cifs_sb
);
162 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
169 * PATH_MAX may be too long - it would presumably be total path,
170 * but note that some servers (includinng Samba 3) have a shorter
173 * Instead could get the real value via SMB_QUERY_FS_ATTRIBUTE_INFO.
175 buf
->f_namelen
= PATH_MAX
;
176 buf
->f_files
= 0; /* undefined */
177 buf
->f_ffree
= 0; /* unlimited */
179 if (server
->ops
->queryfs
)
180 rc
= server
->ops
->queryfs(xid
, tcon
, buf
);
186 static int cifs_permission(struct inode
*inode
, int mask
)
188 struct cifs_sb_info
*cifs_sb
;
190 cifs_sb
= CIFS_SB(inode
->i_sb
);
192 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_NO_PERM
) {
193 if ((mask
& MAY_EXEC
) && !execute_ok(inode
))
197 } else /* file mode might have been restricted at mount time
198 on the client (above and beyond ACL on servers) for
199 servers which do not support setting and viewing mode bits,
200 so allowing client to check permissions is useful */
201 return generic_permission(inode
, mask
);
204 static struct kmem_cache
*cifs_inode_cachep
;
205 static struct kmem_cache
*cifs_req_cachep
;
206 static struct kmem_cache
*cifs_mid_cachep
;
207 static struct kmem_cache
*cifs_sm_req_cachep
;
208 mempool_t
*cifs_sm_req_poolp
;
209 mempool_t
*cifs_req_poolp
;
210 mempool_t
*cifs_mid_poolp
;
212 static struct inode
*
213 cifs_alloc_inode(struct super_block
*sb
)
215 struct cifsInodeInfo
*cifs_inode
;
216 cifs_inode
= kmem_cache_alloc(cifs_inode_cachep
, GFP_KERNEL
);
219 cifs_inode
->cifsAttrs
= 0x20; /* default */
220 cifs_inode
->time
= 0;
221 /* Until the file is open and we have gotten oplock
222 info back from the server, can not assume caching of
223 file data or metadata */
224 cifs_set_oplock_level(cifs_inode
, 0);
225 cifs_inode
->delete_pending
= false;
226 cifs_inode
->invalid_mapping
= false;
227 cifs_inode
->vfs_inode
.i_blkbits
= 14; /* 2**14 = CIFS_MAX_MSGSIZE */
228 cifs_inode
->server_eof
= 0;
229 cifs_inode
->uniqueid
= 0;
230 cifs_inode
->createtime
= 0;
232 /* Can not set i_flags here - they get immediately overwritten
233 to zero by the VFS */
234 /* cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME;*/
235 INIT_LIST_HEAD(&cifs_inode
->openFileList
);
236 return &cifs_inode
->vfs_inode
;
239 static void cifs_i_callback(struct rcu_head
*head
)
241 struct inode
*inode
= container_of(head
, struct inode
, i_rcu
);
242 kmem_cache_free(cifs_inode_cachep
, CIFS_I(inode
));
246 cifs_destroy_inode(struct inode
*inode
)
248 call_rcu(&inode
->i_rcu
, cifs_i_callback
);
252 cifs_evict_inode(struct inode
*inode
)
254 truncate_inode_pages(&inode
->i_data
, 0);
256 cifs_fscache_release_inode_cookie(inode
);
260 cifs_show_address(struct seq_file
*s
, struct TCP_Server_Info
*server
)
262 struct sockaddr_in
*sa
= (struct sockaddr_in
*) &server
->dstaddr
;
263 struct sockaddr_in6
*sa6
= (struct sockaddr_in6
*) &server
->dstaddr
;
265 seq_printf(s
, ",addr=");
267 switch (server
->dstaddr
.ss_family
) {
269 seq_printf(s
, "%pI4", &sa
->sin_addr
.s_addr
);
272 seq_printf(s
, "%pI6", &sa6
->sin6_addr
.s6_addr
);
273 if (sa6
->sin6_scope_id
)
274 seq_printf(s
, "%%%u", sa6
->sin6_scope_id
);
277 seq_printf(s
, "(unknown)");
282 cifs_show_security(struct seq_file
*s
, struct TCP_Server_Info
*server
)
284 seq_printf(s
, ",sec=");
286 switch (server
->secType
) {
288 seq_printf(s
, "lanman");
291 seq_printf(s
, "ntlmv2");
294 seq_printf(s
, "ntlm");
297 seq_printf(s
, "krb5");
300 seq_printf(s
, "ntlmssp");
303 /* shouldn't ever happen */
304 seq_printf(s
, "unknown");
308 if (server
->sec_mode
& (SECMODE_SIGN_REQUIRED
| SECMODE_SIGN_ENABLED
))
313 cifs_show_cache_flavor(struct seq_file
*s
, struct cifs_sb_info
*cifs_sb
)
315 seq_printf(s
, ",cache=");
317 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_STRICT_IO
)
318 seq_printf(s
, "strict");
319 else if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_DIRECT_IO
)
320 seq_printf(s
, "none");
322 seq_printf(s
, "loose");
326 * cifs_show_options() is for displaying mount options in /proc/mounts.
327 * Not all settable options are displayed but most of the important
331 cifs_show_options(struct seq_file
*s
, struct dentry
*root
)
333 struct cifs_sb_info
*cifs_sb
= CIFS_SB(root
->d_sb
);
334 struct cifs_tcon
*tcon
= cifs_sb_master_tcon(cifs_sb
);
335 struct sockaddr
*srcaddr
;
336 srcaddr
= (struct sockaddr
*)&tcon
->ses
->server
->srcaddr
;
338 seq_printf(s
, ",vers=%s", tcon
->ses
->server
->vals
->version_string
);
339 cifs_show_security(s
, tcon
->ses
->server
);
340 cifs_show_cache_flavor(s
, cifs_sb
);
342 seq_printf(s
, ",unc=%s", tcon
->treeName
);
344 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_MULTIUSER
)
345 seq_printf(s
, ",multiuser");
346 else if (tcon
->ses
->user_name
)
347 seq_printf(s
, ",username=%s", tcon
->ses
->user_name
);
349 if (tcon
->ses
->domainName
)
350 seq_printf(s
, ",domain=%s", tcon
->ses
->domainName
);
352 if (srcaddr
->sa_family
!= AF_UNSPEC
) {
353 struct sockaddr_in
*saddr4
;
354 struct sockaddr_in6
*saddr6
;
355 saddr4
= (struct sockaddr_in
*)srcaddr
;
356 saddr6
= (struct sockaddr_in6
*)srcaddr
;
357 if (srcaddr
->sa_family
== AF_INET6
)
358 seq_printf(s
, ",srcaddr=%pI6c",
360 else if (srcaddr
->sa_family
== AF_INET
)
361 seq_printf(s
, ",srcaddr=%pI4",
362 &saddr4
->sin_addr
.s_addr
);
364 seq_printf(s
, ",srcaddr=BAD-AF:%i",
365 (int)(srcaddr
->sa_family
));
368 seq_printf(s
, ",uid=%u", cifs_sb
->mnt_uid
);
369 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_OVERR_UID
)
370 seq_printf(s
, ",forceuid");
372 seq_printf(s
, ",noforceuid");
374 seq_printf(s
, ",gid=%u", cifs_sb
->mnt_gid
);
375 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_OVERR_GID
)
376 seq_printf(s
, ",forcegid");
378 seq_printf(s
, ",noforcegid");
380 cifs_show_address(s
, tcon
->ses
->server
);
383 seq_printf(s
, ",file_mode=0%ho,dir_mode=0%ho",
384 cifs_sb
->mnt_file_mode
,
385 cifs_sb
->mnt_dir_mode
);
387 seq_printf(s
, ",seal");
389 seq_printf(s
, ",nocase");
391 seq_printf(s
, ",hard");
393 seq_printf(s
, ",unix");
395 seq_printf(s
, ",nounix");
396 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_POSIX_PATHS
)
397 seq_printf(s
, ",posixpaths");
398 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_SET_UID
)
399 seq_printf(s
, ",setuids");
400 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_SERVER_INUM
)
401 seq_printf(s
, ",serverino");
402 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_RWPIDFORWARD
)
403 seq_printf(s
, ",rwpidforward");
404 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_NOPOSIXBRL
)
405 seq_printf(s
, ",forcemand");
406 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_NO_XATTR
)
407 seq_printf(s
, ",nouser_xattr");
408 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_MAP_SPECIAL_CHR
)
409 seq_printf(s
, ",mapchars");
410 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_UNX_EMUL
)
411 seq_printf(s
, ",sfu");
412 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_NO_BRL
)
413 seq_printf(s
, ",nobrl");
414 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_CIFS_ACL
)
415 seq_printf(s
, ",cifsacl");
416 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_DYNPERM
)
417 seq_printf(s
, ",dynperm");
418 if (root
->d_sb
->s_flags
& MS_POSIXACL
)
419 seq_printf(s
, ",acl");
420 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_MF_SYMLINKS
)
421 seq_printf(s
, ",mfsymlinks");
422 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_FSCACHE
)
423 seq_printf(s
, ",fsc");
424 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_NOSSYNC
)
425 seq_printf(s
, ",nostrictsync");
426 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_NO_PERM
)
427 seq_printf(s
, ",noperm");
428 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_CIFS_BACKUPUID
)
429 seq_printf(s
, ",backupuid=%u", cifs_sb
->mnt_backupuid
);
430 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_CIFS_BACKUPGID
)
431 seq_printf(s
, ",backupgid=%u", cifs_sb
->mnt_backupgid
);
433 seq_printf(s
, ",rsize=%u", cifs_sb
->rsize
);
434 seq_printf(s
, ",wsize=%u", cifs_sb
->wsize
);
435 /* convert actimeo and display it in seconds */
436 seq_printf(s
, ",actimeo=%lu", cifs_sb
->actimeo
/ HZ
);
441 static void cifs_umount_begin(struct super_block
*sb
)
443 struct cifs_sb_info
*cifs_sb
= CIFS_SB(sb
);
444 struct cifs_tcon
*tcon
;
449 tcon
= cifs_sb_master_tcon(cifs_sb
);
451 spin_lock(&cifs_tcp_ses_lock
);
452 if ((tcon
->tc_count
> 1) || (tcon
->tidStatus
== CifsExiting
)) {
453 /* we have other mounts to same share or we have
454 already tried to force umount this and woken up
455 all waiting network requests, nothing to do */
456 spin_unlock(&cifs_tcp_ses_lock
);
458 } else if (tcon
->tc_count
== 1)
459 tcon
->tidStatus
= CifsExiting
;
460 spin_unlock(&cifs_tcp_ses_lock
);
462 /* cancel_brl_requests(tcon); */ /* BB mark all brl mids as exiting */
463 /* cancel_notify_requests(tcon); */
464 if (tcon
->ses
&& tcon
->ses
->server
) {
465 cFYI(1, "wake up tasks now - umount begin not complete");
466 wake_up_all(&tcon
->ses
->server
->request_q
);
467 wake_up_all(&tcon
->ses
->server
->response_q
);
468 msleep(1); /* yield */
469 /* we have to kick the requests once more */
470 wake_up_all(&tcon
->ses
->server
->response_q
);
477 #ifdef CONFIG_CIFS_STATS2
478 static int cifs_show_stats(struct seq_file
*s
, struct dentry
*root
)
485 static int cifs_remount(struct super_block
*sb
, int *flags
, char *data
)
487 *flags
|= MS_NODIRATIME
;
491 static int cifs_drop_inode(struct inode
*inode
)
493 struct cifs_sb_info
*cifs_sb
= CIFS_SB(inode
->i_sb
);
495 /* no serverino => unconditional eviction */
496 return !(cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_SERVER_INUM
) ||
497 generic_drop_inode(inode
);
500 static const struct super_operations cifs_super_ops
= {
501 .statfs
= cifs_statfs
,
502 .alloc_inode
= cifs_alloc_inode
,
503 .destroy_inode
= cifs_destroy_inode
,
504 .drop_inode
= cifs_drop_inode
,
505 .evict_inode
= cifs_evict_inode
,
506 /* .delete_inode = cifs_delete_inode, */ /* Do not need above
507 function unless later we add lazy close of inodes or unless the
508 kernel forgets to call us with the same number of releases (closes)
510 .show_options
= cifs_show_options
,
511 .umount_begin
= cifs_umount_begin
,
512 .remount_fs
= cifs_remount
,
513 #ifdef CONFIG_CIFS_STATS2
514 .show_stats
= cifs_show_stats
,
519 * Get root dentry from superblock according to prefix path mount option.
520 * Return dentry with refcount + 1 on success and NULL otherwise.
522 static struct dentry
*
523 cifs_get_root(struct smb_vol
*vol
, struct super_block
*sb
)
525 struct dentry
*dentry
;
526 struct cifs_sb_info
*cifs_sb
= CIFS_SB(sb
);
527 char *full_path
= NULL
;
531 full_path
= build_path_to_root(vol
, cifs_sb
,
532 cifs_sb_master_tcon(cifs_sb
));
533 if (full_path
== NULL
)
534 return ERR_PTR(-ENOMEM
);
536 cFYI(1, "Get root dentry for %s", full_path
);
538 sep
= CIFS_DIR_SEP(cifs_sb
);
539 dentry
= dget(sb
->s_root
);
543 struct inode
*dir
= dentry
->d_inode
;
544 struct dentry
*child
;
548 dentry
= ERR_PTR(-ENOENT
);
552 /* skip separators */
559 while (*s
&& *s
!= sep
)
562 mutex_lock(&dir
->i_mutex
);
563 child
= lookup_one_len(p
, dentry
, s
- p
);
564 mutex_unlock(&dir
->i_mutex
);
567 } while (!IS_ERR(dentry
));
572 static int cifs_set_super(struct super_block
*sb
, void *data
)
574 struct cifs_mnt_data
*mnt_data
= data
;
575 sb
->s_fs_info
= mnt_data
->cifs_sb
;
576 return set_anon_super(sb
, NULL
);
579 static struct dentry
*
580 cifs_do_mount(struct file_system_type
*fs_type
,
581 int flags
, const char *dev_name
, void *data
)
584 struct super_block
*sb
;
585 struct cifs_sb_info
*cifs_sb
;
586 struct smb_vol
*volume_info
;
587 struct cifs_mnt_data mnt_data
;
590 cFYI(1, "Devname: %s flags: %d ", dev_name
, flags
);
592 volume_info
= cifs_get_volume_info((char *)data
, dev_name
);
593 if (IS_ERR(volume_info
))
594 return ERR_CAST(volume_info
);
596 cifs_sb
= kzalloc(sizeof(struct cifs_sb_info
), GFP_KERNEL
);
597 if (cifs_sb
== NULL
) {
598 root
= ERR_PTR(-ENOMEM
);
602 cifs_sb
->mountdata
= kstrndup(data
, PAGE_SIZE
, GFP_KERNEL
);
603 if (cifs_sb
->mountdata
== NULL
) {
604 root
= ERR_PTR(-ENOMEM
);
608 cifs_setup_cifs_sb(volume_info
, cifs_sb
);
610 rc
= cifs_mount(cifs_sb
, volume_info
);
612 if (!(flags
& MS_SILENT
))
613 cERROR(1, "cifs_mount failed w/return code = %d", rc
);
618 mnt_data
.vol
= volume_info
;
619 mnt_data
.cifs_sb
= cifs_sb
;
620 mnt_data
.flags
= flags
;
622 /* BB should we make this contingent on mount parm? */
623 flags
|= MS_NODIRATIME
| MS_NOATIME
;
625 sb
= sget(fs_type
, cifs_match_super
, cifs_set_super
, flags
, &mnt_data
);
628 cifs_umount(cifs_sb
);
633 cFYI(1, "Use existing superblock");
634 cifs_umount(cifs_sb
);
636 rc
= cifs_read_super(sb
);
642 sb
->s_flags
|= MS_ACTIVE
;
645 root
= cifs_get_root(volume_info
, sb
);
649 cFYI(1, "dentry root is: %p", root
);
653 deactivate_locked_super(sb
);
655 cifs_cleanup_volume_info(volume_info
);
659 kfree(cifs_sb
->mountdata
);
663 unload_nls(volume_info
->local_nls
);
667 static ssize_t
cifs_file_aio_write(struct kiocb
*iocb
, const struct iovec
*iov
,
668 unsigned long nr_segs
, loff_t pos
)
670 struct inode
*inode
= iocb
->ki_filp
->f_path
.dentry
->d_inode
;
674 written
= generic_file_aio_write(iocb
, iov
, nr_segs
, pos
);
676 if (CIFS_I(inode
)->clientCanCacheAll
)
679 rc
= filemap_fdatawrite(inode
->i_mapping
);
681 cFYI(1, "cifs_file_aio_write: %d rc on %p inode", rc
, inode
);
686 static loff_t
cifs_llseek(struct file
*file
, loff_t offset
, int origin
)
689 * origin == SEEK_END || SEEK_DATA || SEEK_HOLE => we must revalidate
690 * the cached file length
692 if (origin
!= SEEK_SET
&& origin
!= SEEK_CUR
) {
694 struct inode
*inode
= file
->f_path
.dentry
->d_inode
;
697 * We need to be sure that all dirty pages are written and the
698 * server has the newest file length.
700 if (!CIFS_I(inode
)->clientCanCacheRead
&& inode
->i_mapping
&&
701 inode
->i_mapping
->nrpages
!= 0) {
702 rc
= filemap_fdatawait(inode
->i_mapping
);
704 mapping_set_error(inode
->i_mapping
, rc
);
709 * Some applications poll for the file length in this strange
710 * way so we must seek to end on non-oplocked files by
711 * setting the revalidate time to zero.
713 CIFS_I(inode
)->time
= 0;
715 rc
= cifs_revalidate_file_attr(file
);
719 return generic_file_llseek(file
, offset
, origin
);
722 static int cifs_setlease(struct file
*file
, long arg
, struct file_lock
**lease
)
724 /* note that this is called by vfs setlease with lock_flocks held
725 to protect *lease from going away */
726 struct inode
*inode
= file
->f_path
.dentry
->d_inode
;
727 struct cifsFileInfo
*cfile
= file
->private_data
;
729 if (!(S_ISREG(inode
->i_mode
)))
732 /* check if file is oplocked */
733 if (((arg
== F_RDLCK
) &&
734 (CIFS_I(inode
)->clientCanCacheRead
)) ||
736 (CIFS_I(inode
)->clientCanCacheAll
)))
737 return generic_setlease(file
, arg
, lease
);
738 else if (tlink_tcon(cfile
->tlink
)->local_lease
&&
739 !CIFS_I(inode
)->clientCanCacheRead
)
740 /* If the server claims to support oplock on this
741 file, then we still need to check oplock even
742 if the local_lease mount option is set, but there
743 are servers which do not support oplock for which
744 this mount option may be useful if the user
745 knows that the file won't be changed on the server
747 return generic_setlease(file
, arg
, lease
);
752 struct file_system_type cifs_fs_type
= {
753 .owner
= THIS_MODULE
,
755 .mount
= cifs_do_mount
,
756 .kill_sb
= cifs_kill_sb
,
759 const struct inode_operations cifs_dir_inode_ops
= {
760 .create
= cifs_create
,
761 .atomic_open
= cifs_atomic_open
,
762 .lookup
= cifs_lookup
,
763 .getattr
= cifs_getattr
,
764 .unlink
= cifs_unlink
,
765 .link
= cifs_hardlink
,
768 .rename
= cifs_rename
,
769 .permission
= cifs_permission
,
770 /* revalidate:cifs_revalidate, */
771 .setattr
= cifs_setattr
,
772 .symlink
= cifs_symlink
,
774 #ifdef CONFIG_CIFS_XATTR
775 .setxattr
= cifs_setxattr
,
776 .getxattr
= cifs_getxattr
,
777 .listxattr
= cifs_listxattr
,
778 .removexattr
= cifs_removexattr
,
782 const struct inode_operations cifs_file_inode_ops
= {
783 /* revalidate:cifs_revalidate, */
784 .setattr
= cifs_setattr
,
785 .getattr
= cifs_getattr
, /* do we need this anymore? */
786 .rename
= cifs_rename
,
787 .permission
= cifs_permission
,
788 #ifdef CONFIG_CIFS_XATTR
789 .setxattr
= cifs_setxattr
,
790 .getxattr
= cifs_getxattr
,
791 .listxattr
= cifs_listxattr
,
792 .removexattr
= cifs_removexattr
,
796 const struct inode_operations cifs_symlink_inode_ops
= {
797 .readlink
= generic_readlink
,
798 .follow_link
= cifs_follow_link
,
799 .put_link
= cifs_put_link
,
800 .permission
= cifs_permission
,
801 /* BB add the following two eventually */
802 /* revalidate: cifs_revalidate,
803 setattr: cifs_notify_change, *//* BB do we need notify change */
804 #ifdef CONFIG_CIFS_XATTR
805 .setxattr
= cifs_setxattr
,
806 .getxattr
= cifs_getxattr
,
807 .listxattr
= cifs_listxattr
,
808 .removexattr
= cifs_removexattr
,
812 const struct file_operations cifs_file_ops
= {
813 .read
= do_sync_read
,
814 .write
= do_sync_write
,
815 .aio_read
= generic_file_aio_read
,
816 .aio_write
= cifs_file_aio_write
,
818 .release
= cifs_close
,
822 .mmap
= cifs_file_mmap
,
823 .splice_read
= generic_file_splice_read
,
824 .llseek
= cifs_llseek
,
825 #ifdef CONFIG_CIFS_POSIX
826 .unlocked_ioctl
= cifs_ioctl
,
827 #endif /* CONFIG_CIFS_POSIX */
828 .setlease
= cifs_setlease
,
831 const struct file_operations cifs_file_strict_ops
= {
832 .read
= do_sync_read
,
833 .write
= do_sync_write
,
834 .aio_read
= cifs_strict_readv
,
835 .aio_write
= cifs_strict_writev
,
837 .release
= cifs_close
,
839 .fsync
= cifs_strict_fsync
,
841 .mmap
= cifs_file_strict_mmap
,
842 .splice_read
= generic_file_splice_read
,
843 .llseek
= cifs_llseek
,
844 #ifdef CONFIG_CIFS_POSIX
845 .unlocked_ioctl
= cifs_ioctl
,
846 #endif /* CONFIG_CIFS_POSIX */
847 .setlease
= cifs_setlease
,
850 const struct file_operations cifs_file_direct_ops
= {
851 /* BB reevaluate whether they can be done with directio, no cache */
852 .read
= do_sync_read
,
853 .write
= do_sync_write
,
854 .aio_read
= cifs_user_readv
,
855 .aio_write
= cifs_user_writev
,
857 .release
= cifs_close
,
861 .mmap
= cifs_file_mmap
,
862 .splice_read
= generic_file_splice_read
,
863 #ifdef CONFIG_CIFS_POSIX
864 .unlocked_ioctl
= cifs_ioctl
,
865 #endif /* CONFIG_CIFS_POSIX */
866 .llseek
= cifs_llseek
,
867 .setlease
= cifs_setlease
,
870 const struct file_operations cifs_file_nobrl_ops
= {
871 .read
= do_sync_read
,
872 .write
= do_sync_write
,
873 .aio_read
= generic_file_aio_read
,
874 .aio_write
= cifs_file_aio_write
,
876 .release
= cifs_close
,
879 .mmap
= cifs_file_mmap
,
880 .splice_read
= generic_file_splice_read
,
881 .llseek
= cifs_llseek
,
882 #ifdef CONFIG_CIFS_POSIX
883 .unlocked_ioctl
= cifs_ioctl
,
884 #endif /* CONFIG_CIFS_POSIX */
885 .setlease
= cifs_setlease
,
888 const struct file_operations cifs_file_strict_nobrl_ops
= {
889 .read
= do_sync_read
,
890 .write
= do_sync_write
,
891 .aio_read
= cifs_strict_readv
,
892 .aio_write
= cifs_strict_writev
,
894 .release
= cifs_close
,
895 .fsync
= cifs_strict_fsync
,
897 .mmap
= cifs_file_strict_mmap
,
898 .splice_read
= generic_file_splice_read
,
899 .llseek
= cifs_llseek
,
900 #ifdef CONFIG_CIFS_POSIX
901 .unlocked_ioctl
= cifs_ioctl
,
902 #endif /* CONFIG_CIFS_POSIX */
903 .setlease
= cifs_setlease
,
906 const struct file_operations cifs_file_direct_nobrl_ops
= {
907 /* BB reevaluate whether they can be done with directio, no cache */
908 .read
= do_sync_read
,
909 .write
= do_sync_write
,
910 .aio_read
= cifs_user_readv
,
911 .aio_write
= cifs_user_writev
,
913 .release
= cifs_close
,
916 .mmap
= cifs_file_mmap
,
917 .splice_read
= generic_file_splice_read
,
918 #ifdef CONFIG_CIFS_POSIX
919 .unlocked_ioctl
= cifs_ioctl
,
920 #endif /* CONFIG_CIFS_POSIX */
921 .llseek
= cifs_llseek
,
922 .setlease
= cifs_setlease
,
925 const struct file_operations cifs_dir_ops
= {
926 .readdir
= cifs_readdir
,
927 .release
= cifs_closedir
,
928 .read
= generic_read_dir
,
929 .unlocked_ioctl
= cifs_ioctl
,
930 .llseek
= generic_file_llseek
,
934 cifs_init_once(void *inode
)
936 struct cifsInodeInfo
*cifsi
= inode
;
938 inode_init_once(&cifsi
->vfs_inode
);
939 mutex_init(&cifsi
->lock_mutex
);
943 cifs_init_inodecache(void)
945 cifs_inode_cachep
= kmem_cache_create("cifs_inode_cache",
946 sizeof(struct cifsInodeInfo
),
947 0, (SLAB_RECLAIM_ACCOUNT
|
950 if (cifs_inode_cachep
== NULL
)
957 cifs_destroy_inodecache(void)
959 kmem_cache_destroy(cifs_inode_cachep
);
963 cifs_init_request_bufs(void)
965 size_t max_hdr_size
= MAX_CIFS_HDR_SIZE
;
966 #ifdef CONFIG_CIFS_SMB2
968 * SMB2 maximum header size is bigger than CIFS one - no problems to
969 * allocate some more bytes for CIFS.
971 max_hdr_size
= MAX_SMB2_HDR_SIZE
;
973 if (CIFSMaxBufSize
< 8192) {
974 /* Buffer size can not be smaller than 2 * PATH_MAX since maximum
975 Unicode path name has to fit in any SMB/CIFS path based frames */
976 CIFSMaxBufSize
= 8192;
977 } else if (CIFSMaxBufSize
> 1024*127) {
978 CIFSMaxBufSize
= 1024 * 127;
980 CIFSMaxBufSize
&= 0x1FE00; /* Round size to even 512 byte mult*/
982 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
983 cifs_req_cachep
= kmem_cache_create("cifs_request",
984 CIFSMaxBufSize
+ max_hdr_size
, 0,
985 SLAB_HWCACHE_ALIGN
, NULL
);
986 if (cifs_req_cachep
== NULL
)
989 if (cifs_min_rcv
< 1)
991 else if (cifs_min_rcv
> 64) {
993 cERROR(1, "cifs_min_rcv set to maximum (64)");
996 cifs_req_poolp
= mempool_create_slab_pool(cifs_min_rcv
,
999 if (cifs_req_poolp
== NULL
) {
1000 kmem_cache_destroy(cifs_req_cachep
);
1003 /* MAX_CIFS_SMALL_BUFFER_SIZE bytes is enough for most SMB responses and
1004 almost all handle based requests (but not write response, nor is it
1005 sufficient for path based requests). A smaller size would have
1006 been more efficient (compacting multiple slab items on one 4k page)
1007 for the case in which debug was on, but this larger size allows
1008 more SMBs to use small buffer alloc and is still much more
1009 efficient to alloc 1 per page off the slab compared to 17K (5page)
1010 alloc of large cifs buffers even when page debugging is on */
1011 cifs_sm_req_cachep
= kmem_cache_create("cifs_small_rq",
1012 MAX_CIFS_SMALL_BUFFER_SIZE
, 0, SLAB_HWCACHE_ALIGN
,
1014 if (cifs_sm_req_cachep
== NULL
) {
1015 mempool_destroy(cifs_req_poolp
);
1016 kmem_cache_destroy(cifs_req_cachep
);
1020 if (cifs_min_small
< 2)
1022 else if (cifs_min_small
> 256) {
1023 cifs_min_small
= 256;
1024 cFYI(1, "cifs_min_small set to maximum (256)");
1027 cifs_sm_req_poolp
= mempool_create_slab_pool(cifs_min_small
,
1028 cifs_sm_req_cachep
);
1030 if (cifs_sm_req_poolp
== NULL
) {
1031 mempool_destroy(cifs_req_poolp
);
1032 kmem_cache_destroy(cifs_req_cachep
);
1033 kmem_cache_destroy(cifs_sm_req_cachep
);
1041 cifs_destroy_request_bufs(void)
1043 mempool_destroy(cifs_req_poolp
);
1044 kmem_cache_destroy(cifs_req_cachep
);
1045 mempool_destroy(cifs_sm_req_poolp
);
1046 kmem_cache_destroy(cifs_sm_req_cachep
);
1050 cifs_init_mids(void)
1052 cifs_mid_cachep
= kmem_cache_create("cifs_mpx_ids",
1053 sizeof(struct mid_q_entry
), 0,
1054 SLAB_HWCACHE_ALIGN
, NULL
);
1055 if (cifs_mid_cachep
== NULL
)
1058 /* 3 is a reasonable minimum number of simultaneous operations */
1059 cifs_mid_poolp
= mempool_create_slab_pool(3, cifs_mid_cachep
);
1060 if (cifs_mid_poolp
== NULL
) {
1061 kmem_cache_destroy(cifs_mid_cachep
);
1069 cifs_destroy_mids(void)
1071 mempool_destroy(cifs_mid_poolp
);
1072 kmem_cache_destroy(cifs_mid_cachep
);
1080 INIT_LIST_HEAD(&cifs_tcp_ses_list
);
1081 #ifdef CONFIG_CIFS_DNOTIFY_EXPERIMENTAL /* unused temporarily */
1082 INIT_LIST_HEAD(&GlobalDnotifyReqList
);
1083 INIT_LIST_HEAD(&GlobalDnotifyRsp_Q
);
1084 #endif /* was needed for dnotify, and will be needed for inotify when VFS fix */
1086 * Initialize Global counters
1088 atomic_set(&sesInfoAllocCount
, 0);
1089 atomic_set(&tconInfoAllocCount
, 0);
1090 atomic_set(&tcpSesAllocCount
, 0);
1091 atomic_set(&tcpSesReconnectCount
, 0);
1092 atomic_set(&tconInfoReconnectCount
, 0);
1094 atomic_set(&bufAllocCount
, 0);
1095 atomic_set(&smBufAllocCount
, 0);
1096 #ifdef CONFIG_CIFS_STATS2
1097 atomic_set(&totBufAllocCount
, 0);
1098 atomic_set(&totSmBufAllocCount
, 0);
1099 #endif /* CONFIG_CIFS_STATS2 */
1101 atomic_set(&midCount
, 0);
1102 GlobalCurrentXid
= 0;
1103 GlobalTotalActiveXid
= 0;
1104 GlobalMaxActiveXid
= 0;
1105 spin_lock_init(&cifs_tcp_ses_lock
);
1106 spin_lock_init(&cifs_file_list_lock
);
1107 spin_lock_init(&GlobalMid_Lock
);
1109 if (cifs_max_pending
< 2) {
1110 cifs_max_pending
= 2;
1111 cFYI(1, "cifs_max_pending set to min of 2");
1112 } else if (cifs_max_pending
> CIFS_MAX_REQ
) {
1113 cifs_max_pending
= CIFS_MAX_REQ
;
1114 cFYI(1, "cifs_max_pending set to max of %u", CIFS_MAX_REQ
);
1117 cifsiod_wq
= alloc_workqueue("cifsiod", WQ_FREEZABLE
|WQ_MEM_RECLAIM
, 0);
1120 goto out_clean_proc
;
1123 rc
= cifs_fscache_register();
1125 goto out_destroy_wq
;
1127 rc
= cifs_init_inodecache();
1129 goto out_unreg_fscache
;
1131 rc
= cifs_init_mids();
1133 goto out_destroy_inodecache
;
1135 rc
= cifs_init_request_bufs();
1137 goto out_destroy_mids
;
1139 #ifdef CONFIG_CIFS_UPCALL
1140 rc
= register_key_type(&cifs_spnego_key_type
);
1142 goto out_destroy_request_bufs
;
1143 #endif /* CONFIG_CIFS_UPCALL */
1145 #ifdef CONFIG_CIFS_ACL
1146 rc
= init_cifs_idmap();
1148 goto out_register_key_type
;
1149 #endif /* CONFIG_CIFS_ACL */
1151 rc
= register_filesystem(&cifs_fs_type
);
1153 goto out_init_cifs_idmap
;
1157 out_init_cifs_idmap
:
1158 #ifdef CONFIG_CIFS_ACL
1160 out_register_key_type
:
1162 #ifdef CONFIG_CIFS_UPCALL
1163 unregister_key_type(&cifs_spnego_key_type
);
1164 out_destroy_request_bufs
:
1166 cifs_destroy_request_bufs();
1168 cifs_destroy_mids();
1169 out_destroy_inodecache
:
1170 cifs_destroy_inodecache();
1172 cifs_fscache_unregister();
1174 destroy_workqueue(cifsiod_wq
);
1183 cFYI(DBG2
, "exit_cifs");
1184 unregister_filesystem(&cifs_fs_type
);
1185 cifs_dfs_release_automount_timer();
1186 #ifdef CONFIG_CIFS_ACL
1187 cifs_destroy_idmaptrees();
1190 #ifdef CONFIG_CIFS_UPCALL
1191 unregister_key_type(&cifs_spnego_key_type
);
1193 cifs_destroy_request_bufs();
1194 cifs_destroy_mids();
1195 cifs_destroy_inodecache();
1196 cifs_fscache_unregister();
1197 destroy_workqueue(cifsiod_wq
);
1201 MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>");
1202 MODULE_LICENSE("GPL"); /* combination of LGPL + GPL source behaves as GPL */
1204 ("VFS to access servers complying with the SNIA CIFS Specification "
1205 "e.g. Samba and Windows");
1206 MODULE_VERSION(CIFS_VERSION
);
1207 module_init(init_cifs
)
1208 module_exit(exit_cifs
)