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