Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / fs / cifs / cifsfs.c
blob285a575163ca3a5e70eae6f77080aaa4506e904b
1 /*
2 * fs/cifs/cifsfs.c
4 * Copyright (C) International Business Machines Corp., 2002,2007
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>
27 #include <linux/fs.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 "cifsfs.h"
39 #include "cifspdu.h"
40 #define DECLARE_GLOBALS_HERE
41 #include "cifsglob.h"
42 #include "cifsproto.h"
43 #include "cifs_debug.h"
44 #include "cifs_fs_sb.h"
45 #include <linux/mm.h>
46 #include <linux/key-type.h>
47 #include "dns_resolve.h"
48 #include "cifs_spnego.h"
49 #define CIFS_MAGIC_NUMBER 0xFF534D42 /* the first four bytes of SMB PDUs */
51 #ifdef CONFIG_CIFS_QUOTA
52 static struct quotactl_ops cifs_quotactl_ops;
53 #endif /* QUOTA */
55 int cifsFYI = 0;
56 int cifsERROR = 1;
57 int traceSMB = 0;
58 unsigned int oplockEnabled = 1;
59 unsigned int experimEnabled = 0;
60 unsigned int linuxExtEnabled = 1;
61 unsigned int lookupCacheEnabled = 1;
62 unsigned int multiuser_mount = 0;
63 unsigned int extended_security = CIFSSEC_DEF;
64 /* unsigned int ntlmv2_support = 0; */
65 unsigned int sign_CIFS_PDUs = 1;
66 extern struct task_struct *oplockThread; /* remove sparse warning */
67 struct task_struct *oplockThread = NULL;
68 /* extern struct task_struct * dnotifyThread; remove sparse warning */
69 static struct task_struct *dnotifyThread = NULL;
70 static const struct super_operations cifs_super_ops;
71 unsigned int CIFSMaxBufSize = CIFS_MAX_MSGSIZE;
72 module_param(CIFSMaxBufSize, int, 0);
73 MODULE_PARM_DESC(CIFSMaxBufSize, "Network buffer size (not including header). "
74 "Default: 16384 Range: 8192 to 130048");
75 unsigned int cifs_min_rcv = CIFS_MIN_RCV_POOL;
76 module_param(cifs_min_rcv, int, 0);
77 MODULE_PARM_DESC(cifs_min_rcv, "Network buffers in pool. Default: 4 Range: "
78 "1 to 64");
79 unsigned int cifs_min_small = 30;
80 module_param(cifs_min_small, int, 0);
81 MODULE_PARM_DESC(cifs_min_small, "Small network buffers in pool. Default: 30 "
82 "Range: 2 to 256");
83 unsigned int cifs_max_pending = CIFS_MAX_REQ;
84 module_param(cifs_max_pending, int, 0);
85 MODULE_PARM_DESC(cifs_max_pending, "Simultaneous requests to server. "
86 "Default: 50 Range: 2 to 256");
88 extern mempool_t *cifs_sm_req_poolp;
89 extern mempool_t *cifs_req_poolp;
90 extern mempool_t *cifs_mid_poolp;
92 extern struct kmem_cache *cifs_oplock_cachep;
94 static int
95 cifs_read_super(struct super_block *sb, void *data,
96 const char *devname, int silent)
98 struct inode *inode;
99 struct cifs_sb_info *cifs_sb;
100 #ifdef CONFIG_CIFS_DFS_UPCALL
101 int len;
102 #endif
103 int rc = 0;
105 /* BB should we make this contingent on mount parm? */
106 sb->s_flags |= MS_NODIRATIME | MS_NOATIME;
107 sb->s_fs_info = kzalloc(sizeof(struct cifs_sb_info), GFP_KERNEL);
108 cifs_sb = CIFS_SB(sb);
109 if (cifs_sb == NULL)
110 return -ENOMEM;
112 #ifdef CONFIG_CIFS_DFS_UPCALL
113 /* copy mount params to sb for use in submounts */
114 /* BB: should we move this after the mount so we
115 * do not have to do the copy on failed mounts?
116 * BB: May be it is better to do simple copy before
117 * complex operation (mount), and in case of fail
118 * just exit instead of doing mount and attempting
119 * undo it if this copy fails?*/
120 len = strlen(data);
121 cifs_sb->mountdata = kzalloc(len + 1, GFP_KERNEL);
122 if (cifs_sb->mountdata == NULL) {
123 kfree(sb->s_fs_info);
124 sb->s_fs_info = NULL;
125 return -ENOMEM;
127 strncpy(cifs_sb->mountdata, data, len + 1);
128 cifs_sb->mountdata[len] = '\0';
129 #endif
131 rc = cifs_mount(sb, cifs_sb, data, devname);
133 if (rc) {
134 if (!silent)
135 cERROR(1,
136 ("cifs_mount failed w/return code = %d", rc));
137 goto out_mount_failed;
140 sb->s_magic = CIFS_MAGIC_NUMBER;
141 sb->s_op = &cifs_super_ops;
142 /* if (cifs_sb->tcon->ses->server->maxBuf > MAX_CIFS_HDR_SIZE + 512)
143 sb->s_blocksize =
144 cifs_sb->tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE; */
145 #ifdef CONFIG_CIFS_QUOTA
146 sb->s_qcop = &cifs_quotactl_ops;
147 #endif
148 sb->s_blocksize = CIFS_MAX_MSGSIZE;
149 sb->s_blocksize_bits = 14; /* default 2**14 = CIFS_MAX_MSGSIZE */
150 inode = cifs_iget(sb, ROOT_I);
152 if (IS_ERR(inode)) {
153 rc = PTR_ERR(inode);
154 inode = NULL;
155 goto out_no_root;
158 sb->s_root = d_alloc_root(inode);
160 if (!sb->s_root) {
161 rc = -ENOMEM;
162 goto out_no_root;
165 #ifdef CONFIG_CIFS_EXPERIMENTAL
166 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) {
167 cFYI(1, ("export ops supported"));
168 sb->s_export_op = &cifs_export_ops;
170 #endif /* EXPERIMENTAL */
172 return 0;
174 out_no_root:
175 cERROR(1, ("cifs_read_super: get root inode failed"));
176 if (inode)
177 iput(inode);
179 out_mount_failed:
180 if (cifs_sb) {
181 #ifdef CONFIG_CIFS_DFS_UPCALL
182 if (cifs_sb->mountdata) {
183 kfree(cifs_sb->mountdata);
184 cifs_sb->mountdata = NULL;
186 #endif
187 if (cifs_sb->local_nls)
188 unload_nls(cifs_sb->local_nls);
189 kfree(cifs_sb);
191 return rc;
194 static void
195 cifs_put_super(struct super_block *sb)
197 int rc = 0;
198 struct cifs_sb_info *cifs_sb;
200 cFYI(1, ("In cifs_put_super"));
201 cifs_sb = CIFS_SB(sb);
202 if (cifs_sb == NULL) {
203 cFYI(1, ("Empty cifs superblock info passed to unmount"));
204 return;
206 rc = cifs_umount(sb, cifs_sb);
207 <<<<<<< HEAD:fs/cifs/cifsfs.c
208 if (rc) {
209 =======
210 if (rc)
211 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:fs/cifs/cifsfs.c
212 cERROR(1, ("cifs_umount failed with return code %d", rc));
213 <<<<<<< HEAD:fs/cifs/cifsfs.c
215 =======
216 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:fs/cifs/cifsfs.c
217 #ifdef CONFIG_CIFS_DFS_UPCALL
218 if (cifs_sb->mountdata) {
219 kfree(cifs_sb->mountdata);
220 cifs_sb->mountdata = NULL;
222 #endif
224 unload_nls(cifs_sb->local_nls);
225 kfree(cifs_sb);
226 return;
229 static int
230 cifs_statfs(struct dentry *dentry, struct kstatfs *buf)
232 struct super_block *sb = dentry->d_sb;
233 int xid;
234 int rc = -EOPNOTSUPP;
235 struct cifs_sb_info *cifs_sb;
236 struct cifsTconInfo *pTcon;
238 xid = GetXid();
240 cifs_sb = CIFS_SB(sb);
241 pTcon = cifs_sb->tcon;
243 buf->f_type = CIFS_MAGIC_NUMBER;
245 /* instead could get the real value via SMB_QUERY_FS_ATTRIBUTE_INFO */
246 buf->f_namelen = PATH_MAX; /* PATH_MAX may be too long - it would
247 presumably be total path, but note
248 that some servers (includinng Samba 3)
249 have a shorter maximum path */
250 buf->f_files = 0; /* undefined */
251 buf->f_ffree = 0; /* unlimited */
253 /* BB we could add a second check for a QFS Unix capability bit */
254 /* BB FIXME check CIFS_POSIX_EXTENSIONS Unix cap first FIXME BB */
255 if ((pTcon->ses->capabilities & CAP_UNIX) && (CIFS_POSIX_EXTENSIONS &
256 le64_to_cpu(pTcon->fsUnixInfo.Capability)))
257 rc = CIFSSMBQFSPosixInfo(xid, pTcon, buf);
259 /* Only need to call the old QFSInfo if failed
260 on newer one */
261 if (rc)
262 if (pTcon->ses->capabilities & CAP_NT_SMBS)
263 rc = CIFSSMBQFSInfo(xid, pTcon, buf); /* not supported by OS2 */
265 /* Some old Windows servers also do not support level 103, retry with
266 older level one if old server failed the previous call or we
267 bypassed it because we detected that this was an older LANMAN sess */
268 if (rc)
269 rc = SMBOldQFSInfo(xid, pTcon, buf);
270 /* int f_type;
271 __fsid_t f_fsid;
272 int f_namelen; */
273 /* BB get from info in tcon struct at mount time call to QFSAttrInfo */
274 FreeXid(xid);
275 return 0; /* always return success? what if volume is no
276 longer available? */
279 static int cifs_permission(struct inode *inode, int mask, struct nameidata *nd)
281 struct cifs_sb_info *cifs_sb;
283 cifs_sb = CIFS_SB(inode->i_sb);
285 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM)
286 return 0;
287 else /* file mode might have been restricted at mount time
288 on the client (above and beyond ACL on servers) for
289 servers which do not support setting and viewing mode bits,
290 so allowing client to check permissions is useful */
291 return generic_permission(inode, mask, NULL);
294 static struct kmem_cache *cifs_inode_cachep;
295 static struct kmem_cache *cifs_req_cachep;
296 static struct kmem_cache *cifs_mid_cachep;
297 struct kmem_cache *cifs_oplock_cachep;
298 static struct kmem_cache *cifs_sm_req_cachep;
299 mempool_t *cifs_sm_req_poolp;
300 mempool_t *cifs_req_poolp;
301 mempool_t *cifs_mid_poolp;
303 static struct inode *
304 cifs_alloc_inode(struct super_block *sb)
306 struct cifsInodeInfo *cifs_inode;
307 cifs_inode = kmem_cache_alloc(cifs_inode_cachep, GFP_KERNEL);
308 if (!cifs_inode)
309 return NULL;
310 cifs_inode->cifsAttrs = 0x20; /* default */
311 atomic_set(&cifs_inode->inUse, 0);
312 cifs_inode->time = 0;
313 cifs_inode->write_behind_rc = 0;
314 /* Until the file is open and we have gotten oplock
315 info back from the server, can not assume caching of
316 file data or metadata */
317 cifs_inode->clientCanCacheRead = FALSE;
318 cifs_inode->clientCanCacheAll = FALSE;
319 cifs_inode->vfs_inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */
321 /* Can not set i_flags here - they get immediately overwritten
322 to zero by the VFS */
323 /* cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME;*/
324 INIT_LIST_HEAD(&cifs_inode->openFileList);
325 return &cifs_inode->vfs_inode;
328 static void
329 cifs_destroy_inode(struct inode *inode)
331 kmem_cache_free(cifs_inode_cachep, CIFS_I(inode));
335 * cifs_show_options() is for displaying mount options in /proc/mounts.
336 * Not all settable options are displayed but most of the important
337 * ones are.
339 static int
340 cifs_show_options(struct seq_file *s, struct vfsmount *m)
342 struct cifs_sb_info *cifs_sb;
344 cifs_sb = CIFS_SB(m->mnt_sb);
346 if (cifs_sb) {
347 if (cifs_sb->tcon) {
348 /* BB add prepath to mount options displayed */
349 seq_printf(s, ",unc=%s", cifs_sb->tcon->treeName);
350 if (cifs_sb->tcon->ses) {
351 if (cifs_sb->tcon->ses->userName)
352 seq_printf(s, ",username=%s",
353 cifs_sb->tcon->ses->userName);
354 if (cifs_sb->tcon->ses->domainName)
355 seq_printf(s, ",domain=%s",
356 cifs_sb->tcon->ses->domainName);
358 if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID) ||
359 !(cifs_sb->tcon->unix_ext))
360 seq_printf(s, ",uid=%d", cifs_sb->mnt_uid);
361 if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID) ||
362 !(cifs_sb->tcon->unix_ext))
363 seq_printf(s, ",gid=%d", cifs_sb->mnt_gid);
365 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)
366 seq_printf(s, ",posixpaths");
367 seq_printf(s, ",rsize=%d", cifs_sb->rsize);
368 seq_printf(s, ",wsize=%d", cifs_sb->wsize);
370 return 0;
373 #ifdef CONFIG_CIFS_QUOTA
374 int cifs_xquota_set(struct super_block *sb, int quota_type, qid_t qid,
375 struct fs_disk_quota *pdquota)
377 int xid;
378 int rc = 0;
379 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
380 struct cifsTconInfo *pTcon;
382 if (cifs_sb)
383 pTcon = cifs_sb->tcon;
384 else
385 return -EIO;
388 xid = GetXid();
389 if (pTcon) {
390 cFYI(1, ("set type: 0x%x id: %d", quota_type, qid));
391 } else {
392 rc = -EIO;
395 FreeXid(xid);
396 return rc;
399 int cifs_xquota_get(struct super_block *sb, int quota_type, qid_t qid,
400 struct fs_disk_quota *pdquota)
402 int xid;
403 int rc = 0;
404 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
405 struct cifsTconInfo *pTcon;
407 if (cifs_sb)
408 pTcon = cifs_sb->tcon;
409 else
410 return -EIO;
412 xid = GetXid();
413 if (pTcon) {
414 cFYI(1, ("set type: 0x%x id: %d", quota_type, qid));
415 } else {
416 rc = -EIO;
419 FreeXid(xid);
420 return rc;
423 int cifs_xstate_set(struct super_block *sb, unsigned int flags, int operation)
425 int xid;
426 int rc = 0;
427 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
428 struct cifsTconInfo *pTcon;
430 if (cifs_sb)
431 pTcon = cifs_sb->tcon;
432 else
433 return -EIO;
435 xid = GetXid();
436 if (pTcon) {
437 cFYI(1, ("flags: 0x%x operation: 0x%x", flags, operation));
438 } else {
439 rc = -EIO;
442 FreeXid(xid);
443 return rc;
446 int cifs_xstate_get(struct super_block *sb, struct fs_quota_stat *qstats)
448 int xid;
449 int rc = 0;
450 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
451 struct cifsTconInfo *pTcon;
453 if (cifs_sb) {
454 pTcon = cifs_sb->tcon;
455 } else {
456 return -EIO;
458 xid = GetXid();
459 if (pTcon) {
460 cFYI(1, ("pqstats %p", qstats));
461 } else {
462 rc = -EIO;
465 FreeXid(xid);
466 return rc;
469 static struct quotactl_ops cifs_quotactl_ops = {
470 .set_xquota = cifs_xquota_set,
471 <<<<<<< HEAD:fs/cifs/cifsfs.c
472 .get_xquota = cifs_xquota_set,
473 =======
474 .get_xquota = cifs_xquota_get,
475 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:fs/cifs/cifsfs.c
476 .set_xstate = cifs_xstate_set,
477 .get_xstate = cifs_xstate_get,
479 #endif
481 static void cifs_umount_begin(struct vfsmount *vfsmnt, int flags)
483 struct cifs_sb_info *cifs_sb;
484 struct cifsTconInfo *tcon;
486 <<<<<<< HEAD:fs/cifs/cifsfs.c
487 #ifdef CONFIG_CIFS_DFS_UPCALL
488 =======
489 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:fs/cifs/cifsfs.c
490 dfs_shrink_umount_helper(vfsmnt);
491 <<<<<<< HEAD:fs/cifs/cifsfs.c
492 #endif /* CONFIG CIFS_DFS_UPCALL */
493 =======
494 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:fs/cifs/cifsfs.c
496 if (!(flags & MNT_FORCE))
497 return;
498 cifs_sb = CIFS_SB(vfsmnt->mnt_sb);
499 if (cifs_sb == NULL)
500 return;
502 tcon = cifs_sb->tcon;
503 if (tcon == NULL)
504 return;
505 down(&tcon->tconSem);
506 if (atomic_read(&tcon->useCount) == 1)
507 tcon->tidStatus = CifsExiting;
508 up(&tcon->tconSem);
510 /* cancel_brl_requests(tcon); */ /* BB mark all brl mids as exiting */
511 /* cancel_notify_requests(tcon); */
512 if (tcon->ses && tcon->ses->server) {
513 cFYI(1, ("wake up tasks now - umount begin not complete"));
514 wake_up_all(&tcon->ses->server->request_q);
515 wake_up_all(&tcon->ses->server->response_q);
516 msleep(1); /* yield */
517 /* we have to kick the requests once more */
518 wake_up_all(&tcon->ses->server->response_q);
519 msleep(1);
521 /* BB FIXME - finish add checks for tidStatus BB */
523 return;
526 #ifdef CONFIG_CIFS_STATS2
527 static int cifs_show_stats(struct seq_file *s, struct vfsmount *mnt)
529 /* BB FIXME */
530 return 0;
532 #endif
534 static int cifs_remount(struct super_block *sb, int *flags, char *data)
536 *flags |= MS_NODIRATIME;
537 return 0;
540 static const struct super_operations cifs_super_ops = {
541 .put_super = cifs_put_super,
542 .statfs = cifs_statfs,
543 .alloc_inode = cifs_alloc_inode,
544 .destroy_inode = cifs_destroy_inode,
545 /* .drop_inode = generic_delete_inode,
546 .delete_inode = cifs_delete_inode, */ /* Do not need above two
547 functions unless later we add lazy close of inodes or unless the
548 kernel forgets to call us with the same number of releases (closes)
549 as opens */
550 .show_options = cifs_show_options,
551 .umount_begin = cifs_umount_begin,
552 .remount_fs = cifs_remount,
553 #ifdef CONFIG_CIFS_STATS2
554 .show_stats = cifs_show_stats,
555 #endif
558 static int
559 cifs_get_sb(struct file_system_type *fs_type,
560 int flags, const char *dev_name, void *data, struct vfsmount *mnt)
562 int rc;
563 struct super_block *sb = sget(fs_type, NULL, set_anon_super, NULL);
565 cFYI(1, ("Devname: %s flags: %d ", dev_name, flags));
567 if (IS_ERR(sb))
568 return PTR_ERR(sb);
570 sb->s_flags = flags;
572 rc = cifs_read_super(sb, data, dev_name, flags & MS_SILENT ? 1 : 0);
573 if (rc) {
574 up_write(&sb->s_umount);
575 deactivate_super(sb);
576 return rc;
578 sb->s_flags |= MS_ACTIVE;
579 return simple_set_mnt(mnt, sb);
582 static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
583 unsigned long nr_segs, loff_t pos)
585 struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode;
586 ssize_t written;
588 written = generic_file_aio_write(iocb, iov, nr_segs, pos);
589 if (!CIFS_I(inode)->clientCanCacheAll)
590 filemap_fdatawrite(inode->i_mapping);
591 return written;
594 static loff_t cifs_llseek(struct file *file, loff_t offset, int origin)
596 /* origin == SEEK_END => we must revalidate the cached file length */
597 if (origin == SEEK_END) {
598 int retval;
600 /* some applications poll for the file length in this strange
601 way so we must seek to end on non-oplocked files by
602 setting the revalidate time to zero */
603 CIFS_I(file->f_path.dentry->d_inode)->time = 0;
605 retval = cifs_revalidate(file->f_path.dentry);
606 if (retval < 0)
607 return (loff_t)retval;
609 return remote_llseek(file, offset, origin);
612 struct file_system_type cifs_fs_type = {
613 .owner = THIS_MODULE,
614 .name = "cifs",
615 .get_sb = cifs_get_sb,
616 .kill_sb = kill_anon_super,
617 /* .fs_flags */
619 const struct inode_operations cifs_dir_inode_ops = {
620 .create = cifs_create,
621 .lookup = cifs_lookup,
622 .getattr = cifs_getattr,
623 .unlink = cifs_unlink,
624 .link = cifs_hardlink,
625 .mkdir = cifs_mkdir,
626 .rmdir = cifs_rmdir,
627 .rename = cifs_rename,
628 .permission = cifs_permission,
629 /* revalidate:cifs_revalidate, */
630 .setattr = cifs_setattr,
631 .symlink = cifs_symlink,
632 .mknod = cifs_mknod,
633 #ifdef CONFIG_CIFS_XATTR
634 .setxattr = cifs_setxattr,
635 .getxattr = cifs_getxattr,
636 .listxattr = cifs_listxattr,
637 .removexattr = cifs_removexattr,
638 #endif
641 const struct inode_operations cifs_file_inode_ops = {
642 /* revalidate:cifs_revalidate, */
643 .setattr = cifs_setattr,
644 .getattr = cifs_getattr, /* do we need this anymore? */
645 .rename = cifs_rename,
646 .permission = cifs_permission,
647 #ifdef CONFIG_CIFS_XATTR
648 .setxattr = cifs_setxattr,
649 .getxattr = cifs_getxattr,
650 .listxattr = cifs_listxattr,
651 .removexattr = cifs_removexattr,
652 #endif
655 const struct inode_operations cifs_symlink_inode_ops = {
656 .readlink = generic_readlink,
657 .follow_link = cifs_follow_link,
658 .put_link = cifs_put_link,
659 .permission = cifs_permission,
660 /* BB add the following two eventually */
661 /* revalidate: cifs_revalidate,
662 setattr: cifs_notify_change, *//* BB do we need notify change */
663 #ifdef CONFIG_CIFS_XATTR
664 .setxattr = cifs_setxattr,
665 .getxattr = cifs_getxattr,
666 .listxattr = cifs_listxattr,
667 .removexattr = cifs_removexattr,
668 #endif
671 const struct file_operations cifs_file_ops = {
672 .read = do_sync_read,
673 .write = do_sync_write,
674 .aio_read = generic_file_aio_read,
675 .aio_write = cifs_file_aio_write,
676 .open = cifs_open,
677 .release = cifs_close,
678 .lock = cifs_lock,
679 .fsync = cifs_fsync,
680 .flush = cifs_flush,
681 .mmap = cifs_file_mmap,
682 .splice_read = generic_file_splice_read,
683 .llseek = cifs_llseek,
684 #ifdef CONFIG_CIFS_POSIX
685 .ioctl = cifs_ioctl,
686 #endif /* CONFIG_CIFS_POSIX */
688 #ifdef CONFIG_CIFS_EXPERIMENTAL
689 .dir_notify = cifs_dir_notify,
690 #endif /* CONFIG_CIFS_EXPERIMENTAL */
693 const struct file_operations cifs_file_direct_ops = {
694 /* no mmap, no aio, no readv -
695 BB reevaluate whether they can be done with directio, no cache */
696 .read = cifs_user_read,
697 .write = cifs_user_write,
698 .open = cifs_open,
699 .release = cifs_close,
700 .lock = cifs_lock,
701 .fsync = cifs_fsync,
702 .flush = cifs_flush,
703 .splice_read = generic_file_splice_read,
704 #ifdef CONFIG_CIFS_POSIX
705 .ioctl = cifs_ioctl,
706 #endif /* CONFIG_CIFS_POSIX */
707 .llseek = cifs_llseek,
708 #ifdef CONFIG_CIFS_EXPERIMENTAL
709 .dir_notify = cifs_dir_notify,
710 #endif /* CONFIG_CIFS_EXPERIMENTAL */
712 const struct file_operations cifs_file_nobrl_ops = {
713 .read = do_sync_read,
714 .write = do_sync_write,
715 .aio_read = generic_file_aio_read,
716 .aio_write = cifs_file_aio_write,
717 .open = cifs_open,
718 .release = cifs_close,
719 .fsync = cifs_fsync,
720 .flush = cifs_flush,
721 .mmap = cifs_file_mmap,
722 .splice_read = generic_file_splice_read,
723 .llseek = cifs_llseek,
724 #ifdef CONFIG_CIFS_POSIX
725 .ioctl = cifs_ioctl,
726 #endif /* CONFIG_CIFS_POSIX */
728 #ifdef CONFIG_CIFS_EXPERIMENTAL
729 .dir_notify = cifs_dir_notify,
730 #endif /* CONFIG_CIFS_EXPERIMENTAL */
733 const struct file_operations cifs_file_direct_nobrl_ops = {
734 /* no mmap, no aio, no readv -
735 BB reevaluate whether they can be done with directio, no cache */
736 .read = cifs_user_read,
737 .write = cifs_user_write,
738 .open = cifs_open,
739 .release = cifs_close,
740 .fsync = cifs_fsync,
741 .flush = cifs_flush,
742 .splice_read = generic_file_splice_read,
743 #ifdef CONFIG_CIFS_POSIX
744 .ioctl = cifs_ioctl,
745 #endif /* CONFIG_CIFS_POSIX */
746 .llseek = cifs_llseek,
747 #ifdef CONFIG_CIFS_EXPERIMENTAL
748 .dir_notify = cifs_dir_notify,
749 #endif /* CONFIG_CIFS_EXPERIMENTAL */
752 const struct file_operations cifs_dir_ops = {
753 .readdir = cifs_readdir,
754 .release = cifs_closedir,
755 .read = generic_read_dir,
756 #ifdef CONFIG_CIFS_EXPERIMENTAL
757 .dir_notify = cifs_dir_notify,
758 #endif /* CONFIG_CIFS_EXPERIMENTAL */
759 .ioctl = cifs_ioctl,
762 static void
763 cifs_init_once(struct kmem_cache *cachep, void *inode)
765 struct cifsInodeInfo *cifsi = inode;
767 inode_init_once(&cifsi->vfs_inode);
768 INIT_LIST_HEAD(&cifsi->lockList);
771 static int
772 cifs_init_inodecache(void)
774 cifs_inode_cachep = kmem_cache_create("cifs_inode_cache",
775 sizeof(struct cifsInodeInfo),
776 0, (SLAB_RECLAIM_ACCOUNT|
777 SLAB_MEM_SPREAD),
778 cifs_init_once);
779 if (cifs_inode_cachep == NULL)
780 return -ENOMEM;
782 return 0;
785 static void
786 cifs_destroy_inodecache(void)
788 kmem_cache_destroy(cifs_inode_cachep);
791 static int
792 cifs_init_request_bufs(void)
794 if (CIFSMaxBufSize < 8192) {
795 /* Buffer size can not be smaller than 2 * PATH_MAX since maximum
796 Unicode path name has to fit in any SMB/CIFS path based frames */
797 CIFSMaxBufSize = 8192;
798 } else if (CIFSMaxBufSize > 1024*127) {
799 CIFSMaxBufSize = 1024 * 127;
800 } else {
801 CIFSMaxBufSize &= 0x1FE00; /* Round size to even 512 byte mult*/
803 /* cERROR(1,("CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize)); */
804 cifs_req_cachep = kmem_cache_create("cifs_request",
805 CIFSMaxBufSize +
806 MAX_CIFS_HDR_SIZE, 0,
807 SLAB_HWCACHE_ALIGN, NULL);
808 if (cifs_req_cachep == NULL)
809 return -ENOMEM;
811 if (cifs_min_rcv < 1)
812 cifs_min_rcv = 1;
813 else if (cifs_min_rcv > 64) {
814 cifs_min_rcv = 64;
815 cERROR(1, ("cifs_min_rcv set to maximum (64)"));
818 cifs_req_poolp = mempool_create_slab_pool(cifs_min_rcv,
819 cifs_req_cachep);
821 if (cifs_req_poolp == NULL) {
822 kmem_cache_destroy(cifs_req_cachep);
823 return -ENOMEM;
825 /* MAX_CIFS_SMALL_BUFFER_SIZE bytes is enough for most SMB responses and
826 almost all handle based requests (but not write response, nor is it
827 sufficient for path based requests). A smaller size would have
828 been more efficient (compacting multiple slab items on one 4k page)
829 for the case in which debug was on, but this larger size allows
830 more SMBs to use small buffer alloc and is still much more
831 efficient to alloc 1 per page off the slab compared to 17K (5page)
832 alloc of large cifs buffers even when page debugging is on */
833 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
834 MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
835 NULL);
836 if (cifs_sm_req_cachep == NULL) {
837 mempool_destroy(cifs_req_poolp);
838 kmem_cache_destroy(cifs_req_cachep);
839 return -ENOMEM;
842 if (cifs_min_small < 2)
843 cifs_min_small = 2;
844 else if (cifs_min_small > 256) {
845 cifs_min_small = 256;
846 cFYI(1, ("cifs_min_small set to maximum (256)"));
849 cifs_sm_req_poolp = mempool_create_slab_pool(cifs_min_small,
850 cifs_sm_req_cachep);
852 if (cifs_sm_req_poolp == NULL) {
853 mempool_destroy(cifs_req_poolp);
854 kmem_cache_destroy(cifs_req_cachep);
855 kmem_cache_destroy(cifs_sm_req_cachep);
856 return -ENOMEM;
859 return 0;
862 static void
863 cifs_destroy_request_bufs(void)
865 mempool_destroy(cifs_req_poolp);
866 kmem_cache_destroy(cifs_req_cachep);
867 mempool_destroy(cifs_sm_req_poolp);
868 kmem_cache_destroy(cifs_sm_req_cachep);
871 static int
872 cifs_init_mids(void)
874 cifs_mid_cachep = kmem_cache_create("cifs_mpx_ids",
875 sizeof(struct mid_q_entry), 0,
876 SLAB_HWCACHE_ALIGN, NULL);
877 if (cifs_mid_cachep == NULL)
878 return -ENOMEM;
880 /* 3 is a reasonable minimum number of simultaneous operations */
881 cifs_mid_poolp = mempool_create_slab_pool(3, cifs_mid_cachep);
882 if (cifs_mid_poolp == NULL) {
883 kmem_cache_destroy(cifs_mid_cachep);
884 return -ENOMEM;
887 cifs_oplock_cachep = kmem_cache_create("cifs_oplock_structs",
888 sizeof(struct oplock_q_entry), 0,
889 SLAB_HWCACHE_ALIGN, NULL);
890 if (cifs_oplock_cachep == NULL) {
891 mempool_destroy(cifs_mid_poolp);
892 kmem_cache_destroy(cifs_mid_cachep);
893 return -ENOMEM;
896 return 0;
899 static void
900 cifs_destroy_mids(void)
902 mempool_destroy(cifs_mid_poolp);
903 kmem_cache_destroy(cifs_mid_cachep);
904 kmem_cache_destroy(cifs_oplock_cachep);
907 static int cifs_oplock_thread(void *dummyarg)
909 struct oplock_q_entry *oplock_item;
910 struct cifsTconInfo *pTcon;
911 struct inode *inode;
912 __u16 netfid;
913 int rc, waitrc = 0;
915 set_freezable();
916 do {
917 if (try_to_freeze())
918 continue;
920 spin_lock(&GlobalMid_Lock);
921 if (list_empty(&GlobalOplock_Q)) {
922 spin_unlock(&GlobalMid_Lock);
923 set_current_state(TASK_INTERRUPTIBLE);
924 schedule_timeout(39*HZ);
925 } else {
926 oplock_item = list_entry(GlobalOplock_Q.next,
927 struct oplock_q_entry, qhead);
928 if (oplock_item) {
929 cFYI(1, ("found oplock item to write out"));
930 pTcon = oplock_item->tcon;
931 inode = oplock_item->pinode;
932 netfid = oplock_item->netfid;
933 spin_unlock(&GlobalMid_Lock);
934 DeleteOplockQEntry(oplock_item);
935 /* can not grab inode sem here since it would
936 deadlock when oplock received on delete
937 since vfs_unlink holds the i_mutex across
938 the call */
939 /* mutex_lock(&inode->i_mutex);*/
940 if (S_ISREG(inode->i_mode)) {
941 rc =
942 filemap_fdatawrite(inode->i_mapping);
943 if (CIFS_I(inode)->clientCanCacheRead
944 == 0) {
945 waitrc = filemap_fdatawait(inode->i_mapping);
946 invalidate_remote_inode(inode);
948 if (rc == 0)
949 rc = waitrc;
950 } else
951 rc = 0;
952 /* mutex_unlock(&inode->i_mutex);*/
953 if (rc)
954 CIFS_I(inode)->write_behind_rc = rc;
955 cFYI(1, ("Oplock flush inode %p rc %d",
956 inode, rc));
958 /* releasing stale oplock after recent reconnect
959 of smb session using a now incorrect file
960 handle is not a data integrity issue but do
961 not bother sending an oplock release if session
962 to server still is disconnected since oplock
963 already released by the server in that case */
964 if (pTcon->tidStatus != CifsNeedReconnect) {
965 rc = CIFSSMBLock(0, pTcon, netfid,
966 0 /* len */ , 0 /* offset */, 0,
967 0, LOCKING_ANDX_OPLOCK_RELEASE,
968 0 /* wait flag */);
969 cFYI(1, ("Oplock release rc = %d", rc));
971 } else
972 spin_unlock(&GlobalMid_Lock);
973 set_current_state(TASK_INTERRUPTIBLE);
974 schedule_timeout(1); /* yield in case q were corrupt */
976 } while (!kthread_should_stop());
978 return 0;
981 static int cifs_dnotify_thread(void *dummyarg)
983 struct list_head *tmp;
984 struct cifsSesInfo *ses;
986 do {
987 if (try_to_freeze())
988 continue;
989 set_current_state(TASK_INTERRUPTIBLE);
990 schedule_timeout(15*HZ);
991 read_lock(&GlobalSMBSeslock);
992 /* check if any stuck requests that need
993 to be woken up and wakeq so the
994 thread can wake up and error out */
995 list_for_each(tmp, &GlobalSMBSessionList) {
996 ses = list_entry(tmp, struct cifsSesInfo,
997 cifsSessionList);
998 if (ses && ses->server &&
999 atomic_read(&ses->server->inFlight))
1000 wake_up_all(&ses->server->response_q);
1002 read_unlock(&GlobalSMBSeslock);
1003 } while (!kthread_should_stop());
1005 return 0;
1008 static int __init
1009 init_cifs(void)
1011 int rc = 0;
1012 <<<<<<< HEAD:fs/cifs/cifsfs.c
1013 #ifdef CONFIG_PROC_FS
1014 =======
1015 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:fs/cifs/cifsfs.c
1016 cifs_proc_init();
1017 <<<<<<< HEAD:fs/cifs/cifsfs.c
1018 #endif
1019 =======
1020 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:fs/cifs/cifsfs.c
1021 /* INIT_LIST_HEAD(&GlobalServerList);*/ /* BB not implemented yet */
1022 INIT_LIST_HEAD(&GlobalSMBSessionList);
1023 INIT_LIST_HEAD(&GlobalTreeConnectionList);
1024 INIT_LIST_HEAD(&GlobalOplock_Q);
1025 #ifdef CONFIG_CIFS_EXPERIMENTAL
1026 INIT_LIST_HEAD(&GlobalDnotifyReqList);
1027 INIT_LIST_HEAD(&GlobalDnotifyRsp_Q);
1028 #endif
1030 * Initialize Global counters
1032 atomic_set(&sesInfoAllocCount, 0);
1033 atomic_set(&tconInfoAllocCount, 0);
1034 atomic_set(&tcpSesAllocCount, 0);
1035 atomic_set(&tcpSesReconnectCount, 0);
1036 atomic_set(&tconInfoReconnectCount, 0);
1038 atomic_set(&bufAllocCount, 0);
1039 atomic_set(&smBufAllocCount, 0);
1040 #ifdef CONFIG_CIFS_STATS2
1041 atomic_set(&totBufAllocCount, 0);
1042 atomic_set(&totSmBufAllocCount, 0);
1043 #endif /* CONFIG_CIFS_STATS2 */
1045 atomic_set(&midCount, 0);
1046 GlobalCurrentXid = 0;
1047 GlobalTotalActiveXid = 0;
1048 GlobalMaxActiveXid = 0;
1049 memset(Local_System_Name, 0, 15);
1050 rwlock_init(&GlobalSMBSeslock);
1051 spin_lock_init(&GlobalMid_Lock);
1053 if (cifs_max_pending < 2) {
1054 cifs_max_pending = 2;
1055 cFYI(1, ("cifs_max_pending set to min of 2"));
1056 } else if (cifs_max_pending > 256) {
1057 cifs_max_pending = 256;
1058 cFYI(1, ("cifs_max_pending set to max of 256"));
1061 rc = cifs_init_inodecache();
1062 if (rc)
1063 goto out_clean_proc;
1065 rc = cifs_init_mids();
1066 if (rc)
1067 goto out_destroy_inodecache;
1069 rc = cifs_init_request_bufs();
1070 if (rc)
1071 goto out_destroy_mids;
1073 rc = register_filesystem(&cifs_fs_type);
1074 if (rc)
1075 goto out_destroy_request_bufs;
1076 #ifdef CONFIG_CIFS_UPCALL
1077 rc = register_key_type(&cifs_spnego_key_type);
1078 if (rc)
1079 goto out_unregister_filesystem;
1080 #endif
1081 #ifdef CONFIG_CIFS_DFS_UPCALL
1082 rc = register_key_type(&key_type_dns_resolver);
1083 if (rc)
1084 goto out_unregister_key_type;
1085 #endif
1086 oplockThread = kthread_run(cifs_oplock_thread, NULL, "cifsoplockd");
1087 if (IS_ERR(oplockThread)) {
1088 rc = PTR_ERR(oplockThread);
1089 cERROR(1, ("error %d create oplock thread", rc));
1090 goto out_unregister_dfs_key_type;
1093 dnotifyThread = kthread_run(cifs_dnotify_thread, NULL, "cifsdnotifyd");
1094 if (IS_ERR(dnotifyThread)) {
1095 rc = PTR_ERR(dnotifyThread);
1096 cERROR(1, ("error %d create dnotify thread", rc));
1097 goto out_stop_oplock_thread;
1100 return 0;
1102 out_stop_oplock_thread:
1103 kthread_stop(oplockThread);
1104 out_unregister_dfs_key_type:
1105 #ifdef CONFIG_CIFS_DFS_UPCALL
1106 unregister_key_type(&key_type_dns_resolver);
1107 out_unregister_key_type:
1108 #endif
1109 #ifdef CONFIG_CIFS_UPCALL
1110 unregister_key_type(&cifs_spnego_key_type);
1111 out_unregister_filesystem:
1112 #endif
1113 unregister_filesystem(&cifs_fs_type);
1114 out_destroy_request_bufs:
1115 cifs_destroy_request_bufs();
1116 out_destroy_mids:
1117 cifs_destroy_mids();
1118 out_destroy_inodecache:
1119 cifs_destroy_inodecache();
1120 out_clean_proc:
1121 <<<<<<< HEAD:fs/cifs/cifsfs.c
1122 #ifdef CONFIG_PROC_FS
1123 =======
1124 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:fs/cifs/cifsfs.c
1125 cifs_proc_clean();
1126 <<<<<<< HEAD:fs/cifs/cifsfs.c
1127 #endif
1128 =======
1129 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:fs/cifs/cifsfs.c
1130 return rc;
1133 static void __exit
1134 exit_cifs(void)
1136 <<<<<<< HEAD:fs/cifs/cifsfs.c
1137 cFYI(0, ("exit_cifs"));
1138 #ifdef CONFIG_PROC_FS
1139 =======
1140 cFYI(DBG2, ("exit_cifs"));
1141 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:fs/cifs/cifsfs.c
1142 cifs_proc_clean();
1143 <<<<<<< HEAD:fs/cifs/cifsfs.c
1144 #endif
1145 =======
1146 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:fs/cifs/cifsfs.c
1147 #ifdef CONFIG_CIFS_DFS_UPCALL
1148 unregister_key_type(&key_type_dns_resolver);
1149 #endif
1150 #ifdef CONFIG_CIFS_UPCALL
1151 unregister_key_type(&cifs_spnego_key_type);
1152 #endif
1153 unregister_filesystem(&cifs_fs_type);
1154 cifs_destroy_inodecache();
1155 cifs_destroy_mids();
1156 cifs_destroy_request_bufs();
1157 kthread_stop(oplockThread);
1158 kthread_stop(dnotifyThread);
1161 MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>");
1162 MODULE_LICENSE("GPL"); /* combination of LGPL + GPL source behaves as GPL */
1163 MODULE_DESCRIPTION
1164 ("VFS to access servers complying with the SNIA CIFS Specification "
1165 "e.g. Samba and Windows");
1166 MODULE_VERSION(CIFS_VERSION);
1167 module_init(init_cifs)
1168 module_exit(exit_cifs)