Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 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 | |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 20 | #include <linux/pagemap.h> |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 21 | #include <linux/vfs.h> |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 22 | #include "cifsglob.h" |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 23 | #include "smb2pdu.h" |
| 24 | #include "smb2proto.h" |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 25 | #include "cifsproto.h" |
| 26 | #include "cifs_debug.h" |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 27 | #include "cifs_unicode.h" |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 28 | #include "smb2status.h" |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 29 | #include "smb2glob.h" |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 30 | |
| 31 | static int |
| 32 | change_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 Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 42 | cifs_dbg(VFS, "disabling echoes and oplocks\n"); |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 43 | break; |
| 44 | case 2: |
| 45 | server->echoes = true; |
| 46 | server->oplocks = false; |
| 47 | server->echo_credits = 1; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 48 | cifs_dbg(FYI, "disabling oplocks\n"); |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 49 | 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 | |
| 60 | static void |
| 61 | smb2_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 Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 69 | if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP) |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 70 | rc = change_conf(server); |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 71 | /* |
| 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 Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 82 | spin_unlock(&server->req_lock); |
| 83 | wake_up(&server->request_q); |
| 84 | if (rc) |
| 85 | cifs_reconnect(server); |
| 86 | } |
| 87 | |
| 88 | static void |
| 89 | smb2_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 | |
| 96 | static int * |
| 97 | smb2_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 | |
| 109 | static unsigned int |
| 110 | smb2_get_credits(struct mid_q_entry *mid) |
| 111 | { |
| 112 | return le16_to_cpu(((struct smb2_hdr *)mid->resp_buf)->CreditRequest); |
| 113 | } |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 114 | |
| 115 | static __u64 |
| 116 | smb2_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 French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 125 | |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 126 | static struct mid_q_entry * |
| 127 | smb2_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 | |
| 145 | static void |
| 146 | smb2_dump_detail(void *buf) |
| 147 | { |
| 148 | #ifdef CONFIG_CIFS_DEBUG2 |
| 149 | struct smb2_hdr *smb = (struct smb2_hdr *)buf; |
| 150 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 151 | 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 Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 155 | #endif |
| 156 | } |
| 157 | |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 158 | static bool |
| 159 | smb2_need_neg(struct TCP_Server_Info *server) |
| 160 | { |
| 161 | return server->max_read == 0; |
| 162 | } |
| 163 | |
| 164 | static int |
| 165 | smb2_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 Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 176 | static unsigned int |
| 177 | smb2_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 Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 191 | return wsize; |
| 192 | } |
| 193 | |
| 194 | static unsigned int |
| 195 | smb2_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 Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 209 | return rsize; |
| 210 | } |
| 211 | |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 212 | static int |
| 213 | smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon, |
| 214 | struct cifs_sb_info *cifs_sb, const char *full_path) |
| 215 | { |
| 216 | int rc; |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 217 | __le16 *utf16_path; |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 218 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 219 | struct cifs_open_parms oparms; |
| 220 | struct cifs_fid fid; |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 221 | |
| 222 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); |
| 223 | if (!utf16_path) |
| 224 | return -ENOMEM; |
| 225 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 226 | oparms.tcon = tcon; |
| 227 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 228 | oparms.disposition = FILE_OPEN; |
| 229 | oparms.create_options = 0; |
| 230 | oparms.fid = &fid; |
Pavel Shilovsky | 9cbc0b7 | 2013-07-09 18:40:58 +0400 | [diff] [blame] | 231 | oparms.reconnect = false; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 232 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 233 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL); |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 234 | if (rc) { |
| 235 | kfree(utf16_path); |
| 236 | return rc; |
| 237 | } |
| 238 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 239 | rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 240 | kfree(utf16_path); |
| 241 | return rc; |
| 242 | } |
| 243 | |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 244 | static int |
| 245 | smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon, |
| 246 | struct cifs_sb_info *cifs_sb, const char *full_path, |
| 247 | u64 *uniqueid, FILE_ALL_INFO *data) |
| 248 | { |
| 249 | *uniqueid = le64_to_cpu(data->IndexNumber); |
| 250 | return 0; |
| 251 | } |
| 252 | |
Pavel Shilovsky | b7546bc | 2012-09-18 16:20:27 -0700 | [diff] [blame] | 253 | static int |
| 254 | smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon, |
| 255 | struct cifs_fid *fid, FILE_ALL_INFO *data) |
| 256 | { |
| 257 | int rc; |
| 258 | struct smb2_file_all_info *smb2_data; |
| 259 | |
| 260 | smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + MAX_NAME * 2, |
| 261 | GFP_KERNEL); |
| 262 | if (smb2_data == NULL) |
| 263 | return -ENOMEM; |
| 264 | |
| 265 | rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid, |
| 266 | smb2_data); |
| 267 | if (!rc) |
| 268 | move_smb2_info_to_cifs(data, smb2_data); |
| 269 | kfree(smb2_data); |
| 270 | return rc; |
| 271 | } |
| 272 | |
Pavel Shilovsky | 9094fad | 2012-07-12 18:30:44 +0400 | [diff] [blame] | 273 | static bool |
| 274 | smb2_can_echo(struct TCP_Server_Info *server) |
| 275 | { |
| 276 | return server->echoes; |
| 277 | } |
| 278 | |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 279 | static void |
| 280 | smb2_clear_stats(struct cifs_tcon *tcon) |
| 281 | { |
| 282 | #ifdef CONFIG_CIFS_STATS |
| 283 | int i; |
| 284 | for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) { |
| 285 | atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0); |
| 286 | atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0); |
| 287 | } |
| 288 | #endif |
| 289 | } |
| 290 | |
| 291 | static void |
Steve French | 769ee6a | 2013-06-19 14:15:30 -0500 | [diff] [blame] | 292 | smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon) |
| 293 | { |
| 294 | seq_puts(m, "\n\tShare Capabilities:"); |
| 295 | if (tcon->capabilities & SMB2_SHARE_CAP_DFS) |
| 296 | seq_puts(m, " DFS,"); |
| 297 | if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY) |
| 298 | seq_puts(m, " CONTINUOUS AVAILABILITY,"); |
| 299 | if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT) |
| 300 | seq_puts(m, " SCALEOUT,"); |
| 301 | if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER) |
| 302 | seq_puts(m, " CLUSTER,"); |
| 303 | if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC) |
| 304 | seq_puts(m, " ASYMMETRIC,"); |
| 305 | if (tcon->capabilities == 0) |
| 306 | seq_puts(m, " None"); |
| 307 | seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags); |
| 308 | } |
| 309 | |
| 310 | static void |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 311 | smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon) |
| 312 | { |
| 313 | #ifdef CONFIG_CIFS_STATS |
| 314 | atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent; |
| 315 | atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed; |
| 316 | seq_printf(m, "\nNegotiates: %d sent %d failed", |
| 317 | atomic_read(&sent[SMB2_NEGOTIATE_HE]), |
| 318 | atomic_read(&failed[SMB2_NEGOTIATE_HE])); |
| 319 | seq_printf(m, "\nSessionSetups: %d sent %d failed", |
| 320 | atomic_read(&sent[SMB2_SESSION_SETUP_HE]), |
| 321 | atomic_read(&failed[SMB2_SESSION_SETUP_HE])); |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 322 | seq_printf(m, "\nLogoffs: %d sent %d failed", |
| 323 | atomic_read(&sent[SMB2_LOGOFF_HE]), |
| 324 | atomic_read(&failed[SMB2_LOGOFF_HE])); |
| 325 | seq_printf(m, "\nTreeConnects: %d sent %d failed", |
| 326 | atomic_read(&sent[SMB2_TREE_CONNECT_HE]), |
| 327 | atomic_read(&failed[SMB2_TREE_CONNECT_HE])); |
| 328 | seq_printf(m, "\nTreeDisconnects: %d sent %d failed", |
| 329 | atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]), |
| 330 | atomic_read(&failed[SMB2_TREE_DISCONNECT_HE])); |
| 331 | seq_printf(m, "\nCreates: %d sent %d failed", |
| 332 | atomic_read(&sent[SMB2_CREATE_HE]), |
| 333 | atomic_read(&failed[SMB2_CREATE_HE])); |
| 334 | seq_printf(m, "\nCloses: %d sent %d failed", |
| 335 | atomic_read(&sent[SMB2_CLOSE_HE]), |
| 336 | atomic_read(&failed[SMB2_CLOSE_HE])); |
| 337 | seq_printf(m, "\nFlushes: %d sent %d failed", |
| 338 | atomic_read(&sent[SMB2_FLUSH_HE]), |
| 339 | atomic_read(&failed[SMB2_FLUSH_HE])); |
| 340 | seq_printf(m, "\nReads: %d sent %d failed", |
| 341 | atomic_read(&sent[SMB2_READ_HE]), |
| 342 | atomic_read(&failed[SMB2_READ_HE])); |
| 343 | seq_printf(m, "\nWrites: %d sent %d failed", |
| 344 | atomic_read(&sent[SMB2_WRITE_HE]), |
| 345 | atomic_read(&failed[SMB2_WRITE_HE])); |
| 346 | seq_printf(m, "\nLocks: %d sent %d failed", |
| 347 | atomic_read(&sent[SMB2_LOCK_HE]), |
| 348 | atomic_read(&failed[SMB2_LOCK_HE])); |
| 349 | seq_printf(m, "\nIOCTLs: %d sent %d failed", |
| 350 | atomic_read(&sent[SMB2_IOCTL_HE]), |
| 351 | atomic_read(&failed[SMB2_IOCTL_HE])); |
| 352 | seq_printf(m, "\nCancels: %d sent %d failed", |
| 353 | atomic_read(&sent[SMB2_CANCEL_HE]), |
| 354 | atomic_read(&failed[SMB2_CANCEL_HE])); |
| 355 | seq_printf(m, "\nEchos: %d sent %d failed", |
| 356 | atomic_read(&sent[SMB2_ECHO_HE]), |
| 357 | atomic_read(&failed[SMB2_ECHO_HE])); |
| 358 | seq_printf(m, "\nQueryDirectories: %d sent %d failed", |
| 359 | atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]), |
| 360 | atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE])); |
| 361 | seq_printf(m, "\nChangeNotifies: %d sent %d failed", |
| 362 | atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]), |
| 363 | atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE])); |
| 364 | seq_printf(m, "\nQueryInfos: %d sent %d failed", |
| 365 | atomic_read(&sent[SMB2_QUERY_INFO_HE]), |
| 366 | atomic_read(&failed[SMB2_QUERY_INFO_HE])); |
| 367 | seq_printf(m, "\nSetInfos: %d sent %d failed", |
| 368 | atomic_read(&sent[SMB2_SET_INFO_HE]), |
| 369 | atomic_read(&failed[SMB2_SET_INFO_HE])); |
| 370 | seq_printf(m, "\nOplockBreaks: %d sent %d failed", |
| 371 | atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]), |
| 372 | atomic_read(&failed[SMB2_OPLOCK_BREAK_HE])); |
| 373 | #endif |
| 374 | } |
| 375 | |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 376 | static void |
| 377 | smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock) |
| 378 | { |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 379 | struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 380 | struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; |
| 381 | |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 382 | cfile->fid.persistent_fid = fid->persistent_fid; |
| 383 | cfile->fid.volatile_fid = fid->volatile_fid; |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame^] | 384 | server->ops->set_oplock_level(cinode, oplock, fid->epoch, |
| 385 | &fid->purge_cache); |
Pavel Shilovsky | 18cceb6 | 2013-09-05 13:01:06 +0400 | [diff] [blame] | 386 | cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode); |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 387 | } |
| 388 | |
Pavel Shilovsky | 760ad0c | 2012-09-25 11:00:07 +0400 | [diff] [blame] | 389 | static void |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 390 | smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon, |
| 391 | struct cifs_fid *fid) |
| 392 | { |
Pavel Shilovsky | 760ad0c | 2012-09-25 11:00:07 +0400 | [diff] [blame] | 393 | SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 394 | } |
| 395 | |
Pavel Shilovsky | 7a5cfb1 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 396 | static int |
| 397 | smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon, |
| 398 | struct cifs_fid *fid) |
| 399 | { |
| 400 | return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
| 401 | } |
| 402 | |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 403 | static unsigned int |
| 404 | smb2_read_data_offset(char *buf) |
| 405 | { |
| 406 | struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf; |
| 407 | return rsp->DataOffset; |
| 408 | } |
| 409 | |
| 410 | static unsigned int |
| 411 | smb2_read_data_length(char *buf) |
| 412 | { |
| 413 | struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf; |
| 414 | return le32_to_cpu(rsp->DataLength); |
| 415 | } |
| 416 | |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 417 | |
| 418 | static int |
| 419 | smb2_sync_read(const unsigned int xid, struct cifsFileInfo *cfile, |
| 420 | struct cifs_io_parms *parms, unsigned int *bytes_read, |
| 421 | char **buf, int *buf_type) |
| 422 | { |
| 423 | parms->persistent_fid = cfile->fid.persistent_fid; |
| 424 | parms->volatile_fid = cfile->fid.volatile_fid; |
| 425 | return SMB2_read(xid, parms, bytes_read, buf, buf_type); |
| 426 | } |
| 427 | |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 428 | static int |
| 429 | smb2_sync_write(const unsigned int xid, struct cifsFileInfo *cfile, |
| 430 | struct cifs_io_parms *parms, unsigned int *written, |
| 431 | struct kvec *iov, unsigned long nr_segs) |
| 432 | { |
| 433 | |
| 434 | parms->persistent_fid = cfile->fid.persistent_fid; |
| 435 | parms->volatile_fid = cfile->fid.volatile_fid; |
| 436 | return SMB2_write(xid, parms, written, iov, nr_segs); |
| 437 | } |
| 438 | |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 439 | static int |
| 440 | smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon, |
| 441 | struct cifsFileInfo *cfile, __u64 size, bool set_alloc) |
| 442 | { |
| 443 | __le64 eof = cpu_to_le64(size); |
| 444 | return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, |
| 445 | cfile->fid.volatile_fid, cfile->pid, &eof); |
| 446 | } |
| 447 | |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 448 | static int |
| 449 | smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon, |
| 450 | const char *path, struct cifs_sb_info *cifs_sb, |
| 451 | struct cifs_fid *fid, __u16 search_flags, |
| 452 | struct cifs_search_info *srch_inf) |
| 453 | { |
| 454 | __le16 *utf16_path; |
| 455 | int rc; |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 456 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 457 | struct cifs_open_parms oparms; |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 458 | |
| 459 | utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); |
| 460 | if (!utf16_path) |
| 461 | return -ENOMEM; |
| 462 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 463 | oparms.tcon = tcon; |
| 464 | oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA; |
| 465 | oparms.disposition = FILE_OPEN; |
| 466 | oparms.create_options = 0; |
| 467 | oparms.fid = fid; |
Pavel Shilovsky | 9cbc0b7 | 2013-07-09 18:40:58 +0400 | [diff] [blame] | 468 | oparms.reconnect = false; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 469 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 470 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 471 | kfree(utf16_path); |
| 472 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 473 | cifs_dbg(VFS, "open dir failed\n"); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 474 | return rc; |
| 475 | } |
| 476 | |
| 477 | srch_inf->entries_in_buffer = 0; |
| 478 | srch_inf->index_of_last_entry = 0; |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 479 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 480 | rc = SMB2_query_directory(xid, tcon, fid->persistent_fid, |
| 481 | fid->volatile_fid, 0, srch_inf); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 482 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 483 | cifs_dbg(VFS, "query directory failed\n"); |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 484 | SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 485 | } |
| 486 | return rc; |
| 487 | } |
| 488 | |
| 489 | static int |
| 490 | smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon, |
| 491 | struct cifs_fid *fid, __u16 search_flags, |
| 492 | struct cifs_search_info *srch_inf) |
| 493 | { |
| 494 | return SMB2_query_directory(xid, tcon, fid->persistent_fid, |
| 495 | fid->volatile_fid, 0, srch_inf); |
| 496 | } |
| 497 | |
| 498 | static int |
| 499 | smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon, |
| 500 | struct cifs_fid *fid) |
| 501 | { |
| 502 | return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
| 503 | } |
| 504 | |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 505 | /* |
| 506 | * If we negotiate SMB2 protocol and get STATUS_PENDING - update |
| 507 | * the number of credits and return true. Otherwise - return false. |
| 508 | */ |
| 509 | static bool |
| 510 | smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length) |
| 511 | { |
| 512 | struct smb2_hdr *hdr = (struct smb2_hdr *)buf; |
| 513 | |
Steve French | 12e8a20 | 2012-09-19 09:19:39 -0700 | [diff] [blame] | 514 | if (hdr->Status != STATUS_PENDING) |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 515 | return false; |
| 516 | |
| 517 | if (!length) { |
| 518 | spin_lock(&server->req_lock); |
| 519 | server->credits += le16_to_cpu(hdr->CreditRequest); |
| 520 | spin_unlock(&server->req_lock); |
| 521 | wake_up(&server->request_q); |
| 522 | } |
| 523 | |
| 524 | return true; |
| 525 | } |
| 526 | |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 527 | static int |
| 528 | smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid, |
| 529 | struct cifsInodeInfo *cinode) |
| 530 | { |
Pavel Shilovsky | 0822f51 | 2012-09-19 06:22:45 -0700 | [diff] [blame] | 531 | if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING) |
| 532 | return SMB2_lease_break(0, tcon, cinode->lease_key, |
| 533 | smb2_get_lease_state(cinode)); |
| 534 | |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 535 | return SMB2_oplock_break(0, tcon, fid->persistent_fid, |
| 536 | fid->volatile_fid, |
Pavel Shilovsky | 18cceb6 | 2013-09-05 13:01:06 +0400 | [diff] [blame] | 537 | CIFS_CACHE_READ(cinode) ? 1 : 0); |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 538 | } |
| 539 | |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 540 | static int |
| 541 | smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon, |
| 542 | struct kstatfs *buf) |
| 543 | { |
| 544 | int rc; |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 545 | __le16 srch_path = 0; /* Null - open root of share */ |
| 546 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 547 | struct cifs_open_parms oparms; |
| 548 | struct cifs_fid fid; |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 549 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 550 | oparms.tcon = tcon; |
| 551 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 552 | oparms.disposition = FILE_OPEN; |
| 553 | oparms.create_options = 0; |
| 554 | oparms.fid = &fid; |
Pavel Shilovsky | 9cbc0b7 | 2013-07-09 18:40:58 +0400 | [diff] [blame] | 555 | oparms.reconnect = false; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 556 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 557 | rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL); |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 558 | if (rc) |
| 559 | return rc; |
| 560 | buf->f_type = SMB2_MAGIC_NUMBER; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 561 | rc = SMB2_QFS_info(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
| 562 | buf); |
| 563 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 564 | return rc; |
| 565 | } |
| 566 | |
Pavel Shilovsky | 027e8ee | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 567 | static bool |
| 568 | smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2) |
| 569 | { |
| 570 | return ob1->fid.persistent_fid == ob2->fid.persistent_fid && |
| 571 | ob1->fid.volatile_fid == ob2->fid.volatile_fid; |
| 572 | } |
| 573 | |
Pavel Shilovsky | f7ba7fe | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 574 | static int |
| 575 | smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset, |
| 576 | __u64 length, __u32 type, int lock, int unlock, bool wait) |
| 577 | { |
| 578 | if (unlock && !lock) |
| 579 | type = SMB2_LOCKFLAG_UNLOCK; |
| 580 | return SMB2_lock(xid, tlink_tcon(cfile->tlink), |
| 581 | cfile->fid.persistent_fid, cfile->fid.volatile_fid, |
| 582 | current->tgid, length, offset, type, wait); |
| 583 | } |
| 584 | |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 585 | static void |
| 586 | smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid) |
| 587 | { |
| 588 | memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE); |
| 589 | } |
| 590 | |
| 591 | static void |
| 592 | smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid) |
| 593 | { |
| 594 | memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE); |
| 595 | } |
| 596 | |
| 597 | static void |
| 598 | smb2_new_lease_key(struct cifs_fid *fid) |
| 599 | { |
| 600 | get_random_bytes(fid->lease_key, SMB2_LEASE_KEY_SIZE); |
| 601 | } |
| 602 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 603 | static int |
| 604 | smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon, |
| 605 | const char *full_path, char **target_path, |
| 606 | struct cifs_sb_info *cifs_sb) |
| 607 | { |
| 608 | int rc; |
| 609 | __le16 *utf16_path; |
| 610 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 611 | struct cifs_open_parms oparms; |
| 612 | struct cifs_fid fid; |
| 613 | struct smb2_err_rsp *err_buf = NULL; |
| 614 | struct smb2_symlink_err_rsp *symlink; |
| 615 | unsigned int sub_len, sub_offset; |
| 616 | |
| 617 | cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path); |
| 618 | |
| 619 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); |
| 620 | if (!utf16_path) |
| 621 | return -ENOMEM; |
| 622 | |
| 623 | oparms.tcon = tcon; |
| 624 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 625 | oparms.disposition = FILE_OPEN; |
| 626 | oparms.create_options = 0; |
| 627 | oparms.fid = &fid; |
| 628 | oparms.reconnect = false; |
| 629 | |
| 630 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_buf); |
| 631 | |
| 632 | if (!rc || !err_buf) { |
| 633 | kfree(utf16_path); |
| 634 | return -ENOENT; |
| 635 | } |
| 636 | /* open must fail on symlink - reset rc */ |
| 637 | rc = 0; |
| 638 | symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData; |
| 639 | sub_len = le16_to_cpu(symlink->SubstituteNameLength); |
| 640 | sub_offset = le16_to_cpu(symlink->SubstituteNameOffset); |
| 641 | *target_path = cifs_strndup_from_utf16( |
| 642 | (char *)symlink->PathBuffer + sub_offset, |
| 643 | sub_len, true, cifs_sb->local_nls); |
| 644 | if (!(*target_path)) { |
| 645 | kfree(utf16_path); |
| 646 | return -ENOMEM; |
| 647 | } |
| 648 | convert_delimiter(*target_path, '/'); |
| 649 | cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path); |
| 650 | kfree(utf16_path); |
| 651 | return rc; |
| 652 | } |
| 653 | |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 654 | static void |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame^] | 655 | smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock, |
| 656 | unsigned int epoch, bool *purge_cache) |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 657 | { |
| 658 | oplock &= 0xFF; |
| 659 | if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE) |
| 660 | return; |
| 661 | if (oplock == SMB2_OPLOCK_LEVEL_BATCH) { |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame^] | 662 | cinode->oplock = CIFS_CACHE_RHW_FLG; |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 663 | cifs_dbg(FYI, "Batch Oplock granted on inode %p\n", |
| 664 | &cinode->vfs_inode); |
| 665 | } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) { |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame^] | 666 | cinode->oplock = CIFS_CACHE_RW_FLG; |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 667 | cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n", |
| 668 | &cinode->vfs_inode); |
| 669 | } else if (oplock == SMB2_OPLOCK_LEVEL_II) { |
| 670 | cinode->oplock = CIFS_CACHE_READ_FLG; |
| 671 | cifs_dbg(FYI, "Level II Oplock granted on inode %p\n", |
| 672 | &cinode->vfs_inode); |
| 673 | } else |
| 674 | cinode->oplock = 0; |
| 675 | } |
| 676 | |
| 677 | static void |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame^] | 678 | smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock, |
| 679 | unsigned int epoch, bool *purge_cache) |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 680 | { |
| 681 | char message[5] = {0}; |
| 682 | |
| 683 | oplock &= 0xFF; |
| 684 | if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE) |
| 685 | return; |
| 686 | |
| 687 | cinode->oplock = 0; |
| 688 | if (oplock & SMB2_LEASE_READ_CACHING_HE) { |
| 689 | cinode->oplock |= CIFS_CACHE_READ_FLG; |
| 690 | strcat(message, "R"); |
| 691 | } |
| 692 | if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) { |
| 693 | cinode->oplock |= CIFS_CACHE_HANDLE_FLG; |
| 694 | strcat(message, "H"); |
| 695 | } |
| 696 | if (oplock & SMB2_LEASE_WRITE_CACHING_HE) { |
| 697 | cinode->oplock |= CIFS_CACHE_WRITE_FLG; |
| 698 | strcat(message, "W"); |
| 699 | } |
| 700 | if (!cinode->oplock) |
| 701 | strcat(message, "None"); |
| 702 | cifs_dbg(FYI, "%s Lease granted on inode %p\n", message, |
| 703 | &cinode->vfs_inode); |
| 704 | } |
| 705 | |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame^] | 706 | static void |
| 707 | smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock, |
| 708 | unsigned int epoch, bool *purge_cache) |
| 709 | { |
| 710 | unsigned int old_oplock = cinode->oplock; |
| 711 | |
| 712 | smb21_set_oplock_level(cinode, oplock, epoch, purge_cache); |
| 713 | |
| 714 | if (purge_cache) { |
| 715 | *purge_cache = false; |
| 716 | if (old_oplock == CIFS_CACHE_READ_FLG) { |
| 717 | if (cinode->oplock == CIFS_CACHE_READ_FLG && |
| 718 | (epoch - cinode->epoch > 0)) |
| 719 | *purge_cache = true; |
| 720 | else if (cinode->oplock == CIFS_CACHE_RH_FLG && |
| 721 | (epoch - cinode->epoch > 1)) |
| 722 | *purge_cache = true; |
| 723 | else if (cinode->oplock == CIFS_CACHE_RHW_FLG && |
| 724 | (epoch - cinode->epoch > 1)) |
| 725 | *purge_cache = true; |
| 726 | else if (cinode->oplock == 0 && |
| 727 | (epoch - cinode->epoch > 0)) |
| 728 | *purge_cache = true; |
| 729 | } else if (old_oplock == CIFS_CACHE_RH_FLG) { |
| 730 | if (cinode->oplock == CIFS_CACHE_RH_FLG && |
| 731 | (epoch - cinode->epoch > 0)) |
| 732 | *purge_cache = true; |
| 733 | else if (cinode->oplock == CIFS_CACHE_RHW_FLG && |
| 734 | (epoch - cinode->epoch > 1)) |
| 735 | *purge_cache = true; |
| 736 | } |
| 737 | cinode->epoch = epoch; |
| 738 | } |
| 739 | } |
| 740 | |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 741 | static bool |
| 742 | smb2_is_read_op(__u32 oplock) |
| 743 | { |
| 744 | return oplock == SMB2_OPLOCK_LEVEL_II; |
| 745 | } |
| 746 | |
| 747 | static bool |
| 748 | smb21_is_read_op(__u32 oplock) |
| 749 | { |
| 750 | return (oplock & SMB2_LEASE_READ_CACHING_HE) && |
| 751 | !(oplock & SMB2_LEASE_WRITE_CACHING_HE); |
| 752 | } |
| 753 | |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 754 | static __le32 |
| 755 | map_oplock_to_lease(u8 oplock) |
| 756 | { |
| 757 | if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) |
| 758 | return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING; |
| 759 | else if (oplock == SMB2_OPLOCK_LEVEL_II) |
| 760 | return SMB2_LEASE_READ_CACHING; |
| 761 | else if (oplock == SMB2_OPLOCK_LEVEL_BATCH) |
| 762 | return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING | |
| 763 | SMB2_LEASE_WRITE_CACHING; |
| 764 | return 0; |
| 765 | } |
| 766 | |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 767 | static char * |
| 768 | smb2_create_lease_buf(u8 *lease_key, u8 oplock) |
| 769 | { |
| 770 | struct create_lease *buf; |
| 771 | |
| 772 | buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL); |
| 773 | if (!buf) |
| 774 | return NULL; |
| 775 | |
| 776 | buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key)); |
| 777 | buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8))); |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 778 | buf->lcontext.LeaseState = map_oplock_to_lease(oplock); |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 779 | |
| 780 | buf->ccontext.DataOffset = cpu_to_le16(offsetof |
| 781 | (struct create_lease, lcontext)); |
| 782 | buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context)); |
| 783 | buf->ccontext.NameOffset = cpu_to_le16(offsetof |
| 784 | (struct create_lease, Name)); |
| 785 | buf->ccontext.NameLength = cpu_to_le16(4); |
| 786 | buf->Name[0] = 'R'; |
| 787 | buf->Name[1] = 'q'; |
| 788 | buf->Name[2] = 'L'; |
| 789 | buf->Name[3] = 's'; |
| 790 | return (char *)buf; |
| 791 | } |
| 792 | |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 793 | static char * |
| 794 | smb3_create_lease_buf(u8 *lease_key, u8 oplock) |
| 795 | { |
| 796 | struct create_lease_v2 *buf; |
| 797 | |
| 798 | buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL); |
| 799 | if (!buf) |
| 800 | return NULL; |
| 801 | |
| 802 | buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key)); |
| 803 | buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8))); |
| 804 | buf->lcontext.LeaseState = map_oplock_to_lease(oplock); |
| 805 | |
| 806 | buf->ccontext.DataOffset = cpu_to_le16(offsetof |
| 807 | (struct create_lease_v2, lcontext)); |
| 808 | buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2)); |
| 809 | buf->ccontext.NameOffset = cpu_to_le16(offsetof |
| 810 | (struct create_lease_v2, Name)); |
| 811 | buf->ccontext.NameLength = cpu_to_le16(4); |
| 812 | buf->Name[0] = 'R'; |
| 813 | buf->Name[1] = 'q'; |
| 814 | buf->Name[2] = 'L'; |
| 815 | buf->Name[3] = 's'; |
| 816 | return (char *)buf; |
| 817 | } |
| 818 | |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 819 | static __u8 |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame^] | 820 | smb2_parse_lease_buf(void *buf, unsigned int *epoch) |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 821 | { |
| 822 | struct create_lease *lc = (struct create_lease *)buf; |
| 823 | |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame^] | 824 | *epoch = 0; /* not used */ |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 825 | if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS) |
| 826 | return SMB2_OPLOCK_LEVEL_NOCHANGE; |
| 827 | return le32_to_cpu(lc->lcontext.LeaseState); |
| 828 | } |
| 829 | |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 830 | static __u8 |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame^] | 831 | smb3_parse_lease_buf(void *buf, unsigned int *epoch) |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 832 | { |
| 833 | struct create_lease_v2 *lc = (struct create_lease_v2 *)buf; |
| 834 | |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame^] | 835 | *epoch = le16_to_cpu(lc->lcontext.Epoch); |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 836 | if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS) |
| 837 | return SMB2_OPLOCK_LEVEL_NOCHANGE; |
| 838 | return le32_to_cpu(lc->lcontext.LeaseState); |
| 839 | } |
| 840 | |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 841 | struct smb_version_operations smb20_operations = { |
| 842 | .compare_fids = smb2_compare_fids, |
| 843 | .setup_request = smb2_setup_request, |
| 844 | .setup_async_request = smb2_setup_async_request, |
| 845 | .check_receive = smb2_check_receive, |
| 846 | .add_credits = smb2_add_credits, |
| 847 | .set_credits = smb2_set_credits, |
| 848 | .get_credits_field = smb2_get_credits_field, |
| 849 | .get_credits = smb2_get_credits, |
| 850 | .get_next_mid = smb2_get_next_mid, |
| 851 | .read_data_offset = smb2_read_data_offset, |
| 852 | .read_data_length = smb2_read_data_length, |
| 853 | .map_error = map_smb2_to_linux_error, |
| 854 | .find_mid = smb2_find_mid, |
| 855 | .check_message = smb2_check_message, |
| 856 | .dump_detail = smb2_dump_detail, |
| 857 | .clear_stats = smb2_clear_stats, |
| 858 | .print_stats = smb2_print_stats, |
| 859 | .is_oplock_break = smb2_is_valid_oplock_break, |
| 860 | .need_neg = smb2_need_neg, |
| 861 | .negotiate = smb2_negotiate, |
| 862 | .negotiate_wsize = smb2_negotiate_wsize, |
| 863 | .negotiate_rsize = smb2_negotiate_rsize, |
| 864 | .sess_setup = SMB2_sess_setup, |
| 865 | .logoff = SMB2_logoff, |
| 866 | .tree_connect = SMB2_tcon, |
| 867 | .tree_disconnect = SMB2_tdis, |
| 868 | .is_path_accessible = smb2_is_path_accessible, |
| 869 | .can_echo = smb2_can_echo, |
| 870 | .echo = SMB2_echo, |
| 871 | .query_path_info = smb2_query_path_info, |
| 872 | .get_srv_inum = smb2_get_srv_inum, |
| 873 | .query_file_info = smb2_query_file_info, |
| 874 | .set_path_size = smb2_set_path_size, |
| 875 | .set_file_size = smb2_set_file_size, |
| 876 | .set_file_info = smb2_set_file_info, |
| 877 | .mkdir = smb2_mkdir, |
| 878 | .mkdir_setinfo = smb2_mkdir_setinfo, |
| 879 | .rmdir = smb2_rmdir, |
| 880 | .unlink = smb2_unlink, |
| 881 | .rename = smb2_rename_path, |
| 882 | .create_hardlink = smb2_create_hardlink, |
| 883 | .query_symlink = smb2_query_symlink, |
| 884 | .open = smb2_open_file, |
| 885 | .set_fid = smb2_set_fid, |
| 886 | .close = smb2_close_file, |
| 887 | .flush = smb2_flush_file, |
| 888 | .async_readv = smb2_async_readv, |
| 889 | .async_writev = smb2_async_writev, |
| 890 | .sync_read = smb2_sync_read, |
| 891 | .sync_write = smb2_sync_write, |
| 892 | .query_dir_first = smb2_query_dir_first, |
| 893 | .query_dir_next = smb2_query_dir_next, |
| 894 | .close_dir = smb2_close_dir, |
| 895 | .calc_smb_size = smb2_calc_size, |
| 896 | .is_status_pending = smb2_is_status_pending, |
| 897 | .oplock_response = smb2_oplock_response, |
| 898 | .queryfs = smb2_queryfs, |
| 899 | .mand_lock = smb2_mand_lock, |
| 900 | .mand_unlock_range = smb2_unlock_range, |
| 901 | .push_mand_locks = smb2_push_mandatory_locks, |
| 902 | .get_lease_key = smb2_get_lease_key, |
| 903 | .set_lease_key = smb2_set_lease_key, |
| 904 | .new_lease_key = smb2_new_lease_key, |
| 905 | .calc_signature = smb2_calc_signature, |
| 906 | .is_read_op = smb2_is_read_op, |
| 907 | .set_oplock_level = smb2_set_oplock_level, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 908 | .create_lease_buf = smb2_create_lease_buf, |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 909 | .parse_lease_buf = smb2_parse_lease_buf, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 910 | }; |
| 911 | |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 912 | struct smb_version_operations smb21_operations = { |
Pavel Shilovsky | 027e8ee | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 913 | .compare_fids = smb2_compare_fids, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 914 | .setup_request = smb2_setup_request, |
Pavel Shilovsky | c95b8ee | 2012-07-11 14:45:28 +0400 | [diff] [blame] | 915 | .setup_async_request = smb2_setup_async_request, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 916 | .check_receive = smb2_check_receive, |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 917 | .add_credits = smb2_add_credits, |
| 918 | .set_credits = smb2_set_credits, |
| 919 | .get_credits_field = smb2_get_credits_field, |
| 920 | .get_credits = smb2_get_credits, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 921 | .get_next_mid = smb2_get_next_mid, |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 922 | .read_data_offset = smb2_read_data_offset, |
| 923 | .read_data_length = smb2_read_data_length, |
| 924 | .map_error = map_smb2_to_linux_error, |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 925 | .find_mid = smb2_find_mid, |
| 926 | .check_message = smb2_check_message, |
| 927 | .dump_detail = smb2_dump_detail, |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 928 | .clear_stats = smb2_clear_stats, |
| 929 | .print_stats = smb2_print_stats, |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 930 | .is_oplock_break = smb2_is_valid_oplock_break, |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 931 | .need_neg = smb2_need_neg, |
| 932 | .negotiate = smb2_negotiate, |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 933 | .negotiate_wsize = smb2_negotiate_wsize, |
| 934 | .negotiate_rsize = smb2_negotiate_rsize, |
Pavel Shilovsky | 5478f9b | 2011-12-27 16:22:00 +0400 | [diff] [blame] | 935 | .sess_setup = SMB2_sess_setup, |
| 936 | .logoff = SMB2_logoff, |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 937 | .tree_connect = SMB2_tcon, |
| 938 | .tree_disconnect = SMB2_tdis, |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 939 | .is_path_accessible = smb2_is_path_accessible, |
Pavel Shilovsky | 9094fad | 2012-07-12 18:30:44 +0400 | [diff] [blame] | 940 | .can_echo = smb2_can_echo, |
| 941 | .echo = SMB2_echo, |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 942 | .query_path_info = smb2_query_path_info, |
| 943 | .get_srv_inum = smb2_get_srv_inum, |
Pavel Shilovsky | b7546bc | 2012-09-18 16:20:27 -0700 | [diff] [blame] | 944 | .query_file_info = smb2_query_file_info, |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 945 | .set_path_size = smb2_set_path_size, |
| 946 | .set_file_size = smb2_set_file_size, |
Pavel Shilovsky | 1feeaac | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 947 | .set_file_info = smb2_set_file_info, |
Pavel Shilovsky | a0e7318 | 2011-07-19 12:56:37 +0400 | [diff] [blame] | 948 | .mkdir = smb2_mkdir, |
| 949 | .mkdir_setinfo = smb2_mkdir_setinfo, |
Pavel Shilovsky | 1a500f0 | 2012-07-10 16:14:38 +0400 | [diff] [blame] | 950 | .rmdir = smb2_rmdir, |
Pavel Shilovsky | cbe6f43 | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 951 | .unlink = smb2_unlink, |
Pavel Shilovsky | 35143eb | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 952 | .rename = smb2_rename_path, |
Pavel Shilovsky | 568798c | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 953 | .create_hardlink = smb2_create_hardlink, |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 954 | .query_symlink = smb2_query_symlink, |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 955 | .open = smb2_open_file, |
| 956 | .set_fid = smb2_set_fid, |
| 957 | .close = smb2_close_file, |
Pavel Shilovsky | 7a5cfb1 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 958 | .flush = smb2_flush_file, |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 959 | .async_readv = smb2_async_readv, |
Pavel Shilovsky | 3331914 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 960 | .async_writev = smb2_async_writev, |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 961 | .sync_read = smb2_sync_read, |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 962 | .sync_write = smb2_sync_write, |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 963 | .query_dir_first = smb2_query_dir_first, |
| 964 | .query_dir_next = smb2_query_dir_next, |
| 965 | .close_dir = smb2_close_dir, |
| 966 | .calc_smb_size = smb2_calc_size, |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 967 | .is_status_pending = smb2_is_status_pending, |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 968 | .oplock_response = smb2_oplock_response, |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 969 | .queryfs = smb2_queryfs, |
Pavel Shilovsky | f7ba7fe | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 970 | .mand_lock = smb2_mand_lock, |
| 971 | .mand_unlock_range = smb2_unlock_range, |
Pavel Shilovsky | b140799 | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 972 | .push_mand_locks = smb2_push_mandatory_locks, |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 973 | .get_lease_key = smb2_get_lease_key, |
| 974 | .set_lease_key = smb2_set_lease_key, |
| 975 | .new_lease_key = smb2_new_lease_key, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 976 | .calc_signature = smb2_calc_signature, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 977 | .is_read_op = smb21_is_read_op, |
| 978 | .set_oplock_level = smb21_set_oplock_level, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 979 | .create_lease_buf = smb2_create_lease_buf, |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 980 | .parse_lease_buf = smb2_parse_lease_buf, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 981 | }; |
| 982 | |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 983 | struct smb_version_operations smb30_operations = { |
| 984 | .compare_fids = smb2_compare_fids, |
| 985 | .setup_request = smb2_setup_request, |
| 986 | .setup_async_request = smb2_setup_async_request, |
| 987 | .check_receive = smb2_check_receive, |
| 988 | .add_credits = smb2_add_credits, |
| 989 | .set_credits = smb2_set_credits, |
| 990 | .get_credits_field = smb2_get_credits_field, |
| 991 | .get_credits = smb2_get_credits, |
| 992 | .get_next_mid = smb2_get_next_mid, |
| 993 | .read_data_offset = smb2_read_data_offset, |
| 994 | .read_data_length = smb2_read_data_length, |
| 995 | .map_error = map_smb2_to_linux_error, |
| 996 | .find_mid = smb2_find_mid, |
| 997 | .check_message = smb2_check_message, |
| 998 | .dump_detail = smb2_dump_detail, |
| 999 | .clear_stats = smb2_clear_stats, |
| 1000 | .print_stats = smb2_print_stats, |
Steve French | 769ee6a | 2013-06-19 14:15:30 -0500 | [diff] [blame] | 1001 | .dump_share_caps = smb2_dump_share_caps, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 1002 | .is_oplock_break = smb2_is_valid_oplock_break, |
| 1003 | .need_neg = smb2_need_neg, |
| 1004 | .negotiate = smb2_negotiate, |
| 1005 | .negotiate_wsize = smb2_negotiate_wsize, |
| 1006 | .negotiate_rsize = smb2_negotiate_rsize, |
| 1007 | .sess_setup = SMB2_sess_setup, |
| 1008 | .logoff = SMB2_logoff, |
| 1009 | .tree_connect = SMB2_tcon, |
| 1010 | .tree_disconnect = SMB2_tdis, |
| 1011 | .is_path_accessible = smb2_is_path_accessible, |
| 1012 | .can_echo = smb2_can_echo, |
| 1013 | .echo = SMB2_echo, |
| 1014 | .query_path_info = smb2_query_path_info, |
| 1015 | .get_srv_inum = smb2_get_srv_inum, |
| 1016 | .query_file_info = smb2_query_file_info, |
| 1017 | .set_path_size = smb2_set_path_size, |
| 1018 | .set_file_size = smb2_set_file_size, |
| 1019 | .set_file_info = smb2_set_file_info, |
| 1020 | .mkdir = smb2_mkdir, |
| 1021 | .mkdir_setinfo = smb2_mkdir_setinfo, |
| 1022 | .rmdir = smb2_rmdir, |
| 1023 | .unlink = smb2_unlink, |
| 1024 | .rename = smb2_rename_path, |
| 1025 | .create_hardlink = smb2_create_hardlink, |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 1026 | .query_symlink = smb2_query_symlink, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 1027 | .open = smb2_open_file, |
| 1028 | .set_fid = smb2_set_fid, |
| 1029 | .close = smb2_close_file, |
| 1030 | .flush = smb2_flush_file, |
| 1031 | .async_readv = smb2_async_readv, |
| 1032 | .async_writev = smb2_async_writev, |
| 1033 | .sync_read = smb2_sync_read, |
| 1034 | .sync_write = smb2_sync_write, |
| 1035 | .query_dir_first = smb2_query_dir_first, |
| 1036 | .query_dir_next = smb2_query_dir_next, |
| 1037 | .close_dir = smb2_close_dir, |
| 1038 | .calc_smb_size = smb2_calc_size, |
| 1039 | .is_status_pending = smb2_is_status_pending, |
| 1040 | .oplock_response = smb2_oplock_response, |
| 1041 | .queryfs = smb2_queryfs, |
| 1042 | .mand_lock = smb2_mand_lock, |
| 1043 | .mand_unlock_range = smb2_unlock_range, |
| 1044 | .push_mand_locks = smb2_push_mandatory_locks, |
| 1045 | .get_lease_key = smb2_get_lease_key, |
| 1046 | .set_lease_key = smb2_set_lease_key, |
| 1047 | .new_lease_key = smb2_new_lease_key, |
Steve French | e65a5cb | 2013-06-27 01:06:50 -0500 | [diff] [blame] | 1048 | .generate_signingkey = generate_smb3signingkey, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 1049 | .calc_signature = smb3_calc_signature, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1050 | .is_read_op = smb21_is_read_op, |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame^] | 1051 | .set_oplock_level = smb3_set_oplock_level, |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1052 | .create_lease_buf = smb3_create_lease_buf, |
| 1053 | .parse_lease_buf = smb3_parse_lease_buf, |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 1054 | }; |
| 1055 | |
Steve French | dd446b1 | 2012-11-28 23:21:06 -0600 | [diff] [blame] | 1056 | struct smb_version_values smb20_values = { |
| 1057 | .version_string = SMB20_VERSION_STRING, |
| 1058 | .protocol_id = SMB20_PROT_ID, |
| 1059 | .req_capabilities = 0, /* MBZ */ |
| 1060 | .large_lock_type = 0, |
| 1061 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 1062 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 1063 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
| 1064 | .header_size = sizeof(struct smb2_hdr), |
| 1065 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 1066 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 1067 | .lock_cmd = SMB2_LOCK, |
| 1068 | .cap_unix = 0, |
| 1069 | .cap_nt_find = SMB2_NT_FIND, |
| 1070 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 5028588 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 1071 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 1072 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 1073 | .create_lease_size = sizeof(struct create_lease), |
Steve French | dd446b1 | 2012-11-28 23:21:06 -0600 | [diff] [blame] | 1074 | }; |
| 1075 | |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 1076 | struct smb_version_values smb21_values = { |
| 1077 | .version_string = SMB21_VERSION_STRING, |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 1078 | .protocol_id = SMB21_PROT_ID, |
| 1079 | .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */ |
| 1080 | .large_lock_type = 0, |
| 1081 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 1082 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 1083 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
| 1084 | .header_size = sizeof(struct smb2_hdr), |
| 1085 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 1086 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 1087 | .lock_cmd = SMB2_LOCK, |
| 1088 | .cap_unix = 0, |
| 1089 | .cap_nt_find = SMB2_NT_FIND, |
| 1090 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 5028588 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 1091 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 1092 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 1093 | .create_lease_size = sizeof(struct create_lease), |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 1094 | }; |
| 1095 | |
| 1096 | struct smb_version_values smb30_values = { |
| 1097 | .version_string = SMB30_VERSION_STRING, |
| 1098 | .protocol_id = SMB30_PROT_ID, |
| 1099 | .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU, |
Pavel Shilovsky | 027e8ee | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 1100 | .large_lock_type = 0, |
| 1101 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 1102 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 1103 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 1104 | .header_size = sizeof(struct smb2_hdr), |
| 1105 | .max_header_size = MAX_SMB2_HDR_SIZE, |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1106 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 1107 | .lock_cmd = SMB2_LOCK, |
Pavel Shilovsky | 29e20f9 | 2012-07-13 13:58:14 +0400 | [diff] [blame] | 1108 | .cap_unix = 0, |
| 1109 | .cap_nt_find = SMB2_NT_FIND, |
| 1110 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 5028588 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 1111 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 1112 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1113 | .create_lease_size = sizeof(struct create_lease_v2), |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 1114 | }; |
Steve French | 20b6d8b | 2013-06-12 22:48:41 -0500 | [diff] [blame] | 1115 | |
| 1116 | struct smb_version_values smb302_values = { |
| 1117 | .version_string = SMB302_VERSION_STRING, |
| 1118 | .protocol_id = SMB302_PROT_ID, |
| 1119 | .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU, |
| 1120 | .large_lock_type = 0, |
| 1121 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 1122 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 1123 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
| 1124 | .header_size = sizeof(struct smb2_hdr), |
| 1125 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 1126 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 1127 | .lock_cmd = SMB2_LOCK, |
| 1128 | .cap_unix = 0, |
| 1129 | .cap_nt_find = SMB2_NT_FIND, |
| 1130 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 5028588 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 1131 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 1132 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1133 | .create_lease_size = sizeof(struct create_lease_v2), |
Steve French | 20b6d8b | 2013-06-12 22:48:41 -0500 | [diff] [blame] | 1134 | }; |