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 linuxExtEnabled
= 1;
57 unsigned int lookupCacheEnabled
= 1;
58 unsigned int multiuser_mount
= 0;
59 unsigned int global_secflags
= CIFSSEC_DEF
;
60 /* unsigned int ntlmv2_support = 0; */
61 unsigned int sign_CIFS_PDUs
= 1;
62 static const struct super_operations cifs_super_ops
;
63 unsigned int CIFSMaxBufSize
= CIFS_MAX_MSGSIZE
;
64 module_param(CIFSMaxBufSize
, int, 0);
65 MODULE_PARM_DESC(CIFSMaxBufSize
, "Network buffer size (not including header). "
66 "Default: 16384 Range: 8192 to 130048");
67 unsigned int cifs_min_rcv
= CIFS_MIN_RCV_POOL
;
68 module_param(cifs_min_rcv
, int, 0);
69 MODULE_PARM_DESC(cifs_min_rcv
, "Network buffers in pool. Default: 4 Range: "
71 unsigned int cifs_min_small
= 30;
72 module_param(cifs_min_small
, int, 0);
73 MODULE_PARM_DESC(cifs_min_small
, "Small network buffers in pool. Default: 30 "
75 unsigned int cifs_max_pending
= CIFS_MAX_REQ
;
76 module_param(cifs_max_pending
, int, 0);
77 MODULE_PARM_DESC(cifs_max_pending
, "Simultaneous requests to server. "
78 "Default: 50 Range: 2 to 256");
79 unsigned short echo_retries
= 5;
80 module_param(echo_retries
, ushort
, 0644);
81 MODULE_PARM_DESC(echo_retries
, "Number of echo attempts before giving up and "
82 "reconnecting server. Default: 5. 0 means "
84 extern mempool_t
*cifs_sm_req_poolp
;
85 extern mempool_t
*cifs_req_poolp
;
86 extern mempool_t
*cifs_mid_poolp
;
89 cifs_sb_active(struct super_block
*sb
)
91 struct cifs_sb_info
*server
= CIFS_SB(sb
);
93 if (atomic_inc_return(&server
->active
) == 1)
94 atomic_inc(&sb
->s_active
);
98 cifs_sb_deactive(struct super_block
*sb
)
100 struct cifs_sb_info
*server
= CIFS_SB(sb
);
102 if (atomic_dec_and_test(&server
->active
))
103 deactivate_super(sb
);
107 cifs_read_super(struct super_block
*sb
, void *data
,
108 const char *devname
, int silent
)
111 struct cifs_sb_info
*cifs_sb
;
114 /* BB should we make this contingent on mount parm? */
115 sb
->s_flags
|= MS_NODIRATIME
| MS_NOATIME
;
116 sb
->s_fs_info
= kzalloc(sizeof(struct cifs_sb_info
), GFP_KERNEL
);
117 cifs_sb
= CIFS_SB(sb
);
121 spin_lock_init(&cifs_sb
->tlink_tree_lock
);
122 cifs_sb
->tlink_tree
= RB_ROOT
;
124 rc
= bdi_setup_and_register(&cifs_sb
->bdi
, "cifs", BDI_CAP_MAP_COPY
);
129 cifs_sb
->bdi
.ra_pages
= default_backing_dev_info
.ra_pages
;
132 * Copy mount params to sb for use in submounts. Better to do
133 * the copy here and deal with the error before cleanup gets
134 * complicated post-mount.
137 cifs_sb
->mountdata
= kstrndup(data
, PAGE_SIZE
, GFP_KERNEL
);
138 if (cifs_sb
->mountdata
== NULL
) {
139 bdi_destroy(&cifs_sb
->bdi
);
140 kfree(sb
->s_fs_info
);
141 sb
->s_fs_info
= NULL
;
146 rc
= cifs_mount(sb
, cifs_sb
, devname
);
150 cERROR(1, "cifs_mount failed w/return code = %d", rc
);
151 goto out_mount_failed
;
154 sb
->s_magic
= CIFS_MAGIC_NUMBER
;
155 sb
->s_op
= &cifs_super_ops
;
156 sb
->s_bdi
= &cifs_sb
->bdi
;
157 sb
->s_blocksize
= CIFS_MAX_MSGSIZE
;
158 sb
->s_blocksize_bits
= 14; /* default 2**14 = CIFS_MAX_MSGSIZE */
159 inode
= cifs_root_iget(sb
);
167 sb
->s_root
= d_alloc_root(inode
);
174 /* do that *after* d_alloc_root() - we want NULL ->d_op for root here */
175 if (cifs_sb_master_tcon(cifs_sb
)->nocase
)
176 sb
->s_d_op
= &cifs_ci_dentry_ops
;
178 sb
->s_d_op
= &cifs_dentry_ops
;
180 #ifdef CIFS_NFSD_EXPORT
181 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_SERVER_INUM
) {
182 cFYI(1, "export ops supported");
183 sb
->s_export_op
= &cifs_export_ops
;
185 #endif /* CIFS_NFSD_EXPORT */
190 cERROR(1, "cifs_read_super: get root inode failed");
194 cifs_umount(sb
, cifs_sb
);
198 if (cifs_sb
->mountdata
) {
199 kfree(cifs_sb
->mountdata
);
200 cifs_sb
->mountdata
= NULL
;
202 unload_nls(cifs_sb
->local_nls
);
203 bdi_destroy(&cifs_sb
->bdi
);
210 cifs_put_super(struct super_block
*sb
)
213 struct cifs_sb_info
*cifs_sb
;
215 cFYI(1, "In cifs_put_super");
216 cifs_sb
= CIFS_SB(sb
);
217 if (cifs_sb
== NULL
) {
218 cFYI(1, "Empty cifs superblock info passed to unmount");
222 rc
= cifs_umount(sb
, cifs_sb
);
224 cERROR(1, "cifs_umount failed with return code %d", rc
);
225 if (cifs_sb
->mountdata
) {
226 kfree(cifs_sb
->mountdata
);
227 cifs_sb
->mountdata
= NULL
;
230 unload_nls(cifs_sb
->local_nls
);
231 bdi_destroy(&cifs_sb
->bdi
);
236 cifs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
238 struct super_block
*sb
= dentry
->d_sb
;
239 struct cifs_sb_info
*cifs_sb
= CIFS_SB(sb
);
240 struct cifsTconInfo
*tcon
= cifs_sb_master_tcon(cifs_sb
);
241 int rc
= -EOPNOTSUPP
;
246 buf
->f_type
= CIFS_MAGIC_NUMBER
;
249 * PATH_MAX may be too long - it would presumably be total path,
250 * but note that some servers (includinng Samba 3) have a shorter
253 * Instead could get the real value via SMB_QUERY_FS_ATTRIBUTE_INFO.
255 buf
->f_namelen
= PATH_MAX
;
256 buf
->f_files
= 0; /* undefined */
257 buf
->f_ffree
= 0; /* unlimited */
260 * We could add a second check for a QFS Unix capability bit
262 if ((tcon
->ses
->capabilities
& CAP_UNIX
) &&
263 (CIFS_POSIX_EXTENSIONS
& le64_to_cpu(tcon
->fsUnixInfo
.Capability
)))
264 rc
= CIFSSMBQFSPosixInfo(xid
, tcon
, buf
);
267 * Only need to call the old QFSInfo if failed on newer one,
270 if (rc
&& (tcon
->ses
->capabilities
& CAP_NT_SMBS
))
271 rc
= CIFSSMBQFSInfo(xid
, tcon
, buf
);
274 * Some old Windows servers also do not support level 103, retry with
275 * older level one if old server failed the previous call or we
276 * bypassed it because we detected that this was an older LANMAN sess
279 rc
= SMBOldQFSInfo(xid
, tcon
, buf
);
285 static int cifs_permission(struct inode
*inode
, int mask
, unsigned int flags
)
287 struct cifs_sb_info
*cifs_sb
;
289 if (flags
& IPERM_FLAG_RCU
)
292 cifs_sb
= CIFS_SB(inode
->i_sb
);
294 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_NO_PERM
) {
295 if ((mask
& MAY_EXEC
) && !execute_ok(inode
))
299 } else /* file mode might have been restricted at mount time
300 on the client (above and beyond ACL on servers) for
301 servers which do not support setting and viewing mode bits,
302 so allowing client to check permissions is useful */
303 return generic_permission(inode
, mask
, flags
, NULL
);
306 static struct kmem_cache
*cifs_inode_cachep
;
307 static struct kmem_cache
*cifs_req_cachep
;
308 static struct kmem_cache
*cifs_mid_cachep
;
309 static struct kmem_cache
*cifs_sm_req_cachep
;
310 mempool_t
*cifs_sm_req_poolp
;
311 mempool_t
*cifs_req_poolp
;
312 mempool_t
*cifs_mid_poolp
;
314 static struct inode
*
315 cifs_alloc_inode(struct super_block
*sb
)
317 struct cifsInodeInfo
*cifs_inode
;
318 cifs_inode
= kmem_cache_alloc(cifs_inode_cachep
, GFP_KERNEL
);
321 cifs_inode
->cifsAttrs
= 0x20; /* default */
322 cifs_inode
->time
= 0;
323 /* Until the file is open and we have gotten oplock
324 info back from the server, can not assume caching of
325 file data or metadata */
326 cifs_set_oplock_level(cifs_inode
, 0);
327 cifs_inode
->delete_pending
= false;
328 cifs_inode
->invalid_mapping
= false;
329 cifs_inode
->vfs_inode
.i_blkbits
= 14; /* 2**14 = CIFS_MAX_MSGSIZE */
330 cifs_inode
->server_eof
= 0;
331 cifs_inode
->uniqueid
= 0;
332 cifs_inode
->createtime
= 0;
334 /* Can not set i_flags here - they get immediately overwritten
335 to zero by the VFS */
336 /* cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME;*/
337 INIT_LIST_HEAD(&cifs_inode
->openFileList
);
338 return &cifs_inode
->vfs_inode
;
341 static void cifs_i_callback(struct rcu_head
*head
)
343 struct inode
*inode
= container_of(head
, struct inode
, i_rcu
);
344 INIT_LIST_HEAD(&inode
->i_dentry
);
345 kmem_cache_free(cifs_inode_cachep
, CIFS_I(inode
));
349 cifs_destroy_inode(struct inode
*inode
)
351 call_rcu(&inode
->i_rcu
, cifs_i_callback
);
355 cifs_evict_inode(struct inode
*inode
)
357 truncate_inode_pages(&inode
->i_data
, 0);
358 end_writeback(inode
);
359 cifs_fscache_release_inode_cookie(inode
);
363 cifs_show_address(struct seq_file
*s
, struct TCP_Server_Info
*server
)
365 struct sockaddr_in
*sa
= (struct sockaddr_in
*) &server
->dstaddr
;
366 struct sockaddr_in6
*sa6
= (struct sockaddr_in6
*) &server
->dstaddr
;
368 seq_printf(s
, ",addr=");
370 switch (server
->dstaddr
.ss_family
) {
372 seq_printf(s
, "%pI4", &sa
->sin_addr
.s_addr
);
375 seq_printf(s
, "%pI6", &sa6
->sin6_addr
.s6_addr
);
376 if (sa6
->sin6_scope_id
)
377 seq_printf(s
, "%%%u", sa6
->sin6_scope_id
);
380 seq_printf(s
, "(unknown)");
385 * cifs_show_options() is for displaying mount options in /proc/mounts.
386 * Not all settable options are displayed but most of the important
390 cifs_show_options(struct seq_file
*s
, struct vfsmount
*m
)
392 struct cifs_sb_info
*cifs_sb
= CIFS_SB(m
->mnt_sb
);
393 struct cifsTconInfo
*tcon
= cifs_sb_master_tcon(cifs_sb
);
394 struct sockaddr
*srcaddr
;
395 srcaddr
= (struct sockaddr
*)&tcon
->ses
->server
->srcaddr
;
397 seq_printf(s
, ",unc=%s", tcon
->treeName
);
399 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_MULTIUSER
)
400 seq_printf(s
, ",multiuser");
401 else if (tcon
->ses
->user_name
)
402 seq_printf(s
, ",username=%s", tcon
->ses
->user_name
);
404 if (tcon
->ses
->domainName
)
405 seq_printf(s
, ",domain=%s", tcon
->ses
->domainName
);
407 if (srcaddr
->sa_family
!= AF_UNSPEC
) {
408 struct sockaddr_in
*saddr4
;
409 struct sockaddr_in6
*saddr6
;
410 saddr4
= (struct sockaddr_in
*)srcaddr
;
411 saddr6
= (struct sockaddr_in6
*)srcaddr
;
412 if (srcaddr
->sa_family
== AF_INET6
)
413 seq_printf(s
, ",srcaddr=%pI6c",
415 else if (srcaddr
->sa_family
== AF_INET
)
416 seq_printf(s
, ",srcaddr=%pI4",
417 &saddr4
->sin_addr
.s_addr
);
419 seq_printf(s
, ",srcaddr=BAD-AF:%i",
420 (int)(srcaddr
->sa_family
));
423 seq_printf(s
, ",uid=%d", cifs_sb
->mnt_uid
);
424 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_OVERR_UID
)
425 seq_printf(s
, ",forceuid");
427 seq_printf(s
, ",noforceuid");
429 seq_printf(s
, ",gid=%d", cifs_sb
->mnt_gid
);
430 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_OVERR_GID
)
431 seq_printf(s
, ",forcegid");
433 seq_printf(s
, ",noforcegid");
435 cifs_show_address(s
, tcon
->ses
->server
);
438 seq_printf(s
, ",file_mode=0%o,dir_mode=0%o",
439 cifs_sb
->mnt_file_mode
,
440 cifs_sb
->mnt_dir_mode
);
442 seq_printf(s
, ",seal");
444 seq_printf(s
, ",nocase");
446 seq_printf(s
, ",hard");
447 if (cifs_sb
->prepath
)
448 seq_printf(s
, ",prepath=%s", cifs_sb
->prepath
);
449 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_POSIX_PATHS
)
450 seq_printf(s
, ",posixpaths");
451 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_SET_UID
)
452 seq_printf(s
, ",setuids");
453 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_SERVER_INUM
)
454 seq_printf(s
, ",serverino");
455 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_DIRECT_IO
)
456 seq_printf(s
, ",directio");
457 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_NO_XATTR
)
458 seq_printf(s
, ",nouser_xattr");
459 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_MAP_SPECIAL_CHR
)
460 seq_printf(s
, ",mapchars");
461 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_UNX_EMUL
)
462 seq_printf(s
, ",sfu");
463 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_NO_BRL
)
464 seq_printf(s
, ",nobrl");
465 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_CIFS_ACL
)
466 seq_printf(s
, ",cifsacl");
467 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_DYNPERM
)
468 seq_printf(s
, ",dynperm");
469 if (m
->mnt_sb
->s_flags
& MS_POSIXACL
)
470 seq_printf(s
, ",acl");
471 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_MF_SYMLINKS
)
472 seq_printf(s
, ",mfsymlinks");
473 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_FSCACHE
)
474 seq_printf(s
, ",fsc");
476 seq_printf(s
, ",rsize=%d", cifs_sb
->rsize
);
477 seq_printf(s
, ",wsize=%d", cifs_sb
->wsize
);
478 /* convert actimeo and display it in seconds */
479 seq_printf(s
, ",actimeo=%lu", cifs_sb
->actimeo
/ HZ
);
484 static void cifs_umount_begin(struct super_block
*sb
)
486 struct cifs_sb_info
*cifs_sb
= CIFS_SB(sb
);
487 struct cifsTconInfo
*tcon
;
492 tcon
= cifs_sb_master_tcon(cifs_sb
);
494 spin_lock(&cifs_tcp_ses_lock
);
495 if ((tcon
->tc_count
> 1) || (tcon
->tidStatus
== CifsExiting
)) {
496 /* we have other mounts to same share or we have
497 already tried to force umount this and woken up
498 all waiting network requests, nothing to do */
499 spin_unlock(&cifs_tcp_ses_lock
);
501 } else if (tcon
->tc_count
== 1)
502 tcon
->tidStatus
= CifsExiting
;
503 spin_unlock(&cifs_tcp_ses_lock
);
505 /* cancel_brl_requests(tcon); */ /* BB mark all brl mids as exiting */
506 /* cancel_notify_requests(tcon); */
507 if (tcon
->ses
&& tcon
->ses
->server
) {
508 cFYI(1, "wake up tasks now - umount begin not complete");
509 wake_up_all(&tcon
->ses
->server
->request_q
);
510 wake_up_all(&tcon
->ses
->server
->response_q
);
511 msleep(1); /* yield */
512 /* we have to kick the requests once more */
513 wake_up_all(&tcon
->ses
->server
->response_q
);
520 #ifdef CONFIG_CIFS_STATS2
521 static int cifs_show_stats(struct seq_file
*s
, struct vfsmount
*mnt
)
528 static int cifs_remount(struct super_block
*sb
, int *flags
, char *data
)
530 *flags
|= MS_NODIRATIME
;
534 static int cifs_drop_inode(struct inode
*inode
)
536 struct cifs_sb_info
*cifs_sb
= CIFS_SB(inode
->i_sb
);
538 /* no serverino => unconditional eviction */
539 return !(cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_SERVER_INUM
) ||
540 generic_drop_inode(inode
);
543 static const struct super_operations cifs_super_ops
= {
544 .put_super
= cifs_put_super
,
545 .statfs
= cifs_statfs
,
546 .alloc_inode
= cifs_alloc_inode
,
547 .destroy_inode
= cifs_destroy_inode
,
548 .drop_inode
= cifs_drop_inode
,
549 .evict_inode
= cifs_evict_inode
,
550 /* .delete_inode = cifs_delete_inode, */ /* Do not need above
551 function unless later we add lazy close of inodes or unless the
552 kernel forgets to call us with the same number of releases (closes)
554 .show_options
= cifs_show_options
,
555 .umount_begin
= cifs_umount_begin
,
556 .remount_fs
= cifs_remount
,
557 #ifdef CONFIG_CIFS_STATS2
558 .show_stats
= cifs_show_stats
,
562 static struct dentry
*
563 cifs_do_mount(struct file_system_type
*fs_type
,
564 int flags
, const char *dev_name
, void *data
)
567 struct super_block
*sb
;
569 sb
= sget(fs_type
, NULL
, set_anon_super
, NULL
);
571 cFYI(1, "Devname: %s flags: %d ", dev_name
, flags
);
578 rc
= cifs_read_super(sb
, data
, dev_name
, flags
& MS_SILENT
? 1 : 0);
580 deactivate_locked_super(sb
);
583 sb
->s_flags
|= MS_ACTIVE
;
584 return dget(sb
->s_root
);
587 static ssize_t
cifs_file_aio_write(struct kiocb
*iocb
, const struct iovec
*iov
,
588 unsigned long nr_segs
, loff_t pos
)
590 struct inode
*inode
= iocb
->ki_filp
->f_path
.dentry
->d_inode
;
594 written
= generic_file_aio_write(iocb
, iov
, nr_segs
, pos
);
596 if (CIFS_I(inode
)->clientCanCacheAll
)
599 rc
= filemap_fdatawrite(inode
->i_mapping
);
601 cFYI(1, "cifs_file_aio_write: %d rc on %p inode", rc
, inode
);
606 static loff_t
cifs_llseek(struct file
*file
, loff_t offset
, int origin
)
608 /* origin == SEEK_END => we must revalidate the cached file length */
609 if (origin
== SEEK_END
) {
611 struct inode
*inode
= file
->f_path
.dentry
->d_inode
;
614 * We need to be sure that all dirty pages are written and the
615 * server has the newest file length.
617 if (!CIFS_I(inode
)->clientCanCacheRead
&& inode
->i_mapping
&&
618 inode
->i_mapping
->nrpages
!= 0) {
619 rc
= filemap_fdatawait(inode
->i_mapping
);
621 mapping_set_error(inode
->i_mapping
, rc
);
626 * Some applications poll for the file length in this strange
627 * way so we must seek to end on non-oplocked files by
628 * setting the revalidate time to zero.
630 CIFS_I(inode
)->time
= 0;
632 rc
= cifs_revalidate_file_attr(file
);
636 return generic_file_llseek_unlocked(file
, offset
, origin
);
639 static int cifs_setlease(struct file
*file
, long arg
, struct file_lock
**lease
)
641 /* note that this is called by vfs setlease with lock_flocks held
642 to protect *lease from going away */
643 struct inode
*inode
= file
->f_path
.dentry
->d_inode
;
644 struct cifsFileInfo
*cfile
= file
->private_data
;
646 if (!(S_ISREG(inode
->i_mode
)))
649 /* check if file is oplocked */
650 if (((arg
== F_RDLCK
) &&
651 (CIFS_I(inode
)->clientCanCacheRead
)) ||
653 (CIFS_I(inode
)->clientCanCacheAll
)))
654 return generic_setlease(file
, arg
, lease
);
655 else if (tlink_tcon(cfile
->tlink
)->local_lease
&&
656 !CIFS_I(inode
)->clientCanCacheRead
)
657 /* If the server claims to support oplock on this
658 file, then we still need to check oplock even
659 if the local_lease mount option is set, but there
660 are servers which do not support oplock for which
661 this mount option may be useful if the user
662 knows that the file won't be changed on the server
664 return generic_setlease(file
, arg
, lease
);
669 struct file_system_type cifs_fs_type
= {
670 .owner
= THIS_MODULE
,
672 .mount
= cifs_do_mount
,
673 .kill_sb
= kill_anon_super
,
676 const struct inode_operations cifs_dir_inode_ops
= {
677 .create
= cifs_create
,
678 .lookup
= cifs_lookup
,
679 .getattr
= cifs_getattr
,
680 .unlink
= cifs_unlink
,
681 .link
= cifs_hardlink
,
684 .rename
= cifs_rename
,
685 .permission
= cifs_permission
,
686 /* revalidate:cifs_revalidate, */
687 .setattr
= cifs_setattr
,
688 .symlink
= cifs_symlink
,
690 #ifdef CONFIG_CIFS_XATTR
691 .setxattr
= cifs_setxattr
,
692 .getxattr
= cifs_getxattr
,
693 .listxattr
= cifs_listxattr
,
694 .removexattr
= cifs_removexattr
,
698 const struct inode_operations cifs_file_inode_ops
= {
699 /* revalidate:cifs_revalidate, */
700 .setattr
= cifs_setattr
,
701 .getattr
= cifs_getattr
, /* do we need this anymore? */
702 .rename
= cifs_rename
,
703 .permission
= cifs_permission
,
704 #ifdef CONFIG_CIFS_XATTR
705 .setxattr
= cifs_setxattr
,
706 .getxattr
= cifs_getxattr
,
707 .listxattr
= cifs_listxattr
,
708 .removexattr
= cifs_removexattr
,
712 const struct inode_operations cifs_symlink_inode_ops
= {
713 .readlink
= generic_readlink
,
714 .follow_link
= cifs_follow_link
,
715 .put_link
= cifs_put_link
,
716 .permission
= cifs_permission
,
717 /* BB add the following two eventually */
718 /* revalidate: cifs_revalidate,
719 setattr: cifs_notify_change, *//* BB do we need notify change */
720 #ifdef CONFIG_CIFS_XATTR
721 .setxattr
= cifs_setxattr
,
722 .getxattr
= cifs_getxattr
,
723 .listxattr
= cifs_listxattr
,
724 .removexattr
= cifs_removexattr
,
728 const struct file_operations cifs_file_ops
= {
729 .read
= do_sync_read
,
730 .write
= do_sync_write
,
731 .aio_read
= generic_file_aio_read
,
732 .aio_write
= cifs_file_aio_write
,
734 .release
= cifs_close
,
738 .mmap
= cifs_file_mmap
,
739 .splice_read
= generic_file_splice_read
,
740 .llseek
= cifs_llseek
,
741 #ifdef CONFIG_CIFS_POSIX
742 .unlocked_ioctl
= cifs_ioctl
,
743 #endif /* CONFIG_CIFS_POSIX */
744 .setlease
= cifs_setlease
,
747 const struct file_operations cifs_file_strict_ops
= {
748 .read
= do_sync_read
,
749 .write
= do_sync_write
,
750 .aio_read
= cifs_strict_readv
,
751 .aio_write
= cifs_strict_writev
,
753 .release
= cifs_close
,
755 .fsync
= cifs_strict_fsync
,
757 .mmap
= cifs_file_strict_mmap
,
758 .splice_read
= generic_file_splice_read
,
759 .llseek
= cifs_llseek
,
760 #ifdef CONFIG_CIFS_POSIX
761 .unlocked_ioctl
= cifs_ioctl
,
762 #endif /* CONFIG_CIFS_POSIX */
763 .setlease
= cifs_setlease
,
766 const struct file_operations cifs_file_direct_ops
= {
767 /* BB reevaluate whether they can be done with directio, no cache */
768 .read
= do_sync_read
,
769 .write
= do_sync_write
,
770 .aio_read
= cifs_user_readv
,
771 .aio_write
= cifs_user_writev
,
773 .release
= cifs_close
,
777 .mmap
= cifs_file_mmap
,
778 .splice_read
= generic_file_splice_read
,
779 #ifdef CONFIG_CIFS_POSIX
780 .unlocked_ioctl
= cifs_ioctl
,
781 #endif /* CONFIG_CIFS_POSIX */
782 .llseek
= cifs_llseek
,
783 .setlease
= cifs_setlease
,
786 const struct file_operations cifs_file_nobrl_ops
= {
787 .read
= do_sync_read
,
788 .write
= do_sync_write
,
789 .aio_read
= generic_file_aio_read
,
790 .aio_write
= cifs_file_aio_write
,
792 .release
= cifs_close
,
795 .mmap
= cifs_file_mmap
,
796 .splice_read
= generic_file_splice_read
,
797 .llseek
= cifs_llseek
,
798 #ifdef CONFIG_CIFS_POSIX
799 .unlocked_ioctl
= cifs_ioctl
,
800 #endif /* CONFIG_CIFS_POSIX */
801 .setlease
= cifs_setlease
,
804 const struct file_operations cifs_file_strict_nobrl_ops
= {
805 .read
= do_sync_read
,
806 .write
= do_sync_write
,
807 .aio_read
= cifs_strict_readv
,
808 .aio_write
= cifs_strict_writev
,
810 .release
= cifs_close
,
811 .fsync
= cifs_strict_fsync
,
813 .mmap
= cifs_file_strict_mmap
,
814 .splice_read
= generic_file_splice_read
,
815 .llseek
= cifs_llseek
,
816 #ifdef CONFIG_CIFS_POSIX
817 .unlocked_ioctl
= cifs_ioctl
,
818 #endif /* CONFIG_CIFS_POSIX */
819 .setlease
= cifs_setlease
,
822 const struct file_operations cifs_file_direct_nobrl_ops
= {
823 /* BB reevaluate whether they can be done with directio, no cache */
824 .read
= do_sync_read
,
825 .write
= do_sync_write
,
826 .aio_read
= cifs_user_readv
,
827 .aio_write
= cifs_user_writev
,
829 .release
= cifs_close
,
832 .mmap
= cifs_file_mmap
,
833 .splice_read
= generic_file_splice_read
,
834 #ifdef CONFIG_CIFS_POSIX
835 .unlocked_ioctl
= cifs_ioctl
,
836 #endif /* CONFIG_CIFS_POSIX */
837 .llseek
= cifs_llseek
,
838 .setlease
= cifs_setlease
,
841 const struct file_operations cifs_dir_ops
= {
842 .readdir
= cifs_readdir
,
843 .release
= cifs_closedir
,
844 .read
= generic_read_dir
,
845 .unlocked_ioctl
= cifs_ioctl
,
846 .llseek
= generic_file_llseek
,
850 cifs_init_once(void *inode
)
852 struct cifsInodeInfo
*cifsi
= inode
;
854 inode_init_once(&cifsi
->vfs_inode
);
855 INIT_LIST_HEAD(&cifsi
->lockList
);
859 cifs_init_inodecache(void)
861 cifs_inode_cachep
= kmem_cache_create("cifs_inode_cache",
862 sizeof(struct cifsInodeInfo
),
863 0, (SLAB_RECLAIM_ACCOUNT
|
866 if (cifs_inode_cachep
== NULL
)
873 cifs_destroy_inodecache(void)
875 kmem_cache_destroy(cifs_inode_cachep
);
879 cifs_init_request_bufs(void)
881 if (CIFSMaxBufSize
< 8192) {
882 /* Buffer size can not be smaller than 2 * PATH_MAX since maximum
883 Unicode path name has to fit in any SMB/CIFS path based frames */
884 CIFSMaxBufSize
= 8192;
885 } else if (CIFSMaxBufSize
> 1024*127) {
886 CIFSMaxBufSize
= 1024 * 127;
888 CIFSMaxBufSize
&= 0x1FE00; /* Round size to even 512 byte mult*/
890 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
891 cifs_req_cachep
= kmem_cache_create("cifs_request",
893 MAX_CIFS_HDR_SIZE
, 0,
894 SLAB_HWCACHE_ALIGN
, NULL
);
895 if (cifs_req_cachep
== NULL
)
898 if (cifs_min_rcv
< 1)
900 else if (cifs_min_rcv
> 64) {
902 cERROR(1, "cifs_min_rcv set to maximum (64)");
905 cifs_req_poolp
= mempool_create_slab_pool(cifs_min_rcv
,
908 if (cifs_req_poolp
== NULL
) {
909 kmem_cache_destroy(cifs_req_cachep
);
912 /* MAX_CIFS_SMALL_BUFFER_SIZE bytes is enough for most SMB responses and
913 almost all handle based requests (but not write response, nor is it
914 sufficient for path based requests). A smaller size would have
915 been more efficient (compacting multiple slab items on one 4k page)
916 for the case in which debug was on, but this larger size allows
917 more SMBs to use small buffer alloc and is still much more
918 efficient to alloc 1 per page off the slab compared to 17K (5page)
919 alloc of large cifs buffers even when page debugging is on */
920 cifs_sm_req_cachep
= kmem_cache_create("cifs_small_rq",
921 MAX_CIFS_SMALL_BUFFER_SIZE
, 0, SLAB_HWCACHE_ALIGN
,
923 if (cifs_sm_req_cachep
== NULL
) {
924 mempool_destroy(cifs_req_poolp
);
925 kmem_cache_destroy(cifs_req_cachep
);
929 if (cifs_min_small
< 2)
931 else if (cifs_min_small
> 256) {
932 cifs_min_small
= 256;
933 cFYI(1, "cifs_min_small set to maximum (256)");
936 cifs_sm_req_poolp
= mempool_create_slab_pool(cifs_min_small
,
939 if (cifs_sm_req_poolp
== NULL
) {
940 mempool_destroy(cifs_req_poolp
);
941 kmem_cache_destroy(cifs_req_cachep
);
942 kmem_cache_destroy(cifs_sm_req_cachep
);
950 cifs_destroy_request_bufs(void)
952 mempool_destroy(cifs_req_poolp
);
953 kmem_cache_destroy(cifs_req_cachep
);
954 mempool_destroy(cifs_sm_req_poolp
);
955 kmem_cache_destroy(cifs_sm_req_cachep
);
961 cifs_mid_cachep
= kmem_cache_create("cifs_mpx_ids",
962 sizeof(struct mid_q_entry
), 0,
963 SLAB_HWCACHE_ALIGN
, NULL
);
964 if (cifs_mid_cachep
== NULL
)
967 /* 3 is a reasonable minimum number of simultaneous operations */
968 cifs_mid_poolp
= mempool_create_slab_pool(3, cifs_mid_cachep
);
969 if (cifs_mid_poolp
== NULL
) {
970 kmem_cache_destroy(cifs_mid_cachep
);
978 cifs_destroy_mids(void)
980 mempool_destroy(cifs_mid_poolp
);
981 kmem_cache_destroy(cifs_mid_cachep
);
989 INIT_LIST_HEAD(&cifs_tcp_ses_list
);
990 #ifdef CONFIG_CIFS_DNOTIFY_EXPERIMENTAL /* unused temporarily */
991 INIT_LIST_HEAD(&GlobalDnotifyReqList
);
992 INIT_LIST_HEAD(&GlobalDnotifyRsp_Q
);
993 #endif /* was needed for dnotify, and will be needed for inotify when VFS fix */
995 * Initialize Global counters
997 atomic_set(&sesInfoAllocCount
, 0);
998 atomic_set(&tconInfoAllocCount
, 0);
999 atomic_set(&tcpSesAllocCount
, 0);
1000 atomic_set(&tcpSesReconnectCount
, 0);
1001 atomic_set(&tconInfoReconnectCount
, 0);
1003 atomic_set(&bufAllocCount
, 0);
1004 atomic_set(&smBufAllocCount
, 0);
1005 #ifdef CONFIG_CIFS_STATS2
1006 atomic_set(&totBufAllocCount
, 0);
1007 atomic_set(&totSmBufAllocCount
, 0);
1008 #endif /* CONFIG_CIFS_STATS2 */
1010 atomic_set(&midCount
, 0);
1011 GlobalCurrentXid
= 0;
1012 GlobalTotalActiveXid
= 0;
1013 GlobalMaxActiveXid
= 0;
1014 spin_lock_init(&cifs_tcp_ses_lock
);
1015 spin_lock_init(&cifs_file_list_lock
);
1016 spin_lock_init(&GlobalMid_Lock
);
1018 if (cifs_max_pending
< 2) {
1019 cifs_max_pending
= 2;
1020 cFYI(1, "cifs_max_pending set to min of 2");
1021 } else if (cifs_max_pending
> 256) {
1022 cifs_max_pending
= 256;
1023 cFYI(1, "cifs_max_pending set to max of 256");
1026 rc
= cifs_fscache_register();
1028 goto out_clean_proc
;
1030 rc
= cifs_init_inodecache();
1032 goto out_unreg_fscache
;
1034 rc
= cifs_init_mids();
1036 goto out_destroy_inodecache
;
1038 rc
= cifs_init_request_bufs();
1040 goto out_destroy_mids
;
1042 #ifdef CONFIG_CIFS_UPCALL
1043 rc
= register_key_type(&cifs_spnego_key_type
);
1045 goto out_destroy_request_bufs
;
1046 #endif /* CONFIG_CIFS_UPCALL */
1048 #ifdef CONFIG_CIFS_ACL
1049 rc
= init_cifs_idmap();
1051 goto out_register_key_type
;
1052 #endif /* CONFIG_CIFS_ACL */
1054 rc
= register_filesystem(&cifs_fs_type
);
1056 goto out_init_cifs_idmap
;
1060 out_init_cifs_idmap
:
1061 #ifdef CONFIG_CIFS_ACL
1063 out_register_key_type
:
1065 #ifdef CONFIG_CIFS_UPCALL
1066 unregister_key_type(&cifs_spnego_key_type
);
1067 out_destroy_request_bufs
:
1069 cifs_destroy_request_bufs();
1071 cifs_destroy_mids();
1072 out_destroy_inodecache
:
1073 cifs_destroy_inodecache();
1075 cifs_fscache_unregister();
1084 cFYI(DBG2
, "exit_cifs");
1086 cifs_fscache_unregister();
1087 #ifdef CONFIG_CIFS_DFS_UPCALL
1088 cifs_dfs_release_automount_timer();
1090 #ifdef CONFIG_CIFS_ACL
1091 cifs_destroy_idmaptrees();
1094 #ifdef CONFIG_CIFS_UPCALL
1095 unregister_key_type(&cifs_spnego_key_type
);
1097 unregister_filesystem(&cifs_fs_type
);
1098 cifs_destroy_inodecache();
1099 cifs_destroy_mids();
1100 cifs_destroy_request_bufs();
1103 MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>");
1104 MODULE_LICENSE("GPL"); /* combination of LGPL + GPL source behaves as GPL */
1106 ("VFS to access servers complying with the SNIA CIFS Specification "
1107 "e.g. Samba and Windows");
1108 MODULE_VERSION(CIFS_VERSION
);
1109 module_init(init_cifs
)
1110 module_exit(exit_cifs
)