blob: 378260cd25a6216fd26bccd026eeac8fc7b5bf8e [file] [log] [blame]
Steve French1080ef72011-02-24 18:07:19 +00001/*
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
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -070020#include <linux/pagemap.h>
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -070021#include <linux/vfs.h>
Steve Frenchf29ebb42014-07-19 21:44:58 -050022#include <linux/falloc.h>
Steve French1080ef72011-02-24 18:07:19 +000023#include "cifsglob.h"
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +040024#include "smb2pdu.h"
25#include "smb2proto.h"
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040026#include "cifsproto.h"
27#include "cifs_debug.h"
Pavel Shilovskyb42bf882013-08-14 19:25:21 +040028#include "cifs_unicode.h"
Pavel Shilovsky2e44b282012-09-18 16:20:33 -070029#include "smb2status.h"
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -070030#include "smb2glob.h"
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040031
32static int
33change_conf(struct TCP_Server_Info *server)
34{
35 server->credits += server->echo_credits + server->oplock_credits;
36 server->oplock_credits = server->echo_credits = 0;
37 switch (server->credits) {
38 case 0:
39 return -1;
40 case 1:
41 server->echoes = false;
42 server->oplocks = false;
Joe Perchesf96637b2013-05-04 22:12:25 -050043 cifs_dbg(VFS, "disabling echoes and oplocks\n");
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040044 break;
45 case 2:
46 server->echoes = true;
47 server->oplocks = false;
48 server->echo_credits = 1;
Joe Perchesf96637b2013-05-04 22:12:25 -050049 cifs_dbg(FYI, "disabling oplocks\n");
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040050 break;
51 default:
52 server->echoes = true;
Steve Frenche0ddde92015-09-22 09:29:38 -050053 if (enable_oplocks) {
54 server->oplocks = true;
55 server->oplock_credits = 1;
56 } else
57 server->oplocks = false;
58
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040059 server->echo_credits = 1;
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040060 }
61 server->credits -= server->echo_credits + server->oplock_credits;
62 return 0;
63}
64
65static void
66smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add,
67 const int optype)
68{
69 int *val, rc = 0;
70 spin_lock(&server->req_lock);
71 val = server->ops->get_credits_field(server, optype);
72 *val += add;
Steve French141891f2016-09-23 00:44:16 -050073 if (*val > 65000) {
74 *val = 65000; /* Don't get near 64K credits, avoid srv bugs */
75 printk_once(KERN_WARNING "server overflowed SMB3 credits\n");
76 }
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040077 server->in_flight--;
Pavel Shilovskyec2e4522011-12-27 16:12:43 +040078 if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP)
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040079 rc = change_conf(server);
Pavel Shilovsky983c88a2012-09-18 16:20:33 -070080 /*
81 * Sometimes server returns 0 credits on oplock break ack - we need to
82 * rebalance credits in this case.
83 */
84 else if (server->in_flight > 0 && server->oplock_credits == 0 &&
85 server->oplocks) {
86 if (server->credits > 1) {
87 server->credits--;
88 server->oplock_credits++;
89 }
90 }
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040091 spin_unlock(&server->req_lock);
92 wake_up(&server->request_q);
93 if (rc)
94 cifs_reconnect(server);
95}
96
97static void
98smb2_set_credits(struct TCP_Server_Info *server, const int val)
99{
100 spin_lock(&server->req_lock);
101 server->credits = val;
102 spin_unlock(&server->req_lock);
103}
104
105static int *
106smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
107{
108 switch (optype) {
109 case CIFS_ECHO_OP:
110 return &server->echo_credits;
111 case CIFS_OBREAK_OP:
112 return &server->oplock_credits;
113 default:
114 return &server->credits;
115 }
116}
117
118static unsigned int
119smb2_get_credits(struct mid_q_entry *mid)
120{
121 return le16_to_cpu(((struct smb2_hdr *)mid->resp_buf)->CreditRequest);
122}
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +0400123
Pavel Shilovskycb7e9ea2014-06-05 19:03:27 +0400124static int
125smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size,
126 unsigned int *num, unsigned int *credits)
127{
128 int rc = 0;
129 unsigned int scredits;
130
131 spin_lock(&server->req_lock);
132 while (1) {
133 if (server->credits <= 0) {
134 spin_unlock(&server->req_lock);
135 cifs_num_waiters_inc(server);
136 rc = wait_event_killable(server->request_q,
137 has_credits(server, &server->credits));
138 cifs_num_waiters_dec(server);
139 if (rc)
140 return rc;
141 spin_lock(&server->req_lock);
142 } else {
143 if (server->tcpStatus == CifsExiting) {
144 spin_unlock(&server->req_lock);
145 return -ENOENT;
146 }
147
148 scredits = server->credits;
149 /* can deadlock with reopen */
150 if (scredits == 1) {
151 *num = SMB2_MAX_BUFFER_SIZE;
152 *credits = 0;
153 break;
154 }
155
156 /* leave one credit for a possible reopen */
157 scredits--;
158 *num = min_t(unsigned int, size,
159 scredits * SMB2_MAX_BUFFER_SIZE);
160
161 *credits = DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE);
162 server->credits -= *credits;
163 server->in_flight++;
164 break;
165 }
166 }
167 spin_unlock(&server->req_lock);
168 return rc;
169}
170
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +0400171static __u64
172smb2_get_next_mid(struct TCP_Server_Info *server)
173{
174 __u64 mid;
175 /* for SMB2 we need the current value */
176 spin_lock(&GlobalMid_Lock);
177 mid = server->CurrentMid++;
178 spin_unlock(&GlobalMid_Lock);
179 return mid;
180}
Steve French1080ef72011-02-24 18:07:19 +0000181
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400182static struct mid_q_entry *
183smb2_find_mid(struct TCP_Server_Info *server, char *buf)
184{
185 struct mid_q_entry *mid;
186 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
Sachin Prabhu9235d092014-12-09 17:37:00 +0000187 __u64 wire_mid = le64_to_cpu(hdr->MessageId);
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400188
Steve French373512e2015-12-18 13:05:30 -0600189 if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) {
190 cifs_dbg(VFS, "encrypted frame parsing not supported yet");
191 return NULL;
192 }
193
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400194 spin_lock(&GlobalMid_Lock);
195 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
Sachin Prabhu9235d092014-12-09 17:37:00 +0000196 if ((mid->mid == wire_mid) &&
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400197 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
198 (mid->command == hdr->Command)) {
199 spin_unlock(&GlobalMid_Lock);
200 return mid;
201 }
202 }
203 spin_unlock(&GlobalMid_Lock);
204 return NULL;
205}
206
207static void
208smb2_dump_detail(void *buf)
209{
210#ifdef CONFIG_CIFS_DEBUG2
211 struct smb2_hdr *smb = (struct smb2_hdr *)buf;
212
Joe Perchesf96637b2013-05-04 22:12:25 -0500213 cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
214 smb->Command, smb->Status, smb->Flags, smb->MessageId,
215 smb->ProcessId);
216 cifs_dbg(VFS, "smb buf %p len %u\n", smb, smb2_calc_size(smb));
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400217#endif
218}
219
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400220static bool
221smb2_need_neg(struct TCP_Server_Info *server)
222{
223 return server->max_read == 0;
224}
225
226static int
227smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
228{
229 int rc;
230 ses->server->CurrentMid = 0;
231 rc = SMB2_negotiate(xid, ses);
232 /* BB we probably don't need to retry with modern servers */
233 if (rc == -EAGAIN)
234 rc = -EHOSTDOWN;
235 return rc;
236}
237
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700238static unsigned int
239smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
240{
241 struct TCP_Server_Info *server = tcon->ses->server;
242 unsigned int wsize;
243
244 /* start with specified wsize, or default */
245 wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
246 wsize = min_t(unsigned int, wsize, server->max_write);
Pavel Shilovskycb7e9ea2014-06-05 19:03:27 +0400247
248 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
249 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700250
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700251 return wsize;
252}
253
254static unsigned int
255smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
256{
257 struct TCP_Server_Info *server = tcon->ses->server;
258 unsigned int rsize;
259
260 /* start with specified rsize, or default */
261 rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
262 rsize = min_t(unsigned int, rsize, server->max_read);
Pavel Shilovskybed9da02014-06-25 11:28:57 +0400263
264 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
265 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700266
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700267 return rsize;
268}
269
Steve Frenchc481e9f2013-10-14 01:21:53 -0500270#ifdef CONFIG_CIFS_STATS2
271static int
272SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon)
273{
274 int rc;
275 unsigned int ret_data_len = 0;
276 struct network_interface_info_ioctl_rsp *out_buf;
277
278 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
279 FSCTL_QUERY_NETWORK_INTERFACE_INFO, true /* is_fsctl */,
280 NULL /* no data input */, 0 /* no data input */,
281 (char **)&out_buf, &ret_data_len);
Steve French9ffc5412014-10-16 15:13:14 -0500282 if (rc != 0)
283 cifs_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
284 else if (ret_data_len < sizeof(struct network_interface_info_ioctl_rsp)) {
285 cifs_dbg(VFS, "server returned bad net interface info buf\n");
286 rc = -EINVAL;
287 } else {
Steve Frenchc481e9f2013-10-14 01:21:53 -0500288 /* Dump info on first interface */
289 cifs_dbg(FYI, "Adapter Capability 0x%x\t",
290 le32_to_cpu(out_buf->Capability));
291 cifs_dbg(FYI, "Link Speed %lld\n",
292 le64_to_cpu(out_buf->LinkSpeed));
Steve French9ffc5412014-10-16 15:13:14 -0500293 }
Steve Frenchc481e9f2013-10-14 01:21:53 -0500294
295 return rc;
296}
297#endif /* STATS2 */
298
Steve French34f62642013-10-09 02:07:00 -0500299static void
Steven Frenchaf6a12e2013-10-09 20:55:53 -0500300smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
301{
302 int rc;
303 __le16 srch_path = 0; /* Null - open root of share */
304 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
305 struct cifs_open_parms oparms;
306 struct cifs_fid fid;
307
308 oparms.tcon = tcon;
309 oparms.desired_access = FILE_READ_ATTRIBUTES;
310 oparms.disposition = FILE_OPEN;
311 oparms.create_options = 0;
312 oparms.fid = &fid;
313 oparms.reconnect = false;
314
315 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
316 if (rc)
317 return;
318
Steve Frenchc481e9f2013-10-14 01:21:53 -0500319#ifdef CONFIG_CIFS_STATS2
320 SMB3_request_interfaces(xid, tcon);
321#endif /* STATS2 */
322
Steven Frenchaf6a12e2013-10-09 20:55:53 -0500323 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
324 FS_ATTRIBUTE_INFORMATION);
325 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
326 FS_DEVICE_INFORMATION);
327 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
328 FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
329 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
330 return;
331}
332
333static void
Steve French34f62642013-10-09 02:07:00 -0500334smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
335{
336 int rc;
337 __le16 srch_path = 0; /* Null - open root of share */
338 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
339 struct cifs_open_parms oparms;
340 struct cifs_fid fid;
341
342 oparms.tcon = tcon;
343 oparms.desired_access = FILE_READ_ATTRIBUTES;
344 oparms.disposition = FILE_OPEN;
345 oparms.create_options = 0;
346 oparms.fid = &fid;
347 oparms.reconnect = false;
348
349 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
350 if (rc)
351 return;
352
Steven French21671142013-10-09 13:36:35 -0500353 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
354 FS_ATTRIBUTE_INFORMATION);
355 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
356 FS_DEVICE_INFORMATION);
Steve French34f62642013-10-09 02:07:00 -0500357 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
358 return;
359}
360
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400361static int
362smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
363 struct cifs_sb_info *cifs_sb, const char *full_path)
364{
365 int rc;
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400366 __le16 *utf16_path;
Pavel Shilovsky2e44b282012-09-18 16:20:33 -0700367 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400368 struct cifs_open_parms oparms;
369 struct cifs_fid fid;
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400370
371 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
372 if (!utf16_path)
373 return -ENOMEM;
374
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400375 oparms.tcon = tcon;
376 oparms.desired_access = FILE_READ_ATTRIBUTES;
377 oparms.disposition = FILE_OPEN;
378 oparms.create_options = 0;
379 oparms.fid = &fid;
Pavel Shilovsky9cbc0b72013-07-09 18:40:58 +0400380 oparms.reconnect = false;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400381
Pavel Shilovskyb42bf882013-08-14 19:25:21 +0400382 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400383 if (rc) {
384 kfree(utf16_path);
385 return rc;
386 }
387
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400388 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400389 kfree(utf16_path);
390 return rc;
391}
392
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +0400393static int
394smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
395 struct cifs_sb_info *cifs_sb, const char *full_path,
396 u64 *uniqueid, FILE_ALL_INFO *data)
397{
398 *uniqueid = le64_to_cpu(data->IndexNumber);
399 return 0;
400}
401
Pavel Shilovskyb7546bc2012-09-18 16:20:27 -0700402static int
403smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
404 struct cifs_fid *fid, FILE_ALL_INFO *data)
405{
406 int rc;
407 struct smb2_file_all_info *smb2_data;
408
Pavel Shilovsky1bbe4992014-08-22 13:32:11 +0400409 smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
Pavel Shilovskyb7546bc2012-09-18 16:20:27 -0700410 GFP_KERNEL);
411 if (smb2_data == NULL)
412 return -ENOMEM;
413
414 rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
415 smb2_data);
416 if (!rc)
417 move_smb2_info_to_cifs(data, smb2_data);
418 kfree(smb2_data);
419 return rc;
420}
421
Pavel Shilovsky9094fad2012-07-12 18:30:44 +0400422static bool
423smb2_can_echo(struct TCP_Server_Info *server)
424{
425 return server->echoes;
426}
427
Pavel Shilovskyd60622e2012-05-28 15:19:39 +0400428static void
429smb2_clear_stats(struct cifs_tcon *tcon)
430{
431#ifdef CONFIG_CIFS_STATS
432 int i;
433 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
434 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
435 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
436 }
437#endif
438}
439
440static void
Steve French769ee6a2013-06-19 14:15:30 -0500441smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
442{
443 seq_puts(m, "\n\tShare Capabilities:");
444 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
445 seq_puts(m, " DFS,");
446 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
447 seq_puts(m, " CONTINUOUS AVAILABILITY,");
448 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
449 seq_puts(m, " SCALEOUT,");
450 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
451 seq_puts(m, " CLUSTER,");
452 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
453 seq_puts(m, " ASYMMETRIC,");
454 if (tcon->capabilities == 0)
455 seq_puts(m, " None");
Steven Frenchaf6a12e2013-10-09 20:55:53 -0500456 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
457 seq_puts(m, " Aligned,");
458 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
459 seq_puts(m, " Partition Aligned,");
460 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
461 seq_puts(m, " SSD,");
462 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
463 seq_puts(m, " TRIM-support,");
464
Steve French769ee6a2013-06-19 14:15:30 -0500465 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
Steven Frenchaf6a12e2013-10-09 20:55:53 -0500466 if (tcon->perf_sector_size)
467 seq_printf(m, "\tOptimal sector size: 0x%x",
468 tcon->perf_sector_size);
Steve French769ee6a2013-06-19 14:15:30 -0500469}
470
471static void
Pavel Shilovskyd60622e2012-05-28 15:19:39 +0400472smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
473{
474#ifdef CONFIG_CIFS_STATS
475 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
476 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
477 seq_printf(m, "\nNegotiates: %d sent %d failed",
478 atomic_read(&sent[SMB2_NEGOTIATE_HE]),
479 atomic_read(&failed[SMB2_NEGOTIATE_HE]));
480 seq_printf(m, "\nSessionSetups: %d sent %d failed",
481 atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
482 atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
Pavel Shilovskyd60622e2012-05-28 15:19:39 +0400483 seq_printf(m, "\nLogoffs: %d sent %d failed",
484 atomic_read(&sent[SMB2_LOGOFF_HE]),
485 atomic_read(&failed[SMB2_LOGOFF_HE]));
486 seq_printf(m, "\nTreeConnects: %d sent %d failed",
487 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
488 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
489 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
490 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
491 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
492 seq_printf(m, "\nCreates: %d sent %d failed",
493 atomic_read(&sent[SMB2_CREATE_HE]),
494 atomic_read(&failed[SMB2_CREATE_HE]));
495 seq_printf(m, "\nCloses: %d sent %d failed",
496 atomic_read(&sent[SMB2_CLOSE_HE]),
497 atomic_read(&failed[SMB2_CLOSE_HE]));
498 seq_printf(m, "\nFlushes: %d sent %d failed",
499 atomic_read(&sent[SMB2_FLUSH_HE]),
500 atomic_read(&failed[SMB2_FLUSH_HE]));
501 seq_printf(m, "\nReads: %d sent %d failed",
502 atomic_read(&sent[SMB2_READ_HE]),
503 atomic_read(&failed[SMB2_READ_HE]));
504 seq_printf(m, "\nWrites: %d sent %d failed",
505 atomic_read(&sent[SMB2_WRITE_HE]),
506 atomic_read(&failed[SMB2_WRITE_HE]));
507 seq_printf(m, "\nLocks: %d sent %d failed",
508 atomic_read(&sent[SMB2_LOCK_HE]),
509 atomic_read(&failed[SMB2_LOCK_HE]));
510 seq_printf(m, "\nIOCTLs: %d sent %d failed",
511 atomic_read(&sent[SMB2_IOCTL_HE]),
512 atomic_read(&failed[SMB2_IOCTL_HE]));
513 seq_printf(m, "\nCancels: %d sent %d failed",
514 atomic_read(&sent[SMB2_CANCEL_HE]),
515 atomic_read(&failed[SMB2_CANCEL_HE]));
516 seq_printf(m, "\nEchos: %d sent %d failed",
517 atomic_read(&sent[SMB2_ECHO_HE]),
518 atomic_read(&failed[SMB2_ECHO_HE]));
519 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
520 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
521 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
522 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
523 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
524 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
525 seq_printf(m, "\nQueryInfos: %d sent %d failed",
526 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
527 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
528 seq_printf(m, "\nSetInfos: %d sent %d failed",
529 atomic_read(&sent[SMB2_SET_INFO_HE]),
530 atomic_read(&failed[SMB2_SET_INFO_HE]));
531 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
532 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
533 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
534#endif
535}
536
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700537static void
538smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
539{
David Howells2b0143b2015-03-17 22:25:59 +0000540 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
Pavel Shilovsky53ef1012013-09-05 16:11:28 +0400541 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
542
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700543 cfile->fid.persistent_fid = fid->persistent_fid;
544 cfile->fid.volatile_fid = fid->volatile_fid;
Pavel Shilovsky42873b02013-09-05 21:30:16 +0400545 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
546 &fid->purge_cache);
Pavel Shilovsky18cceb62013-09-05 13:01:06 +0400547 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
Aurelien Aptel94f87372016-09-22 07:38:50 +0200548 memcpy(cfile->fid.create_guid, fid->create_guid, 16);
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700549}
550
Pavel Shilovsky760ad0c2012-09-25 11:00:07 +0400551static void
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700552smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
553 struct cifs_fid *fid)
554{
Pavel Shilovsky760ad0c2012-09-25 11:00:07 +0400555 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700556}
557
Pavel Shilovsky7a5cfb12012-09-18 16:20:28 -0700558static int
Steve French41c13582013-11-14 00:05:36 -0600559SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
560 u64 persistent_fid, u64 volatile_fid,
561 struct copychunk_ioctl *pcchunk)
562{
563 int rc;
564 unsigned int ret_data_len;
565 struct resume_key_req *res_key;
566
567 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
568 FSCTL_SRV_REQUEST_RESUME_KEY, true /* is_fsctl */,
569 NULL, 0 /* no input */,
570 (char **)&res_key, &ret_data_len);
571
572 if (rc) {
573 cifs_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
574 goto req_res_key_exit;
575 }
576 if (ret_data_len < sizeof(struct resume_key_req)) {
577 cifs_dbg(VFS, "Invalid refcopy resume key length\n");
578 rc = -EINVAL;
579 goto req_res_key_exit;
580 }
581 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
582
583req_res_key_exit:
584 kfree(res_key);
585 return rc;
586}
587
588static int
589smb2_clone_range(const unsigned int xid,
590 struct cifsFileInfo *srcfile,
591 struct cifsFileInfo *trgtfile, u64 src_off,
592 u64 len, u64 dest_off)
593{
594 int rc;
595 unsigned int ret_data_len;
596 struct copychunk_ioctl *pcchunk;
Steve French9bf0c9c2013-11-16 18:05:28 -0600597 struct copychunk_ioctl_rsp *retbuf = NULL;
598 struct cifs_tcon *tcon;
599 int chunks_copied = 0;
600 bool chunk_sizes_updated = false;
Steve French41c13582013-11-14 00:05:36 -0600601
602 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
603
604 if (pcchunk == NULL)
605 return -ENOMEM;
606
607 cifs_dbg(FYI, "in smb2_clone_range - about to call request res key\n");
608 /* Request a key from the server to identify the source of the copy */
609 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
610 srcfile->fid.persistent_fid,
611 srcfile->fid.volatile_fid, pcchunk);
612
613 /* Note: request_res_key sets res_key null only if rc !=0 */
614 if (rc)
Steve French9bf0c9c2013-11-16 18:05:28 -0600615 goto cchunk_out;
Steve French41c13582013-11-14 00:05:36 -0600616
617 /* For now array only one chunk long, will make more flexible later */
Fabian Frederickbc09d142014-12-10 15:41:15 -0800618 pcchunk->ChunkCount = cpu_to_le32(1);
Steve French41c13582013-11-14 00:05:36 -0600619 pcchunk->Reserved = 0;
Steve French41c13582013-11-14 00:05:36 -0600620 pcchunk->Reserved2 = 0;
621
Steve French9bf0c9c2013-11-16 18:05:28 -0600622 tcon = tlink_tcon(trgtfile->tlink);
623
624 while (len > 0) {
625 pcchunk->SourceOffset = cpu_to_le64(src_off);
626 pcchunk->TargetOffset = cpu_to_le64(dest_off);
627 pcchunk->Length =
628 cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
629
630 /* Request server copy to target from src identified by key */
631 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
Steve French41c13582013-11-14 00:05:36 -0600632 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
633 true /* is_fsctl */, (char *)pcchunk,
Steve French9bf0c9c2013-11-16 18:05:28 -0600634 sizeof(struct copychunk_ioctl), (char **)&retbuf,
635 &ret_data_len);
636 if (rc == 0) {
637 if (ret_data_len !=
638 sizeof(struct copychunk_ioctl_rsp)) {
639 cifs_dbg(VFS, "invalid cchunk response size\n");
640 rc = -EIO;
641 goto cchunk_out;
642 }
643 if (retbuf->TotalBytesWritten == 0) {
644 cifs_dbg(FYI, "no bytes copied\n");
645 rc = -EIO;
646 goto cchunk_out;
647 }
648 /*
649 * Check if server claimed to write more than we asked
650 */
651 if (le32_to_cpu(retbuf->TotalBytesWritten) >
652 le32_to_cpu(pcchunk->Length)) {
653 cifs_dbg(VFS, "invalid copy chunk response\n");
654 rc = -EIO;
655 goto cchunk_out;
656 }
657 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
658 cifs_dbg(VFS, "invalid num chunks written\n");
659 rc = -EIO;
660 goto cchunk_out;
661 }
662 chunks_copied++;
Steve French41c13582013-11-14 00:05:36 -0600663
Steve French9bf0c9c2013-11-16 18:05:28 -0600664 src_off += le32_to_cpu(retbuf->TotalBytesWritten);
665 dest_off += le32_to_cpu(retbuf->TotalBytesWritten);
666 len -= le32_to_cpu(retbuf->TotalBytesWritten);
Steve French41c13582013-11-14 00:05:36 -0600667
Steve French9bf0c9c2013-11-16 18:05:28 -0600668 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %d\n",
669 le32_to_cpu(retbuf->ChunksWritten),
670 le32_to_cpu(retbuf->ChunkBytesWritten),
671 le32_to_cpu(retbuf->TotalBytesWritten));
672 } else if (rc == -EINVAL) {
673 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
674 goto cchunk_out;
Steve French41c13582013-11-14 00:05:36 -0600675
Steve French9bf0c9c2013-11-16 18:05:28 -0600676 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
677 le32_to_cpu(retbuf->ChunksWritten),
678 le32_to_cpu(retbuf->ChunkBytesWritten),
679 le32_to_cpu(retbuf->TotalBytesWritten));
680
681 /*
682 * Check if this is the first request using these sizes,
683 * (ie check if copy succeed once with original sizes
684 * and check if the server gave us different sizes after
685 * we already updated max sizes on previous request).
686 * if not then why is the server returning an error now
687 */
688 if ((chunks_copied != 0) || chunk_sizes_updated)
689 goto cchunk_out;
690
691 /* Check that server is not asking us to grow size */
692 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
693 tcon->max_bytes_chunk)
694 tcon->max_bytes_chunk =
695 le32_to_cpu(retbuf->ChunkBytesWritten);
696 else
697 goto cchunk_out; /* server gave us bogus size */
698
699 /* No need to change MaxChunks since already set to 1 */
700 chunk_sizes_updated = true;
Sachin Prabhu2477bc52015-02-04 13:10:26 +0000701 } else
702 goto cchunk_out;
Steve French9bf0c9c2013-11-16 18:05:28 -0600703 }
704
705cchunk_out:
Steve French41c13582013-11-14 00:05:36 -0600706 kfree(pcchunk);
707 return rc;
708}
709
710static int
Pavel Shilovsky7a5cfb12012-09-18 16:20:28 -0700711smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
712 struct cifs_fid *fid)
713{
714 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
715}
716
Pavel Shilovsky09a47072012-09-18 16:20:29 -0700717static unsigned int
718smb2_read_data_offset(char *buf)
719{
720 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
721 return rsp->DataOffset;
722}
723
724static unsigned int
725smb2_read_data_length(char *buf)
726{
727 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
728 return le32_to_cpu(rsp->DataLength);
729}
730
Pavel Shilovskyd8e05032012-09-18 16:20:30 -0700731
732static int
Steve Frenchdb8b6312014-09-22 05:13:55 -0500733smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
Pavel Shilovskyd8e05032012-09-18 16:20:30 -0700734 struct cifs_io_parms *parms, unsigned int *bytes_read,
735 char **buf, int *buf_type)
736{
Steve Frenchdb8b6312014-09-22 05:13:55 -0500737 parms->persistent_fid = pfid->persistent_fid;
738 parms->volatile_fid = pfid->volatile_fid;
Pavel Shilovskyd8e05032012-09-18 16:20:30 -0700739 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
740}
741
Pavel Shilovsky009d3442012-09-18 16:20:30 -0700742static int
Steve Frenchdb8b6312014-09-22 05:13:55 -0500743smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
Pavel Shilovsky009d3442012-09-18 16:20:30 -0700744 struct cifs_io_parms *parms, unsigned int *written,
745 struct kvec *iov, unsigned long nr_segs)
746{
747
Steve Frenchdb8b6312014-09-22 05:13:55 -0500748 parms->persistent_fid = pfid->persistent_fid;
749 parms->volatile_fid = pfid->volatile_fid;
Pavel Shilovsky009d3442012-09-18 16:20:30 -0700750 return SMB2_write(xid, parms, written, iov, nr_segs);
751}
752
Steve Frenchd43cc792014-08-13 17:16:29 -0500753/* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
754static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
755 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
756{
757 struct cifsInodeInfo *cifsi;
758 int rc;
759
760 cifsi = CIFS_I(inode);
761
762 /* if file already sparse don't bother setting sparse again */
763 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
764 return true; /* already sparse */
765
766 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
767 return true; /* already not sparse */
768
769 /*
770 * Can't check for sparse support on share the usual way via the
771 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
772 * since Samba server doesn't set the flag on the share, yet
773 * supports the set sparse FSCTL and returns sparse correctly
774 * in the file attributes. If we fail setting sparse though we
775 * mark that server does not support sparse files for this share
776 * to avoid repeatedly sending the unsupported fsctl to server
777 * if the file is repeatedly extended.
778 */
779 if (tcon->broken_sparse_sup)
780 return false;
781
782 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
783 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
784 true /* is_fctl */, &setsparse, 1, NULL, NULL);
785 if (rc) {
786 tcon->broken_sparse_sup = true;
787 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
788 return false;
789 }
790
791 if (setsparse)
792 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
793 else
794 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
795
796 return true;
797}
798
Pavel Shilovskyc839ff22012-09-18 16:20:32 -0700799static int
800smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
801 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
802{
803 __le64 eof = cpu_to_le64(size);
Steve French3d1a3742014-08-11 21:05:25 -0500804 struct inode *inode;
805
806 /*
807 * If extending file more than one page make sparse. Many Linux fs
808 * make files sparse by default when extending via ftruncate
809 */
David Howells2b0143b2015-03-17 22:25:59 +0000810 inode = d_inode(cfile->dentry);
Steve French3d1a3742014-08-11 21:05:25 -0500811
812 if (!set_alloc && (size > inode->i_size + 8192)) {
Steve French3d1a3742014-08-11 21:05:25 -0500813 __u8 set_sparse = 1;
Steve French3d1a3742014-08-11 21:05:25 -0500814
Steve Frenchd43cc792014-08-13 17:16:29 -0500815 /* whether set sparse succeeds or not, extend the file */
816 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
Steve French3d1a3742014-08-11 21:05:25 -0500817 }
818
Pavel Shilovskyc839ff22012-09-18 16:20:32 -0700819 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
Steve Frenchf29ebb42014-07-19 21:44:58 -0500820 cfile->fid.volatile_fid, cfile->pid, &eof, false);
Pavel Shilovskyc839ff22012-09-18 16:20:32 -0700821}
822
Steve French02b16662015-06-27 21:18:36 -0700823static int
824smb2_duplicate_extents(const unsigned int xid,
825 struct cifsFileInfo *srcfile,
826 struct cifsFileInfo *trgtfile, u64 src_off,
827 u64 len, u64 dest_off)
828{
829 int rc;
830 unsigned int ret_data_len;
831 char *retbuf = NULL;
832 struct duplicate_extents_to_file dup_ext_buf;
833 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
834
835 /* server fileays advertise duplicate extent support with this flag */
836 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
837 FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
838 return -EOPNOTSUPP;
839
840 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
841 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
842 dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
843 dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
844 dup_ext_buf.ByteCount = cpu_to_le64(len);
845 cifs_dbg(FYI, "duplicate extents: src off %lld dst off %lld len %lld",
846 src_off, dest_off, len);
847
848 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
849 if (rc)
850 goto duplicate_extents_out;
851
852 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
853 trgtfile->fid.volatile_fid,
854 FSCTL_DUPLICATE_EXTENTS_TO_FILE,
855 true /* is_fsctl */, (char *)&dup_ext_buf,
856 sizeof(struct duplicate_extents_to_file),
857 (char **)&retbuf,
858 &ret_data_len);
859
860 if (ret_data_len > 0)
861 cifs_dbg(FYI, "non-zero response length in duplicate extents");
862
863duplicate_extents_out:
864 return rc;
865}
Steve French02b16662015-06-27 21:18:36 -0700866
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700867static int
Steve French64a5cfa2013-10-14 15:31:32 -0500868smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
869 struct cifsFileInfo *cfile)
870{
871 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
872 cfile->fid.volatile_fid);
873}
874
875static int
Steve Frenchb3152e22015-06-24 03:17:02 -0500876smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
877 struct cifsFileInfo *cfile)
878{
879 struct fsctl_set_integrity_information_req integr_info;
880 char *retbuf = NULL;
881 unsigned int ret_data_len;
882
883 integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
884 integr_info.Flags = 0;
885 integr_info.Reserved = 0;
886
887 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
888 cfile->fid.volatile_fid,
889 FSCTL_SET_INTEGRITY_INFORMATION,
890 true /* is_fsctl */, (char *)&integr_info,
891 sizeof(struct fsctl_set_integrity_information_req),
892 (char **)&retbuf,
893 &ret_data_len);
894
895}
896
897static int
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700898smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
899 const char *path, struct cifs_sb_info *cifs_sb,
900 struct cifs_fid *fid, __u16 search_flags,
901 struct cifs_search_info *srch_inf)
902{
903 __le16 *utf16_path;
904 int rc;
Pavel Shilovsky2e44b282012-09-18 16:20:33 -0700905 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400906 struct cifs_open_parms oparms;
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700907
908 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
909 if (!utf16_path)
910 return -ENOMEM;
911
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400912 oparms.tcon = tcon;
913 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
914 oparms.disposition = FILE_OPEN;
915 oparms.create_options = 0;
916 oparms.fid = fid;
Pavel Shilovsky9cbc0b72013-07-09 18:40:58 +0400917 oparms.reconnect = false;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400918
Pavel Shilovskyb42bf882013-08-14 19:25:21 +0400919 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700920 kfree(utf16_path);
921 if (rc) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500922 cifs_dbg(VFS, "open dir failed\n");
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700923 return rc;
924 }
925
926 srch_inf->entries_in_buffer = 0;
927 srch_inf->index_of_last_entry = 0;
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700928
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400929 rc = SMB2_query_directory(xid, tcon, fid->persistent_fid,
930 fid->volatile_fid, 0, srch_inf);
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700931 if (rc) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500932 cifs_dbg(VFS, "query directory failed\n");
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400933 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700934 }
935 return rc;
936}
937
938static int
939smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
940 struct cifs_fid *fid, __u16 search_flags,
941 struct cifs_search_info *srch_inf)
942{
943 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
944 fid->volatile_fid, 0, srch_inf);
945}
946
947static int
948smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
949 struct cifs_fid *fid)
950{
951 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
952}
953
Pavel Shilovsky2e44b282012-09-18 16:20:33 -0700954/*
955* If we negotiate SMB2 protocol and get STATUS_PENDING - update
956* the number of credits and return true. Otherwise - return false.
957*/
958static bool
959smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
960{
961 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
962
Steve French12e8a202012-09-19 09:19:39 -0700963 if (hdr->Status != STATUS_PENDING)
Pavel Shilovsky2e44b282012-09-18 16:20:33 -0700964 return false;
965
966 if (!length) {
967 spin_lock(&server->req_lock);
968 server->credits += le16_to_cpu(hdr->CreditRequest);
969 spin_unlock(&server->req_lock);
970 wake_up(&server->request_q);
971 }
972
973 return true;
974}
975
Pavel Shilovsky983c88a2012-09-18 16:20:33 -0700976static int
977smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
978 struct cifsInodeInfo *cinode)
979{
Pavel Shilovsky0822f512012-09-19 06:22:45 -0700980 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
981 return SMB2_lease_break(0, tcon, cinode->lease_key,
982 smb2_get_lease_state(cinode));
983
Pavel Shilovsky983c88a2012-09-18 16:20:33 -0700984 return SMB2_oplock_break(0, tcon, fid->persistent_fid,
985 fid->volatile_fid,
Pavel Shilovsky18cceb62013-09-05 13:01:06 +0400986 CIFS_CACHE_READ(cinode) ? 1 : 0);
Pavel Shilovsky983c88a2012-09-18 16:20:33 -0700987}
988
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -0700989static int
990smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
991 struct kstatfs *buf)
992{
993 int rc;
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -0700994 __le16 srch_path = 0; /* Null - open root of share */
995 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400996 struct cifs_open_parms oparms;
997 struct cifs_fid fid;
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -0700998
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400999 oparms.tcon = tcon;
1000 oparms.desired_access = FILE_READ_ATTRIBUTES;
1001 oparms.disposition = FILE_OPEN;
1002 oparms.create_options = 0;
1003 oparms.fid = &fid;
Pavel Shilovsky9cbc0b72013-07-09 18:40:58 +04001004 oparms.reconnect = false;
Pavel Shilovsky064f6042013-07-09 18:20:30 +04001005
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001006 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001007 if (rc)
1008 return rc;
1009 buf->f_type = SMB2_MAGIC_NUMBER;
Pavel Shilovsky064f6042013-07-09 18:20:30 +04001010 rc = SMB2_QFS_info(xid, tcon, fid.persistent_fid, fid.volatile_fid,
1011 buf);
1012 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001013 return rc;
1014}
1015
Pavel Shilovsky027e8ee2012-09-19 06:22:43 -07001016static bool
1017smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
1018{
1019 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
1020 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
1021}
1022
Pavel Shilovskyf7ba7fe2012-09-19 06:22:43 -07001023static int
1024smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
1025 __u64 length, __u32 type, int lock, int unlock, bool wait)
1026{
1027 if (unlock && !lock)
1028 type = SMB2_LOCKFLAG_UNLOCK;
1029 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
1030 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
1031 current->tgid, length, offset, type, wait);
1032}
1033
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -07001034static void
1035smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
1036{
1037 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
1038}
1039
1040static void
1041smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
1042{
1043 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
1044}
1045
1046static void
1047smb2_new_lease_key(struct cifs_fid *fid)
1048{
Steve Frenchfa70b872016-09-22 00:39:34 -05001049 generate_random_uuid(fid->lease_key);
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -07001050}
1051
Pavel Shilovsky78932422016-07-24 10:37:38 +03001052#define SMB2_SYMLINK_STRUCT_SIZE \
1053 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
1054
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001055static int
1056smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
1057 const char *full_path, char **target_path,
1058 struct cifs_sb_info *cifs_sb)
1059{
1060 int rc;
1061 __le16 *utf16_path;
1062 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1063 struct cifs_open_parms oparms;
1064 struct cifs_fid fid;
1065 struct smb2_err_rsp *err_buf = NULL;
1066 struct smb2_symlink_err_rsp *symlink;
Pavel Shilovsky78932422016-07-24 10:37:38 +03001067 unsigned int sub_len;
1068 unsigned int sub_offset;
1069 unsigned int print_len;
1070 unsigned int print_offset;
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001071
1072 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
1073
1074 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
1075 if (!utf16_path)
1076 return -ENOMEM;
1077
1078 oparms.tcon = tcon;
1079 oparms.desired_access = FILE_READ_ATTRIBUTES;
1080 oparms.disposition = FILE_OPEN;
1081 oparms.create_options = 0;
1082 oparms.fid = &fid;
1083 oparms.reconnect = false;
1084
1085 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_buf);
1086
1087 if (!rc || !err_buf) {
1088 kfree(utf16_path);
1089 return -ENOENT;
1090 }
Pavel Shilovsky78932422016-07-24 10:37:38 +03001091
1092 if (le32_to_cpu(err_buf->ByteCount) < sizeof(struct smb2_symlink_err_rsp) ||
1093 get_rfc1002_length(err_buf) + 4 < SMB2_SYMLINK_STRUCT_SIZE) {
1094 kfree(utf16_path);
1095 return -ENOENT;
1096 }
1097
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001098 /* open must fail on symlink - reset rc */
1099 rc = 0;
1100 symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
1101 sub_len = le16_to_cpu(symlink->SubstituteNameLength);
1102 sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
Pavel Shilovsky78932422016-07-24 10:37:38 +03001103 print_len = le16_to_cpu(symlink->PrintNameLength);
1104 print_offset = le16_to_cpu(symlink->PrintNameOffset);
1105
1106 if (get_rfc1002_length(err_buf) + 4 <
1107 SMB2_SYMLINK_STRUCT_SIZE + sub_offset + sub_len) {
1108 kfree(utf16_path);
1109 return -ENOENT;
1110 }
1111
1112 if (get_rfc1002_length(err_buf) + 4 <
1113 SMB2_SYMLINK_STRUCT_SIZE + print_offset + print_len) {
1114 kfree(utf16_path);
1115 return -ENOENT;
1116 }
1117
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001118 *target_path = cifs_strndup_from_utf16(
1119 (char *)symlink->PathBuffer + sub_offset,
1120 sub_len, true, cifs_sb->local_nls);
1121 if (!(*target_path)) {
1122 kfree(utf16_path);
1123 return -ENOMEM;
1124 }
1125 convert_delimiter(*target_path, '/');
1126 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
1127 kfree(utf16_path);
1128 return rc;
1129}
1130
Steve French30175622014-08-17 18:16:40 -05001131static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
1132 loff_t offset, loff_t len, bool keep_size)
1133{
1134 struct inode *inode;
1135 struct cifsInodeInfo *cifsi;
1136 struct cifsFileInfo *cfile = file->private_data;
1137 struct file_zero_data_information fsctl_buf;
1138 long rc;
1139 unsigned int xid;
1140
1141 xid = get_xid();
1142
David Howells2b0143b2015-03-17 22:25:59 +00001143 inode = d_inode(cfile->dentry);
Steve French30175622014-08-17 18:16:40 -05001144 cifsi = CIFS_I(inode);
1145
1146 /* if file not oplocked can't be sure whether asking to extend size */
1147 if (!CIFS_CACHE_READ(cifsi))
1148 if (keep_size == false)
1149 return -EOPNOTSUPP;
1150
Steve French2bb93d22014-08-20 18:56:29 -05001151 /*
Steve French30175622014-08-17 18:16:40 -05001152 * Must check if file sparse since fallocate -z (zero range) assumes
1153 * non-sparse allocation
1154 */
1155 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE))
1156 return -EOPNOTSUPP;
1157
1158 /*
1159 * need to make sure we are not asked to extend the file since the SMB3
1160 * fsctl does not change the file size. In the future we could change
1161 * this to zero the first part of the range then set the file size
1162 * which for a non sparse file would zero the newly extended range
1163 */
1164 if (keep_size == false)
1165 if (i_size_read(inode) < offset + len)
1166 return -EOPNOTSUPP;
1167
1168 cifs_dbg(FYI, "offset %lld len %lld", offset, len);
1169
1170 fsctl_buf.FileOffset = cpu_to_le64(offset);
1171 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
1172
1173 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1174 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
1175 true /* is_fctl */, (char *)&fsctl_buf,
1176 sizeof(struct file_zero_data_information), NULL, NULL);
1177 free_xid(xid);
1178 return rc;
1179}
1180
Steve French31742c52014-08-17 08:38:47 -05001181static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
1182 loff_t offset, loff_t len)
1183{
1184 struct inode *inode;
1185 struct cifsInodeInfo *cifsi;
1186 struct cifsFileInfo *cfile = file->private_data;
1187 struct file_zero_data_information fsctl_buf;
1188 long rc;
1189 unsigned int xid;
1190 __u8 set_sparse = 1;
1191
1192 xid = get_xid();
1193
David Howells2b0143b2015-03-17 22:25:59 +00001194 inode = d_inode(cfile->dentry);
Steve French31742c52014-08-17 08:38:47 -05001195 cifsi = CIFS_I(inode);
1196
1197 /* Need to make file sparse, if not already, before freeing range. */
1198 /* Consider adding equivalent for compressed since it could also work */
1199 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse))
1200 return -EOPNOTSUPP;
1201
1202 cifs_dbg(FYI, "offset %lld len %lld", offset, len);
1203
1204 fsctl_buf.FileOffset = cpu_to_le64(offset);
1205 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
1206
1207 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1208 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
1209 true /* is_fctl */, (char *)&fsctl_buf,
1210 sizeof(struct file_zero_data_information), NULL, NULL);
1211 free_xid(xid);
1212 return rc;
1213}
1214
Steve French9ccf3212014-10-18 17:01:15 -05001215static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
1216 loff_t off, loff_t len, bool keep_size)
1217{
1218 struct inode *inode;
1219 struct cifsInodeInfo *cifsi;
1220 struct cifsFileInfo *cfile = file->private_data;
1221 long rc = -EOPNOTSUPP;
1222 unsigned int xid;
1223
1224 xid = get_xid();
1225
David Howells2b0143b2015-03-17 22:25:59 +00001226 inode = d_inode(cfile->dentry);
Steve French9ccf3212014-10-18 17:01:15 -05001227 cifsi = CIFS_I(inode);
1228
1229 /* if file not oplocked can't be sure whether asking to extend size */
1230 if (!CIFS_CACHE_READ(cifsi))
1231 if (keep_size == false)
1232 return -EOPNOTSUPP;
1233
1234 /*
1235 * Files are non-sparse by default so falloc may be a no-op
1236 * Must check if file sparse. If not sparse, and not extending
1237 * then no need to do anything since file already allocated
1238 */
1239 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
1240 if (keep_size == true)
1241 return 0;
1242 /* check if extending file */
1243 else if (i_size_read(inode) >= off + len)
1244 /* not extending file and already not sparse */
1245 return 0;
1246 /* BB: in future add else clause to extend file */
1247 else
1248 return -EOPNOTSUPP;
1249 }
1250
1251 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
1252 /*
1253 * Check if falloc starts within first few pages of file
1254 * and ends within a few pages of the end of file to
1255 * ensure that most of file is being forced to be
1256 * fallocated now. If so then setting whole file sparse
1257 * ie potentially making a few extra pages at the beginning
1258 * or end of the file non-sparse via set_sparse is harmless.
1259 */
1260 if ((off > 8192) || (off + len + 8192 < i_size_read(inode)))
1261 return -EOPNOTSUPP;
1262
1263 rc = smb2_set_sparse(xid, tcon, cfile, inode, false);
1264 }
1265 /* BB: else ... in future add code to extend file and set sparse */
1266
1267
1268 free_xid(xid);
1269 return rc;
1270}
1271
1272
Steve French31742c52014-08-17 08:38:47 -05001273static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
1274 loff_t off, loff_t len)
1275{
1276 /* KEEP_SIZE already checked for by do_fallocate */
1277 if (mode & FALLOC_FL_PUNCH_HOLE)
1278 return smb3_punch_hole(file, tcon, off, len);
Steve French30175622014-08-17 18:16:40 -05001279 else if (mode & FALLOC_FL_ZERO_RANGE) {
1280 if (mode & FALLOC_FL_KEEP_SIZE)
1281 return smb3_zero_range(file, tcon, off, len, true);
1282 return smb3_zero_range(file, tcon, off, len, false);
Steve French9ccf3212014-10-18 17:01:15 -05001283 } else if (mode == FALLOC_FL_KEEP_SIZE)
1284 return smb3_simple_falloc(file, tcon, off, len, true);
1285 else if (mode == 0)
1286 return smb3_simple_falloc(file, tcon, off, len, false);
Steve French31742c52014-08-17 08:38:47 -05001287
1288 return -EOPNOTSUPP;
1289}
1290
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001291static void
Sachin Prabhuc11f1df2014-03-11 16:11:47 +00001292smb2_downgrade_oplock(struct TCP_Server_Info *server,
1293 struct cifsInodeInfo *cinode, bool set_level2)
1294{
1295 if (set_level2)
1296 server->ops->set_oplock_level(cinode, SMB2_OPLOCK_LEVEL_II,
1297 0, NULL);
1298 else
1299 server->ops->set_oplock_level(cinode, 0, 0, NULL);
1300}
1301
1302static void
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001303smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
1304 unsigned int epoch, bool *purge_cache)
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001305{
1306 oplock &= 0xFF;
1307 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
1308 return;
1309 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001310 cinode->oplock = CIFS_CACHE_RHW_FLG;
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001311 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
1312 &cinode->vfs_inode);
1313 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001314 cinode->oplock = CIFS_CACHE_RW_FLG;
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001315 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
1316 &cinode->vfs_inode);
1317 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
1318 cinode->oplock = CIFS_CACHE_READ_FLG;
1319 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
1320 &cinode->vfs_inode);
1321 } else
1322 cinode->oplock = 0;
1323}
1324
1325static void
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001326smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
1327 unsigned int epoch, bool *purge_cache)
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001328{
1329 char message[5] = {0};
1330
1331 oplock &= 0xFF;
1332 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
1333 return;
1334
1335 cinode->oplock = 0;
1336 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
1337 cinode->oplock |= CIFS_CACHE_READ_FLG;
1338 strcat(message, "R");
1339 }
1340 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
1341 cinode->oplock |= CIFS_CACHE_HANDLE_FLG;
1342 strcat(message, "H");
1343 }
1344 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
1345 cinode->oplock |= CIFS_CACHE_WRITE_FLG;
1346 strcat(message, "W");
1347 }
1348 if (!cinode->oplock)
1349 strcat(message, "None");
1350 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
1351 &cinode->vfs_inode);
1352}
1353
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001354static void
1355smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
1356 unsigned int epoch, bool *purge_cache)
1357{
1358 unsigned int old_oplock = cinode->oplock;
1359
1360 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
1361
1362 if (purge_cache) {
1363 *purge_cache = false;
1364 if (old_oplock == CIFS_CACHE_READ_FLG) {
1365 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
1366 (epoch - cinode->epoch > 0))
1367 *purge_cache = true;
1368 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
1369 (epoch - cinode->epoch > 1))
1370 *purge_cache = true;
1371 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
1372 (epoch - cinode->epoch > 1))
1373 *purge_cache = true;
1374 else if (cinode->oplock == 0 &&
1375 (epoch - cinode->epoch > 0))
1376 *purge_cache = true;
1377 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
1378 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
1379 (epoch - cinode->epoch > 0))
1380 *purge_cache = true;
1381 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
1382 (epoch - cinode->epoch > 1))
1383 *purge_cache = true;
1384 }
1385 cinode->epoch = epoch;
1386 }
1387}
1388
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001389static bool
1390smb2_is_read_op(__u32 oplock)
1391{
1392 return oplock == SMB2_OPLOCK_LEVEL_II;
1393}
1394
1395static bool
1396smb21_is_read_op(__u32 oplock)
1397{
1398 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
1399 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
1400}
1401
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001402static __le32
1403map_oplock_to_lease(u8 oplock)
1404{
1405 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
1406 return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
1407 else if (oplock == SMB2_OPLOCK_LEVEL_II)
1408 return SMB2_LEASE_READ_CACHING;
1409 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
1410 return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING |
1411 SMB2_LEASE_WRITE_CACHING;
1412 return 0;
1413}
1414
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001415static char *
1416smb2_create_lease_buf(u8 *lease_key, u8 oplock)
1417{
1418 struct create_lease *buf;
1419
1420 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
1421 if (!buf)
1422 return NULL;
1423
1424 buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
1425 buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001426 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001427
1428 buf->ccontext.DataOffset = cpu_to_le16(offsetof
1429 (struct create_lease, lcontext));
1430 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
1431 buf->ccontext.NameOffset = cpu_to_le16(offsetof
1432 (struct create_lease, Name));
1433 buf->ccontext.NameLength = cpu_to_le16(4);
Steve French12197a72014-05-14 05:29:40 -07001434 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001435 buf->Name[0] = 'R';
1436 buf->Name[1] = 'q';
1437 buf->Name[2] = 'L';
1438 buf->Name[3] = 's';
1439 return (char *)buf;
1440}
1441
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001442static char *
1443smb3_create_lease_buf(u8 *lease_key, u8 oplock)
1444{
1445 struct create_lease_v2 *buf;
1446
1447 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
1448 if (!buf)
1449 return NULL;
1450
1451 buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
1452 buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
1453 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
1454
1455 buf->ccontext.DataOffset = cpu_to_le16(offsetof
1456 (struct create_lease_v2, lcontext));
1457 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
1458 buf->ccontext.NameOffset = cpu_to_le16(offsetof
1459 (struct create_lease_v2, Name));
1460 buf->ccontext.NameLength = cpu_to_le16(4);
Steve French12197a72014-05-14 05:29:40 -07001461 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001462 buf->Name[0] = 'R';
1463 buf->Name[1] = 'q';
1464 buf->Name[2] = 'L';
1465 buf->Name[3] = 's';
1466 return (char *)buf;
1467}
1468
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04001469static __u8
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001470smb2_parse_lease_buf(void *buf, unsigned int *epoch)
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04001471{
1472 struct create_lease *lc = (struct create_lease *)buf;
1473
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001474 *epoch = 0; /* not used */
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04001475 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
1476 return SMB2_OPLOCK_LEVEL_NOCHANGE;
1477 return le32_to_cpu(lc->lcontext.LeaseState);
1478}
1479
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001480static __u8
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001481smb3_parse_lease_buf(void *buf, unsigned int *epoch)
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001482{
1483 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
1484
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001485 *epoch = le16_to_cpu(lc->lcontext.Epoch);
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001486 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
1487 return SMB2_OPLOCK_LEVEL_NOCHANGE;
1488 return le32_to_cpu(lc->lcontext.LeaseState);
1489}
1490
Pavel Shilovsky7f6c5002014-06-22 11:03:22 +04001491static unsigned int
1492smb2_wp_retry_size(struct inode *inode)
1493{
1494 return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize,
1495 SMB2_MAX_BUFFER_SIZE);
1496}
1497
Pavel Shilovsky52755802014-08-18 20:49:57 +04001498static bool
1499smb2_dir_needs_close(struct cifsFileInfo *cfile)
1500{
1501 return !cfile->invalidHandle;
1502}
1503
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001504struct smb_version_operations smb20_operations = {
1505 .compare_fids = smb2_compare_fids,
1506 .setup_request = smb2_setup_request,
1507 .setup_async_request = smb2_setup_async_request,
1508 .check_receive = smb2_check_receive,
1509 .add_credits = smb2_add_credits,
1510 .set_credits = smb2_set_credits,
1511 .get_credits_field = smb2_get_credits_field,
1512 .get_credits = smb2_get_credits,
Pavel Shilovskycb7e9ea2014-06-05 19:03:27 +04001513 .wait_mtu_credits = cifs_wait_mtu_credits,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001514 .get_next_mid = smb2_get_next_mid,
1515 .read_data_offset = smb2_read_data_offset,
1516 .read_data_length = smb2_read_data_length,
1517 .map_error = map_smb2_to_linux_error,
1518 .find_mid = smb2_find_mid,
1519 .check_message = smb2_check_message,
1520 .dump_detail = smb2_dump_detail,
1521 .clear_stats = smb2_clear_stats,
1522 .print_stats = smb2_print_stats,
1523 .is_oplock_break = smb2_is_valid_oplock_break,
Sachin Prabhuc11f1df2014-03-11 16:11:47 +00001524 .downgrade_oplock = smb2_downgrade_oplock,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001525 .need_neg = smb2_need_neg,
1526 .negotiate = smb2_negotiate,
1527 .negotiate_wsize = smb2_negotiate_wsize,
1528 .negotiate_rsize = smb2_negotiate_rsize,
1529 .sess_setup = SMB2_sess_setup,
1530 .logoff = SMB2_logoff,
1531 .tree_connect = SMB2_tcon,
1532 .tree_disconnect = SMB2_tdis,
Steve French34f62642013-10-09 02:07:00 -05001533 .qfs_tcon = smb2_qfs_tcon,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001534 .is_path_accessible = smb2_is_path_accessible,
1535 .can_echo = smb2_can_echo,
1536 .echo = SMB2_echo,
1537 .query_path_info = smb2_query_path_info,
1538 .get_srv_inum = smb2_get_srv_inum,
1539 .query_file_info = smb2_query_file_info,
1540 .set_path_size = smb2_set_path_size,
1541 .set_file_size = smb2_set_file_size,
1542 .set_file_info = smb2_set_file_info,
Steve French64a5cfa2013-10-14 15:31:32 -05001543 .set_compression = smb2_set_compression,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001544 .mkdir = smb2_mkdir,
1545 .mkdir_setinfo = smb2_mkdir_setinfo,
1546 .rmdir = smb2_rmdir,
1547 .unlink = smb2_unlink,
1548 .rename = smb2_rename_path,
1549 .create_hardlink = smb2_create_hardlink,
1550 .query_symlink = smb2_query_symlink,
Sachin Prabhu5b23c972016-07-11 16:53:20 +01001551 .query_mf_symlink = smb3_query_mf_symlink,
1552 .create_mf_symlink = smb3_create_mf_symlink,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001553 .open = smb2_open_file,
1554 .set_fid = smb2_set_fid,
1555 .close = smb2_close_file,
1556 .flush = smb2_flush_file,
1557 .async_readv = smb2_async_readv,
1558 .async_writev = smb2_async_writev,
1559 .sync_read = smb2_sync_read,
1560 .sync_write = smb2_sync_write,
1561 .query_dir_first = smb2_query_dir_first,
1562 .query_dir_next = smb2_query_dir_next,
1563 .close_dir = smb2_close_dir,
1564 .calc_smb_size = smb2_calc_size,
1565 .is_status_pending = smb2_is_status_pending,
1566 .oplock_response = smb2_oplock_response,
1567 .queryfs = smb2_queryfs,
1568 .mand_lock = smb2_mand_lock,
1569 .mand_unlock_range = smb2_unlock_range,
1570 .push_mand_locks = smb2_push_mandatory_locks,
1571 .get_lease_key = smb2_get_lease_key,
1572 .set_lease_key = smb2_set_lease_key,
1573 .new_lease_key = smb2_new_lease_key,
1574 .calc_signature = smb2_calc_signature,
1575 .is_read_op = smb2_is_read_op,
1576 .set_oplock_level = smb2_set_oplock_level,
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001577 .create_lease_buf = smb2_create_lease_buf,
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04001578 .parse_lease_buf = smb2_parse_lease_buf,
Steve French41c13582013-11-14 00:05:36 -06001579 .clone_range = smb2_clone_range,
Pavel Shilovsky7f6c5002014-06-22 11:03:22 +04001580 .wp_retry_size = smb2_wp_retry_size,
Pavel Shilovsky52755802014-08-18 20:49:57 +04001581 .dir_needs_close = smb2_dir_needs_close,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001582};
1583
Steve French1080ef72011-02-24 18:07:19 +00001584struct smb_version_operations smb21_operations = {
Pavel Shilovsky027e8ee2012-09-19 06:22:43 -07001585 .compare_fids = smb2_compare_fids,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +04001586 .setup_request = smb2_setup_request,
Pavel Shilovskyc95b8ee2012-07-11 14:45:28 +04001587 .setup_async_request = smb2_setup_async_request,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +04001588 .check_receive = smb2_check_receive,
Pavel Shilovsky28ea5292012-05-23 16:18:00 +04001589 .add_credits = smb2_add_credits,
1590 .set_credits = smb2_set_credits,
1591 .get_credits_field = smb2_get_credits_field,
1592 .get_credits = smb2_get_credits,
Pavel Shilovskycb7e9ea2014-06-05 19:03:27 +04001593 .wait_mtu_credits = smb2_wait_mtu_credits,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +04001594 .get_next_mid = smb2_get_next_mid,
Pavel Shilovsky09a47072012-09-18 16:20:29 -07001595 .read_data_offset = smb2_read_data_offset,
1596 .read_data_length = smb2_read_data_length,
1597 .map_error = map_smb2_to_linux_error,
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +04001598 .find_mid = smb2_find_mid,
1599 .check_message = smb2_check_message,
1600 .dump_detail = smb2_dump_detail,
Pavel Shilovskyd60622e2012-05-28 15:19:39 +04001601 .clear_stats = smb2_clear_stats,
1602 .print_stats = smb2_print_stats,
Pavel Shilovsky983c88a2012-09-18 16:20:33 -07001603 .is_oplock_break = smb2_is_valid_oplock_break,
Sachin Prabhuc11f1df2014-03-11 16:11:47 +00001604 .downgrade_oplock = smb2_downgrade_oplock,
Pavel Shilovskyec2e4522011-12-27 16:12:43 +04001605 .need_neg = smb2_need_neg,
1606 .negotiate = smb2_negotiate,
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -07001607 .negotiate_wsize = smb2_negotiate_wsize,
1608 .negotiate_rsize = smb2_negotiate_rsize,
Pavel Shilovsky5478f9b2011-12-27 16:22:00 +04001609 .sess_setup = SMB2_sess_setup,
1610 .logoff = SMB2_logoff,
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +04001611 .tree_connect = SMB2_tcon,
1612 .tree_disconnect = SMB2_tdis,
Steve French34f62642013-10-09 02:07:00 -05001613 .qfs_tcon = smb2_qfs_tcon,
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +04001614 .is_path_accessible = smb2_is_path_accessible,
Pavel Shilovsky9094fad2012-07-12 18:30:44 +04001615 .can_echo = smb2_can_echo,
1616 .echo = SMB2_echo,
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +04001617 .query_path_info = smb2_query_path_info,
1618 .get_srv_inum = smb2_get_srv_inum,
Pavel Shilovskyb7546bc2012-09-18 16:20:27 -07001619 .query_file_info = smb2_query_file_info,
Pavel Shilovskyc839ff22012-09-18 16:20:32 -07001620 .set_path_size = smb2_set_path_size,
1621 .set_file_size = smb2_set_file_size,
Pavel Shilovsky1feeaac2012-09-18 16:20:32 -07001622 .set_file_info = smb2_set_file_info,
Steve French64a5cfa2013-10-14 15:31:32 -05001623 .set_compression = smb2_set_compression,
Pavel Shilovskya0e73182011-07-19 12:56:37 +04001624 .mkdir = smb2_mkdir,
1625 .mkdir_setinfo = smb2_mkdir_setinfo,
Pavel Shilovsky1a500f02012-07-10 16:14:38 +04001626 .rmdir = smb2_rmdir,
Pavel Shilovskycbe6f432012-09-18 16:20:25 -07001627 .unlink = smb2_unlink,
Pavel Shilovsky35143eb2012-09-18 16:20:31 -07001628 .rename = smb2_rename_path,
Pavel Shilovsky568798c2012-09-18 16:20:31 -07001629 .create_hardlink = smb2_create_hardlink,
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001630 .query_symlink = smb2_query_symlink,
Steve Frenchc22870e2014-09-16 07:18:19 -05001631 .query_mf_symlink = smb3_query_mf_symlink,
Steve French5ab97572014-09-15 04:49:28 -05001632 .create_mf_symlink = smb3_create_mf_symlink,
Pavel Shilovskyf0df7372012-09-18 16:20:26 -07001633 .open = smb2_open_file,
1634 .set_fid = smb2_set_fid,
1635 .close = smb2_close_file,
Pavel Shilovsky7a5cfb12012-09-18 16:20:28 -07001636 .flush = smb2_flush_file,
Pavel Shilovsky09a47072012-09-18 16:20:29 -07001637 .async_readv = smb2_async_readv,
Pavel Shilovsky33319142012-09-18 16:20:29 -07001638 .async_writev = smb2_async_writev,
Pavel Shilovskyd8e05032012-09-18 16:20:30 -07001639 .sync_read = smb2_sync_read,
Pavel Shilovsky009d3442012-09-18 16:20:30 -07001640 .sync_write = smb2_sync_write,
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -07001641 .query_dir_first = smb2_query_dir_first,
1642 .query_dir_next = smb2_query_dir_next,
1643 .close_dir = smb2_close_dir,
1644 .calc_smb_size = smb2_calc_size,
Pavel Shilovsky2e44b282012-09-18 16:20:33 -07001645 .is_status_pending = smb2_is_status_pending,
Pavel Shilovsky983c88a2012-09-18 16:20:33 -07001646 .oplock_response = smb2_oplock_response,
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001647 .queryfs = smb2_queryfs,
Pavel Shilovskyf7ba7fe2012-09-19 06:22:43 -07001648 .mand_lock = smb2_mand_lock,
1649 .mand_unlock_range = smb2_unlock_range,
Pavel Shilovskyb1407992012-09-19 06:22:44 -07001650 .push_mand_locks = smb2_push_mandatory_locks,
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -07001651 .get_lease_key = smb2_get_lease_key,
1652 .set_lease_key = smb2_set_lease_key,
1653 .new_lease_key = smb2_new_lease_key,
Steve French38107d42012-12-08 22:08:06 -06001654 .calc_signature = smb2_calc_signature,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001655 .is_read_op = smb21_is_read_op,
1656 .set_oplock_level = smb21_set_oplock_level,
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001657 .create_lease_buf = smb2_create_lease_buf,
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04001658 .parse_lease_buf = smb2_parse_lease_buf,
Steve French41c13582013-11-14 00:05:36 -06001659 .clone_range = smb2_clone_range,
Pavel Shilovsky7f6c5002014-06-22 11:03:22 +04001660 .wp_retry_size = smb2_wp_retry_size,
Pavel Shilovsky52755802014-08-18 20:49:57 +04001661 .dir_needs_close = smb2_dir_needs_close,
Steve French38107d42012-12-08 22:08:06 -06001662};
1663
Steve French38107d42012-12-08 22:08:06 -06001664struct smb_version_operations smb30_operations = {
1665 .compare_fids = smb2_compare_fids,
1666 .setup_request = smb2_setup_request,
1667 .setup_async_request = smb2_setup_async_request,
1668 .check_receive = smb2_check_receive,
1669 .add_credits = smb2_add_credits,
1670 .set_credits = smb2_set_credits,
1671 .get_credits_field = smb2_get_credits_field,
1672 .get_credits = smb2_get_credits,
Pavel Shilovskycb7e9ea2014-06-05 19:03:27 +04001673 .wait_mtu_credits = smb2_wait_mtu_credits,
Steve French38107d42012-12-08 22:08:06 -06001674 .get_next_mid = smb2_get_next_mid,
1675 .read_data_offset = smb2_read_data_offset,
1676 .read_data_length = smb2_read_data_length,
1677 .map_error = map_smb2_to_linux_error,
1678 .find_mid = smb2_find_mid,
1679 .check_message = smb2_check_message,
1680 .dump_detail = smb2_dump_detail,
1681 .clear_stats = smb2_clear_stats,
1682 .print_stats = smb2_print_stats,
Steve French769ee6a2013-06-19 14:15:30 -05001683 .dump_share_caps = smb2_dump_share_caps,
Steve French38107d42012-12-08 22:08:06 -06001684 .is_oplock_break = smb2_is_valid_oplock_break,
Sachin Prabhuc11f1df2014-03-11 16:11:47 +00001685 .downgrade_oplock = smb2_downgrade_oplock,
Steve French38107d42012-12-08 22:08:06 -06001686 .need_neg = smb2_need_neg,
1687 .negotiate = smb2_negotiate,
1688 .negotiate_wsize = smb2_negotiate_wsize,
1689 .negotiate_rsize = smb2_negotiate_rsize,
1690 .sess_setup = SMB2_sess_setup,
1691 .logoff = SMB2_logoff,
1692 .tree_connect = SMB2_tcon,
1693 .tree_disconnect = SMB2_tdis,
Steven Frenchaf6a12e2013-10-09 20:55:53 -05001694 .qfs_tcon = smb3_qfs_tcon,
Steve French38107d42012-12-08 22:08:06 -06001695 .is_path_accessible = smb2_is_path_accessible,
1696 .can_echo = smb2_can_echo,
1697 .echo = SMB2_echo,
1698 .query_path_info = smb2_query_path_info,
1699 .get_srv_inum = smb2_get_srv_inum,
1700 .query_file_info = smb2_query_file_info,
1701 .set_path_size = smb2_set_path_size,
1702 .set_file_size = smb2_set_file_size,
1703 .set_file_info = smb2_set_file_info,
Steve French64a5cfa2013-10-14 15:31:32 -05001704 .set_compression = smb2_set_compression,
Steve French38107d42012-12-08 22:08:06 -06001705 .mkdir = smb2_mkdir,
1706 .mkdir_setinfo = smb2_mkdir_setinfo,
1707 .rmdir = smb2_rmdir,
1708 .unlink = smb2_unlink,
1709 .rename = smb2_rename_path,
1710 .create_hardlink = smb2_create_hardlink,
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001711 .query_symlink = smb2_query_symlink,
Steve Frenchc22870e2014-09-16 07:18:19 -05001712 .query_mf_symlink = smb3_query_mf_symlink,
Steve French5ab97572014-09-15 04:49:28 -05001713 .create_mf_symlink = smb3_create_mf_symlink,
Steve French38107d42012-12-08 22:08:06 -06001714 .open = smb2_open_file,
1715 .set_fid = smb2_set_fid,
1716 .close = smb2_close_file,
1717 .flush = smb2_flush_file,
1718 .async_readv = smb2_async_readv,
1719 .async_writev = smb2_async_writev,
1720 .sync_read = smb2_sync_read,
1721 .sync_write = smb2_sync_write,
1722 .query_dir_first = smb2_query_dir_first,
1723 .query_dir_next = smb2_query_dir_next,
1724 .close_dir = smb2_close_dir,
1725 .calc_smb_size = smb2_calc_size,
1726 .is_status_pending = smb2_is_status_pending,
1727 .oplock_response = smb2_oplock_response,
1728 .queryfs = smb2_queryfs,
1729 .mand_lock = smb2_mand_lock,
1730 .mand_unlock_range = smb2_unlock_range,
1731 .push_mand_locks = smb2_push_mandatory_locks,
1732 .get_lease_key = smb2_get_lease_key,
1733 .set_lease_key = smb2_set_lease_key,
1734 .new_lease_key = smb2_new_lease_key,
Steve French373512e2015-12-18 13:05:30 -06001735 .generate_signingkey = generate_smb30signingkey,
Steve French38107d42012-12-08 22:08:06 -06001736 .calc_signature = smb3_calc_signature,
Steve Frenchb3152e22015-06-24 03:17:02 -05001737 .set_integrity = smb3_set_integrity,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001738 .is_read_op = smb21_is_read_op,
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001739 .set_oplock_level = smb3_set_oplock_level,
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001740 .create_lease_buf = smb3_create_lease_buf,
1741 .parse_lease_buf = smb3_parse_lease_buf,
Steve French41c13582013-11-14 00:05:36 -06001742 .clone_range = smb2_clone_range,
Steve Frenchca9e7a12015-10-01 21:40:10 -05001743 .duplicate_extents = smb2_duplicate_extents,
Steve Frenchff1c0382013-11-19 23:44:46 -06001744 .validate_negotiate = smb3_validate_negotiate,
Pavel Shilovsky7f6c5002014-06-22 11:03:22 +04001745 .wp_retry_size = smb2_wp_retry_size,
Pavel Shilovsky52755802014-08-18 20:49:57 +04001746 .dir_needs_close = smb2_dir_needs_close,
Steve French31742c52014-08-17 08:38:47 -05001747 .fallocate = smb3_fallocate,
Steve French1080ef72011-02-24 18:07:19 +00001748};
1749
Steve Frenchaab18932015-06-23 23:37:11 -05001750#ifdef CONFIG_CIFS_SMB311
1751struct smb_version_operations smb311_operations = {
1752 .compare_fids = smb2_compare_fids,
1753 .setup_request = smb2_setup_request,
1754 .setup_async_request = smb2_setup_async_request,
1755 .check_receive = smb2_check_receive,
1756 .add_credits = smb2_add_credits,
1757 .set_credits = smb2_set_credits,
1758 .get_credits_field = smb2_get_credits_field,
1759 .get_credits = smb2_get_credits,
1760 .wait_mtu_credits = smb2_wait_mtu_credits,
1761 .get_next_mid = smb2_get_next_mid,
1762 .read_data_offset = smb2_read_data_offset,
1763 .read_data_length = smb2_read_data_length,
1764 .map_error = map_smb2_to_linux_error,
1765 .find_mid = smb2_find_mid,
1766 .check_message = smb2_check_message,
1767 .dump_detail = smb2_dump_detail,
1768 .clear_stats = smb2_clear_stats,
1769 .print_stats = smb2_print_stats,
1770 .dump_share_caps = smb2_dump_share_caps,
1771 .is_oplock_break = smb2_is_valid_oplock_break,
1772 .downgrade_oplock = smb2_downgrade_oplock,
1773 .need_neg = smb2_need_neg,
1774 .negotiate = smb2_negotiate,
1775 .negotiate_wsize = smb2_negotiate_wsize,
1776 .negotiate_rsize = smb2_negotiate_rsize,
1777 .sess_setup = SMB2_sess_setup,
1778 .logoff = SMB2_logoff,
1779 .tree_connect = SMB2_tcon,
1780 .tree_disconnect = SMB2_tdis,
1781 .qfs_tcon = smb3_qfs_tcon,
1782 .is_path_accessible = smb2_is_path_accessible,
1783 .can_echo = smb2_can_echo,
1784 .echo = SMB2_echo,
1785 .query_path_info = smb2_query_path_info,
1786 .get_srv_inum = smb2_get_srv_inum,
1787 .query_file_info = smb2_query_file_info,
1788 .set_path_size = smb2_set_path_size,
1789 .set_file_size = smb2_set_file_size,
1790 .set_file_info = smb2_set_file_info,
1791 .set_compression = smb2_set_compression,
1792 .mkdir = smb2_mkdir,
1793 .mkdir_setinfo = smb2_mkdir_setinfo,
1794 .rmdir = smb2_rmdir,
1795 .unlink = smb2_unlink,
1796 .rename = smb2_rename_path,
1797 .create_hardlink = smb2_create_hardlink,
1798 .query_symlink = smb2_query_symlink,
1799 .query_mf_symlink = smb3_query_mf_symlink,
1800 .create_mf_symlink = smb3_create_mf_symlink,
1801 .open = smb2_open_file,
1802 .set_fid = smb2_set_fid,
1803 .close = smb2_close_file,
1804 .flush = smb2_flush_file,
1805 .async_readv = smb2_async_readv,
1806 .async_writev = smb2_async_writev,
1807 .sync_read = smb2_sync_read,
1808 .sync_write = smb2_sync_write,
1809 .query_dir_first = smb2_query_dir_first,
1810 .query_dir_next = smb2_query_dir_next,
1811 .close_dir = smb2_close_dir,
1812 .calc_smb_size = smb2_calc_size,
1813 .is_status_pending = smb2_is_status_pending,
1814 .oplock_response = smb2_oplock_response,
1815 .queryfs = smb2_queryfs,
1816 .mand_lock = smb2_mand_lock,
1817 .mand_unlock_range = smb2_unlock_range,
1818 .push_mand_locks = smb2_push_mandatory_locks,
1819 .get_lease_key = smb2_get_lease_key,
1820 .set_lease_key = smb2_set_lease_key,
1821 .new_lease_key = smb2_new_lease_key,
Steve French373512e2015-12-18 13:05:30 -06001822 .generate_signingkey = generate_smb311signingkey,
Steve Frenchaab18932015-06-23 23:37:11 -05001823 .calc_signature = smb3_calc_signature,
Steve Frenchb3152e22015-06-24 03:17:02 -05001824 .set_integrity = smb3_set_integrity,
Steve Frenchaab18932015-06-23 23:37:11 -05001825 .is_read_op = smb21_is_read_op,
1826 .set_oplock_level = smb3_set_oplock_level,
1827 .create_lease_buf = smb3_create_lease_buf,
1828 .parse_lease_buf = smb3_parse_lease_buf,
1829 .clone_range = smb2_clone_range,
Steve French02b16662015-06-27 21:18:36 -07001830 .duplicate_extents = smb2_duplicate_extents,
Steve Frenchaab18932015-06-23 23:37:11 -05001831/* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
1832 .wp_retry_size = smb2_wp_retry_size,
1833 .dir_needs_close = smb2_dir_needs_close,
1834 .fallocate = smb3_fallocate,
1835};
1836#endif /* CIFS_SMB311 */
1837
Steve Frenchdd446b12012-11-28 23:21:06 -06001838struct smb_version_values smb20_values = {
1839 .version_string = SMB20_VERSION_STRING,
1840 .protocol_id = SMB20_PROT_ID,
1841 .req_capabilities = 0, /* MBZ */
1842 .large_lock_type = 0,
1843 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1844 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1845 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
1846 .header_size = sizeof(struct smb2_hdr),
1847 .max_header_size = MAX_SMB2_HDR_SIZE,
1848 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
1849 .lock_cmd = SMB2_LOCK,
1850 .cap_unix = 0,
1851 .cap_nt_find = SMB2_NT_FIND,
1852 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton50285882013-06-27 12:45:00 -04001853 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1854 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001855 .create_lease_size = sizeof(struct create_lease),
Steve Frenchdd446b12012-11-28 23:21:06 -06001856};
1857
Steve French1080ef72011-02-24 18:07:19 +00001858struct smb_version_values smb21_values = {
1859 .version_string = SMB21_VERSION_STRING,
Steve Frenche4aa25e2012-10-01 12:26:22 -05001860 .protocol_id = SMB21_PROT_ID,
1861 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
1862 .large_lock_type = 0,
1863 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1864 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1865 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
1866 .header_size = sizeof(struct smb2_hdr),
1867 .max_header_size = MAX_SMB2_HDR_SIZE,
1868 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
1869 .lock_cmd = SMB2_LOCK,
1870 .cap_unix = 0,
1871 .cap_nt_find = SMB2_NT_FIND,
1872 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton50285882013-06-27 12:45:00 -04001873 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1874 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001875 .create_lease_size = sizeof(struct create_lease),
Steve Frenche4aa25e2012-10-01 12:26:22 -05001876};
1877
1878struct smb_version_values smb30_values = {
1879 .version_string = SMB30_VERSION_STRING,
1880 .protocol_id = SMB30_PROT_ID,
Steve French373512e2015-12-18 13:05:30 -06001881 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
Pavel Shilovsky027e8ee2012-09-19 06:22:43 -07001882 .large_lock_type = 0,
1883 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1884 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1885 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +04001886 .header_size = sizeof(struct smb2_hdr),
1887 .max_header_size = MAX_SMB2_HDR_SIZE,
Pavel Shilovsky09a47072012-09-18 16:20:29 -07001888 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +04001889 .lock_cmd = SMB2_LOCK,
Pavel Shilovsky29e20f92012-07-13 13:58:14 +04001890 .cap_unix = 0,
1891 .cap_nt_find = SMB2_NT_FIND,
1892 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton50285882013-06-27 12:45:00 -04001893 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1894 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001895 .create_lease_size = sizeof(struct create_lease_v2),
Steve French1080ef72011-02-24 18:07:19 +00001896};
Steve French20b6d8b2013-06-12 22:48:41 -05001897
1898struct smb_version_values smb302_values = {
1899 .version_string = SMB302_VERSION_STRING,
1900 .protocol_id = SMB302_PROT_ID,
Steve French373512e2015-12-18 13:05:30 -06001901 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
Steve French20b6d8b2013-06-12 22:48:41 -05001902 .large_lock_type = 0,
1903 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1904 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1905 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
1906 .header_size = sizeof(struct smb2_hdr),
1907 .max_header_size = MAX_SMB2_HDR_SIZE,
1908 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
1909 .lock_cmd = SMB2_LOCK,
1910 .cap_unix = 0,
1911 .cap_nt_find = SMB2_NT_FIND,
1912 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton50285882013-06-27 12:45:00 -04001913 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1914 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001915 .create_lease_size = sizeof(struct create_lease_v2),
Steve French20b6d8b2013-06-12 22:48:41 -05001916};
Steve French5f7fbf72014-12-17 22:52:58 -06001917
1918#ifdef CONFIG_CIFS_SMB311
1919struct smb_version_values smb311_values = {
1920 .version_string = SMB311_VERSION_STRING,
1921 .protocol_id = SMB311_PROT_ID,
Steve Frenchb618f002015-11-03 09:15:03 -06001922 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES,
Steve French5f7fbf72014-12-17 22:52:58 -06001923 .large_lock_type = 0,
1924 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1925 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1926 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
1927 .header_size = sizeof(struct smb2_hdr),
1928 .max_header_size = MAX_SMB2_HDR_SIZE,
1929 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
1930 .lock_cmd = SMB2_LOCK,
1931 .cap_unix = 0,
1932 .cap_nt_find = SMB2_NT_FIND,
1933 .cap_large_files = SMB2_LARGE_FILES,
1934 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1935 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
1936 .create_lease_size = sizeof(struct create_lease_v2),
1937};
1938#endif /* SMB311 */