| .. | .. |
|---|
| 33 | 33 | #include <linux/uaccess.h> |
|---|
| 34 | 34 | #include <asm/processor.h> |
|---|
| 35 | 35 | #include <linux/mempool.h> |
|---|
| 36 | +#include <linux/sched/signal.h> |
|---|
| 36 | 37 | #include "cifspdu.h" |
|---|
| 37 | 38 | #include "cifsglob.h" |
|---|
| 38 | 39 | #include "cifsproto.h" |
|---|
| .. | .. |
|---|
| 75 | 76 | * The default is for the mid to be synchronous, so the |
|---|
| 76 | 77 | * default callback just wakes up the current task. |
|---|
| 77 | 78 | */ |
|---|
| 79 | + get_task_struct(current); |
|---|
| 80 | + temp->creator = current; |
|---|
| 78 | 81 | temp->callback = cifs_wake_up_task; |
|---|
| 79 | 82 | temp->callback_data = current; |
|---|
| 80 | 83 | |
|---|
| .. | .. |
|---|
| 85 | 88 | |
|---|
| 86 | 89 | static void _cifs_mid_q_entry_release(struct kref *refcount) |
|---|
| 87 | 90 | { |
|---|
| 88 | | - struct mid_q_entry *mid = container_of(refcount, struct mid_q_entry, |
|---|
| 89 | | - refcount); |
|---|
| 91 | + struct mid_q_entry *midEntry = |
|---|
| 92 | + container_of(refcount, struct mid_q_entry, refcount); |
|---|
| 93 | +#ifdef CONFIG_CIFS_STATS2 |
|---|
| 94 | + __le16 command = midEntry->server->vals->lock_cmd; |
|---|
| 95 | + __u16 smb_cmd = le16_to_cpu(midEntry->command); |
|---|
| 96 | + unsigned long now; |
|---|
| 97 | + unsigned long roundtrip_time; |
|---|
| 98 | +#endif |
|---|
| 99 | + struct TCP_Server_Info *server = midEntry->server; |
|---|
| 90 | 100 | |
|---|
| 91 | | - mempool_free(mid, cifs_mid_poolp); |
|---|
| 101 | + if (midEntry->resp_buf && (midEntry->mid_flags & MID_WAIT_CANCELLED) && |
|---|
| 102 | + midEntry->mid_state == MID_RESPONSE_RECEIVED && |
|---|
| 103 | + server->ops->handle_cancelled_mid) |
|---|
| 104 | + server->ops->handle_cancelled_mid(midEntry, server); |
|---|
| 105 | + |
|---|
| 106 | + midEntry->mid_state = MID_FREE; |
|---|
| 107 | + atomic_dec(&midCount); |
|---|
| 108 | + if (midEntry->large_buf) |
|---|
| 109 | + cifs_buf_release(midEntry->resp_buf); |
|---|
| 110 | + else |
|---|
| 111 | + cifs_small_buf_release(midEntry->resp_buf); |
|---|
| 112 | +#ifdef CONFIG_CIFS_STATS2 |
|---|
| 113 | + now = jiffies; |
|---|
| 114 | + if (now < midEntry->when_alloc) |
|---|
| 115 | + cifs_server_dbg(VFS, "Invalid mid allocation time\n"); |
|---|
| 116 | + roundtrip_time = now - midEntry->when_alloc; |
|---|
| 117 | + |
|---|
| 118 | + if (smb_cmd < NUMBER_OF_SMB2_COMMANDS) { |
|---|
| 119 | + if (atomic_read(&server->num_cmds[smb_cmd]) == 0) { |
|---|
| 120 | + server->slowest_cmd[smb_cmd] = roundtrip_time; |
|---|
| 121 | + server->fastest_cmd[smb_cmd] = roundtrip_time; |
|---|
| 122 | + } else { |
|---|
| 123 | + if (server->slowest_cmd[smb_cmd] < roundtrip_time) |
|---|
| 124 | + server->slowest_cmd[smb_cmd] = roundtrip_time; |
|---|
| 125 | + else if (server->fastest_cmd[smb_cmd] > roundtrip_time) |
|---|
| 126 | + server->fastest_cmd[smb_cmd] = roundtrip_time; |
|---|
| 127 | + } |
|---|
| 128 | + cifs_stats_inc(&server->num_cmds[smb_cmd]); |
|---|
| 129 | + server->time_per_cmd[smb_cmd] += roundtrip_time; |
|---|
| 130 | + } |
|---|
| 131 | + /* |
|---|
| 132 | + * commands taking longer than one second (default) can be indications |
|---|
| 133 | + * that something is wrong, unless it is quite a slow link or a very |
|---|
| 134 | + * busy server. Note that this calc is unlikely or impossible to wrap |
|---|
| 135 | + * as long as slow_rsp_threshold is not set way above recommended max |
|---|
| 136 | + * value (32767 ie 9 hours) and is generally harmless even if wrong |
|---|
| 137 | + * since only affects debug counters - so leaving the calc as simple |
|---|
| 138 | + * comparison rather than doing multiple conversions and overflow |
|---|
| 139 | + * checks |
|---|
| 140 | + */ |
|---|
| 141 | + if ((slow_rsp_threshold != 0) && |
|---|
| 142 | + time_after(now, midEntry->when_alloc + (slow_rsp_threshold * HZ)) && |
|---|
| 143 | + (midEntry->command != command)) { |
|---|
| 144 | + /* |
|---|
| 145 | + * smb2slowcmd[NUMBER_OF_SMB2_COMMANDS] counts by command |
|---|
| 146 | + * NB: le16_to_cpu returns unsigned so can not be negative below |
|---|
| 147 | + */ |
|---|
| 148 | + if (smb_cmd < NUMBER_OF_SMB2_COMMANDS) |
|---|
| 149 | + cifs_stats_inc(&server->smb2slowcmd[smb_cmd]); |
|---|
| 150 | + |
|---|
| 151 | + trace_smb3_slow_rsp(smb_cmd, midEntry->mid, midEntry->pid, |
|---|
| 152 | + midEntry->when_sent, midEntry->when_received); |
|---|
| 153 | + if (cifsFYI & CIFS_TIMER) { |
|---|
| 154 | + pr_debug("slow rsp: cmd %d mid %llu", |
|---|
| 155 | + midEntry->command, midEntry->mid); |
|---|
| 156 | + cifs_info("A: 0x%lx S: 0x%lx R: 0x%lx\n", |
|---|
| 157 | + now - midEntry->when_alloc, |
|---|
| 158 | + now - midEntry->when_sent, |
|---|
| 159 | + now - midEntry->when_received); |
|---|
| 160 | + } |
|---|
| 161 | + } |
|---|
| 162 | +#endif |
|---|
| 163 | + put_task_struct(midEntry->creator); |
|---|
| 164 | + |
|---|
| 165 | + mempool_free(midEntry, cifs_mid_poolp); |
|---|
| 92 | 166 | } |
|---|
| 93 | 167 | |
|---|
| 94 | 168 | void cifs_mid_q_entry_release(struct mid_q_entry *midEntry) |
|---|
| .. | .. |
|---|
| 98 | 172 | spin_unlock(&GlobalMid_Lock); |
|---|
| 99 | 173 | } |
|---|
| 100 | 174 | |
|---|
| 101 | | -void |
|---|
| 102 | | -DeleteMidQEntry(struct mid_q_entry *midEntry) |
|---|
| 175 | +void DeleteMidQEntry(struct mid_q_entry *midEntry) |
|---|
| 103 | 176 | { |
|---|
| 104 | | -#ifdef CONFIG_CIFS_STATS2 |
|---|
| 105 | | - __le16 command = midEntry->server->vals->lock_cmd; |
|---|
| 106 | | - unsigned long now; |
|---|
| 107 | | -#endif |
|---|
| 108 | | - midEntry->mid_state = MID_FREE; |
|---|
| 109 | | - atomic_dec(&midCount); |
|---|
| 110 | | - if (midEntry->large_buf) |
|---|
| 111 | | - cifs_buf_release(midEntry->resp_buf); |
|---|
| 112 | | - else |
|---|
| 113 | | - cifs_small_buf_release(midEntry->resp_buf); |
|---|
| 114 | | -#ifdef CONFIG_CIFS_STATS2 |
|---|
| 115 | | - now = jiffies; |
|---|
| 116 | | - /* commands taking longer than one second are indications that |
|---|
| 117 | | - something is wrong, unless it is quite a slow link or server */ |
|---|
| 118 | | - if (time_after(now, midEntry->when_alloc + HZ) && |
|---|
| 119 | | - (midEntry->command != command)) { |
|---|
| 120 | | - /* smb2slowcmd[NUMBER_OF_SMB2_COMMANDS] counts by command */ |
|---|
| 121 | | - if ((le16_to_cpu(midEntry->command) < NUMBER_OF_SMB2_COMMANDS) && |
|---|
| 122 | | - (le16_to_cpu(midEntry->command) >= 0)) |
|---|
| 123 | | - cifs_stats_inc(&midEntry->server->smb2slowcmd[le16_to_cpu(midEntry->command)]); |
|---|
| 124 | | - |
|---|
| 125 | | - trace_smb3_slow_rsp(le16_to_cpu(midEntry->command), |
|---|
| 126 | | - midEntry->mid, midEntry->pid, |
|---|
| 127 | | - midEntry->when_sent, midEntry->when_received); |
|---|
| 128 | | - if (cifsFYI & CIFS_TIMER) { |
|---|
| 129 | | - pr_debug(" CIFS slow rsp: cmd %d mid %llu", |
|---|
| 130 | | - midEntry->command, midEntry->mid); |
|---|
| 131 | | - pr_info(" A: 0x%lx S: 0x%lx R: 0x%lx\n", |
|---|
| 132 | | - now - midEntry->when_alloc, |
|---|
| 133 | | - now - midEntry->when_sent, |
|---|
| 134 | | - now - midEntry->when_received); |
|---|
| 135 | | - } |
|---|
| 136 | | - } |
|---|
| 137 | | -#endif |
|---|
| 138 | 177 | cifs_mid_q_entry_release(midEntry); |
|---|
| 139 | 178 | } |
|---|
| 140 | 179 | |
|---|
| .. | .. |
|---|
| 142 | 181 | cifs_delete_mid(struct mid_q_entry *mid) |
|---|
| 143 | 182 | { |
|---|
| 144 | 183 | spin_lock(&GlobalMid_Lock); |
|---|
| 145 | | - list_del_init(&mid->qhead); |
|---|
| 146 | | - mid->mid_flags |= MID_DELETED; |
|---|
| 184 | + if (!(mid->mid_flags & MID_DELETED)) { |
|---|
| 185 | + list_del_init(&mid->qhead); |
|---|
| 186 | + mid->mid_flags |= MID_DELETED; |
|---|
| 187 | + } |
|---|
| 147 | 188 | spin_unlock(&GlobalMid_Lock); |
|---|
| 148 | 189 | |
|---|
| 149 | 190 | DeleteMidQEntry(mid); |
|---|
| .. | .. |
|---|
| 168 | 209 | |
|---|
| 169 | 210 | *sent = 0; |
|---|
| 170 | 211 | |
|---|
| 171 | | - smb_msg->msg_name = (struct sockaddr *) &server->dstaddr; |
|---|
| 172 | | - smb_msg->msg_namelen = sizeof(struct sockaddr); |
|---|
| 173 | | - smb_msg->msg_control = NULL; |
|---|
| 174 | | - smb_msg->msg_controllen = 0; |
|---|
| 175 | 212 | if (server->noblocksnd) |
|---|
| 176 | 213 | smb_msg->msg_flags = MSG_DONTWAIT + MSG_NOSIGNAL; |
|---|
| 177 | 214 | else |
|---|
| .. | .. |
|---|
| 201 | 238 | retries++; |
|---|
| 202 | 239 | if (retries >= 14 || |
|---|
| 203 | 240 | (!server->noblocksnd && (retries > 2))) { |
|---|
| 204 | | - cifs_dbg(VFS, "sends on sock %p stuck for 15 seconds\n", |
|---|
| 241 | + cifs_server_dbg(VFS, "sends on sock %p stuck for 15 seconds\n", |
|---|
| 205 | 242 | ssocket); |
|---|
| 206 | 243 | return -EAGAIN; |
|---|
| 207 | 244 | } |
|---|
| .. | .. |
|---|
| 215 | 252 | if (rc == 0) { |
|---|
| 216 | 253 | /* should never happen, letting socket clear before |
|---|
| 217 | 254 | retrying is our only obvious option here */ |
|---|
| 218 | | - cifs_dbg(VFS, "tcp sent no data\n"); |
|---|
| 255 | + cifs_server_dbg(VFS, "tcp sent no data\n"); |
|---|
| 219 | 256 | msleep(500); |
|---|
| 220 | 257 | continue; |
|---|
| 221 | 258 | } |
|---|
| .. | .. |
|---|
| 275 | 312 | __smb_send_rqst(struct TCP_Server_Info *server, int num_rqst, |
|---|
| 276 | 313 | struct smb_rqst *rqst) |
|---|
| 277 | 314 | { |
|---|
| 278 | | - int rc = 0; |
|---|
| 315 | + int rc; |
|---|
| 279 | 316 | struct kvec *iov; |
|---|
| 280 | 317 | int n_vec; |
|---|
| 281 | 318 | unsigned int send_length = 0; |
|---|
| 282 | 319 | unsigned int i, j; |
|---|
| 320 | + sigset_t mask, oldmask; |
|---|
| 283 | 321 | size_t total_len = 0, sent, size; |
|---|
| 284 | 322 | struct socket *ssocket = server->ssocket; |
|---|
| 285 | | - struct msghdr smb_msg; |
|---|
| 286 | | - int val = 1; |
|---|
| 323 | + struct msghdr smb_msg = {}; |
|---|
| 287 | 324 | __be32 rfc1002_marker; |
|---|
| 288 | 325 | |
|---|
| 326 | + cifs_in_send_inc(server); |
|---|
| 289 | 327 | if (cifs_rdma_enabled(server)) { |
|---|
| 290 | 328 | /* return -EAGAIN when connecting or reconnecting */ |
|---|
| 291 | 329 | rc = -EAGAIN; |
|---|
| .. | .. |
|---|
| 293 | 331 | rc = smbd_send(server, num_rqst, rqst); |
|---|
| 294 | 332 | goto smbd_done; |
|---|
| 295 | 333 | } |
|---|
| 296 | | - if (ssocket == NULL) |
|---|
| 297 | | - return -ENOTSOCK; |
|---|
| 298 | 334 | |
|---|
| 335 | + rc = -EAGAIN; |
|---|
| 336 | + if (ssocket == NULL) |
|---|
| 337 | + goto out; |
|---|
| 338 | + |
|---|
| 339 | + rc = -ERESTARTSYS; |
|---|
| 340 | + if (fatal_signal_pending(current)) { |
|---|
| 341 | + cifs_dbg(FYI, "signal pending before send request\n"); |
|---|
| 342 | + goto out; |
|---|
| 343 | + } |
|---|
| 344 | + |
|---|
| 345 | + rc = 0; |
|---|
| 299 | 346 | /* cork the socket */ |
|---|
| 300 | | - kernel_setsockopt(ssocket, SOL_TCP, TCP_CORK, |
|---|
| 301 | | - (char *)&val, sizeof(val)); |
|---|
| 347 | + tcp_sock_set_cork(ssocket->sk, true); |
|---|
| 302 | 348 | |
|---|
| 303 | 349 | for (j = 0; j < num_rqst; j++) |
|---|
| 304 | 350 | send_length += smb_rqst_len(server, &rqst[j]); |
|---|
| 305 | 351 | rfc1002_marker = cpu_to_be32(send_length); |
|---|
| 352 | + |
|---|
| 353 | + /* |
|---|
| 354 | + * We should not allow signals to interrupt the network send because |
|---|
| 355 | + * any partial send will cause session reconnects thus increasing |
|---|
| 356 | + * latency of system calls and overload a server with unnecessary |
|---|
| 357 | + * requests. |
|---|
| 358 | + */ |
|---|
| 359 | + |
|---|
| 360 | + sigfillset(&mask); |
|---|
| 361 | + sigprocmask(SIG_BLOCK, &mask, &oldmask); |
|---|
| 306 | 362 | |
|---|
| 307 | 363 | /* Generate a rfc1002 marker for SMB2+ */ |
|---|
| 308 | 364 | if (server->vals->header_preamble_size == 0) { |
|---|
| .. | .. |
|---|
| 310 | 366 | .iov_base = &rfc1002_marker, |
|---|
| 311 | 367 | .iov_len = 4 |
|---|
| 312 | 368 | }; |
|---|
| 313 | | - iov_iter_kvec(&smb_msg.msg_iter, WRITE | ITER_KVEC, &hiov, |
|---|
| 314 | | - 1, 4); |
|---|
| 369 | + iov_iter_kvec(&smb_msg.msg_iter, WRITE, &hiov, 1, 4); |
|---|
| 315 | 370 | rc = smb_send_kvec(server, &smb_msg, &sent); |
|---|
| 316 | 371 | if (rc < 0) |
|---|
| 317 | | - goto uncork; |
|---|
| 372 | + goto unmask; |
|---|
| 318 | 373 | |
|---|
| 319 | 374 | total_len += sent; |
|---|
| 320 | 375 | send_length += 4; |
|---|
| .. | .. |
|---|
| 332 | 387 | size += iov[i].iov_len; |
|---|
| 333 | 388 | } |
|---|
| 334 | 389 | |
|---|
| 335 | | - iov_iter_kvec(&smb_msg.msg_iter, WRITE | ITER_KVEC, |
|---|
| 336 | | - iov, n_vec, size); |
|---|
| 390 | + iov_iter_kvec(&smb_msg.msg_iter, WRITE, iov, n_vec, size); |
|---|
| 337 | 391 | |
|---|
| 338 | 392 | rc = smb_send_kvec(server, &smb_msg, &sent); |
|---|
| 339 | 393 | if (rc < 0) |
|---|
| 340 | | - goto uncork; |
|---|
| 394 | + goto unmask; |
|---|
| 341 | 395 | |
|---|
| 342 | 396 | total_len += sent; |
|---|
| 343 | 397 | |
|---|
| .. | .. |
|---|
| 349 | 403 | rqst_page_get_length(&rqst[j], i, &bvec.bv_len, |
|---|
| 350 | 404 | &bvec.bv_offset); |
|---|
| 351 | 405 | |
|---|
| 352 | | - iov_iter_bvec(&smb_msg.msg_iter, WRITE | ITER_BVEC, |
|---|
| 406 | + iov_iter_bvec(&smb_msg.msg_iter, WRITE, |
|---|
| 353 | 407 | &bvec, 1, bvec.bv_len); |
|---|
| 354 | 408 | rc = smb_send_kvec(server, &smb_msg, &sent); |
|---|
| 355 | 409 | if (rc < 0) |
|---|
| .. | .. |
|---|
| 359 | 413 | } |
|---|
| 360 | 414 | } |
|---|
| 361 | 415 | |
|---|
| 362 | | -uncork: |
|---|
| 416 | +unmask: |
|---|
| 417 | + sigprocmask(SIG_SETMASK, &oldmask, NULL); |
|---|
| 418 | + |
|---|
| 419 | + /* |
|---|
| 420 | + * If signal is pending but we have already sent the whole packet to |
|---|
| 421 | + * the server we need to return success status to allow a corresponding |
|---|
| 422 | + * mid entry to be kept in the pending requests queue thus allowing |
|---|
| 423 | + * to handle responses from the server by the client. |
|---|
| 424 | + * |
|---|
| 425 | + * If only part of the packet has been sent there is no need to hide |
|---|
| 426 | + * interrupt because the session will be reconnected anyway, so there |
|---|
| 427 | + * won't be any response from the server to handle. |
|---|
| 428 | + */ |
|---|
| 429 | + |
|---|
| 430 | + if (signal_pending(current) && (total_len != send_length)) { |
|---|
| 431 | + cifs_dbg(FYI, "signal is pending after attempt to send\n"); |
|---|
| 432 | + rc = -ERESTARTSYS; |
|---|
| 433 | + } |
|---|
| 434 | + |
|---|
| 363 | 435 | /* uncork it */ |
|---|
| 364 | | - val = 0; |
|---|
| 365 | | - kernel_setsockopt(ssocket, SOL_TCP, TCP_CORK, |
|---|
| 366 | | - (char *)&val, sizeof(val)); |
|---|
| 436 | + tcp_sock_set_cork(ssocket->sk, false); |
|---|
| 367 | 437 | |
|---|
| 368 | 438 | if ((total_len > 0) && (total_len != send_length)) { |
|---|
| 369 | 439 | cifs_dbg(FYI, "partial send (wanted=%u sent=%zu): terminating session\n", |
|---|
| .. | .. |
|---|
| 379 | 449 | } |
|---|
| 380 | 450 | smbd_done: |
|---|
| 381 | 451 | if (rc < 0 && rc != -EINTR) |
|---|
| 382 | | - cifs_dbg(VFS, "Error %d sending data on socket to server\n", |
|---|
| 452 | + cifs_server_dbg(VFS, "Error %d sending data on socket to server\n", |
|---|
| 383 | 453 | rc); |
|---|
| 384 | 454 | else if (rc > 0) |
|---|
| 385 | 455 | rc = 0; |
|---|
| 386 | | - |
|---|
| 456 | +out: |
|---|
| 457 | + cifs_in_send_dec(server); |
|---|
| 387 | 458 | return rc; |
|---|
| 388 | 459 | } |
|---|
| 389 | 460 | |
|---|
| .. | .. |
|---|
| 403 | 474 | return -ENOMEM; |
|---|
| 404 | 475 | |
|---|
| 405 | 476 | if (!server->ops->init_transform_rq) { |
|---|
| 406 | | - cifs_dbg(VFS, "Encryption requested but transform callback " |
|---|
| 407 | | - "is missing\n"); |
|---|
| 477 | + cifs_server_dbg(VFS, "Encryption requested but transform callback is missing\n"); |
|---|
| 408 | 478 | return -EIO; |
|---|
| 409 | 479 | } |
|---|
| 410 | 480 | |
|---|
| .. | .. |
|---|
| 450 | 520 | } |
|---|
| 451 | 521 | |
|---|
| 452 | 522 | static int |
|---|
| 453 | | -wait_for_free_credits(struct TCP_Server_Info *server, const int timeout, |
|---|
| 454 | | - int *credits) |
|---|
| 523 | +wait_for_free_credits(struct TCP_Server_Info *server, const int num_credits, |
|---|
| 524 | + const int timeout, const int flags, |
|---|
| 525 | + unsigned int *instance) |
|---|
| 455 | 526 | { |
|---|
| 456 | | - int rc; |
|---|
| 527 | + long rc; |
|---|
| 528 | + int *credits; |
|---|
| 529 | + int optype; |
|---|
| 530 | + long int t; |
|---|
| 531 | + |
|---|
| 532 | + if (timeout < 0) |
|---|
| 533 | + t = MAX_JIFFY_OFFSET; |
|---|
| 534 | + else |
|---|
| 535 | + t = msecs_to_jiffies(timeout); |
|---|
| 536 | + |
|---|
| 537 | + optype = flags & CIFS_OP_MASK; |
|---|
| 538 | + |
|---|
| 539 | + *instance = 0; |
|---|
| 540 | + |
|---|
| 541 | + credits = server->ops->get_credits_field(server, optype); |
|---|
| 542 | + /* Since an echo is already inflight, no need to wait to send another */ |
|---|
| 543 | + if (*credits <= 0 && optype == CIFS_ECHO_OP) |
|---|
| 544 | + return -EAGAIN; |
|---|
| 457 | 545 | |
|---|
| 458 | 546 | spin_lock(&server->req_lock); |
|---|
| 459 | | - if (timeout == CIFS_ASYNC_OP) { |
|---|
| 547 | + if ((flags & CIFS_TIMEOUT_MASK) == CIFS_NON_BLOCKING) { |
|---|
| 460 | 548 | /* oplock breaks must not be held up */ |
|---|
| 461 | 549 | server->in_flight++; |
|---|
| 550 | + if (server->in_flight > server->max_in_flight) |
|---|
| 551 | + server->max_in_flight = server->in_flight; |
|---|
| 462 | 552 | *credits -= 1; |
|---|
| 553 | + *instance = server->reconnect_instance; |
|---|
| 463 | 554 | spin_unlock(&server->req_lock); |
|---|
| 464 | 555 | return 0; |
|---|
| 465 | 556 | } |
|---|
| 466 | 557 | |
|---|
| 467 | 558 | while (1) { |
|---|
| 468 | | - if (*credits <= 0) { |
|---|
| 559 | + if (*credits < num_credits) { |
|---|
| 469 | 560 | spin_unlock(&server->req_lock); |
|---|
| 470 | 561 | cifs_num_waiters_inc(server); |
|---|
| 471 | | - rc = wait_event_killable(server->request_q, |
|---|
| 472 | | - has_credits(server, credits)); |
|---|
| 562 | + rc = wait_event_killable_timeout(server->request_q, |
|---|
| 563 | + has_credits(server, credits, num_credits), t); |
|---|
| 473 | 564 | cifs_num_waiters_dec(server); |
|---|
| 474 | | - if (rc) |
|---|
| 475 | | - return rc; |
|---|
| 565 | + if (!rc) { |
|---|
| 566 | + trace_smb3_credit_timeout(server->CurrentMid, |
|---|
| 567 | + server->hostname, num_credits, 0); |
|---|
| 568 | + cifs_server_dbg(VFS, "wait timed out after %d ms\n", |
|---|
| 569 | + timeout); |
|---|
| 570 | + return -ENOTSUPP; |
|---|
| 571 | + } |
|---|
| 572 | + if (rc == -ERESTARTSYS) |
|---|
| 573 | + return -ERESTARTSYS; |
|---|
| 476 | 574 | spin_lock(&server->req_lock); |
|---|
| 477 | 575 | } else { |
|---|
| 478 | 576 | if (server->tcpStatus == CifsExiting) { |
|---|
| .. | .. |
|---|
| 481 | 579 | } |
|---|
| 482 | 580 | |
|---|
| 483 | 581 | /* |
|---|
| 582 | + * For normal commands, reserve the last MAX_COMPOUND |
|---|
| 583 | + * credits to compound requests. |
|---|
| 584 | + * Otherwise these compounds could be permanently |
|---|
| 585 | + * starved for credits by single-credit requests. |
|---|
| 586 | + * |
|---|
| 587 | + * To prevent spinning CPU, block this thread until |
|---|
| 588 | + * there are >MAX_COMPOUND credits available. |
|---|
| 589 | + * But only do this is we already have a lot of |
|---|
| 590 | + * credits in flight to avoid triggering this check |
|---|
| 591 | + * for servers that are slow to hand out credits on |
|---|
| 592 | + * new sessions. |
|---|
| 593 | + */ |
|---|
| 594 | + if (!optype && num_credits == 1 && |
|---|
| 595 | + server->in_flight > 2 * MAX_COMPOUND && |
|---|
| 596 | + *credits <= MAX_COMPOUND) { |
|---|
| 597 | + spin_unlock(&server->req_lock); |
|---|
| 598 | + cifs_num_waiters_inc(server); |
|---|
| 599 | + rc = wait_event_killable_timeout( |
|---|
| 600 | + server->request_q, |
|---|
| 601 | + has_credits(server, credits, |
|---|
| 602 | + MAX_COMPOUND + 1), |
|---|
| 603 | + t); |
|---|
| 604 | + cifs_num_waiters_dec(server); |
|---|
| 605 | + if (!rc) { |
|---|
| 606 | + trace_smb3_credit_timeout( |
|---|
| 607 | + server->CurrentMid, |
|---|
| 608 | + server->hostname, num_credits, |
|---|
| 609 | + 0); |
|---|
| 610 | + cifs_server_dbg(VFS, "wait timed out after %d ms\n", |
|---|
| 611 | + timeout); |
|---|
| 612 | + return -ENOTSUPP; |
|---|
| 613 | + } |
|---|
| 614 | + if (rc == -ERESTARTSYS) |
|---|
| 615 | + return -ERESTARTSYS; |
|---|
| 616 | + spin_lock(&server->req_lock); |
|---|
| 617 | + continue; |
|---|
| 618 | + } |
|---|
| 619 | + |
|---|
| 620 | + /* |
|---|
| 484 | 621 | * Can not count locking commands against total |
|---|
| 485 | 622 | * as they are allowed to block on server. |
|---|
| 486 | 623 | */ |
|---|
| 487 | 624 | |
|---|
| 488 | 625 | /* update # of requests on the wire to server */ |
|---|
| 489 | | - if (timeout != CIFS_BLOCKING_OP) { |
|---|
| 490 | | - *credits -= 1; |
|---|
| 491 | | - server->in_flight++; |
|---|
| 626 | + if ((flags & CIFS_TIMEOUT_MASK) != CIFS_BLOCKING_OP) { |
|---|
| 627 | + *credits -= num_credits; |
|---|
| 628 | + server->in_flight += num_credits; |
|---|
| 629 | + if (server->in_flight > server->max_in_flight) |
|---|
| 630 | + server->max_in_flight = server->in_flight; |
|---|
| 631 | + *instance = server->reconnect_instance; |
|---|
| 492 | 632 | } |
|---|
| 493 | 633 | spin_unlock(&server->req_lock); |
|---|
| 494 | 634 | break; |
|---|
| .. | .. |
|---|
| 498 | 638 | } |
|---|
| 499 | 639 | |
|---|
| 500 | 640 | static int |
|---|
| 501 | | -wait_for_free_request(struct TCP_Server_Info *server, const int timeout, |
|---|
| 502 | | - const int optype) |
|---|
| 641 | +wait_for_free_request(struct TCP_Server_Info *server, const int flags, |
|---|
| 642 | + unsigned int *instance) |
|---|
| 503 | 643 | { |
|---|
| 504 | | - int *val; |
|---|
| 644 | + return wait_for_free_credits(server, 1, -1, flags, |
|---|
| 645 | + instance); |
|---|
| 646 | +} |
|---|
| 505 | 647 | |
|---|
| 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); |
|---|
| 648 | +static int |
|---|
| 649 | +wait_for_compound_request(struct TCP_Server_Info *server, int num, |
|---|
| 650 | + const int flags, unsigned int *instance) |
|---|
| 651 | +{ |
|---|
| 652 | + int *credits; |
|---|
| 653 | + |
|---|
| 654 | + credits = server->ops->get_credits_field(server, flags & CIFS_OP_MASK); |
|---|
| 655 | + |
|---|
| 656 | + spin_lock(&server->req_lock); |
|---|
| 657 | + if (*credits < num) { |
|---|
| 658 | + /* |
|---|
| 659 | + * If the server is tight on resources or just gives us less |
|---|
| 660 | + * credits for other reasons (e.g. requests are coming out of |
|---|
| 661 | + * order and the server delays granting more credits until it |
|---|
| 662 | + * processes a missing mid) and we exhausted most available |
|---|
| 663 | + * credits there may be situations when we try to send |
|---|
| 664 | + * a compound request but we don't have enough credits. At this |
|---|
| 665 | + * point the client needs to decide if it should wait for |
|---|
| 666 | + * additional credits or fail the request. If at least one |
|---|
| 667 | + * request is in flight there is a high probability that the |
|---|
| 668 | + * server will return enough credits to satisfy this compound |
|---|
| 669 | + * request. |
|---|
| 670 | + * |
|---|
| 671 | + * Return immediately if no requests in flight since we will be |
|---|
| 672 | + * stuck on waiting for credits. |
|---|
| 673 | + */ |
|---|
| 674 | + if (server->in_flight == 0) { |
|---|
| 675 | + spin_unlock(&server->req_lock); |
|---|
| 676 | + return -ENOTSUPP; |
|---|
| 677 | + } |
|---|
| 678 | + } |
|---|
| 679 | + spin_unlock(&server->req_lock); |
|---|
| 680 | + |
|---|
| 681 | + return wait_for_free_credits(server, num, 60000, flags, |
|---|
| 682 | + instance); |
|---|
| 511 | 683 | } |
|---|
| 512 | 684 | |
|---|
| 513 | 685 | int |
|---|
| 514 | 686 | cifs_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size, |
|---|
| 515 | | - unsigned int *num, unsigned int *credits) |
|---|
| 687 | + unsigned int *num, struct cifs_credits *credits) |
|---|
| 516 | 688 | { |
|---|
| 517 | 689 | *num = size; |
|---|
| 518 | | - *credits = 0; |
|---|
| 690 | + credits->value = 0; |
|---|
| 691 | + credits->instance = server->reconnect_instance; |
|---|
| 519 | 692 | return 0; |
|---|
| 520 | 693 | } |
|---|
| 521 | 694 | |
|---|
| .. | .. |
|---|
| 602 | 775 | int |
|---|
| 603 | 776 | cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst, |
|---|
| 604 | 777 | mid_receive_t *receive, mid_callback_t *callback, |
|---|
| 605 | | - mid_handle_t *handle, void *cbdata, const int flags) |
|---|
| 778 | + mid_handle_t *handle, void *cbdata, const int flags, |
|---|
| 779 | + const struct cifs_credits *exist_credits) |
|---|
| 606 | 780 | { |
|---|
| 607 | | - int rc, timeout, optype; |
|---|
| 781 | + int rc; |
|---|
| 608 | 782 | struct mid_q_entry *mid; |
|---|
| 609 | | - unsigned int credits = 0; |
|---|
| 783 | + struct cifs_credits credits = { .value = 0, .instance = 0 }; |
|---|
| 784 | + unsigned int instance; |
|---|
| 785 | + int optype; |
|---|
| 610 | 786 | |
|---|
| 611 | | - timeout = flags & CIFS_TIMEOUT_MASK; |
|---|
| 612 | 787 | optype = flags & CIFS_OP_MASK; |
|---|
| 613 | 788 | |
|---|
| 614 | 789 | if ((flags & CIFS_HAS_CREDITS) == 0) { |
|---|
| 615 | | - rc = wait_for_free_request(server, timeout, optype); |
|---|
| 790 | + rc = wait_for_free_request(server, flags, &instance); |
|---|
| 616 | 791 | if (rc) |
|---|
| 617 | 792 | return rc; |
|---|
| 618 | | - credits = 1; |
|---|
| 619 | | - } |
|---|
| 793 | + credits.value = 1; |
|---|
| 794 | + credits.instance = instance; |
|---|
| 795 | + } else |
|---|
| 796 | + instance = exist_credits->instance; |
|---|
| 620 | 797 | |
|---|
| 621 | 798 | mutex_lock(&server->srv_mutex); |
|---|
| 799 | + |
|---|
| 800 | + /* |
|---|
| 801 | + * We can't use credits obtained from the previous session to send this |
|---|
| 802 | + * request. Check if there were reconnects after we obtained credits and |
|---|
| 803 | + * return -EAGAIN in such cases to let callers handle it. |
|---|
| 804 | + */ |
|---|
| 805 | + if (instance != server->reconnect_instance) { |
|---|
| 806 | + mutex_unlock(&server->srv_mutex); |
|---|
| 807 | + add_credits_and_wake_if(server, &credits, optype); |
|---|
| 808 | + return -EAGAIN; |
|---|
| 809 | + } |
|---|
| 810 | + |
|---|
| 622 | 811 | mid = server->ops->setup_async_request(server, rqst); |
|---|
| 623 | 812 | if (IS_ERR(mid)) { |
|---|
| 624 | 813 | mutex_unlock(&server->srv_mutex); |
|---|
| 625 | | - add_credits_and_wake_if(server, credits, optype); |
|---|
| 814 | + add_credits_and_wake_if(server, &credits, optype); |
|---|
| 626 | 815 | return PTR_ERR(mid); |
|---|
| 627 | 816 | } |
|---|
| 628 | 817 | |
|---|
| .. | .. |
|---|
| 642 | 831 | * I/O response may come back and free the mid entry on another thread. |
|---|
| 643 | 832 | */ |
|---|
| 644 | 833 | cifs_save_when_sent(mid); |
|---|
| 645 | | - cifs_in_send_inc(server); |
|---|
| 646 | 834 | rc = smb_send_rqst(server, 1, rqst, flags); |
|---|
| 647 | | - cifs_in_send_dec(server); |
|---|
| 648 | 835 | |
|---|
| 649 | 836 | if (rc < 0) { |
|---|
| 650 | 837 | revert_current_mid(server, mid->credits); |
|---|
| .. | .. |
|---|
| 657 | 844 | if (rc == 0) |
|---|
| 658 | 845 | return 0; |
|---|
| 659 | 846 | |
|---|
| 660 | | - add_credits_and_wake_if(server, credits, optype); |
|---|
| 847 | + add_credits_and_wake_if(server, &credits, optype); |
|---|
| 661 | 848 | return rc; |
|---|
| 662 | 849 | } |
|---|
| 663 | 850 | |
|---|
| .. | .. |
|---|
| 681 | 868 | |
|---|
| 682 | 869 | iov[0].iov_base = in_buf; |
|---|
| 683 | 870 | iov[0].iov_len = get_rfc1002_length(in_buf) + 4; |
|---|
| 684 | | - flags |= CIFS_NO_RESP; |
|---|
| 871 | + flags |= CIFS_NO_RSP_BUF; |
|---|
| 685 | 872 | rc = SendReceive2(xid, ses, iov, 1, &resp_buf_type, flags, &rsp_iov); |
|---|
| 686 | 873 | cifs_dbg(NOISY, "SendRcvNoRsp flags %d rc %d\n", flags, rc); |
|---|
| 687 | 874 | |
|---|
| .. | .. |
|---|
| 711 | 898 | rc = -EHOSTDOWN; |
|---|
| 712 | 899 | break; |
|---|
| 713 | 900 | default: |
|---|
| 714 | | - list_del_init(&mid->qhead); |
|---|
| 715 | | - cifs_dbg(VFS, "%s: invalid mid state mid=%llu state=%d\n", |
|---|
| 901 | + if (!(mid->mid_flags & MID_DELETED)) { |
|---|
| 902 | + list_del_init(&mid->qhead); |
|---|
| 903 | + mid->mid_flags |= MID_DELETED; |
|---|
| 904 | + } |
|---|
| 905 | + cifs_server_dbg(VFS, "%s: invalid mid state mid=%llu state=%d\n", |
|---|
| 716 | 906 | __func__, mid->mid, mid->mid_state); |
|---|
| 717 | 907 | rc = -EIO; |
|---|
| 718 | 908 | } |
|---|
| .. | .. |
|---|
| 753 | 943 | rc = cifs_verify_signature(&rqst, server, |
|---|
| 754 | 944 | mid->sequence_number); |
|---|
| 755 | 945 | if (rc) |
|---|
| 756 | | - cifs_dbg(VFS, "SMB signature verification returned error = %d\n", |
|---|
| 946 | + cifs_server_dbg(VFS, "SMB signature verification returned error = %d\n", |
|---|
| 757 | 947 | rc); |
|---|
| 758 | 948 | } |
|---|
| 759 | 949 | |
|---|
| 760 | 950 | /* BB special case reconnect tid and uid here? */ |
|---|
| 761 | | - return map_smb_to_linux_error(mid->resp_buf, log_error); |
|---|
| 951 | + return map_and_check_smb_error(mid, log_error); |
|---|
| 762 | 952 | } |
|---|
| 763 | 953 | |
|---|
| 764 | 954 | struct mid_q_entry * |
|---|
| 765 | | -cifs_setup_request(struct cifs_ses *ses, struct smb_rqst *rqst) |
|---|
| 955 | +cifs_setup_request(struct cifs_ses *ses, struct TCP_Server_Info *ignored, |
|---|
| 956 | + struct smb_rqst *rqst) |
|---|
| 766 | 957 | { |
|---|
| 767 | 958 | int rc; |
|---|
| 768 | 959 | struct smb_hdr *hdr = (struct smb_hdr *)rqst->rq_iov[0].iov_base; |
|---|
| .. | .. |
|---|
| 784 | 975 | } |
|---|
| 785 | 976 | |
|---|
| 786 | 977 | static void |
|---|
| 787 | | -cifs_noop_callback(struct mid_q_entry *mid) |
|---|
| 978 | +cifs_compound_callback(struct mid_q_entry *mid) |
|---|
| 788 | 979 | { |
|---|
| 980 | + struct TCP_Server_Info *server = mid->server; |
|---|
| 981 | + struct cifs_credits credits; |
|---|
| 982 | + |
|---|
| 983 | + credits.value = server->ops->get_credits(mid); |
|---|
| 984 | + credits.instance = server->reconnect_instance; |
|---|
| 985 | + |
|---|
| 986 | + add_credits(server, &credits, mid->optype); |
|---|
| 987 | +} |
|---|
| 988 | + |
|---|
| 989 | +static void |
|---|
| 990 | +cifs_compound_last_callback(struct mid_q_entry *mid) |
|---|
| 991 | +{ |
|---|
| 992 | + cifs_compound_callback(mid); |
|---|
| 993 | + cifs_wake_up_task(mid); |
|---|
| 994 | +} |
|---|
| 995 | + |
|---|
| 996 | +static void |
|---|
| 997 | +cifs_cancelled_callback(struct mid_q_entry *mid) |
|---|
| 998 | +{ |
|---|
| 999 | + cifs_compound_callback(mid); |
|---|
| 1000 | + DeleteMidQEntry(mid); |
|---|
| 1001 | +} |
|---|
| 1002 | + |
|---|
| 1003 | +/* |
|---|
| 1004 | + * Return a channel (master if none) of @ses that can be used to send |
|---|
| 1005 | + * regular requests. |
|---|
| 1006 | + * |
|---|
| 1007 | + * If we are currently binding a new channel (negprot/sess.setup), |
|---|
| 1008 | + * return the new incomplete channel. |
|---|
| 1009 | + */ |
|---|
| 1010 | +struct TCP_Server_Info *cifs_pick_channel(struct cifs_ses *ses) |
|---|
| 1011 | +{ |
|---|
| 1012 | + uint index = 0; |
|---|
| 1013 | + |
|---|
| 1014 | + if (!ses) |
|---|
| 1015 | + return NULL; |
|---|
| 1016 | + |
|---|
| 1017 | + if (!ses->binding) { |
|---|
| 1018 | + /* round robin */ |
|---|
| 1019 | + if (ses->chan_count > 1) { |
|---|
| 1020 | + index = (uint)atomic_inc_return(&ses->chan_seq); |
|---|
| 1021 | + index %= ses->chan_count; |
|---|
| 1022 | + } |
|---|
| 1023 | + return ses->chans[index].server; |
|---|
| 1024 | + } else { |
|---|
| 1025 | + return cifs_ses_server(ses); |
|---|
| 1026 | + } |
|---|
| 789 | 1027 | } |
|---|
| 790 | 1028 | |
|---|
| 791 | 1029 | int |
|---|
| 792 | 1030 | compound_send_recv(const unsigned int xid, struct cifs_ses *ses, |
|---|
| 1031 | + struct TCP_Server_Info *server, |
|---|
| 793 | 1032 | const int flags, const int num_rqst, struct smb_rqst *rqst, |
|---|
| 794 | 1033 | int *resp_buf_type, struct kvec *resp_iov) |
|---|
| 795 | 1034 | { |
|---|
| 796 | | - int i, j, rc = 0; |
|---|
| 797 | | - int timeout, optype; |
|---|
| 1035 | + int i, j, optype, rc = 0; |
|---|
| 798 | 1036 | struct mid_q_entry *midQ[MAX_COMPOUND]; |
|---|
| 799 | 1037 | bool cancelled_mid[MAX_COMPOUND] = {false}; |
|---|
| 800 | | - unsigned int credits[MAX_COMPOUND] = {0}; |
|---|
| 1038 | + struct cifs_credits credits[MAX_COMPOUND] = { |
|---|
| 1039 | + { .value = 0, .instance = 0 } |
|---|
| 1040 | + }; |
|---|
| 1041 | + unsigned int instance; |
|---|
| 801 | 1042 | char *buf; |
|---|
| 802 | 1043 | |
|---|
| 803 | | - timeout = flags & CIFS_TIMEOUT_MASK; |
|---|
| 804 | 1044 | optype = flags & CIFS_OP_MASK; |
|---|
| 805 | 1045 | |
|---|
| 806 | 1046 | for (i = 0; i < num_rqst; i++) |
|---|
| 807 | 1047 | resp_buf_type[i] = CIFS_NO_BUFFER; /* no response buf yet */ |
|---|
| 808 | 1048 | |
|---|
| 809 | | - if ((ses == NULL) || (ses->server == NULL)) { |
|---|
| 1049 | + if (!ses || !ses->server || !server) { |
|---|
| 810 | 1050 | cifs_dbg(VFS, "Null session\n"); |
|---|
| 811 | 1051 | return -EIO; |
|---|
| 812 | 1052 | } |
|---|
| 813 | 1053 | |
|---|
| 814 | | - if (ses->server->tcpStatus == CifsExiting) |
|---|
| 1054 | + if (server->tcpStatus == CifsExiting) |
|---|
| 815 | 1055 | return -ENOENT; |
|---|
| 816 | 1056 | |
|---|
| 817 | 1057 | /* |
|---|
| 818 | | - * Ensure we obtain 1 credit per request in the compound chain. |
|---|
| 819 | | - * It can be optimized further by waiting for all the credits |
|---|
| 820 | | - * at once but this can wait long enough if we don't have enough |
|---|
| 821 | | - * credits due to some heavy operations in progress or the server |
|---|
| 822 | | - * not granting us much, so a fallback to the current approach is |
|---|
| 823 | | - * needed anyway. |
|---|
| 1058 | + * Wait for all the requests to become available. |
|---|
| 1059 | + * This approach still leaves the possibility to be stuck waiting for |
|---|
| 1060 | + * credits if the server doesn't grant credits to the outstanding |
|---|
| 1061 | + * requests and if the client is completely idle, not generating any |
|---|
| 1062 | + * other requests. |
|---|
| 1063 | + * This can be handled by the eventual session reconnect. |
|---|
| 824 | 1064 | */ |
|---|
| 1065 | + rc = wait_for_compound_request(server, num_rqst, flags, |
|---|
| 1066 | + &instance); |
|---|
| 1067 | + if (rc) |
|---|
| 1068 | + return rc; |
|---|
| 1069 | + |
|---|
| 825 | 1070 | for (i = 0; i < num_rqst; i++) { |
|---|
| 826 | | - rc = wait_for_free_request(ses->server, timeout, optype); |
|---|
| 827 | | - if (rc) { |
|---|
| 828 | | - /* |
|---|
| 829 | | - * We haven't sent an SMB packet to the server yet but |
|---|
| 830 | | - * we already obtained credits for i requests in the |
|---|
| 831 | | - * compound chain - need to return those credits back |
|---|
| 832 | | - * for future use. Note that we need to call add_credits |
|---|
| 833 | | - * multiple times to match the way we obtained credits |
|---|
| 834 | | - * in the first place and to account for in flight |
|---|
| 835 | | - * requests correctly. |
|---|
| 836 | | - */ |
|---|
| 837 | | - for (j = 0; j < i; j++) |
|---|
| 838 | | - add_credits(ses->server, 1, optype); |
|---|
| 839 | | - return rc; |
|---|
| 840 | | - } |
|---|
| 841 | | - credits[i] = 1; |
|---|
| 1071 | + credits[i].value = 1; |
|---|
| 1072 | + credits[i].instance = instance; |
|---|
| 842 | 1073 | } |
|---|
| 843 | 1074 | |
|---|
| 844 | 1075 | /* |
|---|
| .. | .. |
|---|
| 847 | 1078 | * of smb data. |
|---|
| 848 | 1079 | */ |
|---|
| 849 | 1080 | |
|---|
| 850 | | - mutex_lock(&ses->server->srv_mutex); |
|---|
| 1081 | + mutex_lock(&server->srv_mutex); |
|---|
| 1082 | + |
|---|
| 1083 | + /* |
|---|
| 1084 | + * All the parts of the compound chain belong obtained credits from the |
|---|
| 1085 | + * same session. We can not use credits obtained from the previous |
|---|
| 1086 | + * session to send this request. Check if there were reconnects after |
|---|
| 1087 | + * we obtained credits and return -EAGAIN in such cases to let callers |
|---|
| 1088 | + * handle it. |
|---|
| 1089 | + */ |
|---|
| 1090 | + if (instance != server->reconnect_instance) { |
|---|
| 1091 | + mutex_unlock(&server->srv_mutex); |
|---|
| 1092 | + for (j = 0; j < num_rqst; j++) |
|---|
| 1093 | + add_credits(server, &credits[j], optype); |
|---|
| 1094 | + return -EAGAIN; |
|---|
| 1095 | + } |
|---|
| 851 | 1096 | |
|---|
| 852 | 1097 | for (i = 0; i < num_rqst; i++) { |
|---|
| 853 | | - midQ[i] = ses->server->ops->setup_request(ses, &rqst[i]); |
|---|
| 1098 | + midQ[i] = server->ops->setup_request(ses, server, &rqst[i]); |
|---|
| 854 | 1099 | if (IS_ERR(midQ[i])) { |
|---|
| 855 | | - revert_current_mid(ses->server, i); |
|---|
| 1100 | + revert_current_mid(server, i); |
|---|
| 856 | 1101 | for (j = 0; j < i; j++) |
|---|
| 857 | 1102 | cifs_delete_mid(midQ[j]); |
|---|
| 858 | | - mutex_unlock(&ses->server->srv_mutex); |
|---|
| 1103 | + mutex_unlock(&server->srv_mutex); |
|---|
| 859 | 1104 | |
|---|
| 860 | 1105 | /* Update # of requests on wire to server */ |
|---|
| 861 | 1106 | for (j = 0; j < num_rqst; j++) |
|---|
| 862 | | - add_credits(ses->server, credits[j], optype); |
|---|
| 1107 | + add_credits(server, &credits[j], optype); |
|---|
| 863 | 1108 | return PTR_ERR(midQ[i]); |
|---|
| 864 | 1109 | } |
|---|
| 865 | 1110 | |
|---|
| 866 | 1111 | midQ[i]->mid_state = MID_REQUEST_SUBMITTED; |
|---|
| 1112 | + midQ[i]->optype = optype; |
|---|
| 867 | 1113 | /* |
|---|
| 868 | | - * We don't invoke the callback compounds unless it is the last |
|---|
| 869 | | - * request. |
|---|
| 1114 | + * Invoke callback for every part of the compound chain |
|---|
| 1115 | + * to calculate credits properly. Wake up this thread only when |
|---|
| 1116 | + * the last element is received. |
|---|
| 870 | 1117 | */ |
|---|
| 871 | 1118 | if (i < num_rqst - 1) |
|---|
| 872 | | - midQ[i]->callback = cifs_noop_callback; |
|---|
| 1119 | + midQ[i]->callback = cifs_compound_callback; |
|---|
| 1120 | + else |
|---|
| 1121 | + midQ[i]->callback = cifs_compound_last_callback; |
|---|
| 873 | 1122 | } |
|---|
| 874 | | - cifs_in_send_inc(ses->server); |
|---|
| 875 | | - rc = smb_send_rqst(ses->server, num_rqst, rqst, flags); |
|---|
| 876 | | - cifs_in_send_dec(ses->server); |
|---|
| 1123 | + rc = smb_send_rqst(server, num_rqst, rqst, flags); |
|---|
| 877 | 1124 | |
|---|
| 878 | 1125 | for (i = 0; i < num_rqst; i++) |
|---|
| 879 | 1126 | cifs_save_when_sent(midQ[i]); |
|---|
| 880 | 1127 | |
|---|
| 881 | 1128 | if (rc < 0) { |
|---|
| 882 | | - revert_current_mid(ses->server, num_rqst); |
|---|
| 883 | | - ses->server->sequence_number -= 2; |
|---|
| 1129 | + revert_current_mid(server, num_rqst); |
|---|
| 1130 | + server->sequence_number -= 2; |
|---|
| 884 | 1131 | } |
|---|
| 885 | 1132 | |
|---|
| 886 | | - mutex_unlock(&ses->server->srv_mutex); |
|---|
| 1133 | + mutex_unlock(&server->srv_mutex); |
|---|
| 887 | 1134 | |
|---|
| 888 | | - if (rc < 0) |
|---|
| 1135 | + /* |
|---|
| 1136 | + * If sending failed for some reason or it is an oplock break that we |
|---|
| 1137 | + * will not receive a response to - return credits back |
|---|
| 1138 | + */ |
|---|
| 1139 | + if (rc < 0 || (flags & CIFS_NO_SRV_RSP)) { |
|---|
| 1140 | + for (i = 0; i < num_rqst; i++) |
|---|
| 1141 | + add_credits(server, &credits[i], optype); |
|---|
| 889 | 1142 | goto out; |
|---|
| 1143 | + } |
|---|
| 1144 | + |
|---|
| 1145 | + /* |
|---|
| 1146 | + * At this point the request is passed to the network stack - we assume |
|---|
| 1147 | + * that any credits taken from the server structure on the client have |
|---|
| 1148 | + * been spent and we can't return them back. Once we receive responses |
|---|
| 1149 | + * we will collect credits granted by the server in the mid callbacks |
|---|
| 1150 | + * and add those credits to the server structure. |
|---|
| 1151 | + */ |
|---|
| 890 | 1152 | |
|---|
| 891 | 1153 | /* |
|---|
| 892 | 1154 | * Compounding is never used during session establish. |
|---|
| 893 | 1155 | */ |
|---|
| 894 | 1156 | if ((ses->status == CifsNew) || (optype & CIFS_NEG_OP)) { |
|---|
| 895 | | - mutex_lock(&ses->server->srv_mutex); |
|---|
| 1157 | + mutex_lock(&server->srv_mutex); |
|---|
| 896 | 1158 | smb311_update_preauth_hash(ses, rqst[0].rq_iov, |
|---|
| 897 | 1159 | rqst[0].rq_nvec); |
|---|
| 898 | | - mutex_unlock(&ses->server->srv_mutex); |
|---|
| 1160 | + mutex_unlock(&server->srv_mutex); |
|---|
| 899 | 1161 | } |
|---|
| 900 | 1162 | |
|---|
| 901 | | - if (timeout == CIFS_ASYNC_OP) |
|---|
| 902 | | - goto out; |
|---|
| 903 | | - |
|---|
| 904 | 1163 | for (i = 0; i < num_rqst; i++) { |
|---|
| 905 | | - rc = wait_for_response(ses->server, midQ[i]); |
|---|
| 906 | | - if (rc != 0) { |
|---|
| 907 | | - cifs_dbg(FYI, "Cancelling wait for mid %llu\n", |
|---|
| 908 | | - midQ[i]->mid); |
|---|
| 909 | | - send_cancel(ses->server, &rqst[i], midQ[i]); |
|---|
| 1164 | + rc = wait_for_response(server, midQ[i]); |
|---|
| 1165 | + if (rc != 0) |
|---|
| 1166 | + break; |
|---|
| 1167 | + } |
|---|
| 1168 | + if (rc != 0) { |
|---|
| 1169 | + for (; i < num_rqst; i++) { |
|---|
| 1170 | + cifs_server_dbg(FYI, "Cancelling wait for mid %llu cmd: %d\n", |
|---|
| 1171 | + midQ[i]->mid, le16_to_cpu(midQ[i]->command)); |
|---|
| 1172 | + send_cancel(server, &rqst[i], midQ[i]); |
|---|
| 910 | 1173 | spin_lock(&GlobalMid_Lock); |
|---|
| 1174 | + midQ[i]->mid_flags |= MID_WAIT_CANCELLED; |
|---|
| 911 | 1175 | if (midQ[i]->mid_state == MID_REQUEST_SUBMITTED) { |
|---|
| 912 | | - midQ[i]->mid_flags |= MID_WAIT_CANCELLED; |
|---|
| 913 | | - midQ[i]->callback = DeleteMidQEntry; |
|---|
| 1176 | + midQ[i]->callback = cifs_cancelled_callback; |
|---|
| 914 | 1177 | cancelled_mid[i] = true; |
|---|
| 1178 | + credits[i].value = 0; |
|---|
| 915 | 1179 | } |
|---|
| 916 | 1180 | spin_unlock(&GlobalMid_Lock); |
|---|
| 917 | 1181 | } |
|---|
| 918 | 1182 | } |
|---|
| 919 | 1183 | |
|---|
| 920 | | - for (i = 0; i < num_rqst; i++) |
|---|
| 921 | | - if (!cancelled_mid[i] && midQ[i]->resp_buf |
|---|
| 922 | | - && (midQ[i]->mid_state == MID_RESPONSE_RECEIVED)) |
|---|
| 923 | | - credits[i] = ses->server->ops->get_credits(midQ[i]); |
|---|
| 924 | | - |
|---|
| 925 | 1184 | for (i = 0; i < num_rqst; i++) { |
|---|
| 926 | 1185 | if (rc < 0) |
|---|
| 927 | 1186 | goto out; |
|---|
| 928 | 1187 | |
|---|
| 929 | | - rc = cifs_sync_mid_result(midQ[i], ses->server); |
|---|
| 1188 | + rc = cifs_sync_mid_result(midQ[i], server); |
|---|
| 930 | 1189 | if (rc != 0) { |
|---|
| 931 | 1190 | /* mark this mid as cancelled to not free it below */ |
|---|
| 932 | 1191 | cancelled_mid[i] = true; |
|---|
| .. | .. |
|---|
| 943 | 1202 | buf = (char *)midQ[i]->resp_buf; |
|---|
| 944 | 1203 | resp_iov[i].iov_base = buf; |
|---|
| 945 | 1204 | resp_iov[i].iov_len = midQ[i]->resp_buf_size + |
|---|
| 946 | | - ses->server->vals->header_preamble_size; |
|---|
| 1205 | + server->vals->header_preamble_size; |
|---|
| 947 | 1206 | |
|---|
| 948 | 1207 | if (midQ[i]->large_buf) |
|---|
| 949 | 1208 | resp_buf_type[i] = CIFS_LARGE_BUFFER; |
|---|
| 950 | 1209 | else |
|---|
| 951 | 1210 | resp_buf_type[i] = CIFS_SMALL_BUFFER; |
|---|
| 952 | 1211 | |
|---|
| 953 | | - rc = ses->server->ops->check_receive(midQ[i], ses->server, |
|---|
| 1212 | + rc = server->ops->check_receive(midQ[i], server, |
|---|
| 954 | 1213 | flags & CIFS_LOG_ERROR); |
|---|
| 955 | 1214 | |
|---|
| 956 | 1215 | /* mark it so buf will not be freed by cifs_delete_mid */ |
|---|
| 957 | | - if ((flags & CIFS_NO_RESP) == 0) |
|---|
| 1216 | + if ((flags & CIFS_NO_RSP_BUF) == 0) |
|---|
| 958 | 1217 | midQ[i]->resp_buf = NULL; |
|---|
| 959 | 1218 | |
|---|
| 960 | 1219 | } |
|---|
| .. | .. |
|---|
| 967 | 1226 | .iov_base = resp_iov[0].iov_base, |
|---|
| 968 | 1227 | .iov_len = resp_iov[0].iov_len |
|---|
| 969 | 1228 | }; |
|---|
| 970 | | - mutex_lock(&ses->server->srv_mutex); |
|---|
| 1229 | + mutex_lock(&server->srv_mutex); |
|---|
| 971 | 1230 | smb311_update_preauth_hash(ses, &iov, 1); |
|---|
| 972 | | - mutex_unlock(&ses->server->srv_mutex); |
|---|
| 1231 | + mutex_unlock(&server->srv_mutex); |
|---|
| 973 | 1232 | } |
|---|
| 974 | 1233 | |
|---|
| 975 | 1234 | out: |
|---|
| .. | .. |
|---|
| 982 | 1241 | for (i = 0; i < num_rqst; i++) { |
|---|
| 983 | 1242 | if (!cancelled_mid[i]) |
|---|
| 984 | 1243 | cifs_delete_mid(midQ[i]); |
|---|
| 985 | | - add_credits(ses->server, credits[i], optype); |
|---|
| 986 | 1244 | } |
|---|
| 987 | 1245 | |
|---|
| 988 | 1246 | return rc; |
|---|
| .. | .. |
|---|
| 990 | 1248 | |
|---|
| 991 | 1249 | int |
|---|
| 992 | 1250 | cifs_send_recv(const unsigned int xid, struct cifs_ses *ses, |
|---|
| 1251 | + struct TCP_Server_Info *server, |
|---|
| 993 | 1252 | struct smb_rqst *rqst, int *resp_buf_type, const int flags, |
|---|
| 994 | 1253 | struct kvec *resp_iov) |
|---|
| 995 | 1254 | { |
|---|
| 996 | | - return compound_send_recv(xid, ses, flags, 1, rqst, resp_buf_type, |
|---|
| 997 | | - resp_iov); |
|---|
| 1255 | + return compound_send_recv(xid, ses, server, flags, 1, |
|---|
| 1256 | + rqst, resp_buf_type, resp_iov); |
|---|
| 998 | 1257 | } |
|---|
| 999 | 1258 | |
|---|
| 1000 | 1259 | int |
|---|
| .. | .. |
|---|
| 1029 | 1288 | rqst.rq_iov = new_iov; |
|---|
| 1030 | 1289 | rqst.rq_nvec = n_vec + 1; |
|---|
| 1031 | 1290 | |
|---|
| 1032 | | - rc = cifs_send_recv(xid, ses, &rqst, resp_buf_type, flags, resp_iov); |
|---|
| 1291 | + rc = cifs_send_recv(xid, ses, ses->server, |
|---|
| 1292 | + &rqst, resp_buf_type, flags, resp_iov); |
|---|
| 1033 | 1293 | if (n_vec + 1 > CIFS_MAX_IOV_SIZE) |
|---|
| 1034 | 1294 | kfree(new_iov); |
|---|
| 1035 | 1295 | return rc; |
|---|
| .. | .. |
|---|
| 1038 | 1298 | int |
|---|
| 1039 | 1299 | SendReceive(const unsigned int xid, struct cifs_ses *ses, |
|---|
| 1040 | 1300 | struct smb_hdr *in_buf, struct smb_hdr *out_buf, |
|---|
| 1041 | | - int *pbytes_returned, const int timeout) |
|---|
| 1301 | + int *pbytes_returned, const int flags) |
|---|
| 1042 | 1302 | { |
|---|
| 1043 | 1303 | int rc = 0; |
|---|
| 1044 | 1304 | struct mid_q_entry *midQ; |
|---|
| 1045 | 1305 | unsigned int len = be32_to_cpu(in_buf->smb_buf_length); |
|---|
| 1046 | 1306 | struct kvec iov = { .iov_base = in_buf, .iov_len = len }; |
|---|
| 1047 | 1307 | struct smb_rqst rqst = { .rq_iov = &iov, .rq_nvec = 1 }; |
|---|
| 1308 | + struct cifs_credits credits = { .value = 1, .instance = 0 }; |
|---|
| 1309 | + struct TCP_Server_Info *server; |
|---|
| 1048 | 1310 | |
|---|
| 1049 | 1311 | if (ses == NULL) { |
|---|
| 1050 | 1312 | cifs_dbg(VFS, "Null smb session\n"); |
|---|
| 1051 | 1313 | return -EIO; |
|---|
| 1052 | 1314 | } |
|---|
| 1053 | | - if (ses->server == NULL) { |
|---|
| 1315 | + server = ses->server; |
|---|
| 1316 | + if (server == NULL) { |
|---|
| 1054 | 1317 | cifs_dbg(VFS, "Null tcp session\n"); |
|---|
| 1055 | 1318 | return -EIO; |
|---|
| 1056 | 1319 | } |
|---|
| 1057 | 1320 | |
|---|
| 1058 | | - if (ses->server->tcpStatus == CifsExiting) |
|---|
| 1321 | + if (server->tcpStatus == CifsExiting) |
|---|
| 1059 | 1322 | return -ENOENT; |
|---|
| 1060 | 1323 | |
|---|
| 1061 | 1324 | /* Ensure that we do not send more than 50 overlapping requests |
|---|
| .. | .. |
|---|
| 1063 | 1326 | use ses->maxReq */ |
|---|
| 1064 | 1327 | |
|---|
| 1065 | 1328 | if (len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) { |
|---|
| 1066 | | - cifs_dbg(VFS, "Illegal length, greater than maximum frame, %d\n", |
|---|
| 1067 | | - len); |
|---|
| 1329 | + cifs_server_dbg(VFS, "Invalid length, greater than maximum frame, %d\n", |
|---|
| 1330 | + len); |
|---|
| 1068 | 1331 | return -EIO; |
|---|
| 1069 | 1332 | } |
|---|
| 1070 | 1333 | |
|---|
| 1071 | | - rc = wait_for_free_request(ses->server, timeout, 0); |
|---|
| 1334 | + rc = wait_for_free_request(server, flags, &credits.instance); |
|---|
| 1072 | 1335 | if (rc) |
|---|
| 1073 | 1336 | return rc; |
|---|
| 1074 | 1337 | |
|---|
| .. | .. |
|---|
| 1076 | 1339 | and avoid races inside tcp sendmsg code that could cause corruption |
|---|
| 1077 | 1340 | of smb data */ |
|---|
| 1078 | 1341 | |
|---|
| 1079 | | - mutex_lock(&ses->server->srv_mutex); |
|---|
| 1342 | + mutex_lock(&server->srv_mutex); |
|---|
| 1080 | 1343 | |
|---|
| 1081 | 1344 | rc = allocate_mid(ses, in_buf, &midQ); |
|---|
| 1082 | 1345 | if (rc) { |
|---|
| 1083 | | - mutex_unlock(&ses->server->srv_mutex); |
|---|
| 1346 | + mutex_unlock(&server->srv_mutex); |
|---|
| 1084 | 1347 | /* Update # of requests on wire to server */ |
|---|
| 1085 | | - add_credits(ses->server, 1, 0); |
|---|
| 1348 | + add_credits(server, &credits, 0); |
|---|
| 1086 | 1349 | return rc; |
|---|
| 1087 | 1350 | } |
|---|
| 1088 | 1351 | |
|---|
| 1089 | | - rc = cifs_sign_smb(in_buf, ses->server, &midQ->sequence_number); |
|---|
| 1352 | + rc = cifs_sign_smb(in_buf, server, &midQ->sequence_number); |
|---|
| 1090 | 1353 | if (rc) { |
|---|
| 1091 | | - mutex_unlock(&ses->server->srv_mutex); |
|---|
| 1354 | + mutex_unlock(&server->srv_mutex); |
|---|
| 1092 | 1355 | goto out; |
|---|
| 1093 | 1356 | } |
|---|
| 1094 | 1357 | |
|---|
| 1095 | 1358 | midQ->mid_state = MID_REQUEST_SUBMITTED; |
|---|
| 1096 | 1359 | |
|---|
| 1097 | | - cifs_in_send_inc(ses->server); |
|---|
| 1098 | | - rc = smb_send(ses->server, in_buf, len); |
|---|
| 1099 | | - cifs_in_send_dec(ses->server); |
|---|
| 1360 | + rc = smb_send(server, in_buf, len); |
|---|
| 1100 | 1361 | cifs_save_when_sent(midQ); |
|---|
| 1101 | 1362 | |
|---|
| 1102 | 1363 | if (rc < 0) |
|---|
| 1103 | | - ses->server->sequence_number -= 2; |
|---|
| 1364 | + server->sequence_number -= 2; |
|---|
| 1104 | 1365 | |
|---|
| 1105 | | - mutex_unlock(&ses->server->srv_mutex); |
|---|
| 1366 | + mutex_unlock(&server->srv_mutex); |
|---|
| 1106 | 1367 | |
|---|
| 1107 | 1368 | if (rc < 0) |
|---|
| 1108 | 1369 | goto out; |
|---|
| 1109 | 1370 | |
|---|
| 1110 | | - if (timeout == CIFS_ASYNC_OP) |
|---|
| 1111 | | - goto out; |
|---|
| 1112 | | - |
|---|
| 1113 | | - rc = wait_for_response(ses->server, midQ); |
|---|
| 1371 | + rc = wait_for_response(server, midQ); |
|---|
| 1114 | 1372 | if (rc != 0) { |
|---|
| 1115 | | - send_cancel(ses->server, &rqst, midQ); |
|---|
| 1373 | + send_cancel(server, &rqst, midQ); |
|---|
| 1116 | 1374 | spin_lock(&GlobalMid_Lock); |
|---|
| 1117 | 1375 | if (midQ->mid_state == MID_REQUEST_SUBMITTED) { |
|---|
| 1118 | 1376 | /* no longer considered to be "in-flight" */ |
|---|
| 1119 | 1377 | midQ->callback = DeleteMidQEntry; |
|---|
| 1120 | 1378 | spin_unlock(&GlobalMid_Lock); |
|---|
| 1121 | | - add_credits(ses->server, 1, 0); |
|---|
| 1379 | + add_credits(server, &credits, 0); |
|---|
| 1122 | 1380 | return rc; |
|---|
| 1123 | 1381 | } |
|---|
| 1124 | 1382 | spin_unlock(&GlobalMid_Lock); |
|---|
| 1125 | 1383 | } |
|---|
| 1126 | 1384 | |
|---|
| 1127 | | - rc = cifs_sync_mid_result(midQ, ses->server); |
|---|
| 1385 | + rc = cifs_sync_mid_result(midQ, server); |
|---|
| 1128 | 1386 | if (rc != 0) { |
|---|
| 1129 | | - add_credits(ses->server, 1, 0); |
|---|
| 1387 | + add_credits(server, &credits, 0); |
|---|
| 1130 | 1388 | return rc; |
|---|
| 1131 | 1389 | } |
|---|
| 1132 | 1390 | |
|---|
| 1133 | 1391 | if (!midQ->resp_buf || !out_buf || |
|---|
| 1134 | 1392 | midQ->mid_state != MID_RESPONSE_RECEIVED) { |
|---|
| 1135 | 1393 | rc = -EIO; |
|---|
| 1136 | | - cifs_dbg(VFS, "Bad MID state?\n"); |
|---|
| 1394 | + cifs_server_dbg(VFS, "Bad MID state?\n"); |
|---|
| 1137 | 1395 | goto out; |
|---|
| 1138 | 1396 | } |
|---|
| 1139 | 1397 | |
|---|
| 1140 | 1398 | *pbytes_returned = get_rfc1002_length(midQ->resp_buf); |
|---|
| 1141 | 1399 | memcpy(out_buf, midQ->resp_buf, *pbytes_returned + 4); |
|---|
| 1142 | | - rc = cifs_check_receive(midQ, ses->server, 0); |
|---|
| 1400 | + rc = cifs_check_receive(midQ, server, 0); |
|---|
| 1143 | 1401 | out: |
|---|
| 1144 | 1402 | cifs_delete_mid(midQ); |
|---|
| 1145 | | - add_credits(ses->server, 1, 0); |
|---|
| 1403 | + add_credits(server, &credits, 0); |
|---|
| 1146 | 1404 | |
|---|
| 1147 | 1405 | return rc; |
|---|
| 1148 | 1406 | } |
|---|
| .. | .. |
|---|
| 1184 | 1442 | unsigned int len = be32_to_cpu(in_buf->smb_buf_length); |
|---|
| 1185 | 1443 | struct kvec iov = { .iov_base = in_buf, .iov_len = len }; |
|---|
| 1186 | 1444 | struct smb_rqst rqst = { .rq_iov = &iov, .rq_nvec = 1 }; |
|---|
| 1445 | + unsigned int instance; |
|---|
| 1446 | + struct TCP_Server_Info *server; |
|---|
| 1187 | 1447 | |
|---|
| 1188 | 1448 | if (tcon == NULL || tcon->ses == NULL) { |
|---|
| 1189 | 1449 | cifs_dbg(VFS, "Null smb session\n"); |
|---|
| 1190 | 1450 | return -EIO; |
|---|
| 1191 | 1451 | } |
|---|
| 1192 | 1452 | ses = tcon->ses; |
|---|
| 1453 | + server = ses->server; |
|---|
| 1193 | 1454 | |
|---|
| 1194 | | - if (ses->server == NULL) { |
|---|
| 1455 | + if (server == NULL) { |
|---|
| 1195 | 1456 | cifs_dbg(VFS, "Null tcp session\n"); |
|---|
| 1196 | 1457 | return -EIO; |
|---|
| 1197 | 1458 | } |
|---|
| 1198 | 1459 | |
|---|
| 1199 | | - if (ses->server->tcpStatus == CifsExiting) |
|---|
| 1460 | + if (server->tcpStatus == CifsExiting) |
|---|
| 1200 | 1461 | return -ENOENT; |
|---|
| 1201 | 1462 | |
|---|
| 1202 | 1463 | /* Ensure that we do not send more than 50 overlapping requests |
|---|
| .. | .. |
|---|
| 1204 | 1465 | use ses->maxReq */ |
|---|
| 1205 | 1466 | |
|---|
| 1206 | 1467 | if (len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) { |
|---|
| 1207 | | - cifs_dbg(VFS, "Illegal length, greater than maximum frame, %d\n", |
|---|
| 1208 | | - len); |
|---|
| 1468 | + cifs_tcon_dbg(VFS, "Invalid length, greater than maximum frame, %d\n", |
|---|
| 1469 | + len); |
|---|
| 1209 | 1470 | return -EIO; |
|---|
| 1210 | 1471 | } |
|---|
| 1211 | 1472 | |
|---|
| 1212 | | - rc = wait_for_free_request(ses->server, CIFS_BLOCKING_OP, 0); |
|---|
| 1473 | + rc = wait_for_free_request(server, CIFS_BLOCKING_OP, &instance); |
|---|
| 1213 | 1474 | if (rc) |
|---|
| 1214 | 1475 | return rc; |
|---|
| 1215 | 1476 | |
|---|
| .. | .. |
|---|
| 1217 | 1478 | and avoid races inside tcp sendmsg code that could cause corruption |
|---|
| 1218 | 1479 | of smb data */ |
|---|
| 1219 | 1480 | |
|---|
| 1220 | | - mutex_lock(&ses->server->srv_mutex); |
|---|
| 1481 | + mutex_lock(&server->srv_mutex); |
|---|
| 1221 | 1482 | |
|---|
| 1222 | 1483 | rc = allocate_mid(ses, in_buf, &midQ); |
|---|
| 1223 | 1484 | if (rc) { |
|---|
| 1224 | | - mutex_unlock(&ses->server->srv_mutex); |
|---|
| 1485 | + mutex_unlock(&server->srv_mutex); |
|---|
| 1225 | 1486 | return rc; |
|---|
| 1226 | 1487 | } |
|---|
| 1227 | 1488 | |
|---|
| 1228 | | - rc = cifs_sign_smb(in_buf, ses->server, &midQ->sequence_number); |
|---|
| 1489 | + rc = cifs_sign_smb(in_buf, server, &midQ->sequence_number); |
|---|
| 1229 | 1490 | if (rc) { |
|---|
| 1230 | 1491 | cifs_delete_mid(midQ); |
|---|
| 1231 | | - mutex_unlock(&ses->server->srv_mutex); |
|---|
| 1492 | + mutex_unlock(&server->srv_mutex); |
|---|
| 1232 | 1493 | return rc; |
|---|
| 1233 | 1494 | } |
|---|
| 1234 | 1495 | |
|---|
| 1235 | 1496 | midQ->mid_state = MID_REQUEST_SUBMITTED; |
|---|
| 1236 | | - cifs_in_send_inc(ses->server); |
|---|
| 1237 | | - rc = smb_send(ses->server, in_buf, len); |
|---|
| 1238 | | - cifs_in_send_dec(ses->server); |
|---|
| 1497 | + rc = smb_send(server, in_buf, len); |
|---|
| 1239 | 1498 | cifs_save_when_sent(midQ); |
|---|
| 1240 | 1499 | |
|---|
| 1241 | 1500 | if (rc < 0) |
|---|
| 1242 | | - ses->server->sequence_number -= 2; |
|---|
| 1501 | + server->sequence_number -= 2; |
|---|
| 1243 | 1502 | |
|---|
| 1244 | | - mutex_unlock(&ses->server->srv_mutex); |
|---|
| 1503 | + mutex_unlock(&server->srv_mutex); |
|---|
| 1245 | 1504 | |
|---|
| 1246 | 1505 | if (rc < 0) { |
|---|
| 1247 | 1506 | cifs_delete_mid(midQ); |
|---|
| .. | .. |
|---|
| 1249 | 1508 | } |
|---|
| 1250 | 1509 | |
|---|
| 1251 | 1510 | /* Wait for a reply - allow signals to interrupt. */ |
|---|
| 1252 | | - rc = wait_event_interruptible(ses->server->response_q, |
|---|
| 1511 | + rc = wait_event_interruptible(server->response_q, |
|---|
| 1253 | 1512 | (!(midQ->mid_state == MID_REQUEST_SUBMITTED)) || |
|---|
| 1254 | | - ((ses->server->tcpStatus != CifsGood) && |
|---|
| 1255 | | - (ses->server->tcpStatus != CifsNew))); |
|---|
| 1513 | + ((server->tcpStatus != CifsGood) && |
|---|
| 1514 | + (server->tcpStatus != CifsNew))); |
|---|
| 1256 | 1515 | |
|---|
| 1257 | 1516 | /* Were we interrupted by a signal ? */ |
|---|
| 1258 | 1517 | if ((rc == -ERESTARTSYS) && |
|---|
| 1259 | 1518 | (midQ->mid_state == MID_REQUEST_SUBMITTED) && |
|---|
| 1260 | | - ((ses->server->tcpStatus == CifsGood) || |
|---|
| 1261 | | - (ses->server->tcpStatus == CifsNew))) { |
|---|
| 1519 | + ((server->tcpStatus == CifsGood) || |
|---|
| 1520 | + (server->tcpStatus == CifsNew))) { |
|---|
| 1262 | 1521 | |
|---|
| 1263 | 1522 | if (in_buf->Command == SMB_COM_TRANSACTION2) { |
|---|
| 1264 | 1523 | /* POSIX lock. We send a NT_CANCEL SMB to cause the |
|---|
| 1265 | 1524 | blocking lock to return. */ |
|---|
| 1266 | | - rc = send_cancel(ses->server, &rqst, midQ); |
|---|
| 1525 | + rc = send_cancel(server, &rqst, midQ); |
|---|
| 1267 | 1526 | if (rc) { |
|---|
| 1268 | 1527 | cifs_delete_mid(midQ); |
|---|
| 1269 | 1528 | return rc; |
|---|
| .. | .. |
|---|
| 1282 | 1541 | } |
|---|
| 1283 | 1542 | } |
|---|
| 1284 | 1543 | |
|---|
| 1285 | | - rc = wait_for_response(ses->server, midQ); |
|---|
| 1544 | + rc = wait_for_response(server, midQ); |
|---|
| 1286 | 1545 | if (rc) { |
|---|
| 1287 | | - send_cancel(ses->server, &rqst, midQ); |
|---|
| 1546 | + send_cancel(server, &rqst, midQ); |
|---|
| 1288 | 1547 | spin_lock(&GlobalMid_Lock); |
|---|
| 1289 | 1548 | if (midQ->mid_state == MID_REQUEST_SUBMITTED) { |
|---|
| 1290 | 1549 | /* no longer considered to be "in-flight" */ |
|---|
| .. | .. |
|---|
| 1299 | 1558 | rstart = 1; |
|---|
| 1300 | 1559 | } |
|---|
| 1301 | 1560 | |
|---|
| 1302 | | - rc = cifs_sync_mid_result(midQ, ses->server); |
|---|
| 1561 | + rc = cifs_sync_mid_result(midQ, server); |
|---|
| 1303 | 1562 | if (rc != 0) |
|---|
| 1304 | 1563 | return rc; |
|---|
| 1305 | 1564 | |
|---|
| 1306 | 1565 | /* rcvd frame is ok */ |
|---|
| 1307 | 1566 | if (out_buf == NULL || midQ->mid_state != MID_RESPONSE_RECEIVED) { |
|---|
| 1308 | 1567 | rc = -EIO; |
|---|
| 1309 | | - cifs_dbg(VFS, "Bad MID state?\n"); |
|---|
| 1568 | + cifs_tcon_dbg(VFS, "Bad MID state?\n"); |
|---|
| 1310 | 1569 | goto out; |
|---|
| 1311 | 1570 | } |
|---|
| 1312 | 1571 | |
|---|
| 1313 | 1572 | *pbytes_returned = get_rfc1002_length(midQ->resp_buf); |
|---|
| 1314 | 1573 | memcpy(out_buf, midQ->resp_buf, *pbytes_returned + 4); |
|---|
| 1315 | | - rc = cifs_check_receive(midQ, ses->server, 0); |
|---|
| 1574 | + rc = cifs_check_receive(midQ, server, 0); |
|---|
| 1316 | 1575 | out: |
|---|
| 1317 | 1576 | cifs_delete_mid(midQ); |
|---|
| 1318 | 1577 | if (rstart && rc == -EACCES) |
|---|