[CIFS] drop quota operation stubs
[linux-2.6-block.git] / fs / cifs / cifsfs.c
CommitLineData
1da177e4
LT
1/*
2 * fs/cifs/cifsfs.c
3 *
2b280fab 4 * Copyright (C) International Business Machines Corp., 2002,2008
1da177e4
LT
5 * Author(s): Steve French (sfrench@us.ibm.com)
6 *
7 * Common Internet FileSystem (CIFS) client
8 *
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.
13 *
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.
18 *
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
22 */
23
24/* Note that BB means BUGBUG (ie something to fix eventually) */
25
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>
6ab16d24 35#include <linux/delay.h>
45af7a0f 36#include <linux/kthread.h>
7dfb7103 37#include <linux/freezer.h>
67e55205 38#include <linux/smp_lock.h>
1da177e4
LT
39#include "cifsfs.h"
40#include "cifspdu.h"
41#define DECLARE_GLOBALS_HERE
42#include "cifsglob.h"
43#include "cifsproto.h"
44#include "cifs_debug.h"
45#include "cifs_fs_sb.h"
46#include <linux/mm.h>
84a15b93 47#include <linux/key-type.h>
6103335d 48#include "dns_resolve.h"
e545937a 49#include "cifs_spnego.h"
1da177e4
LT
50#define CIFS_MAGIC_NUMBER 0xFF534D42 /* the first four bytes of SMB PDUs */
51
1da177e4
LT
52int cifsFYI = 0;
53int cifsERROR = 1;
54int traceSMB = 0;
55unsigned int oplockEnabled = 1;
56unsigned int experimEnabled = 0;
57unsigned int linuxExtEnabled = 1;
58unsigned int lookupCacheEnabled = 1;
59unsigned int multiuser_mount = 0;
04912d6a 60unsigned int global_secflags = CIFSSEC_DEF;
3979877e 61/* unsigned int ntlmv2_support = 0; */
1da177e4 62unsigned int sign_CIFS_PDUs = 1;
ee9b6d61 63static const struct super_operations cifs_super_ops;
1da177e4
LT
64unsigned int CIFSMaxBufSize = CIFS_MAX_MSGSIZE;
65module_param(CIFSMaxBufSize, int, 0);
63135e08
SF
66MODULE_PARM_DESC(CIFSMaxBufSize, "Network buffer size (not including header). "
67 "Default: 16384 Range: 8192 to 130048");
1da177e4
LT
68unsigned int cifs_min_rcv = CIFS_MIN_RCV_POOL;
69module_param(cifs_min_rcv, int, 0);
63135e08
SF
70MODULE_PARM_DESC(cifs_min_rcv, "Network buffers in pool. Default: 4 Range: "
71 "1 to 64");
1da177e4
LT
72unsigned int cifs_min_small = 30;
73module_param(cifs_min_small, int, 0);
63135e08
SF
74MODULE_PARM_DESC(cifs_min_small, "Small network buffers in pool. Default: 30 "
75 "Range: 2 to 256");
1da177e4
LT
76unsigned int cifs_max_pending = CIFS_MAX_REQ;
77module_param(cifs_max_pending, int, 0);
63135e08
SF
78MODULE_PARM_DESC(cifs_max_pending, "Simultaneous requests to server. "
79 "Default: 50 Range: 2 to 256");
1da177e4 80
1da177e4
LT
81extern mempool_t *cifs_sm_req_poolp;
82extern mempool_t *cifs_req_poolp;
83extern mempool_t *cifs_mid_poolp;
84
1da177e4
LT
85static int
86cifs_read_super(struct super_block *sb, void *data,
87 const char *devname, int silent)
88{
89 struct inode *inode;
90 struct cifs_sb_info *cifs_sb;
91 int rc = 0;
50c2f753 92
1b2b2126
SF
93 /* BB should we make this contingent on mount parm? */
94 sb->s_flags |= MS_NODIRATIME | MS_NOATIME;
790fe579 95 sb->s_fs_info = kzalloc(sizeof(struct cifs_sb_info), GFP_KERNEL);
1da177e4 96 cifs_sb = CIFS_SB(sb);
4523cc30 97 if (cifs_sb == NULL)
1da177e4 98 return -ENOMEM;
1da177e4 99
e6ab1582
IM
100#ifdef CONFIG_CIFS_DFS_UPCALL
101 /* copy mount params to sb for use in submounts */
102 /* BB: should we move this after the mount so we
103 * do not have to do the copy on failed mounts?
104 * BB: May be it is better to do simple copy before
105 * complex operation (mount), and in case of fail
106 * just exit instead of doing mount and attempting
107 * undo it if this copy fails?*/
79ee9a8b
SF
108 if (data) {
109 int len = strlen(data);
110 cifs_sb->mountdata = kzalloc(len + 1, GFP_KERNEL);
111 if (cifs_sb->mountdata == NULL) {
112 kfree(sb->s_fs_info);
113 sb->s_fs_info = NULL;
114 return -ENOMEM;
115 }
116 strncpy(cifs_sb->mountdata, data, len + 1);
117 cifs_sb->mountdata[len] = '\0';
e6ab1582 118 }
e6ab1582
IM
119#endif
120
1da177e4
LT
121 rc = cifs_mount(sb, cifs_sb, data, devname);
122
123 if (rc) {
124 if (!silent)
b6b38f70 125 cERROR(1, "cifs_mount failed w/return code = %d", rc);
1da177e4
LT
126 goto out_mount_failed;
127 }
128
129 sb->s_magic = CIFS_MAGIC_NUMBER;
130 sb->s_op = &cifs_super_ops;
4523cc30 131/* if (cifs_sb->tcon->ses->server->maxBuf > MAX_CIFS_HDR_SIZE + 512)
790fe579
SF
132 sb->s_blocksize =
133 cifs_sb->tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE; */
1da177e4
LT
134 sb->s_blocksize = CIFS_MAX_MSGSIZE;
135 sb->s_blocksize_bits = 14; /* default 2**14 = CIFS_MAX_MSGSIZE */
bd433d4c 136 inode = cifs_root_iget(sb, ROOT_I);
1da177e4 137
ce634ab2
DH
138 if (IS_ERR(inode)) {
139 rc = PTR_ERR(inode);
140 inode = NULL;
1da177e4
LT
141 goto out_no_root;
142 }
143
144 sb->s_root = d_alloc_root(inode);
145
146 if (!sb->s_root) {
147 rc = -ENOMEM;
148 goto out_no_root;
149 }
50c2f753 150
7521a3c5
SF
151#ifdef CONFIG_CIFS_EXPERIMENTAL
152 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) {
b6b38f70 153 cFYI(1, "export ops supported");
7521a3c5
SF
154 sb->s_export_op = &cifs_export_ops;
155 }
156#endif /* EXPERIMENTAL */
1da177e4
LT
157
158 return 0;
159
160out_no_root:
b6b38f70 161 cERROR(1, "cifs_read_super: get root inode failed");
1da177e4
LT
162 if (inode)
163 iput(inode);
54b4602d 164
2c731afb 165 cifs_umount(sb, cifs_sb);
1da177e4
LT
166
167out_mount_failed:
4523cc30 168 if (cifs_sb) {
e6ab1582
IM
169#ifdef CONFIG_CIFS_DFS_UPCALL
170 if (cifs_sb->mountdata) {
171 kfree(cifs_sb->mountdata);
172 cifs_sb->mountdata = NULL;
173 }
174#endif
6d729e44 175 unload_nls(cifs_sb->local_nls);
1da177e4
LT
176 kfree(cifs_sb);
177 }
178 return rc;
179}
180
181static void
182cifs_put_super(struct super_block *sb)
183{
184 int rc = 0;
185 struct cifs_sb_info *cifs_sb;
186
b6b38f70 187 cFYI(1, "In cifs_put_super");
1da177e4 188 cifs_sb = CIFS_SB(sb);
4523cc30 189 if (cifs_sb == NULL) {
b6b38f70 190 cFYI(1, "Empty cifs superblock info passed to unmount");
1da177e4
LT
191 return;
192 }
6cfd0148
CH
193
194 lock_kernel();
195
790fe579 196 rc = cifs_umount(sb, cifs_sb);
ad7a2926 197 if (rc)
b6b38f70 198 cERROR(1, "cifs_umount failed with return code %d", rc);
e6ab1582
IM
199#ifdef CONFIG_CIFS_DFS_UPCALL
200 if (cifs_sb->mountdata) {
201 kfree(cifs_sb->mountdata);
202 cifs_sb->mountdata = NULL;
203 }
204#endif
205
1da177e4
LT
206 unload_nls(cifs_sb->local_nls);
207 kfree(cifs_sb);
6cfd0148
CH
208
209 unlock_kernel();
1da177e4
LT
210}
211
212static int
726c3342 213cifs_statfs(struct dentry *dentry, struct kstatfs *buf)
1da177e4 214{
726c3342 215 struct super_block *sb = dentry->d_sb;
39da9847
SF
216 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
217 struct cifsTconInfo *tcon = cifs_sb->tcon;
c81156dd 218 int rc = -EOPNOTSUPP;
39da9847 219 int xid;
1da177e4
LT
220
221 xid = GetXid();
222
1da177e4
LT
223 buf->f_type = CIFS_MAGIC_NUMBER;
224
39da9847
SF
225 /*
226 * PATH_MAX may be too long - it would presumably be total path,
227 * but note that some servers (includinng Samba 3) have a shorter
228 * maximum path.
229 *
230 * Instead could get the real value via SMB_QUERY_FS_ATTRIBUTE_INFO.
231 */
232 buf->f_namelen = PATH_MAX;
1da177e4
LT
233 buf->f_files = 0; /* undefined */
234 buf->f_ffree = 0; /* unlimited */
235
39da9847
SF
236 /*
237 * We could add a second check for a QFS Unix capability bit
238 */
239 if ((tcon->ses->capabilities & CAP_UNIX) &&
240 (CIFS_POSIX_EXTENSIONS & le64_to_cpu(tcon->fsUnixInfo.Capability)))
241 rc = CIFSSMBQFSPosixInfo(xid, tcon, buf);
242
243 /*
244 * Only need to call the old QFSInfo if failed on newer one,
245 * e.g. by OS/2.
246 **/
247 if (rc && (tcon->ses->capabilities & CAP_NT_SMBS))
248 rc = CIFSSMBQFSInfo(xid, tcon, buf);
249
250 /*
251 * Some old Windows servers also do not support level 103, retry with
252 * older level one if old server failed the previous call or we
253 * bypassed it because we detected that this was an older LANMAN sess
254 */
4523cc30 255 if (rc)
39da9847
SF
256 rc = SMBOldQFSInfo(xid, tcon, buf);
257
1da177e4 258 FreeXid(xid);
39da9847 259 return 0;
1da177e4
LT
260}
261
e6305c43 262static int cifs_permission(struct inode *inode, int mask)
1da177e4
LT
263{
264 struct cifs_sb_info *cifs_sb;
265
266 cifs_sb = CIFS_SB(inode->i_sb);
267
f696a365
MS
268 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) {
269 if ((mask & MAY_EXEC) && !execute_ok(inode))
270 return -EACCES;
271 else
272 return 0;
273 } else /* file mode might have been restricted at mount time
50c2f753 274 on the client (above and beyond ACL on servers) for
1da177e4 275 servers which do not support setting and viewing mode bits,
50c2f753 276 so allowing client to check permissions is useful */
1da177e4
LT
277 return generic_permission(inode, mask, NULL);
278}
279
e18b890b
CL
280static struct kmem_cache *cifs_inode_cachep;
281static struct kmem_cache *cifs_req_cachep;
282static struct kmem_cache *cifs_mid_cachep;
e18b890b 283static struct kmem_cache *cifs_sm_req_cachep;
1da177e4
LT
284mempool_t *cifs_sm_req_poolp;
285mempool_t *cifs_req_poolp;
286mempool_t *cifs_mid_poolp;
287
288static struct inode *
289cifs_alloc_inode(struct super_block *sb)
290{
291 struct cifsInodeInfo *cifs_inode;
e94b1766 292 cifs_inode = kmem_cache_alloc(cifs_inode_cachep, GFP_KERNEL);
1da177e4
LT
293 if (!cifs_inode)
294 return NULL;
295 cifs_inode->cifsAttrs = 0x20; /* default */
1da177e4 296 cifs_inode->time = 0;
cea21805 297 cifs_inode->write_behind_rc = 0;
1da177e4
LT
298 /* Until the file is open and we have gotten oplock
299 info back from the server, can not assume caching of
300 file data or metadata */
4b18f2a9
SF
301 cifs_inode->clientCanCacheRead = false;
302 cifs_inode->clientCanCacheAll = false;
9a8165fc 303 cifs_inode->delete_pending = false;
df2cf170 304 cifs_inode->invalid_mapping = false;
1da177e4 305 cifs_inode->vfs_inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */
fbec9ab9 306 cifs_inode->server_eof = 0;
50c2f753 307
1b2b2126
SF
308 /* Can not set i_flags here - they get immediately overwritten
309 to zero by the VFS */
310/* cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME;*/
1da177e4
LT
311 INIT_LIST_HEAD(&cifs_inode->openFileList);
312 return &cifs_inode->vfs_inode;
313}
314
315static void
316cifs_destroy_inode(struct inode *inode)
317{
318 kmem_cache_free(cifs_inode_cachep, CIFS_I(inode));
319}
320
61f98ffd
JL
321static void
322cifs_show_address(struct seq_file *s, struct TCP_Server_Info *server)
323{
324 seq_printf(s, ",addr=");
325
326 switch (server->addr.sockAddr.sin_family) {
327 case AF_INET:
328 seq_printf(s, "%pI4", &server->addr.sockAddr.sin_addr.s_addr);
329 break;
330 case AF_INET6:
331 seq_printf(s, "%pI6",
332 &server->addr.sockAddr6.sin6_addr.s6_addr);
333 if (server->addr.sockAddr6.sin6_scope_id)
334 seq_printf(s, "%%%u",
335 server->addr.sockAddr6.sin6_scope_id);
336 break;
337 default:
338 seq_printf(s, "(unknown)");
339 }
340}
341
1da177e4
LT
342/*
343 * cifs_show_options() is for displaying mount options in /proc/mounts.
344 * Not all settable options are displayed but most of the important
345 * ones are.
346 */
347static int
348cifs_show_options(struct seq_file *s, struct vfsmount *m)
349{
8e047d09
JL
350 struct cifs_sb_info *cifs_sb = CIFS_SB(m->mnt_sb);
351 struct cifsTconInfo *tcon = cifs_sb->tcon;
8616e0fc 352
8e047d09 353 seq_printf(s, ",unc=%s", tcon->treeName);
8616e0fc
JL
354 if (tcon->ses->userName)
355 seq_printf(s, ",username=%s", tcon->ses->userName);
356 if (tcon->ses->domainName)
357 seq_printf(s, ",domain=%s", tcon->ses->domainName);
358
8616e0fc 359 seq_printf(s, ",uid=%d", cifs_sb->mnt_uid);
340481a3
JL
360 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID)
361 seq_printf(s, ",forceuid");
4486d6ed
JL
362 else
363 seq_printf(s, ",noforceuid");
340481a3 364
8616e0fc 365 seq_printf(s, ",gid=%d", cifs_sb->mnt_gid);
340481a3
JL
366 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID)
367 seq_printf(s, ",forcegid");
4486d6ed
JL
368 else
369 seq_printf(s, ",noforcegid");
8616e0fc 370
61f98ffd 371 cifs_show_address(s, tcon->ses->server);
1da177e4 372
8616e0fc
JL
373 if (!tcon->unix_ext)
374 seq_printf(s, ",file_mode=0%o,dir_mode=0%o",
2b280fab
SF
375 cifs_sb->mnt_file_mode,
376 cifs_sb->mnt_dir_mode);
8616e0fc
JL
377 if (tcon->seal)
378 seq_printf(s, ",seal");
379 if (tcon->nocase)
380 seq_printf(s, ",nocase");
381 if (tcon->retry)
382 seq_printf(s, ",hard");
383 if (cifs_sb->prepath)
384 seq_printf(s, ",prepath=%s", cifs_sb->prepath);
385 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)
386 seq_printf(s, ",posixpaths");
387 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID)
388 seq_printf(s, ",setuids");
389 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)
390 seq_printf(s, ",serverino");
391 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO)
392 seq_printf(s, ",directio");
393 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
394 seq_printf(s, ",nouser_xattr");
395 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR)
396 seq_printf(s, ",mapchars");
397 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL)
398 seq_printf(s, ",sfu");
399 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
400 seq_printf(s, ",nobrl");
401 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL)
402 seq_printf(s, ",cifsacl");
403 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM)
404 seq_printf(s, ",dynperm");
405 if (m->mnt_sb->s_flags & MS_POSIXACL)
406 seq_printf(s, ",acl");
407
408 seq_printf(s, ",rsize=%d", cifs_sb->rsize);
409 seq_printf(s, ",wsize=%d", cifs_sb->wsize);
410
1da177e4
LT
411 return 0;
412}
413
42faad99 414static void cifs_umount_begin(struct super_block *sb)
68058e75 415{
42faad99 416 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
50c2f753 417 struct cifsTconInfo *tcon;
68058e75 418
4523cc30 419 if (cifs_sb == NULL)
9e2e85f8
SF
420 return;
421
422 tcon = cifs_sb->tcon;
4523cc30 423 if (tcon == NULL)
9e2e85f8 424 return;
f1987b44
JL
425
426 read_lock(&cifs_tcp_ses_lock);
ad8034f1
SF
427 if ((tcon->tc_count > 1) || (tcon->tidStatus == CifsExiting)) {
428 /* we have other mounts to same share or we have
429 already tried to force umount this and woken up
430 all waiting network requests, nothing to do */
431 read_unlock(&cifs_tcp_ses_lock);
432 return;
433 } else if (tcon->tc_count == 1)
5e1253b5 434 tcon->tidStatus = CifsExiting;
f1987b44 435 read_unlock(&cifs_tcp_ses_lock);
5e1253b5 436
3a5ff61c 437 /* cancel_brl_requests(tcon); */ /* BB mark all brl mids as exiting */
7b7abfe3 438 /* cancel_notify_requests(tcon); */
50c2f753 439 if (tcon->ses && tcon->ses->server) {
b6b38f70 440 cFYI(1, "wake up tasks now - umount begin not complete");
9e2e85f8 441 wake_up_all(&tcon->ses->server->request_q);
6ab16d24
SF
442 wake_up_all(&tcon->ses->server->response_q);
443 msleep(1); /* yield */
444 /* we have to kick the requests once more */
445 wake_up_all(&tcon->ses->server->response_q);
446 msleep(1);
5e1253b5 447 }
68058e75
SF
448
449 return;
450}
68058e75 451
bf97d287
SF
452#ifdef CONFIG_CIFS_STATS2
453static int cifs_show_stats(struct seq_file *s, struct vfsmount *mnt)
454{
455 /* BB FIXME */
456 return 0;
457}
458#endif
459
1da177e4
LT
460static int cifs_remount(struct super_block *sb, int *flags, char *data)
461{
462 *flags |= MS_NODIRATIME;
463 return 0;
464}
465
ee9b6d61 466static const struct super_operations cifs_super_ops = {
1da177e4
LT
467 .put_super = cifs_put_super,
468 .statfs = cifs_statfs,
469 .alloc_inode = cifs_alloc_inode,
470 .destroy_inode = cifs_destroy_inode,
50c2f753
SF
471/* .drop_inode = generic_delete_inode,
472 .delete_inode = cifs_delete_inode, */ /* Do not need above two
473 functions unless later we add lazy close of inodes or unless the
474 kernel forgets to call us with the same number of releases (closes)
475 as opens */
1da177e4 476 .show_options = cifs_show_options,
7b7abfe3 477 .umount_begin = cifs_umount_begin,
1da177e4 478 .remount_fs = cifs_remount,
bf97d287 479#ifdef CONFIG_CIFS_STATS2
f46d3e11 480 .show_stats = cifs_show_stats,
bf97d287 481#endif
1da177e4
LT
482};
483
454e2398 484static int
1da177e4 485cifs_get_sb(struct file_system_type *fs_type,
454e2398 486 int flags, const char *dev_name, void *data, struct vfsmount *mnt)
1da177e4
LT
487{
488 int rc;
489 struct super_block *sb = sget(fs_type, NULL, set_anon_super, NULL);
490
b6b38f70 491 cFYI(1, "Devname: %s flags: %d ", dev_name, flags);
1da177e4
LT
492
493 if (IS_ERR(sb))
454e2398 494 return PTR_ERR(sb);
1da177e4
LT
495
496 sb->s_flags = flags;
497
9b04c997 498 rc = cifs_read_super(sb, data, dev_name, flags & MS_SILENT ? 1 : 0);
1da177e4 499 if (rc) {
6f5bbff9 500 deactivate_locked_super(sb);
454e2398 501 return rc;
1da177e4
LT
502 }
503 sb->s_flags |= MS_ACTIVE;
a3ec947c
SB
504 simple_set_mnt(mnt, sb);
505 return 0;
1da177e4
LT
506}
507
027445c3
BP
508static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
509 unsigned long nr_segs, loff_t pos)
1da177e4 510{
e6a00296 511 struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode;
1da177e4
LT
512 ssize_t written;
513
027445c3 514 written = generic_file_aio_write(iocb, iov, nr_segs, pos);
87c89dd7
SF
515 if (!CIFS_I(inode)->clientCanCacheAll)
516 filemap_fdatawrite(inode->i_mapping);
1da177e4
LT
517 return written;
518}
519
c32a0b68
SF
520static loff_t cifs_llseek(struct file *file, loff_t offset, int origin)
521{
522 /* origin == SEEK_END => we must revalidate the cached file length */
0889a944 523 if (origin == SEEK_END) {
030e9d81
SF
524 int retval;
525
526 /* some applications poll for the file length in this strange
527 way so we must seek to end on non-oplocked files by
528 setting the revalidate time to zero */
c33f8d32 529 CIFS_I(file->f_path.dentry->d_inode)->time = 0;
030e9d81 530
abab095d 531 retval = cifs_revalidate_file(file);
c32a0b68
SF
532 if (retval < 0)
533 return (loff_t)retval;
534 }
9465efc9 535 return generic_file_llseek_unlocked(file, offset, origin);
c32a0b68
SF
536}
537
84210e91
SF
538static int cifs_setlease(struct file *file, long arg, struct file_lock **lease)
539{
540 /* note that this is called by vfs setlease with the BKL held
541 although I doubt that BKL is needed here in cifs */
542 struct inode *inode = file->f_path.dentry->d_inode;
543
544 if (!(S_ISREG(inode->i_mode)))
545 return -EINVAL;
546
547 /* check if file is oplocked */
548 if (((arg == F_RDLCK) &&
549 (CIFS_I(inode)->clientCanCacheRead)) ||
550 ((arg == F_WRLCK) &&
551 (CIFS_I(inode)->clientCanCacheAll)))
552 return generic_setlease(file, arg, lease);
553 else if (CIFS_SB(inode->i_sb)->tcon->local_lease &&
554 !CIFS_I(inode)->clientCanCacheRead)
555 /* If the server claims to support oplock on this
556 file, then we still need to check oplock even
557 if the local_lease mount option is set, but there
558 are servers which do not support oplock for which
559 this mount option may be useful if the user
560 knows that the file won't be changed on the server
561 by anyone else */
562 return generic_setlease(file, arg, lease);
563 else
564 return -EAGAIN;
565}
84210e91 566
e6ab1582 567struct file_system_type cifs_fs_type = {
1da177e4
LT
568 .owner = THIS_MODULE,
569 .name = "cifs",
570 .get_sb = cifs_get_sb,
571 .kill_sb = kill_anon_super,
572 /* .fs_flags */
573};
754661f1 574const struct inode_operations cifs_dir_inode_ops = {
1da177e4
LT
575 .create = cifs_create,
576 .lookup = cifs_lookup,
577 .getattr = cifs_getattr,
578 .unlink = cifs_unlink,
579 .link = cifs_hardlink,
580 .mkdir = cifs_mkdir,
581 .rmdir = cifs_rmdir,
582 .rename = cifs_rename,
583 .permission = cifs_permission,
584/* revalidate:cifs_revalidate, */
585 .setattr = cifs_setattr,
586 .symlink = cifs_symlink,
587 .mknod = cifs_mknod,
588#ifdef CONFIG_CIFS_XATTR
589 .setxattr = cifs_setxattr,
590 .getxattr = cifs_getxattr,
591 .listxattr = cifs_listxattr,
592 .removexattr = cifs_removexattr,
593#endif
594};
595
754661f1 596const struct inode_operations cifs_file_inode_ops = {
1da177e4
LT
597/* revalidate:cifs_revalidate, */
598 .setattr = cifs_setattr,
599 .getattr = cifs_getattr, /* do we need this anymore? */
600 .rename = cifs_rename,
601 .permission = cifs_permission,
602#ifdef CONFIG_CIFS_XATTR
603 .setxattr = cifs_setxattr,
604 .getxattr = cifs_getxattr,
605 .listxattr = cifs_listxattr,
606 .removexattr = cifs_removexattr,
50c2f753 607#endif
1da177e4
LT
608};
609
754661f1 610const struct inode_operations cifs_symlink_inode_ops = {
50c2f753 611 .readlink = generic_readlink,
1da177e4
LT
612 .follow_link = cifs_follow_link,
613 .put_link = cifs_put_link,
614 .permission = cifs_permission,
615 /* BB add the following two eventually */
616 /* revalidate: cifs_revalidate,
617 setattr: cifs_notify_change, *//* BB do we need notify change */
618#ifdef CONFIG_CIFS_XATTR
619 .setxattr = cifs_setxattr,
620 .getxattr = cifs_getxattr,
621 .listxattr = cifs_listxattr,
622 .removexattr = cifs_removexattr,
50c2f753 623#endif
1da177e4
LT
624};
625
4b6f5d20 626const struct file_operations cifs_file_ops = {
87c89dd7
SF
627 .read = do_sync_read,
628 .write = do_sync_write,
87c89dd7
SF
629 .aio_read = generic_file_aio_read,
630 .aio_write = cifs_file_aio_write,
1da177e4
LT
631 .open = cifs_open,
632 .release = cifs_close,
633 .lock = cifs_lock,
634 .fsync = cifs_fsync,
635 .flush = cifs_flush,
636 .mmap = cifs_file_mmap,
5ffc4ef4 637 .splice_read = generic_file_splice_read,
c32a0b68 638 .llseek = cifs_llseek,
c67593a0 639#ifdef CONFIG_CIFS_POSIX
f9ddcca4 640 .unlocked_ioctl = cifs_ioctl,
c67593a0 641#endif /* CONFIG_CIFS_POSIX */
84210e91 642 .setlease = cifs_setlease,
1da177e4
LT
643};
644
4b6f5d20 645const struct file_operations cifs_file_direct_ops = {
a994b8fa 646 /* no aio, no readv -
1da177e4
LT
647 BB reevaluate whether they can be done with directio, no cache */
648 .read = cifs_user_read,
649 .write = cifs_user_write,
650 .open = cifs_open,
651 .release = cifs_close,
652 .lock = cifs_lock,
653 .fsync = cifs_fsync,
654 .flush = cifs_flush,
a994b8fa 655 .mmap = cifs_file_mmap,
5ffc4ef4 656 .splice_read = generic_file_splice_read,
c67593a0 657#ifdef CONFIG_CIFS_POSIX
f9ddcca4 658 .unlocked_ioctl = cifs_ioctl,
c67593a0 659#endif /* CONFIG_CIFS_POSIX */
c32a0b68 660 .llseek = cifs_llseek,
84210e91 661 .setlease = cifs_setlease,
1da177e4 662};
4b6f5d20 663const struct file_operations cifs_file_nobrl_ops = {
87c89dd7
SF
664 .read = do_sync_read,
665 .write = do_sync_write,
87c89dd7
SF
666 .aio_read = generic_file_aio_read,
667 .aio_write = cifs_file_aio_write,
668 .open = cifs_open,
669 .release = cifs_close,
670 .fsync = cifs_fsync,
671 .flush = cifs_flush,
672 .mmap = cifs_file_mmap,
5ffc4ef4 673 .splice_read = generic_file_splice_read,
c32a0b68 674 .llseek = cifs_llseek,
8b94bcb9 675#ifdef CONFIG_CIFS_POSIX
f9ddcca4 676 .unlocked_ioctl = cifs_ioctl,
8b94bcb9 677#endif /* CONFIG_CIFS_POSIX */
84210e91 678 .setlease = cifs_setlease,
8b94bcb9
SF
679};
680
4b6f5d20 681const struct file_operations cifs_file_direct_nobrl_ops = {
50c2f753 682 /* no mmap, no aio, no readv -
87c89dd7
SF
683 BB reevaluate whether they can be done with directio, no cache */
684 .read = cifs_user_read,
685 .write = cifs_user_write,
686 .open = cifs_open,
687 .release = cifs_close,
688 .fsync = cifs_fsync,
689 .flush = cifs_flush,
810627a0 690 .mmap = cifs_file_mmap,
5ffc4ef4 691 .splice_read = generic_file_splice_read,
8b94bcb9 692#ifdef CONFIG_CIFS_POSIX
f9ddcca4 693 .unlocked_ioctl = cifs_ioctl,
8b94bcb9 694#endif /* CONFIG_CIFS_POSIX */
c32a0b68 695 .llseek = cifs_llseek,
84210e91 696 .setlease = cifs_setlease,
8b94bcb9 697};
1da177e4 698
4b6f5d20 699const struct file_operations cifs_dir_ops = {
1da177e4
LT
700 .readdir = cifs_readdir,
701 .release = cifs_closedir,
702 .read = generic_read_dir,
f9ddcca4 703 .unlocked_ioctl = cifs_ioctl,
3222a3e5 704 .llseek = generic_file_llseek,
1da177e4
LT
705};
706
707static void
51cc5068 708cifs_init_once(void *inode)
1da177e4
LT
709{
710 struct cifsInodeInfo *cifsi = inode;
711
a35afb83
CL
712 inode_init_once(&cifsi->vfs_inode);
713 INIT_LIST_HEAD(&cifsi->lockList);
1da177e4
LT
714}
715
716static int
717cifs_init_inodecache(void)
718{
719 cifs_inode_cachep = kmem_cache_create("cifs_inode_cache",
26f57364 720 sizeof(struct cifsInodeInfo),
fffb60f9
PJ
721 0, (SLAB_RECLAIM_ACCOUNT|
722 SLAB_MEM_SPREAD),
20c2df83 723 cifs_init_once);
1da177e4
LT
724 if (cifs_inode_cachep == NULL)
725 return -ENOMEM;
726
727 return 0;
728}
729
730static void
731cifs_destroy_inodecache(void)
732{
1a1d92c1 733 kmem_cache_destroy(cifs_inode_cachep);
1da177e4
LT
734}
735
736static int
737cifs_init_request_bufs(void)
738{
4523cc30 739 if (CIFSMaxBufSize < 8192) {
1da177e4
LT
740 /* Buffer size can not be smaller than 2 * PATH_MAX since maximum
741 Unicode path name has to fit in any SMB/CIFS path based frames */
742 CIFSMaxBufSize = 8192;
743 } else if (CIFSMaxBufSize > 1024*127) {
744 CIFSMaxBufSize = 1024 * 127;
745 } else {
746 CIFSMaxBufSize &= 0x1FE00; /* Round size to even 512 byte mult*/
747 }
b6b38f70 748/* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
1da177e4
LT
749 cifs_req_cachep = kmem_cache_create("cifs_request",
750 CIFSMaxBufSize +
751 MAX_CIFS_HDR_SIZE, 0,
20c2df83 752 SLAB_HWCACHE_ALIGN, NULL);
1da177e4
LT
753 if (cifs_req_cachep == NULL)
754 return -ENOMEM;
755
4523cc30 756 if (cifs_min_rcv < 1)
1da177e4
LT
757 cifs_min_rcv = 1;
758 else if (cifs_min_rcv > 64) {
759 cifs_min_rcv = 64;
b6b38f70 760 cERROR(1, "cifs_min_rcv set to maximum (64)");
1da177e4
LT
761 }
762
93d2341c
MD
763 cifs_req_poolp = mempool_create_slab_pool(cifs_min_rcv,
764 cifs_req_cachep);
1da177e4 765
4523cc30 766 if (cifs_req_poolp == NULL) {
1da177e4
LT
767 kmem_cache_destroy(cifs_req_cachep);
768 return -ENOMEM;
769 }
ec637e3f 770 /* MAX_CIFS_SMALL_BUFFER_SIZE bytes is enough for most SMB responses and
1da177e4
LT
771 almost all handle based requests (but not write response, nor is it
772 sufficient for path based requests). A smaller size would have
50c2f753 773 been more efficient (compacting multiple slab items on one 4k page)
1da177e4
LT
774 for the case in which debug was on, but this larger size allows
775 more SMBs to use small buffer alloc and is still much more
6dc0f87e 776 efficient to alloc 1 per page off the slab compared to 17K (5page)
1da177e4
LT
777 alloc of large cifs buffers even when page debugging is on */
778 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
6dc0f87e 779 MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
20c2df83 780 NULL);
1da177e4
LT
781 if (cifs_sm_req_cachep == NULL) {
782 mempool_destroy(cifs_req_poolp);
783 kmem_cache_destroy(cifs_req_cachep);
6dc0f87e 784 return -ENOMEM;
1da177e4
LT
785 }
786
4523cc30 787 if (cifs_min_small < 2)
1da177e4
LT
788 cifs_min_small = 2;
789 else if (cifs_min_small > 256) {
790 cifs_min_small = 256;
b6b38f70 791 cFYI(1, "cifs_min_small set to maximum (256)");
1da177e4
LT
792 }
793
93d2341c
MD
794 cifs_sm_req_poolp = mempool_create_slab_pool(cifs_min_small,
795 cifs_sm_req_cachep);
1da177e4 796
4523cc30 797 if (cifs_sm_req_poolp == NULL) {
1da177e4
LT
798 mempool_destroy(cifs_req_poolp);
799 kmem_cache_destroy(cifs_req_cachep);
800 kmem_cache_destroy(cifs_sm_req_cachep);
801 return -ENOMEM;
802 }
803
804 return 0;
805}
806
807static void
808cifs_destroy_request_bufs(void)
809{
810 mempool_destroy(cifs_req_poolp);
1a1d92c1 811 kmem_cache_destroy(cifs_req_cachep);
1da177e4 812 mempool_destroy(cifs_sm_req_poolp);
1a1d92c1 813 kmem_cache_destroy(cifs_sm_req_cachep);
1da177e4
LT
814}
815
816static int
817cifs_init_mids(void)
818{
819 cifs_mid_cachep = kmem_cache_create("cifs_mpx_ids",
26f57364
SF
820 sizeof(struct mid_q_entry), 0,
821 SLAB_HWCACHE_ALIGN, NULL);
1da177e4
LT
822 if (cifs_mid_cachep == NULL)
823 return -ENOMEM;
824
93d2341c
MD
825 /* 3 is a reasonable minimum number of simultaneous operations */
826 cifs_mid_poolp = mempool_create_slab_pool(3, cifs_mid_cachep);
4523cc30 827 if (cifs_mid_poolp == NULL) {
1da177e4
LT
828 kmem_cache_destroy(cifs_mid_cachep);
829 return -ENOMEM;
830 }
831
1da177e4
LT
832 return 0;
833}
834
835static void
836cifs_destroy_mids(void)
837{
838 mempool_destroy(cifs_mid_poolp);
1a1d92c1 839 kmem_cache_destroy(cifs_mid_cachep);
1da177e4
LT
840}
841
1da177e4
LT
842static int __init
843init_cifs(void)
844{
845 int rc = 0;
1da177e4 846 cifs_proc_init();
e7ddee90 847 INIT_LIST_HEAD(&cifs_tcp_ses_list);
4ca9c190
SF
848#ifdef CONFIG_CIFS_EXPERIMENTAL
849 INIT_LIST_HEAD(&GlobalDnotifyReqList);
850 INIT_LIST_HEAD(&GlobalDnotifyRsp_Q);
6dc0f87e 851#endif
1da177e4
LT
852/*
853 * Initialize Global counters
854 */
855 atomic_set(&sesInfoAllocCount, 0);
856 atomic_set(&tconInfoAllocCount, 0);
6dc0f87e 857 atomic_set(&tcpSesAllocCount, 0);
1da177e4
LT
858 atomic_set(&tcpSesReconnectCount, 0);
859 atomic_set(&tconInfoReconnectCount, 0);
860
861 atomic_set(&bufAllocCount, 0);
4498eed5
SF
862 atomic_set(&smBufAllocCount, 0);
863#ifdef CONFIG_CIFS_STATS2
864 atomic_set(&totBufAllocCount, 0);
865 atomic_set(&totSmBufAllocCount, 0);
866#endif /* CONFIG_CIFS_STATS2 */
867
1da177e4
LT
868 atomic_set(&midCount, 0);
869 GlobalCurrentXid = 0;
870 GlobalTotalActiveXid = 0;
871 GlobalMaxActiveXid = 0;
2cd646a2 872 memset(Local_System_Name, 0, 15);
1da177e4 873 rwlock_init(&GlobalSMBSeslock);
e7ddee90 874 rwlock_init(&cifs_tcp_ses_lock);
1da177e4
LT
875 spin_lock_init(&GlobalMid_Lock);
876
4523cc30 877 if (cifs_max_pending < 2) {
1da177e4 878 cifs_max_pending = 2;
b6b38f70 879 cFYI(1, "cifs_max_pending set to min of 2");
4523cc30 880 } else if (cifs_max_pending > 256) {
1da177e4 881 cifs_max_pending = 256;
b6b38f70 882 cFYI(1, "cifs_max_pending set to max of 256");
1da177e4
LT
883 }
884
885 rc = cifs_init_inodecache();
45af7a0f
SF
886 if (rc)
887 goto out_clean_proc;
888
889 rc = cifs_init_mids();
890 if (rc)
891 goto out_destroy_inodecache;
892
893 rc = cifs_init_request_bufs();
894 if (rc)
895 goto out_destroy_mids;
896
897 rc = register_filesystem(&cifs_fs_type);
898 if (rc)
899 goto out_destroy_request_bufs;
84a15b93
JL
900#ifdef CONFIG_CIFS_UPCALL
901 rc = register_key_type(&cifs_spnego_key_type);
902 if (rc)
903 goto out_unregister_filesystem;
6103335d
SF
904#endif
905#ifdef CONFIG_CIFS_DFS_UPCALL
906 rc = register_key_type(&key_type_dns_resolver);
907 if (rc)
908 goto out_unregister_key_type;
84a15b93 909#endif
0109d7e6 910 rc = slow_work_register_user(THIS_MODULE);
3bc303c2
JL
911 if (rc)
912 goto out_unregister_resolver_key;
45af7a0f 913
45af7a0f
SF
914 return 0;
915
3bc303c2 916 out_unregister_resolver_key:
6103335d
SF
917#ifdef CONFIG_CIFS_DFS_UPCALL
918 unregister_key_type(&key_type_dns_resolver);
84a15b93 919 out_unregister_key_type:
6103335d 920#endif
84a15b93
JL
921#ifdef CONFIG_CIFS_UPCALL
922 unregister_key_type(&cifs_spnego_key_type);
45af7a0f 923 out_unregister_filesystem:
84a15b93 924#endif
45af7a0f
SF
925 unregister_filesystem(&cifs_fs_type);
926 out_destroy_request_bufs:
927 cifs_destroy_request_bufs();
928 out_destroy_mids:
929 cifs_destroy_mids();
930 out_destroy_inodecache:
931 cifs_destroy_inodecache();
932 out_clean_proc:
1da177e4 933 cifs_proc_clean();
1da177e4
LT
934 return rc;
935}
936
937static void __exit
938exit_cifs(void)
939{
b6b38f70 940 cFYI(DBG2, "exit_cifs");
1da177e4 941 cifs_proc_clean();
6103335d 942#ifdef CONFIG_CIFS_DFS_UPCALL
78d31a3a 943 cifs_dfs_release_automount_timer();
6103335d
SF
944 unregister_key_type(&key_type_dns_resolver);
945#endif
84a15b93
JL
946#ifdef CONFIG_CIFS_UPCALL
947 unregister_key_type(&cifs_spnego_key_type);
1da177e4
LT
948#endif
949 unregister_filesystem(&cifs_fs_type);
950 cifs_destroy_inodecache();
951 cifs_destroy_mids();
952 cifs_destroy_request_bufs();
1da177e4
LT
953}
954
955MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>");
6dc0f87e 956MODULE_LICENSE("GPL"); /* combination of LGPL + GPL source behaves as GPL */
1da177e4 957MODULE_DESCRIPTION
63135e08
SF
958 ("VFS to access servers complying with the SNIA CIFS Specification "
959 "e.g. Samba and Windows");
1da177e4
LT
960MODULE_VERSION(CIFS_VERSION);
961module_init(init_cifs)
962module_exit(exit_cifs)