CIFS: Change mid_q_entry structure fields
[deliverable/linux.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>
fec11dd9 38#include <linux/namei.h>
3eb9a889 39#include <net/ipv6.h>
1da177e4
LT
40#include "cifsfs.h"
41#include "cifspdu.h"
42#define DECLARE_GLOBALS_HERE
43#include "cifsglob.h"
44#include "cifsproto.h"
45#include "cifs_debug.h"
46#include "cifs_fs_sb.h"
47#include <linux/mm.h>
84a15b93 48#include <linux/key-type.h>
e545937a 49#include "cifs_spnego.h"
f579cf3c 50#include "fscache.h"
1da177e4
LT
51#define CIFS_MAGIC_NUMBER 0xFF534D42 /* the first four bytes of SMB PDUs */
52
1da177e4
LT
53int cifsFYI = 0;
54int cifsERROR = 1;
55int traceSMB = 0;
e7504734 56bool enable_oplocks = true;
1da177e4
LT
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 76unsigned int cifs_max_pending = CIFS_MAX_REQ;
fef33df8 77module_param(cifs_max_pending, int, 0444);
63135e08 78MODULE_PARM_DESC(cifs_max_pending, "Simultaneous requests to server. "
10b9b98e 79 "Default: 32767 Range: 2 to 32767.");
e7504734
SF
80module_param(enable_oplocks, bool, 0644);
81MODULE_PARM_DESC(enable_oplocks, "Enable or disable oplocks (bool). Default:"
82 "y/Y/1");
83
1da177e4
LT
84extern mempool_t *cifs_sm_req_poolp;
85extern mempool_t *cifs_req_poolp;
86extern mempool_t *cifs_mid_poolp;
87
1da177e4 88static int
97d1152a 89cifs_read_super(struct super_block *sb)
1da177e4
LT
90{
91 struct inode *inode;
b2e5cd33 92 struct cifs_sb_info *cifs_sb;
1da177e4 93 int rc = 0;
50c2f753 94
b2e5cd33 95 cifs_sb = CIFS_SB(sb);
1da177e4 96
2c6292ae
AV
97 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIXACL)
98 sb->s_flags |= MS_POSIXACL;
99
100 if (cifs_sb_master_tcon(cifs_sb)->ses->capabilities & CAP_LARGE_FILES)
101 sb->s_maxbytes = MAX_LFS_FILESIZE;
102 else
103 sb->s_maxbytes = MAX_NON_LFS;
104
105 /* BB FIXME fix time_gran to be larger for LANMAN sessions */
106 sb->s_time_gran = 100;
107
1da177e4
LT
108 sb->s_magic = CIFS_MAGIC_NUMBER;
109 sb->s_op = &cifs_super_ops;
8044f7f4 110 sb->s_bdi = &cifs_sb->bdi;
1da177e4
LT
111 sb->s_blocksize = CIFS_MAX_MSGSIZE;
112 sb->s_blocksize_bits = 14; /* default 2**14 = CIFS_MAX_MSGSIZE */
9b6763e0 113 inode = cifs_root_iget(sb);
1da177e4 114
ce634ab2
DH
115 if (IS_ERR(inode)) {
116 rc = PTR_ERR(inode);
1da177e4
LT
117 goto out_no_root;
118 }
119
48fde701 120 sb->s_root = d_make_root(inode);
1da177e4
LT
121 if (!sb->s_root) {
122 rc = -ENOMEM;
123 goto out_no_root;
124 }
50c2f753 125
1c929cfe
AV
126 /* do that *after* d_alloc_root() - we want NULL ->d_op for root here */
127 if (cifs_sb_master_tcon(cifs_sb)->nocase)
128 sb->s_d_op = &cifs_ci_dentry_ops;
129 else
130 sb->s_d_op = &cifs_dentry_ops;
131
f3a6a60e 132#ifdef CONFIG_CIFS_NFSD_EXPORT
7521a3c5 133 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) {
b6b38f70 134 cFYI(1, "export ops supported");
7521a3c5
SF
135 sb->s_export_op = &cifs_export_ops;
136 }
f3a6a60e 137#endif /* CONFIG_CIFS_NFSD_EXPORT */
1da177e4
LT
138
139 return 0;
140
141out_no_root:
b6b38f70 142 cERROR(1, "cifs_read_super: get root inode failed");
1da177e4
LT
143 return rc;
144}
145
6d686175
AV
146static void cifs_kill_sb(struct super_block *sb)
147{
148 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
149 kill_anon_super(sb);
98ab494d 150 cifs_umount(cifs_sb);
1da177e4
LT
151}
152
153static int
726c3342 154cifs_statfs(struct dentry *dentry, struct kstatfs *buf)
1da177e4 155{
726c3342 156 struct super_block *sb = dentry->d_sb;
39da9847 157 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
96daf2b0 158 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
c81156dd 159 int rc = -EOPNOTSUPP;
39da9847 160 int xid;
1da177e4
LT
161
162 xid = GetXid();
163
1da177e4
LT
164 buf->f_type = CIFS_MAGIC_NUMBER;
165
39da9847
SF
166 /*
167 * PATH_MAX may be too long - it would presumably be total path,
168 * but note that some servers (includinng Samba 3) have a shorter
169 * maximum path.
170 *
171 * Instead could get the real value via SMB_QUERY_FS_ATTRIBUTE_INFO.
172 */
173 buf->f_namelen = PATH_MAX;
1da177e4
LT
174 buf->f_files = 0; /* undefined */
175 buf->f_ffree = 0; /* unlimited */
176
39da9847
SF
177 /*
178 * We could add a second check for a QFS Unix capability bit
179 */
180 if ((tcon->ses->capabilities & CAP_UNIX) &&
181 (CIFS_POSIX_EXTENSIONS & le64_to_cpu(tcon->fsUnixInfo.Capability)))
182 rc = CIFSSMBQFSPosixInfo(xid, tcon, buf);
183
184 /*
185 * Only need to call the old QFSInfo if failed on newer one,
186 * e.g. by OS/2.
187 **/
188 if (rc && (tcon->ses->capabilities & CAP_NT_SMBS))
189 rc = CIFSSMBQFSInfo(xid, tcon, buf);
190
191 /*
192 * Some old Windows servers also do not support level 103, retry with
193 * older level one if old server failed the previous call or we
194 * bypassed it because we detected that this was an older LANMAN sess
195 */
4523cc30 196 if (rc)
39da9847
SF
197 rc = SMBOldQFSInfo(xid, tcon, buf);
198
1da177e4 199 FreeXid(xid);
39da9847 200 return 0;
1da177e4
LT
201}
202
10556cb2 203static int cifs_permission(struct inode *inode, int mask)
1da177e4
LT
204{
205 struct cifs_sb_info *cifs_sb;
206
207 cifs_sb = CIFS_SB(inode->i_sb);
208
f696a365
MS
209 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) {
210 if ((mask & MAY_EXEC) && !execute_ok(inode))
211 return -EACCES;
212 else
213 return 0;
214 } else /* file mode might have been restricted at mount time
50c2f753 215 on the client (above and beyond ACL on servers) for
1da177e4 216 servers which do not support setting and viewing mode bits,
50c2f753 217 so allowing client to check permissions is useful */
2830ba7f 218 return generic_permission(inode, mask);
1da177e4
LT
219}
220
e18b890b
CL
221static struct kmem_cache *cifs_inode_cachep;
222static struct kmem_cache *cifs_req_cachep;
223static struct kmem_cache *cifs_mid_cachep;
e18b890b 224static struct kmem_cache *cifs_sm_req_cachep;
1da177e4
LT
225mempool_t *cifs_sm_req_poolp;
226mempool_t *cifs_req_poolp;
227mempool_t *cifs_mid_poolp;
228
229static struct inode *
230cifs_alloc_inode(struct super_block *sb)
231{
232 struct cifsInodeInfo *cifs_inode;
e94b1766 233 cifs_inode = kmem_cache_alloc(cifs_inode_cachep, GFP_KERNEL);
1da177e4
LT
234 if (!cifs_inode)
235 return NULL;
236 cifs_inode->cifsAttrs = 0x20; /* default */
1da177e4
LT
237 cifs_inode->time = 0;
238 /* Until the file is open and we have gotten oplock
239 info back from the server, can not assume caching of
240 file data or metadata */
c6723628 241 cifs_set_oplock_level(cifs_inode, 0);
9a8165fc 242 cifs_inode->delete_pending = false;
df2cf170 243 cifs_inode->invalid_mapping = false;
1da177e4 244 cifs_inode->vfs_inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */
fbec9ab9 245 cifs_inode->server_eof = 0;
20054bd6
JL
246 cifs_inode->uniqueid = 0;
247 cifs_inode->createtime = 0;
50c2f753 248
1b2b2126
SF
249 /* Can not set i_flags here - they get immediately overwritten
250 to zero by the VFS */
251/* cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME;*/
1da177e4
LT
252 INIT_LIST_HEAD(&cifs_inode->openFileList);
253 return &cifs_inode->vfs_inode;
254}
255
fa0d7e3d
NP
256static void cifs_i_callback(struct rcu_head *head)
257{
258 struct inode *inode = container_of(head, struct inode, i_rcu);
259 INIT_LIST_HEAD(&inode->i_dentry);
260 kmem_cache_free(cifs_inode_cachep, CIFS_I(inode));
261}
262
1da177e4
LT
263static void
264cifs_destroy_inode(struct inode *inode)
265{
fa0d7e3d 266 call_rcu(&inode->i_rcu, cifs_i_callback);
1da177e4
LT
267}
268
9451a9a5 269static void
b57922d9 270cifs_evict_inode(struct inode *inode)
9451a9a5 271{
b57922d9
AV
272 truncate_inode_pages(&inode->i_data, 0);
273 end_writeback(inode);
9451a9a5
SJ
274 cifs_fscache_release_inode_cookie(inode);
275}
276
61f98ffd
JL
277static void
278cifs_show_address(struct seq_file *s, struct TCP_Server_Info *server)
279{
a9f1b85e
PS
280 struct sockaddr_in *sa = (struct sockaddr_in *) &server->dstaddr;
281 struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *) &server->dstaddr;
282
61f98ffd
JL
283 seq_printf(s, ",addr=");
284
a9f1b85e 285 switch (server->dstaddr.ss_family) {
61f98ffd 286 case AF_INET:
a9f1b85e 287 seq_printf(s, "%pI4", &sa->sin_addr.s_addr);
61f98ffd
JL
288 break;
289 case AF_INET6:
a9f1b85e
PS
290 seq_printf(s, "%pI6", &sa6->sin6_addr.s6_addr);
291 if (sa6->sin6_scope_id)
292 seq_printf(s, "%%%u", sa6->sin6_scope_id);
61f98ffd
JL
293 break;
294 default:
295 seq_printf(s, "(unknown)");
296 }
297}
298
3e715513
JL
299static void
300cifs_show_security(struct seq_file *s, struct TCP_Server_Info *server)
301{
302 seq_printf(s, ",sec=");
303
304 switch (server->secType) {
305 case LANMAN:
306 seq_printf(s, "lanman");
307 break;
308 case NTLMv2:
309 seq_printf(s, "ntlmv2");
310 break;
311 case NTLM:
312 seq_printf(s, "ntlm");
313 break;
314 case Kerberos:
315 seq_printf(s, "krb5");
316 break;
317 case RawNTLMSSP:
318 seq_printf(s, "ntlmssp");
319 break;
320 default:
321 /* shouldn't ever happen */
322 seq_printf(s, "unknown");
323 break;
324 }
325
326 if (server->sec_mode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
327 seq_printf(s, "i");
328}
329
1da177e4
LT
330/*
331 * cifs_show_options() is for displaying mount options in /proc/mounts.
332 * Not all settable options are displayed but most of the important
333 * ones are.
334 */
335static int
34c80b1d 336cifs_show_options(struct seq_file *s, struct dentry *root)
1da177e4 337{
34c80b1d 338 struct cifs_sb_info *cifs_sb = CIFS_SB(root->d_sb);
96daf2b0 339 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
3eb9a889
BG
340 struct sockaddr *srcaddr;
341 srcaddr = (struct sockaddr *)&tcon->ses->server->srcaddr;
8616e0fc 342
3e715513
JL
343 cifs_show_security(s, tcon->ses->server);
344
8e047d09 345 seq_printf(s, ",unc=%s", tcon->treeName);
29e07c82
JL
346
347 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER)
348 seq_printf(s, ",multiuser");
8727c8a8
SF
349 else if (tcon->ses->user_name)
350 seq_printf(s, ",username=%s", tcon->ses->user_name);
29e07c82 351
8616e0fc
JL
352 if (tcon->ses->domainName)
353 seq_printf(s, ",domain=%s", tcon->ses->domainName);
354
3eb9a889
BG
355 if (srcaddr->sa_family != AF_UNSPEC) {
356 struct sockaddr_in *saddr4;
357 struct sockaddr_in6 *saddr6;
358 saddr4 = (struct sockaddr_in *)srcaddr;
359 saddr6 = (struct sockaddr_in6 *)srcaddr;
360 if (srcaddr->sa_family == AF_INET6)
361 seq_printf(s, ",srcaddr=%pI6c",
362 &saddr6->sin6_addr);
363 else if (srcaddr->sa_family == AF_INET)
364 seq_printf(s, ",srcaddr=%pI4",
365 &saddr4->sin_addr.s_addr);
366 else
367 seq_printf(s, ",srcaddr=BAD-AF:%i",
368 (int)(srcaddr->sa_family));
369 }
370
8616e0fc 371 seq_printf(s, ",uid=%d", cifs_sb->mnt_uid);
340481a3
JL
372 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID)
373 seq_printf(s, ",forceuid");
4486d6ed
JL
374 else
375 seq_printf(s, ",noforceuid");
340481a3 376
8616e0fc 377 seq_printf(s, ",gid=%d", cifs_sb->mnt_gid);
340481a3
JL
378 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID)
379 seq_printf(s, ",forcegid");
4486d6ed
JL
380 else
381 seq_printf(s, ",noforcegid");
8616e0fc 382
61f98ffd 383 cifs_show_address(s, tcon->ses->server);
1da177e4 384
8616e0fc 385 if (!tcon->unix_ext)
5206efd6 386 seq_printf(s, ",file_mode=0%ho,dir_mode=0%ho",
2b280fab
SF
387 cifs_sb->mnt_file_mode,
388 cifs_sb->mnt_dir_mode);
8616e0fc
JL
389 if (tcon->seal)
390 seq_printf(s, ",seal");
391 if (tcon->nocase)
392 seq_printf(s, ",nocase");
393 if (tcon->retry)
394 seq_printf(s, ",hard");
d4ffff1f
PS
395 if (tcon->unix_ext)
396 seq_printf(s, ",unix");
397 else
398 seq_printf(s, ",nounix");
8616e0fc
JL
399 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)
400 seq_printf(s, ",posixpaths");
401 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID)
402 seq_printf(s, ",setuids");
403 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)
404 seq_printf(s, ",serverino");
d4ffff1f
PS
405 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD)
406 seq_printf(s, ",rwpidforward");
407 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL)
408 seq_printf(s, ",forcemand");
8616e0fc
JL
409 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO)
410 seq_printf(s, ",directio");
411 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
412 seq_printf(s, ",nouser_xattr");
413 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR)
414 seq_printf(s, ",mapchars");
415 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL)
416 seq_printf(s, ",sfu");
417 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
418 seq_printf(s, ",nobrl");
419 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL)
420 seq_printf(s, ",cifsacl");
421 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM)
422 seq_printf(s, ",dynperm");
34c80b1d 423 if (root->d_sb->s_flags & MS_POSIXACL)
8616e0fc 424 seq_printf(s, ",acl");
736a3320
SM
425 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS)
426 seq_printf(s, ",mfsymlinks");
476428f8
SJ
427 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_FSCACHE)
428 seq_printf(s, ",fsc");
71c424ba
SF
429 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC)
430 seq_printf(s, ",nostrictsync");
431 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM)
432 seq_printf(s, ",noperm");
875cd043
SP
433 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO)
434 seq_printf(s, ",strictcache");
8616e0fc
JL
435
436 seq_printf(s, ",rsize=%d", cifs_sb->rsize);
437 seq_printf(s, ",wsize=%d", cifs_sb->wsize);
6d20e840
SJ
438 /* convert actimeo and display it in seconds */
439 seq_printf(s, ",actimeo=%lu", cifs_sb->actimeo / HZ);
8616e0fc 440
1da177e4
LT
441 return 0;
442}
443
42faad99 444static void cifs_umount_begin(struct super_block *sb)
68058e75 445{
42faad99 446 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
96daf2b0 447 struct cifs_tcon *tcon;
68058e75 448
4523cc30 449 if (cifs_sb == NULL)
9e2e85f8
SF
450 return;
451
0d424ad0 452 tcon = cifs_sb_master_tcon(cifs_sb);
f1987b44 453
3f9bcca7 454 spin_lock(&cifs_tcp_ses_lock);
ad8034f1
SF
455 if ((tcon->tc_count > 1) || (tcon->tidStatus == CifsExiting)) {
456 /* we have other mounts to same share or we have
457 already tried to force umount this and woken up
458 all waiting network requests, nothing to do */
3f9bcca7 459 spin_unlock(&cifs_tcp_ses_lock);
ad8034f1
SF
460 return;
461 } else if (tcon->tc_count == 1)
5e1253b5 462 tcon->tidStatus = CifsExiting;
3f9bcca7 463 spin_unlock(&cifs_tcp_ses_lock);
5e1253b5 464
3a5ff61c 465 /* cancel_brl_requests(tcon); */ /* BB mark all brl mids as exiting */
7b7abfe3 466 /* cancel_notify_requests(tcon); */
50c2f753 467 if (tcon->ses && tcon->ses->server) {
b6b38f70 468 cFYI(1, "wake up tasks now - umount begin not complete");
9e2e85f8 469 wake_up_all(&tcon->ses->server->request_q);
6ab16d24
SF
470 wake_up_all(&tcon->ses->server->response_q);
471 msleep(1); /* yield */
472 /* we have to kick the requests once more */
473 wake_up_all(&tcon->ses->server->response_q);
474 msleep(1);
5e1253b5 475 }
68058e75
SF
476
477 return;
478}
68058e75 479
bf97d287 480#ifdef CONFIG_CIFS_STATS2
64132379 481static int cifs_show_stats(struct seq_file *s, struct dentry *root)
bf97d287
SF
482{
483 /* BB FIXME */
484 return 0;
485}
486#endif
487
1da177e4
LT
488static int cifs_remount(struct super_block *sb, int *flags, char *data)
489{
490 *flags |= MS_NODIRATIME;
491 return 0;
492}
493
45321ac5 494static int cifs_drop_inode(struct inode *inode)
12420ac3
JL
495{
496 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
497
45321ac5
AV
498 /* no serverino => unconditional eviction */
499 return !(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) ||
500 generic_drop_inode(inode);
12420ac3
JL
501}
502
ee9b6d61 503static const struct super_operations cifs_super_ops = {
1da177e4
LT
504 .statfs = cifs_statfs,
505 .alloc_inode = cifs_alloc_inode,
506 .destroy_inode = cifs_destroy_inode,
12420ac3 507 .drop_inode = cifs_drop_inode,
b57922d9 508 .evict_inode = cifs_evict_inode,
12420ac3
JL
509/* .delete_inode = cifs_delete_inode, */ /* Do not need above
510 function unless later we add lazy close of inodes or unless the
50c2f753
SF
511 kernel forgets to call us with the same number of releases (closes)
512 as opens */
1da177e4 513 .show_options = cifs_show_options,
7b7abfe3 514 .umount_begin = cifs_umount_begin,
1da177e4 515 .remount_fs = cifs_remount,
bf97d287 516#ifdef CONFIG_CIFS_STATS2
f46d3e11 517 .show_stats = cifs_show_stats,
bf97d287 518#endif
1da177e4
LT
519};
520
f87d39d9
SF
521/*
522 * Get root dentry from superblock according to prefix path mount option.
523 * Return dentry with refcount + 1 on success and NULL otherwise.
524 */
525static struct dentry *
526cifs_get_root(struct smb_vol *vol, struct super_block *sb)
527{
fec11dd9 528 struct dentry *dentry;
f87d39d9 529 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
fec11dd9
AV
530 char *full_path = NULL;
531 char *s, *p;
f87d39d9
SF
532 char sep;
533
534 full_path = cifs_build_path_to_root(vol, cifs_sb,
535 cifs_sb_master_tcon(cifs_sb));
536 if (full_path == NULL)
9403c9c5 537 return ERR_PTR(-ENOMEM);
f87d39d9
SF
538
539 cFYI(1, "Get root dentry for %s", full_path);
540
f87d39d9 541 sep = CIFS_DIR_SEP(cifs_sb);
fec11dd9
AV
542 dentry = dget(sb->s_root);
543 p = s = full_path;
544
545 do {
546 struct inode *dir = dentry->d_inode;
547 struct dentry *child;
548
5b980b01
PS
549 if (!dir) {
550 dput(dentry);
551 dentry = ERR_PTR(-ENOENT);
552 break;
553 }
554
fec11dd9
AV
555 /* skip separators */
556 while (*s == sep)
557 s++;
558 if (!*s)
559 break;
560 p = s++;
561 /* next separator */
562 while (*s && *s != sep)
563 s++;
564
565 mutex_lock(&dir->i_mutex);
566 child = lookup_one_len(p, dentry, s - p);
567 mutex_unlock(&dir->i_mutex);
568 dput(dentry);
569 dentry = child;
570 } while (!IS_ERR(dentry));
f87d39d9 571 kfree(full_path);
fec11dd9 572 return dentry;
f87d39d9
SF
573}
574
ee01a14d
AV
575static int cifs_set_super(struct super_block *sb, void *data)
576{
577 struct cifs_mnt_data *mnt_data = data;
578 sb->s_fs_info = mnt_data->cifs_sb;
579 return set_anon_super(sb, NULL);
580}
581
d753ed97
AV
582static struct dentry *
583cifs_do_mount(struct file_system_type *fs_type,
724d9f1c 584 int flags, const char *dev_name, void *data)
1da177e4
LT
585{
586 int rc;
db719222 587 struct super_block *sb;
724d9f1c
PS
588 struct cifs_sb_info *cifs_sb;
589 struct smb_vol *volume_info;
25c7f41e 590 struct cifs_mnt_data mnt_data;
724d9f1c 591 struct dentry *root;
1da177e4 592
b6b38f70 593 cFYI(1, "Devname: %s flags: %d ", dev_name, flags);
1da177e4 594
04db79b0
JL
595 volume_info = cifs_get_volume_info((char *)data, dev_name);
596 if (IS_ERR(volume_info))
597 return ERR_CAST(volume_info);
724d9f1c
PS
598
599 cifs_sb = kzalloc(sizeof(struct cifs_sb_info), GFP_KERNEL);
600 if (cifs_sb == NULL) {
601 root = ERR_PTR(-ENOMEM);
5c4f1ad7 602 goto out_nls;
724d9f1c
PS
603 }
604
5d3bc605
AV
605 cifs_sb->mountdata = kstrndup(data, PAGE_SIZE, GFP_KERNEL);
606 if (cifs_sb->mountdata == NULL) {
607 root = ERR_PTR(-ENOMEM);
5c4f1ad7 608 goto out_cifs_sb;
5d3bc605
AV
609 }
610
724d9f1c
PS
611 cifs_setup_cifs_sb(volume_info, cifs_sb);
612
97d1152a
AV
613 rc = cifs_mount(cifs_sb, volume_info);
614 if (rc) {
615 if (!(flags & MS_SILENT))
616 cERROR(1, "cifs_mount failed w/return code = %d", rc);
617 root = ERR_PTR(rc);
5c4f1ad7 618 goto out_mountdata;
97d1152a
AV
619 }
620
25c7f41e
PS
621 mnt_data.vol = volume_info;
622 mnt_data.cifs_sb = cifs_sb;
623 mnt_data.flags = flags;
624
ee01a14d 625 sb = sget(fs_type, cifs_match_super, cifs_set_super, &mnt_data);
724d9f1c 626 if (IS_ERR(sb)) {
724d9f1c 627 root = ERR_CAST(sb);
97d1152a 628 cifs_umount(cifs_sb);
d757d71b 629 goto out;
724d9f1c 630 }
1da177e4 631
ee01a14d 632 if (sb->s_root) {
25c7f41e 633 cFYI(1, "Use existing superblock");
97d1152a 634 cifs_umount(cifs_sb);
5c4f1ad7
AV
635 } else {
636 sb->s_flags = flags;
637 /* BB should we make this contingent on mount parm? */
638 sb->s_flags |= MS_NODIRATIME | MS_NOATIME;
639
640 rc = cifs_read_super(sb);
641 if (rc) {
642 root = ERR_PTR(rc);
643 goto out_super;
644 }
b2e5cd33 645
5c4f1ad7 646 sb->s_flags |= MS_ACTIVE;
1da177e4 647 }
724d9f1c 648
f87d39d9 649 root = cifs_get_root(volume_info, sb);
9403c9c5 650 if (IS_ERR(root))
f87d39d9 651 goto out_super;
25c7f41e 652
f87d39d9 653 cFYI(1, "dentry root is: %p", root);
641a58d6 654 goto out;
724d9f1c 655
641a58d6 656out_super:
641a58d6 657 deactivate_locked_super(sb);
641a58d6 658out:
f9e59bcb 659 cifs_cleanup_volume_info(volume_info);
724d9f1c 660 return root;
5c4f1ad7
AV
661
662out_mountdata:
663 kfree(cifs_sb->mountdata);
664out_cifs_sb:
665 kfree(cifs_sb);
666out_nls:
667 unload_nls(volume_info->local_nls);
668 goto out;
1da177e4
LT
669}
670
027445c3
BP
671static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
672 unsigned long nr_segs, loff_t pos)
1da177e4 673{
e6a00296 674 struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode;
1da177e4 675 ssize_t written;
72432ffc 676 int rc;
1da177e4 677
027445c3 678 written = generic_file_aio_write(iocb, iov, nr_segs, pos);
72432ffc
PS
679
680 if (CIFS_I(inode)->clientCanCacheAll)
681 return written;
682
683 rc = filemap_fdatawrite(inode->i_mapping);
684 if (rc)
685 cFYI(1, "cifs_file_aio_write: %d rc on %p inode", rc, inode);
686
1da177e4
LT
687 return written;
688}
689
c32a0b68
SF
690static loff_t cifs_llseek(struct file *file, loff_t offset, int origin)
691{
06222e49
JB
692 /*
693 * origin == SEEK_END || SEEK_DATA || SEEK_HOLE => we must revalidate
694 * the cached file length
695 */
696 if (origin != SEEK_SET || origin != SEEK_CUR) {
6feb9891
PS
697 int rc;
698 struct inode *inode = file->f_path.dentry->d_inode;
699
700 /*
701 * We need to be sure that all dirty pages are written and the
702 * server has the newest file length.
703 */
704 if (!CIFS_I(inode)->clientCanCacheRead && inode->i_mapping &&
705 inode->i_mapping->nrpages != 0) {
706 rc = filemap_fdatawait(inode->i_mapping);
156ecb2d
SF
707 if (rc) {
708 mapping_set_error(inode->i_mapping, rc);
709 return rc;
710 }
6feb9891
PS
711 }
712 /*
713 * Some applications poll for the file length in this strange
714 * way so we must seek to end on non-oplocked files by
715 * setting the revalidate time to zero.
716 */
717 CIFS_I(inode)->time = 0;
718
719 rc = cifs_revalidate_file_attr(file);
720 if (rc < 0)
721 return (loff_t)rc;
c32a0b68 722 }
ef3d0fd2 723 return generic_file_llseek(file, offset, origin);
c32a0b68
SF
724}
725
84210e91
SF
726static int cifs_setlease(struct file *file, long arg, struct file_lock **lease)
727{
b89f4321
AB
728 /* note that this is called by vfs setlease with lock_flocks held
729 to protect *lease from going away */
84210e91 730 struct inode *inode = file->f_path.dentry->d_inode;
ba00ba64 731 struct cifsFileInfo *cfile = file->private_data;
84210e91
SF
732
733 if (!(S_ISREG(inode->i_mode)))
734 return -EINVAL;
735
736 /* check if file is oplocked */
737 if (((arg == F_RDLCK) &&
738 (CIFS_I(inode)->clientCanCacheRead)) ||
739 ((arg == F_WRLCK) &&
740 (CIFS_I(inode)->clientCanCacheAll)))
741 return generic_setlease(file, arg, lease);
13cfb733
JL
742 else if (tlink_tcon(cfile->tlink)->local_lease &&
743 !CIFS_I(inode)->clientCanCacheRead)
84210e91
SF
744 /* If the server claims to support oplock on this
745 file, then we still need to check oplock even
746 if the local_lease mount option is set, but there
747 are servers which do not support oplock for which
748 this mount option may be useful if the user
749 knows that the file won't be changed on the server
750 by anyone else */
751 return generic_setlease(file, arg, lease);
51ee4b84 752 else
84210e91
SF
753 return -EAGAIN;
754}
84210e91 755
e6ab1582 756struct file_system_type cifs_fs_type = {
1da177e4
LT
757 .owner = THIS_MODULE,
758 .name = "cifs",
d753ed97 759 .mount = cifs_do_mount,
6d686175 760 .kill_sb = cifs_kill_sb,
1da177e4
LT
761 /* .fs_flags */
762};
754661f1 763const struct inode_operations cifs_dir_inode_ops = {
1da177e4
LT
764 .create = cifs_create,
765 .lookup = cifs_lookup,
766 .getattr = cifs_getattr,
767 .unlink = cifs_unlink,
768 .link = cifs_hardlink,
769 .mkdir = cifs_mkdir,
770 .rmdir = cifs_rmdir,
771 .rename = cifs_rename,
772 .permission = cifs_permission,
773/* revalidate:cifs_revalidate, */
774 .setattr = cifs_setattr,
775 .symlink = cifs_symlink,
776 .mknod = cifs_mknod,
777#ifdef CONFIG_CIFS_XATTR
778 .setxattr = cifs_setxattr,
779 .getxattr = cifs_getxattr,
780 .listxattr = cifs_listxattr,
781 .removexattr = cifs_removexattr,
782#endif
783};
784
754661f1 785const struct inode_operations cifs_file_inode_ops = {
1da177e4
LT
786/* revalidate:cifs_revalidate, */
787 .setattr = cifs_setattr,
788 .getattr = cifs_getattr, /* do we need this anymore? */
789 .rename = cifs_rename,
790 .permission = cifs_permission,
791#ifdef CONFIG_CIFS_XATTR
792 .setxattr = cifs_setxattr,
793 .getxattr = cifs_getxattr,
794 .listxattr = cifs_listxattr,
795 .removexattr = cifs_removexattr,
50c2f753 796#endif
1da177e4
LT
797};
798
754661f1 799const struct inode_operations cifs_symlink_inode_ops = {
50c2f753 800 .readlink = generic_readlink,
1da177e4
LT
801 .follow_link = cifs_follow_link,
802 .put_link = cifs_put_link,
803 .permission = cifs_permission,
804 /* BB add the following two eventually */
805 /* revalidate: cifs_revalidate,
806 setattr: cifs_notify_change, *//* BB do we need notify change */
807#ifdef CONFIG_CIFS_XATTR
808 .setxattr = cifs_setxattr,
809 .getxattr = cifs_getxattr,
810 .listxattr = cifs_listxattr,
811 .removexattr = cifs_removexattr,
50c2f753 812#endif
1da177e4
LT
813};
814
4b6f5d20 815const struct file_operations cifs_file_ops = {
87c89dd7
SF
816 .read = do_sync_read,
817 .write = do_sync_write,
87c89dd7
SF
818 .aio_read = generic_file_aio_read,
819 .aio_write = cifs_file_aio_write,
1da177e4
LT
820 .open = cifs_open,
821 .release = cifs_close,
822 .lock = cifs_lock,
823 .fsync = cifs_fsync,
824 .flush = cifs_flush,
825 .mmap = cifs_file_mmap,
5ffc4ef4 826 .splice_read = generic_file_splice_read,
c32a0b68 827 .llseek = cifs_llseek,
c67593a0 828#ifdef CONFIG_CIFS_POSIX
f9ddcca4 829 .unlocked_ioctl = cifs_ioctl,
c67593a0 830#endif /* CONFIG_CIFS_POSIX */
84210e91 831 .setlease = cifs_setlease,
1da177e4
LT
832};
833
8be7e6ba
PS
834const struct file_operations cifs_file_strict_ops = {
835 .read = do_sync_read,
836 .write = do_sync_write,
a70307ee 837 .aio_read = cifs_strict_readv,
72432ffc 838 .aio_write = cifs_strict_writev,
8be7e6ba
PS
839 .open = cifs_open,
840 .release = cifs_close,
841 .lock = cifs_lock,
842 .fsync = cifs_strict_fsync,
843 .flush = cifs_flush,
7a6a19b1 844 .mmap = cifs_file_strict_mmap,
8be7e6ba
PS
845 .splice_read = generic_file_splice_read,
846 .llseek = cifs_llseek,
847#ifdef CONFIG_CIFS_POSIX
848 .unlocked_ioctl = cifs_ioctl,
849#endif /* CONFIG_CIFS_POSIX */
850 .setlease = cifs_setlease,
851};
852
4b6f5d20 853const struct file_operations cifs_file_direct_ops = {
0b81c1c4
PS
854 /* BB reevaluate whether they can be done with directio, no cache */
855 .read = do_sync_read,
856 .write = do_sync_write,
857 .aio_read = cifs_user_readv,
858 .aio_write = cifs_user_writev,
1da177e4
LT
859 .open = cifs_open,
860 .release = cifs_close,
861 .lock = cifs_lock,
862 .fsync = cifs_fsync,
863 .flush = cifs_flush,
a994b8fa 864 .mmap = cifs_file_mmap,
5ffc4ef4 865 .splice_read = generic_file_splice_read,
c67593a0 866#ifdef CONFIG_CIFS_POSIX
f9ddcca4 867 .unlocked_ioctl = cifs_ioctl,
c67593a0 868#endif /* CONFIG_CIFS_POSIX */
c32a0b68 869 .llseek = cifs_llseek,
84210e91 870 .setlease = cifs_setlease,
1da177e4 871};
8be7e6ba 872
4b6f5d20 873const struct file_operations cifs_file_nobrl_ops = {
87c89dd7
SF
874 .read = do_sync_read,
875 .write = do_sync_write,
87c89dd7
SF
876 .aio_read = generic_file_aio_read,
877 .aio_write = cifs_file_aio_write,
878 .open = cifs_open,
879 .release = cifs_close,
880 .fsync = cifs_fsync,
881 .flush = cifs_flush,
882 .mmap = cifs_file_mmap,
5ffc4ef4 883 .splice_read = generic_file_splice_read,
c32a0b68 884 .llseek = cifs_llseek,
8b94bcb9 885#ifdef CONFIG_CIFS_POSIX
f9ddcca4 886 .unlocked_ioctl = cifs_ioctl,
8b94bcb9 887#endif /* CONFIG_CIFS_POSIX */
84210e91 888 .setlease = cifs_setlease,
8b94bcb9
SF
889};
890
8be7e6ba
PS
891const struct file_operations cifs_file_strict_nobrl_ops = {
892 .read = do_sync_read,
893 .write = do_sync_write,
a70307ee 894 .aio_read = cifs_strict_readv,
72432ffc 895 .aio_write = cifs_strict_writev,
8be7e6ba
PS
896 .open = cifs_open,
897 .release = cifs_close,
898 .fsync = cifs_strict_fsync,
899 .flush = cifs_flush,
7a6a19b1 900 .mmap = cifs_file_strict_mmap,
8be7e6ba
PS
901 .splice_read = generic_file_splice_read,
902 .llseek = cifs_llseek,
903#ifdef CONFIG_CIFS_POSIX
904 .unlocked_ioctl = cifs_ioctl,
905#endif /* CONFIG_CIFS_POSIX */
906 .setlease = cifs_setlease,
907};
908
4b6f5d20 909const struct file_operations cifs_file_direct_nobrl_ops = {
0b81c1c4
PS
910 /* BB reevaluate whether they can be done with directio, no cache */
911 .read = do_sync_read,
912 .write = do_sync_write,
913 .aio_read = cifs_user_readv,
914 .aio_write = cifs_user_writev,
87c89dd7
SF
915 .open = cifs_open,
916 .release = cifs_close,
917 .fsync = cifs_fsync,
918 .flush = cifs_flush,
810627a0 919 .mmap = cifs_file_mmap,
5ffc4ef4 920 .splice_read = generic_file_splice_read,
8b94bcb9 921#ifdef CONFIG_CIFS_POSIX
f9ddcca4 922 .unlocked_ioctl = cifs_ioctl,
8b94bcb9 923#endif /* CONFIG_CIFS_POSIX */
c32a0b68 924 .llseek = cifs_llseek,
84210e91 925 .setlease = cifs_setlease,
8b94bcb9 926};
1da177e4 927
4b6f5d20 928const struct file_operations cifs_dir_ops = {
1da177e4
LT
929 .readdir = cifs_readdir,
930 .release = cifs_closedir,
931 .read = generic_read_dir,
f9ddcca4 932 .unlocked_ioctl = cifs_ioctl,
3222a3e5 933 .llseek = generic_file_llseek,
1da177e4
LT
934};
935
936static void
51cc5068 937cifs_init_once(void *inode)
1da177e4
LT
938{
939 struct cifsInodeInfo *cifsi = inode;
940
a35afb83 941 inode_init_once(&cifsi->vfs_inode);
d59dad2b
PS
942 INIT_LIST_HEAD(&cifsi->llist);
943 mutex_init(&cifsi->lock_mutex);
1da177e4
LT
944}
945
946static int
947cifs_init_inodecache(void)
948{
949 cifs_inode_cachep = kmem_cache_create("cifs_inode_cache",
26f57364 950 sizeof(struct cifsInodeInfo),
fffb60f9
PJ
951 0, (SLAB_RECLAIM_ACCOUNT|
952 SLAB_MEM_SPREAD),
20c2df83 953 cifs_init_once);
1da177e4
LT
954 if (cifs_inode_cachep == NULL)
955 return -ENOMEM;
956
957 return 0;
958}
959
960static void
961cifs_destroy_inodecache(void)
962{
1a1d92c1 963 kmem_cache_destroy(cifs_inode_cachep);
1da177e4
LT
964}
965
966static int
967cifs_init_request_bufs(void)
968{
4523cc30 969 if (CIFSMaxBufSize < 8192) {
1da177e4
LT
970 /* Buffer size can not be smaller than 2 * PATH_MAX since maximum
971 Unicode path name has to fit in any SMB/CIFS path based frames */
972 CIFSMaxBufSize = 8192;
973 } else if (CIFSMaxBufSize > 1024*127) {
974 CIFSMaxBufSize = 1024 * 127;
975 } else {
976 CIFSMaxBufSize &= 0x1FE00; /* Round size to even 512 byte mult*/
977 }
b6b38f70 978/* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
1da177e4
LT
979 cifs_req_cachep = kmem_cache_create("cifs_request",
980 CIFSMaxBufSize +
981 MAX_CIFS_HDR_SIZE, 0,
20c2df83 982 SLAB_HWCACHE_ALIGN, NULL);
1da177e4
LT
983 if (cifs_req_cachep == NULL)
984 return -ENOMEM;
985
4523cc30 986 if (cifs_min_rcv < 1)
1da177e4
LT
987 cifs_min_rcv = 1;
988 else if (cifs_min_rcv > 64) {
989 cifs_min_rcv = 64;
b6b38f70 990 cERROR(1, "cifs_min_rcv set to maximum (64)");
1da177e4
LT
991 }
992
93d2341c
MD
993 cifs_req_poolp = mempool_create_slab_pool(cifs_min_rcv,
994 cifs_req_cachep);
1da177e4 995
4523cc30 996 if (cifs_req_poolp == NULL) {
1da177e4
LT
997 kmem_cache_destroy(cifs_req_cachep);
998 return -ENOMEM;
999 }
ec637e3f 1000 /* MAX_CIFS_SMALL_BUFFER_SIZE bytes is enough for most SMB responses and
1da177e4
LT
1001 almost all handle based requests (but not write response, nor is it
1002 sufficient for path based requests). A smaller size would have
50c2f753 1003 been more efficient (compacting multiple slab items on one 4k page)
1da177e4
LT
1004 for the case in which debug was on, but this larger size allows
1005 more SMBs to use small buffer alloc and is still much more
6dc0f87e 1006 efficient to alloc 1 per page off the slab compared to 17K (5page)
1da177e4
LT
1007 alloc of large cifs buffers even when page debugging is on */
1008 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
6dc0f87e 1009 MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
20c2df83 1010 NULL);
1da177e4
LT
1011 if (cifs_sm_req_cachep == NULL) {
1012 mempool_destroy(cifs_req_poolp);
1013 kmem_cache_destroy(cifs_req_cachep);
6dc0f87e 1014 return -ENOMEM;
1da177e4
LT
1015 }
1016
4523cc30 1017 if (cifs_min_small < 2)
1da177e4
LT
1018 cifs_min_small = 2;
1019 else if (cifs_min_small > 256) {
1020 cifs_min_small = 256;
b6b38f70 1021 cFYI(1, "cifs_min_small set to maximum (256)");
1da177e4
LT
1022 }
1023
93d2341c
MD
1024 cifs_sm_req_poolp = mempool_create_slab_pool(cifs_min_small,
1025 cifs_sm_req_cachep);
1da177e4 1026
4523cc30 1027 if (cifs_sm_req_poolp == NULL) {
1da177e4
LT
1028 mempool_destroy(cifs_req_poolp);
1029 kmem_cache_destroy(cifs_req_cachep);
1030 kmem_cache_destroy(cifs_sm_req_cachep);
1031 return -ENOMEM;
1032 }
1033
1034 return 0;
1035}
1036
1037static void
1038cifs_destroy_request_bufs(void)
1039{
1040 mempool_destroy(cifs_req_poolp);
1a1d92c1 1041 kmem_cache_destroy(cifs_req_cachep);
1da177e4 1042 mempool_destroy(cifs_sm_req_poolp);
1a1d92c1 1043 kmem_cache_destroy(cifs_sm_req_cachep);
1da177e4
LT
1044}
1045
1046static int
1047cifs_init_mids(void)
1048{
1049 cifs_mid_cachep = kmem_cache_create("cifs_mpx_ids",
26f57364
SF
1050 sizeof(struct mid_q_entry), 0,
1051 SLAB_HWCACHE_ALIGN, NULL);
1da177e4
LT
1052 if (cifs_mid_cachep == NULL)
1053 return -ENOMEM;
1054
93d2341c
MD
1055 /* 3 is a reasonable minimum number of simultaneous operations */
1056 cifs_mid_poolp = mempool_create_slab_pool(3, cifs_mid_cachep);
4523cc30 1057 if (cifs_mid_poolp == NULL) {
1da177e4
LT
1058 kmem_cache_destroy(cifs_mid_cachep);
1059 return -ENOMEM;
1060 }
1061
1da177e4
LT
1062 return 0;
1063}
1064
1065static void
1066cifs_destroy_mids(void)
1067{
1068 mempool_destroy(cifs_mid_poolp);
1a1d92c1 1069 kmem_cache_destroy(cifs_mid_cachep);
1da177e4
LT
1070}
1071
1da177e4
LT
1072static int __init
1073init_cifs(void)
1074{
1075 int rc = 0;
1da177e4 1076 cifs_proc_init();
e7ddee90 1077 INIT_LIST_HEAD(&cifs_tcp_ses_list);
0eff0e26 1078#ifdef CONFIG_CIFS_DNOTIFY_EXPERIMENTAL /* unused temporarily */
4ca9c190
SF
1079 INIT_LIST_HEAD(&GlobalDnotifyReqList);
1080 INIT_LIST_HEAD(&GlobalDnotifyRsp_Q);
0eff0e26 1081#endif /* was needed for dnotify, and will be needed for inotify when VFS fix */
1da177e4
LT
1082/*
1083 * Initialize Global counters
1084 */
1085 atomic_set(&sesInfoAllocCount, 0);
1086 atomic_set(&tconInfoAllocCount, 0);
6dc0f87e 1087 atomic_set(&tcpSesAllocCount, 0);
1da177e4
LT
1088 atomic_set(&tcpSesReconnectCount, 0);
1089 atomic_set(&tconInfoReconnectCount, 0);
1090
1091 atomic_set(&bufAllocCount, 0);
4498eed5
SF
1092 atomic_set(&smBufAllocCount, 0);
1093#ifdef CONFIG_CIFS_STATS2
1094 atomic_set(&totBufAllocCount, 0);
1095 atomic_set(&totSmBufAllocCount, 0);
1096#endif /* CONFIG_CIFS_STATS2 */
1097
1da177e4
LT
1098 atomic_set(&midCount, 0);
1099 GlobalCurrentXid = 0;
1100 GlobalTotalActiveXid = 0;
1101 GlobalMaxActiveXid = 0;
3f9bcca7 1102 spin_lock_init(&cifs_tcp_ses_lock);
4477288a 1103 spin_lock_init(&cifs_file_list_lock);
1da177e4
LT
1104 spin_lock_init(&GlobalMid_Lock);
1105
4523cc30 1106 if (cifs_max_pending < 2) {
1da177e4 1107 cifs_max_pending = 2;
b6b38f70 1108 cFYI(1, "cifs_max_pending set to min of 2");
10b9b98e
PS
1109 } else if (cifs_max_pending > CIFS_MAX_REQ) {
1110 cifs_max_pending = CIFS_MAX_REQ;
1111 cFYI(1, "cifs_max_pending set to max of %u", CIFS_MAX_REQ);
1da177e4
LT
1112 }
1113
f579cf3c
SJ
1114 rc = cifs_fscache_register();
1115 if (rc)
d3bf5221 1116 goto out_clean_proc;
f579cf3c 1117
1da177e4 1118 rc = cifs_init_inodecache();
45af7a0f 1119 if (rc)
d3bf5221 1120 goto out_unreg_fscache;
45af7a0f
SF
1121
1122 rc = cifs_init_mids();
1123 if (rc)
1124 goto out_destroy_inodecache;
1125
1126 rc = cifs_init_request_bufs();
1127 if (rc)
1128 goto out_destroy_mids;
1129
84a15b93
JL
1130#ifdef CONFIG_CIFS_UPCALL
1131 rc = register_key_type(&cifs_spnego_key_type);
1132 if (rc)
4d79dba0
SP
1133 goto out_destroy_request_bufs;
1134#endif /* CONFIG_CIFS_UPCALL */
1135
1136#ifdef CONFIG_CIFS_ACL
1137 rc = init_cifs_idmap();
1138 if (rc)
c4aca0c0 1139 goto out_register_key_type;
4d79dba0
SP
1140#endif /* CONFIG_CIFS_ACL */
1141
1142 rc = register_filesystem(&cifs_fs_type);
1143 if (rc)
c4aca0c0 1144 goto out_init_cifs_idmap;
45af7a0f 1145
45af7a0f
SF
1146 return 0;
1147
c4aca0c0 1148out_init_cifs_idmap:
4d79dba0
SP
1149#ifdef CONFIG_CIFS_ACL
1150 exit_cifs_idmap();
c4aca0c0 1151out_register_key_type:
4d79dba0 1152#endif
84a15b93 1153#ifdef CONFIG_CIFS_UPCALL
4d79dba0 1154 unregister_key_type(&cifs_spnego_key_type);
c4aca0c0 1155out_destroy_request_bufs:
1fc7995d 1156#endif
45af7a0f 1157 cifs_destroy_request_bufs();
d3bf5221 1158out_destroy_mids:
45af7a0f 1159 cifs_destroy_mids();
d3bf5221 1160out_destroy_inodecache:
45af7a0f 1161 cifs_destroy_inodecache();
d3bf5221 1162out_unreg_fscache:
f579cf3c 1163 cifs_fscache_unregister();
d3bf5221
SF
1164out_clean_proc:
1165 cifs_proc_clean();
1da177e4
LT
1166 return rc;
1167}
1168
1169static void __exit
1170exit_cifs(void)
1171{
b6b38f70 1172 cFYI(DBG2, "exit_cifs");
3dd93306 1173 unregister_filesystem(&cifs_fs_type);
78d31a3a 1174 cifs_dfs_release_automount_timer();
4d79dba0
SP
1175#ifdef CONFIG_CIFS_ACL
1176 cifs_destroy_idmaptrees();
1177 exit_cifs_idmap();
1178#endif
84a15b93
JL
1179#ifdef CONFIG_CIFS_UPCALL
1180 unregister_key_type(&cifs_spnego_key_type);
1da177e4 1181#endif
1da177e4 1182 cifs_destroy_request_bufs();
3dd93306
JL
1183 cifs_destroy_mids();
1184 cifs_destroy_inodecache();
1185 cifs_fscache_unregister();
1186 cifs_proc_clean();
1da177e4
LT
1187}
1188
1189MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>");
6dc0f87e 1190MODULE_LICENSE("GPL"); /* combination of LGPL + GPL source behaves as GPL */
1da177e4 1191MODULE_DESCRIPTION
63135e08
SF
1192 ("VFS to access servers complying with the SNIA CIFS Specification "
1193 "e.g. Samba and Windows");
1da177e4
LT
1194MODULE_VERSION(CIFS_VERSION);
1195module_init(init_cifs)
1196module_exit(exit_cifs)
This page took 0.627852 seconds and 5 git commands to generate.