cifs: fix lock length calculation
[linux-2.6-microblaze.git] / fs / cifs / cifsfs.c
1 // SPDX-License-Identifier: LGPL-2.1
2 /*
3  *
4  *   Copyright (C) International Business Machines  Corp., 2002,2008
5  *   Author(s): Steve French (sfrench@us.ibm.com)
6  *
7  *   Common Internet FileSystem (CIFS) client
8  *
9  */
10
11 /* Note that BB means BUGBUG (ie something to fix eventually) */
12
13 #include <linux/module.h>
14 #include <linux/fs.h>
15 #include <linux/mount.h>
16 #include <linux/slab.h>
17 #include <linux/init.h>
18 #include <linux/list.h>
19 #include <linux/seq_file.h>
20 #include <linux/vfs.h>
21 #include <linux/mempool.h>
22 #include <linux/delay.h>
23 #include <linux/kthread.h>
24 #include <linux/freezer.h>
25 #include <linux/namei.h>
26 #include <linux/random.h>
27 #include <linux/uuid.h>
28 #include <linux/xattr.h>
29 #include <uapi/linux/magic.h>
30 #include <net/ipv6.h>
31 #include "cifsfs.h"
32 #include "cifspdu.h"
33 #define DECLARE_GLOBALS_HERE
34 #include "cifsglob.h"
35 #include "cifsproto.h"
36 #include "cifs_debug.h"
37 #include "cifs_fs_sb.h"
38 #include <linux/mm.h>
39 #include <linux/key-type.h>
40 #include "cifs_spnego.h"
41 #include "fscache.h"
42 #ifdef CONFIG_CIFS_DFS_UPCALL
43 #include "dfs_cache.h"
44 #endif
45 #ifdef CONFIG_CIFS_SWN_UPCALL
46 #include "netlink.h"
47 #endif
48 #include "fs_context.h"
49
50 /*
51  * DOS dates from 1980/1/1 through 2107/12/31
52  * Protocol specifications indicate the range should be to 119, which
53  * limits maximum year to 2099. But this range has not been checked.
54  */
55 #define SMB_DATE_MAX (127<<9 | 12<<5 | 31)
56 #define SMB_DATE_MIN (0<<9 | 1<<5 | 1)
57 #define SMB_TIME_MAX (23<<11 | 59<<5 | 29)
58
59 int cifsFYI = 0;
60 bool traceSMB;
61 bool enable_oplocks = true;
62 bool linuxExtEnabled = true;
63 bool lookupCacheEnabled = true;
64 bool disable_legacy_dialects; /* false by default */
65 bool enable_gcm_256 = true;
66 bool require_gcm_256; /* false by default */
67 bool enable_negotiate_signing; /* false by default */
68 unsigned int global_secflags = CIFSSEC_DEF;
69 /* unsigned int ntlmv2_support = 0; */
70 unsigned int sign_CIFS_PDUs = 1;
71
72 /*
73  * Global transaction id (XID) information
74  */
75 unsigned int GlobalCurrentXid;  /* protected by GlobalMid_Sem */
76 unsigned int GlobalTotalActiveXid; /* prot by GlobalMid_Sem */
77 unsigned int GlobalMaxActiveXid;        /* prot by GlobalMid_Sem */
78 spinlock_t GlobalMid_Lock; /* protects above & list operations on midQ entries */
79
80 /*
81  *  Global counters, updated atomically
82  */
83 atomic_t sesInfoAllocCount;
84 atomic_t tconInfoAllocCount;
85 atomic_t tcpSesNextId;
86 atomic_t tcpSesAllocCount;
87 atomic_t tcpSesReconnectCount;
88 atomic_t tconInfoReconnectCount;
89
90 atomic_t mid_count;
91 atomic_t buf_alloc_count;
92 atomic_t small_buf_alloc_count;
93 #ifdef CONFIG_CIFS_STATS2
94 atomic_t total_buf_alloc_count;
95 atomic_t total_small_buf_alloc_count;
96 #endif/* STATS2 */
97 struct list_head        cifs_tcp_ses_list;
98 spinlock_t              cifs_tcp_ses_lock;
99 static const struct super_operations cifs_super_ops;
100 unsigned int CIFSMaxBufSize = CIFS_MAX_MSGSIZE;
101 module_param(CIFSMaxBufSize, uint, 0444);
102 MODULE_PARM_DESC(CIFSMaxBufSize, "Network buffer size (not including header) "
103                                  "for CIFS requests. "
104                                  "Default: 16384 Range: 8192 to 130048");
105 unsigned int cifs_min_rcv = CIFS_MIN_RCV_POOL;
106 module_param(cifs_min_rcv, uint, 0444);
107 MODULE_PARM_DESC(cifs_min_rcv, "Network buffers in pool. Default: 4 Range: "
108                                 "1 to 64");
109 unsigned int cifs_min_small = 30;
110 module_param(cifs_min_small, uint, 0444);
111 MODULE_PARM_DESC(cifs_min_small, "Small network buffers in pool. Default: 30 "
112                                  "Range: 2 to 256");
113 unsigned int cifs_max_pending = CIFS_MAX_REQ;
114 module_param(cifs_max_pending, uint, 0444);
115 MODULE_PARM_DESC(cifs_max_pending, "Simultaneous requests to server for "
116                                    "CIFS/SMB1 dialect (N/A for SMB3) "
117                                    "Default: 32767 Range: 2 to 32767.");
118 #ifdef CONFIG_CIFS_STATS2
119 unsigned int slow_rsp_threshold = 1;
120 module_param(slow_rsp_threshold, uint, 0644);
121 MODULE_PARM_DESC(slow_rsp_threshold, "Amount of time (in seconds) to wait "
122                                    "before logging that a response is delayed. "
123                                    "Default: 1 (if set to 0 disables msg).");
124 #endif /* STATS2 */
125
126 module_param(enable_oplocks, bool, 0644);
127 MODULE_PARM_DESC(enable_oplocks, "Enable or disable oplocks. Default: y/Y/1");
128
129 module_param(enable_gcm_256, bool, 0644);
130 MODULE_PARM_DESC(enable_gcm_256, "Enable requesting strongest (256 bit) GCM encryption. Default: n/N/0");
131
132 module_param(require_gcm_256, bool, 0644);
133 MODULE_PARM_DESC(require_gcm_256, "Require strongest (256 bit) GCM encryption. Default: n/N/0");
134
135 module_param(enable_negotiate_signing, bool, 0644);
136 MODULE_PARM_DESC(enable_negotiate_signing, "Enable negotiating packet signing algorithm with server. Default: n/N/0");
137
138 module_param(disable_legacy_dialects, bool, 0644);
139 MODULE_PARM_DESC(disable_legacy_dialects, "To improve security it may be "
140                                   "helpful to restrict the ability to "
141                                   "override the default dialects (SMB2.1, "
142                                   "SMB3 and SMB3.02) on mount with old "
143                                   "dialects (CIFS/SMB1 and SMB2) since "
144                                   "vers=1.0 (CIFS/SMB1) and vers=2.0 are weaker"
145                                   " and less secure. Default: n/N/0");
146
147 extern mempool_t *cifs_sm_req_poolp;
148 extern mempool_t *cifs_req_poolp;
149 extern mempool_t *cifs_mid_poolp;
150
151 struct workqueue_struct *cifsiod_wq;
152 struct workqueue_struct *decrypt_wq;
153 struct workqueue_struct *fileinfo_put_wq;
154 struct workqueue_struct *cifsoplockd_wq;
155 struct workqueue_struct *deferredclose_wq;
156 __u32 cifs_lock_secret;
157
158 /*
159  * Bumps refcount for cifs super block.
160  * Note that it should be only called if a referece to VFS super block is
161  * already held, e.g. in open-type syscalls context. Otherwise it can race with
162  * atomic_dec_and_test in deactivate_locked_super.
163  */
164 void
165 cifs_sb_active(struct super_block *sb)
166 {
167         struct cifs_sb_info *server = CIFS_SB(sb);
168
169         if (atomic_inc_return(&server->active) == 1)
170                 atomic_inc(&sb->s_active);
171 }
172
173 void
174 cifs_sb_deactive(struct super_block *sb)
175 {
176         struct cifs_sb_info *server = CIFS_SB(sb);
177
178         if (atomic_dec_and_test(&server->active))
179                 deactivate_super(sb);
180 }
181
182 static int
183 cifs_read_super(struct super_block *sb)
184 {
185         struct inode *inode;
186         struct cifs_sb_info *cifs_sb;
187         struct cifs_tcon *tcon;
188         struct timespec64 ts;
189         int rc = 0;
190
191         cifs_sb = CIFS_SB(sb);
192         tcon = cifs_sb_master_tcon(cifs_sb);
193
194         if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIXACL)
195                 sb->s_flags |= SB_POSIXACL;
196
197         if (tcon->snapshot_time)
198                 sb->s_flags |= SB_RDONLY;
199
200         if (tcon->ses->capabilities & tcon->ses->server->vals->cap_large_files)
201                 sb->s_maxbytes = MAX_LFS_FILESIZE;
202         else
203                 sb->s_maxbytes = MAX_NON_LFS;
204
205         /*
206          * Some very old servers like DOS and OS/2 used 2 second granularity
207          * (while all current servers use 100ns granularity - see MS-DTYP)
208          * but 1 second is the maximum allowed granularity for the VFS
209          * so for old servers set time granularity to 1 second while for
210          * everything else (current servers) set it to 100ns.
211          */
212         if ((tcon->ses->server->vals->protocol_id == SMB10_PROT_ID) &&
213             ((tcon->ses->capabilities &
214               tcon->ses->server->vals->cap_nt_find) == 0) &&
215             !tcon->unix_ext) {
216                 sb->s_time_gran = 1000000000; /* 1 second is max allowed gran */
217                 ts = cnvrtDosUnixTm(cpu_to_le16(SMB_DATE_MIN), 0, 0);
218                 sb->s_time_min = ts.tv_sec;
219                 ts = cnvrtDosUnixTm(cpu_to_le16(SMB_DATE_MAX),
220                                     cpu_to_le16(SMB_TIME_MAX), 0);
221                 sb->s_time_max = ts.tv_sec;
222         } else {
223                 /*
224                  * Almost every server, including all SMB2+, uses DCE TIME
225                  * ie 100 nanosecond units, since 1601.  See MS-DTYP and MS-FSCC
226                  */
227                 sb->s_time_gran = 100;
228                 ts = cifs_NTtimeToUnix(0);
229                 sb->s_time_min = ts.tv_sec;
230                 ts = cifs_NTtimeToUnix(cpu_to_le64(S64_MAX));
231                 sb->s_time_max = ts.tv_sec;
232         }
233
234         sb->s_magic = CIFS_SUPER_MAGIC;
235         sb->s_op = &cifs_super_ops;
236         sb->s_xattr = cifs_xattr_handlers;
237         rc = super_setup_bdi(sb);
238         if (rc)
239                 goto out_no_root;
240         /* tune readahead according to rsize if readahead size not set on mount */
241         if (cifs_sb->ctx->rsize == 0)
242                 cifs_sb->ctx->rsize =
243                         tcon->ses->server->ops->negotiate_rsize(tcon, cifs_sb->ctx);
244         if (cifs_sb->ctx->rasize)
245                 sb->s_bdi->ra_pages = cifs_sb->ctx->rasize / PAGE_SIZE;
246         else
247                 sb->s_bdi->ra_pages = cifs_sb->ctx->rsize / PAGE_SIZE;
248
249         sb->s_blocksize = CIFS_MAX_MSGSIZE;
250         sb->s_blocksize_bits = 14;      /* default 2**14 = CIFS_MAX_MSGSIZE */
251         inode = cifs_root_iget(sb);
252
253         if (IS_ERR(inode)) {
254                 rc = PTR_ERR(inode);
255                 goto out_no_root;
256         }
257
258         if (tcon->nocase)
259                 sb->s_d_op = &cifs_ci_dentry_ops;
260         else
261                 sb->s_d_op = &cifs_dentry_ops;
262
263         sb->s_root = d_make_root(inode);
264         if (!sb->s_root) {
265                 rc = -ENOMEM;
266                 goto out_no_root;
267         }
268
269 #ifdef CONFIG_CIFS_NFSD_EXPORT
270         if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) {
271                 cifs_dbg(FYI, "export ops supported\n");
272                 sb->s_export_op = &cifs_export_ops;
273         }
274 #endif /* CONFIG_CIFS_NFSD_EXPORT */
275
276         return 0;
277
278 out_no_root:
279         cifs_dbg(VFS, "%s: get root inode failed\n", __func__);
280         return rc;
281 }
282
283 static void cifs_kill_sb(struct super_block *sb)
284 {
285         struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
286         struct cifs_tcon *tcon;
287         struct cached_fid *cfid;
288         struct rb_root *root = &cifs_sb->tlink_tree;
289         struct rb_node *node;
290         struct tcon_link *tlink;
291
292         /*
293          * We ned to release all dentries for the cached directories
294          * before we kill the sb.
295          */
296         if (cifs_sb->root) {
297                 for (node = rb_first(root); node; node = rb_next(node)) {
298                         tlink = rb_entry(node, struct tcon_link, tl_rbnode);
299                         tcon = tlink_tcon(tlink);
300                         if (IS_ERR(tcon))
301                                 continue;
302                         cfid = &tcon->crfid;
303                         mutex_lock(&cfid->fid_mutex);
304                         if (cfid->dentry) {
305                                 dput(cfid->dentry);
306                                 cfid->dentry = NULL;
307                         }
308                         mutex_unlock(&cfid->fid_mutex);
309                 }
310
311                 /* finally release root dentry */
312                 dput(cifs_sb->root);
313                 cifs_sb->root = NULL;
314         }
315
316         kill_anon_super(sb);
317         cifs_umount(cifs_sb);
318 }
319
320 static int
321 cifs_statfs(struct dentry *dentry, struct kstatfs *buf)
322 {
323         struct super_block *sb = dentry->d_sb;
324         struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
325         struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
326         struct TCP_Server_Info *server = tcon->ses->server;
327         unsigned int xid;
328         int rc = 0;
329
330         xid = get_xid();
331
332         if (le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength) > 0)
333                 buf->f_namelen =
334                        le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength);
335         else
336                 buf->f_namelen = PATH_MAX;
337
338         buf->f_fsid.val[0] = tcon->vol_serial_number;
339         /* are using part of create time for more randomness, see man statfs */
340         buf->f_fsid.val[1] =  (int)le64_to_cpu(tcon->vol_create_time);
341
342         buf->f_files = 0;       /* undefined */
343         buf->f_ffree = 0;       /* unlimited */
344
345         if (server->ops->queryfs)
346                 rc = server->ops->queryfs(xid, tcon, cifs_sb, buf);
347
348         free_xid(xid);
349         return rc;
350 }
351
352 static long cifs_fallocate(struct file *file, int mode, loff_t off, loff_t len)
353 {
354         struct cifs_sb_info *cifs_sb = CIFS_FILE_SB(file);
355         struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
356         struct TCP_Server_Info *server = tcon->ses->server;
357
358         if (server->ops->fallocate)
359                 return server->ops->fallocate(file, tcon, mode, off, len);
360
361         return -EOPNOTSUPP;
362 }
363
364 static int cifs_permission(struct user_namespace *mnt_userns,
365                            struct inode *inode, int mask)
366 {
367         struct cifs_sb_info *cifs_sb;
368
369         cifs_sb = CIFS_SB(inode->i_sb);
370
371         if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) {
372                 if ((mask & MAY_EXEC) && !execute_ok(inode))
373                         return -EACCES;
374                 else
375                         return 0;
376         } else /* file mode might have been restricted at mount time
377                 on the client (above and beyond ACL on servers) for
378                 servers which do not support setting and viewing mode bits,
379                 so allowing client to check permissions is useful */
380                 return generic_permission(&init_user_ns, inode, mask);
381 }
382
383 static struct kmem_cache *cifs_inode_cachep;
384 static struct kmem_cache *cifs_req_cachep;
385 static struct kmem_cache *cifs_mid_cachep;
386 static struct kmem_cache *cifs_sm_req_cachep;
387 mempool_t *cifs_sm_req_poolp;
388 mempool_t *cifs_req_poolp;
389 mempool_t *cifs_mid_poolp;
390
391 static struct inode *
392 cifs_alloc_inode(struct super_block *sb)
393 {
394         struct cifsInodeInfo *cifs_inode;
395         cifs_inode = alloc_inode_sb(sb, cifs_inode_cachep, GFP_KERNEL);
396         if (!cifs_inode)
397                 return NULL;
398         cifs_inode->cifsAttrs = 0x20;   /* default */
399         cifs_inode->time = 0;
400         /*
401          * Until the file is open and we have gotten oplock info back from the
402          * server, can not assume caching of file data or metadata.
403          */
404         cifs_set_oplock_level(cifs_inode, 0);
405         cifs_inode->flags = 0;
406         spin_lock_init(&cifs_inode->writers_lock);
407         cifs_inode->writers = 0;
408         cifs_inode->netfs.inode.i_blkbits = 14;  /* 2**14 = CIFS_MAX_MSGSIZE */
409         cifs_inode->server_eof = 0;
410         cifs_inode->uniqueid = 0;
411         cifs_inode->createtime = 0;
412         cifs_inode->epoch = 0;
413         spin_lock_init(&cifs_inode->open_file_lock);
414         generate_random_uuid(cifs_inode->lease_key);
415
416         /*
417          * Can not set i_flags here - they get immediately overwritten to zero
418          * by the VFS.
419          */
420         /* cifs_inode->netfs.inode.i_flags = S_NOATIME | S_NOCMTIME; */
421         INIT_LIST_HEAD(&cifs_inode->openFileList);
422         INIT_LIST_HEAD(&cifs_inode->llist);
423         INIT_LIST_HEAD(&cifs_inode->deferred_closes);
424         spin_lock_init(&cifs_inode->deferred_lock);
425         return &cifs_inode->netfs.inode;
426 }
427
428 static void
429 cifs_free_inode(struct inode *inode)
430 {
431         kmem_cache_free(cifs_inode_cachep, CIFS_I(inode));
432 }
433
434 static void
435 cifs_evict_inode(struct inode *inode)
436 {
437         truncate_inode_pages_final(&inode->i_data);
438         if (inode->i_state & I_PINNING_FSCACHE_WB)
439                 cifs_fscache_unuse_inode_cookie(inode, true);
440         cifs_fscache_release_inode_cookie(inode);
441         clear_inode(inode);
442 }
443
444 static void
445 cifs_show_address(struct seq_file *s, struct TCP_Server_Info *server)
446 {
447         struct sockaddr_in *sa = (struct sockaddr_in *) &server->dstaddr;
448         struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *) &server->dstaddr;
449
450         seq_puts(s, ",addr=");
451
452         switch (server->dstaddr.ss_family) {
453         case AF_INET:
454                 seq_printf(s, "%pI4", &sa->sin_addr.s_addr);
455                 break;
456         case AF_INET6:
457                 seq_printf(s, "%pI6", &sa6->sin6_addr.s6_addr);
458                 if (sa6->sin6_scope_id)
459                         seq_printf(s, "%%%u", sa6->sin6_scope_id);
460                 break;
461         default:
462                 seq_puts(s, "(unknown)");
463         }
464         if (server->rdma)
465                 seq_puts(s, ",rdma");
466 }
467
468 static void
469 cifs_show_security(struct seq_file *s, struct cifs_ses *ses)
470 {
471         if (ses->sectype == Unspecified) {
472                 if (ses->user_name == NULL)
473                         seq_puts(s, ",sec=none");
474                 return;
475         }
476
477         seq_puts(s, ",sec=");
478
479         switch (ses->sectype) {
480         case NTLMv2:
481                 seq_puts(s, "ntlmv2");
482                 break;
483         case Kerberos:
484                 seq_puts(s, "krb5");
485                 break;
486         case RawNTLMSSP:
487                 seq_puts(s, "ntlmssp");
488                 break;
489         default:
490                 /* shouldn't ever happen */
491                 seq_puts(s, "unknown");
492                 break;
493         }
494
495         if (ses->sign)
496                 seq_puts(s, "i");
497
498         if (ses->sectype == Kerberos)
499                 seq_printf(s, ",cruid=%u",
500                            from_kuid_munged(&init_user_ns, ses->cred_uid));
501 }
502
503 static void
504 cifs_show_cache_flavor(struct seq_file *s, struct cifs_sb_info *cifs_sb)
505 {
506         seq_puts(s, ",cache=");
507
508         if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO)
509                 seq_puts(s, "strict");
510         else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO)
511                 seq_puts(s, "none");
512         else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RW_CACHE)
513                 seq_puts(s, "singleclient"); /* assume only one client access */
514         else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RO_CACHE)
515                 seq_puts(s, "ro"); /* read only caching assumed */
516         else
517                 seq_puts(s, "loose");
518 }
519
520 /*
521  * cifs_show_devname() is used so we show the mount device name with correct
522  * format (e.g. forward slashes vs. back slashes) in /proc/mounts
523  */
524 static int cifs_show_devname(struct seq_file *m, struct dentry *root)
525 {
526         struct cifs_sb_info *cifs_sb = CIFS_SB(root->d_sb);
527         char *devname = kstrdup(cifs_sb->ctx->source, GFP_KERNEL);
528
529         if (devname == NULL)
530                 seq_puts(m, "none");
531         else {
532                 convert_delimiter(devname, '/');
533                 /* escape all spaces in share names */
534                 seq_escape(m, devname, " \t");
535                 kfree(devname);
536         }
537         return 0;
538 }
539
540 /*
541  * cifs_show_options() is for displaying mount options in /proc/mounts.
542  * Not all settable options are displayed but most of the important
543  * ones are.
544  */
545 static int
546 cifs_show_options(struct seq_file *s, struct dentry *root)
547 {
548         struct cifs_sb_info *cifs_sb = CIFS_SB(root->d_sb);
549         struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
550         struct sockaddr *srcaddr;
551         srcaddr = (struct sockaddr *)&tcon->ses->server->srcaddr;
552
553         seq_show_option(s, "vers", tcon->ses->server->vals->version_string);
554         cifs_show_security(s, tcon->ses);
555         cifs_show_cache_flavor(s, cifs_sb);
556
557         if (tcon->no_lease)
558                 seq_puts(s, ",nolease");
559         if (cifs_sb->ctx->multiuser)
560                 seq_puts(s, ",multiuser");
561         else if (tcon->ses->user_name)
562                 seq_show_option(s, "username", tcon->ses->user_name);
563
564         if (tcon->ses->domainName && tcon->ses->domainName[0] != 0)
565                 seq_show_option(s, "domain", tcon->ses->domainName);
566
567         if (srcaddr->sa_family != AF_UNSPEC) {
568                 struct sockaddr_in *saddr4;
569                 struct sockaddr_in6 *saddr6;
570                 saddr4 = (struct sockaddr_in *)srcaddr;
571                 saddr6 = (struct sockaddr_in6 *)srcaddr;
572                 if (srcaddr->sa_family == AF_INET6)
573                         seq_printf(s, ",srcaddr=%pI6c",
574                                    &saddr6->sin6_addr);
575                 else if (srcaddr->sa_family == AF_INET)
576                         seq_printf(s, ",srcaddr=%pI4",
577                                    &saddr4->sin_addr.s_addr);
578                 else
579                         seq_printf(s, ",srcaddr=BAD-AF:%i",
580                                    (int)(srcaddr->sa_family));
581         }
582
583         seq_printf(s, ",uid=%u",
584                    from_kuid_munged(&init_user_ns, cifs_sb->ctx->linux_uid));
585         if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID)
586                 seq_puts(s, ",forceuid");
587         else
588                 seq_puts(s, ",noforceuid");
589
590         seq_printf(s, ",gid=%u",
591                    from_kgid_munged(&init_user_ns, cifs_sb->ctx->linux_gid));
592         if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID)
593                 seq_puts(s, ",forcegid");
594         else
595                 seq_puts(s, ",noforcegid");
596
597         cifs_show_address(s, tcon->ses->server);
598
599         if (!tcon->unix_ext)
600                 seq_printf(s, ",file_mode=0%ho,dir_mode=0%ho",
601                                            cifs_sb->ctx->file_mode,
602                                            cifs_sb->ctx->dir_mode);
603         if (cifs_sb->ctx->iocharset)
604                 seq_printf(s, ",iocharset=%s", cifs_sb->ctx->iocharset);
605         if (tcon->seal)
606                 seq_puts(s, ",seal");
607         else if (tcon->ses->server->ignore_signature)
608                 seq_puts(s, ",signloosely");
609         if (tcon->nocase)
610                 seq_puts(s, ",nocase");
611         if (tcon->nodelete)
612                 seq_puts(s, ",nodelete");
613         if (cifs_sb->ctx->no_sparse)
614                 seq_puts(s, ",nosparse");
615         if (tcon->local_lease)
616                 seq_puts(s, ",locallease");
617         if (tcon->retry)
618                 seq_puts(s, ",hard");
619         else
620                 seq_puts(s, ",soft");
621         if (tcon->use_persistent)
622                 seq_puts(s, ",persistenthandles");
623         else if (tcon->use_resilient)
624                 seq_puts(s, ",resilienthandles");
625         if (tcon->posix_extensions)
626                 seq_puts(s, ",posix");
627         else if (tcon->unix_ext)
628                 seq_puts(s, ",unix");
629         else
630                 seq_puts(s, ",nounix");
631         if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_DFS)
632                 seq_puts(s, ",nodfs");
633         if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)
634                 seq_puts(s, ",posixpaths");
635         if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID)
636                 seq_puts(s, ",setuids");
637         if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UID_FROM_ACL)
638                 seq_puts(s, ",idsfromsid");
639         if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)
640                 seq_puts(s, ",serverino");
641         if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD)
642                 seq_puts(s, ",rwpidforward");
643         if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL)
644                 seq_puts(s, ",forcemand");
645         if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
646                 seq_puts(s, ",nouser_xattr");
647         if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR)
648                 seq_puts(s, ",mapchars");
649         if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SFM_CHR)
650                 seq_puts(s, ",mapposix");
651         if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL)
652                 seq_puts(s, ",sfu");
653         if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
654                 seq_puts(s, ",nobrl");
655         if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_HANDLE_CACHE)
656                 seq_puts(s, ",nohandlecache");
657         if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MODE_FROM_SID)
658                 seq_puts(s, ",modefromsid");
659         if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL)
660                 seq_puts(s, ",cifsacl");
661         if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM)
662                 seq_puts(s, ",dynperm");
663         if (root->d_sb->s_flags & SB_POSIXACL)
664                 seq_puts(s, ",acl");
665         if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS)
666                 seq_puts(s, ",mfsymlinks");
667         if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_FSCACHE)
668                 seq_puts(s, ",fsc");
669         if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC)
670                 seq_puts(s, ",nostrictsync");
671         if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM)
672                 seq_puts(s, ",noperm");
673         if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_BACKUPUID)
674                 seq_printf(s, ",backupuid=%u",
675                            from_kuid_munged(&init_user_ns,
676                                             cifs_sb->ctx->backupuid));
677         if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_BACKUPGID)
678                 seq_printf(s, ",backupgid=%u",
679                            from_kgid_munged(&init_user_ns,
680                                             cifs_sb->ctx->backupgid));
681
682         seq_printf(s, ",rsize=%u", cifs_sb->ctx->rsize);
683         seq_printf(s, ",wsize=%u", cifs_sb->ctx->wsize);
684         seq_printf(s, ",bsize=%u", cifs_sb->ctx->bsize);
685         if (cifs_sb->ctx->rasize)
686                 seq_printf(s, ",rasize=%u", cifs_sb->ctx->rasize);
687         if (tcon->ses->server->min_offload)
688                 seq_printf(s, ",esize=%u", tcon->ses->server->min_offload);
689         seq_printf(s, ",echo_interval=%lu",
690                         tcon->ses->server->echo_interval / HZ);
691
692         /* Only display max_credits if it was overridden on mount */
693         if (tcon->ses->server->max_credits != SMB2_MAX_CREDITS_AVAILABLE)
694                 seq_printf(s, ",max_credits=%u", tcon->ses->server->max_credits);
695
696         if (tcon->snapshot_time)
697                 seq_printf(s, ",snapshot=%llu", tcon->snapshot_time);
698         if (tcon->handle_timeout)
699                 seq_printf(s, ",handletimeout=%u", tcon->handle_timeout);
700
701         /*
702          * Display file and directory attribute timeout in seconds.
703          * If file and directory attribute timeout the same then actimeo
704          * was likely specified on mount
705          */
706         if (cifs_sb->ctx->acdirmax == cifs_sb->ctx->acregmax)
707                 seq_printf(s, ",actimeo=%lu", cifs_sb->ctx->acregmax / HZ);
708         else {
709                 seq_printf(s, ",acdirmax=%lu", cifs_sb->ctx->acdirmax / HZ);
710                 seq_printf(s, ",acregmax=%lu", cifs_sb->ctx->acregmax / HZ);
711         }
712
713         if (tcon->ses->chan_max > 1)
714                 seq_printf(s, ",multichannel,max_channels=%zu",
715                            tcon->ses->chan_max);
716
717         if (tcon->use_witness)
718                 seq_puts(s, ",witness");
719
720         return 0;
721 }
722
723 static void cifs_umount_begin(struct super_block *sb)
724 {
725         struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
726         struct cifs_tcon *tcon;
727
728         if (cifs_sb == NULL)
729                 return;
730
731         tcon = cifs_sb_master_tcon(cifs_sb);
732
733         spin_lock(&cifs_tcp_ses_lock);
734         spin_lock(&tcon->tc_lock);
735         if ((tcon->tc_count > 1) || (tcon->status == TID_EXITING)) {
736                 /* we have other mounts to same share or we have
737                    already tried to force umount this and woken up
738                    all waiting network requests, nothing to do */
739                 spin_unlock(&tcon->tc_lock);
740                 spin_unlock(&cifs_tcp_ses_lock);
741                 return;
742         } else if (tcon->tc_count == 1)
743                 tcon->status = TID_EXITING;
744         spin_unlock(&tcon->tc_lock);
745         spin_unlock(&cifs_tcp_ses_lock);
746
747         /* cancel_brl_requests(tcon); */ /* BB mark all brl mids as exiting */
748         /* cancel_notify_requests(tcon); */
749         if (tcon->ses && tcon->ses->server) {
750                 cifs_dbg(FYI, "wake up tasks now - umount begin not complete\n");
751                 wake_up_all(&tcon->ses->server->request_q);
752                 wake_up_all(&tcon->ses->server->response_q);
753                 msleep(1); /* yield */
754                 /* we have to kick the requests once more */
755                 wake_up_all(&tcon->ses->server->response_q);
756                 msleep(1);
757         }
758
759         return;
760 }
761
762 #ifdef CONFIG_CIFS_STATS2
763 static int cifs_show_stats(struct seq_file *s, struct dentry *root)
764 {
765         /* BB FIXME */
766         return 0;
767 }
768 #endif
769
770 static int cifs_write_inode(struct inode *inode, struct writeback_control *wbc)
771 {
772         fscache_unpin_writeback(wbc, cifs_inode_cookie(inode));
773         return 0;
774 }
775
776 static int cifs_drop_inode(struct inode *inode)
777 {
778         struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
779
780         /* no serverino => unconditional eviction */
781         return !(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) ||
782                 generic_drop_inode(inode);
783 }
784
785 static const struct super_operations cifs_super_ops = {
786         .statfs = cifs_statfs,
787         .alloc_inode = cifs_alloc_inode,
788         .write_inode    = cifs_write_inode,
789         .free_inode = cifs_free_inode,
790         .drop_inode     = cifs_drop_inode,
791         .evict_inode    = cifs_evict_inode,
792 /*      .show_path      = cifs_show_path, */ /* Would we ever need show path? */
793         .show_devname   = cifs_show_devname,
794 /*      .delete_inode   = cifs_delete_inode,  */  /* Do not need above
795         function unless later we add lazy close of inodes or unless the
796         kernel forgets to call us with the same number of releases (closes)
797         as opens */
798         .show_options = cifs_show_options,
799         .umount_begin   = cifs_umount_begin,
800 #ifdef CONFIG_CIFS_STATS2
801         .show_stats = cifs_show_stats,
802 #endif
803 };
804
805 /*
806  * Get root dentry from superblock according to prefix path mount option.
807  * Return dentry with refcount + 1 on success and NULL otherwise.
808  */
809 static struct dentry *
810 cifs_get_root(struct smb3_fs_context *ctx, struct super_block *sb)
811 {
812         struct dentry *dentry;
813         struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
814         char *full_path = NULL;
815         char *s, *p;
816         char sep;
817
818         if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_USE_PREFIX_PATH)
819                 return dget(sb->s_root);
820
821         full_path = cifs_build_path_to_root(ctx, cifs_sb,
822                                 cifs_sb_master_tcon(cifs_sb), 0);
823         if (full_path == NULL)
824                 return ERR_PTR(-ENOMEM);
825
826         cifs_dbg(FYI, "Get root dentry for %s\n", full_path);
827
828         sep = CIFS_DIR_SEP(cifs_sb);
829         dentry = dget(sb->s_root);
830         s = full_path;
831
832         do {
833                 struct inode *dir = d_inode(dentry);
834                 struct dentry *child;
835
836                 if (!S_ISDIR(dir->i_mode)) {
837                         dput(dentry);
838                         dentry = ERR_PTR(-ENOTDIR);
839                         break;
840                 }
841
842                 /* skip separators */
843                 while (*s == sep)
844                         s++;
845                 if (!*s)
846                         break;
847                 p = s++;
848                 /* next separator */
849                 while (*s && *s != sep)
850                         s++;
851
852                 child = lookup_positive_unlocked(p, dentry, s - p);
853                 dput(dentry);
854                 dentry = child;
855         } while (!IS_ERR(dentry));
856         kfree(full_path);
857         return dentry;
858 }
859
860 static int cifs_set_super(struct super_block *sb, void *data)
861 {
862         struct cifs_mnt_data *mnt_data = data;
863         sb->s_fs_info = mnt_data->cifs_sb;
864         return set_anon_super(sb, NULL);
865 }
866
867 struct dentry *
868 cifs_smb3_do_mount(struct file_system_type *fs_type,
869               int flags, struct smb3_fs_context *old_ctx)
870 {
871         int rc;
872         struct super_block *sb = NULL;
873         struct cifs_sb_info *cifs_sb = NULL;
874         struct cifs_mnt_data mnt_data;
875         struct dentry *root;
876
877         /*
878          * Prints in Kernel / CIFS log the attempted mount operation
879          *      If CIFS_DEBUG && cifs_FYI
880          */
881         if (cifsFYI)
882                 cifs_dbg(FYI, "Devname: %s flags: %d\n", old_ctx->UNC, flags);
883         else
884                 cifs_info("Attempting to mount %s\n", old_ctx->UNC);
885
886         cifs_sb = kzalloc(sizeof(struct cifs_sb_info), GFP_KERNEL);
887         if (cifs_sb == NULL) {
888                 root = ERR_PTR(-ENOMEM);
889                 goto out;
890         }
891
892         cifs_sb->ctx = kzalloc(sizeof(struct smb3_fs_context), GFP_KERNEL);
893         if (!cifs_sb->ctx) {
894                 root = ERR_PTR(-ENOMEM);
895                 goto out;
896         }
897         rc = smb3_fs_context_dup(cifs_sb->ctx, old_ctx);
898         if (rc) {
899                 root = ERR_PTR(rc);
900                 goto out;
901         }
902
903         rc = cifs_setup_volume_info(cifs_sb->ctx, NULL, NULL);
904         if (rc) {
905                 root = ERR_PTR(rc);
906                 goto out;
907         }
908
909         rc = cifs_setup_cifs_sb(cifs_sb);
910         if (rc) {
911                 root = ERR_PTR(rc);
912                 goto out;
913         }
914
915         rc = cifs_mount(cifs_sb, cifs_sb->ctx);
916         if (rc) {
917                 if (!(flags & SB_SILENT))
918                         cifs_dbg(VFS, "cifs_mount failed w/return code = %d\n",
919                                  rc);
920                 root = ERR_PTR(rc);
921                 goto out;
922         }
923
924         mnt_data.ctx = cifs_sb->ctx;
925         mnt_data.cifs_sb = cifs_sb;
926         mnt_data.flags = flags;
927
928         /* BB should we make this contingent on mount parm? */
929         flags |= SB_NODIRATIME | SB_NOATIME;
930
931         sb = sget(fs_type, cifs_match_super, cifs_set_super, flags, &mnt_data);
932         if (IS_ERR(sb)) {
933                 root = ERR_CAST(sb);
934                 cifs_umount(cifs_sb);
935                 cifs_sb = NULL;
936                 goto out;
937         }
938
939         if (sb->s_root) {
940                 cifs_dbg(FYI, "Use existing superblock\n");
941                 cifs_umount(cifs_sb);
942                 cifs_sb = NULL;
943         } else {
944                 rc = cifs_read_super(sb);
945                 if (rc) {
946                         root = ERR_PTR(rc);
947                         goto out_super;
948                 }
949
950                 sb->s_flags |= SB_ACTIVE;
951         }
952
953         root = cifs_get_root(cifs_sb ? cifs_sb->ctx : old_ctx, sb);
954         if (IS_ERR(root))
955                 goto out_super;
956
957         if (cifs_sb)
958                 cifs_sb->root = dget(root);
959
960         cifs_dbg(FYI, "dentry root is: %p\n", root);
961         return root;
962
963 out_super:
964         deactivate_locked_super(sb);
965         return root;
966 out:
967         if (cifs_sb) {
968                 if (!sb || IS_ERR(sb)) {  /* otherwise kill_sb will handle */
969                         kfree(cifs_sb->prepath);
970                         smb3_cleanup_fs_context(cifs_sb->ctx);
971                         kfree(cifs_sb);
972                 }
973         }
974         return root;
975 }
976
977
978 static ssize_t
979 cifs_loose_read_iter(struct kiocb *iocb, struct iov_iter *iter)
980 {
981         ssize_t rc;
982         struct inode *inode = file_inode(iocb->ki_filp);
983
984         if (iocb->ki_flags & IOCB_DIRECT)
985                 return cifs_user_readv(iocb, iter);
986
987         rc = cifs_revalidate_mapping(inode);
988         if (rc)
989                 return rc;
990
991         return generic_file_read_iter(iocb, iter);
992 }
993
994 static ssize_t cifs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
995 {
996         struct inode *inode = file_inode(iocb->ki_filp);
997         struct cifsInodeInfo *cinode = CIFS_I(inode);
998         ssize_t written;
999         int rc;
1000
1001         if (iocb->ki_filp->f_flags & O_DIRECT) {
1002                 written = cifs_user_writev(iocb, from);
1003                 if (written > 0 && CIFS_CACHE_READ(cinode)) {
1004                         cifs_zap_mapping(inode);
1005                         cifs_dbg(FYI,
1006                                  "Set no oplock for inode=%p after a write operation\n",
1007                                  inode);
1008                         cinode->oplock = 0;
1009                 }
1010                 return written;
1011         }
1012
1013         written = cifs_get_writer(cinode);
1014         if (written)
1015                 return written;
1016
1017         written = generic_file_write_iter(iocb, from);
1018
1019         if (CIFS_CACHE_WRITE(CIFS_I(inode)))
1020                 goto out;
1021
1022         rc = filemap_fdatawrite(inode->i_mapping);
1023         if (rc)
1024                 cifs_dbg(FYI, "cifs_file_write_iter: %d rc on %p inode\n",
1025                          rc, inode);
1026
1027 out:
1028         cifs_put_writer(cinode);
1029         return written;
1030 }
1031
1032 static loff_t cifs_llseek(struct file *file, loff_t offset, int whence)
1033 {
1034         struct cifsFileInfo *cfile = file->private_data;
1035         struct cifs_tcon *tcon;
1036
1037         /*
1038          * whence == SEEK_END || SEEK_DATA || SEEK_HOLE => we must revalidate
1039          * the cached file length
1040          */
1041         if (whence != SEEK_SET && whence != SEEK_CUR) {
1042                 int rc;
1043                 struct inode *inode = file_inode(file);
1044
1045                 /*
1046                  * We need to be sure that all dirty pages are written and the
1047                  * server has the newest file length.
1048                  */
1049                 if (!CIFS_CACHE_READ(CIFS_I(inode)) && inode->i_mapping &&
1050                     inode->i_mapping->nrpages != 0) {
1051                         rc = filemap_fdatawait(inode->i_mapping);
1052                         if (rc) {
1053                                 mapping_set_error(inode->i_mapping, rc);
1054                                 return rc;
1055                         }
1056                 }
1057                 /*
1058                  * Some applications poll for the file length in this strange
1059                  * way so we must seek to end on non-oplocked files by
1060                  * setting the revalidate time to zero.
1061                  */
1062                 CIFS_I(inode)->time = 0;
1063
1064                 rc = cifs_revalidate_file_attr(file);
1065                 if (rc < 0)
1066                         return (loff_t)rc;
1067         }
1068         if (cfile && cfile->tlink) {
1069                 tcon = tlink_tcon(cfile->tlink);
1070                 if (tcon->ses->server->ops->llseek)
1071                         return tcon->ses->server->ops->llseek(file, tcon,
1072                                                               offset, whence);
1073         }
1074         return generic_file_llseek(file, offset, whence);
1075 }
1076
1077 static int
1078 cifs_setlease(struct file *file, long arg, struct file_lock **lease, void **priv)
1079 {
1080         /*
1081          * Note that this is called by vfs setlease with i_lock held to
1082          * protect *lease from going away.
1083          */
1084         struct inode *inode = file_inode(file);
1085         struct cifsFileInfo *cfile = file->private_data;
1086
1087         if (!(S_ISREG(inode->i_mode)))
1088                 return -EINVAL;
1089
1090         /* Check if file is oplocked if this is request for new lease */
1091         if (arg == F_UNLCK ||
1092             ((arg == F_RDLCK) && CIFS_CACHE_READ(CIFS_I(inode))) ||
1093             ((arg == F_WRLCK) && CIFS_CACHE_WRITE(CIFS_I(inode))))
1094                 return generic_setlease(file, arg, lease, priv);
1095         else if (tlink_tcon(cfile->tlink)->local_lease &&
1096                  !CIFS_CACHE_READ(CIFS_I(inode)))
1097                 /*
1098                  * If the server claims to support oplock on this file, then we
1099                  * still need to check oplock even if the local_lease mount
1100                  * option is set, but there are servers which do not support
1101                  * oplock for which this mount option may be useful if the user
1102                  * knows that the file won't be changed on the server by anyone
1103                  * else.
1104                  */
1105                 return generic_setlease(file, arg, lease, priv);
1106         else
1107                 return -EAGAIN;
1108 }
1109
1110 struct file_system_type cifs_fs_type = {
1111         .owner = THIS_MODULE,
1112         .name = "cifs",
1113         .init_fs_context = smb3_init_fs_context,
1114         .parameters = smb3_fs_parameters,
1115         .kill_sb = cifs_kill_sb,
1116         .fs_flags = FS_RENAME_DOES_D_MOVE,
1117 };
1118 MODULE_ALIAS_FS("cifs");
1119
1120 struct file_system_type smb3_fs_type = {
1121         .owner = THIS_MODULE,
1122         .name = "smb3",
1123         .init_fs_context = smb3_init_fs_context,
1124         .parameters = smb3_fs_parameters,
1125         .kill_sb = cifs_kill_sb,
1126         .fs_flags = FS_RENAME_DOES_D_MOVE,
1127 };
1128 MODULE_ALIAS_FS("smb3");
1129 MODULE_ALIAS("smb3");
1130
1131 const struct inode_operations cifs_dir_inode_ops = {
1132         .create = cifs_create,
1133         .atomic_open = cifs_atomic_open,
1134         .lookup = cifs_lookup,
1135         .getattr = cifs_getattr,
1136         .unlink = cifs_unlink,
1137         .link = cifs_hardlink,
1138         .mkdir = cifs_mkdir,
1139         .rmdir = cifs_rmdir,
1140         .rename = cifs_rename2,
1141         .permission = cifs_permission,
1142         .setattr = cifs_setattr,
1143         .symlink = cifs_symlink,
1144         .mknod   = cifs_mknod,
1145         .listxattr = cifs_listxattr,
1146 };
1147
1148 const struct inode_operations cifs_file_inode_ops = {
1149         .setattr = cifs_setattr,
1150         .getattr = cifs_getattr,
1151         .permission = cifs_permission,
1152         .listxattr = cifs_listxattr,
1153         .fiemap = cifs_fiemap,
1154 };
1155
1156 const struct inode_operations cifs_symlink_inode_ops = {
1157         .get_link = cifs_get_link,
1158         .permission = cifs_permission,
1159         .listxattr = cifs_listxattr,
1160 };
1161
1162 static loff_t cifs_remap_file_range(struct file *src_file, loff_t off,
1163                 struct file *dst_file, loff_t destoff, loff_t len,
1164                 unsigned int remap_flags)
1165 {
1166         struct inode *src_inode = file_inode(src_file);
1167         struct inode *target_inode = file_inode(dst_file);
1168         struct cifsFileInfo *smb_file_src = src_file->private_data;
1169         struct cifsFileInfo *smb_file_target;
1170         struct cifs_tcon *target_tcon;
1171         unsigned int xid;
1172         int rc;
1173
1174         if (remap_flags & ~(REMAP_FILE_DEDUP | REMAP_FILE_ADVISORY))
1175                 return -EINVAL;
1176
1177         cifs_dbg(FYI, "clone range\n");
1178
1179         xid = get_xid();
1180
1181         if (!src_file->private_data || !dst_file->private_data) {
1182                 rc = -EBADF;
1183                 cifs_dbg(VFS, "missing cifsFileInfo on copy range src file\n");
1184                 goto out;
1185         }
1186
1187         smb_file_target = dst_file->private_data;
1188         target_tcon = tlink_tcon(smb_file_target->tlink);
1189
1190         /*
1191          * Note: cifs case is easier than btrfs since server responsible for
1192          * checks for proper open modes and file type and if it wants
1193          * server could even support copy of range where source = target
1194          */
1195         lock_two_nondirectories(target_inode, src_inode);
1196
1197         if (len == 0)
1198                 len = src_inode->i_size - off;
1199
1200         cifs_dbg(FYI, "about to flush pages\n");
1201         /* should we flush first and last page first */
1202         truncate_inode_pages_range(&target_inode->i_data, destoff,
1203                                    PAGE_ALIGN(destoff + len)-1);
1204
1205         if (target_tcon->ses->server->ops->duplicate_extents)
1206                 rc = target_tcon->ses->server->ops->duplicate_extents(xid,
1207                         smb_file_src, smb_file_target, off, len, destoff);
1208         else
1209                 rc = -EOPNOTSUPP;
1210
1211         /* force revalidate of size and timestamps of target file now
1212            that target is updated on the server */
1213         CIFS_I(target_inode)->time = 0;
1214         /* although unlocking in the reverse order from locking is not
1215            strictly necessary here it is a little cleaner to be consistent */
1216         unlock_two_nondirectories(src_inode, target_inode);
1217 out:
1218         free_xid(xid);
1219         return rc < 0 ? rc : len;
1220 }
1221
1222 ssize_t cifs_file_copychunk_range(unsigned int xid,
1223                                 struct file *src_file, loff_t off,
1224                                 struct file *dst_file, loff_t destoff,
1225                                 size_t len, unsigned int flags)
1226 {
1227         struct inode *src_inode = file_inode(src_file);
1228         struct inode *target_inode = file_inode(dst_file);
1229         struct cifsFileInfo *smb_file_src;
1230         struct cifsFileInfo *smb_file_target;
1231         struct cifs_tcon *src_tcon;
1232         struct cifs_tcon *target_tcon;
1233         ssize_t rc;
1234
1235         cifs_dbg(FYI, "copychunk range\n");
1236
1237         if (!src_file->private_data || !dst_file->private_data) {
1238                 rc = -EBADF;
1239                 cifs_dbg(VFS, "missing cifsFileInfo on copy range src file\n");
1240                 goto out;
1241         }
1242
1243         rc = -EXDEV;
1244         smb_file_target = dst_file->private_data;
1245         smb_file_src = src_file->private_data;
1246         src_tcon = tlink_tcon(smb_file_src->tlink);
1247         target_tcon = tlink_tcon(smb_file_target->tlink);
1248
1249         if (src_tcon->ses != target_tcon->ses) {
1250                 cifs_dbg(VFS, "source and target of copy not on same server\n");
1251                 goto out;
1252         }
1253
1254         rc = -EOPNOTSUPP;
1255         if (!target_tcon->ses->server->ops->copychunk_range)
1256                 goto out;
1257
1258         /*
1259          * Note: cifs case is easier than btrfs since server responsible for
1260          * checks for proper open modes and file type and if it wants
1261          * server could even support copy of range where source = target
1262          */
1263         lock_two_nondirectories(target_inode, src_inode);
1264
1265         cifs_dbg(FYI, "about to flush pages\n");
1266         /* should we flush first and last page first */
1267         truncate_inode_pages(&target_inode->i_data, 0);
1268
1269         rc = file_modified(dst_file);
1270         if (!rc)
1271                 rc = target_tcon->ses->server->ops->copychunk_range(xid,
1272                         smb_file_src, smb_file_target, off, len, destoff);
1273
1274         file_accessed(src_file);
1275
1276         /* force revalidate of size and timestamps of target file now
1277          * that target is updated on the server
1278          */
1279         CIFS_I(target_inode)->time = 0;
1280         /* although unlocking in the reverse order from locking is not
1281          * strictly necessary here it is a little cleaner to be consistent
1282          */
1283         unlock_two_nondirectories(src_inode, target_inode);
1284
1285 out:
1286         return rc;
1287 }
1288
1289 /*
1290  * Directory operations under CIFS/SMB2/SMB3 are synchronous, so fsync()
1291  * is a dummy operation.
1292  */
1293 static int cifs_dir_fsync(struct file *file, loff_t start, loff_t end, int datasync)
1294 {
1295         cifs_dbg(FYI, "Sync directory - name: %pD datasync: 0x%x\n",
1296                  file, datasync);
1297
1298         return 0;
1299 }
1300
1301 static ssize_t cifs_copy_file_range(struct file *src_file, loff_t off,
1302                                 struct file *dst_file, loff_t destoff,
1303                                 size_t len, unsigned int flags)
1304 {
1305         unsigned int xid = get_xid();
1306         ssize_t rc;
1307         struct cifsFileInfo *cfile = dst_file->private_data;
1308
1309         if (cfile->swapfile)
1310                 return -EOPNOTSUPP;
1311
1312         rc = cifs_file_copychunk_range(xid, src_file, off, dst_file, destoff,
1313                                         len, flags);
1314         free_xid(xid);
1315
1316         if (rc == -EOPNOTSUPP || rc == -EXDEV)
1317                 rc = generic_copy_file_range(src_file, off, dst_file,
1318                                              destoff, len, flags);
1319         return rc;
1320 }
1321
1322 const struct file_operations cifs_file_ops = {
1323         .read_iter = cifs_loose_read_iter,
1324         .write_iter = cifs_file_write_iter,
1325         .open = cifs_open,
1326         .release = cifs_close,
1327         .lock = cifs_lock,
1328         .flock = cifs_flock,
1329         .fsync = cifs_fsync,
1330         .flush = cifs_flush,
1331         .mmap  = cifs_file_mmap,
1332         .splice_read = generic_file_splice_read,
1333         .splice_write = iter_file_splice_write,
1334         .llseek = cifs_llseek,
1335         .unlocked_ioctl = cifs_ioctl,
1336         .copy_file_range = cifs_copy_file_range,
1337         .remap_file_range = cifs_remap_file_range,
1338         .setlease = cifs_setlease,
1339         .fallocate = cifs_fallocate,
1340 };
1341
1342 const struct file_operations cifs_file_strict_ops = {
1343         .read_iter = cifs_strict_readv,
1344         .write_iter = cifs_strict_writev,
1345         .open = cifs_open,
1346         .release = cifs_close,
1347         .lock = cifs_lock,
1348         .flock = cifs_flock,
1349         .fsync = cifs_strict_fsync,
1350         .flush = cifs_flush,
1351         .mmap = cifs_file_strict_mmap,
1352         .splice_read = generic_file_splice_read,
1353         .splice_write = iter_file_splice_write,
1354         .llseek = cifs_llseek,
1355         .unlocked_ioctl = cifs_ioctl,
1356         .copy_file_range = cifs_copy_file_range,
1357         .remap_file_range = cifs_remap_file_range,
1358         .setlease = cifs_setlease,
1359         .fallocate = cifs_fallocate,
1360 };
1361
1362 const struct file_operations cifs_file_direct_ops = {
1363         .read_iter = cifs_direct_readv,
1364         .write_iter = cifs_direct_writev,
1365         .open = cifs_open,
1366         .release = cifs_close,
1367         .lock = cifs_lock,
1368         .flock = cifs_flock,
1369         .fsync = cifs_fsync,
1370         .flush = cifs_flush,
1371         .mmap = cifs_file_mmap,
1372         .splice_read = generic_file_splice_read,
1373         .splice_write = iter_file_splice_write,
1374         .unlocked_ioctl  = cifs_ioctl,
1375         .copy_file_range = cifs_copy_file_range,
1376         .remap_file_range = cifs_remap_file_range,
1377         .llseek = cifs_llseek,
1378         .setlease = cifs_setlease,
1379         .fallocate = cifs_fallocate,
1380 };
1381
1382 const struct file_operations cifs_file_nobrl_ops = {
1383         .read_iter = cifs_loose_read_iter,
1384         .write_iter = cifs_file_write_iter,
1385         .open = cifs_open,
1386         .release = cifs_close,
1387         .fsync = cifs_fsync,
1388         .flush = cifs_flush,
1389         .mmap  = cifs_file_mmap,
1390         .splice_read = generic_file_splice_read,
1391         .splice_write = iter_file_splice_write,
1392         .llseek = cifs_llseek,
1393         .unlocked_ioctl = cifs_ioctl,
1394         .copy_file_range = cifs_copy_file_range,
1395         .remap_file_range = cifs_remap_file_range,
1396         .setlease = cifs_setlease,
1397         .fallocate = cifs_fallocate,
1398 };
1399
1400 const struct file_operations cifs_file_strict_nobrl_ops = {
1401         .read_iter = cifs_strict_readv,
1402         .write_iter = cifs_strict_writev,
1403         .open = cifs_open,
1404         .release = cifs_close,
1405         .fsync = cifs_strict_fsync,
1406         .flush = cifs_flush,
1407         .mmap = cifs_file_strict_mmap,
1408         .splice_read = generic_file_splice_read,
1409         .splice_write = iter_file_splice_write,
1410         .llseek = cifs_llseek,
1411         .unlocked_ioctl = cifs_ioctl,
1412         .copy_file_range = cifs_copy_file_range,
1413         .remap_file_range = cifs_remap_file_range,
1414         .setlease = cifs_setlease,
1415         .fallocate = cifs_fallocate,
1416 };
1417
1418 const struct file_operations cifs_file_direct_nobrl_ops = {
1419         .read_iter = cifs_direct_readv,
1420         .write_iter = cifs_direct_writev,
1421         .open = cifs_open,
1422         .release = cifs_close,
1423         .fsync = cifs_fsync,
1424         .flush = cifs_flush,
1425         .mmap = cifs_file_mmap,
1426         .splice_read = generic_file_splice_read,
1427         .splice_write = iter_file_splice_write,
1428         .unlocked_ioctl  = cifs_ioctl,
1429         .copy_file_range = cifs_copy_file_range,
1430         .remap_file_range = cifs_remap_file_range,
1431         .llseek = cifs_llseek,
1432         .setlease = cifs_setlease,
1433         .fallocate = cifs_fallocate,
1434 };
1435
1436 const struct file_operations cifs_dir_ops = {
1437         .iterate_shared = cifs_readdir,
1438         .release = cifs_closedir,
1439         .read    = generic_read_dir,
1440         .unlocked_ioctl  = cifs_ioctl,
1441         .copy_file_range = cifs_copy_file_range,
1442         .remap_file_range = cifs_remap_file_range,
1443         .llseek = generic_file_llseek,
1444         .fsync = cifs_dir_fsync,
1445 };
1446
1447 static void
1448 cifs_init_once(void *inode)
1449 {
1450         struct cifsInodeInfo *cifsi = inode;
1451
1452         inode_init_once(&cifsi->netfs.inode);
1453         init_rwsem(&cifsi->lock_sem);
1454 }
1455
1456 static int __init
1457 cifs_init_inodecache(void)
1458 {
1459         cifs_inode_cachep = kmem_cache_create("cifs_inode_cache",
1460                                               sizeof(struct cifsInodeInfo),
1461                                               0, (SLAB_RECLAIM_ACCOUNT|
1462                                                 SLAB_MEM_SPREAD|SLAB_ACCOUNT),
1463                                               cifs_init_once);
1464         if (cifs_inode_cachep == NULL)
1465                 return -ENOMEM;
1466
1467         return 0;
1468 }
1469
1470 static void
1471 cifs_destroy_inodecache(void)
1472 {
1473         /*
1474          * Make sure all delayed rcu free inodes are flushed before we
1475          * destroy cache.
1476          */
1477         rcu_barrier();
1478         kmem_cache_destroy(cifs_inode_cachep);
1479 }
1480
1481 static int
1482 cifs_init_request_bufs(void)
1483 {
1484         /*
1485          * SMB2 maximum header size is bigger than CIFS one - no problems to
1486          * allocate some more bytes for CIFS.
1487          */
1488         size_t max_hdr_size = MAX_SMB2_HDR_SIZE;
1489
1490         if (CIFSMaxBufSize < 8192) {
1491         /* Buffer size can not be smaller than 2 * PATH_MAX since maximum
1492         Unicode path name has to fit in any SMB/CIFS path based frames */
1493                 CIFSMaxBufSize = 8192;
1494         } else if (CIFSMaxBufSize > 1024*127) {
1495                 CIFSMaxBufSize = 1024 * 127;
1496         } else {
1497                 CIFSMaxBufSize &= 0x1FE00; /* Round size to even 512 byte mult*/
1498         }
1499 /*
1500         cifs_dbg(VFS, "CIFSMaxBufSize %d 0x%x\n",
1501                  CIFSMaxBufSize, CIFSMaxBufSize);
1502 */
1503         cifs_req_cachep = kmem_cache_create_usercopy("cifs_request",
1504                                             CIFSMaxBufSize + max_hdr_size, 0,
1505                                             SLAB_HWCACHE_ALIGN, 0,
1506                                             CIFSMaxBufSize + max_hdr_size,
1507                                             NULL);
1508         if (cifs_req_cachep == NULL)
1509                 return -ENOMEM;
1510
1511         if (cifs_min_rcv < 1)
1512                 cifs_min_rcv = 1;
1513         else if (cifs_min_rcv > 64) {
1514                 cifs_min_rcv = 64;
1515                 cifs_dbg(VFS, "cifs_min_rcv set to maximum (64)\n");
1516         }
1517
1518         cifs_req_poolp = mempool_create_slab_pool(cifs_min_rcv,
1519                                                   cifs_req_cachep);
1520
1521         if (cifs_req_poolp == NULL) {
1522                 kmem_cache_destroy(cifs_req_cachep);
1523                 return -ENOMEM;
1524         }
1525         /* MAX_CIFS_SMALL_BUFFER_SIZE bytes is enough for most SMB responses and
1526         almost all handle based requests (but not write response, nor is it
1527         sufficient for path based requests).  A smaller size would have
1528         been more efficient (compacting multiple slab items on one 4k page)
1529         for the case in which debug was on, but this larger size allows
1530         more SMBs to use small buffer alloc and is still much more
1531         efficient to alloc 1 per page off the slab compared to 17K (5page)
1532         alloc of large cifs buffers even when page debugging is on */
1533         cifs_sm_req_cachep = kmem_cache_create_usercopy("cifs_small_rq",
1534                         MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
1535                         0, MAX_CIFS_SMALL_BUFFER_SIZE, NULL);
1536         if (cifs_sm_req_cachep == NULL) {
1537                 mempool_destroy(cifs_req_poolp);
1538                 kmem_cache_destroy(cifs_req_cachep);
1539                 return -ENOMEM;
1540         }
1541
1542         if (cifs_min_small < 2)
1543                 cifs_min_small = 2;
1544         else if (cifs_min_small > 256) {
1545                 cifs_min_small = 256;
1546                 cifs_dbg(FYI, "cifs_min_small set to maximum (256)\n");
1547         }
1548
1549         cifs_sm_req_poolp = mempool_create_slab_pool(cifs_min_small,
1550                                                      cifs_sm_req_cachep);
1551
1552         if (cifs_sm_req_poolp == NULL) {
1553                 mempool_destroy(cifs_req_poolp);
1554                 kmem_cache_destroy(cifs_req_cachep);
1555                 kmem_cache_destroy(cifs_sm_req_cachep);
1556                 return -ENOMEM;
1557         }
1558
1559         return 0;
1560 }
1561
1562 static void
1563 cifs_destroy_request_bufs(void)
1564 {
1565         mempool_destroy(cifs_req_poolp);
1566         kmem_cache_destroy(cifs_req_cachep);
1567         mempool_destroy(cifs_sm_req_poolp);
1568         kmem_cache_destroy(cifs_sm_req_cachep);
1569 }
1570
1571 static int init_mids(void)
1572 {
1573         cifs_mid_cachep = kmem_cache_create("cifs_mpx_ids",
1574                                             sizeof(struct mid_q_entry), 0,
1575                                             SLAB_HWCACHE_ALIGN, NULL);
1576         if (cifs_mid_cachep == NULL)
1577                 return -ENOMEM;
1578
1579         /* 3 is a reasonable minimum number of simultaneous operations */
1580         cifs_mid_poolp = mempool_create_slab_pool(3, cifs_mid_cachep);
1581         if (cifs_mid_poolp == NULL) {
1582                 kmem_cache_destroy(cifs_mid_cachep);
1583                 return -ENOMEM;
1584         }
1585
1586         return 0;
1587 }
1588
1589 static void destroy_mids(void)
1590 {
1591         mempool_destroy(cifs_mid_poolp);
1592         kmem_cache_destroy(cifs_mid_cachep);
1593 }
1594
1595 static int __init
1596 init_cifs(void)
1597 {
1598         int rc = 0;
1599         cifs_proc_init();
1600         INIT_LIST_HEAD(&cifs_tcp_ses_list);
1601 /*
1602  *  Initialize Global counters
1603  */
1604         atomic_set(&sesInfoAllocCount, 0);
1605         atomic_set(&tconInfoAllocCount, 0);
1606         atomic_set(&tcpSesNextId, 0);
1607         atomic_set(&tcpSesAllocCount, 0);
1608         atomic_set(&tcpSesReconnectCount, 0);
1609         atomic_set(&tconInfoReconnectCount, 0);
1610
1611         atomic_set(&buf_alloc_count, 0);
1612         atomic_set(&small_buf_alloc_count, 0);
1613 #ifdef CONFIG_CIFS_STATS2
1614         atomic_set(&total_buf_alloc_count, 0);
1615         atomic_set(&total_small_buf_alloc_count, 0);
1616         if (slow_rsp_threshold < 1)
1617                 cifs_dbg(FYI, "slow_response_threshold msgs disabled\n");
1618         else if (slow_rsp_threshold > 32767)
1619                 cifs_dbg(VFS,
1620                        "slow response threshold set higher than recommended (0 to 32767)\n");
1621 #endif /* CONFIG_CIFS_STATS2 */
1622
1623         atomic_set(&mid_count, 0);
1624         GlobalCurrentXid = 0;
1625         GlobalTotalActiveXid = 0;
1626         GlobalMaxActiveXid = 0;
1627         spin_lock_init(&cifs_tcp_ses_lock);
1628         spin_lock_init(&GlobalMid_Lock);
1629
1630         cifs_lock_secret = get_random_u32();
1631
1632         if (cifs_max_pending < 2) {
1633                 cifs_max_pending = 2;
1634                 cifs_dbg(FYI, "cifs_max_pending set to min of 2\n");
1635         } else if (cifs_max_pending > CIFS_MAX_REQ) {
1636                 cifs_max_pending = CIFS_MAX_REQ;
1637                 cifs_dbg(FYI, "cifs_max_pending set to max of %u\n",
1638                          CIFS_MAX_REQ);
1639         }
1640
1641         cifsiod_wq = alloc_workqueue("cifsiod", WQ_FREEZABLE|WQ_MEM_RECLAIM, 0);
1642         if (!cifsiod_wq) {
1643                 rc = -ENOMEM;
1644                 goto out_clean_proc;
1645         }
1646
1647         /*
1648          * Consider in future setting limit!=0 maybe to min(num_of_cores - 1, 3)
1649          * so that we don't launch too many worker threads but
1650          * Documentation/core-api/workqueue.rst recommends setting it to 0
1651          */
1652
1653         /* WQ_UNBOUND allows decrypt tasks to run on any CPU */
1654         decrypt_wq = alloc_workqueue("smb3decryptd",
1655                                      WQ_UNBOUND|WQ_FREEZABLE|WQ_MEM_RECLAIM, 0);
1656         if (!decrypt_wq) {
1657                 rc = -ENOMEM;
1658                 goto out_destroy_cifsiod_wq;
1659         }
1660
1661         fileinfo_put_wq = alloc_workqueue("cifsfileinfoput",
1662                                      WQ_UNBOUND|WQ_FREEZABLE|WQ_MEM_RECLAIM, 0);
1663         if (!fileinfo_put_wq) {
1664                 rc = -ENOMEM;
1665                 goto out_destroy_decrypt_wq;
1666         }
1667
1668         cifsoplockd_wq = alloc_workqueue("cifsoplockd",
1669                                          WQ_FREEZABLE|WQ_MEM_RECLAIM, 0);
1670         if (!cifsoplockd_wq) {
1671                 rc = -ENOMEM;
1672                 goto out_destroy_fileinfo_put_wq;
1673         }
1674
1675         deferredclose_wq = alloc_workqueue("deferredclose",
1676                                            WQ_FREEZABLE|WQ_MEM_RECLAIM, 0);
1677         if (!deferredclose_wq) {
1678                 rc = -ENOMEM;
1679                 goto out_destroy_cifsoplockd_wq;
1680         }
1681
1682         rc = cifs_init_inodecache();
1683         if (rc)
1684                 goto out_destroy_deferredclose_wq;
1685
1686         rc = init_mids();
1687         if (rc)
1688                 goto out_destroy_inodecache;
1689
1690         rc = cifs_init_request_bufs();
1691         if (rc)
1692                 goto out_destroy_mids;
1693
1694 #ifdef CONFIG_CIFS_DFS_UPCALL
1695         rc = dfs_cache_init();
1696         if (rc)
1697                 goto out_destroy_request_bufs;
1698 #endif /* CONFIG_CIFS_DFS_UPCALL */
1699 #ifdef CONFIG_CIFS_UPCALL
1700         rc = init_cifs_spnego();
1701         if (rc)
1702                 goto out_destroy_dfs_cache;
1703 #endif /* CONFIG_CIFS_UPCALL */
1704 #ifdef CONFIG_CIFS_SWN_UPCALL
1705         rc = cifs_genl_init();
1706         if (rc)
1707                 goto out_register_key_type;
1708 #endif /* CONFIG_CIFS_SWN_UPCALL */
1709
1710         rc = init_cifs_idmap();
1711         if (rc)
1712                 goto out_cifs_swn_init;
1713
1714         rc = register_filesystem(&cifs_fs_type);
1715         if (rc)
1716                 goto out_init_cifs_idmap;
1717
1718         rc = register_filesystem(&smb3_fs_type);
1719         if (rc) {
1720                 unregister_filesystem(&cifs_fs_type);
1721                 goto out_init_cifs_idmap;
1722         }
1723
1724         return 0;
1725
1726 out_init_cifs_idmap:
1727         exit_cifs_idmap();
1728 out_cifs_swn_init:
1729 #ifdef CONFIG_CIFS_SWN_UPCALL
1730         cifs_genl_exit();
1731 out_register_key_type:
1732 #endif
1733 #ifdef CONFIG_CIFS_UPCALL
1734         exit_cifs_spnego();
1735 out_destroy_dfs_cache:
1736 #endif
1737 #ifdef CONFIG_CIFS_DFS_UPCALL
1738         dfs_cache_destroy();
1739 out_destroy_request_bufs:
1740 #endif
1741         cifs_destroy_request_bufs();
1742 out_destroy_mids:
1743         destroy_mids();
1744 out_destroy_inodecache:
1745         cifs_destroy_inodecache();
1746 out_destroy_deferredclose_wq:
1747         destroy_workqueue(deferredclose_wq);
1748 out_destroy_cifsoplockd_wq:
1749         destroy_workqueue(cifsoplockd_wq);
1750 out_destroy_fileinfo_put_wq:
1751         destroy_workqueue(fileinfo_put_wq);
1752 out_destroy_decrypt_wq:
1753         destroy_workqueue(decrypt_wq);
1754 out_destroy_cifsiod_wq:
1755         destroy_workqueue(cifsiod_wq);
1756 out_clean_proc:
1757         cifs_proc_clean();
1758         return rc;
1759 }
1760
1761 static void __exit
1762 exit_cifs(void)
1763 {
1764         cifs_dbg(NOISY, "exit_smb3\n");
1765         unregister_filesystem(&cifs_fs_type);
1766         unregister_filesystem(&smb3_fs_type);
1767         cifs_dfs_release_automount_timer();
1768         exit_cifs_idmap();
1769 #ifdef CONFIG_CIFS_SWN_UPCALL
1770         cifs_genl_exit();
1771 #endif
1772 #ifdef CONFIG_CIFS_UPCALL
1773         exit_cifs_spnego();
1774 #endif
1775 #ifdef CONFIG_CIFS_DFS_UPCALL
1776         dfs_cache_destroy();
1777 #endif
1778         cifs_destroy_request_bufs();
1779         destroy_mids();
1780         cifs_destroy_inodecache();
1781         destroy_workqueue(deferredclose_wq);
1782         destroy_workqueue(cifsoplockd_wq);
1783         destroy_workqueue(decrypt_wq);
1784         destroy_workqueue(fileinfo_put_wq);
1785         destroy_workqueue(cifsiod_wq);
1786         cifs_proc_clean();
1787 }
1788
1789 MODULE_AUTHOR("Steve French");
1790 MODULE_LICENSE("GPL");  /* combination of LGPL + GPL source behaves as GPL */
1791 MODULE_DESCRIPTION
1792         ("VFS to access SMB3 servers e.g. Samba, Macs, Azure and Windows (and "
1793         "also older servers complying with the SNIA CIFS Specification)");
1794 MODULE_VERSION(CIFS_VERSION);
1795 MODULE_SOFTDEP("ecb");
1796 MODULE_SOFTDEP("hmac");
1797 MODULE_SOFTDEP("md5");
1798 MODULE_SOFTDEP("nls");
1799 MODULE_SOFTDEP("aes");
1800 MODULE_SOFTDEP("cmac");
1801 MODULE_SOFTDEP("sha256");
1802 MODULE_SOFTDEP("sha512");
1803 MODULE_SOFTDEP("aead2");
1804 MODULE_SOFTDEP("ccm");
1805 MODULE_SOFTDEP("gcm");
1806 module_init(init_cifs)
1807 module_exit(exit_cifs)