blob: d203c0329626cd41ee05fd75da9ee4439304bdc1 [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
Steve French373512e2015-12-18 13:05:30 -0600185 if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) {
186 cifs_dbg(VFS, "encrypted frame parsing not supported yet");
187 return NULL;
188 }
189
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400190 spin_lock(&GlobalMid_Lock);
191 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
Sachin Prabhu9235d092014-12-09 17:37:00 +0000192 if ((mid->mid == wire_mid) &&
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400193 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
194 (mid->command == hdr->Command)) {
195 spin_unlock(&GlobalMid_Lock);
196 return mid;
197 }
198 }
199 spin_unlock(&GlobalMid_Lock);
200 return NULL;
201}
202
203static void
204smb2_dump_detail(void *buf)
205{
206#ifdef CONFIG_CIFS_DEBUG2
207 struct smb2_hdr *smb = (struct smb2_hdr *)buf;
208
Joe Perchesf96637b2013-05-04 22:12:25 -0500209 cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
210 smb->Command, smb->Status, smb->Flags, smb->MessageId,
211 smb->ProcessId);
212 cifs_dbg(VFS, "smb buf %p len %u\n", smb, smb2_calc_size(smb));
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400213#endif
214}
215
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400216static bool
217smb2_need_neg(struct TCP_Server_Info *server)
218{
219 return server->max_read == 0;
220}
221
222static int
223smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
224{
225 int rc;
226 ses->server->CurrentMid = 0;
227 rc = SMB2_negotiate(xid, ses);
228 /* BB we probably don't need to retry with modern servers */
229 if (rc == -EAGAIN)
230 rc = -EHOSTDOWN;
231 return rc;
232}
233
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700234static unsigned int
235smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
236{
237 struct TCP_Server_Info *server = tcon->ses->server;
238 unsigned int wsize;
239
240 /* start with specified wsize, or default */
241 wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
242 wsize = min_t(unsigned int, wsize, server->max_write);
Pavel Shilovskycb7e9ea2014-06-05 19:03:27 +0400243
244 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
245 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700246
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700247 return wsize;
248}
249
250static unsigned int
251smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
252{
253 struct TCP_Server_Info *server = tcon->ses->server;
254 unsigned int rsize;
255
256 /* start with specified rsize, or default */
257 rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
258 rsize = min_t(unsigned int, rsize, server->max_read);
Pavel Shilovskybed9da02014-06-25 11:28:57 +0400259
260 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
261 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700262
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700263 return rsize;
264}
265
Steve Frenchc481e9f2013-10-14 01:21:53 -0500266#ifdef CONFIG_CIFS_STATS2
267static int
268SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon)
269{
270 int rc;
271 unsigned int ret_data_len = 0;
272 struct network_interface_info_ioctl_rsp *out_buf;
273
274 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
275 FSCTL_QUERY_NETWORK_INTERFACE_INFO, true /* is_fsctl */,
276 NULL /* no data input */, 0 /* no data input */,
277 (char **)&out_buf, &ret_data_len);
Steve French9ffc5412014-10-16 15:13:14 -0500278 if (rc != 0)
279 cifs_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
280 else if (ret_data_len < sizeof(struct network_interface_info_ioctl_rsp)) {
281 cifs_dbg(VFS, "server returned bad net interface info buf\n");
282 rc = -EINVAL;
283 } else {
Steve Frenchc481e9f2013-10-14 01:21:53 -0500284 /* Dump info on first interface */
285 cifs_dbg(FYI, "Adapter Capability 0x%x\t",
286 le32_to_cpu(out_buf->Capability));
287 cifs_dbg(FYI, "Link Speed %lld\n",
288 le64_to_cpu(out_buf->LinkSpeed));
Steve French9ffc5412014-10-16 15:13:14 -0500289 }
Steve Frenchc481e9f2013-10-14 01:21:53 -0500290
291 return rc;
292}
293#endif /* STATS2 */
294
Steve French34f62642013-10-09 02:07:00 -0500295static void
Steven Frenchaf6a12e2013-10-09 20:55:53 -0500296smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
297{
298 int rc;
299 __le16 srch_path = 0; /* Null - open root of share */
300 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
301 struct cifs_open_parms oparms;
302 struct cifs_fid fid;
303
304 oparms.tcon = tcon;
305 oparms.desired_access = FILE_READ_ATTRIBUTES;
306 oparms.disposition = FILE_OPEN;
307 oparms.create_options = 0;
308 oparms.fid = &fid;
309 oparms.reconnect = false;
310
311 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
312 if (rc)
313 return;
314
Steve Frenchc481e9f2013-10-14 01:21:53 -0500315#ifdef CONFIG_CIFS_STATS2
316 SMB3_request_interfaces(xid, tcon);
317#endif /* STATS2 */
318
Steven Frenchaf6a12e2013-10-09 20:55:53 -0500319 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
320 FS_ATTRIBUTE_INFORMATION);
321 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
322 FS_DEVICE_INFORMATION);
323 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
324 FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
325 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
326 return;
327}
328
329static void
Steve French34f62642013-10-09 02:07:00 -0500330smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
331{
332 int rc;
333 __le16 srch_path = 0; /* Null - open root of share */
334 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
335 struct cifs_open_parms oparms;
336 struct cifs_fid fid;
337
338 oparms.tcon = tcon;
339 oparms.desired_access = FILE_READ_ATTRIBUTES;
340 oparms.disposition = FILE_OPEN;
341 oparms.create_options = 0;
342 oparms.fid = &fid;
343 oparms.reconnect = false;
344
345 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
346 if (rc)
347 return;
348
Steven French21671142013-10-09 13:36:35 -0500349 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
350 FS_ATTRIBUTE_INFORMATION);
351 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
352 FS_DEVICE_INFORMATION);
Steve French34f62642013-10-09 02:07:00 -0500353 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
354 return;
355}
356
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400357static int
358smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
359 struct cifs_sb_info *cifs_sb, const char *full_path)
360{
361 int rc;
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400362 __le16 *utf16_path;
Pavel Shilovsky2e44b282012-09-18 16:20:33 -0700363 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400364 struct cifs_open_parms oparms;
365 struct cifs_fid fid;
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400366
367 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
368 if (!utf16_path)
369 return -ENOMEM;
370
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400371 oparms.tcon = tcon;
372 oparms.desired_access = FILE_READ_ATTRIBUTES;
373 oparms.disposition = FILE_OPEN;
374 oparms.create_options = 0;
375 oparms.fid = &fid;
Pavel Shilovsky9cbc0b72013-07-09 18:40:58 +0400376 oparms.reconnect = false;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400377
Pavel Shilovskyb42bf882013-08-14 19:25:21 +0400378 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400379 if (rc) {
380 kfree(utf16_path);
381 return rc;
382 }
383
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400384 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400385 kfree(utf16_path);
386 return rc;
387}
388
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +0400389static int
390smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
391 struct cifs_sb_info *cifs_sb, const char *full_path,
392 u64 *uniqueid, FILE_ALL_INFO *data)
393{
394 *uniqueid = le64_to_cpu(data->IndexNumber);
395 return 0;
396}
397
Pavel Shilovskyb7546bc2012-09-18 16:20:27 -0700398static int
399smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
400 struct cifs_fid *fid, FILE_ALL_INFO *data)
401{
402 int rc;
403 struct smb2_file_all_info *smb2_data;
404
Pavel Shilovsky1bbe4992014-08-22 13:32:11 +0400405 smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
Pavel Shilovskyb7546bc2012-09-18 16:20:27 -0700406 GFP_KERNEL);
407 if (smb2_data == NULL)
408 return -ENOMEM;
409
410 rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
411 smb2_data);
412 if (!rc)
413 move_smb2_info_to_cifs(data, smb2_data);
414 kfree(smb2_data);
415 return rc;
416}
417
Pavel Shilovsky9094fad2012-07-12 18:30:44 +0400418static bool
419smb2_can_echo(struct TCP_Server_Info *server)
420{
421 return server->echoes;
422}
423
Pavel Shilovskyd60622e2012-05-28 15:19:39 +0400424static void
425smb2_clear_stats(struct cifs_tcon *tcon)
426{
427#ifdef CONFIG_CIFS_STATS
428 int i;
429 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
430 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
431 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
432 }
433#endif
434}
435
436static void
Steve French769ee6a2013-06-19 14:15:30 -0500437smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
438{
439 seq_puts(m, "\n\tShare Capabilities:");
440 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
441 seq_puts(m, " DFS,");
442 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
443 seq_puts(m, " CONTINUOUS AVAILABILITY,");
444 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
445 seq_puts(m, " SCALEOUT,");
446 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
447 seq_puts(m, " CLUSTER,");
448 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
449 seq_puts(m, " ASYMMETRIC,");
450 if (tcon->capabilities == 0)
451 seq_puts(m, " None");
Steven Frenchaf6a12e2013-10-09 20:55:53 -0500452 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
453 seq_puts(m, " Aligned,");
454 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
455 seq_puts(m, " Partition Aligned,");
456 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
457 seq_puts(m, " SSD,");
458 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
459 seq_puts(m, " TRIM-support,");
460
Steve French769ee6a2013-06-19 14:15:30 -0500461 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
Steven Frenchaf6a12e2013-10-09 20:55:53 -0500462 if (tcon->perf_sector_size)
463 seq_printf(m, "\tOptimal sector size: 0x%x",
464 tcon->perf_sector_size);
Steve French769ee6a2013-06-19 14:15:30 -0500465}
466
467static void
Pavel Shilovskyd60622e2012-05-28 15:19:39 +0400468smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
469{
470#ifdef CONFIG_CIFS_STATS
471 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
472 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
473 seq_printf(m, "\nNegotiates: %d sent %d failed",
474 atomic_read(&sent[SMB2_NEGOTIATE_HE]),
475 atomic_read(&failed[SMB2_NEGOTIATE_HE]));
476 seq_printf(m, "\nSessionSetups: %d sent %d failed",
477 atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
478 atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
Pavel Shilovskyd60622e2012-05-28 15:19:39 +0400479 seq_printf(m, "\nLogoffs: %d sent %d failed",
480 atomic_read(&sent[SMB2_LOGOFF_HE]),
481 atomic_read(&failed[SMB2_LOGOFF_HE]));
482 seq_printf(m, "\nTreeConnects: %d sent %d failed",
483 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
484 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
485 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
486 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
487 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
488 seq_printf(m, "\nCreates: %d sent %d failed",
489 atomic_read(&sent[SMB2_CREATE_HE]),
490 atomic_read(&failed[SMB2_CREATE_HE]));
491 seq_printf(m, "\nCloses: %d sent %d failed",
492 atomic_read(&sent[SMB2_CLOSE_HE]),
493 atomic_read(&failed[SMB2_CLOSE_HE]));
494 seq_printf(m, "\nFlushes: %d sent %d failed",
495 atomic_read(&sent[SMB2_FLUSH_HE]),
496 atomic_read(&failed[SMB2_FLUSH_HE]));
497 seq_printf(m, "\nReads: %d sent %d failed",
498 atomic_read(&sent[SMB2_READ_HE]),
499 atomic_read(&failed[SMB2_READ_HE]));
500 seq_printf(m, "\nWrites: %d sent %d failed",
501 atomic_read(&sent[SMB2_WRITE_HE]),
502 atomic_read(&failed[SMB2_WRITE_HE]));
503 seq_printf(m, "\nLocks: %d sent %d failed",
504 atomic_read(&sent[SMB2_LOCK_HE]),
505 atomic_read(&failed[SMB2_LOCK_HE]));
506 seq_printf(m, "\nIOCTLs: %d sent %d failed",
507 atomic_read(&sent[SMB2_IOCTL_HE]),
508 atomic_read(&failed[SMB2_IOCTL_HE]));
509 seq_printf(m, "\nCancels: %d sent %d failed",
510 atomic_read(&sent[SMB2_CANCEL_HE]),
511 atomic_read(&failed[SMB2_CANCEL_HE]));
512 seq_printf(m, "\nEchos: %d sent %d failed",
513 atomic_read(&sent[SMB2_ECHO_HE]),
514 atomic_read(&failed[SMB2_ECHO_HE]));
515 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
516 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
517 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
518 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
519 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
520 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
521 seq_printf(m, "\nQueryInfos: %d sent %d failed",
522 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
523 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
524 seq_printf(m, "\nSetInfos: %d sent %d failed",
525 atomic_read(&sent[SMB2_SET_INFO_HE]),
526 atomic_read(&failed[SMB2_SET_INFO_HE]));
527 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
528 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
529 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
530#endif
531}
532
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700533static void
534smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
535{
David Howells2b0143b2015-03-17 22:25:59 +0000536 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
Pavel Shilovsky53ef1012013-09-05 16:11:28 +0400537 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
538
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700539 cfile->fid.persistent_fid = fid->persistent_fid;
540 cfile->fid.volatile_fid = fid->volatile_fid;
Pavel Shilovsky42873b02013-09-05 21:30:16 +0400541 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
542 &fid->purge_cache);
Pavel Shilovsky18cceb62013-09-05 13:01:06 +0400543 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700544}
545
Pavel Shilovsky760ad0c2012-09-25 11:00:07 +0400546static void
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700547smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
548 struct cifs_fid *fid)
549{
Pavel Shilovsky760ad0c2012-09-25 11:00:07 +0400550 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700551}
552
Pavel Shilovsky7a5cfb12012-09-18 16:20:28 -0700553static int
Steve French41c13582013-11-14 00:05:36 -0600554SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
555 u64 persistent_fid, u64 volatile_fid,
556 struct copychunk_ioctl *pcchunk)
557{
558 int rc;
559 unsigned int ret_data_len;
560 struct resume_key_req *res_key;
561
562 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
563 FSCTL_SRV_REQUEST_RESUME_KEY, true /* is_fsctl */,
564 NULL, 0 /* no input */,
565 (char **)&res_key, &ret_data_len);
566
567 if (rc) {
568 cifs_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
569 goto req_res_key_exit;
570 }
571 if (ret_data_len < sizeof(struct resume_key_req)) {
572 cifs_dbg(VFS, "Invalid refcopy resume key length\n");
573 rc = -EINVAL;
574 goto req_res_key_exit;
575 }
576 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
577
578req_res_key_exit:
579 kfree(res_key);
580 return rc;
581}
582
583static int
584smb2_clone_range(const unsigned int xid,
585 struct cifsFileInfo *srcfile,
586 struct cifsFileInfo *trgtfile, u64 src_off,
587 u64 len, u64 dest_off)
588{
589 int rc;
590 unsigned int ret_data_len;
591 struct copychunk_ioctl *pcchunk;
Steve French9bf0c9c2013-11-16 18:05:28 -0600592 struct copychunk_ioctl_rsp *retbuf = NULL;
593 struct cifs_tcon *tcon;
594 int chunks_copied = 0;
595 bool chunk_sizes_updated = false;
Steve French41c13582013-11-14 00:05:36 -0600596
597 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
598
599 if (pcchunk == NULL)
600 return -ENOMEM;
601
602 cifs_dbg(FYI, "in smb2_clone_range - about to call request res key\n");
603 /* Request a key from the server to identify the source of the copy */
604 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
605 srcfile->fid.persistent_fid,
606 srcfile->fid.volatile_fid, pcchunk);
607
608 /* Note: request_res_key sets res_key null only if rc !=0 */
609 if (rc)
Steve French9bf0c9c2013-11-16 18:05:28 -0600610 goto cchunk_out;
Steve French41c13582013-11-14 00:05:36 -0600611
612 /* For now array only one chunk long, will make more flexible later */
Fabian Frederickbc09d142014-12-10 15:41:15 -0800613 pcchunk->ChunkCount = cpu_to_le32(1);
Steve French41c13582013-11-14 00:05:36 -0600614 pcchunk->Reserved = 0;
Steve French41c13582013-11-14 00:05:36 -0600615 pcchunk->Reserved2 = 0;
616
Steve French9bf0c9c2013-11-16 18:05:28 -0600617 tcon = tlink_tcon(trgtfile->tlink);
618
619 while (len > 0) {
620 pcchunk->SourceOffset = cpu_to_le64(src_off);
621 pcchunk->TargetOffset = cpu_to_le64(dest_off);
622 pcchunk->Length =
623 cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
624
625 /* Request server copy to target from src identified by key */
626 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
Steve French41c13582013-11-14 00:05:36 -0600627 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
628 true /* is_fsctl */, (char *)pcchunk,
Steve French9bf0c9c2013-11-16 18:05:28 -0600629 sizeof(struct copychunk_ioctl), (char **)&retbuf,
630 &ret_data_len);
631 if (rc == 0) {
632 if (ret_data_len !=
633 sizeof(struct copychunk_ioctl_rsp)) {
634 cifs_dbg(VFS, "invalid cchunk response size\n");
635 rc = -EIO;
636 goto cchunk_out;
637 }
638 if (retbuf->TotalBytesWritten == 0) {
639 cifs_dbg(FYI, "no bytes copied\n");
640 rc = -EIO;
641 goto cchunk_out;
642 }
643 /*
644 * Check if server claimed to write more than we asked
645 */
646 if (le32_to_cpu(retbuf->TotalBytesWritten) >
647 le32_to_cpu(pcchunk->Length)) {
648 cifs_dbg(VFS, "invalid copy chunk response\n");
649 rc = -EIO;
650 goto cchunk_out;
651 }
652 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
653 cifs_dbg(VFS, "invalid num chunks written\n");
654 rc = -EIO;
655 goto cchunk_out;
656 }
657 chunks_copied++;
Steve French41c13582013-11-14 00:05:36 -0600658
Steve French9bf0c9c2013-11-16 18:05:28 -0600659 src_off += le32_to_cpu(retbuf->TotalBytesWritten);
660 dest_off += le32_to_cpu(retbuf->TotalBytesWritten);
661 len -= le32_to_cpu(retbuf->TotalBytesWritten);
Steve French41c13582013-11-14 00:05:36 -0600662
Steve French9bf0c9c2013-11-16 18:05:28 -0600663 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %d\n",
664 le32_to_cpu(retbuf->ChunksWritten),
665 le32_to_cpu(retbuf->ChunkBytesWritten),
666 le32_to_cpu(retbuf->TotalBytesWritten));
667 } else if (rc == -EINVAL) {
668 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
669 goto cchunk_out;
Steve French41c13582013-11-14 00:05:36 -0600670
Steve French9bf0c9c2013-11-16 18:05:28 -0600671 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
672 le32_to_cpu(retbuf->ChunksWritten),
673 le32_to_cpu(retbuf->ChunkBytesWritten),
674 le32_to_cpu(retbuf->TotalBytesWritten));
675
676 /*
677 * Check if this is the first request using these sizes,
678 * (ie check if copy succeed once with original sizes
679 * and check if the server gave us different sizes after
680 * we already updated max sizes on previous request).
681 * if not then why is the server returning an error now
682 */
683 if ((chunks_copied != 0) || chunk_sizes_updated)
684 goto cchunk_out;
685
686 /* Check that server is not asking us to grow size */
687 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
688 tcon->max_bytes_chunk)
689 tcon->max_bytes_chunk =
690 le32_to_cpu(retbuf->ChunkBytesWritten);
691 else
692 goto cchunk_out; /* server gave us bogus size */
693
694 /* No need to change MaxChunks since already set to 1 */
695 chunk_sizes_updated = true;
Sachin Prabhu2477bc52015-02-04 13:10:26 +0000696 } else
697 goto cchunk_out;
Steve French9bf0c9c2013-11-16 18:05:28 -0600698 }
699
700cchunk_out:
Steve French41c13582013-11-14 00:05:36 -0600701 kfree(pcchunk);
702 return rc;
703}
704
705static int
Pavel Shilovsky7a5cfb12012-09-18 16:20:28 -0700706smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
707 struct cifs_fid *fid)
708{
709 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
710}
711
Pavel Shilovsky09a47072012-09-18 16:20:29 -0700712static unsigned int
713smb2_read_data_offset(char *buf)
714{
715 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
716 return rsp->DataOffset;
717}
718
719static unsigned int
720smb2_read_data_length(char *buf)
721{
722 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
723 return le32_to_cpu(rsp->DataLength);
724}
725
Pavel Shilovskyd8e05032012-09-18 16:20:30 -0700726
727static int
Steve Frenchdb8b6312014-09-22 05:13:55 -0500728smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
Pavel Shilovskyd8e05032012-09-18 16:20:30 -0700729 struct cifs_io_parms *parms, unsigned int *bytes_read,
730 char **buf, int *buf_type)
731{
Steve Frenchdb8b6312014-09-22 05:13:55 -0500732 parms->persistent_fid = pfid->persistent_fid;
733 parms->volatile_fid = pfid->volatile_fid;
Pavel Shilovskyd8e05032012-09-18 16:20:30 -0700734 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
735}
736
Pavel Shilovsky009d3442012-09-18 16:20:30 -0700737static int
Steve Frenchdb8b6312014-09-22 05:13:55 -0500738smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
Pavel Shilovsky009d3442012-09-18 16:20:30 -0700739 struct cifs_io_parms *parms, unsigned int *written,
740 struct kvec *iov, unsigned long nr_segs)
741{
742
Steve Frenchdb8b6312014-09-22 05:13:55 -0500743 parms->persistent_fid = pfid->persistent_fid;
744 parms->volatile_fid = pfid->volatile_fid;
Pavel Shilovsky009d3442012-09-18 16:20:30 -0700745 return SMB2_write(xid, parms, written, iov, nr_segs);
746}
747
Steve Frenchd43cc792014-08-13 17:16:29 -0500748/* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
749static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
750 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
751{
752 struct cifsInodeInfo *cifsi;
753 int rc;
754
755 cifsi = CIFS_I(inode);
756
757 /* if file already sparse don't bother setting sparse again */
758 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
759 return true; /* already sparse */
760
761 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
762 return true; /* already not sparse */
763
764 /*
765 * Can't check for sparse support on share the usual way via the
766 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
767 * since Samba server doesn't set the flag on the share, yet
768 * supports the set sparse FSCTL and returns sparse correctly
769 * in the file attributes. If we fail setting sparse though we
770 * mark that server does not support sparse files for this share
771 * to avoid repeatedly sending the unsupported fsctl to server
772 * if the file is repeatedly extended.
773 */
774 if (tcon->broken_sparse_sup)
775 return false;
776
777 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
778 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
779 true /* is_fctl */, &setsparse, 1, NULL, NULL);
780 if (rc) {
781 tcon->broken_sparse_sup = true;
782 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
783 return false;
784 }
785
786 if (setsparse)
787 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
788 else
789 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
790
791 return true;
792}
793
Pavel Shilovskyc839ff22012-09-18 16:20:32 -0700794static int
795smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
796 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
797{
798 __le64 eof = cpu_to_le64(size);
Steve French3d1a3742014-08-11 21:05:25 -0500799 struct inode *inode;
800
801 /*
802 * If extending file more than one page make sparse. Many Linux fs
803 * make files sparse by default when extending via ftruncate
804 */
David Howells2b0143b2015-03-17 22:25:59 +0000805 inode = d_inode(cfile->dentry);
Steve French3d1a3742014-08-11 21:05:25 -0500806
807 if (!set_alloc && (size > inode->i_size + 8192)) {
Steve French3d1a3742014-08-11 21:05:25 -0500808 __u8 set_sparse = 1;
Steve French3d1a3742014-08-11 21:05:25 -0500809
Steve Frenchd43cc792014-08-13 17:16:29 -0500810 /* whether set sparse succeeds or not, extend the file */
811 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
Steve French3d1a3742014-08-11 21:05:25 -0500812 }
813
Pavel Shilovskyc839ff22012-09-18 16:20:32 -0700814 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
Steve Frenchf29ebb42014-07-19 21:44:58 -0500815 cfile->fid.volatile_fid, cfile->pid, &eof, false);
Pavel Shilovskyc839ff22012-09-18 16:20:32 -0700816}
817
Steve French02b16662015-06-27 21:18:36 -0700818static int
819smb2_duplicate_extents(const unsigned int xid,
820 struct cifsFileInfo *srcfile,
821 struct cifsFileInfo *trgtfile, u64 src_off,
822 u64 len, u64 dest_off)
823{
824 int rc;
825 unsigned int ret_data_len;
826 char *retbuf = NULL;
827 struct duplicate_extents_to_file dup_ext_buf;
828 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
829
830 /* server fileays advertise duplicate extent support with this flag */
831 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
832 FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
833 return -EOPNOTSUPP;
834
835 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
836 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
837 dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
838 dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
839 dup_ext_buf.ByteCount = cpu_to_le64(len);
840 cifs_dbg(FYI, "duplicate extents: src off %lld dst off %lld len %lld",
841 src_off, dest_off, len);
842
843 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
844 if (rc)
845 goto duplicate_extents_out;
846
847 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
848 trgtfile->fid.volatile_fid,
849 FSCTL_DUPLICATE_EXTENTS_TO_FILE,
850 true /* is_fsctl */, (char *)&dup_ext_buf,
851 sizeof(struct duplicate_extents_to_file),
852 (char **)&retbuf,
853 &ret_data_len);
854
855 if (ret_data_len > 0)
856 cifs_dbg(FYI, "non-zero response length in duplicate extents");
857
858duplicate_extents_out:
859 return rc;
860}
Steve French02b16662015-06-27 21:18:36 -0700861
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700862static int
Steve French64a5cfa2013-10-14 15:31:32 -0500863smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
864 struct cifsFileInfo *cfile)
865{
866 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
867 cfile->fid.volatile_fid);
868}
869
870static int
Steve Frenchb3152e22015-06-24 03:17:02 -0500871smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
872 struct cifsFileInfo *cfile)
873{
874 struct fsctl_set_integrity_information_req integr_info;
875 char *retbuf = NULL;
876 unsigned int ret_data_len;
877
878 integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
879 integr_info.Flags = 0;
880 integr_info.Reserved = 0;
881
882 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
883 cfile->fid.volatile_fid,
884 FSCTL_SET_INTEGRITY_INFORMATION,
885 true /* is_fsctl */, (char *)&integr_info,
886 sizeof(struct fsctl_set_integrity_information_req),
887 (char **)&retbuf,
888 &ret_data_len);
889
890}
891
892static int
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700893smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
894 const char *path, struct cifs_sb_info *cifs_sb,
895 struct cifs_fid *fid, __u16 search_flags,
896 struct cifs_search_info *srch_inf)
897{
898 __le16 *utf16_path;
899 int rc;
Pavel Shilovsky2e44b282012-09-18 16:20:33 -0700900 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400901 struct cifs_open_parms oparms;
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700902
903 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
904 if (!utf16_path)
905 return -ENOMEM;
906
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400907 oparms.tcon = tcon;
908 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
909 oparms.disposition = FILE_OPEN;
910 oparms.create_options = 0;
911 oparms.fid = fid;
Pavel Shilovsky9cbc0b72013-07-09 18:40:58 +0400912 oparms.reconnect = false;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400913
Pavel Shilovskyb42bf882013-08-14 19:25:21 +0400914 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700915 kfree(utf16_path);
916 if (rc) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500917 cifs_dbg(VFS, "open dir failed\n");
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700918 return rc;
919 }
920
921 srch_inf->entries_in_buffer = 0;
922 srch_inf->index_of_last_entry = 0;
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700923
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400924 rc = SMB2_query_directory(xid, tcon, fid->persistent_fid,
925 fid->volatile_fid, 0, srch_inf);
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700926 if (rc) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500927 cifs_dbg(VFS, "query directory failed\n");
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400928 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700929 }
930 return rc;
931}
932
933static int
934smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
935 struct cifs_fid *fid, __u16 search_flags,
936 struct cifs_search_info *srch_inf)
937{
938 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
939 fid->volatile_fid, 0, srch_inf);
940}
941
942static int
943smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
944 struct cifs_fid *fid)
945{
946 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
947}
948
Pavel Shilovsky2e44b282012-09-18 16:20:33 -0700949/*
950* If we negotiate SMB2 protocol and get STATUS_PENDING - update
951* the number of credits and return true. Otherwise - return false.
952*/
953static bool
954smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
955{
956 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
957
Steve French12e8a202012-09-19 09:19:39 -0700958 if (hdr->Status != STATUS_PENDING)
Pavel Shilovsky2e44b282012-09-18 16:20:33 -0700959 return false;
960
961 if (!length) {
962 spin_lock(&server->req_lock);
963 server->credits += le16_to_cpu(hdr->CreditRequest);
964 spin_unlock(&server->req_lock);
965 wake_up(&server->request_q);
966 }
967
968 return true;
969}
970
Pavel Shilovsky983c88a2012-09-18 16:20:33 -0700971static int
972smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
973 struct cifsInodeInfo *cinode)
974{
Pavel Shilovsky0822f512012-09-19 06:22:45 -0700975 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
976 return SMB2_lease_break(0, tcon, cinode->lease_key,
977 smb2_get_lease_state(cinode));
978
Pavel Shilovsky983c88a2012-09-18 16:20:33 -0700979 return SMB2_oplock_break(0, tcon, fid->persistent_fid,
980 fid->volatile_fid,
Pavel Shilovsky18cceb62013-09-05 13:01:06 +0400981 CIFS_CACHE_READ(cinode) ? 1 : 0);
Pavel Shilovsky983c88a2012-09-18 16:20:33 -0700982}
983
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -0700984static int
985smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
986 struct kstatfs *buf)
987{
988 int rc;
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -0700989 __le16 srch_path = 0; /* Null - open root of share */
990 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400991 struct cifs_open_parms oparms;
992 struct cifs_fid fid;
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -0700993
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400994 oparms.tcon = tcon;
995 oparms.desired_access = FILE_READ_ATTRIBUTES;
996 oparms.disposition = FILE_OPEN;
997 oparms.create_options = 0;
998 oparms.fid = &fid;
Pavel Shilovsky9cbc0b72013-07-09 18:40:58 +0400999 oparms.reconnect = false;
Pavel Shilovsky064f6042013-07-09 18:20:30 +04001000
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001001 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001002 if (rc)
1003 return rc;
1004 buf->f_type = SMB2_MAGIC_NUMBER;
Pavel Shilovsky064f6042013-07-09 18:20:30 +04001005 rc = SMB2_QFS_info(xid, tcon, fid.persistent_fid, fid.volatile_fid,
1006 buf);
1007 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001008 return rc;
1009}
1010
Pavel Shilovsky027e8ee2012-09-19 06:22:43 -07001011static bool
1012smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
1013{
1014 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
1015 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
1016}
1017
Pavel Shilovskyf7ba7fe2012-09-19 06:22:43 -07001018static int
1019smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
1020 __u64 length, __u32 type, int lock, int unlock, bool wait)
1021{
1022 if (unlock && !lock)
1023 type = SMB2_LOCKFLAG_UNLOCK;
1024 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
1025 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
1026 current->tgid, length, offset, type, wait);
1027}
1028
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -07001029static void
1030smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
1031{
1032 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
1033}
1034
1035static void
1036smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
1037{
1038 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
1039}
1040
1041static void
1042smb2_new_lease_key(struct cifs_fid *fid)
1043{
1044 get_random_bytes(fid->lease_key, SMB2_LEASE_KEY_SIZE);
1045}
1046
Pavel Shilovsky78932422016-07-24 10:37:38 +03001047#define SMB2_SYMLINK_STRUCT_SIZE \
1048 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
1049
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001050static int
1051smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
1052 const char *full_path, char **target_path,
1053 struct cifs_sb_info *cifs_sb)
1054{
1055 int rc;
1056 __le16 *utf16_path;
1057 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1058 struct cifs_open_parms oparms;
1059 struct cifs_fid fid;
1060 struct smb2_err_rsp *err_buf = NULL;
1061 struct smb2_symlink_err_rsp *symlink;
Pavel Shilovsky78932422016-07-24 10:37:38 +03001062 unsigned int sub_len;
1063 unsigned int sub_offset;
1064 unsigned int print_len;
1065 unsigned int print_offset;
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001066
1067 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
1068
1069 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
1070 if (!utf16_path)
1071 return -ENOMEM;
1072
1073 oparms.tcon = tcon;
1074 oparms.desired_access = FILE_READ_ATTRIBUTES;
1075 oparms.disposition = FILE_OPEN;
1076 oparms.create_options = 0;
1077 oparms.fid = &fid;
1078 oparms.reconnect = false;
1079
1080 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_buf);
1081
1082 if (!rc || !err_buf) {
1083 kfree(utf16_path);
1084 return -ENOENT;
1085 }
Pavel Shilovsky78932422016-07-24 10:37:38 +03001086
1087 if (le32_to_cpu(err_buf->ByteCount) < sizeof(struct smb2_symlink_err_rsp) ||
1088 get_rfc1002_length(err_buf) + 4 < SMB2_SYMLINK_STRUCT_SIZE) {
1089 kfree(utf16_path);
1090 return -ENOENT;
1091 }
1092
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001093 /* open must fail on symlink - reset rc */
1094 rc = 0;
1095 symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
1096 sub_len = le16_to_cpu(symlink->SubstituteNameLength);
1097 sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
Pavel Shilovsky78932422016-07-24 10:37:38 +03001098 print_len = le16_to_cpu(symlink->PrintNameLength);
1099 print_offset = le16_to_cpu(symlink->PrintNameOffset);
1100
1101 if (get_rfc1002_length(err_buf) + 4 <
1102 SMB2_SYMLINK_STRUCT_SIZE + sub_offset + sub_len) {
1103 kfree(utf16_path);
1104 return -ENOENT;
1105 }
1106
1107 if (get_rfc1002_length(err_buf) + 4 <
1108 SMB2_SYMLINK_STRUCT_SIZE + print_offset + print_len) {
1109 kfree(utf16_path);
1110 return -ENOENT;
1111 }
1112
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001113 *target_path = cifs_strndup_from_utf16(
1114 (char *)symlink->PathBuffer + sub_offset,
1115 sub_len, true, cifs_sb->local_nls);
1116 if (!(*target_path)) {
1117 kfree(utf16_path);
1118 return -ENOMEM;
1119 }
1120 convert_delimiter(*target_path, '/');
1121 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
1122 kfree(utf16_path);
1123 return rc;
1124}
1125
Steve French30175622014-08-17 18:16:40 -05001126static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
1127 loff_t offset, loff_t len, bool keep_size)
1128{
1129 struct inode *inode;
1130 struct cifsInodeInfo *cifsi;
1131 struct cifsFileInfo *cfile = file->private_data;
1132 struct file_zero_data_information fsctl_buf;
1133 long rc;
1134 unsigned int xid;
1135
1136 xid = get_xid();
1137
David Howells2b0143b2015-03-17 22:25:59 +00001138 inode = d_inode(cfile->dentry);
Steve French30175622014-08-17 18:16:40 -05001139 cifsi = CIFS_I(inode);
1140
1141 /* if file not oplocked can't be sure whether asking to extend size */
1142 if (!CIFS_CACHE_READ(cifsi))
1143 if (keep_size == false)
1144 return -EOPNOTSUPP;
1145
Steve French2bb93d22014-08-20 18:56:29 -05001146 /*
Steve French30175622014-08-17 18:16:40 -05001147 * Must check if file sparse since fallocate -z (zero range) assumes
1148 * non-sparse allocation
1149 */
1150 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE))
1151 return -EOPNOTSUPP;
1152
1153 /*
1154 * need to make sure we are not asked to extend the file since the SMB3
1155 * fsctl does not change the file size. In the future we could change
1156 * this to zero the first part of the range then set the file size
1157 * which for a non sparse file would zero the newly extended range
1158 */
1159 if (keep_size == false)
1160 if (i_size_read(inode) < offset + len)
1161 return -EOPNOTSUPP;
1162
1163 cifs_dbg(FYI, "offset %lld len %lld", offset, len);
1164
1165 fsctl_buf.FileOffset = cpu_to_le64(offset);
1166 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
1167
1168 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1169 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
1170 true /* is_fctl */, (char *)&fsctl_buf,
1171 sizeof(struct file_zero_data_information), NULL, NULL);
1172 free_xid(xid);
1173 return rc;
1174}
1175
Steve French31742c52014-08-17 08:38:47 -05001176static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
1177 loff_t offset, loff_t len)
1178{
1179 struct inode *inode;
1180 struct cifsInodeInfo *cifsi;
1181 struct cifsFileInfo *cfile = file->private_data;
1182 struct file_zero_data_information fsctl_buf;
1183 long rc;
1184 unsigned int xid;
1185 __u8 set_sparse = 1;
1186
1187 xid = get_xid();
1188
David Howells2b0143b2015-03-17 22:25:59 +00001189 inode = d_inode(cfile->dentry);
Steve French31742c52014-08-17 08:38:47 -05001190 cifsi = CIFS_I(inode);
1191
1192 /* Need to make file sparse, if not already, before freeing range. */
1193 /* Consider adding equivalent for compressed since it could also work */
1194 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse))
1195 return -EOPNOTSUPP;
1196
1197 cifs_dbg(FYI, "offset %lld len %lld", offset, len);
1198
1199 fsctl_buf.FileOffset = cpu_to_le64(offset);
1200 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
1201
1202 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1203 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
1204 true /* is_fctl */, (char *)&fsctl_buf,
1205 sizeof(struct file_zero_data_information), NULL, NULL);
1206 free_xid(xid);
1207 return rc;
1208}
1209
Steve French9ccf3212014-10-18 17:01:15 -05001210static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
1211 loff_t off, loff_t len, bool keep_size)
1212{
1213 struct inode *inode;
1214 struct cifsInodeInfo *cifsi;
1215 struct cifsFileInfo *cfile = file->private_data;
1216 long rc = -EOPNOTSUPP;
1217 unsigned int xid;
1218
1219 xid = get_xid();
1220
David Howells2b0143b2015-03-17 22:25:59 +00001221 inode = d_inode(cfile->dentry);
Steve French9ccf3212014-10-18 17:01:15 -05001222 cifsi = CIFS_I(inode);
1223
1224 /* if file not oplocked can't be sure whether asking to extend size */
1225 if (!CIFS_CACHE_READ(cifsi))
1226 if (keep_size == false)
1227 return -EOPNOTSUPP;
1228
1229 /*
1230 * Files are non-sparse by default so falloc may be a no-op
1231 * Must check if file sparse. If not sparse, and not extending
1232 * then no need to do anything since file already allocated
1233 */
1234 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
1235 if (keep_size == true)
1236 return 0;
1237 /* check if extending file */
1238 else if (i_size_read(inode) >= off + len)
1239 /* not extending file and already not sparse */
1240 return 0;
1241 /* BB: in future add else clause to extend file */
1242 else
1243 return -EOPNOTSUPP;
1244 }
1245
1246 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
1247 /*
1248 * Check if falloc starts within first few pages of file
1249 * and ends within a few pages of the end of file to
1250 * ensure that most of file is being forced to be
1251 * fallocated now. If so then setting whole file sparse
1252 * ie potentially making a few extra pages at the beginning
1253 * or end of the file non-sparse via set_sparse is harmless.
1254 */
1255 if ((off > 8192) || (off + len + 8192 < i_size_read(inode)))
1256 return -EOPNOTSUPP;
1257
1258 rc = smb2_set_sparse(xid, tcon, cfile, inode, false);
1259 }
1260 /* BB: else ... in future add code to extend file and set sparse */
1261
1262
1263 free_xid(xid);
1264 return rc;
1265}
1266
1267
Steve French31742c52014-08-17 08:38:47 -05001268static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
1269 loff_t off, loff_t len)
1270{
1271 /* KEEP_SIZE already checked for by do_fallocate */
1272 if (mode & FALLOC_FL_PUNCH_HOLE)
1273 return smb3_punch_hole(file, tcon, off, len);
Steve French30175622014-08-17 18:16:40 -05001274 else if (mode & FALLOC_FL_ZERO_RANGE) {
1275 if (mode & FALLOC_FL_KEEP_SIZE)
1276 return smb3_zero_range(file, tcon, off, len, true);
1277 return smb3_zero_range(file, tcon, off, len, false);
Steve French9ccf3212014-10-18 17:01:15 -05001278 } else if (mode == FALLOC_FL_KEEP_SIZE)
1279 return smb3_simple_falloc(file, tcon, off, len, true);
1280 else if (mode == 0)
1281 return smb3_simple_falloc(file, tcon, off, len, false);
Steve French31742c52014-08-17 08:38:47 -05001282
1283 return -EOPNOTSUPP;
1284}
1285
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001286static void
Sachin Prabhuc11f1df2014-03-11 16:11:47 +00001287smb2_downgrade_oplock(struct TCP_Server_Info *server,
1288 struct cifsInodeInfo *cinode, bool set_level2)
1289{
1290 if (set_level2)
1291 server->ops->set_oplock_level(cinode, SMB2_OPLOCK_LEVEL_II,
1292 0, NULL);
1293 else
1294 server->ops->set_oplock_level(cinode, 0, 0, NULL);
1295}
1296
1297static void
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001298smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
1299 unsigned int epoch, bool *purge_cache)
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001300{
1301 oplock &= 0xFF;
1302 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
1303 return;
1304 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001305 cinode->oplock = CIFS_CACHE_RHW_FLG;
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001306 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
1307 &cinode->vfs_inode);
1308 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001309 cinode->oplock = CIFS_CACHE_RW_FLG;
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001310 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
1311 &cinode->vfs_inode);
1312 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
1313 cinode->oplock = CIFS_CACHE_READ_FLG;
1314 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
1315 &cinode->vfs_inode);
1316 } else
1317 cinode->oplock = 0;
1318}
1319
1320static void
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001321smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
1322 unsigned int epoch, bool *purge_cache)
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001323{
1324 char message[5] = {0};
1325
1326 oplock &= 0xFF;
1327 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
1328 return;
1329
1330 cinode->oplock = 0;
1331 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
1332 cinode->oplock |= CIFS_CACHE_READ_FLG;
1333 strcat(message, "R");
1334 }
1335 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
1336 cinode->oplock |= CIFS_CACHE_HANDLE_FLG;
1337 strcat(message, "H");
1338 }
1339 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
1340 cinode->oplock |= CIFS_CACHE_WRITE_FLG;
1341 strcat(message, "W");
1342 }
1343 if (!cinode->oplock)
1344 strcat(message, "None");
1345 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
1346 &cinode->vfs_inode);
1347}
1348
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001349static void
1350smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
1351 unsigned int epoch, bool *purge_cache)
1352{
1353 unsigned int old_oplock = cinode->oplock;
1354
1355 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
1356
1357 if (purge_cache) {
1358 *purge_cache = false;
1359 if (old_oplock == CIFS_CACHE_READ_FLG) {
1360 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
1361 (epoch - cinode->epoch > 0))
1362 *purge_cache = true;
1363 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
1364 (epoch - cinode->epoch > 1))
1365 *purge_cache = true;
1366 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
1367 (epoch - cinode->epoch > 1))
1368 *purge_cache = true;
1369 else if (cinode->oplock == 0 &&
1370 (epoch - cinode->epoch > 0))
1371 *purge_cache = true;
1372 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
1373 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
1374 (epoch - cinode->epoch > 0))
1375 *purge_cache = true;
1376 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
1377 (epoch - cinode->epoch > 1))
1378 *purge_cache = true;
1379 }
1380 cinode->epoch = epoch;
1381 }
1382}
1383
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001384static bool
1385smb2_is_read_op(__u32 oplock)
1386{
1387 return oplock == SMB2_OPLOCK_LEVEL_II;
1388}
1389
1390static bool
1391smb21_is_read_op(__u32 oplock)
1392{
1393 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
1394 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
1395}
1396
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001397static __le32
1398map_oplock_to_lease(u8 oplock)
1399{
1400 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
1401 return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
1402 else if (oplock == SMB2_OPLOCK_LEVEL_II)
1403 return SMB2_LEASE_READ_CACHING;
1404 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
1405 return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING |
1406 SMB2_LEASE_WRITE_CACHING;
1407 return 0;
1408}
1409
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001410static char *
1411smb2_create_lease_buf(u8 *lease_key, u8 oplock)
1412{
1413 struct create_lease *buf;
1414
1415 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
1416 if (!buf)
1417 return NULL;
1418
1419 buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
1420 buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001421 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001422
1423 buf->ccontext.DataOffset = cpu_to_le16(offsetof
1424 (struct create_lease, lcontext));
1425 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
1426 buf->ccontext.NameOffset = cpu_to_le16(offsetof
1427 (struct create_lease, Name));
1428 buf->ccontext.NameLength = cpu_to_le16(4);
Steve French12197a72014-05-14 05:29:40 -07001429 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001430 buf->Name[0] = 'R';
1431 buf->Name[1] = 'q';
1432 buf->Name[2] = 'L';
1433 buf->Name[3] = 's';
1434 return (char *)buf;
1435}
1436
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001437static char *
1438smb3_create_lease_buf(u8 *lease_key, u8 oplock)
1439{
1440 struct create_lease_v2 *buf;
1441
1442 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
1443 if (!buf)
1444 return NULL;
1445
1446 buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
1447 buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
1448 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
1449
1450 buf->ccontext.DataOffset = cpu_to_le16(offsetof
1451 (struct create_lease_v2, lcontext));
1452 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
1453 buf->ccontext.NameOffset = cpu_to_le16(offsetof
1454 (struct create_lease_v2, Name));
1455 buf->ccontext.NameLength = cpu_to_le16(4);
Steve French12197a72014-05-14 05:29:40 -07001456 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001457 buf->Name[0] = 'R';
1458 buf->Name[1] = 'q';
1459 buf->Name[2] = 'L';
1460 buf->Name[3] = 's';
1461 return (char *)buf;
1462}
1463
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04001464static __u8
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001465smb2_parse_lease_buf(void *buf, unsigned int *epoch)
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04001466{
1467 struct create_lease *lc = (struct create_lease *)buf;
1468
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001469 *epoch = 0; /* not used */
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04001470 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
1471 return SMB2_OPLOCK_LEVEL_NOCHANGE;
1472 return le32_to_cpu(lc->lcontext.LeaseState);
1473}
1474
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001475static __u8
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001476smb3_parse_lease_buf(void *buf, unsigned int *epoch)
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001477{
1478 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
1479
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001480 *epoch = le16_to_cpu(lc->lcontext.Epoch);
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001481 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
1482 return SMB2_OPLOCK_LEVEL_NOCHANGE;
1483 return le32_to_cpu(lc->lcontext.LeaseState);
1484}
1485
Pavel Shilovsky7f6c5002014-06-22 11:03:22 +04001486static unsigned int
1487smb2_wp_retry_size(struct inode *inode)
1488{
1489 return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize,
1490 SMB2_MAX_BUFFER_SIZE);
1491}
1492
Pavel Shilovsky52755802014-08-18 20:49:57 +04001493static bool
1494smb2_dir_needs_close(struct cifsFileInfo *cfile)
1495{
1496 return !cfile->invalidHandle;
1497}
1498
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001499struct smb_version_operations smb20_operations = {
1500 .compare_fids = smb2_compare_fids,
1501 .setup_request = smb2_setup_request,
1502 .setup_async_request = smb2_setup_async_request,
1503 .check_receive = smb2_check_receive,
1504 .add_credits = smb2_add_credits,
1505 .set_credits = smb2_set_credits,
1506 .get_credits_field = smb2_get_credits_field,
1507 .get_credits = smb2_get_credits,
Pavel Shilovskycb7e9ea2014-06-05 19:03:27 +04001508 .wait_mtu_credits = cifs_wait_mtu_credits,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001509 .get_next_mid = smb2_get_next_mid,
1510 .read_data_offset = smb2_read_data_offset,
1511 .read_data_length = smb2_read_data_length,
1512 .map_error = map_smb2_to_linux_error,
1513 .find_mid = smb2_find_mid,
1514 .check_message = smb2_check_message,
1515 .dump_detail = smb2_dump_detail,
1516 .clear_stats = smb2_clear_stats,
1517 .print_stats = smb2_print_stats,
1518 .is_oplock_break = smb2_is_valid_oplock_break,
Sachin Prabhuc11f1df2014-03-11 16:11:47 +00001519 .downgrade_oplock = smb2_downgrade_oplock,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001520 .need_neg = smb2_need_neg,
1521 .negotiate = smb2_negotiate,
1522 .negotiate_wsize = smb2_negotiate_wsize,
1523 .negotiate_rsize = smb2_negotiate_rsize,
1524 .sess_setup = SMB2_sess_setup,
1525 .logoff = SMB2_logoff,
1526 .tree_connect = SMB2_tcon,
1527 .tree_disconnect = SMB2_tdis,
Steve French34f62642013-10-09 02:07:00 -05001528 .qfs_tcon = smb2_qfs_tcon,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001529 .is_path_accessible = smb2_is_path_accessible,
1530 .can_echo = smb2_can_echo,
1531 .echo = SMB2_echo,
1532 .query_path_info = smb2_query_path_info,
1533 .get_srv_inum = smb2_get_srv_inum,
1534 .query_file_info = smb2_query_file_info,
1535 .set_path_size = smb2_set_path_size,
1536 .set_file_size = smb2_set_file_size,
1537 .set_file_info = smb2_set_file_info,
Steve French64a5cfa2013-10-14 15:31:32 -05001538 .set_compression = smb2_set_compression,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001539 .mkdir = smb2_mkdir,
1540 .mkdir_setinfo = smb2_mkdir_setinfo,
1541 .rmdir = smb2_rmdir,
1542 .unlink = smb2_unlink,
1543 .rename = smb2_rename_path,
1544 .create_hardlink = smb2_create_hardlink,
1545 .query_symlink = smb2_query_symlink,
Sachin Prabhu5b23c972016-07-11 16:53:20 +01001546 .query_mf_symlink = smb3_query_mf_symlink,
1547 .create_mf_symlink = smb3_create_mf_symlink,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001548 .open = smb2_open_file,
1549 .set_fid = smb2_set_fid,
1550 .close = smb2_close_file,
1551 .flush = smb2_flush_file,
1552 .async_readv = smb2_async_readv,
1553 .async_writev = smb2_async_writev,
1554 .sync_read = smb2_sync_read,
1555 .sync_write = smb2_sync_write,
1556 .query_dir_first = smb2_query_dir_first,
1557 .query_dir_next = smb2_query_dir_next,
1558 .close_dir = smb2_close_dir,
1559 .calc_smb_size = smb2_calc_size,
1560 .is_status_pending = smb2_is_status_pending,
1561 .oplock_response = smb2_oplock_response,
1562 .queryfs = smb2_queryfs,
1563 .mand_lock = smb2_mand_lock,
1564 .mand_unlock_range = smb2_unlock_range,
1565 .push_mand_locks = smb2_push_mandatory_locks,
1566 .get_lease_key = smb2_get_lease_key,
1567 .set_lease_key = smb2_set_lease_key,
1568 .new_lease_key = smb2_new_lease_key,
1569 .calc_signature = smb2_calc_signature,
1570 .is_read_op = smb2_is_read_op,
1571 .set_oplock_level = smb2_set_oplock_level,
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001572 .create_lease_buf = smb2_create_lease_buf,
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04001573 .parse_lease_buf = smb2_parse_lease_buf,
Steve French41c13582013-11-14 00:05:36 -06001574 .clone_range = smb2_clone_range,
Pavel Shilovsky7f6c5002014-06-22 11:03:22 +04001575 .wp_retry_size = smb2_wp_retry_size,
Pavel Shilovsky52755802014-08-18 20:49:57 +04001576 .dir_needs_close = smb2_dir_needs_close,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001577};
1578
Steve French1080ef72011-02-24 18:07:19 +00001579struct smb_version_operations smb21_operations = {
Pavel Shilovsky027e8ee2012-09-19 06:22:43 -07001580 .compare_fids = smb2_compare_fids,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +04001581 .setup_request = smb2_setup_request,
Pavel Shilovskyc95b8ee2012-07-11 14:45:28 +04001582 .setup_async_request = smb2_setup_async_request,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +04001583 .check_receive = smb2_check_receive,
Pavel Shilovsky28ea5292012-05-23 16:18:00 +04001584 .add_credits = smb2_add_credits,
1585 .set_credits = smb2_set_credits,
1586 .get_credits_field = smb2_get_credits_field,
1587 .get_credits = smb2_get_credits,
Pavel Shilovskycb7e9ea2014-06-05 19:03:27 +04001588 .wait_mtu_credits = smb2_wait_mtu_credits,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +04001589 .get_next_mid = smb2_get_next_mid,
Pavel Shilovsky09a47072012-09-18 16:20:29 -07001590 .read_data_offset = smb2_read_data_offset,
1591 .read_data_length = smb2_read_data_length,
1592 .map_error = map_smb2_to_linux_error,
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +04001593 .find_mid = smb2_find_mid,
1594 .check_message = smb2_check_message,
1595 .dump_detail = smb2_dump_detail,
Pavel Shilovskyd60622e2012-05-28 15:19:39 +04001596 .clear_stats = smb2_clear_stats,
1597 .print_stats = smb2_print_stats,
Pavel Shilovsky983c88a2012-09-18 16:20:33 -07001598 .is_oplock_break = smb2_is_valid_oplock_break,
Sachin Prabhuc11f1df2014-03-11 16:11:47 +00001599 .downgrade_oplock = smb2_downgrade_oplock,
Pavel Shilovskyec2e4522011-12-27 16:12:43 +04001600 .need_neg = smb2_need_neg,
1601 .negotiate = smb2_negotiate,
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -07001602 .negotiate_wsize = smb2_negotiate_wsize,
1603 .negotiate_rsize = smb2_negotiate_rsize,
Pavel Shilovsky5478f9b2011-12-27 16:22:00 +04001604 .sess_setup = SMB2_sess_setup,
1605 .logoff = SMB2_logoff,
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +04001606 .tree_connect = SMB2_tcon,
1607 .tree_disconnect = SMB2_tdis,
Steve French34f62642013-10-09 02:07:00 -05001608 .qfs_tcon = smb2_qfs_tcon,
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +04001609 .is_path_accessible = smb2_is_path_accessible,
Pavel Shilovsky9094fad2012-07-12 18:30:44 +04001610 .can_echo = smb2_can_echo,
1611 .echo = SMB2_echo,
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +04001612 .query_path_info = smb2_query_path_info,
1613 .get_srv_inum = smb2_get_srv_inum,
Pavel Shilovskyb7546bc2012-09-18 16:20:27 -07001614 .query_file_info = smb2_query_file_info,
Pavel Shilovskyc839ff22012-09-18 16:20:32 -07001615 .set_path_size = smb2_set_path_size,
1616 .set_file_size = smb2_set_file_size,
Pavel Shilovsky1feeaac2012-09-18 16:20:32 -07001617 .set_file_info = smb2_set_file_info,
Steve French64a5cfa2013-10-14 15:31:32 -05001618 .set_compression = smb2_set_compression,
Pavel Shilovskya0e73182011-07-19 12:56:37 +04001619 .mkdir = smb2_mkdir,
1620 .mkdir_setinfo = smb2_mkdir_setinfo,
Pavel Shilovsky1a500f02012-07-10 16:14:38 +04001621 .rmdir = smb2_rmdir,
Pavel Shilovskycbe6f432012-09-18 16:20:25 -07001622 .unlink = smb2_unlink,
Pavel Shilovsky35143eb2012-09-18 16:20:31 -07001623 .rename = smb2_rename_path,
Pavel Shilovsky568798c2012-09-18 16:20:31 -07001624 .create_hardlink = smb2_create_hardlink,
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001625 .query_symlink = smb2_query_symlink,
Steve Frenchc22870e2014-09-16 07:18:19 -05001626 .query_mf_symlink = smb3_query_mf_symlink,
Steve French5ab97572014-09-15 04:49:28 -05001627 .create_mf_symlink = smb3_create_mf_symlink,
Pavel Shilovskyf0df7372012-09-18 16:20:26 -07001628 .open = smb2_open_file,
1629 .set_fid = smb2_set_fid,
1630 .close = smb2_close_file,
Pavel Shilovsky7a5cfb12012-09-18 16:20:28 -07001631 .flush = smb2_flush_file,
Pavel Shilovsky09a47072012-09-18 16:20:29 -07001632 .async_readv = smb2_async_readv,
Pavel Shilovsky33319142012-09-18 16:20:29 -07001633 .async_writev = smb2_async_writev,
Pavel Shilovskyd8e05032012-09-18 16:20:30 -07001634 .sync_read = smb2_sync_read,
Pavel Shilovsky009d3442012-09-18 16:20:30 -07001635 .sync_write = smb2_sync_write,
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -07001636 .query_dir_first = smb2_query_dir_first,
1637 .query_dir_next = smb2_query_dir_next,
1638 .close_dir = smb2_close_dir,
1639 .calc_smb_size = smb2_calc_size,
Pavel Shilovsky2e44b282012-09-18 16:20:33 -07001640 .is_status_pending = smb2_is_status_pending,
Pavel Shilovsky983c88a2012-09-18 16:20:33 -07001641 .oplock_response = smb2_oplock_response,
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001642 .queryfs = smb2_queryfs,
Pavel Shilovskyf7ba7fe2012-09-19 06:22:43 -07001643 .mand_lock = smb2_mand_lock,
1644 .mand_unlock_range = smb2_unlock_range,
Pavel Shilovskyb1407992012-09-19 06:22:44 -07001645 .push_mand_locks = smb2_push_mandatory_locks,
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -07001646 .get_lease_key = smb2_get_lease_key,
1647 .set_lease_key = smb2_set_lease_key,
1648 .new_lease_key = smb2_new_lease_key,
Steve French38107d42012-12-08 22:08:06 -06001649 .calc_signature = smb2_calc_signature,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001650 .is_read_op = smb21_is_read_op,
1651 .set_oplock_level = smb21_set_oplock_level,
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001652 .create_lease_buf = smb2_create_lease_buf,
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04001653 .parse_lease_buf = smb2_parse_lease_buf,
Steve French41c13582013-11-14 00:05:36 -06001654 .clone_range = smb2_clone_range,
Pavel Shilovsky7f6c5002014-06-22 11:03:22 +04001655 .wp_retry_size = smb2_wp_retry_size,
Pavel Shilovsky52755802014-08-18 20:49:57 +04001656 .dir_needs_close = smb2_dir_needs_close,
Steve French38107d42012-12-08 22:08:06 -06001657};
1658
Steve French38107d42012-12-08 22:08:06 -06001659struct smb_version_operations smb30_operations = {
1660 .compare_fids = smb2_compare_fids,
1661 .setup_request = smb2_setup_request,
1662 .setup_async_request = smb2_setup_async_request,
1663 .check_receive = smb2_check_receive,
1664 .add_credits = smb2_add_credits,
1665 .set_credits = smb2_set_credits,
1666 .get_credits_field = smb2_get_credits_field,
1667 .get_credits = smb2_get_credits,
Pavel Shilovskycb7e9ea2014-06-05 19:03:27 +04001668 .wait_mtu_credits = smb2_wait_mtu_credits,
Steve French38107d42012-12-08 22:08:06 -06001669 .get_next_mid = smb2_get_next_mid,
1670 .read_data_offset = smb2_read_data_offset,
1671 .read_data_length = smb2_read_data_length,
1672 .map_error = map_smb2_to_linux_error,
1673 .find_mid = smb2_find_mid,
1674 .check_message = smb2_check_message,
1675 .dump_detail = smb2_dump_detail,
1676 .clear_stats = smb2_clear_stats,
1677 .print_stats = smb2_print_stats,
Steve French769ee6a2013-06-19 14:15:30 -05001678 .dump_share_caps = smb2_dump_share_caps,
Steve French38107d42012-12-08 22:08:06 -06001679 .is_oplock_break = smb2_is_valid_oplock_break,
Sachin Prabhuc11f1df2014-03-11 16:11:47 +00001680 .downgrade_oplock = smb2_downgrade_oplock,
Steve French38107d42012-12-08 22:08:06 -06001681 .need_neg = smb2_need_neg,
1682 .negotiate = smb2_negotiate,
1683 .negotiate_wsize = smb2_negotiate_wsize,
1684 .negotiate_rsize = smb2_negotiate_rsize,
1685 .sess_setup = SMB2_sess_setup,
1686 .logoff = SMB2_logoff,
1687 .tree_connect = SMB2_tcon,
1688 .tree_disconnect = SMB2_tdis,
Steven Frenchaf6a12e2013-10-09 20:55:53 -05001689 .qfs_tcon = smb3_qfs_tcon,
Steve French38107d42012-12-08 22:08:06 -06001690 .is_path_accessible = smb2_is_path_accessible,
1691 .can_echo = smb2_can_echo,
1692 .echo = SMB2_echo,
1693 .query_path_info = smb2_query_path_info,
1694 .get_srv_inum = smb2_get_srv_inum,
1695 .query_file_info = smb2_query_file_info,
1696 .set_path_size = smb2_set_path_size,
1697 .set_file_size = smb2_set_file_size,
1698 .set_file_info = smb2_set_file_info,
Steve French64a5cfa2013-10-14 15:31:32 -05001699 .set_compression = smb2_set_compression,
Steve French38107d42012-12-08 22:08:06 -06001700 .mkdir = smb2_mkdir,
1701 .mkdir_setinfo = smb2_mkdir_setinfo,
1702 .rmdir = smb2_rmdir,
1703 .unlink = smb2_unlink,
1704 .rename = smb2_rename_path,
1705 .create_hardlink = smb2_create_hardlink,
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001706 .query_symlink = smb2_query_symlink,
Steve Frenchc22870e2014-09-16 07:18:19 -05001707 .query_mf_symlink = smb3_query_mf_symlink,
Steve French5ab97572014-09-15 04:49:28 -05001708 .create_mf_symlink = smb3_create_mf_symlink,
Steve French38107d42012-12-08 22:08:06 -06001709 .open = smb2_open_file,
1710 .set_fid = smb2_set_fid,
1711 .close = smb2_close_file,
1712 .flush = smb2_flush_file,
1713 .async_readv = smb2_async_readv,
1714 .async_writev = smb2_async_writev,
1715 .sync_read = smb2_sync_read,
1716 .sync_write = smb2_sync_write,
1717 .query_dir_first = smb2_query_dir_first,
1718 .query_dir_next = smb2_query_dir_next,
1719 .close_dir = smb2_close_dir,
1720 .calc_smb_size = smb2_calc_size,
1721 .is_status_pending = smb2_is_status_pending,
1722 .oplock_response = smb2_oplock_response,
1723 .queryfs = smb2_queryfs,
1724 .mand_lock = smb2_mand_lock,
1725 .mand_unlock_range = smb2_unlock_range,
1726 .push_mand_locks = smb2_push_mandatory_locks,
1727 .get_lease_key = smb2_get_lease_key,
1728 .set_lease_key = smb2_set_lease_key,
1729 .new_lease_key = smb2_new_lease_key,
Steve French373512e2015-12-18 13:05:30 -06001730 .generate_signingkey = generate_smb30signingkey,
Steve French38107d42012-12-08 22:08:06 -06001731 .calc_signature = smb3_calc_signature,
Steve Frenchb3152e22015-06-24 03:17:02 -05001732 .set_integrity = smb3_set_integrity,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001733 .is_read_op = smb21_is_read_op,
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001734 .set_oplock_level = smb3_set_oplock_level,
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001735 .create_lease_buf = smb3_create_lease_buf,
1736 .parse_lease_buf = smb3_parse_lease_buf,
Steve French41c13582013-11-14 00:05:36 -06001737 .clone_range = smb2_clone_range,
Steve Frenchca9e7a12015-10-01 21:40:10 -05001738 .duplicate_extents = smb2_duplicate_extents,
Steve Frenchff1c0382013-11-19 23:44:46 -06001739 .validate_negotiate = smb3_validate_negotiate,
Pavel Shilovsky7f6c5002014-06-22 11:03:22 +04001740 .wp_retry_size = smb2_wp_retry_size,
Pavel Shilovsky52755802014-08-18 20:49:57 +04001741 .dir_needs_close = smb2_dir_needs_close,
Steve French31742c52014-08-17 08:38:47 -05001742 .fallocate = smb3_fallocate,
Steve French1080ef72011-02-24 18:07:19 +00001743};
1744
Steve Frenchaab18932015-06-23 23:37:11 -05001745#ifdef CONFIG_CIFS_SMB311
1746struct smb_version_operations smb311_operations = {
1747 .compare_fids = smb2_compare_fids,
1748 .setup_request = smb2_setup_request,
1749 .setup_async_request = smb2_setup_async_request,
1750 .check_receive = smb2_check_receive,
1751 .add_credits = smb2_add_credits,
1752 .set_credits = smb2_set_credits,
1753 .get_credits_field = smb2_get_credits_field,
1754 .get_credits = smb2_get_credits,
1755 .wait_mtu_credits = smb2_wait_mtu_credits,
1756 .get_next_mid = smb2_get_next_mid,
1757 .read_data_offset = smb2_read_data_offset,
1758 .read_data_length = smb2_read_data_length,
1759 .map_error = map_smb2_to_linux_error,
1760 .find_mid = smb2_find_mid,
1761 .check_message = smb2_check_message,
1762 .dump_detail = smb2_dump_detail,
1763 .clear_stats = smb2_clear_stats,
1764 .print_stats = smb2_print_stats,
1765 .dump_share_caps = smb2_dump_share_caps,
1766 .is_oplock_break = smb2_is_valid_oplock_break,
1767 .downgrade_oplock = smb2_downgrade_oplock,
1768 .need_neg = smb2_need_neg,
1769 .negotiate = smb2_negotiate,
1770 .negotiate_wsize = smb2_negotiate_wsize,
1771 .negotiate_rsize = smb2_negotiate_rsize,
1772 .sess_setup = SMB2_sess_setup,
1773 .logoff = SMB2_logoff,
1774 .tree_connect = SMB2_tcon,
1775 .tree_disconnect = SMB2_tdis,
1776 .qfs_tcon = smb3_qfs_tcon,
1777 .is_path_accessible = smb2_is_path_accessible,
1778 .can_echo = smb2_can_echo,
1779 .echo = SMB2_echo,
1780 .query_path_info = smb2_query_path_info,
1781 .get_srv_inum = smb2_get_srv_inum,
1782 .query_file_info = smb2_query_file_info,
1783 .set_path_size = smb2_set_path_size,
1784 .set_file_size = smb2_set_file_size,
1785 .set_file_info = smb2_set_file_info,
1786 .set_compression = smb2_set_compression,
1787 .mkdir = smb2_mkdir,
1788 .mkdir_setinfo = smb2_mkdir_setinfo,
1789 .rmdir = smb2_rmdir,
1790 .unlink = smb2_unlink,
1791 .rename = smb2_rename_path,
1792 .create_hardlink = smb2_create_hardlink,
1793 .query_symlink = smb2_query_symlink,
1794 .query_mf_symlink = smb3_query_mf_symlink,
1795 .create_mf_symlink = smb3_create_mf_symlink,
1796 .open = smb2_open_file,
1797 .set_fid = smb2_set_fid,
1798 .close = smb2_close_file,
1799 .flush = smb2_flush_file,
1800 .async_readv = smb2_async_readv,
1801 .async_writev = smb2_async_writev,
1802 .sync_read = smb2_sync_read,
1803 .sync_write = smb2_sync_write,
1804 .query_dir_first = smb2_query_dir_first,
1805 .query_dir_next = smb2_query_dir_next,
1806 .close_dir = smb2_close_dir,
1807 .calc_smb_size = smb2_calc_size,
1808 .is_status_pending = smb2_is_status_pending,
1809 .oplock_response = smb2_oplock_response,
1810 .queryfs = smb2_queryfs,
1811 .mand_lock = smb2_mand_lock,
1812 .mand_unlock_range = smb2_unlock_range,
1813 .push_mand_locks = smb2_push_mandatory_locks,
1814 .get_lease_key = smb2_get_lease_key,
1815 .set_lease_key = smb2_set_lease_key,
1816 .new_lease_key = smb2_new_lease_key,
Steve French373512e2015-12-18 13:05:30 -06001817 .generate_signingkey = generate_smb311signingkey,
Steve Frenchaab18932015-06-23 23:37:11 -05001818 .calc_signature = smb3_calc_signature,
Steve Frenchb3152e22015-06-24 03:17:02 -05001819 .set_integrity = smb3_set_integrity,
Steve Frenchaab18932015-06-23 23:37:11 -05001820 .is_read_op = smb21_is_read_op,
1821 .set_oplock_level = smb3_set_oplock_level,
1822 .create_lease_buf = smb3_create_lease_buf,
1823 .parse_lease_buf = smb3_parse_lease_buf,
1824 .clone_range = smb2_clone_range,
Steve French02b16662015-06-27 21:18:36 -07001825 .duplicate_extents = smb2_duplicate_extents,
Steve Frenchaab18932015-06-23 23:37:11 -05001826/* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
1827 .wp_retry_size = smb2_wp_retry_size,
1828 .dir_needs_close = smb2_dir_needs_close,
1829 .fallocate = smb3_fallocate,
1830};
1831#endif /* CIFS_SMB311 */
1832
Steve Frenchdd446b12012-11-28 23:21:06 -06001833struct smb_version_values smb20_values = {
1834 .version_string = SMB20_VERSION_STRING,
1835 .protocol_id = SMB20_PROT_ID,
1836 .req_capabilities = 0, /* MBZ */
1837 .large_lock_type = 0,
1838 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1839 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1840 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
1841 .header_size = sizeof(struct smb2_hdr),
1842 .max_header_size = MAX_SMB2_HDR_SIZE,
1843 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
1844 .lock_cmd = SMB2_LOCK,
1845 .cap_unix = 0,
1846 .cap_nt_find = SMB2_NT_FIND,
1847 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton50285882013-06-27 12:45:00 -04001848 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1849 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001850 .create_lease_size = sizeof(struct create_lease),
Steve Frenchdd446b12012-11-28 23:21:06 -06001851};
1852
Steve French1080ef72011-02-24 18:07:19 +00001853struct smb_version_values smb21_values = {
1854 .version_string = SMB21_VERSION_STRING,
Steve Frenche4aa25e2012-10-01 12:26:22 -05001855 .protocol_id = SMB21_PROT_ID,
1856 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
1857 .large_lock_type = 0,
1858 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1859 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1860 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
1861 .header_size = sizeof(struct smb2_hdr),
1862 .max_header_size = MAX_SMB2_HDR_SIZE,
1863 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
1864 .lock_cmd = SMB2_LOCK,
1865 .cap_unix = 0,
1866 .cap_nt_find = SMB2_NT_FIND,
1867 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton50285882013-06-27 12:45:00 -04001868 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1869 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001870 .create_lease_size = sizeof(struct create_lease),
Steve Frenche4aa25e2012-10-01 12:26:22 -05001871};
1872
1873struct smb_version_values smb30_values = {
1874 .version_string = SMB30_VERSION_STRING,
1875 .protocol_id = SMB30_PROT_ID,
Steve French373512e2015-12-18 13:05:30 -06001876 .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 -07001877 .large_lock_type = 0,
1878 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1879 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1880 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +04001881 .header_size = sizeof(struct smb2_hdr),
1882 .max_header_size = MAX_SMB2_HDR_SIZE,
Pavel Shilovsky09a47072012-09-18 16:20:29 -07001883 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +04001884 .lock_cmd = SMB2_LOCK,
Pavel Shilovsky29e20f92012-07-13 13:58:14 +04001885 .cap_unix = 0,
1886 .cap_nt_find = SMB2_NT_FIND,
1887 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton50285882013-06-27 12:45:00 -04001888 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1889 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001890 .create_lease_size = sizeof(struct create_lease_v2),
Steve French1080ef72011-02-24 18:07:19 +00001891};
Steve French20b6d8b2013-06-12 22:48:41 -05001892
1893struct smb_version_values smb302_values = {
1894 .version_string = SMB302_VERSION_STRING,
1895 .protocol_id = SMB302_PROT_ID,
Steve French373512e2015-12-18 13:05:30 -06001896 .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 -05001897 .large_lock_type = 0,
1898 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1899 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1900 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
1901 .header_size = sizeof(struct smb2_hdr),
1902 .max_header_size = MAX_SMB2_HDR_SIZE,
1903 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
1904 .lock_cmd = SMB2_LOCK,
1905 .cap_unix = 0,
1906 .cap_nt_find = SMB2_NT_FIND,
1907 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton50285882013-06-27 12:45:00 -04001908 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1909 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001910 .create_lease_size = sizeof(struct create_lease_v2),
Steve French20b6d8b2013-06-12 22:48:41 -05001911};
Steve French5f7fbf72014-12-17 22:52:58 -06001912
1913#ifdef CONFIG_CIFS_SMB311
1914struct smb_version_values smb311_values = {
1915 .version_string = SMB311_VERSION_STRING,
1916 .protocol_id = SMB311_PROT_ID,
Steve Frenchb618f002015-11-03 09:15:03 -06001917 .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 -06001918 .large_lock_type = 0,
1919 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1920 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1921 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
1922 .header_size = sizeof(struct smb2_hdr),
1923 .max_header_size = MAX_SMB2_HDR_SIZE,
1924 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
1925 .lock_cmd = SMB2_LOCK,
1926 .cap_unix = 0,
1927 .cap_nt_find = SMB2_NT_FIND,
1928 .cap_large_files = SMB2_LARGE_FILES,
1929 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1930 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
1931 .create_lease_size = sizeof(struct create_lease_v2),
1932};
1933#endif /* SMB311 */