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