]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * fs/cifs/cifsfs.c | |
3 | * | |
35c11fdd | 4 | * Copyright (C) International Business Machines Corp., 2002,2007 |
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> |
1da177e4 LT |
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> | |
84a15b93 | 46 | #include <linux/key-type.h> |
1da177e4 LT |
47 | #define CIFS_MAGIC_NUMBER 0xFF534D42 /* the first four bytes of SMB PDUs */ |
48 | ||
49 | #ifdef CONFIG_CIFS_QUOTA | |
50 | static struct quotactl_ops cifs_quotactl_ops; | |
35c11fdd SF |
51 | #endif /* QUOTA */ |
52 | ||
1da177e4 LT |
53 | int cifsFYI = 0; |
54 | int cifsERROR = 1; | |
55 | int traceSMB = 0; | |
56 | unsigned int oplockEnabled = 1; | |
57 | unsigned int experimEnabled = 0; | |
58 | unsigned int linuxExtEnabled = 1; | |
59 | unsigned int lookupCacheEnabled = 1; | |
60 | unsigned int multiuser_mount = 0; | |
3979877e SF |
61 | unsigned int extended_security = CIFSSEC_DEF; |
62 | /* unsigned int ntlmv2_support = 0; */ | |
1da177e4 | 63 | unsigned int sign_CIFS_PDUs = 1; |
6dc0f87e SF |
64 | extern struct task_struct *oplockThread; /* remove sparse warning */ |
65 | struct task_struct *oplockThread = NULL; | |
99ee4dbd | 66 | /* extern struct task_struct * dnotifyThread; remove sparse warning */ |
6dc0f87e | 67 | static struct task_struct *dnotifyThread = NULL; |
ee9b6d61 | 68 | static const struct super_operations cifs_super_ops; |
1da177e4 LT |
69 | unsigned int CIFSMaxBufSize = CIFS_MAX_MSGSIZE; |
70 | module_param(CIFSMaxBufSize, int, 0); | |
63135e08 SF |
71 | MODULE_PARM_DESC(CIFSMaxBufSize, "Network buffer size (not including header). " |
72 | "Default: 16384 Range: 8192 to 130048"); | |
1da177e4 LT |
73 | unsigned int cifs_min_rcv = CIFS_MIN_RCV_POOL; |
74 | module_param(cifs_min_rcv, int, 0); | |
63135e08 SF |
75 | MODULE_PARM_DESC(cifs_min_rcv, "Network buffers in pool. Default: 4 Range: " |
76 | "1 to 64"); | |
1da177e4 LT |
77 | unsigned int cifs_min_small = 30; |
78 | module_param(cifs_min_small, int, 0); | |
63135e08 SF |
79 | MODULE_PARM_DESC(cifs_min_small, "Small network buffers in pool. Default: 30 " |
80 | "Range: 2 to 256"); | |
1da177e4 LT |
81 | unsigned int cifs_max_pending = CIFS_MAX_REQ; |
82 | module_param(cifs_max_pending, int, 0); | |
63135e08 SF |
83 | MODULE_PARM_DESC(cifs_max_pending, "Simultaneous requests to server. " |
84 | "Default: 50 Range: 2 to 256"); | |
1da177e4 | 85 | |
1da177e4 LT |
86 | extern mempool_t *cifs_sm_req_poolp; |
87 | extern mempool_t *cifs_req_poolp; | |
88 | extern mempool_t *cifs_mid_poolp; | |
89 | ||
e18b890b | 90 | extern struct kmem_cache *cifs_oplock_cachep; |
1da177e4 LT |
91 | |
92 | static int | |
93 | cifs_read_super(struct super_block *sb, void *data, | |
94 | const char *devname, int silent) | |
95 | { | |
96 | struct inode *inode; | |
97 | struct cifs_sb_info *cifs_sb; | |
98 | int rc = 0; | |
50c2f753 | 99 | |
1b2b2126 SF |
100 | /* BB should we make this contingent on mount parm? */ |
101 | sb->s_flags |= MS_NODIRATIME | MS_NOATIME; | |
790fe579 | 102 | sb->s_fs_info = kzalloc(sizeof(struct cifs_sb_info), GFP_KERNEL); |
1da177e4 | 103 | cifs_sb = CIFS_SB(sb); |
4523cc30 | 104 | if (cifs_sb == NULL) |
1da177e4 | 105 | return -ENOMEM; |
1da177e4 LT |
106 | |
107 | rc = cifs_mount(sb, cifs_sb, data, devname); | |
108 | ||
109 | if (rc) { | |
110 | if (!silent) | |
111 | cERROR(1, | |
112 | ("cifs_mount failed w/return code = %d", rc)); | |
113 | goto out_mount_failed; | |
114 | } | |
115 | ||
116 | sb->s_magic = CIFS_MAGIC_NUMBER; | |
117 | sb->s_op = &cifs_super_ops; | |
4523cc30 | 118 | /* if (cifs_sb->tcon->ses->server->maxBuf > MAX_CIFS_HDR_SIZE + 512) |
790fe579 SF |
119 | sb->s_blocksize = |
120 | cifs_sb->tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE; */ | |
1da177e4 LT |
121 | #ifdef CONFIG_CIFS_QUOTA |
122 | sb->s_qcop = &cifs_quotactl_ops; | |
123 | #endif | |
124 | sb->s_blocksize = CIFS_MAX_MSGSIZE; | |
125 | sb->s_blocksize_bits = 14; /* default 2**14 = CIFS_MAX_MSGSIZE */ | |
126 | inode = iget(sb, ROOT_I); | |
127 | ||
128 | if (!inode) { | |
129 | rc = -ENOMEM; | |
130 | goto out_no_root; | |
131 | } | |
132 | ||
133 | sb->s_root = d_alloc_root(inode); | |
134 | ||
135 | if (!sb->s_root) { | |
136 | rc = -ENOMEM; | |
137 | goto out_no_root; | |
138 | } | |
50c2f753 | 139 | |
7521a3c5 SF |
140 | #ifdef CONFIG_CIFS_EXPERIMENTAL |
141 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) { | |
142 | cFYI(1, ("export ops supported")); | |
143 | sb->s_export_op = &cifs_export_ops; | |
144 | } | |
145 | #endif /* EXPERIMENTAL */ | |
1da177e4 LT |
146 | |
147 | return 0; | |
148 | ||
149 | out_no_root: | |
150 | cERROR(1, ("cifs_read_super: get root inode failed")); | |
151 | if (inode) | |
152 | iput(inode); | |
153 | ||
154 | out_mount_failed: | |
4523cc30 SF |
155 | if (cifs_sb) { |
156 | if (cifs_sb->local_nls) | |
50c2f753 | 157 | unload_nls(cifs_sb->local_nls); |
1da177e4 LT |
158 | kfree(cifs_sb); |
159 | } | |
160 | return rc; | |
161 | } | |
162 | ||
163 | static void | |
164 | cifs_put_super(struct super_block *sb) | |
165 | { | |
166 | int rc = 0; | |
167 | struct cifs_sb_info *cifs_sb; | |
168 | ||
169 | cFYI(1, ("In cifs_put_super")); | |
170 | cifs_sb = CIFS_SB(sb); | |
4523cc30 | 171 | if (cifs_sb == NULL) { |
790fe579 | 172 | cFYI(1, ("Empty cifs superblock info passed to unmount")); |
1da177e4 LT |
173 | return; |
174 | } | |
790fe579 | 175 | rc = cifs_umount(sb, cifs_sb); |
1da177e4 LT |
176 | if (rc) { |
177 | cERROR(1, ("cifs_umount failed with return code %d", rc)); | |
178 | } | |
179 | unload_nls(cifs_sb->local_nls); | |
180 | kfree(cifs_sb); | |
181 | return; | |
182 | } | |
183 | ||
184 | static int | |
726c3342 | 185 | cifs_statfs(struct dentry *dentry, struct kstatfs *buf) |
1da177e4 | 186 | { |
726c3342 | 187 | struct super_block *sb = dentry->d_sb; |
790fe579 | 188 | int xid; |
c81156dd | 189 | int rc = -EOPNOTSUPP; |
1da177e4 LT |
190 | struct cifs_sb_info *cifs_sb; |
191 | struct cifsTconInfo *pTcon; | |
192 | ||
193 | xid = GetXid(); | |
194 | ||
195 | cifs_sb = CIFS_SB(sb); | |
196 | pTcon = cifs_sb->tcon; | |
197 | ||
198 | buf->f_type = CIFS_MAGIC_NUMBER; | |
199 | ||
200 | /* instead could get the real value via SMB_QUERY_FS_ATTRIBUTE_INFO */ | |
790fe579 | 201 | buf->f_namelen = PATH_MAX; /* PATH_MAX may be too long - it would |
c81156dd SF |
202 | presumably be total path, but note |
203 | that some servers (includinng Samba 3) | |
204 | have a shorter maximum path */ | |
1da177e4 LT |
205 | buf->f_files = 0; /* undefined */ |
206 | buf->f_ffree = 0; /* unlimited */ | |
207 | ||
1da177e4 | 208 | /* BB we could add a second check for a QFS Unix capability bit */ |
f28ac91b | 209 | /* BB FIXME check CIFS_POSIX_EXTENSIONS Unix cap first FIXME BB */ |
c81156dd SF |
210 | if ((pTcon->ses->capabilities & CAP_UNIX) && (CIFS_POSIX_EXTENSIONS & |
211 | le64_to_cpu(pTcon->fsUnixInfo.Capability))) | |
737b758c | 212 | rc = CIFSSMBQFSPosixInfo(xid, pTcon, buf); |
1da177e4 LT |
213 | |
214 | /* Only need to call the old QFSInfo if failed | |
215 | on newer one */ | |
4523cc30 SF |
216 | if (rc) |
217 | if (pTcon->ses->capabilities & CAP_NT_SMBS) | |
9ac00b7d | 218 | rc = CIFSSMBQFSInfo(xid, pTcon, buf); /* not supported by OS2 */ |
1da177e4 | 219 | |
9ac00b7d SF |
220 | /* Some old Windows servers also do not support level 103, retry with |
221 | older level one if old server failed the previous call or we | |
222 | bypassed it because we detected that this was an older LANMAN sess */ | |
4523cc30 | 223 | if (rc) |
20962438 | 224 | rc = SMBOldQFSInfo(xid, pTcon, buf); |
790fe579 | 225 | /* int f_type; |
1da177e4 LT |
226 | __fsid_t f_fsid; |
227 | int f_namelen; */ | |
c81156dd | 228 | /* BB get from info in tcon struct at mount time call to QFSAttrInfo */ |
1da177e4 | 229 | FreeXid(xid); |
c81156dd SF |
230 | return 0; /* always return success? what if volume is no |
231 | longer available? */ | |
1da177e4 LT |
232 | } |
233 | ||
50c2f753 | 234 | static int cifs_permission(struct inode *inode, int mask, struct nameidata *nd) |
1da177e4 LT |
235 | { |
236 | struct cifs_sb_info *cifs_sb; | |
237 | ||
238 | cifs_sb = CIFS_SB(inode->i_sb); | |
239 | ||
26f57364 | 240 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) |
1da177e4 | 241 | return 0; |
26f57364 | 242 | else /* file mode might have been restricted at mount time |
50c2f753 | 243 | on the client (above and beyond ACL on servers) for |
1da177e4 | 244 | servers which do not support setting and viewing mode bits, |
50c2f753 | 245 | so allowing client to check permissions is useful */ |
1da177e4 LT |
246 | return generic_permission(inode, mask, NULL); |
247 | } | |
248 | ||
e18b890b CL |
249 | static struct kmem_cache *cifs_inode_cachep; |
250 | static struct kmem_cache *cifs_req_cachep; | |
251 | static struct kmem_cache *cifs_mid_cachep; | |
252 | struct kmem_cache *cifs_oplock_cachep; | |
253 | static struct kmem_cache *cifs_sm_req_cachep; | |
1da177e4 LT |
254 | mempool_t *cifs_sm_req_poolp; |
255 | mempool_t *cifs_req_poolp; | |
256 | mempool_t *cifs_mid_poolp; | |
257 | ||
258 | static struct inode * | |
259 | cifs_alloc_inode(struct super_block *sb) | |
260 | { | |
261 | struct cifsInodeInfo *cifs_inode; | |
e94b1766 | 262 | cifs_inode = kmem_cache_alloc(cifs_inode_cachep, GFP_KERNEL); |
1da177e4 LT |
263 | if (!cifs_inode) |
264 | return NULL; | |
265 | cifs_inode->cifsAttrs = 0x20; /* default */ | |
266 | atomic_set(&cifs_inode->inUse, 0); | |
267 | cifs_inode->time = 0; | |
268 | /* Until the file is open and we have gotten oplock | |
269 | info back from the server, can not assume caching of | |
270 | file data or metadata */ | |
271 | cifs_inode->clientCanCacheRead = FALSE; | |
272 | cifs_inode->clientCanCacheAll = FALSE; | |
1da177e4 | 273 | cifs_inode->vfs_inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */ |
50c2f753 | 274 | |
1b2b2126 SF |
275 | /* Can not set i_flags here - they get immediately overwritten |
276 | to zero by the VFS */ | |
277 | /* cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME;*/ | |
1da177e4 LT |
278 | INIT_LIST_HEAD(&cifs_inode->openFileList); |
279 | return &cifs_inode->vfs_inode; | |
280 | } | |
281 | ||
282 | static void | |
283 | cifs_destroy_inode(struct inode *inode) | |
284 | { | |
285 | kmem_cache_free(cifs_inode_cachep, CIFS_I(inode)); | |
286 | } | |
287 | ||
288 | /* | |
289 | * cifs_show_options() is for displaying mount options in /proc/mounts. | |
290 | * Not all settable options are displayed but most of the important | |
291 | * ones are. | |
292 | */ | |
293 | static int | |
294 | cifs_show_options(struct seq_file *s, struct vfsmount *m) | |
295 | { | |
296 | struct cifs_sb_info *cifs_sb; | |
297 | ||
298 | cifs_sb = CIFS_SB(m->mnt_sb); | |
299 | ||
300 | if (cifs_sb) { | |
301 | if (cifs_sb->tcon) { | |
004c46b9 | 302 | /* BB add prepath to mount options displayed */ |
1da177e4 LT |
303 | seq_printf(s, ",unc=%s", cifs_sb->tcon->treeName); |
304 | if (cifs_sb->tcon->ses) { | |
305 | if (cifs_sb->tcon->ses->userName) | |
306 | seq_printf(s, ",username=%s", | |
307 | cifs_sb->tcon->ses->userName); | |
4523cc30 | 308 | if (cifs_sb->tcon->ses->domainName) |
1da177e4 LT |
309 | seq_printf(s, ",domain=%s", |
310 | cifs_sb->tcon->ses->domainName); | |
311 | } | |
d5d18501 SF |
312 | if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID) || |
313 | !(cifs_sb->tcon->unix_ext)) | |
314 | seq_printf(s, ",uid=%d", cifs_sb->mnt_uid); | |
315 | if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID) || | |
316 | !(cifs_sb->tcon->unix_ext)) | |
317 | seq_printf(s, ",gid=%d", cifs_sb->mnt_gid); | |
1da177e4 | 318 | } |
4523cc30 SF |
319 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS) |
320 | seq_printf(s, ",posixpaths"); | |
50c2f753 SF |
321 | seq_printf(s, ",rsize=%d", cifs_sb->rsize); |
322 | seq_printf(s, ",wsize=%d", cifs_sb->wsize); | |
1da177e4 LT |
323 | } |
324 | return 0; | |
325 | } | |
326 | ||
327 | #ifdef CONFIG_CIFS_QUOTA | |
50c2f753 SF |
328 | int cifs_xquota_set(struct super_block *sb, int quota_type, qid_t qid, |
329 | struct fs_disk_quota *pdquota) | |
1da177e4 LT |
330 | { |
331 | int xid; | |
332 | int rc = 0; | |
333 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); | |
334 | struct cifsTconInfo *pTcon; | |
50c2f753 | 335 | |
4523cc30 | 336 | if (cifs_sb) |
1da177e4 LT |
337 | pTcon = cifs_sb->tcon; |
338 | else | |
339 | return -EIO; | |
340 | ||
341 | ||
342 | xid = GetXid(); | |
4523cc30 | 343 | if (pTcon) { |
50c2f753 | 344 | cFYI(1, ("set type: 0x%x id: %d", quota_type, qid)); |
1da177e4 | 345 | } else { |
95ba7362 | 346 | rc = -EIO; |
1da177e4 LT |
347 | } |
348 | ||
349 | FreeXid(xid); | |
350 | return rc; | |
351 | } | |
352 | ||
50c2f753 SF |
353 | int cifs_xquota_get(struct super_block *sb, int quota_type, qid_t qid, |
354 | struct fs_disk_quota *pdquota) | |
1da177e4 LT |
355 | { |
356 | int xid; | |
357 | int rc = 0; | |
358 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); | |
359 | struct cifsTconInfo *pTcon; | |
360 | ||
4523cc30 | 361 | if (cifs_sb) |
1da177e4 LT |
362 | pTcon = cifs_sb->tcon; |
363 | else | |
364 | return -EIO; | |
365 | ||
366 | xid = GetXid(); | |
4523cc30 | 367 | if (pTcon) { |
50c2f753 | 368 | cFYI(1, ("set type: 0x%x id: %d", quota_type, qid)); |
1da177e4 LT |
369 | } else { |
370 | rc = -EIO; | |
371 | } | |
372 | ||
373 | FreeXid(xid); | |
374 | return rc; | |
375 | } | |
376 | ||
50c2f753 | 377 | int cifs_xstate_set(struct super_block *sb, unsigned int flags, int operation) |
1da177e4 | 378 | { |
50c2f753 | 379 | int xid; |
1da177e4 LT |
380 | int rc = 0; |
381 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); | |
382 | struct cifsTconInfo *pTcon; | |
383 | ||
4523cc30 | 384 | if (cifs_sb) |
1da177e4 LT |
385 | pTcon = cifs_sb->tcon; |
386 | else | |
387 | return -EIO; | |
388 | ||
389 | xid = GetXid(); | |
4523cc30 | 390 | if (pTcon) { |
50c2f753 | 391 | cFYI(1, ("flags: 0x%x operation: 0x%x", flags, operation)); |
1da177e4 LT |
392 | } else { |
393 | rc = -EIO; | |
394 | } | |
395 | ||
396 | FreeXid(xid); | |
397 | return rc; | |
398 | } | |
399 | ||
50c2f753 | 400 | int cifs_xstate_get(struct super_block *sb, struct fs_quota_stat *qstats) |
1da177e4 LT |
401 | { |
402 | int xid; | |
403 | int rc = 0; | |
404 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); | |
405 | struct cifsTconInfo *pTcon; | |
406 | ||
4523cc30 | 407 | if (cifs_sb) { |
1da177e4 LT |
408 | pTcon = cifs_sb->tcon; |
409 | } else { | |
410 | return -EIO; | |
411 | } | |
412 | xid = GetXid(); | |
4523cc30 | 413 | if (pTcon) { |
50c2f753 | 414 | cFYI(1, ("pqstats %p", qstats)); |
1da177e4 LT |
415 | } else { |
416 | rc = -EIO; | |
417 | } | |
418 | ||
419 | FreeXid(xid); | |
420 | return rc; | |
421 | } | |
422 | ||
423 | static struct quotactl_ops cifs_quotactl_ops = { | |
424 | .set_xquota = cifs_xquota_set, | |
425 | .get_xquota = cifs_xquota_set, | |
426 | .set_xstate = cifs_xstate_set, | |
427 | .get_xstate = cifs_xstate_get, | |
428 | }; | |
429 | #endif | |
430 | ||
50c2f753 | 431 | static void cifs_umount_begin(struct vfsmount *vfsmnt, int flags) |
68058e75 | 432 | { |
5e1253b5 | 433 | struct cifs_sb_info *cifs_sb; |
50c2f753 | 434 | struct cifsTconInfo *tcon; |
68058e75 | 435 | |
8b512d9a TM |
436 | if (!(flags & MNT_FORCE)) |
437 | return; | |
438 | cifs_sb = CIFS_SB(vfsmnt->mnt_sb); | |
4523cc30 | 439 | if (cifs_sb == NULL) |
9e2e85f8 SF |
440 | return; |
441 | ||
442 | tcon = cifs_sb->tcon; | |
4523cc30 | 443 | if (tcon == NULL) |
9e2e85f8 | 444 | return; |
5e1253b5 SF |
445 | down(&tcon->tconSem); |
446 | if (atomic_read(&tcon->useCount) == 1) | |
447 | tcon->tidStatus = CifsExiting; | |
448 | up(&tcon->tconSem); | |
449 | ||
3a5ff61c | 450 | /* cancel_brl_requests(tcon); */ /* BB mark all brl mids as exiting */ |
7b7abfe3 | 451 | /* cancel_notify_requests(tcon); */ |
50c2f753 SF |
452 | if (tcon->ses && tcon->ses->server) { |
453 | cFYI(1, ("wake up tasks now - umount begin not complete")); | |
9e2e85f8 | 454 | wake_up_all(&tcon->ses->server->request_q); |
6ab16d24 SF |
455 | wake_up_all(&tcon->ses->server->response_q); |
456 | msleep(1); /* yield */ | |
457 | /* we have to kick the requests once more */ | |
458 | wake_up_all(&tcon->ses->server->response_q); | |
459 | msleep(1); | |
5e1253b5 SF |
460 | } |
461 | /* BB FIXME - finish add checks for tidStatus BB */ | |
68058e75 SF |
462 | |
463 | return; | |
464 | } | |
68058e75 | 465 | |
bf97d287 SF |
466 | #ifdef CONFIG_CIFS_STATS2 |
467 | static int cifs_show_stats(struct seq_file *s, struct vfsmount *mnt) | |
468 | { | |
469 | /* BB FIXME */ | |
470 | return 0; | |
471 | } | |
472 | #endif | |
473 | ||
1da177e4 LT |
474 | static int cifs_remount(struct super_block *sb, int *flags, char *data) |
475 | { | |
476 | *flags |= MS_NODIRATIME; | |
477 | return 0; | |
478 | } | |
479 | ||
ee9b6d61 | 480 | static const struct super_operations cifs_super_ops = { |
1da177e4 LT |
481 | .read_inode = cifs_read_inode, |
482 | .put_super = cifs_put_super, | |
483 | .statfs = cifs_statfs, | |
484 | .alloc_inode = cifs_alloc_inode, | |
485 | .destroy_inode = cifs_destroy_inode, | |
50c2f753 SF |
486 | /* .drop_inode = generic_delete_inode, |
487 | .delete_inode = cifs_delete_inode, */ /* Do not need above two | |
488 | functions unless later we add lazy close of inodes or unless the | |
489 | kernel forgets to call us with the same number of releases (closes) | |
490 | as opens */ | |
1da177e4 | 491 | .show_options = cifs_show_options, |
7b7abfe3 | 492 | .umount_begin = cifs_umount_begin, |
1da177e4 | 493 | .remount_fs = cifs_remount, |
bf97d287 | 494 | #ifdef CONFIG_CIFS_STATS2 |
f46d3e11 | 495 | .show_stats = cifs_show_stats, |
bf97d287 | 496 | #endif |
1da177e4 LT |
497 | }; |
498 | ||
454e2398 | 499 | static int |
1da177e4 | 500 | cifs_get_sb(struct file_system_type *fs_type, |
454e2398 | 501 | int flags, const char *dev_name, void *data, struct vfsmount *mnt) |
1da177e4 LT |
502 | { |
503 | int rc; | |
504 | struct super_block *sb = sget(fs_type, NULL, set_anon_super, NULL); | |
505 | ||
506 | cFYI(1, ("Devname: %s flags: %d ", dev_name, flags)); | |
507 | ||
508 | if (IS_ERR(sb)) | |
454e2398 | 509 | return PTR_ERR(sb); |
1da177e4 LT |
510 | |
511 | sb->s_flags = flags; | |
512 | ||
9b04c997 | 513 | rc = cifs_read_super(sb, data, dev_name, flags & MS_SILENT ? 1 : 0); |
1da177e4 LT |
514 | if (rc) { |
515 | up_write(&sb->s_umount); | |
516 | deactivate_super(sb); | |
454e2398 | 517 | return rc; |
1da177e4 LT |
518 | } |
519 | sb->s_flags |= MS_ACTIVE; | |
454e2398 | 520 | return simple_set_mnt(mnt, sb); |
1da177e4 LT |
521 | } |
522 | ||
027445c3 BP |
523 | static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov, |
524 | unsigned long nr_segs, loff_t pos) | |
1da177e4 | 525 | { |
e6a00296 | 526 | struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode; |
1da177e4 LT |
527 | ssize_t written; |
528 | ||
027445c3 | 529 | written = generic_file_aio_write(iocb, iov, nr_segs, pos); |
87c89dd7 SF |
530 | if (!CIFS_I(inode)->clientCanCacheAll) |
531 | filemap_fdatawrite(inode->i_mapping); | |
1da177e4 LT |
532 | return written; |
533 | } | |
534 | ||
c32a0b68 SF |
535 | static loff_t cifs_llseek(struct file *file, loff_t offset, int origin) |
536 | { | |
537 | /* origin == SEEK_END => we must revalidate the cached file length */ | |
0889a944 | 538 | if (origin == SEEK_END) { |
030e9d81 SF |
539 | int retval; |
540 | ||
541 | /* some applications poll for the file length in this strange | |
542 | way so we must seek to end on non-oplocked files by | |
543 | setting the revalidate time to zero */ | |
c33f8d32 | 544 | CIFS_I(file->f_path.dentry->d_inode)->time = 0; |
030e9d81 SF |
545 | |
546 | retval = cifs_revalidate(file->f_path.dentry); | |
c32a0b68 SF |
547 | if (retval < 0) |
548 | return (loff_t)retval; | |
549 | } | |
550 | return remote_llseek(file, offset, origin); | |
551 | } | |
552 | ||
1da177e4 LT |
553 | static struct file_system_type cifs_fs_type = { |
554 | .owner = THIS_MODULE, | |
555 | .name = "cifs", | |
556 | .get_sb = cifs_get_sb, | |
557 | .kill_sb = kill_anon_super, | |
558 | /* .fs_flags */ | |
559 | }; | |
754661f1 | 560 | const struct inode_operations cifs_dir_inode_ops = { |
1da177e4 LT |
561 | .create = cifs_create, |
562 | .lookup = cifs_lookup, | |
563 | .getattr = cifs_getattr, | |
564 | .unlink = cifs_unlink, | |
565 | .link = cifs_hardlink, | |
566 | .mkdir = cifs_mkdir, | |
567 | .rmdir = cifs_rmdir, | |
568 | .rename = cifs_rename, | |
569 | .permission = cifs_permission, | |
570 | /* revalidate:cifs_revalidate, */ | |
571 | .setattr = cifs_setattr, | |
572 | .symlink = cifs_symlink, | |
573 | .mknod = cifs_mknod, | |
574 | #ifdef CONFIG_CIFS_XATTR | |
575 | .setxattr = cifs_setxattr, | |
576 | .getxattr = cifs_getxattr, | |
577 | .listxattr = cifs_listxattr, | |
578 | .removexattr = cifs_removexattr, | |
579 | #endif | |
580 | }; | |
581 | ||
754661f1 | 582 | const struct inode_operations cifs_file_inode_ops = { |
1da177e4 LT |
583 | /* revalidate:cifs_revalidate, */ |
584 | .setattr = cifs_setattr, | |
585 | .getattr = cifs_getattr, /* do we need this anymore? */ | |
586 | .rename = cifs_rename, | |
587 | .permission = cifs_permission, | |
588 | #ifdef CONFIG_CIFS_XATTR | |
589 | .setxattr = cifs_setxattr, | |
590 | .getxattr = cifs_getxattr, | |
591 | .listxattr = cifs_listxattr, | |
592 | .removexattr = cifs_removexattr, | |
50c2f753 | 593 | #endif |
1da177e4 LT |
594 | }; |
595 | ||
754661f1 | 596 | const struct inode_operations cifs_symlink_inode_ops = { |
50c2f753 | 597 | .readlink = generic_readlink, |
1da177e4 LT |
598 | .follow_link = cifs_follow_link, |
599 | .put_link = cifs_put_link, | |
600 | .permission = cifs_permission, | |
601 | /* BB add the following two eventually */ | |
602 | /* revalidate: cifs_revalidate, | |
603 | setattr: cifs_notify_change, *//* BB do we need notify change */ | |
604 | #ifdef CONFIG_CIFS_XATTR | |
605 | .setxattr = cifs_setxattr, | |
606 | .getxattr = cifs_getxattr, | |
607 | .listxattr = cifs_listxattr, | |
608 | .removexattr = cifs_removexattr, | |
50c2f753 | 609 | #endif |
1da177e4 LT |
610 | }; |
611 | ||
4b6f5d20 | 612 | const struct file_operations cifs_file_ops = { |
87c89dd7 SF |
613 | .read = do_sync_read, |
614 | .write = do_sync_write, | |
87c89dd7 SF |
615 | .aio_read = generic_file_aio_read, |
616 | .aio_write = cifs_file_aio_write, | |
1da177e4 LT |
617 | .open = cifs_open, |
618 | .release = cifs_close, | |
619 | .lock = cifs_lock, | |
620 | .fsync = cifs_fsync, | |
621 | .flush = cifs_flush, | |
622 | .mmap = cifs_file_mmap, | |
5ffc4ef4 | 623 | .splice_read = generic_file_splice_read, |
c32a0b68 | 624 | .llseek = cifs_llseek, |
c67593a0 SF |
625 | #ifdef CONFIG_CIFS_POSIX |
626 | .ioctl = cifs_ioctl, | |
627 | #endif /* CONFIG_CIFS_POSIX */ | |
628 | ||
1da177e4 | 629 | #ifdef CONFIG_CIFS_EXPERIMENTAL |
1da177e4 LT |
630 | .dir_notify = cifs_dir_notify, |
631 | #endif /* CONFIG_CIFS_EXPERIMENTAL */ | |
632 | }; | |
633 | ||
4b6f5d20 | 634 | const struct file_operations cifs_file_direct_ops = { |
50c2f753 | 635 | /* no mmap, no aio, no readv - |
1da177e4 LT |
636 | BB reevaluate whether they can be done with directio, no cache */ |
637 | .read = cifs_user_read, | |
638 | .write = cifs_user_write, | |
639 | .open = cifs_open, | |
640 | .release = cifs_close, | |
641 | .lock = cifs_lock, | |
642 | .fsync = cifs_fsync, | |
643 | .flush = cifs_flush, | |
5ffc4ef4 | 644 | .splice_read = generic_file_splice_read, |
c67593a0 SF |
645 | #ifdef CONFIG_CIFS_POSIX |
646 | .ioctl = cifs_ioctl, | |
647 | #endif /* CONFIG_CIFS_POSIX */ | |
c32a0b68 | 648 | .llseek = cifs_llseek, |
1da177e4 LT |
649 | #ifdef CONFIG_CIFS_EXPERIMENTAL |
650 | .dir_notify = cifs_dir_notify, | |
651 | #endif /* CONFIG_CIFS_EXPERIMENTAL */ | |
652 | }; | |
4b6f5d20 | 653 | const struct file_operations cifs_file_nobrl_ops = { |
87c89dd7 SF |
654 | .read = do_sync_read, |
655 | .write = do_sync_write, | |
87c89dd7 SF |
656 | .aio_read = generic_file_aio_read, |
657 | .aio_write = cifs_file_aio_write, | |
658 | .open = cifs_open, | |
659 | .release = cifs_close, | |
660 | .fsync = cifs_fsync, | |
661 | .flush = cifs_flush, | |
662 | .mmap = cifs_file_mmap, | |
5ffc4ef4 | 663 | .splice_read = generic_file_splice_read, |
c32a0b68 | 664 | .llseek = cifs_llseek, |
8b94bcb9 | 665 | #ifdef CONFIG_CIFS_POSIX |
87c89dd7 | 666 | .ioctl = cifs_ioctl, |
8b94bcb9 SF |
667 | #endif /* CONFIG_CIFS_POSIX */ |
668 | ||
669 | #ifdef CONFIG_CIFS_EXPERIMENTAL | |
87c89dd7 | 670 | .dir_notify = cifs_dir_notify, |
8b94bcb9 SF |
671 | #endif /* CONFIG_CIFS_EXPERIMENTAL */ |
672 | }; | |
673 | ||
4b6f5d20 | 674 | const struct file_operations cifs_file_direct_nobrl_ops = { |
50c2f753 | 675 | /* no mmap, no aio, no readv - |
87c89dd7 SF |
676 | BB reevaluate whether they can be done with directio, no cache */ |
677 | .read = cifs_user_read, | |
678 | .write = cifs_user_write, | |
679 | .open = cifs_open, | |
680 | .release = cifs_close, | |
681 | .fsync = cifs_fsync, | |
682 | .flush = cifs_flush, | |
5ffc4ef4 | 683 | .splice_read = generic_file_splice_read, |
8b94bcb9 | 684 | #ifdef CONFIG_CIFS_POSIX |
87c89dd7 | 685 | .ioctl = cifs_ioctl, |
8b94bcb9 | 686 | #endif /* CONFIG_CIFS_POSIX */ |
c32a0b68 | 687 | .llseek = cifs_llseek, |
8b94bcb9 | 688 | #ifdef CONFIG_CIFS_EXPERIMENTAL |
87c89dd7 | 689 | .dir_notify = cifs_dir_notify, |
8b94bcb9 SF |
690 | #endif /* CONFIG_CIFS_EXPERIMENTAL */ |
691 | }; | |
1da177e4 | 692 | |
4b6f5d20 | 693 | const struct file_operations cifs_dir_ops = { |
1da177e4 LT |
694 | .readdir = cifs_readdir, |
695 | .release = cifs_closedir, | |
696 | .read = generic_read_dir, | |
697 | #ifdef CONFIG_CIFS_EXPERIMENTAL | |
698 | .dir_notify = cifs_dir_notify, | |
699 | #endif /* CONFIG_CIFS_EXPERIMENTAL */ | |
50c2f753 | 700 | .ioctl = cifs_ioctl, |
1da177e4 LT |
701 | }; |
702 | ||
703 | static void | |
4ba9b9d0 | 704 | cifs_init_once(struct kmem_cache *cachep, void *inode) |
1da177e4 LT |
705 | { |
706 | struct cifsInodeInfo *cifsi = inode; | |
707 | ||
a35afb83 CL |
708 | inode_init_once(&cifsi->vfs_inode); |
709 | INIT_LIST_HEAD(&cifsi->lockList); | |
1da177e4 LT |
710 | } |
711 | ||
712 | static int | |
713 | cifs_init_inodecache(void) | |
714 | { | |
715 | cifs_inode_cachep = kmem_cache_create("cifs_inode_cache", | |
26f57364 | 716 | sizeof(struct cifsInodeInfo), |
fffb60f9 PJ |
717 | 0, (SLAB_RECLAIM_ACCOUNT| |
718 | SLAB_MEM_SPREAD), | |
20c2df83 | 719 | cifs_init_once); |
1da177e4 LT |
720 | if (cifs_inode_cachep == NULL) |
721 | return -ENOMEM; | |
722 | ||
723 | return 0; | |
724 | } | |
725 | ||
726 | static void | |
727 | cifs_destroy_inodecache(void) | |
728 | { | |
1a1d92c1 | 729 | kmem_cache_destroy(cifs_inode_cachep); |
1da177e4 LT |
730 | } |
731 | ||
732 | static int | |
733 | cifs_init_request_bufs(void) | |
734 | { | |
4523cc30 | 735 | if (CIFSMaxBufSize < 8192) { |
1da177e4 LT |
736 | /* Buffer size can not be smaller than 2 * PATH_MAX since maximum |
737 | Unicode path name has to fit in any SMB/CIFS path based frames */ | |
738 | CIFSMaxBufSize = 8192; | |
739 | } else if (CIFSMaxBufSize > 1024*127) { | |
740 | CIFSMaxBufSize = 1024 * 127; | |
741 | } else { | |
742 | CIFSMaxBufSize &= 0x1FE00; /* Round size to even 512 byte mult*/ | |
743 | } | |
744 | /* cERROR(1,("CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize)); */ | |
745 | cifs_req_cachep = kmem_cache_create("cifs_request", | |
746 | CIFSMaxBufSize + | |
747 | MAX_CIFS_HDR_SIZE, 0, | |
20c2df83 | 748 | SLAB_HWCACHE_ALIGN, NULL); |
1da177e4 LT |
749 | if (cifs_req_cachep == NULL) |
750 | return -ENOMEM; | |
751 | ||
4523cc30 | 752 | if (cifs_min_rcv < 1) |
1da177e4 LT |
753 | cifs_min_rcv = 1; |
754 | else if (cifs_min_rcv > 64) { | |
755 | cifs_min_rcv = 64; | |
50c2f753 | 756 | cERROR(1, ("cifs_min_rcv set to maximum (64)")); |
1da177e4 LT |
757 | } |
758 | ||
93d2341c MD |
759 | cifs_req_poolp = mempool_create_slab_pool(cifs_min_rcv, |
760 | cifs_req_cachep); | |
1da177e4 | 761 | |
4523cc30 | 762 | if (cifs_req_poolp == NULL) { |
1da177e4 LT |
763 | kmem_cache_destroy(cifs_req_cachep); |
764 | return -ENOMEM; | |
765 | } | |
ec637e3f | 766 | /* MAX_CIFS_SMALL_BUFFER_SIZE bytes is enough for most SMB responses and |
1da177e4 LT |
767 | almost all handle based requests (but not write response, nor is it |
768 | sufficient for path based requests). A smaller size would have | |
50c2f753 | 769 | been more efficient (compacting multiple slab items on one 4k page) |
1da177e4 LT |
770 | for the case in which debug was on, but this larger size allows |
771 | more SMBs to use small buffer alloc and is still much more | |
6dc0f87e | 772 | efficient to alloc 1 per page off the slab compared to 17K (5page) |
1da177e4 LT |
773 | alloc of large cifs buffers even when page debugging is on */ |
774 | cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq", | |
6dc0f87e | 775 | MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN, |
20c2df83 | 776 | NULL); |
1da177e4 LT |
777 | if (cifs_sm_req_cachep == NULL) { |
778 | mempool_destroy(cifs_req_poolp); | |
779 | kmem_cache_destroy(cifs_req_cachep); | |
6dc0f87e | 780 | return -ENOMEM; |
1da177e4 LT |
781 | } |
782 | ||
4523cc30 | 783 | if (cifs_min_small < 2) |
1da177e4 LT |
784 | cifs_min_small = 2; |
785 | else if (cifs_min_small > 256) { | |
786 | cifs_min_small = 256; | |
6dc0f87e | 787 | cFYI(1, ("cifs_min_small set to maximum (256)")); |
1da177e4 LT |
788 | } |
789 | ||
93d2341c MD |
790 | cifs_sm_req_poolp = mempool_create_slab_pool(cifs_min_small, |
791 | cifs_sm_req_cachep); | |
1da177e4 | 792 | |
4523cc30 | 793 | if (cifs_sm_req_poolp == NULL) { |
1da177e4 LT |
794 | mempool_destroy(cifs_req_poolp); |
795 | kmem_cache_destroy(cifs_req_cachep); | |
796 | kmem_cache_destroy(cifs_sm_req_cachep); | |
797 | return -ENOMEM; | |
798 | } | |
799 | ||
800 | return 0; | |
801 | } | |
802 | ||
803 | static void | |
804 | cifs_destroy_request_bufs(void) | |
805 | { | |
806 | mempool_destroy(cifs_req_poolp); | |
1a1d92c1 | 807 | kmem_cache_destroy(cifs_req_cachep); |
1da177e4 | 808 | mempool_destroy(cifs_sm_req_poolp); |
1a1d92c1 | 809 | kmem_cache_destroy(cifs_sm_req_cachep); |
1da177e4 LT |
810 | } |
811 | ||
812 | static int | |
813 | cifs_init_mids(void) | |
814 | { | |
815 | cifs_mid_cachep = kmem_cache_create("cifs_mpx_ids", | |
26f57364 SF |
816 | sizeof(struct mid_q_entry), 0, |
817 | SLAB_HWCACHE_ALIGN, NULL); | |
1da177e4 LT |
818 | if (cifs_mid_cachep == NULL) |
819 | return -ENOMEM; | |
820 | ||
93d2341c MD |
821 | /* 3 is a reasonable minimum number of simultaneous operations */ |
822 | cifs_mid_poolp = mempool_create_slab_pool(3, cifs_mid_cachep); | |
4523cc30 | 823 | if (cifs_mid_poolp == NULL) { |
1da177e4 LT |
824 | kmem_cache_destroy(cifs_mid_cachep); |
825 | return -ENOMEM; | |
826 | } | |
827 | ||
828 | cifs_oplock_cachep = kmem_cache_create("cifs_oplock_structs", | |
26f57364 SF |
829 | sizeof(struct oplock_q_entry), 0, |
830 | SLAB_HWCACHE_ALIGN, NULL); | |
1da177e4 | 831 | if (cifs_oplock_cachep == NULL) { |
1da177e4 | 832 | mempool_destroy(cifs_mid_poolp); |
e6985c7f | 833 | kmem_cache_destroy(cifs_mid_cachep); |
1da177e4 LT |
834 | return -ENOMEM; |
835 | } | |
836 | ||
837 | return 0; | |
838 | } | |
839 | ||
840 | static void | |
841 | cifs_destroy_mids(void) | |
842 | { | |
843 | mempool_destroy(cifs_mid_poolp); | |
1a1d92c1 AD |
844 | kmem_cache_destroy(cifs_mid_cachep); |
845 | kmem_cache_destroy(cifs_oplock_cachep); | |
1da177e4 LT |
846 | } |
847 | ||
50c2f753 | 848 | static int cifs_oplock_thread(void *dummyarg) |
1da177e4 | 849 | { |
6dc0f87e | 850 | struct oplock_q_entry *oplock_item; |
1da177e4 | 851 | struct cifsTconInfo *pTcon; |
6dc0f87e | 852 | struct inode *inode; |
1da177e4 LT |
853 | __u16 netfid; |
854 | int rc; | |
855 | ||
83144186 | 856 | set_freezable(); |
1da177e4 | 857 | do { |
6dc0f87e | 858 | if (try_to_freeze()) |
ede1327e | 859 | continue; |
50c2f753 | 860 | |
1da177e4 | 861 | spin_lock(&GlobalMid_Lock); |
4523cc30 | 862 | if (list_empty(&GlobalOplock_Q)) { |
1da177e4 LT |
863 | spin_unlock(&GlobalMid_Lock); |
864 | set_current_state(TASK_INTERRUPTIBLE); | |
865 | schedule_timeout(39*HZ); | |
866 | } else { | |
6dc0f87e | 867 | oplock_item = list_entry(GlobalOplock_Q.next, |
1da177e4 | 868 | struct oplock_q_entry, qhead); |
4523cc30 | 869 | if (oplock_item) { |
50c2f753 | 870 | cFYI(1, ("found oplock item to write out")); |
1da177e4 LT |
871 | pTcon = oplock_item->tcon; |
872 | inode = oplock_item->pinode; | |
873 | netfid = oplock_item->netfid; | |
874 | spin_unlock(&GlobalMid_Lock); | |
875 | DeleteOplockQEntry(oplock_item); | |
876 | /* can not grab inode sem here since it would | |
6dc0f87e | 877 | deadlock when oplock received on delete |
1b1dcc1b | 878 | since vfs_unlink holds the i_mutex across |
1da177e4 | 879 | the call */ |
1b1dcc1b | 880 | /* mutex_lock(&inode->i_mutex);*/ |
1da177e4 | 881 | if (S_ISREG(inode->i_mode)) { |
26f57364 SF |
882 | rc = |
883 | filemap_fdatawrite(inode->i_mapping); | |
50c2f753 SF |
884 | if (CIFS_I(inode)->clientCanCacheRead |
885 | == 0) { | |
1da177e4 LT |
886 | filemap_fdatawait(inode->i_mapping); |
887 | invalidate_remote_inode(inode); | |
888 | } | |
889 | } else | |
890 | rc = 0; | |
1b1dcc1b | 891 | /* mutex_unlock(&inode->i_mutex);*/ |
1da177e4 LT |
892 | if (rc) |
893 | CIFS_I(inode)->write_behind_rc = rc; | |
6dc0f87e SF |
894 | cFYI(1, ("Oplock flush inode %p rc %d", |
895 | inode, rc)); | |
896 | ||
897 | /* releasing stale oplock after recent reconnect | |
898 | of smb session using a now incorrect file | |
899 | handle is not a data integrity issue but do | |
900 | not bother sending an oplock release if session | |
901 | to server still is disconnected since oplock | |
1da177e4 | 902 | already released by the server in that case */ |
4523cc30 | 903 | if (pTcon->tidStatus != CifsNeedReconnect) { |
1da177e4 | 904 | rc = CIFSSMBLock(0, pTcon, netfid, |
6dc0f87e | 905 | 0 /* len */ , 0 /* offset */, 0, |
1da177e4 LT |
906 | 0, LOCKING_ANDX_OPLOCK_RELEASE, |
907 | 0 /* wait flag */); | |
26f57364 | 908 | cFYI(1, ("Oplock release rc = %d", rc)); |
1da177e4 LT |
909 | } |
910 | } else | |
911 | spin_unlock(&GlobalMid_Lock); | |
68058e75 SF |
912 | set_current_state(TASK_INTERRUPTIBLE); |
913 | schedule_timeout(1); /* yield in case q were corrupt */ | |
1da177e4 | 914 | } |
45af7a0f SF |
915 | } while (!kthread_should_stop()); |
916 | ||
917 | return 0; | |
1da177e4 LT |
918 | } |
919 | ||
50c2f753 | 920 | static int cifs_dnotify_thread(void *dummyarg) |
8d0d5094 | 921 | { |
6ab16d24 SF |
922 | struct list_head *tmp; |
923 | struct cifsSesInfo *ses; | |
924 | ||
8d0d5094 | 925 | do { |
0fd1ffe0 | 926 | if (try_to_freeze()) |
16abbecd | 927 | continue; |
8d0d5094 | 928 | set_current_state(TASK_INTERRUPTIBLE); |
6ab16d24 SF |
929 | schedule_timeout(15*HZ); |
930 | read_lock(&GlobalSMBSeslock); | |
931 | /* check if any stuck requests that need | |
932 | to be woken up and wakeq so the | |
933 | thread can wake up and error out */ | |
934 | list_for_each(tmp, &GlobalSMBSessionList) { | |
6dc0f87e | 935 | ses = list_entry(tmp, struct cifsSesInfo, |
6ab16d24 | 936 | cifsSessionList); |
6dc0f87e | 937 | if (ses && ses->server && |
2a138ebb | 938 | atomic_read(&ses->server->inFlight)) |
6ab16d24 SF |
939 | wake_up_all(&ses->server->response_q); |
940 | } | |
941 | read_unlock(&GlobalSMBSeslock); | |
45af7a0f SF |
942 | } while (!kthread_should_stop()); |
943 | ||
944 | return 0; | |
1da177e4 LT |
945 | } |
946 | ||
947 | static int __init | |
948 | init_cifs(void) | |
949 | { | |
950 | int rc = 0; | |
951 | #ifdef CONFIG_PROC_FS | |
952 | cifs_proc_init(); | |
953 | #endif | |
2cd646a2 | 954 | /* INIT_LIST_HEAD(&GlobalServerList);*/ /* BB not implemented yet */ |
1da177e4 LT |
955 | INIT_LIST_HEAD(&GlobalSMBSessionList); |
956 | INIT_LIST_HEAD(&GlobalTreeConnectionList); | |
957 | INIT_LIST_HEAD(&GlobalOplock_Q); | |
4ca9c190 SF |
958 | #ifdef CONFIG_CIFS_EXPERIMENTAL |
959 | INIT_LIST_HEAD(&GlobalDnotifyReqList); | |
960 | INIT_LIST_HEAD(&GlobalDnotifyRsp_Q); | |
6dc0f87e | 961 | #endif |
1da177e4 LT |
962 | /* |
963 | * Initialize Global counters | |
964 | */ | |
965 | atomic_set(&sesInfoAllocCount, 0); | |
966 | atomic_set(&tconInfoAllocCount, 0); | |
6dc0f87e | 967 | atomic_set(&tcpSesAllocCount, 0); |
1da177e4 LT |
968 | atomic_set(&tcpSesReconnectCount, 0); |
969 | atomic_set(&tconInfoReconnectCount, 0); | |
970 | ||
971 | atomic_set(&bufAllocCount, 0); | |
4498eed5 SF |
972 | atomic_set(&smBufAllocCount, 0); |
973 | #ifdef CONFIG_CIFS_STATS2 | |
974 | atomic_set(&totBufAllocCount, 0); | |
975 | atomic_set(&totSmBufAllocCount, 0); | |
976 | #endif /* CONFIG_CIFS_STATS2 */ | |
977 | ||
1da177e4 LT |
978 | atomic_set(&midCount, 0); |
979 | GlobalCurrentXid = 0; | |
980 | GlobalTotalActiveXid = 0; | |
981 | GlobalMaxActiveXid = 0; | |
2cd646a2 | 982 | memset(Local_System_Name, 0, 15); |
1da177e4 LT |
983 | rwlock_init(&GlobalSMBSeslock); |
984 | spin_lock_init(&GlobalMid_Lock); | |
985 | ||
4523cc30 | 986 | if (cifs_max_pending < 2) { |
1da177e4 | 987 | cifs_max_pending = 2; |
6dc0f87e | 988 | cFYI(1, ("cifs_max_pending set to min of 2")); |
4523cc30 | 989 | } else if (cifs_max_pending > 256) { |
1da177e4 | 990 | cifs_max_pending = 256; |
6dc0f87e | 991 | cFYI(1, ("cifs_max_pending set to max of 256")); |
1da177e4 LT |
992 | } |
993 | ||
994 | rc = cifs_init_inodecache(); | |
45af7a0f SF |
995 | if (rc) |
996 | goto out_clean_proc; | |
997 | ||
998 | rc = cifs_init_mids(); | |
999 | if (rc) | |
1000 | goto out_destroy_inodecache; | |
1001 | ||
1002 | rc = cifs_init_request_bufs(); | |
1003 | if (rc) | |
1004 | goto out_destroy_mids; | |
1005 | ||
1006 | rc = register_filesystem(&cifs_fs_type); | |
1007 | if (rc) | |
1008 | goto out_destroy_request_bufs; | |
84a15b93 JL |
1009 | #ifdef CONFIG_CIFS_UPCALL |
1010 | rc = register_key_type(&cifs_spnego_key_type); | |
1011 | if (rc) | |
1012 | goto out_unregister_filesystem; | |
1013 | #endif | |
45af7a0f SF |
1014 | oplockThread = kthread_run(cifs_oplock_thread, NULL, "cifsoplockd"); |
1015 | if (IS_ERR(oplockThread)) { | |
1016 | rc = PTR_ERR(oplockThread); | |
6dc0f87e | 1017 | cERROR(1, ("error %d create oplock thread", rc)); |
84a15b93 | 1018 | goto out_unregister_key_type; |
1da177e4 | 1019 | } |
45af7a0f SF |
1020 | |
1021 | dnotifyThread = kthread_run(cifs_dnotify_thread, NULL, "cifsdnotifyd"); | |
1022 | if (IS_ERR(dnotifyThread)) { | |
1023 | rc = PTR_ERR(dnotifyThread); | |
6dc0f87e | 1024 | cERROR(1, ("error %d create dnotify thread", rc)); |
45af7a0f SF |
1025 | goto out_stop_oplock_thread; |
1026 | } | |
1027 | ||
1028 | return 0; | |
1029 | ||
1030 | out_stop_oplock_thread: | |
1031 | kthread_stop(oplockThread); | |
84a15b93 JL |
1032 | out_unregister_key_type: |
1033 | #ifdef CONFIG_CIFS_UPCALL | |
1034 | unregister_key_type(&cifs_spnego_key_type); | |
45af7a0f | 1035 | out_unregister_filesystem: |
84a15b93 | 1036 | #endif |
45af7a0f SF |
1037 | unregister_filesystem(&cifs_fs_type); |
1038 | out_destroy_request_bufs: | |
1039 | cifs_destroy_request_bufs(); | |
1040 | out_destroy_mids: | |
1041 | cifs_destroy_mids(); | |
1042 | out_destroy_inodecache: | |
1043 | cifs_destroy_inodecache(); | |
1044 | out_clean_proc: | |
1da177e4 LT |
1045 | #ifdef CONFIG_PROC_FS |
1046 | cifs_proc_clean(); | |
1047 | #endif | |
1048 | return rc; | |
1049 | } | |
1050 | ||
1051 | static void __exit | |
1052 | exit_cifs(void) | |
1053 | { | |
63135e08 | 1054 | cFYI(0, ("exit_cifs")); |
1da177e4 LT |
1055 | #ifdef CONFIG_PROC_FS |
1056 | cifs_proc_clean(); | |
84a15b93 JL |
1057 | #endif |
1058 | #ifdef CONFIG_CIFS_UPCALL | |
1059 | unregister_key_type(&cifs_spnego_key_type); | |
1da177e4 LT |
1060 | #endif |
1061 | unregister_filesystem(&cifs_fs_type); | |
1062 | cifs_destroy_inodecache(); | |
1063 | cifs_destroy_mids(); | |
1064 | cifs_destroy_request_bufs(); | |
45af7a0f SF |
1065 | kthread_stop(oplockThread); |
1066 | kthread_stop(dnotifyThread); | |
1da177e4 LT |
1067 | } |
1068 | ||
1069 | MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>"); | |
6dc0f87e | 1070 | MODULE_LICENSE("GPL"); /* combination of LGPL + GPL source behaves as GPL */ |
1da177e4 | 1071 | MODULE_DESCRIPTION |
63135e08 SF |
1072 | ("VFS to access servers complying with the SNIA CIFS Specification " |
1073 | "e.g. Samba and Windows"); | |
1da177e4 LT |
1074 | MODULE_VERSION(CIFS_VERSION); |
1075 | module_init(init_cifs) | |
1076 | module_exit(exit_cifs) |