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 | |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 115 | static int |
| 116 | smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size, |
| 117 | unsigned int *num, unsigned int *credits) |
| 118 | { |
| 119 | int rc = 0; |
| 120 | unsigned int scredits; |
| 121 | |
| 122 | spin_lock(&server->req_lock); |
| 123 | while (1) { |
| 124 | if (server->credits <= 0) { |
| 125 | spin_unlock(&server->req_lock); |
| 126 | cifs_num_waiters_inc(server); |
| 127 | rc = wait_event_killable(server->request_q, |
| 128 | has_credits(server, &server->credits)); |
| 129 | cifs_num_waiters_dec(server); |
| 130 | if (rc) |
| 131 | return rc; |
| 132 | spin_lock(&server->req_lock); |
| 133 | } else { |
| 134 | if (server->tcpStatus == CifsExiting) { |
| 135 | spin_unlock(&server->req_lock); |
| 136 | return -ENOENT; |
| 137 | } |
| 138 | |
| 139 | scredits = server->credits; |
| 140 | /* can deadlock with reopen */ |
| 141 | if (scredits == 1) { |
| 142 | *num = SMB2_MAX_BUFFER_SIZE; |
| 143 | *credits = 0; |
| 144 | break; |
| 145 | } |
| 146 | |
| 147 | /* leave one credit for a possible reopen */ |
| 148 | scredits--; |
| 149 | *num = min_t(unsigned int, size, |
| 150 | scredits * SMB2_MAX_BUFFER_SIZE); |
| 151 | |
| 152 | *credits = DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE); |
| 153 | server->credits -= *credits; |
| 154 | server->in_flight++; |
| 155 | break; |
| 156 | } |
| 157 | } |
| 158 | spin_unlock(&server->req_lock); |
| 159 | return rc; |
| 160 | } |
| 161 | |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 162 | static __u64 |
| 163 | smb2_get_next_mid(struct TCP_Server_Info *server) |
| 164 | { |
| 165 | __u64 mid; |
| 166 | /* for SMB2 we need the current value */ |
| 167 | spin_lock(&GlobalMid_Lock); |
| 168 | mid = server->CurrentMid++; |
| 169 | spin_unlock(&GlobalMid_Lock); |
| 170 | return mid; |
| 171 | } |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 172 | |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 173 | static struct mid_q_entry * |
| 174 | smb2_find_mid(struct TCP_Server_Info *server, char *buf) |
| 175 | { |
| 176 | struct mid_q_entry *mid; |
| 177 | struct smb2_hdr *hdr = (struct smb2_hdr *)buf; |
| 178 | |
| 179 | spin_lock(&GlobalMid_Lock); |
| 180 | list_for_each_entry(mid, &server->pending_mid_q, qhead) { |
| 181 | if ((mid->mid == hdr->MessageId) && |
| 182 | (mid->mid_state == MID_REQUEST_SUBMITTED) && |
| 183 | (mid->command == hdr->Command)) { |
| 184 | spin_unlock(&GlobalMid_Lock); |
| 185 | return mid; |
| 186 | } |
| 187 | } |
| 188 | spin_unlock(&GlobalMid_Lock); |
| 189 | return NULL; |
| 190 | } |
| 191 | |
| 192 | static void |
| 193 | smb2_dump_detail(void *buf) |
| 194 | { |
| 195 | #ifdef CONFIG_CIFS_DEBUG2 |
| 196 | struct smb2_hdr *smb = (struct smb2_hdr *)buf; |
| 197 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 198 | cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n", |
| 199 | smb->Command, smb->Status, smb->Flags, smb->MessageId, |
| 200 | smb->ProcessId); |
| 201 | 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] | 202 | #endif |
| 203 | } |
| 204 | |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 205 | static bool |
| 206 | smb2_need_neg(struct TCP_Server_Info *server) |
| 207 | { |
| 208 | return server->max_read == 0; |
| 209 | } |
| 210 | |
| 211 | static int |
| 212 | smb2_negotiate(const unsigned int xid, struct cifs_ses *ses) |
| 213 | { |
| 214 | int rc; |
| 215 | ses->server->CurrentMid = 0; |
| 216 | rc = SMB2_negotiate(xid, ses); |
| 217 | /* BB we probably don't need to retry with modern servers */ |
| 218 | if (rc == -EAGAIN) |
| 219 | rc = -EHOSTDOWN; |
| 220 | return rc; |
| 221 | } |
| 222 | |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 223 | static unsigned int |
| 224 | smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) |
| 225 | { |
| 226 | struct TCP_Server_Info *server = tcon->ses->server; |
| 227 | unsigned int wsize; |
| 228 | |
| 229 | /* start with specified wsize, or default */ |
| 230 | wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE; |
| 231 | wsize = min_t(unsigned int, wsize, server->max_write); |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 232 | |
| 233 | if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU)) |
| 234 | wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE); |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 235 | |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 236 | return wsize; |
| 237 | } |
| 238 | |
| 239 | static unsigned int |
| 240 | smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) |
| 241 | { |
| 242 | struct TCP_Server_Info *server = tcon->ses->server; |
| 243 | unsigned int rsize; |
| 244 | |
| 245 | /* start with specified rsize, or default */ |
| 246 | rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE; |
| 247 | rsize = min_t(unsigned int, rsize, server->max_read); |
Pavel Shilovsky | bed9da0 | 2014-06-25 11:28:57 +0400 | [diff] [blame^] | 248 | |
| 249 | if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU)) |
| 250 | rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE); |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 251 | |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 252 | return rsize; |
| 253 | } |
| 254 | |
Steve French | c481e9f | 2013-10-14 01:21:53 -0500 | [diff] [blame] | 255 | #ifdef CONFIG_CIFS_STATS2 |
| 256 | static int |
| 257 | SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon) |
| 258 | { |
| 259 | int rc; |
| 260 | unsigned int ret_data_len = 0; |
| 261 | struct network_interface_info_ioctl_rsp *out_buf; |
| 262 | |
| 263 | rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID, |
| 264 | FSCTL_QUERY_NETWORK_INTERFACE_INFO, true /* is_fsctl */, |
| 265 | NULL /* no data input */, 0 /* no data input */, |
| 266 | (char **)&out_buf, &ret_data_len); |
| 267 | |
| 268 | if ((rc == 0) && (ret_data_len > 0)) { |
| 269 | /* Dump info on first interface */ |
| 270 | cifs_dbg(FYI, "Adapter Capability 0x%x\t", |
| 271 | le32_to_cpu(out_buf->Capability)); |
| 272 | cifs_dbg(FYI, "Link Speed %lld\n", |
| 273 | le64_to_cpu(out_buf->LinkSpeed)); |
| 274 | } else |
| 275 | cifs_dbg(VFS, "error %d on ioctl to get interface list\n", rc); |
| 276 | |
| 277 | return rc; |
| 278 | } |
| 279 | #endif /* STATS2 */ |
| 280 | |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 281 | static void |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 282 | smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon) |
| 283 | { |
| 284 | int rc; |
| 285 | __le16 srch_path = 0; /* Null - open root of share */ |
| 286 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 287 | struct cifs_open_parms oparms; |
| 288 | struct cifs_fid fid; |
| 289 | |
| 290 | oparms.tcon = tcon; |
| 291 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 292 | oparms.disposition = FILE_OPEN; |
| 293 | oparms.create_options = 0; |
| 294 | oparms.fid = &fid; |
| 295 | oparms.reconnect = false; |
| 296 | |
| 297 | rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL); |
| 298 | if (rc) |
| 299 | return; |
| 300 | |
Steve French | c481e9f | 2013-10-14 01:21:53 -0500 | [diff] [blame] | 301 | #ifdef CONFIG_CIFS_STATS2 |
| 302 | SMB3_request_interfaces(xid, tcon); |
| 303 | #endif /* STATS2 */ |
| 304 | |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 305 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
| 306 | FS_ATTRIBUTE_INFORMATION); |
| 307 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
| 308 | FS_DEVICE_INFORMATION); |
| 309 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
| 310 | FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */ |
| 311 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
| 312 | return; |
| 313 | } |
| 314 | |
| 315 | static void |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 316 | smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon) |
| 317 | { |
| 318 | int rc; |
| 319 | __le16 srch_path = 0; /* Null - open root of share */ |
| 320 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 321 | struct cifs_open_parms oparms; |
| 322 | struct cifs_fid fid; |
| 323 | |
| 324 | oparms.tcon = tcon; |
| 325 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 326 | oparms.disposition = FILE_OPEN; |
| 327 | oparms.create_options = 0; |
| 328 | oparms.fid = &fid; |
| 329 | oparms.reconnect = false; |
| 330 | |
| 331 | rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL); |
| 332 | if (rc) |
| 333 | return; |
| 334 | |
Steven French | 2167114 | 2013-10-09 13:36:35 -0500 | [diff] [blame] | 335 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
| 336 | FS_ATTRIBUTE_INFORMATION); |
| 337 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
| 338 | FS_DEVICE_INFORMATION); |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 339 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
| 340 | return; |
| 341 | } |
| 342 | |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 343 | static int |
| 344 | smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon, |
| 345 | struct cifs_sb_info *cifs_sb, const char *full_path) |
| 346 | { |
| 347 | int rc; |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 348 | __le16 *utf16_path; |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 349 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 350 | struct cifs_open_parms oparms; |
| 351 | struct cifs_fid fid; |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 352 | |
| 353 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); |
| 354 | if (!utf16_path) |
| 355 | return -ENOMEM; |
| 356 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 357 | oparms.tcon = tcon; |
| 358 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 359 | oparms.disposition = FILE_OPEN; |
| 360 | oparms.create_options = 0; |
| 361 | oparms.fid = &fid; |
Pavel Shilovsky | 9cbc0b7 | 2013-07-09 18:40:58 +0400 | [diff] [blame] | 362 | oparms.reconnect = false; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 363 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 364 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL); |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 365 | if (rc) { |
| 366 | kfree(utf16_path); |
| 367 | return rc; |
| 368 | } |
| 369 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 370 | rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 371 | kfree(utf16_path); |
| 372 | return rc; |
| 373 | } |
| 374 | |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 375 | static int |
| 376 | smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon, |
| 377 | struct cifs_sb_info *cifs_sb, const char *full_path, |
| 378 | u64 *uniqueid, FILE_ALL_INFO *data) |
| 379 | { |
| 380 | *uniqueid = le64_to_cpu(data->IndexNumber); |
| 381 | return 0; |
| 382 | } |
| 383 | |
Pavel Shilovsky | b7546bc | 2012-09-18 16:20:27 -0700 | [diff] [blame] | 384 | static int |
| 385 | smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon, |
| 386 | struct cifs_fid *fid, FILE_ALL_INFO *data) |
| 387 | { |
| 388 | int rc; |
| 389 | struct smb2_file_all_info *smb2_data; |
| 390 | |
| 391 | smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + MAX_NAME * 2, |
| 392 | GFP_KERNEL); |
| 393 | if (smb2_data == NULL) |
| 394 | return -ENOMEM; |
| 395 | |
| 396 | rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid, |
| 397 | smb2_data); |
| 398 | if (!rc) |
| 399 | move_smb2_info_to_cifs(data, smb2_data); |
| 400 | kfree(smb2_data); |
| 401 | return rc; |
| 402 | } |
| 403 | |
Pavel Shilovsky | 9094fad | 2012-07-12 18:30:44 +0400 | [diff] [blame] | 404 | static bool |
| 405 | smb2_can_echo(struct TCP_Server_Info *server) |
| 406 | { |
| 407 | return server->echoes; |
| 408 | } |
| 409 | |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 410 | static void |
| 411 | smb2_clear_stats(struct cifs_tcon *tcon) |
| 412 | { |
| 413 | #ifdef CONFIG_CIFS_STATS |
| 414 | int i; |
| 415 | for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) { |
| 416 | atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0); |
| 417 | atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0); |
| 418 | } |
| 419 | #endif |
| 420 | } |
| 421 | |
| 422 | static void |
Steve French | 769ee6a | 2013-06-19 14:15:30 -0500 | [diff] [blame] | 423 | smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon) |
| 424 | { |
| 425 | seq_puts(m, "\n\tShare Capabilities:"); |
| 426 | if (tcon->capabilities & SMB2_SHARE_CAP_DFS) |
| 427 | seq_puts(m, " DFS,"); |
| 428 | if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY) |
| 429 | seq_puts(m, " CONTINUOUS AVAILABILITY,"); |
| 430 | if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT) |
| 431 | seq_puts(m, " SCALEOUT,"); |
| 432 | if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER) |
| 433 | seq_puts(m, " CLUSTER,"); |
| 434 | if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC) |
| 435 | seq_puts(m, " ASYMMETRIC,"); |
| 436 | if (tcon->capabilities == 0) |
| 437 | seq_puts(m, " None"); |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 438 | if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE) |
| 439 | seq_puts(m, " Aligned,"); |
| 440 | if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE) |
| 441 | seq_puts(m, " Partition Aligned,"); |
| 442 | if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY) |
| 443 | seq_puts(m, " SSD,"); |
| 444 | if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED) |
| 445 | seq_puts(m, " TRIM-support,"); |
| 446 | |
Steve French | 769ee6a | 2013-06-19 14:15:30 -0500 | [diff] [blame] | 447 | seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags); |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 448 | if (tcon->perf_sector_size) |
| 449 | seq_printf(m, "\tOptimal sector size: 0x%x", |
| 450 | tcon->perf_sector_size); |
Steve French | 769ee6a | 2013-06-19 14:15:30 -0500 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | static void |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 454 | smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon) |
| 455 | { |
| 456 | #ifdef CONFIG_CIFS_STATS |
| 457 | atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent; |
| 458 | atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed; |
| 459 | seq_printf(m, "\nNegotiates: %d sent %d failed", |
| 460 | atomic_read(&sent[SMB2_NEGOTIATE_HE]), |
| 461 | atomic_read(&failed[SMB2_NEGOTIATE_HE])); |
| 462 | seq_printf(m, "\nSessionSetups: %d sent %d failed", |
| 463 | atomic_read(&sent[SMB2_SESSION_SETUP_HE]), |
| 464 | atomic_read(&failed[SMB2_SESSION_SETUP_HE])); |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 465 | seq_printf(m, "\nLogoffs: %d sent %d failed", |
| 466 | atomic_read(&sent[SMB2_LOGOFF_HE]), |
| 467 | atomic_read(&failed[SMB2_LOGOFF_HE])); |
| 468 | seq_printf(m, "\nTreeConnects: %d sent %d failed", |
| 469 | atomic_read(&sent[SMB2_TREE_CONNECT_HE]), |
| 470 | atomic_read(&failed[SMB2_TREE_CONNECT_HE])); |
| 471 | seq_printf(m, "\nTreeDisconnects: %d sent %d failed", |
| 472 | atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]), |
| 473 | atomic_read(&failed[SMB2_TREE_DISCONNECT_HE])); |
| 474 | seq_printf(m, "\nCreates: %d sent %d failed", |
| 475 | atomic_read(&sent[SMB2_CREATE_HE]), |
| 476 | atomic_read(&failed[SMB2_CREATE_HE])); |
| 477 | seq_printf(m, "\nCloses: %d sent %d failed", |
| 478 | atomic_read(&sent[SMB2_CLOSE_HE]), |
| 479 | atomic_read(&failed[SMB2_CLOSE_HE])); |
| 480 | seq_printf(m, "\nFlushes: %d sent %d failed", |
| 481 | atomic_read(&sent[SMB2_FLUSH_HE]), |
| 482 | atomic_read(&failed[SMB2_FLUSH_HE])); |
| 483 | seq_printf(m, "\nReads: %d sent %d failed", |
| 484 | atomic_read(&sent[SMB2_READ_HE]), |
| 485 | atomic_read(&failed[SMB2_READ_HE])); |
| 486 | seq_printf(m, "\nWrites: %d sent %d failed", |
| 487 | atomic_read(&sent[SMB2_WRITE_HE]), |
| 488 | atomic_read(&failed[SMB2_WRITE_HE])); |
| 489 | seq_printf(m, "\nLocks: %d sent %d failed", |
| 490 | atomic_read(&sent[SMB2_LOCK_HE]), |
| 491 | atomic_read(&failed[SMB2_LOCK_HE])); |
| 492 | seq_printf(m, "\nIOCTLs: %d sent %d failed", |
| 493 | atomic_read(&sent[SMB2_IOCTL_HE]), |
| 494 | atomic_read(&failed[SMB2_IOCTL_HE])); |
| 495 | seq_printf(m, "\nCancels: %d sent %d failed", |
| 496 | atomic_read(&sent[SMB2_CANCEL_HE]), |
| 497 | atomic_read(&failed[SMB2_CANCEL_HE])); |
| 498 | seq_printf(m, "\nEchos: %d sent %d failed", |
| 499 | atomic_read(&sent[SMB2_ECHO_HE]), |
| 500 | atomic_read(&failed[SMB2_ECHO_HE])); |
| 501 | seq_printf(m, "\nQueryDirectories: %d sent %d failed", |
| 502 | atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]), |
| 503 | atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE])); |
| 504 | seq_printf(m, "\nChangeNotifies: %d sent %d failed", |
| 505 | atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]), |
| 506 | atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE])); |
| 507 | seq_printf(m, "\nQueryInfos: %d sent %d failed", |
| 508 | atomic_read(&sent[SMB2_QUERY_INFO_HE]), |
| 509 | atomic_read(&failed[SMB2_QUERY_INFO_HE])); |
| 510 | seq_printf(m, "\nSetInfos: %d sent %d failed", |
| 511 | atomic_read(&sent[SMB2_SET_INFO_HE]), |
| 512 | atomic_read(&failed[SMB2_SET_INFO_HE])); |
| 513 | seq_printf(m, "\nOplockBreaks: %d sent %d failed", |
| 514 | atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]), |
| 515 | atomic_read(&failed[SMB2_OPLOCK_BREAK_HE])); |
| 516 | #endif |
| 517 | } |
| 518 | |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 519 | static void |
| 520 | smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock) |
| 521 | { |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 522 | struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 523 | struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; |
| 524 | |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 525 | cfile->fid.persistent_fid = fid->persistent_fid; |
| 526 | cfile->fid.volatile_fid = fid->volatile_fid; |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 527 | server->ops->set_oplock_level(cinode, oplock, fid->epoch, |
| 528 | &fid->purge_cache); |
Pavel Shilovsky | 18cceb6 | 2013-09-05 13:01:06 +0400 | [diff] [blame] | 529 | cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode); |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 530 | } |
| 531 | |
Pavel Shilovsky | 760ad0c | 2012-09-25 11:00:07 +0400 | [diff] [blame] | 532 | static void |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 533 | smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon, |
| 534 | struct cifs_fid *fid) |
| 535 | { |
Pavel Shilovsky | 760ad0c | 2012-09-25 11:00:07 +0400 | [diff] [blame] | 536 | SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 537 | } |
| 538 | |
Pavel Shilovsky | 7a5cfb1 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 539 | static int |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 540 | SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon, |
| 541 | u64 persistent_fid, u64 volatile_fid, |
| 542 | struct copychunk_ioctl *pcchunk) |
| 543 | { |
| 544 | int rc; |
| 545 | unsigned int ret_data_len; |
| 546 | struct resume_key_req *res_key; |
| 547 | |
| 548 | rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid, |
| 549 | FSCTL_SRV_REQUEST_RESUME_KEY, true /* is_fsctl */, |
| 550 | NULL, 0 /* no input */, |
| 551 | (char **)&res_key, &ret_data_len); |
| 552 | |
| 553 | if (rc) { |
| 554 | cifs_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc); |
| 555 | goto req_res_key_exit; |
| 556 | } |
| 557 | if (ret_data_len < sizeof(struct resume_key_req)) { |
| 558 | cifs_dbg(VFS, "Invalid refcopy resume key length\n"); |
| 559 | rc = -EINVAL; |
| 560 | goto req_res_key_exit; |
| 561 | } |
| 562 | memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE); |
| 563 | |
| 564 | req_res_key_exit: |
| 565 | kfree(res_key); |
| 566 | return rc; |
| 567 | } |
| 568 | |
| 569 | static int |
| 570 | smb2_clone_range(const unsigned int xid, |
| 571 | struct cifsFileInfo *srcfile, |
| 572 | struct cifsFileInfo *trgtfile, u64 src_off, |
| 573 | u64 len, u64 dest_off) |
| 574 | { |
| 575 | int rc; |
| 576 | unsigned int ret_data_len; |
| 577 | struct copychunk_ioctl *pcchunk; |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 578 | struct copychunk_ioctl_rsp *retbuf = NULL; |
| 579 | struct cifs_tcon *tcon; |
| 580 | int chunks_copied = 0; |
| 581 | bool chunk_sizes_updated = false; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 582 | |
| 583 | pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL); |
| 584 | |
| 585 | if (pcchunk == NULL) |
| 586 | return -ENOMEM; |
| 587 | |
| 588 | cifs_dbg(FYI, "in smb2_clone_range - about to call request res key\n"); |
| 589 | /* Request a key from the server to identify the source of the copy */ |
| 590 | rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink), |
| 591 | srcfile->fid.persistent_fid, |
| 592 | srcfile->fid.volatile_fid, pcchunk); |
| 593 | |
| 594 | /* Note: request_res_key sets res_key null only if rc !=0 */ |
| 595 | if (rc) |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 596 | goto cchunk_out; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 597 | |
| 598 | /* For now array only one chunk long, will make more flexible later */ |
| 599 | pcchunk->ChunkCount = __constant_cpu_to_le32(1); |
| 600 | pcchunk->Reserved = 0; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 601 | pcchunk->Reserved2 = 0; |
| 602 | |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 603 | tcon = tlink_tcon(trgtfile->tlink); |
| 604 | |
| 605 | while (len > 0) { |
| 606 | pcchunk->SourceOffset = cpu_to_le64(src_off); |
| 607 | pcchunk->TargetOffset = cpu_to_le64(dest_off); |
| 608 | pcchunk->Length = |
| 609 | cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk)); |
| 610 | |
| 611 | /* Request server copy to target from src identified by key */ |
| 612 | rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid, |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 613 | trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE, |
| 614 | true /* is_fsctl */, (char *)pcchunk, |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 615 | sizeof(struct copychunk_ioctl), (char **)&retbuf, |
| 616 | &ret_data_len); |
| 617 | if (rc == 0) { |
| 618 | if (ret_data_len != |
| 619 | sizeof(struct copychunk_ioctl_rsp)) { |
| 620 | cifs_dbg(VFS, "invalid cchunk response size\n"); |
| 621 | rc = -EIO; |
| 622 | goto cchunk_out; |
| 623 | } |
| 624 | if (retbuf->TotalBytesWritten == 0) { |
| 625 | cifs_dbg(FYI, "no bytes copied\n"); |
| 626 | rc = -EIO; |
| 627 | goto cchunk_out; |
| 628 | } |
| 629 | /* |
| 630 | * Check if server claimed to write more than we asked |
| 631 | */ |
| 632 | if (le32_to_cpu(retbuf->TotalBytesWritten) > |
| 633 | le32_to_cpu(pcchunk->Length)) { |
| 634 | cifs_dbg(VFS, "invalid copy chunk response\n"); |
| 635 | rc = -EIO; |
| 636 | goto cchunk_out; |
| 637 | } |
| 638 | if (le32_to_cpu(retbuf->ChunksWritten) != 1) { |
| 639 | cifs_dbg(VFS, "invalid num chunks written\n"); |
| 640 | rc = -EIO; |
| 641 | goto cchunk_out; |
| 642 | } |
| 643 | chunks_copied++; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 644 | |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 645 | src_off += le32_to_cpu(retbuf->TotalBytesWritten); |
| 646 | dest_off += le32_to_cpu(retbuf->TotalBytesWritten); |
| 647 | len -= le32_to_cpu(retbuf->TotalBytesWritten); |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 648 | |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 649 | cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %d\n", |
| 650 | le32_to_cpu(retbuf->ChunksWritten), |
| 651 | le32_to_cpu(retbuf->ChunkBytesWritten), |
| 652 | le32_to_cpu(retbuf->TotalBytesWritten)); |
| 653 | } else if (rc == -EINVAL) { |
| 654 | if (ret_data_len != sizeof(struct copychunk_ioctl_rsp)) |
| 655 | goto cchunk_out; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 656 | |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 657 | cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n", |
| 658 | le32_to_cpu(retbuf->ChunksWritten), |
| 659 | le32_to_cpu(retbuf->ChunkBytesWritten), |
| 660 | le32_to_cpu(retbuf->TotalBytesWritten)); |
| 661 | |
| 662 | /* |
| 663 | * Check if this is the first request using these sizes, |
| 664 | * (ie check if copy succeed once with original sizes |
| 665 | * and check if the server gave us different sizes after |
| 666 | * we already updated max sizes on previous request). |
| 667 | * if not then why is the server returning an error now |
| 668 | */ |
| 669 | if ((chunks_copied != 0) || chunk_sizes_updated) |
| 670 | goto cchunk_out; |
| 671 | |
| 672 | /* Check that server is not asking us to grow size */ |
| 673 | if (le32_to_cpu(retbuf->ChunkBytesWritten) < |
| 674 | tcon->max_bytes_chunk) |
| 675 | tcon->max_bytes_chunk = |
| 676 | le32_to_cpu(retbuf->ChunkBytesWritten); |
| 677 | else |
| 678 | goto cchunk_out; /* server gave us bogus size */ |
| 679 | |
| 680 | /* No need to change MaxChunks since already set to 1 */ |
| 681 | chunk_sizes_updated = true; |
| 682 | } |
| 683 | } |
| 684 | |
| 685 | cchunk_out: |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 686 | kfree(pcchunk); |
| 687 | return rc; |
| 688 | } |
| 689 | |
| 690 | static int |
Pavel Shilovsky | 7a5cfb1 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 691 | smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon, |
| 692 | struct cifs_fid *fid) |
| 693 | { |
| 694 | return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
| 695 | } |
| 696 | |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 697 | static unsigned int |
| 698 | smb2_read_data_offset(char *buf) |
| 699 | { |
| 700 | struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf; |
| 701 | return rsp->DataOffset; |
| 702 | } |
| 703 | |
| 704 | static unsigned int |
| 705 | smb2_read_data_length(char *buf) |
| 706 | { |
| 707 | struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf; |
| 708 | return le32_to_cpu(rsp->DataLength); |
| 709 | } |
| 710 | |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 711 | |
| 712 | static int |
| 713 | smb2_sync_read(const unsigned int xid, struct cifsFileInfo *cfile, |
| 714 | struct cifs_io_parms *parms, unsigned int *bytes_read, |
| 715 | char **buf, int *buf_type) |
| 716 | { |
| 717 | parms->persistent_fid = cfile->fid.persistent_fid; |
| 718 | parms->volatile_fid = cfile->fid.volatile_fid; |
| 719 | return SMB2_read(xid, parms, bytes_read, buf, buf_type); |
| 720 | } |
| 721 | |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 722 | static int |
| 723 | smb2_sync_write(const unsigned int xid, struct cifsFileInfo *cfile, |
| 724 | struct cifs_io_parms *parms, unsigned int *written, |
| 725 | struct kvec *iov, unsigned long nr_segs) |
| 726 | { |
| 727 | |
| 728 | parms->persistent_fid = cfile->fid.persistent_fid; |
| 729 | parms->volatile_fid = cfile->fid.volatile_fid; |
| 730 | return SMB2_write(xid, parms, written, iov, nr_segs); |
| 731 | } |
| 732 | |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 733 | static int |
| 734 | smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon, |
| 735 | struct cifsFileInfo *cfile, __u64 size, bool set_alloc) |
| 736 | { |
| 737 | __le64 eof = cpu_to_le64(size); |
| 738 | return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, |
| 739 | cfile->fid.volatile_fid, cfile->pid, &eof); |
| 740 | } |
| 741 | |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 742 | static int |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 743 | smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon, |
| 744 | struct cifsFileInfo *cfile) |
| 745 | { |
| 746 | return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid, |
| 747 | cfile->fid.volatile_fid); |
| 748 | } |
| 749 | |
| 750 | static int |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 751 | smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon, |
| 752 | const char *path, struct cifs_sb_info *cifs_sb, |
| 753 | struct cifs_fid *fid, __u16 search_flags, |
| 754 | struct cifs_search_info *srch_inf) |
| 755 | { |
| 756 | __le16 *utf16_path; |
| 757 | int rc; |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 758 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 759 | struct cifs_open_parms oparms; |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 760 | |
| 761 | utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); |
| 762 | if (!utf16_path) |
| 763 | return -ENOMEM; |
| 764 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 765 | oparms.tcon = tcon; |
| 766 | oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA; |
| 767 | oparms.disposition = FILE_OPEN; |
| 768 | oparms.create_options = 0; |
| 769 | oparms.fid = fid; |
Pavel Shilovsky | 9cbc0b7 | 2013-07-09 18:40:58 +0400 | [diff] [blame] | 770 | oparms.reconnect = false; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 771 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 772 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 773 | kfree(utf16_path); |
| 774 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 775 | cifs_dbg(VFS, "open dir failed\n"); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 776 | return rc; |
| 777 | } |
| 778 | |
| 779 | srch_inf->entries_in_buffer = 0; |
| 780 | srch_inf->index_of_last_entry = 0; |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 781 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 782 | rc = SMB2_query_directory(xid, tcon, fid->persistent_fid, |
| 783 | fid->volatile_fid, 0, srch_inf); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 784 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 785 | cifs_dbg(VFS, "query directory failed\n"); |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 786 | SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 787 | } |
| 788 | return rc; |
| 789 | } |
| 790 | |
| 791 | static int |
| 792 | smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon, |
| 793 | struct cifs_fid *fid, __u16 search_flags, |
| 794 | struct cifs_search_info *srch_inf) |
| 795 | { |
| 796 | return SMB2_query_directory(xid, tcon, fid->persistent_fid, |
| 797 | fid->volatile_fid, 0, srch_inf); |
| 798 | } |
| 799 | |
| 800 | static int |
| 801 | smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon, |
| 802 | struct cifs_fid *fid) |
| 803 | { |
| 804 | return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
| 805 | } |
| 806 | |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 807 | /* |
| 808 | * If we negotiate SMB2 protocol and get STATUS_PENDING - update |
| 809 | * the number of credits and return true. Otherwise - return false. |
| 810 | */ |
| 811 | static bool |
| 812 | smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length) |
| 813 | { |
| 814 | struct smb2_hdr *hdr = (struct smb2_hdr *)buf; |
| 815 | |
Steve French | 12e8a20 | 2012-09-19 09:19:39 -0700 | [diff] [blame] | 816 | if (hdr->Status != STATUS_PENDING) |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 817 | return false; |
| 818 | |
| 819 | if (!length) { |
| 820 | spin_lock(&server->req_lock); |
| 821 | server->credits += le16_to_cpu(hdr->CreditRequest); |
| 822 | spin_unlock(&server->req_lock); |
| 823 | wake_up(&server->request_q); |
| 824 | } |
| 825 | |
| 826 | return true; |
| 827 | } |
| 828 | |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 829 | static int |
| 830 | smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid, |
| 831 | struct cifsInodeInfo *cinode) |
| 832 | { |
Pavel Shilovsky | 0822f51 | 2012-09-19 06:22:45 -0700 | [diff] [blame] | 833 | if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING) |
| 834 | return SMB2_lease_break(0, tcon, cinode->lease_key, |
| 835 | smb2_get_lease_state(cinode)); |
| 836 | |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 837 | return SMB2_oplock_break(0, tcon, fid->persistent_fid, |
| 838 | fid->volatile_fid, |
Pavel Shilovsky | 18cceb6 | 2013-09-05 13:01:06 +0400 | [diff] [blame] | 839 | CIFS_CACHE_READ(cinode) ? 1 : 0); |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 840 | } |
| 841 | |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 842 | static int |
| 843 | smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon, |
| 844 | struct kstatfs *buf) |
| 845 | { |
| 846 | int rc; |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 847 | __le16 srch_path = 0; /* Null - open root of share */ |
| 848 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 849 | struct cifs_open_parms oparms; |
| 850 | struct cifs_fid fid; |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 851 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 852 | oparms.tcon = tcon; |
| 853 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 854 | oparms.disposition = FILE_OPEN; |
| 855 | oparms.create_options = 0; |
| 856 | oparms.fid = &fid; |
Pavel Shilovsky | 9cbc0b7 | 2013-07-09 18:40:58 +0400 | [diff] [blame] | 857 | oparms.reconnect = false; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 858 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 859 | rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL); |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 860 | if (rc) |
| 861 | return rc; |
| 862 | buf->f_type = SMB2_MAGIC_NUMBER; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 863 | rc = SMB2_QFS_info(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
| 864 | buf); |
| 865 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 866 | return rc; |
| 867 | } |
| 868 | |
Pavel Shilovsky | 027e8ee | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 869 | static bool |
| 870 | smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2) |
| 871 | { |
| 872 | return ob1->fid.persistent_fid == ob2->fid.persistent_fid && |
| 873 | ob1->fid.volatile_fid == ob2->fid.volatile_fid; |
| 874 | } |
| 875 | |
Pavel Shilovsky | f7ba7fe | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 876 | static int |
| 877 | smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset, |
| 878 | __u64 length, __u32 type, int lock, int unlock, bool wait) |
| 879 | { |
| 880 | if (unlock && !lock) |
| 881 | type = SMB2_LOCKFLAG_UNLOCK; |
| 882 | return SMB2_lock(xid, tlink_tcon(cfile->tlink), |
| 883 | cfile->fid.persistent_fid, cfile->fid.volatile_fid, |
| 884 | current->tgid, length, offset, type, wait); |
| 885 | } |
| 886 | |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 887 | static void |
| 888 | smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid) |
| 889 | { |
| 890 | memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE); |
| 891 | } |
| 892 | |
| 893 | static void |
| 894 | smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid) |
| 895 | { |
| 896 | memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE); |
| 897 | } |
| 898 | |
| 899 | static void |
| 900 | smb2_new_lease_key(struct cifs_fid *fid) |
| 901 | { |
| 902 | get_random_bytes(fid->lease_key, SMB2_LEASE_KEY_SIZE); |
| 903 | } |
| 904 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 905 | static int |
| 906 | smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon, |
| 907 | const char *full_path, char **target_path, |
| 908 | struct cifs_sb_info *cifs_sb) |
| 909 | { |
| 910 | int rc; |
| 911 | __le16 *utf16_path; |
| 912 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 913 | struct cifs_open_parms oparms; |
| 914 | struct cifs_fid fid; |
| 915 | struct smb2_err_rsp *err_buf = NULL; |
| 916 | struct smb2_symlink_err_rsp *symlink; |
| 917 | unsigned int sub_len, sub_offset; |
| 918 | |
| 919 | cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path); |
| 920 | |
| 921 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); |
| 922 | if (!utf16_path) |
| 923 | return -ENOMEM; |
| 924 | |
| 925 | oparms.tcon = tcon; |
| 926 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 927 | oparms.disposition = FILE_OPEN; |
| 928 | oparms.create_options = 0; |
| 929 | oparms.fid = &fid; |
| 930 | oparms.reconnect = false; |
| 931 | |
| 932 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_buf); |
| 933 | |
| 934 | if (!rc || !err_buf) { |
| 935 | kfree(utf16_path); |
| 936 | return -ENOENT; |
| 937 | } |
| 938 | /* open must fail on symlink - reset rc */ |
| 939 | rc = 0; |
| 940 | symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData; |
| 941 | sub_len = le16_to_cpu(symlink->SubstituteNameLength); |
| 942 | sub_offset = le16_to_cpu(symlink->SubstituteNameOffset); |
| 943 | *target_path = cifs_strndup_from_utf16( |
| 944 | (char *)symlink->PathBuffer + sub_offset, |
| 945 | sub_len, true, cifs_sb->local_nls); |
| 946 | if (!(*target_path)) { |
| 947 | kfree(utf16_path); |
| 948 | return -ENOMEM; |
| 949 | } |
| 950 | convert_delimiter(*target_path, '/'); |
| 951 | cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path); |
| 952 | kfree(utf16_path); |
| 953 | return rc; |
| 954 | } |
| 955 | |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 956 | static void |
Sachin Prabhu | c11f1df | 2014-03-11 16:11:47 +0000 | [diff] [blame] | 957 | smb2_downgrade_oplock(struct TCP_Server_Info *server, |
| 958 | struct cifsInodeInfo *cinode, bool set_level2) |
| 959 | { |
| 960 | if (set_level2) |
| 961 | server->ops->set_oplock_level(cinode, SMB2_OPLOCK_LEVEL_II, |
| 962 | 0, NULL); |
| 963 | else |
| 964 | server->ops->set_oplock_level(cinode, 0, 0, NULL); |
| 965 | } |
| 966 | |
| 967 | static void |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 968 | smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock, |
| 969 | unsigned int epoch, bool *purge_cache) |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 970 | { |
| 971 | oplock &= 0xFF; |
| 972 | if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE) |
| 973 | return; |
| 974 | if (oplock == SMB2_OPLOCK_LEVEL_BATCH) { |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 975 | cinode->oplock = CIFS_CACHE_RHW_FLG; |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 976 | cifs_dbg(FYI, "Batch Oplock granted on inode %p\n", |
| 977 | &cinode->vfs_inode); |
| 978 | } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) { |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 979 | cinode->oplock = CIFS_CACHE_RW_FLG; |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 980 | cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n", |
| 981 | &cinode->vfs_inode); |
| 982 | } else if (oplock == SMB2_OPLOCK_LEVEL_II) { |
| 983 | cinode->oplock = CIFS_CACHE_READ_FLG; |
| 984 | cifs_dbg(FYI, "Level II Oplock granted on inode %p\n", |
| 985 | &cinode->vfs_inode); |
| 986 | } else |
| 987 | cinode->oplock = 0; |
| 988 | } |
| 989 | |
| 990 | static void |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 991 | smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock, |
| 992 | unsigned int epoch, bool *purge_cache) |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 993 | { |
| 994 | char message[5] = {0}; |
| 995 | |
| 996 | oplock &= 0xFF; |
| 997 | if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE) |
| 998 | return; |
| 999 | |
| 1000 | cinode->oplock = 0; |
| 1001 | if (oplock & SMB2_LEASE_READ_CACHING_HE) { |
| 1002 | cinode->oplock |= CIFS_CACHE_READ_FLG; |
| 1003 | strcat(message, "R"); |
| 1004 | } |
| 1005 | if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) { |
| 1006 | cinode->oplock |= CIFS_CACHE_HANDLE_FLG; |
| 1007 | strcat(message, "H"); |
| 1008 | } |
| 1009 | if (oplock & SMB2_LEASE_WRITE_CACHING_HE) { |
| 1010 | cinode->oplock |= CIFS_CACHE_WRITE_FLG; |
| 1011 | strcat(message, "W"); |
| 1012 | } |
| 1013 | if (!cinode->oplock) |
| 1014 | strcat(message, "None"); |
| 1015 | cifs_dbg(FYI, "%s Lease granted on inode %p\n", message, |
| 1016 | &cinode->vfs_inode); |
| 1017 | } |
| 1018 | |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 1019 | static void |
| 1020 | smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock, |
| 1021 | unsigned int epoch, bool *purge_cache) |
| 1022 | { |
| 1023 | unsigned int old_oplock = cinode->oplock; |
| 1024 | |
| 1025 | smb21_set_oplock_level(cinode, oplock, epoch, purge_cache); |
| 1026 | |
| 1027 | if (purge_cache) { |
| 1028 | *purge_cache = false; |
| 1029 | if (old_oplock == CIFS_CACHE_READ_FLG) { |
| 1030 | if (cinode->oplock == CIFS_CACHE_READ_FLG && |
| 1031 | (epoch - cinode->epoch > 0)) |
| 1032 | *purge_cache = true; |
| 1033 | else if (cinode->oplock == CIFS_CACHE_RH_FLG && |
| 1034 | (epoch - cinode->epoch > 1)) |
| 1035 | *purge_cache = true; |
| 1036 | else if (cinode->oplock == CIFS_CACHE_RHW_FLG && |
| 1037 | (epoch - cinode->epoch > 1)) |
| 1038 | *purge_cache = true; |
| 1039 | else if (cinode->oplock == 0 && |
| 1040 | (epoch - cinode->epoch > 0)) |
| 1041 | *purge_cache = true; |
| 1042 | } else if (old_oplock == CIFS_CACHE_RH_FLG) { |
| 1043 | if (cinode->oplock == CIFS_CACHE_RH_FLG && |
| 1044 | (epoch - cinode->epoch > 0)) |
| 1045 | *purge_cache = true; |
| 1046 | else if (cinode->oplock == CIFS_CACHE_RHW_FLG && |
| 1047 | (epoch - cinode->epoch > 1)) |
| 1048 | *purge_cache = true; |
| 1049 | } |
| 1050 | cinode->epoch = epoch; |
| 1051 | } |
| 1052 | } |
| 1053 | |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1054 | static bool |
| 1055 | smb2_is_read_op(__u32 oplock) |
| 1056 | { |
| 1057 | return oplock == SMB2_OPLOCK_LEVEL_II; |
| 1058 | } |
| 1059 | |
| 1060 | static bool |
| 1061 | smb21_is_read_op(__u32 oplock) |
| 1062 | { |
| 1063 | return (oplock & SMB2_LEASE_READ_CACHING_HE) && |
| 1064 | !(oplock & SMB2_LEASE_WRITE_CACHING_HE); |
| 1065 | } |
| 1066 | |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1067 | static __le32 |
| 1068 | map_oplock_to_lease(u8 oplock) |
| 1069 | { |
| 1070 | if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) |
| 1071 | return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING; |
| 1072 | else if (oplock == SMB2_OPLOCK_LEVEL_II) |
| 1073 | return SMB2_LEASE_READ_CACHING; |
| 1074 | else if (oplock == SMB2_OPLOCK_LEVEL_BATCH) |
| 1075 | return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING | |
| 1076 | SMB2_LEASE_WRITE_CACHING; |
| 1077 | return 0; |
| 1078 | } |
| 1079 | |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 1080 | static char * |
| 1081 | smb2_create_lease_buf(u8 *lease_key, u8 oplock) |
| 1082 | { |
| 1083 | struct create_lease *buf; |
| 1084 | |
| 1085 | buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL); |
| 1086 | if (!buf) |
| 1087 | return NULL; |
| 1088 | |
| 1089 | buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key)); |
| 1090 | buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8))); |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1091 | buf->lcontext.LeaseState = map_oplock_to_lease(oplock); |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 1092 | |
| 1093 | buf->ccontext.DataOffset = cpu_to_le16(offsetof |
| 1094 | (struct create_lease, lcontext)); |
| 1095 | buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context)); |
| 1096 | buf->ccontext.NameOffset = cpu_to_le16(offsetof |
| 1097 | (struct create_lease, Name)); |
| 1098 | buf->ccontext.NameLength = cpu_to_le16(4); |
Steve French | 12197a7 | 2014-05-14 05:29:40 -0700 | [diff] [blame] | 1099 | /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */ |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 1100 | buf->Name[0] = 'R'; |
| 1101 | buf->Name[1] = 'q'; |
| 1102 | buf->Name[2] = 'L'; |
| 1103 | buf->Name[3] = 's'; |
| 1104 | return (char *)buf; |
| 1105 | } |
| 1106 | |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1107 | static char * |
| 1108 | smb3_create_lease_buf(u8 *lease_key, u8 oplock) |
| 1109 | { |
| 1110 | struct create_lease_v2 *buf; |
| 1111 | |
| 1112 | buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL); |
| 1113 | if (!buf) |
| 1114 | return NULL; |
| 1115 | |
| 1116 | buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key)); |
| 1117 | buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8))); |
| 1118 | buf->lcontext.LeaseState = map_oplock_to_lease(oplock); |
| 1119 | |
| 1120 | buf->ccontext.DataOffset = cpu_to_le16(offsetof |
| 1121 | (struct create_lease_v2, lcontext)); |
| 1122 | buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2)); |
| 1123 | buf->ccontext.NameOffset = cpu_to_le16(offsetof |
| 1124 | (struct create_lease_v2, Name)); |
| 1125 | buf->ccontext.NameLength = cpu_to_le16(4); |
Steve French | 12197a7 | 2014-05-14 05:29:40 -0700 | [diff] [blame] | 1126 | /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */ |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1127 | buf->Name[0] = 'R'; |
| 1128 | buf->Name[1] = 'q'; |
| 1129 | buf->Name[2] = 'L'; |
| 1130 | buf->Name[3] = 's'; |
| 1131 | return (char *)buf; |
| 1132 | } |
| 1133 | |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 1134 | static __u8 |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 1135 | smb2_parse_lease_buf(void *buf, unsigned int *epoch) |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 1136 | { |
| 1137 | struct create_lease *lc = (struct create_lease *)buf; |
| 1138 | |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 1139 | *epoch = 0; /* not used */ |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 1140 | if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS) |
| 1141 | return SMB2_OPLOCK_LEVEL_NOCHANGE; |
| 1142 | return le32_to_cpu(lc->lcontext.LeaseState); |
| 1143 | } |
| 1144 | |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1145 | static __u8 |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 1146 | smb3_parse_lease_buf(void *buf, unsigned int *epoch) |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1147 | { |
| 1148 | struct create_lease_v2 *lc = (struct create_lease_v2 *)buf; |
| 1149 | |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 1150 | *epoch = le16_to_cpu(lc->lcontext.Epoch); |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1151 | if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS) |
| 1152 | return SMB2_OPLOCK_LEVEL_NOCHANGE; |
| 1153 | return le32_to_cpu(lc->lcontext.LeaseState); |
| 1154 | } |
| 1155 | |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 1156 | static unsigned int |
| 1157 | smb2_wp_retry_size(struct inode *inode) |
| 1158 | { |
| 1159 | return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize, |
| 1160 | SMB2_MAX_BUFFER_SIZE); |
| 1161 | } |
| 1162 | |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1163 | struct smb_version_operations smb20_operations = { |
| 1164 | .compare_fids = smb2_compare_fids, |
| 1165 | .setup_request = smb2_setup_request, |
| 1166 | .setup_async_request = smb2_setup_async_request, |
| 1167 | .check_receive = smb2_check_receive, |
| 1168 | .add_credits = smb2_add_credits, |
| 1169 | .set_credits = smb2_set_credits, |
| 1170 | .get_credits_field = smb2_get_credits_field, |
| 1171 | .get_credits = smb2_get_credits, |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 1172 | .wait_mtu_credits = cifs_wait_mtu_credits, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1173 | .get_next_mid = smb2_get_next_mid, |
| 1174 | .read_data_offset = smb2_read_data_offset, |
| 1175 | .read_data_length = smb2_read_data_length, |
| 1176 | .map_error = map_smb2_to_linux_error, |
| 1177 | .find_mid = smb2_find_mid, |
| 1178 | .check_message = smb2_check_message, |
| 1179 | .dump_detail = smb2_dump_detail, |
| 1180 | .clear_stats = smb2_clear_stats, |
| 1181 | .print_stats = smb2_print_stats, |
| 1182 | .is_oplock_break = smb2_is_valid_oplock_break, |
Sachin Prabhu | c11f1df | 2014-03-11 16:11:47 +0000 | [diff] [blame] | 1183 | .downgrade_oplock = smb2_downgrade_oplock, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1184 | .need_neg = smb2_need_neg, |
| 1185 | .negotiate = smb2_negotiate, |
| 1186 | .negotiate_wsize = smb2_negotiate_wsize, |
| 1187 | .negotiate_rsize = smb2_negotiate_rsize, |
| 1188 | .sess_setup = SMB2_sess_setup, |
| 1189 | .logoff = SMB2_logoff, |
| 1190 | .tree_connect = SMB2_tcon, |
| 1191 | .tree_disconnect = SMB2_tdis, |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 1192 | .qfs_tcon = smb2_qfs_tcon, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1193 | .is_path_accessible = smb2_is_path_accessible, |
| 1194 | .can_echo = smb2_can_echo, |
| 1195 | .echo = SMB2_echo, |
| 1196 | .query_path_info = smb2_query_path_info, |
| 1197 | .get_srv_inum = smb2_get_srv_inum, |
| 1198 | .query_file_info = smb2_query_file_info, |
| 1199 | .set_path_size = smb2_set_path_size, |
| 1200 | .set_file_size = smb2_set_file_size, |
| 1201 | .set_file_info = smb2_set_file_info, |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 1202 | .set_compression = smb2_set_compression, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1203 | .mkdir = smb2_mkdir, |
| 1204 | .mkdir_setinfo = smb2_mkdir_setinfo, |
| 1205 | .rmdir = smb2_rmdir, |
| 1206 | .unlink = smb2_unlink, |
| 1207 | .rename = smb2_rename_path, |
| 1208 | .create_hardlink = smb2_create_hardlink, |
| 1209 | .query_symlink = smb2_query_symlink, |
| 1210 | .open = smb2_open_file, |
| 1211 | .set_fid = smb2_set_fid, |
| 1212 | .close = smb2_close_file, |
| 1213 | .flush = smb2_flush_file, |
| 1214 | .async_readv = smb2_async_readv, |
| 1215 | .async_writev = smb2_async_writev, |
| 1216 | .sync_read = smb2_sync_read, |
| 1217 | .sync_write = smb2_sync_write, |
| 1218 | .query_dir_first = smb2_query_dir_first, |
| 1219 | .query_dir_next = smb2_query_dir_next, |
| 1220 | .close_dir = smb2_close_dir, |
| 1221 | .calc_smb_size = smb2_calc_size, |
| 1222 | .is_status_pending = smb2_is_status_pending, |
| 1223 | .oplock_response = smb2_oplock_response, |
| 1224 | .queryfs = smb2_queryfs, |
| 1225 | .mand_lock = smb2_mand_lock, |
| 1226 | .mand_unlock_range = smb2_unlock_range, |
| 1227 | .push_mand_locks = smb2_push_mandatory_locks, |
| 1228 | .get_lease_key = smb2_get_lease_key, |
| 1229 | .set_lease_key = smb2_set_lease_key, |
| 1230 | .new_lease_key = smb2_new_lease_key, |
| 1231 | .calc_signature = smb2_calc_signature, |
| 1232 | .is_read_op = smb2_is_read_op, |
| 1233 | .set_oplock_level = smb2_set_oplock_level, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 1234 | .create_lease_buf = smb2_create_lease_buf, |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 1235 | .parse_lease_buf = smb2_parse_lease_buf, |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1236 | .clone_range = smb2_clone_range, |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 1237 | .wp_retry_size = smb2_wp_retry_size, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1238 | }; |
| 1239 | |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 1240 | struct smb_version_operations smb21_operations = { |
Pavel Shilovsky | 027e8ee | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 1241 | .compare_fids = smb2_compare_fids, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 1242 | .setup_request = smb2_setup_request, |
Pavel Shilovsky | c95b8ee | 2012-07-11 14:45:28 +0400 | [diff] [blame] | 1243 | .setup_async_request = smb2_setup_async_request, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 1244 | .check_receive = smb2_check_receive, |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 1245 | .add_credits = smb2_add_credits, |
| 1246 | .set_credits = smb2_set_credits, |
| 1247 | .get_credits_field = smb2_get_credits_field, |
| 1248 | .get_credits = smb2_get_credits, |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 1249 | .wait_mtu_credits = smb2_wait_mtu_credits, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 1250 | .get_next_mid = smb2_get_next_mid, |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1251 | .read_data_offset = smb2_read_data_offset, |
| 1252 | .read_data_length = smb2_read_data_length, |
| 1253 | .map_error = map_smb2_to_linux_error, |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 1254 | .find_mid = smb2_find_mid, |
| 1255 | .check_message = smb2_check_message, |
| 1256 | .dump_detail = smb2_dump_detail, |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 1257 | .clear_stats = smb2_clear_stats, |
| 1258 | .print_stats = smb2_print_stats, |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1259 | .is_oplock_break = smb2_is_valid_oplock_break, |
Sachin Prabhu | c11f1df | 2014-03-11 16:11:47 +0000 | [diff] [blame] | 1260 | .downgrade_oplock = smb2_downgrade_oplock, |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 1261 | .need_neg = smb2_need_neg, |
| 1262 | .negotiate = smb2_negotiate, |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 1263 | .negotiate_wsize = smb2_negotiate_wsize, |
| 1264 | .negotiate_rsize = smb2_negotiate_rsize, |
Pavel Shilovsky | 5478f9b | 2011-12-27 16:22:00 +0400 | [diff] [blame] | 1265 | .sess_setup = SMB2_sess_setup, |
| 1266 | .logoff = SMB2_logoff, |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 1267 | .tree_connect = SMB2_tcon, |
| 1268 | .tree_disconnect = SMB2_tdis, |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 1269 | .qfs_tcon = smb2_qfs_tcon, |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 1270 | .is_path_accessible = smb2_is_path_accessible, |
Pavel Shilovsky | 9094fad | 2012-07-12 18:30:44 +0400 | [diff] [blame] | 1271 | .can_echo = smb2_can_echo, |
| 1272 | .echo = SMB2_echo, |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 1273 | .query_path_info = smb2_query_path_info, |
| 1274 | .get_srv_inum = smb2_get_srv_inum, |
Pavel Shilovsky | b7546bc | 2012-09-18 16:20:27 -0700 | [diff] [blame] | 1275 | .query_file_info = smb2_query_file_info, |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 1276 | .set_path_size = smb2_set_path_size, |
| 1277 | .set_file_size = smb2_set_file_size, |
Pavel Shilovsky | 1feeaac | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 1278 | .set_file_info = smb2_set_file_info, |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 1279 | .set_compression = smb2_set_compression, |
Pavel Shilovsky | a0e7318 | 2011-07-19 12:56:37 +0400 | [diff] [blame] | 1280 | .mkdir = smb2_mkdir, |
| 1281 | .mkdir_setinfo = smb2_mkdir_setinfo, |
Pavel Shilovsky | 1a500f0 | 2012-07-10 16:14:38 +0400 | [diff] [blame] | 1282 | .rmdir = smb2_rmdir, |
Pavel Shilovsky | cbe6f43 | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 1283 | .unlink = smb2_unlink, |
Pavel Shilovsky | 35143eb | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 1284 | .rename = smb2_rename_path, |
Pavel Shilovsky | 568798c | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 1285 | .create_hardlink = smb2_create_hardlink, |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 1286 | .query_symlink = smb2_query_symlink, |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 1287 | .open = smb2_open_file, |
| 1288 | .set_fid = smb2_set_fid, |
| 1289 | .close = smb2_close_file, |
Pavel Shilovsky | 7a5cfb1 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 1290 | .flush = smb2_flush_file, |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1291 | .async_readv = smb2_async_readv, |
Pavel Shilovsky | 3331914 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1292 | .async_writev = smb2_async_writev, |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 1293 | .sync_read = smb2_sync_read, |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 1294 | .sync_write = smb2_sync_write, |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1295 | .query_dir_first = smb2_query_dir_first, |
| 1296 | .query_dir_next = smb2_query_dir_next, |
| 1297 | .close_dir = smb2_close_dir, |
| 1298 | .calc_smb_size = smb2_calc_size, |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1299 | .is_status_pending = smb2_is_status_pending, |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1300 | .oplock_response = smb2_oplock_response, |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 1301 | .queryfs = smb2_queryfs, |
Pavel Shilovsky | f7ba7fe | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 1302 | .mand_lock = smb2_mand_lock, |
| 1303 | .mand_unlock_range = smb2_unlock_range, |
Pavel Shilovsky | b140799 | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 1304 | .push_mand_locks = smb2_push_mandatory_locks, |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 1305 | .get_lease_key = smb2_get_lease_key, |
| 1306 | .set_lease_key = smb2_set_lease_key, |
| 1307 | .new_lease_key = smb2_new_lease_key, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 1308 | .calc_signature = smb2_calc_signature, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1309 | .is_read_op = smb21_is_read_op, |
| 1310 | .set_oplock_level = smb21_set_oplock_level, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 1311 | .create_lease_buf = smb2_create_lease_buf, |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 1312 | .parse_lease_buf = smb2_parse_lease_buf, |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1313 | .clone_range = smb2_clone_range, |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 1314 | .wp_retry_size = smb2_wp_retry_size, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 1315 | }; |
| 1316 | |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 1317 | struct smb_version_operations smb30_operations = { |
| 1318 | .compare_fids = smb2_compare_fids, |
| 1319 | .setup_request = smb2_setup_request, |
| 1320 | .setup_async_request = smb2_setup_async_request, |
| 1321 | .check_receive = smb2_check_receive, |
| 1322 | .add_credits = smb2_add_credits, |
| 1323 | .set_credits = smb2_set_credits, |
| 1324 | .get_credits_field = smb2_get_credits_field, |
| 1325 | .get_credits = smb2_get_credits, |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 1326 | .wait_mtu_credits = smb2_wait_mtu_credits, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 1327 | .get_next_mid = smb2_get_next_mid, |
| 1328 | .read_data_offset = smb2_read_data_offset, |
| 1329 | .read_data_length = smb2_read_data_length, |
| 1330 | .map_error = map_smb2_to_linux_error, |
| 1331 | .find_mid = smb2_find_mid, |
| 1332 | .check_message = smb2_check_message, |
| 1333 | .dump_detail = smb2_dump_detail, |
| 1334 | .clear_stats = smb2_clear_stats, |
| 1335 | .print_stats = smb2_print_stats, |
Steve French | 769ee6a | 2013-06-19 14:15:30 -0500 | [diff] [blame] | 1336 | .dump_share_caps = smb2_dump_share_caps, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 1337 | .is_oplock_break = smb2_is_valid_oplock_break, |
Sachin Prabhu | c11f1df | 2014-03-11 16:11:47 +0000 | [diff] [blame] | 1338 | .downgrade_oplock = smb2_downgrade_oplock, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 1339 | .need_neg = smb2_need_neg, |
| 1340 | .negotiate = smb2_negotiate, |
| 1341 | .negotiate_wsize = smb2_negotiate_wsize, |
| 1342 | .negotiate_rsize = smb2_negotiate_rsize, |
| 1343 | .sess_setup = SMB2_sess_setup, |
| 1344 | .logoff = SMB2_logoff, |
| 1345 | .tree_connect = SMB2_tcon, |
| 1346 | .tree_disconnect = SMB2_tdis, |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 1347 | .qfs_tcon = smb3_qfs_tcon, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 1348 | .is_path_accessible = smb2_is_path_accessible, |
| 1349 | .can_echo = smb2_can_echo, |
| 1350 | .echo = SMB2_echo, |
| 1351 | .query_path_info = smb2_query_path_info, |
| 1352 | .get_srv_inum = smb2_get_srv_inum, |
| 1353 | .query_file_info = smb2_query_file_info, |
| 1354 | .set_path_size = smb2_set_path_size, |
| 1355 | .set_file_size = smb2_set_file_size, |
| 1356 | .set_file_info = smb2_set_file_info, |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 1357 | .set_compression = smb2_set_compression, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 1358 | .mkdir = smb2_mkdir, |
| 1359 | .mkdir_setinfo = smb2_mkdir_setinfo, |
| 1360 | .rmdir = smb2_rmdir, |
| 1361 | .unlink = smb2_unlink, |
| 1362 | .rename = smb2_rename_path, |
| 1363 | .create_hardlink = smb2_create_hardlink, |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 1364 | .query_symlink = smb2_query_symlink, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 1365 | .open = smb2_open_file, |
| 1366 | .set_fid = smb2_set_fid, |
| 1367 | .close = smb2_close_file, |
| 1368 | .flush = smb2_flush_file, |
| 1369 | .async_readv = smb2_async_readv, |
| 1370 | .async_writev = smb2_async_writev, |
| 1371 | .sync_read = smb2_sync_read, |
| 1372 | .sync_write = smb2_sync_write, |
| 1373 | .query_dir_first = smb2_query_dir_first, |
| 1374 | .query_dir_next = smb2_query_dir_next, |
| 1375 | .close_dir = smb2_close_dir, |
| 1376 | .calc_smb_size = smb2_calc_size, |
| 1377 | .is_status_pending = smb2_is_status_pending, |
| 1378 | .oplock_response = smb2_oplock_response, |
| 1379 | .queryfs = smb2_queryfs, |
| 1380 | .mand_lock = smb2_mand_lock, |
| 1381 | .mand_unlock_range = smb2_unlock_range, |
| 1382 | .push_mand_locks = smb2_push_mandatory_locks, |
| 1383 | .get_lease_key = smb2_get_lease_key, |
| 1384 | .set_lease_key = smb2_set_lease_key, |
| 1385 | .new_lease_key = smb2_new_lease_key, |
Steve French | e65a5cb | 2013-06-27 01:06:50 -0500 | [diff] [blame] | 1386 | .generate_signingkey = generate_smb3signingkey, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 1387 | .calc_signature = smb3_calc_signature, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1388 | .is_read_op = smb21_is_read_op, |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 1389 | .set_oplock_level = smb3_set_oplock_level, |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1390 | .create_lease_buf = smb3_create_lease_buf, |
| 1391 | .parse_lease_buf = smb3_parse_lease_buf, |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1392 | .clone_range = smb2_clone_range, |
Steve French | ff1c038 | 2013-11-19 23:44:46 -0600 | [diff] [blame] | 1393 | .validate_negotiate = smb3_validate_negotiate, |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 1394 | .wp_retry_size = smb2_wp_retry_size, |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 1395 | }; |
| 1396 | |
Steve French | dd446b1 | 2012-11-28 23:21:06 -0600 | [diff] [blame] | 1397 | struct smb_version_values smb20_values = { |
| 1398 | .version_string = SMB20_VERSION_STRING, |
| 1399 | .protocol_id = SMB20_PROT_ID, |
| 1400 | .req_capabilities = 0, /* MBZ */ |
| 1401 | .large_lock_type = 0, |
| 1402 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 1403 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 1404 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
| 1405 | .header_size = sizeof(struct smb2_hdr), |
| 1406 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 1407 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 1408 | .lock_cmd = SMB2_LOCK, |
| 1409 | .cap_unix = 0, |
| 1410 | .cap_nt_find = SMB2_NT_FIND, |
| 1411 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 5028588 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 1412 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 1413 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 1414 | .create_lease_size = sizeof(struct create_lease), |
Steve French | dd446b1 | 2012-11-28 23:21:06 -0600 | [diff] [blame] | 1415 | }; |
| 1416 | |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 1417 | struct smb_version_values smb21_values = { |
| 1418 | .version_string = SMB21_VERSION_STRING, |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 1419 | .protocol_id = SMB21_PROT_ID, |
| 1420 | .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */ |
| 1421 | .large_lock_type = 0, |
| 1422 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 1423 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 1424 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
| 1425 | .header_size = sizeof(struct smb2_hdr), |
| 1426 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 1427 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 1428 | .lock_cmd = SMB2_LOCK, |
| 1429 | .cap_unix = 0, |
| 1430 | .cap_nt_find = SMB2_NT_FIND, |
| 1431 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 5028588 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 1432 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 1433 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 1434 | .create_lease_size = sizeof(struct create_lease), |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 1435 | }; |
| 1436 | |
| 1437 | struct smb_version_values smb30_values = { |
| 1438 | .version_string = SMB30_VERSION_STRING, |
| 1439 | .protocol_id = SMB30_PROT_ID, |
| 1440 | .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] | 1441 | .large_lock_type = 0, |
| 1442 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 1443 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 1444 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 1445 | .header_size = sizeof(struct smb2_hdr), |
| 1446 | .max_header_size = MAX_SMB2_HDR_SIZE, |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1447 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 1448 | .lock_cmd = SMB2_LOCK, |
Pavel Shilovsky | 29e20f9 | 2012-07-13 13:58:14 +0400 | [diff] [blame] | 1449 | .cap_unix = 0, |
| 1450 | .cap_nt_find = SMB2_NT_FIND, |
| 1451 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 5028588 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 1452 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 1453 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1454 | .create_lease_size = sizeof(struct create_lease_v2), |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 1455 | }; |
Steve French | 20b6d8b | 2013-06-12 22:48:41 -0500 | [diff] [blame] | 1456 | |
| 1457 | struct smb_version_values smb302_values = { |
| 1458 | .version_string = SMB302_VERSION_STRING, |
| 1459 | .protocol_id = SMB302_PROT_ID, |
| 1460 | .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU, |
| 1461 | .large_lock_type = 0, |
| 1462 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 1463 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 1464 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
| 1465 | .header_size = sizeof(struct smb2_hdr), |
| 1466 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 1467 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 1468 | .lock_cmd = SMB2_LOCK, |
| 1469 | .cap_unix = 0, |
| 1470 | .cap_nt_find = SMB2_NT_FIND, |
| 1471 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 5028588 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 1472 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 1473 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1474 | .create_lease_size = sizeof(struct create_lease_v2), |
Steve French | 20b6d8b | 2013-06-12 22:48:41 -0500 | [diff] [blame] | 1475 | }; |