4 * Copyright (C) International Business Machines Corp., 2002,2008
5 * Author(s): Steve French (sfrench@us.ibm.com)
6 * Jeremy Allison (jra@samba.org) 2006.
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.
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.
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
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <linux/list.h>
25 #include <linux/gfp.h>
26 #include <linux/wait.h>
27 #include <linux/net.h>
28 #include <linux/delay.h>
29 #include <linux/freezer.h>
30 #include <asm/uaccess.h>
31 #include <asm/processor.h>
32 #include <linux/mempool.h>
35 #include "cifsproto.h"
36 #include "cifs_debug.h"
39 cifs_wake_up_task(struct mid_q_entry
*mid
)
41 wake_up_process(mid
->callback_data
);
45 AllocMidQEntry(const struct smb_hdr
*smb_buffer
, struct TCP_Server_Info
*server
)
47 struct mid_q_entry
*temp
;
50 cERROR(1, "Null TCP session in AllocMidQEntry");
54 temp
= mempool_alloc(cifs_mid_poolp
, GFP_NOFS
);
58 memset(temp
, 0, sizeof(struct mid_q_entry
));
59 temp
->mid
= smb_buffer
->Mid
; /* always LE */
60 temp
->pid
= current
->pid
;
61 temp
->command
= cpu_to_le16(smb_buffer
->Command
);
62 cFYI(1, "For smb_command %d", smb_buffer
->Command
);
63 /* do_gettimeofday(&temp->when_sent);*/ /* easier to use jiffies */
64 /* when mid allocated can be before when sent */
65 temp
->when_alloc
= jiffies
;
66 temp
->server
= server
;
69 * The default is for the mid to be synchronous, so the
70 * default callback just wakes up the current task.
72 temp
->callback
= cifs_wake_up_task
;
73 temp
->callback_data
= current
;
76 atomic_inc(&midCount
);
77 temp
->mid_state
= MID_REQUEST_ALLOCATED
;
82 DeleteMidQEntry(struct mid_q_entry
*midEntry
)
84 #ifdef CONFIG_CIFS_STATS2
85 __le16 command
= midEntry
->server
->vals
->lock_cmd
;
88 midEntry
->mid_state
= MID_FREE
;
89 atomic_dec(&midCount
);
90 if (midEntry
->large_buf
)
91 cifs_buf_release(midEntry
->resp_buf
);
93 cifs_small_buf_release(midEntry
->resp_buf
);
94 #ifdef CONFIG_CIFS_STATS2
96 /* commands taking longer than one second are indications that
97 something is wrong, unless it is quite a slow link or server */
98 if ((now
- midEntry
->when_alloc
) > HZ
) {
99 if ((cifsFYI
& CIFS_TIMER
) && (midEntry
->command
!= command
)) {
100 printk(KERN_DEBUG
" CIFS slow rsp: cmd %d mid %llu",
101 midEntry
->command
, midEntry
->mid
);
102 printk(" A: 0x%lx S: 0x%lx R: 0x%lx\n",
103 now
- midEntry
->when_alloc
,
104 now
- midEntry
->when_sent
,
105 now
- midEntry
->when_received
);
109 mempool_free(midEntry
, cifs_mid_poolp
);
113 delete_mid(struct mid_q_entry
*mid
)
115 spin_lock(&GlobalMid_Lock
);
116 list_del(&mid
->qhead
);
117 spin_unlock(&GlobalMid_Lock
);
119 DeleteMidQEntry(mid
);
123 smb_sendv(struct TCP_Server_Info
*server
, struct kvec
*iov
, int n_vec
)
127 struct msghdr smb_msg
;
128 unsigned int len
= iov
[0].iov_len
;
129 unsigned int total_len
;
131 unsigned int smb_buf_length
= get_rfc1002_length(iov
[0].iov_base
);
132 struct socket
*ssocket
= server
->ssocket
;
135 return -ENOTSOCK
; /* BB eventually add reconnect code here */
137 smb_msg
.msg_name
= (struct sockaddr
*) &server
->dstaddr
;
138 smb_msg
.msg_namelen
= sizeof(struct sockaddr
);
139 smb_msg
.msg_control
= NULL
;
140 smb_msg
.msg_controllen
= 0;
141 if (server
->noblocksnd
)
142 smb_msg
.msg_flags
= MSG_DONTWAIT
+ MSG_NOSIGNAL
;
144 smb_msg
.msg_flags
= MSG_NOSIGNAL
;
147 for (i
= 0; i
< n_vec
; i
++)
148 total_len
+= iov
[i
].iov_len
;
150 cFYI(1, "Sending smb: total_len %d", total_len
);
151 dump_smb(iov
[0].iov_base
, len
);
155 rc
= kernel_sendmsg(ssocket
, &smb_msg
, &iov
[first_vec
],
156 n_vec
- first_vec
, total_len
);
157 if ((rc
== -ENOSPC
) || (rc
== -EAGAIN
)) {
160 * If blocking send we try 3 times, since each can block
161 * for 5 seconds. For nonblocking we have to try more
162 * but wait increasing amounts of time allowing time for
163 * socket to clear. The overall time we wait in either
164 * case to send on the socket is about 15 seconds.
165 * Similarly we wait for 15 seconds for a response from
166 * the server in SendReceive[2] for the server to send
167 * a response back for most types of requests (except
168 * SMB Write past end of file which can be slow, and
169 * blocking lock operations). NFS waits slightly longer
170 * than CIFS, but this can make it take longer for
171 * nonresponsive servers to be detected and 15 seconds
172 * is more than enough time for modern networks to
173 * send a packet. In most cases if we fail to send
174 * after the retries we will kill the socket and
175 * reconnect which may clear the network problem.
177 if ((i
>= 14) || (!server
->noblocksnd
&& (i
> 2))) {
178 cERROR(1, "sends on sock %p stuck for 15 seconds",
189 if (rc
== total_len
) {
192 } else if (rc
> total_len
) {
193 cERROR(1, "sent %d requested %d", rc
, total_len
);
197 /* should never happen, letting socket clear before
198 retrying is our only obvious option here */
199 cERROR(1, "tcp sent no data");
204 /* the line below resets i */
205 for (i
= first_vec
; i
< n_vec
; i
++) {
206 if (iov
[i
].iov_len
) {
207 if (rc
> iov
[i
].iov_len
) {
208 rc
-= iov
[i
].iov_len
;
211 iov
[i
].iov_base
+= rc
;
212 iov
[i
].iov_len
-= rc
;
218 i
= 0; /* in case we get ENOSPC on the next send */
221 if ((total_len
> 0) && (total_len
!= smb_buf_length
+ 4)) {
222 cFYI(1, "partial send (%d remaining), terminating session",
224 /* If we have only sent part of an SMB then the next SMB
225 could be taken as the remainder of this one. We need
226 to kill the socket so the server throws away the partial
228 server
->tcpStatus
= CifsNeedReconnect
;
231 if (rc
< 0 && rc
!= -EINTR
)
232 cERROR(1, "Error %d sending data on socket to server", rc
);
240 smb_send(struct TCP_Server_Info
*server
, struct smb_hdr
*smb_buffer
,
241 unsigned int smb_buf_length
)
245 iov
.iov_base
= smb_buffer
;
246 iov
.iov_len
= smb_buf_length
+ 4;
248 return smb_sendv(server
, &iov
, 1);
252 wait_for_free_credits(struct TCP_Server_Info
*server
, const int timeout
,
257 spin_lock(&server
->req_lock
);
258 if (timeout
== CIFS_ASYNC_OP
) {
259 /* oplock breaks must not be held up */
262 spin_unlock(&server
->req_lock
);
268 spin_unlock(&server
->req_lock
);
269 cifs_num_waiters_inc(server
);
270 rc
= wait_event_killable(server
->request_q
,
271 has_credits(server
, credits
));
272 cifs_num_waiters_dec(server
);
275 spin_lock(&server
->req_lock
);
277 if (server
->tcpStatus
== CifsExiting
) {
278 spin_unlock(&server
->req_lock
);
283 * Can not count locking commands against total
284 * as they are allowed to block on server.
287 /* update # of requests on the wire to server */
288 if (timeout
!= CIFS_BLOCKING_OP
) {
292 spin_unlock(&server
->req_lock
);
300 wait_for_free_request(struct TCP_Server_Info
*server
, const int timeout
,
303 return wait_for_free_credits(server
, timeout
,
304 server
->ops
->get_credits_field(server
, optype
));
307 static int allocate_mid(struct cifs_ses
*ses
, struct smb_hdr
*in_buf
,
308 struct mid_q_entry
**ppmidQ
)
310 if (ses
->server
->tcpStatus
== CifsExiting
) {
314 if (ses
->server
->tcpStatus
== CifsNeedReconnect
) {
315 cFYI(1, "tcp session dead - return to caller to retry");
319 if (ses
->status
!= CifsGood
) {
320 /* check if SMB session is bad because we are setting it up */
321 if ((in_buf
->Command
!= SMB_COM_SESSION_SETUP_ANDX
) &&
322 (in_buf
->Command
!= SMB_COM_NEGOTIATE
))
324 /* else ok - we are setting up session */
326 *ppmidQ
= AllocMidQEntry(in_buf
, ses
->server
);
329 spin_lock(&GlobalMid_Lock
);
330 list_add_tail(&(*ppmidQ
)->qhead
, &ses
->server
->pending_mid_q
);
331 spin_unlock(&GlobalMid_Lock
);
336 wait_for_response(struct TCP_Server_Info
*server
, struct mid_q_entry
*midQ
)
340 error
= wait_event_freezekillable(server
->response_q
,
341 midQ
->mid_state
!= MID_REQUEST_SUBMITTED
);
349 cifs_setup_async_request(struct TCP_Server_Info
*server
, struct kvec
*iov
,
350 unsigned int nvec
, struct mid_q_entry
**ret_mid
)
353 struct smb_hdr
*hdr
= (struct smb_hdr
*)iov
[0].iov_base
;
354 struct mid_q_entry
*mid
;
356 /* enable signing if server requires it */
357 if (server
->sec_mode
& (SECMODE_SIGN_REQUIRED
| SECMODE_SIGN_ENABLED
))
358 hdr
->Flags2
|= SMBFLG2_SECURITY_SIGNATURE
;
360 mid
= AllocMidQEntry(hdr
, server
);
364 rc
= cifs_sign_smbv(iov
, nvec
, server
, &mid
->sequence_number
);
366 DeleteMidQEntry(mid
);
375 * Send a SMB request and set the callback function in the mid to handle
376 * the result. Caller is responsible for dealing with timeouts.
379 cifs_call_async(struct TCP_Server_Info
*server
, struct kvec
*iov
,
380 unsigned int nvec
, mid_receive_t
*receive
,
381 mid_callback_t
*callback
, void *cbdata
, const int flags
)
383 int rc
, timeout
, optype
;
384 struct mid_q_entry
*mid
;
386 timeout
= flags
& CIFS_TIMEOUT_MASK
;
387 optype
= flags
& CIFS_OP_MASK
;
389 rc
= wait_for_free_request(server
, timeout
, optype
);
393 mutex_lock(&server
->srv_mutex
);
394 rc
= server
->ops
->setup_async_request(server
, iov
, nvec
, &mid
);
396 mutex_unlock(&server
->srv_mutex
);
397 add_credits(server
, 1, optype
);
398 wake_up(&server
->request_q
);
402 mid
->receive
= receive
;
403 mid
->callback
= callback
;
404 mid
->callback_data
= cbdata
;
405 mid
->mid_state
= MID_REQUEST_SUBMITTED
;
407 /* put it on the pending_mid_q */
408 spin_lock(&GlobalMid_Lock
);
409 list_add_tail(&mid
->qhead
, &server
->pending_mid_q
);
410 spin_unlock(&GlobalMid_Lock
);
413 cifs_in_send_inc(server
);
414 rc
= smb_sendv(server
, iov
, nvec
);
415 cifs_in_send_dec(server
);
416 cifs_save_when_sent(mid
);
417 mutex_unlock(&server
->srv_mutex
);
423 add_credits(server
, 1, optype
);
424 wake_up(&server
->request_q
);
430 * Send an SMB Request. No response info (other than return code)
431 * needs to be parsed.
433 * flags indicate the type of request buffer and how long to wait
434 * and whether to log NT STATUS code (error) before mapping it to POSIX error
438 SendReceiveNoRsp(const unsigned int xid
, struct cifs_ses
*ses
,
439 char *in_buf
, int flags
)
445 iov
[0].iov_base
= in_buf
;
446 iov
[0].iov_len
= get_rfc1002_length(in_buf
) + 4;
447 flags
|= CIFS_NO_RESP
;
448 rc
= SendReceive2(xid
, ses
, iov
, 1, &resp_buf_type
, flags
);
449 cFYI(DBG2
, "SendRcvNoRsp flags %d rc %d", flags
, rc
);
455 cifs_sync_mid_result(struct mid_q_entry
*mid
, struct TCP_Server_Info
*server
)
459 cFYI(1, "%s: cmd=%d mid=%llu state=%d", __func__
,
460 le16_to_cpu(mid
->command
), mid
->mid
, mid
->mid_state
);
462 spin_lock(&GlobalMid_Lock
);
463 switch (mid
->mid_state
) {
464 case MID_RESPONSE_RECEIVED
:
465 spin_unlock(&GlobalMid_Lock
);
467 case MID_RETRY_NEEDED
:
470 case MID_RESPONSE_MALFORMED
:
477 list_del_init(&mid
->qhead
);
478 cERROR(1, "%s: invalid mid state mid=%llu state=%d", __func__
,
479 mid
->mid
, mid
->mid_state
);
482 spin_unlock(&GlobalMid_Lock
);
484 DeleteMidQEntry(mid
);
489 send_cancel(struct TCP_Server_Info
*server
, void *buf
, struct mid_q_entry
*mid
)
491 return server
->ops
->send_cancel
?
492 server
->ops
->send_cancel(server
, buf
, mid
) : 0;
496 cifs_check_receive(struct mid_q_entry
*mid
, struct TCP_Server_Info
*server
,
499 unsigned int len
= get_rfc1002_length(mid
->resp_buf
) + 4;
501 dump_smb(mid
->resp_buf
, min_t(u32
, 92, len
));
503 /* convert the length into a more usable form */
504 if (server
->sec_mode
& (SECMODE_SIGN_REQUIRED
| SECMODE_SIGN_ENABLED
)) {
508 iov
.iov_base
= mid
->resp_buf
;
510 /* FIXME: add code to kill session */
511 rc
= cifs_verify_signature(&iov
, 1, server
,
512 mid
->sequence_number
+ 1);
514 cERROR(1, "SMB signature verification returned error = "
518 /* BB special case reconnect tid and uid here? */
519 return map_smb_to_linux_error(mid
->resp_buf
, log_error
);
523 cifs_setup_request(struct cifs_ses
*ses
, struct kvec
*iov
,
524 unsigned int nvec
, struct mid_q_entry
**ret_mid
)
527 struct smb_hdr
*hdr
= (struct smb_hdr
*)iov
[0].iov_base
;
528 struct mid_q_entry
*mid
;
530 rc
= allocate_mid(ses
, hdr
, &mid
);
533 rc
= cifs_sign_smbv(iov
, nvec
, ses
->server
, &mid
->sequence_number
);
541 SendReceive2(const unsigned int xid
, struct cifs_ses
*ses
,
542 struct kvec
*iov
, int n_vec
, int *resp_buf_type
/* ret */,
547 struct mid_q_entry
*midQ
;
548 char *buf
= iov
[0].iov_base
;
549 unsigned int credits
= 1;
551 timeout
= flags
& CIFS_TIMEOUT_MASK
;
552 optype
= flags
& CIFS_OP_MASK
;
554 *resp_buf_type
= CIFS_NO_BUFFER
; /* no response buf yet */
556 if ((ses
== NULL
) || (ses
->server
== NULL
)) {
557 cifs_small_buf_release(buf
);
558 cERROR(1, "Null session");
562 if (ses
->server
->tcpStatus
== CifsExiting
) {
563 cifs_small_buf_release(buf
);
568 * Ensure that we do not send more than 50 overlapping requests
569 * to the same server. We may make this configurable later or
573 rc
= wait_for_free_request(ses
->server
, timeout
, optype
);
575 cifs_small_buf_release(buf
);
580 * Make sure that we sign in the same order that we send on this socket
581 * and avoid races inside tcp sendmsg code that could cause corruption
585 mutex_lock(&ses
->server
->srv_mutex
);
587 rc
= ses
->server
->ops
->setup_request(ses
, iov
, n_vec
, &midQ
);
589 mutex_unlock(&ses
->server
->srv_mutex
);
590 cifs_small_buf_release(buf
);
591 /* Update # of requests on wire to server */
592 add_credits(ses
->server
, 1, optype
);
596 midQ
->mid_state
= MID_REQUEST_SUBMITTED
;
597 cifs_in_send_inc(ses
->server
);
598 rc
= smb_sendv(ses
->server
, iov
, n_vec
);
599 cifs_in_send_dec(ses
->server
);
600 cifs_save_when_sent(midQ
);
602 mutex_unlock(&ses
->server
->srv_mutex
);
605 cifs_small_buf_release(buf
);
609 if (timeout
== CIFS_ASYNC_OP
) {
610 cifs_small_buf_release(buf
);
614 rc
= wait_for_response(ses
->server
, midQ
);
616 send_cancel(ses
->server
, buf
, midQ
);
617 spin_lock(&GlobalMid_Lock
);
618 if (midQ
->mid_state
== MID_REQUEST_SUBMITTED
) {
619 midQ
->callback
= DeleteMidQEntry
;
620 spin_unlock(&GlobalMid_Lock
);
621 cifs_small_buf_release(buf
);
622 add_credits(ses
->server
, 1, optype
);
625 spin_unlock(&GlobalMid_Lock
);
628 cifs_small_buf_release(buf
);
630 rc
= cifs_sync_mid_result(midQ
, ses
->server
);
632 add_credits(ses
->server
, 1, optype
);
636 if (!midQ
->resp_buf
|| midQ
->mid_state
!= MID_RESPONSE_RECEIVED
) {
638 cFYI(1, "Bad MID state?");
642 buf
= (char *)midQ
->resp_buf
;
643 iov
[0].iov_base
= buf
;
644 iov
[0].iov_len
= get_rfc1002_length(buf
) + 4;
646 *resp_buf_type
= CIFS_LARGE_BUFFER
;
648 *resp_buf_type
= CIFS_SMALL_BUFFER
;
650 credits
= ses
->server
->ops
->get_credits(midQ
);
652 rc
= ses
->server
->ops
->check_receive(midQ
, ses
->server
,
653 flags
& CIFS_LOG_ERROR
);
655 /* mark it so buf will not be freed by delete_mid */
656 if ((flags
& CIFS_NO_RESP
) == 0)
657 midQ
->resp_buf
= NULL
;
660 add_credits(ses
->server
, credits
, optype
);
666 SendReceive(const unsigned int xid
, struct cifs_ses
*ses
,
667 struct smb_hdr
*in_buf
, struct smb_hdr
*out_buf
,
668 int *pbytes_returned
, const int timeout
)
671 struct mid_q_entry
*midQ
;
674 cERROR(1, "Null smb session");
677 if (ses
->server
== NULL
) {
678 cERROR(1, "Null tcp session");
682 if (ses
->server
->tcpStatus
== CifsExiting
)
685 /* Ensure that we do not send more than 50 overlapping requests
686 to the same server. We may make this configurable later or
689 if (be32_to_cpu(in_buf
->smb_buf_length
) > CIFSMaxBufSize
+
690 MAX_CIFS_HDR_SIZE
- 4) {
691 cERROR(1, "Illegal length, greater than maximum frame, %d",
692 be32_to_cpu(in_buf
->smb_buf_length
));
696 rc
= wait_for_free_request(ses
->server
, timeout
, 0);
700 /* make sure that we sign in the same order that we send on this socket
701 and avoid races inside tcp sendmsg code that could cause corruption
704 mutex_lock(&ses
->server
->srv_mutex
);
706 rc
= allocate_mid(ses
, in_buf
, &midQ
);
708 mutex_unlock(&ses
->server
->srv_mutex
);
709 /* Update # of requests on wire to server */
710 add_credits(ses
->server
, 1, 0);
714 rc
= cifs_sign_smb(in_buf
, ses
->server
, &midQ
->sequence_number
);
716 mutex_unlock(&ses
->server
->srv_mutex
);
720 midQ
->mid_state
= MID_REQUEST_SUBMITTED
;
722 cifs_in_send_inc(ses
->server
);
723 rc
= smb_send(ses
->server
, in_buf
, be32_to_cpu(in_buf
->smb_buf_length
));
724 cifs_in_send_dec(ses
->server
);
725 cifs_save_when_sent(midQ
);
726 mutex_unlock(&ses
->server
->srv_mutex
);
731 if (timeout
== CIFS_ASYNC_OP
)
734 rc
= wait_for_response(ses
->server
, midQ
);
736 send_cancel(ses
->server
, in_buf
, midQ
);
737 spin_lock(&GlobalMid_Lock
);
738 if (midQ
->mid_state
== MID_REQUEST_SUBMITTED
) {
739 /* no longer considered to be "in-flight" */
740 midQ
->callback
= DeleteMidQEntry
;
741 spin_unlock(&GlobalMid_Lock
);
742 add_credits(ses
->server
, 1, 0);
745 spin_unlock(&GlobalMid_Lock
);
748 rc
= cifs_sync_mid_result(midQ
, ses
->server
);
750 add_credits(ses
->server
, 1, 0);
754 if (!midQ
->resp_buf
|| !out_buf
||
755 midQ
->mid_state
!= MID_RESPONSE_RECEIVED
) {
757 cERROR(1, "Bad MID state?");
761 *pbytes_returned
= get_rfc1002_length(midQ
->resp_buf
);
762 memcpy(out_buf
, midQ
->resp_buf
, *pbytes_returned
+ 4);
763 rc
= cifs_check_receive(midQ
, ses
->server
, 0);
766 add_credits(ses
->server
, 1, 0);
771 /* We send a LOCKINGX_CANCEL_LOCK to cause the Windows
772 blocking lock to return. */
775 send_lock_cancel(const unsigned int xid
, struct cifs_tcon
*tcon
,
776 struct smb_hdr
*in_buf
,
777 struct smb_hdr
*out_buf
)
780 struct cifs_ses
*ses
= tcon
->ses
;
781 LOCK_REQ
*pSMB
= (LOCK_REQ
*)in_buf
;
783 /* We just modify the current in_buf to change
784 the type of lock from LOCKING_ANDX_SHARED_LOCK
785 or LOCKING_ANDX_EXCLUSIVE_LOCK to
786 LOCKING_ANDX_CANCEL_LOCK. */
788 pSMB
->LockType
= LOCKING_ANDX_CANCEL_LOCK
|LOCKING_ANDX_LARGE_FILES
;
790 pSMB
->hdr
.Mid
= get_next_mid(ses
->server
);
792 return SendReceive(xid
, ses
, in_buf
, out_buf
,
797 SendReceiveBlockingLock(const unsigned int xid
, struct cifs_tcon
*tcon
,
798 struct smb_hdr
*in_buf
, struct smb_hdr
*out_buf
,
799 int *pbytes_returned
)
803 struct mid_q_entry
*midQ
;
804 struct cifs_ses
*ses
;
806 if (tcon
== NULL
|| tcon
->ses
== NULL
) {
807 cERROR(1, "Null smb session");
812 if (ses
->server
== NULL
) {
813 cERROR(1, "Null tcp session");
817 if (ses
->server
->tcpStatus
== CifsExiting
)
820 /* Ensure that we do not send more than 50 overlapping requests
821 to the same server. We may make this configurable later or
824 if (be32_to_cpu(in_buf
->smb_buf_length
) > CIFSMaxBufSize
+
825 MAX_CIFS_HDR_SIZE
- 4) {
826 cERROR(1, "Illegal length, greater than maximum frame, %d",
827 be32_to_cpu(in_buf
->smb_buf_length
));
831 rc
= wait_for_free_request(ses
->server
, CIFS_BLOCKING_OP
, 0);
835 /* make sure that we sign in the same order that we send on this socket
836 and avoid races inside tcp sendmsg code that could cause corruption
839 mutex_lock(&ses
->server
->srv_mutex
);
841 rc
= allocate_mid(ses
, in_buf
, &midQ
);
843 mutex_unlock(&ses
->server
->srv_mutex
);
847 rc
= cifs_sign_smb(in_buf
, ses
->server
, &midQ
->sequence_number
);
850 mutex_unlock(&ses
->server
->srv_mutex
);
854 midQ
->mid_state
= MID_REQUEST_SUBMITTED
;
855 cifs_in_send_inc(ses
->server
);
856 rc
= smb_send(ses
->server
, in_buf
, be32_to_cpu(in_buf
->smb_buf_length
));
857 cifs_in_send_dec(ses
->server
);
858 cifs_save_when_sent(midQ
);
859 mutex_unlock(&ses
->server
->srv_mutex
);
866 /* Wait for a reply - allow signals to interrupt. */
867 rc
= wait_event_interruptible(ses
->server
->response_q
,
868 (!(midQ
->mid_state
== MID_REQUEST_SUBMITTED
)) ||
869 ((ses
->server
->tcpStatus
!= CifsGood
) &&
870 (ses
->server
->tcpStatus
!= CifsNew
)));
872 /* Were we interrupted by a signal ? */
873 if ((rc
== -ERESTARTSYS
) &&
874 (midQ
->mid_state
== MID_REQUEST_SUBMITTED
) &&
875 ((ses
->server
->tcpStatus
== CifsGood
) ||
876 (ses
->server
->tcpStatus
== CifsNew
))) {
878 if (in_buf
->Command
== SMB_COM_TRANSACTION2
) {
879 /* POSIX lock. We send a NT_CANCEL SMB to cause the
880 blocking lock to return. */
881 rc
= send_cancel(ses
->server
, in_buf
, midQ
);
887 /* Windows lock. We send a LOCKINGX_CANCEL_LOCK
888 to cause the blocking lock to return. */
890 rc
= send_lock_cancel(xid
, tcon
, in_buf
, out_buf
);
892 /* If we get -ENOLCK back the lock may have
893 already been removed. Don't exit in this case. */
894 if (rc
&& rc
!= -ENOLCK
) {
900 rc
= wait_for_response(ses
->server
, midQ
);
902 send_cancel(ses
->server
, in_buf
, midQ
);
903 spin_lock(&GlobalMid_Lock
);
904 if (midQ
->mid_state
== MID_REQUEST_SUBMITTED
) {
905 /* no longer considered to be "in-flight" */
906 midQ
->callback
= DeleteMidQEntry
;
907 spin_unlock(&GlobalMid_Lock
);
910 spin_unlock(&GlobalMid_Lock
);
913 /* We got the response - restart system call. */
917 rc
= cifs_sync_mid_result(midQ
, ses
->server
);
921 /* rcvd frame is ok */
922 if (out_buf
== NULL
|| midQ
->mid_state
!= MID_RESPONSE_RECEIVED
) {
924 cERROR(1, "Bad MID state?");
928 *pbytes_returned
= get_rfc1002_length(midQ
->resp_buf
);
929 memcpy(out_buf
, midQ
->resp_buf
, *pbytes_returned
+ 4);
930 rc
= cifs_check_receive(midQ
, ses
->server
, 0);
933 if (rstart
&& rc
== -EACCES
)