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> |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 23 | #include <linux/scatterlist.h> |
| 24 | #include <crypto/aead.h> |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 25 | #include "cifsglob.h" |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 26 | #include "smb2pdu.h" |
| 27 | #include "smb2proto.h" |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 28 | #include "cifsproto.h" |
| 29 | #include "cifs_debug.h" |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 30 | #include "cifs_unicode.h" |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 31 | #include "smb2status.h" |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 32 | #include "smb2glob.h" |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 33 | #include "cifs_ioctl.h" |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 34 | |
| 35 | static int |
| 36 | change_conf(struct TCP_Server_Info *server) |
| 37 | { |
| 38 | server->credits += server->echo_credits + server->oplock_credits; |
| 39 | server->oplock_credits = server->echo_credits = 0; |
| 40 | switch (server->credits) { |
| 41 | case 0: |
| 42 | return -1; |
| 43 | case 1: |
| 44 | server->echoes = false; |
| 45 | server->oplocks = false; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 46 | cifs_dbg(VFS, "disabling echoes and oplocks\n"); |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 47 | break; |
| 48 | case 2: |
| 49 | server->echoes = true; |
| 50 | server->oplocks = false; |
| 51 | server->echo_credits = 1; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 52 | cifs_dbg(FYI, "disabling oplocks\n"); |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 53 | break; |
| 54 | default: |
| 55 | server->echoes = true; |
Steve French | e0ddde9 | 2015-09-22 09:29:38 -0500 | [diff] [blame] | 56 | if (enable_oplocks) { |
| 57 | server->oplocks = true; |
| 58 | server->oplock_credits = 1; |
| 59 | } else |
| 60 | server->oplocks = false; |
| 61 | |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 62 | server->echo_credits = 1; |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 63 | } |
| 64 | server->credits -= server->echo_credits + server->oplock_credits; |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | static void |
| 69 | smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add, |
| 70 | const int optype) |
| 71 | { |
| 72 | int *val, rc = 0; |
| 73 | spin_lock(&server->req_lock); |
| 74 | val = server->ops->get_credits_field(server, optype); |
| 75 | *val += add; |
Steve French | 141891f | 2016-09-23 00:44:16 -0500 | [diff] [blame] | 76 | if (*val > 65000) { |
| 77 | *val = 65000; /* Don't get near 64K credits, avoid srv bugs */ |
| 78 | printk_once(KERN_WARNING "server overflowed SMB3 credits\n"); |
| 79 | } |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 80 | server->in_flight--; |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 81 | if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP) |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 82 | rc = change_conf(server); |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 83 | /* |
| 84 | * Sometimes server returns 0 credits on oplock break ack - we need to |
| 85 | * rebalance credits in this case. |
| 86 | */ |
| 87 | else if (server->in_flight > 0 && server->oplock_credits == 0 && |
| 88 | server->oplocks) { |
| 89 | if (server->credits > 1) { |
| 90 | server->credits--; |
| 91 | server->oplock_credits++; |
| 92 | } |
| 93 | } |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 94 | spin_unlock(&server->req_lock); |
| 95 | wake_up(&server->request_q); |
| 96 | if (rc) |
| 97 | cifs_reconnect(server); |
| 98 | } |
| 99 | |
| 100 | static void |
| 101 | smb2_set_credits(struct TCP_Server_Info *server, const int val) |
| 102 | { |
| 103 | spin_lock(&server->req_lock); |
| 104 | server->credits = val; |
| 105 | spin_unlock(&server->req_lock); |
| 106 | } |
| 107 | |
| 108 | static int * |
| 109 | smb2_get_credits_field(struct TCP_Server_Info *server, const int optype) |
| 110 | { |
| 111 | switch (optype) { |
| 112 | case CIFS_ECHO_OP: |
| 113 | return &server->echo_credits; |
| 114 | case CIFS_OBREAK_OP: |
| 115 | return &server->oplock_credits; |
| 116 | default: |
| 117 | return &server->credits; |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | static unsigned int |
| 122 | smb2_get_credits(struct mid_q_entry *mid) |
| 123 | { |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 124 | struct smb2_sync_hdr *shdr = get_sync_hdr(mid->resp_buf); |
| 125 | |
| 126 | return le16_to_cpu(shdr->CreditRequest); |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 127 | } |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 128 | |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 129 | static int |
| 130 | smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size, |
| 131 | unsigned int *num, unsigned int *credits) |
| 132 | { |
| 133 | int rc = 0; |
| 134 | unsigned int scredits; |
| 135 | |
| 136 | spin_lock(&server->req_lock); |
| 137 | while (1) { |
| 138 | if (server->credits <= 0) { |
| 139 | spin_unlock(&server->req_lock); |
| 140 | cifs_num_waiters_inc(server); |
| 141 | rc = wait_event_killable(server->request_q, |
| 142 | has_credits(server, &server->credits)); |
| 143 | cifs_num_waiters_dec(server); |
| 144 | if (rc) |
| 145 | return rc; |
| 146 | spin_lock(&server->req_lock); |
| 147 | } else { |
| 148 | if (server->tcpStatus == CifsExiting) { |
| 149 | spin_unlock(&server->req_lock); |
| 150 | return -ENOENT; |
| 151 | } |
| 152 | |
| 153 | scredits = server->credits; |
| 154 | /* can deadlock with reopen */ |
| 155 | if (scredits == 1) { |
| 156 | *num = SMB2_MAX_BUFFER_SIZE; |
| 157 | *credits = 0; |
| 158 | break; |
| 159 | } |
| 160 | |
| 161 | /* leave one credit for a possible reopen */ |
| 162 | scredits--; |
| 163 | *num = min_t(unsigned int, size, |
| 164 | scredits * SMB2_MAX_BUFFER_SIZE); |
| 165 | |
| 166 | *credits = DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE); |
| 167 | server->credits -= *credits; |
| 168 | server->in_flight++; |
| 169 | break; |
| 170 | } |
| 171 | } |
| 172 | spin_unlock(&server->req_lock); |
| 173 | return rc; |
| 174 | } |
| 175 | |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 176 | static __u64 |
| 177 | smb2_get_next_mid(struct TCP_Server_Info *server) |
| 178 | { |
| 179 | __u64 mid; |
| 180 | /* for SMB2 we need the current value */ |
| 181 | spin_lock(&GlobalMid_Lock); |
| 182 | mid = server->CurrentMid++; |
| 183 | spin_unlock(&GlobalMid_Lock); |
| 184 | return mid; |
| 185 | } |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 186 | |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 187 | static struct mid_q_entry * |
| 188 | smb2_find_mid(struct TCP_Server_Info *server, char *buf) |
| 189 | { |
| 190 | struct mid_q_entry *mid; |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 191 | struct smb2_sync_hdr *shdr = get_sync_hdr(buf); |
| 192 | __u64 wire_mid = le64_to_cpu(shdr->MessageId); |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 193 | |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 194 | if (shdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) { |
Steve French | 373512e | 2015-12-18 13:05:30 -0600 | [diff] [blame] | 195 | cifs_dbg(VFS, "encrypted frame parsing not supported yet"); |
| 196 | return NULL; |
| 197 | } |
| 198 | |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 199 | spin_lock(&GlobalMid_Lock); |
| 200 | list_for_each_entry(mid, &server->pending_mid_q, qhead) { |
Sachin Prabhu | 9235d09 | 2014-12-09 17:37:00 +0000 | [diff] [blame] | 201 | if ((mid->mid == wire_mid) && |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 202 | (mid->mid_state == MID_REQUEST_SUBMITTED) && |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 203 | (mid->command == shdr->Command)) { |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 204 | spin_unlock(&GlobalMid_Lock); |
| 205 | return mid; |
| 206 | } |
| 207 | } |
| 208 | spin_unlock(&GlobalMid_Lock); |
| 209 | return NULL; |
| 210 | } |
| 211 | |
| 212 | static void |
| 213 | smb2_dump_detail(void *buf) |
| 214 | { |
| 215 | #ifdef CONFIG_CIFS_DEBUG2 |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 216 | struct smb2_sync_hdr *shdr = get_sync_hdr(buf); |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 217 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 218 | cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n", |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 219 | shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId, |
| 220 | shdr->ProcessId); |
| 221 | cifs_dbg(VFS, "smb buf %p len %u\n", buf, smb2_calc_size(buf)); |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 222 | #endif |
| 223 | } |
| 224 | |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 225 | static bool |
| 226 | smb2_need_neg(struct TCP_Server_Info *server) |
| 227 | { |
| 228 | return server->max_read == 0; |
| 229 | } |
| 230 | |
| 231 | static int |
| 232 | smb2_negotiate(const unsigned int xid, struct cifs_ses *ses) |
| 233 | { |
| 234 | int rc; |
| 235 | ses->server->CurrentMid = 0; |
| 236 | rc = SMB2_negotiate(xid, ses); |
| 237 | /* BB we probably don't need to retry with modern servers */ |
| 238 | if (rc == -EAGAIN) |
| 239 | rc = -EHOSTDOWN; |
| 240 | return rc; |
| 241 | } |
| 242 | |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 243 | static unsigned int |
| 244 | smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) |
| 245 | { |
| 246 | struct TCP_Server_Info *server = tcon->ses->server; |
| 247 | unsigned int wsize; |
| 248 | |
| 249 | /* start with specified wsize, or default */ |
| 250 | wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE; |
| 251 | wsize = min_t(unsigned int, wsize, server->max_write); |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 252 | |
| 253 | if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU)) |
| 254 | wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE); |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 255 | |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 256 | return wsize; |
| 257 | } |
| 258 | |
| 259 | static unsigned int |
| 260 | smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) |
| 261 | { |
| 262 | struct TCP_Server_Info *server = tcon->ses->server; |
| 263 | unsigned int rsize; |
| 264 | |
| 265 | /* start with specified rsize, or default */ |
| 266 | rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE; |
| 267 | rsize = min_t(unsigned int, rsize, server->max_read); |
Pavel Shilovsky | bed9da0 | 2014-06-25 11:28:57 +0400 | [diff] [blame] | 268 | |
| 269 | if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU)) |
| 270 | rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE); |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 271 | |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 272 | return rsize; |
| 273 | } |
| 274 | |
Steve French | c481e9f | 2013-10-14 01:21:53 -0500 | [diff] [blame] | 275 | #ifdef CONFIG_CIFS_STATS2 |
| 276 | static int |
| 277 | SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon) |
| 278 | { |
| 279 | int rc; |
| 280 | unsigned int ret_data_len = 0; |
| 281 | struct network_interface_info_ioctl_rsp *out_buf; |
| 282 | |
| 283 | rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID, |
| 284 | FSCTL_QUERY_NETWORK_INTERFACE_INFO, true /* is_fsctl */, |
Aurelien Aptel | 5114662 | 2017-02-28 15:08:41 +0100 | [diff] [blame^] | 285 | false /* use_ipc */, |
Steve French | c481e9f | 2013-10-14 01:21:53 -0500 | [diff] [blame] | 286 | NULL /* no data input */, 0 /* no data input */, |
| 287 | (char **)&out_buf, &ret_data_len); |
Steve French | 9ffc541 | 2014-10-16 15:13:14 -0500 | [diff] [blame] | 288 | if (rc != 0) |
| 289 | cifs_dbg(VFS, "error %d on ioctl to get interface list\n", rc); |
| 290 | else if (ret_data_len < sizeof(struct network_interface_info_ioctl_rsp)) { |
| 291 | cifs_dbg(VFS, "server returned bad net interface info buf\n"); |
| 292 | rc = -EINVAL; |
| 293 | } else { |
Steve French | c481e9f | 2013-10-14 01:21:53 -0500 | [diff] [blame] | 294 | /* Dump info on first interface */ |
| 295 | cifs_dbg(FYI, "Adapter Capability 0x%x\t", |
| 296 | le32_to_cpu(out_buf->Capability)); |
| 297 | cifs_dbg(FYI, "Link Speed %lld\n", |
| 298 | le64_to_cpu(out_buf->LinkSpeed)); |
Steve French | 9ffc541 | 2014-10-16 15:13:14 -0500 | [diff] [blame] | 299 | } |
Steve French | 24df148 | 2016-09-29 04:20:23 -0500 | [diff] [blame] | 300 | kfree(out_buf); |
Steve French | c481e9f | 2013-10-14 01:21:53 -0500 | [diff] [blame] | 301 | return rc; |
| 302 | } |
| 303 | #endif /* STATS2 */ |
| 304 | |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 305 | static void |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 306 | smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon) |
| 307 | { |
| 308 | int rc; |
| 309 | __le16 srch_path = 0; /* Null - open root of share */ |
| 310 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 311 | struct cifs_open_parms oparms; |
| 312 | struct cifs_fid fid; |
| 313 | |
| 314 | oparms.tcon = tcon; |
| 315 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 316 | oparms.disposition = FILE_OPEN; |
| 317 | oparms.create_options = 0; |
| 318 | oparms.fid = &fid; |
| 319 | oparms.reconnect = false; |
| 320 | |
| 321 | rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL); |
| 322 | if (rc) |
| 323 | return; |
| 324 | |
Steve French | c481e9f | 2013-10-14 01:21:53 -0500 | [diff] [blame] | 325 | #ifdef CONFIG_CIFS_STATS2 |
| 326 | SMB3_request_interfaces(xid, tcon); |
| 327 | #endif /* STATS2 */ |
| 328 | |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 329 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
| 330 | FS_ATTRIBUTE_INFORMATION); |
| 331 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
| 332 | FS_DEVICE_INFORMATION); |
| 333 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
| 334 | FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */ |
| 335 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
| 336 | return; |
| 337 | } |
| 338 | |
| 339 | static void |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 340 | smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon) |
| 341 | { |
| 342 | int rc; |
| 343 | __le16 srch_path = 0; /* Null - open root of share */ |
| 344 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 345 | struct cifs_open_parms oparms; |
| 346 | struct cifs_fid fid; |
| 347 | |
| 348 | oparms.tcon = tcon; |
| 349 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 350 | oparms.disposition = FILE_OPEN; |
| 351 | oparms.create_options = 0; |
| 352 | oparms.fid = &fid; |
| 353 | oparms.reconnect = false; |
| 354 | |
| 355 | rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL); |
| 356 | if (rc) |
| 357 | return; |
| 358 | |
Steven French | 2167114 | 2013-10-09 13:36:35 -0500 | [diff] [blame] | 359 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
| 360 | FS_ATTRIBUTE_INFORMATION); |
| 361 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
| 362 | FS_DEVICE_INFORMATION); |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 363 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
| 364 | return; |
| 365 | } |
| 366 | |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 367 | static int |
| 368 | smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon, |
| 369 | struct cifs_sb_info *cifs_sb, const char *full_path) |
| 370 | { |
| 371 | int rc; |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 372 | __le16 *utf16_path; |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 373 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 374 | struct cifs_open_parms oparms; |
| 375 | struct cifs_fid fid; |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 376 | |
| 377 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); |
| 378 | if (!utf16_path) |
| 379 | return -ENOMEM; |
| 380 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 381 | oparms.tcon = tcon; |
| 382 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 383 | oparms.disposition = FILE_OPEN; |
| 384 | oparms.create_options = 0; |
| 385 | oparms.fid = &fid; |
Pavel Shilovsky | 9cbc0b7 | 2013-07-09 18:40:58 +0400 | [diff] [blame] | 386 | oparms.reconnect = false; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 387 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 388 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL); |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 389 | if (rc) { |
| 390 | kfree(utf16_path); |
| 391 | return rc; |
| 392 | } |
| 393 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 394 | rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 395 | kfree(utf16_path); |
| 396 | return rc; |
| 397 | } |
| 398 | |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 399 | static int |
| 400 | smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon, |
| 401 | struct cifs_sb_info *cifs_sb, const char *full_path, |
| 402 | u64 *uniqueid, FILE_ALL_INFO *data) |
| 403 | { |
| 404 | *uniqueid = le64_to_cpu(data->IndexNumber); |
| 405 | return 0; |
| 406 | } |
| 407 | |
Pavel Shilovsky | b7546bc | 2012-09-18 16:20:27 -0700 | [diff] [blame] | 408 | static int |
| 409 | smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon, |
| 410 | struct cifs_fid *fid, FILE_ALL_INFO *data) |
| 411 | { |
| 412 | int rc; |
| 413 | struct smb2_file_all_info *smb2_data; |
| 414 | |
Pavel Shilovsky | 1bbe499 | 2014-08-22 13:32:11 +0400 | [diff] [blame] | 415 | smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2, |
Pavel Shilovsky | b7546bc | 2012-09-18 16:20:27 -0700 | [diff] [blame] | 416 | GFP_KERNEL); |
| 417 | if (smb2_data == NULL) |
| 418 | return -ENOMEM; |
| 419 | |
| 420 | rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid, |
| 421 | smb2_data); |
| 422 | if (!rc) |
| 423 | move_smb2_info_to_cifs(data, smb2_data); |
| 424 | kfree(smb2_data); |
| 425 | return rc; |
| 426 | } |
| 427 | |
Pavel Shilovsky | 9094fad | 2012-07-12 18:30:44 +0400 | [diff] [blame] | 428 | static bool |
| 429 | smb2_can_echo(struct TCP_Server_Info *server) |
| 430 | { |
| 431 | return server->echoes; |
| 432 | } |
| 433 | |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 434 | static void |
| 435 | smb2_clear_stats(struct cifs_tcon *tcon) |
| 436 | { |
| 437 | #ifdef CONFIG_CIFS_STATS |
| 438 | int i; |
| 439 | for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) { |
| 440 | atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0); |
| 441 | atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0); |
| 442 | } |
| 443 | #endif |
| 444 | } |
| 445 | |
| 446 | static void |
Steve French | 769ee6a | 2013-06-19 14:15:30 -0500 | [diff] [blame] | 447 | smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon) |
| 448 | { |
| 449 | seq_puts(m, "\n\tShare Capabilities:"); |
| 450 | if (tcon->capabilities & SMB2_SHARE_CAP_DFS) |
| 451 | seq_puts(m, " DFS,"); |
| 452 | if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY) |
| 453 | seq_puts(m, " CONTINUOUS AVAILABILITY,"); |
| 454 | if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT) |
| 455 | seq_puts(m, " SCALEOUT,"); |
| 456 | if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER) |
| 457 | seq_puts(m, " CLUSTER,"); |
| 458 | if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC) |
| 459 | seq_puts(m, " ASYMMETRIC,"); |
| 460 | if (tcon->capabilities == 0) |
| 461 | seq_puts(m, " None"); |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 462 | if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE) |
| 463 | seq_puts(m, " Aligned,"); |
| 464 | if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE) |
| 465 | seq_puts(m, " Partition Aligned,"); |
| 466 | if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY) |
| 467 | seq_puts(m, " SSD,"); |
| 468 | if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED) |
| 469 | seq_puts(m, " TRIM-support,"); |
| 470 | |
Steve French | 769ee6a | 2013-06-19 14:15:30 -0500 | [diff] [blame] | 471 | seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags); |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 472 | if (tcon->perf_sector_size) |
| 473 | seq_printf(m, "\tOptimal sector size: 0x%x", |
| 474 | tcon->perf_sector_size); |
Steve French | 769ee6a | 2013-06-19 14:15:30 -0500 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | static void |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 478 | smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon) |
| 479 | { |
| 480 | #ifdef CONFIG_CIFS_STATS |
| 481 | atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent; |
| 482 | atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed; |
| 483 | seq_printf(m, "\nNegotiates: %d sent %d failed", |
| 484 | atomic_read(&sent[SMB2_NEGOTIATE_HE]), |
| 485 | atomic_read(&failed[SMB2_NEGOTIATE_HE])); |
| 486 | seq_printf(m, "\nSessionSetups: %d sent %d failed", |
| 487 | atomic_read(&sent[SMB2_SESSION_SETUP_HE]), |
| 488 | atomic_read(&failed[SMB2_SESSION_SETUP_HE])); |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 489 | seq_printf(m, "\nLogoffs: %d sent %d failed", |
| 490 | atomic_read(&sent[SMB2_LOGOFF_HE]), |
| 491 | atomic_read(&failed[SMB2_LOGOFF_HE])); |
| 492 | seq_printf(m, "\nTreeConnects: %d sent %d failed", |
| 493 | atomic_read(&sent[SMB2_TREE_CONNECT_HE]), |
| 494 | atomic_read(&failed[SMB2_TREE_CONNECT_HE])); |
| 495 | seq_printf(m, "\nTreeDisconnects: %d sent %d failed", |
| 496 | atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]), |
| 497 | atomic_read(&failed[SMB2_TREE_DISCONNECT_HE])); |
| 498 | seq_printf(m, "\nCreates: %d sent %d failed", |
| 499 | atomic_read(&sent[SMB2_CREATE_HE]), |
| 500 | atomic_read(&failed[SMB2_CREATE_HE])); |
| 501 | seq_printf(m, "\nCloses: %d sent %d failed", |
| 502 | atomic_read(&sent[SMB2_CLOSE_HE]), |
| 503 | atomic_read(&failed[SMB2_CLOSE_HE])); |
| 504 | seq_printf(m, "\nFlushes: %d sent %d failed", |
| 505 | atomic_read(&sent[SMB2_FLUSH_HE]), |
| 506 | atomic_read(&failed[SMB2_FLUSH_HE])); |
| 507 | seq_printf(m, "\nReads: %d sent %d failed", |
| 508 | atomic_read(&sent[SMB2_READ_HE]), |
| 509 | atomic_read(&failed[SMB2_READ_HE])); |
| 510 | seq_printf(m, "\nWrites: %d sent %d failed", |
| 511 | atomic_read(&sent[SMB2_WRITE_HE]), |
| 512 | atomic_read(&failed[SMB2_WRITE_HE])); |
| 513 | seq_printf(m, "\nLocks: %d sent %d failed", |
| 514 | atomic_read(&sent[SMB2_LOCK_HE]), |
| 515 | atomic_read(&failed[SMB2_LOCK_HE])); |
| 516 | seq_printf(m, "\nIOCTLs: %d sent %d failed", |
| 517 | atomic_read(&sent[SMB2_IOCTL_HE]), |
| 518 | atomic_read(&failed[SMB2_IOCTL_HE])); |
| 519 | seq_printf(m, "\nCancels: %d sent %d failed", |
| 520 | atomic_read(&sent[SMB2_CANCEL_HE]), |
| 521 | atomic_read(&failed[SMB2_CANCEL_HE])); |
| 522 | seq_printf(m, "\nEchos: %d sent %d failed", |
| 523 | atomic_read(&sent[SMB2_ECHO_HE]), |
| 524 | atomic_read(&failed[SMB2_ECHO_HE])); |
| 525 | seq_printf(m, "\nQueryDirectories: %d sent %d failed", |
| 526 | atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]), |
| 527 | atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE])); |
| 528 | seq_printf(m, "\nChangeNotifies: %d sent %d failed", |
| 529 | atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]), |
| 530 | atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE])); |
| 531 | seq_printf(m, "\nQueryInfos: %d sent %d failed", |
| 532 | atomic_read(&sent[SMB2_QUERY_INFO_HE]), |
| 533 | atomic_read(&failed[SMB2_QUERY_INFO_HE])); |
| 534 | seq_printf(m, "\nSetInfos: %d sent %d failed", |
| 535 | atomic_read(&sent[SMB2_SET_INFO_HE]), |
| 536 | atomic_read(&failed[SMB2_SET_INFO_HE])); |
| 537 | seq_printf(m, "\nOplockBreaks: %d sent %d failed", |
| 538 | atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]), |
| 539 | atomic_read(&failed[SMB2_OPLOCK_BREAK_HE])); |
| 540 | #endif |
| 541 | } |
| 542 | |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 543 | static void |
| 544 | smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock) |
| 545 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 546 | struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry)); |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 547 | struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; |
| 548 | |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 549 | cfile->fid.persistent_fid = fid->persistent_fid; |
| 550 | cfile->fid.volatile_fid = fid->volatile_fid; |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 551 | server->ops->set_oplock_level(cinode, oplock, fid->epoch, |
| 552 | &fid->purge_cache); |
Pavel Shilovsky | 18cceb6 | 2013-09-05 13:01:06 +0400 | [diff] [blame] | 553 | cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode); |
Aurelien Aptel | 94f8737 | 2016-09-22 07:38:50 +0200 | [diff] [blame] | 554 | memcpy(cfile->fid.create_guid, fid->create_guid, 16); |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 555 | } |
| 556 | |
Pavel Shilovsky | 760ad0c | 2012-09-25 11:00:07 +0400 | [diff] [blame] | 557 | static void |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 558 | smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon, |
| 559 | struct cifs_fid *fid) |
| 560 | { |
Pavel Shilovsky | 760ad0c | 2012-09-25 11:00:07 +0400 | [diff] [blame] | 561 | SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 562 | } |
| 563 | |
Pavel Shilovsky | 7a5cfb1 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 564 | static int |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 565 | SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon, |
| 566 | u64 persistent_fid, u64 volatile_fid, |
| 567 | struct copychunk_ioctl *pcchunk) |
| 568 | { |
| 569 | int rc; |
| 570 | unsigned int ret_data_len; |
| 571 | struct resume_key_req *res_key; |
| 572 | |
| 573 | rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid, |
| 574 | FSCTL_SRV_REQUEST_RESUME_KEY, true /* is_fsctl */, |
Aurelien Aptel | 5114662 | 2017-02-28 15:08:41 +0100 | [diff] [blame^] | 575 | false /* use_ipc */, |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 576 | NULL, 0 /* no input */, |
| 577 | (char **)&res_key, &ret_data_len); |
| 578 | |
| 579 | if (rc) { |
| 580 | cifs_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc); |
| 581 | goto req_res_key_exit; |
| 582 | } |
| 583 | if (ret_data_len < sizeof(struct resume_key_req)) { |
| 584 | cifs_dbg(VFS, "Invalid refcopy resume key length\n"); |
| 585 | rc = -EINVAL; |
| 586 | goto req_res_key_exit; |
| 587 | } |
| 588 | memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE); |
| 589 | |
| 590 | req_res_key_exit: |
| 591 | kfree(res_key); |
| 592 | return rc; |
| 593 | } |
| 594 | |
| 595 | static int |
| 596 | smb2_clone_range(const unsigned int xid, |
| 597 | struct cifsFileInfo *srcfile, |
| 598 | struct cifsFileInfo *trgtfile, u64 src_off, |
| 599 | u64 len, u64 dest_off) |
| 600 | { |
| 601 | int rc; |
| 602 | unsigned int ret_data_len; |
| 603 | struct copychunk_ioctl *pcchunk; |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 604 | struct copychunk_ioctl_rsp *retbuf = NULL; |
| 605 | struct cifs_tcon *tcon; |
| 606 | int chunks_copied = 0; |
| 607 | bool chunk_sizes_updated = false; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 608 | |
| 609 | pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL); |
| 610 | |
| 611 | if (pcchunk == NULL) |
| 612 | return -ENOMEM; |
| 613 | |
| 614 | cifs_dbg(FYI, "in smb2_clone_range - about to call request res key\n"); |
| 615 | /* Request a key from the server to identify the source of the copy */ |
| 616 | rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink), |
| 617 | srcfile->fid.persistent_fid, |
| 618 | srcfile->fid.volatile_fid, pcchunk); |
| 619 | |
| 620 | /* Note: request_res_key sets res_key null only if rc !=0 */ |
| 621 | if (rc) |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 622 | goto cchunk_out; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 623 | |
| 624 | /* For now array only one chunk long, will make more flexible later */ |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 625 | pcchunk->ChunkCount = cpu_to_le32(1); |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 626 | pcchunk->Reserved = 0; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 627 | pcchunk->Reserved2 = 0; |
| 628 | |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 629 | tcon = tlink_tcon(trgtfile->tlink); |
| 630 | |
| 631 | while (len > 0) { |
| 632 | pcchunk->SourceOffset = cpu_to_le64(src_off); |
| 633 | pcchunk->TargetOffset = cpu_to_le64(dest_off); |
| 634 | pcchunk->Length = |
| 635 | cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk)); |
| 636 | |
| 637 | /* Request server copy to target from src identified by key */ |
| 638 | rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid, |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 639 | trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE, |
Aurelien Aptel | 5114662 | 2017-02-28 15:08:41 +0100 | [diff] [blame^] | 640 | true /* is_fsctl */, false /* use_ipc */, |
| 641 | (char *)pcchunk, |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 642 | sizeof(struct copychunk_ioctl), (char **)&retbuf, |
| 643 | &ret_data_len); |
| 644 | if (rc == 0) { |
| 645 | if (ret_data_len != |
| 646 | sizeof(struct copychunk_ioctl_rsp)) { |
| 647 | cifs_dbg(VFS, "invalid cchunk response size\n"); |
| 648 | rc = -EIO; |
| 649 | goto cchunk_out; |
| 650 | } |
| 651 | if (retbuf->TotalBytesWritten == 0) { |
| 652 | cifs_dbg(FYI, "no bytes copied\n"); |
| 653 | rc = -EIO; |
| 654 | goto cchunk_out; |
| 655 | } |
| 656 | /* |
| 657 | * Check if server claimed to write more than we asked |
| 658 | */ |
| 659 | if (le32_to_cpu(retbuf->TotalBytesWritten) > |
| 660 | le32_to_cpu(pcchunk->Length)) { |
| 661 | cifs_dbg(VFS, "invalid copy chunk response\n"); |
| 662 | rc = -EIO; |
| 663 | goto cchunk_out; |
| 664 | } |
| 665 | if (le32_to_cpu(retbuf->ChunksWritten) != 1) { |
| 666 | cifs_dbg(VFS, "invalid num chunks written\n"); |
| 667 | rc = -EIO; |
| 668 | goto cchunk_out; |
| 669 | } |
| 670 | chunks_copied++; |
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 | src_off += le32_to_cpu(retbuf->TotalBytesWritten); |
| 673 | dest_off += le32_to_cpu(retbuf->TotalBytesWritten); |
| 674 | len -= le32_to_cpu(retbuf->TotalBytesWritten); |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 675 | |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 676 | cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %d\n", |
| 677 | le32_to_cpu(retbuf->ChunksWritten), |
| 678 | le32_to_cpu(retbuf->ChunkBytesWritten), |
| 679 | le32_to_cpu(retbuf->TotalBytesWritten)); |
| 680 | } else if (rc == -EINVAL) { |
| 681 | if (ret_data_len != sizeof(struct copychunk_ioctl_rsp)) |
| 682 | goto cchunk_out; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 683 | |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 684 | cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n", |
| 685 | le32_to_cpu(retbuf->ChunksWritten), |
| 686 | le32_to_cpu(retbuf->ChunkBytesWritten), |
| 687 | le32_to_cpu(retbuf->TotalBytesWritten)); |
| 688 | |
| 689 | /* |
| 690 | * Check if this is the first request using these sizes, |
| 691 | * (ie check if copy succeed once with original sizes |
| 692 | * and check if the server gave us different sizes after |
| 693 | * we already updated max sizes on previous request). |
| 694 | * if not then why is the server returning an error now |
| 695 | */ |
| 696 | if ((chunks_copied != 0) || chunk_sizes_updated) |
| 697 | goto cchunk_out; |
| 698 | |
| 699 | /* Check that server is not asking us to grow size */ |
| 700 | if (le32_to_cpu(retbuf->ChunkBytesWritten) < |
| 701 | tcon->max_bytes_chunk) |
| 702 | tcon->max_bytes_chunk = |
| 703 | le32_to_cpu(retbuf->ChunkBytesWritten); |
| 704 | else |
| 705 | goto cchunk_out; /* server gave us bogus size */ |
| 706 | |
| 707 | /* No need to change MaxChunks since already set to 1 */ |
| 708 | chunk_sizes_updated = true; |
Sachin Prabhu | 2477bc5 | 2015-02-04 13:10:26 +0000 | [diff] [blame] | 709 | } else |
| 710 | goto cchunk_out; |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | cchunk_out: |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 714 | kfree(pcchunk); |
Steve French | 24df148 | 2016-09-29 04:20:23 -0500 | [diff] [blame] | 715 | kfree(retbuf); |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 716 | return rc; |
| 717 | } |
| 718 | |
| 719 | static int |
Pavel Shilovsky | 7a5cfb1 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 720 | smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon, |
| 721 | struct cifs_fid *fid) |
| 722 | { |
| 723 | return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
| 724 | } |
| 725 | |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 726 | static unsigned int |
| 727 | smb2_read_data_offset(char *buf) |
| 728 | { |
| 729 | struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf; |
| 730 | return rsp->DataOffset; |
| 731 | } |
| 732 | |
| 733 | static unsigned int |
| 734 | smb2_read_data_length(char *buf) |
| 735 | { |
| 736 | struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf; |
| 737 | return le32_to_cpu(rsp->DataLength); |
| 738 | } |
| 739 | |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 740 | |
| 741 | static int |
Steve French | db8b631 | 2014-09-22 05:13:55 -0500 | [diff] [blame] | 742 | smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid, |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 743 | struct cifs_io_parms *parms, unsigned int *bytes_read, |
| 744 | char **buf, int *buf_type) |
| 745 | { |
Steve French | db8b631 | 2014-09-22 05:13:55 -0500 | [diff] [blame] | 746 | parms->persistent_fid = pfid->persistent_fid; |
| 747 | parms->volatile_fid = pfid->volatile_fid; |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 748 | return SMB2_read(xid, parms, bytes_read, buf, buf_type); |
| 749 | } |
| 750 | |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 751 | static int |
Steve French | db8b631 | 2014-09-22 05:13:55 -0500 | [diff] [blame] | 752 | smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid, |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 753 | struct cifs_io_parms *parms, unsigned int *written, |
| 754 | struct kvec *iov, unsigned long nr_segs) |
| 755 | { |
| 756 | |
Steve French | db8b631 | 2014-09-22 05:13:55 -0500 | [diff] [blame] | 757 | parms->persistent_fid = pfid->persistent_fid; |
| 758 | parms->volatile_fid = pfid->volatile_fid; |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 759 | return SMB2_write(xid, parms, written, iov, nr_segs); |
| 760 | } |
| 761 | |
Steve French | d43cc79 | 2014-08-13 17:16:29 -0500 | [diff] [blame] | 762 | /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */ |
| 763 | static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon, |
| 764 | struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse) |
| 765 | { |
| 766 | struct cifsInodeInfo *cifsi; |
| 767 | int rc; |
| 768 | |
| 769 | cifsi = CIFS_I(inode); |
| 770 | |
| 771 | /* if file already sparse don't bother setting sparse again */ |
| 772 | if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse) |
| 773 | return true; /* already sparse */ |
| 774 | |
| 775 | if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse) |
| 776 | return true; /* already not sparse */ |
| 777 | |
| 778 | /* |
| 779 | * Can't check for sparse support on share the usual way via the |
| 780 | * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share |
| 781 | * since Samba server doesn't set the flag on the share, yet |
| 782 | * supports the set sparse FSCTL and returns sparse correctly |
| 783 | * in the file attributes. If we fail setting sparse though we |
| 784 | * mark that server does not support sparse files for this share |
| 785 | * to avoid repeatedly sending the unsupported fsctl to server |
| 786 | * if the file is repeatedly extended. |
| 787 | */ |
| 788 | if (tcon->broken_sparse_sup) |
| 789 | return false; |
| 790 | |
| 791 | rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, |
| 792 | cfile->fid.volatile_fid, FSCTL_SET_SPARSE, |
Aurelien Aptel | 5114662 | 2017-02-28 15:08:41 +0100 | [diff] [blame^] | 793 | true /* is_fctl */, false /* use_ipc */, |
| 794 | &setsparse, 1, NULL, NULL); |
Steve French | d43cc79 | 2014-08-13 17:16:29 -0500 | [diff] [blame] | 795 | if (rc) { |
| 796 | tcon->broken_sparse_sup = true; |
| 797 | cifs_dbg(FYI, "set sparse rc = %d\n", rc); |
| 798 | return false; |
| 799 | } |
| 800 | |
| 801 | if (setsparse) |
| 802 | cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE; |
| 803 | else |
| 804 | cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE); |
| 805 | |
| 806 | return true; |
| 807 | } |
| 808 | |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 809 | static int |
| 810 | smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon, |
| 811 | struct cifsFileInfo *cfile, __u64 size, bool set_alloc) |
| 812 | { |
| 813 | __le64 eof = cpu_to_le64(size); |
Steve French | 3d1a374 | 2014-08-11 21:05:25 -0500 | [diff] [blame] | 814 | struct inode *inode; |
| 815 | |
| 816 | /* |
| 817 | * If extending file more than one page make sparse. Many Linux fs |
| 818 | * make files sparse by default when extending via ftruncate |
| 819 | */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 820 | inode = d_inode(cfile->dentry); |
Steve French | 3d1a374 | 2014-08-11 21:05:25 -0500 | [diff] [blame] | 821 | |
| 822 | if (!set_alloc && (size > inode->i_size + 8192)) { |
Steve French | 3d1a374 | 2014-08-11 21:05:25 -0500 | [diff] [blame] | 823 | __u8 set_sparse = 1; |
Steve French | 3d1a374 | 2014-08-11 21:05:25 -0500 | [diff] [blame] | 824 | |
Steve French | d43cc79 | 2014-08-13 17:16:29 -0500 | [diff] [blame] | 825 | /* whether set sparse succeeds or not, extend the file */ |
| 826 | smb2_set_sparse(xid, tcon, cfile, inode, set_sparse); |
Steve French | 3d1a374 | 2014-08-11 21:05:25 -0500 | [diff] [blame] | 827 | } |
| 828 | |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 829 | return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, |
Steve French | f29ebb4 | 2014-07-19 21:44:58 -0500 | [diff] [blame] | 830 | cfile->fid.volatile_fid, cfile->pid, &eof, false); |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 831 | } |
| 832 | |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 833 | static int |
| 834 | smb2_duplicate_extents(const unsigned int xid, |
| 835 | struct cifsFileInfo *srcfile, |
| 836 | struct cifsFileInfo *trgtfile, u64 src_off, |
| 837 | u64 len, u64 dest_off) |
| 838 | { |
| 839 | int rc; |
| 840 | unsigned int ret_data_len; |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 841 | struct duplicate_extents_to_file dup_ext_buf; |
| 842 | struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink); |
| 843 | |
| 844 | /* server fileays advertise duplicate extent support with this flag */ |
| 845 | if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) & |
| 846 | FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0) |
| 847 | return -EOPNOTSUPP; |
| 848 | |
| 849 | dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid; |
| 850 | dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid; |
| 851 | dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off); |
| 852 | dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off); |
| 853 | dup_ext_buf.ByteCount = cpu_to_le64(len); |
| 854 | cifs_dbg(FYI, "duplicate extents: src off %lld dst off %lld len %lld", |
| 855 | src_off, dest_off, len); |
| 856 | |
| 857 | rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false); |
| 858 | if (rc) |
| 859 | goto duplicate_extents_out; |
| 860 | |
| 861 | rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid, |
| 862 | trgtfile->fid.volatile_fid, |
| 863 | FSCTL_DUPLICATE_EXTENTS_TO_FILE, |
Aurelien Aptel | 5114662 | 2017-02-28 15:08:41 +0100 | [diff] [blame^] | 864 | true /* is_fsctl */, false /* use_ipc */, |
| 865 | (char *)&dup_ext_buf, |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 866 | sizeof(struct duplicate_extents_to_file), |
Steve French | 24df148 | 2016-09-29 04:20:23 -0500 | [diff] [blame] | 867 | NULL, |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 868 | &ret_data_len); |
| 869 | |
| 870 | if (ret_data_len > 0) |
| 871 | cifs_dbg(FYI, "non-zero response length in duplicate extents"); |
| 872 | |
| 873 | duplicate_extents_out: |
| 874 | return rc; |
| 875 | } |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 876 | |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 877 | static int |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 878 | smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon, |
| 879 | struct cifsFileInfo *cfile) |
| 880 | { |
| 881 | return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid, |
| 882 | cfile->fid.volatile_fid); |
| 883 | } |
| 884 | |
| 885 | static int |
Steve French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 886 | smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon, |
| 887 | struct cifsFileInfo *cfile) |
| 888 | { |
| 889 | struct fsctl_set_integrity_information_req integr_info; |
Steve French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 890 | unsigned int ret_data_len; |
| 891 | |
| 892 | integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED); |
| 893 | integr_info.Flags = 0; |
| 894 | integr_info.Reserved = 0; |
| 895 | |
| 896 | return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, |
| 897 | cfile->fid.volatile_fid, |
| 898 | FSCTL_SET_INTEGRITY_INFORMATION, |
Aurelien Aptel | 5114662 | 2017-02-28 15:08:41 +0100 | [diff] [blame^] | 899 | true /* is_fsctl */, false /* use_ipc */, |
| 900 | (char *)&integr_info, |
Steve French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 901 | sizeof(struct fsctl_set_integrity_information_req), |
Steve French | 24df148 | 2016-09-29 04:20:23 -0500 | [diff] [blame] | 902 | NULL, |
Steve French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 903 | &ret_data_len); |
| 904 | |
| 905 | } |
| 906 | |
| 907 | static int |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 908 | smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon, |
| 909 | struct cifsFileInfo *cfile, void __user *ioc_buf) |
| 910 | { |
| 911 | char *retbuf = NULL; |
| 912 | unsigned int ret_data_len = 0; |
| 913 | int rc; |
| 914 | struct smb_snapshot_array snapshot_in; |
| 915 | |
| 916 | rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, |
| 917 | cfile->fid.volatile_fid, |
| 918 | FSCTL_SRV_ENUMERATE_SNAPSHOTS, |
Aurelien Aptel | 5114662 | 2017-02-28 15:08:41 +0100 | [diff] [blame^] | 919 | true /* is_fsctl */, false /* use_ipc */, |
| 920 | NULL, 0 /* no input data */, |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 921 | (char **)&retbuf, |
| 922 | &ret_data_len); |
| 923 | cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n", |
| 924 | rc, ret_data_len); |
| 925 | if (rc) |
| 926 | return rc; |
| 927 | |
| 928 | if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) { |
| 929 | /* Fixup buffer */ |
| 930 | if (copy_from_user(&snapshot_in, ioc_buf, |
| 931 | sizeof(struct smb_snapshot_array))) { |
| 932 | rc = -EFAULT; |
| 933 | kfree(retbuf); |
| 934 | return rc; |
| 935 | } |
| 936 | if (snapshot_in.snapshot_array_size < sizeof(struct smb_snapshot_array)) { |
| 937 | rc = -ERANGE; |
| 938 | return rc; |
| 939 | } |
| 940 | |
| 941 | if (ret_data_len > snapshot_in.snapshot_array_size) |
| 942 | ret_data_len = snapshot_in.snapshot_array_size; |
| 943 | |
| 944 | if (copy_to_user(ioc_buf, retbuf, ret_data_len)) |
| 945 | rc = -EFAULT; |
| 946 | } |
| 947 | |
| 948 | kfree(retbuf); |
| 949 | return rc; |
| 950 | } |
| 951 | |
| 952 | static int |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 953 | smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon, |
| 954 | const char *path, struct cifs_sb_info *cifs_sb, |
| 955 | struct cifs_fid *fid, __u16 search_flags, |
| 956 | struct cifs_search_info *srch_inf) |
| 957 | { |
| 958 | __le16 *utf16_path; |
| 959 | int rc; |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 960 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 961 | struct cifs_open_parms oparms; |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 962 | |
| 963 | utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); |
| 964 | if (!utf16_path) |
| 965 | return -ENOMEM; |
| 966 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 967 | oparms.tcon = tcon; |
| 968 | oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA; |
| 969 | oparms.disposition = FILE_OPEN; |
| 970 | oparms.create_options = 0; |
| 971 | oparms.fid = fid; |
Pavel Shilovsky | 9cbc0b7 | 2013-07-09 18:40:58 +0400 | [diff] [blame] | 972 | oparms.reconnect = false; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 973 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 974 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 975 | kfree(utf16_path); |
| 976 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 977 | cifs_dbg(VFS, "open dir failed\n"); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 978 | return rc; |
| 979 | } |
| 980 | |
| 981 | srch_inf->entries_in_buffer = 0; |
| 982 | srch_inf->index_of_last_entry = 0; |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 983 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 984 | rc = SMB2_query_directory(xid, tcon, fid->persistent_fid, |
| 985 | fid->volatile_fid, 0, srch_inf); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 986 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 987 | cifs_dbg(VFS, "query directory failed\n"); |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 988 | SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 989 | } |
| 990 | return rc; |
| 991 | } |
| 992 | |
| 993 | static int |
| 994 | smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon, |
| 995 | struct cifs_fid *fid, __u16 search_flags, |
| 996 | struct cifs_search_info *srch_inf) |
| 997 | { |
| 998 | return SMB2_query_directory(xid, tcon, fid->persistent_fid, |
| 999 | fid->volatile_fid, 0, srch_inf); |
| 1000 | } |
| 1001 | |
| 1002 | static int |
| 1003 | smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon, |
| 1004 | struct cifs_fid *fid) |
| 1005 | { |
| 1006 | return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
| 1007 | } |
| 1008 | |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1009 | /* |
| 1010 | * If we negotiate SMB2 protocol and get STATUS_PENDING - update |
| 1011 | * the number of credits and return true. Otherwise - return false. |
| 1012 | */ |
| 1013 | static bool |
| 1014 | smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length) |
| 1015 | { |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 1016 | struct smb2_sync_hdr *shdr = get_sync_hdr(buf); |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1017 | |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 1018 | if (shdr->Status != STATUS_PENDING) |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1019 | return false; |
| 1020 | |
| 1021 | if (!length) { |
| 1022 | spin_lock(&server->req_lock); |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 1023 | server->credits += le16_to_cpu(shdr->CreditRequest); |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1024 | spin_unlock(&server->req_lock); |
| 1025 | wake_up(&server->request_q); |
| 1026 | } |
| 1027 | |
| 1028 | return true; |
| 1029 | } |
| 1030 | |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1031 | static int |
| 1032 | smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid, |
| 1033 | struct cifsInodeInfo *cinode) |
| 1034 | { |
Pavel Shilovsky | 0822f51 | 2012-09-19 06:22:45 -0700 | [diff] [blame] | 1035 | if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING) |
| 1036 | return SMB2_lease_break(0, tcon, cinode->lease_key, |
| 1037 | smb2_get_lease_state(cinode)); |
| 1038 | |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1039 | return SMB2_oplock_break(0, tcon, fid->persistent_fid, |
| 1040 | fid->volatile_fid, |
Pavel Shilovsky | 18cceb6 | 2013-09-05 13:01:06 +0400 | [diff] [blame] | 1041 | CIFS_CACHE_READ(cinode) ? 1 : 0); |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1042 | } |
| 1043 | |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 1044 | static int |
| 1045 | smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon, |
| 1046 | struct kstatfs *buf) |
| 1047 | { |
| 1048 | int rc; |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 1049 | __le16 srch_path = 0; /* Null - open root of share */ |
| 1050 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1051 | struct cifs_open_parms oparms; |
| 1052 | struct cifs_fid fid; |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 1053 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1054 | oparms.tcon = tcon; |
| 1055 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 1056 | oparms.disposition = FILE_OPEN; |
| 1057 | oparms.create_options = 0; |
| 1058 | oparms.fid = &fid; |
Pavel Shilovsky | 9cbc0b7 | 2013-07-09 18:40:58 +0400 | [diff] [blame] | 1059 | oparms.reconnect = false; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1060 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 1061 | rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL); |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 1062 | if (rc) |
| 1063 | return rc; |
| 1064 | buf->f_type = SMB2_MAGIC_NUMBER; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1065 | rc = SMB2_QFS_info(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
| 1066 | buf); |
| 1067 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 1068 | return rc; |
| 1069 | } |
| 1070 | |
Pavel Shilovsky | 027e8ee | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 1071 | static bool |
| 1072 | smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2) |
| 1073 | { |
| 1074 | return ob1->fid.persistent_fid == ob2->fid.persistent_fid && |
| 1075 | ob1->fid.volatile_fid == ob2->fid.volatile_fid; |
| 1076 | } |
| 1077 | |
Pavel Shilovsky | f7ba7fe | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 1078 | static int |
| 1079 | smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset, |
| 1080 | __u64 length, __u32 type, int lock, int unlock, bool wait) |
| 1081 | { |
| 1082 | if (unlock && !lock) |
| 1083 | type = SMB2_LOCKFLAG_UNLOCK; |
| 1084 | return SMB2_lock(xid, tlink_tcon(cfile->tlink), |
| 1085 | cfile->fid.persistent_fid, cfile->fid.volatile_fid, |
| 1086 | current->tgid, length, offset, type, wait); |
| 1087 | } |
| 1088 | |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 1089 | static void |
| 1090 | smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid) |
| 1091 | { |
| 1092 | memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE); |
| 1093 | } |
| 1094 | |
| 1095 | static void |
| 1096 | smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid) |
| 1097 | { |
| 1098 | memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE); |
| 1099 | } |
| 1100 | |
| 1101 | static void |
| 1102 | smb2_new_lease_key(struct cifs_fid *fid) |
| 1103 | { |
Steve French | fa70b87 | 2016-09-22 00:39:34 -0500 | [diff] [blame] | 1104 | generate_random_uuid(fid->lease_key); |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 1105 | } |
| 1106 | |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 1107 | #define SMB2_SYMLINK_STRUCT_SIZE \ |
| 1108 | (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp)) |
| 1109 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 1110 | static int |
| 1111 | smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon, |
| 1112 | const char *full_path, char **target_path, |
| 1113 | struct cifs_sb_info *cifs_sb) |
| 1114 | { |
| 1115 | int rc; |
| 1116 | __le16 *utf16_path; |
| 1117 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 1118 | struct cifs_open_parms oparms; |
| 1119 | struct cifs_fid fid; |
| 1120 | struct smb2_err_rsp *err_buf = NULL; |
| 1121 | struct smb2_symlink_err_rsp *symlink; |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 1122 | unsigned int sub_len; |
| 1123 | unsigned int sub_offset; |
| 1124 | unsigned int print_len; |
| 1125 | unsigned int print_offset; |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 1126 | |
| 1127 | cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path); |
| 1128 | |
| 1129 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); |
| 1130 | if (!utf16_path) |
| 1131 | return -ENOMEM; |
| 1132 | |
| 1133 | oparms.tcon = tcon; |
| 1134 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 1135 | oparms.disposition = FILE_OPEN; |
| 1136 | oparms.create_options = 0; |
| 1137 | oparms.fid = &fid; |
| 1138 | oparms.reconnect = false; |
| 1139 | |
| 1140 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_buf); |
| 1141 | |
| 1142 | if (!rc || !err_buf) { |
| 1143 | kfree(utf16_path); |
| 1144 | return -ENOENT; |
| 1145 | } |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 1146 | |
| 1147 | if (le32_to_cpu(err_buf->ByteCount) < sizeof(struct smb2_symlink_err_rsp) || |
| 1148 | get_rfc1002_length(err_buf) + 4 < SMB2_SYMLINK_STRUCT_SIZE) { |
| 1149 | kfree(utf16_path); |
| 1150 | return -ENOENT; |
| 1151 | } |
| 1152 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 1153 | /* open must fail on symlink - reset rc */ |
| 1154 | rc = 0; |
| 1155 | symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData; |
| 1156 | sub_len = le16_to_cpu(symlink->SubstituteNameLength); |
| 1157 | sub_offset = le16_to_cpu(symlink->SubstituteNameOffset); |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 1158 | print_len = le16_to_cpu(symlink->PrintNameLength); |
| 1159 | print_offset = le16_to_cpu(symlink->PrintNameOffset); |
| 1160 | |
| 1161 | if (get_rfc1002_length(err_buf) + 4 < |
| 1162 | SMB2_SYMLINK_STRUCT_SIZE + sub_offset + sub_len) { |
| 1163 | kfree(utf16_path); |
| 1164 | return -ENOENT; |
| 1165 | } |
| 1166 | |
| 1167 | if (get_rfc1002_length(err_buf) + 4 < |
| 1168 | SMB2_SYMLINK_STRUCT_SIZE + print_offset + print_len) { |
| 1169 | kfree(utf16_path); |
| 1170 | return -ENOENT; |
| 1171 | } |
| 1172 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 1173 | *target_path = cifs_strndup_from_utf16( |
| 1174 | (char *)symlink->PathBuffer + sub_offset, |
| 1175 | sub_len, true, cifs_sb->local_nls); |
| 1176 | if (!(*target_path)) { |
| 1177 | kfree(utf16_path); |
| 1178 | return -ENOMEM; |
| 1179 | } |
| 1180 | convert_delimiter(*target_path, '/'); |
| 1181 | cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path); |
| 1182 | kfree(utf16_path); |
| 1183 | return rc; |
| 1184 | } |
| 1185 | |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 1186 | static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon, |
| 1187 | loff_t offset, loff_t len, bool keep_size) |
| 1188 | { |
| 1189 | struct inode *inode; |
| 1190 | struct cifsInodeInfo *cifsi; |
| 1191 | struct cifsFileInfo *cfile = file->private_data; |
| 1192 | struct file_zero_data_information fsctl_buf; |
| 1193 | long rc; |
| 1194 | unsigned int xid; |
| 1195 | |
| 1196 | xid = get_xid(); |
| 1197 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1198 | inode = d_inode(cfile->dentry); |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 1199 | cifsi = CIFS_I(inode); |
| 1200 | |
| 1201 | /* if file not oplocked can't be sure whether asking to extend size */ |
| 1202 | if (!CIFS_CACHE_READ(cifsi)) |
| 1203 | if (keep_size == false) |
| 1204 | return -EOPNOTSUPP; |
| 1205 | |
Steve French | 2bb93d2 | 2014-08-20 18:56:29 -0500 | [diff] [blame] | 1206 | /* |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 1207 | * Must check if file sparse since fallocate -z (zero range) assumes |
| 1208 | * non-sparse allocation |
| 1209 | */ |
| 1210 | if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) |
| 1211 | return -EOPNOTSUPP; |
| 1212 | |
| 1213 | /* |
| 1214 | * need to make sure we are not asked to extend the file since the SMB3 |
| 1215 | * fsctl does not change the file size. In the future we could change |
| 1216 | * this to zero the first part of the range then set the file size |
| 1217 | * which for a non sparse file would zero the newly extended range |
| 1218 | */ |
| 1219 | if (keep_size == false) |
| 1220 | if (i_size_read(inode) < offset + len) |
| 1221 | return -EOPNOTSUPP; |
| 1222 | |
| 1223 | cifs_dbg(FYI, "offset %lld len %lld", offset, len); |
| 1224 | |
| 1225 | fsctl_buf.FileOffset = cpu_to_le64(offset); |
| 1226 | fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len); |
| 1227 | |
| 1228 | rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, |
| 1229 | cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA, |
Aurelien Aptel | 5114662 | 2017-02-28 15:08:41 +0100 | [diff] [blame^] | 1230 | true /* is_fctl */, false /* use_ipc */, |
| 1231 | (char *)&fsctl_buf, |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 1232 | sizeof(struct file_zero_data_information), NULL, NULL); |
| 1233 | free_xid(xid); |
| 1234 | return rc; |
| 1235 | } |
| 1236 | |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 1237 | static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon, |
| 1238 | loff_t offset, loff_t len) |
| 1239 | { |
| 1240 | struct inode *inode; |
| 1241 | struct cifsInodeInfo *cifsi; |
| 1242 | struct cifsFileInfo *cfile = file->private_data; |
| 1243 | struct file_zero_data_information fsctl_buf; |
| 1244 | long rc; |
| 1245 | unsigned int xid; |
| 1246 | __u8 set_sparse = 1; |
| 1247 | |
| 1248 | xid = get_xid(); |
| 1249 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1250 | inode = d_inode(cfile->dentry); |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 1251 | cifsi = CIFS_I(inode); |
| 1252 | |
| 1253 | /* Need to make file sparse, if not already, before freeing range. */ |
| 1254 | /* Consider adding equivalent for compressed since it could also work */ |
| 1255 | if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) |
| 1256 | return -EOPNOTSUPP; |
| 1257 | |
| 1258 | cifs_dbg(FYI, "offset %lld len %lld", offset, len); |
| 1259 | |
| 1260 | fsctl_buf.FileOffset = cpu_to_le64(offset); |
| 1261 | fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len); |
| 1262 | |
| 1263 | rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, |
| 1264 | cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA, |
Aurelien Aptel | 5114662 | 2017-02-28 15:08:41 +0100 | [diff] [blame^] | 1265 | true /* is_fctl */, false /* use_ipc */, |
| 1266 | (char *)&fsctl_buf, |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 1267 | sizeof(struct file_zero_data_information), NULL, NULL); |
| 1268 | free_xid(xid); |
| 1269 | return rc; |
| 1270 | } |
| 1271 | |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 1272 | static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon, |
| 1273 | loff_t off, loff_t len, bool keep_size) |
| 1274 | { |
| 1275 | struct inode *inode; |
| 1276 | struct cifsInodeInfo *cifsi; |
| 1277 | struct cifsFileInfo *cfile = file->private_data; |
| 1278 | long rc = -EOPNOTSUPP; |
| 1279 | unsigned int xid; |
| 1280 | |
| 1281 | xid = get_xid(); |
| 1282 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1283 | inode = d_inode(cfile->dentry); |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 1284 | cifsi = CIFS_I(inode); |
| 1285 | |
| 1286 | /* if file not oplocked can't be sure whether asking to extend size */ |
| 1287 | if (!CIFS_CACHE_READ(cifsi)) |
| 1288 | if (keep_size == false) |
| 1289 | return -EOPNOTSUPP; |
| 1290 | |
| 1291 | /* |
| 1292 | * Files are non-sparse by default so falloc may be a no-op |
| 1293 | * Must check if file sparse. If not sparse, and not extending |
| 1294 | * then no need to do anything since file already allocated |
| 1295 | */ |
| 1296 | if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) { |
| 1297 | if (keep_size == true) |
| 1298 | return 0; |
| 1299 | /* check if extending file */ |
| 1300 | else if (i_size_read(inode) >= off + len) |
| 1301 | /* not extending file and already not sparse */ |
| 1302 | return 0; |
| 1303 | /* BB: in future add else clause to extend file */ |
| 1304 | else |
| 1305 | return -EOPNOTSUPP; |
| 1306 | } |
| 1307 | |
| 1308 | if ((keep_size == true) || (i_size_read(inode) >= off + len)) { |
| 1309 | /* |
| 1310 | * Check if falloc starts within first few pages of file |
| 1311 | * and ends within a few pages of the end of file to |
| 1312 | * ensure that most of file is being forced to be |
| 1313 | * fallocated now. If so then setting whole file sparse |
| 1314 | * ie potentially making a few extra pages at the beginning |
| 1315 | * or end of the file non-sparse via set_sparse is harmless. |
| 1316 | */ |
| 1317 | if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) |
| 1318 | return -EOPNOTSUPP; |
| 1319 | |
| 1320 | rc = smb2_set_sparse(xid, tcon, cfile, inode, false); |
| 1321 | } |
| 1322 | /* BB: else ... in future add code to extend file and set sparse */ |
| 1323 | |
| 1324 | |
| 1325 | free_xid(xid); |
| 1326 | return rc; |
| 1327 | } |
| 1328 | |
| 1329 | |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 1330 | static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode, |
| 1331 | loff_t off, loff_t len) |
| 1332 | { |
| 1333 | /* KEEP_SIZE already checked for by do_fallocate */ |
| 1334 | if (mode & FALLOC_FL_PUNCH_HOLE) |
| 1335 | return smb3_punch_hole(file, tcon, off, len); |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 1336 | else if (mode & FALLOC_FL_ZERO_RANGE) { |
| 1337 | if (mode & FALLOC_FL_KEEP_SIZE) |
| 1338 | return smb3_zero_range(file, tcon, off, len, true); |
| 1339 | return smb3_zero_range(file, tcon, off, len, false); |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 1340 | } else if (mode == FALLOC_FL_KEEP_SIZE) |
| 1341 | return smb3_simple_falloc(file, tcon, off, len, true); |
| 1342 | else if (mode == 0) |
| 1343 | return smb3_simple_falloc(file, tcon, off, len, false); |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 1344 | |
| 1345 | return -EOPNOTSUPP; |
| 1346 | } |
| 1347 | |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1348 | static void |
Sachin Prabhu | c11f1df | 2014-03-11 16:11:47 +0000 | [diff] [blame] | 1349 | smb2_downgrade_oplock(struct TCP_Server_Info *server, |
| 1350 | struct cifsInodeInfo *cinode, bool set_level2) |
| 1351 | { |
| 1352 | if (set_level2) |
| 1353 | server->ops->set_oplock_level(cinode, SMB2_OPLOCK_LEVEL_II, |
| 1354 | 0, NULL); |
| 1355 | else |
| 1356 | server->ops->set_oplock_level(cinode, 0, 0, NULL); |
| 1357 | } |
| 1358 | |
| 1359 | static void |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 1360 | smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock, |
| 1361 | unsigned int epoch, bool *purge_cache) |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1362 | { |
| 1363 | oplock &= 0xFF; |
| 1364 | if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE) |
| 1365 | return; |
| 1366 | if (oplock == SMB2_OPLOCK_LEVEL_BATCH) { |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 1367 | cinode->oplock = CIFS_CACHE_RHW_FLG; |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1368 | cifs_dbg(FYI, "Batch Oplock granted on inode %p\n", |
| 1369 | &cinode->vfs_inode); |
| 1370 | } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) { |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 1371 | cinode->oplock = CIFS_CACHE_RW_FLG; |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1372 | cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n", |
| 1373 | &cinode->vfs_inode); |
| 1374 | } else if (oplock == SMB2_OPLOCK_LEVEL_II) { |
| 1375 | cinode->oplock = CIFS_CACHE_READ_FLG; |
| 1376 | cifs_dbg(FYI, "Level II Oplock granted on inode %p\n", |
| 1377 | &cinode->vfs_inode); |
| 1378 | } else |
| 1379 | cinode->oplock = 0; |
| 1380 | } |
| 1381 | |
| 1382 | static void |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 1383 | smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock, |
| 1384 | unsigned int epoch, bool *purge_cache) |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1385 | { |
| 1386 | char message[5] = {0}; |
| 1387 | |
| 1388 | oplock &= 0xFF; |
| 1389 | if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE) |
| 1390 | return; |
| 1391 | |
| 1392 | cinode->oplock = 0; |
| 1393 | if (oplock & SMB2_LEASE_READ_CACHING_HE) { |
| 1394 | cinode->oplock |= CIFS_CACHE_READ_FLG; |
| 1395 | strcat(message, "R"); |
| 1396 | } |
| 1397 | if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) { |
| 1398 | cinode->oplock |= CIFS_CACHE_HANDLE_FLG; |
| 1399 | strcat(message, "H"); |
| 1400 | } |
| 1401 | if (oplock & SMB2_LEASE_WRITE_CACHING_HE) { |
| 1402 | cinode->oplock |= CIFS_CACHE_WRITE_FLG; |
| 1403 | strcat(message, "W"); |
| 1404 | } |
| 1405 | if (!cinode->oplock) |
| 1406 | strcat(message, "None"); |
| 1407 | cifs_dbg(FYI, "%s Lease granted on inode %p\n", message, |
| 1408 | &cinode->vfs_inode); |
| 1409 | } |
| 1410 | |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 1411 | static void |
| 1412 | smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock, |
| 1413 | unsigned int epoch, bool *purge_cache) |
| 1414 | { |
| 1415 | unsigned int old_oplock = cinode->oplock; |
| 1416 | |
| 1417 | smb21_set_oplock_level(cinode, oplock, epoch, purge_cache); |
| 1418 | |
| 1419 | if (purge_cache) { |
| 1420 | *purge_cache = false; |
| 1421 | if (old_oplock == CIFS_CACHE_READ_FLG) { |
| 1422 | if (cinode->oplock == CIFS_CACHE_READ_FLG && |
| 1423 | (epoch - cinode->epoch > 0)) |
| 1424 | *purge_cache = true; |
| 1425 | else if (cinode->oplock == CIFS_CACHE_RH_FLG && |
| 1426 | (epoch - cinode->epoch > 1)) |
| 1427 | *purge_cache = true; |
| 1428 | else if (cinode->oplock == CIFS_CACHE_RHW_FLG && |
| 1429 | (epoch - cinode->epoch > 1)) |
| 1430 | *purge_cache = true; |
| 1431 | else if (cinode->oplock == 0 && |
| 1432 | (epoch - cinode->epoch > 0)) |
| 1433 | *purge_cache = true; |
| 1434 | } else if (old_oplock == CIFS_CACHE_RH_FLG) { |
| 1435 | if (cinode->oplock == CIFS_CACHE_RH_FLG && |
| 1436 | (epoch - cinode->epoch > 0)) |
| 1437 | *purge_cache = true; |
| 1438 | else if (cinode->oplock == CIFS_CACHE_RHW_FLG && |
| 1439 | (epoch - cinode->epoch > 1)) |
| 1440 | *purge_cache = true; |
| 1441 | } |
| 1442 | cinode->epoch = epoch; |
| 1443 | } |
| 1444 | } |
| 1445 | |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1446 | static bool |
| 1447 | smb2_is_read_op(__u32 oplock) |
| 1448 | { |
| 1449 | return oplock == SMB2_OPLOCK_LEVEL_II; |
| 1450 | } |
| 1451 | |
| 1452 | static bool |
| 1453 | smb21_is_read_op(__u32 oplock) |
| 1454 | { |
| 1455 | return (oplock & SMB2_LEASE_READ_CACHING_HE) && |
| 1456 | !(oplock & SMB2_LEASE_WRITE_CACHING_HE); |
| 1457 | } |
| 1458 | |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1459 | static __le32 |
| 1460 | map_oplock_to_lease(u8 oplock) |
| 1461 | { |
| 1462 | if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) |
| 1463 | return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING; |
| 1464 | else if (oplock == SMB2_OPLOCK_LEVEL_II) |
| 1465 | return SMB2_LEASE_READ_CACHING; |
| 1466 | else if (oplock == SMB2_OPLOCK_LEVEL_BATCH) |
| 1467 | return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING | |
| 1468 | SMB2_LEASE_WRITE_CACHING; |
| 1469 | return 0; |
| 1470 | } |
| 1471 | |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 1472 | static char * |
| 1473 | smb2_create_lease_buf(u8 *lease_key, u8 oplock) |
| 1474 | { |
| 1475 | struct create_lease *buf; |
| 1476 | |
| 1477 | buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL); |
| 1478 | if (!buf) |
| 1479 | return NULL; |
| 1480 | |
| 1481 | buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key)); |
| 1482 | buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8))); |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1483 | buf->lcontext.LeaseState = map_oplock_to_lease(oplock); |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 1484 | |
| 1485 | buf->ccontext.DataOffset = cpu_to_le16(offsetof |
| 1486 | (struct create_lease, lcontext)); |
| 1487 | buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context)); |
| 1488 | buf->ccontext.NameOffset = cpu_to_le16(offsetof |
| 1489 | (struct create_lease, Name)); |
| 1490 | buf->ccontext.NameLength = cpu_to_le16(4); |
Steve French | 12197a7 | 2014-05-14 05:29:40 -0700 | [diff] [blame] | 1491 | /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */ |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 1492 | buf->Name[0] = 'R'; |
| 1493 | buf->Name[1] = 'q'; |
| 1494 | buf->Name[2] = 'L'; |
| 1495 | buf->Name[3] = 's'; |
| 1496 | return (char *)buf; |
| 1497 | } |
| 1498 | |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1499 | static char * |
| 1500 | smb3_create_lease_buf(u8 *lease_key, u8 oplock) |
| 1501 | { |
| 1502 | struct create_lease_v2 *buf; |
| 1503 | |
| 1504 | buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL); |
| 1505 | if (!buf) |
| 1506 | return NULL; |
| 1507 | |
| 1508 | buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key)); |
| 1509 | buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8))); |
| 1510 | buf->lcontext.LeaseState = map_oplock_to_lease(oplock); |
| 1511 | |
| 1512 | buf->ccontext.DataOffset = cpu_to_le16(offsetof |
| 1513 | (struct create_lease_v2, lcontext)); |
| 1514 | buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2)); |
| 1515 | buf->ccontext.NameOffset = cpu_to_le16(offsetof |
| 1516 | (struct create_lease_v2, Name)); |
| 1517 | buf->ccontext.NameLength = cpu_to_le16(4); |
Steve French | 12197a7 | 2014-05-14 05:29:40 -0700 | [diff] [blame] | 1518 | /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */ |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1519 | buf->Name[0] = 'R'; |
| 1520 | buf->Name[1] = 'q'; |
| 1521 | buf->Name[2] = 'L'; |
| 1522 | buf->Name[3] = 's'; |
| 1523 | return (char *)buf; |
| 1524 | } |
| 1525 | |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 1526 | static __u8 |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 1527 | smb2_parse_lease_buf(void *buf, unsigned int *epoch) |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 1528 | { |
| 1529 | struct create_lease *lc = (struct create_lease *)buf; |
| 1530 | |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 1531 | *epoch = 0; /* not used */ |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 1532 | if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS) |
| 1533 | return SMB2_OPLOCK_LEVEL_NOCHANGE; |
| 1534 | return le32_to_cpu(lc->lcontext.LeaseState); |
| 1535 | } |
| 1536 | |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1537 | static __u8 |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 1538 | smb3_parse_lease_buf(void *buf, unsigned int *epoch) |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1539 | { |
| 1540 | struct create_lease_v2 *lc = (struct create_lease_v2 *)buf; |
| 1541 | |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 1542 | *epoch = le16_to_cpu(lc->lcontext.Epoch); |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1543 | if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS) |
| 1544 | return SMB2_OPLOCK_LEVEL_NOCHANGE; |
| 1545 | return le32_to_cpu(lc->lcontext.LeaseState); |
| 1546 | } |
| 1547 | |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 1548 | static unsigned int |
| 1549 | smb2_wp_retry_size(struct inode *inode) |
| 1550 | { |
| 1551 | return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize, |
| 1552 | SMB2_MAX_BUFFER_SIZE); |
| 1553 | } |
| 1554 | |
Pavel Shilovsky | 5275580 | 2014-08-18 20:49:57 +0400 | [diff] [blame] | 1555 | static bool |
| 1556 | smb2_dir_needs_close(struct cifsFileInfo *cfile) |
| 1557 | { |
| 1558 | return !cfile->invalidHandle; |
| 1559 | } |
| 1560 | |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 1561 | static void |
| 1562 | fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, struct smb_rqst *old_rq) |
| 1563 | { |
| 1564 | struct smb2_sync_hdr *shdr = |
| 1565 | (struct smb2_sync_hdr *)old_rq->rq_iov[1].iov_base; |
| 1566 | unsigned int orig_len = get_rfc1002_length(old_rq->rq_iov[0].iov_base); |
| 1567 | |
| 1568 | memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr)); |
| 1569 | tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM; |
| 1570 | tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len); |
| 1571 | tr_hdr->Flags = cpu_to_le16(0x01); |
| 1572 | get_random_bytes(&tr_hdr->Nonce, SMB3_AES128CMM_NONCE); |
| 1573 | memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8); |
| 1574 | inc_rfc1001_len(tr_hdr, sizeof(struct smb2_transform_hdr) - 4); |
| 1575 | inc_rfc1001_len(tr_hdr, orig_len); |
| 1576 | } |
| 1577 | |
| 1578 | static struct scatterlist * |
| 1579 | init_sg(struct smb_rqst *rqst, u8 *sign) |
| 1580 | { |
| 1581 | unsigned int sg_len = rqst->rq_nvec + rqst->rq_npages + 1; |
| 1582 | unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 24; |
| 1583 | struct scatterlist *sg; |
| 1584 | unsigned int i; |
| 1585 | unsigned int j; |
| 1586 | |
| 1587 | sg = kmalloc_array(sg_len, sizeof(struct scatterlist), GFP_KERNEL); |
| 1588 | if (!sg) |
| 1589 | return NULL; |
| 1590 | |
| 1591 | sg_init_table(sg, sg_len); |
| 1592 | sg_set_buf(&sg[0], rqst->rq_iov[0].iov_base + 24, assoc_data_len); |
| 1593 | for (i = 1; i < rqst->rq_nvec; i++) |
| 1594 | sg_set_buf(&sg[i], rqst->rq_iov[i].iov_base, |
| 1595 | rqst->rq_iov[i].iov_len); |
| 1596 | for (j = 0; i < sg_len - 1; i++, j++) { |
| 1597 | unsigned int len = (j < rqst->rq_npages - 1) ? rqst->rq_pagesz |
| 1598 | : rqst->rq_tailsz; |
| 1599 | sg_set_page(&sg[i], rqst->rq_pages[j], len, 0); |
| 1600 | } |
| 1601 | sg_set_buf(&sg[sg_len - 1], sign, SMB2_SIGNATURE_SIZE); |
| 1602 | return sg; |
| 1603 | } |
| 1604 | |
| 1605 | struct cifs_crypt_result { |
| 1606 | int err; |
| 1607 | struct completion completion; |
| 1608 | }; |
| 1609 | |
| 1610 | static void cifs_crypt_complete(struct crypto_async_request *req, int err) |
| 1611 | { |
| 1612 | struct cifs_crypt_result *res = req->data; |
| 1613 | |
| 1614 | if (err == -EINPROGRESS) |
| 1615 | return; |
| 1616 | |
| 1617 | res->err = err; |
| 1618 | complete(&res->completion); |
| 1619 | } |
| 1620 | |
Pavel Shilovsky | 61cfac6f | 2017-02-28 16:05:19 -0800 | [diff] [blame] | 1621 | static int |
| 1622 | smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key) |
| 1623 | { |
| 1624 | struct cifs_ses *ses; |
| 1625 | u8 *ses_enc_key; |
| 1626 | |
| 1627 | spin_lock(&cifs_tcp_ses_lock); |
| 1628 | list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) { |
| 1629 | if (ses->Suid != ses_id) |
| 1630 | continue; |
| 1631 | ses_enc_key = enc ? ses->smb3encryptionkey : |
| 1632 | ses->smb3decryptionkey; |
| 1633 | memcpy(key, ses_enc_key, SMB3_SIGN_KEY_SIZE); |
| 1634 | spin_unlock(&cifs_tcp_ses_lock); |
| 1635 | return 0; |
| 1636 | } |
| 1637 | spin_unlock(&cifs_tcp_ses_lock); |
| 1638 | |
| 1639 | return 1; |
| 1640 | } |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 1641 | /* |
| 1642 | * Encrypt or decrypt @rqst message. @rqst has the following format: |
| 1643 | * iov[0] - transform header (associate data), |
| 1644 | * iov[1-N] and pages - data to encrypt. |
| 1645 | * On success return encrypted data in iov[1-N] and pages, leave iov[0] |
| 1646 | * untouched. |
| 1647 | */ |
| 1648 | static int |
| 1649 | crypt_message(struct TCP_Server_Info *server, struct smb_rqst *rqst, int enc) |
| 1650 | { |
| 1651 | struct smb2_transform_hdr *tr_hdr = |
| 1652 | (struct smb2_transform_hdr *)rqst->rq_iov[0].iov_base; |
| 1653 | unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 24; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 1654 | int rc = 0; |
| 1655 | struct scatterlist *sg; |
| 1656 | u8 sign[SMB2_SIGNATURE_SIZE] = {}; |
Pavel Shilovsky | 61cfac6f | 2017-02-28 16:05:19 -0800 | [diff] [blame] | 1657 | u8 key[SMB3_SIGN_KEY_SIZE]; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 1658 | struct aead_request *req; |
| 1659 | char *iv; |
| 1660 | unsigned int iv_len; |
| 1661 | struct cifs_crypt_result result = {0, }; |
| 1662 | struct crypto_aead *tfm; |
| 1663 | unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize); |
| 1664 | |
| 1665 | init_completion(&result.completion); |
| 1666 | |
Pavel Shilovsky | 61cfac6f | 2017-02-28 16:05:19 -0800 | [diff] [blame] | 1667 | rc = smb2_get_enc_key(server, tr_hdr->SessionId, enc, key); |
| 1668 | if (rc) { |
| 1669 | cifs_dbg(VFS, "%s: Could not get %scryption key\n", __func__, |
| 1670 | enc ? "en" : "de"); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 1671 | return 0; |
| 1672 | } |
| 1673 | |
| 1674 | rc = smb3_crypto_aead_allocate(server); |
| 1675 | if (rc) { |
| 1676 | cifs_dbg(VFS, "%s: crypto alloc failed\n", __func__); |
| 1677 | return rc; |
| 1678 | } |
| 1679 | |
| 1680 | tfm = enc ? server->secmech.ccmaesencrypt : |
| 1681 | server->secmech.ccmaesdecrypt; |
Pavel Shilovsky | 61cfac6f | 2017-02-28 16:05:19 -0800 | [diff] [blame] | 1682 | rc = crypto_aead_setkey(tfm, key, SMB3_SIGN_KEY_SIZE); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 1683 | if (rc) { |
| 1684 | cifs_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc); |
| 1685 | return rc; |
| 1686 | } |
| 1687 | |
| 1688 | rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE); |
| 1689 | if (rc) { |
| 1690 | cifs_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc); |
| 1691 | return rc; |
| 1692 | } |
| 1693 | |
| 1694 | req = aead_request_alloc(tfm, GFP_KERNEL); |
| 1695 | if (!req) { |
| 1696 | cifs_dbg(VFS, "%s: Failed to alloc aead request", __func__); |
| 1697 | return -ENOMEM; |
| 1698 | } |
| 1699 | |
| 1700 | if (!enc) { |
| 1701 | memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE); |
| 1702 | crypt_len += SMB2_SIGNATURE_SIZE; |
| 1703 | } |
| 1704 | |
| 1705 | sg = init_sg(rqst, sign); |
| 1706 | if (!sg) { |
| 1707 | cifs_dbg(VFS, "%s: Failed to init sg %d", __func__, rc); |
| 1708 | goto free_req; |
| 1709 | } |
| 1710 | |
| 1711 | iv_len = crypto_aead_ivsize(tfm); |
| 1712 | iv = kzalloc(iv_len, GFP_KERNEL); |
| 1713 | if (!iv) { |
| 1714 | cifs_dbg(VFS, "%s: Failed to alloc IV", __func__); |
| 1715 | goto free_sg; |
| 1716 | } |
| 1717 | iv[0] = 3; |
| 1718 | memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES128CMM_NONCE); |
| 1719 | |
| 1720 | aead_request_set_crypt(req, sg, sg, crypt_len, iv); |
| 1721 | aead_request_set_ad(req, assoc_data_len); |
| 1722 | |
| 1723 | aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, |
| 1724 | cifs_crypt_complete, &result); |
| 1725 | |
| 1726 | rc = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req); |
| 1727 | |
| 1728 | if (rc == -EINPROGRESS || rc == -EBUSY) { |
| 1729 | wait_for_completion(&result.completion); |
| 1730 | rc = result.err; |
| 1731 | } |
| 1732 | |
| 1733 | if (!rc && enc) |
| 1734 | memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE); |
| 1735 | |
| 1736 | kfree(iv); |
| 1737 | free_sg: |
| 1738 | kfree(sg); |
| 1739 | free_req: |
| 1740 | kfree(req); |
| 1741 | return rc; |
| 1742 | } |
| 1743 | |
| 1744 | static int |
| 1745 | smb3_init_transform_rq(struct TCP_Server_Info *server, struct smb_rqst *new_rq, |
| 1746 | struct smb_rqst *old_rq) |
| 1747 | { |
| 1748 | struct kvec *iov; |
| 1749 | struct page **pages; |
| 1750 | struct smb2_transform_hdr *tr_hdr; |
| 1751 | unsigned int npages = old_rq->rq_npages; |
| 1752 | int i; |
| 1753 | int rc = -ENOMEM; |
| 1754 | |
| 1755 | pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL); |
| 1756 | if (!pages) |
| 1757 | return rc; |
| 1758 | |
| 1759 | new_rq->rq_pages = pages; |
| 1760 | new_rq->rq_npages = old_rq->rq_npages; |
| 1761 | new_rq->rq_pagesz = old_rq->rq_pagesz; |
| 1762 | new_rq->rq_tailsz = old_rq->rq_tailsz; |
| 1763 | |
| 1764 | for (i = 0; i < npages; i++) { |
| 1765 | pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM); |
| 1766 | if (!pages[i]) |
| 1767 | goto err_free_pages; |
| 1768 | } |
| 1769 | |
| 1770 | iov = kmalloc_array(old_rq->rq_nvec, sizeof(struct kvec), GFP_KERNEL); |
| 1771 | if (!iov) |
| 1772 | goto err_free_pages; |
| 1773 | |
| 1774 | /* copy all iovs from the old except the 1st one (rfc1002 length) */ |
| 1775 | memcpy(&iov[1], &old_rq->rq_iov[1], |
| 1776 | sizeof(struct kvec) * (old_rq->rq_nvec - 1)); |
| 1777 | new_rq->rq_iov = iov; |
| 1778 | new_rq->rq_nvec = old_rq->rq_nvec; |
| 1779 | |
| 1780 | tr_hdr = kmalloc(sizeof(struct smb2_transform_hdr), GFP_KERNEL); |
| 1781 | if (!tr_hdr) |
| 1782 | goto err_free_iov; |
| 1783 | |
| 1784 | /* fill the 1st iov with a transform header */ |
| 1785 | fill_transform_hdr(tr_hdr, old_rq); |
| 1786 | new_rq->rq_iov[0].iov_base = tr_hdr; |
| 1787 | new_rq->rq_iov[0].iov_len = sizeof(struct smb2_transform_hdr); |
| 1788 | |
| 1789 | /* copy pages form the old */ |
| 1790 | for (i = 0; i < npages; i++) { |
| 1791 | char *dst = kmap(new_rq->rq_pages[i]); |
| 1792 | char *src = kmap(old_rq->rq_pages[i]); |
| 1793 | unsigned int len = (i < npages - 1) ? new_rq->rq_pagesz : |
| 1794 | new_rq->rq_tailsz; |
| 1795 | memcpy(dst, src, len); |
| 1796 | kunmap(new_rq->rq_pages[i]); |
| 1797 | kunmap(old_rq->rq_pages[i]); |
| 1798 | } |
| 1799 | |
| 1800 | rc = crypt_message(server, new_rq, 1); |
| 1801 | cifs_dbg(FYI, "encrypt message returned %d", rc); |
| 1802 | if (rc) |
| 1803 | goto err_free_tr_hdr; |
| 1804 | |
| 1805 | return rc; |
| 1806 | |
| 1807 | err_free_tr_hdr: |
| 1808 | kfree(tr_hdr); |
| 1809 | err_free_iov: |
| 1810 | kfree(iov); |
| 1811 | err_free_pages: |
| 1812 | for (i = i - 1; i >= 0; i--) |
| 1813 | put_page(pages[i]); |
| 1814 | kfree(pages); |
| 1815 | return rc; |
| 1816 | } |
| 1817 | |
| 1818 | static void |
| 1819 | smb3_free_transform_rq(struct smb_rqst *rqst) |
| 1820 | { |
| 1821 | int i = rqst->rq_npages - 1; |
| 1822 | |
| 1823 | for (; i >= 0; i--) |
| 1824 | put_page(rqst->rq_pages[i]); |
| 1825 | kfree(rqst->rq_pages); |
| 1826 | /* free transform header */ |
| 1827 | kfree(rqst->rq_iov[0].iov_base); |
| 1828 | kfree(rqst->rq_iov); |
| 1829 | } |
| 1830 | |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 1831 | static int |
| 1832 | smb3_is_transform_hdr(void *buf) |
| 1833 | { |
| 1834 | struct smb2_transform_hdr *trhdr = buf; |
| 1835 | |
| 1836 | return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM; |
| 1837 | } |
| 1838 | |
| 1839 | static int |
| 1840 | decrypt_raw_data(struct TCP_Server_Info *server, char *buf, |
| 1841 | unsigned int buf_data_size, struct page **pages, |
| 1842 | unsigned int npages, unsigned int page_data_size) |
| 1843 | { |
| 1844 | struct kvec iov[2]; |
| 1845 | struct smb_rqst rqst = {NULL}; |
| 1846 | struct smb2_hdr *hdr; |
| 1847 | int rc; |
| 1848 | |
| 1849 | iov[0].iov_base = buf; |
| 1850 | iov[0].iov_len = sizeof(struct smb2_transform_hdr); |
| 1851 | iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr); |
| 1852 | iov[1].iov_len = buf_data_size; |
| 1853 | |
| 1854 | rqst.rq_iov = iov; |
| 1855 | rqst.rq_nvec = 2; |
| 1856 | rqst.rq_pages = pages; |
| 1857 | rqst.rq_npages = npages; |
| 1858 | rqst.rq_pagesz = PAGE_SIZE; |
| 1859 | rqst.rq_tailsz = (page_data_size % PAGE_SIZE) ? : PAGE_SIZE; |
| 1860 | |
| 1861 | rc = crypt_message(server, &rqst, 0); |
| 1862 | cifs_dbg(FYI, "decrypt message returned %d\n", rc); |
| 1863 | |
| 1864 | if (rc) |
| 1865 | return rc; |
| 1866 | |
| 1867 | memmove(buf + 4, iov[1].iov_base, buf_data_size); |
| 1868 | hdr = (struct smb2_hdr *)buf; |
| 1869 | hdr->smb2_buf_length = cpu_to_be32(buf_data_size + page_data_size); |
| 1870 | server->total_read = buf_data_size + page_data_size + 4; |
| 1871 | |
| 1872 | return rc; |
| 1873 | } |
| 1874 | |
| 1875 | static int |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 1876 | read_data_into_pages(struct TCP_Server_Info *server, struct page **pages, |
| 1877 | unsigned int npages, unsigned int len) |
| 1878 | { |
| 1879 | int i; |
| 1880 | int length; |
| 1881 | |
| 1882 | for (i = 0; i < npages; i++) { |
| 1883 | struct page *page = pages[i]; |
| 1884 | size_t n; |
| 1885 | |
| 1886 | n = len; |
| 1887 | if (len >= PAGE_SIZE) { |
| 1888 | /* enough data to fill the page */ |
| 1889 | n = PAGE_SIZE; |
| 1890 | len -= n; |
| 1891 | } else { |
| 1892 | zero_user(page, len, PAGE_SIZE - len); |
| 1893 | len = 0; |
| 1894 | } |
| 1895 | length = cifs_read_page_from_socket(server, page, n); |
| 1896 | if (length < 0) |
| 1897 | return length; |
| 1898 | server->total_read += length; |
| 1899 | } |
| 1900 | |
| 1901 | return 0; |
| 1902 | } |
| 1903 | |
| 1904 | static int |
| 1905 | init_read_bvec(struct page **pages, unsigned int npages, unsigned int data_size, |
| 1906 | unsigned int cur_off, struct bio_vec **page_vec) |
| 1907 | { |
| 1908 | struct bio_vec *bvec; |
| 1909 | int i; |
| 1910 | |
| 1911 | bvec = kcalloc(npages, sizeof(struct bio_vec), GFP_KERNEL); |
| 1912 | if (!bvec) |
| 1913 | return -ENOMEM; |
| 1914 | |
| 1915 | for (i = 0; i < npages; i++) { |
| 1916 | bvec[i].bv_page = pages[i]; |
| 1917 | bvec[i].bv_offset = (i == 0) ? cur_off : 0; |
| 1918 | bvec[i].bv_len = min_t(unsigned int, PAGE_SIZE, data_size); |
| 1919 | data_size -= bvec[i].bv_len; |
| 1920 | } |
| 1921 | |
| 1922 | if (data_size != 0) { |
| 1923 | cifs_dbg(VFS, "%s: something went wrong\n", __func__); |
| 1924 | kfree(bvec); |
| 1925 | return -EIO; |
| 1926 | } |
| 1927 | |
| 1928 | *page_vec = bvec; |
| 1929 | return 0; |
| 1930 | } |
| 1931 | |
| 1932 | static int |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 1933 | handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid, |
| 1934 | char *buf, unsigned int buf_len, struct page **pages, |
| 1935 | unsigned int npages, unsigned int page_data_size) |
| 1936 | { |
| 1937 | unsigned int data_offset; |
| 1938 | unsigned int data_len; |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 1939 | unsigned int cur_off; |
| 1940 | unsigned int cur_page_idx; |
| 1941 | unsigned int pad_len; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 1942 | struct cifs_readdata *rdata = mid->callback_data; |
| 1943 | struct smb2_sync_hdr *shdr = get_sync_hdr(buf); |
| 1944 | struct bio_vec *bvec = NULL; |
| 1945 | struct iov_iter iter; |
| 1946 | struct kvec iov; |
| 1947 | int length; |
| 1948 | |
| 1949 | if (shdr->Command != SMB2_READ) { |
| 1950 | cifs_dbg(VFS, "only big read responses are supported\n"); |
| 1951 | return -ENOTSUPP; |
| 1952 | } |
| 1953 | |
| 1954 | if (server->ops->is_status_pending && |
| 1955 | server->ops->is_status_pending(buf, server, 0)) |
| 1956 | return -1; |
| 1957 | |
| 1958 | rdata->result = server->ops->map_error(buf, false); |
| 1959 | if (rdata->result != 0) { |
| 1960 | cifs_dbg(FYI, "%s: server returned error %d\n", |
| 1961 | __func__, rdata->result); |
| 1962 | dequeue_mid(mid, rdata->result); |
| 1963 | return 0; |
| 1964 | } |
| 1965 | |
| 1966 | data_offset = server->ops->read_data_offset(buf) + 4; |
| 1967 | data_len = server->ops->read_data_length(buf); |
| 1968 | |
| 1969 | if (data_offset < server->vals->read_rsp_size) { |
| 1970 | /* |
| 1971 | * win2k8 sometimes sends an offset of 0 when the read |
| 1972 | * is beyond the EOF. Treat it as if the data starts just after |
| 1973 | * the header. |
| 1974 | */ |
| 1975 | cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n", |
| 1976 | __func__, data_offset); |
| 1977 | data_offset = server->vals->read_rsp_size; |
| 1978 | } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) { |
| 1979 | /* data_offset is beyond the end of smallbuf */ |
| 1980 | cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n", |
| 1981 | __func__, data_offset); |
| 1982 | rdata->result = -EIO; |
| 1983 | dequeue_mid(mid, rdata->result); |
| 1984 | return 0; |
| 1985 | } |
| 1986 | |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 1987 | pad_len = data_offset - server->vals->read_rsp_size; |
| 1988 | |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 1989 | if (buf_len <= data_offset) { |
| 1990 | /* read response payload is in pages */ |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 1991 | cur_page_idx = pad_len / PAGE_SIZE; |
| 1992 | cur_off = pad_len % PAGE_SIZE; |
| 1993 | |
| 1994 | if (cur_page_idx != 0) { |
| 1995 | /* data offset is beyond the 1st page of response */ |
| 1996 | cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n", |
| 1997 | __func__, data_offset); |
| 1998 | rdata->result = -EIO; |
| 1999 | dequeue_mid(mid, rdata->result); |
| 2000 | return 0; |
| 2001 | } |
| 2002 | |
| 2003 | if (data_len > page_data_size - pad_len) { |
| 2004 | /* data_len is corrupt -- discard frame */ |
| 2005 | rdata->result = -EIO; |
| 2006 | dequeue_mid(mid, rdata->result); |
| 2007 | return 0; |
| 2008 | } |
| 2009 | |
| 2010 | rdata->result = init_read_bvec(pages, npages, page_data_size, |
| 2011 | cur_off, &bvec); |
| 2012 | if (rdata->result != 0) { |
| 2013 | dequeue_mid(mid, rdata->result); |
| 2014 | return 0; |
| 2015 | } |
| 2016 | |
| 2017 | iov_iter_bvec(&iter, WRITE | ITER_BVEC, bvec, npages, data_len); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2018 | } else if (buf_len >= data_offset + data_len) { |
| 2019 | /* read response payload is in buf */ |
| 2020 | WARN_ONCE(npages > 0, "read data can be either in buf or in pages"); |
| 2021 | iov.iov_base = buf + data_offset; |
| 2022 | iov.iov_len = data_len; |
| 2023 | iov_iter_kvec(&iter, WRITE | ITER_KVEC, &iov, 1, data_len); |
| 2024 | } else { |
| 2025 | /* read response payload cannot be in both buf and pages */ |
| 2026 | WARN_ONCE(1, "buf can not contain only a part of read data"); |
| 2027 | rdata->result = -EIO; |
| 2028 | dequeue_mid(mid, rdata->result); |
| 2029 | return 0; |
| 2030 | } |
| 2031 | |
| 2032 | /* set up first iov for signature check */ |
| 2033 | rdata->iov[0].iov_base = buf; |
| 2034 | rdata->iov[0].iov_len = 4; |
| 2035 | rdata->iov[1].iov_base = buf + 4; |
| 2036 | rdata->iov[1].iov_len = server->vals->read_rsp_size - 4; |
| 2037 | cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n", |
| 2038 | rdata->iov[0].iov_base, server->vals->read_rsp_size); |
| 2039 | |
| 2040 | length = rdata->copy_into_pages(server, rdata, &iter); |
| 2041 | |
| 2042 | kfree(bvec); |
| 2043 | |
| 2044 | if (length < 0) |
| 2045 | return length; |
| 2046 | |
| 2047 | dequeue_mid(mid, false); |
| 2048 | return length; |
| 2049 | } |
| 2050 | |
| 2051 | static int |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 2052 | receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid) |
| 2053 | { |
| 2054 | char *buf = server->smallbuf; |
| 2055 | struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf; |
| 2056 | unsigned int npages; |
| 2057 | struct page **pages; |
| 2058 | unsigned int len; |
| 2059 | unsigned int buflen = get_rfc1002_length(buf) + 4; |
| 2060 | int rc; |
| 2061 | int i = 0; |
| 2062 | |
| 2063 | len = min_t(unsigned int, buflen, server->vals->read_rsp_size - 4 + |
| 2064 | sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1; |
| 2065 | |
| 2066 | rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len); |
| 2067 | if (rc < 0) |
| 2068 | return rc; |
| 2069 | server->total_read += rc; |
| 2070 | |
| 2071 | len = le32_to_cpu(tr_hdr->OriginalMessageSize) + 4 - |
| 2072 | server->vals->read_rsp_size; |
| 2073 | npages = DIV_ROUND_UP(len, PAGE_SIZE); |
| 2074 | |
| 2075 | pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL); |
| 2076 | if (!pages) { |
| 2077 | rc = -ENOMEM; |
| 2078 | goto discard_data; |
| 2079 | } |
| 2080 | |
| 2081 | for (; i < npages; i++) { |
| 2082 | pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM); |
| 2083 | if (!pages[i]) { |
| 2084 | rc = -ENOMEM; |
| 2085 | goto discard_data; |
| 2086 | } |
| 2087 | } |
| 2088 | |
| 2089 | /* read read data into pages */ |
| 2090 | rc = read_data_into_pages(server, pages, npages, len); |
| 2091 | if (rc) |
| 2092 | goto free_pages; |
| 2093 | |
| 2094 | rc = cifs_discard_remaining_data(server); |
| 2095 | if (rc) |
| 2096 | goto free_pages; |
| 2097 | |
| 2098 | rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size - 4, |
| 2099 | pages, npages, len); |
| 2100 | if (rc) |
| 2101 | goto free_pages; |
| 2102 | |
| 2103 | *mid = smb2_find_mid(server, buf); |
| 2104 | if (*mid == NULL) |
| 2105 | cifs_dbg(FYI, "mid not found\n"); |
| 2106 | else { |
| 2107 | cifs_dbg(FYI, "mid found\n"); |
| 2108 | (*mid)->decrypted = true; |
| 2109 | rc = handle_read_data(server, *mid, buf, |
| 2110 | server->vals->read_rsp_size, |
| 2111 | pages, npages, len); |
| 2112 | } |
| 2113 | |
| 2114 | free_pages: |
| 2115 | for (i = i - 1; i >= 0; i--) |
| 2116 | put_page(pages[i]); |
| 2117 | kfree(pages); |
| 2118 | return rc; |
| 2119 | discard_data: |
| 2120 | cifs_discard_remaining_data(server); |
| 2121 | goto free_pages; |
| 2122 | } |
| 2123 | |
| 2124 | static int |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2125 | receive_encrypted_standard(struct TCP_Server_Info *server, |
| 2126 | struct mid_q_entry **mid) |
| 2127 | { |
| 2128 | int length; |
| 2129 | char *buf = server->smallbuf; |
| 2130 | unsigned int pdu_length = get_rfc1002_length(buf); |
| 2131 | unsigned int buf_size; |
| 2132 | struct mid_q_entry *mid_entry; |
| 2133 | |
| 2134 | /* switch to large buffer if too big for a small one */ |
| 2135 | if (pdu_length + 4 > MAX_CIFS_SMALL_BUFFER_SIZE) { |
| 2136 | server->large_buf = true; |
| 2137 | memcpy(server->bigbuf, buf, server->total_read); |
| 2138 | buf = server->bigbuf; |
| 2139 | } |
| 2140 | |
| 2141 | /* now read the rest */ |
| 2142 | length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, |
| 2143 | pdu_length - HEADER_SIZE(server) + 1 + 4); |
| 2144 | if (length < 0) |
| 2145 | return length; |
| 2146 | server->total_read += length; |
| 2147 | |
| 2148 | buf_size = pdu_length + 4 - sizeof(struct smb2_transform_hdr); |
| 2149 | length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0); |
| 2150 | if (length) |
| 2151 | return length; |
| 2152 | |
| 2153 | mid_entry = smb2_find_mid(server, buf); |
| 2154 | if (mid_entry == NULL) |
| 2155 | cifs_dbg(FYI, "mid not found\n"); |
| 2156 | else { |
| 2157 | cifs_dbg(FYI, "mid found\n"); |
| 2158 | mid_entry->decrypted = true; |
| 2159 | } |
| 2160 | |
| 2161 | *mid = mid_entry; |
| 2162 | |
| 2163 | if (mid_entry && mid_entry->handle) |
| 2164 | return mid_entry->handle(server, mid_entry); |
| 2165 | |
| 2166 | return cifs_handle_standard(server, mid_entry); |
| 2167 | } |
| 2168 | |
| 2169 | static int |
| 2170 | smb3_receive_transform(struct TCP_Server_Info *server, struct mid_q_entry **mid) |
| 2171 | { |
| 2172 | char *buf = server->smallbuf; |
| 2173 | unsigned int pdu_length = get_rfc1002_length(buf); |
| 2174 | struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf; |
| 2175 | unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize); |
| 2176 | |
| 2177 | if (pdu_length + 4 < sizeof(struct smb2_transform_hdr) + |
| 2178 | sizeof(struct smb2_sync_hdr)) { |
| 2179 | cifs_dbg(VFS, "Transform message is too small (%u)\n", |
| 2180 | pdu_length); |
| 2181 | cifs_reconnect(server); |
| 2182 | wake_up(&server->response_q); |
| 2183 | return -ECONNABORTED; |
| 2184 | } |
| 2185 | |
| 2186 | if (pdu_length + 4 < orig_len + sizeof(struct smb2_transform_hdr)) { |
| 2187 | cifs_dbg(VFS, "Transform message is broken\n"); |
| 2188 | cifs_reconnect(server); |
| 2189 | wake_up(&server->response_q); |
| 2190 | return -ECONNABORTED; |
| 2191 | } |
| 2192 | |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 2193 | if (pdu_length + 4 > CIFSMaxBufSize + MAX_HEADER_SIZE(server)) |
| 2194 | return receive_encrypted_read(server, mid); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2195 | |
| 2196 | return receive_encrypted_standard(server, mid); |
| 2197 | } |
| 2198 | |
| 2199 | int |
| 2200 | smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid) |
| 2201 | { |
| 2202 | char *buf = server->large_buf ? server->bigbuf : server->smallbuf; |
| 2203 | |
| 2204 | return handle_read_data(server, mid, buf, get_rfc1002_length(buf) + 4, |
| 2205 | NULL, 0, 0); |
| 2206 | } |
| 2207 | |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 2208 | struct smb_version_operations smb20_operations = { |
| 2209 | .compare_fids = smb2_compare_fids, |
| 2210 | .setup_request = smb2_setup_request, |
| 2211 | .setup_async_request = smb2_setup_async_request, |
| 2212 | .check_receive = smb2_check_receive, |
| 2213 | .add_credits = smb2_add_credits, |
| 2214 | .set_credits = smb2_set_credits, |
| 2215 | .get_credits_field = smb2_get_credits_field, |
| 2216 | .get_credits = smb2_get_credits, |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 2217 | .wait_mtu_credits = cifs_wait_mtu_credits, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 2218 | .get_next_mid = smb2_get_next_mid, |
| 2219 | .read_data_offset = smb2_read_data_offset, |
| 2220 | .read_data_length = smb2_read_data_length, |
| 2221 | .map_error = map_smb2_to_linux_error, |
| 2222 | .find_mid = smb2_find_mid, |
| 2223 | .check_message = smb2_check_message, |
| 2224 | .dump_detail = smb2_dump_detail, |
| 2225 | .clear_stats = smb2_clear_stats, |
| 2226 | .print_stats = smb2_print_stats, |
| 2227 | .is_oplock_break = smb2_is_valid_oplock_break, |
Sachin Prabhu | c11f1df | 2014-03-11 16:11:47 +0000 | [diff] [blame] | 2228 | .downgrade_oplock = smb2_downgrade_oplock, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 2229 | .need_neg = smb2_need_neg, |
| 2230 | .negotiate = smb2_negotiate, |
| 2231 | .negotiate_wsize = smb2_negotiate_wsize, |
| 2232 | .negotiate_rsize = smb2_negotiate_rsize, |
| 2233 | .sess_setup = SMB2_sess_setup, |
| 2234 | .logoff = SMB2_logoff, |
| 2235 | .tree_connect = SMB2_tcon, |
| 2236 | .tree_disconnect = SMB2_tdis, |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 2237 | .qfs_tcon = smb2_qfs_tcon, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 2238 | .is_path_accessible = smb2_is_path_accessible, |
| 2239 | .can_echo = smb2_can_echo, |
| 2240 | .echo = SMB2_echo, |
| 2241 | .query_path_info = smb2_query_path_info, |
| 2242 | .get_srv_inum = smb2_get_srv_inum, |
| 2243 | .query_file_info = smb2_query_file_info, |
| 2244 | .set_path_size = smb2_set_path_size, |
| 2245 | .set_file_size = smb2_set_file_size, |
| 2246 | .set_file_info = smb2_set_file_info, |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 2247 | .set_compression = smb2_set_compression, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 2248 | .mkdir = smb2_mkdir, |
| 2249 | .mkdir_setinfo = smb2_mkdir_setinfo, |
| 2250 | .rmdir = smb2_rmdir, |
| 2251 | .unlink = smb2_unlink, |
| 2252 | .rename = smb2_rename_path, |
| 2253 | .create_hardlink = smb2_create_hardlink, |
| 2254 | .query_symlink = smb2_query_symlink, |
Sachin Prabhu | 5b23c97 | 2016-07-11 16:53:20 +0100 | [diff] [blame] | 2255 | .query_mf_symlink = smb3_query_mf_symlink, |
| 2256 | .create_mf_symlink = smb3_create_mf_symlink, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 2257 | .open = smb2_open_file, |
| 2258 | .set_fid = smb2_set_fid, |
| 2259 | .close = smb2_close_file, |
| 2260 | .flush = smb2_flush_file, |
| 2261 | .async_readv = smb2_async_readv, |
| 2262 | .async_writev = smb2_async_writev, |
| 2263 | .sync_read = smb2_sync_read, |
| 2264 | .sync_write = smb2_sync_write, |
| 2265 | .query_dir_first = smb2_query_dir_first, |
| 2266 | .query_dir_next = smb2_query_dir_next, |
| 2267 | .close_dir = smb2_close_dir, |
| 2268 | .calc_smb_size = smb2_calc_size, |
| 2269 | .is_status_pending = smb2_is_status_pending, |
| 2270 | .oplock_response = smb2_oplock_response, |
| 2271 | .queryfs = smb2_queryfs, |
| 2272 | .mand_lock = smb2_mand_lock, |
| 2273 | .mand_unlock_range = smb2_unlock_range, |
| 2274 | .push_mand_locks = smb2_push_mandatory_locks, |
| 2275 | .get_lease_key = smb2_get_lease_key, |
| 2276 | .set_lease_key = smb2_set_lease_key, |
| 2277 | .new_lease_key = smb2_new_lease_key, |
| 2278 | .calc_signature = smb2_calc_signature, |
| 2279 | .is_read_op = smb2_is_read_op, |
| 2280 | .set_oplock_level = smb2_set_oplock_level, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 2281 | .create_lease_buf = smb2_create_lease_buf, |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 2282 | .parse_lease_buf = smb2_parse_lease_buf, |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 2283 | .clone_range = smb2_clone_range, |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2284 | .wp_retry_size = smb2_wp_retry_size, |
Pavel Shilovsky | 5275580 | 2014-08-18 20:49:57 +0400 | [diff] [blame] | 2285 | .dir_needs_close = smb2_dir_needs_close, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 2286 | }; |
| 2287 | |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 2288 | struct smb_version_operations smb21_operations = { |
Pavel Shilovsky | 027e8ee | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 2289 | .compare_fids = smb2_compare_fids, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 2290 | .setup_request = smb2_setup_request, |
Pavel Shilovsky | c95b8ee | 2012-07-11 14:45:28 +0400 | [diff] [blame] | 2291 | .setup_async_request = smb2_setup_async_request, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 2292 | .check_receive = smb2_check_receive, |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 2293 | .add_credits = smb2_add_credits, |
| 2294 | .set_credits = smb2_set_credits, |
| 2295 | .get_credits_field = smb2_get_credits_field, |
| 2296 | .get_credits = smb2_get_credits, |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 2297 | .wait_mtu_credits = smb2_wait_mtu_credits, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 2298 | .get_next_mid = smb2_get_next_mid, |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2299 | .read_data_offset = smb2_read_data_offset, |
| 2300 | .read_data_length = smb2_read_data_length, |
| 2301 | .map_error = map_smb2_to_linux_error, |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 2302 | .find_mid = smb2_find_mid, |
| 2303 | .check_message = smb2_check_message, |
| 2304 | .dump_detail = smb2_dump_detail, |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 2305 | .clear_stats = smb2_clear_stats, |
| 2306 | .print_stats = smb2_print_stats, |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2307 | .is_oplock_break = smb2_is_valid_oplock_break, |
Sachin Prabhu | c11f1df | 2014-03-11 16:11:47 +0000 | [diff] [blame] | 2308 | .downgrade_oplock = smb2_downgrade_oplock, |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 2309 | .need_neg = smb2_need_neg, |
| 2310 | .negotiate = smb2_negotiate, |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 2311 | .negotiate_wsize = smb2_negotiate_wsize, |
| 2312 | .negotiate_rsize = smb2_negotiate_rsize, |
Pavel Shilovsky | 5478f9b | 2011-12-27 16:22:00 +0400 | [diff] [blame] | 2313 | .sess_setup = SMB2_sess_setup, |
| 2314 | .logoff = SMB2_logoff, |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 2315 | .tree_connect = SMB2_tcon, |
| 2316 | .tree_disconnect = SMB2_tdis, |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 2317 | .qfs_tcon = smb2_qfs_tcon, |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 2318 | .is_path_accessible = smb2_is_path_accessible, |
Pavel Shilovsky | 9094fad | 2012-07-12 18:30:44 +0400 | [diff] [blame] | 2319 | .can_echo = smb2_can_echo, |
| 2320 | .echo = SMB2_echo, |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 2321 | .query_path_info = smb2_query_path_info, |
| 2322 | .get_srv_inum = smb2_get_srv_inum, |
Pavel Shilovsky | b7546bc | 2012-09-18 16:20:27 -0700 | [diff] [blame] | 2323 | .query_file_info = smb2_query_file_info, |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 2324 | .set_path_size = smb2_set_path_size, |
| 2325 | .set_file_size = smb2_set_file_size, |
Pavel Shilovsky | 1feeaac | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 2326 | .set_file_info = smb2_set_file_info, |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 2327 | .set_compression = smb2_set_compression, |
Pavel Shilovsky | a0e7318 | 2011-07-19 12:56:37 +0400 | [diff] [blame] | 2328 | .mkdir = smb2_mkdir, |
| 2329 | .mkdir_setinfo = smb2_mkdir_setinfo, |
Pavel Shilovsky | 1a500f0 | 2012-07-10 16:14:38 +0400 | [diff] [blame] | 2330 | .rmdir = smb2_rmdir, |
Pavel Shilovsky | cbe6f43 | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 2331 | .unlink = smb2_unlink, |
Pavel Shilovsky | 35143eb | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 2332 | .rename = smb2_rename_path, |
Pavel Shilovsky | 568798c | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 2333 | .create_hardlink = smb2_create_hardlink, |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 2334 | .query_symlink = smb2_query_symlink, |
Steve French | c22870e | 2014-09-16 07:18:19 -0500 | [diff] [blame] | 2335 | .query_mf_symlink = smb3_query_mf_symlink, |
Steve French | 5ab9757 | 2014-09-15 04:49:28 -0500 | [diff] [blame] | 2336 | .create_mf_symlink = smb3_create_mf_symlink, |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 2337 | .open = smb2_open_file, |
| 2338 | .set_fid = smb2_set_fid, |
| 2339 | .close = smb2_close_file, |
Pavel Shilovsky | 7a5cfb1 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 2340 | .flush = smb2_flush_file, |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2341 | .async_readv = smb2_async_readv, |
Pavel Shilovsky | 3331914 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2342 | .async_writev = smb2_async_writev, |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2343 | .sync_read = smb2_sync_read, |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2344 | .sync_write = smb2_sync_write, |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2345 | .query_dir_first = smb2_query_dir_first, |
| 2346 | .query_dir_next = smb2_query_dir_next, |
| 2347 | .close_dir = smb2_close_dir, |
| 2348 | .calc_smb_size = smb2_calc_size, |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2349 | .is_status_pending = smb2_is_status_pending, |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2350 | .oplock_response = smb2_oplock_response, |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 2351 | .queryfs = smb2_queryfs, |
Pavel Shilovsky | f7ba7fe | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 2352 | .mand_lock = smb2_mand_lock, |
| 2353 | .mand_unlock_range = smb2_unlock_range, |
Pavel Shilovsky | b140799 | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 2354 | .push_mand_locks = smb2_push_mandatory_locks, |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 2355 | .get_lease_key = smb2_get_lease_key, |
| 2356 | .set_lease_key = smb2_set_lease_key, |
| 2357 | .new_lease_key = smb2_new_lease_key, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 2358 | .calc_signature = smb2_calc_signature, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 2359 | .is_read_op = smb21_is_read_op, |
| 2360 | .set_oplock_level = smb21_set_oplock_level, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 2361 | .create_lease_buf = smb2_create_lease_buf, |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 2362 | .parse_lease_buf = smb2_parse_lease_buf, |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 2363 | .clone_range = smb2_clone_range, |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2364 | .wp_retry_size = smb2_wp_retry_size, |
Pavel Shilovsky | 5275580 | 2014-08-18 20:49:57 +0400 | [diff] [blame] | 2365 | .dir_needs_close = smb2_dir_needs_close, |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 2366 | .enum_snapshots = smb3_enum_snapshots, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 2367 | }; |
| 2368 | |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 2369 | struct smb_version_operations smb30_operations = { |
| 2370 | .compare_fids = smb2_compare_fids, |
| 2371 | .setup_request = smb2_setup_request, |
| 2372 | .setup_async_request = smb2_setup_async_request, |
| 2373 | .check_receive = smb2_check_receive, |
| 2374 | .add_credits = smb2_add_credits, |
| 2375 | .set_credits = smb2_set_credits, |
| 2376 | .get_credits_field = smb2_get_credits_field, |
| 2377 | .get_credits = smb2_get_credits, |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 2378 | .wait_mtu_credits = smb2_wait_mtu_credits, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 2379 | .get_next_mid = smb2_get_next_mid, |
| 2380 | .read_data_offset = smb2_read_data_offset, |
| 2381 | .read_data_length = smb2_read_data_length, |
| 2382 | .map_error = map_smb2_to_linux_error, |
| 2383 | .find_mid = smb2_find_mid, |
| 2384 | .check_message = smb2_check_message, |
| 2385 | .dump_detail = smb2_dump_detail, |
| 2386 | .clear_stats = smb2_clear_stats, |
| 2387 | .print_stats = smb2_print_stats, |
Steve French | 769ee6a | 2013-06-19 14:15:30 -0500 | [diff] [blame] | 2388 | .dump_share_caps = smb2_dump_share_caps, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 2389 | .is_oplock_break = smb2_is_valid_oplock_break, |
Sachin Prabhu | c11f1df | 2014-03-11 16:11:47 +0000 | [diff] [blame] | 2390 | .downgrade_oplock = smb2_downgrade_oplock, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 2391 | .need_neg = smb2_need_neg, |
| 2392 | .negotiate = smb2_negotiate, |
| 2393 | .negotiate_wsize = smb2_negotiate_wsize, |
| 2394 | .negotiate_rsize = smb2_negotiate_rsize, |
| 2395 | .sess_setup = SMB2_sess_setup, |
| 2396 | .logoff = SMB2_logoff, |
| 2397 | .tree_connect = SMB2_tcon, |
| 2398 | .tree_disconnect = SMB2_tdis, |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 2399 | .qfs_tcon = smb3_qfs_tcon, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 2400 | .is_path_accessible = smb2_is_path_accessible, |
| 2401 | .can_echo = smb2_can_echo, |
| 2402 | .echo = SMB2_echo, |
| 2403 | .query_path_info = smb2_query_path_info, |
| 2404 | .get_srv_inum = smb2_get_srv_inum, |
| 2405 | .query_file_info = smb2_query_file_info, |
| 2406 | .set_path_size = smb2_set_path_size, |
| 2407 | .set_file_size = smb2_set_file_size, |
| 2408 | .set_file_info = smb2_set_file_info, |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 2409 | .set_compression = smb2_set_compression, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 2410 | .mkdir = smb2_mkdir, |
| 2411 | .mkdir_setinfo = smb2_mkdir_setinfo, |
| 2412 | .rmdir = smb2_rmdir, |
| 2413 | .unlink = smb2_unlink, |
| 2414 | .rename = smb2_rename_path, |
| 2415 | .create_hardlink = smb2_create_hardlink, |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 2416 | .query_symlink = smb2_query_symlink, |
Steve French | c22870e | 2014-09-16 07:18:19 -0500 | [diff] [blame] | 2417 | .query_mf_symlink = smb3_query_mf_symlink, |
Steve French | 5ab9757 | 2014-09-15 04:49:28 -0500 | [diff] [blame] | 2418 | .create_mf_symlink = smb3_create_mf_symlink, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 2419 | .open = smb2_open_file, |
| 2420 | .set_fid = smb2_set_fid, |
| 2421 | .close = smb2_close_file, |
| 2422 | .flush = smb2_flush_file, |
| 2423 | .async_readv = smb2_async_readv, |
| 2424 | .async_writev = smb2_async_writev, |
| 2425 | .sync_read = smb2_sync_read, |
| 2426 | .sync_write = smb2_sync_write, |
| 2427 | .query_dir_first = smb2_query_dir_first, |
| 2428 | .query_dir_next = smb2_query_dir_next, |
| 2429 | .close_dir = smb2_close_dir, |
| 2430 | .calc_smb_size = smb2_calc_size, |
| 2431 | .is_status_pending = smb2_is_status_pending, |
| 2432 | .oplock_response = smb2_oplock_response, |
| 2433 | .queryfs = smb2_queryfs, |
| 2434 | .mand_lock = smb2_mand_lock, |
| 2435 | .mand_unlock_range = smb2_unlock_range, |
| 2436 | .push_mand_locks = smb2_push_mandatory_locks, |
| 2437 | .get_lease_key = smb2_get_lease_key, |
| 2438 | .set_lease_key = smb2_set_lease_key, |
| 2439 | .new_lease_key = smb2_new_lease_key, |
Steve French | 373512e | 2015-12-18 13:05:30 -0600 | [diff] [blame] | 2440 | .generate_signingkey = generate_smb30signingkey, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 2441 | .calc_signature = smb3_calc_signature, |
Steve French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 2442 | .set_integrity = smb3_set_integrity, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 2443 | .is_read_op = smb21_is_read_op, |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 2444 | .set_oplock_level = smb3_set_oplock_level, |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 2445 | .create_lease_buf = smb3_create_lease_buf, |
| 2446 | .parse_lease_buf = smb3_parse_lease_buf, |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 2447 | .clone_range = smb2_clone_range, |
Steve French | ca9e7a1 | 2015-10-01 21:40:10 -0500 | [diff] [blame] | 2448 | .duplicate_extents = smb2_duplicate_extents, |
Steve French | ff1c038 | 2013-11-19 23:44:46 -0600 | [diff] [blame] | 2449 | .validate_negotiate = smb3_validate_negotiate, |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2450 | .wp_retry_size = smb2_wp_retry_size, |
Pavel Shilovsky | 5275580 | 2014-08-18 20:49:57 +0400 | [diff] [blame] | 2451 | .dir_needs_close = smb2_dir_needs_close, |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 2452 | .fallocate = smb3_fallocate, |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 2453 | .enum_snapshots = smb3_enum_snapshots, |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2454 | .init_transform_rq = smb3_init_transform_rq, |
| 2455 | .free_transform_rq = smb3_free_transform_rq, |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2456 | .is_transform_hdr = smb3_is_transform_hdr, |
| 2457 | .receive_transform = smb3_receive_transform, |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 2458 | }; |
| 2459 | |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 2460 | #ifdef CONFIG_CIFS_SMB311 |
| 2461 | struct smb_version_operations smb311_operations = { |
| 2462 | .compare_fids = smb2_compare_fids, |
| 2463 | .setup_request = smb2_setup_request, |
| 2464 | .setup_async_request = smb2_setup_async_request, |
| 2465 | .check_receive = smb2_check_receive, |
| 2466 | .add_credits = smb2_add_credits, |
| 2467 | .set_credits = smb2_set_credits, |
| 2468 | .get_credits_field = smb2_get_credits_field, |
| 2469 | .get_credits = smb2_get_credits, |
| 2470 | .wait_mtu_credits = smb2_wait_mtu_credits, |
| 2471 | .get_next_mid = smb2_get_next_mid, |
| 2472 | .read_data_offset = smb2_read_data_offset, |
| 2473 | .read_data_length = smb2_read_data_length, |
| 2474 | .map_error = map_smb2_to_linux_error, |
| 2475 | .find_mid = smb2_find_mid, |
| 2476 | .check_message = smb2_check_message, |
| 2477 | .dump_detail = smb2_dump_detail, |
| 2478 | .clear_stats = smb2_clear_stats, |
| 2479 | .print_stats = smb2_print_stats, |
| 2480 | .dump_share_caps = smb2_dump_share_caps, |
| 2481 | .is_oplock_break = smb2_is_valid_oplock_break, |
| 2482 | .downgrade_oplock = smb2_downgrade_oplock, |
| 2483 | .need_neg = smb2_need_neg, |
| 2484 | .negotiate = smb2_negotiate, |
| 2485 | .negotiate_wsize = smb2_negotiate_wsize, |
| 2486 | .negotiate_rsize = smb2_negotiate_rsize, |
| 2487 | .sess_setup = SMB2_sess_setup, |
| 2488 | .logoff = SMB2_logoff, |
| 2489 | .tree_connect = SMB2_tcon, |
| 2490 | .tree_disconnect = SMB2_tdis, |
| 2491 | .qfs_tcon = smb3_qfs_tcon, |
| 2492 | .is_path_accessible = smb2_is_path_accessible, |
| 2493 | .can_echo = smb2_can_echo, |
| 2494 | .echo = SMB2_echo, |
| 2495 | .query_path_info = smb2_query_path_info, |
| 2496 | .get_srv_inum = smb2_get_srv_inum, |
| 2497 | .query_file_info = smb2_query_file_info, |
| 2498 | .set_path_size = smb2_set_path_size, |
| 2499 | .set_file_size = smb2_set_file_size, |
| 2500 | .set_file_info = smb2_set_file_info, |
| 2501 | .set_compression = smb2_set_compression, |
| 2502 | .mkdir = smb2_mkdir, |
| 2503 | .mkdir_setinfo = smb2_mkdir_setinfo, |
| 2504 | .rmdir = smb2_rmdir, |
| 2505 | .unlink = smb2_unlink, |
| 2506 | .rename = smb2_rename_path, |
| 2507 | .create_hardlink = smb2_create_hardlink, |
| 2508 | .query_symlink = smb2_query_symlink, |
| 2509 | .query_mf_symlink = smb3_query_mf_symlink, |
| 2510 | .create_mf_symlink = smb3_create_mf_symlink, |
| 2511 | .open = smb2_open_file, |
| 2512 | .set_fid = smb2_set_fid, |
| 2513 | .close = smb2_close_file, |
| 2514 | .flush = smb2_flush_file, |
| 2515 | .async_readv = smb2_async_readv, |
| 2516 | .async_writev = smb2_async_writev, |
| 2517 | .sync_read = smb2_sync_read, |
| 2518 | .sync_write = smb2_sync_write, |
| 2519 | .query_dir_first = smb2_query_dir_first, |
| 2520 | .query_dir_next = smb2_query_dir_next, |
| 2521 | .close_dir = smb2_close_dir, |
| 2522 | .calc_smb_size = smb2_calc_size, |
| 2523 | .is_status_pending = smb2_is_status_pending, |
| 2524 | .oplock_response = smb2_oplock_response, |
| 2525 | .queryfs = smb2_queryfs, |
| 2526 | .mand_lock = smb2_mand_lock, |
| 2527 | .mand_unlock_range = smb2_unlock_range, |
| 2528 | .push_mand_locks = smb2_push_mandatory_locks, |
| 2529 | .get_lease_key = smb2_get_lease_key, |
| 2530 | .set_lease_key = smb2_set_lease_key, |
| 2531 | .new_lease_key = smb2_new_lease_key, |
Steve French | 373512e | 2015-12-18 13:05:30 -0600 | [diff] [blame] | 2532 | .generate_signingkey = generate_smb311signingkey, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 2533 | .calc_signature = smb3_calc_signature, |
Steve French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 2534 | .set_integrity = smb3_set_integrity, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 2535 | .is_read_op = smb21_is_read_op, |
| 2536 | .set_oplock_level = smb3_set_oplock_level, |
| 2537 | .create_lease_buf = smb3_create_lease_buf, |
| 2538 | .parse_lease_buf = smb3_parse_lease_buf, |
| 2539 | .clone_range = smb2_clone_range, |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 2540 | .duplicate_extents = smb2_duplicate_extents, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 2541 | /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */ |
| 2542 | .wp_retry_size = smb2_wp_retry_size, |
| 2543 | .dir_needs_close = smb2_dir_needs_close, |
| 2544 | .fallocate = smb3_fallocate, |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 2545 | .enum_snapshots = smb3_enum_snapshots, |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2546 | .init_transform_rq = smb3_init_transform_rq, |
| 2547 | .free_transform_rq = smb3_free_transform_rq, |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2548 | .is_transform_hdr = smb3_is_transform_hdr, |
| 2549 | .receive_transform = smb3_receive_transform, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 2550 | }; |
| 2551 | #endif /* CIFS_SMB311 */ |
| 2552 | |
Steve French | dd446b1 | 2012-11-28 23:21:06 -0600 | [diff] [blame] | 2553 | struct smb_version_values smb20_values = { |
| 2554 | .version_string = SMB20_VERSION_STRING, |
| 2555 | .protocol_id = SMB20_PROT_ID, |
| 2556 | .req_capabilities = 0, /* MBZ */ |
| 2557 | .large_lock_type = 0, |
| 2558 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 2559 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 2560 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
| 2561 | .header_size = sizeof(struct smb2_hdr), |
| 2562 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 2563 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 2564 | .lock_cmd = SMB2_LOCK, |
| 2565 | .cap_unix = 0, |
| 2566 | .cap_nt_find = SMB2_NT_FIND, |
| 2567 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 50285882 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 2568 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 2569 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 2570 | .create_lease_size = sizeof(struct create_lease), |
Steve French | dd446b1 | 2012-11-28 23:21:06 -0600 | [diff] [blame] | 2571 | }; |
| 2572 | |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 2573 | struct smb_version_values smb21_values = { |
| 2574 | .version_string = SMB21_VERSION_STRING, |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 2575 | .protocol_id = SMB21_PROT_ID, |
| 2576 | .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */ |
| 2577 | .large_lock_type = 0, |
| 2578 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 2579 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 2580 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
| 2581 | .header_size = sizeof(struct smb2_hdr), |
| 2582 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 2583 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 2584 | .lock_cmd = SMB2_LOCK, |
| 2585 | .cap_unix = 0, |
| 2586 | .cap_nt_find = SMB2_NT_FIND, |
| 2587 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 50285882 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 2588 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 2589 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 2590 | .create_lease_size = sizeof(struct create_lease), |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 2591 | }; |
| 2592 | |
| 2593 | struct smb_version_values smb30_values = { |
| 2594 | .version_string = SMB30_VERSION_STRING, |
| 2595 | .protocol_id = SMB30_PROT_ID, |
Steve French | 373512e | 2015-12-18 13:05:30 -0600 | [diff] [blame] | 2596 | .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] | 2597 | .large_lock_type = 0, |
| 2598 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 2599 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 2600 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 2601 | .header_size = sizeof(struct smb2_hdr), |
| 2602 | .max_header_size = MAX_SMB2_HDR_SIZE, |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2603 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 2604 | .lock_cmd = SMB2_LOCK, |
Pavel Shilovsky | 29e20f9 | 2012-07-13 13:58:14 +0400 | [diff] [blame] | 2605 | .cap_unix = 0, |
| 2606 | .cap_nt_find = SMB2_NT_FIND, |
| 2607 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 50285882 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 2608 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 2609 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 2610 | .create_lease_size = sizeof(struct create_lease_v2), |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 2611 | }; |
Steve French | 20b6d8b | 2013-06-12 22:48:41 -0500 | [diff] [blame] | 2612 | |
| 2613 | struct smb_version_values smb302_values = { |
| 2614 | .version_string = SMB302_VERSION_STRING, |
| 2615 | .protocol_id = SMB302_PROT_ID, |
Steve French | 373512e | 2015-12-18 13:05:30 -0600 | [diff] [blame] | 2616 | .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] | 2617 | .large_lock_type = 0, |
| 2618 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 2619 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 2620 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
| 2621 | .header_size = sizeof(struct smb2_hdr), |
| 2622 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 2623 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 2624 | .lock_cmd = SMB2_LOCK, |
| 2625 | .cap_unix = 0, |
| 2626 | .cap_nt_find = SMB2_NT_FIND, |
| 2627 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 50285882 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 2628 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 2629 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 2630 | .create_lease_size = sizeof(struct create_lease_v2), |
Steve French | 20b6d8b | 2013-06-12 22:48:41 -0500 | [diff] [blame] | 2631 | }; |
Steve French | 5f7fbf7 | 2014-12-17 22:52:58 -0600 | [diff] [blame] | 2632 | |
| 2633 | #ifdef CONFIG_CIFS_SMB311 |
| 2634 | struct smb_version_values smb311_values = { |
| 2635 | .version_string = SMB311_VERSION_STRING, |
| 2636 | .protocol_id = SMB311_PROT_ID, |
Steve French | b618f00 | 2015-11-03 09:15:03 -0600 | [diff] [blame] | 2637 | .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] | 2638 | .large_lock_type = 0, |
| 2639 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 2640 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 2641 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
| 2642 | .header_size = sizeof(struct smb2_hdr), |
| 2643 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 2644 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 2645 | .lock_cmd = SMB2_LOCK, |
| 2646 | .cap_unix = 0, |
| 2647 | .cap_nt_find = SMB2_NT_FIND, |
| 2648 | .cap_large_files = SMB2_LARGE_FILES, |
| 2649 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 2650 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 2651 | .create_lease_size = sizeof(struct create_lease_v2), |
| 2652 | }; |
| 2653 | #endif /* SMB311 */ |