blob: dd8543caa56e93267bc39c8819db021167276b52 [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;
73 server->in_flight--;
Pavel Shilovskyec2e4522011-12-27 16:12:43 +040074 if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP)
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040075 rc = change_conf(server);
Pavel Shilovsky983c88a2012-09-18 16:20:33 -070076 /*
77 * Sometimes server returns 0 credits on oplock break ack - we need to
78 * rebalance credits in this case.
79 */
80 else if (server->in_flight > 0 && server->oplock_credits == 0 &&
81 server->oplocks) {
82 if (server->credits > 1) {
83 server->credits--;
84 server->oplock_credits++;
85 }
86 }
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040087 spin_unlock(&server->req_lock);
88 wake_up(&server->request_q);
89 if (rc)
90 cifs_reconnect(server);
91}
92
93static void
94smb2_set_credits(struct TCP_Server_Info *server, const int val)
95{
96 spin_lock(&server->req_lock);
97 server->credits = val;
98 spin_unlock(&server->req_lock);
99}
100
101static int *
102smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
103{
104 switch (optype) {
105 case CIFS_ECHO_OP:
106 return &server->echo_credits;
107 case CIFS_OBREAK_OP:
108 return &server->oplock_credits;
109 default:
110 return &server->credits;
111 }
112}
113
114static unsigned int
115smb2_get_credits(struct mid_q_entry *mid)
116{
117 return le16_to_cpu(((struct smb2_hdr *)mid->resp_buf)->CreditRequest);
118}
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +0400119
Pavel Shilovskycb7e9ea2014-06-05 19:03:27 +0400120static int
121smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size,
122 unsigned int *num, unsigned int *credits)
123{
124 int rc = 0;
125 unsigned int scredits;
126
127 spin_lock(&server->req_lock);
128 while (1) {
129 if (server->credits <= 0) {
130 spin_unlock(&server->req_lock);
131 cifs_num_waiters_inc(server);
132 rc = wait_event_killable(server->request_q,
133 has_credits(server, &server->credits));
134 cifs_num_waiters_dec(server);
135 if (rc)
136 return rc;
137 spin_lock(&server->req_lock);
138 } else {
139 if (server->tcpStatus == CifsExiting) {
140 spin_unlock(&server->req_lock);
141 return -ENOENT;
142 }
143
144 scredits = server->credits;
145 /* can deadlock with reopen */
146 if (scredits == 1) {
147 *num = SMB2_MAX_BUFFER_SIZE;
148 *credits = 0;
149 break;
150 }
151
152 /* leave one credit for a possible reopen */
153 scredits--;
154 *num = min_t(unsigned int, size,
155 scredits * SMB2_MAX_BUFFER_SIZE);
156
157 *credits = DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE);
158 server->credits -= *credits;
159 server->in_flight++;
160 break;
161 }
162 }
163 spin_unlock(&server->req_lock);
164 return rc;
165}
166
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +0400167static __u64
168smb2_get_next_mid(struct TCP_Server_Info *server)
169{
170 __u64 mid;
171 /* for SMB2 we need the current value */
172 spin_lock(&GlobalMid_Lock);
173 mid = server->CurrentMid++;
174 spin_unlock(&GlobalMid_Lock);
175 return mid;
176}
Steve French1080ef72011-02-24 18:07:19 +0000177
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400178static struct mid_q_entry *
179smb2_find_mid(struct TCP_Server_Info *server, char *buf)
180{
181 struct mid_q_entry *mid;
182 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
Sachin Prabhu9235d092014-12-09 17:37:00 +0000183 __u64 wire_mid = le64_to_cpu(hdr->MessageId);
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400184
185 spin_lock(&GlobalMid_Lock);
186 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
Sachin Prabhu9235d092014-12-09 17:37:00 +0000187 if ((mid->mid == wire_mid) &&
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400188 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
189 (mid->command == hdr->Command)) {
190 spin_unlock(&GlobalMid_Lock);
191 return mid;
192 }
193 }
194 spin_unlock(&GlobalMid_Lock);
195 return NULL;
196}
197
198static void
199smb2_dump_detail(void *buf)
200{
201#ifdef CONFIG_CIFS_DEBUG2
202 struct smb2_hdr *smb = (struct smb2_hdr *)buf;
203
Joe Perchesf96637b2013-05-04 22:12:25 -0500204 cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
205 smb->Command, smb->Status, smb->Flags, smb->MessageId,
206 smb->ProcessId);
207 cifs_dbg(VFS, "smb buf %p len %u\n", smb, smb2_calc_size(smb));
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400208#endif
209}
210
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400211static bool
212smb2_need_neg(struct TCP_Server_Info *server)
213{
214 return server->max_read == 0;
215}
216
217static int
218smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
219{
220 int rc;
221 ses->server->CurrentMid = 0;
222 rc = SMB2_negotiate(xid, ses);
223 /* BB we probably don't need to retry with modern servers */
224 if (rc == -EAGAIN)
225 rc = -EHOSTDOWN;
226 return rc;
227}
228
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700229static unsigned int
230smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
231{
232 struct TCP_Server_Info *server = tcon->ses->server;
233 unsigned int wsize;
234
235 /* start with specified wsize, or default */
236 wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
237 wsize = min_t(unsigned int, wsize, server->max_write);
Pavel Shilovskycb7e9ea2014-06-05 19:03:27 +0400238
239 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
240 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700241
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700242 return wsize;
243}
244
245static unsigned int
246smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
247{
248 struct TCP_Server_Info *server = tcon->ses->server;
249 unsigned int rsize;
250
251 /* start with specified rsize, or default */
252 rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
253 rsize = min_t(unsigned int, rsize, server->max_read);
Pavel Shilovskybed9da02014-06-25 11:28:57 +0400254
255 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
256 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700257
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700258 return rsize;
259}
260
Steve Frenchc481e9f2013-10-14 01:21:53 -0500261#ifdef CONFIG_CIFS_STATS2
262static int
263SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon)
264{
265 int rc;
266 unsigned int ret_data_len = 0;
267 struct network_interface_info_ioctl_rsp *out_buf;
268
269 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
270 FSCTL_QUERY_NETWORK_INTERFACE_INFO, true /* is_fsctl */,
271 NULL /* no data input */, 0 /* no data input */,
272 (char **)&out_buf, &ret_data_len);
Steve French9ffc5412014-10-16 15:13:14 -0500273 if (rc != 0)
274 cifs_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
275 else if (ret_data_len < sizeof(struct network_interface_info_ioctl_rsp)) {
276 cifs_dbg(VFS, "server returned bad net interface info buf\n");
277 rc = -EINVAL;
278 } else {
Steve Frenchc481e9f2013-10-14 01:21:53 -0500279 /* Dump info on first interface */
280 cifs_dbg(FYI, "Adapter Capability 0x%x\t",
281 le32_to_cpu(out_buf->Capability));
282 cifs_dbg(FYI, "Link Speed %lld\n",
283 le64_to_cpu(out_buf->LinkSpeed));
Steve French9ffc5412014-10-16 15:13:14 -0500284 }
Steve Frenchc481e9f2013-10-14 01:21:53 -0500285
286 return rc;
287}
288#endif /* STATS2 */
289
Steve French34f62642013-10-09 02:07:00 -0500290static void
Steven Frenchaf6a12e2013-10-09 20:55:53 -0500291smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
292{
293 int rc;
294 __le16 srch_path = 0; /* Null - open root of share */
295 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
296 struct cifs_open_parms oparms;
297 struct cifs_fid fid;
298
299 oparms.tcon = tcon;
300 oparms.desired_access = FILE_READ_ATTRIBUTES;
301 oparms.disposition = FILE_OPEN;
302 oparms.create_options = 0;
303 oparms.fid = &fid;
304 oparms.reconnect = false;
305
306 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
307 if (rc)
308 return;
309
Steve Frenchc481e9f2013-10-14 01:21:53 -0500310#ifdef CONFIG_CIFS_STATS2
311 SMB3_request_interfaces(xid, tcon);
312#endif /* STATS2 */
313
Steven Frenchaf6a12e2013-10-09 20:55:53 -0500314 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
315 FS_ATTRIBUTE_INFORMATION);
316 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
317 FS_DEVICE_INFORMATION);
318 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
319 FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
320 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
321 return;
322}
323
324static void
Steve French34f62642013-10-09 02:07:00 -0500325smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
326{
327 int rc;
328 __le16 srch_path = 0; /* Null - open root of share */
329 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
330 struct cifs_open_parms oparms;
331 struct cifs_fid fid;
332
333 oparms.tcon = tcon;
334 oparms.desired_access = FILE_READ_ATTRIBUTES;
335 oparms.disposition = FILE_OPEN;
336 oparms.create_options = 0;
337 oparms.fid = &fid;
338 oparms.reconnect = false;
339
340 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
341 if (rc)
342 return;
343
Steven French21671142013-10-09 13:36:35 -0500344 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
345 FS_ATTRIBUTE_INFORMATION);
346 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
347 FS_DEVICE_INFORMATION);
Steve French34f62642013-10-09 02:07:00 -0500348 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
349 return;
350}
351
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400352static int
353smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
354 struct cifs_sb_info *cifs_sb, const char *full_path)
355{
356 int rc;
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400357 __le16 *utf16_path;
Pavel Shilovsky2e44b282012-09-18 16:20:33 -0700358 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400359 struct cifs_open_parms oparms;
360 struct cifs_fid fid;
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400361
362 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
363 if (!utf16_path)
364 return -ENOMEM;
365
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400366 oparms.tcon = tcon;
367 oparms.desired_access = FILE_READ_ATTRIBUTES;
368 oparms.disposition = FILE_OPEN;
369 oparms.create_options = 0;
370 oparms.fid = &fid;
Pavel Shilovsky9cbc0b72013-07-09 18:40:58 +0400371 oparms.reconnect = false;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400372
Pavel Shilovskyb42bf882013-08-14 19:25:21 +0400373 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400374 if (rc) {
375 kfree(utf16_path);
376 return rc;
377 }
378
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400379 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400380 kfree(utf16_path);
381 return rc;
382}
383
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +0400384static int
385smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
386 struct cifs_sb_info *cifs_sb, const char *full_path,
387 u64 *uniqueid, FILE_ALL_INFO *data)
388{
389 *uniqueid = le64_to_cpu(data->IndexNumber);
390 return 0;
391}
392
Pavel Shilovskyb7546bc2012-09-18 16:20:27 -0700393static int
394smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
395 struct cifs_fid *fid, FILE_ALL_INFO *data)
396{
397 int rc;
398 struct smb2_file_all_info *smb2_data;
399
Pavel Shilovsky1bbe4992014-08-22 13:32:11 +0400400 smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
Pavel Shilovskyb7546bc2012-09-18 16:20:27 -0700401 GFP_KERNEL);
402 if (smb2_data == NULL)
403 return -ENOMEM;
404
405 rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
406 smb2_data);
407 if (!rc)
408 move_smb2_info_to_cifs(data, smb2_data);
409 kfree(smb2_data);
410 return rc;
411}
412
Pavel Shilovsky9094fad2012-07-12 18:30:44 +0400413static bool
414smb2_can_echo(struct TCP_Server_Info *server)
415{
416 return server->echoes;
417}
418
Pavel Shilovskyd60622e2012-05-28 15:19:39 +0400419static void
420smb2_clear_stats(struct cifs_tcon *tcon)
421{
422#ifdef CONFIG_CIFS_STATS
423 int i;
424 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
425 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
426 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
427 }
428#endif
429}
430
431static void
Steve French769ee6a2013-06-19 14:15:30 -0500432smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
433{
434 seq_puts(m, "\n\tShare Capabilities:");
435 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
436 seq_puts(m, " DFS,");
437 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
438 seq_puts(m, " CONTINUOUS AVAILABILITY,");
439 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
440 seq_puts(m, " SCALEOUT,");
441 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
442 seq_puts(m, " CLUSTER,");
443 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
444 seq_puts(m, " ASYMMETRIC,");
445 if (tcon->capabilities == 0)
446 seq_puts(m, " None");
Steven Frenchaf6a12e2013-10-09 20:55:53 -0500447 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
448 seq_puts(m, " Aligned,");
449 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
450 seq_puts(m, " Partition Aligned,");
451 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
452 seq_puts(m, " SSD,");
453 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
454 seq_puts(m, " TRIM-support,");
455
Steve French769ee6a2013-06-19 14:15:30 -0500456 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
Steven Frenchaf6a12e2013-10-09 20:55:53 -0500457 if (tcon->perf_sector_size)
458 seq_printf(m, "\tOptimal sector size: 0x%x",
459 tcon->perf_sector_size);
Steve French769ee6a2013-06-19 14:15:30 -0500460}
461
462static void
Pavel Shilovskyd60622e2012-05-28 15:19:39 +0400463smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
464{
465#ifdef CONFIG_CIFS_STATS
466 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
467 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
468 seq_printf(m, "\nNegotiates: %d sent %d failed",
469 atomic_read(&sent[SMB2_NEGOTIATE_HE]),
470 atomic_read(&failed[SMB2_NEGOTIATE_HE]));
471 seq_printf(m, "\nSessionSetups: %d sent %d failed",
472 atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
473 atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
Pavel Shilovskyd60622e2012-05-28 15:19:39 +0400474 seq_printf(m, "\nLogoffs: %d sent %d failed",
475 atomic_read(&sent[SMB2_LOGOFF_HE]),
476 atomic_read(&failed[SMB2_LOGOFF_HE]));
477 seq_printf(m, "\nTreeConnects: %d sent %d failed",
478 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
479 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
480 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
481 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
482 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
483 seq_printf(m, "\nCreates: %d sent %d failed",
484 atomic_read(&sent[SMB2_CREATE_HE]),
485 atomic_read(&failed[SMB2_CREATE_HE]));
486 seq_printf(m, "\nCloses: %d sent %d failed",
487 atomic_read(&sent[SMB2_CLOSE_HE]),
488 atomic_read(&failed[SMB2_CLOSE_HE]));
489 seq_printf(m, "\nFlushes: %d sent %d failed",
490 atomic_read(&sent[SMB2_FLUSH_HE]),
491 atomic_read(&failed[SMB2_FLUSH_HE]));
492 seq_printf(m, "\nReads: %d sent %d failed",
493 atomic_read(&sent[SMB2_READ_HE]),
494 atomic_read(&failed[SMB2_READ_HE]));
495 seq_printf(m, "\nWrites: %d sent %d failed",
496 atomic_read(&sent[SMB2_WRITE_HE]),
497 atomic_read(&failed[SMB2_WRITE_HE]));
498 seq_printf(m, "\nLocks: %d sent %d failed",
499 atomic_read(&sent[SMB2_LOCK_HE]),
500 atomic_read(&failed[SMB2_LOCK_HE]));
501 seq_printf(m, "\nIOCTLs: %d sent %d failed",
502 atomic_read(&sent[SMB2_IOCTL_HE]),
503 atomic_read(&failed[SMB2_IOCTL_HE]));
504 seq_printf(m, "\nCancels: %d sent %d failed",
505 atomic_read(&sent[SMB2_CANCEL_HE]),
506 atomic_read(&failed[SMB2_CANCEL_HE]));
507 seq_printf(m, "\nEchos: %d sent %d failed",
508 atomic_read(&sent[SMB2_ECHO_HE]),
509 atomic_read(&failed[SMB2_ECHO_HE]));
510 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
511 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
512 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
513 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
514 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
515 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
516 seq_printf(m, "\nQueryInfos: %d sent %d failed",
517 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
518 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
519 seq_printf(m, "\nSetInfos: %d sent %d failed",
520 atomic_read(&sent[SMB2_SET_INFO_HE]),
521 atomic_read(&failed[SMB2_SET_INFO_HE]));
522 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
523 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
524 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
525#endif
526}
527
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700528static void
529smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
530{
David Howells2b0143b2015-03-17 22:25:59 +0000531 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
Pavel Shilovsky53ef1012013-09-05 16:11:28 +0400532 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
533
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700534 cfile->fid.persistent_fid = fid->persistent_fid;
535 cfile->fid.volatile_fid = fid->volatile_fid;
Pavel Shilovsky42873b02013-09-05 21:30:16 +0400536 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
537 &fid->purge_cache);
Pavel Shilovsky18cceb62013-09-05 13:01:06 +0400538 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700539}
540
Pavel Shilovsky760ad0c2012-09-25 11:00:07 +0400541static void
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700542smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
543 struct cifs_fid *fid)
544{
Pavel Shilovsky760ad0c2012-09-25 11:00:07 +0400545 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700546}
547
Pavel Shilovsky7a5cfb12012-09-18 16:20:28 -0700548static int
Steve French41c13582013-11-14 00:05:36 -0600549SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
550 u64 persistent_fid, u64 volatile_fid,
551 struct copychunk_ioctl *pcchunk)
552{
553 int rc;
554 unsigned int ret_data_len;
555 struct resume_key_req *res_key;
556
557 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
558 FSCTL_SRV_REQUEST_RESUME_KEY, true /* is_fsctl */,
559 NULL, 0 /* no input */,
560 (char **)&res_key, &ret_data_len);
561
562 if (rc) {
563 cifs_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
564 goto req_res_key_exit;
565 }
566 if (ret_data_len < sizeof(struct resume_key_req)) {
567 cifs_dbg(VFS, "Invalid refcopy resume key length\n");
568 rc = -EINVAL;
569 goto req_res_key_exit;
570 }
571 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
572
573req_res_key_exit:
574 kfree(res_key);
575 return rc;
576}
577
578static int
579smb2_clone_range(const unsigned int xid,
580 struct cifsFileInfo *srcfile,
581 struct cifsFileInfo *trgtfile, u64 src_off,
582 u64 len, u64 dest_off)
583{
584 int rc;
585 unsigned int ret_data_len;
586 struct copychunk_ioctl *pcchunk;
Steve French9bf0c9c2013-11-16 18:05:28 -0600587 struct copychunk_ioctl_rsp *retbuf = NULL;
588 struct cifs_tcon *tcon;
589 int chunks_copied = 0;
590 bool chunk_sizes_updated = false;
Steve French41c13582013-11-14 00:05:36 -0600591
592 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
593
594 if (pcchunk == NULL)
595 return -ENOMEM;
596
597 cifs_dbg(FYI, "in smb2_clone_range - about to call request res key\n");
598 /* Request a key from the server to identify the source of the copy */
599 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
600 srcfile->fid.persistent_fid,
601 srcfile->fid.volatile_fid, pcchunk);
602
603 /* Note: request_res_key sets res_key null only if rc !=0 */
604 if (rc)
Steve French9bf0c9c2013-11-16 18:05:28 -0600605 goto cchunk_out;
Steve French41c13582013-11-14 00:05:36 -0600606
607 /* For now array only one chunk long, will make more flexible later */
Fabian Frederickbc09d142014-12-10 15:41:15 -0800608 pcchunk->ChunkCount = cpu_to_le32(1);
Steve French41c13582013-11-14 00:05:36 -0600609 pcchunk->Reserved = 0;
Steve French41c13582013-11-14 00:05:36 -0600610 pcchunk->Reserved2 = 0;
611
Steve French9bf0c9c2013-11-16 18:05:28 -0600612 tcon = tlink_tcon(trgtfile->tlink);
613
614 while (len > 0) {
615 pcchunk->SourceOffset = cpu_to_le64(src_off);
616 pcchunk->TargetOffset = cpu_to_le64(dest_off);
617 pcchunk->Length =
618 cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
619
620 /* Request server copy to target from src identified by key */
621 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
Steve French41c13582013-11-14 00:05:36 -0600622 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
623 true /* is_fsctl */, (char *)pcchunk,
Steve French9bf0c9c2013-11-16 18:05:28 -0600624 sizeof(struct copychunk_ioctl), (char **)&retbuf,
625 &ret_data_len);
626 if (rc == 0) {
627 if (ret_data_len !=
628 sizeof(struct copychunk_ioctl_rsp)) {
629 cifs_dbg(VFS, "invalid cchunk response size\n");
630 rc = -EIO;
631 goto cchunk_out;
632 }
633 if (retbuf->TotalBytesWritten == 0) {
634 cifs_dbg(FYI, "no bytes copied\n");
635 rc = -EIO;
636 goto cchunk_out;
637 }
638 /*
639 * Check if server claimed to write more than we asked
640 */
641 if (le32_to_cpu(retbuf->TotalBytesWritten) >
642 le32_to_cpu(pcchunk->Length)) {
643 cifs_dbg(VFS, "invalid copy chunk response\n");
644 rc = -EIO;
645 goto cchunk_out;
646 }
647 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
648 cifs_dbg(VFS, "invalid num chunks written\n");
649 rc = -EIO;
650 goto cchunk_out;
651 }
652 chunks_copied++;
Steve French41c13582013-11-14 00:05:36 -0600653
Steve French9bf0c9c2013-11-16 18:05:28 -0600654 src_off += le32_to_cpu(retbuf->TotalBytesWritten);
655 dest_off += le32_to_cpu(retbuf->TotalBytesWritten);
656 len -= le32_to_cpu(retbuf->TotalBytesWritten);
Steve French41c13582013-11-14 00:05:36 -0600657
Steve French9bf0c9c2013-11-16 18:05:28 -0600658 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %d\n",
659 le32_to_cpu(retbuf->ChunksWritten),
660 le32_to_cpu(retbuf->ChunkBytesWritten),
661 le32_to_cpu(retbuf->TotalBytesWritten));
662 } else if (rc == -EINVAL) {
663 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
664 goto cchunk_out;
Steve French41c13582013-11-14 00:05:36 -0600665
Steve French9bf0c9c2013-11-16 18:05:28 -0600666 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
667 le32_to_cpu(retbuf->ChunksWritten),
668 le32_to_cpu(retbuf->ChunkBytesWritten),
669 le32_to_cpu(retbuf->TotalBytesWritten));
670
671 /*
672 * Check if this is the first request using these sizes,
673 * (ie check if copy succeed once with original sizes
674 * and check if the server gave us different sizes after
675 * we already updated max sizes on previous request).
676 * if not then why is the server returning an error now
677 */
678 if ((chunks_copied != 0) || chunk_sizes_updated)
679 goto cchunk_out;
680
681 /* Check that server is not asking us to grow size */
682 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
683 tcon->max_bytes_chunk)
684 tcon->max_bytes_chunk =
685 le32_to_cpu(retbuf->ChunkBytesWritten);
686 else
687 goto cchunk_out; /* server gave us bogus size */
688
689 /* No need to change MaxChunks since already set to 1 */
690 chunk_sizes_updated = true;
Sachin Prabhu2477bc52015-02-04 13:10:26 +0000691 } else
692 goto cchunk_out;
Steve French9bf0c9c2013-11-16 18:05:28 -0600693 }
694
695cchunk_out:
Steve French41c13582013-11-14 00:05:36 -0600696 kfree(pcchunk);
697 return rc;
698}
699
700static int
Pavel Shilovsky7a5cfb12012-09-18 16:20:28 -0700701smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
702 struct cifs_fid *fid)
703{
704 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
705}
706
Pavel Shilovsky09a47072012-09-18 16:20:29 -0700707static unsigned int
708smb2_read_data_offset(char *buf)
709{
710 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
711 return rsp->DataOffset;
712}
713
714static unsigned int
715smb2_read_data_length(char *buf)
716{
717 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
718 return le32_to_cpu(rsp->DataLength);
719}
720
Pavel Shilovskyd8e05032012-09-18 16:20:30 -0700721
722static int
Steve Frenchdb8b6312014-09-22 05:13:55 -0500723smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
Pavel Shilovskyd8e05032012-09-18 16:20:30 -0700724 struct cifs_io_parms *parms, unsigned int *bytes_read,
725 char **buf, int *buf_type)
726{
Steve Frenchdb8b6312014-09-22 05:13:55 -0500727 parms->persistent_fid = pfid->persistent_fid;
728 parms->volatile_fid = pfid->volatile_fid;
Pavel Shilovskyd8e05032012-09-18 16:20:30 -0700729 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
730}
731
Pavel Shilovsky009d3442012-09-18 16:20:30 -0700732static int
Steve Frenchdb8b6312014-09-22 05:13:55 -0500733smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
Pavel Shilovsky009d3442012-09-18 16:20:30 -0700734 struct cifs_io_parms *parms, unsigned int *written,
735 struct kvec *iov, unsigned long nr_segs)
736{
737
Steve Frenchdb8b6312014-09-22 05:13:55 -0500738 parms->persistent_fid = pfid->persistent_fid;
739 parms->volatile_fid = pfid->volatile_fid;
Pavel Shilovsky009d3442012-09-18 16:20:30 -0700740 return SMB2_write(xid, parms, written, iov, nr_segs);
741}
742
Steve Frenchd43cc792014-08-13 17:16:29 -0500743/* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
744static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
745 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
746{
747 struct cifsInodeInfo *cifsi;
748 int rc;
749
750 cifsi = CIFS_I(inode);
751
752 /* if file already sparse don't bother setting sparse again */
753 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
754 return true; /* already sparse */
755
756 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
757 return true; /* already not sparse */
758
759 /*
760 * Can't check for sparse support on share the usual way via the
761 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
762 * since Samba server doesn't set the flag on the share, yet
763 * supports the set sparse FSCTL and returns sparse correctly
764 * in the file attributes. If we fail setting sparse though we
765 * mark that server does not support sparse files for this share
766 * to avoid repeatedly sending the unsupported fsctl to server
767 * if the file is repeatedly extended.
768 */
769 if (tcon->broken_sparse_sup)
770 return false;
771
772 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
773 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
774 true /* is_fctl */, &setsparse, 1, NULL, NULL);
775 if (rc) {
776 tcon->broken_sparse_sup = true;
777 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
778 return false;
779 }
780
781 if (setsparse)
782 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
783 else
784 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
785
786 return true;
787}
788
Pavel Shilovskyc839ff22012-09-18 16:20:32 -0700789static int
790smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
791 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
792{
793 __le64 eof = cpu_to_le64(size);
Steve French3d1a3742014-08-11 21:05:25 -0500794 struct inode *inode;
795
796 /*
797 * If extending file more than one page make sparse. Many Linux fs
798 * make files sparse by default when extending via ftruncate
799 */
David Howells2b0143b2015-03-17 22:25:59 +0000800 inode = d_inode(cfile->dentry);
Steve French3d1a3742014-08-11 21:05:25 -0500801
802 if (!set_alloc && (size > inode->i_size + 8192)) {
Steve French3d1a3742014-08-11 21:05:25 -0500803 __u8 set_sparse = 1;
Steve French3d1a3742014-08-11 21:05:25 -0500804
Steve Frenchd43cc792014-08-13 17:16:29 -0500805 /* whether set sparse succeeds or not, extend the file */
806 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
Steve French3d1a3742014-08-11 21:05:25 -0500807 }
808
Pavel Shilovskyc839ff22012-09-18 16:20:32 -0700809 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
Steve Frenchf29ebb42014-07-19 21:44:58 -0500810 cfile->fid.volatile_fid, cfile->pid, &eof, false);
Pavel Shilovskyc839ff22012-09-18 16:20:32 -0700811}
812
Steve French02b16662015-06-27 21:18:36 -0700813static int
814smb2_duplicate_extents(const unsigned int xid,
815 struct cifsFileInfo *srcfile,
816 struct cifsFileInfo *trgtfile, u64 src_off,
817 u64 len, u64 dest_off)
818{
819 int rc;
820 unsigned int ret_data_len;
821 char *retbuf = NULL;
822 struct duplicate_extents_to_file dup_ext_buf;
823 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
824
825 /* server fileays advertise duplicate extent support with this flag */
826 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
827 FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
828 return -EOPNOTSUPP;
829
830 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
831 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
832 dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
833 dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
834 dup_ext_buf.ByteCount = cpu_to_le64(len);
835 cifs_dbg(FYI, "duplicate extents: src off %lld dst off %lld len %lld",
836 src_off, dest_off, len);
837
838 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
839 if (rc)
840 goto duplicate_extents_out;
841
842 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
843 trgtfile->fid.volatile_fid,
844 FSCTL_DUPLICATE_EXTENTS_TO_FILE,
845 true /* is_fsctl */, (char *)&dup_ext_buf,
846 sizeof(struct duplicate_extents_to_file),
847 (char **)&retbuf,
848 &ret_data_len);
849
850 if (ret_data_len > 0)
851 cifs_dbg(FYI, "non-zero response length in duplicate extents");
852
853duplicate_extents_out:
854 return rc;
855}
Steve French02b16662015-06-27 21:18:36 -0700856
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700857static int
Steve French64a5cfa2013-10-14 15:31:32 -0500858smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
859 struct cifsFileInfo *cfile)
860{
861 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
862 cfile->fid.volatile_fid);
863}
864
865static int
Steve Frenchb3152e22015-06-24 03:17:02 -0500866smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
867 struct cifsFileInfo *cfile)
868{
869 struct fsctl_set_integrity_information_req integr_info;
870 char *retbuf = NULL;
871 unsigned int ret_data_len;
872
873 integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
874 integr_info.Flags = 0;
875 integr_info.Reserved = 0;
876
877 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
878 cfile->fid.volatile_fid,
879 FSCTL_SET_INTEGRITY_INFORMATION,
880 true /* is_fsctl */, (char *)&integr_info,
881 sizeof(struct fsctl_set_integrity_information_req),
882 (char **)&retbuf,
883 &ret_data_len);
884
885}
886
887static int
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700888smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
889 const char *path, struct cifs_sb_info *cifs_sb,
890 struct cifs_fid *fid, __u16 search_flags,
891 struct cifs_search_info *srch_inf)
892{
893 __le16 *utf16_path;
894 int rc;
Pavel Shilovsky2e44b282012-09-18 16:20:33 -0700895 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400896 struct cifs_open_parms oparms;
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700897
898 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
899 if (!utf16_path)
900 return -ENOMEM;
901
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400902 oparms.tcon = tcon;
903 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
904 oparms.disposition = FILE_OPEN;
905 oparms.create_options = 0;
906 oparms.fid = fid;
Pavel Shilovsky9cbc0b72013-07-09 18:40:58 +0400907 oparms.reconnect = false;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400908
Pavel Shilovskyb42bf882013-08-14 19:25:21 +0400909 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700910 kfree(utf16_path);
911 if (rc) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500912 cifs_dbg(VFS, "open dir failed\n");
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700913 return rc;
914 }
915
916 srch_inf->entries_in_buffer = 0;
917 srch_inf->index_of_last_entry = 0;
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700918
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400919 rc = SMB2_query_directory(xid, tcon, fid->persistent_fid,
920 fid->volatile_fid, 0, srch_inf);
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700921 if (rc) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500922 cifs_dbg(VFS, "query directory failed\n");
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400923 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700924 }
925 return rc;
926}
927
928static int
929smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
930 struct cifs_fid *fid, __u16 search_flags,
931 struct cifs_search_info *srch_inf)
932{
933 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
934 fid->volatile_fid, 0, srch_inf);
935}
936
937static int
938smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
939 struct cifs_fid *fid)
940{
941 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
942}
943
Pavel Shilovsky2e44b282012-09-18 16:20:33 -0700944/*
945* If we negotiate SMB2 protocol and get STATUS_PENDING - update
946* the number of credits and return true. Otherwise - return false.
947*/
948static bool
949smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
950{
951 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
952
Steve French12e8a202012-09-19 09:19:39 -0700953 if (hdr->Status != STATUS_PENDING)
Pavel Shilovsky2e44b282012-09-18 16:20:33 -0700954 return false;
955
956 if (!length) {
957 spin_lock(&server->req_lock);
958 server->credits += le16_to_cpu(hdr->CreditRequest);
959 spin_unlock(&server->req_lock);
960 wake_up(&server->request_q);
961 }
962
963 return true;
964}
965
Pavel Shilovsky983c88a2012-09-18 16:20:33 -0700966static int
967smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
968 struct cifsInodeInfo *cinode)
969{
Pavel Shilovsky0822f512012-09-19 06:22:45 -0700970 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
971 return SMB2_lease_break(0, tcon, cinode->lease_key,
972 smb2_get_lease_state(cinode));
973
Pavel Shilovsky983c88a2012-09-18 16:20:33 -0700974 return SMB2_oplock_break(0, tcon, fid->persistent_fid,
975 fid->volatile_fid,
Pavel Shilovsky18cceb62013-09-05 13:01:06 +0400976 CIFS_CACHE_READ(cinode) ? 1 : 0);
Pavel Shilovsky983c88a2012-09-18 16:20:33 -0700977}
978
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -0700979static int
980smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
981 struct kstatfs *buf)
982{
983 int rc;
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -0700984 __le16 srch_path = 0; /* Null - open root of share */
985 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400986 struct cifs_open_parms oparms;
987 struct cifs_fid fid;
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -0700988
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400989 oparms.tcon = tcon;
990 oparms.desired_access = FILE_READ_ATTRIBUTES;
991 oparms.disposition = FILE_OPEN;
992 oparms.create_options = 0;
993 oparms.fid = &fid;
Pavel Shilovsky9cbc0b72013-07-09 18:40:58 +0400994 oparms.reconnect = false;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400995
Pavel Shilovskyb42bf882013-08-14 19:25:21 +0400996 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -0700997 if (rc)
998 return rc;
999 buf->f_type = SMB2_MAGIC_NUMBER;
Pavel Shilovsky064f6042013-07-09 18:20:30 +04001000 rc = SMB2_QFS_info(xid, tcon, fid.persistent_fid, fid.volatile_fid,
1001 buf);
1002 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001003 return rc;
1004}
1005
Pavel Shilovsky027e8ee2012-09-19 06:22:43 -07001006static bool
1007smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
1008{
1009 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
1010 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
1011}
1012
Pavel Shilovskyf7ba7fe2012-09-19 06:22:43 -07001013static int
1014smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
1015 __u64 length, __u32 type, int lock, int unlock, bool wait)
1016{
1017 if (unlock && !lock)
1018 type = SMB2_LOCKFLAG_UNLOCK;
1019 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
1020 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
1021 current->tgid, length, offset, type, wait);
1022}
1023
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -07001024static void
1025smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
1026{
1027 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
1028}
1029
1030static void
1031smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
1032{
1033 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
1034}
1035
1036static void
1037smb2_new_lease_key(struct cifs_fid *fid)
1038{
1039 get_random_bytes(fid->lease_key, SMB2_LEASE_KEY_SIZE);
1040}
1041
Pavel Shilovskyadc58bf2016-07-24 10:37:38 +03001042#define SMB2_SYMLINK_STRUCT_SIZE \
1043 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
1044
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001045static int
1046smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
1047 const char *full_path, char **target_path,
1048 struct cifs_sb_info *cifs_sb)
1049{
1050 int rc;
1051 __le16 *utf16_path;
1052 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1053 struct cifs_open_parms oparms;
1054 struct cifs_fid fid;
1055 struct smb2_err_rsp *err_buf = NULL;
1056 struct smb2_symlink_err_rsp *symlink;
Pavel Shilovskyadc58bf2016-07-24 10:37:38 +03001057 unsigned int sub_len;
1058 unsigned int sub_offset;
1059 unsigned int print_len;
1060 unsigned int print_offset;
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001061
1062 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
1063
1064 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
1065 if (!utf16_path)
1066 return -ENOMEM;
1067
1068 oparms.tcon = tcon;
1069 oparms.desired_access = FILE_READ_ATTRIBUTES;
1070 oparms.disposition = FILE_OPEN;
1071 oparms.create_options = 0;
1072 oparms.fid = &fid;
1073 oparms.reconnect = false;
1074
1075 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_buf);
1076
1077 if (!rc || !err_buf) {
1078 kfree(utf16_path);
1079 return -ENOENT;
1080 }
Pavel Shilovskyadc58bf2016-07-24 10:37:38 +03001081
1082 if (le32_to_cpu(err_buf->ByteCount) < sizeof(struct smb2_symlink_err_rsp) ||
1083 get_rfc1002_length(err_buf) + 4 < SMB2_SYMLINK_STRUCT_SIZE) {
1084 kfree(utf16_path);
1085 return -ENOENT;
1086 }
1087
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001088 /* open must fail on symlink - reset rc */
1089 rc = 0;
1090 symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
1091 sub_len = le16_to_cpu(symlink->SubstituteNameLength);
1092 sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
Pavel Shilovskyadc58bf2016-07-24 10:37:38 +03001093 print_len = le16_to_cpu(symlink->PrintNameLength);
1094 print_offset = le16_to_cpu(symlink->PrintNameOffset);
1095
1096 if (get_rfc1002_length(err_buf) + 4 <
1097 SMB2_SYMLINK_STRUCT_SIZE + sub_offset + sub_len) {
1098 kfree(utf16_path);
1099 return -ENOENT;
1100 }
1101
1102 if (get_rfc1002_length(err_buf) + 4 <
1103 SMB2_SYMLINK_STRUCT_SIZE + print_offset + print_len) {
1104 kfree(utf16_path);
1105 return -ENOENT;
1106 }
1107
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001108 *target_path = cifs_strndup_from_utf16(
1109 (char *)symlink->PathBuffer + sub_offset,
1110 sub_len, true, cifs_sb->local_nls);
1111 if (!(*target_path)) {
1112 kfree(utf16_path);
1113 return -ENOMEM;
1114 }
1115 convert_delimiter(*target_path, '/');
1116 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
1117 kfree(utf16_path);
1118 return rc;
1119}
1120
Steve French30175622014-08-17 18:16:40 -05001121static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
1122 loff_t offset, loff_t len, bool keep_size)
1123{
1124 struct inode *inode;
1125 struct cifsInodeInfo *cifsi;
1126 struct cifsFileInfo *cfile = file->private_data;
1127 struct file_zero_data_information fsctl_buf;
1128 long rc;
1129 unsigned int xid;
1130
1131 xid = get_xid();
1132
David Howells2b0143b2015-03-17 22:25:59 +00001133 inode = d_inode(cfile->dentry);
Steve French30175622014-08-17 18:16:40 -05001134 cifsi = CIFS_I(inode);
1135
1136 /* if file not oplocked can't be sure whether asking to extend size */
1137 if (!CIFS_CACHE_READ(cifsi))
1138 if (keep_size == false)
1139 return -EOPNOTSUPP;
1140
Steve French2bb93d22014-08-20 18:56:29 -05001141 /*
Steve French30175622014-08-17 18:16:40 -05001142 * Must check if file sparse since fallocate -z (zero range) assumes
1143 * non-sparse allocation
1144 */
1145 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE))
1146 return -EOPNOTSUPP;
1147
1148 /*
1149 * need to make sure we are not asked to extend the file since the SMB3
1150 * fsctl does not change the file size. In the future we could change
1151 * this to zero the first part of the range then set the file size
1152 * which for a non sparse file would zero the newly extended range
1153 */
1154 if (keep_size == false)
1155 if (i_size_read(inode) < offset + len)
1156 return -EOPNOTSUPP;
1157
1158 cifs_dbg(FYI, "offset %lld len %lld", offset, len);
1159
1160 fsctl_buf.FileOffset = cpu_to_le64(offset);
1161 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
1162
1163 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1164 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
1165 true /* is_fctl */, (char *)&fsctl_buf,
1166 sizeof(struct file_zero_data_information), NULL, NULL);
1167 free_xid(xid);
1168 return rc;
1169}
1170
Steve French31742c52014-08-17 08:38:47 -05001171static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
1172 loff_t offset, loff_t len)
1173{
1174 struct inode *inode;
1175 struct cifsInodeInfo *cifsi;
1176 struct cifsFileInfo *cfile = file->private_data;
1177 struct file_zero_data_information fsctl_buf;
1178 long rc;
1179 unsigned int xid;
1180 __u8 set_sparse = 1;
1181
1182 xid = get_xid();
1183
David Howells2b0143b2015-03-17 22:25:59 +00001184 inode = d_inode(cfile->dentry);
Steve French31742c52014-08-17 08:38:47 -05001185 cifsi = CIFS_I(inode);
1186
1187 /* Need to make file sparse, if not already, before freeing range. */
1188 /* Consider adding equivalent for compressed since it could also work */
1189 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse))
1190 return -EOPNOTSUPP;
1191
1192 cifs_dbg(FYI, "offset %lld len %lld", offset, len);
1193
1194 fsctl_buf.FileOffset = cpu_to_le64(offset);
1195 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
1196
1197 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1198 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
1199 true /* is_fctl */, (char *)&fsctl_buf,
1200 sizeof(struct file_zero_data_information), NULL, NULL);
1201 free_xid(xid);
1202 return rc;
1203}
1204
Steve French9ccf3212014-10-18 17:01:15 -05001205static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
1206 loff_t off, loff_t len, bool keep_size)
1207{
1208 struct inode *inode;
1209 struct cifsInodeInfo *cifsi;
1210 struct cifsFileInfo *cfile = file->private_data;
1211 long rc = -EOPNOTSUPP;
1212 unsigned int xid;
1213
1214 xid = get_xid();
1215
David Howells2b0143b2015-03-17 22:25:59 +00001216 inode = d_inode(cfile->dentry);
Steve French9ccf3212014-10-18 17:01:15 -05001217 cifsi = CIFS_I(inode);
1218
1219 /* if file not oplocked can't be sure whether asking to extend size */
1220 if (!CIFS_CACHE_READ(cifsi))
1221 if (keep_size == false)
1222 return -EOPNOTSUPP;
1223
1224 /*
1225 * Files are non-sparse by default so falloc may be a no-op
1226 * Must check if file sparse. If not sparse, and not extending
1227 * then no need to do anything since file already allocated
1228 */
1229 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
1230 if (keep_size == true)
1231 return 0;
1232 /* check if extending file */
1233 else if (i_size_read(inode) >= off + len)
1234 /* not extending file and already not sparse */
1235 return 0;
1236 /* BB: in future add else clause to extend file */
1237 else
1238 return -EOPNOTSUPP;
1239 }
1240
1241 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
1242 /*
1243 * Check if falloc starts within first few pages of file
1244 * and ends within a few pages of the end of file to
1245 * ensure that most of file is being forced to be
1246 * fallocated now. If so then setting whole file sparse
1247 * ie potentially making a few extra pages at the beginning
1248 * or end of the file non-sparse via set_sparse is harmless.
1249 */
1250 if ((off > 8192) || (off + len + 8192 < i_size_read(inode)))
1251 return -EOPNOTSUPP;
1252
1253 rc = smb2_set_sparse(xid, tcon, cfile, inode, false);
1254 }
1255 /* BB: else ... in future add code to extend file and set sparse */
1256
1257
1258 free_xid(xid);
1259 return rc;
1260}
1261
1262
Steve French31742c52014-08-17 08:38:47 -05001263static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
1264 loff_t off, loff_t len)
1265{
1266 /* KEEP_SIZE already checked for by do_fallocate */
1267 if (mode & FALLOC_FL_PUNCH_HOLE)
1268 return smb3_punch_hole(file, tcon, off, len);
Steve French30175622014-08-17 18:16:40 -05001269 else if (mode & FALLOC_FL_ZERO_RANGE) {
1270 if (mode & FALLOC_FL_KEEP_SIZE)
1271 return smb3_zero_range(file, tcon, off, len, true);
1272 return smb3_zero_range(file, tcon, off, len, false);
Steve French9ccf3212014-10-18 17:01:15 -05001273 } else if (mode == FALLOC_FL_KEEP_SIZE)
1274 return smb3_simple_falloc(file, tcon, off, len, true);
1275 else if (mode == 0)
1276 return smb3_simple_falloc(file, tcon, off, len, false);
Steve French31742c52014-08-17 08:38:47 -05001277
1278 return -EOPNOTSUPP;
1279}
1280
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001281static void
Sachin Prabhuc11f1df2014-03-11 16:11:47 +00001282smb2_downgrade_oplock(struct TCP_Server_Info *server,
1283 struct cifsInodeInfo *cinode, bool set_level2)
1284{
1285 if (set_level2)
1286 server->ops->set_oplock_level(cinode, SMB2_OPLOCK_LEVEL_II,
1287 0, NULL);
1288 else
1289 server->ops->set_oplock_level(cinode, 0, 0, NULL);
1290}
1291
1292static void
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001293smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
1294 unsigned int epoch, bool *purge_cache)
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001295{
1296 oplock &= 0xFF;
1297 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
1298 return;
1299 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001300 cinode->oplock = CIFS_CACHE_RHW_FLG;
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001301 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
1302 &cinode->vfs_inode);
1303 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001304 cinode->oplock = CIFS_CACHE_RW_FLG;
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001305 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
1306 &cinode->vfs_inode);
1307 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
1308 cinode->oplock = CIFS_CACHE_READ_FLG;
1309 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
1310 &cinode->vfs_inode);
1311 } else
1312 cinode->oplock = 0;
1313}
1314
1315static void
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001316smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
1317 unsigned int epoch, bool *purge_cache)
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001318{
1319 char message[5] = {0};
1320
1321 oplock &= 0xFF;
1322 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
1323 return;
1324
1325 cinode->oplock = 0;
1326 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
1327 cinode->oplock |= CIFS_CACHE_READ_FLG;
1328 strcat(message, "R");
1329 }
1330 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
1331 cinode->oplock |= CIFS_CACHE_HANDLE_FLG;
1332 strcat(message, "H");
1333 }
1334 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
1335 cinode->oplock |= CIFS_CACHE_WRITE_FLG;
1336 strcat(message, "W");
1337 }
1338 if (!cinode->oplock)
1339 strcat(message, "None");
1340 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
1341 &cinode->vfs_inode);
1342}
1343
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001344static void
1345smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
1346 unsigned int epoch, bool *purge_cache)
1347{
1348 unsigned int old_oplock = cinode->oplock;
1349
1350 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
1351
1352 if (purge_cache) {
1353 *purge_cache = false;
1354 if (old_oplock == CIFS_CACHE_READ_FLG) {
1355 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
1356 (epoch - cinode->epoch > 0))
1357 *purge_cache = true;
1358 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
1359 (epoch - cinode->epoch > 1))
1360 *purge_cache = true;
1361 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
1362 (epoch - cinode->epoch > 1))
1363 *purge_cache = true;
1364 else if (cinode->oplock == 0 &&
1365 (epoch - cinode->epoch > 0))
1366 *purge_cache = true;
1367 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
1368 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
1369 (epoch - cinode->epoch > 0))
1370 *purge_cache = true;
1371 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
1372 (epoch - cinode->epoch > 1))
1373 *purge_cache = true;
1374 }
1375 cinode->epoch = epoch;
1376 }
1377}
1378
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001379static bool
1380smb2_is_read_op(__u32 oplock)
1381{
1382 return oplock == SMB2_OPLOCK_LEVEL_II;
1383}
1384
1385static bool
1386smb21_is_read_op(__u32 oplock)
1387{
1388 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
1389 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
1390}
1391
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001392static __le32
1393map_oplock_to_lease(u8 oplock)
1394{
1395 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
1396 return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
1397 else if (oplock == SMB2_OPLOCK_LEVEL_II)
1398 return SMB2_LEASE_READ_CACHING;
1399 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
1400 return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING |
1401 SMB2_LEASE_WRITE_CACHING;
1402 return 0;
1403}
1404
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001405static char *
1406smb2_create_lease_buf(u8 *lease_key, u8 oplock)
1407{
1408 struct create_lease *buf;
1409
1410 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
1411 if (!buf)
1412 return NULL;
1413
1414 buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
1415 buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001416 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001417
1418 buf->ccontext.DataOffset = cpu_to_le16(offsetof
1419 (struct create_lease, lcontext));
1420 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
1421 buf->ccontext.NameOffset = cpu_to_le16(offsetof
1422 (struct create_lease, Name));
1423 buf->ccontext.NameLength = cpu_to_le16(4);
Steve French12197a72014-05-14 05:29:40 -07001424 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001425 buf->Name[0] = 'R';
1426 buf->Name[1] = 'q';
1427 buf->Name[2] = 'L';
1428 buf->Name[3] = 's';
1429 return (char *)buf;
1430}
1431
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001432static char *
1433smb3_create_lease_buf(u8 *lease_key, u8 oplock)
1434{
1435 struct create_lease_v2 *buf;
1436
1437 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
1438 if (!buf)
1439 return NULL;
1440
1441 buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
1442 buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
1443 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
1444
1445 buf->ccontext.DataOffset = cpu_to_le16(offsetof
1446 (struct create_lease_v2, lcontext));
1447 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
1448 buf->ccontext.NameOffset = cpu_to_le16(offsetof
1449 (struct create_lease_v2, Name));
1450 buf->ccontext.NameLength = cpu_to_le16(4);
Steve French12197a72014-05-14 05:29:40 -07001451 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001452 buf->Name[0] = 'R';
1453 buf->Name[1] = 'q';
1454 buf->Name[2] = 'L';
1455 buf->Name[3] = 's';
1456 return (char *)buf;
1457}
1458
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04001459static __u8
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001460smb2_parse_lease_buf(void *buf, unsigned int *epoch)
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04001461{
1462 struct create_lease *lc = (struct create_lease *)buf;
1463
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001464 *epoch = 0; /* not used */
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04001465 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
1466 return SMB2_OPLOCK_LEVEL_NOCHANGE;
1467 return le32_to_cpu(lc->lcontext.LeaseState);
1468}
1469
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001470static __u8
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001471smb3_parse_lease_buf(void *buf, unsigned int *epoch)
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001472{
1473 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
1474
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001475 *epoch = le16_to_cpu(lc->lcontext.Epoch);
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001476 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
1477 return SMB2_OPLOCK_LEVEL_NOCHANGE;
1478 return le32_to_cpu(lc->lcontext.LeaseState);
1479}
1480
Pavel Shilovsky7f6c5002014-06-22 11:03:22 +04001481static unsigned int
1482smb2_wp_retry_size(struct inode *inode)
1483{
1484 return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize,
1485 SMB2_MAX_BUFFER_SIZE);
1486}
1487
Pavel Shilovsky52755802014-08-18 20:49:57 +04001488static bool
1489smb2_dir_needs_close(struct cifsFileInfo *cfile)
1490{
1491 return !cfile->invalidHandle;
1492}
1493
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001494struct smb_version_operations smb20_operations = {
1495 .compare_fids = smb2_compare_fids,
1496 .setup_request = smb2_setup_request,
1497 .setup_async_request = smb2_setup_async_request,
1498 .check_receive = smb2_check_receive,
1499 .add_credits = smb2_add_credits,
1500 .set_credits = smb2_set_credits,
1501 .get_credits_field = smb2_get_credits_field,
1502 .get_credits = smb2_get_credits,
Pavel Shilovskycb7e9ea2014-06-05 19:03:27 +04001503 .wait_mtu_credits = cifs_wait_mtu_credits,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001504 .get_next_mid = smb2_get_next_mid,
1505 .read_data_offset = smb2_read_data_offset,
1506 .read_data_length = smb2_read_data_length,
1507 .map_error = map_smb2_to_linux_error,
1508 .find_mid = smb2_find_mid,
1509 .check_message = smb2_check_message,
1510 .dump_detail = smb2_dump_detail,
1511 .clear_stats = smb2_clear_stats,
1512 .print_stats = smb2_print_stats,
1513 .is_oplock_break = smb2_is_valid_oplock_break,
Sachin Prabhuc11f1df2014-03-11 16:11:47 +00001514 .downgrade_oplock = smb2_downgrade_oplock,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001515 .need_neg = smb2_need_neg,
1516 .negotiate = smb2_negotiate,
1517 .negotiate_wsize = smb2_negotiate_wsize,
1518 .negotiate_rsize = smb2_negotiate_rsize,
1519 .sess_setup = SMB2_sess_setup,
1520 .logoff = SMB2_logoff,
1521 .tree_connect = SMB2_tcon,
1522 .tree_disconnect = SMB2_tdis,
Steve French34f62642013-10-09 02:07:00 -05001523 .qfs_tcon = smb2_qfs_tcon,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001524 .is_path_accessible = smb2_is_path_accessible,
1525 .can_echo = smb2_can_echo,
1526 .echo = SMB2_echo,
1527 .query_path_info = smb2_query_path_info,
1528 .get_srv_inum = smb2_get_srv_inum,
1529 .query_file_info = smb2_query_file_info,
1530 .set_path_size = smb2_set_path_size,
1531 .set_file_size = smb2_set_file_size,
1532 .set_file_info = smb2_set_file_info,
Steve French64a5cfa2013-10-14 15:31:32 -05001533 .set_compression = smb2_set_compression,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001534 .mkdir = smb2_mkdir,
1535 .mkdir_setinfo = smb2_mkdir_setinfo,
1536 .rmdir = smb2_rmdir,
1537 .unlink = smb2_unlink,
1538 .rename = smb2_rename_path,
1539 .create_hardlink = smb2_create_hardlink,
1540 .query_symlink = smb2_query_symlink,
1541 .open = smb2_open_file,
1542 .set_fid = smb2_set_fid,
1543 .close = smb2_close_file,
1544 .flush = smb2_flush_file,
1545 .async_readv = smb2_async_readv,
1546 .async_writev = smb2_async_writev,
1547 .sync_read = smb2_sync_read,
1548 .sync_write = smb2_sync_write,
1549 .query_dir_first = smb2_query_dir_first,
1550 .query_dir_next = smb2_query_dir_next,
1551 .close_dir = smb2_close_dir,
1552 .calc_smb_size = smb2_calc_size,
1553 .is_status_pending = smb2_is_status_pending,
1554 .oplock_response = smb2_oplock_response,
1555 .queryfs = smb2_queryfs,
1556 .mand_lock = smb2_mand_lock,
1557 .mand_unlock_range = smb2_unlock_range,
1558 .push_mand_locks = smb2_push_mandatory_locks,
1559 .get_lease_key = smb2_get_lease_key,
1560 .set_lease_key = smb2_set_lease_key,
1561 .new_lease_key = smb2_new_lease_key,
1562 .calc_signature = smb2_calc_signature,
1563 .is_read_op = smb2_is_read_op,
1564 .set_oplock_level = smb2_set_oplock_level,
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001565 .create_lease_buf = smb2_create_lease_buf,
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04001566 .parse_lease_buf = smb2_parse_lease_buf,
Steve French41c13582013-11-14 00:05:36 -06001567 .clone_range = smb2_clone_range,
Pavel Shilovsky7f6c5002014-06-22 11:03:22 +04001568 .wp_retry_size = smb2_wp_retry_size,
Pavel Shilovsky52755802014-08-18 20:49:57 +04001569 .dir_needs_close = smb2_dir_needs_close,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001570};
1571
Steve French1080ef72011-02-24 18:07:19 +00001572struct smb_version_operations smb21_operations = {
Pavel Shilovsky027e8ee2012-09-19 06:22:43 -07001573 .compare_fids = smb2_compare_fids,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +04001574 .setup_request = smb2_setup_request,
Pavel Shilovskyc95b8ee2012-07-11 14:45:28 +04001575 .setup_async_request = smb2_setup_async_request,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +04001576 .check_receive = smb2_check_receive,
Pavel Shilovsky28ea5292012-05-23 16:18:00 +04001577 .add_credits = smb2_add_credits,
1578 .set_credits = smb2_set_credits,
1579 .get_credits_field = smb2_get_credits_field,
1580 .get_credits = smb2_get_credits,
Pavel Shilovskycb7e9ea2014-06-05 19:03:27 +04001581 .wait_mtu_credits = smb2_wait_mtu_credits,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +04001582 .get_next_mid = smb2_get_next_mid,
Pavel Shilovsky09a47072012-09-18 16:20:29 -07001583 .read_data_offset = smb2_read_data_offset,
1584 .read_data_length = smb2_read_data_length,
1585 .map_error = map_smb2_to_linux_error,
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +04001586 .find_mid = smb2_find_mid,
1587 .check_message = smb2_check_message,
1588 .dump_detail = smb2_dump_detail,
Pavel Shilovskyd60622e2012-05-28 15:19:39 +04001589 .clear_stats = smb2_clear_stats,
1590 .print_stats = smb2_print_stats,
Pavel Shilovsky983c88a2012-09-18 16:20:33 -07001591 .is_oplock_break = smb2_is_valid_oplock_break,
Sachin Prabhuc11f1df2014-03-11 16:11:47 +00001592 .downgrade_oplock = smb2_downgrade_oplock,
Pavel Shilovskyec2e4522011-12-27 16:12:43 +04001593 .need_neg = smb2_need_neg,
1594 .negotiate = smb2_negotiate,
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -07001595 .negotiate_wsize = smb2_negotiate_wsize,
1596 .negotiate_rsize = smb2_negotiate_rsize,
Pavel Shilovsky5478f9b2011-12-27 16:22:00 +04001597 .sess_setup = SMB2_sess_setup,
1598 .logoff = SMB2_logoff,
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +04001599 .tree_connect = SMB2_tcon,
1600 .tree_disconnect = SMB2_tdis,
Steve French34f62642013-10-09 02:07:00 -05001601 .qfs_tcon = smb2_qfs_tcon,
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +04001602 .is_path_accessible = smb2_is_path_accessible,
Pavel Shilovsky9094fad2012-07-12 18:30:44 +04001603 .can_echo = smb2_can_echo,
1604 .echo = SMB2_echo,
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +04001605 .query_path_info = smb2_query_path_info,
1606 .get_srv_inum = smb2_get_srv_inum,
Pavel Shilovskyb7546bc2012-09-18 16:20:27 -07001607 .query_file_info = smb2_query_file_info,
Pavel Shilovskyc839ff22012-09-18 16:20:32 -07001608 .set_path_size = smb2_set_path_size,
1609 .set_file_size = smb2_set_file_size,
Pavel Shilovsky1feeaac2012-09-18 16:20:32 -07001610 .set_file_info = smb2_set_file_info,
Steve French64a5cfa2013-10-14 15:31:32 -05001611 .set_compression = smb2_set_compression,
Pavel Shilovskya0e73182011-07-19 12:56:37 +04001612 .mkdir = smb2_mkdir,
1613 .mkdir_setinfo = smb2_mkdir_setinfo,
Pavel Shilovsky1a500f02012-07-10 16:14:38 +04001614 .rmdir = smb2_rmdir,
Pavel Shilovskycbe6f432012-09-18 16:20:25 -07001615 .unlink = smb2_unlink,
Pavel Shilovsky35143eb2012-09-18 16:20:31 -07001616 .rename = smb2_rename_path,
Pavel Shilovsky568798c2012-09-18 16:20:31 -07001617 .create_hardlink = smb2_create_hardlink,
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001618 .query_symlink = smb2_query_symlink,
Steve Frenchc22870e2014-09-16 07:18:19 -05001619 .query_mf_symlink = smb3_query_mf_symlink,
Steve French5ab97572014-09-15 04:49:28 -05001620 .create_mf_symlink = smb3_create_mf_symlink,
Pavel Shilovskyf0df7372012-09-18 16:20:26 -07001621 .open = smb2_open_file,
1622 .set_fid = smb2_set_fid,
1623 .close = smb2_close_file,
Pavel Shilovsky7a5cfb12012-09-18 16:20:28 -07001624 .flush = smb2_flush_file,
Pavel Shilovsky09a47072012-09-18 16:20:29 -07001625 .async_readv = smb2_async_readv,
Pavel Shilovsky33319142012-09-18 16:20:29 -07001626 .async_writev = smb2_async_writev,
Pavel Shilovskyd8e05032012-09-18 16:20:30 -07001627 .sync_read = smb2_sync_read,
Pavel Shilovsky009d3442012-09-18 16:20:30 -07001628 .sync_write = smb2_sync_write,
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -07001629 .query_dir_first = smb2_query_dir_first,
1630 .query_dir_next = smb2_query_dir_next,
1631 .close_dir = smb2_close_dir,
1632 .calc_smb_size = smb2_calc_size,
Pavel Shilovsky2e44b282012-09-18 16:20:33 -07001633 .is_status_pending = smb2_is_status_pending,
Pavel Shilovsky983c88a2012-09-18 16:20:33 -07001634 .oplock_response = smb2_oplock_response,
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001635 .queryfs = smb2_queryfs,
Pavel Shilovskyf7ba7fe2012-09-19 06:22:43 -07001636 .mand_lock = smb2_mand_lock,
1637 .mand_unlock_range = smb2_unlock_range,
Pavel Shilovskyb1407992012-09-19 06:22:44 -07001638 .push_mand_locks = smb2_push_mandatory_locks,
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -07001639 .get_lease_key = smb2_get_lease_key,
1640 .set_lease_key = smb2_set_lease_key,
1641 .new_lease_key = smb2_new_lease_key,
Steve French38107d42012-12-08 22:08:06 -06001642 .calc_signature = smb2_calc_signature,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001643 .is_read_op = smb21_is_read_op,
1644 .set_oplock_level = smb21_set_oplock_level,
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001645 .create_lease_buf = smb2_create_lease_buf,
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04001646 .parse_lease_buf = smb2_parse_lease_buf,
Steve French41c13582013-11-14 00:05:36 -06001647 .clone_range = smb2_clone_range,
Pavel Shilovsky7f6c5002014-06-22 11:03:22 +04001648 .wp_retry_size = smb2_wp_retry_size,
Pavel Shilovsky52755802014-08-18 20:49:57 +04001649 .dir_needs_close = smb2_dir_needs_close,
Steve French38107d42012-12-08 22:08:06 -06001650};
1651
Steve French38107d42012-12-08 22:08:06 -06001652struct smb_version_operations smb30_operations = {
1653 .compare_fids = smb2_compare_fids,
1654 .setup_request = smb2_setup_request,
1655 .setup_async_request = smb2_setup_async_request,
1656 .check_receive = smb2_check_receive,
1657 .add_credits = smb2_add_credits,
1658 .set_credits = smb2_set_credits,
1659 .get_credits_field = smb2_get_credits_field,
1660 .get_credits = smb2_get_credits,
Pavel Shilovskycb7e9ea2014-06-05 19:03:27 +04001661 .wait_mtu_credits = smb2_wait_mtu_credits,
Steve French38107d42012-12-08 22:08:06 -06001662 .get_next_mid = smb2_get_next_mid,
1663 .read_data_offset = smb2_read_data_offset,
1664 .read_data_length = smb2_read_data_length,
1665 .map_error = map_smb2_to_linux_error,
1666 .find_mid = smb2_find_mid,
1667 .check_message = smb2_check_message,
1668 .dump_detail = smb2_dump_detail,
1669 .clear_stats = smb2_clear_stats,
1670 .print_stats = smb2_print_stats,
Steve French769ee6a2013-06-19 14:15:30 -05001671 .dump_share_caps = smb2_dump_share_caps,
Steve French38107d42012-12-08 22:08:06 -06001672 .is_oplock_break = smb2_is_valid_oplock_break,
Sachin Prabhuc11f1df2014-03-11 16:11:47 +00001673 .downgrade_oplock = smb2_downgrade_oplock,
Steve French38107d42012-12-08 22:08:06 -06001674 .need_neg = smb2_need_neg,
1675 .negotiate = smb2_negotiate,
1676 .negotiate_wsize = smb2_negotiate_wsize,
1677 .negotiate_rsize = smb2_negotiate_rsize,
1678 .sess_setup = SMB2_sess_setup,
1679 .logoff = SMB2_logoff,
1680 .tree_connect = SMB2_tcon,
1681 .tree_disconnect = SMB2_tdis,
Steven Frenchaf6a12e2013-10-09 20:55:53 -05001682 .qfs_tcon = smb3_qfs_tcon,
Steve French38107d42012-12-08 22:08:06 -06001683 .is_path_accessible = smb2_is_path_accessible,
1684 .can_echo = smb2_can_echo,
1685 .echo = SMB2_echo,
1686 .query_path_info = smb2_query_path_info,
1687 .get_srv_inum = smb2_get_srv_inum,
1688 .query_file_info = smb2_query_file_info,
1689 .set_path_size = smb2_set_path_size,
1690 .set_file_size = smb2_set_file_size,
1691 .set_file_info = smb2_set_file_info,
Steve French64a5cfa2013-10-14 15:31:32 -05001692 .set_compression = smb2_set_compression,
Steve French38107d42012-12-08 22:08:06 -06001693 .mkdir = smb2_mkdir,
1694 .mkdir_setinfo = smb2_mkdir_setinfo,
1695 .rmdir = smb2_rmdir,
1696 .unlink = smb2_unlink,
1697 .rename = smb2_rename_path,
1698 .create_hardlink = smb2_create_hardlink,
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001699 .query_symlink = smb2_query_symlink,
Steve Frenchc22870e2014-09-16 07:18:19 -05001700 .query_mf_symlink = smb3_query_mf_symlink,
Steve French5ab97572014-09-15 04:49:28 -05001701 .create_mf_symlink = smb3_create_mf_symlink,
Steve French38107d42012-12-08 22:08:06 -06001702 .open = smb2_open_file,
1703 .set_fid = smb2_set_fid,
1704 .close = smb2_close_file,
1705 .flush = smb2_flush_file,
1706 .async_readv = smb2_async_readv,
1707 .async_writev = smb2_async_writev,
1708 .sync_read = smb2_sync_read,
1709 .sync_write = smb2_sync_write,
1710 .query_dir_first = smb2_query_dir_first,
1711 .query_dir_next = smb2_query_dir_next,
1712 .close_dir = smb2_close_dir,
1713 .calc_smb_size = smb2_calc_size,
1714 .is_status_pending = smb2_is_status_pending,
1715 .oplock_response = smb2_oplock_response,
1716 .queryfs = smb2_queryfs,
1717 .mand_lock = smb2_mand_lock,
1718 .mand_unlock_range = smb2_unlock_range,
1719 .push_mand_locks = smb2_push_mandatory_locks,
1720 .get_lease_key = smb2_get_lease_key,
1721 .set_lease_key = smb2_set_lease_key,
1722 .new_lease_key = smb2_new_lease_key,
Steve Frenche65a5cb2013-06-27 01:06:50 -05001723 .generate_signingkey = generate_smb3signingkey,
Steve French38107d42012-12-08 22:08:06 -06001724 .calc_signature = smb3_calc_signature,
Steve Frenchb3152e22015-06-24 03:17:02 -05001725 .set_integrity = smb3_set_integrity,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001726 .is_read_op = smb21_is_read_op,
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001727 .set_oplock_level = smb3_set_oplock_level,
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001728 .create_lease_buf = smb3_create_lease_buf,
1729 .parse_lease_buf = smb3_parse_lease_buf,
Steve French41c13582013-11-14 00:05:36 -06001730 .clone_range = smb2_clone_range,
Steve Frenchca9e7a12015-10-01 21:40:10 -05001731 .duplicate_extents = smb2_duplicate_extents,
Steve Frenchff1c0382013-11-19 23:44:46 -06001732 .validate_negotiate = smb3_validate_negotiate,
Pavel Shilovsky7f6c5002014-06-22 11:03:22 +04001733 .wp_retry_size = smb2_wp_retry_size,
Pavel Shilovsky52755802014-08-18 20:49:57 +04001734 .dir_needs_close = smb2_dir_needs_close,
Steve French31742c52014-08-17 08:38:47 -05001735 .fallocate = smb3_fallocate,
Steve French1080ef72011-02-24 18:07:19 +00001736};
1737
Steve Frenchaab18932015-06-23 23:37:11 -05001738#ifdef CONFIG_CIFS_SMB311
1739struct smb_version_operations smb311_operations = {
1740 .compare_fids = smb2_compare_fids,
1741 .setup_request = smb2_setup_request,
1742 .setup_async_request = smb2_setup_async_request,
1743 .check_receive = smb2_check_receive,
1744 .add_credits = smb2_add_credits,
1745 .set_credits = smb2_set_credits,
1746 .get_credits_field = smb2_get_credits_field,
1747 .get_credits = smb2_get_credits,
1748 .wait_mtu_credits = smb2_wait_mtu_credits,
1749 .get_next_mid = smb2_get_next_mid,
1750 .read_data_offset = smb2_read_data_offset,
1751 .read_data_length = smb2_read_data_length,
1752 .map_error = map_smb2_to_linux_error,
1753 .find_mid = smb2_find_mid,
1754 .check_message = smb2_check_message,
1755 .dump_detail = smb2_dump_detail,
1756 .clear_stats = smb2_clear_stats,
1757 .print_stats = smb2_print_stats,
1758 .dump_share_caps = smb2_dump_share_caps,
1759 .is_oplock_break = smb2_is_valid_oplock_break,
1760 .downgrade_oplock = smb2_downgrade_oplock,
1761 .need_neg = smb2_need_neg,
1762 .negotiate = smb2_negotiate,
1763 .negotiate_wsize = smb2_negotiate_wsize,
1764 .negotiate_rsize = smb2_negotiate_rsize,
1765 .sess_setup = SMB2_sess_setup,
1766 .logoff = SMB2_logoff,
1767 .tree_connect = SMB2_tcon,
1768 .tree_disconnect = SMB2_tdis,
1769 .qfs_tcon = smb3_qfs_tcon,
1770 .is_path_accessible = smb2_is_path_accessible,
1771 .can_echo = smb2_can_echo,
1772 .echo = SMB2_echo,
1773 .query_path_info = smb2_query_path_info,
1774 .get_srv_inum = smb2_get_srv_inum,
1775 .query_file_info = smb2_query_file_info,
1776 .set_path_size = smb2_set_path_size,
1777 .set_file_size = smb2_set_file_size,
1778 .set_file_info = smb2_set_file_info,
1779 .set_compression = smb2_set_compression,
1780 .mkdir = smb2_mkdir,
1781 .mkdir_setinfo = smb2_mkdir_setinfo,
1782 .rmdir = smb2_rmdir,
1783 .unlink = smb2_unlink,
1784 .rename = smb2_rename_path,
1785 .create_hardlink = smb2_create_hardlink,
1786 .query_symlink = smb2_query_symlink,
1787 .query_mf_symlink = smb3_query_mf_symlink,
1788 .create_mf_symlink = smb3_create_mf_symlink,
1789 .open = smb2_open_file,
1790 .set_fid = smb2_set_fid,
1791 .close = smb2_close_file,
1792 .flush = smb2_flush_file,
1793 .async_readv = smb2_async_readv,
1794 .async_writev = smb2_async_writev,
1795 .sync_read = smb2_sync_read,
1796 .sync_write = smb2_sync_write,
1797 .query_dir_first = smb2_query_dir_first,
1798 .query_dir_next = smb2_query_dir_next,
1799 .close_dir = smb2_close_dir,
1800 .calc_smb_size = smb2_calc_size,
1801 .is_status_pending = smb2_is_status_pending,
1802 .oplock_response = smb2_oplock_response,
1803 .queryfs = smb2_queryfs,
1804 .mand_lock = smb2_mand_lock,
1805 .mand_unlock_range = smb2_unlock_range,
1806 .push_mand_locks = smb2_push_mandatory_locks,
1807 .get_lease_key = smb2_get_lease_key,
1808 .set_lease_key = smb2_set_lease_key,
1809 .new_lease_key = smb2_new_lease_key,
1810 .generate_signingkey = generate_smb3signingkey,
1811 .calc_signature = smb3_calc_signature,
Steve Frenchb3152e22015-06-24 03:17:02 -05001812 .set_integrity = smb3_set_integrity,
Steve Frenchaab18932015-06-23 23:37:11 -05001813 .is_read_op = smb21_is_read_op,
1814 .set_oplock_level = smb3_set_oplock_level,
1815 .create_lease_buf = smb3_create_lease_buf,
1816 .parse_lease_buf = smb3_parse_lease_buf,
1817 .clone_range = smb2_clone_range,
Steve French02b16662015-06-27 21:18:36 -07001818 .duplicate_extents = smb2_duplicate_extents,
Steve Frenchaab18932015-06-23 23:37:11 -05001819/* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
1820 .wp_retry_size = smb2_wp_retry_size,
1821 .dir_needs_close = smb2_dir_needs_close,
1822 .fallocate = smb3_fallocate,
1823};
1824#endif /* CIFS_SMB311 */
1825
Steve Frenchdd446b12012-11-28 23:21:06 -06001826struct smb_version_values smb20_values = {
1827 .version_string = SMB20_VERSION_STRING,
1828 .protocol_id = SMB20_PROT_ID,
1829 .req_capabilities = 0, /* MBZ */
1830 .large_lock_type = 0,
1831 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1832 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1833 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
1834 .header_size = sizeof(struct smb2_hdr),
1835 .max_header_size = MAX_SMB2_HDR_SIZE,
1836 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
1837 .lock_cmd = SMB2_LOCK,
1838 .cap_unix = 0,
1839 .cap_nt_find = SMB2_NT_FIND,
1840 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton50285882013-06-27 12:45:00 -04001841 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1842 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001843 .create_lease_size = sizeof(struct create_lease),
Steve Frenchdd446b12012-11-28 23:21:06 -06001844};
1845
Steve French1080ef72011-02-24 18:07:19 +00001846struct smb_version_values smb21_values = {
1847 .version_string = SMB21_VERSION_STRING,
Steve Frenche4aa25e2012-10-01 12:26:22 -05001848 .protocol_id = SMB21_PROT_ID,
1849 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
1850 .large_lock_type = 0,
1851 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1852 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1853 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
1854 .header_size = sizeof(struct smb2_hdr),
1855 .max_header_size = MAX_SMB2_HDR_SIZE,
1856 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
1857 .lock_cmd = SMB2_LOCK,
1858 .cap_unix = 0,
1859 .cap_nt_find = SMB2_NT_FIND,
1860 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton50285882013-06-27 12:45:00 -04001861 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1862 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001863 .create_lease_size = sizeof(struct create_lease),
Steve Frenche4aa25e2012-10-01 12:26:22 -05001864};
1865
1866struct smb_version_values smb30_values = {
1867 .version_string = SMB30_VERSION_STRING,
1868 .protocol_id = SMB30_PROT_ID,
Steve Frenchb618f002015-11-03 09:15:03 -06001869 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES,
Pavel Shilovsky027e8ee2012-09-19 06:22:43 -07001870 .large_lock_type = 0,
1871 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1872 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1873 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +04001874 .header_size = sizeof(struct smb2_hdr),
1875 .max_header_size = MAX_SMB2_HDR_SIZE,
Pavel Shilovsky09a47072012-09-18 16:20:29 -07001876 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +04001877 .lock_cmd = SMB2_LOCK,
Pavel Shilovsky29e20f92012-07-13 13:58:14 +04001878 .cap_unix = 0,
1879 .cap_nt_find = SMB2_NT_FIND,
1880 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton50285882013-06-27 12:45:00 -04001881 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1882 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001883 .create_lease_size = sizeof(struct create_lease_v2),
Steve French1080ef72011-02-24 18:07:19 +00001884};
Steve French20b6d8b2013-06-12 22:48:41 -05001885
1886struct smb_version_values smb302_values = {
1887 .version_string = SMB302_VERSION_STRING,
1888 .protocol_id = SMB302_PROT_ID,
Steve Frenchb618f002015-11-03 09:15:03 -06001889 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES,
Steve French20b6d8b2013-06-12 22:48:41 -05001890 .large_lock_type = 0,
1891 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1892 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1893 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
1894 .header_size = sizeof(struct smb2_hdr),
1895 .max_header_size = MAX_SMB2_HDR_SIZE,
1896 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
1897 .lock_cmd = SMB2_LOCK,
1898 .cap_unix = 0,
1899 .cap_nt_find = SMB2_NT_FIND,
1900 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton50285882013-06-27 12:45:00 -04001901 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1902 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001903 .create_lease_size = sizeof(struct create_lease_v2),
Steve French20b6d8b2013-06-12 22:48:41 -05001904};
Steve French5f7fbf72014-12-17 22:52:58 -06001905
1906#ifdef CONFIG_CIFS_SMB311
1907struct smb_version_values smb311_values = {
1908 .version_string = SMB311_VERSION_STRING,
1909 .protocol_id = SMB311_PROT_ID,
Steve Frenchb618f002015-11-03 09:15:03 -06001910 .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 -06001911 .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,
1922 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1923 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
1924 .create_lease_size = sizeof(struct create_lease_v2),
1925};
1926#endif /* SMB311 */