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; |
Steve French | e0ddde9 | 2015-09-22 09:29:38 -0500 | [diff] [blame] | 53 | if (enable_oplocks) { |
| 54 | server->oplocks = true; |
| 55 | server->oplock_credits = 1; |
| 56 | } else |
| 57 | server->oplocks = false; |
| 58 | |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 59 | server->echo_credits = 1; |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 60 | } |
| 61 | server->credits -= server->echo_credits + server->oplock_credits; |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | static void |
| 66 | smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add, |
| 67 | const int optype) |
| 68 | { |
| 69 | int *val, rc = 0; |
| 70 | spin_lock(&server->req_lock); |
| 71 | val = server->ops->get_credits_field(server, optype); |
| 72 | *val += add; |
| 73 | server->in_flight--; |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 74 | if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP) |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 75 | rc = change_conf(server); |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 76 | /* |
| 77 | * Sometimes server returns 0 credits on oplock break ack - we need to |
| 78 | * rebalance credits in this case. |
| 79 | */ |
| 80 | else if (server->in_flight > 0 && server->oplock_credits == 0 && |
| 81 | server->oplocks) { |
| 82 | if (server->credits > 1) { |
| 83 | server->credits--; |
| 84 | server->oplock_credits++; |
| 85 | } |
| 86 | } |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 87 | spin_unlock(&server->req_lock); |
| 88 | wake_up(&server->request_q); |
| 89 | if (rc) |
| 90 | cifs_reconnect(server); |
| 91 | } |
| 92 | |
| 93 | static void |
| 94 | smb2_set_credits(struct TCP_Server_Info *server, const int val) |
| 95 | { |
| 96 | spin_lock(&server->req_lock); |
| 97 | server->credits = val; |
| 98 | spin_unlock(&server->req_lock); |
| 99 | } |
| 100 | |
| 101 | static int * |
| 102 | smb2_get_credits_field(struct TCP_Server_Info *server, const int optype) |
| 103 | { |
| 104 | switch (optype) { |
| 105 | case CIFS_ECHO_OP: |
| 106 | return &server->echo_credits; |
| 107 | case CIFS_OBREAK_OP: |
| 108 | return &server->oplock_credits; |
| 109 | default: |
| 110 | return &server->credits; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | static unsigned int |
| 115 | smb2_get_credits(struct mid_q_entry *mid) |
| 116 | { |
| 117 | return le16_to_cpu(((struct smb2_hdr *)mid->resp_buf)->CreditRequest); |
| 118 | } |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 119 | |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 120 | static int |
| 121 | smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size, |
| 122 | unsigned int *num, unsigned int *credits) |
| 123 | { |
| 124 | int rc = 0; |
| 125 | unsigned int scredits; |
| 126 | |
| 127 | spin_lock(&server->req_lock); |
| 128 | while (1) { |
| 129 | if (server->credits <= 0) { |
| 130 | spin_unlock(&server->req_lock); |
| 131 | cifs_num_waiters_inc(server); |
| 132 | rc = wait_event_killable(server->request_q, |
| 133 | has_credits(server, &server->credits)); |
| 134 | cifs_num_waiters_dec(server); |
| 135 | if (rc) |
| 136 | return rc; |
| 137 | spin_lock(&server->req_lock); |
| 138 | } else { |
| 139 | if (server->tcpStatus == CifsExiting) { |
| 140 | spin_unlock(&server->req_lock); |
| 141 | return -ENOENT; |
| 142 | } |
| 143 | |
| 144 | scredits = server->credits; |
| 145 | /* can deadlock with reopen */ |
| 146 | if (scredits == 1) { |
| 147 | *num = SMB2_MAX_BUFFER_SIZE; |
| 148 | *credits = 0; |
| 149 | break; |
| 150 | } |
| 151 | |
| 152 | /* leave one credit for a possible reopen */ |
| 153 | scredits--; |
| 154 | *num = min_t(unsigned int, size, |
| 155 | scredits * SMB2_MAX_BUFFER_SIZE); |
| 156 | |
| 157 | *credits = DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE); |
| 158 | server->credits -= *credits; |
| 159 | server->in_flight++; |
| 160 | break; |
| 161 | } |
| 162 | } |
| 163 | spin_unlock(&server->req_lock); |
| 164 | return rc; |
| 165 | } |
| 166 | |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 167 | static __u64 |
| 168 | smb2_get_next_mid(struct TCP_Server_Info *server) |
| 169 | { |
| 170 | __u64 mid; |
| 171 | /* for SMB2 we need the current value */ |
| 172 | spin_lock(&GlobalMid_Lock); |
| 173 | mid = server->CurrentMid++; |
| 174 | spin_unlock(&GlobalMid_Lock); |
| 175 | return mid; |
| 176 | } |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 177 | |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 178 | static struct mid_q_entry * |
| 179 | smb2_find_mid(struct TCP_Server_Info *server, char *buf) |
| 180 | { |
| 181 | struct mid_q_entry *mid; |
| 182 | struct smb2_hdr *hdr = (struct smb2_hdr *)buf; |
Sachin Prabhu | 9235d09 | 2014-12-09 17:37:00 +0000 | [diff] [blame] | 183 | __u64 wire_mid = le64_to_cpu(hdr->MessageId); |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 184 | |
Steve French | 373512e | 2015-12-18 13:05:30 -0600 | [diff] [blame] | 185 | if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) { |
| 186 | cifs_dbg(VFS, "encrypted frame parsing not supported yet"); |
| 187 | return NULL; |
| 188 | } |
| 189 | |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 190 | spin_lock(&GlobalMid_Lock); |
| 191 | list_for_each_entry(mid, &server->pending_mid_q, qhead) { |
Sachin Prabhu | 9235d09 | 2014-12-09 17:37:00 +0000 | [diff] [blame] | 192 | if ((mid->mid == wire_mid) && |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 193 | (mid->mid_state == MID_REQUEST_SUBMITTED) && |
| 194 | (mid->command == hdr->Command)) { |
| 195 | spin_unlock(&GlobalMid_Lock); |
| 196 | return mid; |
| 197 | } |
| 198 | } |
| 199 | spin_unlock(&GlobalMid_Lock); |
| 200 | return NULL; |
| 201 | } |
| 202 | |
| 203 | static void |
| 204 | smb2_dump_detail(void *buf) |
| 205 | { |
| 206 | #ifdef CONFIG_CIFS_DEBUG2 |
| 207 | struct smb2_hdr *smb = (struct smb2_hdr *)buf; |
| 208 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 209 | cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n", |
| 210 | smb->Command, smb->Status, smb->Flags, smb->MessageId, |
| 211 | smb->ProcessId); |
| 212 | 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] | 213 | #endif |
| 214 | } |
| 215 | |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 216 | static bool |
| 217 | smb2_need_neg(struct TCP_Server_Info *server) |
| 218 | { |
| 219 | return server->max_read == 0; |
| 220 | } |
| 221 | |
| 222 | static int |
| 223 | smb2_negotiate(const unsigned int xid, struct cifs_ses *ses) |
| 224 | { |
| 225 | int rc; |
| 226 | ses->server->CurrentMid = 0; |
| 227 | rc = SMB2_negotiate(xid, ses); |
| 228 | /* BB we probably don't need to retry with modern servers */ |
| 229 | if (rc == -EAGAIN) |
| 230 | rc = -EHOSTDOWN; |
| 231 | return rc; |
| 232 | } |
| 233 | |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 234 | static unsigned int |
| 235 | smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) |
| 236 | { |
| 237 | struct TCP_Server_Info *server = tcon->ses->server; |
| 238 | unsigned int wsize; |
| 239 | |
| 240 | /* start with specified wsize, or default */ |
| 241 | wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE; |
| 242 | wsize = min_t(unsigned int, wsize, server->max_write); |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 243 | |
| 244 | if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU)) |
| 245 | wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE); |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 246 | |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 247 | return wsize; |
| 248 | } |
| 249 | |
| 250 | static unsigned int |
| 251 | smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) |
| 252 | { |
| 253 | struct TCP_Server_Info *server = tcon->ses->server; |
| 254 | unsigned int rsize; |
| 255 | |
| 256 | /* start with specified rsize, or default */ |
| 257 | rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE; |
| 258 | rsize = min_t(unsigned int, rsize, server->max_read); |
Pavel Shilovsky | bed9da0 | 2014-06-25 11:28:57 +0400 | [diff] [blame] | 259 | |
| 260 | if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU)) |
| 261 | rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE); |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 262 | |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 263 | return rsize; |
| 264 | } |
| 265 | |
Steve French | c481e9f | 2013-10-14 01:21:53 -0500 | [diff] [blame] | 266 | #ifdef CONFIG_CIFS_STATS2 |
| 267 | static int |
| 268 | SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon) |
| 269 | { |
| 270 | int rc; |
| 271 | unsigned int ret_data_len = 0; |
| 272 | struct network_interface_info_ioctl_rsp *out_buf; |
| 273 | |
| 274 | rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID, |
| 275 | FSCTL_QUERY_NETWORK_INTERFACE_INFO, true /* is_fsctl */, |
| 276 | NULL /* no data input */, 0 /* no data input */, |
| 277 | (char **)&out_buf, &ret_data_len); |
Steve French | 9ffc541 | 2014-10-16 15:13:14 -0500 | [diff] [blame] | 278 | if (rc != 0) |
| 279 | cifs_dbg(VFS, "error %d on ioctl to get interface list\n", rc); |
| 280 | else if (ret_data_len < sizeof(struct network_interface_info_ioctl_rsp)) { |
| 281 | cifs_dbg(VFS, "server returned bad net interface info buf\n"); |
| 282 | rc = -EINVAL; |
| 283 | } else { |
Steve French | c481e9f | 2013-10-14 01:21:53 -0500 | [diff] [blame] | 284 | /* Dump info on first interface */ |
| 285 | cifs_dbg(FYI, "Adapter Capability 0x%x\t", |
| 286 | le32_to_cpu(out_buf->Capability)); |
| 287 | cifs_dbg(FYI, "Link Speed %lld\n", |
| 288 | le64_to_cpu(out_buf->LinkSpeed)); |
Steve French | 9ffc541 | 2014-10-16 15:13:14 -0500 | [diff] [blame] | 289 | } |
Steve French | c481e9f | 2013-10-14 01:21:53 -0500 | [diff] [blame] | 290 | |
| 291 | return rc; |
| 292 | } |
| 293 | #endif /* STATS2 */ |
| 294 | |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 295 | static void |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 296 | smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon) |
| 297 | { |
| 298 | int rc; |
| 299 | __le16 srch_path = 0; /* Null - open root of share */ |
| 300 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 301 | struct cifs_open_parms oparms; |
| 302 | struct cifs_fid fid; |
| 303 | |
| 304 | oparms.tcon = tcon; |
| 305 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 306 | oparms.disposition = FILE_OPEN; |
| 307 | oparms.create_options = 0; |
| 308 | oparms.fid = &fid; |
| 309 | oparms.reconnect = false; |
| 310 | |
| 311 | rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL); |
| 312 | if (rc) |
| 313 | return; |
| 314 | |
Steve French | c481e9f | 2013-10-14 01:21:53 -0500 | [diff] [blame] | 315 | #ifdef CONFIG_CIFS_STATS2 |
| 316 | SMB3_request_interfaces(xid, tcon); |
| 317 | #endif /* STATS2 */ |
| 318 | |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 319 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
| 320 | FS_ATTRIBUTE_INFORMATION); |
| 321 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
| 322 | FS_DEVICE_INFORMATION); |
| 323 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
| 324 | FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */ |
| 325 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
| 326 | return; |
| 327 | } |
| 328 | |
| 329 | static void |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 330 | smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon) |
| 331 | { |
| 332 | int rc; |
| 333 | __le16 srch_path = 0; /* Null - open root of share */ |
| 334 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 335 | struct cifs_open_parms oparms; |
| 336 | struct cifs_fid fid; |
| 337 | |
| 338 | oparms.tcon = tcon; |
| 339 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 340 | oparms.disposition = FILE_OPEN; |
| 341 | oparms.create_options = 0; |
| 342 | oparms.fid = &fid; |
| 343 | oparms.reconnect = false; |
| 344 | |
| 345 | rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL); |
| 346 | if (rc) |
| 347 | return; |
| 348 | |
Steven French | 2167114 | 2013-10-09 13:36:35 -0500 | [diff] [blame] | 349 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
| 350 | FS_ATTRIBUTE_INFORMATION); |
| 351 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
| 352 | FS_DEVICE_INFORMATION); |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 353 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
| 354 | return; |
| 355 | } |
| 356 | |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 357 | static int |
| 358 | smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon, |
| 359 | struct cifs_sb_info *cifs_sb, const char *full_path) |
| 360 | { |
| 361 | int rc; |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 362 | __le16 *utf16_path; |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 363 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 364 | struct cifs_open_parms oparms; |
| 365 | struct cifs_fid fid; |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 366 | |
| 367 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); |
| 368 | if (!utf16_path) |
| 369 | return -ENOMEM; |
| 370 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 371 | oparms.tcon = tcon; |
| 372 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 373 | oparms.disposition = FILE_OPEN; |
| 374 | oparms.create_options = 0; |
| 375 | oparms.fid = &fid; |
Pavel Shilovsky | 9cbc0b7 | 2013-07-09 18:40:58 +0400 | [diff] [blame] | 376 | oparms.reconnect = false; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 377 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 378 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL); |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 379 | if (rc) { |
| 380 | kfree(utf16_path); |
| 381 | return rc; |
| 382 | } |
| 383 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 384 | rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 385 | kfree(utf16_path); |
| 386 | return rc; |
| 387 | } |
| 388 | |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 389 | static int |
| 390 | smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon, |
| 391 | struct cifs_sb_info *cifs_sb, const char *full_path, |
| 392 | u64 *uniqueid, FILE_ALL_INFO *data) |
| 393 | { |
| 394 | *uniqueid = le64_to_cpu(data->IndexNumber); |
| 395 | return 0; |
| 396 | } |
| 397 | |
Pavel Shilovsky | b7546bc | 2012-09-18 16:20:27 -0700 | [diff] [blame] | 398 | static int |
| 399 | smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon, |
| 400 | struct cifs_fid *fid, FILE_ALL_INFO *data) |
| 401 | { |
| 402 | int rc; |
| 403 | struct smb2_file_all_info *smb2_data; |
| 404 | |
Pavel Shilovsky | 1bbe499 | 2014-08-22 13:32:11 +0400 | [diff] [blame] | 405 | smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2, |
Pavel Shilovsky | b7546bc | 2012-09-18 16:20:27 -0700 | [diff] [blame] | 406 | GFP_KERNEL); |
| 407 | if (smb2_data == NULL) |
| 408 | return -ENOMEM; |
| 409 | |
| 410 | rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid, |
| 411 | smb2_data); |
| 412 | if (!rc) |
| 413 | move_smb2_info_to_cifs(data, smb2_data); |
| 414 | kfree(smb2_data); |
| 415 | return rc; |
| 416 | } |
| 417 | |
Pavel Shilovsky | 9094fad | 2012-07-12 18:30:44 +0400 | [diff] [blame] | 418 | static bool |
| 419 | smb2_can_echo(struct TCP_Server_Info *server) |
| 420 | { |
| 421 | return server->echoes; |
| 422 | } |
| 423 | |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 424 | static void |
| 425 | smb2_clear_stats(struct cifs_tcon *tcon) |
| 426 | { |
| 427 | #ifdef CONFIG_CIFS_STATS |
| 428 | int i; |
| 429 | for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) { |
| 430 | atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0); |
| 431 | atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0); |
| 432 | } |
| 433 | #endif |
| 434 | } |
| 435 | |
| 436 | static void |
Steve French | 769ee6a | 2013-06-19 14:15:30 -0500 | [diff] [blame] | 437 | smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon) |
| 438 | { |
| 439 | seq_puts(m, "\n\tShare Capabilities:"); |
| 440 | if (tcon->capabilities & SMB2_SHARE_CAP_DFS) |
| 441 | seq_puts(m, " DFS,"); |
| 442 | if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY) |
| 443 | seq_puts(m, " CONTINUOUS AVAILABILITY,"); |
| 444 | if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT) |
| 445 | seq_puts(m, " SCALEOUT,"); |
| 446 | if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER) |
| 447 | seq_puts(m, " CLUSTER,"); |
| 448 | if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC) |
| 449 | seq_puts(m, " ASYMMETRIC,"); |
| 450 | if (tcon->capabilities == 0) |
| 451 | seq_puts(m, " None"); |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 452 | if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE) |
| 453 | seq_puts(m, " Aligned,"); |
| 454 | if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE) |
| 455 | seq_puts(m, " Partition Aligned,"); |
| 456 | if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY) |
| 457 | seq_puts(m, " SSD,"); |
| 458 | if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED) |
| 459 | seq_puts(m, " TRIM-support,"); |
| 460 | |
Steve French | 769ee6a | 2013-06-19 14:15:30 -0500 | [diff] [blame] | 461 | seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags); |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 462 | if (tcon->perf_sector_size) |
| 463 | seq_printf(m, "\tOptimal sector size: 0x%x", |
| 464 | tcon->perf_sector_size); |
Steve French | 769ee6a | 2013-06-19 14:15:30 -0500 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | static void |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 468 | smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon) |
| 469 | { |
| 470 | #ifdef CONFIG_CIFS_STATS |
| 471 | atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent; |
| 472 | atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed; |
| 473 | seq_printf(m, "\nNegotiates: %d sent %d failed", |
| 474 | atomic_read(&sent[SMB2_NEGOTIATE_HE]), |
| 475 | atomic_read(&failed[SMB2_NEGOTIATE_HE])); |
| 476 | seq_printf(m, "\nSessionSetups: %d sent %d failed", |
| 477 | atomic_read(&sent[SMB2_SESSION_SETUP_HE]), |
| 478 | atomic_read(&failed[SMB2_SESSION_SETUP_HE])); |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 479 | seq_printf(m, "\nLogoffs: %d sent %d failed", |
| 480 | atomic_read(&sent[SMB2_LOGOFF_HE]), |
| 481 | atomic_read(&failed[SMB2_LOGOFF_HE])); |
| 482 | seq_printf(m, "\nTreeConnects: %d sent %d failed", |
| 483 | atomic_read(&sent[SMB2_TREE_CONNECT_HE]), |
| 484 | atomic_read(&failed[SMB2_TREE_CONNECT_HE])); |
| 485 | seq_printf(m, "\nTreeDisconnects: %d sent %d failed", |
| 486 | atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]), |
| 487 | atomic_read(&failed[SMB2_TREE_DISCONNECT_HE])); |
| 488 | seq_printf(m, "\nCreates: %d sent %d failed", |
| 489 | atomic_read(&sent[SMB2_CREATE_HE]), |
| 490 | atomic_read(&failed[SMB2_CREATE_HE])); |
| 491 | seq_printf(m, "\nCloses: %d sent %d failed", |
| 492 | atomic_read(&sent[SMB2_CLOSE_HE]), |
| 493 | atomic_read(&failed[SMB2_CLOSE_HE])); |
| 494 | seq_printf(m, "\nFlushes: %d sent %d failed", |
| 495 | atomic_read(&sent[SMB2_FLUSH_HE]), |
| 496 | atomic_read(&failed[SMB2_FLUSH_HE])); |
| 497 | seq_printf(m, "\nReads: %d sent %d failed", |
| 498 | atomic_read(&sent[SMB2_READ_HE]), |
| 499 | atomic_read(&failed[SMB2_READ_HE])); |
| 500 | seq_printf(m, "\nWrites: %d sent %d failed", |
| 501 | atomic_read(&sent[SMB2_WRITE_HE]), |
| 502 | atomic_read(&failed[SMB2_WRITE_HE])); |
| 503 | seq_printf(m, "\nLocks: %d sent %d failed", |
| 504 | atomic_read(&sent[SMB2_LOCK_HE]), |
| 505 | atomic_read(&failed[SMB2_LOCK_HE])); |
| 506 | seq_printf(m, "\nIOCTLs: %d sent %d failed", |
| 507 | atomic_read(&sent[SMB2_IOCTL_HE]), |
| 508 | atomic_read(&failed[SMB2_IOCTL_HE])); |
| 509 | seq_printf(m, "\nCancels: %d sent %d failed", |
| 510 | atomic_read(&sent[SMB2_CANCEL_HE]), |
| 511 | atomic_read(&failed[SMB2_CANCEL_HE])); |
| 512 | seq_printf(m, "\nEchos: %d sent %d failed", |
| 513 | atomic_read(&sent[SMB2_ECHO_HE]), |
| 514 | atomic_read(&failed[SMB2_ECHO_HE])); |
| 515 | seq_printf(m, "\nQueryDirectories: %d sent %d failed", |
| 516 | atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]), |
| 517 | atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE])); |
| 518 | seq_printf(m, "\nChangeNotifies: %d sent %d failed", |
| 519 | atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]), |
| 520 | atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE])); |
| 521 | seq_printf(m, "\nQueryInfos: %d sent %d failed", |
| 522 | atomic_read(&sent[SMB2_QUERY_INFO_HE]), |
| 523 | atomic_read(&failed[SMB2_QUERY_INFO_HE])); |
| 524 | seq_printf(m, "\nSetInfos: %d sent %d failed", |
| 525 | atomic_read(&sent[SMB2_SET_INFO_HE]), |
| 526 | atomic_read(&failed[SMB2_SET_INFO_HE])); |
| 527 | seq_printf(m, "\nOplockBreaks: %d sent %d failed", |
| 528 | atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]), |
| 529 | atomic_read(&failed[SMB2_OPLOCK_BREAK_HE])); |
| 530 | #endif |
| 531 | } |
| 532 | |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 533 | static void |
| 534 | smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock) |
| 535 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 536 | struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry)); |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 537 | struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; |
| 538 | |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 539 | cfile->fid.persistent_fid = fid->persistent_fid; |
| 540 | cfile->fid.volatile_fid = fid->volatile_fid; |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 541 | server->ops->set_oplock_level(cinode, oplock, fid->epoch, |
| 542 | &fid->purge_cache); |
Pavel Shilovsky | 18cceb6 | 2013-09-05 13:01:06 +0400 | [diff] [blame] | 543 | cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode); |
Aurelien Aptel | 94f8737 | 2016-09-22 07:38:50 +0200 | [diff] [blame^] | 544 | memcpy(cfile->fid.create_guid, fid->create_guid, 16); |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 545 | } |
| 546 | |
Pavel Shilovsky | 760ad0c | 2012-09-25 11:00:07 +0400 | [diff] [blame] | 547 | static void |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 548 | smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon, |
| 549 | struct cifs_fid *fid) |
| 550 | { |
Pavel Shilovsky | 760ad0c | 2012-09-25 11:00:07 +0400 | [diff] [blame] | 551 | SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 552 | } |
| 553 | |
Pavel Shilovsky | 7a5cfb1 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 554 | static int |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 555 | SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon, |
| 556 | u64 persistent_fid, u64 volatile_fid, |
| 557 | struct copychunk_ioctl *pcchunk) |
| 558 | { |
| 559 | int rc; |
| 560 | unsigned int ret_data_len; |
| 561 | struct resume_key_req *res_key; |
| 562 | |
| 563 | rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid, |
| 564 | FSCTL_SRV_REQUEST_RESUME_KEY, true /* is_fsctl */, |
| 565 | NULL, 0 /* no input */, |
| 566 | (char **)&res_key, &ret_data_len); |
| 567 | |
| 568 | if (rc) { |
| 569 | cifs_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc); |
| 570 | goto req_res_key_exit; |
| 571 | } |
| 572 | if (ret_data_len < sizeof(struct resume_key_req)) { |
| 573 | cifs_dbg(VFS, "Invalid refcopy resume key length\n"); |
| 574 | rc = -EINVAL; |
| 575 | goto req_res_key_exit; |
| 576 | } |
| 577 | memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE); |
| 578 | |
| 579 | req_res_key_exit: |
| 580 | kfree(res_key); |
| 581 | return rc; |
| 582 | } |
| 583 | |
| 584 | static int |
| 585 | smb2_clone_range(const unsigned int xid, |
| 586 | struct cifsFileInfo *srcfile, |
| 587 | struct cifsFileInfo *trgtfile, u64 src_off, |
| 588 | u64 len, u64 dest_off) |
| 589 | { |
| 590 | int rc; |
| 591 | unsigned int ret_data_len; |
| 592 | struct copychunk_ioctl *pcchunk; |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 593 | struct copychunk_ioctl_rsp *retbuf = NULL; |
| 594 | struct cifs_tcon *tcon; |
| 595 | int chunks_copied = 0; |
| 596 | bool chunk_sizes_updated = false; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 597 | |
| 598 | pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL); |
| 599 | |
| 600 | if (pcchunk == NULL) |
| 601 | return -ENOMEM; |
| 602 | |
| 603 | cifs_dbg(FYI, "in smb2_clone_range - about to call request res key\n"); |
| 604 | /* Request a key from the server to identify the source of the copy */ |
| 605 | rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink), |
| 606 | srcfile->fid.persistent_fid, |
| 607 | srcfile->fid.volatile_fid, pcchunk); |
| 608 | |
| 609 | /* Note: request_res_key sets res_key null only if rc !=0 */ |
| 610 | if (rc) |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 611 | goto cchunk_out; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 612 | |
| 613 | /* For now array only one chunk long, will make more flexible later */ |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 614 | pcchunk->ChunkCount = cpu_to_le32(1); |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 615 | pcchunk->Reserved = 0; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 616 | pcchunk->Reserved2 = 0; |
| 617 | |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 618 | tcon = tlink_tcon(trgtfile->tlink); |
| 619 | |
| 620 | while (len > 0) { |
| 621 | pcchunk->SourceOffset = cpu_to_le64(src_off); |
| 622 | pcchunk->TargetOffset = cpu_to_le64(dest_off); |
| 623 | pcchunk->Length = |
| 624 | cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk)); |
| 625 | |
| 626 | /* Request server copy to target from src identified by key */ |
| 627 | rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid, |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 628 | trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE, |
| 629 | true /* is_fsctl */, (char *)pcchunk, |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 630 | sizeof(struct copychunk_ioctl), (char **)&retbuf, |
| 631 | &ret_data_len); |
| 632 | if (rc == 0) { |
| 633 | if (ret_data_len != |
| 634 | sizeof(struct copychunk_ioctl_rsp)) { |
| 635 | cifs_dbg(VFS, "invalid cchunk response size\n"); |
| 636 | rc = -EIO; |
| 637 | goto cchunk_out; |
| 638 | } |
| 639 | if (retbuf->TotalBytesWritten == 0) { |
| 640 | cifs_dbg(FYI, "no bytes copied\n"); |
| 641 | rc = -EIO; |
| 642 | goto cchunk_out; |
| 643 | } |
| 644 | /* |
| 645 | * Check if server claimed to write more than we asked |
| 646 | */ |
| 647 | if (le32_to_cpu(retbuf->TotalBytesWritten) > |
| 648 | le32_to_cpu(pcchunk->Length)) { |
| 649 | cifs_dbg(VFS, "invalid copy chunk response\n"); |
| 650 | rc = -EIO; |
| 651 | goto cchunk_out; |
| 652 | } |
| 653 | if (le32_to_cpu(retbuf->ChunksWritten) != 1) { |
| 654 | cifs_dbg(VFS, "invalid num chunks written\n"); |
| 655 | rc = -EIO; |
| 656 | goto cchunk_out; |
| 657 | } |
| 658 | chunks_copied++; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 659 | |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 660 | src_off += le32_to_cpu(retbuf->TotalBytesWritten); |
| 661 | dest_off += le32_to_cpu(retbuf->TotalBytesWritten); |
| 662 | len -= le32_to_cpu(retbuf->TotalBytesWritten); |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 663 | |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 664 | cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %d\n", |
| 665 | le32_to_cpu(retbuf->ChunksWritten), |
| 666 | le32_to_cpu(retbuf->ChunkBytesWritten), |
| 667 | le32_to_cpu(retbuf->TotalBytesWritten)); |
| 668 | } else if (rc == -EINVAL) { |
| 669 | if (ret_data_len != sizeof(struct copychunk_ioctl_rsp)) |
| 670 | goto cchunk_out; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 671 | |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 672 | cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n", |
| 673 | le32_to_cpu(retbuf->ChunksWritten), |
| 674 | le32_to_cpu(retbuf->ChunkBytesWritten), |
| 675 | le32_to_cpu(retbuf->TotalBytesWritten)); |
| 676 | |
| 677 | /* |
| 678 | * Check if this is the first request using these sizes, |
| 679 | * (ie check if copy succeed once with original sizes |
| 680 | * and check if the server gave us different sizes after |
| 681 | * we already updated max sizes on previous request). |
| 682 | * if not then why is the server returning an error now |
| 683 | */ |
| 684 | if ((chunks_copied != 0) || chunk_sizes_updated) |
| 685 | goto cchunk_out; |
| 686 | |
| 687 | /* Check that server is not asking us to grow size */ |
| 688 | if (le32_to_cpu(retbuf->ChunkBytesWritten) < |
| 689 | tcon->max_bytes_chunk) |
| 690 | tcon->max_bytes_chunk = |
| 691 | le32_to_cpu(retbuf->ChunkBytesWritten); |
| 692 | else |
| 693 | goto cchunk_out; /* server gave us bogus size */ |
| 694 | |
| 695 | /* No need to change MaxChunks since already set to 1 */ |
| 696 | chunk_sizes_updated = true; |
Sachin Prabhu | 2477bc5 | 2015-02-04 13:10:26 +0000 | [diff] [blame] | 697 | } else |
| 698 | goto cchunk_out; |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | cchunk_out: |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 702 | kfree(pcchunk); |
| 703 | return rc; |
| 704 | } |
| 705 | |
| 706 | static int |
Pavel Shilovsky | 7a5cfb1 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 707 | smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon, |
| 708 | struct cifs_fid *fid) |
| 709 | { |
| 710 | return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
| 711 | } |
| 712 | |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 713 | static unsigned int |
| 714 | smb2_read_data_offset(char *buf) |
| 715 | { |
| 716 | struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf; |
| 717 | return rsp->DataOffset; |
| 718 | } |
| 719 | |
| 720 | static unsigned int |
| 721 | smb2_read_data_length(char *buf) |
| 722 | { |
| 723 | struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf; |
| 724 | return le32_to_cpu(rsp->DataLength); |
| 725 | } |
| 726 | |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 727 | |
| 728 | static int |
Steve French | db8b631 | 2014-09-22 05:13:55 -0500 | [diff] [blame] | 729 | smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid, |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 730 | struct cifs_io_parms *parms, unsigned int *bytes_read, |
| 731 | char **buf, int *buf_type) |
| 732 | { |
Steve French | db8b631 | 2014-09-22 05:13:55 -0500 | [diff] [blame] | 733 | parms->persistent_fid = pfid->persistent_fid; |
| 734 | parms->volatile_fid = pfid->volatile_fid; |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 735 | return SMB2_read(xid, parms, bytes_read, buf, buf_type); |
| 736 | } |
| 737 | |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 738 | static int |
Steve French | db8b631 | 2014-09-22 05:13:55 -0500 | [diff] [blame] | 739 | smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid, |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 740 | struct cifs_io_parms *parms, unsigned int *written, |
| 741 | struct kvec *iov, unsigned long nr_segs) |
| 742 | { |
| 743 | |
Steve French | db8b631 | 2014-09-22 05:13:55 -0500 | [diff] [blame] | 744 | parms->persistent_fid = pfid->persistent_fid; |
| 745 | parms->volatile_fid = pfid->volatile_fid; |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 746 | return SMB2_write(xid, parms, written, iov, nr_segs); |
| 747 | } |
| 748 | |
Steve French | d43cc79 | 2014-08-13 17:16:29 -0500 | [diff] [blame] | 749 | /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */ |
| 750 | static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon, |
| 751 | struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse) |
| 752 | { |
| 753 | struct cifsInodeInfo *cifsi; |
| 754 | int rc; |
| 755 | |
| 756 | cifsi = CIFS_I(inode); |
| 757 | |
| 758 | /* if file already sparse don't bother setting sparse again */ |
| 759 | if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse) |
| 760 | return true; /* already sparse */ |
| 761 | |
| 762 | if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse) |
| 763 | return true; /* already not sparse */ |
| 764 | |
| 765 | /* |
| 766 | * Can't check for sparse support on share the usual way via the |
| 767 | * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share |
| 768 | * since Samba server doesn't set the flag on the share, yet |
| 769 | * supports the set sparse FSCTL and returns sparse correctly |
| 770 | * in the file attributes. If we fail setting sparse though we |
| 771 | * mark that server does not support sparse files for this share |
| 772 | * to avoid repeatedly sending the unsupported fsctl to server |
| 773 | * if the file is repeatedly extended. |
| 774 | */ |
| 775 | if (tcon->broken_sparse_sup) |
| 776 | return false; |
| 777 | |
| 778 | rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, |
| 779 | cfile->fid.volatile_fid, FSCTL_SET_SPARSE, |
| 780 | true /* is_fctl */, &setsparse, 1, NULL, NULL); |
| 781 | if (rc) { |
| 782 | tcon->broken_sparse_sup = true; |
| 783 | cifs_dbg(FYI, "set sparse rc = %d\n", rc); |
| 784 | return false; |
| 785 | } |
| 786 | |
| 787 | if (setsparse) |
| 788 | cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE; |
| 789 | else |
| 790 | cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE); |
| 791 | |
| 792 | return true; |
| 793 | } |
| 794 | |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 795 | static int |
| 796 | smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon, |
| 797 | struct cifsFileInfo *cfile, __u64 size, bool set_alloc) |
| 798 | { |
| 799 | __le64 eof = cpu_to_le64(size); |
Steve French | 3d1a374 | 2014-08-11 21:05:25 -0500 | [diff] [blame] | 800 | struct inode *inode; |
| 801 | |
| 802 | /* |
| 803 | * If extending file more than one page make sparse. Many Linux fs |
| 804 | * make files sparse by default when extending via ftruncate |
| 805 | */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 806 | inode = d_inode(cfile->dentry); |
Steve French | 3d1a374 | 2014-08-11 21:05:25 -0500 | [diff] [blame] | 807 | |
| 808 | if (!set_alloc && (size > inode->i_size + 8192)) { |
Steve French | 3d1a374 | 2014-08-11 21:05:25 -0500 | [diff] [blame] | 809 | __u8 set_sparse = 1; |
Steve French | 3d1a374 | 2014-08-11 21:05:25 -0500 | [diff] [blame] | 810 | |
Steve French | d43cc79 | 2014-08-13 17:16:29 -0500 | [diff] [blame] | 811 | /* whether set sparse succeeds or not, extend the file */ |
| 812 | smb2_set_sparse(xid, tcon, cfile, inode, set_sparse); |
Steve French | 3d1a374 | 2014-08-11 21:05:25 -0500 | [diff] [blame] | 813 | } |
| 814 | |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 815 | return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, |
Steve French | f29ebb4 | 2014-07-19 21:44:58 -0500 | [diff] [blame] | 816 | cfile->fid.volatile_fid, cfile->pid, &eof, false); |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 817 | } |
| 818 | |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 819 | static int |
| 820 | smb2_duplicate_extents(const unsigned int xid, |
| 821 | struct cifsFileInfo *srcfile, |
| 822 | struct cifsFileInfo *trgtfile, u64 src_off, |
| 823 | u64 len, u64 dest_off) |
| 824 | { |
| 825 | int rc; |
| 826 | unsigned int ret_data_len; |
| 827 | char *retbuf = NULL; |
| 828 | struct duplicate_extents_to_file dup_ext_buf; |
| 829 | struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink); |
| 830 | |
| 831 | /* server fileays advertise duplicate extent support with this flag */ |
| 832 | if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) & |
| 833 | FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0) |
| 834 | return -EOPNOTSUPP; |
| 835 | |
| 836 | dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid; |
| 837 | dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid; |
| 838 | dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off); |
| 839 | dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off); |
| 840 | dup_ext_buf.ByteCount = cpu_to_le64(len); |
| 841 | cifs_dbg(FYI, "duplicate extents: src off %lld dst off %lld len %lld", |
| 842 | src_off, dest_off, len); |
| 843 | |
| 844 | rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false); |
| 845 | if (rc) |
| 846 | goto duplicate_extents_out; |
| 847 | |
| 848 | rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid, |
| 849 | trgtfile->fid.volatile_fid, |
| 850 | FSCTL_DUPLICATE_EXTENTS_TO_FILE, |
| 851 | true /* is_fsctl */, (char *)&dup_ext_buf, |
| 852 | sizeof(struct duplicate_extents_to_file), |
| 853 | (char **)&retbuf, |
| 854 | &ret_data_len); |
| 855 | |
| 856 | if (ret_data_len > 0) |
| 857 | cifs_dbg(FYI, "non-zero response length in duplicate extents"); |
| 858 | |
| 859 | duplicate_extents_out: |
| 860 | return rc; |
| 861 | } |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 862 | |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 863 | static int |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 864 | smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon, |
| 865 | struct cifsFileInfo *cfile) |
| 866 | { |
| 867 | return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid, |
| 868 | cfile->fid.volatile_fid); |
| 869 | } |
| 870 | |
| 871 | static int |
Steve French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 872 | smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon, |
| 873 | struct cifsFileInfo *cfile) |
| 874 | { |
| 875 | struct fsctl_set_integrity_information_req integr_info; |
| 876 | char *retbuf = NULL; |
| 877 | unsigned int ret_data_len; |
| 878 | |
| 879 | integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED); |
| 880 | integr_info.Flags = 0; |
| 881 | integr_info.Reserved = 0; |
| 882 | |
| 883 | return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, |
| 884 | cfile->fid.volatile_fid, |
| 885 | FSCTL_SET_INTEGRITY_INFORMATION, |
| 886 | true /* is_fsctl */, (char *)&integr_info, |
| 887 | sizeof(struct fsctl_set_integrity_information_req), |
| 888 | (char **)&retbuf, |
| 889 | &ret_data_len); |
| 890 | |
| 891 | } |
| 892 | |
| 893 | static int |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 894 | smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon, |
| 895 | const char *path, struct cifs_sb_info *cifs_sb, |
| 896 | struct cifs_fid *fid, __u16 search_flags, |
| 897 | struct cifs_search_info *srch_inf) |
| 898 | { |
| 899 | __le16 *utf16_path; |
| 900 | int rc; |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 901 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 902 | struct cifs_open_parms oparms; |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 903 | |
| 904 | utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); |
| 905 | if (!utf16_path) |
| 906 | return -ENOMEM; |
| 907 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 908 | oparms.tcon = tcon; |
| 909 | oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA; |
| 910 | oparms.disposition = FILE_OPEN; |
| 911 | oparms.create_options = 0; |
| 912 | oparms.fid = fid; |
Pavel Shilovsky | 9cbc0b7 | 2013-07-09 18:40:58 +0400 | [diff] [blame] | 913 | oparms.reconnect = false; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 914 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 915 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 916 | kfree(utf16_path); |
| 917 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 918 | cifs_dbg(VFS, "open dir failed\n"); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 919 | return rc; |
| 920 | } |
| 921 | |
| 922 | srch_inf->entries_in_buffer = 0; |
| 923 | srch_inf->index_of_last_entry = 0; |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 924 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 925 | rc = SMB2_query_directory(xid, tcon, fid->persistent_fid, |
| 926 | fid->volatile_fid, 0, srch_inf); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 927 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 928 | cifs_dbg(VFS, "query directory failed\n"); |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 929 | SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 930 | } |
| 931 | return rc; |
| 932 | } |
| 933 | |
| 934 | static int |
| 935 | smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon, |
| 936 | struct cifs_fid *fid, __u16 search_flags, |
| 937 | struct cifs_search_info *srch_inf) |
| 938 | { |
| 939 | return SMB2_query_directory(xid, tcon, fid->persistent_fid, |
| 940 | fid->volatile_fid, 0, srch_inf); |
| 941 | } |
| 942 | |
| 943 | static int |
| 944 | smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon, |
| 945 | struct cifs_fid *fid) |
| 946 | { |
| 947 | return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
| 948 | } |
| 949 | |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 950 | /* |
| 951 | * If we negotiate SMB2 protocol and get STATUS_PENDING - update |
| 952 | * the number of credits and return true. Otherwise - return false. |
| 953 | */ |
| 954 | static bool |
| 955 | smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length) |
| 956 | { |
| 957 | struct smb2_hdr *hdr = (struct smb2_hdr *)buf; |
| 958 | |
Steve French | 12e8a20 | 2012-09-19 09:19:39 -0700 | [diff] [blame] | 959 | if (hdr->Status != STATUS_PENDING) |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 960 | return false; |
| 961 | |
| 962 | if (!length) { |
| 963 | spin_lock(&server->req_lock); |
| 964 | server->credits += le16_to_cpu(hdr->CreditRequest); |
| 965 | spin_unlock(&server->req_lock); |
| 966 | wake_up(&server->request_q); |
| 967 | } |
| 968 | |
| 969 | return true; |
| 970 | } |
| 971 | |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 972 | static int |
| 973 | smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid, |
| 974 | struct cifsInodeInfo *cinode) |
| 975 | { |
Pavel Shilovsky | 0822f51 | 2012-09-19 06:22:45 -0700 | [diff] [blame] | 976 | if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING) |
| 977 | return SMB2_lease_break(0, tcon, cinode->lease_key, |
| 978 | smb2_get_lease_state(cinode)); |
| 979 | |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 980 | return SMB2_oplock_break(0, tcon, fid->persistent_fid, |
| 981 | fid->volatile_fid, |
Pavel Shilovsky | 18cceb6 | 2013-09-05 13:01:06 +0400 | [diff] [blame] | 982 | CIFS_CACHE_READ(cinode) ? 1 : 0); |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 983 | } |
| 984 | |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 985 | static int |
| 986 | smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon, |
| 987 | struct kstatfs *buf) |
| 988 | { |
| 989 | int rc; |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 990 | __le16 srch_path = 0; /* Null - open root of share */ |
| 991 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 992 | struct cifs_open_parms oparms; |
| 993 | struct cifs_fid fid; |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 994 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 995 | oparms.tcon = tcon; |
| 996 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 997 | oparms.disposition = FILE_OPEN; |
| 998 | oparms.create_options = 0; |
| 999 | oparms.fid = &fid; |
Pavel Shilovsky | 9cbc0b7 | 2013-07-09 18:40:58 +0400 | [diff] [blame] | 1000 | oparms.reconnect = false; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1001 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 1002 | rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL); |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 1003 | if (rc) |
| 1004 | return rc; |
| 1005 | buf->f_type = SMB2_MAGIC_NUMBER; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1006 | rc = SMB2_QFS_info(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
| 1007 | buf); |
| 1008 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 1009 | return rc; |
| 1010 | } |
| 1011 | |
Pavel Shilovsky | 027e8ee | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 1012 | static bool |
| 1013 | smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2) |
| 1014 | { |
| 1015 | return ob1->fid.persistent_fid == ob2->fid.persistent_fid && |
| 1016 | ob1->fid.volatile_fid == ob2->fid.volatile_fid; |
| 1017 | } |
| 1018 | |
Pavel Shilovsky | f7ba7fe | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 1019 | static int |
| 1020 | smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset, |
| 1021 | __u64 length, __u32 type, int lock, int unlock, bool wait) |
| 1022 | { |
| 1023 | if (unlock && !lock) |
| 1024 | type = SMB2_LOCKFLAG_UNLOCK; |
| 1025 | return SMB2_lock(xid, tlink_tcon(cfile->tlink), |
| 1026 | cfile->fid.persistent_fid, cfile->fid.volatile_fid, |
| 1027 | current->tgid, length, offset, type, wait); |
| 1028 | } |
| 1029 | |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 1030 | static void |
| 1031 | smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid) |
| 1032 | { |
| 1033 | memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE); |
| 1034 | } |
| 1035 | |
| 1036 | static void |
| 1037 | smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid) |
| 1038 | { |
| 1039 | memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE); |
| 1040 | } |
| 1041 | |
| 1042 | static void |
| 1043 | smb2_new_lease_key(struct cifs_fid *fid) |
| 1044 | { |
Steve French | fa70b87 | 2016-09-22 00:39:34 -0500 | [diff] [blame] | 1045 | generate_random_uuid(fid->lease_key); |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 1046 | } |
| 1047 | |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 1048 | #define SMB2_SYMLINK_STRUCT_SIZE \ |
| 1049 | (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp)) |
| 1050 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 1051 | static int |
| 1052 | smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon, |
| 1053 | const char *full_path, char **target_path, |
| 1054 | struct cifs_sb_info *cifs_sb) |
| 1055 | { |
| 1056 | int rc; |
| 1057 | __le16 *utf16_path; |
| 1058 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 1059 | struct cifs_open_parms oparms; |
| 1060 | struct cifs_fid fid; |
| 1061 | struct smb2_err_rsp *err_buf = NULL; |
| 1062 | struct smb2_symlink_err_rsp *symlink; |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 1063 | unsigned int sub_len; |
| 1064 | unsigned int sub_offset; |
| 1065 | unsigned int print_len; |
| 1066 | unsigned int print_offset; |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 1067 | |
| 1068 | cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path); |
| 1069 | |
| 1070 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); |
| 1071 | if (!utf16_path) |
| 1072 | return -ENOMEM; |
| 1073 | |
| 1074 | oparms.tcon = tcon; |
| 1075 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 1076 | oparms.disposition = FILE_OPEN; |
| 1077 | oparms.create_options = 0; |
| 1078 | oparms.fid = &fid; |
| 1079 | oparms.reconnect = false; |
| 1080 | |
| 1081 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_buf); |
| 1082 | |
| 1083 | if (!rc || !err_buf) { |
| 1084 | kfree(utf16_path); |
| 1085 | return -ENOENT; |
| 1086 | } |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 1087 | |
| 1088 | if (le32_to_cpu(err_buf->ByteCount) < sizeof(struct smb2_symlink_err_rsp) || |
| 1089 | get_rfc1002_length(err_buf) + 4 < SMB2_SYMLINK_STRUCT_SIZE) { |
| 1090 | kfree(utf16_path); |
| 1091 | return -ENOENT; |
| 1092 | } |
| 1093 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 1094 | /* open must fail on symlink - reset rc */ |
| 1095 | rc = 0; |
| 1096 | symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData; |
| 1097 | sub_len = le16_to_cpu(symlink->SubstituteNameLength); |
| 1098 | sub_offset = le16_to_cpu(symlink->SubstituteNameOffset); |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 1099 | print_len = le16_to_cpu(symlink->PrintNameLength); |
| 1100 | print_offset = le16_to_cpu(symlink->PrintNameOffset); |
| 1101 | |
| 1102 | if (get_rfc1002_length(err_buf) + 4 < |
| 1103 | SMB2_SYMLINK_STRUCT_SIZE + sub_offset + sub_len) { |
| 1104 | kfree(utf16_path); |
| 1105 | return -ENOENT; |
| 1106 | } |
| 1107 | |
| 1108 | if (get_rfc1002_length(err_buf) + 4 < |
| 1109 | SMB2_SYMLINK_STRUCT_SIZE + print_offset + print_len) { |
| 1110 | kfree(utf16_path); |
| 1111 | return -ENOENT; |
| 1112 | } |
| 1113 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 1114 | *target_path = cifs_strndup_from_utf16( |
| 1115 | (char *)symlink->PathBuffer + sub_offset, |
| 1116 | sub_len, true, cifs_sb->local_nls); |
| 1117 | if (!(*target_path)) { |
| 1118 | kfree(utf16_path); |
| 1119 | return -ENOMEM; |
| 1120 | } |
| 1121 | convert_delimiter(*target_path, '/'); |
| 1122 | cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path); |
| 1123 | kfree(utf16_path); |
| 1124 | return rc; |
| 1125 | } |
| 1126 | |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 1127 | static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon, |
| 1128 | loff_t offset, loff_t len, bool keep_size) |
| 1129 | { |
| 1130 | struct inode *inode; |
| 1131 | struct cifsInodeInfo *cifsi; |
| 1132 | struct cifsFileInfo *cfile = file->private_data; |
| 1133 | struct file_zero_data_information fsctl_buf; |
| 1134 | long rc; |
| 1135 | unsigned int xid; |
| 1136 | |
| 1137 | xid = get_xid(); |
| 1138 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1139 | inode = d_inode(cfile->dentry); |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 1140 | cifsi = CIFS_I(inode); |
| 1141 | |
| 1142 | /* if file not oplocked can't be sure whether asking to extend size */ |
| 1143 | if (!CIFS_CACHE_READ(cifsi)) |
| 1144 | if (keep_size == false) |
| 1145 | return -EOPNOTSUPP; |
| 1146 | |
Steve French | 2bb93d2 | 2014-08-20 18:56:29 -0500 | [diff] [blame] | 1147 | /* |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 1148 | * Must check if file sparse since fallocate -z (zero range) assumes |
| 1149 | * non-sparse allocation |
| 1150 | */ |
| 1151 | if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) |
| 1152 | return -EOPNOTSUPP; |
| 1153 | |
| 1154 | /* |
| 1155 | * need to make sure we are not asked to extend the file since the SMB3 |
| 1156 | * fsctl does not change the file size. In the future we could change |
| 1157 | * this to zero the first part of the range then set the file size |
| 1158 | * which for a non sparse file would zero the newly extended range |
| 1159 | */ |
| 1160 | if (keep_size == false) |
| 1161 | if (i_size_read(inode) < offset + len) |
| 1162 | return -EOPNOTSUPP; |
| 1163 | |
| 1164 | cifs_dbg(FYI, "offset %lld len %lld", offset, len); |
| 1165 | |
| 1166 | fsctl_buf.FileOffset = cpu_to_le64(offset); |
| 1167 | fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len); |
| 1168 | |
| 1169 | rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, |
| 1170 | cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA, |
| 1171 | true /* is_fctl */, (char *)&fsctl_buf, |
| 1172 | sizeof(struct file_zero_data_information), NULL, NULL); |
| 1173 | free_xid(xid); |
| 1174 | return rc; |
| 1175 | } |
| 1176 | |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 1177 | static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon, |
| 1178 | loff_t offset, loff_t len) |
| 1179 | { |
| 1180 | struct inode *inode; |
| 1181 | struct cifsInodeInfo *cifsi; |
| 1182 | struct cifsFileInfo *cfile = file->private_data; |
| 1183 | struct file_zero_data_information fsctl_buf; |
| 1184 | long rc; |
| 1185 | unsigned int xid; |
| 1186 | __u8 set_sparse = 1; |
| 1187 | |
| 1188 | xid = get_xid(); |
| 1189 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1190 | inode = d_inode(cfile->dentry); |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 1191 | cifsi = CIFS_I(inode); |
| 1192 | |
| 1193 | /* Need to make file sparse, if not already, before freeing range. */ |
| 1194 | /* Consider adding equivalent for compressed since it could also work */ |
| 1195 | if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) |
| 1196 | return -EOPNOTSUPP; |
| 1197 | |
| 1198 | cifs_dbg(FYI, "offset %lld len %lld", offset, len); |
| 1199 | |
| 1200 | fsctl_buf.FileOffset = cpu_to_le64(offset); |
| 1201 | fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len); |
| 1202 | |
| 1203 | rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, |
| 1204 | cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA, |
| 1205 | true /* is_fctl */, (char *)&fsctl_buf, |
| 1206 | sizeof(struct file_zero_data_information), NULL, NULL); |
| 1207 | free_xid(xid); |
| 1208 | return rc; |
| 1209 | } |
| 1210 | |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 1211 | static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon, |
| 1212 | loff_t off, loff_t len, bool keep_size) |
| 1213 | { |
| 1214 | struct inode *inode; |
| 1215 | struct cifsInodeInfo *cifsi; |
| 1216 | struct cifsFileInfo *cfile = file->private_data; |
| 1217 | long rc = -EOPNOTSUPP; |
| 1218 | unsigned int xid; |
| 1219 | |
| 1220 | xid = get_xid(); |
| 1221 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1222 | inode = d_inode(cfile->dentry); |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 1223 | cifsi = CIFS_I(inode); |
| 1224 | |
| 1225 | /* if file not oplocked can't be sure whether asking to extend size */ |
| 1226 | if (!CIFS_CACHE_READ(cifsi)) |
| 1227 | if (keep_size == false) |
| 1228 | return -EOPNOTSUPP; |
| 1229 | |
| 1230 | /* |
| 1231 | * Files are non-sparse by default so falloc may be a no-op |
| 1232 | * Must check if file sparse. If not sparse, and not extending |
| 1233 | * then no need to do anything since file already allocated |
| 1234 | */ |
| 1235 | if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) { |
| 1236 | if (keep_size == true) |
| 1237 | return 0; |
| 1238 | /* check if extending file */ |
| 1239 | else if (i_size_read(inode) >= off + len) |
| 1240 | /* not extending file and already not sparse */ |
| 1241 | return 0; |
| 1242 | /* BB: in future add else clause to extend file */ |
| 1243 | else |
| 1244 | return -EOPNOTSUPP; |
| 1245 | } |
| 1246 | |
| 1247 | if ((keep_size == true) || (i_size_read(inode) >= off + len)) { |
| 1248 | /* |
| 1249 | * Check if falloc starts within first few pages of file |
| 1250 | * and ends within a few pages of the end of file to |
| 1251 | * ensure that most of file is being forced to be |
| 1252 | * fallocated now. If so then setting whole file sparse |
| 1253 | * ie potentially making a few extra pages at the beginning |
| 1254 | * or end of the file non-sparse via set_sparse is harmless. |
| 1255 | */ |
| 1256 | if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) |
| 1257 | return -EOPNOTSUPP; |
| 1258 | |
| 1259 | rc = smb2_set_sparse(xid, tcon, cfile, inode, false); |
| 1260 | } |
| 1261 | /* BB: else ... in future add code to extend file and set sparse */ |
| 1262 | |
| 1263 | |
| 1264 | free_xid(xid); |
| 1265 | return rc; |
| 1266 | } |
| 1267 | |
| 1268 | |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 1269 | static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode, |
| 1270 | loff_t off, loff_t len) |
| 1271 | { |
| 1272 | /* KEEP_SIZE already checked for by do_fallocate */ |
| 1273 | if (mode & FALLOC_FL_PUNCH_HOLE) |
| 1274 | return smb3_punch_hole(file, tcon, off, len); |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 1275 | else if (mode & FALLOC_FL_ZERO_RANGE) { |
| 1276 | if (mode & FALLOC_FL_KEEP_SIZE) |
| 1277 | return smb3_zero_range(file, tcon, off, len, true); |
| 1278 | return smb3_zero_range(file, tcon, off, len, false); |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 1279 | } else if (mode == FALLOC_FL_KEEP_SIZE) |
| 1280 | return smb3_simple_falloc(file, tcon, off, len, true); |
| 1281 | else if (mode == 0) |
| 1282 | return smb3_simple_falloc(file, tcon, off, len, false); |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 1283 | |
| 1284 | return -EOPNOTSUPP; |
| 1285 | } |
| 1286 | |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1287 | static void |
Sachin Prabhu | c11f1df | 2014-03-11 16:11:47 +0000 | [diff] [blame] | 1288 | smb2_downgrade_oplock(struct TCP_Server_Info *server, |
| 1289 | struct cifsInodeInfo *cinode, bool set_level2) |
| 1290 | { |
| 1291 | if (set_level2) |
| 1292 | server->ops->set_oplock_level(cinode, SMB2_OPLOCK_LEVEL_II, |
| 1293 | 0, NULL); |
| 1294 | else |
| 1295 | server->ops->set_oplock_level(cinode, 0, 0, NULL); |
| 1296 | } |
| 1297 | |
| 1298 | static void |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 1299 | smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock, |
| 1300 | unsigned int epoch, bool *purge_cache) |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1301 | { |
| 1302 | oplock &= 0xFF; |
| 1303 | if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE) |
| 1304 | return; |
| 1305 | if (oplock == SMB2_OPLOCK_LEVEL_BATCH) { |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 1306 | cinode->oplock = CIFS_CACHE_RHW_FLG; |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1307 | cifs_dbg(FYI, "Batch Oplock granted on inode %p\n", |
| 1308 | &cinode->vfs_inode); |
| 1309 | } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) { |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 1310 | cinode->oplock = CIFS_CACHE_RW_FLG; |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1311 | cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n", |
| 1312 | &cinode->vfs_inode); |
| 1313 | } else if (oplock == SMB2_OPLOCK_LEVEL_II) { |
| 1314 | cinode->oplock = CIFS_CACHE_READ_FLG; |
| 1315 | cifs_dbg(FYI, "Level II Oplock granted on inode %p\n", |
| 1316 | &cinode->vfs_inode); |
| 1317 | } else |
| 1318 | cinode->oplock = 0; |
| 1319 | } |
| 1320 | |
| 1321 | static void |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 1322 | smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock, |
| 1323 | unsigned int epoch, bool *purge_cache) |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1324 | { |
| 1325 | char message[5] = {0}; |
| 1326 | |
| 1327 | oplock &= 0xFF; |
| 1328 | if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE) |
| 1329 | return; |
| 1330 | |
| 1331 | cinode->oplock = 0; |
| 1332 | if (oplock & SMB2_LEASE_READ_CACHING_HE) { |
| 1333 | cinode->oplock |= CIFS_CACHE_READ_FLG; |
| 1334 | strcat(message, "R"); |
| 1335 | } |
| 1336 | if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) { |
| 1337 | cinode->oplock |= CIFS_CACHE_HANDLE_FLG; |
| 1338 | strcat(message, "H"); |
| 1339 | } |
| 1340 | if (oplock & SMB2_LEASE_WRITE_CACHING_HE) { |
| 1341 | cinode->oplock |= CIFS_CACHE_WRITE_FLG; |
| 1342 | strcat(message, "W"); |
| 1343 | } |
| 1344 | if (!cinode->oplock) |
| 1345 | strcat(message, "None"); |
| 1346 | cifs_dbg(FYI, "%s Lease granted on inode %p\n", message, |
| 1347 | &cinode->vfs_inode); |
| 1348 | } |
| 1349 | |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 1350 | static void |
| 1351 | smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock, |
| 1352 | unsigned int epoch, bool *purge_cache) |
| 1353 | { |
| 1354 | unsigned int old_oplock = cinode->oplock; |
| 1355 | |
| 1356 | smb21_set_oplock_level(cinode, oplock, epoch, purge_cache); |
| 1357 | |
| 1358 | if (purge_cache) { |
| 1359 | *purge_cache = false; |
| 1360 | if (old_oplock == CIFS_CACHE_READ_FLG) { |
| 1361 | if (cinode->oplock == CIFS_CACHE_READ_FLG && |
| 1362 | (epoch - cinode->epoch > 0)) |
| 1363 | *purge_cache = true; |
| 1364 | else if (cinode->oplock == CIFS_CACHE_RH_FLG && |
| 1365 | (epoch - cinode->epoch > 1)) |
| 1366 | *purge_cache = true; |
| 1367 | else if (cinode->oplock == CIFS_CACHE_RHW_FLG && |
| 1368 | (epoch - cinode->epoch > 1)) |
| 1369 | *purge_cache = true; |
| 1370 | else if (cinode->oplock == 0 && |
| 1371 | (epoch - cinode->epoch > 0)) |
| 1372 | *purge_cache = true; |
| 1373 | } else if (old_oplock == CIFS_CACHE_RH_FLG) { |
| 1374 | if (cinode->oplock == CIFS_CACHE_RH_FLG && |
| 1375 | (epoch - cinode->epoch > 0)) |
| 1376 | *purge_cache = true; |
| 1377 | else if (cinode->oplock == CIFS_CACHE_RHW_FLG && |
| 1378 | (epoch - cinode->epoch > 1)) |
| 1379 | *purge_cache = true; |
| 1380 | } |
| 1381 | cinode->epoch = epoch; |
| 1382 | } |
| 1383 | } |
| 1384 | |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1385 | static bool |
| 1386 | smb2_is_read_op(__u32 oplock) |
| 1387 | { |
| 1388 | return oplock == SMB2_OPLOCK_LEVEL_II; |
| 1389 | } |
| 1390 | |
| 1391 | static bool |
| 1392 | smb21_is_read_op(__u32 oplock) |
| 1393 | { |
| 1394 | return (oplock & SMB2_LEASE_READ_CACHING_HE) && |
| 1395 | !(oplock & SMB2_LEASE_WRITE_CACHING_HE); |
| 1396 | } |
| 1397 | |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1398 | static __le32 |
| 1399 | map_oplock_to_lease(u8 oplock) |
| 1400 | { |
| 1401 | if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) |
| 1402 | return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING; |
| 1403 | else if (oplock == SMB2_OPLOCK_LEVEL_II) |
| 1404 | return SMB2_LEASE_READ_CACHING; |
| 1405 | else if (oplock == SMB2_OPLOCK_LEVEL_BATCH) |
| 1406 | return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING | |
| 1407 | SMB2_LEASE_WRITE_CACHING; |
| 1408 | return 0; |
| 1409 | } |
| 1410 | |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 1411 | static char * |
| 1412 | smb2_create_lease_buf(u8 *lease_key, u8 oplock) |
| 1413 | { |
| 1414 | struct create_lease *buf; |
| 1415 | |
| 1416 | buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL); |
| 1417 | if (!buf) |
| 1418 | return NULL; |
| 1419 | |
| 1420 | buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key)); |
| 1421 | buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8))); |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1422 | buf->lcontext.LeaseState = map_oplock_to_lease(oplock); |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 1423 | |
| 1424 | buf->ccontext.DataOffset = cpu_to_le16(offsetof |
| 1425 | (struct create_lease, lcontext)); |
| 1426 | buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context)); |
| 1427 | buf->ccontext.NameOffset = cpu_to_le16(offsetof |
| 1428 | (struct create_lease, Name)); |
| 1429 | buf->ccontext.NameLength = cpu_to_le16(4); |
Steve French | 12197a7 | 2014-05-14 05:29:40 -0700 | [diff] [blame] | 1430 | /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */ |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 1431 | buf->Name[0] = 'R'; |
| 1432 | buf->Name[1] = 'q'; |
| 1433 | buf->Name[2] = 'L'; |
| 1434 | buf->Name[3] = 's'; |
| 1435 | return (char *)buf; |
| 1436 | } |
| 1437 | |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1438 | static char * |
| 1439 | smb3_create_lease_buf(u8 *lease_key, u8 oplock) |
| 1440 | { |
| 1441 | struct create_lease_v2 *buf; |
| 1442 | |
| 1443 | buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL); |
| 1444 | if (!buf) |
| 1445 | return NULL; |
| 1446 | |
| 1447 | buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key)); |
| 1448 | buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8))); |
| 1449 | buf->lcontext.LeaseState = map_oplock_to_lease(oplock); |
| 1450 | |
| 1451 | buf->ccontext.DataOffset = cpu_to_le16(offsetof |
| 1452 | (struct create_lease_v2, lcontext)); |
| 1453 | buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2)); |
| 1454 | buf->ccontext.NameOffset = cpu_to_le16(offsetof |
| 1455 | (struct create_lease_v2, Name)); |
| 1456 | buf->ccontext.NameLength = cpu_to_le16(4); |
Steve French | 12197a7 | 2014-05-14 05:29:40 -0700 | [diff] [blame] | 1457 | /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */ |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1458 | buf->Name[0] = 'R'; |
| 1459 | buf->Name[1] = 'q'; |
| 1460 | buf->Name[2] = 'L'; |
| 1461 | buf->Name[3] = 's'; |
| 1462 | return (char *)buf; |
| 1463 | } |
| 1464 | |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 1465 | static __u8 |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 1466 | smb2_parse_lease_buf(void *buf, unsigned int *epoch) |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 1467 | { |
| 1468 | struct create_lease *lc = (struct create_lease *)buf; |
| 1469 | |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 1470 | *epoch = 0; /* not used */ |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 1471 | if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS) |
| 1472 | return SMB2_OPLOCK_LEVEL_NOCHANGE; |
| 1473 | return le32_to_cpu(lc->lcontext.LeaseState); |
| 1474 | } |
| 1475 | |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1476 | static __u8 |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 1477 | smb3_parse_lease_buf(void *buf, unsigned int *epoch) |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1478 | { |
| 1479 | struct create_lease_v2 *lc = (struct create_lease_v2 *)buf; |
| 1480 | |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 1481 | *epoch = le16_to_cpu(lc->lcontext.Epoch); |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1482 | if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS) |
| 1483 | return SMB2_OPLOCK_LEVEL_NOCHANGE; |
| 1484 | return le32_to_cpu(lc->lcontext.LeaseState); |
| 1485 | } |
| 1486 | |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 1487 | static unsigned int |
| 1488 | smb2_wp_retry_size(struct inode *inode) |
| 1489 | { |
| 1490 | return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize, |
| 1491 | SMB2_MAX_BUFFER_SIZE); |
| 1492 | } |
| 1493 | |
Pavel Shilovsky | 5275580 | 2014-08-18 20:49:57 +0400 | [diff] [blame] | 1494 | static bool |
| 1495 | smb2_dir_needs_close(struct cifsFileInfo *cfile) |
| 1496 | { |
| 1497 | return !cfile->invalidHandle; |
| 1498 | } |
| 1499 | |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1500 | struct smb_version_operations smb20_operations = { |
| 1501 | .compare_fids = smb2_compare_fids, |
| 1502 | .setup_request = smb2_setup_request, |
| 1503 | .setup_async_request = smb2_setup_async_request, |
| 1504 | .check_receive = smb2_check_receive, |
| 1505 | .add_credits = smb2_add_credits, |
| 1506 | .set_credits = smb2_set_credits, |
| 1507 | .get_credits_field = smb2_get_credits_field, |
| 1508 | .get_credits = smb2_get_credits, |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 1509 | .wait_mtu_credits = cifs_wait_mtu_credits, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1510 | .get_next_mid = smb2_get_next_mid, |
| 1511 | .read_data_offset = smb2_read_data_offset, |
| 1512 | .read_data_length = smb2_read_data_length, |
| 1513 | .map_error = map_smb2_to_linux_error, |
| 1514 | .find_mid = smb2_find_mid, |
| 1515 | .check_message = smb2_check_message, |
| 1516 | .dump_detail = smb2_dump_detail, |
| 1517 | .clear_stats = smb2_clear_stats, |
| 1518 | .print_stats = smb2_print_stats, |
| 1519 | .is_oplock_break = smb2_is_valid_oplock_break, |
Sachin Prabhu | c11f1df | 2014-03-11 16:11:47 +0000 | [diff] [blame] | 1520 | .downgrade_oplock = smb2_downgrade_oplock, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1521 | .need_neg = smb2_need_neg, |
| 1522 | .negotiate = smb2_negotiate, |
| 1523 | .negotiate_wsize = smb2_negotiate_wsize, |
| 1524 | .negotiate_rsize = smb2_negotiate_rsize, |
| 1525 | .sess_setup = SMB2_sess_setup, |
| 1526 | .logoff = SMB2_logoff, |
| 1527 | .tree_connect = SMB2_tcon, |
| 1528 | .tree_disconnect = SMB2_tdis, |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 1529 | .qfs_tcon = smb2_qfs_tcon, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1530 | .is_path_accessible = smb2_is_path_accessible, |
| 1531 | .can_echo = smb2_can_echo, |
| 1532 | .echo = SMB2_echo, |
| 1533 | .query_path_info = smb2_query_path_info, |
| 1534 | .get_srv_inum = smb2_get_srv_inum, |
| 1535 | .query_file_info = smb2_query_file_info, |
| 1536 | .set_path_size = smb2_set_path_size, |
| 1537 | .set_file_size = smb2_set_file_size, |
| 1538 | .set_file_info = smb2_set_file_info, |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 1539 | .set_compression = smb2_set_compression, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1540 | .mkdir = smb2_mkdir, |
| 1541 | .mkdir_setinfo = smb2_mkdir_setinfo, |
| 1542 | .rmdir = smb2_rmdir, |
| 1543 | .unlink = smb2_unlink, |
| 1544 | .rename = smb2_rename_path, |
| 1545 | .create_hardlink = smb2_create_hardlink, |
| 1546 | .query_symlink = smb2_query_symlink, |
Sachin Prabhu | 5b23c97 | 2016-07-11 16:53:20 +0100 | [diff] [blame] | 1547 | .query_mf_symlink = smb3_query_mf_symlink, |
| 1548 | .create_mf_symlink = smb3_create_mf_symlink, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1549 | .open = smb2_open_file, |
| 1550 | .set_fid = smb2_set_fid, |
| 1551 | .close = smb2_close_file, |
| 1552 | .flush = smb2_flush_file, |
| 1553 | .async_readv = smb2_async_readv, |
| 1554 | .async_writev = smb2_async_writev, |
| 1555 | .sync_read = smb2_sync_read, |
| 1556 | .sync_write = smb2_sync_write, |
| 1557 | .query_dir_first = smb2_query_dir_first, |
| 1558 | .query_dir_next = smb2_query_dir_next, |
| 1559 | .close_dir = smb2_close_dir, |
| 1560 | .calc_smb_size = smb2_calc_size, |
| 1561 | .is_status_pending = smb2_is_status_pending, |
| 1562 | .oplock_response = smb2_oplock_response, |
| 1563 | .queryfs = smb2_queryfs, |
| 1564 | .mand_lock = smb2_mand_lock, |
| 1565 | .mand_unlock_range = smb2_unlock_range, |
| 1566 | .push_mand_locks = smb2_push_mandatory_locks, |
| 1567 | .get_lease_key = smb2_get_lease_key, |
| 1568 | .set_lease_key = smb2_set_lease_key, |
| 1569 | .new_lease_key = smb2_new_lease_key, |
| 1570 | .calc_signature = smb2_calc_signature, |
| 1571 | .is_read_op = smb2_is_read_op, |
| 1572 | .set_oplock_level = smb2_set_oplock_level, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 1573 | .create_lease_buf = smb2_create_lease_buf, |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 1574 | .parse_lease_buf = smb2_parse_lease_buf, |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1575 | .clone_range = smb2_clone_range, |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 1576 | .wp_retry_size = smb2_wp_retry_size, |
Pavel Shilovsky | 5275580 | 2014-08-18 20:49:57 +0400 | [diff] [blame] | 1577 | .dir_needs_close = smb2_dir_needs_close, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1578 | }; |
| 1579 | |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 1580 | struct smb_version_operations smb21_operations = { |
Pavel Shilovsky | 027e8ee | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 1581 | .compare_fids = smb2_compare_fids, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 1582 | .setup_request = smb2_setup_request, |
Pavel Shilovsky | c95b8ee | 2012-07-11 14:45:28 +0400 | [diff] [blame] | 1583 | .setup_async_request = smb2_setup_async_request, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 1584 | .check_receive = smb2_check_receive, |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 1585 | .add_credits = smb2_add_credits, |
| 1586 | .set_credits = smb2_set_credits, |
| 1587 | .get_credits_field = smb2_get_credits_field, |
| 1588 | .get_credits = smb2_get_credits, |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 1589 | .wait_mtu_credits = smb2_wait_mtu_credits, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 1590 | .get_next_mid = smb2_get_next_mid, |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1591 | .read_data_offset = smb2_read_data_offset, |
| 1592 | .read_data_length = smb2_read_data_length, |
| 1593 | .map_error = map_smb2_to_linux_error, |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 1594 | .find_mid = smb2_find_mid, |
| 1595 | .check_message = smb2_check_message, |
| 1596 | .dump_detail = smb2_dump_detail, |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 1597 | .clear_stats = smb2_clear_stats, |
| 1598 | .print_stats = smb2_print_stats, |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1599 | .is_oplock_break = smb2_is_valid_oplock_break, |
Sachin Prabhu | c11f1df | 2014-03-11 16:11:47 +0000 | [diff] [blame] | 1600 | .downgrade_oplock = smb2_downgrade_oplock, |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 1601 | .need_neg = smb2_need_neg, |
| 1602 | .negotiate = smb2_negotiate, |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 1603 | .negotiate_wsize = smb2_negotiate_wsize, |
| 1604 | .negotiate_rsize = smb2_negotiate_rsize, |
Pavel Shilovsky | 5478f9b | 2011-12-27 16:22:00 +0400 | [diff] [blame] | 1605 | .sess_setup = SMB2_sess_setup, |
| 1606 | .logoff = SMB2_logoff, |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 1607 | .tree_connect = SMB2_tcon, |
| 1608 | .tree_disconnect = SMB2_tdis, |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 1609 | .qfs_tcon = smb2_qfs_tcon, |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 1610 | .is_path_accessible = smb2_is_path_accessible, |
Pavel Shilovsky | 9094fad | 2012-07-12 18:30:44 +0400 | [diff] [blame] | 1611 | .can_echo = smb2_can_echo, |
| 1612 | .echo = SMB2_echo, |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 1613 | .query_path_info = smb2_query_path_info, |
| 1614 | .get_srv_inum = smb2_get_srv_inum, |
Pavel Shilovsky | b7546bc | 2012-09-18 16:20:27 -0700 | [diff] [blame] | 1615 | .query_file_info = smb2_query_file_info, |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 1616 | .set_path_size = smb2_set_path_size, |
| 1617 | .set_file_size = smb2_set_file_size, |
Pavel Shilovsky | 1feeaac | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 1618 | .set_file_info = smb2_set_file_info, |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 1619 | .set_compression = smb2_set_compression, |
Pavel Shilovsky | a0e7318 | 2011-07-19 12:56:37 +0400 | [diff] [blame] | 1620 | .mkdir = smb2_mkdir, |
| 1621 | .mkdir_setinfo = smb2_mkdir_setinfo, |
Pavel Shilovsky | 1a500f0 | 2012-07-10 16:14:38 +0400 | [diff] [blame] | 1622 | .rmdir = smb2_rmdir, |
Pavel Shilovsky | cbe6f43 | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 1623 | .unlink = smb2_unlink, |
Pavel Shilovsky | 35143eb | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 1624 | .rename = smb2_rename_path, |
Pavel Shilovsky | 568798c | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 1625 | .create_hardlink = smb2_create_hardlink, |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 1626 | .query_symlink = smb2_query_symlink, |
Steve French | c22870e | 2014-09-16 07:18:19 -0500 | [diff] [blame] | 1627 | .query_mf_symlink = smb3_query_mf_symlink, |
Steve French | 5ab9757 | 2014-09-15 04:49:28 -0500 | [diff] [blame] | 1628 | .create_mf_symlink = smb3_create_mf_symlink, |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 1629 | .open = smb2_open_file, |
| 1630 | .set_fid = smb2_set_fid, |
| 1631 | .close = smb2_close_file, |
Pavel Shilovsky | 7a5cfb1 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 1632 | .flush = smb2_flush_file, |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1633 | .async_readv = smb2_async_readv, |
Pavel Shilovsky | 3331914 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1634 | .async_writev = smb2_async_writev, |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 1635 | .sync_read = smb2_sync_read, |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 1636 | .sync_write = smb2_sync_write, |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1637 | .query_dir_first = smb2_query_dir_first, |
| 1638 | .query_dir_next = smb2_query_dir_next, |
| 1639 | .close_dir = smb2_close_dir, |
| 1640 | .calc_smb_size = smb2_calc_size, |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1641 | .is_status_pending = smb2_is_status_pending, |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1642 | .oplock_response = smb2_oplock_response, |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 1643 | .queryfs = smb2_queryfs, |
Pavel Shilovsky | f7ba7fe | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 1644 | .mand_lock = smb2_mand_lock, |
| 1645 | .mand_unlock_range = smb2_unlock_range, |
Pavel Shilovsky | b140799 | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 1646 | .push_mand_locks = smb2_push_mandatory_locks, |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 1647 | .get_lease_key = smb2_get_lease_key, |
| 1648 | .set_lease_key = smb2_set_lease_key, |
| 1649 | .new_lease_key = smb2_new_lease_key, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 1650 | .calc_signature = smb2_calc_signature, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1651 | .is_read_op = smb21_is_read_op, |
| 1652 | .set_oplock_level = smb21_set_oplock_level, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 1653 | .create_lease_buf = smb2_create_lease_buf, |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 1654 | .parse_lease_buf = smb2_parse_lease_buf, |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1655 | .clone_range = smb2_clone_range, |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 1656 | .wp_retry_size = smb2_wp_retry_size, |
Pavel Shilovsky | 5275580 | 2014-08-18 20:49:57 +0400 | [diff] [blame] | 1657 | .dir_needs_close = smb2_dir_needs_close, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 1658 | }; |
| 1659 | |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 1660 | struct smb_version_operations smb30_operations = { |
| 1661 | .compare_fids = smb2_compare_fids, |
| 1662 | .setup_request = smb2_setup_request, |
| 1663 | .setup_async_request = smb2_setup_async_request, |
| 1664 | .check_receive = smb2_check_receive, |
| 1665 | .add_credits = smb2_add_credits, |
| 1666 | .set_credits = smb2_set_credits, |
| 1667 | .get_credits_field = smb2_get_credits_field, |
| 1668 | .get_credits = smb2_get_credits, |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 1669 | .wait_mtu_credits = smb2_wait_mtu_credits, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 1670 | .get_next_mid = smb2_get_next_mid, |
| 1671 | .read_data_offset = smb2_read_data_offset, |
| 1672 | .read_data_length = smb2_read_data_length, |
| 1673 | .map_error = map_smb2_to_linux_error, |
| 1674 | .find_mid = smb2_find_mid, |
| 1675 | .check_message = smb2_check_message, |
| 1676 | .dump_detail = smb2_dump_detail, |
| 1677 | .clear_stats = smb2_clear_stats, |
| 1678 | .print_stats = smb2_print_stats, |
Steve French | 769ee6a | 2013-06-19 14:15:30 -0500 | [diff] [blame] | 1679 | .dump_share_caps = smb2_dump_share_caps, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 1680 | .is_oplock_break = smb2_is_valid_oplock_break, |
Sachin Prabhu | c11f1df | 2014-03-11 16:11:47 +0000 | [diff] [blame] | 1681 | .downgrade_oplock = smb2_downgrade_oplock, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 1682 | .need_neg = smb2_need_neg, |
| 1683 | .negotiate = smb2_negotiate, |
| 1684 | .negotiate_wsize = smb2_negotiate_wsize, |
| 1685 | .negotiate_rsize = smb2_negotiate_rsize, |
| 1686 | .sess_setup = SMB2_sess_setup, |
| 1687 | .logoff = SMB2_logoff, |
| 1688 | .tree_connect = SMB2_tcon, |
| 1689 | .tree_disconnect = SMB2_tdis, |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 1690 | .qfs_tcon = smb3_qfs_tcon, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 1691 | .is_path_accessible = smb2_is_path_accessible, |
| 1692 | .can_echo = smb2_can_echo, |
| 1693 | .echo = SMB2_echo, |
| 1694 | .query_path_info = smb2_query_path_info, |
| 1695 | .get_srv_inum = smb2_get_srv_inum, |
| 1696 | .query_file_info = smb2_query_file_info, |
| 1697 | .set_path_size = smb2_set_path_size, |
| 1698 | .set_file_size = smb2_set_file_size, |
| 1699 | .set_file_info = smb2_set_file_info, |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 1700 | .set_compression = smb2_set_compression, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 1701 | .mkdir = smb2_mkdir, |
| 1702 | .mkdir_setinfo = smb2_mkdir_setinfo, |
| 1703 | .rmdir = smb2_rmdir, |
| 1704 | .unlink = smb2_unlink, |
| 1705 | .rename = smb2_rename_path, |
| 1706 | .create_hardlink = smb2_create_hardlink, |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 1707 | .query_symlink = smb2_query_symlink, |
Steve French | c22870e | 2014-09-16 07:18:19 -0500 | [diff] [blame] | 1708 | .query_mf_symlink = smb3_query_mf_symlink, |
Steve French | 5ab9757 | 2014-09-15 04:49:28 -0500 | [diff] [blame] | 1709 | .create_mf_symlink = smb3_create_mf_symlink, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 1710 | .open = smb2_open_file, |
| 1711 | .set_fid = smb2_set_fid, |
| 1712 | .close = smb2_close_file, |
| 1713 | .flush = smb2_flush_file, |
| 1714 | .async_readv = smb2_async_readv, |
| 1715 | .async_writev = smb2_async_writev, |
| 1716 | .sync_read = smb2_sync_read, |
| 1717 | .sync_write = smb2_sync_write, |
| 1718 | .query_dir_first = smb2_query_dir_first, |
| 1719 | .query_dir_next = smb2_query_dir_next, |
| 1720 | .close_dir = smb2_close_dir, |
| 1721 | .calc_smb_size = smb2_calc_size, |
| 1722 | .is_status_pending = smb2_is_status_pending, |
| 1723 | .oplock_response = smb2_oplock_response, |
| 1724 | .queryfs = smb2_queryfs, |
| 1725 | .mand_lock = smb2_mand_lock, |
| 1726 | .mand_unlock_range = smb2_unlock_range, |
| 1727 | .push_mand_locks = smb2_push_mandatory_locks, |
| 1728 | .get_lease_key = smb2_get_lease_key, |
| 1729 | .set_lease_key = smb2_set_lease_key, |
| 1730 | .new_lease_key = smb2_new_lease_key, |
Steve French | 373512e | 2015-12-18 13:05:30 -0600 | [diff] [blame] | 1731 | .generate_signingkey = generate_smb30signingkey, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 1732 | .calc_signature = smb3_calc_signature, |
Steve French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 1733 | .set_integrity = smb3_set_integrity, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1734 | .is_read_op = smb21_is_read_op, |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 1735 | .set_oplock_level = smb3_set_oplock_level, |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1736 | .create_lease_buf = smb3_create_lease_buf, |
| 1737 | .parse_lease_buf = smb3_parse_lease_buf, |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1738 | .clone_range = smb2_clone_range, |
Steve French | ca9e7a1 | 2015-10-01 21:40:10 -0500 | [diff] [blame] | 1739 | .duplicate_extents = smb2_duplicate_extents, |
Steve French | ff1c038 | 2013-11-19 23:44:46 -0600 | [diff] [blame] | 1740 | .validate_negotiate = smb3_validate_negotiate, |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 1741 | .wp_retry_size = smb2_wp_retry_size, |
Pavel Shilovsky | 5275580 | 2014-08-18 20:49:57 +0400 | [diff] [blame] | 1742 | .dir_needs_close = smb2_dir_needs_close, |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 1743 | .fallocate = smb3_fallocate, |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 1744 | }; |
| 1745 | |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 1746 | #ifdef CONFIG_CIFS_SMB311 |
| 1747 | struct smb_version_operations smb311_operations = { |
| 1748 | .compare_fids = smb2_compare_fids, |
| 1749 | .setup_request = smb2_setup_request, |
| 1750 | .setup_async_request = smb2_setup_async_request, |
| 1751 | .check_receive = smb2_check_receive, |
| 1752 | .add_credits = smb2_add_credits, |
| 1753 | .set_credits = smb2_set_credits, |
| 1754 | .get_credits_field = smb2_get_credits_field, |
| 1755 | .get_credits = smb2_get_credits, |
| 1756 | .wait_mtu_credits = smb2_wait_mtu_credits, |
| 1757 | .get_next_mid = smb2_get_next_mid, |
| 1758 | .read_data_offset = smb2_read_data_offset, |
| 1759 | .read_data_length = smb2_read_data_length, |
| 1760 | .map_error = map_smb2_to_linux_error, |
| 1761 | .find_mid = smb2_find_mid, |
| 1762 | .check_message = smb2_check_message, |
| 1763 | .dump_detail = smb2_dump_detail, |
| 1764 | .clear_stats = smb2_clear_stats, |
| 1765 | .print_stats = smb2_print_stats, |
| 1766 | .dump_share_caps = smb2_dump_share_caps, |
| 1767 | .is_oplock_break = smb2_is_valid_oplock_break, |
| 1768 | .downgrade_oplock = smb2_downgrade_oplock, |
| 1769 | .need_neg = smb2_need_neg, |
| 1770 | .negotiate = smb2_negotiate, |
| 1771 | .negotiate_wsize = smb2_negotiate_wsize, |
| 1772 | .negotiate_rsize = smb2_negotiate_rsize, |
| 1773 | .sess_setup = SMB2_sess_setup, |
| 1774 | .logoff = SMB2_logoff, |
| 1775 | .tree_connect = SMB2_tcon, |
| 1776 | .tree_disconnect = SMB2_tdis, |
| 1777 | .qfs_tcon = smb3_qfs_tcon, |
| 1778 | .is_path_accessible = smb2_is_path_accessible, |
| 1779 | .can_echo = smb2_can_echo, |
| 1780 | .echo = SMB2_echo, |
| 1781 | .query_path_info = smb2_query_path_info, |
| 1782 | .get_srv_inum = smb2_get_srv_inum, |
| 1783 | .query_file_info = smb2_query_file_info, |
| 1784 | .set_path_size = smb2_set_path_size, |
| 1785 | .set_file_size = smb2_set_file_size, |
| 1786 | .set_file_info = smb2_set_file_info, |
| 1787 | .set_compression = smb2_set_compression, |
| 1788 | .mkdir = smb2_mkdir, |
| 1789 | .mkdir_setinfo = smb2_mkdir_setinfo, |
| 1790 | .rmdir = smb2_rmdir, |
| 1791 | .unlink = smb2_unlink, |
| 1792 | .rename = smb2_rename_path, |
| 1793 | .create_hardlink = smb2_create_hardlink, |
| 1794 | .query_symlink = smb2_query_symlink, |
| 1795 | .query_mf_symlink = smb3_query_mf_symlink, |
| 1796 | .create_mf_symlink = smb3_create_mf_symlink, |
| 1797 | .open = smb2_open_file, |
| 1798 | .set_fid = smb2_set_fid, |
| 1799 | .close = smb2_close_file, |
| 1800 | .flush = smb2_flush_file, |
| 1801 | .async_readv = smb2_async_readv, |
| 1802 | .async_writev = smb2_async_writev, |
| 1803 | .sync_read = smb2_sync_read, |
| 1804 | .sync_write = smb2_sync_write, |
| 1805 | .query_dir_first = smb2_query_dir_first, |
| 1806 | .query_dir_next = smb2_query_dir_next, |
| 1807 | .close_dir = smb2_close_dir, |
| 1808 | .calc_smb_size = smb2_calc_size, |
| 1809 | .is_status_pending = smb2_is_status_pending, |
| 1810 | .oplock_response = smb2_oplock_response, |
| 1811 | .queryfs = smb2_queryfs, |
| 1812 | .mand_lock = smb2_mand_lock, |
| 1813 | .mand_unlock_range = smb2_unlock_range, |
| 1814 | .push_mand_locks = smb2_push_mandatory_locks, |
| 1815 | .get_lease_key = smb2_get_lease_key, |
| 1816 | .set_lease_key = smb2_set_lease_key, |
| 1817 | .new_lease_key = smb2_new_lease_key, |
Steve French | 373512e | 2015-12-18 13:05:30 -0600 | [diff] [blame] | 1818 | .generate_signingkey = generate_smb311signingkey, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 1819 | .calc_signature = smb3_calc_signature, |
Steve French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 1820 | .set_integrity = smb3_set_integrity, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 1821 | .is_read_op = smb21_is_read_op, |
| 1822 | .set_oplock_level = smb3_set_oplock_level, |
| 1823 | .create_lease_buf = smb3_create_lease_buf, |
| 1824 | .parse_lease_buf = smb3_parse_lease_buf, |
| 1825 | .clone_range = smb2_clone_range, |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 1826 | .duplicate_extents = smb2_duplicate_extents, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 1827 | /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */ |
| 1828 | .wp_retry_size = smb2_wp_retry_size, |
| 1829 | .dir_needs_close = smb2_dir_needs_close, |
| 1830 | .fallocate = smb3_fallocate, |
| 1831 | }; |
| 1832 | #endif /* CIFS_SMB311 */ |
| 1833 | |
Steve French | dd446b1 | 2012-11-28 23:21:06 -0600 | [diff] [blame] | 1834 | struct smb_version_values smb20_values = { |
| 1835 | .version_string = SMB20_VERSION_STRING, |
| 1836 | .protocol_id = SMB20_PROT_ID, |
| 1837 | .req_capabilities = 0, /* MBZ */ |
| 1838 | .large_lock_type = 0, |
| 1839 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 1840 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 1841 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
| 1842 | .header_size = sizeof(struct smb2_hdr), |
| 1843 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 1844 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 1845 | .lock_cmd = SMB2_LOCK, |
| 1846 | .cap_unix = 0, |
| 1847 | .cap_nt_find = SMB2_NT_FIND, |
| 1848 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 50285882 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 1849 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 1850 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 1851 | .create_lease_size = sizeof(struct create_lease), |
Steve French | dd446b1 | 2012-11-28 23:21:06 -0600 | [diff] [blame] | 1852 | }; |
| 1853 | |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 1854 | struct smb_version_values smb21_values = { |
| 1855 | .version_string = SMB21_VERSION_STRING, |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 1856 | .protocol_id = SMB21_PROT_ID, |
| 1857 | .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */ |
| 1858 | .large_lock_type = 0, |
| 1859 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 1860 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 1861 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
| 1862 | .header_size = sizeof(struct smb2_hdr), |
| 1863 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 1864 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 1865 | .lock_cmd = SMB2_LOCK, |
| 1866 | .cap_unix = 0, |
| 1867 | .cap_nt_find = SMB2_NT_FIND, |
| 1868 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 50285882 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 1869 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 1870 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 1871 | .create_lease_size = sizeof(struct create_lease), |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 1872 | }; |
| 1873 | |
| 1874 | struct smb_version_values smb30_values = { |
| 1875 | .version_string = SMB30_VERSION_STRING, |
| 1876 | .protocol_id = SMB30_PROT_ID, |
Steve French | 373512e | 2015-12-18 13:05:30 -0600 | [diff] [blame] | 1877 | .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION, |
Pavel Shilovsky | 027e8ee | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 1878 | .large_lock_type = 0, |
| 1879 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 1880 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 1881 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 1882 | .header_size = sizeof(struct smb2_hdr), |
| 1883 | .max_header_size = MAX_SMB2_HDR_SIZE, |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1884 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 1885 | .lock_cmd = SMB2_LOCK, |
Pavel Shilovsky | 29e20f9 | 2012-07-13 13:58:14 +0400 | [diff] [blame] | 1886 | .cap_unix = 0, |
| 1887 | .cap_nt_find = SMB2_NT_FIND, |
| 1888 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 50285882 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 1889 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 1890 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1891 | .create_lease_size = sizeof(struct create_lease_v2), |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 1892 | }; |
Steve French | 20b6d8b | 2013-06-12 22:48:41 -0500 | [diff] [blame] | 1893 | |
| 1894 | struct smb_version_values smb302_values = { |
| 1895 | .version_string = SMB302_VERSION_STRING, |
| 1896 | .protocol_id = SMB302_PROT_ID, |
Steve French | 373512e | 2015-12-18 13:05:30 -0600 | [diff] [blame] | 1897 | .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION, |
Steve French | 20b6d8b | 2013-06-12 22:48:41 -0500 | [diff] [blame] | 1898 | .large_lock_type = 0, |
| 1899 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 1900 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 1901 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
| 1902 | .header_size = sizeof(struct smb2_hdr), |
| 1903 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 1904 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 1905 | .lock_cmd = SMB2_LOCK, |
| 1906 | .cap_unix = 0, |
| 1907 | .cap_nt_find = SMB2_NT_FIND, |
| 1908 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 50285882 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 1909 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 1910 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1911 | .create_lease_size = sizeof(struct create_lease_v2), |
Steve French | 20b6d8b | 2013-06-12 22:48:41 -0500 | [diff] [blame] | 1912 | }; |
Steve French | 5f7fbf7 | 2014-12-17 22:52:58 -0600 | [diff] [blame] | 1913 | |
| 1914 | #ifdef CONFIG_CIFS_SMB311 |
| 1915 | struct smb_version_values smb311_values = { |
| 1916 | .version_string = SMB311_VERSION_STRING, |
| 1917 | .protocol_id = SMB311_PROT_ID, |
Steve French | b618f00 | 2015-11-03 09:15:03 -0600 | [diff] [blame] | 1918 | .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES, |
Steve French | 5f7fbf7 | 2014-12-17 22:52:58 -0600 | [diff] [blame] | 1919 | .large_lock_type = 0, |
| 1920 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 1921 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 1922 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
| 1923 | .header_size = sizeof(struct smb2_hdr), |
| 1924 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 1925 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 1926 | .lock_cmd = SMB2_LOCK, |
| 1927 | .cap_unix = 0, |
| 1928 | .cap_nt_find = SMB2_NT_FIND, |
| 1929 | .cap_large_files = SMB2_LARGE_FILES, |
| 1930 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 1931 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 1932 | .create_lease_size = sizeof(struct create_lease_v2), |
| 1933 | }; |
| 1934 | #endif /* SMB311 */ |