vfs: no fallback for ->copy_file_range
[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>
fec11dd9 38#include <linux/namei.h>
b8c32dbb 39#include <linux/random.h>
c6e970a0 40#include <linux/uuid.h>
a9ae008f 41#include <linux/xattr.h>
3eb9a889 42#include <net/ipv6.h>
1da177e4
LT
43#include "cifsfs.h"
44#include "cifspdu.h"
45#define DECLARE_GLOBALS_HERE
46#include "cifsglob.h"
47#include "cifsproto.h"
48#include "cifs_debug.h"
49#include "cifs_fs_sb.h"
50#include <linux/mm.h>
84a15b93 51#include <linux/key-type.h>
e545937a 52#include "cifs_spnego.h"
f579cf3c 53#include "fscache.h"
3792c173 54#include "smb2pdu.h"
1c780228
PA
55#ifdef CONFIG_CIFS_DFS_UPCALL
56#include "dfs_cache.h"
57#endif
1da177e4 58
1da177e4 59int cifsFYI = 0;
1404297e 60bool traceSMB;
e7504734 61bool enable_oplocks = true;
1404297e
KC
62bool linuxExtEnabled = true;
63bool lookupCacheEnabled = true;
f92a720e 64bool disable_legacy_dialects; /* false by default */
04912d6a 65unsigned int global_secflags = CIFSSEC_DEF;
3979877e 66/* unsigned int ntlmv2_support = 0; */
1da177e4 67unsigned int sign_CIFS_PDUs = 1;
ee9b6d61 68static const struct super_operations cifs_super_ops;
1da177e4 69unsigned int CIFSMaxBufSize = CIFS_MAX_MSGSIZE;
cb978ac8 70module_param(CIFSMaxBufSize, uint, 0444);
11911b95
SF
71MODULE_PARM_DESC(CIFSMaxBufSize, "Network buffer size (not including header) "
72 "for CIFS requests. "
63135e08 73 "Default: 16384 Range: 8192 to 130048");
1da177e4 74unsigned int cifs_min_rcv = CIFS_MIN_RCV_POOL;
cb978ac8 75module_param(cifs_min_rcv, uint, 0444);
63135e08
SF
76MODULE_PARM_DESC(cifs_min_rcv, "Network buffers in pool. Default: 4 Range: "
77 "1 to 64");
1da177e4 78unsigned int cifs_min_small = 30;
cb978ac8 79module_param(cifs_min_small, uint, 0444);
63135e08
SF
80MODULE_PARM_DESC(cifs_min_small, "Small network buffers in pool. Default: 30 "
81 "Range: 2 to 256");
1da177e4 82unsigned int cifs_max_pending = CIFS_MAX_REQ;
60654ce0 83module_param(cifs_max_pending, uint, 0444);
11911b95
SF
84MODULE_PARM_DESC(cifs_max_pending, "Simultaneous requests to server for "
85 "CIFS/SMB1 dialect (N/A for SMB3) "
10b9b98e 86 "Default: 32767 Range: 2 to 32767.");
00778e22
SF
87#ifdef CONFIG_CIFS_STATS2
88unsigned int slow_rsp_threshold = 1;
89module_param(slow_rsp_threshold, uint, 0644);
90MODULE_PARM_DESC(slow_rsp_threshold, "Amount of time (in seconds) to wait "
91 "before logging that a response is delayed. "
92 "Default: 1 (if set to 0 disables msg).");
93#endif /* STATS2 */
94
e7504734 95module_param(enable_oplocks, bool, 0644);
60654ce0 96MODULE_PARM_DESC(enable_oplocks, "Enable or disable oplocks. Default: y/Y/1");
e7504734 97
f92a720e
SF
98module_param(disable_legacy_dialects, bool, 0644);
99MODULE_PARM_DESC(disable_legacy_dialects, "To improve security it may be "
100 "helpful to restrict the ability to "
101 "override the default dialects (SMB2.1, "
102 "SMB3 and SMB3.02) on mount with old "
103 "dialects (CIFS/SMB1 and SMB2) since "
104 "vers=1.0 (CIFS/SMB1) and vers=2.0 are weaker"
105 " and less secure. Default: n/N/0");
106
1da177e4
LT
107extern mempool_t *cifs_sm_req_poolp;
108extern mempool_t *cifs_req_poolp;
109extern mempool_t *cifs_mid_poolp;
110
da472fc8 111struct workqueue_struct *cifsiod_wq;
3998e6b8 112struct workqueue_struct *cifsoplockd_wq;
3d22462a 113__u32 cifs_lock_secret;
da472fc8 114
24261fc2
MG
115/*
116 * Bumps refcount for cifs super block.
117 * Note that it should be only called if a referece to VFS super block is
118 * already held, e.g. in open-type syscalls context. Otherwise it can race with
119 * atomic_dec_and_test in deactivate_locked_super.
120 */
121void
122cifs_sb_active(struct super_block *sb)
123{
124 struct cifs_sb_info *server = CIFS_SB(sb);
125
126 if (atomic_inc_return(&server->active) == 1)
127 atomic_inc(&sb->s_active);
128}
129
130void
131cifs_sb_deactive(struct super_block *sb)
132{
133 struct cifs_sb_info *server = CIFS_SB(sb);
134
135 if (atomic_dec_and_test(&server->active))
136 deactivate_super(sb);
137}
138
1da177e4 139static int
97d1152a 140cifs_read_super(struct super_block *sb)
1da177e4
LT
141{
142 struct inode *inode;
b2e5cd33 143 struct cifs_sb_info *cifs_sb;
2f6c9479 144 struct cifs_tcon *tcon;
1da177e4 145 int rc = 0;
50c2f753 146
b2e5cd33 147 cifs_sb = CIFS_SB(sb);
2f6c9479 148 tcon = cifs_sb_master_tcon(cifs_sb);
1da177e4 149
2c6292ae 150 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIXACL)
1751e8a6 151 sb->s_flags |= SB_POSIXACL;
2c6292ae 152
8a69e96e
SF
153 if (tcon->snapshot_time)
154 sb->s_flags |= SB_RDONLY;
155
2f6c9479 156 if (tcon->ses->capabilities & tcon->ses->server->vals->cap_large_files)
2c6292ae
AV
157 sb->s_maxbytes = MAX_LFS_FILESIZE;
158 else
159 sb->s_maxbytes = MAX_NON_LFS;
160
161 /* BB FIXME fix time_gran to be larger for LANMAN sessions */
162 sb->s_time_gran = 100;
163
1da177e4
LT
164 sb->s_magic = CIFS_MAGIC_NUMBER;
165 sb->s_op = &cifs_super_ops;
a9ae008f 166 sb->s_xattr = cifs_xattr_handlers;
851ea086
JK
167 rc = super_setup_bdi(sb);
168 if (rc)
169 goto out_no_root;
170 /* tune readahead according to rsize */
171 sb->s_bdi->ra_pages = cifs_sb->rsize / PAGE_SIZE;
172
1da177e4
LT
173 sb->s_blocksize = CIFS_MAX_MSGSIZE;
174 sb->s_blocksize_bits = 14; /* default 2**14 = CIFS_MAX_MSGSIZE */
9b6763e0 175 inode = cifs_root_iget(sb);
1da177e4 176
ce634ab2
DH
177 if (IS_ERR(inode)) {
178 rc = PTR_ERR(inode);
1da177e4
LT
179 goto out_no_root;
180 }
181
2f6c9479 182 if (tcon->nocase)
66ffd113
JL
183 sb->s_d_op = &cifs_ci_dentry_ops;
184 else
185 sb->s_d_op = &cifs_dentry_ops;
186
48fde701 187 sb->s_root = d_make_root(inode);
1da177e4
LT
188 if (!sb->s_root) {
189 rc = -ENOMEM;
190 goto out_no_root;
191 }
50c2f753 192
f3a6a60e 193#ifdef CONFIG_CIFS_NFSD_EXPORT
7521a3c5 194 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) {
f96637be 195 cifs_dbg(FYI, "export ops supported\n");
7521a3c5
SF
196 sb->s_export_op = &cifs_export_ops;
197 }
f3a6a60e 198#endif /* CONFIG_CIFS_NFSD_EXPORT */
1da177e4
LT
199
200 return 0;
201
202out_no_root:
f96637be 203 cifs_dbg(VFS, "%s: get root inode failed\n", __func__);
1da177e4
LT
204 return rc;
205}
206
6d686175
AV
207static void cifs_kill_sb(struct super_block *sb)
208{
209 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
210 kill_anon_super(sb);
98ab494d 211 cifs_umount(cifs_sb);
1da177e4
LT
212}
213
214static int
726c3342 215cifs_statfs(struct dentry *dentry, struct kstatfs *buf)
1da177e4 216{
726c3342 217 struct super_block *sb = dentry->d_sb;
39da9847 218 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
96daf2b0 219 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
76ec5e33 220 struct TCP_Server_Info *server = tcon->ses->server;
6d5786a3 221 unsigned int xid;
76ec5e33 222 int rc = 0;
1da177e4 223
6d5786a3 224 xid = get_xid();
1da177e4 225
21ba3845
SF
226 if (le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength) > 0)
227 buf->f_namelen =
228 le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength);
229 else
230 buf->f_namelen = PATH_MAX;
231
232 buf->f_fsid.val[0] = tcon->vol_serial_number;
233 /* are using part of create time for more randomness, see man statfs */
234 buf->f_fsid.val[1] = (int)le64_to_cpu(tcon->vol_create_time);
235
1da177e4
LT
236 buf->f_files = 0; /* undefined */
237 buf->f_ffree = 0; /* unlimited */
238
76ec5e33
PS
239 if (server->ops->queryfs)
240 rc = server->ops->queryfs(xid, tcon, buf);
39da9847 241
6d5786a3 242 free_xid(xid);
39da9847 243 return 0;
1da177e4
LT
244}
245
31742c5a
SF
246static long cifs_fallocate(struct file *file, int mode, loff_t off, loff_t len)
247{
7119e220 248 struct cifs_sb_info *cifs_sb = CIFS_FILE_SB(file);
31742c5a
SF
249 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
250 struct TCP_Server_Info *server = tcon->ses->server;
251
252 if (server->ops->fallocate)
253 return server->ops->fallocate(file, tcon, mode, off, len);
254
255 return -EOPNOTSUPP;
256}
257
10556cb2 258static int cifs_permission(struct inode *inode, int mask)
1da177e4
LT
259{
260 struct cifs_sb_info *cifs_sb;
261
262 cifs_sb = CIFS_SB(inode->i_sb);
263
f696a365
MS
264 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) {
265 if ((mask & MAY_EXEC) && !execute_ok(inode))
266 return -EACCES;
267 else
268 return 0;
269 } else /* file mode might have been restricted at mount time
50c2f753 270 on the client (above and beyond ACL on servers) for
1da177e4 271 servers which do not support setting and viewing mode bits,
50c2f753 272 so allowing client to check permissions is useful */
2830ba7f 273 return generic_permission(inode, mask);
1da177e4
LT
274}
275
e18b890b
CL
276static struct kmem_cache *cifs_inode_cachep;
277static struct kmem_cache *cifs_req_cachep;
278static struct kmem_cache *cifs_mid_cachep;
e18b890b 279static struct kmem_cache *cifs_sm_req_cachep;
1da177e4
LT
280mempool_t *cifs_sm_req_poolp;
281mempool_t *cifs_req_poolp;
282mempool_t *cifs_mid_poolp;
283
284static struct inode *
285cifs_alloc_inode(struct super_block *sb)
286{
287 struct cifsInodeInfo *cifs_inode;
e94b1766 288 cifs_inode = kmem_cache_alloc(cifs_inode_cachep, GFP_KERNEL);
1da177e4
LT
289 if (!cifs_inode)
290 return NULL;
291 cifs_inode->cifsAttrs = 0x20; /* default */
1da177e4 292 cifs_inode->time = 0;
b8c32dbb
PS
293 /*
294 * Until the file is open and we have gotten oplock info back from the
295 * server, can not assume caching of file data or metadata.
296 */
c6723628 297 cifs_set_oplock_level(cifs_inode, 0);
aff8d5ca 298 cifs_inode->flags = 0;
c11f1df5
SP
299 spin_lock_init(&cifs_inode->writers_lock);
300 cifs_inode->writers = 0;
1da177e4 301 cifs_inode->vfs_inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */
fbec9ab9 302 cifs_inode->server_eof = 0;
20054bd6
JL
303 cifs_inode->uniqueid = 0;
304 cifs_inode->createtime = 0;
42873b0a 305 cifs_inode->epoch = 0;
fa70b87c 306 generate_random_uuid(cifs_inode->lease_key);
2a38e120 307
b8c32dbb
PS
308 /*
309 * Can not set i_flags here - they get immediately overwritten to zero
310 * by the VFS.
311 */
312 /* cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME; */
1da177e4 313 INIT_LIST_HEAD(&cifs_inode->openFileList);
f45d3416 314 INIT_LIST_HEAD(&cifs_inode->llist);
1da177e4
LT
315 return &cifs_inode->vfs_inode;
316}
317
318static void
c2e6802e 319cifs_free_inode(struct inode *inode)
1da177e4 320{
c2e6802e 321 kmem_cache_free(cifs_inode_cachep, CIFS_I(inode));
1da177e4
LT
322}
323
9451a9a5 324static void
b57922d9 325cifs_evict_inode(struct inode *inode)
9451a9a5 326{
91b0abe3 327 truncate_inode_pages_final(&inode->i_data);
dbd5768f 328 clear_inode(inode);
9451a9a5
SJ
329 cifs_fscache_release_inode_cookie(inode);
330}
331
61f98ffd
JL
332static void
333cifs_show_address(struct seq_file *s, struct TCP_Server_Info *server)
334{
a9f1b85e
PS
335 struct sockaddr_in *sa = (struct sockaddr_in *) &server->dstaddr;
336 struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *) &server->dstaddr;
337
571d5972 338 seq_puts(s, ",addr=");
61f98ffd 339
a9f1b85e 340 switch (server->dstaddr.ss_family) {
61f98ffd 341 case AF_INET:
a9f1b85e 342 seq_printf(s, "%pI4", &sa->sin_addr.s_addr);
61f98ffd
JL
343 break;
344 case AF_INET6:
a9f1b85e
PS
345 seq_printf(s, "%pI6", &sa6->sin6_addr.s6_addr);
346 if (sa6->sin6_scope_id)
347 seq_printf(s, "%%%u", sa6->sin6_scope_id);
61f98ffd
JL
348 break;
349 default:
571d5972 350 seq_puts(s, "(unknown)");
61f98ffd 351 }
8339dd32
LL
352 if (server->rdma)
353 seq_puts(s, ",rdma");
61f98ffd
JL
354}
355
3e715513 356static void
28e11bd8 357cifs_show_security(struct seq_file *s, struct cifs_ses *ses)
3e715513 358{
eda2116f
SF
359 if (ses->sectype == Unspecified) {
360 if (ses->user_name == NULL)
361 seq_puts(s, ",sec=none");
28e11bd8 362 return;
eda2116f 363 }
28e11bd8 364
571d5972 365 seq_puts(s, ",sec=");
3e715513 366
28e11bd8 367 switch (ses->sectype) {
3e715513 368 case LANMAN:
571d5972 369 seq_puts(s, "lanman");
3e715513
JL
370 break;
371 case NTLMv2:
571d5972 372 seq_puts(s, "ntlmv2");
3e715513
JL
373 break;
374 case NTLM:
571d5972 375 seq_puts(s, "ntlm");
3e715513
JL
376 break;
377 case Kerberos:
96281b9e 378 seq_printf(s, "krb5,cruid=%u", from_kuid_munged(&init_user_ns,ses->cred_uid));
3e715513
JL
379 break;
380 case RawNTLMSSP:
571d5972 381 seq_puts(s, "ntlmssp");
3e715513
JL
382 break;
383 default:
384 /* shouldn't ever happen */
571d5972 385 seq_puts(s, "unknown");
3e715513
JL
386 break;
387 }
388
28e11bd8 389 if (ses->sign)
571d5972 390 seq_puts(s, "i");
3e715513
JL
391}
392
d06b5056
JL
393static void
394cifs_show_cache_flavor(struct seq_file *s, struct cifs_sb_info *cifs_sb)
395{
571d5972 396 seq_puts(s, ",cache=");
d06b5056
JL
397
398 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO)
571d5972 399 seq_puts(s, "strict");
d06b5056 400 else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO)
571d5972 401 seq_puts(s, "none");
d06b5056 402 else
571d5972 403 seq_puts(s, "loose");
d06b5056
JL
404}
405
3ae35cde
JL
406static void
407cifs_show_nls(struct seq_file *s, struct nls_table *cur)
408{
409 struct nls_table *def;
410
411 /* Display iocharset= option if it's not default charset */
412 def = load_nls_default();
413 if (def != cur)
414 seq_printf(s, ",iocharset=%s", cur->charset);
415 unload_nls(def);
416}
417
1da177e4
LT
418/*
419 * cifs_show_options() is for displaying mount options in /proc/mounts.
420 * Not all settable options are displayed but most of the important
421 * ones are.
422 */
423static int
34c80b1d 424cifs_show_options(struct seq_file *s, struct dentry *root)
1da177e4 425{
34c80b1d 426 struct cifs_sb_info *cifs_sb = CIFS_SB(root->d_sb);
96daf2b0 427 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
3eb9a889
BG
428 struct sockaddr *srcaddr;
429 srcaddr = (struct sockaddr *)&tcon->ses->server->srcaddr;
8616e0fc 430
a068acf2 431 seq_show_option(s, "vers", tcon->ses->server->vals->version_string);
28e11bd8 432 cifs_show_security(s, tcon->ses);
d06b5056 433 cifs_show_cache_flavor(s, cifs_sb);
3e715513 434
29e07c82 435 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER)
571d5972 436 seq_puts(s, ",multiuser");
8727c8a8 437 else if (tcon->ses->user_name)
a068acf2 438 seq_show_option(s, "username", tcon->ses->user_name);
29e07c82 439
e55954a5 440 if (tcon->ses->domainName && tcon->ses->domainName[0] != 0)
a068acf2 441 seq_show_option(s, "domain", tcon->ses->domainName);
8616e0fc 442
3eb9a889
BG
443 if (srcaddr->sa_family != AF_UNSPEC) {
444 struct sockaddr_in *saddr4;
445 struct sockaddr_in6 *saddr6;
446 saddr4 = (struct sockaddr_in *)srcaddr;
447 saddr6 = (struct sockaddr_in6 *)srcaddr;
448 if (srcaddr->sa_family == AF_INET6)
449 seq_printf(s, ",srcaddr=%pI6c",
450 &saddr6->sin6_addr);
451 else if (srcaddr->sa_family == AF_INET)
452 seq_printf(s, ",srcaddr=%pI4",
453 &saddr4->sin_addr.s_addr);
454 else
455 seq_printf(s, ",srcaddr=BAD-AF:%i",
456 (int)(srcaddr->sa_family));
457 }
458
1f68233c
EB
459 seq_printf(s, ",uid=%u",
460 from_kuid_munged(&init_user_ns, cifs_sb->mnt_uid));
340481a3 461 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID)
571d5972 462 seq_puts(s, ",forceuid");
4486d6ed 463 else
571d5972 464 seq_puts(s, ",noforceuid");
340481a3 465
1f68233c
EB
466 seq_printf(s, ",gid=%u",
467 from_kgid_munged(&init_user_ns, cifs_sb->mnt_gid));
340481a3 468 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID)
571d5972 469 seq_puts(s, ",forcegid");
4486d6ed 470 else
571d5972 471 seq_puts(s, ",noforcegid");
8616e0fc 472
61f98ffd 473 cifs_show_address(s, tcon->ses->server);
1da177e4 474
8616e0fc 475 if (!tcon->unix_ext)
5206efd6 476 seq_printf(s, ",file_mode=0%ho,dir_mode=0%ho",
2b280fab
SF
477 cifs_sb->mnt_file_mode,
478 cifs_sb->mnt_dir_mode);
3ae35cde
JL
479
480 cifs_show_nls(s, cifs_sb->local_nls);
481
8616e0fc 482 if (tcon->seal)
571d5972 483 seq_puts(s, ",seal");
8616e0fc 484 if (tcon->nocase)
571d5972 485 seq_puts(s, ",nocase");
c8b6ac1a
K
486 if (tcon->local_lease)
487 seq_puts(s, ",locallease");
8616e0fc 488 if (tcon->retry)
571d5972 489 seq_puts(s, ",hard");
6e82e929
RS
490 else
491 seq_puts(s, ",soft");
f16dfa7c
SF
492 if (tcon->use_persistent)
493 seq_puts(s, ",persistenthandles");
592fafe6
SF
494 else if (tcon->use_resilient)
495 seq_puts(s, ",resilienthandles");
b326614e
SF
496 if (tcon->posix_extensions)
497 seq_puts(s, ",posix");
498 else if (tcon->unix_ext)
499 seq_puts(s, ",unix");
500 else
501 seq_puts(s, ",nounix");
8393072b
AA
502 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_DFS)
503 seq_puts(s, ",nodfs");
8616e0fc 504 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)
571d5972 505 seq_puts(s, ",posixpaths");
8616e0fc 506 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID)
571d5972 507 seq_puts(s, ",setuids");
95932655
SF
508 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UID_FROM_ACL)
509 seq_puts(s, ",idsfromsid");
8616e0fc 510 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)
571d5972 511 seq_puts(s, ",serverino");
d4ffff1f 512 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD)
571d5972 513 seq_puts(s, ",rwpidforward");
d4ffff1f 514 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL)
571d5972 515 seq_puts(s, ",forcemand");
8616e0fc 516 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
571d5972 517 seq_puts(s, ",nouser_xattr");
8616e0fc 518 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR)
571d5972 519 seq_puts(s, ",mapchars");
bc8ebdc4
NA
520 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SFM_CHR)
521 seq_puts(s, ",mapposix");
8616e0fc 522 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL)
571d5972 523 seq_puts(s, ",sfu");
8616e0fc 524 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
571d5972 525 seq_puts(s, ",nobrl");
3d4ef9a1
SF
526 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_HANDLE_CACHE)
527 seq_puts(s, ",nohandlecache");
8616e0fc 528 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL)
571d5972 529 seq_puts(s, ",cifsacl");
8616e0fc 530 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM)
571d5972 531 seq_puts(s, ",dynperm");
1751e8a6 532 if (root->d_sb->s_flags & SB_POSIXACL)
571d5972 533 seq_puts(s, ",acl");
736a3320 534 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS)
571d5972 535 seq_puts(s, ",mfsymlinks");
476428f8 536 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_FSCACHE)
571d5972 537 seq_puts(s, ",fsc");
71c424ba 538 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC)
571d5972 539 seq_puts(s, ",nostrictsync");
71c424ba 540 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM)
571d5972 541 seq_puts(s, ",noperm");
3c7c87fd 542 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_BACKUPUID)
1f68233c
EB
543 seq_printf(s, ",backupuid=%u",
544 from_kuid_munged(&init_user_ns,
545 cifs_sb->mnt_backupuid));
3c7c87fd 546 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_BACKUPGID)
1f68233c
EB
547 seq_printf(s, ",backupgid=%u",
548 from_kgid_munged(&init_user_ns,
549 cifs_sb->mnt_backupgid));
8616e0fc 550
28f88810
SP
551 seq_printf(s, ",rsize=%u", cifs_sb->rsize);
552 seq_printf(s, ",wsize=%u", cifs_sb->wsize);
e8506d25 553 seq_printf(s, ",bsize=%u", cifs_sb->bsize);
adfeb3e0
SF
554 seq_printf(s, ",echo_interval=%lu",
555 tcon->ses->server->echo_interval / HZ);
8a69e96e
SF
556 if (tcon->snapshot_time)
557 seq_printf(s, ",snapshot=%llu", tcon->snapshot_time);
ca567eb2
SF
558 if (tcon->handle_timeout)
559 seq_printf(s, ",handletimeout=%u", tcon->handle_timeout);
6d20e840 560 /* convert actimeo and display it in seconds */
156d1790 561 seq_printf(s, ",actimeo=%lu", cifs_sb->actimeo / HZ);
8616e0fc 562
1da177e4
LT
563 return 0;
564}
565
42faad99 566static void cifs_umount_begin(struct super_block *sb)
68058e75 567{
42faad99 568 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
96daf2b0 569 struct cifs_tcon *tcon;
68058e75 570
4523cc30 571 if (cifs_sb == NULL)
9e2e85f8
SF
572 return;
573
0d424ad0 574 tcon = cifs_sb_master_tcon(cifs_sb);
f1987b44 575
3f9bcca7 576 spin_lock(&cifs_tcp_ses_lock);
ad8034f1
SF
577 if ((tcon->tc_count > 1) || (tcon->tidStatus == CifsExiting)) {
578 /* we have other mounts to same share or we have
579 already tried to force umount this and woken up
580 all waiting network requests, nothing to do */
3f9bcca7 581 spin_unlock(&cifs_tcp_ses_lock);
ad8034f1
SF
582 return;
583 } else if (tcon->tc_count == 1)
5e1253b5 584 tcon->tidStatus = CifsExiting;
3f9bcca7 585 spin_unlock(&cifs_tcp_ses_lock);
5e1253b5 586
3a5ff61c 587 /* cancel_brl_requests(tcon); */ /* BB mark all brl mids as exiting */
7b7abfe3 588 /* cancel_notify_requests(tcon); */
50c2f753 589 if (tcon->ses && tcon->ses->server) {
f96637be 590 cifs_dbg(FYI, "wake up tasks now - umount begin not complete\n");
9e2e85f8 591 wake_up_all(&tcon->ses->server->request_q);
6ab16d24
SF
592 wake_up_all(&tcon->ses->server->response_q);
593 msleep(1); /* yield */
594 /* we have to kick the requests once more */
595 wake_up_all(&tcon->ses->server->response_q);
596 msleep(1);
5e1253b5 597 }
68058e75
SF
598
599 return;
600}
68058e75 601
bf97d287 602#ifdef CONFIG_CIFS_STATS2
64132379 603static int cifs_show_stats(struct seq_file *s, struct dentry *root)
bf97d287
SF
604{
605 /* BB FIXME */
606 return 0;
607}
608#endif
609
1da177e4
LT
610static int cifs_remount(struct super_block *sb, int *flags, char *data)
611{
02b9984d 612 sync_filesystem(sb);
1751e8a6 613 *flags |= SB_NODIRATIME;
1da177e4
LT
614 return 0;
615}
616
45321ac5 617static int cifs_drop_inode(struct inode *inode)
12420ac3
JL
618{
619 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
620
45321ac5
AV
621 /* no serverino => unconditional eviction */
622 return !(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) ||
623 generic_drop_inode(inode);
12420ac3
JL
624}
625
ee9b6d61 626static const struct super_operations cifs_super_ops = {
1da177e4
LT
627 .statfs = cifs_statfs,
628 .alloc_inode = cifs_alloc_inode,
c2e6802e 629 .free_inode = cifs_free_inode,
12420ac3 630 .drop_inode = cifs_drop_inode,
b57922d9 631 .evict_inode = cifs_evict_inode,
12420ac3
JL
632/* .delete_inode = cifs_delete_inode, */ /* Do not need above
633 function unless later we add lazy close of inodes or unless the
50c2f753
SF
634 kernel forgets to call us with the same number of releases (closes)
635 as opens */
1da177e4 636 .show_options = cifs_show_options,
7b7abfe3 637 .umount_begin = cifs_umount_begin,
1da177e4 638 .remount_fs = cifs_remount,
bf97d287 639#ifdef CONFIG_CIFS_STATS2
f46d3e11 640 .show_stats = cifs_show_stats,
bf97d287 641#endif
1da177e4
LT
642};
643
f87d39d9
SF
644/*
645 * Get root dentry from superblock according to prefix path mount option.
646 * Return dentry with refcount + 1 on success and NULL otherwise.
647 */
648static struct dentry *
649cifs_get_root(struct smb_vol *vol, struct super_block *sb)
650{
fec11dd9 651 struct dentry *dentry;
f87d39d9 652 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
fec11dd9
AV
653 char *full_path = NULL;
654 char *s, *p;
f87d39d9
SF
655 char sep;
656
348c1bfa
SP
657 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_USE_PREFIX_PATH)
658 return dget(sb->s_root);
659
6d3ea7e4 660 full_path = cifs_build_path_to_root(vol, cifs_sb,
374402a2 661 cifs_sb_master_tcon(cifs_sb), 0);
f87d39d9 662 if (full_path == NULL)
9403c9c5 663 return ERR_PTR(-ENOMEM);
f87d39d9 664
f96637be 665 cifs_dbg(FYI, "Get root dentry for %s\n", full_path);
f87d39d9 666
f87d39d9 667 sep = CIFS_DIR_SEP(cifs_sb);
fec11dd9
AV
668 dentry = dget(sb->s_root);
669 p = s = full_path;
670
671 do {
2b0143b5 672 struct inode *dir = d_inode(dentry);
fec11dd9
AV
673 struct dentry *child;
674
5b980b01
PS
675 if (!dir) {
676 dput(dentry);
677 dentry = ERR_PTR(-ENOENT);
678 break;
679 }
ce2ac521
JL
680 if (!S_ISDIR(dir->i_mode)) {
681 dput(dentry);
682 dentry = ERR_PTR(-ENOTDIR);
683 break;
684 }
5b980b01 685
fec11dd9
AV
686 /* skip separators */
687 while (*s == sep)
688 s++;
689 if (!*s)
690 break;
691 p = s++;
692 /* next separator */
693 while (*s && *s != sep)
694 s++;
695
85f40482 696 child = lookup_one_len_unlocked(p, dentry, s - p);
fec11dd9
AV
697 dput(dentry);
698 dentry = child;
699 } while (!IS_ERR(dentry));
f87d39d9 700 kfree(full_path);
fec11dd9 701 return dentry;
f87d39d9
SF
702}
703
ee01a14d
AV
704static int cifs_set_super(struct super_block *sb, void *data)
705{
706 struct cifs_mnt_data *mnt_data = data;
707 sb->s_fs_info = mnt_data->cifs_sb;
708 return set_anon_super(sb, NULL);
709}
710
d753ed97 711static struct dentry *
c7c137b9
SF
712cifs_smb3_do_mount(struct file_system_type *fs_type,
713 int flags, const char *dev_name, void *data, bool is_smb3)
1da177e4
LT
714{
715 int rc;
db719222 716 struct super_block *sb;
724d9f1c
PS
717 struct cifs_sb_info *cifs_sb;
718 struct smb_vol *volume_info;
25c7f41e 719 struct cifs_mnt_data mnt_data;
724d9f1c 720 struct dentry *root;
1da177e4 721
8c1beb98
SF
722 /*
723 * Prints in Kernel / CIFS log the attempted mount operation
724 * If CIFS_DEBUG && cifs_FYI
725 */
f80eaedd
RF
726 if (cifsFYI)
727 cifs_dbg(FYI, "Devname: %s flags: %d\n", dev_name, flags);
728 else
729 cifs_info("Attempting to mount %s\n", dev_name);
1da177e4 730
c7c137b9 731 volume_info = cifs_get_volume_info((char *)data, dev_name, is_smb3);
04db79b0
JL
732 if (IS_ERR(volume_info))
733 return ERR_CAST(volume_info);
724d9f1c
PS
734
735 cifs_sb = kzalloc(sizeof(struct cifs_sb_info), GFP_KERNEL);
736 if (cifs_sb == NULL) {
737 root = ERR_PTR(-ENOMEM);
5c4f1ad7 738 goto out_nls;
724d9f1c
PS
739 }
740
5d3bc605
AV
741 cifs_sb->mountdata = kstrndup(data, PAGE_SIZE, GFP_KERNEL);
742 if (cifs_sb->mountdata == NULL) {
743 root = ERR_PTR(-ENOMEM);
4214ebf4 744 goto out_free;
5d3bc605
AV
745 }
746
4214ebf4
SP
747 rc = cifs_setup_cifs_sb(volume_info, cifs_sb);
748 if (rc) {
749 root = ERR_PTR(rc);
750 goto out_free;
a6b5058f
AA
751 }
752
97d1152a
AV
753 rc = cifs_mount(cifs_sb, volume_info);
754 if (rc) {
1751e8a6 755 if (!(flags & SB_SILENT))
f96637be
JP
756 cifs_dbg(VFS, "cifs_mount failed w/return code = %d\n",
757 rc);
97d1152a 758 root = ERR_PTR(rc);
4214ebf4 759 goto out_free;
97d1152a
AV
760 }
761
25c7f41e
PS
762 mnt_data.vol = volume_info;
763 mnt_data.cifs_sb = cifs_sb;
764 mnt_data.flags = flags;
765
9249e17f 766 /* BB should we make this contingent on mount parm? */
1751e8a6 767 flags |= SB_NODIRATIME | SB_NOATIME;
9249e17f
DH
768
769 sb = sget(fs_type, cifs_match_super, cifs_set_super, flags, &mnt_data);
724d9f1c 770 if (IS_ERR(sb)) {
724d9f1c 771 root = ERR_CAST(sb);
97d1152a 772 cifs_umount(cifs_sb);
d757d71b 773 goto out;
724d9f1c 774 }
1da177e4 775
ee01a14d 776 if (sb->s_root) {
f96637be 777 cifs_dbg(FYI, "Use existing superblock\n");
97d1152a 778 cifs_umount(cifs_sb);
5c4f1ad7 779 } else {
5c4f1ad7
AV
780 rc = cifs_read_super(sb);
781 if (rc) {
782 root = ERR_PTR(rc);
783 goto out_super;
784 }
b2e5cd33 785
1751e8a6 786 sb->s_flags |= SB_ACTIVE;
1da177e4 787 }
724d9f1c 788
348c1bfa 789 root = cifs_get_root(volume_info, sb);
9403c9c5 790 if (IS_ERR(root))
f87d39d9 791 goto out_super;
25c7f41e 792
f96637be 793 cifs_dbg(FYI, "dentry root is: %p\n", root);
641a58d6 794 goto out;
724d9f1c 795
641a58d6 796out_super:
641a58d6 797 deactivate_locked_super(sb);
641a58d6 798out:
f9e59bcb 799 cifs_cleanup_volume_info(volume_info);
724d9f1c 800 return root;
5c4f1ad7 801
4214ebf4
SP
802out_free:
803 kfree(cifs_sb->prepath);
5c4f1ad7 804 kfree(cifs_sb->mountdata);
5c4f1ad7
AV
805 kfree(cifs_sb);
806out_nls:
807 unload_nls(volume_info->local_nls);
808 goto out;
1da177e4
LT
809}
810
c7c137b9
SF
811static struct dentry *
812smb3_do_mount(struct file_system_type *fs_type,
813 int flags, const char *dev_name, void *data)
814{
815 return cifs_smb3_do_mount(fs_type, flags, dev_name, data, true);
816}
817
818static struct dentry *
819cifs_do_mount(struct file_system_type *fs_type,
820 int flags, const char *dev_name, void *data)
821{
822 return cifs_smb3_do_mount(fs_type, flags, dev_name, data, false);
823}
824
08bc0353
JL
825static ssize_t
826cifs_loose_read_iter(struct kiocb *iocb, struct iov_iter *iter)
827{
828 ssize_t rc;
829 struct inode *inode = file_inode(iocb->ki_filp);
830
882137c4
RL
831 if (iocb->ki_filp->f_flags & O_DIRECT)
832 return cifs_user_readv(iocb, iter);
833
08bc0353
JL
834 rc = cifs_revalidate_mapping(inode);
835 if (rc)
836 return rc;
837
838 return generic_file_read_iter(iocb, iter);
839}
840
3dae8750 841static ssize_t cifs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
1da177e4 842{
496ad9aa 843 struct inode *inode = file_inode(iocb->ki_filp);
c11f1df5 844 struct cifsInodeInfo *cinode = CIFS_I(inode);
1da177e4 845 ssize_t written;
72432ffc 846 int rc;
1da177e4 847
882137c4
RL
848 if (iocb->ki_filp->f_flags & O_DIRECT) {
849 written = cifs_user_writev(iocb, from);
850 if (written > 0 && CIFS_CACHE_READ(cinode)) {
851 cifs_zap_mapping(inode);
852 cifs_dbg(FYI,
853 "Set no oplock for inode=%p after a write operation\n",
854 inode);
855 cinode->oplock = 0;
856 }
857 return written;
858 }
859
c11f1df5
SP
860 written = cifs_get_writer(cinode);
861 if (written)
862 return written;
863
3dae8750 864 written = generic_file_write_iter(iocb, from);
72432ffc 865
18cceb6a 866 if (CIFS_CACHE_WRITE(CIFS_I(inode)))
c11f1df5 867 goto out;
72432ffc
PS
868
869 rc = filemap_fdatawrite(inode->i_mapping);
870 if (rc)
3dae8750 871 cifs_dbg(FYI, "cifs_file_write_iter: %d rc on %p inode\n",
f96637be 872 rc, inode);
72432ffc 873
c11f1df5
SP
874out:
875 cifs_put_writer(cinode);
1da177e4
LT
876 return written;
877}
878
965c8e59 879static loff_t cifs_llseek(struct file *file, loff_t offset, int whence)
c32a0b68 880{
dece44e3
RS
881 struct cifsFileInfo *cfile = file->private_data;
882 struct cifs_tcon *tcon;
883
06222e49 884 /*
965c8e59 885 * whence == SEEK_END || SEEK_DATA || SEEK_HOLE => we must revalidate
06222e49
JB
886 * the cached file length
887 */
965c8e59 888 if (whence != SEEK_SET && whence != SEEK_CUR) {
6feb9891 889 int rc;
496ad9aa 890 struct inode *inode = file_inode(file);
6feb9891
PS
891
892 /*
893 * We need to be sure that all dirty pages are written and the
894 * server has the newest file length.
895 */
18cceb6a 896 if (!CIFS_CACHE_READ(CIFS_I(inode)) && inode->i_mapping &&
6feb9891
PS
897 inode->i_mapping->nrpages != 0) {
898 rc = filemap_fdatawait(inode->i_mapping);
156ecb2d
SF
899 if (rc) {
900 mapping_set_error(inode->i_mapping, rc);
901 return rc;
902 }
6feb9891
PS
903 }
904 /*
905 * Some applications poll for the file length in this strange
906 * way so we must seek to end on non-oplocked files by
907 * setting the revalidate time to zero.
908 */
909 CIFS_I(inode)->time = 0;
910
911 rc = cifs_revalidate_file_attr(file);
912 if (rc < 0)
913 return (loff_t)rc;
c32a0b68 914 }
dece44e3
RS
915 if (cfile && cfile->tlink) {
916 tcon = tlink_tcon(cfile->tlink);
917 if (tcon->ses->server->ops->llseek)
918 return tcon->ses->server->ops->llseek(file, tcon,
919 offset, whence);
920 }
965c8e59 921 return generic_file_llseek(file, offset, whence);
c32a0b68
SF
922}
923
e6f5c789
JL
924static int
925cifs_setlease(struct file *file, long arg, struct file_lock **lease, void **priv)
84210e91 926{
18cceb6a
PS
927 /*
928 * Note that this is called by vfs setlease with i_lock held to
929 * protect *lease from going away.
930 */
496ad9aa 931 struct inode *inode = file_inode(file);
ba00ba64 932 struct cifsFileInfo *cfile = file->private_data;
84210e91
SF
933
934 if (!(S_ISREG(inode->i_mode)))
935 return -EINVAL;
936
02440806
JL
937 /* Check if file is oplocked if this is request for new lease */
938 if (arg == F_UNLCK ||
939 ((arg == F_RDLCK) && CIFS_CACHE_READ(CIFS_I(inode))) ||
18cceb6a 940 ((arg == F_WRLCK) && CIFS_CACHE_WRITE(CIFS_I(inode))))
e6f5c789 941 return generic_setlease(file, arg, lease, priv);
13cfb733 942 else if (tlink_tcon(cfile->tlink)->local_lease &&
18cceb6a
PS
943 !CIFS_CACHE_READ(CIFS_I(inode)))
944 /*
945 * If the server claims to support oplock on this file, then we
946 * still need to check oplock even if the local_lease mount
947 * option is set, but there are servers which do not support
948 * oplock for which this mount option may be useful if the user
949 * knows that the file won't be changed on the server by anyone
950 * else.
951 */
e6f5c789 952 return generic_setlease(file, arg, lease, priv);
51ee4b84 953 else
84210e91
SF
954 return -EAGAIN;
955}
84210e91 956
e6ab1582 957struct file_system_type cifs_fs_type = {
1da177e4
LT
958 .owner = THIS_MODULE,
959 .name = "cifs",
d753ed97 960 .mount = cifs_do_mount,
6d686175 961 .kill_sb = cifs_kill_sb,
1da177e4
LT
962 /* .fs_flags */
963};
3e64fe5b 964MODULE_ALIAS_FS("cifs");
49218b4f
SF
965
966static struct file_system_type smb3_fs_type = {
967 .owner = THIS_MODULE,
968 .name = "smb3",
c7c137b9 969 .mount = smb3_do_mount,
49218b4f
SF
970 .kill_sb = cifs_kill_sb,
971 /* .fs_flags */
972};
973MODULE_ALIAS_FS("smb3");
974MODULE_ALIAS("smb3");
975
754661f1 976const struct inode_operations cifs_dir_inode_ops = {
1da177e4 977 .create = cifs_create,
d2c12719 978 .atomic_open = cifs_atomic_open,
1da177e4
LT
979 .lookup = cifs_lookup,
980 .getattr = cifs_getattr,
981 .unlink = cifs_unlink,
982 .link = cifs_hardlink,
983 .mkdir = cifs_mkdir,
984 .rmdir = cifs_rmdir,
2773bf00 985 .rename = cifs_rename2,
1da177e4 986 .permission = cifs_permission,
1da177e4
LT
987 .setattr = cifs_setattr,
988 .symlink = cifs_symlink,
989 .mknod = cifs_mknod,
1da177e4 990 .listxattr = cifs_listxattr,
1da177e4
LT
991};
992
754661f1 993const struct inode_operations cifs_file_inode_ops = {
1da177e4 994 .setattr = cifs_setattr,
48a77aa7 995 .getattr = cifs_getattr,
1da177e4 996 .permission = cifs_permission,
1da177e4 997 .listxattr = cifs_listxattr,
2f3ebaba 998 .fiemap = cifs_fiemap,
1da177e4
LT
999};
1000
754661f1 1001const struct inode_operations cifs_symlink_inode_ops = {
6b255391 1002 .get_link = cifs_get_link,
1da177e4 1003 .permission = cifs_permission,
1da177e4 1004 .listxattr = cifs_listxattr,
1da177e4
LT
1005};
1006
42ec3d4c
DW
1007static loff_t cifs_remap_file_range(struct file *src_file, loff_t off,
1008 struct file *dst_file, loff_t destoff, loff_t len,
2e5dfc99 1009 unsigned int remap_flags)
04b38d60
CH
1010{
1011 struct inode *src_inode = file_inode(src_file);
1012 struct inode *target_inode = file_inode(dst_file);
1013 struct cifsFileInfo *smb_file_src = src_file->private_data;
8c6c9bed
CIK
1014 struct cifsFileInfo *smb_file_target;
1015 struct cifs_tcon *target_tcon;
04b38d60
CH
1016 unsigned int xid;
1017 int rc;
1018
b073a080 1019 if (remap_flags & ~(REMAP_FILE_DEDUP | REMAP_FILE_ADVISORY))
2e5dfc99
DW
1020 return -EINVAL;
1021
04b38d60
CH
1022 cifs_dbg(FYI, "clone range\n");
1023
1024 xid = get_xid();
1025
1026 if (!src_file->private_data || !dst_file->private_data) {
1027 rc = -EBADF;
1028 cifs_dbg(VFS, "missing cifsFileInfo on copy range src file\n");
1029 goto out;
1030 }
1031
8c6c9bed
CIK
1032 smb_file_target = dst_file->private_data;
1033 target_tcon = tlink_tcon(smb_file_target->tlink);
1034
04b38d60
CH
1035 /*
1036 * Note: cifs case is easier than btrfs since server responsible for
1037 * checks for proper open modes and file type and if it wants
1038 * server could even support copy of range where source = target
1039 */
1040 lock_two_nondirectories(target_inode, src_inode);
1041
1042 if (len == 0)
1043 len = src_inode->i_size - off;
1044
1045 cifs_dbg(FYI, "about to flush pages\n");
1046 /* should we flush first and last page first */
1047 truncate_inode_pages_range(&target_inode->i_data, destoff,
09cbfeaf 1048 PAGE_ALIGN(destoff + len)-1);
04b38d60
CH
1049
1050 if (target_tcon->ses->server->ops->duplicate_extents)
1051 rc = target_tcon->ses->server->ops->duplicate_extents(xid,
1052 smb_file_src, smb_file_target, off, len, destoff);
1053 else
1054 rc = -EOPNOTSUPP;
1055
1056 /* force revalidate of size and timestamps of target file now
1057 that target is updated on the server */
1058 CIFS_I(target_inode)->time = 0;
04b38d60
CH
1059 /* although unlocking in the reverse order from locking is not
1060 strictly necessary here it is a little cleaner to be consistent */
1061 unlock_two_nondirectories(src_inode, target_inode);
1062out:
1063 free_xid(xid);
42ec3d4c 1064 return rc < 0 ? rc : len;
04b38d60
CH
1065}
1066
620d8745
SP
1067ssize_t cifs_file_copychunk_range(unsigned int xid,
1068 struct file *src_file, loff_t off,
1069 struct file *dst_file, loff_t destoff,
1070 size_t len, unsigned int flags)
1071{
1072 struct inode *src_inode = file_inode(src_file);
1073 struct inode *target_inode = file_inode(dst_file);
1074 struct cifsFileInfo *smb_file_src;
1075 struct cifsFileInfo *smb_file_target;
1076 struct cifs_tcon *src_tcon;
1077 struct cifs_tcon *target_tcon;
1078 ssize_t rc;
1079
1080 cifs_dbg(FYI, "copychunk range\n");
1081
620d8745
SP
1082 if (!src_file->private_data || !dst_file->private_data) {
1083 rc = -EBADF;
1084 cifs_dbg(VFS, "missing cifsFileInfo on copy range src file\n");
1085 goto out;
1086 }
1087
1088 rc = -EXDEV;
1089 smb_file_target = dst_file->private_data;
1090 smb_file_src = src_file->private_data;
1091 src_tcon = tlink_tcon(smb_file_src->tlink);
1092 target_tcon = tlink_tcon(smb_file_target->tlink);
1093
1094 if (src_tcon->ses != target_tcon->ses) {
1095 cifs_dbg(VFS, "source and target of copy not on same server\n");
1096 goto out;
1097 }
1098
1099 /*
1100 * Note: cifs case is easier than btrfs since server responsible for
1101 * checks for proper open modes and file type and if it wants
1102 * server could even support copy of range where source = target
1103 */
1104 lock_two_nondirectories(target_inode, src_inode);
1105
1106 cifs_dbg(FYI, "about to flush pages\n");
1107 /* should we flush first and last page first */
1108 truncate_inode_pages(&target_inode->i_data, 0);
1109
1110 if (target_tcon->ses->server->ops->copychunk_range)
1111 rc = target_tcon->ses->server->ops->copychunk_range(xid,
1112 smb_file_src, smb_file_target, off, len, destoff);
1113 else
1114 rc = -EOPNOTSUPP;
1115
1116 /* force revalidate of size and timestamps of target file now
1117 * that target is updated on the server
1118 */
1119 CIFS_I(target_inode)->time = 0;
1120 /* although unlocking in the reverse order from locking is not
1121 * strictly necessary here it is a little cleaner to be consistent
1122 */
1123 unlock_two_nondirectories(src_inode, target_inode);
1124
1125out:
1126 return rc;
1127}
1128
6e70c267
SF
1129/*
1130 * Directory operations under CIFS/SMB2/SMB3 are synchronous, so fsync()
1131 * is a dummy operation.
1132 */
1133static int cifs_dir_fsync(struct file *file, loff_t start, loff_t end, int datasync)
1134{
1135 cifs_dbg(FYI, "Sync directory - name: %pD datasync: 0x%x\n",
1136 file, datasync);
1137
1138 return 0;
1139}
1140
620d8745
SP
1141static ssize_t cifs_copy_file_range(struct file *src_file, loff_t off,
1142 struct file *dst_file, loff_t destoff,
1143 size_t len, unsigned int flags)
1144{
1145 unsigned int xid = get_xid();
1146 ssize_t rc;
1147
1148 rc = cifs_file_copychunk_range(xid, src_file, off, dst_file, destoff,
1149 len, flags);
1150 free_xid(xid);
64bf5ff5
DC
1151
1152 if (rc == -EOPNOTSUPP)
1153 rc = generic_copy_file_range(src_file, off, dst_file,
1154 destoff, len, flags);
620d8745
SP
1155 return rc;
1156}
1157
4b6f5d20 1158const struct file_operations cifs_file_ops = {
08bc0353 1159 .read_iter = cifs_loose_read_iter,
3dae8750 1160 .write_iter = cifs_file_write_iter,
1da177e4
LT
1161 .open = cifs_open,
1162 .release = cifs_close,
1163 .lock = cifs_lock,
1164 .fsync = cifs_fsync,
1165 .flush = cifs_flush,
1166 .mmap = cifs_file_mmap,
5ffc4ef4 1167 .splice_read = generic_file_splice_read,
cd1aca29 1168 .splice_write = iter_file_splice_write,
c32a0b68 1169 .llseek = cifs_llseek,
f9ddcca4 1170 .unlocked_ioctl = cifs_ioctl,
620d8745 1171 .copy_file_range = cifs_copy_file_range,
2e5dfc99 1172 .remap_file_range = cifs_remap_file_range,
84210e91 1173 .setlease = cifs_setlease,
31742c5a 1174 .fallocate = cifs_fallocate,
1da177e4
LT
1175};
1176
8be7e6ba 1177const struct file_operations cifs_file_strict_ops = {
e6a7bcb4 1178 .read_iter = cifs_strict_readv,
3dae8750 1179 .write_iter = cifs_strict_writev,
8be7e6ba
PS
1180 .open = cifs_open,
1181 .release = cifs_close,
1182 .lock = cifs_lock,
1183 .fsync = cifs_strict_fsync,
1184 .flush = cifs_flush,
7a6a19b1 1185 .mmap = cifs_file_strict_mmap,
8be7e6ba 1186 .splice_read = generic_file_splice_read,
cd1aca29 1187 .splice_write = iter_file_splice_write,
8be7e6ba 1188 .llseek = cifs_llseek,
8be7e6ba 1189 .unlocked_ioctl = cifs_ioctl,
620d8745 1190 .copy_file_range = cifs_copy_file_range,
2e5dfc99 1191 .remap_file_range = cifs_remap_file_range,
8be7e6ba 1192 .setlease = cifs_setlease,
31742c5a 1193 .fallocate = cifs_fallocate,
8be7e6ba
PS
1194};
1195
4b6f5d20 1196const struct file_operations cifs_file_direct_ops = {
be4eb688
LL
1197 .read_iter = cifs_direct_readv,
1198 .write_iter = cifs_direct_writev,
1da177e4
LT
1199 .open = cifs_open,
1200 .release = cifs_close,
1201 .lock = cifs_lock,
1202 .fsync = cifs_fsync,
1203 .flush = cifs_flush,
a994b8fa 1204 .mmap = cifs_file_mmap,
5ffc4ef4 1205 .splice_read = generic_file_splice_read,
cd1aca29 1206 .splice_write = iter_file_splice_write,
f9ddcca4 1207 .unlocked_ioctl = cifs_ioctl,
620d8745 1208 .copy_file_range = cifs_copy_file_range,
2e5dfc99 1209 .remap_file_range = cifs_remap_file_range,
c32a0b68 1210 .llseek = cifs_llseek,
84210e91 1211 .setlease = cifs_setlease,
31742c5a 1212 .fallocate = cifs_fallocate,
1da177e4 1213};
8be7e6ba 1214
4b6f5d20 1215const struct file_operations cifs_file_nobrl_ops = {
08bc0353 1216 .read_iter = cifs_loose_read_iter,
3dae8750 1217 .write_iter = cifs_file_write_iter,
87c89dd7
SF
1218 .open = cifs_open,
1219 .release = cifs_close,
1220 .fsync = cifs_fsync,
1221 .flush = cifs_flush,
1222 .mmap = cifs_file_mmap,
5ffc4ef4 1223 .splice_read = generic_file_splice_read,
cd1aca29 1224 .splice_write = iter_file_splice_write,
c32a0b68 1225 .llseek = cifs_llseek,
f9ddcca4 1226 .unlocked_ioctl = cifs_ioctl,
620d8745 1227 .copy_file_range = cifs_copy_file_range,
2e5dfc99 1228 .remap_file_range = cifs_remap_file_range,
84210e91 1229 .setlease = cifs_setlease,
31742c5a 1230 .fallocate = cifs_fallocate,
8b94bcb9
SF
1231};
1232
8be7e6ba 1233const struct file_operations cifs_file_strict_nobrl_ops = {
e6a7bcb4 1234 .read_iter = cifs_strict_readv,
3dae8750 1235 .write_iter = cifs_strict_writev,
8be7e6ba
PS
1236 .open = cifs_open,
1237 .release = cifs_close,
1238 .fsync = cifs_strict_fsync,
1239 .flush = cifs_flush,
7a6a19b1 1240 .mmap = cifs_file_strict_mmap,
8be7e6ba 1241 .splice_read = generic_file_splice_read,
cd1aca29 1242 .splice_write = iter_file_splice_write,
8be7e6ba 1243 .llseek = cifs_llseek,
8be7e6ba 1244 .unlocked_ioctl = cifs_ioctl,
620d8745 1245 .copy_file_range = cifs_copy_file_range,
2e5dfc99 1246 .remap_file_range = cifs_remap_file_range,
8be7e6ba 1247 .setlease = cifs_setlease,
31742c5a 1248 .fallocate = cifs_fallocate,
8be7e6ba
PS
1249};
1250
4b6f5d20 1251const struct file_operations cifs_file_direct_nobrl_ops = {
be4eb688
LL
1252 .read_iter = cifs_direct_readv,
1253 .write_iter = cifs_direct_writev,
87c89dd7
SF
1254 .open = cifs_open,
1255 .release = cifs_close,
1256 .fsync = cifs_fsync,
1257 .flush = cifs_flush,
810627a0 1258 .mmap = cifs_file_mmap,
5ffc4ef4 1259 .splice_read = generic_file_splice_read,
cd1aca29 1260 .splice_write = iter_file_splice_write,
f9ddcca4 1261 .unlocked_ioctl = cifs_ioctl,
620d8745 1262 .copy_file_range = cifs_copy_file_range,
2e5dfc99 1263 .remap_file_range = cifs_remap_file_range,
c32a0b68 1264 .llseek = cifs_llseek,
84210e91 1265 .setlease = cifs_setlease,
31742c5a 1266 .fallocate = cifs_fallocate,
8b94bcb9 1267};
1da177e4 1268
4b6f5d20 1269const struct file_operations cifs_dir_ops = {
3125d265 1270 .iterate_shared = cifs_readdir,
1da177e4
LT
1271 .release = cifs_closedir,
1272 .read = generic_read_dir,
f9ddcca4 1273 .unlocked_ioctl = cifs_ioctl,
620d8745 1274 .copy_file_range = cifs_copy_file_range,
2e5dfc99 1275 .remap_file_range = cifs_remap_file_range,
3222a3e5 1276 .llseek = generic_file_llseek,
6e70c267 1277 .fsync = cifs_dir_fsync,
1da177e4
LT
1278};
1279
1280static void
51cc5068 1281cifs_init_once(void *inode)
1da177e4
LT
1282{
1283 struct cifsInodeInfo *cifsi = inode;
1284
a35afb83 1285 inode_init_once(&cifsi->vfs_inode);
1b4b55a1 1286 init_rwsem(&cifsi->lock_sem);
1da177e4
LT
1287}
1288
9ee108b2 1289static int __init
1da177e4
LT
1290cifs_init_inodecache(void)
1291{
1292 cifs_inode_cachep = kmem_cache_create("cifs_inode_cache",
26f57364 1293 sizeof(struct cifsInodeInfo),
fffb60f9 1294 0, (SLAB_RECLAIM_ACCOUNT|
5d097056 1295 SLAB_MEM_SPREAD|SLAB_ACCOUNT),
20c2df83 1296 cifs_init_once);
1da177e4
LT
1297 if (cifs_inode_cachep == NULL)
1298 return -ENOMEM;
1299
1300 return 0;
1301}
1302
1303static void
1304cifs_destroy_inodecache(void)
1305{
8c0a8537
KS
1306 /*
1307 * Make sure all delayed rcu free inodes are flushed before we
1308 * destroy cache.
1309 */
1310 rcu_barrier();
1a1d92c1 1311 kmem_cache_destroy(cifs_inode_cachep);
1da177e4
LT
1312}
1313
1314static int
1315cifs_init_request_bufs(void)
1316{
3792c173
PS
1317 /*
1318 * SMB2 maximum header size is bigger than CIFS one - no problems to
1319 * allocate some more bytes for CIFS.
1320 */
2a38e120
SF
1321 size_t max_hdr_size = MAX_SMB2_HDR_SIZE;
1322
4523cc30 1323 if (CIFSMaxBufSize < 8192) {
1da177e4
LT
1324 /* Buffer size can not be smaller than 2 * PATH_MAX since maximum
1325 Unicode path name has to fit in any SMB/CIFS path based frames */
1326 CIFSMaxBufSize = 8192;
1327 } else if (CIFSMaxBufSize > 1024*127) {
1328 CIFSMaxBufSize = 1024 * 127;
1329 } else {
1330 CIFSMaxBufSize &= 0x1FE00; /* Round size to even 512 byte mult*/
1331 }
f96637be
JP
1332/*
1333 cifs_dbg(VFS, "CIFSMaxBufSize %d 0x%x\n",
1334 CIFSMaxBufSize, CIFSMaxBufSize);
1335*/
de046449 1336 cifs_req_cachep = kmem_cache_create_usercopy("cifs_request",
3792c173 1337 CIFSMaxBufSize + max_hdr_size, 0,
de046449
DW
1338 SLAB_HWCACHE_ALIGN, 0,
1339 CIFSMaxBufSize + max_hdr_size,
1340 NULL);
1da177e4
LT
1341 if (cifs_req_cachep == NULL)
1342 return -ENOMEM;
1343
4523cc30 1344 if (cifs_min_rcv < 1)
1da177e4
LT
1345 cifs_min_rcv = 1;
1346 else if (cifs_min_rcv > 64) {
1347 cifs_min_rcv = 64;
f96637be 1348 cifs_dbg(VFS, "cifs_min_rcv set to maximum (64)\n");
1da177e4
LT
1349 }
1350
93d2341c
MD
1351 cifs_req_poolp = mempool_create_slab_pool(cifs_min_rcv,
1352 cifs_req_cachep);
1da177e4 1353
4523cc30 1354 if (cifs_req_poolp == NULL) {
1da177e4
LT
1355 kmem_cache_destroy(cifs_req_cachep);
1356 return -ENOMEM;
1357 }
ec637e3f 1358 /* MAX_CIFS_SMALL_BUFFER_SIZE bytes is enough for most SMB responses and
1da177e4
LT
1359 almost all handle based requests (but not write response, nor is it
1360 sufficient for path based requests). A smaller size would have
50c2f753 1361 been more efficient (compacting multiple slab items on one 4k page)
1da177e4
LT
1362 for the case in which debug was on, but this larger size allows
1363 more SMBs to use small buffer alloc and is still much more
6dc0f87e 1364 efficient to alloc 1 per page off the slab compared to 17K (5page)
1da177e4 1365 alloc of large cifs buffers even when page debugging is on */
de046449 1366 cifs_sm_req_cachep = kmem_cache_create_usercopy("cifs_small_rq",
6dc0f87e 1367 MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
de046449 1368 0, MAX_CIFS_SMALL_BUFFER_SIZE, NULL);
1da177e4
LT
1369 if (cifs_sm_req_cachep == NULL) {
1370 mempool_destroy(cifs_req_poolp);
1371 kmem_cache_destroy(cifs_req_cachep);
6dc0f87e 1372 return -ENOMEM;
1da177e4
LT
1373 }
1374
4523cc30 1375 if (cifs_min_small < 2)
1da177e4
LT
1376 cifs_min_small = 2;
1377 else if (cifs_min_small > 256) {
1378 cifs_min_small = 256;
f96637be 1379 cifs_dbg(FYI, "cifs_min_small set to maximum (256)\n");
1da177e4
LT
1380 }
1381
93d2341c
MD
1382 cifs_sm_req_poolp = mempool_create_slab_pool(cifs_min_small,
1383 cifs_sm_req_cachep);
1da177e4 1384
4523cc30 1385 if (cifs_sm_req_poolp == NULL) {
1da177e4
LT
1386 mempool_destroy(cifs_req_poolp);
1387 kmem_cache_destroy(cifs_req_cachep);
1388 kmem_cache_destroy(cifs_sm_req_cachep);
1389 return -ENOMEM;
1390 }
1391
1392 return 0;
1393}
1394
1395static void
1396cifs_destroy_request_bufs(void)
1397{
1398 mempool_destroy(cifs_req_poolp);
1a1d92c1 1399 kmem_cache_destroy(cifs_req_cachep);
1da177e4 1400 mempool_destroy(cifs_sm_req_poolp);
1a1d92c1 1401 kmem_cache_destroy(cifs_sm_req_cachep);
1da177e4
LT
1402}
1403
1404static int
1405cifs_init_mids(void)
1406{
1407 cifs_mid_cachep = kmem_cache_create("cifs_mpx_ids",
26f57364
SF
1408 sizeof(struct mid_q_entry), 0,
1409 SLAB_HWCACHE_ALIGN, NULL);
1da177e4
LT
1410 if (cifs_mid_cachep == NULL)
1411 return -ENOMEM;
1412
93d2341c
MD
1413 /* 3 is a reasonable minimum number of simultaneous operations */
1414 cifs_mid_poolp = mempool_create_slab_pool(3, cifs_mid_cachep);
4523cc30 1415 if (cifs_mid_poolp == NULL) {
1da177e4
LT
1416 kmem_cache_destroy(cifs_mid_cachep);
1417 return -ENOMEM;
1418 }
1419
1da177e4
LT
1420 return 0;
1421}
1422
1423static void
1424cifs_destroy_mids(void)
1425{
1426 mempool_destroy(cifs_mid_poolp);
1a1d92c1 1427 kmem_cache_destroy(cifs_mid_cachep);
1da177e4
LT
1428}
1429
1da177e4
LT
1430static int __init
1431init_cifs(void)
1432{
1433 int rc = 0;
1da177e4 1434 cifs_proc_init();
e7ddee90 1435 INIT_LIST_HEAD(&cifs_tcp_ses_list);
0eff0e26 1436#ifdef CONFIG_CIFS_DNOTIFY_EXPERIMENTAL /* unused temporarily */
4ca9c190
SF
1437 INIT_LIST_HEAD(&GlobalDnotifyReqList);
1438 INIT_LIST_HEAD(&GlobalDnotifyRsp_Q);
0eff0e26 1439#endif /* was needed for dnotify, and will be needed for inotify when VFS fix */
1da177e4
LT
1440/*
1441 * Initialize Global counters
1442 */
1443 atomic_set(&sesInfoAllocCount, 0);
1444 atomic_set(&tconInfoAllocCount, 0);
6dc0f87e 1445 atomic_set(&tcpSesAllocCount, 0);
1da177e4
LT
1446 atomic_set(&tcpSesReconnectCount, 0);
1447 atomic_set(&tconInfoReconnectCount, 0);
1448
1449 atomic_set(&bufAllocCount, 0);
4498eed5
SF
1450 atomic_set(&smBufAllocCount, 0);
1451#ifdef CONFIG_CIFS_STATS2
1452 atomic_set(&totBufAllocCount, 0);
1453 atomic_set(&totSmBufAllocCount, 0);
00778e22
SF
1454 if (slow_rsp_threshold < 1)
1455 cifs_dbg(FYI, "slow_response_threshold msgs disabled\n");
1456 else if (slow_rsp_threshold > 32767)
1457 cifs_dbg(VFS,
1458 "slow response threshold set higher than recommended (0 to 32767)\n");
4498eed5
SF
1459#endif /* CONFIG_CIFS_STATS2 */
1460
1da177e4
LT
1461 atomic_set(&midCount, 0);
1462 GlobalCurrentXid = 0;
1463 GlobalTotalActiveXid = 0;
1464 GlobalMaxActiveXid = 0;
3f9bcca7 1465 spin_lock_init(&cifs_tcp_ses_lock);
1da177e4
LT
1466 spin_lock_init(&GlobalMid_Lock);
1467
51b0817b 1468 cifs_lock_secret = get_random_u32();
3d22462a 1469
4523cc30 1470 if (cifs_max_pending < 2) {
1da177e4 1471 cifs_max_pending = 2;
f96637be 1472 cifs_dbg(FYI, "cifs_max_pending set to min of 2\n");
10b9b98e
PS
1473 } else if (cifs_max_pending > CIFS_MAX_REQ) {
1474 cifs_max_pending = CIFS_MAX_REQ;
f96637be
JP
1475 cifs_dbg(FYI, "cifs_max_pending set to max of %u\n",
1476 CIFS_MAX_REQ);
1da177e4
LT
1477 }
1478
da472fc8
JL
1479 cifsiod_wq = alloc_workqueue("cifsiod", WQ_FREEZABLE|WQ_MEM_RECLAIM, 0);
1480 if (!cifsiod_wq) {
1481 rc = -ENOMEM;
1482 goto out_clean_proc;
1483 }
1484
3998e6b8
RV
1485 cifsoplockd_wq = alloc_workqueue("cifsoplockd",
1486 WQ_FREEZABLE|WQ_MEM_RECLAIM, 0);
1487 if (!cifsoplockd_wq) {
1488 rc = -ENOMEM;
1489 goto out_destroy_cifsiod_wq;
1490 }
1491
f579cf3c
SJ
1492 rc = cifs_fscache_register();
1493 if (rc)
3998e6b8 1494 goto out_destroy_cifsoplockd_wq;
f579cf3c 1495
1da177e4 1496 rc = cifs_init_inodecache();
45af7a0f 1497 if (rc)
d3bf5221 1498 goto out_unreg_fscache;
45af7a0f
SF
1499
1500 rc = cifs_init_mids();
1501 if (rc)
1502 goto out_destroy_inodecache;
1503
1504 rc = cifs_init_request_bufs();
1505 if (rc)
1506 goto out_destroy_mids;
1507
1c780228
PA
1508#ifdef CONFIG_CIFS_DFS_UPCALL
1509 rc = dfs_cache_init();
1510 if (rc)
1511 goto out_destroy_request_bufs;
1512#endif /* CONFIG_CIFS_DFS_UPCALL */
84a15b93 1513#ifdef CONFIG_CIFS_UPCALL
b74cb9a8 1514 rc = init_cifs_spnego();
84a15b93 1515 if (rc)
1c780228 1516 goto out_destroy_dfs_cache;
4d79dba0
SP
1517#endif /* CONFIG_CIFS_UPCALL */
1518
1519#ifdef CONFIG_CIFS_ACL
1520 rc = init_cifs_idmap();
1521 if (rc)
c4aca0c0 1522 goto out_register_key_type;
4d79dba0
SP
1523#endif /* CONFIG_CIFS_ACL */
1524
1525 rc = register_filesystem(&cifs_fs_type);
1526 if (rc)
c4aca0c0 1527 goto out_init_cifs_idmap;
45af7a0f 1528
49218b4f
SF
1529 rc = register_filesystem(&smb3_fs_type);
1530 if (rc) {
1531 unregister_filesystem(&cifs_fs_type);
1532 goto out_init_cifs_idmap;
1533 }
1534
45af7a0f
SF
1535 return 0;
1536
c4aca0c0 1537out_init_cifs_idmap:
4d79dba0
SP
1538#ifdef CONFIG_CIFS_ACL
1539 exit_cifs_idmap();
c4aca0c0 1540out_register_key_type:
4d79dba0 1541#endif
84a15b93 1542#ifdef CONFIG_CIFS_UPCALL
b74cb9a8 1543 exit_cifs_spnego();
1c780228
PA
1544out_destroy_dfs_cache:
1545#endif
1546#ifdef CONFIG_CIFS_DFS_UPCALL
1547 dfs_cache_destroy();
c4aca0c0 1548out_destroy_request_bufs:
1fc7995d 1549#endif
45af7a0f 1550 cifs_destroy_request_bufs();
d3bf5221 1551out_destroy_mids:
45af7a0f 1552 cifs_destroy_mids();
d3bf5221 1553out_destroy_inodecache:
45af7a0f 1554 cifs_destroy_inodecache();
d3bf5221 1555out_unreg_fscache:
f579cf3c 1556 cifs_fscache_unregister();
3998e6b8
RV
1557out_destroy_cifsoplockd_wq:
1558 destroy_workqueue(cifsoplockd_wq);
1559out_destroy_cifsiod_wq:
da472fc8 1560 destroy_workqueue(cifsiod_wq);
d3bf5221
SF
1561out_clean_proc:
1562 cifs_proc_clean();
1da177e4
LT
1563 return rc;
1564}
1565
1566static void __exit
1567exit_cifs(void)
1568{
49218b4f 1569 cifs_dbg(NOISY, "exit_smb3\n");
3dd93306 1570 unregister_filesystem(&cifs_fs_type);
49218b4f 1571 unregister_filesystem(&smb3_fs_type);
78d31a3a 1572 cifs_dfs_release_automount_timer();
4d79dba0 1573#ifdef CONFIG_CIFS_ACL
4d79dba0
SP
1574 exit_cifs_idmap();
1575#endif
84a15b93 1576#ifdef CONFIG_CIFS_UPCALL
94183331 1577 exit_cifs_spnego();
1c780228
PA
1578#endif
1579#ifdef CONFIG_CIFS_DFS_UPCALL
1580 dfs_cache_destroy();
1da177e4 1581#endif
1da177e4 1582 cifs_destroy_request_bufs();
3dd93306
JL
1583 cifs_destroy_mids();
1584 cifs_destroy_inodecache();
1585 cifs_fscache_unregister();
3998e6b8 1586 destroy_workqueue(cifsoplockd_wq);
da472fc8 1587 destroy_workqueue(cifsiod_wq);
3dd93306 1588 cifs_proc_clean();
1da177e4
LT
1589}
1590
1c3a13a3 1591MODULE_AUTHOR("Steve French");
6dc0f87e 1592MODULE_LICENSE("GPL"); /* combination of LGPL + GPL source behaves as GPL */
1da177e4 1593MODULE_DESCRIPTION
1c3a13a3
SF
1594 ("VFS to access SMB3 servers e.g. Samba, Macs, Azure and Windows (and "
1595 "also older servers complying with the SNIA CIFS Specification)");
1da177e4 1596MODULE_VERSION(CIFS_VERSION);
b9be76d5
JD
1597MODULE_SOFTDEP("pre: arc4");
1598MODULE_SOFTDEP("pre: des");
1599MODULE_SOFTDEP("pre: ecb");
1600MODULE_SOFTDEP("pre: hmac");
1601MODULE_SOFTDEP("pre: md4");
1602MODULE_SOFTDEP("pre: md5");
1603MODULE_SOFTDEP("pre: nls");
b9be76d5
JD
1604MODULE_SOFTDEP("pre: aes");
1605MODULE_SOFTDEP("pre: cmac");
1606MODULE_SOFTDEP("pre: sha256");
5fcd7f3f 1607MODULE_SOFTDEP("pre: sha512");
026e93dc
PS
1608MODULE_SOFTDEP("pre: aead2");
1609MODULE_SOFTDEP("pre: ccm");
1da177e4
LT
1610module_init(init_cifs)
1611module_exit(exit_cifs)