Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/cifs/transport.c |
| 3 | * |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4 | * Copyright (C) International Business Machines Corp., 2002,2008 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Author(s): Steve French (sfrench@us.ibm.com) |
Steve French | 14a441a2b | 2006-07-16 04:32:51 +0000 | [diff] [blame] | 6 | * Jeremy Allison (jra@samba.org) 2006. |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 7 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * This library is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU Lesser General Public License as published |
| 10 | * by the Free Software Foundation; either version 2.1 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This library is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 16 | * the GNU Lesser General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Lesser General Public License |
| 19 | * along with this library; if not, write to the Free Software |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | #include <linux/fs.h> |
| 24 | #include <linux/list.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 25 | #include <linux/gfp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/wait.h> |
| 27 | #include <linux/net.h> |
| 28 | #include <linux/delay.h> |
Jeff Layton | f06ac72 | 2011-10-19 15:30:40 -0400 | [diff] [blame] | 29 | #include <linux/freezer.h> |
Jeff Layton | b8eed28 | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 30 | #include <linux/tcp.h> |
Christoph Hellwig | 2f8b544 | 2016-11-01 07:40:13 -0600 | [diff] [blame] | 31 | #include <linux/bvec.h> |
Jeff Layton | 97bc00b | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 32 | #include <linux/highmem.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 33 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <asm/processor.h> |
| 35 | #include <linux/mempool.h> |
| 36 | #include "cifspdu.h" |
| 37 | #include "cifsglob.h" |
| 38 | #include "cifsproto.h" |
| 39 | #include "cifs_debug.h" |
Aurelien Aptel | 8bd68c6 | 2018-02-16 19:19:29 +0100 | [diff] [blame] | 40 | #include "smb2proto.h" |
Long Li | 9762c2d | 2017-11-22 17:38:43 -0700 | [diff] [blame] | 41 | #include "smbdirect.h" |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 42 | |
Ronnie Sahlberg | 3cecf48 | 2017-11-21 15:08:07 +1100 | [diff] [blame] | 43 | /* Max number of iovectors we can use off the stack when sending requests. */ |
| 44 | #define CIFS_MAX_IOV_SIZE 8 |
| 45 | |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 46 | void |
| 47 | cifs_wake_up_task(struct mid_q_entry *mid) |
Jeff Layton | 2b84a36c | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 48 | { |
| 49 | wake_up_process(mid->callback_data); |
| 50 | } |
| 51 | |
Jeff Layton | a6827c1 | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 52 | struct mid_q_entry * |
Jeff Layton | 24b9b06 | 2008-12-01 07:09:34 -0500 | [diff] [blame] | 53 | AllocMidQEntry(const struct smb_hdr *smb_buffer, struct TCP_Server_Info *server) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | { |
| 55 | struct mid_q_entry *temp; |
| 56 | |
Jeff Layton | 24b9b06 | 2008-12-01 07:09:34 -0500 | [diff] [blame] | 57 | if (server == NULL) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 58 | cifs_dbg(VFS, "Null TCP session in AllocMidQEntry\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | return NULL; |
| 60 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 61 | |
Pekka Enberg | 232087c | 2008-09-15 13:22:54 +0300 | [diff] [blame] | 62 | temp = mempool_alloc(cifs_mid_poolp, GFP_NOFS); |
NeilBrown | a6f74e8 | 2017-04-10 12:08:53 +1000 | [diff] [blame] | 63 | memset(temp, 0, sizeof(struct mid_q_entry)); |
Lars Persson | 696e420 | 2018-06-25 14:05:25 +0200 | [diff] [blame] | 64 | kref_init(&temp->refcount); |
NeilBrown | a6f74e8 | 2017-04-10 12:08:53 +1000 | [diff] [blame] | 65 | temp->mid = get_mid(smb_buffer); |
| 66 | temp->pid = current->pid; |
| 67 | temp->command = cpu_to_le16(smb_buffer->Command); |
| 68 | cifs_dbg(FYI, "For smb_command %d\n", smb_buffer->Command); |
Steve French | 1047abc | 2005-10-11 19:58:06 -0700 | [diff] [blame] | 69 | /* do_gettimeofday(&temp->when_sent);*/ /* easier to use jiffies */ |
NeilBrown | a6f74e8 | 2017-04-10 12:08:53 +1000 | [diff] [blame] | 70 | /* when mid allocated can be before when sent */ |
| 71 | temp->when_alloc = jiffies; |
| 72 | temp->server = server; |
Jeff Layton | 2b84a36c | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 73 | |
NeilBrown | a6f74e8 | 2017-04-10 12:08:53 +1000 | [diff] [blame] | 74 | /* |
| 75 | * The default is for the mid to be synchronous, so the |
| 76 | * default callback just wakes up the current task. |
| 77 | */ |
| 78 | temp->callback = cifs_wake_up_task; |
| 79 | temp->callback_data = current; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | atomic_inc(&midCount); |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 82 | temp->mid_state = MID_REQUEST_ALLOCATED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | return temp; |
| 84 | } |
| 85 | |
Lars Persson | 696e420 | 2018-06-25 14:05:25 +0200 | [diff] [blame] | 86 | static void _cifs_mid_q_entry_release(struct kref *refcount) |
| 87 | { |
| 88 | struct mid_q_entry *mid = container_of(refcount, struct mid_q_entry, |
| 89 | refcount); |
| 90 | |
| 91 | mempool_free(mid, cifs_mid_poolp); |
| 92 | } |
| 93 | |
| 94 | void cifs_mid_q_entry_release(struct mid_q_entry *midEntry) |
| 95 | { |
| 96 | spin_lock(&GlobalMid_Lock); |
| 97 | kref_put(&midEntry->refcount, _cifs_mid_q_entry_release); |
| 98 | spin_unlock(&GlobalMid_Lock); |
| 99 | } |
| 100 | |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 101 | void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | DeleteMidQEntry(struct mid_q_entry *midEntry) |
| 103 | { |
Steve French | 1047abc | 2005-10-11 19:58:06 -0700 | [diff] [blame] | 104 | #ifdef CONFIG_CIFS_STATS2 |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 105 | __le16 command = midEntry->server->vals->lock_cmd; |
Steve French | 1047abc | 2005-10-11 19:58:06 -0700 | [diff] [blame] | 106 | unsigned long now; |
| 107 | #endif |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 108 | midEntry->mid_state = MID_FREE; |
Jeff Layton | 8097531 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 109 | atomic_dec(&midCount); |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 110 | if (midEntry->large_buf) |
Steve French | b8643e1 | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 111 | cifs_buf_release(midEntry->resp_buf); |
| 112 | else |
| 113 | cifs_small_buf_release(midEntry->resp_buf); |
Steve French | 1047abc | 2005-10-11 19:58:06 -0700 | [diff] [blame] | 114 | #ifdef CONFIG_CIFS_STATS2 |
| 115 | now = jiffies; |
Steve French | 00778e2 | 2018-09-18 14:05:18 -0500 | [diff] [blame] | 116 | /* |
| 117 | * commands taking longer than one second (default) can be indications |
| 118 | * that something is wrong, unless it is quite a slow link or a very |
| 119 | * busy server. Note that this calc is unlikely or impossible to wrap |
| 120 | * as long as slow_rsp_threshold is not set way above recommended max |
| 121 | * value (32767 ie 9 hours) and is generally harmless even if wrong |
| 122 | * since only affects debug counters - so leaving the calc as simple |
| 123 | * comparison rather than doing multiple conversions and overflow |
| 124 | * checks |
| 125 | */ |
| 126 | if ((slow_rsp_threshold != 0) && |
| 127 | time_after(now, midEntry->when_alloc + (slow_rsp_threshold * HZ)) && |
Steve French | 020eec5 | 2018-08-01 16:38:07 -0500 | [diff] [blame] | 128 | (midEntry->command != command)) { |
Steve French | f5942db | 2018-11-14 01:37:39 -0600 | [diff] [blame] | 129 | /* |
| 130 | * smb2slowcmd[NUMBER_OF_SMB2_COMMANDS] counts by command |
| 131 | * NB: le16_to_cpu returns unsigned so can not be negative below |
| 132 | */ |
| 133 | if (le16_to_cpu(midEntry->command) < NUMBER_OF_SMB2_COMMANDS) |
Steve French | 468d677 | 2018-08-04 05:24:34 -0500 | [diff] [blame] | 134 | cifs_stats_inc(&midEntry->server->smb2slowcmd[le16_to_cpu(midEntry->command)]); |
| 135 | |
Steve French | 020eec5 | 2018-08-01 16:38:07 -0500 | [diff] [blame] | 136 | trace_smb3_slow_rsp(le16_to_cpu(midEntry->command), |
| 137 | midEntry->mid, midEntry->pid, |
| 138 | midEntry->when_sent, midEntry->when_received); |
| 139 | if (cifsFYI & CIFS_TIMER) { |
Andy Shevchenko | 0b456f0 | 2014-08-27 16:49:44 +0300 | [diff] [blame] | 140 | pr_debug(" CIFS slow rsp: cmd %d mid %llu", |
Steve French | 1047abc | 2005-10-11 19:58:06 -0700 | [diff] [blame] | 141 | midEntry->command, midEntry->mid); |
Rodrigo Freire | f80eaed | 2018-10-07 12:21:26 -0300 | [diff] [blame] | 142 | cifs_info(" A: 0x%lx S: 0x%lx R: 0x%lx\n", |
Steve French | 1047abc | 2005-10-11 19:58:06 -0700 | [diff] [blame] | 143 | now - midEntry->when_alloc, |
| 144 | now - midEntry->when_sent, |
| 145 | now - midEntry->when_received); |
| 146 | } |
| 147 | } |
| 148 | #endif |
Lars Persson | 696e420 | 2018-06-25 14:05:25 +0200 | [diff] [blame] | 149 | cifs_mid_q_entry_release(midEntry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | } |
| 151 | |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 152 | void |
| 153 | cifs_delete_mid(struct mid_q_entry *mid) |
Jeff Layton | ddc8cf8 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 154 | { |
| 155 | spin_lock(&GlobalMid_Lock); |
Ronnie Sahlberg | ddf83af | 2018-08-30 10:12:59 +1000 | [diff] [blame] | 156 | list_del_init(&mid->qhead); |
| 157 | mid->mid_flags |= MID_DELETED; |
Jeff Layton | ddc8cf8 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 158 | spin_unlock(&GlobalMid_Lock); |
| 159 | |
| 160 | DeleteMidQEntry(mid); |
| 161 | } |
| 162 | |
Jeff Layton | 6f49f46 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 163 | /* |
| 164 | * smb_send_kvec - send an array of kvecs to the server |
| 165 | * @server: Server to send the data to |
Al Viro | 3ab3f2a | 2015-11-13 02:36:04 -0500 | [diff] [blame] | 166 | * @smb_msg: Message to send |
Jeff Layton | 6f49f46 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 167 | * @sent: amount of data sent on socket is stored here |
| 168 | * |
| 169 | * Our basic "send data to server" function. Should be called with srv_mutex |
| 170 | * held. The caller is responsible for handling the results. |
| 171 | */ |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 172 | static int |
Al Viro | 3ab3f2a | 2015-11-13 02:36:04 -0500 | [diff] [blame] | 173 | smb_send_kvec(struct TCP_Server_Info *server, struct msghdr *smb_msg, |
| 174 | size_t *sent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | { |
| 176 | int rc = 0; |
Al Viro | 3ab3f2a | 2015-11-13 02:36:04 -0500 | [diff] [blame] | 177 | int retries = 0; |
Steve French | edf1ae4 | 2008-10-29 00:47:57 +0000 | [diff] [blame] | 178 | struct socket *ssocket = server->ssocket; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 179 | |
Jeff Layton | 6f49f46 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 180 | *sent = 0; |
| 181 | |
Al Viro | 3ab3f2a | 2015-11-13 02:36:04 -0500 | [diff] [blame] | 182 | smb_msg->msg_name = (struct sockaddr *) &server->dstaddr; |
| 183 | smb_msg->msg_namelen = sizeof(struct sockaddr); |
| 184 | smb_msg->msg_control = NULL; |
| 185 | smb_msg->msg_controllen = 0; |
Jeff Layton | 0496e02 | 2008-12-30 12:39:16 -0500 | [diff] [blame] | 186 | if (server->noblocksnd) |
Al Viro | 3ab3f2a | 2015-11-13 02:36:04 -0500 | [diff] [blame] | 187 | smb_msg->msg_flags = MSG_DONTWAIT + MSG_NOSIGNAL; |
Steve French | edf1ae4 | 2008-10-29 00:47:57 +0000 | [diff] [blame] | 188 | else |
Al Viro | 3ab3f2a | 2015-11-13 02:36:04 -0500 | [diff] [blame] | 189 | smb_msg->msg_flags = MSG_NOSIGNAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
Al Viro | 3ab3f2a | 2015-11-13 02:36:04 -0500 | [diff] [blame] | 191 | while (msg_data_left(smb_msg)) { |
Jeff Layton | 6f49f46 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 192 | /* |
| 193 | * If blocking send, we try 3 times, since each can block |
| 194 | * for 5 seconds. For nonblocking we have to try more |
| 195 | * but wait increasing amounts of time allowing time for |
| 196 | * socket to clear. The overall time we wait in either |
| 197 | * case to send on the socket is about 15 seconds. |
| 198 | * Similarly we wait for 15 seconds for a response from |
| 199 | * the server in SendReceive[2] for the server to send |
| 200 | * a response back for most types of requests (except |
| 201 | * SMB Write past end of file which can be slow, and |
| 202 | * blocking lock operations). NFS waits slightly longer |
| 203 | * than CIFS, but this can make it take longer for |
| 204 | * nonresponsive servers to be detected and 15 seconds |
| 205 | * is more than enough time for modern networks to |
| 206 | * send a packet. In most cases if we fail to send |
| 207 | * after the retries we will kill the socket and |
| 208 | * reconnect which may clear the network problem. |
| 209 | */ |
Al Viro | 3ab3f2a | 2015-11-13 02:36:04 -0500 | [diff] [blame] | 210 | rc = sock_sendmsg(ssocket, smb_msg); |
Jeff Layton | ce6c44e | 2013-03-22 08:36:45 -0400 | [diff] [blame] | 211 | if (rc == -EAGAIN) { |
Al Viro | 3ab3f2a | 2015-11-13 02:36:04 -0500 | [diff] [blame] | 212 | retries++; |
| 213 | if (retries >= 14 || |
| 214 | (!server->noblocksnd && (retries > 2))) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 215 | cifs_dbg(VFS, "sends on sock %p stuck for 15 seconds\n", |
| 216 | ssocket); |
Al Viro | 3ab3f2a | 2015-11-13 02:36:04 -0500 | [diff] [blame] | 217 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | } |
Al Viro | 3ab3f2a | 2015-11-13 02:36:04 -0500 | [diff] [blame] | 219 | msleep(1 << retries); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | continue; |
| 221 | } |
Jeff Layton | 6f49f46 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 222 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 223 | if (rc < 0) |
Al Viro | 3ab3f2a | 2015-11-13 02:36:04 -0500 | [diff] [blame] | 224 | return rc; |
Jeff Layton | 6f49f46 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 225 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 226 | if (rc == 0) { |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 227 | /* should never happen, letting socket clear before |
| 228 | retrying is our only obvious option here */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 229 | cifs_dbg(VFS, "tcp sent no data\n"); |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 230 | msleep(500); |
| 231 | continue; |
| 232 | } |
Jeff Layton | 6f49f46 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 233 | |
Al Viro | 3ab3f2a | 2015-11-13 02:36:04 -0500 | [diff] [blame] | 234 | /* send was at least partially successful */ |
| 235 | *sent += rc; |
| 236 | retries = 0; /* in case we get ENOSPC on the next send */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | } |
Al Viro | 3ab3f2a | 2015-11-13 02:36:04 -0500 | [diff] [blame] | 238 | return 0; |
Jeff Layton | 97bc00b | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Paulo Alcantara | 35e2cc1 | 2018-06-15 10:22:44 -0300 | [diff] [blame] | 241 | unsigned long |
Ronnie Sahlberg | 81f39f9 | 2018-06-28 10:47:14 +1000 | [diff] [blame] | 242 | smb_rqst_len(struct TCP_Server_Info *server, struct smb_rqst *rqst) |
Jeff Layton | a26054d | 2014-02-14 07:21:00 -0500 | [diff] [blame] | 243 | { |
| 244 | unsigned int i; |
Paulo Alcantara | 35e2cc1 | 2018-06-15 10:22:44 -0300 | [diff] [blame] | 245 | struct kvec *iov; |
| 246 | int nvec; |
Jeff Layton | a26054d | 2014-02-14 07:21:00 -0500 | [diff] [blame] | 247 | unsigned long buflen = 0; |
| 248 | |
Ronnie Sahlberg | 81f39f9 | 2018-06-28 10:47:14 +1000 | [diff] [blame] | 249 | if (server->vals->header_preamble_size == 0 && |
| 250 | rqst->rq_nvec >= 2 && rqst->rq_iov[0].iov_len == 4) { |
Paulo Alcantara | 35e2cc1 | 2018-06-15 10:22:44 -0300 | [diff] [blame] | 251 | iov = &rqst->rq_iov[1]; |
| 252 | nvec = rqst->rq_nvec - 1; |
| 253 | } else { |
| 254 | iov = rqst->rq_iov; |
| 255 | nvec = rqst->rq_nvec; |
| 256 | } |
| 257 | |
Jeff Layton | a26054d | 2014-02-14 07:21:00 -0500 | [diff] [blame] | 258 | /* total up iov array first */ |
Paulo Alcantara | 35e2cc1 | 2018-06-15 10:22:44 -0300 | [diff] [blame] | 259 | for (i = 0; i < nvec; i++) |
Jeff Layton | a26054d | 2014-02-14 07:21:00 -0500 | [diff] [blame] | 260 | buflen += iov[i].iov_len; |
| 261 | |
Long Li | c06a0f2 | 2018-05-30 12:47:57 -0700 | [diff] [blame] | 262 | /* |
| 263 | * Add in the page array if there is one. The caller needs to make |
| 264 | * sure rq_offset and rq_tailsz are set correctly. If a buffer of |
| 265 | * multiple pages ends at page boundary, rq_tailsz needs to be set to |
| 266 | * PAGE_SIZE. |
| 267 | */ |
Jeff Layton | a26054d | 2014-02-14 07:21:00 -0500 | [diff] [blame] | 268 | if (rqst->rq_npages) { |
Long Li | c06a0f2 | 2018-05-30 12:47:57 -0700 | [diff] [blame] | 269 | if (rqst->rq_npages == 1) |
| 270 | buflen += rqst->rq_tailsz; |
| 271 | else { |
| 272 | /* |
| 273 | * If there is more than one page, calculate the |
| 274 | * buffer length based on rq_offset and rq_tailsz |
| 275 | */ |
| 276 | buflen += rqst->rq_pagesz * (rqst->rq_npages - 1) - |
| 277 | rqst->rq_offset; |
| 278 | buflen += rqst->rq_tailsz; |
| 279 | } |
Jeff Layton | a26054d | 2014-02-14 07:21:00 -0500 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | return buflen; |
| 283 | } |
| 284 | |
Jeff Layton | 6f49f46 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 285 | static int |
Ronnie Sahlberg | 07cd952 | 2018-06-12 08:01:00 +1000 | [diff] [blame] | 286 | __smb_send_rqst(struct TCP_Server_Info *server, int num_rqst, |
| 287 | struct smb_rqst *rqst) |
Jeff Layton | 6f49f46 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 288 | { |
Ronnie Sahlberg | 07cd952 | 2018-06-12 08:01:00 +1000 | [diff] [blame] | 289 | int rc = 0; |
| 290 | struct kvec *iov; |
| 291 | int n_vec; |
| 292 | unsigned int send_length = 0; |
| 293 | unsigned int i, j; |
Al Viro | 3ab3f2a | 2015-11-13 02:36:04 -0500 | [diff] [blame] | 294 | size_t total_len = 0, sent, size; |
Jeff Layton | b8eed28 | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 295 | struct socket *ssocket = server->ssocket; |
Al Viro | 3ab3f2a | 2015-11-13 02:36:04 -0500 | [diff] [blame] | 296 | struct msghdr smb_msg; |
Jeff Layton | b8eed28 | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 297 | int val = 1; |
Ronnie Sahlberg | c713c87 | 2018-06-12 08:00:58 +1000 | [diff] [blame] | 298 | __be32 rfc1002_marker; |
| 299 | |
Long Li | 9762c2d | 2017-11-22 17:38:43 -0700 | [diff] [blame] | 300 | if (cifs_rdma_enabled(server) && server->smbd_conn) { |
Ronnie Sahlberg | 81f39f9 | 2018-06-28 10:47:14 +1000 | [diff] [blame] | 301 | rc = smbd_send(server, rqst); |
Long Li | 9762c2d | 2017-11-22 17:38:43 -0700 | [diff] [blame] | 302 | goto smbd_done; |
| 303 | } |
Jeff Layton | ea702b8 | 2012-12-27 07:28:55 -0500 | [diff] [blame] | 304 | if (ssocket == NULL) |
| 305 | return -ENOTSOCK; |
| 306 | |
Jeff Layton | b8eed28 | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 307 | /* cork the socket */ |
| 308 | kernel_setsockopt(ssocket, SOL_TCP, TCP_CORK, |
| 309 | (char *)&val, sizeof(val)); |
| 310 | |
Ronnie Sahlberg | 07cd952 | 2018-06-12 08:01:00 +1000 | [diff] [blame] | 311 | for (j = 0; j < num_rqst; j++) |
Ronnie Sahlberg | 81f39f9 | 2018-06-28 10:47:14 +1000 | [diff] [blame] | 312 | send_length += smb_rqst_len(server, &rqst[j]); |
Ronnie Sahlberg | 07cd952 | 2018-06-12 08:01:00 +1000 | [diff] [blame] | 313 | rfc1002_marker = cpu_to_be32(send_length); |
| 314 | |
Ronnie Sahlberg | c713c87 | 2018-06-12 08:00:58 +1000 | [diff] [blame] | 315 | /* Generate a rfc1002 marker for SMB2+ */ |
| 316 | if (server->vals->header_preamble_size == 0) { |
| 317 | struct kvec hiov = { |
| 318 | .iov_base = &rfc1002_marker, |
| 319 | .iov_len = 4 |
| 320 | }; |
David Howells | aa563d7 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 321 | iov_iter_kvec(&smb_msg.msg_iter, WRITE, &hiov, 1, 4); |
Ronnie Sahlberg | c713c87 | 2018-06-12 08:00:58 +1000 | [diff] [blame] | 322 | rc = smb_send_kvec(server, &smb_msg, &sent); |
| 323 | if (rc < 0) |
| 324 | goto uncork; |
| 325 | |
| 326 | total_len += sent; |
| 327 | send_length += 4; |
| 328 | } |
| 329 | |
Paulo Alcantara | 662bf5b | 2018-06-14 17:34:08 -0300 | [diff] [blame] | 330 | cifs_dbg(FYI, "Sending smb: smb_len=%u\n", send_length); |
| 331 | |
Ronnie Sahlberg | 07cd952 | 2018-06-12 08:01:00 +1000 | [diff] [blame] | 332 | for (j = 0; j < num_rqst; j++) { |
| 333 | iov = rqst[j].rq_iov; |
| 334 | n_vec = rqst[j].rq_nvec; |
Ronnie Sahlberg | c713c87 | 2018-06-12 08:00:58 +1000 | [diff] [blame] | 335 | |
Ronnie Sahlberg | 07cd952 | 2018-06-12 08:01:00 +1000 | [diff] [blame] | 336 | size = 0; |
Paulo Alcantara | 662bf5b | 2018-06-14 17:34:08 -0300 | [diff] [blame] | 337 | for (i = 0; i < n_vec; i++) { |
| 338 | dump_smb(iov[i].iov_base, iov[i].iov_len); |
Ronnie Sahlberg | 07cd952 | 2018-06-12 08:01:00 +1000 | [diff] [blame] | 339 | size += iov[i].iov_len; |
Paulo Alcantara | 662bf5b | 2018-06-14 17:34:08 -0300 | [diff] [blame] | 340 | } |
Al Viro | 3ab3f2a | 2015-11-13 02:36:04 -0500 | [diff] [blame] | 341 | |
David Howells | aa563d7 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 342 | iov_iter_kvec(&smb_msg.msg_iter, WRITE, iov, n_vec, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | |
Al Viro | 3ab3f2a | 2015-11-13 02:36:04 -0500 | [diff] [blame] | 344 | rc = smb_send_kvec(server, &smb_msg, &sent); |
Jeff Layton | 97bc00b | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 345 | if (rc < 0) |
Ronnie Sahlberg | 07cd952 | 2018-06-12 08:01:00 +1000 | [diff] [blame] | 346 | goto uncork; |
Jeff Layton | 97bc00b | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 347 | |
| 348 | total_len += sent; |
Ronnie Sahlberg | 07cd952 | 2018-06-12 08:01:00 +1000 | [diff] [blame] | 349 | |
| 350 | /* now walk the page array and send each page in it */ |
| 351 | for (i = 0; i < rqst[j].rq_npages; i++) { |
| 352 | struct bio_vec bvec; |
| 353 | |
| 354 | bvec.bv_page = rqst[j].rq_pages[i]; |
| 355 | rqst_page_get_length(&rqst[j], i, &bvec.bv_len, |
| 356 | &bvec.bv_offset); |
| 357 | |
David Howells | aa563d7 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 358 | iov_iter_bvec(&smb_msg.msg_iter, WRITE, |
Ronnie Sahlberg | 07cd952 | 2018-06-12 08:01:00 +1000 | [diff] [blame] | 359 | &bvec, 1, bvec.bv_len); |
| 360 | rc = smb_send_kvec(server, &smb_msg, &sent); |
| 361 | if (rc < 0) |
| 362 | break; |
| 363 | |
| 364 | total_len += sent; |
| 365 | } |
Jeff Layton | 97bc00b | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | uncork: |
Jeff Layton | b8eed28 | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 369 | /* uncork it */ |
| 370 | val = 0; |
| 371 | kernel_setsockopt(ssocket, SOL_TCP, TCP_CORK, |
| 372 | (char *)&val, sizeof(val)); |
| 373 | |
Ronnie Sahlberg | c713c87 | 2018-06-12 08:00:58 +1000 | [diff] [blame] | 374 | if ((total_len > 0) && (total_len != send_length)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 375 | cifs_dbg(FYI, "partial send (wanted=%u sent=%zu): terminating session\n", |
Ronnie Sahlberg | c713c87 | 2018-06-12 08:00:58 +1000 | [diff] [blame] | 376 | send_length, total_len); |
Jeff Layton | 6f49f46 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 377 | /* |
| 378 | * If we have only sent part of an SMB then the next SMB could |
| 379 | * be taken as the remainder of this one. We need to kill the |
| 380 | * socket so the server throws away the partial SMB |
| 381 | */ |
Steve French | edf1ae4 | 2008-10-29 00:47:57 +0000 | [diff] [blame] | 382 | server->tcpStatus = CifsNeedReconnect; |
Steve French | bf1fdeb | 2018-07-30 19:23:09 -0500 | [diff] [blame] | 383 | trace_smb3_partial_send_reconnect(server->CurrentMid, |
| 384 | server->hostname); |
Steve French | edf1ae4 | 2008-10-29 00:47:57 +0000 | [diff] [blame] | 385 | } |
Long Li | 9762c2d | 2017-11-22 17:38:43 -0700 | [diff] [blame] | 386 | smbd_done: |
Jeff Layton | d804d41 | 2011-01-28 15:05:43 -0500 | [diff] [blame] | 387 | if (rc < 0 && rc != -EINTR) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 388 | cifs_dbg(VFS, "Error %d sending data on socket to server\n", |
| 389 | rc); |
Jeff Layton | d804d41 | 2011-01-28 15:05:43 -0500 | [diff] [blame] | 390 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | |
| 393 | return rc; |
| 394 | } |
| 395 | |
Jeff Layton | 6f49f46 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 396 | static int |
Ronnie Sahlberg | 1f3a8f5 | 2018-08-01 09:26:12 +1000 | [diff] [blame] | 397 | smb_send_rqst(struct TCP_Server_Info *server, int num_rqst, |
| 398 | struct smb_rqst *rqst, int flags) |
Jeff Layton | 6f49f46 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 399 | { |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 400 | struct kvec iov; |
| 401 | struct smb2_transform_hdr tr_hdr; |
| 402 | struct smb_rqst cur_rqst[MAX_COMPOUND]; |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 403 | int rc; |
Jeff Layton | 6f49f46 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 404 | |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 405 | if (!(flags & CIFS_TRANSFORM_REQ)) |
Ronnie Sahlberg | 1f3a8f5 | 2018-08-01 09:26:12 +1000 | [diff] [blame] | 406 | return __smb_send_rqst(server, num_rqst, rqst); |
| 407 | |
| 408 | if (num_rqst > MAX_COMPOUND - 1) |
| 409 | return -ENOMEM; |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 410 | |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 411 | memset(&cur_rqst[0], 0, sizeof(cur_rqst)); |
| 412 | memset(&iov, 0, sizeof(iov)); |
| 413 | memset(&tr_hdr, 0, sizeof(tr_hdr)); |
| 414 | |
| 415 | iov.iov_base = &tr_hdr; |
| 416 | iov.iov_len = sizeof(tr_hdr); |
| 417 | cur_rqst[0].rq_iov = &iov; |
| 418 | cur_rqst[0].rq_nvec = 1; |
| 419 | |
| 420 | if (!server->ops->init_transform_rq) { |
| 421 | cifs_dbg(VFS, "Encryption requested but transform callback " |
| 422 | "is missing\n"); |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 423 | return -EIO; |
| 424 | } |
| 425 | |
Ronnie Sahlberg | 1f3a8f5 | 2018-08-01 09:26:12 +1000 | [diff] [blame] | 426 | rc = server->ops->init_transform_rq(server, num_rqst + 1, |
| 427 | &cur_rqst[0], rqst); |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 428 | if (rc) |
| 429 | return rc; |
| 430 | |
Ronnie Sahlberg | 1f3a8f5 | 2018-08-01 09:26:12 +1000 | [diff] [blame] | 431 | rc = __smb_send_rqst(server, num_rqst + 1, &cur_rqst[0]); |
| 432 | smb3_free_compound_rqst(num_rqst, &cur_rqst[1]); |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 433 | return rc; |
Jeff Layton | 6f49f46 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 434 | } |
| 435 | |
Jeff Layton | 0496e02 | 2008-12-30 12:39:16 -0500 | [diff] [blame] | 436 | int |
| 437 | smb_send(struct TCP_Server_Info *server, struct smb_hdr *smb_buffer, |
| 438 | unsigned int smb_buf_length) |
| 439 | { |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 440 | struct kvec iov[2]; |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 441 | struct smb_rqst rqst = { .rq_iov = iov, |
| 442 | .rq_nvec = 2 }; |
Jeff Layton | 0496e02 | 2008-12-30 12:39:16 -0500 | [diff] [blame] | 443 | |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 444 | iov[0].iov_base = smb_buffer; |
| 445 | iov[0].iov_len = 4; |
| 446 | iov[1].iov_base = (char *)smb_buffer + 4; |
| 447 | iov[1].iov_len = smb_buf_length; |
Jeff Layton | 0496e02 | 2008-12-30 12:39:16 -0500 | [diff] [blame] | 448 | |
Ronnie Sahlberg | 07cd952 | 2018-06-12 08:01:00 +1000 | [diff] [blame] | 449 | return __smb_send_rqst(server, 1, &rqst); |
Jeff Layton | 0496e02 | 2008-12-30 12:39:16 -0500 | [diff] [blame] | 450 | } |
| 451 | |
Pavel Shilovsky | fc40f9c | 2012-02-17 17:09:12 +0300 | [diff] [blame] | 452 | static int |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 453 | wait_for_free_credits(struct TCP_Server_Info *server, const int timeout, |
Pavel Shilovsky | bc205ed | 2012-03-15 13:22:27 +0300 | [diff] [blame] | 454 | int *credits) |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 455 | { |
Pavel Shilovsky | 5bc5949 | 2012-02-21 19:56:08 +0300 | [diff] [blame] | 456 | int rc; |
| 457 | |
Pavel Shilovsky | fc40f9c | 2012-02-17 17:09:12 +0300 | [diff] [blame] | 458 | spin_lock(&server->req_lock); |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 459 | if (timeout == CIFS_ASYNC_OP) { |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 460 | /* oplock breaks must not be held up */ |
Pavel Shilovsky | fc40f9c | 2012-02-17 17:09:12 +0300 | [diff] [blame] | 461 | server->in_flight++; |
Pavel Shilovsky | bc205ed | 2012-03-15 13:22:27 +0300 | [diff] [blame] | 462 | *credits -= 1; |
Pavel Shilovsky | fc40f9c | 2012-02-17 17:09:12 +0300 | [diff] [blame] | 463 | spin_unlock(&server->req_lock); |
Volker Lendecke | 27a97a6 | 2008-12-08 20:59:39 +0000 | [diff] [blame] | 464 | return 0; |
| 465 | } |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 466 | |
Volker Lendecke | 27a97a6 | 2008-12-08 20:59:39 +0000 | [diff] [blame] | 467 | while (1) { |
Pavel Shilovsky | bc205ed | 2012-03-15 13:22:27 +0300 | [diff] [blame] | 468 | if (*credits <= 0) { |
Pavel Shilovsky | fc40f9c | 2012-02-17 17:09:12 +0300 | [diff] [blame] | 469 | spin_unlock(&server->req_lock); |
Steve French | 789e666 | 2011-08-09 18:44:44 +0000 | [diff] [blame] | 470 | cifs_num_waiters_inc(server); |
Pavel Shilovsky | 5bc5949 | 2012-02-21 19:56:08 +0300 | [diff] [blame] | 471 | rc = wait_event_killable(server->request_q, |
Pavel Shilovsky | bc205ed | 2012-03-15 13:22:27 +0300 | [diff] [blame] | 472 | has_credits(server, credits)); |
Steve French | 789e666 | 2011-08-09 18:44:44 +0000 | [diff] [blame] | 473 | cifs_num_waiters_dec(server); |
Pavel Shilovsky | 5bc5949 | 2012-02-21 19:56:08 +0300 | [diff] [blame] | 474 | if (rc) |
| 475 | return rc; |
Pavel Shilovsky | fc40f9c | 2012-02-17 17:09:12 +0300 | [diff] [blame] | 476 | spin_lock(&server->req_lock); |
Volker Lendecke | 27a97a6 | 2008-12-08 20:59:39 +0000 | [diff] [blame] | 477 | } else { |
Jeff Layton | c5797a9 | 2011-01-11 07:24:01 -0500 | [diff] [blame] | 478 | if (server->tcpStatus == CifsExiting) { |
Pavel Shilovsky | fc40f9c | 2012-02-17 17:09:12 +0300 | [diff] [blame] | 479 | spin_unlock(&server->req_lock); |
Volker Lendecke | 27a97a6 | 2008-12-08 20:59:39 +0000 | [diff] [blame] | 480 | return -ENOENT; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 481 | } |
Volker Lendecke | 27a97a6 | 2008-12-08 20:59:39 +0000 | [diff] [blame] | 482 | |
Pavel Shilovsky | 2d86dbc | 2012-02-06 15:59:18 +0400 | [diff] [blame] | 483 | /* |
| 484 | * Can not count locking commands against total |
| 485 | * as they are allowed to block on server. |
| 486 | */ |
Volker Lendecke | 27a97a6 | 2008-12-08 20:59:39 +0000 | [diff] [blame] | 487 | |
| 488 | /* update # of requests on the wire to server */ |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 489 | if (timeout != CIFS_BLOCKING_OP) { |
Pavel Shilovsky | bc205ed | 2012-03-15 13:22:27 +0300 | [diff] [blame] | 490 | *credits -= 1; |
Pavel Shilovsky | fc40f9c | 2012-02-17 17:09:12 +0300 | [diff] [blame] | 491 | server->in_flight++; |
Pavel Shilovsky | 2d86dbc | 2012-02-06 15:59:18 +0400 | [diff] [blame] | 492 | } |
Pavel Shilovsky | fc40f9c | 2012-02-17 17:09:12 +0300 | [diff] [blame] | 493 | spin_unlock(&server->req_lock); |
Volker Lendecke | 27a97a6 | 2008-12-08 20:59:39 +0000 | [diff] [blame] | 494 | break; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 495 | } |
| 496 | } |
| 497 | return 0; |
| 498 | } |
| 499 | |
Pavel Shilovsky | bc205ed | 2012-03-15 13:22:27 +0300 | [diff] [blame] | 500 | static int |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 501 | wait_for_free_request(struct TCP_Server_Info *server, const int timeout, |
| 502 | const int optype) |
Pavel Shilovsky | bc205ed | 2012-03-15 13:22:27 +0300 | [diff] [blame] | 503 | { |
Shirish Pargaonkar | eb4c7df | 2013-10-03 05:44:45 -0500 | [diff] [blame] | 504 | int *val; |
| 505 | |
| 506 | val = server->ops->get_credits_field(server, optype); |
| 507 | /* Since an echo is already inflight, no need to wait to send another */ |
| 508 | if (*val <= 0 && optype == CIFS_ECHO_OP) |
| 509 | return -EAGAIN; |
| 510 | return wait_for_free_credits(server, timeout, val); |
Pavel Shilovsky | bc205ed | 2012-03-15 13:22:27 +0300 | [diff] [blame] | 511 | } |
| 512 | |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 513 | int |
| 514 | cifs_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size, |
| 515 | unsigned int *num, unsigned int *credits) |
| 516 | { |
| 517 | *num = size; |
| 518 | *credits = 0; |
| 519 | return 0; |
| 520 | } |
| 521 | |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 522 | static int allocate_mid(struct cifs_ses *ses, struct smb_hdr *in_buf, |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 523 | struct mid_q_entry **ppmidQ) |
| 524 | { |
| 525 | if (ses->server->tcpStatus == CifsExiting) { |
| 526 | return -ENOENT; |
Volker Lendecke | 8fbbd36 | 2008-12-06 13:12:34 +0100 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | if (ses->server->tcpStatus == CifsNeedReconnect) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 530 | cifs_dbg(FYI, "tcp session dead - return to caller to retry\n"); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 531 | return -EAGAIN; |
Volker Lendecke | 8fbbd36 | 2008-12-06 13:12:34 +0100 | [diff] [blame] | 532 | } |
| 533 | |
Shirish Pargaonkar | 7f48558 | 2013-10-12 10:06:03 -0500 | [diff] [blame] | 534 | if (ses->status == CifsNew) { |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 535 | if ((in_buf->Command != SMB_COM_SESSION_SETUP_ANDX) && |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 536 | (in_buf->Command != SMB_COM_NEGOTIATE)) |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 537 | return -EAGAIN; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 538 | /* else ok - we are setting up session */ |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 539 | } |
Shirish Pargaonkar | 7f48558 | 2013-10-12 10:06:03 -0500 | [diff] [blame] | 540 | |
| 541 | if (ses->status == CifsExiting) { |
| 542 | /* check if SMB session is bad because we are setting it up */ |
| 543 | if (in_buf->Command != SMB_COM_LOGOFF_ANDX) |
| 544 | return -EAGAIN; |
| 545 | /* else ok - we are shutting down session */ |
| 546 | } |
| 547 | |
Jeff Layton | 24b9b06 | 2008-12-01 07:09:34 -0500 | [diff] [blame] | 548 | *ppmidQ = AllocMidQEntry(in_buf, ses->server); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 549 | if (*ppmidQ == NULL) |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 550 | return -ENOMEM; |
Jeff Layton | ddc8cf8 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 551 | spin_lock(&GlobalMid_Lock); |
| 552 | list_add_tail(&(*ppmidQ)->qhead, &ses->server->pending_mid_q); |
| 553 | spin_unlock(&GlobalMid_Lock); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 554 | return 0; |
| 555 | } |
| 556 | |
Jeff Layton | 0ade640 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 557 | static int |
| 558 | wait_for_response(struct TCP_Server_Info *server, struct mid_q_entry *midQ) |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 559 | { |
Jeff Layton | 0ade640 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 560 | int error; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 561 | |
Colin Cross | 5853cc2 | 2013-05-07 17:52:05 +0000 | [diff] [blame] | 562 | error = wait_event_freezekillable_unsafe(server->response_q, |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 563 | midQ->mid_state != MID_REQUEST_SUBMITTED); |
Jeff Layton | 0ade640 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 564 | if (error < 0) |
| 565 | return -ERESTARTSYS; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 566 | |
Jeff Layton | 0ade640 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 567 | return 0; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 568 | } |
| 569 | |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 570 | struct mid_q_entry * |
| 571 | cifs_setup_async_request(struct TCP_Server_Info *server, struct smb_rqst *rqst) |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 572 | { |
| 573 | int rc; |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 574 | struct smb_hdr *hdr = (struct smb_hdr *)rqst->rq_iov[0].iov_base; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 575 | struct mid_q_entry *mid; |
| 576 | |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 577 | if (rqst->rq_iov[0].iov_len != 4 || |
| 578 | rqst->rq_iov[0].iov_base + 4 != rqst->rq_iov[1].iov_base) |
| 579 | return ERR_PTR(-EIO); |
| 580 | |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 581 | /* enable signing if server requires it */ |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 582 | if (server->sign) |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 583 | hdr->Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
| 584 | |
| 585 | mid = AllocMidQEntry(hdr, server); |
| 586 | if (mid == NULL) |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 587 | return ERR_PTR(-ENOMEM); |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 588 | |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 589 | rc = cifs_sign_rqst(rqst, server, &mid->sequence_number); |
Sachin Prabhu | ffc61cc | 2012-07-11 12:28:05 +0100 | [diff] [blame] | 590 | if (rc) { |
| 591 | DeleteMidQEntry(mid); |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 592 | return ERR_PTR(rc); |
Sachin Prabhu | ffc61cc | 2012-07-11 12:28:05 +0100 | [diff] [blame] | 593 | } |
| 594 | |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 595 | return mid; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 596 | } |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 597 | |
| 598 | /* |
Jeff Layton | a6827c1 | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 599 | * Send a SMB request and set the callback function in the mid to handle |
| 600 | * the result. Caller is responsible for dealing with timeouts. |
| 601 | */ |
| 602 | int |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 603 | cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst, |
Pavel Shilovsky | 9b7c18a | 2016-11-16 14:06:17 -0800 | [diff] [blame] | 604 | mid_receive_t *receive, mid_callback_t *callback, |
| 605 | mid_handle_t *handle, void *cbdata, const int flags) |
Jeff Layton | a6827c1 | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 606 | { |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 607 | int rc, timeout, optype; |
Jeff Layton | a6827c1 | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 608 | struct mid_q_entry *mid; |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 609 | unsigned int credits = 0; |
Jeff Layton | a6827c1 | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 610 | |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 611 | timeout = flags & CIFS_TIMEOUT_MASK; |
| 612 | optype = flags & CIFS_OP_MASK; |
| 613 | |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 614 | if ((flags & CIFS_HAS_CREDITS) == 0) { |
| 615 | rc = wait_for_free_request(server, timeout, optype); |
| 616 | if (rc) |
| 617 | return rc; |
| 618 | credits = 1; |
| 619 | } |
Jeff Layton | a6827c1 | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 620 | |
| 621 | mutex_lock(&server->srv_mutex); |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 622 | mid = server->ops->setup_async_request(server, rqst); |
| 623 | if (IS_ERR(mid)) { |
Jeff Layton | a6827c1 | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 624 | mutex_unlock(&server->srv_mutex); |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 625 | add_credits_and_wake_if(server, credits, optype); |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 626 | return PTR_ERR(mid); |
Jeff Layton | a6827c1 | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 627 | } |
| 628 | |
Jeff Layton | 44d22d8 | 2011-10-19 15:29:49 -0400 | [diff] [blame] | 629 | mid->receive = receive; |
Jeff Layton | a6827c1 | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 630 | mid->callback = callback; |
| 631 | mid->callback_data = cbdata; |
Pavel Shilovsky | 9b7c18a | 2016-11-16 14:06:17 -0800 | [diff] [blame] | 632 | mid->handle = handle; |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 633 | mid->mid_state = MID_REQUEST_SUBMITTED; |
Steve French | 789e666 | 2011-08-09 18:44:44 +0000 | [diff] [blame] | 634 | |
Sachin Prabhu | ffc61cc | 2012-07-11 12:28:05 +0100 | [diff] [blame] | 635 | /* put it on the pending_mid_q */ |
| 636 | spin_lock(&GlobalMid_Lock); |
| 637 | list_add_tail(&mid->qhead, &server->pending_mid_q); |
| 638 | spin_unlock(&GlobalMid_Lock); |
| 639 | |
Long Li | 93d2cb6 | 2017-06-28 15:55:55 -0700 | [diff] [blame] | 640 | /* |
| 641 | * Need to store the time in mid before calling I/O. For call_async, |
| 642 | * I/O response may come back and free the mid entry on another thread. |
| 643 | */ |
| 644 | cifs_save_when_sent(mid); |
Steve French | 789e666 | 2011-08-09 18:44:44 +0000 | [diff] [blame] | 645 | cifs_in_send_inc(server); |
Ronnie Sahlberg | 1f3a8f5 | 2018-08-01 09:26:12 +1000 | [diff] [blame] | 646 | rc = smb_send_rqst(server, 1, rqst, flags); |
Steve French | 789e666 | 2011-08-09 18:44:44 +0000 | [diff] [blame] | 647 | cifs_in_send_dec(server); |
Jeff Layton | ad313cb | 2013-04-03 10:27:36 -0400 | [diff] [blame] | 648 | |
Rabin Vincent | 820962d | 2015-12-23 07:32:41 +0100 | [diff] [blame] | 649 | if (rc < 0) { |
Jeff Layton | ad313cb | 2013-04-03 10:27:36 -0400 | [diff] [blame] | 650 | server->sequence_number -= 2; |
Rabin Vincent | 820962d | 2015-12-23 07:32:41 +0100 | [diff] [blame] | 651 | cifs_delete_mid(mid); |
| 652 | } |
| 653 | |
Jeff Layton | a6827c1 | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 654 | mutex_unlock(&server->srv_mutex); |
Steve French | 789e666 | 2011-08-09 18:44:44 +0000 | [diff] [blame] | 655 | |
Sachin Prabhu | ffc61cc | 2012-07-11 12:28:05 +0100 | [diff] [blame] | 656 | if (rc == 0) |
| 657 | return 0; |
Jeff Layton | a6827c1 | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 658 | |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 659 | add_credits_and_wake_if(server, credits, optype); |
Jeff Layton | a6827c1 | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 660 | return rc; |
| 661 | } |
| 662 | |
| 663 | /* |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 664 | * |
| 665 | * Send an SMB Request. No response info (other than return code) |
| 666 | * needs to be parsed. |
| 667 | * |
| 668 | * flags indicate the type of request buffer and how long to wait |
| 669 | * and whether to log NT STATUS code (error) before mapping it to POSIX error |
| 670 | * |
| 671 | */ |
| 672 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 673 | SendReceiveNoRsp(const unsigned int xid, struct cifs_ses *ses, |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 674 | char *in_buf, int flags) |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 675 | { |
| 676 | int rc; |
| 677 | struct kvec iov[1]; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 678 | struct kvec rsp_iov; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 679 | int resp_buf_type; |
| 680 | |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 681 | iov[0].iov_base = in_buf; |
| 682 | iov[0].iov_len = get_rfc1002_length(in_buf) + 4; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 683 | flags |= CIFS_NO_RESP; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 684 | rc = SendReceive2(xid, ses, iov, 1, &resp_buf_type, flags, &rsp_iov); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 685 | cifs_dbg(NOISY, "SendRcvNoRsp flags %d rc %d\n", flags, rc); |
Steve French | 90c81e0 | 2008-02-12 20:32:36 +0000 | [diff] [blame] | 686 | |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 687 | return rc; |
| 688 | } |
| 689 | |
Jeff Layton | 053d503 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 690 | static int |
Jeff Layton | 3c1105d | 2011-05-22 07:09:13 -0400 | [diff] [blame] | 691 | cifs_sync_mid_result(struct mid_q_entry *mid, struct TCP_Server_Info *server) |
Jeff Layton | 053d503 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 692 | { |
| 693 | int rc = 0; |
| 694 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 695 | cifs_dbg(FYI, "%s: cmd=%d mid=%llu state=%d\n", |
| 696 | __func__, le16_to_cpu(mid->command), mid->mid, mid->mid_state); |
Jeff Layton | 053d503 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 697 | |
Jeff Layton | 74dd92a | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 698 | spin_lock(&GlobalMid_Lock); |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 699 | switch (mid->mid_state) { |
Jeff Layton | 74dd92a | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 700 | case MID_RESPONSE_RECEIVED: |
Jeff Layton | 053d503 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 701 | spin_unlock(&GlobalMid_Lock); |
| 702 | return rc; |
Jeff Layton | 74dd92a | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 703 | case MID_RETRY_NEEDED: |
| 704 | rc = -EAGAIN; |
| 705 | break; |
Jeff Layton | 71823ba | 2011-02-10 08:03:50 -0500 | [diff] [blame] | 706 | case MID_RESPONSE_MALFORMED: |
| 707 | rc = -EIO; |
| 708 | break; |
Jeff Layton | 3c1105d | 2011-05-22 07:09:13 -0400 | [diff] [blame] | 709 | case MID_SHUTDOWN: |
| 710 | rc = -EHOSTDOWN; |
| 711 | break; |
Jeff Layton | 74dd92a | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 712 | default: |
Jeff Layton | 3c1105d | 2011-05-22 07:09:13 -0400 | [diff] [blame] | 713 | list_del_init(&mid->qhead); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 714 | cifs_dbg(VFS, "%s: invalid mid state mid=%llu state=%d\n", |
| 715 | __func__, mid->mid, mid->mid_state); |
Jeff Layton | 74dd92a | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 716 | rc = -EIO; |
Jeff Layton | 053d503 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 717 | } |
| 718 | spin_unlock(&GlobalMid_Lock); |
| 719 | |
Jeff Layton | 2b84a36c | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 720 | DeleteMidQEntry(mid); |
Jeff Layton | 053d503 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 721 | return rc; |
| 722 | } |
| 723 | |
Jeff Layton | 121b046 | 2012-05-15 12:21:10 -0400 | [diff] [blame] | 724 | static inline int |
Pavel Shilovsky | fb2036d | 2016-11-23 15:08:14 -0800 | [diff] [blame] | 725 | send_cancel(struct TCP_Server_Info *server, struct smb_rqst *rqst, |
| 726 | struct mid_q_entry *mid) |
Jeff Layton | 76dcc26 | 2011-01-11 07:24:24 -0500 | [diff] [blame] | 727 | { |
Jeff Layton | 121b046 | 2012-05-15 12:21:10 -0400 | [diff] [blame] | 728 | return server->ops->send_cancel ? |
Pavel Shilovsky | fb2036d | 2016-11-23 15:08:14 -0800 | [diff] [blame] | 729 | server->ops->send_cancel(server, rqst, mid) : 0; |
Jeff Layton | 76dcc26 | 2011-01-11 07:24:24 -0500 | [diff] [blame] | 730 | } |
| 731 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | int |
Jeff Layton | 2c8f981 | 2011-05-19 16:22:52 -0400 | [diff] [blame] | 733 | cifs_check_receive(struct mid_q_entry *mid, struct TCP_Server_Info *server, |
| 734 | bool log_error) |
| 735 | { |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 736 | unsigned int len = get_rfc1002_length(mid->resp_buf) + 4; |
Jeff Layton | 826a95e | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 737 | |
| 738 | dump_smb(mid->resp_buf, min_t(u32, 92, len)); |
Jeff Layton | 2c8f981 | 2011-05-19 16:22:52 -0400 | [diff] [blame] | 739 | |
| 740 | /* convert the length into a more usable form */ |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 741 | if (server->sign) { |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 742 | struct kvec iov[2]; |
Steve French | 985e4ff0 | 2012-08-03 09:42:45 -0500 | [diff] [blame] | 743 | int rc = 0; |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 744 | struct smb_rqst rqst = { .rq_iov = iov, |
| 745 | .rq_nvec = 2 }; |
Jeff Layton | 826a95e | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 746 | |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 747 | iov[0].iov_base = mid->resp_buf; |
| 748 | iov[0].iov_len = 4; |
| 749 | iov[1].iov_base = (char *)mid->resp_buf + 4; |
| 750 | iov[1].iov_len = len - 4; |
Jeff Layton | 2c8f981 | 2011-05-19 16:22:52 -0400 | [diff] [blame] | 751 | /* FIXME: add code to kill session */ |
Jeff Layton | bf5ea0e | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 752 | rc = cifs_verify_signature(&rqst, server, |
Jeff Layton | 0124cc4 | 2013-04-03 11:55:03 -0400 | [diff] [blame] | 753 | mid->sequence_number); |
Steve French | 985e4ff0 | 2012-08-03 09:42:45 -0500 | [diff] [blame] | 754 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 755 | cifs_dbg(VFS, "SMB signature verification returned error = %d\n", |
| 756 | rc); |
Jeff Layton | 2c8f981 | 2011-05-19 16:22:52 -0400 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | /* BB special case reconnect tid and uid here? */ |
| 760 | return map_smb_to_linux_error(mid->resp_buf, log_error); |
| 761 | } |
| 762 | |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 763 | struct mid_q_entry * |
| 764 | cifs_setup_request(struct cifs_ses *ses, struct smb_rqst *rqst) |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 765 | { |
| 766 | int rc; |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 767 | struct smb_hdr *hdr = (struct smb_hdr *)rqst->rq_iov[0].iov_base; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 768 | struct mid_q_entry *mid; |
| 769 | |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 770 | if (rqst->rq_iov[0].iov_len != 4 || |
| 771 | rqst->rq_iov[0].iov_base + 4 != rqst->rq_iov[1].iov_base) |
| 772 | return ERR_PTR(-EIO); |
| 773 | |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 774 | rc = allocate_mid(ses, hdr, &mid); |
| 775 | if (rc) |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 776 | return ERR_PTR(rc); |
| 777 | rc = cifs_sign_rqst(rqst, ses->server, &mid->sequence_number); |
| 778 | if (rc) { |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 779 | cifs_delete_mid(mid); |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 780 | return ERR_PTR(rc); |
| 781 | } |
| 782 | return mid; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 783 | } |
| 784 | |
Ronnie Sahlberg | 4e34feb | 2018-08-30 10:13:00 +1000 | [diff] [blame] | 785 | static void |
| 786 | cifs_noop_callback(struct mid_q_entry *mid) |
| 787 | { |
| 788 | } |
| 789 | |
Pavel Shilovsky | b8f57ee | 2016-11-23 15:31:54 -0800 | [diff] [blame] | 790 | int |
Ronnie Sahlberg | e0bba0b8 | 2018-08-01 09:26:13 +1000 | [diff] [blame] | 791 | compound_send_recv(const unsigned int xid, struct cifs_ses *ses, |
| 792 | const int flags, const int num_rqst, struct smb_rqst *rqst, |
| 793 | int *resp_buf_type, struct kvec *resp_iov) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | { |
Ronnie Sahlberg | e0bba0b8 | 2018-08-01 09:26:13 +1000 | [diff] [blame] | 795 | int i, j, rc = 0; |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 796 | int timeout, optype; |
Ronnie Sahlberg | e0bba0b8 | 2018-08-01 09:26:13 +1000 | [diff] [blame] | 797 | struct mid_q_entry *midQ[MAX_COMPOUND]; |
Pavel Shilovsky | 8544f4a | 2018-12-22 12:40:05 -0800 | [diff] [blame^] | 798 | bool cancelled_mid[MAX_COMPOUND] = {false}; |
| 799 | unsigned int credits[MAX_COMPOUND] = {0}; |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 800 | char *buf; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 801 | |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 802 | timeout = flags & CIFS_TIMEOUT_MASK; |
| 803 | optype = flags & CIFS_OP_MASK; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 804 | |
Ronnie Sahlberg | e0bba0b8 | 2018-08-01 09:26:13 +1000 | [diff] [blame] | 805 | for (i = 0; i < num_rqst; i++) |
| 806 | resp_buf_type[i] = CIFS_NO_BUFFER; /* no response buf yet */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 808 | if ((ses == NULL) || (ses->server == NULL)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 809 | cifs_dbg(VFS, "Null session\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | return -EIO; |
| 811 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 813 | if (ses->server->tcpStatus == CifsExiting) |
Steve French | 31ca3bc | 2005-04-28 22:41:11 -0700 | [diff] [blame] | 814 | return -ENOENT; |
| 815 | |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 816 | /* |
Pavel Shilovsky | 8544f4a | 2018-12-22 12:40:05 -0800 | [diff] [blame^] | 817 | * Ensure we obtain 1 credit per request in the compound chain. |
| 818 | * It can be optimized further by waiting for all the credits |
| 819 | * at once but this can wait long enough if we don't have enough |
| 820 | * credits due to some heavy operations in progress or the server |
| 821 | * not granting us much, so a fallback to the current approach is |
| 822 | * needed anyway. |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 823 | */ |
Pavel Shilovsky | 8544f4a | 2018-12-22 12:40:05 -0800 | [diff] [blame^] | 824 | for (i = 0; i < num_rqst; i++) { |
| 825 | rc = wait_for_free_request(ses->server, timeout, optype); |
| 826 | if (rc) { |
| 827 | /* |
| 828 | * We haven't sent an SMB packet to the server yet but |
| 829 | * we already obtained credits for i requests in the |
| 830 | * compound chain - need to return those credits back |
| 831 | * for future use. Note that we need to call add_credits |
| 832 | * multiple times to match the way we obtained credits |
| 833 | * in the first place and to account for in flight |
| 834 | * requests correctly. |
| 835 | */ |
| 836 | for (j = 0; j < i; j++) |
| 837 | add_credits(ses->server, 1, optype); |
| 838 | return rc; |
| 839 | } |
| 840 | credits[i] = 1; |
| 841 | } |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 842 | |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 843 | /* |
| 844 | * Make sure that we sign in the same order that we send on this socket |
| 845 | * and avoid races inside tcp sendmsg code that could cause corruption |
| 846 | * of smb data. |
| 847 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | |
Jeff Layton | 72ca545 | 2008-12-01 07:09:36 -0500 | [diff] [blame] | 849 | mutex_lock(&ses->server->srv_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | |
Ronnie Sahlberg | e0bba0b8 | 2018-08-01 09:26:13 +1000 | [diff] [blame] | 851 | for (i = 0; i < num_rqst; i++) { |
| 852 | midQ[i] = ses->server->ops->setup_request(ses, &rqst[i]); |
| 853 | if (IS_ERR(midQ[i])) { |
| 854 | for (j = 0; j < i; j++) |
| 855 | cifs_delete_mid(midQ[j]); |
| 856 | mutex_unlock(&ses->server->srv_mutex); |
Pavel Shilovsky | 8544f4a | 2018-12-22 12:40:05 -0800 | [diff] [blame^] | 857 | |
Ronnie Sahlberg | e0bba0b8 | 2018-08-01 09:26:13 +1000 | [diff] [blame] | 858 | /* Update # of requests on wire to server */ |
Pavel Shilovsky | 8544f4a | 2018-12-22 12:40:05 -0800 | [diff] [blame^] | 859 | for (j = 0; j < num_rqst; j++) |
| 860 | add_credits(ses->server, credits[j], optype); |
Ronnie Sahlberg | e0bba0b8 | 2018-08-01 09:26:13 +1000 | [diff] [blame] | 861 | return PTR_ERR(midQ[i]); |
| 862 | } |
| 863 | |
| 864 | midQ[i]->mid_state = MID_REQUEST_SUBMITTED; |
Ronnie Sahlberg | 4e34feb | 2018-08-30 10:13:00 +1000 | [diff] [blame] | 865 | /* |
| 866 | * We don't invoke the callback compounds unless it is the last |
| 867 | * request. |
| 868 | */ |
| 869 | if (i < num_rqst - 1) |
| 870 | midQ[i]->callback = cifs_noop_callback; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | } |
Steve French | 789e666 | 2011-08-09 18:44:44 +0000 | [diff] [blame] | 872 | cifs_in_send_inc(ses->server); |
Ronnie Sahlberg | e0bba0b8 | 2018-08-01 09:26:13 +1000 | [diff] [blame] | 873 | rc = smb_send_rqst(ses->server, num_rqst, rqst, flags); |
Steve French | 789e666 | 2011-08-09 18:44:44 +0000 | [diff] [blame] | 874 | cifs_in_send_dec(ses->server); |
Ronnie Sahlberg | e0bba0b8 | 2018-08-01 09:26:13 +1000 | [diff] [blame] | 875 | |
| 876 | for (i = 0; i < num_rqst; i++) |
| 877 | cifs_save_when_sent(midQ[i]); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 878 | |
Jeff Layton | ad313cb | 2013-04-03 10:27:36 -0400 | [diff] [blame] | 879 | if (rc < 0) |
| 880 | ses->server->sequence_number -= 2; |
Ronnie Sahlberg | e0bba0b8 | 2018-08-01 09:26:13 +1000 | [diff] [blame] | 881 | |
Jeff Layton | 72ca545 | 2008-12-01 07:09:36 -0500 | [diff] [blame] | 882 | mutex_unlock(&ses->server->srv_mutex); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 883 | |
Ronnie Sahlberg | cb5c2e6 | 2018-10-10 15:29:06 +1000 | [diff] [blame] | 884 | if (rc < 0) |
| 885 | goto out; |
| 886 | |
| 887 | /* |
| 888 | * Compounding is never used during session establish. |
| 889 | */ |
| 890 | if ((ses->status == CifsNew) || (optype & CIFS_NEG_OP)) |
| 891 | smb311_update_preauth_hash(ses, rqst[0].rq_iov, |
| 892 | rqst[0].rq_nvec); |
| 893 | |
| 894 | if (timeout == CIFS_ASYNC_OP) |
| 895 | goto out; |
| 896 | |
Ronnie Sahlberg | e0bba0b8 | 2018-08-01 09:26:13 +1000 | [diff] [blame] | 897 | for (i = 0; i < num_rqst; i++) { |
Ronnie Sahlberg | e0bba0b8 | 2018-08-01 09:26:13 +1000 | [diff] [blame] | 898 | rc = wait_for_response(ses->server, midQ[i]); |
| 899 | if (rc != 0) { |
Steve French | 43de1db | 2018-10-23 21:04:57 -0500 | [diff] [blame] | 900 | cifs_dbg(VFS, "Cancelling wait for mid %llu cmd: %d\n", |
| 901 | midQ[i]->mid, le16_to_cpu(midQ[i]->command)); |
Ronnie Sahlberg | e0bba0b8 | 2018-08-01 09:26:13 +1000 | [diff] [blame] | 902 | send_cancel(ses->server, &rqst[i], midQ[i]); |
| 903 | spin_lock(&GlobalMid_Lock); |
| 904 | if (midQ[i]->mid_state == MID_REQUEST_SUBMITTED) { |
| 905 | midQ[i]->mid_flags |= MID_WAIT_CANCELLED; |
| 906 | midQ[i]->callback = DeleteMidQEntry; |
Pavel Shilovsky | 8544f4a | 2018-12-22 12:40:05 -0800 | [diff] [blame^] | 907 | cancelled_mid[i] = true; |
Ronnie Sahlberg | e0bba0b8 | 2018-08-01 09:26:13 +1000 | [diff] [blame] | 908 | } |
Jeff Layton | 1be912d | 2011-01-28 07:08:28 -0500 | [diff] [blame] | 909 | spin_unlock(&GlobalMid_Lock); |
Ronnie Sahlberg | e0bba0b8 | 2018-08-01 09:26:13 +1000 | [diff] [blame] | 910 | } |
Ronnie Sahlberg | cb5c2e6 | 2018-10-10 15:29:06 +1000 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | for (i = 0; i < num_rqst; i++) |
Pavel Shilovsky | 8544f4a | 2018-12-22 12:40:05 -0800 | [diff] [blame^] | 914 | if (!cancelled_mid[i] && midQ[i]->resp_buf |
| 915 | && (midQ[i]->mid_state == MID_RESPONSE_RECEIVED)) |
| 916 | credits[i] = ses->server->ops->get_credits(midQ[i]); |
Ronnie Sahlberg | cb5c2e6 | 2018-10-10 15:29:06 +1000 | [diff] [blame] | 917 | |
| 918 | for (i = 0; i < num_rqst; i++) { |
| 919 | if (rc < 0) |
| 920 | goto out; |
Ronnie Sahlberg | e0bba0b8 | 2018-08-01 09:26:13 +1000 | [diff] [blame] | 921 | |
| 922 | rc = cifs_sync_mid_result(midQ[i], ses->server); |
| 923 | if (rc != 0) { |
Pavel Shilovsky | 8544f4a | 2018-12-22 12:40:05 -0800 | [diff] [blame^] | 924 | /* mark this mid as cancelled to not free it below */ |
| 925 | cancelled_mid[i] = true; |
| 926 | goto out; |
Jeff Layton | 1be912d | 2011-01-28 07:08:28 -0500 | [diff] [blame] | 927 | } |
Ronnie Sahlberg | e0bba0b8 | 2018-08-01 09:26:13 +1000 | [diff] [blame] | 928 | |
| 929 | if (!midQ[i]->resp_buf || |
| 930 | midQ[i]->mid_state != MID_RESPONSE_RECEIVED) { |
| 931 | rc = -EIO; |
| 932 | cifs_dbg(FYI, "Bad MID state?\n"); |
| 933 | goto out; |
| 934 | } |
| 935 | |
| 936 | buf = (char *)midQ[i]->resp_buf; |
| 937 | resp_iov[i].iov_base = buf; |
| 938 | resp_iov[i].iov_len = midQ[i]->resp_buf_size + |
| 939 | ses->server->vals->header_preamble_size; |
| 940 | |
| 941 | if (midQ[i]->large_buf) |
| 942 | resp_buf_type[i] = CIFS_LARGE_BUFFER; |
| 943 | else |
| 944 | resp_buf_type[i] = CIFS_SMALL_BUFFER; |
| 945 | |
Ronnie Sahlberg | e0bba0b8 | 2018-08-01 09:26:13 +1000 | [diff] [blame] | 946 | rc = ses->server->ops->check_receive(midQ[i], ses->server, |
| 947 | flags & CIFS_LOG_ERROR); |
| 948 | |
| 949 | /* mark it so buf will not be freed by cifs_delete_mid */ |
| 950 | if ((flags & CIFS_NO_RESP) == 0) |
| 951 | midQ[i]->resp_buf = NULL; |
Ronnie Sahlberg | cb5c2e6 | 2018-10-10 15:29:06 +1000 | [diff] [blame] | 952 | |
Jeff Layton | 1be912d | 2011-01-28 07:08:28 -0500 | [diff] [blame] | 953 | } |
Ronnie Sahlberg | cb5c2e6 | 2018-10-10 15:29:06 +1000 | [diff] [blame] | 954 | |
| 955 | /* |
| 956 | * Compounding is never used during session establish. |
| 957 | */ |
| 958 | if ((ses->status == CifsNew) || (optype & CIFS_NEG_OP)) { |
| 959 | struct kvec iov = { |
| 960 | .iov_base = resp_iov[0].iov_base, |
| 961 | .iov_len = resp_iov[0].iov_len |
| 962 | }; |
| 963 | smb311_update_preauth_hash(ses, &iov, 1); |
| 964 | } |
| 965 | |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 966 | out: |
Ronnie Sahlberg | 4e34feb | 2018-08-30 10:13:00 +1000 | [diff] [blame] | 967 | /* |
| 968 | * This will dequeue all mids. After this it is important that the |
| 969 | * demultiplex_thread will not process any of these mids any futher. |
| 970 | * This is prevented above by using a noop callback that will not |
| 971 | * wake this thread except for the very last PDU. |
| 972 | */ |
Pavel Shilovsky | 8544f4a | 2018-12-22 12:40:05 -0800 | [diff] [blame^] | 973 | for (i = 0; i < num_rqst; i++) { |
| 974 | if (!cancelled_mid[i]) |
| 975 | cifs_delete_mid(midQ[i]); |
| 976 | add_credits(ses->server, credits[i], optype); |
| 977 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | |
| 979 | return rc; |
| 980 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | |
| 982 | int |
Ronnie Sahlberg | e0bba0b8 | 2018-08-01 09:26:13 +1000 | [diff] [blame] | 983 | cifs_send_recv(const unsigned int xid, struct cifs_ses *ses, |
| 984 | struct smb_rqst *rqst, int *resp_buf_type, const int flags, |
| 985 | struct kvec *resp_iov) |
| 986 | { |
| 987 | return compound_send_recv(xid, ses, flags, 1, rqst, resp_buf_type, |
| 988 | resp_iov); |
| 989 | } |
| 990 | |
| 991 | int |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 992 | SendReceive2(const unsigned int xid, struct cifs_ses *ses, |
| 993 | struct kvec *iov, int n_vec, int *resp_buf_type /* ret */, |
| 994 | const int flags, struct kvec *resp_iov) |
| 995 | { |
| 996 | struct smb_rqst rqst; |
Ronnie Sahlberg | 3cecf48 | 2017-11-21 15:08:07 +1100 | [diff] [blame] | 997 | struct kvec s_iov[CIFS_MAX_IOV_SIZE], *new_iov; |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 998 | int rc; |
| 999 | |
Ronnie Sahlberg | 3cecf48 | 2017-11-21 15:08:07 +1100 | [diff] [blame] | 1000 | if (n_vec + 1 > CIFS_MAX_IOV_SIZE) { |
Kees Cook | 6da2ec5 | 2018-06-12 13:55:00 -0700 | [diff] [blame] | 1001 | new_iov = kmalloc_array(n_vec + 1, sizeof(struct kvec), |
| 1002 | GFP_KERNEL); |
Steve French | 117e3b7 | 2018-04-22 10:24:19 -0500 | [diff] [blame] | 1003 | if (!new_iov) { |
| 1004 | /* otherwise cifs_send_recv below sets resp_buf_type */ |
| 1005 | *resp_buf_type = CIFS_NO_BUFFER; |
Ronnie Sahlberg | 3cecf48 | 2017-11-21 15:08:07 +1100 | [diff] [blame] | 1006 | return -ENOMEM; |
Steve French | 117e3b7 | 2018-04-22 10:24:19 -0500 | [diff] [blame] | 1007 | } |
Ronnie Sahlberg | 3cecf48 | 2017-11-21 15:08:07 +1100 | [diff] [blame] | 1008 | } else |
| 1009 | new_iov = s_iov; |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 1010 | |
| 1011 | /* 1st iov is a RFC1001 length followed by the rest of the packet */ |
| 1012 | memcpy(new_iov + 1, iov, (sizeof(struct kvec) * n_vec)); |
| 1013 | |
| 1014 | new_iov[0].iov_base = new_iov[1].iov_base; |
| 1015 | new_iov[0].iov_len = 4; |
| 1016 | new_iov[1].iov_base += 4; |
| 1017 | new_iov[1].iov_len -= 4; |
| 1018 | |
| 1019 | memset(&rqst, 0, sizeof(struct smb_rqst)); |
| 1020 | rqst.rq_iov = new_iov; |
| 1021 | rqst.rq_nvec = n_vec + 1; |
| 1022 | |
| 1023 | rc = cifs_send_recv(xid, ses, &rqst, resp_buf_type, flags, resp_iov); |
Ronnie Sahlberg | 3cecf48 | 2017-11-21 15:08:07 +1100 | [diff] [blame] | 1024 | if (n_vec + 1 > CIFS_MAX_IOV_SIZE) |
| 1025 | kfree(new_iov); |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 1026 | return rc; |
| 1027 | } |
| 1028 | |
| 1029 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1030 | SendReceive(const unsigned int xid, struct cifs_ses *ses, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | struct smb_hdr *in_buf, struct smb_hdr *out_buf, |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 1032 | int *pbytes_returned, const int timeout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | { |
| 1034 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | struct mid_q_entry *midQ; |
Pavel Shilovsky | fb2036d | 2016-11-23 15:08:14 -0800 | [diff] [blame] | 1036 | unsigned int len = be32_to_cpu(in_buf->smb_buf_length); |
| 1037 | struct kvec iov = { .iov_base = in_buf, .iov_len = len }; |
| 1038 | struct smb_rqst rqst = { .rq_iov = &iov, .rq_nvec = 1 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | |
| 1040 | if (ses == NULL) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1041 | cifs_dbg(VFS, "Null smb session\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | return -EIO; |
| 1043 | } |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 1044 | if (ses->server == NULL) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1045 | cifs_dbg(VFS, "Null tcp session\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | return -EIO; |
| 1047 | } |
| 1048 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 1049 | if (ses->server->tcpStatus == CifsExiting) |
Steve French | 31ca3bc | 2005-04-28 22:41:11 -0700 | [diff] [blame] | 1050 | return -ENOENT; |
| 1051 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 1052 | /* Ensure that we do not send more than 50 overlapping requests |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | to the same server. We may make this configurable later or |
| 1054 | use ses->maxReq */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | |
Pavel Shilovsky | fb2036d | 2016-11-23 15:08:14 -0800 | [diff] [blame] | 1056 | if (len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1057 | cifs_dbg(VFS, "Illegal length, greater than maximum frame, %d\n", |
Pavel Shilovsky | fb2036d | 2016-11-23 15:08:14 -0800 | [diff] [blame] | 1058 | len); |
Volker Lendecke | 6d9c6d5 | 2008-12-08 20:50:24 +0000 | [diff] [blame] | 1059 | return -EIO; |
| 1060 | } |
| 1061 | |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 1062 | rc = wait_for_free_request(ses->server, timeout, 0); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1063 | if (rc) |
| 1064 | return rc; |
| 1065 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 1066 | /* make sure that we sign in the same order that we send on this socket |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | and avoid races inside tcp sendmsg code that could cause corruption |
| 1068 | of smb data */ |
| 1069 | |
Jeff Layton | 72ca545 | 2008-12-01 07:09:36 -0500 | [diff] [blame] | 1070 | mutex_lock(&ses->server->srv_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1072 | rc = allocate_mid(ses, in_buf, &midQ); |
| 1073 | if (rc) { |
Jeff Layton | 72ca545 | 2008-12-01 07:09:36 -0500 | [diff] [blame] | 1074 | mutex_unlock(&ses->server->srv_mutex); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1075 | /* Update # of requests on wire to server */ |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 1076 | add_credits(ses->server, 1, 0); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1077 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | } |
| 1079 | |
Steve French | ad009ac | 2005-04-28 22:41:05 -0700 | [diff] [blame] | 1080 | rc = cifs_sign_smb(in_buf, ses->server, &midQ->sequence_number); |
Volker Lendecke | 829049c | 2008-12-06 16:00:53 +0100 | [diff] [blame] | 1081 | if (rc) { |
| 1082 | mutex_unlock(&ses->server->srv_mutex); |
| 1083 | goto out; |
| 1084 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1086 | midQ->mid_state = MID_REQUEST_SUBMITTED; |
Steve French | 789e666 | 2011-08-09 18:44:44 +0000 | [diff] [blame] | 1087 | |
| 1088 | cifs_in_send_inc(ses->server); |
Pavel Shilovsky | fb2036d | 2016-11-23 15:08:14 -0800 | [diff] [blame] | 1089 | rc = smb_send(ses->server, in_buf, len); |
Steve French | 789e666 | 2011-08-09 18:44:44 +0000 | [diff] [blame] | 1090 | cifs_in_send_dec(ses->server); |
| 1091 | cifs_save_when_sent(midQ); |
Jeff Layton | ad313cb | 2013-04-03 10:27:36 -0400 | [diff] [blame] | 1092 | |
| 1093 | if (rc < 0) |
| 1094 | ses->server->sequence_number -= 2; |
| 1095 | |
Jeff Layton | 72ca545 | 2008-12-01 07:09:36 -0500 | [diff] [blame] | 1096 | mutex_unlock(&ses->server->srv_mutex); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1097 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 1098 | if (rc < 0) |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1099 | goto out; |
| 1100 | |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 1101 | if (timeout == CIFS_ASYNC_OP) |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1102 | goto out; |
Jeff Layton | 0ade640 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 1103 | |
| 1104 | rc = wait_for_response(ses->server, midQ); |
Jeff Layton | 1be912d | 2011-01-28 07:08:28 -0500 | [diff] [blame] | 1105 | if (rc != 0) { |
Pavel Shilovsky | fb2036d | 2016-11-23 15:08:14 -0800 | [diff] [blame] | 1106 | send_cancel(ses->server, &rqst, midQ); |
Jeff Layton | 1be912d | 2011-01-28 07:08:28 -0500 | [diff] [blame] | 1107 | spin_lock(&GlobalMid_Lock); |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1108 | if (midQ->mid_state == MID_REQUEST_SUBMITTED) { |
Jeff Layton | 1be912d | 2011-01-28 07:08:28 -0500 | [diff] [blame] | 1109 | /* no longer considered to be "in-flight" */ |
| 1110 | midQ->callback = DeleteMidQEntry; |
| 1111 | spin_unlock(&GlobalMid_Lock); |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 1112 | add_credits(ses->server, 1, 0); |
Jeff Layton | 1be912d | 2011-01-28 07:08:28 -0500 | [diff] [blame] | 1113 | return rc; |
| 1114 | } |
| 1115 | spin_unlock(&GlobalMid_Lock); |
| 1116 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | |
Jeff Layton | 3c1105d | 2011-05-22 07:09:13 -0400 | [diff] [blame] | 1118 | rc = cifs_sync_mid_result(midQ, ses->server); |
Jeff Layton | 053d503 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 1119 | if (rc != 0) { |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 1120 | add_credits(ses->server, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | return rc; |
| 1122 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1123 | |
Jeff Layton | 2c8f981 | 2011-05-19 16:22:52 -0400 | [diff] [blame] | 1124 | if (!midQ->resp_buf || !out_buf || |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1125 | midQ->mid_state != MID_RESPONSE_RECEIVED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | rc = -EIO; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1127 | cifs_dbg(VFS, "Bad MID state?\n"); |
Steve French | 2b2bdfb | 2008-12-11 17:26:54 +0000 | [diff] [blame] | 1128 | goto out; |
| 1129 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | |
Pavel Shilovsky | d4e4854 | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 1131 | *pbytes_returned = get_rfc1002_length(midQ->resp_buf); |
Jeff Layton | 2c8f981 | 2011-05-19 16:22:52 -0400 | [diff] [blame] | 1132 | memcpy(out_buf, midQ->resp_buf, *pbytes_returned + 4); |
| 1133 | rc = cifs_check_receive(midQ, ses->server, 0); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1134 | out: |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 1135 | cifs_delete_mid(midQ); |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 1136 | add_credits(ses->server, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | |
| 1138 | return rc; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1139 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1141 | /* We send a LOCKINGX_CANCEL_LOCK to cause the Windows |
| 1142 | blocking lock to return. */ |
| 1143 | |
| 1144 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1145 | send_lock_cancel(const unsigned int xid, struct cifs_tcon *tcon, |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1146 | struct smb_hdr *in_buf, |
| 1147 | struct smb_hdr *out_buf) |
| 1148 | { |
| 1149 | int bytes_returned; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1150 | struct cifs_ses *ses = tcon->ses; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1151 | LOCK_REQ *pSMB = (LOCK_REQ *)in_buf; |
| 1152 | |
| 1153 | /* We just modify the current in_buf to change |
| 1154 | the type of lock from LOCKING_ANDX_SHARED_LOCK |
| 1155 | or LOCKING_ANDX_EXCLUSIVE_LOCK to |
| 1156 | LOCKING_ANDX_CANCEL_LOCK. */ |
| 1157 | |
| 1158 | pSMB->LockType = LOCKING_ANDX_CANCEL_LOCK|LOCKING_ANDX_LARGE_FILES; |
| 1159 | pSMB->Timeout = 0; |
Pavel Shilovsky | 8825736 | 2012-05-23 14:01:59 +0400 | [diff] [blame] | 1160 | pSMB->hdr.Mid = get_next_mid(ses->server); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1161 | |
| 1162 | return SendReceive(xid, ses, in_buf, out_buf, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 1163 | &bytes_returned, 0); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1164 | } |
| 1165 | |
| 1166 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1167 | SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon, |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1168 | struct smb_hdr *in_buf, struct smb_hdr *out_buf, |
| 1169 | int *pbytes_returned) |
| 1170 | { |
| 1171 | int rc = 0; |
| 1172 | int rstart = 0; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1173 | struct mid_q_entry *midQ; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1174 | struct cifs_ses *ses; |
Pavel Shilovsky | fb2036d | 2016-11-23 15:08:14 -0800 | [diff] [blame] | 1175 | unsigned int len = be32_to_cpu(in_buf->smb_buf_length); |
| 1176 | struct kvec iov = { .iov_base = in_buf, .iov_len = len }; |
| 1177 | struct smb_rqst rqst = { .rq_iov = &iov, .rq_nvec = 1 }; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1178 | |
| 1179 | if (tcon == NULL || tcon->ses == NULL) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1180 | cifs_dbg(VFS, "Null smb session\n"); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1181 | return -EIO; |
| 1182 | } |
| 1183 | ses = tcon->ses; |
| 1184 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 1185 | if (ses->server == NULL) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1186 | cifs_dbg(VFS, "Null tcp session\n"); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1187 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | } |
| 1189 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 1190 | if (ses->server->tcpStatus == CifsExiting) |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1191 | return -ENOENT; |
| 1192 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 1193 | /* Ensure that we do not send more than 50 overlapping requests |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1194 | to the same server. We may make this configurable later or |
| 1195 | use ses->maxReq */ |
| 1196 | |
Pavel Shilovsky | fb2036d | 2016-11-23 15:08:14 -0800 | [diff] [blame] | 1197 | if (len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1198 | cifs_dbg(VFS, "Illegal length, greater than maximum frame, %d\n", |
Pavel Shilovsky | fb2036d | 2016-11-23 15:08:14 -0800 | [diff] [blame] | 1199 | len); |
Volker Lendecke | 6d9c6d5 | 2008-12-08 20:50:24 +0000 | [diff] [blame] | 1200 | return -EIO; |
| 1201 | } |
| 1202 | |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 1203 | rc = wait_for_free_request(ses->server, CIFS_BLOCKING_OP, 0); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1204 | if (rc) |
| 1205 | return rc; |
| 1206 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 1207 | /* make sure that we sign in the same order that we send on this socket |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1208 | and avoid races inside tcp sendmsg code that could cause corruption |
| 1209 | of smb data */ |
| 1210 | |
Jeff Layton | 72ca545 | 2008-12-01 07:09:36 -0500 | [diff] [blame] | 1211 | mutex_lock(&ses->server->srv_mutex); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1212 | |
| 1213 | rc = allocate_mid(ses, in_buf, &midQ); |
| 1214 | if (rc) { |
Jeff Layton | 72ca545 | 2008-12-01 07:09:36 -0500 | [diff] [blame] | 1215 | mutex_unlock(&ses->server->srv_mutex); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1216 | return rc; |
| 1217 | } |
| 1218 | |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1219 | rc = cifs_sign_smb(in_buf, ses->server, &midQ->sequence_number); |
Volker Lendecke | 829049c | 2008-12-06 16:00:53 +0100 | [diff] [blame] | 1220 | if (rc) { |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 1221 | cifs_delete_mid(midQ); |
Volker Lendecke | 829049c | 2008-12-06 16:00:53 +0100 | [diff] [blame] | 1222 | mutex_unlock(&ses->server->srv_mutex); |
| 1223 | return rc; |
| 1224 | } |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1225 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1226 | midQ->mid_state = MID_REQUEST_SUBMITTED; |
Steve French | 789e666 | 2011-08-09 18:44:44 +0000 | [diff] [blame] | 1227 | cifs_in_send_inc(ses->server); |
Pavel Shilovsky | fb2036d | 2016-11-23 15:08:14 -0800 | [diff] [blame] | 1228 | rc = smb_send(ses->server, in_buf, len); |
Steve French | 789e666 | 2011-08-09 18:44:44 +0000 | [diff] [blame] | 1229 | cifs_in_send_dec(ses->server); |
| 1230 | cifs_save_when_sent(midQ); |
Jeff Layton | ad313cb | 2013-04-03 10:27:36 -0400 | [diff] [blame] | 1231 | |
| 1232 | if (rc < 0) |
| 1233 | ses->server->sequence_number -= 2; |
| 1234 | |
Jeff Layton | 72ca545 | 2008-12-01 07:09:36 -0500 | [diff] [blame] | 1235 | mutex_unlock(&ses->server->srv_mutex); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1236 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 1237 | if (rc < 0) { |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 1238 | cifs_delete_mid(midQ); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1239 | return rc; |
| 1240 | } |
| 1241 | |
| 1242 | /* Wait for a reply - allow signals to interrupt. */ |
| 1243 | rc = wait_event_interruptible(ses->server->response_q, |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1244 | (!(midQ->mid_state == MID_REQUEST_SUBMITTED)) || |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1245 | ((ses->server->tcpStatus != CifsGood) && |
| 1246 | (ses->server->tcpStatus != CifsNew))); |
| 1247 | |
| 1248 | /* Were we interrupted by a signal ? */ |
| 1249 | if ((rc == -ERESTARTSYS) && |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1250 | (midQ->mid_state == MID_REQUEST_SUBMITTED) && |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1251 | ((ses->server->tcpStatus == CifsGood) || |
| 1252 | (ses->server->tcpStatus == CifsNew))) { |
| 1253 | |
| 1254 | if (in_buf->Command == SMB_COM_TRANSACTION2) { |
| 1255 | /* POSIX lock. We send a NT_CANCEL SMB to cause the |
| 1256 | blocking lock to return. */ |
Pavel Shilovsky | fb2036d | 2016-11-23 15:08:14 -0800 | [diff] [blame] | 1257 | rc = send_cancel(ses->server, &rqst, midQ); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1258 | if (rc) { |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 1259 | cifs_delete_mid(midQ); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1260 | return rc; |
| 1261 | } |
| 1262 | } else { |
| 1263 | /* Windows lock. We send a LOCKINGX_CANCEL_LOCK |
| 1264 | to cause the blocking lock to return. */ |
| 1265 | |
| 1266 | rc = send_lock_cancel(xid, tcon, in_buf, out_buf); |
| 1267 | |
| 1268 | /* If we get -ENOLCK back the lock may have |
| 1269 | already been removed. Don't exit in this case. */ |
| 1270 | if (rc && rc != -ENOLCK) { |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 1271 | cifs_delete_mid(midQ); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1272 | return rc; |
| 1273 | } |
| 1274 | } |
| 1275 | |
Jeff Layton | 1be912d | 2011-01-28 07:08:28 -0500 | [diff] [blame] | 1276 | rc = wait_for_response(ses->server, midQ); |
| 1277 | if (rc) { |
Pavel Shilovsky | fb2036d | 2016-11-23 15:08:14 -0800 | [diff] [blame] | 1278 | send_cancel(ses->server, &rqst, midQ); |
Jeff Layton | 1be912d | 2011-01-28 07:08:28 -0500 | [diff] [blame] | 1279 | spin_lock(&GlobalMid_Lock); |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1280 | if (midQ->mid_state == MID_REQUEST_SUBMITTED) { |
Jeff Layton | 1be912d | 2011-01-28 07:08:28 -0500 | [diff] [blame] | 1281 | /* no longer considered to be "in-flight" */ |
| 1282 | midQ->callback = DeleteMidQEntry; |
| 1283 | spin_unlock(&GlobalMid_Lock); |
| 1284 | return rc; |
| 1285 | } |
| 1286 | spin_unlock(&GlobalMid_Lock); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1287 | } |
Jeff Layton | 1be912d | 2011-01-28 07:08:28 -0500 | [diff] [blame] | 1288 | |
| 1289 | /* We got the response - restart system call. */ |
| 1290 | rstart = 1; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1291 | } |
| 1292 | |
Jeff Layton | 3c1105d | 2011-05-22 07:09:13 -0400 | [diff] [blame] | 1293 | rc = cifs_sync_mid_result(midQ, ses->server); |
Jeff Layton | 053d503 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 1294 | if (rc != 0) |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1295 | return rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1296 | |
Volker Lendecke | 17c8bfe | 2008-12-06 16:38:19 +0100 | [diff] [blame] | 1297 | /* rcvd frame is ok */ |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 1298 | if (out_buf == NULL || midQ->mid_state != MID_RESPONSE_RECEIVED) { |
Volker Lendecke | 17c8bfe | 2008-12-06 16:38:19 +0100 | [diff] [blame] | 1299 | rc = -EIO; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1300 | cifs_dbg(VFS, "Bad MID state?\n"); |
Volker Lendecke | 698e96a | 2008-12-06 16:39:31 +0100 | [diff] [blame] | 1301 | goto out; |
Volker Lendecke | 17c8bfe | 2008-12-06 16:38:19 +0100 | [diff] [blame] | 1302 | } |
| 1303 | |
Pavel Shilovsky | d4e4854 | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 1304 | *pbytes_returned = get_rfc1002_length(midQ->resp_buf); |
Jeff Layton | 2c8f981 | 2011-05-19 16:22:52 -0400 | [diff] [blame] | 1305 | memcpy(out_buf, midQ->resp_buf, *pbytes_returned + 4); |
| 1306 | rc = cifs_check_receive(midQ, ses->server, 0); |
Volker Lendecke | 17c8bfe | 2008-12-06 16:38:19 +0100 | [diff] [blame] | 1307 | out: |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 1308 | cifs_delete_mid(midQ); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1309 | if (rstart && rc == -EACCES) |
| 1310 | return -ERESTARTSYS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | return rc; |
| 1312 | } |