]>
Commit | Line | Data |
---|---|---|
1080ef75 SF |
1 | /* |
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 | ||
3a3bab50 | 20 | #include <linux/pagemap.h> |
6fc05c25 | 21 | #include <linux/vfs.h> |
1080ef75 | 22 | #include "cifsglob.h" |
2dc7e1c0 PS |
23 | #include "smb2pdu.h" |
24 | #include "smb2proto.h" | |
28ea5290 PS |
25 | #include "cifsproto.h" |
26 | #include "cifs_debug.h" | |
2e44b288 | 27 | #include "smb2status.h" |
6fc05c25 | 28 | #include "smb2glob.h" |
28ea5290 PS |
29 | |
30 | static int | |
31 | change_conf(struct TCP_Server_Info *server) | |
32 | { | |
33 | server->credits += server->echo_credits + server->oplock_credits; | |
34 | server->oplock_credits = server->echo_credits = 0; | |
35 | switch (server->credits) { | |
36 | case 0: | |
37 | return -1; | |
38 | case 1: | |
39 | server->echoes = false; | |
40 | server->oplocks = false; | |
41 | cERROR(1, "disabling echoes and oplocks"); | |
42 | break; | |
43 | case 2: | |
44 | server->echoes = true; | |
45 | server->oplocks = false; | |
46 | server->echo_credits = 1; | |
47 | cFYI(1, "disabling oplocks"); | |
48 | break; | |
49 | default: | |
50 | server->echoes = true; | |
51 | server->oplocks = true; | |
52 | server->echo_credits = 1; | |
53 | server->oplock_credits = 1; | |
54 | } | |
55 | server->credits -= server->echo_credits + server->oplock_credits; | |
56 | return 0; | |
57 | } | |
58 | ||
59 | static void | |
60 | smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add, | |
61 | const int optype) | |
62 | { | |
63 | int *val, rc = 0; | |
64 | spin_lock(&server->req_lock); | |
65 | val = server->ops->get_credits_field(server, optype); | |
66 | *val += add; | |
67 | server->in_flight--; | |
ec2e4523 | 68 | if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP) |
28ea5290 | 69 | rc = change_conf(server); |
983c88a4 PS |
70 | /* |
71 | * Sometimes server returns 0 credits on oplock break ack - we need to | |
72 | * rebalance credits in this case. | |
73 | */ | |
74 | else if (server->in_flight > 0 && server->oplock_credits == 0 && | |
75 | server->oplocks) { | |
76 | if (server->credits > 1) { | |
77 | server->credits--; | |
78 | server->oplock_credits++; | |
79 | } | |
80 | } | |
28ea5290 PS |
81 | spin_unlock(&server->req_lock); |
82 | wake_up(&server->request_q); | |
83 | if (rc) | |
84 | cifs_reconnect(server); | |
85 | } | |
86 | ||
87 | static void | |
88 | smb2_set_credits(struct TCP_Server_Info *server, const int val) | |
89 | { | |
90 | spin_lock(&server->req_lock); | |
91 | server->credits = val; | |
92 | spin_unlock(&server->req_lock); | |
93 | } | |
94 | ||
95 | static int * | |
96 | smb2_get_credits_field(struct TCP_Server_Info *server, const int optype) | |
97 | { | |
98 | switch (optype) { | |
99 | case CIFS_ECHO_OP: | |
100 | return &server->echo_credits; | |
101 | case CIFS_OBREAK_OP: | |
102 | return &server->oplock_credits; | |
103 | default: | |
104 | return &server->credits; | |
105 | } | |
106 | } | |
107 | ||
108 | static unsigned int | |
109 | smb2_get_credits(struct mid_q_entry *mid) | |
110 | { | |
111 | return le16_to_cpu(((struct smb2_hdr *)mid->resp_buf)->CreditRequest); | |
112 | } | |
2dc7e1c0 PS |
113 | |
114 | static __u64 | |
115 | smb2_get_next_mid(struct TCP_Server_Info *server) | |
116 | { | |
117 | __u64 mid; | |
118 | /* for SMB2 we need the current value */ | |
119 | spin_lock(&GlobalMid_Lock); | |
120 | mid = server->CurrentMid++; | |
121 | spin_unlock(&GlobalMid_Lock); | |
122 | return mid; | |
123 | } | |
1080ef75 | 124 | |
093b2bda PS |
125 | static struct mid_q_entry * |
126 | smb2_find_mid(struct TCP_Server_Info *server, char *buf) | |
127 | { | |
128 | struct mid_q_entry *mid; | |
129 | struct smb2_hdr *hdr = (struct smb2_hdr *)buf; | |
130 | ||
131 | spin_lock(&GlobalMid_Lock); | |
132 | list_for_each_entry(mid, &server->pending_mid_q, qhead) { | |
133 | if ((mid->mid == hdr->MessageId) && | |
134 | (mid->mid_state == MID_REQUEST_SUBMITTED) && | |
135 | (mid->command == hdr->Command)) { | |
136 | spin_unlock(&GlobalMid_Lock); | |
137 | return mid; | |
138 | } | |
139 | } | |
140 | spin_unlock(&GlobalMid_Lock); | |
141 | return NULL; | |
142 | } | |
143 | ||
144 | static void | |
145 | smb2_dump_detail(void *buf) | |
146 | { | |
147 | #ifdef CONFIG_CIFS_DEBUG2 | |
148 | struct smb2_hdr *smb = (struct smb2_hdr *)buf; | |
149 | ||
150 | cERROR(1, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d", | |
151 | smb->Command, smb->Status, smb->Flags, smb->MessageId, | |
152 | smb->ProcessId); | |
153 | cERROR(1, "smb buf %p len %u", smb, smb2_calc_size(smb)); | |
154 | #endif | |
155 | } | |
156 | ||
ec2e4523 PS |
157 | static bool |
158 | smb2_need_neg(struct TCP_Server_Info *server) | |
159 | { | |
160 | return server->max_read == 0; | |
161 | } | |
162 | ||
163 | static int | |
164 | smb2_negotiate(const unsigned int xid, struct cifs_ses *ses) | |
165 | { | |
166 | int rc; | |
167 | ses->server->CurrentMid = 0; | |
168 | rc = SMB2_negotiate(xid, ses); | |
169 | /* BB we probably don't need to retry with modern servers */ | |
170 | if (rc == -EAGAIN) | |
171 | rc = -EHOSTDOWN; | |
172 | return rc; | |
173 | } | |
174 | ||
3a3bab50 PS |
175 | static unsigned int |
176 | smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) | |
177 | { | |
178 | struct TCP_Server_Info *server = tcon->ses->server; | |
179 | unsigned int wsize; | |
180 | ||
181 | /* start with specified wsize, or default */ | |
182 | wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE; | |
183 | wsize = min_t(unsigned int, wsize, server->max_write); | |
184 | /* | |
185 | * limit write size to 2 ** 16, because we don't support multicredit | |
186 | * requests now. | |
187 | */ | |
188 | wsize = min_t(unsigned int, wsize, 2 << 15); | |
189 | ||
3a3bab50 PS |
190 | return wsize; |
191 | } | |
192 | ||
193 | static unsigned int | |
194 | smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) | |
195 | { | |
196 | struct TCP_Server_Info *server = tcon->ses->server; | |
197 | unsigned int rsize; | |
198 | ||
199 | /* start with specified rsize, or default */ | |
200 | rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE; | |
201 | rsize = min_t(unsigned int, rsize, server->max_read); | |
202 | /* | |
203 | * limit write size to 2 ** 16, because we don't support multicredit | |
204 | * requests now. | |
205 | */ | |
206 | rsize = min_t(unsigned int, rsize, 2 << 15); | |
207 | ||
3a3bab50 PS |
208 | return rsize; |
209 | } | |
210 | ||
2503a0db PS |
211 | static int |
212 | smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon, | |
213 | struct cifs_sb_info *cifs_sb, const char *full_path) | |
214 | { | |
215 | int rc; | |
216 | __u64 persistent_fid, volatile_fid; | |
217 | __le16 *utf16_path; | |
2e44b288 | 218 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
2503a0db PS |
219 | |
220 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); | |
221 | if (!utf16_path) | |
222 | return -ENOMEM; | |
223 | ||
224 | rc = SMB2_open(xid, tcon, utf16_path, &persistent_fid, &volatile_fid, | |
2e44b288 | 225 | FILE_READ_ATTRIBUTES, FILE_OPEN, 0, 0, &oplock, NULL); |
2503a0db PS |
226 | if (rc) { |
227 | kfree(utf16_path); | |
228 | return rc; | |
229 | } | |
230 | ||
231 | rc = SMB2_close(xid, tcon, persistent_fid, volatile_fid); | |
232 | kfree(utf16_path); | |
233 | return rc; | |
234 | } | |
235 | ||
be4cb9e3 PS |
236 | static int |
237 | smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon, | |
238 | struct cifs_sb_info *cifs_sb, const char *full_path, | |
239 | u64 *uniqueid, FILE_ALL_INFO *data) | |
240 | { | |
241 | *uniqueid = le64_to_cpu(data->IndexNumber); | |
242 | return 0; | |
243 | } | |
244 | ||
b7546bc5 PS |
245 | static int |
246 | smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon, | |
247 | struct cifs_fid *fid, FILE_ALL_INFO *data) | |
248 | { | |
249 | int rc; | |
250 | struct smb2_file_all_info *smb2_data; | |
251 | ||
252 | smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + MAX_NAME * 2, | |
253 | GFP_KERNEL); | |
254 | if (smb2_data == NULL) | |
255 | return -ENOMEM; | |
256 | ||
257 | rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid, | |
258 | smb2_data); | |
259 | if (!rc) | |
260 | move_smb2_info_to_cifs(data, smb2_data); | |
261 | kfree(smb2_data); | |
262 | return rc; | |
263 | } | |
264 | ||
25e26632 PS |
265 | static char * |
266 | smb2_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb, | |
267 | struct cifs_tcon *tcon) | |
268 | { | |
269 | int pplen = vol->prepath ? strlen(vol->prepath) : 0; | |
270 | char *full_path = NULL; | |
271 | ||
272 | /* if no prefix path, simply set path to the root of share to "" */ | |
273 | if (pplen == 0) { | |
274 | full_path = kzalloc(2, GFP_KERNEL); | |
275 | return full_path; | |
276 | } | |
277 | ||
278 | cERROR(1, "prefixpath is not supported for SMB2 now"); | |
279 | return NULL; | |
280 | } | |
281 | ||
9094fad1 PS |
282 | static bool |
283 | smb2_can_echo(struct TCP_Server_Info *server) | |
284 | { | |
285 | return server->echoes; | |
286 | } | |
287 | ||
d60622eb PS |
288 | static void |
289 | smb2_clear_stats(struct cifs_tcon *tcon) | |
290 | { | |
291 | #ifdef CONFIG_CIFS_STATS | |
292 | int i; | |
293 | for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) { | |
294 | atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0); | |
295 | atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0); | |
296 | } | |
297 | #endif | |
298 | } | |
299 | ||
300 | static void | |
301 | smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon) | |
302 | { | |
303 | #ifdef CONFIG_CIFS_STATS | |
304 | atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent; | |
305 | atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed; | |
306 | seq_printf(m, "\nNegotiates: %d sent %d failed", | |
307 | atomic_read(&sent[SMB2_NEGOTIATE_HE]), | |
308 | atomic_read(&failed[SMB2_NEGOTIATE_HE])); | |
309 | seq_printf(m, "\nSessionSetups: %d sent %d failed", | |
310 | atomic_read(&sent[SMB2_SESSION_SETUP_HE]), | |
311 | atomic_read(&failed[SMB2_SESSION_SETUP_HE])); | |
312 | #define SMB2LOGOFF 0x0002 /* trivial request/resp */ | |
313 | seq_printf(m, "\nLogoffs: %d sent %d failed", | |
314 | atomic_read(&sent[SMB2_LOGOFF_HE]), | |
315 | atomic_read(&failed[SMB2_LOGOFF_HE])); | |
316 | seq_printf(m, "\nTreeConnects: %d sent %d failed", | |
317 | atomic_read(&sent[SMB2_TREE_CONNECT_HE]), | |
318 | atomic_read(&failed[SMB2_TREE_CONNECT_HE])); | |
319 | seq_printf(m, "\nTreeDisconnects: %d sent %d failed", | |
320 | atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]), | |
321 | atomic_read(&failed[SMB2_TREE_DISCONNECT_HE])); | |
322 | seq_printf(m, "\nCreates: %d sent %d failed", | |
323 | atomic_read(&sent[SMB2_CREATE_HE]), | |
324 | atomic_read(&failed[SMB2_CREATE_HE])); | |
325 | seq_printf(m, "\nCloses: %d sent %d failed", | |
326 | atomic_read(&sent[SMB2_CLOSE_HE]), | |
327 | atomic_read(&failed[SMB2_CLOSE_HE])); | |
328 | seq_printf(m, "\nFlushes: %d sent %d failed", | |
329 | atomic_read(&sent[SMB2_FLUSH_HE]), | |
330 | atomic_read(&failed[SMB2_FLUSH_HE])); | |
331 | seq_printf(m, "\nReads: %d sent %d failed", | |
332 | atomic_read(&sent[SMB2_READ_HE]), | |
333 | atomic_read(&failed[SMB2_READ_HE])); | |
334 | seq_printf(m, "\nWrites: %d sent %d failed", | |
335 | atomic_read(&sent[SMB2_WRITE_HE]), | |
336 | atomic_read(&failed[SMB2_WRITE_HE])); | |
337 | seq_printf(m, "\nLocks: %d sent %d failed", | |
338 | atomic_read(&sent[SMB2_LOCK_HE]), | |
339 | atomic_read(&failed[SMB2_LOCK_HE])); | |
340 | seq_printf(m, "\nIOCTLs: %d sent %d failed", | |
341 | atomic_read(&sent[SMB2_IOCTL_HE]), | |
342 | atomic_read(&failed[SMB2_IOCTL_HE])); | |
343 | seq_printf(m, "\nCancels: %d sent %d failed", | |
344 | atomic_read(&sent[SMB2_CANCEL_HE]), | |
345 | atomic_read(&failed[SMB2_CANCEL_HE])); | |
346 | seq_printf(m, "\nEchos: %d sent %d failed", | |
347 | atomic_read(&sent[SMB2_ECHO_HE]), | |
348 | atomic_read(&failed[SMB2_ECHO_HE])); | |
349 | seq_printf(m, "\nQueryDirectories: %d sent %d failed", | |
350 | atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]), | |
351 | atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE])); | |
352 | seq_printf(m, "\nChangeNotifies: %d sent %d failed", | |
353 | atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]), | |
354 | atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE])); | |
355 | seq_printf(m, "\nQueryInfos: %d sent %d failed", | |
356 | atomic_read(&sent[SMB2_QUERY_INFO_HE]), | |
357 | atomic_read(&failed[SMB2_QUERY_INFO_HE])); | |
358 | seq_printf(m, "\nSetInfos: %d sent %d failed", | |
359 | atomic_read(&sent[SMB2_SET_INFO_HE]), | |
360 | atomic_read(&failed[SMB2_SET_INFO_HE])); | |
361 | seq_printf(m, "\nOplockBreaks: %d sent %d failed", | |
362 | atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]), | |
363 | atomic_read(&failed[SMB2_OPLOCK_BREAK_HE])); | |
364 | #endif | |
365 | } | |
366 | ||
f0df737e PS |
367 | static void |
368 | smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock) | |
369 | { | |
2e44b288 | 370 | struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); |
f0df737e PS |
371 | cfile->fid.persistent_fid = fid->persistent_fid; |
372 | cfile->fid.volatile_fid = fid->volatile_fid; | |
2e44b288 | 373 | smb2_set_oplock_level(cinode, oplock); |
b140799a | 374 | cinode->can_cache_brlcks = cinode->clientCanCacheAll; |
f0df737e PS |
375 | } |
376 | ||
760ad0ca | 377 | static void |
f0df737e PS |
378 | smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon, |
379 | struct cifs_fid *fid) | |
380 | { | |
760ad0ca | 381 | SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
f0df737e PS |
382 | } |
383 | ||
7a5cfb19 PS |
384 | static int |
385 | smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon, | |
386 | struct cifs_fid *fid) | |
387 | { | |
388 | return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid); | |
389 | } | |
390 | ||
09a4707e PS |
391 | static unsigned int |
392 | smb2_read_data_offset(char *buf) | |
393 | { | |
394 | struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf; | |
395 | return rsp->DataOffset; | |
396 | } | |
397 | ||
398 | static unsigned int | |
399 | smb2_read_data_length(char *buf) | |
400 | { | |
401 | struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf; | |
402 | return le32_to_cpu(rsp->DataLength); | |
403 | } | |
404 | ||
d8e05039 PS |
405 | |
406 | static int | |
407 | smb2_sync_read(const unsigned int xid, struct cifsFileInfo *cfile, | |
408 | struct cifs_io_parms *parms, unsigned int *bytes_read, | |
409 | char **buf, int *buf_type) | |
410 | { | |
411 | parms->persistent_fid = cfile->fid.persistent_fid; | |
412 | parms->volatile_fid = cfile->fid.volatile_fid; | |
413 | return SMB2_read(xid, parms, bytes_read, buf, buf_type); | |
414 | } | |
415 | ||
009d3443 PS |
416 | static int |
417 | smb2_sync_write(const unsigned int xid, struct cifsFileInfo *cfile, | |
418 | struct cifs_io_parms *parms, unsigned int *written, | |
419 | struct kvec *iov, unsigned long nr_segs) | |
420 | { | |
421 | ||
422 | parms->persistent_fid = cfile->fid.persistent_fid; | |
423 | parms->volatile_fid = cfile->fid.volatile_fid; | |
424 | return SMB2_write(xid, parms, written, iov, nr_segs); | |
425 | } | |
426 | ||
c839ff24 PS |
427 | static int |
428 | smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon, | |
429 | struct cifsFileInfo *cfile, __u64 size, bool set_alloc) | |
430 | { | |
431 | __le64 eof = cpu_to_le64(size); | |
432 | return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, | |
433 | cfile->fid.volatile_fid, cfile->pid, &eof); | |
434 | } | |
435 | ||
d324f08d PS |
436 | static int |
437 | smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon, | |
438 | const char *path, struct cifs_sb_info *cifs_sb, | |
439 | struct cifs_fid *fid, __u16 search_flags, | |
440 | struct cifs_search_info *srch_inf) | |
441 | { | |
442 | __le16 *utf16_path; | |
443 | int rc; | |
2e44b288 | 444 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
d324f08d PS |
445 | __u64 persistent_fid, volatile_fid; |
446 | ||
447 | utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); | |
448 | if (!utf16_path) | |
449 | return -ENOMEM; | |
450 | ||
451 | rc = SMB2_open(xid, tcon, utf16_path, &persistent_fid, &volatile_fid, | |
452 | FILE_READ_ATTRIBUTES | FILE_READ_DATA, FILE_OPEN, 0, 0, | |
2e44b288 | 453 | &oplock, NULL); |
d324f08d PS |
454 | kfree(utf16_path); |
455 | if (rc) { | |
456 | cERROR(1, "open dir failed"); | |
457 | return rc; | |
458 | } | |
459 | ||
460 | srch_inf->entries_in_buffer = 0; | |
461 | srch_inf->index_of_last_entry = 0; | |
462 | fid->persistent_fid = persistent_fid; | |
463 | fid->volatile_fid = volatile_fid; | |
464 | ||
465 | rc = SMB2_query_directory(xid, tcon, persistent_fid, volatile_fid, 0, | |
466 | srch_inf); | |
467 | if (rc) { | |
468 | cERROR(1, "query directory failed"); | |
469 | SMB2_close(xid, tcon, persistent_fid, volatile_fid); | |
470 | } | |
471 | return rc; | |
472 | } | |
473 | ||
474 | static int | |
475 | smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon, | |
476 | struct cifs_fid *fid, __u16 search_flags, | |
477 | struct cifs_search_info *srch_inf) | |
478 | { | |
479 | return SMB2_query_directory(xid, tcon, fid->persistent_fid, | |
480 | fid->volatile_fid, 0, srch_inf); | |
481 | } | |
482 | ||
483 | static int | |
484 | smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon, | |
485 | struct cifs_fid *fid) | |
486 | { | |
487 | return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); | |
488 | } | |
489 | ||
2e44b288 PS |
490 | /* |
491 | * If we negotiate SMB2 protocol and get STATUS_PENDING - update | |
492 | * the number of credits and return true. Otherwise - return false. | |
493 | */ | |
494 | static bool | |
495 | smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length) | |
496 | { | |
497 | struct smb2_hdr *hdr = (struct smb2_hdr *)buf; | |
498 | ||
12e8a208 | 499 | if (hdr->Status != STATUS_PENDING) |
2e44b288 PS |
500 | return false; |
501 | ||
502 | if (!length) { | |
503 | spin_lock(&server->req_lock); | |
504 | server->credits += le16_to_cpu(hdr->CreditRequest); | |
505 | spin_unlock(&server->req_lock); | |
506 | wake_up(&server->request_q); | |
507 | } | |
508 | ||
509 | return true; | |
510 | } | |
511 | ||
983c88a4 PS |
512 | static int |
513 | smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid, | |
514 | struct cifsInodeInfo *cinode) | |
515 | { | |
0822f514 PS |
516 | if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING) |
517 | return SMB2_lease_break(0, tcon, cinode->lease_key, | |
518 | smb2_get_lease_state(cinode)); | |
519 | ||
983c88a4 PS |
520 | return SMB2_oplock_break(0, tcon, fid->persistent_fid, |
521 | fid->volatile_fid, | |
522 | cinode->clientCanCacheRead ? 1 : 0); | |
523 | } | |
524 | ||
6fc05c25 PS |
525 | static int |
526 | smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon, | |
527 | struct kstatfs *buf) | |
528 | { | |
529 | int rc; | |
530 | u64 persistent_fid, volatile_fid; | |
531 | __le16 srch_path = 0; /* Null - open root of share */ | |
532 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; | |
533 | ||
534 | rc = SMB2_open(xid, tcon, &srch_path, &persistent_fid, &volatile_fid, | |
535 | FILE_READ_ATTRIBUTES, FILE_OPEN, 0, 0, &oplock, NULL); | |
536 | if (rc) | |
537 | return rc; | |
538 | buf->f_type = SMB2_MAGIC_NUMBER; | |
539 | rc = SMB2_QFS_info(xid, tcon, persistent_fid, volatile_fid, buf); | |
540 | SMB2_close(xid, tcon, persistent_fid, volatile_fid); | |
541 | return rc; | |
542 | } | |
543 | ||
027e8eec PS |
544 | static bool |
545 | smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2) | |
546 | { | |
547 | return ob1->fid.persistent_fid == ob2->fid.persistent_fid && | |
548 | ob1->fid.volatile_fid == ob2->fid.volatile_fid; | |
549 | } | |
550 | ||
f7ba7fe6 PS |
551 | static int |
552 | smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset, | |
553 | __u64 length, __u32 type, int lock, int unlock, bool wait) | |
554 | { | |
555 | if (unlock && !lock) | |
556 | type = SMB2_LOCKFLAG_UNLOCK; | |
557 | return SMB2_lock(xid, tlink_tcon(cfile->tlink), | |
558 | cfile->fid.persistent_fid, cfile->fid.volatile_fid, | |
559 | current->tgid, length, offset, type, wait); | |
560 | } | |
561 | ||
b8c32dbb PS |
562 | static void |
563 | smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid) | |
564 | { | |
565 | memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE); | |
566 | } | |
567 | ||
568 | static void | |
569 | smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid) | |
570 | { | |
571 | memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE); | |
572 | } | |
573 | ||
574 | static void | |
575 | smb2_new_lease_key(struct cifs_fid *fid) | |
576 | { | |
577 | get_random_bytes(fid->lease_key, SMB2_LEASE_KEY_SIZE); | |
578 | } | |
579 | ||
1080ef75 | 580 | struct smb_version_operations smb21_operations = { |
027e8eec | 581 | .compare_fids = smb2_compare_fids, |
2dc7e1c0 | 582 | .setup_request = smb2_setup_request, |
c95b8eed | 583 | .setup_async_request = smb2_setup_async_request, |
2dc7e1c0 | 584 | .check_receive = smb2_check_receive, |
28ea5290 PS |
585 | .add_credits = smb2_add_credits, |
586 | .set_credits = smb2_set_credits, | |
587 | .get_credits_field = smb2_get_credits_field, | |
588 | .get_credits = smb2_get_credits, | |
2dc7e1c0 | 589 | .get_next_mid = smb2_get_next_mid, |
09a4707e PS |
590 | .read_data_offset = smb2_read_data_offset, |
591 | .read_data_length = smb2_read_data_length, | |
592 | .map_error = map_smb2_to_linux_error, | |
093b2bda PS |
593 | .find_mid = smb2_find_mid, |
594 | .check_message = smb2_check_message, | |
595 | .dump_detail = smb2_dump_detail, | |
d60622eb PS |
596 | .clear_stats = smb2_clear_stats, |
597 | .print_stats = smb2_print_stats, | |
983c88a4 | 598 | .is_oplock_break = smb2_is_valid_oplock_break, |
ec2e4523 PS |
599 | .need_neg = smb2_need_neg, |
600 | .negotiate = smb2_negotiate, | |
3a3bab50 PS |
601 | .negotiate_wsize = smb2_negotiate_wsize, |
602 | .negotiate_rsize = smb2_negotiate_rsize, | |
5478f9ba PS |
603 | .sess_setup = SMB2_sess_setup, |
604 | .logoff = SMB2_logoff, | |
faaf946a PS |
605 | .tree_connect = SMB2_tcon, |
606 | .tree_disconnect = SMB2_tdis, | |
2503a0db | 607 | .is_path_accessible = smb2_is_path_accessible, |
9094fad1 PS |
608 | .can_echo = smb2_can_echo, |
609 | .echo = SMB2_echo, | |
be4cb9e3 PS |
610 | .query_path_info = smb2_query_path_info, |
611 | .get_srv_inum = smb2_get_srv_inum, | |
b7546bc5 | 612 | .query_file_info = smb2_query_file_info, |
c839ff24 PS |
613 | .set_path_size = smb2_set_path_size, |
614 | .set_file_size = smb2_set_file_size, | |
1feeaac7 | 615 | .set_file_info = smb2_set_file_info, |
25e26632 | 616 | .build_path_to_root = smb2_build_path_to_root, |
a0e73183 PS |
617 | .mkdir = smb2_mkdir, |
618 | .mkdir_setinfo = smb2_mkdir_setinfo, | |
1a500f01 | 619 | .rmdir = smb2_rmdir, |
cbe6f439 | 620 | .unlink = smb2_unlink, |
35143eb5 | 621 | .rename = smb2_rename_path, |
568798cc | 622 | .create_hardlink = smb2_create_hardlink, |
f0df737e PS |
623 | .open = smb2_open_file, |
624 | .set_fid = smb2_set_fid, | |
625 | .close = smb2_close_file, | |
7a5cfb19 | 626 | .flush = smb2_flush_file, |
09a4707e | 627 | .async_readv = smb2_async_readv, |
33319141 | 628 | .async_writev = smb2_async_writev, |
d8e05039 | 629 | .sync_read = smb2_sync_read, |
009d3443 | 630 | .sync_write = smb2_sync_write, |
d324f08d PS |
631 | .query_dir_first = smb2_query_dir_first, |
632 | .query_dir_next = smb2_query_dir_next, | |
633 | .close_dir = smb2_close_dir, | |
634 | .calc_smb_size = smb2_calc_size, | |
2e44b288 | 635 | .is_status_pending = smb2_is_status_pending, |
983c88a4 | 636 | .oplock_response = smb2_oplock_response, |
6fc05c25 | 637 | .queryfs = smb2_queryfs, |
f7ba7fe6 PS |
638 | .mand_lock = smb2_mand_lock, |
639 | .mand_unlock_range = smb2_unlock_range, | |
b140799a | 640 | .push_mand_locks = smb2_push_mandatory_locks, |
b8c32dbb PS |
641 | .get_lease_key = smb2_get_lease_key, |
642 | .set_lease_key = smb2_set_lease_key, | |
643 | .new_lease_key = smb2_new_lease_key, | |
1080ef75 SF |
644 | }; |
645 | ||
646 | struct smb_version_values smb21_values = { | |
647 | .version_string = SMB21_VERSION_STRING, | |
e4aa25e7 SF |
648 | .protocol_id = SMB21_PROT_ID, |
649 | .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */ | |
650 | .large_lock_type = 0, | |
651 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, | |
652 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, | |
653 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, | |
654 | .header_size = sizeof(struct smb2_hdr), | |
655 | .max_header_size = MAX_SMB2_HDR_SIZE, | |
656 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, | |
657 | .lock_cmd = SMB2_LOCK, | |
658 | .cap_unix = 0, | |
659 | .cap_nt_find = SMB2_NT_FIND, | |
660 | .cap_large_files = SMB2_LARGE_FILES, | |
661 | }; | |
662 | ||
663 | struct smb_version_values smb30_values = { | |
664 | .version_string = SMB30_VERSION_STRING, | |
665 | .protocol_id = SMB30_PROT_ID, | |
666 | .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU, | |
027e8eec PS |
667 | .large_lock_type = 0, |
668 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, | |
669 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, | |
670 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, | |
093b2bda PS |
671 | .header_size = sizeof(struct smb2_hdr), |
672 | .max_header_size = MAX_SMB2_HDR_SIZE, | |
09a4707e | 673 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
2dc7e1c0 | 674 | .lock_cmd = SMB2_LOCK, |
29e20f9c PS |
675 | .cap_unix = 0, |
676 | .cap_nt_find = SMB2_NT_FIND, | |
677 | .cap_large_files = SMB2_LARGE_FILES, | |
1080ef75 | 678 | }; |