blob: df91bcf56d67a35f0dd60d0361514f65cdc6705e [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;
53 server->oplocks = true;
54 server->echo_credits = 1;
55 server->oplock_credits = 1;
56 }
57 server->credits -= server->echo_credits + server->oplock_credits;
58 return 0;
59}
60
61static void
62smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add,
63 const int optype)
64{
65 int *val, rc = 0;
66 spin_lock(&server->req_lock);
67 val = server->ops->get_credits_field(server, optype);
68 *val += add;
69 server->in_flight--;
Pavel Shilovskyec2e4522011-12-27 16:12:43 +040070 if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP)
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040071 rc = change_conf(server);
Pavel Shilovsky983c88a2012-09-18 16:20:33 -070072 /*
73 * Sometimes server returns 0 credits on oplock break ack - we need to
74 * rebalance credits in this case.
75 */
76 else if (server->in_flight > 0 && server->oplock_credits == 0 &&
77 server->oplocks) {
78 if (server->credits > 1) {
79 server->credits--;
80 server->oplock_credits++;
81 }
82 }
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040083 spin_unlock(&server->req_lock);
84 wake_up(&server->request_q);
85 if (rc)
86 cifs_reconnect(server);
87}
88
89static void
90smb2_set_credits(struct TCP_Server_Info *server, const int val)
91{
92 spin_lock(&server->req_lock);
93 server->credits = val;
94 spin_unlock(&server->req_lock);
95}
96
97static int *
98smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
99{
100 switch (optype) {
101 case CIFS_ECHO_OP:
102 return &server->echo_credits;
103 case CIFS_OBREAK_OP:
104 return &server->oplock_credits;
105 default:
106 return &server->credits;
107 }
108}
109
110static unsigned int
111smb2_get_credits(struct mid_q_entry *mid)
112{
113 return le16_to_cpu(((struct smb2_hdr *)mid->resp_buf)->CreditRequest);
114}
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +0400115
Pavel Shilovskycb7e9ea2014-06-05 19:03:27 +0400116static int
117smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size,
118 unsigned int *num, unsigned int *credits)
119{
120 int rc = 0;
121 unsigned int scredits;
122
123 spin_lock(&server->req_lock);
124 while (1) {
125 if (server->credits <= 0) {
126 spin_unlock(&server->req_lock);
127 cifs_num_waiters_inc(server);
128 rc = wait_event_killable(server->request_q,
129 has_credits(server, &server->credits));
130 cifs_num_waiters_dec(server);
131 if (rc)
132 return rc;
133 spin_lock(&server->req_lock);
134 } else {
135 if (server->tcpStatus == CifsExiting) {
136 spin_unlock(&server->req_lock);
137 return -ENOENT;
138 }
139
140 scredits = server->credits;
141 /* can deadlock with reopen */
142 if (scredits == 1) {
143 *num = SMB2_MAX_BUFFER_SIZE;
144 *credits = 0;
145 break;
146 }
147
148 /* leave one credit for a possible reopen */
149 scredits--;
150 *num = min_t(unsigned int, size,
151 scredits * SMB2_MAX_BUFFER_SIZE);
152
153 *credits = DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE);
154 server->credits -= *credits;
155 server->in_flight++;
156 break;
157 }
158 }
159 spin_unlock(&server->req_lock);
160 return rc;
161}
162
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +0400163static __u64
164smb2_get_next_mid(struct TCP_Server_Info *server)
165{
166 __u64 mid;
167 /* for SMB2 we need the current value */
168 spin_lock(&GlobalMid_Lock);
169 mid = server->CurrentMid++;
170 spin_unlock(&GlobalMid_Lock);
171 return mid;
172}
Steve French1080ef72011-02-24 18:07:19 +0000173
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400174static struct mid_q_entry *
175smb2_find_mid(struct TCP_Server_Info *server, char *buf)
176{
177 struct mid_q_entry *mid;
178 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
Sachin Prabhu9235d092014-12-09 17:37:00 +0000179 __u64 wire_mid = le64_to_cpu(hdr->MessageId);
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400180
181 spin_lock(&GlobalMid_Lock);
182 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
Sachin Prabhu9235d092014-12-09 17:37:00 +0000183 if ((mid->mid == wire_mid) &&
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400184 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
185 (mid->command == hdr->Command)) {
186 spin_unlock(&GlobalMid_Lock);
187 return mid;
188 }
189 }
190 spin_unlock(&GlobalMid_Lock);
191 return NULL;
192}
193
194static void
195smb2_dump_detail(void *buf)
196{
197#ifdef CONFIG_CIFS_DEBUG2
198 struct smb2_hdr *smb = (struct smb2_hdr *)buf;
199
Joe Perchesf96637b2013-05-04 22:12:25 -0500200 cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
201 smb->Command, smb->Status, smb->Flags, smb->MessageId,
202 smb->ProcessId);
203 cifs_dbg(VFS, "smb buf %p len %u\n", smb, smb2_calc_size(smb));
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400204#endif
205}
206
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400207static bool
208smb2_need_neg(struct TCP_Server_Info *server)
209{
210 return server->max_read == 0;
211}
212
213static int
214smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
215{
216 int rc;
217 ses->server->CurrentMid = 0;
218 rc = SMB2_negotiate(xid, ses);
219 /* BB we probably don't need to retry with modern servers */
220 if (rc == -EAGAIN)
221 rc = -EHOSTDOWN;
222 return rc;
223}
224
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700225static unsigned int
226smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
227{
228 struct TCP_Server_Info *server = tcon->ses->server;
229 unsigned int wsize;
230
231 /* start with specified wsize, or default */
232 wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
233 wsize = min_t(unsigned int, wsize, server->max_write);
Pavel Shilovskycb7e9ea2014-06-05 19:03:27 +0400234
235 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
236 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700237
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700238 return wsize;
239}
240
241static unsigned int
242smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
243{
244 struct TCP_Server_Info *server = tcon->ses->server;
245 unsigned int rsize;
246
247 /* start with specified rsize, or default */
248 rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
249 rsize = min_t(unsigned int, rsize, server->max_read);
Pavel Shilovskybed9da02014-06-25 11:28:57 +0400250
251 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
252 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700253
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700254 return rsize;
255}
256
Steve Frenchc481e9f2013-10-14 01:21:53 -0500257#ifdef CONFIG_CIFS_STATS2
258static int
259SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon)
260{
261 int rc;
262 unsigned int ret_data_len = 0;
263 struct network_interface_info_ioctl_rsp *out_buf;
264
265 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
266 FSCTL_QUERY_NETWORK_INTERFACE_INFO, true /* is_fsctl */,
267 NULL /* no data input */, 0 /* no data input */,
268 (char **)&out_buf, &ret_data_len);
Steve French9ffc5412014-10-16 15:13:14 -0500269 if (rc != 0)
270 cifs_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
271 else if (ret_data_len < sizeof(struct network_interface_info_ioctl_rsp)) {
272 cifs_dbg(VFS, "server returned bad net interface info buf\n");
273 rc = -EINVAL;
274 } else {
Steve Frenchc481e9f2013-10-14 01:21:53 -0500275 /* Dump info on first interface */
276 cifs_dbg(FYI, "Adapter Capability 0x%x\t",
277 le32_to_cpu(out_buf->Capability));
278 cifs_dbg(FYI, "Link Speed %lld\n",
279 le64_to_cpu(out_buf->LinkSpeed));
Steve French9ffc5412014-10-16 15:13:14 -0500280 }
Steve Frenchc481e9f2013-10-14 01:21:53 -0500281
282 return rc;
283}
284#endif /* STATS2 */
285
Steve French34f62642013-10-09 02:07:00 -0500286static void
Steven Frenchaf6a12e2013-10-09 20:55:53 -0500287smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
288{
289 int rc;
290 __le16 srch_path = 0; /* Null - open root of share */
291 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
292 struct cifs_open_parms oparms;
293 struct cifs_fid fid;
294
295 oparms.tcon = tcon;
296 oparms.desired_access = FILE_READ_ATTRIBUTES;
297 oparms.disposition = FILE_OPEN;
298 oparms.create_options = 0;
299 oparms.fid = &fid;
300 oparms.reconnect = false;
301
302 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
303 if (rc)
304 return;
305
Steve Frenchc481e9f2013-10-14 01:21:53 -0500306#ifdef CONFIG_CIFS_STATS2
307 SMB3_request_interfaces(xid, tcon);
308#endif /* STATS2 */
309
Steven Frenchaf6a12e2013-10-09 20:55:53 -0500310 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
311 FS_ATTRIBUTE_INFORMATION);
312 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
313 FS_DEVICE_INFORMATION);
314 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
315 FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
316 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
317 return;
318}
319
320static void
Steve French34f62642013-10-09 02:07:00 -0500321smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
322{
323 int rc;
324 __le16 srch_path = 0; /* Null - open root of share */
325 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
326 struct cifs_open_parms oparms;
327 struct cifs_fid fid;
328
329 oparms.tcon = tcon;
330 oparms.desired_access = FILE_READ_ATTRIBUTES;
331 oparms.disposition = FILE_OPEN;
332 oparms.create_options = 0;
333 oparms.fid = &fid;
334 oparms.reconnect = false;
335
336 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
337 if (rc)
338 return;
339
Steven French21671142013-10-09 13:36:35 -0500340 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
341 FS_ATTRIBUTE_INFORMATION);
342 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
343 FS_DEVICE_INFORMATION);
Steve French34f62642013-10-09 02:07:00 -0500344 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
345 return;
346}
347
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400348static int
349smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
350 struct cifs_sb_info *cifs_sb, const char *full_path)
351{
352 int rc;
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400353 __le16 *utf16_path;
Pavel Shilovsky2e44b282012-09-18 16:20:33 -0700354 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400355 struct cifs_open_parms oparms;
356 struct cifs_fid fid;
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400357
358 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
359 if (!utf16_path)
360 return -ENOMEM;
361
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400362 oparms.tcon = tcon;
363 oparms.desired_access = FILE_READ_ATTRIBUTES;
364 oparms.disposition = FILE_OPEN;
365 oparms.create_options = 0;
366 oparms.fid = &fid;
Pavel Shilovsky9cbc0b72013-07-09 18:40:58 +0400367 oparms.reconnect = false;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400368
Pavel Shilovskyb42bf882013-08-14 19:25:21 +0400369 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400370 if (rc) {
371 kfree(utf16_path);
372 return rc;
373 }
374
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400375 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400376 kfree(utf16_path);
377 return rc;
378}
379
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +0400380static int
381smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
382 struct cifs_sb_info *cifs_sb, const char *full_path,
383 u64 *uniqueid, FILE_ALL_INFO *data)
384{
385 *uniqueid = le64_to_cpu(data->IndexNumber);
386 return 0;
387}
388
Pavel Shilovskyb7546bc2012-09-18 16:20:27 -0700389static int
390smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
391 struct cifs_fid *fid, FILE_ALL_INFO *data)
392{
393 int rc;
394 struct smb2_file_all_info *smb2_data;
395
Pavel Shilovsky1bbe4992014-08-22 13:32:11 +0400396 smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
Pavel Shilovskyb7546bc2012-09-18 16:20:27 -0700397 GFP_KERNEL);
398 if (smb2_data == NULL)
399 return -ENOMEM;
400
401 rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
402 smb2_data);
403 if (!rc)
404 move_smb2_info_to_cifs(data, smb2_data);
405 kfree(smb2_data);
406 return rc;
407}
408
Pavel Shilovsky9094fad2012-07-12 18:30:44 +0400409static bool
410smb2_can_echo(struct TCP_Server_Info *server)
411{
412 return server->echoes;
413}
414
Pavel Shilovskyd60622e2012-05-28 15:19:39 +0400415static void
416smb2_clear_stats(struct cifs_tcon *tcon)
417{
418#ifdef CONFIG_CIFS_STATS
419 int i;
420 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
421 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
422 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
423 }
424#endif
425}
426
427static void
Steve French769ee6a2013-06-19 14:15:30 -0500428smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
429{
430 seq_puts(m, "\n\tShare Capabilities:");
431 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
432 seq_puts(m, " DFS,");
433 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
434 seq_puts(m, " CONTINUOUS AVAILABILITY,");
435 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
436 seq_puts(m, " SCALEOUT,");
437 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
438 seq_puts(m, " CLUSTER,");
439 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
440 seq_puts(m, " ASYMMETRIC,");
441 if (tcon->capabilities == 0)
442 seq_puts(m, " None");
Steven Frenchaf6a12e2013-10-09 20:55:53 -0500443 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
444 seq_puts(m, " Aligned,");
445 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
446 seq_puts(m, " Partition Aligned,");
447 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
448 seq_puts(m, " SSD,");
449 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
450 seq_puts(m, " TRIM-support,");
451
Steve French769ee6a2013-06-19 14:15:30 -0500452 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
Steven Frenchaf6a12e2013-10-09 20:55:53 -0500453 if (tcon->perf_sector_size)
454 seq_printf(m, "\tOptimal sector size: 0x%x",
455 tcon->perf_sector_size);
Steve French769ee6a2013-06-19 14:15:30 -0500456}
457
458static void
Pavel Shilovskyd60622e2012-05-28 15:19:39 +0400459smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
460{
461#ifdef CONFIG_CIFS_STATS
462 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
463 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
464 seq_printf(m, "\nNegotiates: %d sent %d failed",
465 atomic_read(&sent[SMB2_NEGOTIATE_HE]),
466 atomic_read(&failed[SMB2_NEGOTIATE_HE]));
467 seq_printf(m, "\nSessionSetups: %d sent %d failed",
468 atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
469 atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
Pavel Shilovskyd60622e2012-05-28 15:19:39 +0400470 seq_printf(m, "\nLogoffs: %d sent %d failed",
471 atomic_read(&sent[SMB2_LOGOFF_HE]),
472 atomic_read(&failed[SMB2_LOGOFF_HE]));
473 seq_printf(m, "\nTreeConnects: %d sent %d failed",
474 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
475 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
476 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
477 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
478 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
479 seq_printf(m, "\nCreates: %d sent %d failed",
480 atomic_read(&sent[SMB2_CREATE_HE]),
481 atomic_read(&failed[SMB2_CREATE_HE]));
482 seq_printf(m, "\nCloses: %d sent %d failed",
483 atomic_read(&sent[SMB2_CLOSE_HE]),
484 atomic_read(&failed[SMB2_CLOSE_HE]));
485 seq_printf(m, "\nFlushes: %d sent %d failed",
486 atomic_read(&sent[SMB2_FLUSH_HE]),
487 atomic_read(&failed[SMB2_FLUSH_HE]));
488 seq_printf(m, "\nReads: %d sent %d failed",
489 atomic_read(&sent[SMB2_READ_HE]),
490 atomic_read(&failed[SMB2_READ_HE]));
491 seq_printf(m, "\nWrites: %d sent %d failed",
492 atomic_read(&sent[SMB2_WRITE_HE]),
493 atomic_read(&failed[SMB2_WRITE_HE]));
494 seq_printf(m, "\nLocks: %d sent %d failed",
495 atomic_read(&sent[SMB2_LOCK_HE]),
496 atomic_read(&failed[SMB2_LOCK_HE]));
497 seq_printf(m, "\nIOCTLs: %d sent %d failed",
498 atomic_read(&sent[SMB2_IOCTL_HE]),
499 atomic_read(&failed[SMB2_IOCTL_HE]));
500 seq_printf(m, "\nCancels: %d sent %d failed",
501 atomic_read(&sent[SMB2_CANCEL_HE]),
502 atomic_read(&failed[SMB2_CANCEL_HE]));
503 seq_printf(m, "\nEchos: %d sent %d failed",
504 atomic_read(&sent[SMB2_ECHO_HE]),
505 atomic_read(&failed[SMB2_ECHO_HE]));
506 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
507 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
508 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
509 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
510 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
511 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
512 seq_printf(m, "\nQueryInfos: %d sent %d failed",
513 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
514 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
515 seq_printf(m, "\nSetInfos: %d sent %d failed",
516 atomic_read(&sent[SMB2_SET_INFO_HE]),
517 atomic_read(&failed[SMB2_SET_INFO_HE]));
518 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
519 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
520 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
521#endif
522}
523
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700524static void
525smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
526{
David Howells2b0143b2015-03-17 22:25:59 +0000527 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
Pavel Shilovsky53ef1012013-09-05 16:11:28 +0400528 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
529
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700530 cfile->fid.persistent_fid = fid->persistent_fid;
531 cfile->fid.volatile_fid = fid->volatile_fid;
Pavel Shilovsky42873b02013-09-05 21:30:16 +0400532 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
533 &fid->purge_cache);
Pavel Shilovsky18cceb62013-09-05 13:01:06 +0400534 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700535}
536
Pavel Shilovsky760ad0c2012-09-25 11:00:07 +0400537static void
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700538smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
539 struct cifs_fid *fid)
540{
Pavel Shilovsky760ad0c2012-09-25 11:00:07 +0400541 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700542}
543
Pavel Shilovsky7a5cfb12012-09-18 16:20:28 -0700544static int
Steve French41c13582013-11-14 00:05:36 -0600545SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
546 u64 persistent_fid, u64 volatile_fid,
547 struct copychunk_ioctl *pcchunk)
548{
549 int rc;
550 unsigned int ret_data_len;
551 struct resume_key_req *res_key;
552
553 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
554 FSCTL_SRV_REQUEST_RESUME_KEY, true /* is_fsctl */,
555 NULL, 0 /* no input */,
556 (char **)&res_key, &ret_data_len);
557
558 if (rc) {
559 cifs_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
560 goto req_res_key_exit;
561 }
562 if (ret_data_len < sizeof(struct resume_key_req)) {
563 cifs_dbg(VFS, "Invalid refcopy resume key length\n");
564 rc = -EINVAL;
565 goto req_res_key_exit;
566 }
567 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
568
569req_res_key_exit:
570 kfree(res_key);
571 return rc;
572}
573
574static int
575smb2_clone_range(const unsigned int xid,
576 struct cifsFileInfo *srcfile,
577 struct cifsFileInfo *trgtfile, u64 src_off,
578 u64 len, u64 dest_off)
579{
580 int rc;
581 unsigned int ret_data_len;
582 struct copychunk_ioctl *pcchunk;
Steve French9bf0c9c2013-11-16 18:05:28 -0600583 struct copychunk_ioctl_rsp *retbuf = NULL;
584 struct cifs_tcon *tcon;
585 int chunks_copied = 0;
586 bool chunk_sizes_updated = false;
Steve French41c13582013-11-14 00:05:36 -0600587
588 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
589
590 if (pcchunk == NULL)
591 return -ENOMEM;
592
593 cifs_dbg(FYI, "in smb2_clone_range - about to call request res key\n");
594 /* Request a key from the server to identify the source of the copy */
595 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
596 srcfile->fid.persistent_fid,
597 srcfile->fid.volatile_fid, pcchunk);
598
599 /* Note: request_res_key sets res_key null only if rc !=0 */
600 if (rc)
Steve French9bf0c9c2013-11-16 18:05:28 -0600601 goto cchunk_out;
Steve French41c13582013-11-14 00:05:36 -0600602
603 /* For now array only one chunk long, will make more flexible later */
Fabian Frederickbc09d142014-12-10 15:41:15 -0800604 pcchunk->ChunkCount = cpu_to_le32(1);
Steve French41c13582013-11-14 00:05:36 -0600605 pcchunk->Reserved = 0;
Steve French41c13582013-11-14 00:05:36 -0600606 pcchunk->Reserved2 = 0;
607
Steve French9bf0c9c2013-11-16 18:05:28 -0600608 tcon = tlink_tcon(trgtfile->tlink);
609
610 while (len > 0) {
611 pcchunk->SourceOffset = cpu_to_le64(src_off);
612 pcchunk->TargetOffset = cpu_to_le64(dest_off);
613 pcchunk->Length =
614 cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
615
616 /* Request server copy to target from src identified by key */
617 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
Steve French41c13582013-11-14 00:05:36 -0600618 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
619 true /* is_fsctl */, (char *)pcchunk,
Steve French9bf0c9c2013-11-16 18:05:28 -0600620 sizeof(struct copychunk_ioctl), (char **)&retbuf,
621 &ret_data_len);
622 if (rc == 0) {
623 if (ret_data_len !=
624 sizeof(struct copychunk_ioctl_rsp)) {
625 cifs_dbg(VFS, "invalid cchunk response size\n");
626 rc = -EIO;
627 goto cchunk_out;
628 }
629 if (retbuf->TotalBytesWritten == 0) {
630 cifs_dbg(FYI, "no bytes copied\n");
631 rc = -EIO;
632 goto cchunk_out;
633 }
634 /*
635 * Check if server claimed to write more than we asked
636 */
637 if (le32_to_cpu(retbuf->TotalBytesWritten) >
638 le32_to_cpu(pcchunk->Length)) {
639 cifs_dbg(VFS, "invalid copy chunk response\n");
640 rc = -EIO;
641 goto cchunk_out;
642 }
643 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
644 cifs_dbg(VFS, "invalid num chunks written\n");
645 rc = -EIO;
646 goto cchunk_out;
647 }
648 chunks_copied++;
Steve French41c13582013-11-14 00:05:36 -0600649
Steve French9bf0c9c2013-11-16 18:05:28 -0600650 src_off += le32_to_cpu(retbuf->TotalBytesWritten);
651 dest_off += le32_to_cpu(retbuf->TotalBytesWritten);
652 len -= le32_to_cpu(retbuf->TotalBytesWritten);
Steve French41c13582013-11-14 00:05:36 -0600653
Steve French9bf0c9c2013-11-16 18:05:28 -0600654 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %d\n",
655 le32_to_cpu(retbuf->ChunksWritten),
656 le32_to_cpu(retbuf->ChunkBytesWritten),
657 le32_to_cpu(retbuf->TotalBytesWritten));
658 } else if (rc == -EINVAL) {
659 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
660 goto cchunk_out;
Steve French41c13582013-11-14 00:05:36 -0600661
Steve French9bf0c9c2013-11-16 18:05:28 -0600662 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
663 le32_to_cpu(retbuf->ChunksWritten),
664 le32_to_cpu(retbuf->ChunkBytesWritten),
665 le32_to_cpu(retbuf->TotalBytesWritten));
666
667 /*
668 * Check if this is the first request using these sizes,
669 * (ie check if copy succeed once with original sizes
670 * and check if the server gave us different sizes after
671 * we already updated max sizes on previous request).
672 * if not then why is the server returning an error now
673 */
674 if ((chunks_copied != 0) || chunk_sizes_updated)
675 goto cchunk_out;
676
677 /* Check that server is not asking us to grow size */
678 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
679 tcon->max_bytes_chunk)
680 tcon->max_bytes_chunk =
681 le32_to_cpu(retbuf->ChunkBytesWritten);
682 else
683 goto cchunk_out; /* server gave us bogus size */
684
685 /* No need to change MaxChunks since already set to 1 */
686 chunk_sizes_updated = true;
Sachin Prabhu2477bc52015-02-04 13:10:26 +0000687 } else
688 goto cchunk_out;
Steve French9bf0c9c2013-11-16 18:05:28 -0600689 }
690
691cchunk_out:
Steve French41c13582013-11-14 00:05:36 -0600692 kfree(pcchunk);
693 return rc;
694}
695
696static int
Pavel Shilovsky7a5cfb12012-09-18 16:20:28 -0700697smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
698 struct cifs_fid *fid)
699{
700 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
701}
702
Pavel Shilovsky09a47072012-09-18 16:20:29 -0700703static unsigned int
704smb2_read_data_offset(char *buf)
705{
706 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
707 return rsp->DataOffset;
708}
709
710static unsigned int
711smb2_read_data_length(char *buf)
712{
713 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
714 return le32_to_cpu(rsp->DataLength);
715}
716
Pavel Shilovskyd8e05032012-09-18 16:20:30 -0700717
718static int
Steve Frenchdb8b6312014-09-22 05:13:55 -0500719smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
Pavel Shilovskyd8e05032012-09-18 16:20:30 -0700720 struct cifs_io_parms *parms, unsigned int *bytes_read,
721 char **buf, int *buf_type)
722{
Steve Frenchdb8b6312014-09-22 05:13:55 -0500723 parms->persistent_fid = pfid->persistent_fid;
724 parms->volatile_fid = pfid->volatile_fid;
Pavel Shilovskyd8e05032012-09-18 16:20:30 -0700725 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
726}
727
Pavel Shilovsky009d3442012-09-18 16:20:30 -0700728static int
Steve Frenchdb8b6312014-09-22 05:13:55 -0500729smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
Pavel Shilovsky009d3442012-09-18 16:20:30 -0700730 struct cifs_io_parms *parms, unsigned int *written,
731 struct kvec *iov, unsigned long nr_segs)
732{
733
Steve Frenchdb8b6312014-09-22 05:13:55 -0500734 parms->persistent_fid = pfid->persistent_fid;
735 parms->volatile_fid = pfid->volatile_fid;
Pavel Shilovsky009d3442012-09-18 16:20:30 -0700736 return SMB2_write(xid, parms, written, iov, nr_segs);
737}
738
Steve Frenchd43cc792014-08-13 17:16:29 -0500739/* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
740static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
741 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
742{
743 struct cifsInodeInfo *cifsi;
744 int rc;
745
746 cifsi = CIFS_I(inode);
747
748 /* if file already sparse don't bother setting sparse again */
749 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
750 return true; /* already sparse */
751
752 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
753 return true; /* already not sparse */
754
755 /*
756 * Can't check for sparse support on share the usual way via the
757 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
758 * since Samba server doesn't set the flag on the share, yet
759 * supports the set sparse FSCTL and returns sparse correctly
760 * in the file attributes. If we fail setting sparse though we
761 * mark that server does not support sparse files for this share
762 * to avoid repeatedly sending the unsupported fsctl to server
763 * if the file is repeatedly extended.
764 */
765 if (tcon->broken_sparse_sup)
766 return false;
767
768 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
769 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
770 true /* is_fctl */, &setsparse, 1, NULL, NULL);
771 if (rc) {
772 tcon->broken_sparse_sup = true;
773 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
774 return false;
775 }
776
777 if (setsparse)
778 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
779 else
780 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
781
782 return true;
783}
784
Pavel Shilovskyc839ff22012-09-18 16:20:32 -0700785static int
786smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
787 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
788{
789 __le64 eof = cpu_to_le64(size);
Steve French3d1a3742014-08-11 21:05:25 -0500790 struct inode *inode;
791
792 /*
793 * If extending file more than one page make sparse. Many Linux fs
794 * make files sparse by default when extending via ftruncate
795 */
David Howells2b0143b2015-03-17 22:25:59 +0000796 inode = d_inode(cfile->dentry);
Steve French3d1a3742014-08-11 21:05:25 -0500797
798 if (!set_alloc && (size > inode->i_size + 8192)) {
Steve French3d1a3742014-08-11 21:05:25 -0500799 __u8 set_sparse = 1;
Steve French3d1a3742014-08-11 21:05:25 -0500800
Steve Frenchd43cc792014-08-13 17:16:29 -0500801 /* whether set sparse succeeds or not, extend the file */
802 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
Steve French3d1a3742014-08-11 21:05:25 -0500803 }
804
Pavel Shilovskyc839ff22012-09-18 16:20:32 -0700805 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
Steve Frenchf29ebb42014-07-19 21:44:58 -0500806 cfile->fid.volatile_fid, cfile->pid, &eof, false);
Pavel Shilovskyc839ff22012-09-18 16:20:32 -0700807}
808
Steve French02b16662015-06-27 21:18:36 -0700809#ifdef CONFIG_CIFS_SMB311
810static int
811smb2_duplicate_extents(const unsigned int xid,
812 struct cifsFileInfo *srcfile,
813 struct cifsFileInfo *trgtfile, u64 src_off,
814 u64 len, u64 dest_off)
815{
816 int rc;
817 unsigned int ret_data_len;
818 char *retbuf = NULL;
819 struct duplicate_extents_to_file dup_ext_buf;
820 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
821
822 /* server fileays advertise duplicate extent support with this flag */
823 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
824 FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
825 return -EOPNOTSUPP;
826
827 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
828 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
829 dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
830 dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
831 dup_ext_buf.ByteCount = cpu_to_le64(len);
832 cifs_dbg(FYI, "duplicate extents: src off %lld dst off %lld len %lld",
833 src_off, dest_off, len);
834
835 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
836 if (rc)
837 goto duplicate_extents_out;
838
839 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
840 trgtfile->fid.volatile_fid,
841 FSCTL_DUPLICATE_EXTENTS_TO_FILE,
842 true /* is_fsctl */, (char *)&dup_ext_buf,
843 sizeof(struct duplicate_extents_to_file),
844 (char **)&retbuf,
845 &ret_data_len);
846
847 if (ret_data_len > 0)
848 cifs_dbg(FYI, "non-zero response length in duplicate extents");
849
850duplicate_extents_out:
851 return rc;
852}
853#endif /* CONFIG_CIFS_SMB311 */
854
855
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700856static int
Steve French64a5cfa2013-10-14 15:31:32 -0500857smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
858 struct cifsFileInfo *cfile)
859{
860 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
861 cfile->fid.volatile_fid);
862}
863
864static int
Steve Frenchb3152e22015-06-24 03:17:02 -0500865smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
866 struct cifsFileInfo *cfile)
867{
868 struct fsctl_set_integrity_information_req integr_info;
869 char *retbuf = NULL;
870 unsigned int ret_data_len;
871
872 integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
873 integr_info.Flags = 0;
874 integr_info.Reserved = 0;
875
876 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
877 cfile->fid.volatile_fid,
878 FSCTL_SET_INTEGRITY_INFORMATION,
879 true /* is_fsctl */, (char *)&integr_info,
880 sizeof(struct fsctl_set_integrity_information_req),
881 (char **)&retbuf,
882 &ret_data_len);
883
884}
885
886static int
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700887smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
888 const char *path, struct cifs_sb_info *cifs_sb,
889 struct cifs_fid *fid, __u16 search_flags,
890 struct cifs_search_info *srch_inf)
891{
892 __le16 *utf16_path;
893 int rc;
Pavel Shilovsky2e44b282012-09-18 16:20:33 -0700894 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400895 struct cifs_open_parms oparms;
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700896
897 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
898 if (!utf16_path)
899 return -ENOMEM;
900
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400901 oparms.tcon = tcon;
902 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
903 oparms.disposition = FILE_OPEN;
904 oparms.create_options = 0;
905 oparms.fid = fid;
Pavel Shilovsky9cbc0b72013-07-09 18:40:58 +0400906 oparms.reconnect = false;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400907
Pavel Shilovskyb42bf882013-08-14 19:25:21 +0400908 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700909 kfree(utf16_path);
910 if (rc) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500911 cifs_dbg(VFS, "open dir failed\n");
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700912 return rc;
913 }
914
915 srch_inf->entries_in_buffer = 0;
916 srch_inf->index_of_last_entry = 0;
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700917
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400918 rc = SMB2_query_directory(xid, tcon, fid->persistent_fid,
919 fid->volatile_fid, 0, srch_inf);
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700920 if (rc) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500921 cifs_dbg(VFS, "query directory failed\n");
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400922 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700923 }
924 return rc;
925}
926
927static int
928smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
929 struct cifs_fid *fid, __u16 search_flags,
930 struct cifs_search_info *srch_inf)
931{
932 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
933 fid->volatile_fid, 0, srch_inf);
934}
935
936static int
937smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
938 struct cifs_fid *fid)
939{
940 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
941}
942
Pavel Shilovsky2e44b282012-09-18 16:20:33 -0700943/*
944* If we negotiate SMB2 protocol and get STATUS_PENDING - update
945* the number of credits and return true. Otherwise - return false.
946*/
947static bool
948smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
949{
950 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
951
Steve French12e8a202012-09-19 09:19:39 -0700952 if (hdr->Status != STATUS_PENDING)
Pavel Shilovsky2e44b282012-09-18 16:20:33 -0700953 return false;
954
955 if (!length) {
956 spin_lock(&server->req_lock);
957 server->credits += le16_to_cpu(hdr->CreditRequest);
958 spin_unlock(&server->req_lock);
959 wake_up(&server->request_q);
960 }
961
962 return true;
963}
964
Pavel Shilovsky983c88a2012-09-18 16:20:33 -0700965static int
966smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
967 struct cifsInodeInfo *cinode)
968{
Pavel Shilovsky0822f512012-09-19 06:22:45 -0700969 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
970 return SMB2_lease_break(0, tcon, cinode->lease_key,
971 smb2_get_lease_state(cinode));
972
Pavel Shilovsky983c88a2012-09-18 16:20:33 -0700973 return SMB2_oplock_break(0, tcon, fid->persistent_fid,
974 fid->volatile_fid,
Pavel Shilovsky18cceb62013-09-05 13:01:06 +0400975 CIFS_CACHE_READ(cinode) ? 1 : 0);
Pavel Shilovsky983c88a2012-09-18 16:20:33 -0700976}
977
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -0700978static int
979smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
980 struct kstatfs *buf)
981{
982 int rc;
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -0700983 __le16 srch_path = 0; /* Null - open root of share */
984 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400985 struct cifs_open_parms oparms;
986 struct cifs_fid fid;
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -0700987
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400988 oparms.tcon = tcon;
989 oparms.desired_access = FILE_READ_ATTRIBUTES;
990 oparms.disposition = FILE_OPEN;
991 oparms.create_options = 0;
992 oparms.fid = &fid;
Pavel Shilovsky9cbc0b72013-07-09 18:40:58 +0400993 oparms.reconnect = false;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400994
Pavel Shilovskyb42bf882013-08-14 19:25:21 +0400995 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -0700996 if (rc)
997 return rc;
998 buf->f_type = SMB2_MAGIC_NUMBER;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400999 rc = SMB2_QFS_info(xid, tcon, fid.persistent_fid, fid.volatile_fid,
1000 buf);
1001 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001002 return rc;
1003}
1004
Pavel Shilovsky027e8ee2012-09-19 06:22:43 -07001005static bool
1006smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
1007{
1008 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
1009 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
1010}
1011
Pavel Shilovskyf7ba7fe2012-09-19 06:22:43 -07001012static int
1013smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
1014 __u64 length, __u32 type, int lock, int unlock, bool wait)
1015{
1016 if (unlock && !lock)
1017 type = SMB2_LOCKFLAG_UNLOCK;
1018 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
1019 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
1020 current->tgid, length, offset, type, wait);
1021}
1022
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -07001023static void
1024smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
1025{
1026 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
1027}
1028
1029static void
1030smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
1031{
1032 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
1033}
1034
1035static void
1036smb2_new_lease_key(struct cifs_fid *fid)
1037{
1038 get_random_bytes(fid->lease_key, SMB2_LEASE_KEY_SIZE);
1039}
1040
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001041static int
1042smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
1043 const char *full_path, char **target_path,
1044 struct cifs_sb_info *cifs_sb)
1045{
1046 int rc;
1047 __le16 *utf16_path;
1048 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1049 struct cifs_open_parms oparms;
1050 struct cifs_fid fid;
1051 struct smb2_err_rsp *err_buf = NULL;
1052 struct smb2_symlink_err_rsp *symlink;
1053 unsigned int sub_len, sub_offset;
1054
1055 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
1056
1057 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
1058 if (!utf16_path)
1059 return -ENOMEM;
1060
1061 oparms.tcon = tcon;
1062 oparms.desired_access = FILE_READ_ATTRIBUTES;
1063 oparms.disposition = FILE_OPEN;
1064 oparms.create_options = 0;
1065 oparms.fid = &fid;
1066 oparms.reconnect = false;
1067
1068 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_buf);
1069
1070 if (!rc || !err_buf) {
1071 kfree(utf16_path);
1072 return -ENOENT;
1073 }
1074 /* open must fail on symlink - reset rc */
1075 rc = 0;
1076 symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
1077 sub_len = le16_to_cpu(symlink->SubstituteNameLength);
1078 sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
1079 *target_path = cifs_strndup_from_utf16(
1080 (char *)symlink->PathBuffer + sub_offset,
1081 sub_len, true, cifs_sb->local_nls);
1082 if (!(*target_path)) {
1083 kfree(utf16_path);
1084 return -ENOMEM;
1085 }
1086 convert_delimiter(*target_path, '/');
1087 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
1088 kfree(utf16_path);
1089 return rc;
1090}
1091
Steve French30175622014-08-17 18:16:40 -05001092static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
1093 loff_t offset, loff_t len, bool keep_size)
1094{
1095 struct inode *inode;
1096 struct cifsInodeInfo *cifsi;
1097 struct cifsFileInfo *cfile = file->private_data;
1098 struct file_zero_data_information fsctl_buf;
1099 long rc;
1100 unsigned int xid;
1101
1102 xid = get_xid();
1103
David Howells2b0143b2015-03-17 22:25:59 +00001104 inode = d_inode(cfile->dentry);
Steve French30175622014-08-17 18:16:40 -05001105 cifsi = CIFS_I(inode);
1106
1107 /* if file not oplocked can't be sure whether asking to extend size */
1108 if (!CIFS_CACHE_READ(cifsi))
1109 if (keep_size == false)
1110 return -EOPNOTSUPP;
1111
Steve French2bb93d22014-08-20 18:56:29 -05001112 /*
Steve French30175622014-08-17 18:16:40 -05001113 * Must check if file sparse since fallocate -z (zero range) assumes
1114 * non-sparse allocation
1115 */
1116 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE))
1117 return -EOPNOTSUPP;
1118
1119 /*
1120 * need to make sure we are not asked to extend the file since the SMB3
1121 * fsctl does not change the file size. In the future we could change
1122 * this to zero the first part of the range then set the file size
1123 * which for a non sparse file would zero the newly extended range
1124 */
1125 if (keep_size == false)
1126 if (i_size_read(inode) < offset + len)
1127 return -EOPNOTSUPP;
1128
1129 cifs_dbg(FYI, "offset %lld len %lld", offset, len);
1130
1131 fsctl_buf.FileOffset = cpu_to_le64(offset);
1132 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
1133
1134 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1135 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
1136 true /* is_fctl */, (char *)&fsctl_buf,
1137 sizeof(struct file_zero_data_information), NULL, NULL);
1138 free_xid(xid);
1139 return rc;
1140}
1141
Steve French31742c52014-08-17 08:38:47 -05001142static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
1143 loff_t offset, loff_t len)
1144{
1145 struct inode *inode;
1146 struct cifsInodeInfo *cifsi;
1147 struct cifsFileInfo *cfile = file->private_data;
1148 struct file_zero_data_information fsctl_buf;
1149 long rc;
1150 unsigned int xid;
1151 __u8 set_sparse = 1;
1152
1153 xid = get_xid();
1154
David Howells2b0143b2015-03-17 22:25:59 +00001155 inode = d_inode(cfile->dentry);
Steve French31742c52014-08-17 08:38:47 -05001156 cifsi = CIFS_I(inode);
1157
1158 /* Need to make file sparse, if not already, before freeing range. */
1159 /* Consider adding equivalent for compressed since it could also work */
1160 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse))
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 French9ccf3212014-10-18 17:01:15 -05001176static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
1177 loff_t off, loff_t len, bool keep_size)
1178{
1179 struct inode *inode;
1180 struct cifsInodeInfo *cifsi;
1181 struct cifsFileInfo *cfile = file->private_data;
1182 long rc = -EOPNOTSUPP;
1183 unsigned int xid;
1184
1185 xid = get_xid();
1186
David Howells2b0143b2015-03-17 22:25:59 +00001187 inode = d_inode(cfile->dentry);
Steve French9ccf3212014-10-18 17:01:15 -05001188 cifsi = CIFS_I(inode);
1189
1190 /* if file not oplocked can't be sure whether asking to extend size */
1191 if (!CIFS_CACHE_READ(cifsi))
1192 if (keep_size == false)
1193 return -EOPNOTSUPP;
1194
1195 /*
1196 * Files are non-sparse by default so falloc may be a no-op
1197 * Must check if file sparse. If not sparse, and not extending
1198 * then no need to do anything since file already allocated
1199 */
1200 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
1201 if (keep_size == true)
1202 return 0;
1203 /* check if extending file */
1204 else if (i_size_read(inode) >= off + len)
1205 /* not extending file and already not sparse */
1206 return 0;
1207 /* BB: in future add else clause to extend file */
1208 else
1209 return -EOPNOTSUPP;
1210 }
1211
1212 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
1213 /*
1214 * Check if falloc starts within first few pages of file
1215 * and ends within a few pages of the end of file to
1216 * ensure that most of file is being forced to be
1217 * fallocated now. If so then setting whole file sparse
1218 * ie potentially making a few extra pages at the beginning
1219 * or end of the file non-sparse via set_sparse is harmless.
1220 */
1221 if ((off > 8192) || (off + len + 8192 < i_size_read(inode)))
1222 return -EOPNOTSUPP;
1223
1224 rc = smb2_set_sparse(xid, tcon, cfile, inode, false);
1225 }
1226 /* BB: else ... in future add code to extend file and set sparse */
1227
1228
1229 free_xid(xid);
1230 return rc;
1231}
1232
1233
Steve French31742c52014-08-17 08:38:47 -05001234static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
1235 loff_t off, loff_t len)
1236{
1237 /* KEEP_SIZE already checked for by do_fallocate */
1238 if (mode & FALLOC_FL_PUNCH_HOLE)
1239 return smb3_punch_hole(file, tcon, off, len);
Steve French30175622014-08-17 18:16:40 -05001240 else if (mode & FALLOC_FL_ZERO_RANGE) {
1241 if (mode & FALLOC_FL_KEEP_SIZE)
1242 return smb3_zero_range(file, tcon, off, len, true);
1243 return smb3_zero_range(file, tcon, off, len, false);
Steve French9ccf3212014-10-18 17:01:15 -05001244 } else if (mode == FALLOC_FL_KEEP_SIZE)
1245 return smb3_simple_falloc(file, tcon, off, len, true);
1246 else if (mode == 0)
1247 return smb3_simple_falloc(file, tcon, off, len, false);
Steve French31742c52014-08-17 08:38:47 -05001248
1249 return -EOPNOTSUPP;
1250}
1251
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001252static void
Sachin Prabhuc11f1df2014-03-11 16:11:47 +00001253smb2_downgrade_oplock(struct TCP_Server_Info *server,
1254 struct cifsInodeInfo *cinode, bool set_level2)
1255{
1256 if (set_level2)
1257 server->ops->set_oplock_level(cinode, SMB2_OPLOCK_LEVEL_II,
1258 0, NULL);
1259 else
1260 server->ops->set_oplock_level(cinode, 0, 0, NULL);
1261}
1262
1263static void
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001264smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
1265 unsigned int epoch, bool *purge_cache)
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001266{
1267 oplock &= 0xFF;
1268 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
1269 return;
1270 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001271 cinode->oplock = CIFS_CACHE_RHW_FLG;
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001272 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
1273 &cinode->vfs_inode);
1274 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001275 cinode->oplock = CIFS_CACHE_RW_FLG;
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001276 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
1277 &cinode->vfs_inode);
1278 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
1279 cinode->oplock = CIFS_CACHE_READ_FLG;
1280 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
1281 &cinode->vfs_inode);
1282 } else
1283 cinode->oplock = 0;
1284}
1285
1286static void
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001287smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
1288 unsigned int epoch, bool *purge_cache)
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001289{
1290 char message[5] = {0};
1291
1292 oplock &= 0xFF;
1293 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
1294 return;
1295
1296 cinode->oplock = 0;
1297 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
1298 cinode->oplock |= CIFS_CACHE_READ_FLG;
1299 strcat(message, "R");
1300 }
1301 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
1302 cinode->oplock |= CIFS_CACHE_HANDLE_FLG;
1303 strcat(message, "H");
1304 }
1305 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
1306 cinode->oplock |= CIFS_CACHE_WRITE_FLG;
1307 strcat(message, "W");
1308 }
1309 if (!cinode->oplock)
1310 strcat(message, "None");
1311 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
1312 &cinode->vfs_inode);
1313}
1314
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001315static void
1316smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
1317 unsigned int epoch, bool *purge_cache)
1318{
1319 unsigned int old_oplock = cinode->oplock;
1320
1321 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
1322
1323 if (purge_cache) {
1324 *purge_cache = false;
1325 if (old_oplock == CIFS_CACHE_READ_FLG) {
1326 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
1327 (epoch - cinode->epoch > 0))
1328 *purge_cache = true;
1329 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
1330 (epoch - cinode->epoch > 1))
1331 *purge_cache = true;
1332 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
1333 (epoch - cinode->epoch > 1))
1334 *purge_cache = true;
1335 else if (cinode->oplock == 0 &&
1336 (epoch - cinode->epoch > 0))
1337 *purge_cache = true;
1338 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
1339 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
1340 (epoch - cinode->epoch > 0))
1341 *purge_cache = true;
1342 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
1343 (epoch - cinode->epoch > 1))
1344 *purge_cache = true;
1345 }
1346 cinode->epoch = epoch;
1347 }
1348}
1349
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001350static bool
1351smb2_is_read_op(__u32 oplock)
1352{
1353 return oplock == SMB2_OPLOCK_LEVEL_II;
1354}
1355
1356static bool
1357smb21_is_read_op(__u32 oplock)
1358{
1359 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
1360 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
1361}
1362
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001363static __le32
1364map_oplock_to_lease(u8 oplock)
1365{
1366 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
1367 return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
1368 else if (oplock == SMB2_OPLOCK_LEVEL_II)
1369 return SMB2_LEASE_READ_CACHING;
1370 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
1371 return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING |
1372 SMB2_LEASE_WRITE_CACHING;
1373 return 0;
1374}
1375
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001376static char *
1377smb2_create_lease_buf(u8 *lease_key, u8 oplock)
1378{
1379 struct create_lease *buf;
1380
1381 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
1382 if (!buf)
1383 return NULL;
1384
1385 buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
1386 buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001387 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001388
1389 buf->ccontext.DataOffset = cpu_to_le16(offsetof
1390 (struct create_lease, lcontext));
1391 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
1392 buf->ccontext.NameOffset = cpu_to_le16(offsetof
1393 (struct create_lease, Name));
1394 buf->ccontext.NameLength = cpu_to_le16(4);
Steve French12197a72014-05-14 05:29:40 -07001395 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001396 buf->Name[0] = 'R';
1397 buf->Name[1] = 'q';
1398 buf->Name[2] = 'L';
1399 buf->Name[3] = 's';
1400 return (char *)buf;
1401}
1402
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001403static char *
1404smb3_create_lease_buf(u8 *lease_key, u8 oplock)
1405{
1406 struct create_lease_v2 *buf;
1407
1408 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
1409 if (!buf)
1410 return NULL;
1411
1412 buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
1413 buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
1414 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
1415
1416 buf->ccontext.DataOffset = cpu_to_le16(offsetof
1417 (struct create_lease_v2, lcontext));
1418 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
1419 buf->ccontext.NameOffset = cpu_to_le16(offsetof
1420 (struct create_lease_v2, Name));
1421 buf->ccontext.NameLength = cpu_to_le16(4);
Steve French12197a72014-05-14 05:29:40 -07001422 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001423 buf->Name[0] = 'R';
1424 buf->Name[1] = 'q';
1425 buf->Name[2] = 'L';
1426 buf->Name[3] = 's';
1427 return (char *)buf;
1428}
1429
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04001430static __u8
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001431smb2_parse_lease_buf(void *buf, unsigned int *epoch)
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04001432{
1433 struct create_lease *lc = (struct create_lease *)buf;
1434
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001435 *epoch = 0; /* not used */
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04001436 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
1437 return SMB2_OPLOCK_LEVEL_NOCHANGE;
1438 return le32_to_cpu(lc->lcontext.LeaseState);
1439}
1440
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001441static __u8
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001442smb3_parse_lease_buf(void *buf, unsigned int *epoch)
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001443{
1444 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
1445
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001446 *epoch = le16_to_cpu(lc->lcontext.Epoch);
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001447 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
1448 return SMB2_OPLOCK_LEVEL_NOCHANGE;
1449 return le32_to_cpu(lc->lcontext.LeaseState);
1450}
1451
Pavel Shilovsky7f6c5002014-06-22 11:03:22 +04001452static unsigned int
1453smb2_wp_retry_size(struct inode *inode)
1454{
1455 return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize,
1456 SMB2_MAX_BUFFER_SIZE);
1457}
1458
Pavel Shilovsky52755802014-08-18 20:49:57 +04001459static bool
1460smb2_dir_needs_close(struct cifsFileInfo *cfile)
1461{
1462 return !cfile->invalidHandle;
1463}
1464
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001465struct smb_version_operations smb20_operations = {
1466 .compare_fids = smb2_compare_fids,
1467 .setup_request = smb2_setup_request,
1468 .setup_async_request = smb2_setup_async_request,
1469 .check_receive = smb2_check_receive,
1470 .add_credits = smb2_add_credits,
1471 .set_credits = smb2_set_credits,
1472 .get_credits_field = smb2_get_credits_field,
1473 .get_credits = smb2_get_credits,
Pavel Shilovskycb7e9ea2014-06-05 19:03:27 +04001474 .wait_mtu_credits = cifs_wait_mtu_credits,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001475 .get_next_mid = smb2_get_next_mid,
1476 .read_data_offset = smb2_read_data_offset,
1477 .read_data_length = smb2_read_data_length,
1478 .map_error = map_smb2_to_linux_error,
1479 .find_mid = smb2_find_mid,
1480 .check_message = smb2_check_message,
1481 .dump_detail = smb2_dump_detail,
1482 .clear_stats = smb2_clear_stats,
1483 .print_stats = smb2_print_stats,
1484 .is_oplock_break = smb2_is_valid_oplock_break,
Sachin Prabhuc11f1df2014-03-11 16:11:47 +00001485 .downgrade_oplock = smb2_downgrade_oplock,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001486 .need_neg = smb2_need_neg,
1487 .negotiate = smb2_negotiate,
1488 .negotiate_wsize = smb2_negotiate_wsize,
1489 .negotiate_rsize = smb2_negotiate_rsize,
1490 .sess_setup = SMB2_sess_setup,
1491 .logoff = SMB2_logoff,
1492 .tree_connect = SMB2_tcon,
1493 .tree_disconnect = SMB2_tdis,
Steve French34f62642013-10-09 02:07:00 -05001494 .qfs_tcon = smb2_qfs_tcon,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001495 .is_path_accessible = smb2_is_path_accessible,
1496 .can_echo = smb2_can_echo,
1497 .echo = SMB2_echo,
1498 .query_path_info = smb2_query_path_info,
1499 .get_srv_inum = smb2_get_srv_inum,
1500 .query_file_info = smb2_query_file_info,
1501 .set_path_size = smb2_set_path_size,
1502 .set_file_size = smb2_set_file_size,
1503 .set_file_info = smb2_set_file_info,
Steve French64a5cfa2013-10-14 15:31:32 -05001504 .set_compression = smb2_set_compression,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001505 .mkdir = smb2_mkdir,
1506 .mkdir_setinfo = smb2_mkdir_setinfo,
1507 .rmdir = smb2_rmdir,
1508 .unlink = smb2_unlink,
1509 .rename = smb2_rename_path,
1510 .create_hardlink = smb2_create_hardlink,
1511 .query_symlink = smb2_query_symlink,
1512 .open = smb2_open_file,
1513 .set_fid = smb2_set_fid,
1514 .close = smb2_close_file,
1515 .flush = smb2_flush_file,
1516 .async_readv = smb2_async_readv,
1517 .async_writev = smb2_async_writev,
1518 .sync_read = smb2_sync_read,
1519 .sync_write = smb2_sync_write,
1520 .query_dir_first = smb2_query_dir_first,
1521 .query_dir_next = smb2_query_dir_next,
1522 .close_dir = smb2_close_dir,
1523 .calc_smb_size = smb2_calc_size,
1524 .is_status_pending = smb2_is_status_pending,
1525 .oplock_response = smb2_oplock_response,
1526 .queryfs = smb2_queryfs,
1527 .mand_lock = smb2_mand_lock,
1528 .mand_unlock_range = smb2_unlock_range,
1529 .push_mand_locks = smb2_push_mandatory_locks,
1530 .get_lease_key = smb2_get_lease_key,
1531 .set_lease_key = smb2_set_lease_key,
1532 .new_lease_key = smb2_new_lease_key,
1533 .calc_signature = smb2_calc_signature,
1534 .is_read_op = smb2_is_read_op,
1535 .set_oplock_level = smb2_set_oplock_level,
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001536 .create_lease_buf = smb2_create_lease_buf,
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04001537 .parse_lease_buf = smb2_parse_lease_buf,
Steve French41c13582013-11-14 00:05:36 -06001538 .clone_range = smb2_clone_range,
Pavel Shilovsky7f6c5002014-06-22 11:03:22 +04001539 .wp_retry_size = smb2_wp_retry_size,
Pavel Shilovsky52755802014-08-18 20:49:57 +04001540 .dir_needs_close = smb2_dir_needs_close,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001541};
1542
Steve French1080ef72011-02-24 18:07:19 +00001543struct smb_version_operations smb21_operations = {
Pavel Shilovsky027e8ee2012-09-19 06:22:43 -07001544 .compare_fids = smb2_compare_fids,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +04001545 .setup_request = smb2_setup_request,
Pavel Shilovskyc95b8ee2012-07-11 14:45:28 +04001546 .setup_async_request = smb2_setup_async_request,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +04001547 .check_receive = smb2_check_receive,
Pavel Shilovsky28ea5292012-05-23 16:18:00 +04001548 .add_credits = smb2_add_credits,
1549 .set_credits = smb2_set_credits,
1550 .get_credits_field = smb2_get_credits_field,
1551 .get_credits = smb2_get_credits,
Pavel Shilovskycb7e9ea2014-06-05 19:03:27 +04001552 .wait_mtu_credits = smb2_wait_mtu_credits,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +04001553 .get_next_mid = smb2_get_next_mid,
Pavel Shilovsky09a47072012-09-18 16:20:29 -07001554 .read_data_offset = smb2_read_data_offset,
1555 .read_data_length = smb2_read_data_length,
1556 .map_error = map_smb2_to_linux_error,
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +04001557 .find_mid = smb2_find_mid,
1558 .check_message = smb2_check_message,
1559 .dump_detail = smb2_dump_detail,
Pavel Shilovskyd60622e2012-05-28 15:19:39 +04001560 .clear_stats = smb2_clear_stats,
1561 .print_stats = smb2_print_stats,
Pavel Shilovsky983c88a2012-09-18 16:20:33 -07001562 .is_oplock_break = smb2_is_valid_oplock_break,
Sachin Prabhuc11f1df2014-03-11 16:11:47 +00001563 .downgrade_oplock = smb2_downgrade_oplock,
Pavel Shilovskyec2e4522011-12-27 16:12:43 +04001564 .need_neg = smb2_need_neg,
1565 .negotiate = smb2_negotiate,
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -07001566 .negotiate_wsize = smb2_negotiate_wsize,
1567 .negotiate_rsize = smb2_negotiate_rsize,
Pavel Shilovsky5478f9b2011-12-27 16:22:00 +04001568 .sess_setup = SMB2_sess_setup,
1569 .logoff = SMB2_logoff,
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +04001570 .tree_connect = SMB2_tcon,
1571 .tree_disconnect = SMB2_tdis,
Steve French34f62642013-10-09 02:07:00 -05001572 .qfs_tcon = smb2_qfs_tcon,
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +04001573 .is_path_accessible = smb2_is_path_accessible,
Pavel Shilovsky9094fad2012-07-12 18:30:44 +04001574 .can_echo = smb2_can_echo,
1575 .echo = SMB2_echo,
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +04001576 .query_path_info = smb2_query_path_info,
1577 .get_srv_inum = smb2_get_srv_inum,
Pavel Shilovskyb7546bc2012-09-18 16:20:27 -07001578 .query_file_info = smb2_query_file_info,
Pavel Shilovskyc839ff22012-09-18 16:20:32 -07001579 .set_path_size = smb2_set_path_size,
1580 .set_file_size = smb2_set_file_size,
Pavel Shilovsky1feeaac2012-09-18 16:20:32 -07001581 .set_file_info = smb2_set_file_info,
Steve French64a5cfa2013-10-14 15:31:32 -05001582 .set_compression = smb2_set_compression,
Pavel Shilovskya0e73182011-07-19 12:56:37 +04001583 .mkdir = smb2_mkdir,
1584 .mkdir_setinfo = smb2_mkdir_setinfo,
Pavel Shilovsky1a500f02012-07-10 16:14:38 +04001585 .rmdir = smb2_rmdir,
Pavel Shilovskycbe6f432012-09-18 16:20:25 -07001586 .unlink = smb2_unlink,
Pavel Shilovsky35143eb2012-09-18 16:20:31 -07001587 .rename = smb2_rename_path,
Pavel Shilovsky568798c2012-09-18 16:20:31 -07001588 .create_hardlink = smb2_create_hardlink,
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001589 .query_symlink = smb2_query_symlink,
Steve Frenchc22870e2014-09-16 07:18:19 -05001590 .query_mf_symlink = smb3_query_mf_symlink,
Steve French5ab97572014-09-15 04:49:28 -05001591 .create_mf_symlink = smb3_create_mf_symlink,
Pavel Shilovskyf0df7372012-09-18 16:20:26 -07001592 .open = smb2_open_file,
1593 .set_fid = smb2_set_fid,
1594 .close = smb2_close_file,
Pavel Shilovsky7a5cfb12012-09-18 16:20:28 -07001595 .flush = smb2_flush_file,
Pavel Shilovsky09a47072012-09-18 16:20:29 -07001596 .async_readv = smb2_async_readv,
Pavel Shilovsky33319142012-09-18 16:20:29 -07001597 .async_writev = smb2_async_writev,
Pavel Shilovskyd8e05032012-09-18 16:20:30 -07001598 .sync_read = smb2_sync_read,
Pavel Shilovsky009d3442012-09-18 16:20:30 -07001599 .sync_write = smb2_sync_write,
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -07001600 .query_dir_first = smb2_query_dir_first,
1601 .query_dir_next = smb2_query_dir_next,
1602 .close_dir = smb2_close_dir,
1603 .calc_smb_size = smb2_calc_size,
Pavel Shilovsky2e44b282012-09-18 16:20:33 -07001604 .is_status_pending = smb2_is_status_pending,
Pavel Shilovsky983c88a2012-09-18 16:20:33 -07001605 .oplock_response = smb2_oplock_response,
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001606 .queryfs = smb2_queryfs,
Pavel Shilovskyf7ba7fe2012-09-19 06:22:43 -07001607 .mand_lock = smb2_mand_lock,
1608 .mand_unlock_range = smb2_unlock_range,
Pavel Shilovskyb1407992012-09-19 06:22:44 -07001609 .push_mand_locks = smb2_push_mandatory_locks,
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -07001610 .get_lease_key = smb2_get_lease_key,
1611 .set_lease_key = smb2_set_lease_key,
1612 .new_lease_key = smb2_new_lease_key,
Steve French38107d42012-12-08 22:08:06 -06001613 .calc_signature = smb2_calc_signature,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001614 .is_read_op = smb21_is_read_op,
1615 .set_oplock_level = smb21_set_oplock_level,
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001616 .create_lease_buf = smb2_create_lease_buf,
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04001617 .parse_lease_buf = smb2_parse_lease_buf,
Steve French41c13582013-11-14 00:05:36 -06001618 .clone_range = smb2_clone_range,
Pavel Shilovsky7f6c5002014-06-22 11:03:22 +04001619 .wp_retry_size = smb2_wp_retry_size,
Pavel Shilovsky52755802014-08-18 20:49:57 +04001620 .dir_needs_close = smb2_dir_needs_close,
Steve French38107d42012-12-08 22:08:06 -06001621};
1622
Steve French38107d42012-12-08 22:08:06 -06001623struct smb_version_operations smb30_operations = {
1624 .compare_fids = smb2_compare_fids,
1625 .setup_request = smb2_setup_request,
1626 .setup_async_request = smb2_setup_async_request,
1627 .check_receive = smb2_check_receive,
1628 .add_credits = smb2_add_credits,
1629 .set_credits = smb2_set_credits,
1630 .get_credits_field = smb2_get_credits_field,
1631 .get_credits = smb2_get_credits,
Pavel Shilovskycb7e9ea2014-06-05 19:03:27 +04001632 .wait_mtu_credits = smb2_wait_mtu_credits,
Steve French38107d42012-12-08 22:08:06 -06001633 .get_next_mid = smb2_get_next_mid,
1634 .read_data_offset = smb2_read_data_offset,
1635 .read_data_length = smb2_read_data_length,
1636 .map_error = map_smb2_to_linux_error,
1637 .find_mid = smb2_find_mid,
1638 .check_message = smb2_check_message,
1639 .dump_detail = smb2_dump_detail,
1640 .clear_stats = smb2_clear_stats,
1641 .print_stats = smb2_print_stats,
Steve French769ee6a2013-06-19 14:15:30 -05001642 .dump_share_caps = smb2_dump_share_caps,
Steve French38107d42012-12-08 22:08:06 -06001643 .is_oplock_break = smb2_is_valid_oplock_break,
Sachin Prabhuc11f1df2014-03-11 16:11:47 +00001644 .downgrade_oplock = smb2_downgrade_oplock,
Steve French38107d42012-12-08 22:08:06 -06001645 .need_neg = smb2_need_neg,
1646 .negotiate = smb2_negotiate,
1647 .negotiate_wsize = smb2_negotiate_wsize,
1648 .negotiate_rsize = smb2_negotiate_rsize,
1649 .sess_setup = SMB2_sess_setup,
1650 .logoff = SMB2_logoff,
1651 .tree_connect = SMB2_tcon,
1652 .tree_disconnect = SMB2_tdis,
Steven Frenchaf6a12e2013-10-09 20:55:53 -05001653 .qfs_tcon = smb3_qfs_tcon,
Steve French38107d42012-12-08 22:08:06 -06001654 .is_path_accessible = smb2_is_path_accessible,
1655 .can_echo = smb2_can_echo,
1656 .echo = SMB2_echo,
1657 .query_path_info = smb2_query_path_info,
1658 .get_srv_inum = smb2_get_srv_inum,
1659 .query_file_info = smb2_query_file_info,
1660 .set_path_size = smb2_set_path_size,
1661 .set_file_size = smb2_set_file_size,
1662 .set_file_info = smb2_set_file_info,
Steve French64a5cfa2013-10-14 15:31:32 -05001663 .set_compression = smb2_set_compression,
Steve French38107d42012-12-08 22:08:06 -06001664 .mkdir = smb2_mkdir,
1665 .mkdir_setinfo = smb2_mkdir_setinfo,
1666 .rmdir = smb2_rmdir,
1667 .unlink = smb2_unlink,
1668 .rename = smb2_rename_path,
1669 .create_hardlink = smb2_create_hardlink,
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001670 .query_symlink = smb2_query_symlink,
Steve Frenchc22870e2014-09-16 07:18:19 -05001671 .query_mf_symlink = smb3_query_mf_symlink,
Steve French5ab97572014-09-15 04:49:28 -05001672 .create_mf_symlink = smb3_create_mf_symlink,
Steve French38107d42012-12-08 22:08:06 -06001673 .open = smb2_open_file,
1674 .set_fid = smb2_set_fid,
1675 .close = smb2_close_file,
1676 .flush = smb2_flush_file,
1677 .async_readv = smb2_async_readv,
1678 .async_writev = smb2_async_writev,
1679 .sync_read = smb2_sync_read,
1680 .sync_write = smb2_sync_write,
1681 .query_dir_first = smb2_query_dir_first,
1682 .query_dir_next = smb2_query_dir_next,
1683 .close_dir = smb2_close_dir,
1684 .calc_smb_size = smb2_calc_size,
1685 .is_status_pending = smb2_is_status_pending,
1686 .oplock_response = smb2_oplock_response,
1687 .queryfs = smb2_queryfs,
1688 .mand_lock = smb2_mand_lock,
1689 .mand_unlock_range = smb2_unlock_range,
1690 .push_mand_locks = smb2_push_mandatory_locks,
1691 .get_lease_key = smb2_get_lease_key,
1692 .set_lease_key = smb2_set_lease_key,
1693 .new_lease_key = smb2_new_lease_key,
Steve Frenche65a5cb2013-06-27 01:06:50 -05001694 .generate_signingkey = generate_smb3signingkey,
Steve French38107d42012-12-08 22:08:06 -06001695 .calc_signature = smb3_calc_signature,
Steve Frenchb3152e22015-06-24 03:17:02 -05001696 .set_integrity = smb3_set_integrity,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001697 .is_read_op = smb21_is_read_op,
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001698 .set_oplock_level = smb3_set_oplock_level,
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001699 .create_lease_buf = smb3_create_lease_buf,
1700 .parse_lease_buf = smb3_parse_lease_buf,
Steve French41c13582013-11-14 00:05:36 -06001701 .clone_range = smb2_clone_range,
Steve Frenchff1c0382013-11-19 23:44:46 -06001702 .validate_negotiate = smb3_validate_negotiate,
Pavel Shilovsky7f6c5002014-06-22 11:03:22 +04001703 .wp_retry_size = smb2_wp_retry_size,
Pavel Shilovsky52755802014-08-18 20:49:57 +04001704 .dir_needs_close = smb2_dir_needs_close,
Steve French31742c52014-08-17 08:38:47 -05001705 .fallocate = smb3_fallocate,
Steve French1080ef72011-02-24 18:07:19 +00001706};
1707
Steve Frenchaab18932015-06-23 23:37:11 -05001708#ifdef CONFIG_CIFS_SMB311
1709struct smb_version_operations smb311_operations = {
1710 .compare_fids = smb2_compare_fids,
1711 .setup_request = smb2_setup_request,
1712 .setup_async_request = smb2_setup_async_request,
1713 .check_receive = smb2_check_receive,
1714 .add_credits = smb2_add_credits,
1715 .set_credits = smb2_set_credits,
1716 .get_credits_field = smb2_get_credits_field,
1717 .get_credits = smb2_get_credits,
1718 .wait_mtu_credits = smb2_wait_mtu_credits,
1719 .get_next_mid = smb2_get_next_mid,
1720 .read_data_offset = smb2_read_data_offset,
1721 .read_data_length = smb2_read_data_length,
1722 .map_error = map_smb2_to_linux_error,
1723 .find_mid = smb2_find_mid,
1724 .check_message = smb2_check_message,
1725 .dump_detail = smb2_dump_detail,
1726 .clear_stats = smb2_clear_stats,
1727 .print_stats = smb2_print_stats,
1728 .dump_share_caps = smb2_dump_share_caps,
1729 .is_oplock_break = smb2_is_valid_oplock_break,
1730 .downgrade_oplock = smb2_downgrade_oplock,
1731 .need_neg = smb2_need_neg,
1732 .negotiate = smb2_negotiate,
1733 .negotiate_wsize = smb2_negotiate_wsize,
1734 .negotiate_rsize = smb2_negotiate_rsize,
1735 .sess_setup = SMB2_sess_setup,
1736 .logoff = SMB2_logoff,
1737 .tree_connect = SMB2_tcon,
1738 .tree_disconnect = SMB2_tdis,
1739 .qfs_tcon = smb3_qfs_tcon,
1740 .is_path_accessible = smb2_is_path_accessible,
1741 .can_echo = smb2_can_echo,
1742 .echo = SMB2_echo,
1743 .query_path_info = smb2_query_path_info,
1744 .get_srv_inum = smb2_get_srv_inum,
1745 .query_file_info = smb2_query_file_info,
1746 .set_path_size = smb2_set_path_size,
1747 .set_file_size = smb2_set_file_size,
1748 .set_file_info = smb2_set_file_info,
1749 .set_compression = smb2_set_compression,
1750 .mkdir = smb2_mkdir,
1751 .mkdir_setinfo = smb2_mkdir_setinfo,
1752 .rmdir = smb2_rmdir,
1753 .unlink = smb2_unlink,
1754 .rename = smb2_rename_path,
1755 .create_hardlink = smb2_create_hardlink,
1756 .query_symlink = smb2_query_symlink,
1757 .query_mf_symlink = smb3_query_mf_symlink,
1758 .create_mf_symlink = smb3_create_mf_symlink,
1759 .open = smb2_open_file,
1760 .set_fid = smb2_set_fid,
1761 .close = smb2_close_file,
1762 .flush = smb2_flush_file,
1763 .async_readv = smb2_async_readv,
1764 .async_writev = smb2_async_writev,
1765 .sync_read = smb2_sync_read,
1766 .sync_write = smb2_sync_write,
1767 .query_dir_first = smb2_query_dir_first,
1768 .query_dir_next = smb2_query_dir_next,
1769 .close_dir = smb2_close_dir,
1770 .calc_smb_size = smb2_calc_size,
1771 .is_status_pending = smb2_is_status_pending,
1772 .oplock_response = smb2_oplock_response,
1773 .queryfs = smb2_queryfs,
1774 .mand_lock = smb2_mand_lock,
1775 .mand_unlock_range = smb2_unlock_range,
1776 .push_mand_locks = smb2_push_mandatory_locks,
1777 .get_lease_key = smb2_get_lease_key,
1778 .set_lease_key = smb2_set_lease_key,
1779 .new_lease_key = smb2_new_lease_key,
1780 .generate_signingkey = generate_smb3signingkey,
1781 .calc_signature = smb3_calc_signature,
Steve Frenchb3152e22015-06-24 03:17:02 -05001782 .set_integrity = smb3_set_integrity,
Steve Frenchaab18932015-06-23 23:37:11 -05001783 .is_read_op = smb21_is_read_op,
1784 .set_oplock_level = smb3_set_oplock_level,
1785 .create_lease_buf = smb3_create_lease_buf,
1786 .parse_lease_buf = smb3_parse_lease_buf,
1787 .clone_range = smb2_clone_range,
Steve French02b16662015-06-27 21:18:36 -07001788 .duplicate_extents = smb2_duplicate_extents,
Steve Frenchaab18932015-06-23 23:37:11 -05001789/* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
1790 .wp_retry_size = smb2_wp_retry_size,
1791 .dir_needs_close = smb2_dir_needs_close,
1792 .fallocate = smb3_fallocate,
1793};
1794#endif /* CIFS_SMB311 */
1795
Steve Frenchdd446b12012-11-28 23:21:06 -06001796struct smb_version_values smb20_values = {
1797 .version_string = SMB20_VERSION_STRING,
1798 .protocol_id = SMB20_PROT_ID,
1799 .req_capabilities = 0, /* MBZ */
1800 .large_lock_type = 0,
1801 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1802 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1803 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
1804 .header_size = sizeof(struct smb2_hdr),
1805 .max_header_size = MAX_SMB2_HDR_SIZE,
1806 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
1807 .lock_cmd = SMB2_LOCK,
1808 .cap_unix = 0,
1809 .cap_nt_find = SMB2_NT_FIND,
1810 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton50285882013-06-27 12:45:00 -04001811 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1812 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001813 .create_lease_size = sizeof(struct create_lease),
Steve Frenchdd446b12012-11-28 23:21:06 -06001814};
1815
Steve French1080ef72011-02-24 18:07:19 +00001816struct smb_version_values smb21_values = {
1817 .version_string = SMB21_VERSION_STRING,
Steve Frenche4aa25e2012-10-01 12:26:22 -05001818 .protocol_id = SMB21_PROT_ID,
1819 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
1820 .large_lock_type = 0,
1821 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1822 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1823 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
1824 .header_size = sizeof(struct smb2_hdr),
1825 .max_header_size = MAX_SMB2_HDR_SIZE,
1826 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
1827 .lock_cmd = SMB2_LOCK,
1828 .cap_unix = 0,
1829 .cap_nt_find = SMB2_NT_FIND,
1830 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton50285882013-06-27 12:45:00 -04001831 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1832 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001833 .create_lease_size = sizeof(struct create_lease),
Steve Frenche4aa25e2012-10-01 12:26:22 -05001834};
1835
1836struct smb_version_values smb30_values = {
1837 .version_string = SMB30_VERSION_STRING,
1838 .protocol_id = SMB30_PROT_ID,
1839 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU,
Pavel Shilovsky027e8ee2012-09-19 06:22:43 -07001840 .large_lock_type = 0,
1841 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1842 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1843 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +04001844 .header_size = sizeof(struct smb2_hdr),
1845 .max_header_size = MAX_SMB2_HDR_SIZE,
Pavel Shilovsky09a47072012-09-18 16:20:29 -07001846 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +04001847 .lock_cmd = SMB2_LOCK,
Pavel Shilovsky29e20f92012-07-13 13:58:14 +04001848 .cap_unix = 0,
1849 .cap_nt_find = SMB2_NT_FIND,
1850 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton50285882013-06-27 12:45:00 -04001851 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1852 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001853 .create_lease_size = sizeof(struct create_lease_v2),
Steve French1080ef72011-02-24 18:07:19 +00001854};
Steve French20b6d8b2013-06-12 22:48:41 -05001855
1856struct smb_version_values smb302_values = {
1857 .version_string = SMB302_VERSION_STRING,
1858 .protocol_id = SMB302_PROT_ID,
1859 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU,
1860 .large_lock_type = 0,
1861 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1862 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1863 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
1864 .header_size = sizeof(struct smb2_hdr),
1865 .max_header_size = MAX_SMB2_HDR_SIZE,
1866 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
1867 .lock_cmd = SMB2_LOCK,
1868 .cap_unix = 0,
1869 .cap_nt_find = SMB2_NT_FIND,
1870 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton50285882013-06-27 12:45:00 -04001871 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1872 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001873 .create_lease_size = sizeof(struct create_lease_v2),
Steve French20b6d8b2013-06-12 22:48:41 -05001874};
Steve French5f7fbf72014-12-17 22:52:58 -06001875
1876#ifdef CONFIG_CIFS_SMB311
1877struct smb_version_values smb311_values = {
1878 .version_string = SMB311_VERSION_STRING,
1879 .protocol_id = SMB311_PROT_ID,
1880 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU,
1881 .large_lock_type = 0,
1882 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1883 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1884 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
1885 .header_size = sizeof(struct smb2_hdr),
1886 .max_header_size = MAX_SMB2_HDR_SIZE,
1887 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
1888 .lock_cmd = SMB2_LOCK,
1889 .cap_unix = 0,
1890 .cap_nt_find = SMB2_NT_FIND,
1891 .cap_large_files = SMB2_LARGE_FILES,
1892 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1893 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
1894 .create_lease_size = sizeof(struct create_lease_v2),
1895};
1896#endif /* SMB311 */