24 #include <linux/list.h>
26 #include <linux/wait.h>
27 #include <linux/net.h>
30 #include <linux/tcp.h>
32 #include <asm/uaccess.h>
33 #include <asm/processor.h>
52 cERROR(1,
"Null TCP session in AllocMidQEntry");
61 temp->
mid = smb_buffer->
Mid;
86 #ifdef CONFIG_CIFS_STATS2
96 #ifdef CONFIG_CIFS_STATS2
104 printk(
" A: 0x%lx S: 0x%lx R: 0x%lx\n",
106 now - midEntry->when_sent,
107 now - midEntry->when_received);
141 unsigned int remaining;
142 size_t first_vec = 0;
151 smb_msg.msg_namelen =
sizeof(
struct sockaddr);
152 smb_msg.msg_control =
NULL;
153 smb_msg.msg_controllen = 0;
160 for (i = 0; i < n_vec; i++)
161 remaining += iov[i].iov_len;
184 n_vec - first_vec, remaining);
193 if (i >= 14 || (!server->
noblocksnd && (i > 2))) {
194 cERROR(1,
"sends on sock %p stuck for 15 "
209 if (rc == remaining) {
214 if (rc > remaining) {
215 cERROR(1,
"sent %d requested %d", rc, remaining);
222 cERROR(1,
"tcp sent no data");
230 for (i = first_vec; i < n_vec; i++) {
231 if (iov[i].iov_len) {
232 if (rc > iov[i].iov_len) {
294 cFYI(1,
"Sending smb: smb_len=%u", smb_buf_length);
295 dump_smb(iov[0].iov_base, iov[0].iov_len);
299 (
char *)&val,
sizeof(val));
301 rc = smb_send_kvec(server, iov, n_vec, &sent);
312 rc = smb_send_kvec(server, &p_iov, 1, &sent);
324 (
char *)&val,
sizeof(val));
326 if ((total_len > 0) && (total_len != smb_buf_length + 4)) {
327 cFYI(1,
"partial send (wanted=%u sent=%zu): terminating "
328 "session", smb_buf_length + 4, total_len);
337 if (rc < 0 && rc != -
EINTR)
338 cERROR(1,
"Error %d sending data on socket to server", rc);
351 return smb_send_rqst(server, &rqst);
356 unsigned int smb_buf_length)
361 iov.
iov_len = smb_buf_length + 4;
363 return smb_sendv(server, &iov, 1);
367 wait_for_free_credits(
struct TCP_Server_Info *server,
const int timeout,
384 cifs_num_waiters_inc(server);
386 has_credits(server, credits));
387 cifs_num_waiters_dec(server);
415 wait_for_free_request(
struct TCP_Server_Info *server,
const int timeout,
418 return wait_for_free_credits(server, timeout,
419 server->
ops->get_credits_field(server, optype));
430 cFYI(1,
"tcp session dead - return to caller to retry");
494 void *cbdata,
const int flags)
496 int rc, timeout, optype;
502 rc = wait_for_free_request(server, timeout, optype);
507 mid = server->
ops->setup_async_request(server, rqst);
510 add_credits(server, 1, optype);
526 cifs_in_send_inc(server);
527 rc = smb_send_rqst(server, rqst);
528 cifs_in_send_dec(server);
529 cifs_save_when_sent(mid);
536 add_credits(server, 1, optype);
552 char *in_buf,
int flags)
559 iov[0].
iov_len = get_rfc1002_length(in_buf) + 4;
561 rc =
SendReceive2(xid, ses, iov, 1, &resp_buf_type, flags);
562 cFYI(
DBG2,
"SendRcvNoRsp flags %d rc %d", flags, rc);
572 cFYI(1,
"%s: cmd=%d mid=%llu state=%d", __func__,
590 list_del_init(&mid->
qhead);
591 cERROR(1,
"%s: invalid mid state mid=%llu state=%d", __func__,
604 return server->
ops->send_cancel ?
605 server->
ops->send_cancel(server, buf, mid) : 0;
612 unsigned int len = get_rfc1002_length(mid->
resp_buf) + 4;
629 cERROR(1,
"SMB signature verification returned error = "
644 rc = allocate_mid(ses, hdr, &mid);
657 struct kvec *iov,
int n_vec,
int *resp_buf_type ,
664 unsigned int credits = 1;
675 cERROR(1,
"Null session");
690 rc = wait_for_free_request(ses->
server, timeout, optype);
704 midQ = ses->
server->ops->setup_request(ses, &rqst);
709 add_credits(ses->
server, 1, optype);
710 return PTR_ERR(midQ);
714 cifs_in_send_inc(ses->
server);
715 rc = smb_sendv(ses->
server, iov, n_vec);
716 cifs_in_send_dec(ses->
server);
717 cifs_save_when_sent(midQ);
731 rc = wait_for_response(ses->
server, midQ);
733 send_cancel(ses->
server, buf, midQ);
739 add_credits(ses->
server, 1, optype);
747 rc = cifs_sync_mid_result(midQ, ses->
server);
749 add_credits(ses->
server, 1, optype);
755 cFYI(1,
"Bad MID state?");
761 iov[0].
iov_len = get_rfc1002_length(buf) + 4;
767 credits = ses->
server->ops->get_credits(midQ);
777 add_credits(ses->
server, credits, optype);
785 int *pbytes_returned,
const int timeout)
791 cERROR(1,
"Null smb session");
795 cERROR(1,
"Null tcp session");
808 cERROR(1,
"Illegal length, greater than maximum frame, %d",
813 rc = wait_for_free_request(ses->
server, timeout, 0);
823 rc = allocate_mid(ses, in_buf, &midQ);
827 add_credits(ses->
server, 1, 0);
839 cifs_in_send_inc(ses->
server);
841 cifs_in_send_dec(ses->
server);
842 cifs_save_when_sent(midQ);
851 rc = wait_for_response(ses->
server, midQ);
853 send_cancel(ses->
server, in_buf, midQ);
859 add_credits(ses->
server, 1, 0);
865 rc = cifs_sync_mid_result(midQ, ses->
server);
867 add_credits(ses->
server, 1, 0);
874 cERROR(1,
"Bad MID state?");
878 *pbytes_returned = get_rfc1002_length(midQ->
resp_buf);
883 add_credits(ses->
server, 1, 0);
892 send_lock_cancel(
const unsigned int xid,
struct cifs_tcon *tcon,
898 LOCK_REQ *pSMB = (LOCK_REQ *)in_buf;
907 pSMB->hdr.Mid = get_next_mid(ses->
server);
916 int *pbytes_returned)
924 cERROR(1,
"Null smb session");
930 cERROR(1,
"Null tcp session");
943 cERROR(1,
"Illegal length, greater than maximum frame, %d",
958 rc = allocate_mid(ses, in_buf, &midQ);
972 cifs_in_send_inc(ses->
server);
974 cifs_in_send_dec(ses->
server);
975 cifs_save_when_sent(midQ);
998 rc = send_cancel(ses->
server, in_buf, midQ);
1007 rc = send_lock_cancel(xid, tcon, in_buf, out_buf);
1011 if (rc && rc != -
ENOLCK) {
1017 rc = wait_for_response(ses->
server, midQ);
1019 send_cancel(ses->
server, in_buf, midQ);
1034 rc = cifs_sync_mid_result(midQ, ses->
server);
1041 cERROR(1,
"Bad MID state?");
1045 *pbytes_returned = get_rfc1002_length(midQ->
resp_buf);
1050 if (rstart && rc == -
EACCES)