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>
39 #include <linux/random.h>
43 #define DECLARE_GLOBALS_HERE
45 #include "cifsproto.h"
46 #include "cifs_debug.h"
47 #include "cifs_fs_sb.h"
49 #include <linux/key-type.h>
50 #include "cifs_spnego.h"
52 #ifdef CONFIG_CIFS_SMB2
59 bool enable_oplocks
= true;
60 unsigned int linuxExtEnabled
= 1;
61 unsigned int lookupCacheEnabled
= 1;
62 unsigned int global_secflags
= CIFSSEC_DEF
;
63 /* unsigned int ntlmv2_support = 0; */
64 unsigned int sign_CIFS_PDUs
= 1;
65 static const struct super_operations cifs_super_ops
;
66 unsigned int CIFSMaxBufSize
= CIFS_MAX_MSGSIZE
;
67 module_param(CIFSMaxBufSize
, uint
, 0);
68 MODULE_PARM_DESC(CIFSMaxBufSize
, "Network buffer size (not including header). "
69 "Default: 16384 Range: 8192 to 130048");
70 unsigned int cifs_min_rcv
= CIFS_MIN_RCV_POOL
;
71 module_param(cifs_min_rcv
, uint
, 0);
72 MODULE_PARM_DESC(cifs_min_rcv
, "Network buffers in pool. Default: 4 Range: "
74 unsigned int cifs_min_small
= 30;
75 module_param(cifs_min_small
, uint
, 0);
76 MODULE_PARM_DESC(cifs_min_small
, "Small network buffers in pool. Default: 30 "
78 unsigned int cifs_max_pending
= CIFS_MAX_REQ
;
79 module_param(cifs_max_pending
, uint
, 0444);
80 MODULE_PARM_DESC(cifs_max_pending
, "Simultaneous requests to server. "
81 "Default: 32767 Range: 2 to 32767.");
82 module_param(enable_oplocks
, bool, 0644);
83 MODULE_PARM_DESC(enable_oplocks
, "Enable or disable oplocks. Default: y/Y/1");
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
;
91 #ifdef CONFIG_CIFS_SMB2
92 __u8 cifs_client_guid
[SMB2_CLIENT_GUID_SIZE
];
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;
226 * Until the file is open and we have gotten oplock info back from the
227 * server, can not assume caching of file data or metadata.
229 cifs_set_oplock_level(cifs_inode
, 0);
230 cifs_inode
->delete_pending
= false;
231 cifs_inode
->invalid_mapping
= false;
232 cifs_inode
->vfs_inode
.i_blkbits
= 14; /* 2**14 = CIFS_MAX_MSGSIZE */
233 cifs_inode
->server_eof
= 0;
234 cifs_inode
->uniqueid
= 0;
235 cifs_inode
->createtime
= 0;
236 #ifdef CONFIG_CIFS_SMB2
237 get_random_bytes(cifs_inode
->lease_key
, SMB2_LEASE_KEY_SIZE
);
240 * Can not set i_flags here - they get immediately overwritten to zero
243 /* cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME; */
244 INIT_LIST_HEAD(&cifs_inode
->openFileList
);
245 INIT_LIST_HEAD(&cifs_inode
->llist
);
246 return &cifs_inode
->vfs_inode
;
249 static void cifs_i_callback(struct rcu_head
*head
)
251 struct inode
*inode
= container_of(head
, struct inode
, i_rcu
);
252 kmem_cache_free(cifs_inode_cachep
, CIFS_I(inode
));
256 cifs_destroy_inode(struct inode
*inode
)
258 call_rcu(&inode
->i_rcu
, cifs_i_callback
);
262 cifs_evict_inode(struct inode
*inode
)
264 truncate_inode_pages(&inode
->i_data
, 0);
266 cifs_fscache_release_inode_cookie(inode
);
270 cifs_show_address(struct seq_file
*s
, struct TCP_Server_Info
*server
)
272 struct sockaddr_in
*sa
= (struct sockaddr_in
*) &server
->dstaddr
;
273 struct sockaddr_in6
*sa6
= (struct sockaddr_in6
*) &server
->dstaddr
;
275 seq_printf(s
, ",addr=");
277 switch (server
->dstaddr
.ss_family
) {
279 seq_printf(s
, "%pI4", &sa
->sin_addr
.s_addr
);
282 seq_printf(s
, "%pI6", &sa6
->sin6_addr
.s6_addr
);
283 if (sa6
->sin6_scope_id
)
284 seq_printf(s
, "%%%u", sa6
->sin6_scope_id
);
287 seq_printf(s
, "(unknown)");
292 cifs_show_security(struct seq_file
*s
, struct TCP_Server_Info
*server
)
294 seq_printf(s
, ",sec=");
296 switch (server
->secType
) {
298 seq_printf(s
, "lanman");
301 seq_printf(s
, "ntlmv2");
304 seq_printf(s
, "ntlm");
307 seq_printf(s
, "krb5");
310 seq_printf(s
, "ntlmssp");
313 /* shouldn't ever happen */
314 seq_printf(s
, "unknown");
318 if (server
->sec_mode
& (SECMODE_SIGN_REQUIRED
| SECMODE_SIGN_ENABLED
))
323 cifs_show_cache_flavor(struct seq_file
*s
, struct cifs_sb_info
*cifs_sb
)
325 seq_printf(s
, ",cache=");
327 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_STRICT_IO
)
328 seq_printf(s
, "strict");
329 else if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_DIRECT_IO
)
330 seq_printf(s
, "none");
332 seq_printf(s
, "loose");
336 * cifs_show_options() is for displaying mount options in /proc/mounts.
337 * Not all settable options are displayed but most of the important
341 cifs_show_options(struct seq_file
*s
, struct dentry
*root
)
343 struct cifs_sb_info
*cifs_sb
= CIFS_SB(root
->d_sb
);
344 struct cifs_tcon
*tcon
= cifs_sb_master_tcon(cifs_sb
);
345 struct sockaddr
*srcaddr
;
346 srcaddr
= (struct sockaddr
*)&tcon
->ses
->server
->srcaddr
;
348 seq_printf(s
, ",vers=%s", tcon
->ses
->server
->vals
->version_string
);
349 cifs_show_security(s
, tcon
->ses
->server
);
350 cifs_show_cache_flavor(s
, cifs_sb
);
352 seq_printf(s
, ",unc=");
353 seq_escape(s
, tcon
->treeName
, " \t\n\\");
355 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_MULTIUSER
)
356 seq_printf(s
, ",multiuser");
357 else if (tcon
->ses
->user_name
)
358 seq_printf(s
, ",username=%s", tcon
->ses
->user_name
);
360 if (tcon
->ses
->domainName
)
361 seq_printf(s
, ",domain=%s", tcon
->ses
->domainName
);
363 if (srcaddr
->sa_family
!= AF_UNSPEC
) {
364 struct sockaddr_in
*saddr4
;
365 struct sockaddr_in6
*saddr6
;
366 saddr4
= (struct sockaddr_in
*)srcaddr
;
367 saddr6
= (struct sockaddr_in6
*)srcaddr
;
368 if (srcaddr
->sa_family
== AF_INET6
)
369 seq_printf(s
, ",srcaddr=%pI6c",
371 else if (srcaddr
->sa_family
== AF_INET
)
372 seq_printf(s
, ",srcaddr=%pI4",
373 &saddr4
->sin_addr
.s_addr
);
375 seq_printf(s
, ",srcaddr=BAD-AF:%i",
376 (int)(srcaddr
->sa_family
));
379 seq_printf(s
, ",uid=%u", cifs_sb
->mnt_uid
);
380 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_OVERR_UID
)
381 seq_printf(s
, ",forceuid");
383 seq_printf(s
, ",noforceuid");
385 seq_printf(s
, ",gid=%u", cifs_sb
->mnt_gid
);
386 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_OVERR_GID
)
387 seq_printf(s
, ",forcegid");
389 seq_printf(s
, ",noforcegid");
391 cifs_show_address(s
, tcon
->ses
->server
);
394 seq_printf(s
, ",file_mode=0%ho,dir_mode=0%ho",
395 cifs_sb
->mnt_file_mode
,
396 cifs_sb
->mnt_dir_mode
);
398 seq_printf(s
, ",seal");
400 seq_printf(s
, ",nocase");
402 seq_printf(s
, ",hard");
404 seq_printf(s
, ",unix");
406 seq_printf(s
, ",nounix");
407 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_POSIX_PATHS
)
408 seq_printf(s
, ",posixpaths");
409 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_SET_UID
)
410 seq_printf(s
, ",setuids");
411 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_SERVER_INUM
)
412 seq_printf(s
, ",serverino");
413 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_RWPIDFORWARD
)
414 seq_printf(s
, ",rwpidforward");
415 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_NOPOSIXBRL
)
416 seq_printf(s
, ",forcemand");
417 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_NO_XATTR
)
418 seq_printf(s
, ",nouser_xattr");
419 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_MAP_SPECIAL_CHR
)
420 seq_printf(s
, ",mapchars");
421 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_UNX_EMUL
)
422 seq_printf(s
, ",sfu");
423 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_NO_BRL
)
424 seq_printf(s
, ",nobrl");
425 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_CIFS_ACL
)
426 seq_printf(s
, ",cifsacl");
427 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_DYNPERM
)
428 seq_printf(s
, ",dynperm");
429 if (root
->d_sb
->s_flags
& MS_POSIXACL
)
430 seq_printf(s
, ",acl");
431 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_MF_SYMLINKS
)
432 seq_printf(s
, ",mfsymlinks");
433 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_FSCACHE
)
434 seq_printf(s
, ",fsc");
435 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_NOSSYNC
)
436 seq_printf(s
, ",nostrictsync");
437 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_NO_PERM
)
438 seq_printf(s
, ",noperm");
439 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_CIFS_BACKUPUID
)
440 seq_printf(s
, ",backupuid=%u", cifs_sb
->mnt_backupuid
);
441 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_CIFS_BACKUPGID
)
442 seq_printf(s
, ",backupgid=%u", cifs_sb
->mnt_backupgid
);
444 seq_printf(s
, ",rsize=%u", cifs_sb
->rsize
);
445 seq_printf(s
, ",wsize=%u", cifs_sb
->wsize
);
446 /* convert actimeo and display it in seconds */
447 seq_printf(s
, ",actimeo=%lu", cifs_sb
->actimeo
/ HZ
);
452 static void cifs_umount_begin(struct super_block
*sb
)
454 struct cifs_sb_info
*cifs_sb
= CIFS_SB(sb
);
455 struct cifs_tcon
*tcon
;
460 tcon
= cifs_sb_master_tcon(cifs_sb
);
462 spin_lock(&cifs_tcp_ses_lock
);
463 if ((tcon
->tc_count
> 1) || (tcon
->tidStatus
== CifsExiting
)) {
464 /* we have other mounts to same share or we have
465 already tried to force umount this and woken up
466 all waiting network requests, nothing to do */
467 spin_unlock(&cifs_tcp_ses_lock
);
469 } else if (tcon
->tc_count
== 1)
470 tcon
->tidStatus
= CifsExiting
;
471 spin_unlock(&cifs_tcp_ses_lock
);
473 /* cancel_brl_requests(tcon); */ /* BB mark all brl mids as exiting */
474 /* cancel_notify_requests(tcon); */
475 if (tcon
->ses
&& tcon
->ses
->server
) {
476 cFYI(1, "wake up tasks now - umount begin not complete");
477 wake_up_all(&tcon
->ses
->server
->request_q
);
478 wake_up_all(&tcon
->ses
->server
->response_q
);
479 msleep(1); /* yield */
480 /* we have to kick the requests once more */
481 wake_up_all(&tcon
->ses
->server
->response_q
);
488 #ifdef CONFIG_CIFS_STATS2
489 static int cifs_show_stats(struct seq_file
*s
, struct dentry
*root
)
496 static int cifs_remount(struct super_block
*sb
, int *flags
, char *data
)
498 *flags
|= MS_NODIRATIME
;
502 static int cifs_drop_inode(struct inode
*inode
)
504 struct cifs_sb_info
*cifs_sb
= CIFS_SB(inode
->i_sb
);
506 /* no serverino => unconditional eviction */
507 return !(cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_SERVER_INUM
) ||
508 generic_drop_inode(inode
);
511 static const struct super_operations cifs_super_ops
= {
512 .statfs
= cifs_statfs
,
513 .alloc_inode
= cifs_alloc_inode
,
514 .destroy_inode
= cifs_destroy_inode
,
515 .drop_inode
= cifs_drop_inode
,
516 .evict_inode
= cifs_evict_inode
,
517 /* .delete_inode = cifs_delete_inode, */ /* Do not need above
518 function unless later we add lazy close of inodes or unless the
519 kernel forgets to call us with the same number of releases (closes)
521 .show_options
= cifs_show_options
,
522 .umount_begin
= cifs_umount_begin
,
523 .remount_fs
= cifs_remount
,
524 #ifdef CONFIG_CIFS_STATS2
525 .show_stats
= cifs_show_stats
,
530 * Get root dentry from superblock according to prefix path mount option.
531 * Return dentry with refcount + 1 on success and NULL otherwise.
533 static struct dentry
*
534 cifs_get_root(struct smb_vol
*vol
, struct super_block
*sb
)
536 struct dentry
*dentry
;
537 struct cifs_sb_info
*cifs_sb
= CIFS_SB(sb
);
538 char *full_path
= NULL
;
542 full_path
= build_path_to_root(vol
, cifs_sb
,
543 cifs_sb_master_tcon(cifs_sb
));
544 if (full_path
== NULL
)
545 return ERR_PTR(-ENOMEM
);
547 cFYI(1, "Get root dentry for %s", full_path
);
549 sep
= CIFS_DIR_SEP(cifs_sb
);
550 dentry
= dget(sb
->s_root
);
554 struct inode
*dir
= dentry
->d_inode
;
555 struct dentry
*child
;
559 dentry
= ERR_PTR(-ENOENT
);
563 /* skip separators */
570 while (*s
&& *s
!= sep
)
573 mutex_lock(&dir
->i_mutex
);
574 child
= lookup_one_len(p
, dentry
, s
- p
);
575 mutex_unlock(&dir
->i_mutex
);
578 } while (!IS_ERR(dentry
));
583 static int cifs_set_super(struct super_block
*sb
, void *data
)
585 struct cifs_mnt_data
*mnt_data
= data
;
586 sb
->s_fs_info
= mnt_data
->cifs_sb
;
587 return set_anon_super(sb
, NULL
);
590 static struct dentry
*
591 cifs_do_mount(struct file_system_type
*fs_type
,
592 int flags
, const char *dev_name
, void *data
)
595 struct super_block
*sb
;
596 struct cifs_sb_info
*cifs_sb
;
597 struct smb_vol
*volume_info
;
598 struct cifs_mnt_data mnt_data
;
601 cFYI(1, "Devname: %s flags: %d ", dev_name
, flags
);
603 volume_info
= cifs_get_volume_info((char *)data
, dev_name
);
604 if (IS_ERR(volume_info
))
605 return ERR_CAST(volume_info
);
607 cifs_sb
= kzalloc(sizeof(struct cifs_sb_info
), GFP_KERNEL
);
608 if (cifs_sb
== NULL
) {
609 root
= ERR_PTR(-ENOMEM
);
613 cifs_sb
->mountdata
= kstrndup(data
, PAGE_SIZE
, GFP_KERNEL
);
614 if (cifs_sb
->mountdata
== NULL
) {
615 root
= ERR_PTR(-ENOMEM
);
619 cifs_setup_cifs_sb(volume_info
, cifs_sb
);
621 rc
= cifs_mount(cifs_sb
, volume_info
);
623 if (!(flags
& MS_SILENT
))
624 cERROR(1, "cifs_mount failed w/return code = %d", rc
);
629 mnt_data
.vol
= volume_info
;
630 mnt_data
.cifs_sb
= cifs_sb
;
631 mnt_data
.flags
= flags
;
633 /* BB should we make this contingent on mount parm? */
634 flags
|= MS_NODIRATIME
| MS_NOATIME
;
636 sb
= sget(fs_type
, cifs_match_super
, cifs_set_super
, flags
, &mnt_data
);
639 cifs_umount(cifs_sb
);
644 cFYI(1, "Use existing superblock");
645 cifs_umount(cifs_sb
);
647 rc
= cifs_read_super(sb
);
653 sb
->s_flags
|= MS_ACTIVE
;
656 root
= cifs_get_root(volume_info
, sb
);
660 cFYI(1, "dentry root is: %p", root
);
664 deactivate_locked_super(sb
);
666 cifs_cleanup_volume_info(volume_info
);
670 kfree(cifs_sb
->mountdata
);
674 unload_nls(volume_info
->local_nls
);
678 static ssize_t
cifs_file_aio_write(struct kiocb
*iocb
, const struct iovec
*iov
,
679 unsigned long nr_segs
, loff_t pos
)
681 struct inode
*inode
= iocb
->ki_filp
->f_path
.dentry
->d_inode
;
685 written
= generic_file_aio_write(iocb
, iov
, nr_segs
, pos
);
687 if (CIFS_I(inode
)->clientCanCacheAll
)
690 rc
= filemap_fdatawrite(inode
->i_mapping
);
692 cFYI(1, "cifs_file_aio_write: %d rc on %p inode", rc
, inode
);
697 static loff_t
cifs_llseek(struct file
*file
, loff_t offset
, int origin
)
700 * origin == SEEK_END || SEEK_DATA || SEEK_HOLE => we must revalidate
701 * the cached file length
703 if (origin
!= SEEK_SET
&& origin
!= SEEK_CUR
) {
705 struct inode
*inode
= file
->f_path
.dentry
->d_inode
;
708 * We need to be sure that all dirty pages are written and the
709 * server has the newest file length.
711 if (!CIFS_I(inode
)->clientCanCacheRead
&& inode
->i_mapping
&&
712 inode
->i_mapping
->nrpages
!= 0) {
713 rc
= filemap_fdatawait(inode
->i_mapping
);
715 mapping_set_error(inode
->i_mapping
, rc
);
720 * Some applications poll for the file length in this strange
721 * way so we must seek to end on non-oplocked files by
722 * setting the revalidate time to zero.
724 CIFS_I(inode
)->time
= 0;
726 rc
= cifs_revalidate_file_attr(file
);
730 return generic_file_llseek(file
, offset
, origin
);
733 static int cifs_setlease(struct file
*file
, long arg
, struct file_lock
**lease
)
735 /* note that this is called by vfs setlease with lock_flocks held
736 to protect *lease from going away */
737 struct inode
*inode
= file
->f_path
.dentry
->d_inode
;
738 struct cifsFileInfo
*cfile
= file
->private_data
;
740 if (!(S_ISREG(inode
->i_mode
)))
743 /* check if file is oplocked */
744 if (((arg
== F_RDLCK
) &&
745 (CIFS_I(inode
)->clientCanCacheRead
)) ||
747 (CIFS_I(inode
)->clientCanCacheAll
)))
748 return generic_setlease(file
, arg
, lease
);
749 else if (tlink_tcon(cfile
->tlink
)->local_lease
&&
750 !CIFS_I(inode
)->clientCanCacheRead
)
751 /* If the server claims to support oplock on this
752 file, then we still need to check oplock even
753 if the local_lease mount option is set, but there
754 are servers which do not support oplock for which
755 this mount option may be useful if the user
756 knows that the file won't be changed on the server
758 return generic_setlease(file
, arg
, lease
);
763 struct file_system_type cifs_fs_type
= {
764 .owner
= THIS_MODULE
,
766 .mount
= cifs_do_mount
,
767 .kill_sb
= cifs_kill_sb
,
770 const struct inode_operations cifs_dir_inode_ops
= {
771 .create
= cifs_create
,
772 .atomic_open
= cifs_atomic_open
,
773 .lookup
= cifs_lookup
,
774 .getattr
= cifs_getattr
,
775 .unlink
= cifs_unlink
,
776 .link
= cifs_hardlink
,
779 .rename
= cifs_rename
,
780 .permission
= cifs_permission
,
781 /* revalidate:cifs_revalidate, */
782 .setattr
= cifs_setattr
,
783 .symlink
= cifs_symlink
,
785 #ifdef CONFIG_CIFS_XATTR
786 .setxattr
= cifs_setxattr
,
787 .getxattr
= cifs_getxattr
,
788 .listxattr
= cifs_listxattr
,
789 .removexattr
= cifs_removexattr
,
793 const struct inode_operations cifs_file_inode_ops
= {
794 /* revalidate:cifs_revalidate, */
795 .setattr
= cifs_setattr
,
796 .getattr
= cifs_getattr
, /* do we need this anymore? */
797 .rename
= cifs_rename
,
798 .permission
= cifs_permission
,
799 #ifdef CONFIG_CIFS_XATTR
800 .setxattr
= cifs_setxattr
,
801 .getxattr
= cifs_getxattr
,
802 .listxattr
= cifs_listxattr
,
803 .removexattr
= cifs_removexattr
,
807 const struct inode_operations cifs_symlink_inode_ops
= {
808 .readlink
= generic_readlink
,
809 .follow_link
= cifs_follow_link
,
810 .put_link
= cifs_put_link
,
811 .permission
= cifs_permission
,
812 /* BB add the following two eventually */
813 /* revalidate: cifs_revalidate,
814 setattr: cifs_notify_change, *//* BB do we need notify change */
815 #ifdef CONFIG_CIFS_XATTR
816 .setxattr
= cifs_setxattr
,
817 .getxattr
= cifs_getxattr
,
818 .listxattr
= cifs_listxattr
,
819 .removexattr
= cifs_removexattr
,
823 const struct file_operations cifs_file_ops
= {
824 .read
= do_sync_read
,
825 .write
= do_sync_write
,
826 .aio_read
= generic_file_aio_read
,
827 .aio_write
= cifs_file_aio_write
,
829 .release
= cifs_close
,
833 .mmap
= cifs_file_mmap
,
834 .splice_read
= generic_file_splice_read
,
835 .llseek
= cifs_llseek
,
836 #ifdef CONFIG_CIFS_POSIX
837 .unlocked_ioctl
= cifs_ioctl
,
838 #endif /* CONFIG_CIFS_POSIX */
839 .setlease
= cifs_setlease
,
842 const struct file_operations cifs_file_strict_ops
= {
843 .read
= do_sync_read
,
844 .write
= do_sync_write
,
845 .aio_read
= cifs_strict_readv
,
846 .aio_write
= cifs_strict_writev
,
848 .release
= cifs_close
,
850 .fsync
= cifs_strict_fsync
,
852 .mmap
= cifs_file_strict_mmap
,
853 .splice_read
= generic_file_splice_read
,
854 .llseek
= cifs_llseek
,
855 #ifdef CONFIG_CIFS_POSIX
856 .unlocked_ioctl
= cifs_ioctl
,
857 #endif /* CONFIG_CIFS_POSIX */
858 .setlease
= cifs_setlease
,
861 const struct file_operations cifs_file_direct_ops
= {
862 /* BB reevaluate whether they can be done with directio, no cache */
863 .read
= do_sync_read
,
864 .write
= do_sync_write
,
865 .aio_read
= cifs_user_readv
,
866 .aio_write
= cifs_user_writev
,
868 .release
= cifs_close
,
872 .mmap
= cifs_file_mmap
,
873 .splice_read
= generic_file_splice_read
,
874 #ifdef CONFIG_CIFS_POSIX
875 .unlocked_ioctl
= cifs_ioctl
,
876 #endif /* CONFIG_CIFS_POSIX */
877 .llseek
= cifs_llseek
,
878 .setlease
= cifs_setlease
,
881 const struct file_operations cifs_file_nobrl_ops
= {
882 .read
= do_sync_read
,
883 .write
= do_sync_write
,
884 .aio_read
= generic_file_aio_read
,
885 .aio_write
= cifs_file_aio_write
,
887 .release
= cifs_close
,
890 .mmap
= cifs_file_mmap
,
891 .splice_read
= generic_file_splice_read
,
892 .llseek
= cifs_llseek
,
893 #ifdef CONFIG_CIFS_POSIX
894 .unlocked_ioctl
= cifs_ioctl
,
895 #endif /* CONFIG_CIFS_POSIX */
896 .setlease
= cifs_setlease
,
899 const struct file_operations cifs_file_strict_nobrl_ops
= {
900 .read
= do_sync_read
,
901 .write
= do_sync_write
,
902 .aio_read
= cifs_strict_readv
,
903 .aio_write
= cifs_strict_writev
,
905 .release
= cifs_close
,
906 .fsync
= cifs_strict_fsync
,
908 .mmap
= cifs_file_strict_mmap
,
909 .splice_read
= generic_file_splice_read
,
910 .llseek
= cifs_llseek
,
911 #ifdef CONFIG_CIFS_POSIX
912 .unlocked_ioctl
= cifs_ioctl
,
913 #endif /* CONFIG_CIFS_POSIX */
914 .setlease
= cifs_setlease
,
917 const struct file_operations cifs_file_direct_nobrl_ops
= {
918 /* BB reevaluate whether they can be done with directio, no cache */
919 .read
= do_sync_read
,
920 .write
= do_sync_write
,
921 .aio_read
= cifs_user_readv
,
922 .aio_write
= cifs_user_writev
,
924 .release
= cifs_close
,
927 .mmap
= cifs_file_mmap
,
928 .splice_read
= generic_file_splice_read
,
929 #ifdef CONFIG_CIFS_POSIX
930 .unlocked_ioctl
= cifs_ioctl
,
931 #endif /* CONFIG_CIFS_POSIX */
932 .llseek
= cifs_llseek
,
933 .setlease
= cifs_setlease
,
936 const struct file_operations cifs_dir_ops
= {
937 .readdir
= cifs_readdir
,
938 .release
= cifs_closedir
,
939 .read
= generic_read_dir
,
940 .unlocked_ioctl
= cifs_ioctl
,
941 .llseek
= generic_file_llseek
,
945 cifs_init_once(void *inode
)
947 struct cifsInodeInfo
*cifsi
= inode
;
949 inode_init_once(&cifsi
->vfs_inode
);
950 init_rwsem(&cifsi
->lock_sem
);
954 cifs_init_inodecache(void)
956 cifs_inode_cachep
= kmem_cache_create("cifs_inode_cache",
957 sizeof(struct cifsInodeInfo
),
958 0, (SLAB_RECLAIM_ACCOUNT
|
961 if (cifs_inode_cachep
== NULL
)
968 cifs_destroy_inodecache(void)
971 * Make sure all delayed rcu free inodes are flushed before we
975 kmem_cache_destroy(cifs_inode_cachep
);
979 cifs_init_request_bufs(void)
981 size_t max_hdr_size
= MAX_CIFS_HDR_SIZE
;
982 #ifdef CONFIG_CIFS_SMB2
984 * SMB2 maximum header size is bigger than CIFS one - no problems to
985 * allocate some more bytes for CIFS.
987 max_hdr_size
= MAX_SMB2_HDR_SIZE
;
989 if (CIFSMaxBufSize
< 8192) {
990 /* Buffer size can not be smaller than 2 * PATH_MAX since maximum
991 Unicode path name has to fit in any SMB/CIFS path based frames */
992 CIFSMaxBufSize
= 8192;
993 } else if (CIFSMaxBufSize
> 1024*127) {
994 CIFSMaxBufSize
= 1024 * 127;
996 CIFSMaxBufSize
&= 0x1FE00; /* Round size to even 512 byte mult*/
998 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
999 cifs_req_cachep
= kmem_cache_create("cifs_request",
1000 CIFSMaxBufSize
+ max_hdr_size
, 0,
1001 SLAB_HWCACHE_ALIGN
, NULL
);
1002 if (cifs_req_cachep
== NULL
)
1005 if (cifs_min_rcv
< 1)
1007 else if (cifs_min_rcv
> 64) {
1009 cERROR(1, "cifs_min_rcv set to maximum (64)");
1012 cifs_req_poolp
= mempool_create_slab_pool(cifs_min_rcv
,
1015 if (cifs_req_poolp
== NULL
) {
1016 kmem_cache_destroy(cifs_req_cachep
);
1019 /* MAX_CIFS_SMALL_BUFFER_SIZE bytes is enough for most SMB responses and
1020 almost all handle based requests (but not write response, nor is it
1021 sufficient for path based requests). A smaller size would have
1022 been more efficient (compacting multiple slab items on one 4k page)
1023 for the case in which debug was on, but this larger size allows
1024 more SMBs to use small buffer alloc and is still much more
1025 efficient to alloc 1 per page off the slab compared to 17K (5page)
1026 alloc of large cifs buffers even when page debugging is on */
1027 cifs_sm_req_cachep
= kmem_cache_create("cifs_small_rq",
1028 MAX_CIFS_SMALL_BUFFER_SIZE
, 0, SLAB_HWCACHE_ALIGN
,
1030 if (cifs_sm_req_cachep
== NULL
) {
1031 mempool_destroy(cifs_req_poolp
);
1032 kmem_cache_destroy(cifs_req_cachep
);
1036 if (cifs_min_small
< 2)
1038 else if (cifs_min_small
> 256) {
1039 cifs_min_small
= 256;
1040 cFYI(1, "cifs_min_small set to maximum (256)");
1043 cifs_sm_req_poolp
= mempool_create_slab_pool(cifs_min_small
,
1044 cifs_sm_req_cachep
);
1046 if (cifs_sm_req_poolp
== NULL
) {
1047 mempool_destroy(cifs_req_poolp
);
1048 kmem_cache_destroy(cifs_req_cachep
);
1049 kmem_cache_destroy(cifs_sm_req_cachep
);
1057 cifs_destroy_request_bufs(void)
1059 mempool_destroy(cifs_req_poolp
);
1060 kmem_cache_destroy(cifs_req_cachep
);
1061 mempool_destroy(cifs_sm_req_poolp
);
1062 kmem_cache_destroy(cifs_sm_req_cachep
);
1066 cifs_init_mids(void)
1068 cifs_mid_cachep
= kmem_cache_create("cifs_mpx_ids",
1069 sizeof(struct mid_q_entry
), 0,
1070 SLAB_HWCACHE_ALIGN
, NULL
);
1071 if (cifs_mid_cachep
== NULL
)
1074 /* 3 is a reasonable minimum number of simultaneous operations */
1075 cifs_mid_poolp
= mempool_create_slab_pool(3, cifs_mid_cachep
);
1076 if (cifs_mid_poolp
== NULL
) {
1077 kmem_cache_destroy(cifs_mid_cachep
);
1085 cifs_destroy_mids(void)
1087 mempool_destroy(cifs_mid_poolp
);
1088 kmem_cache_destroy(cifs_mid_cachep
);
1096 INIT_LIST_HEAD(&cifs_tcp_ses_list
);
1097 #ifdef CONFIG_CIFS_DNOTIFY_EXPERIMENTAL /* unused temporarily */
1098 INIT_LIST_HEAD(&GlobalDnotifyReqList
);
1099 INIT_LIST_HEAD(&GlobalDnotifyRsp_Q
);
1100 #endif /* was needed for dnotify, and will be needed for inotify when VFS fix */
1102 * Initialize Global counters
1104 atomic_set(&sesInfoAllocCount
, 0);
1105 atomic_set(&tconInfoAllocCount
, 0);
1106 atomic_set(&tcpSesAllocCount
, 0);
1107 atomic_set(&tcpSesReconnectCount
, 0);
1108 atomic_set(&tconInfoReconnectCount
, 0);
1110 atomic_set(&bufAllocCount
, 0);
1111 atomic_set(&smBufAllocCount
, 0);
1112 #ifdef CONFIG_CIFS_STATS2
1113 atomic_set(&totBufAllocCount
, 0);
1114 atomic_set(&totSmBufAllocCount
, 0);
1115 #endif /* CONFIG_CIFS_STATS2 */
1117 atomic_set(&midCount
, 0);
1118 GlobalCurrentXid
= 0;
1119 GlobalTotalActiveXid
= 0;
1120 GlobalMaxActiveXid
= 0;
1121 spin_lock_init(&cifs_tcp_ses_lock
);
1122 spin_lock_init(&cifs_file_list_lock
);
1123 spin_lock_init(&GlobalMid_Lock
);
1125 #ifdef CONFIG_CIFS_SMB2
1126 get_random_bytes(cifs_client_guid
, SMB2_CLIENT_GUID_SIZE
);
1129 if (cifs_max_pending
< 2) {
1130 cifs_max_pending
= 2;
1131 cFYI(1, "cifs_max_pending set to min of 2");
1132 } else if (cifs_max_pending
> CIFS_MAX_REQ
) {
1133 cifs_max_pending
= CIFS_MAX_REQ
;
1134 cFYI(1, "cifs_max_pending set to max of %u", CIFS_MAX_REQ
);
1137 cifsiod_wq
= alloc_workqueue("cifsiod", WQ_FREEZABLE
|WQ_MEM_RECLAIM
, 0);
1140 goto out_clean_proc
;
1143 rc
= cifs_fscache_register();
1145 goto out_destroy_wq
;
1147 rc
= cifs_init_inodecache();
1149 goto out_unreg_fscache
;
1151 rc
= cifs_init_mids();
1153 goto out_destroy_inodecache
;
1155 rc
= cifs_init_request_bufs();
1157 goto out_destroy_mids
;
1159 #ifdef CONFIG_CIFS_UPCALL
1160 rc
= register_key_type(&cifs_spnego_key_type
);
1162 goto out_destroy_request_bufs
;
1163 #endif /* CONFIG_CIFS_UPCALL */
1165 #ifdef CONFIG_CIFS_ACL
1166 rc
= init_cifs_idmap();
1168 goto out_register_key_type
;
1169 #endif /* CONFIG_CIFS_ACL */
1171 rc
= register_filesystem(&cifs_fs_type
);
1173 goto out_init_cifs_idmap
;
1177 out_init_cifs_idmap
:
1178 #ifdef CONFIG_CIFS_ACL
1180 out_register_key_type
:
1182 #ifdef CONFIG_CIFS_UPCALL
1183 unregister_key_type(&cifs_spnego_key_type
);
1184 out_destroy_request_bufs
:
1186 cifs_destroy_request_bufs();
1188 cifs_destroy_mids();
1189 out_destroy_inodecache
:
1190 cifs_destroy_inodecache();
1192 cifs_fscache_unregister();
1194 destroy_workqueue(cifsiod_wq
);
1203 cFYI(DBG2
, "exit_cifs");
1204 unregister_filesystem(&cifs_fs_type
);
1205 cifs_dfs_release_automount_timer();
1206 #ifdef CONFIG_CIFS_ACL
1207 cifs_destroy_idmaptrees();
1210 #ifdef CONFIG_CIFS_UPCALL
1211 unregister_key_type(&cifs_spnego_key_type
);
1213 cifs_destroy_request_bufs();
1214 cifs_destroy_mids();
1215 cifs_destroy_inodecache();
1216 cifs_fscache_unregister();
1217 destroy_workqueue(cifsiod_wq
);
1221 MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>");
1222 MODULE_LICENSE("GPL"); /* combination of LGPL + GPL source behaves as GPL */
1224 ("VFS to access servers complying with the SNIA CIFS Specification "
1225 "e.g. Samba and Windows");
1226 MODULE_VERSION(CIFS_VERSION
);
1227 module_init(init_cifs
)
1228 module_exit(exit_cifs
)