]>
Commit | Line | Data |
---|---|---|
1080ef75 SF |
1 | /* |
2 | * SMB2 version specific operations | |
3 | * | |
4 | * Copyright (c) 2012, Jeff Layton <jlayton@redhat.com> | |
5 | * | |
6 | * This library is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License v2 as published | |
8 | * by the Free Software Foundation. | |
9 | * | |
10 | * This library is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See | |
13 | * the GNU Lesser General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU Lesser General Public License | |
16 | * along with this library; if not, write to the Free Software | |
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | */ | |
19 | ||
3a3bab50 | 20 | #include <linux/pagemap.h> |
6fc05c25 | 21 | #include <linux/vfs.h> |
f29ebb47 | 22 | #include <linux/falloc.h> |
1080ef75 | 23 | #include "cifsglob.h" |
2dc7e1c0 PS |
24 | #include "smb2pdu.h" |
25 | #include "smb2proto.h" | |
28ea5290 PS |
26 | #include "cifsproto.h" |
27 | #include "cifs_debug.h" | |
b42bf888 | 28 | #include "cifs_unicode.h" |
2e44b288 | 29 | #include "smb2status.h" |
6fc05c25 | 30 | #include "smb2glob.h" |
834170c8 | 31 | #include "cifs_ioctl.h" |
28ea5290 PS |
32 | |
33 | static int | |
34 | change_conf(struct TCP_Server_Info *server) | |
35 | { | |
36 | server->credits += server->echo_credits + server->oplock_credits; | |
37 | server->oplock_credits = server->echo_credits = 0; | |
38 | switch (server->credits) { | |
39 | case 0: | |
40 | return -1; | |
41 | case 1: | |
42 | server->echoes = false; | |
43 | server->oplocks = false; | |
f96637be | 44 | cifs_dbg(VFS, "disabling echoes and oplocks\n"); |
28ea5290 PS |
45 | break; |
46 | case 2: | |
47 | server->echoes = true; | |
48 | server->oplocks = false; | |
49 | server->echo_credits = 1; | |
f96637be | 50 | cifs_dbg(FYI, "disabling oplocks\n"); |
28ea5290 PS |
51 | break; |
52 | default: | |
53 | server->echoes = true; | |
e0ddde9d SF |
54 | if (enable_oplocks) { |
55 | server->oplocks = true; | |
56 | server->oplock_credits = 1; | |
57 | } else | |
58 | server->oplocks = false; | |
59 | ||
28ea5290 | 60 | server->echo_credits = 1; |
28ea5290 PS |
61 | } |
62 | server->credits -= server->echo_credits + server->oplock_credits; | |
63 | return 0; | |
64 | } | |
65 | ||
66 | static void | |
67 | smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add, | |
68 | const int optype) | |
69 | { | |
70 | int *val, rc = 0; | |
71 | spin_lock(&server->req_lock); | |
72 | val = server->ops->get_credits_field(server, optype); | |
73 | *val += add; | |
141891f4 SF |
74 | if (*val > 65000) { |
75 | *val = 65000; /* Don't get near 64K credits, avoid srv bugs */ | |
76 | printk_once(KERN_WARNING "server overflowed SMB3 credits\n"); | |
77 | } | |
28ea5290 | 78 | server->in_flight--; |
ec2e4523 | 79 | if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP) |
28ea5290 | 80 | rc = change_conf(server); |
983c88a4 PS |
81 | /* |
82 | * Sometimes server returns 0 credits on oplock break ack - we need to | |
83 | * rebalance credits in this case. | |
84 | */ | |
85 | else if (server->in_flight > 0 && server->oplock_credits == 0 && | |
86 | server->oplocks) { | |
87 | if (server->credits > 1) { | |
88 | server->credits--; | |
89 | server->oplock_credits++; | |
90 | } | |
91 | } | |
28ea5290 PS |
92 | spin_unlock(&server->req_lock); |
93 | wake_up(&server->request_q); | |
94 | if (rc) | |
95 | cifs_reconnect(server); | |
96 | } | |
97 | ||
98 | static void | |
99 | smb2_set_credits(struct TCP_Server_Info *server, const int val) | |
100 | { | |
101 | spin_lock(&server->req_lock); | |
102 | server->credits = val; | |
103 | spin_unlock(&server->req_lock); | |
104 | } | |
105 | ||
106 | static int * | |
107 | smb2_get_credits_field(struct TCP_Server_Info *server, const int optype) | |
108 | { | |
109 | switch (optype) { | |
110 | case CIFS_ECHO_OP: | |
111 | return &server->echo_credits; | |
112 | case CIFS_OBREAK_OP: | |
113 | return &server->oplock_credits; | |
114 | default: | |
115 | return &server->credits; | |
116 | } | |
117 | } | |
118 | ||
119 | static unsigned int | |
120 | smb2_get_credits(struct mid_q_entry *mid) | |
121 | { | |
b6932a6a PS |
122 | struct smb2_sync_hdr *shdr = get_sync_hdr(mid->resp_buf); |
123 | ||
124 | return le16_to_cpu(shdr->CreditRequest); | |
28ea5290 | 125 | } |
2dc7e1c0 | 126 | |
cb7e9eab PS |
127 | static int |
128 | smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size, | |
129 | unsigned int *num, unsigned int *credits) | |
130 | { | |
131 | int rc = 0; | |
132 | unsigned int scredits; | |
133 | ||
134 | spin_lock(&server->req_lock); | |
135 | while (1) { | |
136 | if (server->credits <= 0) { | |
137 | spin_unlock(&server->req_lock); | |
138 | cifs_num_waiters_inc(server); | |
139 | rc = wait_event_killable(server->request_q, | |
140 | has_credits(server, &server->credits)); | |
141 | cifs_num_waiters_dec(server); | |
142 | if (rc) | |
143 | return rc; | |
144 | spin_lock(&server->req_lock); | |
145 | } else { | |
146 | if (server->tcpStatus == CifsExiting) { | |
147 | spin_unlock(&server->req_lock); | |
148 | return -ENOENT; | |
149 | } | |
150 | ||
151 | scredits = server->credits; | |
152 | /* can deadlock with reopen */ | |
153 | if (scredits == 1) { | |
154 | *num = SMB2_MAX_BUFFER_SIZE; | |
155 | *credits = 0; | |
156 | break; | |
157 | } | |
158 | ||
159 | /* leave one credit for a possible reopen */ | |
160 | scredits--; | |
161 | *num = min_t(unsigned int, size, | |
162 | scredits * SMB2_MAX_BUFFER_SIZE); | |
163 | ||
164 | *credits = DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE); | |
165 | server->credits -= *credits; | |
166 | server->in_flight++; | |
167 | break; | |
168 | } | |
169 | } | |
170 | spin_unlock(&server->req_lock); | |
171 | return rc; | |
172 | } | |
173 | ||
2dc7e1c0 PS |
174 | static __u64 |
175 | smb2_get_next_mid(struct TCP_Server_Info *server) | |
176 | { | |
177 | __u64 mid; | |
178 | /* for SMB2 we need the current value */ | |
179 | spin_lock(&GlobalMid_Lock); | |
180 | mid = server->CurrentMid++; | |
181 | spin_unlock(&GlobalMid_Lock); | |
182 | return mid; | |
183 | } | |
1080ef75 | 184 | |
093b2bda PS |
185 | static struct mid_q_entry * |
186 | smb2_find_mid(struct TCP_Server_Info *server, char *buf) | |
187 | { | |
188 | struct mid_q_entry *mid; | |
b6932a6a PS |
189 | struct smb2_sync_hdr *shdr = get_sync_hdr(buf); |
190 | __u64 wire_mid = le64_to_cpu(shdr->MessageId); | |
093b2bda | 191 | |
b6932a6a | 192 | if (shdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) { |
373512ec SF |
193 | cifs_dbg(VFS, "encrypted frame parsing not supported yet"); |
194 | return NULL; | |
195 | } | |
196 | ||
093b2bda PS |
197 | spin_lock(&GlobalMid_Lock); |
198 | list_for_each_entry(mid, &server->pending_mid_q, qhead) { | |
9235d098 | 199 | if ((mid->mid == wire_mid) && |
093b2bda | 200 | (mid->mid_state == MID_REQUEST_SUBMITTED) && |
b6932a6a | 201 | (mid->command == shdr->Command)) { |
093b2bda PS |
202 | spin_unlock(&GlobalMid_Lock); |
203 | return mid; | |
204 | } | |
205 | } | |
206 | spin_unlock(&GlobalMid_Lock); | |
207 | return NULL; | |
208 | } | |
209 | ||
210 | static void | |
211 | smb2_dump_detail(void *buf) | |
212 | { | |
213 | #ifdef CONFIG_CIFS_DEBUG2 | |
b6932a6a | 214 | struct smb2_sync_hdr *shdr = get_sync_hdr(buf); |
093b2bda | 215 | |
f96637be | 216 | cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n", |
b6932a6a PS |
217 | shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId, |
218 | shdr->ProcessId); | |
219 | cifs_dbg(VFS, "smb buf %p len %u\n", buf, smb2_calc_size(buf)); | |
093b2bda PS |
220 | #endif |
221 | } | |
222 | ||
ec2e4523 PS |
223 | static bool |
224 | smb2_need_neg(struct TCP_Server_Info *server) | |
225 | { | |
226 | return server->max_read == 0; | |
227 | } | |
228 | ||
229 | static int | |
230 | smb2_negotiate(const unsigned int xid, struct cifs_ses *ses) | |
231 | { | |
232 | int rc; | |
233 | ses->server->CurrentMid = 0; | |
234 | rc = SMB2_negotiate(xid, ses); | |
235 | /* BB we probably don't need to retry with modern servers */ | |
236 | if (rc == -EAGAIN) | |
237 | rc = -EHOSTDOWN; | |
238 | return rc; | |
239 | } | |
240 | ||
3a3bab50 PS |
241 | static unsigned int |
242 | smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) | |
243 | { | |
244 | struct TCP_Server_Info *server = tcon->ses->server; | |
245 | unsigned int wsize; | |
246 | ||
247 | /* start with specified wsize, or default */ | |
248 | wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE; | |
249 | wsize = min_t(unsigned int, wsize, server->max_write); | |
cb7e9eab PS |
250 | |
251 | if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU)) | |
252 | wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE); | |
3a3bab50 | 253 | |
3a3bab50 PS |
254 | return wsize; |
255 | } | |
256 | ||
257 | static unsigned int | |
258 | smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) | |
259 | { | |
260 | struct TCP_Server_Info *server = tcon->ses->server; | |
261 | unsigned int rsize; | |
262 | ||
263 | /* start with specified rsize, or default */ | |
264 | rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE; | |
265 | rsize = min_t(unsigned int, rsize, server->max_read); | |
bed9da02 PS |
266 | |
267 | if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU)) | |
268 | rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE); | |
3a3bab50 | 269 | |
3a3bab50 PS |
270 | return rsize; |
271 | } | |
272 | ||
c481e9fe SF |
273 | #ifdef CONFIG_CIFS_STATS2 |
274 | static int | |
275 | SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon) | |
276 | { | |
277 | int rc; | |
278 | unsigned int ret_data_len = 0; | |
279 | struct network_interface_info_ioctl_rsp *out_buf; | |
280 | ||
281 | rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID, | |
282 | FSCTL_QUERY_NETWORK_INTERFACE_INFO, true /* is_fsctl */, | |
283 | NULL /* no data input */, 0 /* no data input */, | |
284 | (char **)&out_buf, &ret_data_len); | |
9ffc5412 SF |
285 | if (rc != 0) |
286 | cifs_dbg(VFS, "error %d on ioctl to get interface list\n", rc); | |
287 | else if (ret_data_len < sizeof(struct network_interface_info_ioctl_rsp)) { | |
288 | cifs_dbg(VFS, "server returned bad net interface info buf\n"); | |
289 | rc = -EINVAL; | |
290 | } else { | |
c481e9fe SF |
291 | /* Dump info on first interface */ |
292 | cifs_dbg(FYI, "Adapter Capability 0x%x\t", | |
293 | le32_to_cpu(out_buf->Capability)); | |
294 | cifs_dbg(FYI, "Link Speed %lld\n", | |
295 | le64_to_cpu(out_buf->LinkSpeed)); | |
9ffc5412 | 296 | } |
24df1483 | 297 | kfree(out_buf); |
c481e9fe SF |
298 | return rc; |
299 | } | |
300 | #endif /* STATS2 */ | |
301 | ||
af6a12ea SF |
302 | static void |
303 | smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon) | |
304 | { | |
305 | int rc; | |
306 | __le16 srch_path = 0; /* Null - open root of share */ | |
307 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; | |
308 | struct cifs_open_parms oparms; | |
309 | struct cifs_fid fid; | |
310 | ||
311 | oparms.tcon = tcon; | |
312 | oparms.desired_access = FILE_READ_ATTRIBUTES; | |
313 | oparms.disposition = FILE_OPEN; | |
314 | oparms.create_options = 0; | |
315 | oparms.fid = &fid; | |
316 | oparms.reconnect = false; | |
317 | ||
318 | rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL); | |
319 | if (rc) | |
320 | return; | |
321 | ||
c481e9fe SF |
322 | #ifdef CONFIG_CIFS_STATS2 |
323 | SMB3_request_interfaces(xid, tcon); | |
324 | #endif /* STATS2 */ | |
325 | ||
af6a12ea SF |
326 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
327 | FS_ATTRIBUTE_INFORMATION); | |
328 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, | |
329 | FS_DEVICE_INFORMATION); | |
330 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, | |
331 | FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */ | |
332 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); | |
333 | return; | |
334 | } | |
335 | ||
34f62640 SF |
336 | static void |
337 | smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon) | |
338 | { | |
339 | int rc; | |
340 | __le16 srch_path = 0; /* Null - open root of share */ | |
341 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; | |
342 | struct cifs_open_parms oparms; | |
343 | struct cifs_fid fid; | |
344 | ||
345 | oparms.tcon = tcon; | |
346 | oparms.desired_access = FILE_READ_ATTRIBUTES; | |
347 | oparms.disposition = FILE_OPEN; | |
348 | oparms.create_options = 0; | |
349 | oparms.fid = &fid; | |
350 | oparms.reconnect = false; | |
351 | ||
352 | rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL); | |
353 | if (rc) | |
354 | return; | |
355 | ||
2167114c SF |
356 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
357 | FS_ATTRIBUTE_INFORMATION); | |
358 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, | |
359 | FS_DEVICE_INFORMATION); | |
34f62640 SF |
360 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
361 | return; | |
362 | } | |
363 | ||
2503a0db PS |
364 | static int |
365 | smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon, | |
366 | struct cifs_sb_info *cifs_sb, const char *full_path) | |
367 | { | |
368 | int rc; | |
2503a0db | 369 | __le16 *utf16_path; |
2e44b288 | 370 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
064f6047 PS |
371 | struct cifs_open_parms oparms; |
372 | struct cifs_fid fid; | |
2503a0db PS |
373 | |
374 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); | |
375 | if (!utf16_path) | |
376 | return -ENOMEM; | |
377 | ||
064f6047 PS |
378 | oparms.tcon = tcon; |
379 | oparms.desired_access = FILE_READ_ATTRIBUTES; | |
380 | oparms.disposition = FILE_OPEN; | |
381 | oparms.create_options = 0; | |
382 | oparms.fid = &fid; | |
9cbc0b73 | 383 | oparms.reconnect = false; |
064f6047 | 384 | |
b42bf888 | 385 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL); |
2503a0db PS |
386 | if (rc) { |
387 | kfree(utf16_path); | |
388 | return rc; | |
389 | } | |
390 | ||
064f6047 | 391 | rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
2503a0db PS |
392 | kfree(utf16_path); |
393 | return rc; | |
394 | } | |
395 | ||
be4cb9e3 PS |
396 | static int |
397 | smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon, | |
398 | struct cifs_sb_info *cifs_sb, const char *full_path, | |
399 | u64 *uniqueid, FILE_ALL_INFO *data) | |
400 | { | |
401 | *uniqueid = le64_to_cpu(data->IndexNumber); | |
402 | return 0; | |
403 | } | |
404 | ||
b7546bc5 PS |
405 | static int |
406 | smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon, | |
407 | struct cifs_fid *fid, FILE_ALL_INFO *data) | |
408 | { | |
409 | int rc; | |
410 | struct smb2_file_all_info *smb2_data; | |
411 | ||
1bbe4997 | 412 | smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2, |
b7546bc5 PS |
413 | GFP_KERNEL); |
414 | if (smb2_data == NULL) | |
415 | return -ENOMEM; | |
416 | ||
417 | rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid, | |
418 | smb2_data); | |
419 | if (!rc) | |
420 | move_smb2_info_to_cifs(data, smb2_data); | |
421 | kfree(smb2_data); | |
422 | return rc; | |
423 | } | |
424 | ||
9094fad1 PS |
425 | static bool |
426 | smb2_can_echo(struct TCP_Server_Info *server) | |
427 | { | |
428 | return server->echoes; | |
429 | } | |
430 | ||
d60622eb PS |
431 | static void |
432 | smb2_clear_stats(struct cifs_tcon *tcon) | |
433 | { | |
434 | #ifdef CONFIG_CIFS_STATS | |
435 | int i; | |
436 | for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) { | |
437 | atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0); | |
438 | atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0); | |
439 | } | |
440 | #endif | |
441 | } | |
442 | ||
769ee6a4 SF |
443 | static void |
444 | smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon) | |
445 | { | |
446 | seq_puts(m, "\n\tShare Capabilities:"); | |
447 | if (tcon->capabilities & SMB2_SHARE_CAP_DFS) | |
448 | seq_puts(m, " DFS,"); | |
449 | if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY) | |
450 | seq_puts(m, " CONTINUOUS AVAILABILITY,"); | |
451 | if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT) | |
452 | seq_puts(m, " SCALEOUT,"); | |
453 | if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER) | |
454 | seq_puts(m, " CLUSTER,"); | |
455 | if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC) | |
456 | seq_puts(m, " ASYMMETRIC,"); | |
457 | if (tcon->capabilities == 0) | |
458 | seq_puts(m, " None"); | |
af6a12ea SF |
459 | if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE) |
460 | seq_puts(m, " Aligned,"); | |
461 | if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE) | |
462 | seq_puts(m, " Partition Aligned,"); | |
463 | if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY) | |
464 | seq_puts(m, " SSD,"); | |
465 | if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED) | |
466 | seq_puts(m, " TRIM-support,"); | |
467 | ||
769ee6a4 | 468 | seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags); |
af6a12ea SF |
469 | if (tcon->perf_sector_size) |
470 | seq_printf(m, "\tOptimal sector size: 0x%x", | |
471 | tcon->perf_sector_size); | |
769ee6a4 SF |
472 | } |
473 | ||
d60622eb PS |
474 | static void |
475 | smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon) | |
476 | { | |
477 | #ifdef CONFIG_CIFS_STATS | |
478 | atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent; | |
479 | atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed; | |
480 | seq_printf(m, "\nNegotiates: %d sent %d failed", | |
481 | atomic_read(&sent[SMB2_NEGOTIATE_HE]), | |
482 | atomic_read(&failed[SMB2_NEGOTIATE_HE])); | |
483 | seq_printf(m, "\nSessionSetups: %d sent %d failed", | |
484 | atomic_read(&sent[SMB2_SESSION_SETUP_HE]), | |
485 | atomic_read(&failed[SMB2_SESSION_SETUP_HE])); | |
d60622eb PS |
486 | seq_printf(m, "\nLogoffs: %d sent %d failed", |
487 | atomic_read(&sent[SMB2_LOGOFF_HE]), | |
488 | atomic_read(&failed[SMB2_LOGOFF_HE])); | |
489 | seq_printf(m, "\nTreeConnects: %d sent %d failed", | |
490 | atomic_read(&sent[SMB2_TREE_CONNECT_HE]), | |
491 | atomic_read(&failed[SMB2_TREE_CONNECT_HE])); | |
492 | seq_printf(m, "\nTreeDisconnects: %d sent %d failed", | |
493 | atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]), | |
494 | atomic_read(&failed[SMB2_TREE_DISCONNECT_HE])); | |
495 | seq_printf(m, "\nCreates: %d sent %d failed", | |
496 | atomic_read(&sent[SMB2_CREATE_HE]), | |
497 | atomic_read(&failed[SMB2_CREATE_HE])); | |
498 | seq_printf(m, "\nCloses: %d sent %d failed", | |
499 | atomic_read(&sent[SMB2_CLOSE_HE]), | |
500 | atomic_read(&failed[SMB2_CLOSE_HE])); | |
501 | seq_printf(m, "\nFlushes: %d sent %d failed", | |
502 | atomic_read(&sent[SMB2_FLUSH_HE]), | |
503 | atomic_read(&failed[SMB2_FLUSH_HE])); | |
504 | seq_printf(m, "\nReads: %d sent %d failed", | |
505 | atomic_read(&sent[SMB2_READ_HE]), | |
506 | atomic_read(&failed[SMB2_READ_HE])); | |
507 | seq_printf(m, "\nWrites: %d sent %d failed", | |
508 | atomic_read(&sent[SMB2_WRITE_HE]), | |
509 | atomic_read(&failed[SMB2_WRITE_HE])); | |
510 | seq_printf(m, "\nLocks: %d sent %d failed", | |
511 | atomic_read(&sent[SMB2_LOCK_HE]), | |
512 | atomic_read(&failed[SMB2_LOCK_HE])); | |
513 | seq_printf(m, "\nIOCTLs: %d sent %d failed", | |
514 | atomic_read(&sent[SMB2_IOCTL_HE]), | |
515 | atomic_read(&failed[SMB2_IOCTL_HE])); | |
516 | seq_printf(m, "\nCancels: %d sent %d failed", | |
517 | atomic_read(&sent[SMB2_CANCEL_HE]), | |
518 | atomic_read(&failed[SMB2_CANCEL_HE])); | |
519 | seq_printf(m, "\nEchos: %d sent %d failed", | |
520 | atomic_read(&sent[SMB2_ECHO_HE]), | |
521 | atomic_read(&failed[SMB2_ECHO_HE])); | |
522 | seq_printf(m, "\nQueryDirectories: %d sent %d failed", | |
523 | atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]), | |
524 | atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE])); | |
525 | seq_printf(m, "\nChangeNotifies: %d sent %d failed", | |
526 | atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]), | |
527 | atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE])); | |
528 | seq_printf(m, "\nQueryInfos: %d sent %d failed", | |
529 | atomic_read(&sent[SMB2_QUERY_INFO_HE]), | |
530 | atomic_read(&failed[SMB2_QUERY_INFO_HE])); | |
531 | seq_printf(m, "\nSetInfos: %d sent %d failed", | |
532 | atomic_read(&sent[SMB2_SET_INFO_HE]), | |
533 | atomic_read(&failed[SMB2_SET_INFO_HE])); | |
534 | seq_printf(m, "\nOplockBreaks: %d sent %d failed", | |
535 | atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]), | |
536 | atomic_read(&failed[SMB2_OPLOCK_BREAK_HE])); | |
537 | #endif | |
538 | } | |
539 | ||
f0df737e PS |
540 | static void |
541 | smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock) | |
542 | { | |
2b0143b5 | 543 | struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry)); |
53ef1016 PS |
544 | struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; |
545 | ||
f0df737e PS |
546 | cfile->fid.persistent_fid = fid->persistent_fid; |
547 | cfile->fid.volatile_fid = fid->volatile_fid; | |
42873b0a PS |
548 | server->ops->set_oplock_level(cinode, oplock, fid->epoch, |
549 | &fid->purge_cache); | |
18cceb6a | 550 | cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode); |
94f87371 | 551 | memcpy(cfile->fid.create_guid, fid->create_guid, 16); |
f0df737e PS |
552 | } |
553 | ||
760ad0ca | 554 | static void |
f0df737e PS |
555 | smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon, |
556 | struct cifs_fid *fid) | |
557 | { | |
760ad0ca | 558 | SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
f0df737e PS |
559 | } |
560 | ||
41c1358e SF |
561 | static int |
562 | SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon, | |
563 | u64 persistent_fid, u64 volatile_fid, | |
564 | struct copychunk_ioctl *pcchunk) | |
565 | { | |
566 | int rc; | |
567 | unsigned int ret_data_len; | |
568 | struct resume_key_req *res_key; | |
569 | ||
570 | rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid, | |
571 | FSCTL_SRV_REQUEST_RESUME_KEY, true /* is_fsctl */, | |
572 | NULL, 0 /* no input */, | |
573 | (char **)&res_key, &ret_data_len); | |
574 | ||
575 | if (rc) { | |
576 | cifs_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc); | |
577 | goto req_res_key_exit; | |
578 | } | |
579 | if (ret_data_len < sizeof(struct resume_key_req)) { | |
580 | cifs_dbg(VFS, "Invalid refcopy resume key length\n"); | |
581 | rc = -EINVAL; | |
582 | goto req_res_key_exit; | |
583 | } | |
584 | memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE); | |
585 | ||
586 | req_res_key_exit: | |
587 | kfree(res_key); | |
588 | return rc; | |
589 | } | |
590 | ||
591 | static int | |
592 | smb2_clone_range(const unsigned int xid, | |
593 | struct cifsFileInfo *srcfile, | |
594 | struct cifsFileInfo *trgtfile, u64 src_off, | |
595 | u64 len, u64 dest_off) | |
596 | { | |
597 | int rc; | |
598 | unsigned int ret_data_len; | |
599 | struct copychunk_ioctl *pcchunk; | |
9bf0c9cd SF |
600 | struct copychunk_ioctl_rsp *retbuf = NULL; |
601 | struct cifs_tcon *tcon; | |
602 | int chunks_copied = 0; | |
603 | bool chunk_sizes_updated = false; | |
41c1358e SF |
604 | |
605 | pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL); | |
606 | ||
607 | if (pcchunk == NULL) | |
608 | return -ENOMEM; | |
609 | ||
610 | cifs_dbg(FYI, "in smb2_clone_range - about to call request res key\n"); | |
611 | /* Request a key from the server to identify the source of the copy */ | |
612 | rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink), | |
613 | srcfile->fid.persistent_fid, | |
614 | srcfile->fid.volatile_fid, pcchunk); | |
615 | ||
616 | /* Note: request_res_key sets res_key null only if rc !=0 */ | |
617 | if (rc) | |
9bf0c9cd | 618 | goto cchunk_out; |
41c1358e SF |
619 | |
620 | /* For now array only one chunk long, will make more flexible later */ | |
bc09d141 | 621 | pcchunk->ChunkCount = cpu_to_le32(1); |
41c1358e | 622 | pcchunk->Reserved = 0; |
41c1358e SF |
623 | pcchunk->Reserved2 = 0; |
624 | ||
9bf0c9cd | 625 | tcon = tlink_tcon(trgtfile->tlink); |
41c1358e | 626 | |
9bf0c9cd SF |
627 | while (len > 0) { |
628 | pcchunk->SourceOffset = cpu_to_le64(src_off); | |
629 | pcchunk->TargetOffset = cpu_to_le64(dest_off); | |
630 | pcchunk->Length = | |
631 | cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk)); | |
41c1358e | 632 | |
9bf0c9cd SF |
633 | /* Request server copy to target from src identified by key */ |
634 | rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid, | |
635 | trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE, | |
636 | true /* is_fsctl */, (char *)pcchunk, | |
637 | sizeof(struct copychunk_ioctl), (char **)&retbuf, | |
638 | &ret_data_len); | |
639 | if (rc == 0) { | |
640 | if (ret_data_len != | |
641 | sizeof(struct copychunk_ioctl_rsp)) { | |
642 | cifs_dbg(VFS, "invalid cchunk response size\n"); | |
643 | rc = -EIO; | |
644 | goto cchunk_out; | |
645 | } | |
646 | if (retbuf->TotalBytesWritten == 0) { | |
647 | cifs_dbg(FYI, "no bytes copied\n"); | |
648 | rc = -EIO; | |
649 | goto cchunk_out; | |
650 | } | |
651 | /* | |
652 | * Check if server claimed to write more than we asked | |
653 | */ | |
654 | if (le32_to_cpu(retbuf->TotalBytesWritten) > | |
655 | le32_to_cpu(pcchunk->Length)) { | |
656 | cifs_dbg(VFS, "invalid copy chunk response\n"); | |
657 | rc = -EIO; | |
658 | goto cchunk_out; | |
659 | } | |
660 | if (le32_to_cpu(retbuf->ChunksWritten) != 1) { | |
661 | cifs_dbg(VFS, "invalid num chunks written\n"); | |
662 | rc = -EIO; | |
663 | goto cchunk_out; | |
664 | } | |
665 | chunks_copied++; | |
666 | ||
667 | src_off += le32_to_cpu(retbuf->TotalBytesWritten); | |
668 | dest_off += le32_to_cpu(retbuf->TotalBytesWritten); | |
669 | len -= le32_to_cpu(retbuf->TotalBytesWritten); | |
670 | ||
671 | cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %d\n", | |
672 | le32_to_cpu(retbuf->ChunksWritten), | |
673 | le32_to_cpu(retbuf->ChunkBytesWritten), | |
674 | le32_to_cpu(retbuf->TotalBytesWritten)); | |
675 | } else if (rc == -EINVAL) { | |
676 | if (ret_data_len != sizeof(struct copychunk_ioctl_rsp)) | |
677 | goto cchunk_out; | |
678 | ||
679 | cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n", | |
680 | le32_to_cpu(retbuf->ChunksWritten), | |
681 | le32_to_cpu(retbuf->ChunkBytesWritten), | |
682 | le32_to_cpu(retbuf->TotalBytesWritten)); | |
683 | ||
684 | /* | |
685 | * Check if this is the first request using these sizes, | |
686 | * (ie check if copy succeed once with original sizes | |
687 | * and check if the server gave us different sizes after | |
688 | * we already updated max sizes on previous request). | |
689 | * if not then why is the server returning an error now | |
690 | */ | |
691 | if ((chunks_copied != 0) || chunk_sizes_updated) | |
692 | goto cchunk_out; | |
693 | ||
694 | /* Check that server is not asking us to grow size */ | |
695 | if (le32_to_cpu(retbuf->ChunkBytesWritten) < | |
696 | tcon->max_bytes_chunk) | |
697 | tcon->max_bytes_chunk = | |
698 | le32_to_cpu(retbuf->ChunkBytesWritten); | |
699 | else | |
700 | goto cchunk_out; /* server gave us bogus size */ | |
701 | ||
702 | /* No need to change MaxChunks since already set to 1 */ | |
703 | chunk_sizes_updated = true; | |
2477bc58 SP |
704 | } else |
705 | goto cchunk_out; | |
9bf0c9cd | 706 | } |
41c1358e | 707 | |
9bf0c9cd | 708 | cchunk_out: |
41c1358e | 709 | kfree(pcchunk); |
24df1483 | 710 | kfree(retbuf); |
41c1358e SF |
711 | return rc; |
712 | } | |
713 | ||
7a5cfb19 PS |
714 | static int |
715 | smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon, | |
716 | struct cifs_fid *fid) | |
717 | { | |
718 | return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid); | |
719 | } | |
720 | ||
09a4707e PS |
721 | static unsigned int |
722 | smb2_read_data_offset(char *buf) | |
723 | { | |
724 | struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf; | |
725 | return rsp->DataOffset; | |
726 | } | |
727 | ||
728 | static unsigned int | |
729 | smb2_read_data_length(char *buf) | |
730 | { | |
731 | struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf; | |
732 | return le32_to_cpu(rsp->DataLength); | |
733 | } | |
734 | ||
d8e05039 PS |
735 | |
736 | static int | |
db8b631d | 737 | smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid, |
d8e05039 PS |
738 | struct cifs_io_parms *parms, unsigned int *bytes_read, |
739 | char **buf, int *buf_type) | |
740 | { | |
db8b631d SF |
741 | parms->persistent_fid = pfid->persistent_fid; |
742 | parms->volatile_fid = pfid->volatile_fid; | |
d8e05039 PS |
743 | return SMB2_read(xid, parms, bytes_read, buf, buf_type); |
744 | } | |
745 | ||
009d3443 | 746 | static int |
db8b631d | 747 | smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid, |
009d3443 PS |
748 | struct cifs_io_parms *parms, unsigned int *written, |
749 | struct kvec *iov, unsigned long nr_segs) | |
750 | { | |
751 | ||
db8b631d SF |
752 | parms->persistent_fid = pfid->persistent_fid; |
753 | parms->volatile_fid = pfid->volatile_fid; | |
009d3443 PS |
754 | return SMB2_write(xid, parms, written, iov, nr_segs); |
755 | } | |
756 | ||
d43cc793 SF |
757 | /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */ |
758 | static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon, | |
759 | struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse) | |
760 | { | |
761 | struct cifsInodeInfo *cifsi; | |
762 | int rc; | |
763 | ||
764 | cifsi = CIFS_I(inode); | |
765 | ||
766 | /* if file already sparse don't bother setting sparse again */ | |
767 | if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse) | |
768 | return true; /* already sparse */ | |
769 | ||
770 | if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse) | |
771 | return true; /* already not sparse */ | |
772 | ||
773 | /* | |
774 | * Can't check for sparse support on share the usual way via the | |
775 | * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share | |
776 | * since Samba server doesn't set the flag on the share, yet | |
777 | * supports the set sparse FSCTL and returns sparse correctly | |
778 | * in the file attributes. If we fail setting sparse though we | |
779 | * mark that server does not support sparse files for this share | |
780 | * to avoid repeatedly sending the unsupported fsctl to server | |
781 | * if the file is repeatedly extended. | |
782 | */ | |
783 | if (tcon->broken_sparse_sup) | |
784 | return false; | |
785 | ||
786 | rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, | |
787 | cfile->fid.volatile_fid, FSCTL_SET_SPARSE, | |
788 | true /* is_fctl */, &setsparse, 1, NULL, NULL); | |
789 | if (rc) { | |
790 | tcon->broken_sparse_sup = true; | |
791 | cifs_dbg(FYI, "set sparse rc = %d\n", rc); | |
792 | return false; | |
793 | } | |
794 | ||
795 | if (setsparse) | |
796 | cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE; | |
797 | else | |
798 | cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE); | |
799 | ||
800 | return true; | |
801 | } | |
802 | ||
c839ff24 PS |
803 | static int |
804 | smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon, | |
805 | struct cifsFileInfo *cfile, __u64 size, bool set_alloc) | |
806 | { | |
807 | __le64 eof = cpu_to_le64(size); | |
3d1a3745 SF |
808 | struct inode *inode; |
809 | ||
810 | /* | |
811 | * If extending file more than one page make sparse. Many Linux fs | |
812 | * make files sparse by default when extending via ftruncate | |
813 | */ | |
2b0143b5 | 814 | inode = d_inode(cfile->dentry); |
3d1a3745 SF |
815 | |
816 | if (!set_alloc && (size > inode->i_size + 8192)) { | |
3d1a3745 | 817 | __u8 set_sparse = 1; |
d43cc793 SF |
818 | |
819 | /* whether set sparse succeeds or not, extend the file */ | |
820 | smb2_set_sparse(xid, tcon, cfile, inode, set_sparse); | |
3d1a3745 SF |
821 | } |
822 | ||
c839ff24 | 823 | return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, |
f29ebb47 | 824 | cfile->fid.volatile_fid, cfile->pid, &eof, false); |
c839ff24 PS |
825 | } |
826 | ||
02b16665 SF |
827 | static int |
828 | smb2_duplicate_extents(const unsigned int xid, | |
829 | struct cifsFileInfo *srcfile, | |
830 | struct cifsFileInfo *trgtfile, u64 src_off, | |
831 | u64 len, u64 dest_off) | |
832 | { | |
833 | int rc; | |
834 | unsigned int ret_data_len; | |
02b16665 SF |
835 | struct duplicate_extents_to_file dup_ext_buf; |
836 | struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink); | |
837 | ||
838 | /* server fileays advertise duplicate extent support with this flag */ | |
839 | if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) & | |
840 | FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0) | |
841 | return -EOPNOTSUPP; | |
842 | ||
843 | dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid; | |
844 | dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid; | |
845 | dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off); | |
846 | dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off); | |
847 | dup_ext_buf.ByteCount = cpu_to_le64(len); | |
848 | cifs_dbg(FYI, "duplicate extents: src off %lld dst off %lld len %lld", | |
849 | src_off, dest_off, len); | |
850 | ||
851 | rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false); | |
852 | if (rc) | |
853 | goto duplicate_extents_out; | |
854 | ||
855 | rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid, | |
856 | trgtfile->fid.volatile_fid, | |
857 | FSCTL_DUPLICATE_EXTENTS_TO_FILE, | |
858 | true /* is_fsctl */, (char *)&dup_ext_buf, | |
859 | sizeof(struct duplicate_extents_to_file), | |
24df1483 | 860 | NULL, |
02b16665 SF |
861 | &ret_data_len); |
862 | ||
863 | if (ret_data_len > 0) | |
864 | cifs_dbg(FYI, "non-zero response length in duplicate extents"); | |
865 | ||
866 | duplicate_extents_out: | |
867 | return rc; | |
868 | } | |
02b16665 | 869 | |
64a5cfa6 SF |
870 | static int |
871 | smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon, | |
872 | struct cifsFileInfo *cfile) | |
873 | { | |
874 | return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid, | |
875 | cfile->fid.volatile_fid); | |
876 | } | |
877 | ||
b3152e2c SF |
878 | static int |
879 | smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon, | |
880 | struct cifsFileInfo *cfile) | |
881 | { | |
882 | struct fsctl_set_integrity_information_req integr_info; | |
b3152e2c SF |
883 | unsigned int ret_data_len; |
884 | ||
885 | integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED); | |
886 | integr_info.Flags = 0; | |
887 | integr_info.Reserved = 0; | |
888 | ||
889 | return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, | |
890 | cfile->fid.volatile_fid, | |
891 | FSCTL_SET_INTEGRITY_INFORMATION, | |
892 | true /* is_fsctl */, (char *)&integr_info, | |
893 | sizeof(struct fsctl_set_integrity_information_req), | |
24df1483 | 894 | NULL, |
b3152e2c SF |
895 | &ret_data_len); |
896 | ||
897 | } | |
898 | ||
834170c8 SF |
899 | static int |
900 | smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon, | |
901 | struct cifsFileInfo *cfile, void __user *ioc_buf) | |
902 | { | |
903 | char *retbuf = NULL; | |
904 | unsigned int ret_data_len = 0; | |
905 | int rc; | |
906 | struct smb_snapshot_array snapshot_in; | |
907 | ||
908 | rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, | |
909 | cfile->fid.volatile_fid, | |
910 | FSCTL_SRV_ENUMERATE_SNAPSHOTS, | |
911 | true /* is_fsctl */, NULL, 0 /* no input data */, | |
912 | (char **)&retbuf, | |
913 | &ret_data_len); | |
914 | cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n", | |
915 | rc, ret_data_len); | |
916 | if (rc) | |
917 | return rc; | |
918 | ||
919 | if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) { | |
920 | /* Fixup buffer */ | |
921 | if (copy_from_user(&snapshot_in, ioc_buf, | |
922 | sizeof(struct smb_snapshot_array))) { | |
923 | rc = -EFAULT; | |
924 | kfree(retbuf); | |
925 | return rc; | |
926 | } | |
927 | if (snapshot_in.snapshot_array_size < sizeof(struct smb_snapshot_array)) { | |
928 | rc = -ERANGE; | |
929 | return rc; | |
930 | } | |
931 | ||
932 | if (ret_data_len > snapshot_in.snapshot_array_size) | |
933 | ret_data_len = snapshot_in.snapshot_array_size; | |
934 | ||
935 | if (copy_to_user(ioc_buf, retbuf, ret_data_len)) | |
936 | rc = -EFAULT; | |
937 | } | |
938 | ||
939 | kfree(retbuf); | |
940 | return rc; | |
941 | } | |
942 | ||
d324f08d PS |
943 | static int |
944 | smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon, | |
945 | const char *path, struct cifs_sb_info *cifs_sb, | |
946 | struct cifs_fid *fid, __u16 search_flags, | |
947 | struct cifs_search_info *srch_inf) | |
948 | { | |
949 | __le16 *utf16_path; | |
950 | int rc; | |
2e44b288 | 951 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
064f6047 | 952 | struct cifs_open_parms oparms; |
d324f08d PS |
953 | |
954 | utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); | |
955 | if (!utf16_path) | |
956 | return -ENOMEM; | |
957 | ||
064f6047 PS |
958 | oparms.tcon = tcon; |
959 | oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA; | |
960 | oparms.disposition = FILE_OPEN; | |
961 | oparms.create_options = 0; | |
962 | oparms.fid = fid; | |
9cbc0b73 | 963 | oparms.reconnect = false; |
064f6047 | 964 | |
b42bf888 | 965 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL); |
d324f08d PS |
966 | kfree(utf16_path); |
967 | if (rc) { | |
f96637be | 968 | cifs_dbg(VFS, "open dir failed\n"); |
d324f08d PS |
969 | return rc; |
970 | } | |
971 | ||
972 | srch_inf->entries_in_buffer = 0; | |
973 | srch_inf->index_of_last_entry = 0; | |
d324f08d | 974 | |
064f6047 PS |
975 | rc = SMB2_query_directory(xid, tcon, fid->persistent_fid, |
976 | fid->volatile_fid, 0, srch_inf); | |
d324f08d | 977 | if (rc) { |
f96637be | 978 | cifs_dbg(VFS, "query directory failed\n"); |
064f6047 | 979 | SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
d324f08d PS |
980 | } |
981 | return rc; | |
982 | } | |
983 | ||
984 | static int | |
985 | smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon, | |
986 | struct cifs_fid *fid, __u16 search_flags, | |
987 | struct cifs_search_info *srch_inf) | |
988 | { | |
989 | return SMB2_query_directory(xid, tcon, fid->persistent_fid, | |
990 | fid->volatile_fid, 0, srch_inf); | |
991 | } | |
992 | ||
993 | static int | |
994 | smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon, | |
995 | struct cifs_fid *fid) | |
996 | { | |
997 | return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); | |
998 | } | |
999 | ||
2e44b288 PS |
1000 | /* |
1001 | * If we negotiate SMB2 protocol and get STATUS_PENDING - update | |
1002 | * the number of credits and return true. Otherwise - return false. | |
1003 | */ | |
1004 | static bool | |
1005 | smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length) | |
1006 | { | |
b6932a6a | 1007 | struct smb2_sync_hdr *shdr = get_sync_hdr(buf); |
2e44b288 | 1008 | |
b6932a6a | 1009 | if (shdr->Status != STATUS_PENDING) |
2e44b288 PS |
1010 | return false; |
1011 | ||
1012 | if (!length) { | |
1013 | spin_lock(&server->req_lock); | |
b6932a6a | 1014 | server->credits += le16_to_cpu(shdr->CreditRequest); |
2e44b288 PS |
1015 | spin_unlock(&server->req_lock); |
1016 | wake_up(&server->request_q); | |
1017 | } | |
1018 | ||
1019 | return true; | |
1020 | } | |
1021 | ||
983c88a4 PS |
1022 | static int |
1023 | smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid, | |
1024 | struct cifsInodeInfo *cinode) | |
1025 | { | |
0822f514 PS |
1026 | if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING) |
1027 | return SMB2_lease_break(0, tcon, cinode->lease_key, | |
1028 | smb2_get_lease_state(cinode)); | |
1029 | ||
983c88a4 PS |
1030 | return SMB2_oplock_break(0, tcon, fid->persistent_fid, |
1031 | fid->volatile_fid, | |
18cceb6a | 1032 | CIFS_CACHE_READ(cinode) ? 1 : 0); |
983c88a4 PS |
1033 | } |
1034 | ||
6fc05c25 PS |
1035 | static int |
1036 | smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon, | |
1037 | struct kstatfs *buf) | |
1038 | { | |
1039 | int rc; | |
6fc05c25 PS |
1040 | __le16 srch_path = 0; /* Null - open root of share */ |
1041 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; | |
064f6047 PS |
1042 | struct cifs_open_parms oparms; |
1043 | struct cifs_fid fid; | |
1044 | ||
1045 | oparms.tcon = tcon; | |
1046 | oparms.desired_access = FILE_READ_ATTRIBUTES; | |
1047 | oparms.disposition = FILE_OPEN; | |
1048 | oparms.create_options = 0; | |
1049 | oparms.fid = &fid; | |
9cbc0b73 | 1050 | oparms.reconnect = false; |
6fc05c25 | 1051 | |
b42bf888 | 1052 | rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL); |
6fc05c25 PS |
1053 | if (rc) |
1054 | return rc; | |
1055 | buf->f_type = SMB2_MAGIC_NUMBER; | |
064f6047 PS |
1056 | rc = SMB2_QFS_info(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
1057 | buf); | |
1058 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); | |
6fc05c25 PS |
1059 | return rc; |
1060 | } | |
1061 | ||
027e8eec PS |
1062 | static bool |
1063 | smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2) | |
1064 | { | |
1065 | return ob1->fid.persistent_fid == ob2->fid.persistent_fid && | |
1066 | ob1->fid.volatile_fid == ob2->fid.volatile_fid; | |
1067 | } | |
1068 | ||
f7ba7fe6 PS |
1069 | static int |
1070 | smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset, | |
1071 | __u64 length, __u32 type, int lock, int unlock, bool wait) | |
1072 | { | |
1073 | if (unlock && !lock) | |
1074 | type = SMB2_LOCKFLAG_UNLOCK; | |
1075 | return SMB2_lock(xid, tlink_tcon(cfile->tlink), | |
1076 | cfile->fid.persistent_fid, cfile->fid.volatile_fid, | |
1077 | current->tgid, length, offset, type, wait); | |
1078 | } | |
1079 | ||
b8c32dbb PS |
1080 | static void |
1081 | smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid) | |
1082 | { | |
1083 | memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE); | |
1084 | } | |
1085 | ||
1086 | static void | |
1087 | smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid) | |
1088 | { | |
1089 | memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE); | |
1090 | } | |
1091 | ||
1092 | static void | |
1093 | smb2_new_lease_key(struct cifs_fid *fid) | |
1094 | { | |
fa70b87c | 1095 | generate_random_uuid(fid->lease_key); |
b8c32dbb PS |
1096 | } |
1097 | ||
7893242e PS |
1098 | #define SMB2_SYMLINK_STRUCT_SIZE \ |
1099 | (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp)) | |
1100 | ||
b42bf888 PS |
1101 | static int |
1102 | smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon, | |
1103 | const char *full_path, char **target_path, | |
1104 | struct cifs_sb_info *cifs_sb) | |
1105 | { | |
1106 | int rc; | |
1107 | __le16 *utf16_path; | |
1108 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; | |
1109 | struct cifs_open_parms oparms; | |
1110 | struct cifs_fid fid; | |
1111 | struct smb2_err_rsp *err_buf = NULL; | |
1112 | struct smb2_symlink_err_rsp *symlink; | |
7893242e PS |
1113 | unsigned int sub_len; |
1114 | unsigned int sub_offset; | |
1115 | unsigned int print_len; | |
1116 | unsigned int print_offset; | |
b42bf888 PS |
1117 | |
1118 | cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path); | |
1119 | ||
1120 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); | |
1121 | if (!utf16_path) | |
1122 | return -ENOMEM; | |
1123 | ||
1124 | oparms.tcon = tcon; | |
1125 | oparms.desired_access = FILE_READ_ATTRIBUTES; | |
1126 | oparms.disposition = FILE_OPEN; | |
1127 | oparms.create_options = 0; | |
1128 | oparms.fid = &fid; | |
1129 | oparms.reconnect = false; | |
1130 | ||
1131 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_buf); | |
1132 | ||
1133 | if (!rc || !err_buf) { | |
1134 | kfree(utf16_path); | |
1135 | return -ENOENT; | |
1136 | } | |
7893242e PS |
1137 | |
1138 | if (le32_to_cpu(err_buf->ByteCount) < sizeof(struct smb2_symlink_err_rsp) || | |
1139 | get_rfc1002_length(err_buf) + 4 < SMB2_SYMLINK_STRUCT_SIZE) { | |
1140 | kfree(utf16_path); | |
1141 | return -ENOENT; | |
1142 | } | |
1143 | ||
b42bf888 PS |
1144 | /* open must fail on symlink - reset rc */ |
1145 | rc = 0; | |
1146 | symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData; | |
1147 | sub_len = le16_to_cpu(symlink->SubstituteNameLength); | |
1148 | sub_offset = le16_to_cpu(symlink->SubstituteNameOffset); | |
7893242e PS |
1149 | print_len = le16_to_cpu(symlink->PrintNameLength); |
1150 | print_offset = le16_to_cpu(symlink->PrintNameOffset); | |
1151 | ||
1152 | if (get_rfc1002_length(err_buf) + 4 < | |
1153 | SMB2_SYMLINK_STRUCT_SIZE + sub_offset + sub_len) { | |
1154 | kfree(utf16_path); | |
1155 | return -ENOENT; | |
1156 | } | |
1157 | ||
1158 | if (get_rfc1002_length(err_buf) + 4 < | |
1159 | SMB2_SYMLINK_STRUCT_SIZE + print_offset + print_len) { | |
1160 | kfree(utf16_path); | |
1161 | return -ENOENT; | |
1162 | } | |
1163 | ||
b42bf888 PS |
1164 | *target_path = cifs_strndup_from_utf16( |
1165 | (char *)symlink->PathBuffer + sub_offset, | |
1166 | sub_len, true, cifs_sb->local_nls); | |
1167 | if (!(*target_path)) { | |
1168 | kfree(utf16_path); | |
1169 | return -ENOMEM; | |
1170 | } | |
1171 | convert_delimiter(*target_path, '/'); | |
1172 | cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path); | |
1173 | kfree(utf16_path); | |
1174 | return rc; | |
1175 | } | |
1176 | ||
30175628 SF |
1177 | static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon, |
1178 | loff_t offset, loff_t len, bool keep_size) | |
1179 | { | |
1180 | struct inode *inode; | |
1181 | struct cifsInodeInfo *cifsi; | |
1182 | struct cifsFileInfo *cfile = file->private_data; | |
1183 | struct file_zero_data_information fsctl_buf; | |
1184 | long rc; | |
1185 | unsigned int xid; | |
1186 | ||
1187 | xid = get_xid(); | |
1188 | ||
2b0143b5 | 1189 | inode = d_inode(cfile->dentry); |
30175628 SF |
1190 | cifsi = CIFS_I(inode); |
1191 | ||
1192 | /* if file not oplocked can't be sure whether asking to extend size */ | |
1193 | if (!CIFS_CACHE_READ(cifsi)) | |
1194 | if (keep_size == false) | |
1195 | return -EOPNOTSUPP; | |
1196 | ||
2bb93d24 | 1197 | /* |
30175628 SF |
1198 | * Must check if file sparse since fallocate -z (zero range) assumes |
1199 | * non-sparse allocation | |
1200 | */ | |
1201 | if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) | |
1202 | return -EOPNOTSUPP; | |
1203 | ||
1204 | /* | |
1205 | * need to make sure we are not asked to extend the file since the SMB3 | |
1206 | * fsctl does not change the file size. In the future we could change | |
1207 | * this to zero the first part of the range then set the file size | |
1208 | * which for a non sparse file would zero the newly extended range | |
1209 | */ | |
1210 | if (keep_size == false) | |
1211 | if (i_size_read(inode) < offset + len) | |
1212 | return -EOPNOTSUPP; | |
1213 | ||
1214 | cifs_dbg(FYI, "offset %lld len %lld", offset, len); | |
1215 | ||
1216 | fsctl_buf.FileOffset = cpu_to_le64(offset); | |
1217 | fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len); | |
1218 | ||
1219 | rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, | |
1220 | cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA, | |
1221 | true /* is_fctl */, (char *)&fsctl_buf, | |
1222 | sizeof(struct file_zero_data_information), NULL, NULL); | |
1223 | free_xid(xid); | |
1224 | return rc; | |
1225 | } | |
1226 | ||
31742c5a SF |
1227 | static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon, |
1228 | loff_t offset, loff_t len) | |
1229 | { | |
1230 | struct inode *inode; | |
1231 | struct cifsInodeInfo *cifsi; | |
1232 | struct cifsFileInfo *cfile = file->private_data; | |
1233 | struct file_zero_data_information fsctl_buf; | |
1234 | long rc; | |
1235 | unsigned int xid; | |
1236 | __u8 set_sparse = 1; | |
1237 | ||
1238 | xid = get_xid(); | |
1239 | ||
2b0143b5 | 1240 | inode = d_inode(cfile->dentry); |
31742c5a SF |
1241 | cifsi = CIFS_I(inode); |
1242 | ||
1243 | /* Need to make file sparse, if not already, before freeing range. */ | |
1244 | /* Consider adding equivalent for compressed since it could also work */ | |
1245 | if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) | |
1246 | return -EOPNOTSUPP; | |
1247 | ||
1248 | cifs_dbg(FYI, "offset %lld len %lld", offset, len); | |
1249 | ||
1250 | fsctl_buf.FileOffset = cpu_to_le64(offset); | |
1251 | fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len); | |
1252 | ||
1253 | rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, | |
1254 | cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA, | |
1255 | true /* is_fctl */, (char *)&fsctl_buf, | |
1256 | sizeof(struct file_zero_data_information), NULL, NULL); | |
1257 | free_xid(xid); | |
1258 | return rc; | |
1259 | } | |
1260 | ||
9ccf3216 SF |
1261 | static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon, |
1262 | loff_t off, loff_t len, bool keep_size) | |
1263 | { | |
1264 | struct inode *inode; | |
1265 | struct cifsInodeInfo *cifsi; | |
1266 | struct cifsFileInfo *cfile = file->private_data; | |
1267 | long rc = -EOPNOTSUPP; | |
1268 | unsigned int xid; | |
1269 | ||
1270 | xid = get_xid(); | |
1271 | ||
2b0143b5 | 1272 | inode = d_inode(cfile->dentry); |
9ccf3216 SF |
1273 | cifsi = CIFS_I(inode); |
1274 | ||
1275 | /* if file not oplocked can't be sure whether asking to extend size */ | |
1276 | if (!CIFS_CACHE_READ(cifsi)) | |
1277 | if (keep_size == false) | |
1278 | return -EOPNOTSUPP; | |
1279 | ||
1280 | /* | |
1281 | * Files are non-sparse by default so falloc may be a no-op | |
1282 | * Must check if file sparse. If not sparse, and not extending | |
1283 | * then no need to do anything since file already allocated | |
1284 | */ | |
1285 | if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) { | |
1286 | if (keep_size == true) | |
1287 | return 0; | |
1288 | /* check if extending file */ | |
1289 | else if (i_size_read(inode) >= off + len) | |
1290 | /* not extending file and already not sparse */ | |
1291 | return 0; | |
1292 | /* BB: in future add else clause to extend file */ | |
1293 | else | |
1294 | return -EOPNOTSUPP; | |
1295 | } | |
1296 | ||
1297 | if ((keep_size == true) || (i_size_read(inode) >= off + len)) { | |
1298 | /* | |
1299 | * Check if falloc starts within first few pages of file | |
1300 | * and ends within a few pages of the end of file to | |
1301 | * ensure that most of file is being forced to be | |
1302 | * fallocated now. If so then setting whole file sparse | |
1303 | * ie potentially making a few extra pages at the beginning | |
1304 | * or end of the file non-sparse via set_sparse is harmless. | |
1305 | */ | |
1306 | if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) | |
1307 | return -EOPNOTSUPP; | |
1308 | ||
1309 | rc = smb2_set_sparse(xid, tcon, cfile, inode, false); | |
1310 | } | |
1311 | /* BB: else ... in future add code to extend file and set sparse */ | |
1312 | ||
1313 | ||
1314 | free_xid(xid); | |
1315 | return rc; | |
1316 | } | |
1317 | ||
1318 | ||
31742c5a SF |
1319 | static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode, |
1320 | loff_t off, loff_t len) | |
1321 | { | |
1322 | /* KEEP_SIZE already checked for by do_fallocate */ | |
1323 | if (mode & FALLOC_FL_PUNCH_HOLE) | |
1324 | return smb3_punch_hole(file, tcon, off, len); | |
30175628 SF |
1325 | else if (mode & FALLOC_FL_ZERO_RANGE) { |
1326 | if (mode & FALLOC_FL_KEEP_SIZE) | |
1327 | return smb3_zero_range(file, tcon, off, len, true); | |
1328 | return smb3_zero_range(file, tcon, off, len, false); | |
9ccf3216 SF |
1329 | } else if (mode == FALLOC_FL_KEEP_SIZE) |
1330 | return smb3_simple_falloc(file, tcon, off, len, true); | |
1331 | else if (mode == 0) | |
1332 | return smb3_simple_falloc(file, tcon, off, len, false); | |
31742c5a SF |
1333 | |
1334 | return -EOPNOTSUPP; | |
1335 | } | |
1336 | ||
c11f1df5 SP |
1337 | static void |
1338 | smb2_downgrade_oplock(struct TCP_Server_Info *server, | |
1339 | struct cifsInodeInfo *cinode, bool set_level2) | |
1340 | { | |
1341 | if (set_level2) | |
1342 | server->ops->set_oplock_level(cinode, SMB2_OPLOCK_LEVEL_II, | |
1343 | 0, NULL); | |
1344 | else | |
1345 | server->ops->set_oplock_level(cinode, 0, 0, NULL); | |
1346 | } | |
1347 | ||
53ef1016 | 1348 | static void |
42873b0a PS |
1349 | smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock, |
1350 | unsigned int epoch, bool *purge_cache) | |
53ef1016 PS |
1351 | { |
1352 | oplock &= 0xFF; | |
1353 | if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE) | |
1354 | return; | |
1355 | if (oplock == SMB2_OPLOCK_LEVEL_BATCH) { | |
42873b0a | 1356 | cinode->oplock = CIFS_CACHE_RHW_FLG; |
53ef1016 PS |
1357 | cifs_dbg(FYI, "Batch Oplock granted on inode %p\n", |
1358 | &cinode->vfs_inode); | |
1359 | } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) { | |
42873b0a | 1360 | cinode->oplock = CIFS_CACHE_RW_FLG; |
53ef1016 PS |
1361 | cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n", |
1362 | &cinode->vfs_inode); | |
1363 | } else if (oplock == SMB2_OPLOCK_LEVEL_II) { | |
1364 | cinode->oplock = CIFS_CACHE_READ_FLG; | |
1365 | cifs_dbg(FYI, "Level II Oplock granted on inode %p\n", | |
1366 | &cinode->vfs_inode); | |
1367 | } else | |
1368 | cinode->oplock = 0; | |
1369 | } | |
1370 | ||
1371 | static void | |
42873b0a PS |
1372 | smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock, |
1373 | unsigned int epoch, bool *purge_cache) | |
53ef1016 PS |
1374 | { |
1375 | char message[5] = {0}; | |
1376 | ||
1377 | oplock &= 0xFF; | |
1378 | if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE) | |
1379 | return; | |
1380 | ||
1381 | cinode->oplock = 0; | |
1382 | if (oplock & SMB2_LEASE_READ_CACHING_HE) { | |
1383 | cinode->oplock |= CIFS_CACHE_READ_FLG; | |
1384 | strcat(message, "R"); | |
1385 | } | |
1386 | if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) { | |
1387 | cinode->oplock |= CIFS_CACHE_HANDLE_FLG; | |
1388 | strcat(message, "H"); | |
1389 | } | |
1390 | if (oplock & SMB2_LEASE_WRITE_CACHING_HE) { | |
1391 | cinode->oplock |= CIFS_CACHE_WRITE_FLG; | |
1392 | strcat(message, "W"); | |
1393 | } | |
1394 | if (!cinode->oplock) | |
1395 | strcat(message, "None"); | |
1396 | cifs_dbg(FYI, "%s Lease granted on inode %p\n", message, | |
1397 | &cinode->vfs_inode); | |
1398 | } | |
1399 | ||
42873b0a PS |
1400 | static void |
1401 | smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock, | |
1402 | unsigned int epoch, bool *purge_cache) | |
1403 | { | |
1404 | unsigned int old_oplock = cinode->oplock; | |
1405 | ||
1406 | smb21_set_oplock_level(cinode, oplock, epoch, purge_cache); | |
1407 | ||
1408 | if (purge_cache) { | |
1409 | *purge_cache = false; | |
1410 | if (old_oplock == CIFS_CACHE_READ_FLG) { | |
1411 | if (cinode->oplock == CIFS_CACHE_READ_FLG && | |
1412 | (epoch - cinode->epoch > 0)) | |
1413 | *purge_cache = true; | |
1414 | else if (cinode->oplock == CIFS_CACHE_RH_FLG && | |
1415 | (epoch - cinode->epoch > 1)) | |
1416 | *purge_cache = true; | |
1417 | else if (cinode->oplock == CIFS_CACHE_RHW_FLG && | |
1418 | (epoch - cinode->epoch > 1)) | |
1419 | *purge_cache = true; | |
1420 | else if (cinode->oplock == 0 && | |
1421 | (epoch - cinode->epoch > 0)) | |
1422 | *purge_cache = true; | |
1423 | } else if (old_oplock == CIFS_CACHE_RH_FLG) { | |
1424 | if (cinode->oplock == CIFS_CACHE_RH_FLG && | |
1425 | (epoch - cinode->epoch > 0)) | |
1426 | *purge_cache = true; | |
1427 | else if (cinode->oplock == CIFS_CACHE_RHW_FLG && | |
1428 | (epoch - cinode->epoch > 1)) | |
1429 | *purge_cache = true; | |
1430 | } | |
1431 | cinode->epoch = epoch; | |
1432 | } | |
1433 | } | |
1434 | ||
53ef1016 PS |
1435 | static bool |
1436 | smb2_is_read_op(__u32 oplock) | |
1437 | { | |
1438 | return oplock == SMB2_OPLOCK_LEVEL_II; | |
1439 | } | |
1440 | ||
1441 | static bool | |
1442 | smb21_is_read_op(__u32 oplock) | |
1443 | { | |
1444 | return (oplock & SMB2_LEASE_READ_CACHING_HE) && | |
1445 | !(oplock & SMB2_LEASE_WRITE_CACHING_HE); | |
1446 | } | |
1447 | ||
f047390a PS |
1448 | static __le32 |
1449 | map_oplock_to_lease(u8 oplock) | |
1450 | { | |
1451 | if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) | |
1452 | return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING; | |
1453 | else if (oplock == SMB2_OPLOCK_LEVEL_II) | |
1454 | return SMB2_LEASE_READ_CACHING; | |
1455 | else if (oplock == SMB2_OPLOCK_LEVEL_BATCH) | |
1456 | return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING | | |
1457 | SMB2_LEASE_WRITE_CACHING; | |
1458 | return 0; | |
1459 | } | |
1460 | ||
a41a28bd PS |
1461 | static char * |
1462 | smb2_create_lease_buf(u8 *lease_key, u8 oplock) | |
1463 | { | |
1464 | struct create_lease *buf; | |
1465 | ||
1466 | buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL); | |
1467 | if (!buf) | |
1468 | return NULL; | |
1469 | ||
1470 | buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key)); | |
1471 | buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8))); | |
f047390a | 1472 | buf->lcontext.LeaseState = map_oplock_to_lease(oplock); |
a41a28bd PS |
1473 | |
1474 | buf->ccontext.DataOffset = cpu_to_le16(offsetof | |
1475 | (struct create_lease, lcontext)); | |
1476 | buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context)); | |
1477 | buf->ccontext.NameOffset = cpu_to_le16(offsetof | |
1478 | (struct create_lease, Name)); | |
1479 | buf->ccontext.NameLength = cpu_to_le16(4); | |
12197a7f | 1480 | /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */ |
a41a28bd PS |
1481 | buf->Name[0] = 'R'; |
1482 | buf->Name[1] = 'q'; | |
1483 | buf->Name[2] = 'L'; | |
1484 | buf->Name[3] = 's'; | |
1485 | return (char *)buf; | |
1486 | } | |
1487 | ||
f047390a PS |
1488 | static char * |
1489 | smb3_create_lease_buf(u8 *lease_key, u8 oplock) | |
1490 | { | |
1491 | struct create_lease_v2 *buf; | |
1492 | ||
1493 | buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL); | |
1494 | if (!buf) | |
1495 | return NULL; | |
1496 | ||
1497 | buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key)); | |
1498 | buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8))); | |
1499 | buf->lcontext.LeaseState = map_oplock_to_lease(oplock); | |
1500 | ||
1501 | buf->ccontext.DataOffset = cpu_to_le16(offsetof | |
1502 | (struct create_lease_v2, lcontext)); | |
1503 | buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2)); | |
1504 | buf->ccontext.NameOffset = cpu_to_le16(offsetof | |
1505 | (struct create_lease_v2, Name)); | |
1506 | buf->ccontext.NameLength = cpu_to_le16(4); | |
12197a7f | 1507 | /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */ |
f047390a PS |
1508 | buf->Name[0] = 'R'; |
1509 | buf->Name[1] = 'q'; | |
1510 | buf->Name[2] = 'L'; | |
1511 | buf->Name[3] = 's'; | |
1512 | return (char *)buf; | |
1513 | } | |
1514 | ||
b5c7cde3 | 1515 | static __u8 |
42873b0a | 1516 | smb2_parse_lease_buf(void *buf, unsigned int *epoch) |
b5c7cde3 PS |
1517 | { |
1518 | struct create_lease *lc = (struct create_lease *)buf; | |
1519 | ||
42873b0a | 1520 | *epoch = 0; /* not used */ |
b5c7cde3 PS |
1521 | if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS) |
1522 | return SMB2_OPLOCK_LEVEL_NOCHANGE; | |
1523 | return le32_to_cpu(lc->lcontext.LeaseState); | |
1524 | } | |
1525 | ||
f047390a | 1526 | static __u8 |
42873b0a | 1527 | smb3_parse_lease_buf(void *buf, unsigned int *epoch) |
f047390a PS |
1528 | { |
1529 | struct create_lease_v2 *lc = (struct create_lease_v2 *)buf; | |
1530 | ||
42873b0a | 1531 | *epoch = le16_to_cpu(lc->lcontext.Epoch); |
f047390a PS |
1532 | if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS) |
1533 | return SMB2_OPLOCK_LEVEL_NOCHANGE; | |
1534 | return le32_to_cpu(lc->lcontext.LeaseState); | |
1535 | } | |
1536 | ||
7f6c5008 PS |
1537 | static unsigned int |
1538 | smb2_wp_retry_size(struct inode *inode) | |
1539 | { | |
1540 | return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize, | |
1541 | SMB2_MAX_BUFFER_SIZE); | |
1542 | } | |
1543 | ||
52755808 PS |
1544 | static bool |
1545 | smb2_dir_needs_close(struct cifsFileInfo *cfile) | |
1546 | { | |
1547 | return !cfile->invalidHandle; | |
1548 | } | |
1549 | ||
53ef1016 | 1550 | struct smb_version_operations smb20_operations = { |
027e8eec | 1551 | .compare_fids = smb2_compare_fids, |
2dc7e1c0 | 1552 | .setup_request = smb2_setup_request, |
c95b8eed | 1553 | .setup_async_request = smb2_setup_async_request, |
2dc7e1c0 | 1554 | .check_receive = smb2_check_receive, |
28ea5290 PS |
1555 | .add_credits = smb2_add_credits, |
1556 | .set_credits = smb2_set_credits, | |
1557 | .get_credits_field = smb2_get_credits_field, | |
1558 | .get_credits = smb2_get_credits, | |
cb7e9eab | 1559 | .wait_mtu_credits = cifs_wait_mtu_credits, |
2dc7e1c0 | 1560 | .get_next_mid = smb2_get_next_mid, |
09a4707e PS |
1561 | .read_data_offset = smb2_read_data_offset, |
1562 | .read_data_length = smb2_read_data_length, | |
1563 | .map_error = map_smb2_to_linux_error, | |
093b2bda PS |
1564 | .find_mid = smb2_find_mid, |
1565 | .check_message = smb2_check_message, | |
1566 | .dump_detail = smb2_dump_detail, | |
d60622eb PS |
1567 | .clear_stats = smb2_clear_stats, |
1568 | .print_stats = smb2_print_stats, | |
983c88a4 | 1569 | .is_oplock_break = smb2_is_valid_oplock_break, |
c11f1df5 | 1570 | .downgrade_oplock = smb2_downgrade_oplock, |
ec2e4523 PS |
1571 | .need_neg = smb2_need_neg, |
1572 | .negotiate = smb2_negotiate, | |
3a3bab50 PS |
1573 | .negotiate_wsize = smb2_negotiate_wsize, |
1574 | .negotiate_rsize = smb2_negotiate_rsize, | |
5478f9ba PS |
1575 | .sess_setup = SMB2_sess_setup, |
1576 | .logoff = SMB2_logoff, | |
faaf946a PS |
1577 | .tree_connect = SMB2_tcon, |
1578 | .tree_disconnect = SMB2_tdis, | |
34f62640 | 1579 | .qfs_tcon = smb2_qfs_tcon, |
2503a0db | 1580 | .is_path_accessible = smb2_is_path_accessible, |
9094fad1 PS |
1581 | .can_echo = smb2_can_echo, |
1582 | .echo = SMB2_echo, | |
be4cb9e3 PS |
1583 | .query_path_info = smb2_query_path_info, |
1584 | .get_srv_inum = smb2_get_srv_inum, | |
b7546bc5 | 1585 | .query_file_info = smb2_query_file_info, |
c839ff24 PS |
1586 | .set_path_size = smb2_set_path_size, |
1587 | .set_file_size = smb2_set_file_size, | |
1feeaac7 | 1588 | .set_file_info = smb2_set_file_info, |
64a5cfa6 | 1589 | .set_compression = smb2_set_compression, |
a0e73183 PS |
1590 | .mkdir = smb2_mkdir, |
1591 | .mkdir_setinfo = smb2_mkdir_setinfo, | |
1a500f01 | 1592 | .rmdir = smb2_rmdir, |
cbe6f439 | 1593 | .unlink = smb2_unlink, |
35143eb5 | 1594 | .rename = smb2_rename_path, |
568798cc | 1595 | .create_hardlink = smb2_create_hardlink, |
b42bf888 | 1596 | .query_symlink = smb2_query_symlink, |
5b23c97d SP |
1597 | .query_mf_symlink = smb3_query_mf_symlink, |
1598 | .create_mf_symlink = smb3_create_mf_symlink, | |
f0df737e PS |
1599 | .open = smb2_open_file, |
1600 | .set_fid = smb2_set_fid, | |
1601 | .close = smb2_close_file, | |
7a5cfb19 | 1602 | .flush = smb2_flush_file, |
09a4707e | 1603 | .async_readv = smb2_async_readv, |
33319141 | 1604 | .async_writev = smb2_async_writev, |
d8e05039 | 1605 | .sync_read = smb2_sync_read, |
009d3443 | 1606 | .sync_write = smb2_sync_write, |
d324f08d PS |
1607 | .query_dir_first = smb2_query_dir_first, |
1608 | .query_dir_next = smb2_query_dir_next, | |
1609 | .close_dir = smb2_close_dir, | |
1610 | .calc_smb_size = smb2_calc_size, | |
2e44b288 | 1611 | .is_status_pending = smb2_is_status_pending, |
983c88a4 | 1612 | .oplock_response = smb2_oplock_response, |
6fc05c25 | 1613 | .queryfs = smb2_queryfs, |
f7ba7fe6 PS |
1614 | .mand_lock = smb2_mand_lock, |
1615 | .mand_unlock_range = smb2_unlock_range, | |
b140799a | 1616 | .push_mand_locks = smb2_push_mandatory_locks, |
b8c32dbb PS |
1617 | .get_lease_key = smb2_get_lease_key, |
1618 | .set_lease_key = smb2_set_lease_key, | |
1619 | .new_lease_key = smb2_new_lease_key, | |
38107d45 | 1620 | .calc_signature = smb2_calc_signature, |
53ef1016 PS |
1621 | .is_read_op = smb2_is_read_op, |
1622 | .set_oplock_level = smb2_set_oplock_level, | |
a41a28bd | 1623 | .create_lease_buf = smb2_create_lease_buf, |
b5c7cde3 | 1624 | .parse_lease_buf = smb2_parse_lease_buf, |
41c1358e | 1625 | .clone_range = smb2_clone_range, |
7f6c5008 | 1626 | .wp_retry_size = smb2_wp_retry_size, |
52755808 | 1627 | .dir_needs_close = smb2_dir_needs_close, |
38107d45 SF |
1628 | }; |
1629 | ||
53ef1016 PS |
1630 | struct smb_version_operations smb21_operations = { |
1631 | .compare_fids = smb2_compare_fids, | |
1632 | .setup_request = smb2_setup_request, | |
1633 | .setup_async_request = smb2_setup_async_request, | |
1634 | .check_receive = smb2_check_receive, | |
1635 | .add_credits = smb2_add_credits, | |
1636 | .set_credits = smb2_set_credits, | |
1637 | .get_credits_field = smb2_get_credits_field, | |
1638 | .get_credits = smb2_get_credits, | |
cb7e9eab | 1639 | .wait_mtu_credits = smb2_wait_mtu_credits, |
53ef1016 PS |
1640 | .get_next_mid = smb2_get_next_mid, |
1641 | .read_data_offset = smb2_read_data_offset, | |
1642 | .read_data_length = smb2_read_data_length, | |
1643 | .map_error = map_smb2_to_linux_error, | |
1644 | .find_mid = smb2_find_mid, | |
1645 | .check_message = smb2_check_message, | |
1646 | .dump_detail = smb2_dump_detail, | |
1647 | .clear_stats = smb2_clear_stats, | |
1648 | .print_stats = smb2_print_stats, | |
1649 | .is_oplock_break = smb2_is_valid_oplock_break, | |
c11f1df5 | 1650 | .downgrade_oplock = smb2_downgrade_oplock, |
53ef1016 PS |
1651 | .need_neg = smb2_need_neg, |
1652 | .negotiate = smb2_negotiate, | |
1653 | .negotiate_wsize = smb2_negotiate_wsize, | |
1654 | .negotiate_rsize = smb2_negotiate_rsize, | |
1655 | .sess_setup = SMB2_sess_setup, | |
1656 | .logoff = SMB2_logoff, | |
1657 | .tree_connect = SMB2_tcon, | |
1658 | .tree_disconnect = SMB2_tdis, | |
34f62640 | 1659 | .qfs_tcon = smb2_qfs_tcon, |
53ef1016 PS |
1660 | .is_path_accessible = smb2_is_path_accessible, |
1661 | .can_echo = smb2_can_echo, | |
1662 | .echo = SMB2_echo, | |
1663 | .query_path_info = smb2_query_path_info, | |
1664 | .get_srv_inum = smb2_get_srv_inum, | |
1665 | .query_file_info = smb2_query_file_info, | |
1666 | .set_path_size = smb2_set_path_size, | |
1667 | .set_file_size = smb2_set_file_size, | |
1668 | .set_file_info = smb2_set_file_info, | |
64a5cfa6 | 1669 | .set_compression = smb2_set_compression, |
53ef1016 PS |
1670 | .mkdir = smb2_mkdir, |
1671 | .mkdir_setinfo = smb2_mkdir_setinfo, | |
1672 | .rmdir = smb2_rmdir, | |
1673 | .unlink = smb2_unlink, | |
1674 | .rename = smb2_rename_path, | |
1675 | .create_hardlink = smb2_create_hardlink, | |
1676 | .query_symlink = smb2_query_symlink, | |
c22870ea | 1677 | .query_mf_symlink = smb3_query_mf_symlink, |
5ab97578 | 1678 | .create_mf_symlink = smb3_create_mf_symlink, |
53ef1016 PS |
1679 | .open = smb2_open_file, |
1680 | .set_fid = smb2_set_fid, | |
1681 | .close = smb2_close_file, | |
1682 | .flush = smb2_flush_file, | |
1683 | .async_readv = smb2_async_readv, | |
1684 | .async_writev = smb2_async_writev, | |
1685 | .sync_read = smb2_sync_read, | |
1686 | .sync_write = smb2_sync_write, | |
1687 | .query_dir_first = smb2_query_dir_first, | |
1688 | .query_dir_next = smb2_query_dir_next, | |
1689 | .close_dir = smb2_close_dir, | |
1690 | .calc_smb_size = smb2_calc_size, | |
1691 | .is_status_pending = smb2_is_status_pending, | |
1692 | .oplock_response = smb2_oplock_response, | |
1693 | .queryfs = smb2_queryfs, | |
1694 | .mand_lock = smb2_mand_lock, | |
1695 | .mand_unlock_range = smb2_unlock_range, | |
1696 | .push_mand_locks = smb2_push_mandatory_locks, | |
1697 | .get_lease_key = smb2_get_lease_key, | |
1698 | .set_lease_key = smb2_set_lease_key, | |
1699 | .new_lease_key = smb2_new_lease_key, | |
1700 | .calc_signature = smb2_calc_signature, | |
1701 | .is_read_op = smb21_is_read_op, | |
1702 | .set_oplock_level = smb21_set_oplock_level, | |
a41a28bd | 1703 | .create_lease_buf = smb2_create_lease_buf, |
b5c7cde3 | 1704 | .parse_lease_buf = smb2_parse_lease_buf, |
41c1358e | 1705 | .clone_range = smb2_clone_range, |
7f6c5008 | 1706 | .wp_retry_size = smb2_wp_retry_size, |
52755808 | 1707 | .dir_needs_close = smb2_dir_needs_close, |
834170c8 | 1708 | .enum_snapshots = smb3_enum_snapshots, |
53ef1016 | 1709 | }; |
38107d45 SF |
1710 | |
1711 | struct smb_version_operations smb30_operations = { | |
1712 | .compare_fids = smb2_compare_fids, | |
1713 | .setup_request = smb2_setup_request, | |
1714 | .setup_async_request = smb2_setup_async_request, | |
1715 | .check_receive = smb2_check_receive, | |
1716 | .add_credits = smb2_add_credits, | |
1717 | .set_credits = smb2_set_credits, | |
1718 | .get_credits_field = smb2_get_credits_field, | |
1719 | .get_credits = smb2_get_credits, | |
cb7e9eab | 1720 | .wait_mtu_credits = smb2_wait_mtu_credits, |
38107d45 SF |
1721 | .get_next_mid = smb2_get_next_mid, |
1722 | .read_data_offset = smb2_read_data_offset, | |
1723 | .read_data_length = smb2_read_data_length, | |
1724 | .map_error = map_smb2_to_linux_error, | |
1725 | .find_mid = smb2_find_mid, | |
1726 | .check_message = smb2_check_message, | |
1727 | .dump_detail = smb2_dump_detail, | |
1728 | .clear_stats = smb2_clear_stats, | |
1729 | .print_stats = smb2_print_stats, | |
769ee6a4 | 1730 | .dump_share_caps = smb2_dump_share_caps, |
38107d45 | 1731 | .is_oplock_break = smb2_is_valid_oplock_break, |
c11f1df5 | 1732 | .downgrade_oplock = smb2_downgrade_oplock, |
38107d45 SF |
1733 | .need_neg = smb2_need_neg, |
1734 | .negotiate = smb2_negotiate, | |
1735 | .negotiate_wsize = smb2_negotiate_wsize, | |
1736 | .negotiate_rsize = smb2_negotiate_rsize, | |
1737 | .sess_setup = SMB2_sess_setup, | |
1738 | .logoff = SMB2_logoff, | |
1739 | .tree_connect = SMB2_tcon, | |
1740 | .tree_disconnect = SMB2_tdis, | |
af6a12ea | 1741 | .qfs_tcon = smb3_qfs_tcon, |
38107d45 SF |
1742 | .is_path_accessible = smb2_is_path_accessible, |
1743 | .can_echo = smb2_can_echo, | |
1744 | .echo = SMB2_echo, | |
1745 | .query_path_info = smb2_query_path_info, | |
1746 | .get_srv_inum = smb2_get_srv_inum, | |
1747 | .query_file_info = smb2_query_file_info, | |
1748 | .set_path_size = smb2_set_path_size, | |
1749 | .set_file_size = smb2_set_file_size, | |
1750 | .set_file_info = smb2_set_file_info, | |
64a5cfa6 | 1751 | .set_compression = smb2_set_compression, |
38107d45 SF |
1752 | .mkdir = smb2_mkdir, |
1753 | .mkdir_setinfo = smb2_mkdir_setinfo, | |
1754 | .rmdir = smb2_rmdir, | |
1755 | .unlink = smb2_unlink, | |
1756 | .rename = smb2_rename_path, | |
1757 | .create_hardlink = smb2_create_hardlink, | |
b42bf888 | 1758 | .query_symlink = smb2_query_symlink, |
c22870ea | 1759 | .query_mf_symlink = smb3_query_mf_symlink, |
5ab97578 | 1760 | .create_mf_symlink = smb3_create_mf_symlink, |
38107d45 SF |
1761 | .open = smb2_open_file, |
1762 | .set_fid = smb2_set_fid, | |
1763 | .close = smb2_close_file, | |
1764 | .flush = smb2_flush_file, | |
1765 | .async_readv = smb2_async_readv, | |
1766 | .async_writev = smb2_async_writev, | |
1767 | .sync_read = smb2_sync_read, | |
1768 | .sync_write = smb2_sync_write, | |
1769 | .query_dir_first = smb2_query_dir_first, | |
1770 | .query_dir_next = smb2_query_dir_next, | |
1771 | .close_dir = smb2_close_dir, | |
1772 | .calc_smb_size = smb2_calc_size, | |
1773 | .is_status_pending = smb2_is_status_pending, | |
1774 | .oplock_response = smb2_oplock_response, | |
1775 | .queryfs = smb2_queryfs, | |
1776 | .mand_lock = smb2_mand_lock, | |
1777 | .mand_unlock_range = smb2_unlock_range, | |
1778 | .push_mand_locks = smb2_push_mandatory_locks, | |
1779 | .get_lease_key = smb2_get_lease_key, | |
1780 | .set_lease_key = smb2_set_lease_key, | |
1781 | .new_lease_key = smb2_new_lease_key, | |
373512ec | 1782 | .generate_signingkey = generate_smb30signingkey, |
38107d45 | 1783 | .calc_signature = smb3_calc_signature, |
b3152e2c | 1784 | .set_integrity = smb3_set_integrity, |
53ef1016 | 1785 | .is_read_op = smb21_is_read_op, |
42873b0a | 1786 | .set_oplock_level = smb3_set_oplock_level, |
f047390a PS |
1787 | .create_lease_buf = smb3_create_lease_buf, |
1788 | .parse_lease_buf = smb3_parse_lease_buf, | |
41c1358e | 1789 | .clone_range = smb2_clone_range, |
ca9e7a1c | 1790 | .duplicate_extents = smb2_duplicate_extents, |
ff1c038a | 1791 | .validate_negotiate = smb3_validate_negotiate, |
7f6c5008 | 1792 | .wp_retry_size = smb2_wp_retry_size, |
52755808 | 1793 | .dir_needs_close = smb2_dir_needs_close, |
31742c5a | 1794 | .fallocate = smb3_fallocate, |
834170c8 | 1795 | .enum_snapshots = smb3_enum_snapshots, |
1080ef75 SF |
1796 | }; |
1797 | ||
aab1893d SF |
1798 | #ifdef CONFIG_CIFS_SMB311 |
1799 | struct smb_version_operations smb311_operations = { | |
1800 | .compare_fids = smb2_compare_fids, | |
1801 | .setup_request = smb2_setup_request, | |
1802 | .setup_async_request = smb2_setup_async_request, | |
1803 | .check_receive = smb2_check_receive, | |
1804 | .add_credits = smb2_add_credits, | |
1805 | .set_credits = smb2_set_credits, | |
1806 | .get_credits_field = smb2_get_credits_field, | |
1807 | .get_credits = smb2_get_credits, | |
1808 | .wait_mtu_credits = smb2_wait_mtu_credits, | |
1809 | .get_next_mid = smb2_get_next_mid, | |
1810 | .read_data_offset = smb2_read_data_offset, | |
1811 | .read_data_length = smb2_read_data_length, | |
1812 | .map_error = map_smb2_to_linux_error, | |
1813 | .find_mid = smb2_find_mid, | |
1814 | .check_message = smb2_check_message, | |
1815 | .dump_detail = smb2_dump_detail, | |
1816 | .clear_stats = smb2_clear_stats, | |
1817 | .print_stats = smb2_print_stats, | |
1818 | .dump_share_caps = smb2_dump_share_caps, | |
1819 | .is_oplock_break = smb2_is_valid_oplock_break, | |
1820 | .downgrade_oplock = smb2_downgrade_oplock, | |
1821 | .need_neg = smb2_need_neg, | |
1822 | .negotiate = smb2_negotiate, | |
1823 | .negotiate_wsize = smb2_negotiate_wsize, | |
1824 | .negotiate_rsize = smb2_negotiate_rsize, | |
1825 | .sess_setup = SMB2_sess_setup, | |
1826 | .logoff = SMB2_logoff, | |
1827 | .tree_connect = SMB2_tcon, | |
1828 | .tree_disconnect = SMB2_tdis, | |
1829 | .qfs_tcon = smb3_qfs_tcon, | |
1830 | .is_path_accessible = smb2_is_path_accessible, | |
1831 | .can_echo = smb2_can_echo, | |
1832 | .echo = SMB2_echo, | |
1833 | .query_path_info = smb2_query_path_info, | |
1834 | .get_srv_inum = smb2_get_srv_inum, | |
1835 | .query_file_info = smb2_query_file_info, | |
1836 | .set_path_size = smb2_set_path_size, | |
1837 | .set_file_size = smb2_set_file_size, | |
1838 | .set_file_info = smb2_set_file_info, | |
1839 | .set_compression = smb2_set_compression, | |
1840 | .mkdir = smb2_mkdir, | |
1841 | .mkdir_setinfo = smb2_mkdir_setinfo, | |
1842 | .rmdir = smb2_rmdir, | |
1843 | .unlink = smb2_unlink, | |
1844 | .rename = smb2_rename_path, | |
1845 | .create_hardlink = smb2_create_hardlink, | |
1846 | .query_symlink = smb2_query_symlink, | |
1847 | .query_mf_symlink = smb3_query_mf_symlink, | |
1848 | .create_mf_symlink = smb3_create_mf_symlink, | |
1849 | .open = smb2_open_file, | |
1850 | .set_fid = smb2_set_fid, | |
1851 | .close = smb2_close_file, | |
1852 | .flush = smb2_flush_file, | |
1853 | .async_readv = smb2_async_readv, | |
1854 | .async_writev = smb2_async_writev, | |
1855 | .sync_read = smb2_sync_read, | |
1856 | .sync_write = smb2_sync_write, | |
1857 | .query_dir_first = smb2_query_dir_first, | |
1858 | .query_dir_next = smb2_query_dir_next, | |
1859 | .close_dir = smb2_close_dir, | |
1860 | .calc_smb_size = smb2_calc_size, | |
1861 | .is_status_pending = smb2_is_status_pending, | |
1862 | .oplock_response = smb2_oplock_response, | |
1863 | .queryfs = smb2_queryfs, | |
1864 | .mand_lock = smb2_mand_lock, | |
1865 | .mand_unlock_range = smb2_unlock_range, | |
1866 | .push_mand_locks = smb2_push_mandatory_locks, | |
1867 | .get_lease_key = smb2_get_lease_key, | |
1868 | .set_lease_key = smb2_set_lease_key, | |
1869 | .new_lease_key = smb2_new_lease_key, | |
373512ec | 1870 | .generate_signingkey = generate_smb311signingkey, |
aab1893d | 1871 | .calc_signature = smb3_calc_signature, |
b3152e2c | 1872 | .set_integrity = smb3_set_integrity, |
aab1893d SF |
1873 | .is_read_op = smb21_is_read_op, |
1874 | .set_oplock_level = smb3_set_oplock_level, | |
1875 | .create_lease_buf = smb3_create_lease_buf, | |
1876 | .parse_lease_buf = smb3_parse_lease_buf, | |
1877 | .clone_range = smb2_clone_range, | |
02b16665 | 1878 | .duplicate_extents = smb2_duplicate_extents, |
aab1893d SF |
1879 | /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */ |
1880 | .wp_retry_size = smb2_wp_retry_size, | |
1881 | .dir_needs_close = smb2_dir_needs_close, | |
1882 | .fallocate = smb3_fallocate, | |
834170c8 | 1883 | .enum_snapshots = smb3_enum_snapshots, |
aab1893d SF |
1884 | }; |
1885 | #endif /* CIFS_SMB311 */ | |
1886 | ||
dd446b16 SF |
1887 | struct smb_version_values smb20_values = { |
1888 | .version_string = SMB20_VERSION_STRING, | |
1889 | .protocol_id = SMB20_PROT_ID, | |
1890 | .req_capabilities = 0, /* MBZ */ | |
1891 | .large_lock_type = 0, | |
1892 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, | |
1893 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, | |
1894 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, | |
1895 | .header_size = sizeof(struct smb2_hdr), | |
1896 | .max_header_size = MAX_SMB2_HDR_SIZE, | |
1897 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, | |
1898 | .lock_cmd = SMB2_LOCK, | |
1899 | .cap_unix = 0, | |
1900 | .cap_nt_find = SMB2_NT_FIND, | |
1901 | .cap_large_files = SMB2_LARGE_FILES, | |
50285882 JL |
1902 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
1903 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, | |
a41a28bd | 1904 | .create_lease_size = sizeof(struct create_lease), |
dd446b16 SF |
1905 | }; |
1906 | ||
1080ef75 SF |
1907 | struct smb_version_values smb21_values = { |
1908 | .version_string = SMB21_VERSION_STRING, | |
e4aa25e7 SF |
1909 | .protocol_id = SMB21_PROT_ID, |
1910 | .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */ | |
1911 | .large_lock_type = 0, | |
1912 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, | |
1913 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, | |
1914 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, | |
1915 | .header_size = sizeof(struct smb2_hdr), | |
1916 | .max_header_size = MAX_SMB2_HDR_SIZE, | |
1917 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, | |
1918 | .lock_cmd = SMB2_LOCK, | |
1919 | .cap_unix = 0, | |
1920 | .cap_nt_find = SMB2_NT_FIND, | |
1921 | .cap_large_files = SMB2_LARGE_FILES, | |
50285882 JL |
1922 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
1923 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, | |
a41a28bd | 1924 | .create_lease_size = sizeof(struct create_lease), |
e4aa25e7 SF |
1925 | }; |
1926 | ||
1927 | struct smb_version_values smb30_values = { | |
1928 | .version_string = SMB30_VERSION_STRING, | |
1929 | .protocol_id = SMB30_PROT_ID, | |
373512ec | 1930 | .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION, |
027e8eec PS |
1931 | .large_lock_type = 0, |
1932 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, | |
1933 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, | |
1934 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, | |
093b2bda PS |
1935 | .header_size = sizeof(struct smb2_hdr), |
1936 | .max_header_size = MAX_SMB2_HDR_SIZE, | |
09a4707e | 1937 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
2dc7e1c0 | 1938 | .lock_cmd = SMB2_LOCK, |
29e20f9c PS |
1939 | .cap_unix = 0, |
1940 | .cap_nt_find = SMB2_NT_FIND, | |
1941 | .cap_large_files = SMB2_LARGE_FILES, | |
50285882 JL |
1942 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
1943 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, | |
f047390a | 1944 | .create_lease_size = sizeof(struct create_lease_v2), |
1080ef75 | 1945 | }; |
20b6d8b4 SF |
1946 | |
1947 | struct smb_version_values smb302_values = { | |
1948 | .version_string = SMB302_VERSION_STRING, | |
1949 | .protocol_id = SMB302_PROT_ID, | |
373512ec | 1950 | .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION, |
20b6d8b4 SF |
1951 | .large_lock_type = 0, |
1952 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, | |
1953 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, | |
1954 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, | |
1955 | .header_size = sizeof(struct smb2_hdr), | |
1956 | .max_header_size = MAX_SMB2_HDR_SIZE, | |
1957 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, | |
1958 | .lock_cmd = SMB2_LOCK, | |
1959 | .cap_unix = 0, | |
1960 | .cap_nt_find = SMB2_NT_FIND, | |
1961 | .cap_large_files = SMB2_LARGE_FILES, | |
50285882 JL |
1962 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
1963 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, | |
f047390a | 1964 | .create_lease_size = sizeof(struct create_lease_v2), |
20b6d8b4 | 1965 | }; |
5f7fbf73 SF |
1966 | |
1967 | #ifdef CONFIG_CIFS_SMB311 | |
1968 | struct smb_version_values smb311_values = { | |
1969 | .version_string = SMB311_VERSION_STRING, | |
1970 | .protocol_id = SMB311_PROT_ID, | |
b618f001 | 1971 | .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES, |
5f7fbf73 SF |
1972 | .large_lock_type = 0, |
1973 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, | |
1974 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, | |
1975 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, | |
1976 | .header_size = sizeof(struct smb2_hdr), | |
1977 | .max_header_size = MAX_SMB2_HDR_SIZE, | |
1978 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, | |
1979 | .lock_cmd = SMB2_LOCK, | |
1980 | .cap_unix = 0, | |
1981 | .cap_nt_find = SMB2_NT_FIND, | |
1982 | .cap_large_files = SMB2_LARGE_FILES, | |
1983 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, | |
1984 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, | |
1985 | .create_lease_size = sizeof(struct create_lease_v2), | |
1986 | }; | |
1987 | #endif /* SMB311 */ |