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>
41 #define DECLARE_GLOBALS_HERE
43 #include "cifsproto.h"
44 #include "cifs_debug.h"
45 #include "cifs_fs_sb.h"
47 #include <linux/key-type.h>
48 #include "cifs_spnego.h"
50 #define CIFS_MAGIC_NUMBER 0xFF534D42 /* the first four bytes of SMB PDUs */
55 unsigned int oplockEnabled
= 1;
56 unsigned int experimEnabled
= 0;
57 unsigned int linuxExtEnabled
= 1;
58 unsigned int lookupCacheEnabled
= 1;
59 unsigned int multiuser_mount
= 0;
60 unsigned int global_secflags
= CIFSSEC_DEF
;
61 /* unsigned int ntlmv2_support = 0; */
62 unsigned int sign_CIFS_PDUs
= 1;
63 static const struct super_operations cifs_super_ops
;
64 unsigned int CIFSMaxBufSize
= CIFS_MAX_MSGSIZE
;
65 module_param(CIFSMaxBufSize
, int, 0);
66 MODULE_PARM_DESC(CIFSMaxBufSize
, "Network buffer size (not including header). "
67 "Default: 16384 Range: 8192 to 130048");
68 unsigned int cifs_min_rcv
= CIFS_MIN_RCV_POOL
;
69 module_param(cifs_min_rcv
, int, 0);
70 MODULE_PARM_DESC(cifs_min_rcv
, "Network buffers in pool. Default: 4 Range: "
72 unsigned int cifs_min_small
= 30;
73 module_param(cifs_min_small
, int, 0);
74 MODULE_PARM_DESC(cifs_min_small
, "Small network buffers in pool. Default: 30 "
76 unsigned int cifs_max_pending
= CIFS_MAX_REQ
;
77 module_param(cifs_max_pending
, int, 0);
78 MODULE_PARM_DESC(cifs_max_pending
, "Simultaneous requests to server. "
79 "Default: 50 Range: 2 to 256");
80 unsigned short echo_retries
= 5;
81 module_param(echo_retries
, ushort
, 0644);
82 MODULE_PARM_DESC(echo_retries
, "Number of echo attempts before giving up and "
83 "reconnecting server. Default: 5. 0 means "
85 extern mempool_t
*cifs_sm_req_poolp
;
86 extern mempool_t
*cifs_req_poolp
;
87 extern mempool_t
*cifs_mid_poolp
;
90 cifs_sb_active(struct super_block
*sb
)
92 struct cifs_sb_info
*server
= CIFS_SB(sb
);
94 if (atomic_inc_return(&server
->active
) == 1)
95 atomic_inc(&sb
->s_active
);
99 cifs_sb_deactive(struct super_block
*sb
)
101 struct cifs_sb_info
*server
= CIFS_SB(sb
);
103 if (atomic_dec_and_test(&server
->active
))
104 deactivate_super(sb
);
108 cifs_read_super(struct super_block
*sb
, void *data
,
109 const char *devname
, int silent
)
112 struct cifs_sb_info
*cifs_sb
;
115 /* BB should we make this contingent on mount parm? */
116 sb
->s_flags
|= MS_NODIRATIME
| MS_NOATIME
;
117 sb
->s_fs_info
= kzalloc(sizeof(struct cifs_sb_info
), GFP_KERNEL
);
118 cifs_sb
= CIFS_SB(sb
);
122 spin_lock_init(&cifs_sb
->tlink_tree_lock
);
123 cifs_sb
->tlink_tree
= RB_ROOT
;
125 rc
= bdi_setup_and_register(&cifs_sb
->bdi
, "cifs", BDI_CAP_MAP_COPY
);
130 cifs_sb
->bdi
.ra_pages
= default_backing_dev_info
.ra_pages
;
132 #ifdef CONFIG_CIFS_DFS_UPCALL
133 /* copy mount params to sb for use in submounts */
134 /* BB: should we move this after the mount so we
135 * do not have to do the copy on failed mounts?
136 * BB: May be it is better to do simple copy before
137 * complex operation (mount), and in case of fail
138 * just exit instead of doing mount and attempting
139 * undo it if this copy fails?*/
141 int len
= strlen(data
);
142 cifs_sb
->mountdata
= kzalloc(len
+ 1, GFP_KERNEL
);
143 if (cifs_sb
->mountdata
== NULL
) {
144 bdi_destroy(&cifs_sb
->bdi
);
145 kfree(sb
->s_fs_info
);
146 sb
->s_fs_info
= NULL
;
149 strncpy(cifs_sb
->mountdata
, data
, len
+ 1);
150 cifs_sb
->mountdata
[len
] = '\0';
154 rc
= cifs_mount(sb
, cifs_sb
, data
, devname
);
158 cERROR(1, "cifs_mount failed w/return code = %d", rc
);
159 goto out_mount_failed
;
162 sb
->s_magic
= CIFS_MAGIC_NUMBER
;
163 sb
->s_op
= &cifs_super_ops
;
164 sb
->s_bdi
= &cifs_sb
->bdi
;
165 sb
->s_blocksize
= CIFS_MAX_MSGSIZE
;
166 sb
->s_blocksize_bits
= 14; /* default 2**14 = CIFS_MAX_MSGSIZE */
167 inode
= cifs_root_iget(sb
, ROOT_I
);
175 sb
->s_root
= d_alloc_root(inode
);
182 /* do that *after* d_alloc_root() - we want NULL ->d_op for root here */
183 if (cifs_sb_master_tcon(cifs_sb
)->nocase
)
184 sb
->s_d_op
= &cifs_ci_dentry_ops
;
186 sb
->s_d_op
= &cifs_dentry_ops
;
188 #ifdef CONFIG_CIFS_EXPERIMENTAL
189 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_SERVER_INUM
) {
190 cFYI(1, "export ops supported");
191 sb
->s_export_op
= &cifs_export_ops
;
193 #endif /* EXPERIMENTAL */
198 cERROR(1, "cifs_read_super: get root inode failed");
202 cifs_umount(sb
, cifs_sb
);
206 #ifdef CONFIG_CIFS_DFS_UPCALL
207 if (cifs_sb
->mountdata
) {
208 kfree(cifs_sb
->mountdata
);
209 cifs_sb
->mountdata
= NULL
;
212 unload_nls(cifs_sb
->local_nls
);
213 bdi_destroy(&cifs_sb
->bdi
);
220 cifs_put_super(struct super_block
*sb
)
223 struct cifs_sb_info
*cifs_sb
;
225 cFYI(1, "In cifs_put_super");
226 cifs_sb
= CIFS_SB(sb
);
227 if (cifs_sb
== NULL
) {
228 cFYI(1, "Empty cifs superblock info passed to unmount");
232 rc
= cifs_umount(sb
, cifs_sb
);
234 cERROR(1, "cifs_umount failed with return code %d", rc
);
235 #ifdef CONFIG_CIFS_DFS_UPCALL
236 if (cifs_sb
->mountdata
) {
237 kfree(cifs_sb
->mountdata
);
238 cifs_sb
->mountdata
= NULL
;
242 unload_nls(cifs_sb
->local_nls
);
243 bdi_destroy(&cifs_sb
->bdi
);
248 cifs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
250 struct super_block
*sb
= dentry
->d_sb
;
251 struct cifs_sb_info
*cifs_sb
= CIFS_SB(sb
);
252 struct cifsTconInfo
*tcon
= cifs_sb_master_tcon(cifs_sb
);
253 int rc
= -EOPNOTSUPP
;
258 buf
->f_type
= CIFS_MAGIC_NUMBER
;
261 * PATH_MAX may be too long - it would presumably be total path,
262 * but note that some servers (includinng Samba 3) have a shorter
265 * Instead could get the real value via SMB_QUERY_FS_ATTRIBUTE_INFO.
267 buf
->f_namelen
= PATH_MAX
;
268 buf
->f_files
= 0; /* undefined */
269 buf
->f_ffree
= 0; /* unlimited */
272 * We could add a second check for a QFS Unix capability bit
274 if ((tcon
->ses
->capabilities
& CAP_UNIX
) &&
275 (CIFS_POSIX_EXTENSIONS
& le64_to_cpu(tcon
->fsUnixInfo
.Capability
)))
276 rc
= CIFSSMBQFSPosixInfo(xid
, tcon
, buf
);
279 * Only need to call the old QFSInfo if failed on newer one,
282 if (rc
&& (tcon
->ses
->capabilities
& CAP_NT_SMBS
))
283 rc
= CIFSSMBQFSInfo(xid
, tcon
, buf
);
286 * Some old Windows servers also do not support level 103, retry with
287 * older level one if old server failed the previous call or we
288 * bypassed it because we detected that this was an older LANMAN sess
291 rc
= SMBOldQFSInfo(xid
, tcon
, buf
);
297 static int cifs_permission(struct inode
*inode
, int mask
, unsigned int flags
)
299 struct cifs_sb_info
*cifs_sb
;
301 if (flags
& IPERM_FLAG_RCU
)
304 cifs_sb
= CIFS_SB(inode
->i_sb
);
306 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_NO_PERM
) {
307 if ((mask
& MAY_EXEC
) && !execute_ok(inode
))
311 } else /* file mode might have been restricted at mount time
312 on the client (above and beyond ACL on servers) for
313 servers which do not support setting and viewing mode bits,
314 so allowing client to check permissions is useful */
315 return generic_permission(inode
, mask
, flags
, NULL
);
318 static struct kmem_cache
*cifs_inode_cachep
;
319 static struct kmem_cache
*cifs_req_cachep
;
320 static struct kmem_cache
*cifs_mid_cachep
;
321 static struct kmem_cache
*cifs_sm_req_cachep
;
322 mempool_t
*cifs_sm_req_poolp
;
323 mempool_t
*cifs_req_poolp
;
324 mempool_t
*cifs_mid_poolp
;
326 static struct inode
*
327 cifs_alloc_inode(struct super_block
*sb
)
329 struct cifsInodeInfo
*cifs_inode
;
330 cifs_inode
= kmem_cache_alloc(cifs_inode_cachep
, GFP_KERNEL
);
333 cifs_inode
->cifsAttrs
= 0x20; /* default */
334 cifs_inode
->time
= 0;
335 /* Until the file is open and we have gotten oplock
336 info back from the server, can not assume caching of
337 file data or metadata */
338 cifs_set_oplock_level(cifs_inode
, 0);
339 cifs_inode
->delete_pending
= false;
340 cifs_inode
->invalid_mapping
= false;
341 cifs_inode
->vfs_inode
.i_blkbits
= 14; /* 2**14 = CIFS_MAX_MSGSIZE */
342 cifs_inode
->server_eof
= 0;
343 cifs_inode
->uniqueid
= 0;
344 cifs_inode
->createtime
= 0;
346 /* Can not set i_flags here - they get immediately overwritten
347 to zero by the VFS */
348 /* cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME;*/
349 INIT_LIST_HEAD(&cifs_inode
->openFileList
);
350 return &cifs_inode
->vfs_inode
;
353 static void cifs_i_callback(struct rcu_head
*head
)
355 struct inode
*inode
= container_of(head
, struct inode
, i_rcu
);
356 INIT_LIST_HEAD(&inode
->i_dentry
);
357 kmem_cache_free(cifs_inode_cachep
, CIFS_I(inode
));
361 cifs_destroy_inode(struct inode
*inode
)
363 call_rcu(&inode
->i_rcu
, cifs_i_callback
);
367 cifs_evict_inode(struct inode
*inode
)
369 truncate_inode_pages(&inode
->i_data
, 0);
370 end_writeback(inode
);
371 cifs_fscache_release_inode_cookie(inode
);
375 cifs_show_address(struct seq_file
*s
, struct TCP_Server_Info
*server
)
377 struct sockaddr_in
*sa
= (struct sockaddr_in
*) &server
->dstaddr
;
378 struct sockaddr_in6
*sa6
= (struct sockaddr_in6
*) &server
->dstaddr
;
380 seq_printf(s
, ",addr=");
382 switch (server
->dstaddr
.ss_family
) {
384 seq_printf(s
, "%pI4", &sa
->sin_addr
.s_addr
);
387 seq_printf(s
, "%pI6", &sa6
->sin6_addr
.s6_addr
);
388 if (sa6
->sin6_scope_id
)
389 seq_printf(s
, "%%%u", sa6
->sin6_scope_id
);
392 seq_printf(s
, "(unknown)");
397 * cifs_show_options() is for displaying mount options in /proc/mounts.
398 * Not all settable options are displayed but most of the important
402 cifs_show_options(struct seq_file
*s
, struct vfsmount
*m
)
404 struct cifs_sb_info
*cifs_sb
= CIFS_SB(m
->mnt_sb
);
405 struct cifsTconInfo
*tcon
= cifs_sb_master_tcon(cifs_sb
);
406 struct sockaddr
*srcaddr
;
407 srcaddr
= (struct sockaddr
*)&tcon
->ses
->server
->srcaddr
;
409 seq_printf(s
, ",unc=%s", tcon
->treeName
);
411 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_MULTIUSER
)
412 seq_printf(s
, ",multiuser");
413 else if (tcon
->ses
->userName
)
414 seq_printf(s
, ",username=%s", tcon
->ses
->userName
);
416 if (tcon
->ses
->domainName
)
417 seq_printf(s
, ",domain=%s", tcon
->ses
->domainName
);
419 if (srcaddr
->sa_family
!= AF_UNSPEC
) {
420 struct sockaddr_in
*saddr4
;
421 struct sockaddr_in6
*saddr6
;
422 saddr4
= (struct sockaddr_in
*)srcaddr
;
423 saddr6
= (struct sockaddr_in6
*)srcaddr
;
424 if (srcaddr
->sa_family
== AF_INET6
)
425 seq_printf(s
, ",srcaddr=%pI6c",
427 else if (srcaddr
->sa_family
== AF_INET
)
428 seq_printf(s
, ",srcaddr=%pI4",
429 &saddr4
->sin_addr
.s_addr
);
431 seq_printf(s
, ",srcaddr=BAD-AF:%i",
432 (int)(srcaddr
->sa_family
));
435 seq_printf(s
, ",uid=%d", cifs_sb
->mnt_uid
);
436 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_OVERR_UID
)
437 seq_printf(s
, ",forceuid");
439 seq_printf(s
, ",noforceuid");
441 seq_printf(s
, ",gid=%d", cifs_sb
->mnt_gid
);
442 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_OVERR_GID
)
443 seq_printf(s
, ",forcegid");
445 seq_printf(s
, ",noforcegid");
447 cifs_show_address(s
, tcon
->ses
->server
);
450 seq_printf(s
, ",file_mode=0%o,dir_mode=0%o",
451 cifs_sb
->mnt_file_mode
,
452 cifs_sb
->mnt_dir_mode
);
454 seq_printf(s
, ",seal");
456 seq_printf(s
, ",nocase");
458 seq_printf(s
, ",hard");
459 if (cifs_sb
->prepath
)
460 seq_printf(s
, ",prepath=%s", cifs_sb
->prepath
);
461 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_POSIX_PATHS
)
462 seq_printf(s
, ",posixpaths");
463 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_SET_UID
)
464 seq_printf(s
, ",setuids");
465 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_SERVER_INUM
)
466 seq_printf(s
, ",serverino");
467 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_DIRECT_IO
)
468 seq_printf(s
, ",directio");
469 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_NO_XATTR
)
470 seq_printf(s
, ",nouser_xattr");
471 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_MAP_SPECIAL_CHR
)
472 seq_printf(s
, ",mapchars");
473 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_UNX_EMUL
)
474 seq_printf(s
, ",sfu");
475 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_NO_BRL
)
476 seq_printf(s
, ",nobrl");
477 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_CIFS_ACL
)
478 seq_printf(s
, ",cifsacl");
479 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_DYNPERM
)
480 seq_printf(s
, ",dynperm");
481 if (m
->mnt_sb
->s_flags
& MS_POSIXACL
)
482 seq_printf(s
, ",acl");
483 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_MF_SYMLINKS
)
484 seq_printf(s
, ",mfsymlinks");
485 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_FSCACHE
)
486 seq_printf(s
, ",fsc");
488 seq_printf(s
, ",rsize=%d", cifs_sb
->rsize
);
489 seq_printf(s
, ",wsize=%d", cifs_sb
->wsize
);
490 /* convert actimeo and display it in seconds */
491 seq_printf(s
, ",actimeo=%lu", cifs_sb
->actimeo
/ HZ
);
496 static void cifs_umount_begin(struct super_block
*sb
)
498 struct cifs_sb_info
*cifs_sb
= CIFS_SB(sb
);
499 struct cifsTconInfo
*tcon
;
504 tcon
= cifs_sb_master_tcon(cifs_sb
);
506 spin_lock(&cifs_tcp_ses_lock
);
507 if ((tcon
->tc_count
> 1) || (tcon
->tidStatus
== CifsExiting
)) {
508 /* we have other mounts to same share or we have
509 already tried to force umount this and woken up
510 all waiting network requests, nothing to do */
511 spin_unlock(&cifs_tcp_ses_lock
);
513 } else if (tcon
->tc_count
== 1)
514 tcon
->tidStatus
= CifsExiting
;
515 spin_unlock(&cifs_tcp_ses_lock
);
517 /* cancel_brl_requests(tcon); */ /* BB mark all brl mids as exiting */
518 /* cancel_notify_requests(tcon); */
519 if (tcon
->ses
&& tcon
->ses
->server
) {
520 cFYI(1, "wake up tasks now - umount begin not complete");
521 wake_up_all(&tcon
->ses
->server
->request_q
);
522 wake_up_all(&tcon
->ses
->server
->response_q
);
523 msleep(1); /* yield */
524 /* we have to kick the requests once more */
525 wake_up_all(&tcon
->ses
->server
->response_q
);
532 #ifdef CONFIG_CIFS_STATS2
533 static int cifs_show_stats(struct seq_file
*s
, struct vfsmount
*mnt
)
540 static int cifs_remount(struct super_block
*sb
, int *flags
, char *data
)
542 *flags
|= MS_NODIRATIME
;
546 static int cifs_drop_inode(struct inode
*inode
)
548 struct cifs_sb_info
*cifs_sb
= CIFS_SB(inode
->i_sb
);
550 /* no serverino => unconditional eviction */
551 return !(cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_SERVER_INUM
) ||
552 generic_drop_inode(inode
);
555 static const struct super_operations cifs_super_ops
= {
556 .put_super
= cifs_put_super
,
557 .statfs
= cifs_statfs
,
558 .alloc_inode
= cifs_alloc_inode
,
559 .destroy_inode
= cifs_destroy_inode
,
560 .drop_inode
= cifs_drop_inode
,
561 .evict_inode
= cifs_evict_inode
,
562 /* .delete_inode = cifs_delete_inode, */ /* Do not need above
563 function unless later we add lazy close of inodes or unless the
564 kernel forgets to call us with the same number of releases (closes)
566 .show_options
= cifs_show_options
,
567 .umount_begin
= cifs_umount_begin
,
568 .remount_fs
= cifs_remount
,
569 #ifdef CONFIG_CIFS_STATS2
570 .show_stats
= cifs_show_stats
,
574 static struct dentry
*
575 cifs_do_mount(struct file_system_type
*fs_type
,
576 int flags
, const char *dev_name
, void *data
)
579 struct super_block
*sb
;
581 sb
= sget(fs_type
, NULL
, set_anon_super
, NULL
);
583 cFYI(1, "Devname: %s flags: %d ", dev_name
, flags
);
590 rc
= cifs_read_super(sb
, data
, dev_name
, flags
& MS_SILENT
? 1 : 0);
592 deactivate_locked_super(sb
);
595 sb
->s_flags
|= MS_ACTIVE
;
596 return dget(sb
->s_root
);
599 static ssize_t
cifs_file_aio_write(struct kiocb
*iocb
, const struct iovec
*iov
,
600 unsigned long nr_segs
, loff_t pos
)
602 struct inode
*inode
= iocb
->ki_filp
->f_path
.dentry
->d_inode
;
606 written
= generic_file_aio_write(iocb
, iov
, nr_segs
, pos
);
608 if (CIFS_I(inode
)->clientCanCacheAll
)
611 rc
= filemap_fdatawrite(inode
->i_mapping
);
613 cFYI(1, "cifs_file_aio_write: %d rc on %p inode", rc
, inode
);
618 static loff_t
cifs_llseek(struct file
*file
, loff_t offset
, int origin
)
620 /* origin == SEEK_END => we must revalidate the cached file length */
621 if (origin
== SEEK_END
) {
624 /* some applications poll for the file length in this strange
625 way so we must seek to end on non-oplocked files by
626 setting the revalidate time to zero */
627 CIFS_I(file
->f_path
.dentry
->d_inode
)->time
= 0;
629 retval
= cifs_revalidate_file(file
);
631 return (loff_t
)retval
;
633 return generic_file_llseek_unlocked(file
, offset
, origin
);
636 static int cifs_setlease(struct file
*file
, long arg
, struct file_lock
**lease
)
638 /* note that this is called by vfs setlease with lock_flocks held
639 to protect *lease from going away */
640 struct inode
*inode
= file
->f_path
.dentry
->d_inode
;
641 struct cifsFileInfo
*cfile
= file
->private_data
;
643 if (!(S_ISREG(inode
->i_mode
)))
646 /* check if file is oplocked */
647 if (((arg
== F_RDLCK
) &&
648 (CIFS_I(inode
)->clientCanCacheRead
)) ||
650 (CIFS_I(inode
)->clientCanCacheAll
)))
651 return generic_setlease(file
, arg
, lease
);
652 else if (tlink_tcon(cfile
->tlink
)->local_lease
&&
653 !CIFS_I(inode
)->clientCanCacheRead
)
654 /* If the server claims to support oplock on this
655 file, then we still need to check oplock even
656 if the local_lease mount option is set, but there
657 are servers which do not support oplock for which
658 this mount option may be useful if the user
659 knows that the file won't be changed on the server
661 return generic_setlease(file
, arg
, lease
);
666 struct file_system_type cifs_fs_type
= {
667 .owner
= THIS_MODULE
,
669 .mount
= cifs_do_mount
,
670 .kill_sb
= kill_anon_super
,
673 const struct inode_operations cifs_dir_inode_ops
= {
674 .create
= cifs_create
,
675 .lookup
= cifs_lookup
,
676 .getattr
= cifs_getattr
,
677 .unlink
= cifs_unlink
,
678 .link
= cifs_hardlink
,
681 .rename
= cifs_rename
,
682 .permission
= cifs_permission
,
683 /* revalidate:cifs_revalidate, */
684 .setattr
= cifs_setattr
,
685 .symlink
= cifs_symlink
,
687 #ifdef CONFIG_CIFS_XATTR
688 .setxattr
= cifs_setxattr
,
689 .getxattr
= cifs_getxattr
,
690 .listxattr
= cifs_listxattr
,
691 .removexattr
= cifs_removexattr
,
695 const struct inode_operations cifs_file_inode_ops
= {
696 /* revalidate:cifs_revalidate, */
697 .setattr
= cifs_setattr
,
698 .getattr
= cifs_getattr
, /* do we need this anymore? */
699 .rename
= cifs_rename
,
700 .permission
= cifs_permission
,
701 #ifdef CONFIG_CIFS_XATTR
702 .setxattr
= cifs_setxattr
,
703 .getxattr
= cifs_getxattr
,
704 .listxattr
= cifs_listxattr
,
705 .removexattr
= cifs_removexattr
,
709 const struct inode_operations cifs_symlink_inode_ops
= {
710 .readlink
= generic_readlink
,
711 .follow_link
= cifs_follow_link
,
712 .put_link
= cifs_put_link
,
713 .permission
= cifs_permission
,
714 /* BB add the following two eventually */
715 /* revalidate: cifs_revalidate,
716 setattr: cifs_notify_change, *//* BB do we need notify change */
717 #ifdef CONFIG_CIFS_XATTR
718 .setxattr
= cifs_setxattr
,
719 .getxattr
= cifs_getxattr
,
720 .listxattr
= cifs_listxattr
,
721 .removexattr
= cifs_removexattr
,
725 const struct file_operations cifs_file_ops
= {
726 .read
= do_sync_read
,
727 .write
= do_sync_write
,
728 .aio_read
= generic_file_aio_read
,
729 .aio_write
= cifs_file_aio_write
,
731 .release
= cifs_close
,
735 .mmap
= cifs_file_mmap
,
736 .splice_read
= generic_file_splice_read
,
737 .llseek
= cifs_llseek
,
738 #ifdef CONFIG_CIFS_POSIX
739 .unlocked_ioctl
= cifs_ioctl
,
740 #endif /* CONFIG_CIFS_POSIX */
741 .setlease
= cifs_setlease
,
744 const struct file_operations cifs_file_strict_ops
= {
745 .read
= do_sync_read
,
746 .write
= do_sync_write
,
747 .aio_read
= cifs_strict_readv
,
748 .aio_write
= cifs_strict_writev
,
750 .release
= cifs_close
,
752 .fsync
= cifs_strict_fsync
,
754 .mmap
= cifs_file_strict_mmap
,
755 .splice_read
= generic_file_splice_read
,
756 .llseek
= cifs_llseek
,
757 #ifdef CONFIG_CIFS_POSIX
758 .unlocked_ioctl
= cifs_ioctl
,
759 #endif /* CONFIG_CIFS_POSIX */
760 .setlease
= cifs_setlease
,
763 const struct file_operations cifs_file_direct_ops
= {
764 /* no aio, no readv -
765 BB reevaluate whether they can be done with directio, no cache */
766 .read
= cifs_user_read
,
767 .write
= cifs_user_write
,
769 .release
= cifs_close
,
773 .mmap
= cifs_file_mmap
,
774 .splice_read
= generic_file_splice_read
,
775 #ifdef CONFIG_CIFS_POSIX
776 .unlocked_ioctl
= cifs_ioctl
,
777 #endif /* CONFIG_CIFS_POSIX */
778 .llseek
= cifs_llseek
,
779 .setlease
= cifs_setlease
,
782 const struct file_operations cifs_file_nobrl_ops
= {
783 .read
= do_sync_read
,
784 .write
= do_sync_write
,
785 .aio_read
= generic_file_aio_read
,
786 .aio_write
= cifs_file_aio_write
,
788 .release
= cifs_close
,
791 .mmap
= cifs_file_mmap
,
792 .splice_read
= generic_file_splice_read
,
793 .llseek
= cifs_llseek
,
794 #ifdef CONFIG_CIFS_POSIX
795 .unlocked_ioctl
= cifs_ioctl
,
796 #endif /* CONFIG_CIFS_POSIX */
797 .setlease
= cifs_setlease
,
800 const struct file_operations cifs_file_strict_nobrl_ops
= {
801 .read
= do_sync_read
,
802 .write
= do_sync_write
,
803 .aio_read
= cifs_strict_readv
,
804 .aio_write
= cifs_strict_writev
,
806 .release
= cifs_close
,
807 .fsync
= cifs_strict_fsync
,
809 .mmap
= cifs_file_strict_mmap
,
810 .splice_read
= generic_file_splice_read
,
811 .llseek
= cifs_llseek
,
812 #ifdef CONFIG_CIFS_POSIX
813 .unlocked_ioctl
= cifs_ioctl
,
814 #endif /* CONFIG_CIFS_POSIX */
815 .setlease
= cifs_setlease
,
818 const struct file_operations cifs_file_direct_nobrl_ops
= {
819 /* no mmap, no aio, no readv -
820 BB reevaluate whether they can be done with directio, no cache */
821 .read
= cifs_user_read
,
822 .write
= cifs_user_write
,
824 .release
= cifs_close
,
827 .mmap
= cifs_file_mmap
,
828 .splice_read
= generic_file_splice_read
,
829 #ifdef CONFIG_CIFS_POSIX
830 .unlocked_ioctl
= cifs_ioctl
,
831 #endif /* CONFIG_CIFS_POSIX */
832 .llseek
= cifs_llseek
,
833 .setlease
= cifs_setlease
,
836 const struct file_operations cifs_dir_ops
= {
837 .readdir
= cifs_readdir
,
838 .release
= cifs_closedir
,
839 .read
= generic_read_dir
,
840 .unlocked_ioctl
= cifs_ioctl
,
841 .llseek
= generic_file_llseek
,
845 cifs_init_once(void *inode
)
847 struct cifsInodeInfo
*cifsi
= inode
;
849 inode_init_once(&cifsi
->vfs_inode
);
850 INIT_LIST_HEAD(&cifsi
->lockList
);
854 cifs_init_inodecache(void)
856 cifs_inode_cachep
= kmem_cache_create("cifs_inode_cache",
857 sizeof(struct cifsInodeInfo
),
858 0, (SLAB_RECLAIM_ACCOUNT
|
861 if (cifs_inode_cachep
== NULL
)
868 cifs_destroy_inodecache(void)
870 kmem_cache_destroy(cifs_inode_cachep
);
874 cifs_init_request_bufs(void)
876 if (CIFSMaxBufSize
< 8192) {
877 /* Buffer size can not be smaller than 2 * PATH_MAX since maximum
878 Unicode path name has to fit in any SMB/CIFS path based frames */
879 CIFSMaxBufSize
= 8192;
880 } else if (CIFSMaxBufSize
> 1024*127) {
881 CIFSMaxBufSize
= 1024 * 127;
883 CIFSMaxBufSize
&= 0x1FE00; /* Round size to even 512 byte mult*/
885 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
886 cifs_req_cachep
= kmem_cache_create("cifs_request",
888 MAX_CIFS_HDR_SIZE
, 0,
889 SLAB_HWCACHE_ALIGN
, NULL
);
890 if (cifs_req_cachep
== NULL
)
893 if (cifs_min_rcv
< 1)
895 else if (cifs_min_rcv
> 64) {
897 cERROR(1, "cifs_min_rcv set to maximum (64)");
900 cifs_req_poolp
= mempool_create_slab_pool(cifs_min_rcv
,
903 if (cifs_req_poolp
== NULL
) {
904 kmem_cache_destroy(cifs_req_cachep
);
907 /* MAX_CIFS_SMALL_BUFFER_SIZE bytes is enough for most SMB responses and
908 almost all handle based requests (but not write response, nor is it
909 sufficient for path based requests). A smaller size would have
910 been more efficient (compacting multiple slab items on one 4k page)
911 for the case in which debug was on, but this larger size allows
912 more SMBs to use small buffer alloc and is still much more
913 efficient to alloc 1 per page off the slab compared to 17K (5page)
914 alloc of large cifs buffers even when page debugging is on */
915 cifs_sm_req_cachep
= kmem_cache_create("cifs_small_rq",
916 MAX_CIFS_SMALL_BUFFER_SIZE
, 0, SLAB_HWCACHE_ALIGN
,
918 if (cifs_sm_req_cachep
== NULL
) {
919 mempool_destroy(cifs_req_poolp
);
920 kmem_cache_destroy(cifs_req_cachep
);
924 if (cifs_min_small
< 2)
926 else if (cifs_min_small
> 256) {
927 cifs_min_small
= 256;
928 cFYI(1, "cifs_min_small set to maximum (256)");
931 cifs_sm_req_poolp
= mempool_create_slab_pool(cifs_min_small
,
934 if (cifs_sm_req_poolp
== NULL
) {
935 mempool_destroy(cifs_req_poolp
);
936 kmem_cache_destroy(cifs_req_cachep
);
937 kmem_cache_destroy(cifs_sm_req_cachep
);
945 cifs_destroy_request_bufs(void)
947 mempool_destroy(cifs_req_poolp
);
948 kmem_cache_destroy(cifs_req_cachep
);
949 mempool_destroy(cifs_sm_req_poolp
);
950 kmem_cache_destroy(cifs_sm_req_cachep
);
956 cifs_mid_cachep
= kmem_cache_create("cifs_mpx_ids",
957 sizeof(struct mid_q_entry
), 0,
958 SLAB_HWCACHE_ALIGN
, NULL
);
959 if (cifs_mid_cachep
== NULL
)
962 /* 3 is a reasonable minimum number of simultaneous operations */
963 cifs_mid_poolp
= mempool_create_slab_pool(3, cifs_mid_cachep
);
964 if (cifs_mid_poolp
== NULL
) {
965 kmem_cache_destroy(cifs_mid_cachep
);
973 cifs_destroy_mids(void)
975 mempool_destroy(cifs_mid_poolp
);
976 kmem_cache_destroy(cifs_mid_cachep
);
984 INIT_LIST_HEAD(&cifs_tcp_ses_list
);
985 #ifdef CONFIG_CIFS_EXPERIMENTAL
986 INIT_LIST_HEAD(&GlobalDnotifyReqList
);
987 INIT_LIST_HEAD(&GlobalDnotifyRsp_Q
);
990 * Initialize Global counters
992 atomic_set(&sesInfoAllocCount
, 0);
993 atomic_set(&tconInfoAllocCount
, 0);
994 atomic_set(&tcpSesAllocCount
, 0);
995 atomic_set(&tcpSesReconnectCount
, 0);
996 atomic_set(&tconInfoReconnectCount
, 0);
998 atomic_set(&bufAllocCount
, 0);
999 atomic_set(&smBufAllocCount
, 0);
1000 #ifdef CONFIG_CIFS_STATS2
1001 atomic_set(&totBufAllocCount
, 0);
1002 atomic_set(&totSmBufAllocCount
, 0);
1003 #endif /* CONFIG_CIFS_STATS2 */
1005 atomic_set(&midCount
, 0);
1006 GlobalCurrentXid
= 0;
1007 GlobalTotalActiveXid
= 0;
1008 GlobalMaxActiveXid
= 0;
1009 spin_lock_init(&cifs_tcp_ses_lock
);
1010 spin_lock_init(&cifs_file_list_lock
);
1011 spin_lock_init(&GlobalMid_Lock
);
1013 if (cifs_max_pending
< 2) {
1014 cifs_max_pending
= 2;
1015 cFYI(1, "cifs_max_pending set to min of 2");
1016 } else if (cifs_max_pending
> 256) {
1017 cifs_max_pending
= 256;
1018 cFYI(1, "cifs_max_pending set to max of 256");
1021 rc
= cifs_fscache_register();
1023 goto out_clean_proc
;
1025 rc
= cifs_init_inodecache();
1027 goto out_unreg_fscache
;
1029 rc
= cifs_init_mids();
1031 goto out_destroy_inodecache
;
1033 rc
= cifs_init_request_bufs();
1035 goto out_destroy_mids
;
1037 rc
= register_filesystem(&cifs_fs_type
);
1039 goto out_destroy_request_bufs
;
1040 #ifdef CONFIG_CIFS_UPCALL
1041 rc
= register_key_type(&cifs_spnego_key_type
);
1043 goto out_unregister_filesystem
;
1048 #ifdef CONFIG_CIFS_UPCALL
1049 out_unregister_filesystem
:
1050 unregister_filesystem(&cifs_fs_type
);
1052 out_destroy_request_bufs
:
1053 cifs_destroy_request_bufs();
1055 cifs_destroy_mids();
1056 out_destroy_inodecache
:
1057 cifs_destroy_inodecache();
1059 cifs_fscache_unregister();
1068 cFYI(DBG2
, "exit_cifs");
1070 cifs_fscache_unregister();
1071 #ifdef CONFIG_CIFS_DFS_UPCALL
1072 cifs_dfs_release_automount_timer();
1074 #ifdef CONFIG_CIFS_UPCALL
1075 unregister_key_type(&cifs_spnego_key_type
);
1077 unregister_filesystem(&cifs_fs_type
);
1078 cifs_destroy_inodecache();
1079 cifs_destroy_mids();
1080 cifs_destroy_request_bufs();
1083 MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>");
1084 MODULE_LICENSE("GPL"); /* combination of LGPL + GPL source behaves as GPL */
1086 ("VFS to access servers complying with the SNIA CIFS Specification "
1087 "e.g. Samba and Windows");
1088 MODULE_VERSION(CIFS_VERSION
);
1089 module_init(init_cifs
)
1090 module_exit(exit_cifs
)