blob: c571be8cb76ef418ffcca63634fde5e3d39294f5 [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 French1080ef72011-02-24 18:07:19 +000022#include "cifsglob.h"
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +040023#include "smb2pdu.h"
24#include "smb2proto.h"
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040025#include "cifsproto.h"
26#include "cifs_debug.h"
Pavel Shilovskyb42bf882013-08-14 19:25:21 +040027#include "cifs_unicode.h"
Pavel Shilovsky2e44b282012-09-18 16:20:33 -070028#include "smb2status.h"
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -070029#include "smb2glob.h"
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040030
31static int
32change_conf(struct TCP_Server_Info *server)
33{
34 server->credits += server->echo_credits + server->oplock_credits;
35 server->oplock_credits = server->echo_credits = 0;
36 switch (server->credits) {
37 case 0:
38 return -1;
39 case 1:
40 server->echoes = false;
41 server->oplocks = false;
Joe Perchesf96637b2013-05-04 22:12:25 -050042 cifs_dbg(VFS, "disabling echoes and oplocks\n");
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040043 break;
44 case 2:
45 server->echoes = true;
46 server->oplocks = false;
47 server->echo_credits = 1;
Joe Perchesf96637b2013-05-04 22:12:25 -050048 cifs_dbg(FYI, "disabling oplocks\n");
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040049 break;
50 default:
51 server->echoes = true;
52 server->oplocks = true;
53 server->echo_credits = 1;
54 server->oplock_credits = 1;
55 }
56 server->credits -= server->echo_credits + server->oplock_credits;
57 return 0;
58}
59
60static void
61smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add,
62 const int optype)
63{
64 int *val, rc = 0;
65 spin_lock(&server->req_lock);
66 val = server->ops->get_credits_field(server, optype);
67 *val += add;
68 server->in_flight--;
Pavel Shilovskyec2e4522011-12-27 16:12:43 +040069 if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP)
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040070 rc = change_conf(server);
Pavel Shilovsky983c88a2012-09-18 16:20:33 -070071 /*
72 * Sometimes server returns 0 credits on oplock break ack - we need to
73 * rebalance credits in this case.
74 */
75 else if (server->in_flight > 0 && server->oplock_credits == 0 &&
76 server->oplocks) {
77 if (server->credits > 1) {
78 server->credits--;
79 server->oplock_credits++;
80 }
81 }
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040082 spin_unlock(&server->req_lock);
83 wake_up(&server->request_q);
84 if (rc)
85 cifs_reconnect(server);
86}
87
88static void
89smb2_set_credits(struct TCP_Server_Info *server, const int val)
90{
91 spin_lock(&server->req_lock);
92 server->credits = val;
93 spin_unlock(&server->req_lock);
94}
95
96static int *
97smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
98{
99 switch (optype) {
100 case CIFS_ECHO_OP:
101 return &server->echo_credits;
102 case CIFS_OBREAK_OP:
103 return &server->oplock_credits;
104 default:
105 return &server->credits;
106 }
107}
108
109static unsigned int
110smb2_get_credits(struct mid_q_entry *mid)
111{
112 return le16_to_cpu(((struct smb2_hdr *)mid->resp_buf)->CreditRequest);
113}
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +0400114
115static __u64
116smb2_get_next_mid(struct TCP_Server_Info *server)
117{
118 __u64 mid;
119 /* for SMB2 we need the current value */
120 spin_lock(&GlobalMid_Lock);
121 mid = server->CurrentMid++;
122 spin_unlock(&GlobalMid_Lock);
123 return mid;
124}
Steve French1080ef72011-02-24 18:07:19 +0000125
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400126static struct mid_q_entry *
127smb2_find_mid(struct TCP_Server_Info *server, char *buf)
128{
129 struct mid_q_entry *mid;
130 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
131
132 spin_lock(&GlobalMid_Lock);
133 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
134 if ((mid->mid == hdr->MessageId) &&
135 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
136 (mid->command == hdr->Command)) {
137 spin_unlock(&GlobalMid_Lock);
138 return mid;
139 }
140 }
141 spin_unlock(&GlobalMid_Lock);
142 return NULL;
143}
144
145static void
146smb2_dump_detail(void *buf)
147{
148#ifdef CONFIG_CIFS_DEBUG2
149 struct smb2_hdr *smb = (struct smb2_hdr *)buf;
150
Joe Perchesf96637b2013-05-04 22:12:25 -0500151 cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
152 smb->Command, smb->Status, smb->Flags, smb->MessageId,
153 smb->ProcessId);
154 cifs_dbg(VFS, "smb buf %p len %u\n", smb, smb2_calc_size(smb));
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400155#endif
156}
157
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400158static bool
159smb2_need_neg(struct TCP_Server_Info *server)
160{
161 return server->max_read == 0;
162}
163
164static int
165smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
166{
167 int rc;
168 ses->server->CurrentMid = 0;
169 rc = SMB2_negotiate(xid, ses);
170 /* BB we probably don't need to retry with modern servers */
171 if (rc == -EAGAIN)
172 rc = -EHOSTDOWN;
173 return rc;
174}
175
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700176static unsigned int
177smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
178{
179 struct TCP_Server_Info *server = tcon->ses->server;
180 unsigned int wsize;
181
182 /* start with specified wsize, or default */
183 wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
184 wsize = min_t(unsigned int, wsize, server->max_write);
185 /*
186 * limit write size to 2 ** 16, because we don't support multicredit
187 * requests now.
188 */
189 wsize = min_t(unsigned int, wsize, 2 << 15);
190
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700191 return wsize;
192}
193
194static unsigned int
195smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
196{
197 struct TCP_Server_Info *server = tcon->ses->server;
198 unsigned int rsize;
199
200 /* start with specified rsize, or default */
201 rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
202 rsize = min_t(unsigned int, rsize, server->max_read);
203 /*
204 * limit write size to 2 ** 16, because we don't support multicredit
205 * requests now.
206 */
207 rsize = min_t(unsigned int, rsize, 2 << 15);
208
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700209 return rsize;
210}
211
Steve Frenchc481e9f2013-10-14 01:21:53 -0500212#ifdef CONFIG_CIFS_STATS2
213static int
214SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon)
215{
216 int rc;
217 unsigned int ret_data_len = 0;
218 struct network_interface_info_ioctl_rsp *out_buf;
219
220 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
221 FSCTL_QUERY_NETWORK_INTERFACE_INFO, true /* is_fsctl */,
222 NULL /* no data input */, 0 /* no data input */,
223 (char **)&out_buf, &ret_data_len);
224
225 if ((rc == 0) && (ret_data_len > 0)) {
226 /* Dump info on first interface */
227 cifs_dbg(FYI, "Adapter Capability 0x%x\t",
228 le32_to_cpu(out_buf->Capability));
229 cifs_dbg(FYI, "Link Speed %lld\n",
230 le64_to_cpu(out_buf->LinkSpeed));
231 } else
232 cifs_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
233
234 return rc;
235}
236#endif /* STATS2 */
237
Steve French34f62642013-10-09 02:07:00 -0500238static void
Steven Frenchaf6a12e2013-10-09 20:55:53 -0500239smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
240{
241 int rc;
242 __le16 srch_path = 0; /* Null - open root of share */
243 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
244 struct cifs_open_parms oparms;
245 struct cifs_fid fid;
246
247 oparms.tcon = tcon;
248 oparms.desired_access = FILE_READ_ATTRIBUTES;
249 oparms.disposition = FILE_OPEN;
250 oparms.create_options = 0;
251 oparms.fid = &fid;
252 oparms.reconnect = false;
253
254 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
255 if (rc)
256 return;
257
Steve Frenchc481e9f2013-10-14 01:21:53 -0500258#ifdef CONFIG_CIFS_STATS2
259 SMB3_request_interfaces(xid, tcon);
260#endif /* STATS2 */
261
Steven Frenchaf6a12e2013-10-09 20:55:53 -0500262 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
263 FS_ATTRIBUTE_INFORMATION);
264 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
265 FS_DEVICE_INFORMATION);
266 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
267 FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
268 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
269 return;
270}
271
272static void
Steve French34f62642013-10-09 02:07:00 -0500273smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
274{
275 int rc;
276 __le16 srch_path = 0; /* Null - open root of share */
277 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
278 struct cifs_open_parms oparms;
279 struct cifs_fid fid;
280
281 oparms.tcon = tcon;
282 oparms.desired_access = FILE_READ_ATTRIBUTES;
283 oparms.disposition = FILE_OPEN;
284 oparms.create_options = 0;
285 oparms.fid = &fid;
286 oparms.reconnect = false;
287
288 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
289 if (rc)
290 return;
291
Steven French21671142013-10-09 13:36:35 -0500292 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
293 FS_ATTRIBUTE_INFORMATION);
294 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
295 FS_DEVICE_INFORMATION);
Steve French34f62642013-10-09 02:07:00 -0500296 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
297 return;
298}
299
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400300static int
301smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
302 struct cifs_sb_info *cifs_sb, const char *full_path)
303{
304 int rc;
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400305 __le16 *utf16_path;
Pavel Shilovsky2e44b282012-09-18 16:20:33 -0700306 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400307 struct cifs_open_parms oparms;
308 struct cifs_fid fid;
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400309
310 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
311 if (!utf16_path)
312 return -ENOMEM;
313
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400314 oparms.tcon = tcon;
315 oparms.desired_access = FILE_READ_ATTRIBUTES;
316 oparms.disposition = FILE_OPEN;
317 oparms.create_options = 0;
318 oparms.fid = &fid;
Pavel Shilovsky9cbc0b72013-07-09 18:40:58 +0400319 oparms.reconnect = false;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400320
Pavel Shilovskyb42bf882013-08-14 19:25:21 +0400321 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400322 if (rc) {
323 kfree(utf16_path);
324 return rc;
325 }
326
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400327 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400328 kfree(utf16_path);
329 return rc;
330}
331
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +0400332static int
333smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
334 struct cifs_sb_info *cifs_sb, const char *full_path,
335 u64 *uniqueid, FILE_ALL_INFO *data)
336{
337 *uniqueid = le64_to_cpu(data->IndexNumber);
338 return 0;
339}
340
Pavel Shilovskyb7546bc2012-09-18 16:20:27 -0700341static int
342smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
343 struct cifs_fid *fid, FILE_ALL_INFO *data)
344{
345 int rc;
346 struct smb2_file_all_info *smb2_data;
347
348 smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + MAX_NAME * 2,
349 GFP_KERNEL);
350 if (smb2_data == NULL)
351 return -ENOMEM;
352
353 rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
354 smb2_data);
355 if (!rc)
356 move_smb2_info_to_cifs(data, smb2_data);
357 kfree(smb2_data);
358 return rc;
359}
360
Pavel Shilovsky9094fad2012-07-12 18:30:44 +0400361static bool
362smb2_can_echo(struct TCP_Server_Info *server)
363{
364 return server->echoes;
365}
366
Pavel Shilovskyd60622e2012-05-28 15:19:39 +0400367static void
368smb2_clear_stats(struct cifs_tcon *tcon)
369{
370#ifdef CONFIG_CIFS_STATS
371 int i;
372 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
373 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
374 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
375 }
376#endif
377}
378
379static void
Steve French769ee6a2013-06-19 14:15:30 -0500380smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
381{
382 seq_puts(m, "\n\tShare Capabilities:");
383 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
384 seq_puts(m, " DFS,");
385 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
386 seq_puts(m, " CONTINUOUS AVAILABILITY,");
387 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
388 seq_puts(m, " SCALEOUT,");
389 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
390 seq_puts(m, " CLUSTER,");
391 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
392 seq_puts(m, " ASYMMETRIC,");
393 if (tcon->capabilities == 0)
394 seq_puts(m, " None");
Steven Frenchaf6a12e2013-10-09 20:55:53 -0500395 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
396 seq_puts(m, " Aligned,");
397 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
398 seq_puts(m, " Partition Aligned,");
399 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
400 seq_puts(m, " SSD,");
401 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
402 seq_puts(m, " TRIM-support,");
403
Steve French769ee6a2013-06-19 14:15:30 -0500404 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
Steven Frenchaf6a12e2013-10-09 20:55:53 -0500405 if (tcon->perf_sector_size)
406 seq_printf(m, "\tOptimal sector size: 0x%x",
407 tcon->perf_sector_size);
Steve French769ee6a2013-06-19 14:15:30 -0500408}
409
410static void
Pavel Shilovskyd60622e2012-05-28 15:19:39 +0400411smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
412{
413#ifdef CONFIG_CIFS_STATS
414 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
415 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
416 seq_printf(m, "\nNegotiates: %d sent %d failed",
417 atomic_read(&sent[SMB2_NEGOTIATE_HE]),
418 atomic_read(&failed[SMB2_NEGOTIATE_HE]));
419 seq_printf(m, "\nSessionSetups: %d sent %d failed",
420 atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
421 atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
Pavel Shilovskyd60622e2012-05-28 15:19:39 +0400422 seq_printf(m, "\nLogoffs: %d sent %d failed",
423 atomic_read(&sent[SMB2_LOGOFF_HE]),
424 atomic_read(&failed[SMB2_LOGOFF_HE]));
425 seq_printf(m, "\nTreeConnects: %d sent %d failed",
426 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
427 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
428 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
429 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
430 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
431 seq_printf(m, "\nCreates: %d sent %d failed",
432 atomic_read(&sent[SMB2_CREATE_HE]),
433 atomic_read(&failed[SMB2_CREATE_HE]));
434 seq_printf(m, "\nCloses: %d sent %d failed",
435 atomic_read(&sent[SMB2_CLOSE_HE]),
436 atomic_read(&failed[SMB2_CLOSE_HE]));
437 seq_printf(m, "\nFlushes: %d sent %d failed",
438 atomic_read(&sent[SMB2_FLUSH_HE]),
439 atomic_read(&failed[SMB2_FLUSH_HE]));
440 seq_printf(m, "\nReads: %d sent %d failed",
441 atomic_read(&sent[SMB2_READ_HE]),
442 atomic_read(&failed[SMB2_READ_HE]));
443 seq_printf(m, "\nWrites: %d sent %d failed",
444 atomic_read(&sent[SMB2_WRITE_HE]),
445 atomic_read(&failed[SMB2_WRITE_HE]));
446 seq_printf(m, "\nLocks: %d sent %d failed",
447 atomic_read(&sent[SMB2_LOCK_HE]),
448 atomic_read(&failed[SMB2_LOCK_HE]));
449 seq_printf(m, "\nIOCTLs: %d sent %d failed",
450 atomic_read(&sent[SMB2_IOCTL_HE]),
451 atomic_read(&failed[SMB2_IOCTL_HE]));
452 seq_printf(m, "\nCancels: %d sent %d failed",
453 atomic_read(&sent[SMB2_CANCEL_HE]),
454 atomic_read(&failed[SMB2_CANCEL_HE]));
455 seq_printf(m, "\nEchos: %d sent %d failed",
456 atomic_read(&sent[SMB2_ECHO_HE]),
457 atomic_read(&failed[SMB2_ECHO_HE]));
458 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
459 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
460 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
461 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
462 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
463 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
464 seq_printf(m, "\nQueryInfos: %d sent %d failed",
465 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
466 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
467 seq_printf(m, "\nSetInfos: %d sent %d failed",
468 atomic_read(&sent[SMB2_SET_INFO_HE]),
469 atomic_read(&failed[SMB2_SET_INFO_HE]));
470 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
471 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
472 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
473#endif
474}
475
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700476static void
477smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
478{
Pavel Shilovsky2e44b282012-09-18 16:20:33 -0700479 struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);
Pavel Shilovsky53ef1012013-09-05 16:11:28 +0400480 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
481
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700482 cfile->fid.persistent_fid = fid->persistent_fid;
483 cfile->fid.volatile_fid = fid->volatile_fid;
Pavel Shilovsky42873b02013-09-05 21:30:16 +0400484 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
485 &fid->purge_cache);
Pavel Shilovsky18cceb62013-09-05 13:01:06 +0400486 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700487}
488
Pavel Shilovsky760ad0c2012-09-25 11:00:07 +0400489static void
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700490smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
491 struct cifs_fid *fid)
492{
Pavel Shilovsky760ad0c2012-09-25 11:00:07 +0400493 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700494}
495
Pavel Shilovsky7a5cfb12012-09-18 16:20:28 -0700496static int
497smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
498 struct cifs_fid *fid)
499{
500 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
501}
502
Pavel Shilovsky09a47072012-09-18 16:20:29 -0700503static unsigned int
504smb2_read_data_offset(char *buf)
505{
506 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
507 return rsp->DataOffset;
508}
509
510static unsigned int
511smb2_read_data_length(char *buf)
512{
513 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
514 return le32_to_cpu(rsp->DataLength);
515}
516
Pavel Shilovskyd8e05032012-09-18 16:20:30 -0700517
518static int
519smb2_sync_read(const unsigned int xid, struct cifsFileInfo *cfile,
520 struct cifs_io_parms *parms, unsigned int *bytes_read,
521 char **buf, int *buf_type)
522{
523 parms->persistent_fid = cfile->fid.persistent_fid;
524 parms->volatile_fid = cfile->fid.volatile_fid;
525 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
526}
527
Pavel Shilovsky009d3442012-09-18 16:20:30 -0700528static int
529smb2_sync_write(const unsigned int xid, struct cifsFileInfo *cfile,
530 struct cifs_io_parms *parms, unsigned int *written,
531 struct kvec *iov, unsigned long nr_segs)
532{
533
534 parms->persistent_fid = cfile->fid.persistent_fid;
535 parms->volatile_fid = cfile->fid.volatile_fid;
536 return SMB2_write(xid, parms, written, iov, nr_segs);
537}
538
Pavel Shilovskyc839ff22012-09-18 16:20:32 -0700539static int
540smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
541 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
542{
543 __le64 eof = cpu_to_le64(size);
544 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
545 cfile->fid.volatile_fid, cfile->pid, &eof);
546}
547
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700548static int
Steve French64a5cfa2013-10-14 15:31:32 -0500549smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
550 struct cifsFileInfo *cfile)
551{
552 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
553 cfile->fid.volatile_fid);
554}
555
556static int
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700557smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
558 const char *path, struct cifs_sb_info *cifs_sb,
559 struct cifs_fid *fid, __u16 search_flags,
560 struct cifs_search_info *srch_inf)
561{
562 __le16 *utf16_path;
563 int rc;
Pavel Shilovsky2e44b282012-09-18 16:20:33 -0700564 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400565 struct cifs_open_parms oparms;
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700566
567 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
568 if (!utf16_path)
569 return -ENOMEM;
570
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400571 oparms.tcon = tcon;
572 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
573 oparms.disposition = FILE_OPEN;
574 oparms.create_options = 0;
575 oparms.fid = fid;
Pavel Shilovsky9cbc0b72013-07-09 18:40:58 +0400576 oparms.reconnect = false;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400577
Pavel Shilovskyb42bf882013-08-14 19:25:21 +0400578 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700579 kfree(utf16_path);
580 if (rc) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500581 cifs_dbg(VFS, "open dir failed\n");
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700582 return rc;
583 }
584
585 srch_inf->entries_in_buffer = 0;
586 srch_inf->index_of_last_entry = 0;
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700587
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400588 rc = SMB2_query_directory(xid, tcon, fid->persistent_fid,
589 fid->volatile_fid, 0, srch_inf);
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700590 if (rc) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500591 cifs_dbg(VFS, "query directory failed\n");
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400592 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700593 }
594 return rc;
595}
596
597static int
598smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
599 struct cifs_fid *fid, __u16 search_flags,
600 struct cifs_search_info *srch_inf)
601{
602 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
603 fid->volatile_fid, 0, srch_inf);
604}
605
606static int
607smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
608 struct cifs_fid *fid)
609{
610 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
611}
612
Pavel Shilovsky2e44b282012-09-18 16:20:33 -0700613/*
614* If we negotiate SMB2 protocol and get STATUS_PENDING - update
615* the number of credits and return true. Otherwise - return false.
616*/
617static bool
618smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
619{
620 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
621
Steve French12e8a202012-09-19 09:19:39 -0700622 if (hdr->Status != STATUS_PENDING)
Pavel Shilovsky2e44b282012-09-18 16:20:33 -0700623 return false;
624
625 if (!length) {
626 spin_lock(&server->req_lock);
627 server->credits += le16_to_cpu(hdr->CreditRequest);
628 spin_unlock(&server->req_lock);
629 wake_up(&server->request_q);
630 }
631
632 return true;
633}
634
Pavel Shilovsky983c88a2012-09-18 16:20:33 -0700635static int
636smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
637 struct cifsInodeInfo *cinode)
638{
Pavel Shilovsky0822f512012-09-19 06:22:45 -0700639 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
640 return SMB2_lease_break(0, tcon, cinode->lease_key,
641 smb2_get_lease_state(cinode));
642
Pavel Shilovsky983c88a2012-09-18 16:20:33 -0700643 return SMB2_oplock_break(0, tcon, fid->persistent_fid,
644 fid->volatile_fid,
Pavel Shilovsky18cceb62013-09-05 13:01:06 +0400645 CIFS_CACHE_READ(cinode) ? 1 : 0);
Pavel Shilovsky983c88a2012-09-18 16:20:33 -0700646}
647
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -0700648static int
649smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
650 struct kstatfs *buf)
651{
652 int rc;
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -0700653 __le16 srch_path = 0; /* Null - open root of share */
654 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400655 struct cifs_open_parms oparms;
656 struct cifs_fid fid;
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -0700657
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400658 oparms.tcon = tcon;
659 oparms.desired_access = FILE_READ_ATTRIBUTES;
660 oparms.disposition = FILE_OPEN;
661 oparms.create_options = 0;
662 oparms.fid = &fid;
Pavel Shilovsky9cbc0b72013-07-09 18:40:58 +0400663 oparms.reconnect = false;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400664
Pavel Shilovskyb42bf882013-08-14 19:25:21 +0400665 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -0700666 if (rc)
667 return rc;
668 buf->f_type = SMB2_MAGIC_NUMBER;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400669 rc = SMB2_QFS_info(xid, tcon, fid.persistent_fid, fid.volatile_fid,
670 buf);
671 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -0700672 return rc;
673}
674
Pavel Shilovsky027e8ee2012-09-19 06:22:43 -0700675static bool
676smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
677{
678 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
679 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
680}
681
Pavel Shilovskyf7ba7fe2012-09-19 06:22:43 -0700682static int
683smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
684 __u64 length, __u32 type, int lock, int unlock, bool wait)
685{
686 if (unlock && !lock)
687 type = SMB2_LOCKFLAG_UNLOCK;
688 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
689 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
690 current->tgid, length, offset, type, wait);
691}
692
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700693static void
694smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
695{
696 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
697}
698
699static void
700smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
701{
702 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
703}
704
705static void
706smb2_new_lease_key(struct cifs_fid *fid)
707{
708 get_random_bytes(fid->lease_key, SMB2_LEASE_KEY_SIZE);
709}
710
Pavel Shilovskyb42bf882013-08-14 19:25:21 +0400711static int
712smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
713 const char *full_path, char **target_path,
714 struct cifs_sb_info *cifs_sb)
715{
716 int rc;
717 __le16 *utf16_path;
718 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
719 struct cifs_open_parms oparms;
720 struct cifs_fid fid;
721 struct smb2_err_rsp *err_buf = NULL;
722 struct smb2_symlink_err_rsp *symlink;
723 unsigned int sub_len, sub_offset;
724
725 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
726
727 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
728 if (!utf16_path)
729 return -ENOMEM;
730
731 oparms.tcon = tcon;
732 oparms.desired_access = FILE_READ_ATTRIBUTES;
733 oparms.disposition = FILE_OPEN;
734 oparms.create_options = 0;
735 oparms.fid = &fid;
736 oparms.reconnect = false;
737
738 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_buf);
739
740 if (!rc || !err_buf) {
741 kfree(utf16_path);
742 return -ENOENT;
743 }
744 /* open must fail on symlink - reset rc */
745 rc = 0;
746 symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
747 sub_len = le16_to_cpu(symlink->SubstituteNameLength);
748 sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
749 *target_path = cifs_strndup_from_utf16(
750 (char *)symlink->PathBuffer + sub_offset,
751 sub_len, true, cifs_sb->local_nls);
752 if (!(*target_path)) {
753 kfree(utf16_path);
754 return -ENOMEM;
755 }
756 convert_delimiter(*target_path, '/');
757 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
758 kfree(utf16_path);
759 return rc;
760}
761
Pavel Shilovsky53ef1012013-09-05 16:11:28 +0400762static void
Pavel Shilovsky42873b02013-09-05 21:30:16 +0400763smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
764 unsigned int epoch, bool *purge_cache)
Pavel Shilovsky53ef1012013-09-05 16:11:28 +0400765{
766 oplock &= 0xFF;
767 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
768 return;
769 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
Pavel Shilovsky42873b02013-09-05 21:30:16 +0400770 cinode->oplock = CIFS_CACHE_RHW_FLG;
Pavel Shilovsky53ef1012013-09-05 16:11:28 +0400771 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
772 &cinode->vfs_inode);
773 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
Pavel Shilovsky42873b02013-09-05 21:30:16 +0400774 cinode->oplock = CIFS_CACHE_RW_FLG;
Pavel Shilovsky53ef1012013-09-05 16:11:28 +0400775 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
776 &cinode->vfs_inode);
777 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
778 cinode->oplock = CIFS_CACHE_READ_FLG;
779 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
780 &cinode->vfs_inode);
781 } else
782 cinode->oplock = 0;
783}
784
785static void
Pavel Shilovsky42873b02013-09-05 21:30:16 +0400786smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
787 unsigned int epoch, bool *purge_cache)
Pavel Shilovsky53ef1012013-09-05 16:11:28 +0400788{
789 char message[5] = {0};
790
791 oplock &= 0xFF;
792 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
793 return;
794
795 cinode->oplock = 0;
796 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
797 cinode->oplock |= CIFS_CACHE_READ_FLG;
798 strcat(message, "R");
799 }
800 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
801 cinode->oplock |= CIFS_CACHE_HANDLE_FLG;
802 strcat(message, "H");
803 }
804 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
805 cinode->oplock |= CIFS_CACHE_WRITE_FLG;
806 strcat(message, "W");
807 }
808 if (!cinode->oplock)
809 strcat(message, "None");
810 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
811 &cinode->vfs_inode);
812}
813
Pavel Shilovsky42873b02013-09-05 21:30:16 +0400814static void
815smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
816 unsigned int epoch, bool *purge_cache)
817{
818 unsigned int old_oplock = cinode->oplock;
819
820 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
821
822 if (purge_cache) {
823 *purge_cache = false;
824 if (old_oplock == CIFS_CACHE_READ_FLG) {
825 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
826 (epoch - cinode->epoch > 0))
827 *purge_cache = true;
828 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
829 (epoch - cinode->epoch > 1))
830 *purge_cache = true;
831 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
832 (epoch - cinode->epoch > 1))
833 *purge_cache = true;
834 else if (cinode->oplock == 0 &&
835 (epoch - cinode->epoch > 0))
836 *purge_cache = true;
837 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
838 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
839 (epoch - cinode->epoch > 0))
840 *purge_cache = true;
841 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
842 (epoch - cinode->epoch > 1))
843 *purge_cache = true;
844 }
845 cinode->epoch = epoch;
846 }
847}
848
Pavel Shilovsky53ef1012013-09-05 16:11:28 +0400849static bool
850smb2_is_read_op(__u32 oplock)
851{
852 return oplock == SMB2_OPLOCK_LEVEL_II;
853}
854
855static bool
856smb21_is_read_op(__u32 oplock)
857{
858 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
859 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
860}
861
Pavel Shilovskyf0473902013-09-04 13:44:05 +0400862static __le32
863map_oplock_to_lease(u8 oplock)
864{
865 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
866 return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
867 else if (oplock == SMB2_OPLOCK_LEVEL_II)
868 return SMB2_LEASE_READ_CACHING;
869 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
870 return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING |
871 SMB2_LEASE_WRITE_CACHING;
872 return 0;
873}
874
Pavel Shilovskya41a28b2013-09-04 13:07:41 +0400875static char *
876smb2_create_lease_buf(u8 *lease_key, u8 oplock)
877{
878 struct create_lease *buf;
879
880 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
881 if (!buf)
882 return NULL;
883
884 buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
885 buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
Pavel Shilovskyf0473902013-09-04 13:44:05 +0400886 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
Pavel Shilovskya41a28b2013-09-04 13:07:41 +0400887
888 buf->ccontext.DataOffset = cpu_to_le16(offsetof
889 (struct create_lease, lcontext));
890 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
891 buf->ccontext.NameOffset = cpu_to_le16(offsetof
892 (struct create_lease, Name));
893 buf->ccontext.NameLength = cpu_to_le16(4);
894 buf->Name[0] = 'R';
895 buf->Name[1] = 'q';
896 buf->Name[2] = 'L';
897 buf->Name[3] = 's';
898 return (char *)buf;
899}
900
Pavel Shilovskyf0473902013-09-04 13:44:05 +0400901static char *
902smb3_create_lease_buf(u8 *lease_key, u8 oplock)
903{
904 struct create_lease_v2 *buf;
905
906 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
907 if (!buf)
908 return NULL;
909
910 buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
911 buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
912 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
913
914 buf->ccontext.DataOffset = cpu_to_le16(offsetof
915 (struct create_lease_v2, lcontext));
916 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
917 buf->ccontext.NameOffset = cpu_to_le16(offsetof
918 (struct create_lease_v2, Name));
919 buf->ccontext.NameLength = cpu_to_le16(4);
920 buf->Name[0] = 'R';
921 buf->Name[1] = 'q';
922 buf->Name[2] = 'L';
923 buf->Name[3] = 's';
924 return (char *)buf;
925}
926
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +0400927static __u8
Pavel Shilovsky42873b02013-09-05 21:30:16 +0400928smb2_parse_lease_buf(void *buf, unsigned int *epoch)
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +0400929{
930 struct create_lease *lc = (struct create_lease *)buf;
931
Pavel Shilovsky42873b02013-09-05 21:30:16 +0400932 *epoch = 0; /* not used */
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +0400933 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
934 return SMB2_OPLOCK_LEVEL_NOCHANGE;
935 return le32_to_cpu(lc->lcontext.LeaseState);
936}
937
Pavel Shilovskyf0473902013-09-04 13:44:05 +0400938static __u8
Pavel Shilovsky42873b02013-09-05 21:30:16 +0400939smb3_parse_lease_buf(void *buf, unsigned int *epoch)
Pavel Shilovskyf0473902013-09-04 13:44:05 +0400940{
941 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
942
Pavel Shilovsky42873b02013-09-05 21:30:16 +0400943 *epoch = le16_to_cpu(lc->lcontext.Epoch);
Pavel Shilovskyf0473902013-09-04 13:44:05 +0400944 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
945 return SMB2_OPLOCK_LEVEL_NOCHANGE;
946 return le32_to_cpu(lc->lcontext.LeaseState);
947}
948
Pavel Shilovsky53ef1012013-09-05 16:11:28 +0400949struct smb_version_operations smb20_operations = {
950 .compare_fids = smb2_compare_fids,
951 .setup_request = smb2_setup_request,
952 .setup_async_request = smb2_setup_async_request,
953 .check_receive = smb2_check_receive,
954 .add_credits = smb2_add_credits,
955 .set_credits = smb2_set_credits,
956 .get_credits_field = smb2_get_credits_field,
957 .get_credits = smb2_get_credits,
958 .get_next_mid = smb2_get_next_mid,
959 .read_data_offset = smb2_read_data_offset,
960 .read_data_length = smb2_read_data_length,
961 .map_error = map_smb2_to_linux_error,
962 .find_mid = smb2_find_mid,
963 .check_message = smb2_check_message,
964 .dump_detail = smb2_dump_detail,
965 .clear_stats = smb2_clear_stats,
966 .print_stats = smb2_print_stats,
967 .is_oplock_break = smb2_is_valid_oplock_break,
968 .need_neg = smb2_need_neg,
969 .negotiate = smb2_negotiate,
970 .negotiate_wsize = smb2_negotiate_wsize,
971 .negotiate_rsize = smb2_negotiate_rsize,
972 .sess_setup = SMB2_sess_setup,
973 .logoff = SMB2_logoff,
974 .tree_connect = SMB2_tcon,
975 .tree_disconnect = SMB2_tdis,
Steve French34f62642013-10-09 02:07:00 -0500976 .qfs_tcon = smb2_qfs_tcon,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +0400977 .is_path_accessible = smb2_is_path_accessible,
978 .can_echo = smb2_can_echo,
979 .echo = SMB2_echo,
980 .query_path_info = smb2_query_path_info,
981 .get_srv_inum = smb2_get_srv_inum,
982 .query_file_info = smb2_query_file_info,
983 .set_path_size = smb2_set_path_size,
984 .set_file_size = smb2_set_file_size,
985 .set_file_info = smb2_set_file_info,
Steve French64a5cfa2013-10-14 15:31:32 -0500986 .set_compression = smb2_set_compression,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +0400987 .mkdir = smb2_mkdir,
988 .mkdir_setinfo = smb2_mkdir_setinfo,
989 .rmdir = smb2_rmdir,
990 .unlink = smb2_unlink,
991 .rename = smb2_rename_path,
992 .create_hardlink = smb2_create_hardlink,
993 .query_symlink = smb2_query_symlink,
994 .open = smb2_open_file,
995 .set_fid = smb2_set_fid,
996 .close = smb2_close_file,
997 .flush = smb2_flush_file,
998 .async_readv = smb2_async_readv,
999 .async_writev = smb2_async_writev,
1000 .sync_read = smb2_sync_read,
1001 .sync_write = smb2_sync_write,
1002 .query_dir_first = smb2_query_dir_first,
1003 .query_dir_next = smb2_query_dir_next,
1004 .close_dir = smb2_close_dir,
1005 .calc_smb_size = smb2_calc_size,
1006 .is_status_pending = smb2_is_status_pending,
1007 .oplock_response = smb2_oplock_response,
1008 .queryfs = smb2_queryfs,
1009 .mand_lock = smb2_mand_lock,
1010 .mand_unlock_range = smb2_unlock_range,
1011 .push_mand_locks = smb2_push_mandatory_locks,
1012 .get_lease_key = smb2_get_lease_key,
1013 .set_lease_key = smb2_set_lease_key,
1014 .new_lease_key = smb2_new_lease_key,
1015 .calc_signature = smb2_calc_signature,
1016 .is_read_op = smb2_is_read_op,
1017 .set_oplock_level = smb2_set_oplock_level,
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001018 .create_lease_buf = smb2_create_lease_buf,
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04001019 .parse_lease_buf = smb2_parse_lease_buf,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001020};
1021
Steve French1080ef72011-02-24 18:07:19 +00001022struct smb_version_operations smb21_operations = {
Pavel Shilovsky027e8ee2012-09-19 06:22:43 -07001023 .compare_fids = smb2_compare_fids,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +04001024 .setup_request = smb2_setup_request,
Pavel Shilovskyc95b8ee2012-07-11 14:45:28 +04001025 .setup_async_request = smb2_setup_async_request,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +04001026 .check_receive = smb2_check_receive,
Pavel Shilovsky28ea5292012-05-23 16:18:00 +04001027 .add_credits = smb2_add_credits,
1028 .set_credits = smb2_set_credits,
1029 .get_credits_field = smb2_get_credits_field,
1030 .get_credits = smb2_get_credits,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +04001031 .get_next_mid = smb2_get_next_mid,
Pavel Shilovsky09a47072012-09-18 16:20:29 -07001032 .read_data_offset = smb2_read_data_offset,
1033 .read_data_length = smb2_read_data_length,
1034 .map_error = map_smb2_to_linux_error,
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +04001035 .find_mid = smb2_find_mid,
1036 .check_message = smb2_check_message,
1037 .dump_detail = smb2_dump_detail,
Pavel Shilovskyd60622e2012-05-28 15:19:39 +04001038 .clear_stats = smb2_clear_stats,
1039 .print_stats = smb2_print_stats,
Pavel Shilovsky983c88a2012-09-18 16:20:33 -07001040 .is_oplock_break = smb2_is_valid_oplock_break,
Pavel Shilovskyec2e4522011-12-27 16:12:43 +04001041 .need_neg = smb2_need_neg,
1042 .negotiate = smb2_negotiate,
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -07001043 .negotiate_wsize = smb2_negotiate_wsize,
1044 .negotiate_rsize = smb2_negotiate_rsize,
Pavel Shilovsky5478f9b2011-12-27 16:22:00 +04001045 .sess_setup = SMB2_sess_setup,
1046 .logoff = SMB2_logoff,
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +04001047 .tree_connect = SMB2_tcon,
1048 .tree_disconnect = SMB2_tdis,
Steve French34f62642013-10-09 02:07:00 -05001049 .qfs_tcon = smb2_qfs_tcon,
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +04001050 .is_path_accessible = smb2_is_path_accessible,
Pavel Shilovsky9094fad2012-07-12 18:30:44 +04001051 .can_echo = smb2_can_echo,
1052 .echo = SMB2_echo,
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +04001053 .query_path_info = smb2_query_path_info,
1054 .get_srv_inum = smb2_get_srv_inum,
Pavel Shilovskyb7546bc2012-09-18 16:20:27 -07001055 .query_file_info = smb2_query_file_info,
Pavel Shilovskyc839ff22012-09-18 16:20:32 -07001056 .set_path_size = smb2_set_path_size,
1057 .set_file_size = smb2_set_file_size,
Pavel Shilovsky1feeaac2012-09-18 16:20:32 -07001058 .set_file_info = smb2_set_file_info,
Steve French64a5cfa2013-10-14 15:31:32 -05001059 .set_compression = smb2_set_compression,
Pavel Shilovskya0e73182011-07-19 12:56:37 +04001060 .mkdir = smb2_mkdir,
1061 .mkdir_setinfo = smb2_mkdir_setinfo,
Pavel Shilovsky1a500f02012-07-10 16:14:38 +04001062 .rmdir = smb2_rmdir,
Pavel Shilovskycbe6f432012-09-18 16:20:25 -07001063 .unlink = smb2_unlink,
Pavel Shilovsky35143eb2012-09-18 16:20:31 -07001064 .rename = smb2_rename_path,
Pavel Shilovsky568798c2012-09-18 16:20:31 -07001065 .create_hardlink = smb2_create_hardlink,
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001066 .query_symlink = smb2_query_symlink,
Pavel Shilovskyf0df7372012-09-18 16:20:26 -07001067 .open = smb2_open_file,
1068 .set_fid = smb2_set_fid,
1069 .close = smb2_close_file,
Pavel Shilovsky7a5cfb12012-09-18 16:20:28 -07001070 .flush = smb2_flush_file,
Pavel Shilovsky09a47072012-09-18 16:20:29 -07001071 .async_readv = smb2_async_readv,
Pavel Shilovsky33319142012-09-18 16:20:29 -07001072 .async_writev = smb2_async_writev,
Pavel Shilovskyd8e05032012-09-18 16:20:30 -07001073 .sync_read = smb2_sync_read,
Pavel Shilovsky009d3442012-09-18 16:20:30 -07001074 .sync_write = smb2_sync_write,
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -07001075 .query_dir_first = smb2_query_dir_first,
1076 .query_dir_next = smb2_query_dir_next,
1077 .close_dir = smb2_close_dir,
1078 .calc_smb_size = smb2_calc_size,
Pavel Shilovsky2e44b282012-09-18 16:20:33 -07001079 .is_status_pending = smb2_is_status_pending,
Pavel Shilovsky983c88a2012-09-18 16:20:33 -07001080 .oplock_response = smb2_oplock_response,
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001081 .queryfs = smb2_queryfs,
Pavel Shilovskyf7ba7fe2012-09-19 06:22:43 -07001082 .mand_lock = smb2_mand_lock,
1083 .mand_unlock_range = smb2_unlock_range,
Pavel Shilovskyb1407992012-09-19 06:22:44 -07001084 .push_mand_locks = smb2_push_mandatory_locks,
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -07001085 .get_lease_key = smb2_get_lease_key,
1086 .set_lease_key = smb2_set_lease_key,
1087 .new_lease_key = smb2_new_lease_key,
Steve French38107d42012-12-08 22:08:06 -06001088 .calc_signature = smb2_calc_signature,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001089 .is_read_op = smb21_is_read_op,
1090 .set_oplock_level = smb21_set_oplock_level,
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001091 .create_lease_buf = smb2_create_lease_buf,
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04001092 .parse_lease_buf = smb2_parse_lease_buf,
Steve French38107d42012-12-08 22:08:06 -06001093};
1094
Steve French38107d42012-12-08 22:08:06 -06001095struct smb_version_operations smb30_operations = {
1096 .compare_fids = smb2_compare_fids,
1097 .setup_request = smb2_setup_request,
1098 .setup_async_request = smb2_setup_async_request,
1099 .check_receive = smb2_check_receive,
1100 .add_credits = smb2_add_credits,
1101 .set_credits = smb2_set_credits,
1102 .get_credits_field = smb2_get_credits_field,
1103 .get_credits = smb2_get_credits,
1104 .get_next_mid = smb2_get_next_mid,
1105 .read_data_offset = smb2_read_data_offset,
1106 .read_data_length = smb2_read_data_length,
1107 .map_error = map_smb2_to_linux_error,
1108 .find_mid = smb2_find_mid,
1109 .check_message = smb2_check_message,
1110 .dump_detail = smb2_dump_detail,
1111 .clear_stats = smb2_clear_stats,
1112 .print_stats = smb2_print_stats,
Steve French769ee6a2013-06-19 14:15:30 -05001113 .dump_share_caps = smb2_dump_share_caps,
Steve French38107d42012-12-08 22:08:06 -06001114 .is_oplock_break = smb2_is_valid_oplock_break,
1115 .need_neg = smb2_need_neg,
1116 .negotiate = smb2_negotiate,
1117 .negotiate_wsize = smb2_negotiate_wsize,
1118 .negotiate_rsize = smb2_negotiate_rsize,
1119 .sess_setup = SMB2_sess_setup,
1120 .logoff = SMB2_logoff,
1121 .tree_connect = SMB2_tcon,
1122 .tree_disconnect = SMB2_tdis,
Steven Frenchaf6a12e2013-10-09 20:55:53 -05001123 .qfs_tcon = smb3_qfs_tcon,
Steve French38107d42012-12-08 22:08:06 -06001124 .is_path_accessible = smb2_is_path_accessible,
1125 .can_echo = smb2_can_echo,
1126 .echo = SMB2_echo,
1127 .query_path_info = smb2_query_path_info,
1128 .get_srv_inum = smb2_get_srv_inum,
1129 .query_file_info = smb2_query_file_info,
1130 .set_path_size = smb2_set_path_size,
1131 .set_file_size = smb2_set_file_size,
1132 .set_file_info = smb2_set_file_info,
Steve French64a5cfa2013-10-14 15:31:32 -05001133 .set_compression = smb2_set_compression,
Steve French38107d42012-12-08 22:08:06 -06001134 .mkdir = smb2_mkdir,
1135 .mkdir_setinfo = smb2_mkdir_setinfo,
1136 .rmdir = smb2_rmdir,
1137 .unlink = smb2_unlink,
1138 .rename = smb2_rename_path,
1139 .create_hardlink = smb2_create_hardlink,
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001140 .query_symlink = smb2_query_symlink,
Steve French38107d42012-12-08 22:08:06 -06001141 .open = smb2_open_file,
1142 .set_fid = smb2_set_fid,
1143 .close = smb2_close_file,
1144 .flush = smb2_flush_file,
1145 .async_readv = smb2_async_readv,
1146 .async_writev = smb2_async_writev,
1147 .sync_read = smb2_sync_read,
1148 .sync_write = smb2_sync_write,
1149 .query_dir_first = smb2_query_dir_first,
1150 .query_dir_next = smb2_query_dir_next,
1151 .close_dir = smb2_close_dir,
1152 .calc_smb_size = smb2_calc_size,
1153 .is_status_pending = smb2_is_status_pending,
1154 .oplock_response = smb2_oplock_response,
1155 .queryfs = smb2_queryfs,
1156 .mand_lock = smb2_mand_lock,
1157 .mand_unlock_range = smb2_unlock_range,
1158 .push_mand_locks = smb2_push_mandatory_locks,
1159 .get_lease_key = smb2_get_lease_key,
1160 .set_lease_key = smb2_set_lease_key,
1161 .new_lease_key = smb2_new_lease_key,
Steve Frenche65a5cb2013-06-27 01:06:50 -05001162 .generate_signingkey = generate_smb3signingkey,
Steve French38107d42012-12-08 22:08:06 -06001163 .calc_signature = smb3_calc_signature,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001164 .is_read_op = smb21_is_read_op,
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001165 .set_oplock_level = smb3_set_oplock_level,
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001166 .create_lease_buf = smb3_create_lease_buf,
1167 .parse_lease_buf = smb3_parse_lease_buf,
Steve French1080ef72011-02-24 18:07:19 +00001168};
1169
Steve Frenchdd446b12012-11-28 23:21:06 -06001170struct smb_version_values smb20_values = {
1171 .version_string = SMB20_VERSION_STRING,
1172 .protocol_id = SMB20_PROT_ID,
1173 .req_capabilities = 0, /* MBZ */
1174 .large_lock_type = 0,
1175 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1176 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1177 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
1178 .header_size = sizeof(struct smb2_hdr),
1179 .max_header_size = MAX_SMB2_HDR_SIZE,
1180 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
1181 .lock_cmd = SMB2_LOCK,
1182 .cap_unix = 0,
1183 .cap_nt_find = SMB2_NT_FIND,
1184 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton50285882013-06-27 12:45:00 -04001185 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1186 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001187 .create_lease_size = sizeof(struct create_lease),
Steve Frenchdd446b12012-11-28 23:21:06 -06001188};
1189
Steve French1080ef72011-02-24 18:07:19 +00001190struct smb_version_values smb21_values = {
1191 .version_string = SMB21_VERSION_STRING,
Steve Frenche4aa25e2012-10-01 12:26:22 -05001192 .protocol_id = SMB21_PROT_ID,
1193 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
1194 .large_lock_type = 0,
1195 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1196 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1197 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
1198 .header_size = sizeof(struct smb2_hdr),
1199 .max_header_size = MAX_SMB2_HDR_SIZE,
1200 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
1201 .lock_cmd = SMB2_LOCK,
1202 .cap_unix = 0,
1203 .cap_nt_find = SMB2_NT_FIND,
1204 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton50285882013-06-27 12:45:00 -04001205 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1206 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001207 .create_lease_size = sizeof(struct create_lease),
Steve Frenche4aa25e2012-10-01 12:26:22 -05001208};
1209
1210struct smb_version_values smb30_values = {
1211 .version_string = SMB30_VERSION_STRING,
1212 .protocol_id = SMB30_PROT_ID,
1213 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU,
Pavel Shilovsky027e8ee2012-09-19 06:22:43 -07001214 .large_lock_type = 0,
1215 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1216 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1217 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +04001218 .header_size = sizeof(struct smb2_hdr),
1219 .max_header_size = MAX_SMB2_HDR_SIZE,
Pavel Shilovsky09a47072012-09-18 16:20:29 -07001220 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +04001221 .lock_cmd = SMB2_LOCK,
Pavel Shilovsky29e20f92012-07-13 13:58:14 +04001222 .cap_unix = 0,
1223 .cap_nt_find = SMB2_NT_FIND,
1224 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton50285882013-06-27 12:45:00 -04001225 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1226 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001227 .create_lease_size = sizeof(struct create_lease_v2),
Steve French1080ef72011-02-24 18:07:19 +00001228};
Steve French20b6d8b2013-06-12 22:48:41 -05001229
1230struct smb_version_values smb302_values = {
1231 .version_string = SMB302_VERSION_STRING,
1232 .protocol_id = SMB302_PROT_ID,
1233 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU,
1234 .large_lock_type = 0,
1235 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1236 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1237 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
1238 .header_size = sizeof(struct smb2_hdr),
1239 .max_header_size = MAX_SMB2_HDR_SIZE,
1240 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
1241 .lock_cmd = SMB2_LOCK,
1242 .cap_unix = 0,
1243 .cap_nt_find = SMB2_NT_FIND,
1244 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton50285882013-06-27 12:45:00 -04001245 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1246 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001247 .create_lease_size = sizeof(struct create_lease_v2),
Steve French20b6d8b2013-06-12 22:48:41 -05001248};