Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 1 | /* |
| 2 | * SMB2 version specific operations |
| 3 | * |
| 4 | * Copyright (c) 2012, Jeff Layton <jlayton@redhat.com> |
| 5 | * |
| 6 | * This library is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License v2 as published |
| 8 | * by the Free Software Foundation. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 13 | * the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Lesser General Public License |
| 16 | * along with this library; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | */ |
| 19 | |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 20 | #include <linux/pagemap.h> |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 21 | #include <linux/vfs.h> |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 22 | #include "cifsglob.h" |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 23 | #include "smb2pdu.h" |
| 24 | #include "smb2proto.h" |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 25 | #include "cifsproto.h" |
| 26 | #include "cifs_debug.h" |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 27 | #include "cifs_unicode.h" |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 28 | #include "smb2status.h" |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 29 | #include "smb2glob.h" |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 30 | |
| 31 | static int |
| 32 | change_conf(struct TCP_Server_Info *server) |
| 33 | { |
| 34 | server->credits += server->echo_credits + server->oplock_credits; |
| 35 | server->oplock_credits = server->echo_credits = 0; |
| 36 | switch (server->credits) { |
| 37 | case 0: |
| 38 | return -1; |
| 39 | case 1: |
| 40 | server->echoes = false; |
| 41 | server->oplocks = false; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 42 | cifs_dbg(VFS, "disabling echoes and oplocks\n"); |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 43 | break; |
| 44 | case 2: |
| 45 | server->echoes = true; |
| 46 | server->oplocks = false; |
| 47 | server->echo_credits = 1; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 48 | cifs_dbg(FYI, "disabling oplocks\n"); |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 49 | break; |
| 50 | default: |
| 51 | server->echoes = true; |
| 52 | server->oplocks = true; |
| 53 | server->echo_credits = 1; |
| 54 | server->oplock_credits = 1; |
| 55 | } |
| 56 | server->credits -= server->echo_credits + server->oplock_credits; |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | static void |
| 61 | smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add, |
| 62 | const int optype) |
| 63 | { |
| 64 | int *val, rc = 0; |
| 65 | spin_lock(&server->req_lock); |
| 66 | val = server->ops->get_credits_field(server, optype); |
| 67 | *val += add; |
| 68 | server->in_flight--; |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 69 | if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP) |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 70 | rc = change_conf(server); |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 71 | /* |
| 72 | * Sometimes server returns 0 credits on oplock break ack - we need to |
| 73 | * rebalance credits in this case. |
| 74 | */ |
| 75 | else if (server->in_flight > 0 && server->oplock_credits == 0 && |
| 76 | server->oplocks) { |
| 77 | if (server->credits > 1) { |
| 78 | server->credits--; |
| 79 | server->oplock_credits++; |
| 80 | } |
| 81 | } |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 82 | spin_unlock(&server->req_lock); |
| 83 | wake_up(&server->request_q); |
| 84 | if (rc) |
| 85 | cifs_reconnect(server); |
| 86 | } |
| 87 | |
| 88 | static void |
| 89 | smb2_set_credits(struct TCP_Server_Info *server, const int val) |
| 90 | { |
| 91 | spin_lock(&server->req_lock); |
| 92 | server->credits = val; |
| 93 | spin_unlock(&server->req_lock); |
| 94 | } |
| 95 | |
| 96 | static int * |
| 97 | smb2_get_credits_field(struct TCP_Server_Info *server, const int optype) |
| 98 | { |
| 99 | switch (optype) { |
| 100 | case CIFS_ECHO_OP: |
| 101 | return &server->echo_credits; |
| 102 | case CIFS_OBREAK_OP: |
| 103 | return &server->oplock_credits; |
| 104 | default: |
| 105 | return &server->credits; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | static unsigned int |
| 110 | smb2_get_credits(struct mid_q_entry *mid) |
| 111 | { |
| 112 | return le16_to_cpu(((struct smb2_hdr *)mid->resp_buf)->CreditRequest); |
| 113 | } |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 114 | |
| 115 | static __u64 |
| 116 | smb2_get_next_mid(struct TCP_Server_Info *server) |
| 117 | { |
| 118 | __u64 mid; |
| 119 | /* for SMB2 we need the current value */ |
| 120 | spin_lock(&GlobalMid_Lock); |
| 121 | mid = server->CurrentMid++; |
| 122 | spin_unlock(&GlobalMid_Lock); |
| 123 | return mid; |
| 124 | } |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 125 | |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 126 | static struct mid_q_entry * |
| 127 | smb2_find_mid(struct TCP_Server_Info *server, char *buf) |
| 128 | { |
| 129 | struct mid_q_entry *mid; |
| 130 | struct smb2_hdr *hdr = (struct smb2_hdr *)buf; |
| 131 | |
| 132 | spin_lock(&GlobalMid_Lock); |
| 133 | list_for_each_entry(mid, &server->pending_mid_q, qhead) { |
| 134 | if ((mid->mid == hdr->MessageId) && |
| 135 | (mid->mid_state == MID_REQUEST_SUBMITTED) && |
| 136 | (mid->command == hdr->Command)) { |
| 137 | spin_unlock(&GlobalMid_Lock); |
| 138 | return mid; |
| 139 | } |
| 140 | } |
| 141 | spin_unlock(&GlobalMid_Lock); |
| 142 | return NULL; |
| 143 | } |
| 144 | |
| 145 | static void |
| 146 | smb2_dump_detail(void *buf) |
| 147 | { |
| 148 | #ifdef CONFIG_CIFS_DEBUG2 |
| 149 | struct smb2_hdr *smb = (struct smb2_hdr *)buf; |
| 150 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 151 | cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n", |
| 152 | smb->Command, smb->Status, smb->Flags, smb->MessageId, |
| 153 | smb->ProcessId); |
| 154 | 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] | 155 | #endif |
| 156 | } |
| 157 | |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 158 | static bool |
| 159 | smb2_need_neg(struct TCP_Server_Info *server) |
| 160 | { |
| 161 | return server->max_read == 0; |
| 162 | } |
| 163 | |
| 164 | static int |
| 165 | smb2_negotiate(const unsigned int xid, struct cifs_ses *ses) |
| 166 | { |
| 167 | int rc; |
| 168 | ses->server->CurrentMid = 0; |
| 169 | rc = SMB2_negotiate(xid, ses); |
| 170 | /* BB we probably don't need to retry with modern servers */ |
| 171 | if (rc == -EAGAIN) |
| 172 | rc = -EHOSTDOWN; |
| 173 | return rc; |
| 174 | } |
| 175 | |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 176 | static unsigned int |
| 177 | smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) |
| 178 | { |
| 179 | struct TCP_Server_Info *server = tcon->ses->server; |
| 180 | unsigned int wsize; |
| 181 | |
| 182 | /* start with specified wsize, or default */ |
| 183 | wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE; |
| 184 | wsize = min_t(unsigned int, wsize, server->max_write); |
| 185 | /* |
| 186 | * limit write size to 2 ** 16, because we don't support multicredit |
| 187 | * requests now. |
| 188 | */ |
| 189 | wsize = min_t(unsigned int, wsize, 2 << 15); |
| 190 | |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 191 | return wsize; |
| 192 | } |
| 193 | |
| 194 | static unsigned int |
| 195 | smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) |
| 196 | { |
| 197 | struct TCP_Server_Info *server = tcon->ses->server; |
| 198 | unsigned int rsize; |
| 199 | |
| 200 | /* start with specified rsize, or default */ |
| 201 | rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE; |
| 202 | rsize = min_t(unsigned int, rsize, server->max_read); |
| 203 | /* |
| 204 | * limit write size to 2 ** 16, because we don't support multicredit |
| 205 | * requests now. |
| 206 | */ |
| 207 | rsize = min_t(unsigned int, rsize, 2 << 15); |
| 208 | |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 209 | return rsize; |
| 210 | } |
| 211 | |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 212 | static void |
| 213 | smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon) |
| 214 | { |
| 215 | int rc; |
| 216 | __le16 srch_path = 0; /* Null - open root of share */ |
| 217 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 218 | struct cifs_open_parms oparms; |
| 219 | struct cifs_fid fid; |
| 220 | |
| 221 | oparms.tcon = tcon; |
| 222 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 223 | oparms.disposition = FILE_OPEN; |
| 224 | oparms.create_options = 0; |
| 225 | oparms.fid = &fid; |
| 226 | oparms.reconnect = false; |
| 227 | |
| 228 | rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL); |
| 229 | if (rc) |
| 230 | return; |
| 231 | |
Steven French | 2167114 | 2013-10-09 13:36:35 -0500 | [diff] [blame^] | 232 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
| 233 | FS_ATTRIBUTE_INFORMATION); |
| 234 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
| 235 | FS_DEVICE_INFORMATION); |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 236 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
| 237 | return; |
| 238 | } |
| 239 | |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 240 | static int |
| 241 | smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon, |
| 242 | struct cifs_sb_info *cifs_sb, const char *full_path) |
| 243 | { |
| 244 | int rc; |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 245 | __le16 *utf16_path; |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 246 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 247 | struct cifs_open_parms oparms; |
| 248 | struct cifs_fid fid; |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 249 | |
| 250 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); |
| 251 | if (!utf16_path) |
| 252 | return -ENOMEM; |
| 253 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 254 | oparms.tcon = tcon; |
| 255 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 256 | oparms.disposition = FILE_OPEN; |
| 257 | oparms.create_options = 0; |
| 258 | oparms.fid = &fid; |
Pavel Shilovsky | 9cbc0b7 | 2013-07-09 18:40:58 +0400 | [diff] [blame] | 259 | oparms.reconnect = false; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 260 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 261 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL); |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 262 | if (rc) { |
| 263 | kfree(utf16_path); |
| 264 | return rc; |
| 265 | } |
| 266 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 267 | rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 268 | kfree(utf16_path); |
| 269 | return rc; |
| 270 | } |
| 271 | |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 272 | static int |
| 273 | smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon, |
| 274 | struct cifs_sb_info *cifs_sb, const char *full_path, |
| 275 | u64 *uniqueid, FILE_ALL_INFO *data) |
| 276 | { |
| 277 | *uniqueid = le64_to_cpu(data->IndexNumber); |
| 278 | return 0; |
| 279 | } |
| 280 | |
Pavel Shilovsky | b7546bc | 2012-09-18 16:20:27 -0700 | [diff] [blame] | 281 | static int |
| 282 | smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon, |
| 283 | struct cifs_fid *fid, FILE_ALL_INFO *data) |
| 284 | { |
| 285 | int rc; |
| 286 | struct smb2_file_all_info *smb2_data; |
| 287 | |
| 288 | smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + MAX_NAME * 2, |
| 289 | GFP_KERNEL); |
| 290 | if (smb2_data == NULL) |
| 291 | return -ENOMEM; |
| 292 | |
| 293 | rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid, |
| 294 | smb2_data); |
| 295 | if (!rc) |
| 296 | move_smb2_info_to_cifs(data, smb2_data); |
| 297 | kfree(smb2_data); |
| 298 | return rc; |
| 299 | } |
| 300 | |
Pavel Shilovsky | 9094fad | 2012-07-12 18:30:44 +0400 | [diff] [blame] | 301 | static bool |
| 302 | smb2_can_echo(struct TCP_Server_Info *server) |
| 303 | { |
| 304 | return server->echoes; |
| 305 | } |
| 306 | |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 307 | static void |
| 308 | smb2_clear_stats(struct cifs_tcon *tcon) |
| 309 | { |
| 310 | #ifdef CONFIG_CIFS_STATS |
| 311 | int i; |
| 312 | for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) { |
| 313 | atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0); |
| 314 | atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0); |
| 315 | } |
| 316 | #endif |
| 317 | } |
| 318 | |
| 319 | static void |
Steve French | 769ee6a | 2013-06-19 14:15:30 -0500 | [diff] [blame] | 320 | smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon) |
| 321 | { |
| 322 | seq_puts(m, "\n\tShare Capabilities:"); |
| 323 | if (tcon->capabilities & SMB2_SHARE_CAP_DFS) |
| 324 | seq_puts(m, " DFS,"); |
| 325 | if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY) |
| 326 | seq_puts(m, " CONTINUOUS AVAILABILITY,"); |
| 327 | if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT) |
| 328 | seq_puts(m, " SCALEOUT,"); |
| 329 | if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER) |
| 330 | seq_puts(m, " CLUSTER,"); |
| 331 | if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC) |
| 332 | seq_puts(m, " ASYMMETRIC,"); |
| 333 | if (tcon->capabilities == 0) |
| 334 | seq_puts(m, " None"); |
| 335 | seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags); |
| 336 | } |
| 337 | |
| 338 | static void |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 339 | smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon) |
| 340 | { |
| 341 | #ifdef CONFIG_CIFS_STATS |
| 342 | atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent; |
| 343 | atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed; |
| 344 | seq_printf(m, "\nNegotiates: %d sent %d failed", |
| 345 | atomic_read(&sent[SMB2_NEGOTIATE_HE]), |
| 346 | atomic_read(&failed[SMB2_NEGOTIATE_HE])); |
| 347 | seq_printf(m, "\nSessionSetups: %d sent %d failed", |
| 348 | atomic_read(&sent[SMB2_SESSION_SETUP_HE]), |
| 349 | atomic_read(&failed[SMB2_SESSION_SETUP_HE])); |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 350 | seq_printf(m, "\nLogoffs: %d sent %d failed", |
| 351 | atomic_read(&sent[SMB2_LOGOFF_HE]), |
| 352 | atomic_read(&failed[SMB2_LOGOFF_HE])); |
| 353 | seq_printf(m, "\nTreeConnects: %d sent %d failed", |
| 354 | atomic_read(&sent[SMB2_TREE_CONNECT_HE]), |
| 355 | atomic_read(&failed[SMB2_TREE_CONNECT_HE])); |
| 356 | seq_printf(m, "\nTreeDisconnects: %d sent %d failed", |
| 357 | atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]), |
| 358 | atomic_read(&failed[SMB2_TREE_DISCONNECT_HE])); |
| 359 | seq_printf(m, "\nCreates: %d sent %d failed", |
| 360 | atomic_read(&sent[SMB2_CREATE_HE]), |
| 361 | atomic_read(&failed[SMB2_CREATE_HE])); |
| 362 | seq_printf(m, "\nCloses: %d sent %d failed", |
| 363 | atomic_read(&sent[SMB2_CLOSE_HE]), |
| 364 | atomic_read(&failed[SMB2_CLOSE_HE])); |
| 365 | seq_printf(m, "\nFlushes: %d sent %d failed", |
| 366 | atomic_read(&sent[SMB2_FLUSH_HE]), |
| 367 | atomic_read(&failed[SMB2_FLUSH_HE])); |
| 368 | seq_printf(m, "\nReads: %d sent %d failed", |
| 369 | atomic_read(&sent[SMB2_READ_HE]), |
| 370 | atomic_read(&failed[SMB2_READ_HE])); |
| 371 | seq_printf(m, "\nWrites: %d sent %d failed", |
| 372 | atomic_read(&sent[SMB2_WRITE_HE]), |
| 373 | atomic_read(&failed[SMB2_WRITE_HE])); |
| 374 | seq_printf(m, "\nLocks: %d sent %d failed", |
| 375 | atomic_read(&sent[SMB2_LOCK_HE]), |
| 376 | atomic_read(&failed[SMB2_LOCK_HE])); |
| 377 | seq_printf(m, "\nIOCTLs: %d sent %d failed", |
| 378 | atomic_read(&sent[SMB2_IOCTL_HE]), |
| 379 | atomic_read(&failed[SMB2_IOCTL_HE])); |
| 380 | seq_printf(m, "\nCancels: %d sent %d failed", |
| 381 | atomic_read(&sent[SMB2_CANCEL_HE]), |
| 382 | atomic_read(&failed[SMB2_CANCEL_HE])); |
| 383 | seq_printf(m, "\nEchos: %d sent %d failed", |
| 384 | atomic_read(&sent[SMB2_ECHO_HE]), |
| 385 | atomic_read(&failed[SMB2_ECHO_HE])); |
| 386 | seq_printf(m, "\nQueryDirectories: %d sent %d failed", |
| 387 | atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]), |
| 388 | atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE])); |
| 389 | seq_printf(m, "\nChangeNotifies: %d sent %d failed", |
| 390 | atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]), |
| 391 | atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE])); |
| 392 | seq_printf(m, "\nQueryInfos: %d sent %d failed", |
| 393 | atomic_read(&sent[SMB2_QUERY_INFO_HE]), |
| 394 | atomic_read(&failed[SMB2_QUERY_INFO_HE])); |
| 395 | seq_printf(m, "\nSetInfos: %d sent %d failed", |
| 396 | atomic_read(&sent[SMB2_SET_INFO_HE]), |
| 397 | atomic_read(&failed[SMB2_SET_INFO_HE])); |
| 398 | seq_printf(m, "\nOplockBreaks: %d sent %d failed", |
| 399 | atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]), |
| 400 | atomic_read(&failed[SMB2_OPLOCK_BREAK_HE])); |
| 401 | #endif |
| 402 | } |
| 403 | |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 404 | static void |
| 405 | smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock) |
| 406 | { |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 407 | struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 408 | struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; |
| 409 | |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 410 | cfile->fid.persistent_fid = fid->persistent_fid; |
| 411 | cfile->fid.volatile_fid = fid->volatile_fid; |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 412 | server->ops->set_oplock_level(cinode, oplock, fid->epoch, |
| 413 | &fid->purge_cache); |
Pavel Shilovsky | 18cceb6 | 2013-09-05 13:01:06 +0400 | [diff] [blame] | 414 | cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode); |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 415 | } |
| 416 | |
Pavel Shilovsky | 760ad0c | 2012-09-25 11:00:07 +0400 | [diff] [blame] | 417 | static void |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 418 | smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon, |
| 419 | struct cifs_fid *fid) |
| 420 | { |
Pavel Shilovsky | 760ad0c | 2012-09-25 11:00:07 +0400 | [diff] [blame] | 421 | SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 422 | } |
| 423 | |
Pavel Shilovsky | 7a5cfb1 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 424 | static int |
| 425 | smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon, |
| 426 | struct cifs_fid *fid) |
| 427 | { |
| 428 | return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
| 429 | } |
| 430 | |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 431 | static unsigned int |
| 432 | smb2_read_data_offset(char *buf) |
| 433 | { |
| 434 | struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf; |
| 435 | return rsp->DataOffset; |
| 436 | } |
| 437 | |
| 438 | static unsigned int |
| 439 | smb2_read_data_length(char *buf) |
| 440 | { |
| 441 | struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf; |
| 442 | return le32_to_cpu(rsp->DataLength); |
| 443 | } |
| 444 | |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 445 | |
| 446 | static int |
| 447 | smb2_sync_read(const unsigned int xid, struct cifsFileInfo *cfile, |
| 448 | struct cifs_io_parms *parms, unsigned int *bytes_read, |
| 449 | char **buf, int *buf_type) |
| 450 | { |
| 451 | parms->persistent_fid = cfile->fid.persistent_fid; |
| 452 | parms->volatile_fid = cfile->fid.volatile_fid; |
| 453 | return SMB2_read(xid, parms, bytes_read, buf, buf_type); |
| 454 | } |
| 455 | |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 456 | static int |
| 457 | smb2_sync_write(const unsigned int xid, struct cifsFileInfo *cfile, |
| 458 | struct cifs_io_parms *parms, unsigned int *written, |
| 459 | struct kvec *iov, unsigned long nr_segs) |
| 460 | { |
| 461 | |
| 462 | parms->persistent_fid = cfile->fid.persistent_fid; |
| 463 | parms->volatile_fid = cfile->fid.volatile_fid; |
| 464 | return SMB2_write(xid, parms, written, iov, nr_segs); |
| 465 | } |
| 466 | |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 467 | static int |
| 468 | smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon, |
| 469 | struct cifsFileInfo *cfile, __u64 size, bool set_alloc) |
| 470 | { |
| 471 | __le64 eof = cpu_to_le64(size); |
| 472 | return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, |
| 473 | cfile->fid.volatile_fid, cfile->pid, &eof); |
| 474 | } |
| 475 | |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 476 | static int |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 477 | smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon, |
| 478 | struct cifsFileInfo *cfile) |
| 479 | { |
| 480 | return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid, |
| 481 | cfile->fid.volatile_fid); |
| 482 | } |
| 483 | |
| 484 | static int |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 485 | smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon, |
| 486 | const char *path, struct cifs_sb_info *cifs_sb, |
| 487 | struct cifs_fid *fid, __u16 search_flags, |
| 488 | struct cifs_search_info *srch_inf) |
| 489 | { |
| 490 | __le16 *utf16_path; |
| 491 | int rc; |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 492 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 493 | struct cifs_open_parms oparms; |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 494 | |
| 495 | utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); |
| 496 | if (!utf16_path) |
| 497 | return -ENOMEM; |
| 498 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 499 | oparms.tcon = tcon; |
| 500 | oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA; |
| 501 | oparms.disposition = FILE_OPEN; |
| 502 | oparms.create_options = 0; |
| 503 | oparms.fid = fid; |
Pavel Shilovsky | 9cbc0b7 | 2013-07-09 18:40:58 +0400 | [diff] [blame] | 504 | oparms.reconnect = false; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 505 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 506 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 507 | kfree(utf16_path); |
| 508 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 509 | cifs_dbg(VFS, "open dir failed\n"); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 510 | return rc; |
| 511 | } |
| 512 | |
| 513 | srch_inf->entries_in_buffer = 0; |
| 514 | srch_inf->index_of_last_entry = 0; |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 515 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 516 | rc = SMB2_query_directory(xid, tcon, fid->persistent_fid, |
| 517 | fid->volatile_fid, 0, srch_inf); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 518 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 519 | cifs_dbg(VFS, "query directory failed\n"); |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 520 | SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 521 | } |
| 522 | return rc; |
| 523 | } |
| 524 | |
| 525 | static int |
| 526 | smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon, |
| 527 | struct cifs_fid *fid, __u16 search_flags, |
| 528 | struct cifs_search_info *srch_inf) |
| 529 | { |
| 530 | return SMB2_query_directory(xid, tcon, fid->persistent_fid, |
| 531 | fid->volatile_fid, 0, srch_inf); |
| 532 | } |
| 533 | |
| 534 | static int |
| 535 | smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon, |
| 536 | struct cifs_fid *fid) |
| 537 | { |
| 538 | return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
| 539 | } |
| 540 | |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 541 | /* |
| 542 | * If we negotiate SMB2 protocol and get STATUS_PENDING - update |
| 543 | * the number of credits and return true. Otherwise - return false. |
| 544 | */ |
| 545 | static bool |
| 546 | smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length) |
| 547 | { |
| 548 | struct smb2_hdr *hdr = (struct smb2_hdr *)buf; |
| 549 | |
Steve French | 12e8a20 | 2012-09-19 09:19:39 -0700 | [diff] [blame] | 550 | if (hdr->Status != STATUS_PENDING) |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 551 | return false; |
| 552 | |
| 553 | if (!length) { |
| 554 | spin_lock(&server->req_lock); |
| 555 | server->credits += le16_to_cpu(hdr->CreditRequest); |
| 556 | spin_unlock(&server->req_lock); |
| 557 | wake_up(&server->request_q); |
| 558 | } |
| 559 | |
| 560 | return true; |
| 561 | } |
| 562 | |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 563 | static int |
| 564 | smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid, |
| 565 | struct cifsInodeInfo *cinode) |
| 566 | { |
Pavel Shilovsky | 0822f51 | 2012-09-19 06:22:45 -0700 | [diff] [blame] | 567 | if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING) |
| 568 | return SMB2_lease_break(0, tcon, cinode->lease_key, |
| 569 | smb2_get_lease_state(cinode)); |
| 570 | |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 571 | return SMB2_oplock_break(0, tcon, fid->persistent_fid, |
| 572 | fid->volatile_fid, |
Pavel Shilovsky | 18cceb6 | 2013-09-05 13:01:06 +0400 | [diff] [blame] | 573 | CIFS_CACHE_READ(cinode) ? 1 : 0); |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 574 | } |
| 575 | |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 576 | static int |
| 577 | smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon, |
| 578 | struct kstatfs *buf) |
| 579 | { |
| 580 | int rc; |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 581 | __le16 srch_path = 0; /* Null - open root of share */ |
| 582 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 583 | struct cifs_open_parms oparms; |
| 584 | struct cifs_fid fid; |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 585 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 586 | oparms.tcon = tcon; |
| 587 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 588 | oparms.disposition = FILE_OPEN; |
| 589 | oparms.create_options = 0; |
| 590 | oparms.fid = &fid; |
Pavel Shilovsky | 9cbc0b7 | 2013-07-09 18:40:58 +0400 | [diff] [blame] | 591 | oparms.reconnect = false; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 592 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 593 | rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL); |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 594 | if (rc) |
| 595 | return rc; |
| 596 | buf->f_type = SMB2_MAGIC_NUMBER; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 597 | rc = SMB2_QFS_info(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
| 598 | buf); |
| 599 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 600 | return rc; |
| 601 | } |
| 602 | |
Pavel Shilovsky | 027e8ee | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 603 | static bool |
| 604 | smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2) |
| 605 | { |
| 606 | return ob1->fid.persistent_fid == ob2->fid.persistent_fid && |
| 607 | ob1->fid.volatile_fid == ob2->fid.volatile_fid; |
| 608 | } |
| 609 | |
Pavel Shilovsky | f7ba7fe | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 610 | static int |
| 611 | smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset, |
| 612 | __u64 length, __u32 type, int lock, int unlock, bool wait) |
| 613 | { |
| 614 | if (unlock && !lock) |
| 615 | type = SMB2_LOCKFLAG_UNLOCK; |
| 616 | return SMB2_lock(xid, tlink_tcon(cfile->tlink), |
| 617 | cfile->fid.persistent_fid, cfile->fid.volatile_fid, |
| 618 | current->tgid, length, offset, type, wait); |
| 619 | } |
| 620 | |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 621 | static void |
| 622 | smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid) |
| 623 | { |
| 624 | memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE); |
| 625 | } |
| 626 | |
| 627 | static void |
| 628 | smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid) |
| 629 | { |
| 630 | memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE); |
| 631 | } |
| 632 | |
| 633 | static void |
| 634 | smb2_new_lease_key(struct cifs_fid *fid) |
| 635 | { |
| 636 | get_random_bytes(fid->lease_key, SMB2_LEASE_KEY_SIZE); |
| 637 | } |
| 638 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 639 | static int |
| 640 | smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon, |
| 641 | const char *full_path, char **target_path, |
| 642 | struct cifs_sb_info *cifs_sb) |
| 643 | { |
| 644 | int rc; |
| 645 | __le16 *utf16_path; |
| 646 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 647 | struct cifs_open_parms oparms; |
| 648 | struct cifs_fid fid; |
| 649 | struct smb2_err_rsp *err_buf = NULL; |
| 650 | struct smb2_symlink_err_rsp *symlink; |
| 651 | unsigned int sub_len, sub_offset; |
| 652 | |
| 653 | cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path); |
| 654 | |
| 655 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); |
| 656 | if (!utf16_path) |
| 657 | return -ENOMEM; |
| 658 | |
| 659 | oparms.tcon = tcon; |
| 660 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 661 | oparms.disposition = FILE_OPEN; |
| 662 | oparms.create_options = 0; |
| 663 | oparms.fid = &fid; |
| 664 | oparms.reconnect = false; |
| 665 | |
| 666 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_buf); |
| 667 | |
| 668 | if (!rc || !err_buf) { |
| 669 | kfree(utf16_path); |
| 670 | return -ENOENT; |
| 671 | } |
| 672 | /* open must fail on symlink - reset rc */ |
| 673 | rc = 0; |
| 674 | symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData; |
| 675 | sub_len = le16_to_cpu(symlink->SubstituteNameLength); |
| 676 | sub_offset = le16_to_cpu(symlink->SubstituteNameOffset); |
| 677 | *target_path = cifs_strndup_from_utf16( |
| 678 | (char *)symlink->PathBuffer + sub_offset, |
| 679 | sub_len, true, cifs_sb->local_nls); |
| 680 | if (!(*target_path)) { |
| 681 | kfree(utf16_path); |
| 682 | return -ENOMEM; |
| 683 | } |
| 684 | convert_delimiter(*target_path, '/'); |
| 685 | cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path); |
| 686 | kfree(utf16_path); |
| 687 | return rc; |
| 688 | } |
| 689 | |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 690 | static void |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 691 | smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock, |
| 692 | unsigned int epoch, bool *purge_cache) |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 693 | { |
| 694 | oplock &= 0xFF; |
| 695 | if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE) |
| 696 | return; |
| 697 | if (oplock == SMB2_OPLOCK_LEVEL_BATCH) { |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 698 | cinode->oplock = CIFS_CACHE_RHW_FLG; |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 699 | cifs_dbg(FYI, "Batch Oplock granted on inode %p\n", |
| 700 | &cinode->vfs_inode); |
| 701 | } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) { |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 702 | cinode->oplock = CIFS_CACHE_RW_FLG; |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 703 | cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n", |
| 704 | &cinode->vfs_inode); |
| 705 | } else if (oplock == SMB2_OPLOCK_LEVEL_II) { |
| 706 | cinode->oplock = CIFS_CACHE_READ_FLG; |
| 707 | cifs_dbg(FYI, "Level II Oplock granted on inode %p\n", |
| 708 | &cinode->vfs_inode); |
| 709 | } else |
| 710 | cinode->oplock = 0; |
| 711 | } |
| 712 | |
| 713 | static void |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 714 | smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock, |
| 715 | unsigned int epoch, bool *purge_cache) |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 716 | { |
| 717 | char message[5] = {0}; |
| 718 | |
| 719 | oplock &= 0xFF; |
| 720 | if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE) |
| 721 | return; |
| 722 | |
| 723 | cinode->oplock = 0; |
| 724 | if (oplock & SMB2_LEASE_READ_CACHING_HE) { |
| 725 | cinode->oplock |= CIFS_CACHE_READ_FLG; |
| 726 | strcat(message, "R"); |
| 727 | } |
| 728 | if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) { |
| 729 | cinode->oplock |= CIFS_CACHE_HANDLE_FLG; |
| 730 | strcat(message, "H"); |
| 731 | } |
| 732 | if (oplock & SMB2_LEASE_WRITE_CACHING_HE) { |
| 733 | cinode->oplock |= CIFS_CACHE_WRITE_FLG; |
| 734 | strcat(message, "W"); |
| 735 | } |
| 736 | if (!cinode->oplock) |
| 737 | strcat(message, "None"); |
| 738 | cifs_dbg(FYI, "%s Lease granted on inode %p\n", message, |
| 739 | &cinode->vfs_inode); |
| 740 | } |
| 741 | |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 742 | static void |
| 743 | smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock, |
| 744 | unsigned int epoch, bool *purge_cache) |
| 745 | { |
| 746 | unsigned int old_oplock = cinode->oplock; |
| 747 | |
| 748 | smb21_set_oplock_level(cinode, oplock, epoch, purge_cache); |
| 749 | |
| 750 | if (purge_cache) { |
| 751 | *purge_cache = false; |
| 752 | if (old_oplock == CIFS_CACHE_READ_FLG) { |
| 753 | if (cinode->oplock == CIFS_CACHE_READ_FLG && |
| 754 | (epoch - cinode->epoch > 0)) |
| 755 | *purge_cache = true; |
| 756 | else if (cinode->oplock == CIFS_CACHE_RH_FLG && |
| 757 | (epoch - cinode->epoch > 1)) |
| 758 | *purge_cache = true; |
| 759 | else if (cinode->oplock == CIFS_CACHE_RHW_FLG && |
| 760 | (epoch - cinode->epoch > 1)) |
| 761 | *purge_cache = true; |
| 762 | else if (cinode->oplock == 0 && |
| 763 | (epoch - cinode->epoch > 0)) |
| 764 | *purge_cache = true; |
| 765 | } else if (old_oplock == CIFS_CACHE_RH_FLG) { |
| 766 | if (cinode->oplock == CIFS_CACHE_RH_FLG && |
| 767 | (epoch - cinode->epoch > 0)) |
| 768 | *purge_cache = true; |
| 769 | else if (cinode->oplock == CIFS_CACHE_RHW_FLG && |
| 770 | (epoch - cinode->epoch > 1)) |
| 771 | *purge_cache = true; |
| 772 | } |
| 773 | cinode->epoch = epoch; |
| 774 | } |
| 775 | } |
| 776 | |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 777 | static bool |
| 778 | smb2_is_read_op(__u32 oplock) |
| 779 | { |
| 780 | return oplock == SMB2_OPLOCK_LEVEL_II; |
| 781 | } |
| 782 | |
| 783 | static bool |
| 784 | smb21_is_read_op(__u32 oplock) |
| 785 | { |
| 786 | return (oplock & SMB2_LEASE_READ_CACHING_HE) && |
| 787 | !(oplock & SMB2_LEASE_WRITE_CACHING_HE); |
| 788 | } |
| 789 | |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 790 | static __le32 |
| 791 | map_oplock_to_lease(u8 oplock) |
| 792 | { |
| 793 | if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) |
| 794 | return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING; |
| 795 | else if (oplock == SMB2_OPLOCK_LEVEL_II) |
| 796 | return SMB2_LEASE_READ_CACHING; |
| 797 | else if (oplock == SMB2_OPLOCK_LEVEL_BATCH) |
| 798 | return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING | |
| 799 | SMB2_LEASE_WRITE_CACHING; |
| 800 | return 0; |
| 801 | } |
| 802 | |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 803 | static char * |
| 804 | smb2_create_lease_buf(u8 *lease_key, u8 oplock) |
| 805 | { |
| 806 | struct create_lease *buf; |
| 807 | |
| 808 | buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL); |
| 809 | if (!buf) |
| 810 | return NULL; |
| 811 | |
| 812 | buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key)); |
| 813 | buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8))); |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 814 | buf->lcontext.LeaseState = map_oplock_to_lease(oplock); |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 815 | |
| 816 | buf->ccontext.DataOffset = cpu_to_le16(offsetof |
| 817 | (struct create_lease, lcontext)); |
| 818 | buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context)); |
| 819 | buf->ccontext.NameOffset = cpu_to_le16(offsetof |
| 820 | (struct create_lease, Name)); |
| 821 | buf->ccontext.NameLength = cpu_to_le16(4); |
| 822 | buf->Name[0] = 'R'; |
| 823 | buf->Name[1] = 'q'; |
| 824 | buf->Name[2] = 'L'; |
| 825 | buf->Name[3] = 's'; |
| 826 | return (char *)buf; |
| 827 | } |
| 828 | |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 829 | static char * |
| 830 | smb3_create_lease_buf(u8 *lease_key, u8 oplock) |
| 831 | { |
| 832 | struct create_lease_v2 *buf; |
| 833 | |
| 834 | buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL); |
| 835 | if (!buf) |
| 836 | return NULL; |
| 837 | |
| 838 | buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key)); |
| 839 | buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8))); |
| 840 | buf->lcontext.LeaseState = map_oplock_to_lease(oplock); |
| 841 | |
| 842 | buf->ccontext.DataOffset = cpu_to_le16(offsetof |
| 843 | (struct create_lease_v2, lcontext)); |
| 844 | buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2)); |
| 845 | buf->ccontext.NameOffset = cpu_to_le16(offsetof |
| 846 | (struct create_lease_v2, Name)); |
| 847 | buf->ccontext.NameLength = cpu_to_le16(4); |
| 848 | buf->Name[0] = 'R'; |
| 849 | buf->Name[1] = 'q'; |
| 850 | buf->Name[2] = 'L'; |
| 851 | buf->Name[3] = 's'; |
| 852 | return (char *)buf; |
| 853 | } |
| 854 | |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 855 | static __u8 |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 856 | smb2_parse_lease_buf(void *buf, unsigned int *epoch) |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 857 | { |
| 858 | struct create_lease *lc = (struct create_lease *)buf; |
| 859 | |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 860 | *epoch = 0; /* not used */ |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 861 | if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS) |
| 862 | return SMB2_OPLOCK_LEVEL_NOCHANGE; |
| 863 | return le32_to_cpu(lc->lcontext.LeaseState); |
| 864 | } |
| 865 | |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 866 | static __u8 |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 867 | smb3_parse_lease_buf(void *buf, unsigned int *epoch) |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 868 | { |
| 869 | struct create_lease_v2 *lc = (struct create_lease_v2 *)buf; |
| 870 | |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 871 | *epoch = le16_to_cpu(lc->lcontext.Epoch); |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 872 | if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS) |
| 873 | return SMB2_OPLOCK_LEVEL_NOCHANGE; |
| 874 | return le32_to_cpu(lc->lcontext.LeaseState); |
| 875 | } |
| 876 | |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 877 | struct smb_version_operations smb20_operations = { |
| 878 | .compare_fids = smb2_compare_fids, |
| 879 | .setup_request = smb2_setup_request, |
| 880 | .setup_async_request = smb2_setup_async_request, |
| 881 | .check_receive = smb2_check_receive, |
| 882 | .add_credits = smb2_add_credits, |
| 883 | .set_credits = smb2_set_credits, |
| 884 | .get_credits_field = smb2_get_credits_field, |
| 885 | .get_credits = smb2_get_credits, |
| 886 | .get_next_mid = smb2_get_next_mid, |
| 887 | .read_data_offset = smb2_read_data_offset, |
| 888 | .read_data_length = smb2_read_data_length, |
| 889 | .map_error = map_smb2_to_linux_error, |
| 890 | .find_mid = smb2_find_mid, |
| 891 | .check_message = smb2_check_message, |
| 892 | .dump_detail = smb2_dump_detail, |
| 893 | .clear_stats = smb2_clear_stats, |
| 894 | .print_stats = smb2_print_stats, |
| 895 | .is_oplock_break = smb2_is_valid_oplock_break, |
| 896 | .need_neg = smb2_need_neg, |
| 897 | .negotiate = smb2_negotiate, |
| 898 | .negotiate_wsize = smb2_negotiate_wsize, |
| 899 | .negotiate_rsize = smb2_negotiate_rsize, |
| 900 | .sess_setup = SMB2_sess_setup, |
| 901 | .logoff = SMB2_logoff, |
| 902 | .tree_connect = SMB2_tcon, |
| 903 | .tree_disconnect = SMB2_tdis, |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 904 | .qfs_tcon = smb2_qfs_tcon, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 905 | .is_path_accessible = smb2_is_path_accessible, |
| 906 | .can_echo = smb2_can_echo, |
| 907 | .echo = SMB2_echo, |
| 908 | .query_path_info = smb2_query_path_info, |
| 909 | .get_srv_inum = smb2_get_srv_inum, |
| 910 | .query_file_info = smb2_query_file_info, |
| 911 | .set_path_size = smb2_set_path_size, |
| 912 | .set_file_size = smb2_set_file_size, |
| 913 | .set_file_info = smb2_set_file_info, |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 914 | .set_compression = smb2_set_compression, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 915 | .mkdir = smb2_mkdir, |
| 916 | .mkdir_setinfo = smb2_mkdir_setinfo, |
| 917 | .rmdir = smb2_rmdir, |
| 918 | .unlink = smb2_unlink, |
| 919 | .rename = smb2_rename_path, |
| 920 | .create_hardlink = smb2_create_hardlink, |
| 921 | .query_symlink = smb2_query_symlink, |
| 922 | .open = smb2_open_file, |
| 923 | .set_fid = smb2_set_fid, |
| 924 | .close = smb2_close_file, |
| 925 | .flush = smb2_flush_file, |
| 926 | .async_readv = smb2_async_readv, |
| 927 | .async_writev = smb2_async_writev, |
| 928 | .sync_read = smb2_sync_read, |
| 929 | .sync_write = smb2_sync_write, |
| 930 | .query_dir_first = smb2_query_dir_first, |
| 931 | .query_dir_next = smb2_query_dir_next, |
| 932 | .close_dir = smb2_close_dir, |
| 933 | .calc_smb_size = smb2_calc_size, |
| 934 | .is_status_pending = smb2_is_status_pending, |
| 935 | .oplock_response = smb2_oplock_response, |
| 936 | .queryfs = smb2_queryfs, |
| 937 | .mand_lock = smb2_mand_lock, |
| 938 | .mand_unlock_range = smb2_unlock_range, |
| 939 | .push_mand_locks = smb2_push_mandatory_locks, |
| 940 | .get_lease_key = smb2_get_lease_key, |
| 941 | .set_lease_key = smb2_set_lease_key, |
| 942 | .new_lease_key = smb2_new_lease_key, |
| 943 | .calc_signature = smb2_calc_signature, |
| 944 | .is_read_op = smb2_is_read_op, |
| 945 | .set_oplock_level = smb2_set_oplock_level, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 946 | .create_lease_buf = smb2_create_lease_buf, |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 947 | .parse_lease_buf = smb2_parse_lease_buf, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 948 | }; |
| 949 | |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 950 | struct smb_version_operations smb21_operations = { |
Pavel Shilovsky | 027e8ee | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 951 | .compare_fids = smb2_compare_fids, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 952 | .setup_request = smb2_setup_request, |
Pavel Shilovsky | c95b8ee | 2012-07-11 14:45:28 +0400 | [diff] [blame] | 953 | .setup_async_request = smb2_setup_async_request, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 954 | .check_receive = smb2_check_receive, |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 955 | .add_credits = smb2_add_credits, |
| 956 | .set_credits = smb2_set_credits, |
| 957 | .get_credits_field = smb2_get_credits_field, |
| 958 | .get_credits = smb2_get_credits, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 959 | .get_next_mid = smb2_get_next_mid, |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 960 | .read_data_offset = smb2_read_data_offset, |
| 961 | .read_data_length = smb2_read_data_length, |
| 962 | .map_error = map_smb2_to_linux_error, |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 963 | .find_mid = smb2_find_mid, |
| 964 | .check_message = smb2_check_message, |
| 965 | .dump_detail = smb2_dump_detail, |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 966 | .clear_stats = smb2_clear_stats, |
| 967 | .print_stats = smb2_print_stats, |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 968 | .is_oplock_break = smb2_is_valid_oplock_break, |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 969 | .need_neg = smb2_need_neg, |
| 970 | .negotiate = smb2_negotiate, |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 971 | .negotiate_wsize = smb2_negotiate_wsize, |
| 972 | .negotiate_rsize = smb2_negotiate_rsize, |
Pavel Shilovsky | 5478f9b | 2011-12-27 16:22:00 +0400 | [diff] [blame] | 973 | .sess_setup = SMB2_sess_setup, |
| 974 | .logoff = SMB2_logoff, |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 975 | .tree_connect = SMB2_tcon, |
| 976 | .tree_disconnect = SMB2_tdis, |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 977 | .qfs_tcon = smb2_qfs_tcon, |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 978 | .is_path_accessible = smb2_is_path_accessible, |
Pavel Shilovsky | 9094fad | 2012-07-12 18:30:44 +0400 | [diff] [blame] | 979 | .can_echo = smb2_can_echo, |
| 980 | .echo = SMB2_echo, |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 981 | .query_path_info = smb2_query_path_info, |
| 982 | .get_srv_inum = smb2_get_srv_inum, |
Pavel Shilovsky | b7546bc | 2012-09-18 16:20:27 -0700 | [diff] [blame] | 983 | .query_file_info = smb2_query_file_info, |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 984 | .set_path_size = smb2_set_path_size, |
| 985 | .set_file_size = smb2_set_file_size, |
Pavel Shilovsky | 1feeaac | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 986 | .set_file_info = smb2_set_file_info, |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 987 | .set_compression = smb2_set_compression, |
Pavel Shilovsky | a0e7318 | 2011-07-19 12:56:37 +0400 | [diff] [blame] | 988 | .mkdir = smb2_mkdir, |
| 989 | .mkdir_setinfo = smb2_mkdir_setinfo, |
Pavel Shilovsky | 1a500f0 | 2012-07-10 16:14:38 +0400 | [diff] [blame] | 990 | .rmdir = smb2_rmdir, |
Pavel Shilovsky | cbe6f43 | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 991 | .unlink = smb2_unlink, |
Pavel Shilovsky | 35143eb | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 992 | .rename = smb2_rename_path, |
Pavel Shilovsky | 568798c | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 993 | .create_hardlink = smb2_create_hardlink, |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 994 | .query_symlink = smb2_query_symlink, |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 995 | .open = smb2_open_file, |
| 996 | .set_fid = smb2_set_fid, |
| 997 | .close = smb2_close_file, |
Pavel Shilovsky | 7a5cfb1 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 998 | .flush = smb2_flush_file, |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 999 | .async_readv = smb2_async_readv, |
Pavel Shilovsky | 3331914 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1000 | .async_writev = smb2_async_writev, |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 1001 | .sync_read = smb2_sync_read, |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 1002 | .sync_write = smb2_sync_write, |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1003 | .query_dir_first = smb2_query_dir_first, |
| 1004 | .query_dir_next = smb2_query_dir_next, |
| 1005 | .close_dir = smb2_close_dir, |
| 1006 | .calc_smb_size = smb2_calc_size, |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1007 | .is_status_pending = smb2_is_status_pending, |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1008 | .oplock_response = smb2_oplock_response, |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 1009 | .queryfs = smb2_queryfs, |
Pavel Shilovsky | f7ba7fe | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 1010 | .mand_lock = smb2_mand_lock, |
| 1011 | .mand_unlock_range = smb2_unlock_range, |
Pavel Shilovsky | b140799 | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 1012 | .push_mand_locks = smb2_push_mandatory_locks, |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 1013 | .get_lease_key = smb2_get_lease_key, |
| 1014 | .set_lease_key = smb2_set_lease_key, |
| 1015 | .new_lease_key = smb2_new_lease_key, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 1016 | .calc_signature = smb2_calc_signature, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1017 | .is_read_op = smb21_is_read_op, |
| 1018 | .set_oplock_level = smb21_set_oplock_level, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 1019 | .create_lease_buf = smb2_create_lease_buf, |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 1020 | .parse_lease_buf = smb2_parse_lease_buf, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 1021 | }; |
| 1022 | |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 1023 | struct smb_version_operations smb30_operations = { |
| 1024 | .compare_fids = smb2_compare_fids, |
| 1025 | .setup_request = smb2_setup_request, |
| 1026 | .setup_async_request = smb2_setup_async_request, |
| 1027 | .check_receive = smb2_check_receive, |
| 1028 | .add_credits = smb2_add_credits, |
| 1029 | .set_credits = smb2_set_credits, |
| 1030 | .get_credits_field = smb2_get_credits_field, |
| 1031 | .get_credits = smb2_get_credits, |
| 1032 | .get_next_mid = smb2_get_next_mid, |
| 1033 | .read_data_offset = smb2_read_data_offset, |
| 1034 | .read_data_length = smb2_read_data_length, |
| 1035 | .map_error = map_smb2_to_linux_error, |
| 1036 | .find_mid = smb2_find_mid, |
| 1037 | .check_message = smb2_check_message, |
| 1038 | .dump_detail = smb2_dump_detail, |
| 1039 | .clear_stats = smb2_clear_stats, |
| 1040 | .print_stats = smb2_print_stats, |
Steve French | 769ee6a | 2013-06-19 14:15:30 -0500 | [diff] [blame] | 1041 | .dump_share_caps = smb2_dump_share_caps, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 1042 | .is_oplock_break = smb2_is_valid_oplock_break, |
| 1043 | .need_neg = smb2_need_neg, |
| 1044 | .negotiate = smb2_negotiate, |
| 1045 | .negotiate_wsize = smb2_negotiate_wsize, |
| 1046 | .negotiate_rsize = smb2_negotiate_rsize, |
| 1047 | .sess_setup = SMB2_sess_setup, |
| 1048 | .logoff = SMB2_logoff, |
| 1049 | .tree_connect = SMB2_tcon, |
| 1050 | .tree_disconnect = SMB2_tdis, |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 1051 | .qfs_tcon = smb2_qfs_tcon, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 1052 | .is_path_accessible = smb2_is_path_accessible, |
| 1053 | .can_echo = smb2_can_echo, |
| 1054 | .echo = SMB2_echo, |
| 1055 | .query_path_info = smb2_query_path_info, |
| 1056 | .get_srv_inum = smb2_get_srv_inum, |
| 1057 | .query_file_info = smb2_query_file_info, |
| 1058 | .set_path_size = smb2_set_path_size, |
| 1059 | .set_file_size = smb2_set_file_size, |
| 1060 | .set_file_info = smb2_set_file_info, |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 1061 | .set_compression = smb2_set_compression, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 1062 | .mkdir = smb2_mkdir, |
| 1063 | .mkdir_setinfo = smb2_mkdir_setinfo, |
| 1064 | .rmdir = smb2_rmdir, |
| 1065 | .unlink = smb2_unlink, |
| 1066 | .rename = smb2_rename_path, |
| 1067 | .create_hardlink = smb2_create_hardlink, |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 1068 | .query_symlink = smb2_query_symlink, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 1069 | .open = smb2_open_file, |
| 1070 | .set_fid = smb2_set_fid, |
| 1071 | .close = smb2_close_file, |
| 1072 | .flush = smb2_flush_file, |
| 1073 | .async_readv = smb2_async_readv, |
| 1074 | .async_writev = smb2_async_writev, |
| 1075 | .sync_read = smb2_sync_read, |
| 1076 | .sync_write = smb2_sync_write, |
| 1077 | .query_dir_first = smb2_query_dir_first, |
| 1078 | .query_dir_next = smb2_query_dir_next, |
| 1079 | .close_dir = smb2_close_dir, |
| 1080 | .calc_smb_size = smb2_calc_size, |
| 1081 | .is_status_pending = smb2_is_status_pending, |
| 1082 | .oplock_response = smb2_oplock_response, |
| 1083 | .queryfs = smb2_queryfs, |
| 1084 | .mand_lock = smb2_mand_lock, |
| 1085 | .mand_unlock_range = smb2_unlock_range, |
| 1086 | .push_mand_locks = smb2_push_mandatory_locks, |
| 1087 | .get_lease_key = smb2_get_lease_key, |
| 1088 | .set_lease_key = smb2_set_lease_key, |
| 1089 | .new_lease_key = smb2_new_lease_key, |
Steve French | e65a5cb | 2013-06-27 01:06:50 -0500 | [diff] [blame] | 1090 | .generate_signingkey = generate_smb3signingkey, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 1091 | .calc_signature = smb3_calc_signature, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1092 | .is_read_op = smb21_is_read_op, |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 1093 | .set_oplock_level = smb3_set_oplock_level, |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1094 | .create_lease_buf = smb3_create_lease_buf, |
| 1095 | .parse_lease_buf = smb3_parse_lease_buf, |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 1096 | }; |
| 1097 | |
Steve French | dd446b1 | 2012-11-28 23:21:06 -0600 | [diff] [blame] | 1098 | struct smb_version_values smb20_values = { |
| 1099 | .version_string = SMB20_VERSION_STRING, |
| 1100 | .protocol_id = SMB20_PROT_ID, |
| 1101 | .req_capabilities = 0, /* MBZ */ |
| 1102 | .large_lock_type = 0, |
| 1103 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 1104 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 1105 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
| 1106 | .header_size = sizeof(struct smb2_hdr), |
| 1107 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 1108 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 1109 | .lock_cmd = SMB2_LOCK, |
| 1110 | .cap_unix = 0, |
| 1111 | .cap_nt_find = SMB2_NT_FIND, |
| 1112 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 5028588 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 1113 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 1114 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 1115 | .create_lease_size = sizeof(struct create_lease), |
Steve French | dd446b1 | 2012-11-28 23:21:06 -0600 | [diff] [blame] | 1116 | }; |
| 1117 | |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 1118 | struct smb_version_values smb21_values = { |
| 1119 | .version_string = SMB21_VERSION_STRING, |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 1120 | .protocol_id = SMB21_PROT_ID, |
| 1121 | .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */ |
| 1122 | .large_lock_type = 0, |
| 1123 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 1124 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 1125 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
| 1126 | .header_size = sizeof(struct smb2_hdr), |
| 1127 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 1128 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 1129 | .lock_cmd = SMB2_LOCK, |
| 1130 | .cap_unix = 0, |
| 1131 | .cap_nt_find = SMB2_NT_FIND, |
| 1132 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 5028588 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 1133 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 1134 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 1135 | .create_lease_size = sizeof(struct create_lease), |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 1136 | }; |
| 1137 | |
| 1138 | struct smb_version_values smb30_values = { |
| 1139 | .version_string = SMB30_VERSION_STRING, |
| 1140 | .protocol_id = SMB30_PROT_ID, |
| 1141 | .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU, |
Pavel Shilovsky | 027e8ee | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 1142 | .large_lock_type = 0, |
| 1143 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 1144 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 1145 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 1146 | .header_size = sizeof(struct smb2_hdr), |
| 1147 | .max_header_size = MAX_SMB2_HDR_SIZE, |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1148 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 1149 | .lock_cmd = SMB2_LOCK, |
Pavel Shilovsky | 29e20f9 | 2012-07-13 13:58:14 +0400 | [diff] [blame] | 1150 | .cap_unix = 0, |
| 1151 | .cap_nt_find = SMB2_NT_FIND, |
| 1152 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 5028588 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 1153 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 1154 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1155 | .create_lease_size = sizeof(struct create_lease_v2), |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 1156 | }; |
Steve French | 20b6d8b | 2013-06-12 22:48:41 -0500 | [diff] [blame] | 1157 | |
| 1158 | struct smb_version_values smb302_values = { |
| 1159 | .version_string = SMB302_VERSION_STRING, |
| 1160 | .protocol_id = SMB302_PROT_ID, |
| 1161 | .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU, |
| 1162 | .large_lock_type = 0, |
| 1163 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 1164 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 1165 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
| 1166 | .header_size = sizeof(struct smb2_hdr), |
| 1167 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 1168 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 1169 | .lock_cmd = SMB2_LOCK, |
| 1170 | .cap_unix = 0, |
| 1171 | .cap_nt_find = SMB2_NT_FIND, |
| 1172 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 5028588 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 1173 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 1174 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1175 | .create_lease_size = sizeof(struct create_lease_v2), |
Steve French | 20b6d8b | 2013-06-12 22:48:41 -0500 | [diff] [blame] | 1176 | }; |