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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <asm/uaccess.h> |
| 32 | #include <asm/processor.h> |
| 33 | #include <linux/mempool.h> |
| 34 | #include "cifspdu.h" |
| 35 | #include "cifsglob.h" |
| 36 | #include "cifsproto.h" |
| 37 | #include "cifs_debug.h" |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 38 | |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 39 | void |
| 40 | cifs_wake_up_task(struct mid_q_entry *mid) |
Jeff Layton | 2b84a36c | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 41 | { |
| 42 | wake_up_process(mid->callback_data); |
| 43 | } |
| 44 | |
Jeff Layton | a6827c1 | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 45 | struct mid_q_entry * |
Jeff Layton | 24b9b06 | 2008-12-01 07:09:34 -0500 | [diff] [blame] | 46 | AllocMidQEntry(const struct smb_hdr *smb_buffer, struct TCP_Server_Info *server) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | { |
| 48 | struct mid_q_entry *temp; |
| 49 | |
Jeff Layton | 24b9b06 | 2008-12-01 07:09:34 -0500 | [diff] [blame] | 50 | if (server == NULL) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 51 | cERROR(1, "Null TCP session in AllocMidQEntry"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | return NULL; |
| 53 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 54 | |
Pekka Enberg | 232087c | 2008-09-15 13:22:54 +0300 | [diff] [blame] | 55 | temp = mempool_alloc(cifs_mid_poolp, GFP_NOFS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | if (temp == NULL) |
| 57 | return temp; |
| 58 | else { |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 59 | memset(temp, 0, sizeof(struct mid_q_entry)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | temp->mid = smb_buffer->Mid; /* always LE */ |
| 61 | temp->pid = current->pid; |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 62 | temp->command = cpu_to_le16(smb_buffer->Command); |
| 63 | cFYI(1, "For smb_command %d", smb_buffer->Command); |
Steve French | 1047abc | 2005-10-11 19:58:06 -0700 | [diff] [blame] | 64 | /* do_gettimeofday(&temp->when_sent);*/ /* easier to use jiffies */ |
| 65 | /* when mid allocated can be before when sent */ |
| 66 | temp->when_alloc = jiffies; |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 67 | temp->server = server; |
Jeff Layton | 2b84a36c | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 68 | |
| 69 | /* |
| 70 | * The default is for the mid to be synchronous, so the |
| 71 | * default callback just wakes up the current task. |
| 72 | */ |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 73 | temp->callback = cifs_wake_up_task; |
Jeff Layton | 2b84a36c | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 74 | temp->callback_data = current; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | atomic_inc(&midCount); |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 78 | temp->mid_state = MID_REQUEST_ALLOCATED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | return temp; |
| 80 | } |
| 81 | |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 82 | void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | DeleteMidQEntry(struct mid_q_entry *midEntry) |
| 84 | { |
Steve French | 1047abc | 2005-10-11 19:58:06 -0700 | [diff] [blame] | 85 | #ifdef CONFIG_CIFS_STATS2 |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 86 | __le16 command = midEntry->server->vals->lock_cmd; |
Steve French | 1047abc | 2005-10-11 19:58:06 -0700 | [diff] [blame] | 87 | unsigned long now; |
| 88 | #endif |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 89 | midEntry->mid_state = MID_FREE; |
Jeff Layton | 8097531 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 90 | atomic_dec(&midCount); |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 91 | if (midEntry->large_buf) |
Steve French | b8643e1 | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 92 | cifs_buf_release(midEntry->resp_buf); |
| 93 | else |
| 94 | cifs_small_buf_release(midEntry->resp_buf); |
Steve French | 1047abc | 2005-10-11 19:58:06 -0700 | [diff] [blame] | 95 | #ifdef CONFIG_CIFS_STATS2 |
| 96 | now = jiffies; |
| 97 | /* commands taking longer than one second are indications that |
| 98 | something is wrong, unless it is quite a slow link or server */ |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 99 | if ((now - midEntry->when_alloc) > HZ) { |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 100 | if ((cifsFYI & CIFS_TIMER) && (midEntry->command != command)) { |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 101 | printk(KERN_DEBUG " CIFS slow rsp: cmd %d mid %llu", |
Steve French | 1047abc | 2005-10-11 19:58:06 -0700 | [diff] [blame] | 102 | midEntry->command, midEntry->mid); |
| 103 | printk(" A: 0x%lx S: 0x%lx R: 0x%lx\n", |
| 104 | now - midEntry->when_alloc, |
| 105 | now - midEntry->when_sent, |
| 106 | now - midEntry->when_received); |
| 107 | } |
| 108 | } |
| 109 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | mempool_free(midEntry, cifs_mid_poolp); |
| 111 | } |
| 112 | |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 113 | void |
| 114 | cifs_delete_mid(struct mid_q_entry *mid) |
Jeff Layton | ddc8cf8 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 115 | { |
| 116 | spin_lock(&GlobalMid_Lock); |
| 117 | list_del(&mid->qhead); |
| 118 | spin_unlock(&GlobalMid_Lock); |
| 119 | |
| 120 | DeleteMidQEntry(mid); |
| 121 | } |
| 122 | |
Jeff Layton | 6f49f46 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 123 | /* |
| 124 | * smb_send_kvec - send an array of kvecs to the server |
| 125 | * @server: Server to send the data to |
| 126 | * @iov: Pointer to array of kvecs |
| 127 | * @n_vec: length of kvec array |
| 128 | * @sent: amount of data sent on socket is stored here |
| 129 | * |
| 130 | * Our basic "send data to server" function. Should be called with srv_mutex |
| 131 | * held. The caller is responsible for handling the results. |
| 132 | */ |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 133 | static int |
Jeff Layton | 6f49f46 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 134 | smb_send_kvec(struct TCP_Server_Info *server, struct kvec *iov, size_t n_vec, |
| 135 | size_t *sent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | { |
| 137 | int rc = 0; |
| 138 | int i = 0; |
| 139 | struct msghdr smb_msg; |
Jeff Layton | 6f49f46 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 140 | unsigned int remaining; |
| 141 | size_t first_vec = 0; |
Steve French | edf1ae4 | 2008-10-29 00:47:57 +0000 | [diff] [blame] | 142 | struct socket *ssocket = server->ssocket; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 143 | |
Jeff Layton | 6f49f46 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 144 | *sent = 0; |
| 145 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 146 | if (ssocket == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | return -ENOTSOCK; /* BB eventually add reconnect code here */ |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 148 | |
Pavel Shilovsky | a9f1b85 | 2010-12-13 19:08:35 +0300 | [diff] [blame] | 149 | smb_msg.msg_name = (struct sockaddr *) &server->dstaddr; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 150 | smb_msg.msg_namelen = sizeof(struct sockaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | smb_msg.msg_control = NULL; |
| 152 | smb_msg.msg_controllen = 0; |
Jeff Layton | 0496e02 | 2008-12-30 12:39:16 -0500 | [diff] [blame] | 153 | if (server->noblocksnd) |
Steve French | edf1ae4 | 2008-10-29 00:47:57 +0000 | [diff] [blame] | 154 | smb_msg.msg_flags = MSG_DONTWAIT + MSG_NOSIGNAL; |
| 155 | else |
| 156 | smb_msg.msg_flags = MSG_NOSIGNAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
Jeff Layton | 6f49f46 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 158 | remaining = 0; |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 159 | for (i = 0; i < n_vec; i++) |
Jeff Layton | 6f49f46 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 160 | remaining += iov[i].iov_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
Shirish Pargaonkar | 1768035 | 2008-07-29 21:26:13 +0000 | [diff] [blame] | 162 | i = 0; |
Jeff Layton | 6f49f46 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 163 | while (remaining) { |
| 164 | /* |
| 165 | * If blocking send, we try 3 times, since each can block |
| 166 | * for 5 seconds. For nonblocking we have to try more |
| 167 | * but wait increasing amounts of time allowing time for |
| 168 | * socket to clear. The overall time we wait in either |
| 169 | * case to send on the socket is about 15 seconds. |
| 170 | * Similarly we wait for 15 seconds for a response from |
| 171 | * the server in SendReceive[2] for the server to send |
| 172 | * a response back for most types of requests (except |
| 173 | * SMB Write past end of file which can be slow, and |
| 174 | * blocking lock operations). NFS waits slightly longer |
| 175 | * than CIFS, but this can make it take longer for |
| 176 | * nonresponsive servers to be detected and 15 seconds |
| 177 | * is more than enough time for modern networks to |
| 178 | * send a packet. In most cases if we fail to send |
| 179 | * after the retries we will kill the socket and |
| 180 | * reconnect which may clear the network problem. |
| 181 | */ |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 182 | rc = kernel_sendmsg(ssocket, &smb_msg, &iov[first_vec], |
Jeff Layton | 6f49f46 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 183 | n_vec - first_vec, remaining); |
| 184 | if (rc == -ENOSPC || rc == -EAGAIN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | i++; |
Jeff Layton | 6f49f46 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 186 | if (i >= 14 || (!server->noblocksnd && (i > 2))) { |
| 187 | cERROR(1, "sends on sock %p stuck for 15 " |
| 188 | "seconds", ssocket); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | rc = -EAGAIN; |
| 190 | break; |
| 191 | } |
Steve French | 68058e7 | 2005-10-10 10:34:22 -0700 | [diff] [blame] | 192 | msleep(1 << i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | continue; |
| 194 | } |
Jeff Layton | 6f49f46 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 195 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 196 | if (rc < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | break; |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 198 | |
Jeff Layton | 6f49f46 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 199 | /* send was at least partially successful */ |
| 200 | *sent += rc; |
| 201 | |
| 202 | if (rc == remaining) { |
| 203 | remaining = 0; |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 204 | break; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 205 | } |
Jeff Layton | 6f49f46 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 206 | |
| 207 | if (rc > remaining) { |
| 208 | cERROR(1, "sent %d requested %d", rc, remaining); |
| 209 | break; |
| 210 | } |
| 211 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 212 | if (rc == 0) { |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 213 | /* should never happen, letting socket clear before |
| 214 | retrying is our only obvious option here */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 215 | cERROR(1, "tcp sent no data"); |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 216 | msleep(500); |
| 217 | continue; |
| 218 | } |
Jeff Layton | 6f49f46 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 219 | |
| 220 | remaining -= rc; |
| 221 | |
Steve French | 68058e7 | 2005-10-10 10:34:22 -0700 | [diff] [blame] | 222 | /* the line below resets i */ |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 223 | for (i = first_vec; i < n_vec; i++) { |
| 224 | if (iov[i].iov_len) { |
| 225 | if (rc > iov[i].iov_len) { |
| 226 | rc -= iov[i].iov_len; |
| 227 | iov[i].iov_len = 0; |
| 228 | } else { |
| 229 | iov[i].iov_base += rc; |
| 230 | iov[i].iov_len -= rc; |
| 231 | first_vec = i; |
| 232 | break; |
| 233 | } |
| 234 | } |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 235 | } |
Jeff Layton | 6f49f46 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 236 | |
Steve French | 5e1253b | 2005-10-10 14:06:37 -0700 | [diff] [blame] | 237 | i = 0; /* in case we get ENOSPC on the next send */ |
Jeff Layton | 6f49f46 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 238 | rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | } |
Jeff Layton | 6f49f46 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 240 | return rc; |
| 241 | } |
| 242 | |
| 243 | static int |
| 244 | smb_send_rqst(struct TCP_Server_Info *server, struct smb_rqst *rqst) |
| 245 | { |
| 246 | int rc; |
| 247 | struct kvec *iov = rqst->rq_iov; |
| 248 | int n_vec = rqst->rq_nvec; |
| 249 | unsigned int smb_buf_length = get_rfc1002_length(iov[0].iov_base); |
| 250 | size_t total_len; |
Jeff Layton | b8eed28 | 2012-09-18 16:20:35 -0700 | [diff] [blame^] | 251 | struct socket *ssocket = server->ssocket; |
| 252 | int val = 1; |
Jeff Layton | 6f49f46 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 253 | |
| 254 | cFYI(1, "Sending smb: smb_len=%u", smb_buf_length); |
| 255 | dump_smb(iov[0].iov_base, iov[0].iov_len); |
| 256 | |
Jeff Layton | b8eed28 | 2012-09-18 16:20:35 -0700 | [diff] [blame^] | 257 | /* cork the socket */ |
| 258 | kernel_setsockopt(ssocket, SOL_TCP, TCP_CORK, |
| 259 | (char *)&val, sizeof(val)); |
| 260 | |
Jeff Layton | 6f49f46 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 261 | rc = smb_send_kvec(server, iov, n_vec, &total_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | |
Jeff Layton | b8eed28 | 2012-09-18 16:20:35 -0700 | [diff] [blame^] | 263 | /* uncork it */ |
| 264 | val = 0; |
| 265 | kernel_setsockopt(ssocket, SOL_TCP, TCP_CORK, |
| 266 | (char *)&val, sizeof(val)); |
| 267 | |
Steve French | edf1ae4 | 2008-10-29 00:47:57 +0000 | [diff] [blame] | 268 | if ((total_len > 0) && (total_len != smb_buf_length + 4)) { |
Jeff Layton | 6f49f46 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 269 | cFYI(1, "partial send (wanted=%u sent=%zu): terminating " |
| 270 | "session", smb_buf_length + 4, total_len); |
| 271 | /* |
| 272 | * If we have only sent part of an SMB then the next SMB could |
| 273 | * be taken as the remainder of this one. We need to kill the |
| 274 | * socket so the server throws away the partial SMB |
| 275 | */ |
Steve French | edf1ae4 | 2008-10-29 00:47:57 +0000 | [diff] [blame] | 276 | server->tcpStatus = CifsNeedReconnect; |
| 277 | } |
| 278 | |
Jeff Layton | d804d41 | 2011-01-28 15:05:43 -0500 | [diff] [blame] | 279 | if (rc < 0 && rc != -EINTR) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 280 | cERROR(1, "Error %d sending data on socket to server", rc); |
Jeff Layton | d804d41 | 2011-01-28 15:05:43 -0500 | [diff] [blame] | 281 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | |
| 284 | return rc; |
| 285 | } |
| 286 | |
Jeff Layton | 6f49f46 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 287 | static int |
| 288 | smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec) |
| 289 | { |
| 290 | struct smb_rqst rqst = { .rq_iov = iov, |
| 291 | .rq_nvec = n_vec }; |
| 292 | |
| 293 | return smb_send_rqst(server, &rqst); |
| 294 | } |
| 295 | |
Jeff Layton | 0496e02 | 2008-12-30 12:39:16 -0500 | [diff] [blame] | 296 | int |
| 297 | smb_send(struct TCP_Server_Info *server, struct smb_hdr *smb_buffer, |
| 298 | unsigned int smb_buf_length) |
| 299 | { |
| 300 | struct kvec iov; |
| 301 | |
| 302 | iov.iov_base = smb_buffer; |
| 303 | iov.iov_len = smb_buf_length + 4; |
| 304 | |
| 305 | return smb_sendv(server, &iov, 1); |
| 306 | } |
| 307 | |
Pavel Shilovsky | fc40f9c | 2012-02-17 17:09:12 +0300 | [diff] [blame] | 308 | static int |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 309 | wait_for_free_credits(struct TCP_Server_Info *server, const int timeout, |
Pavel Shilovsky | bc205ed | 2012-03-15 13:22:27 +0300 | [diff] [blame] | 310 | int *credits) |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 311 | { |
Pavel Shilovsky | 5bc5949 | 2012-02-21 19:56:08 +0300 | [diff] [blame] | 312 | int rc; |
| 313 | |
Pavel Shilovsky | fc40f9c | 2012-02-17 17:09:12 +0300 | [diff] [blame] | 314 | spin_lock(&server->req_lock); |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 315 | if (timeout == CIFS_ASYNC_OP) { |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 316 | /* oplock breaks must not be held up */ |
Pavel Shilovsky | fc40f9c | 2012-02-17 17:09:12 +0300 | [diff] [blame] | 317 | server->in_flight++; |
Pavel Shilovsky | bc205ed | 2012-03-15 13:22:27 +0300 | [diff] [blame] | 318 | *credits -= 1; |
Pavel Shilovsky | fc40f9c | 2012-02-17 17:09:12 +0300 | [diff] [blame] | 319 | spin_unlock(&server->req_lock); |
Volker Lendecke | 27a97a6 | 2008-12-08 20:59:39 +0000 | [diff] [blame] | 320 | return 0; |
| 321 | } |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 322 | |
Volker Lendecke | 27a97a6 | 2008-12-08 20:59:39 +0000 | [diff] [blame] | 323 | while (1) { |
Pavel Shilovsky | bc205ed | 2012-03-15 13:22:27 +0300 | [diff] [blame] | 324 | if (*credits <= 0) { |
Pavel Shilovsky | fc40f9c | 2012-02-17 17:09:12 +0300 | [diff] [blame] | 325 | spin_unlock(&server->req_lock); |
Steve French | 789e666 | 2011-08-09 18:44:44 +0000 | [diff] [blame] | 326 | cifs_num_waiters_inc(server); |
Pavel Shilovsky | 5bc5949 | 2012-02-21 19:56:08 +0300 | [diff] [blame] | 327 | rc = wait_event_killable(server->request_q, |
Pavel Shilovsky | bc205ed | 2012-03-15 13:22:27 +0300 | [diff] [blame] | 328 | has_credits(server, credits)); |
Steve French | 789e666 | 2011-08-09 18:44:44 +0000 | [diff] [blame] | 329 | cifs_num_waiters_dec(server); |
Pavel Shilovsky | 5bc5949 | 2012-02-21 19:56:08 +0300 | [diff] [blame] | 330 | if (rc) |
| 331 | return rc; |
Pavel Shilovsky | fc40f9c | 2012-02-17 17:09:12 +0300 | [diff] [blame] | 332 | spin_lock(&server->req_lock); |
Volker Lendecke | 27a97a6 | 2008-12-08 20:59:39 +0000 | [diff] [blame] | 333 | } else { |
Jeff Layton | c5797a9 | 2011-01-11 07:24:01 -0500 | [diff] [blame] | 334 | if (server->tcpStatus == CifsExiting) { |
Pavel Shilovsky | fc40f9c | 2012-02-17 17:09:12 +0300 | [diff] [blame] | 335 | spin_unlock(&server->req_lock); |
Volker Lendecke | 27a97a6 | 2008-12-08 20:59:39 +0000 | [diff] [blame] | 336 | return -ENOENT; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 337 | } |
Volker Lendecke | 27a97a6 | 2008-12-08 20:59:39 +0000 | [diff] [blame] | 338 | |
Pavel Shilovsky | 2d86dbc | 2012-02-06 15:59:18 +0400 | [diff] [blame] | 339 | /* |
| 340 | * Can not count locking commands against total |
| 341 | * as they are allowed to block on server. |
| 342 | */ |
Volker Lendecke | 27a97a6 | 2008-12-08 20:59:39 +0000 | [diff] [blame] | 343 | |
| 344 | /* update # of requests on the wire to server */ |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 345 | if (timeout != CIFS_BLOCKING_OP) { |
Pavel Shilovsky | bc205ed | 2012-03-15 13:22:27 +0300 | [diff] [blame] | 346 | *credits -= 1; |
Pavel Shilovsky | fc40f9c | 2012-02-17 17:09:12 +0300 | [diff] [blame] | 347 | server->in_flight++; |
Pavel Shilovsky | 2d86dbc | 2012-02-06 15:59:18 +0400 | [diff] [blame] | 348 | } |
Pavel Shilovsky | fc40f9c | 2012-02-17 17:09:12 +0300 | [diff] [blame] | 349 | spin_unlock(&server->req_lock); |
Volker Lendecke | 27a97a6 | 2008-12-08 20:59:39 +0000 | [diff] [blame] | 350 | break; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | return 0; |
| 354 | } |
| 355 | |
Pavel Shilovsky | bc205ed | 2012-03-15 13:22:27 +0300 | [diff] [blame] | 356 | static int |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 357 | wait_for_free_request(struct TCP_Server_Info *server, const int timeout, |
| 358 | const int optype) |
Pavel Shilovsky | bc205ed | 2012-03-15 13:22:27 +0300 | [diff] [blame] | 359 | { |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 360 | return wait_for_free_credits(server, timeout, |
| 361 | server->ops->get_credits_field(server, optype)); |
Pavel Shilovsky | bc205ed | 2012-03-15 13:22:27 +0300 | [diff] [blame] | 362 | } |
| 363 | |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 364 | 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] | 365 | struct mid_q_entry **ppmidQ) |
| 366 | { |
| 367 | if (ses->server->tcpStatus == CifsExiting) { |
| 368 | return -ENOENT; |
Volker Lendecke | 8fbbd36 | 2008-12-06 13:12:34 +0100 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | if (ses->server->tcpStatus == CifsNeedReconnect) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 372 | cFYI(1, "tcp session dead - return to caller to retry"); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 373 | return -EAGAIN; |
Volker Lendecke | 8fbbd36 | 2008-12-06 13:12:34 +0100 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | if (ses->status != CifsGood) { |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 377 | /* check if SMB session is bad because we are setting it up */ |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 378 | if ((in_buf->Command != SMB_COM_SESSION_SETUP_ANDX) && |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 379 | (in_buf->Command != SMB_COM_NEGOTIATE)) |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 380 | return -EAGAIN; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 381 | /* else ok - we are setting up session */ |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 382 | } |
Jeff Layton | 24b9b06 | 2008-12-01 07:09:34 -0500 | [diff] [blame] | 383 | *ppmidQ = AllocMidQEntry(in_buf, ses->server); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 384 | if (*ppmidQ == NULL) |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 385 | return -ENOMEM; |
Jeff Layton | ddc8cf8 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 386 | spin_lock(&GlobalMid_Lock); |
| 387 | list_add_tail(&(*ppmidQ)->qhead, &ses->server->pending_mid_q); |
| 388 | spin_unlock(&GlobalMid_Lock); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 389 | return 0; |
| 390 | } |
| 391 | |
Jeff Layton | 0ade640 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 392 | static int |
| 393 | 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] | 394 | { |
Jeff Layton | 0ade640 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 395 | int error; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 396 | |
Jeff Layton | f06ac72 | 2011-10-19 15:30:40 -0400 | [diff] [blame] | 397 | error = wait_event_freezekillable(server->response_q, |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 398 | midQ->mid_state != MID_REQUEST_SUBMITTED); |
Jeff Layton | 0ade640 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 399 | if (error < 0) |
| 400 | return -ERESTARTSYS; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 401 | |
Jeff Layton | 0ade640 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 402 | return 0; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 403 | } |
| 404 | |
Pavel Shilovsky | 4574084 | 2012-06-01 14:26:18 +0400 | [diff] [blame] | 405 | int |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 406 | cifs_setup_async_request(struct TCP_Server_Info *server, struct kvec *iov, |
| 407 | unsigned int nvec, struct mid_q_entry **ret_mid) |
| 408 | { |
| 409 | int rc; |
| 410 | struct smb_hdr *hdr = (struct smb_hdr *)iov[0].iov_base; |
| 411 | struct mid_q_entry *mid; |
| 412 | |
| 413 | /* enable signing if server requires it */ |
| 414 | if (server->sec_mode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) |
| 415 | hdr->Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
| 416 | |
| 417 | mid = AllocMidQEntry(hdr, server); |
| 418 | if (mid == NULL) |
| 419 | return -ENOMEM; |
| 420 | |
Jeff Layton | 762a420 | 2012-07-23 13:28:38 -0400 | [diff] [blame] | 421 | rc = cifs_sign_smbv(iov, nvec, server, &mid->sequence_number); |
Sachin Prabhu | ffc61cc | 2012-07-11 12:28:05 +0100 | [diff] [blame] | 422 | if (rc) { |
| 423 | DeleteMidQEntry(mid); |
| 424 | return rc; |
| 425 | } |
| 426 | |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 427 | *ret_mid = mid; |
Sachin Prabhu | ffc61cc | 2012-07-11 12:28:05 +0100 | [diff] [blame] | 428 | return 0; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 429 | } |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 430 | |
| 431 | /* |
Jeff Layton | a6827c1 | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 432 | * Send a SMB request and set the callback function in the mid to handle |
| 433 | * the result. Caller is responsible for dealing with timeouts. |
| 434 | */ |
| 435 | int |
Jeff Layton | fcc31cb | 2011-05-19 16:22:53 -0400 | [diff] [blame] | 436 | cifs_call_async(struct TCP_Server_Info *server, struct kvec *iov, |
Jeff Layton | 44d22d8 | 2011-10-19 15:29:49 -0400 | [diff] [blame] | 437 | unsigned int nvec, mid_receive_t *receive, |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 438 | mid_callback_t *callback, void *cbdata, const int flags) |
Jeff Layton | a6827c1 | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 439 | { |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 440 | int rc, timeout, optype; |
Jeff Layton | a6827c1 | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 441 | struct mid_q_entry *mid; |
| 442 | |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 443 | timeout = flags & CIFS_TIMEOUT_MASK; |
| 444 | optype = flags & CIFS_OP_MASK; |
| 445 | |
| 446 | rc = wait_for_free_request(server, timeout, optype); |
Jeff Layton | a6827c1 | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 447 | if (rc) |
| 448 | return rc; |
| 449 | |
| 450 | mutex_lock(&server->srv_mutex); |
Pavel Shilovsky | 4574084 | 2012-06-01 14:26:18 +0400 | [diff] [blame] | 451 | rc = server->ops->setup_async_request(server, iov, nvec, &mid); |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 452 | if (rc) { |
Jeff Layton | a6827c1 | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 453 | mutex_unlock(&server->srv_mutex); |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 454 | add_credits(server, 1, optype); |
Pavel Shilovsky | 0193e07 | 2011-08-03 23:12:18 +0400 | [diff] [blame] | 455 | wake_up(&server->request_q); |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 456 | return rc; |
Jeff Layton | a6827c1 | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 457 | } |
| 458 | |
Jeff Layton | 44d22d8 | 2011-10-19 15:29:49 -0400 | [diff] [blame] | 459 | mid->receive = receive; |
Jeff Layton | a6827c1 | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 460 | mid->callback = callback; |
| 461 | mid->callback_data = cbdata; |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 462 | mid->mid_state = MID_REQUEST_SUBMITTED; |
Steve French | 789e666 | 2011-08-09 18:44:44 +0000 | [diff] [blame] | 463 | |
Sachin Prabhu | ffc61cc | 2012-07-11 12:28:05 +0100 | [diff] [blame] | 464 | /* put it on the pending_mid_q */ |
| 465 | spin_lock(&GlobalMid_Lock); |
| 466 | list_add_tail(&mid->qhead, &server->pending_mid_q); |
| 467 | spin_unlock(&GlobalMid_Lock); |
| 468 | |
| 469 | |
Steve French | 789e666 | 2011-08-09 18:44:44 +0000 | [diff] [blame] | 470 | cifs_in_send_inc(server); |
Jeff Layton | fcc31cb | 2011-05-19 16:22:53 -0400 | [diff] [blame] | 471 | rc = smb_sendv(server, iov, nvec); |
Steve French | 789e666 | 2011-08-09 18:44:44 +0000 | [diff] [blame] | 472 | cifs_in_send_dec(server); |
| 473 | cifs_save_when_sent(mid); |
Jeff Layton | a6827c1 | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 474 | mutex_unlock(&server->srv_mutex); |
Steve French | 789e666 | 2011-08-09 18:44:44 +0000 | [diff] [blame] | 475 | |
Sachin Prabhu | ffc61cc | 2012-07-11 12:28:05 +0100 | [diff] [blame] | 476 | if (rc == 0) |
| 477 | return 0; |
Jeff Layton | a6827c1 | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 478 | |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 479 | cifs_delete_mid(mid); |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 480 | add_credits(server, 1, optype); |
Jeff Layton | a6827c1 | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 481 | wake_up(&server->request_q); |
| 482 | return rc; |
| 483 | } |
| 484 | |
| 485 | /* |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 486 | * |
| 487 | * Send an SMB Request. No response info (other than return code) |
| 488 | * needs to be parsed. |
| 489 | * |
| 490 | * flags indicate the type of request buffer and how long to wait |
| 491 | * and whether to log NT STATUS code (error) before mapping it to POSIX error |
| 492 | * |
| 493 | */ |
| 494 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 495 | SendReceiveNoRsp(const unsigned int xid, struct cifs_ses *ses, |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 496 | char *in_buf, int flags) |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 497 | { |
| 498 | int rc; |
| 499 | struct kvec iov[1]; |
| 500 | int resp_buf_type; |
| 501 | |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 502 | iov[0].iov_base = in_buf; |
| 503 | iov[0].iov_len = get_rfc1002_length(in_buf) + 4; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 504 | flags |= CIFS_NO_RESP; |
| 505 | rc = SendReceive2(xid, ses, iov, 1, &resp_buf_type, flags); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 506 | cFYI(DBG2, "SendRcvNoRsp flags %d rc %d", flags, rc); |
Steve French | 90c81e0 | 2008-02-12 20:32:36 +0000 | [diff] [blame] | 507 | |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 508 | return rc; |
| 509 | } |
| 510 | |
Jeff Layton | 053d503 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 511 | static int |
Jeff Layton | 3c1105d | 2011-05-22 07:09:13 -0400 | [diff] [blame] | 512 | 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] | 513 | { |
| 514 | int rc = 0; |
| 515 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 516 | cFYI(1, "%s: cmd=%d mid=%llu state=%d", __func__, |
| 517 | le16_to_cpu(mid->command), mid->mid, mid->mid_state); |
Jeff Layton | 053d503 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 518 | |
Jeff Layton | 74dd92a | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 519 | spin_lock(&GlobalMid_Lock); |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 520 | switch (mid->mid_state) { |
Jeff Layton | 74dd92a | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 521 | case MID_RESPONSE_RECEIVED: |
Jeff Layton | 053d503 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 522 | spin_unlock(&GlobalMid_Lock); |
| 523 | return rc; |
Jeff Layton | 74dd92a | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 524 | case MID_RETRY_NEEDED: |
| 525 | rc = -EAGAIN; |
| 526 | break; |
Jeff Layton | 71823ba | 2011-02-10 08:03:50 -0500 | [diff] [blame] | 527 | case MID_RESPONSE_MALFORMED: |
| 528 | rc = -EIO; |
| 529 | break; |
Jeff Layton | 3c1105d | 2011-05-22 07:09:13 -0400 | [diff] [blame] | 530 | case MID_SHUTDOWN: |
| 531 | rc = -EHOSTDOWN; |
| 532 | break; |
Jeff Layton | 74dd92a | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 533 | default: |
Jeff Layton | 3c1105d | 2011-05-22 07:09:13 -0400 | [diff] [blame] | 534 | list_del_init(&mid->qhead); |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 535 | cERROR(1, "%s: invalid mid state mid=%llu state=%d", __func__, |
| 536 | mid->mid, mid->mid_state); |
Jeff Layton | 74dd92a | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 537 | rc = -EIO; |
Jeff Layton | 053d503 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 538 | } |
| 539 | spin_unlock(&GlobalMid_Lock); |
| 540 | |
Jeff Layton | 2b84a36c | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 541 | DeleteMidQEntry(mid); |
Jeff Layton | 053d503 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 542 | return rc; |
| 543 | } |
| 544 | |
Jeff Layton | 121b046 | 2012-05-15 12:21:10 -0400 | [diff] [blame] | 545 | static inline int |
| 546 | send_cancel(struct TCP_Server_Info *server, void *buf, struct mid_q_entry *mid) |
Jeff Layton | 76dcc26 | 2011-01-11 07:24:24 -0500 | [diff] [blame] | 547 | { |
Jeff Layton | 121b046 | 2012-05-15 12:21:10 -0400 | [diff] [blame] | 548 | return server->ops->send_cancel ? |
| 549 | server->ops->send_cancel(server, buf, mid) : 0; |
Jeff Layton | 76dcc26 | 2011-01-11 07:24:24 -0500 | [diff] [blame] | 550 | } |
| 551 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | int |
Jeff Layton | 2c8f981 | 2011-05-19 16:22:52 -0400 | [diff] [blame] | 553 | cifs_check_receive(struct mid_q_entry *mid, struct TCP_Server_Info *server, |
| 554 | bool log_error) |
| 555 | { |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 556 | unsigned int len = get_rfc1002_length(mid->resp_buf) + 4; |
Jeff Layton | 826a95e | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 557 | |
| 558 | dump_smb(mid->resp_buf, min_t(u32, 92, len)); |
Jeff Layton | 2c8f981 | 2011-05-19 16:22:52 -0400 | [diff] [blame] | 559 | |
| 560 | /* convert the length into a more usable form */ |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 561 | if (server->sec_mode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) { |
Jeff Layton | 826a95e | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 562 | struct kvec iov; |
Steve French | 985e4ff0 | 2012-08-03 09:42:45 -0500 | [diff] [blame] | 563 | int rc = 0; |
Jeff Layton | bf5ea0e | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 564 | struct smb_rqst rqst = { .rq_iov = &iov, |
| 565 | .rq_nvec = 1 }; |
Jeff Layton | 826a95e | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 566 | |
| 567 | iov.iov_base = mid->resp_buf; |
| 568 | iov.iov_len = len; |
Jeff Layton | 2c8f981 | 2011-05-19 16:22:52 -0400 | [diff] [blame] | 569 | /* FIXME: add code to kill session */ |
Jeff Layton | bf5ea0e | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 570 | rc = cifs_verify_signature(&rqst, server, |
Steve French | 985e4ff0 | 2012-08-03 09:42:45 -0500 | [diff] [blame] | 571 | mid->sequence_number + 1); |
| 572 | if (rc) |
| 573 | cERROR(1, "SMB signature verification returned error = " |
| 574 | "%d", rc); |
Jeff Layton | 2c8f981 | 2011-05-19 16:22:52 -0400 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | /* BB special case reconnect tid and uid here? */ |
| 578 | return map_smb_to_linux_error(mid->resp_buf, log_error); |
| 579 | } |
| 580 | |
Pavel Shilovsky | 082d064 | 2012-05-17 12:18:21 +0400 | [diff] [blame] | 581 | int |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 582 | cifs_setup_request(struct cifs_ses *ses, struct kvec *iov, |
| 583 | unsigned int nvec, struct mid_q_entry **ret_mid) |
| 584 | { |
| 585 | int rc; |
| 586 | struct smb_hdr *hdr = (struct smb_hdr *)iov[0].iov_base; |
| 587 | struct mid_q_entry *mid; |
| 588 | |
| 589 | rc = allocate_mid(ses, hdr, &mid); |
| 590 | if (rc) |
| 591 | return rc; |
Jeff Layton | 762a420 | 2012-07-23 13:28:38 -0400 | [diff] [blame] | 592 | rc = cifs_sign_smbv(iov, nvec, ses->server, &mid->sequence_number); |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 593 | if (rc) |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 594 | cifs_delete_mid(mid); |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 595 | *ret_mid = mid; |
| 596 | return rc; |
| 597 | } |
| 598 | |
Jeff Layton | 2c8f981 | 2011-05-19 16:22:52 -0400 | [diff] [blame] | 599 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 600 | SendReceive2(const unsigned int xid, struct cifs_ses *ses, |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 601 | struct kvec *iov, int n_vec, int *resp_buf_type /* ret */, |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 602 | const int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | { |
| 604 | int rc = 0; |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 605 | int timeout, optype; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 606 | struct mid_q_entry *midQ; |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 607 | char *buf = iov[0].iov_base; |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 608 | unsigned int credits = 1; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 609 | |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 610 | timeout = flags & CIFS_TIMEOUT_MASK; |
| 611 | optype = flags & CIFS_OP_MASK; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 612 | |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 613 | *resp_buf_type = CIFS_NO_BUFFER; /* no response buf yet */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 615 | if ((ses == NULL) || (ses->server == NULL)) { |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 616 | cifs_small_buf_release(buf); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 617 | cERROR(1, "Null session"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | return -EIO; |
| 619 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 621 | if (ses->server->tcpStatus == CifsExiting) { |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 622 | cifs_small_buf_release(buf); |
Steve French | 31ca3bc | 2005-04-28 22:41:11 -0700 | [diff] [blame] | 623 | return -ENOENT; |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 624 | } |
Steve French | 31ca3bc | 2005-04-28 22:41:11 -0700 | [diff] [blame] | 625 | |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 626 | /* |
| 627 | * Ensure that we do not send more than 50 overlapping requests |
| 628 | * to the same server. We may make this configurable later or |
| 629 | * use ses->maxReq. |
| 630 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 632 | rc = wait_for_free_request(ses->server, timeout, optype); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 633 | if (rc) { |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 634 | cifs_small_buf_release(buf); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 635 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | } |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 637 | |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 638 | /* |
| 639 | * Make sure that we sign in the same order that we send on this socket |
| 640 | * and avoid races inside tcp sendmsg code that could cause corruption |
| 641 | * of smb data. |
| 642 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | |
Jeff Layton | 72ca545 | 2008-12-01 07:09:36 -0500 | [diff] [blame] | 644 | mutex_lock(&ses->server->srv_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | |
Pavel Shilovsky | 082d064 | 2012-05-17 12:18:21 +0400 | [diff] [blame] | 646 | rc = ses->server->ops->setup_request(ses, iov, n_vec, &midQ); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 647 | if (rc) { |
Jeff Layton | 72ca545 | 2008-12-01 07:09:36 -0500 | [diff] [blame] | 648 | mutex_unlock(&ses->server->srv_mutex); |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 649 | cifs_small_buf_release(buf); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 650 | /* Update # of requests on wire to server */ |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 651 | add_credits(ses->server, 1, optype); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 652 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 655 | midQ->mid_state = MID_REQUEST_SUBMITTED; |
Steve French | 789e666 | 2011-08-09 18:44:44 +0000 | [diff] [blame] | 656 | cifs_in_send_inc(ses->server); |
Jeff Layton | 0496e02 | 2008-12-30 12:39:16 -0500 | [diff] [blame] | 657 | rc = smb_sendv(ses->server, iov, n_vec); |
Steve French | 789e666 | 2011-08-09 18:44:44 +0000 | [diff] [blame] | 658 | cifs_in_send_dec(ses->server); |
| 659 | cifs_save_when_sent(midQ); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 660 | |
Jeff Layton | 72ca545 | 2008-12-01 07:09:36 -0500 | [diff] [blame] | 661 | mutex_unlock(&ses->server->srv_mutex); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 662 | |
Jeff Layton | 2db7c58 | 2011-01-28 07:08:28 -0500 | [diff] [blame] | 663 | if (rc < 0) { |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 664 | cifs_small_buf_release(buf); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 665 | goto out; |
Jeff Layton | 2db7c58 | 2011-01-28 07:08:28 -0500 | [diff] [blame] | 666 | } |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 667 | |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 668 | if (timeout == CIFS_ASYNC_OP) { |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 669 | cifs_small_buf_release(buf); |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 670 | goto out; |
Jeff Layton | 2db7c58 | 2011-01-28 07:08:28 -0500 | [diff] [blame] | 671 | } |
Jeff Layton | 0ade640 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 672 | |
| 673 | rc = wait_for_response(ses->server, midQ); |
Jeff Layton | 1be912d | 2011-01-28 07:08:28 -0500 | [diff] [blame] | 674 | if (rc != 0) { |
Jeff Layton | 121b046 | 2012-05-15 12:21:10 -0400 | [diff] [blame] | 675 | send_cancel(ses->server, buf, midQ); |
Jeff Layton | 1be912d | 2011-01-28 07:08:28 -0500 | [diff] [blame] | 676 | spin_lock(&GlobalMid_Lock); |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 677 | if (midQ->mid_state == MID_REQUEST_SUBMITTED) { |
Jeff Layton | 1be912d | 2011-01-28 07:08:28 -0500 | [diff] [blame] | 678 | midQ->callback = DeleteMidQEntry; |
| 679 | spin_unlock(&GlobalMid_Lock); |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 680 | cifs_small_buf_release(buf); |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 681 | add_credits(ses->server, 1, optype); |
Jeff Layton | 1be912d | 2011-01-28 07:08:28 -0500 | [diff] [blame] | 682 | return rc; |
| 683 | } |
| 684 | spin_unlock(&GlobalMid_Lock); |
| 685 | } |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 686 | |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 687 | cifs_small_buf_release(buf); |
Jeff Layton | 2db7c58 | 2011-01-28 07:08:28 -0500 | [diff] [blame] | 688 | |
Jeff Layton | 3c1105d | 2011-05-22 07:09:13 -0400 | [diff] [blame] | 689 | rc = cifs_sync_mid_result(midQ, ses->server); |
Jeff Layton | 053d503 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 690 | if (rc != 0) { |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 691 | add_credits(ses->server, 1, optype); |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 692 | return rc; |
| 693 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 694 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 695 | if (!midQ->resp_buf || midQ->mid_state != MID_RESPONSE_RECEIVED) { |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 696 | rc = -EIO; |
Jeff Layton | 2c8f981 | 2011-05-19 16:22:52 -0400 | [diff] [blame] | 697 | cFYI(1, "Bad MID state?"); |
Steve French | 2b2bdfb | 2008-12-11 17:26:54 +0000 | [diff] [blame] | 698 | goto out; |
| 699 | } |
Steve French | 84afc29 | 2005-12-02 13:32:45 -0800 | [diff] [blame] | 700 | |
Pavel Shilovsky | 792af7b | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 701 | buf = (char *)midQ->resp_buf; |
| 702 | iov[0].iov_base = buf; |
| 703 | iov[0].iov_len = get_rfc1002_length(buf) + 4; |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 704 | if (midQ->large_buf) |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 705 | *resp_buf_type = CIFS_LARGE_BUFFER; |
Jeff Layton | 2c8f981 | 2011-05-19 16:22:52 -0400 | [diff] [blame] | 706 | else |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 707 | *resp_buf_type = CIFS_SMALL_BUFFER; |
| 708 | |
| 709 | credits = ses->server->ops->get_credits(midQ); |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 710 | |
Pavel Shilovsky | 082d064 | 2012-05-17 12:18:21 +0400 | [diff] [blame] | 711 | rc = ses->server->ops->check_receive(midQ, ses->server, |
| 712 | flags & CIFS_LOG_ERROR); |
Steve French | 2b2bdfb | 2008-12-11 17:26:54 +0000 | [diff] [blame] | 713 | |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 714 | /* mark it so buf will not be freed by cifs_delete_mid */ |
Jeff Layton | 2c8f981 | 2011-05-19 16:22:52 -0400 | [diff] [blame] | 715 | if ((flags & CIFS_NO_RESP) == 0) |
| 716 | midQ->resp_buf = NULL; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 717 | out: |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 718 | cifs_delete_mid(midQ); |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 719 | add_credits(ses->server, credits, optype); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | |
| 721 | return rc; |
| 722 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | |
| 724 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 725 | SendReceive(const unsigned int xid, struct cifs_ses *ses, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | struct smb_hdr *in_buf, struct smb_hdr *out_buf, |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 727 | int *pbytes_returned, const int timeout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | { |
| 729 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | struct mid_q_entry *midQ; |
| 731 | |
| 732 | if (ses == NULL) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 733 | cERROR(1, "Null smb session"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | return -EIO; |
| 735 | } |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 736 | if (ses->server == NULL) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 737 | cERROR(1, "Null tcp session"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | return -EIO; |
| 739 | } |
| 740 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 741 | if (ses->server->tcpStatus == CifsExiting) |
Steve French | 31ca3bc | 2005-04-28 22:41:11 -0700 | [diff] [blame] | 742 | return -ENOENT; |
| 743 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 744 | /* Ensure that we do not send more than 50 overlapping requests |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | to the same server. We may make this configurable later or |
| 746 | use ses->maxReq */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 748 | if (be32_to_cpu(in_buf->smb_buf_length) > CIFSMaxBufSize + |
| 749 | MAX_CIFS_HDR_SIZE - 4) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 750 | cERROR(1, "Illegal length, greater than maximum frame, %d", |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 751 | be32_to_cpu(in_buf->smb_buf_length)); |
Volker Lendecke | 6d9c6d5 | 2008-12-08 20:50:24 +0000 | [diff] [blame] | 752 | return -EIO; |
| 753 | } |
| 754 | |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 755 | rc = wait_for_free_request(ses->server, timeout, 0); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 756 | if (rc) |
| 757 | return rc; |
| 758 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 759 | /* 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] | 760 | and avoid races inside tcp sendmsg code that could cause corruption |
| 761 | of smb data */ |
| 762 | |
Jeff Layton | 72ca545 | 2008-12-01 07:09:36 -0500 | [diff] [blame] | 763 | mutex_lock(&ses->server->srv_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 765 | rc = allocate_mid(ses, in_buf, &midQ); |
| 766 | if (rc) { |
Jeff Layton | 72ca545 | 2008-12-01 07:09:36 -0500 | [diff] [blame] | 767 | mutex_unlock(&ses->server->srv_mutex); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 768 | /* Update # of requests on wire to server */ |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 769 | add_credits(ses->server, 1, 0); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 770 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | } |
| 772 | |
Steve French | ad009ac | 2005-04-28 22:41:05 -0700 | [diff] [blame] | 773 | rc = cifs_sign_smb(in_buf, ses->server, &midQ->sequence_number); |
Volker Lendecke | 829049c | 2008-12-06 16:00:53 +0100 | [diff] [blame] | 774 | if (rc) { |
| 775 | mutex_unlock(&ses->server->srv_mutex); |
| 776 | goto out; |
| 777 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 779 | midQ->mid_state = MID_REQUEST_SUBMITTED; |
Steve French | 789e666 | 2011-08-09 18:44:44 +0000 | [diff] [blame] | 780 | |
| 781 | cifs_in_send_inc(ses->server); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 782 | rc = smb_send(ses->server, in_buf, be32_to_cpu(in_buf->smb_buf_length)); |
Steve French | 789e666 | 2011-08-09 18:44:44 +0000 | [diff] [blame] | 783 | cifs_in_send_dec(ses->server); |
| 784 | cifs_save_when_sent(midQ); |
Jeff Layton | 72ca545 | 2008-12-01 07:09:36 -0500 | [diff] [blame] | 785 | mutex_unlock(&ses->server->srv_mutex); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 786 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 787 | if (rc < 0) |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 788 | goto out; |
| 789 | |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 790 | if (timeout == CIFS_ASYNC_OP) |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 791 | goto out; |
Jeff Layton | 0ade640 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 792 | |
| 793 | rc = wait_for_response(ses->server, midQ); |
Jeff Layton | 1be912d | 2011-01-28 07:08:28 -0500 | [diff] [blame] | 794 | if (rc != 0) { |
Jeff Layton | 121b046 | 2012-05-15 12:21:10 -0400 | [diff] [blame] | 795 | send_cancel(ses->server, in_buf, midQ); |
Jeff Layton | 1be912d | 2011-01-28 07:08:28 -0500 | [diff] [blame] | 796 | spin_lock(&GlobalMid_Lock); |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 797 | if (midQ->mid_state == MID_REQUEST_SUBMITTED) { |
Jeff Layton | 1be912d | 2011-01-28 07:08:28 -0500 | [diff] [blame] | 798 | /* no longer considered to be "in-flight" */ |
| 799 | midQ->callback = DeleteMidQEntry; |
| 800 | spin_unlock(&GlobalMid_Lock); |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 801 | add_credits(ses->server, 1, 0); |
Jeff Layton | 1be912d | 2011-01-28 07:08:28 -0500 | [diff] [blame] | 802 | return rc; |
| 803 | } |
| 804 | spin_unlock(&GlobalMid_Lock); |
| 805 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | |
Jeff Layton | 3c1105d | 2011-05-22 07:09:13 -0400 | [diff] [blame] | 807 | rc = cifs_sync_mid_result(midQ, ses->server); |
Jeff Layton | 053d503 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 808 | if (rc != 0) { |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 809 | add_credits(ses->server, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | return rc; |
| 811 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 812 | |
Jeff Layton | 2c8f981 | 2011-05-19 16:22:52 -0400 | [diff] [blame] | 813 | if (!midQ->resp_buf || !out_buf || |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 814 | midQ->mid_state != MID_RESPONSE_RECEIVED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | rc = -EIO; |
Jeff Layton | 2c8f981 | 2011-05-19 16:22:52 -0400 | [diff] [blame] | 816 | cERROR(1, "Bad MID state?"); |
Steve French | 2b2bdfb | 2008-12-11 17:26:54 +0000 | [diff] [blame] | 817 | goto out; |
| 818 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | |
Pavel Shilovsky | d4e4854 | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 820 | *pbytes_returned = get_rfc1002_length(midQ->resp_buf); |
Jeff Layton | 2c8f981 | 2011-05-19 16:22:52 -0400 | [diff] [blame] | 821 | memcpy(out_buf, midQ->resp_buf, *pbytes_returned + 4); |
| 822 | rc = cifs_check_receive(midQ, ses->server, 0); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 823 | out: |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 824 | cifs_delete_mid(midQ); |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 825 | add_credits(ses->server, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | |
| 827 | return rc; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 828 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 830 | /* We send a LOCKINGX_CANCEL_LOCK to cause the Windows |
| 831 | blocking lock to return. */ |
| 832 | |
| 833 | static int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 834 | send_lock_cancel(const unsigned int xid, struct cifs_tcon *tcon, |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 835 | struct smb_hdr *in_buf, |
| 836 | struct smb_hdr *out_buf) |
| 837 | { |
| 838 | int bytes_returned; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 839 | struct cifs_ses *ses = tcon->ses; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 840 | LOCK_REQ *pSMB = (LOCK_REQ *)in_buf; |
| 841 | |
| 842 | /* We just modify the current in_buf to change |
| 843 | the type of lock from LOCKING_ANDX_SHARED_LOCK |
| 844 | or LOCKING_ANDX_EXCLUSIVE_LOCK to |
| 845 | LOCKING_ANDX_CANCEL_LOCK. */ |
| 846 | |
| 847 | pSMB->LockType = LOCKING_ANDX_CANCEL_LOCK|LOCKING_ANDX_LARGE_FILES; |
| 848 | pSMB->Timeout = 0; |
Pavel Shilovsky | 8825736 | 2012-05-23 14:01:59 +0400 | [diff] [blame] | 849 | pSMB->hdr.Mid = get_next_mid(ses->server); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 850 | |
| 851 | return SendReceive(xid, ses, in_buf, out_buf, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 852 | &bytes_returned, 0); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | int |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 856 | SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon, |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 857 | struct smb_hdr *in_buf, struct smb_hdr *out_buf, |
| 858 | int *pbytes_returned) |
| 859 | { |
| 860 | int rc = 0; |
| 861 | int rstart = 0; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 862 | struct mid_q_entry *midQ; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 863 | struct cifs_ses *ses; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 864 | |
| 865 | if (tcon == NULL || tcon->ses == NULL) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 866 | cERROR(1, "Null smb session"); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 867 | return -EIO; |
| 868 | } |
| 869 | ses = tcon->ses; |
| 870 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 871 | if (ses->server == NULL) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 872 | cERROR(1, "Null tcp session"); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 873 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | } |
| 875 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 876 | if (ses->server->tcpStatus == CifsExiting) |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 877 | return -ENOENT; |
| 878 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 879 | /* Ensure that we do not send more than 50 overlapping requests |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 880 | to the same server. We may make this configurable later or |
| 881 | use ses->maxReq */ |
| 882 | |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 883 | if (be32_to_cpu(in_buf->smb_buf_length) > CIFSMaxBufSize + |
| 884 | MAX_CIFS_HDR_SIZE - 4) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 885 | cERROR(1, "Illegal length, greater than maximum frame, %d", |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 886 | be32_to_cpu(in_buf->smb_buf_length)); |
Volker Lendecke | 6d9c6d5 | 2008-12-08 20:50:24 +0000 | [diff] [blame] | 887 | return -EIO; |
| 888 | } |
| 889 | |
Pavel Shilovsky | a891f0f | 2012-05-23 16:14:34 +0400 | [diff] [blame] | 890 | rc = wait_for_free_request(ses->server, CIFS_BLOCKING_OP, 0); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 891 | if (rc) |
| 892 | return rc; |
| 893 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 894 | /* 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] | 895 | and avoid races inside tcp sendmsg code that could cause corruption |
| 896 | of smb data */ |
| 897 | |
Jeff Layton | 72ca545 | 2008-12-01 07:09:36 -0500 | [diff] [blame] | 898 | mutex_lock(&ses->server->srv_mutex); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 899 | |
| 900 | rc = allocate_mid(ses, in_buf, &midQ); |
| 901 | if (rc) { |
Jeff Layton | 72ca545 | 2008-12-01 07:09:36 -0500 | [diff] [blame] | 902 | mutex_unlock(&ses->server->srv_mutex); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 903 | return rc; |
| 904 | } |
| 905 | |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 906 | rc = cifs_sign_smb(in_buf, ses->server, &midQ->sequence_number); |
Volker Lendecke | 829049c | 2008-12-06 16:00:53 +0100 | [diff] [blame] | 907 | if (rc) { |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 908 | cifs_delete_mid(midQ); |
Volker Lendecke | 829049c | 2008-12-06 16:00:53 +0100 | [diff] [blame] | 909 | mutex_unlock(&ses->server->srv_mutex); |
| 910 | return rc; |
| 911 | } |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 912 | |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 913 | midQ->mid_state = MID_REQUEST_SUBMITTED; |
Steve French | 789e666 | 2011-08-09 18:44:44 +0000 | [diff] [blame] | 914 | cifs_in_send_inc(ses->server); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 915 | rc = smb_send(ses->server, in_buf, be32_to_cpu(in_buf->smb_buf_length)); |
Steve French | 789e666 | 2011-08-09 18:44:44 +0000 | [diff] [blame] | 916 | cifs_in_send_dec(ses->server); |
| 917 | cifs_save_when_sent(midQ); |
Jeff Layton | 72ca545 | 2008-12-01 07:09:36 -0500 | [diff] [blame] | 918 | mutex_unlock(&ses->server->srv_mutex); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 919 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 920 | if (rc < 0) { |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 921 | cifs_delete_mid(midQ); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 922 | return rc; |
| 923 | } |
| 924 | |
| 925 | /* Wait for a reply - allow signals to interrupt. */ |
| 926 | rc = wait_event_interruptible(ses->server->response_q, |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 927 | (!(midQ->mid_state == MID_REQUEST_SUBMITTED)) || |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 928 | ((ses->server->tcpStatus != CifsGood) && |
| 929 | (ses->server->tcpStatus != CifsNew))); |
| 930 | |
| 931 | /* Were we interrupted by a signal ? */ |
| 932 | if ((rc == -ERESTARTSYS) && |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 933 | (midQ->mid_state == MID_REQUEST_SUBMITTED) && |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 934 | ((ses->server->tcpStatus == CifsGood) || |
| 935 | (ses->server->tcpStatus == CifsNew))) { |
| 936 | |
| 937 | if (in_buf->Command == SMB_COM_TRANSACTION2) { |
| 938 | /* POSIX lock. We send a NT_CANCEL SMB to cause the |
| 939 | blocking lock to return. */ |
Jeff Layton | 121b046 | 2012-05-15 12:21:10 -0400 | [diff] [blame] | 940 | rc = send_cancel(ses->server, in_buf, midQ); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 941 | if (rc) { |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 942 | cifs_delete_mid(midQ); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 943 | return rc; |
| 944 | } |
| 945 | } else { |
| 946 | /* Windows lock. We send a LOCKINGX_CANCEL_LOCK |
| 947 | to cause the blocking lock to return. */ |
| 948 | |
| 949 | rc = send_lock_cancel(xid, tcon, in_buf, out_buf); |
| 950 | |
| 951 | /* If we get -ENOLCK back the lock may have |
| 952 | already been removed. Don't exit in this case. */ |
| 953 | if (rc && rc != -ENOLCK) { |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 954 | cifs_delete_mid(midQ); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 955 | return rc; |
| 956 | } |
| 957 | } |
| 958 | |
Jeff Layton | 1be912d | 2011-01-28 07:08:28 -0500 | [diff] [blame] | 959 | rc = wait_for_response(ses->server, midQ); |
| 960 | if (rc) { |
Jeff Layton | 121b046 | 2012-05-15 12:21:10 -0400 | [diff] [blame] | 961 | send_cancel(ses->server, in_buf, midQ); |
Jeff Layton | 1be912d | 2011-01-28 07:08:28 -0500 | [diff] [blame] | 962 | spin_lock(&GlobalMid_Lock); |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 963 | if (midQ->mid_state == MID_REQUEST_SUBMITTED) { |
Jeff Layton | 1be912d | 2011-01-28 07:08:28 -0500 | [diff] [blame] | 964 | /* no longer considered to be "in-flight" */ |
| 965 | midQ->callback = DeleteMidQEntry; |
| 966 | spin_unlock(&GlobalMid_Lock); |
| 967 | return rc; |
| 968 | } |
| 969 | spin_unlock(&GlobalMid_Lock); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 970 | } |
Jeff Layton | 1be912d | 2011-01-28 07:08:28 -0500 | [diff] [blame] | 971 | |
| 972 | /* We got the response - restart system call. */ |
| 973 | rstart = 1; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 974 | } |
| 975 | |
Jeff Layton | 3c1105d | 2011-05-22 07:09:13 -0400 | [diff] [blame] | 976 | rc = cifs_sync_mid_result(midQ, ses->server); |
Jeff Layton | 053d503 | 2011-01-11 07:24:02 -0500 | [diff] [blame] | 977 | if (rc != 0) |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 978 | return rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 979 | |
Volker Lendecke | 17c8bfe | 2008-12-06 16:38:19 +0100 | [diff] [blame] | 980 | /* rcvd frame is ok */ |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 981 | if (out_buf == NULL || midQ->mid_state != MID_RESPONSE_RECEIVED) { |
Volker Lendecke | 17c8bfe | 2008-12-06 16:38:19 +0100 | [diff] [blame] | 982 | rc = -EIO; |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 983 | cERROR(1, "Bad MID state?"); |
Volker Lendecke | 698e96a | 2008-12-06 16:39:31 +0100 | [diff] [blame] | 984 | goto out; |
Volker Lendecke | 17c8bfe | 2008-12-06 16:38:19 +0100 | [diff] [blame] | 985 | } |
| 986 | |
Pavel Shilovsky | d4e4854 | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 987 | *pbytes_returned = get_rfc1002_length(midQ->resp_buf); |
Jeff Layton | 2c8f981 | 2011-05-19 16:22:52 -0400 | [diff] [blame] | 988 | memcpy(out_buf, midQ->resp_buf, *pbytes_returned + 4); |
| 989 | rc = cifs_check_receive(midQ, ses->server, 0); |
Volker Lendecke | 17c8bfe | 2008-12-06 16:38:19 +0100 | [diff] [blame] | 990 | out: |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 991 | cifs_delete_mid(midQ); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 992 | if (rstart && rc == -EACCES) |
| 993 | return -ERESTARTSYS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | return rc; |
| 995 | } |