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