aboutsummaryrefslogtreecommitdiffstats
path: root/fs/cifs
diff options
context:
space:
mode:
Diffstat (limited to 'fs/cifs')
-rw-r--r--fs/cifs/cifs_debug.c2
-rw-r--r--fs/cifs/cifs_dfs_ref.c5
-rw-r--r--fs/cifs/cifsacl.c28
-rw-r--r--fs/cifs/cifsencrypt.c126
-rw-r--r--fs/cifs/cifsfs.c22
-rw-r--r--fs/cifs/cifsfs.h6
-rw-r--r--fs/cifs/cifsglob.h60
-rw-r--r--fs/cifs/cifssmb.c6
-rw-r--r--fs/cifs/connect.c662
-rw-r--r--fs/cifs/dir.c9
-rw-r--r--fs/cifs/dns_resolve.c4
-rw-r--r--fs/cifs/file.c27
-rw-r--r--fs/cifs/inode.c14
-rw-r--r--fs/cifs/link.c8
-rw-r--r--fs/cifs/misc.c11
-rw-r--r--fs/cifs/readdir.c427
-rw-r--r--fs/cifs/smbencrypt.c8
-rw-r--r--fs/cifs/transport.c53
18 files changed, 740 insertions, 738 deletions
diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
index 2fe3cf13b2e9..6d40656e1e29 100644
--- a/fs/cifs/cifs_debug.c
+++ b/fs/cifs/cifs_debug.c
@@ -176,7 +176,7 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
176 176
177#ifdef CONFIG_CIFS_STATS2 177#ifdef CONFIG_CIFS_STATS2
178 seq_printf(m, " In Send: %d In MaxReq Wait: %d", 178 seq_printf(m, " In Send: %d In MaxReq Wait: %d",
179 atomic_read(&server->inSend), 179 atomic_read(&server->in_send),
180 atomic_read(&server->num_waiters)); 180 atomic_read(&server->num_waiters));
181#endif 181#endif
182 182
diff --git a/fs/cifs/cifs_dfs_ref.c b/fs/cifs/cifs_dfs_ref.c
index 8d8f28c94c0f..6873bb634a97 100644
--- a/fs/cifs/cifs_dfs_ref.c
+++ b/fs/cifs/cifs_dfs_ref.c
@@ -141,10 +141,11 @@ char *cifs_compose_mount_options(const char *sb_mountdata,
141 141
142 rc = dns_resolve_server_name_to_ip(*devname, &srvIP); 142 rc = dns_resolve_server_name_to_ip(*devname, &srvIP);
143 if (rc < 0) { 143 if (rc < 0) {
144 cERROR(1, "%s: Failed to resolve server part of %s to IP: %d", 144 cFYI(1, "%s: Failed to resolve server part of %s to IP: %d",
145 __func__, *devname, rc); 145 __func__, *devname, rc);
146 goto compose_mount_options_err; 146 goto compose_mount_options_err;
147 } 147 }
148
148 /* md_len = strlen(...) + 12 for 'sep+prefixpath=' 149 /* md_len = strlen(...) + 12 for 'sep+prefixpath='
149 * assuming that we have 'unc=' and 'ip=' in 150 * assuming that we have 'unc=' and 'ip=' in
150 * the original sb_mountdata 151 * the original sb_mountdata
diff --git a/fs/cifs/cifsacl.c b/fs/cifs/cifsacl.c
index 21de1d6d5849..d0f59faefb78 100644
--- a/fs/cifs/cifsacl.c
+++ b/fs/cifs/cifsacl.c
@@ -991,24 +991,6 @@ struct cifs_ntsd *get_cifs_acl(struct cifs_sb_info *cifs_sb,
991 return pntsd; 991 return pntsd;
992} 992}
993 993
994static int set_cifs_acl_by_fid(struct cifs_sb_info *cifs_sb, __u16 fid,
995 struct cifs_ntsd *pnntsd, u32 acllen)
996{
997 int xid, rc;
998 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
999
1000 if (IS_ERR(tlink))
1001 return PTR_ERR(tlink);
1002
1003 xid = GetXid();
1004 rc = CIFSSMBSetCIFSACL(xid, tlink_tcon(tlink), fid, pnntsd, acllen);
1005 FreeXid(xid);
1006 cifs_put_tlink(tlink);
1007
1008 cFYI(DBG2, "SetCIFSACL rc = %d", rc);
1009 return rc;
1010}
1011
1012static int set_cifs_acl_by_path(struct cifs_sb_info *cifs_sb, const char *path, 994static int set_cifs_acl_by_path(struct cifs_sb_info *cifs_sb, const char *path,
1013 struct cifs_ntsd *pnntsd, u32 acllen) 995 struct cifs_ntsd *pnntsd, u32 acllen)
1014{ 996{
@@ -1047,18 +1029,10 @@ int set_cifs_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
1047 struct inode *inode, const char *path) 1029 struct inode *inode, const char *path)
1048{ 1030{
1049 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); 1031 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
1050 struct cifsFileInfo *open_file;
1051 int rc;
1052 1032
1053 cFYI(DBG2, "set ACL for %s from mode 0x%x", path, inode->i_mode); 1033 cFYI(DBG2, "set ACL for %s from mode 0x%x", path, inode->i_mode);
1054 1034
1055 open_file = find_readable_file(CIFS_I(inode), true); 1035 return set_cifs_acl_by_path(cifs_sb, path, pnntsd, acllen);
1056 if (!open_file)
1057 return set_cifs_acl_by_path(cifs_sb, path, pnntsd, acllen);
1058
1059 rc = set_cifs_acl_by_fid(cifs_sb, open_file->netfid, pnntsd, acllen);
1060 cifsFileInfo_put(open_file);
1061 return rc;
1062} 1036}
1063 1037
1064/* Translate the CIFS ACL (simlar to NTFS ACL) for a file into mode bits */ 1038/* Translate the CIFS ACL (simlar to NTFS ACL) for a file into mode bits */
diff --git a/fs/cifs/cifsencrypt.c b/fs/cifs/cifsencrypt.c
index 5a0ee7f2af06..e76bfeb68267 100644
--- a/fs/cifs/cifsencrypt.c
+++ b/fs/cifs/cifsencrypt.c
@@ -52,19 +52,29 @@ static int cifs_calculate_signature(const struct smb_hdr *cifs_pdu,
52 52
53 rc = crypto_shash_init(&server->secmech.sdescmd5->shash); 53 rc = crypto_shash_init(&server->secmech.sdescmd5->shash);
54 if (rc) { 54 if (rc) {
55 cERROR(1, "%s: Oould not init md5\n", __func__); 55 cERROR(1, "%s: Could not init md5\n", __func__);
56 return rc; 56 return rc;
57 } 57 }
58 58
59 crypto_shash_update(&server->secmech.sdescmd5->shash, 59 rc = crypto_shash_update(&server->secmech.sdescmd5->shash,
60 server->session_key.response, server->session_key.len); 60 server->session_key.response, server->session_key.len);
61 if (rc) {
62 cERROR(1, "%s: Could not update with response\n", __func__);
63 return rc;
64 }
61 65
62 crypto_shash_update(&server->secmech.sdescmd5->shash, 66 rc = crypto_shash_update(&server->secmech.sdescmd5->shash,
63 cifs_pdu->Protocol, be32_to_cpu(cifs_pdu->smb_buf_length)); 67 cifs_pdu->Protocol, be32_to_cpu(cifs_pdu->smb_buf_length));
68 if (rc) {
69 cERROR(1, "%s: Could not update with payload\n", __func__);
70 return rc;
71 }
64 72
65 rc = crypto_shash_final(&server->secmech.sdescmd5->shash, signature); 73 rc = crypto_shash_final(&server->secmech.sdescmd5->shash, signature);
74 if (rc)
75 cERROR(1, "%s: Could not generate md5 hash\n", __func__);
66 76
67 return 0; 77 return rc;
68} 78}
69 79
70/* must be called with server->srv_mutex held */ 80/* must be called with server->srv_mutex held */
@@ -77,9 +87,15 @@ int cifs_sign_smb(struct smb_hdr *cifs_pdu, struct TCP_Server_Info *server,
77 if ((cifs_pdu == NULL) || (server == NULL)) 87 if ((cifs_pdu == NULL) || (server == NULL))
78 return -EINVAL; 88 return -EINVAL;
79 89
80 if ((cifs_pdu->Flags2 & SMBFLG2_SECURITY_SIGNATURE) == 0) 90 if (!(cifs_pdu->Flags2 & SMBFLG2_SECURITY_SIGNATURE) ||
91 server->tcpStatus == CifsNeedNegotiate)
81 return rc; 92 return rc;
82 93
94 if (!server->session_estab) {
95 strncpy(cifs_pdu->Signature.SecuritySignature, "BSRSPYL", 8);
96 return rc;
97 }
98
83 cifs_pdu->Signature.Sequence.SequenceNumber = 99 cifs_pdu->Signature.Sequence.SequenceNumber =
84 cpu_to_le32(server->sequence_number); 100 cpu_to_le32(server->sequence_number);
85 cifs_pdu->Signature.Sequence.Reserved = 0; 101 cifs_pdu->Signature.Sequence.Reserved = 0;
@@ -112,12 +128,16 @@ static int cifs_calc_signature2(const struct kvec *iov, int n_vec,
112 128
113 rc = crypto_shash_init(&server->secmech.sdescmd5->shash); 129 rc = crypto_shash_init(&server->secmech.sdescmd5->shash);
114 if (rc) { 130 if (rc) {
115 cERROR(1, "%s: Oould not init md5\n", __func__); 131 cERROR(1, "%s: Could not init md5\n", __func__);
116 return rc; 132 return rc;
117 } 133 }
118 134
119 crypto_shash_update(&server->secmech.sdescmd5->shash, 135 rc = crypto_shash_update(&server->secmech.sdescmd5->shash,
120 server->session_key.response, server->session_key.len); 136 server->session_key.response, server->session_key.len);
137 if (rc) {
138 cERROR(1, "%s: Could not update with response\n", __func__);
139 return rc;
140 }
121 141
122 for (i = 0; i < n_vec; i++) { 142 for (i = 0; i < n_vec; i++) {
123 if (iov[i].iov_len == 0) 143 if (iov[i].iov_len == 0)
@@ -131,14 +151,24 @@ static int cifs_calc_signature2(const struct kvec *iov, int n_vec,
131 if (i == 0) { 151 if (i == 0) {
132 if (iov[0].iov_len <= 8) /* cmd field at offset 9 */ 152 if (iov[0].iov_len <= 8) /* cmd field at offset 9 */
133 break; /* nothing to sign or corrupt header */ 153 break; /* nothing to sign or corrupt header */
154 rc =
134 crypto_shash_update(&server->secmech.sdescmd5->shash, 155 crypto_shash_update(&server->secmech.sdescmd5->shash,
135 iov[i].iov_base + 4, iov[i].iov_len - 4); 156 iov[i].iov_base + 4, iov[i].iov_len - 4);
136 } else 157 } else {
158 rc =
137 crypto_shash_update(&server->secmech.sdescmd5->shash, 159 crypto_shash_update(&server->secmech.sdescmd5->shash,
138 iov[i].iov_base, iov[i].iov_len); 160 iov[i].iov_base, iov[i].iov_len);
161 }
162 if (rc) {
163 cERROR(1, "%s: Could not update with payload\n",
164 __func__);
165 return rc;
166 }
139 } 167 }
140 168
141 rc = crypto_shash_final(&server->secmech.sdescmd5->shash, signature); 169 rc = crypto_shash_final(&server->secmech.sdescmd5->shash, signature);
170 if (rc)
171 cERROR(1, "%s: Could not generate md5 hash\n", __func__);
142 172
143 return rc; 173 return rc;
144} 174}
@@ -154,8 +184,14 @@ int cifs_sign_smb2(struct kvec *iov, int n_vec, struct TCP_Server_Info *server,
154 if ((cifs_pdu == NULL) || (server == NULL)) 184 if ((cifs_pdu == NULL) || (server == NULL))
155 return -EINVAL; 185 return -EINVAL;
156 186
157 if ((cifs_pdu->Flags2 & SMBFLG2_SECURITY_SIGNATURE) == 0) 187 if (!(cifs_pdu->Flags2 & SMBFLG2_SECURITY_SIGNATURE) ||
188 server->tcpStatus == CifsNeedNegotiate)
189 return rc;
190
191 if (!server->session_estab) {
192 strncpy(cifs_pdu->Signature.SecuritySignature, "BSRSPYL", 8);
158 return rc; 193 return rc;
194 }
159 195
160 cifs_pdu->Signature.Sequence.SequenceNumber = 196 cifs_pdu->Signature.Sequence.SequenceNumber =
161 cpu_to_le32(server->sequence_number); 197 cpu_to_le32(server->sequence_number);
@@ -463,8 +499,12 @@ static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash,
463 /* calculate md4 hash of password */ 499 /* calculate md4 hash of password */
464 E_md4hash(ses->password, nt_hash); 500 E_md4hash(ses->password, nt_hash);
465 501
466 crypto_shash_setkey(ses->server->secmech.hmacmd5, nt_hash, 502 rc = crypto_shash_setkey(ses->server->secmech.hmacmd5, nt_hash,
467 CIFS_NTHASH_SIZE); 503 CIFS_NTHASH_SIZE);
504 if (rc) {
505 cERROR(1, "%s: Could not set NT Hash as a key", __func__);
506 return rc;
507 }
468 508
469 rc = crypto_shash_init(&ses->server->secmech.sdeschmacmd5->shash); 509 rc = crypto_shash_init(&ses->server->secmech.sdeschmacmd5->shash);
470 if (rc) { 510 if (rc) {
@@ -478,13 +518,18 @@ static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash,
478 if (user == NULL) { 518 if (user == NULL) {
479 cERROR(1, "calc_ntlmv2_hash: user mem alloc failure\n"); 519 cERROR(1, "calc_ntlmv2_hash: user mem alloc failure\n");
480 rc = -ENOMEM; 520 rc = -ENOMEM;
481 goto calc_exit_2; 521 return rc;
482 } 522 }
483 len = cifs_strtoUCS((__le16 *)user, ses->user_name, len, nls_cp); 523 len = cifs_strtoUCS((__le16 *)user, ses->user_name, len, nls_cp);
484 UniStrupr(user); 524 UniStrupr(user);
485 525
486 crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash, 526 rc = crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash,
487 (char *)user, 2 * len); 527 (char *)user, 2 * len);
528 kfree(user);
529 if (rc) {
530 cERROR(1, "%s: Could not update with user\n", __func__);
531 return rc;
532 }
488 533
489 /* convert ses->domainName to unicode and uppercase */ 534 /* convert ses->domainName to unicode and uppercase */
490 if (ses->domainName) { 535 if (ses->domainName) {
@@ -494,13 +539,19 @@ static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash,
494 if (domain == NULL) { 539 if (domain == NULL) {
495 cERROR(1, "calc_ntlmv2_hash: domain mem alloc failure"); 540 cERROR(1, "calc_ntlmv2_hash: domain mem alloc failure");
496 rc = -ENOMEM; 541 rc = -ENOMEM;
497 goto calc_exit_1; 542 return rc;
498 } 543 }
499 len = cifs_strtoUCS((__le16 *)domain, ses->domainName, len, 544 len = cifs_strtoUCS((__le16 *)domain, ses->domainName, len,
500 nls_cp); 545 nls_cp);
546 rc =
501 crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash, 547 crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash,
502 (char *)domain, 2 * len); 548 (char *)domain, 2 * len);
503 kfree(domain); 549 kfree(domain);
550 if (rc) {
551 cERROR(1, "%s: Could not update with domain\n",
552 __func__);
553 return rc;
554 }
504 } else if (ses->serverName) { 555 } else if (ses->serverName) {
505 len = strlen(ses->serverName); 556 len = strlen(ses->serverName);
506 557
@@ -508,21 +559,26 @@ static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash,
508 if (server == NULL) { 559 if (server == NULL) {
509 cERROR(1, "calc_ntlmv2_hash: server mem alloc failure"); 560 cERROR(1, "calc_ntlmv2_hash: server mem alloc failure");
510 rc = -ENOMEM; 561 rc = -ENOMEM;
511 goto calc_exit_1; 562 return rc;
512 } 563 }
513 len = cifs_strtoUCS((__le16 *)server, ses->serverName, len, 564 len = cifs_strtoUCS((__le16 *)server, ses->serverName, len,
514 nls_cp); 565 nls_cp);
566 rc =
515 crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash, 567 crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash,
516 (char *)server, 2 * len); 568 (char *)server, 2 * len);
517 kfree(server); 569 kfree(server);
570 if (rc) {
571 cERROR(1, "%s: Could not update with server\n",
572 __func__);
573 return rc;
574 }
518 } 575 }
519 576
520 rc = crypto_shash_final(&ses->server->secmech.sdeschmacmd5->shash, 577 rc = crypto_shash_final(&ses->server->secmech.sdeschmacmd5->shash,
521 ntlmv2_hash); 578 ntlmv2_hash);
579 if (rc)
580 cERROR(1, "%s: Could not generate md5 hash\n", __func__);
522 581
523calc_exit_1:
524 kfree(user);
525calc_exit_2:
526 return rc; 582 return rc;
527} 583}
528 584
@@ -537,8 +593,12 @@ CalcNTLMv2_response(const struct cifs_ses *ses, char *ntlmv2_hash)
537 return -1; 593 return -1;
538 } 594 }
539 595
540 crypto_shash_setkey(ses->server->secmech.hmacmd5, 596 rc = crypto_shash_setkey(ses->server->secmech.hmacmd5,
541 ntlmv2_hash, CIFS_HMAC_MD5_HASH_SIZE); 597 ntlmv2_hash, CIFS_HMAC_MD5_HASH_SIZE);
598 if (rc) {
599 cERROR(1, "%s: Could not set NTLMV2 Hash as a key", __func__);
600 return rc;
601 }
542 602
543 rc = crypto_shash_init(&ses->server->secmech.sdeschmacmd5->shash); 603 rc = crypto_shash_init(&ses->server->secmech.sdeschmacmd5->shash);
544 if (rc) { 604 if (rc) {
@@ -552,11 +612,17 @@ CalcNTLMv2_response(const struct cifs_ses *ses, char *ntlmv2_hash)
552 else 612 else
553 memcpy(ses->auth_key.response + offset, 613 memcpy(ses->auth_key.response + offset,
554 ses->server->cryptkey, CIFS_SERVER_CHALLENGE_SIZE); 614 ses->server->cryptkey, CIFS_SERVER_CHALLENGE_SIZE);
555 crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash, 615 rc = crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash,
556 ses->auth_key.response + offset, ses->auth_key.len - offset); 616 ses->auth_key.response + offset, ses->auth_key.len - offset);
617 if (rc) {
618 cERROR(1, "%s: Could not update with response\n", __func__);
619 return rc;
620 }
557 621
558 rc = crypto_shash_final(&ses->server->secmech.sdeschmacmd5->shash, 622 rc = crypto_shash_final(&ses->server->secmech.sdeschmacmd5->shash,
559 ses->auth_key.response + CIFS_SESS_KEY_SIZE); 623 ses->auth_key.response + CIFS_SESS_KEY_SIZE);
624 if (rc)
625 cERROR(1, "%s: Could not generate md5 hash\n", __func__);
560 626
561 return rc; 627 return rc;
562} 628}
@@ -626,8 +692,12 @@ setup_ntlmv2_rsp(struct cifs_ses *ses, const struct nls_table *nls_cp)
626 } 692 }
627 693
628 /* now calculate the session key for NTLMv2 */ 694 /* now calculate the session key for NTLMv2 */
629 crypto_shash_setkey(ses->server->secmech.hmacmd5, 695 rc = crypto_shash_setkey(ses->server->secmech.hmacmd5,
630 ntlmv2_hash, CIFS_HMAC_MD5_HASH_SIZE); 696 ntlmv2_hash, CIFS_HMAC_MD5_HASH_SIZE);
697 if (rc) {
698 cERROR(1, "%s: Could not set NTLMV2 Hash as a key", __func__);
699 goto setup_ntlmv2_rsp_ret;
700 }
631 701
632 rc = crypto_shash_init(&ses->server->secmech.sdeschmacmd5->shash); 702 rc = crypto_shash_init(&ses->server->secmech.sdeschmacmd5->shash);
633 if (rc) { 703 if (rc) {
@@ -635,12 +705,18 @@ setup_ntlmv2_rsp(struct cifs_ses *ses, const struct nls_table *nls_cp)
635 goto setup_ntlmv2_rsp_ret; 705 goto setup_ntlmv2_rsp_ret;
636 } 706 }
637 707
638 crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash, 708 rc = crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash,
639 ses->auth_key.response + CIFS_SESS_KEY_SIZE, 709 ses->auth_key.response + CIFS_SESS_KEY_SIZE,
640 CIFS_HMAC_MD5_HASH_SIZE); 710 CIFS_HMAC_MD5_HASH_SIZE);
711 if (rc) {
712 cERROR(1, "%s: Could not update with response\n", __func__);
713 goto setup_ntlmv2_rsp_ret;
714 }
641 715
642 rc = crypto_shash_final(&ses->server->secmech.sdeschmacmd5->shash, 716 rc = crypto_shash_final(&ses->server->secmech.sdeschmacmd5->shash,
643 ses->auth_key.response); 717 ses->auth_key.response);
718 if (rc)
719 cERROR(1, "%s: Could not generate md5 hash\n", __func__);
644 720
645setup_ntlmv2_rsp_ret: 721setup_ntlmv2_rsp_ret:
646 kfree(tiblob); 722 kfree(tiblob);
@@ -668,8 +744,12 @@ calc_seckey(struct cifs_ses *ses)
668 744
669 desc.tfm = tfm_arc4; 745 desc.tfm = tfm_arc4;
670 746
671 crypto_blkcipher_setkey(tfm_arc4, ses->auth_key.response, 747 rc = crypto_blkcipher_setkey(tfm_arc4, ses->auth_key.response,
672 CIFS_SESS_KEY_SIZE); 748 CIFS_SESS_KEY_SIZE);
749 if (rc) {
750 cERROR(1, "%s: Could not set response as a key", __func__);
751 return rc;
752 }
673 753
674 sg_init_one(&sgin, sec_key, CIFS_SESS_KEY_SIZE); 754 sg_init_one(&sgin, sec_key, CIFS_SESS_KEY_SIZE);
675 sg_init_one(&sgout, ses->ntlmssp->ciphertext, CIFS_CPHTXT_SIZE); 755 sg_init_one(&sgout, ses->ntlmssp->ciphertext, CIFS_CPHTXT_SIZE);
@@ -688,7 +768,7 @@ calc_seckey(struct cifs_ses *ses)
688 768
689 crypto_free_blkcipher(tfm_arc4); 769 crypto_free_blkcipher(tfm_arc4);
690 770
691 return 0; 771 return rc;
692} 772}
693 773
694void 774void
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
index 865517470967..f93eb948d071 100644
--- a/fs/cifs/cifsfs.c
+++ b/fs/cifs/cifsfs.c
@@ -86,24 +86,6 @@ extern mempool_t *cifs_sm_req_poolp;
86extern mempool_t *cifs_req_poolp; 86extern mempool_t *cifs_req_poolp;
87extern mempool_t *cifs_mid_poolp; 87extern mempool_t *cifs_mid_poolp;
88 88
89void
90cifs_sb_active(struct super_block *sb)
91{
92 struct cifs_sb_info *server = CIFS_SB(sb);
93
94 if (atomic_inc_return(&server->active) == 1)
95 atomic_inc(&sb->s_active);
96}
97
98void
99cifs_sb_deactive(struct super_block *sb)
100{
101 struct cifs_sb_info *server = CIFS_SB(sb);
102
103 if (atomic_dec_and_test(&server->active))
104 deactivate_super(sb);
105}
106
107static int 89static int
108cifs_read_super(struct super_block *sb) 90cifs_read_super(struct super_block *sb)
109{ 91{
@@ -581,6 +563,10 @@ cifs_get_root(struct smb_vol *vol, struct super_block *sb)
581 mutex_unlock(&dir->i_mutex); 563 mutex_unlock(&dir->i_mutex);
582 dput(dentry); 564 dput(dentry);
583 dentry = child; 565 dentry = child;
566 if (!dentry->d_inode) {
567 dput(dentry);
568 dentry = ERR_PTR(-ENOENT);
569 }
584 } while (!IS_ERR(dentry)); 570 } while (!IS_ERR(dentry));
585 _FreeXid(xid); 571 _FreeXid(xid);
586 kfree(full_path); 572 kfree(full_path);
diff --git a/fs/cifs/cifsfs.h b/fs/cifs/cifsfs.h
index fbd050c8d52a..95da8027983d 100644
--- a/fs/cifs/cifsfs.h
+++ b/fs/cifs/cifsfs.h
@@ -41,10 +41,6 @@ extern struct file_system_type cifs_fs_type;
41extern const struct address_space_operations cifs_addr_ops; 41extern const struct address_space_operations cifs_addr_ops;
42extern const struct address_space_operations cifs_addr_ops_smallbuf; 42extern const struct address_space_operations cifs_addr_ops_smallbuf;
43 43
44/* Functions related to super block operations */
45extern void cifs_sb_active(struct super_block *sb);
46extern void cifs_sb_deactive(struct super_block *sb);
47
48/* Functions related to inodes */ 44/* Functions related to inodes */
49extern const struct inode_operations cifs_dir_inode_ops; 45extern const struct inode_operations cifs_dir_inode_ops;
50extern struct inode *cifs_root_iget(struct super_block *); 46extern struct inode *cifs_root_iget(struct super_block *);
@@ -129,5 +125,5 @@ extern long cifs_ioctl(struct file *filep, unsigned int cmd, unsigned long arg);
129extern const struct export_operations cifs_export_ops; 125extern const struct export_operations cifs_export_ops;
130#endif /* CIFS_NFSD_EXPORT */ 126#endif /* CIFS_NFSD_EXPORT */
131 127
132#define CIFS_VERSION "1.74" 128#define CIFS_VERSION "1.75"
133#endif /* _CIFSFS_H */ 129#endif /* _CIFSFS_H */
diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
index 6255fa812c7a..95dad9d14cf1 100644
--- a/fs/cifs/cifsglob.h
+++ b/fs/cifs/cifsglob.h
@@ -291,7 +291,7 @@ struct TCP_Server_Info {
291 struct fscache_cookie *fscache; /* client index cache cookie */ 291 struct fscache_cookie *fscache; /* client index cache cookie */
292#endif 292#endif
293#ifdef CONFIG_CIFS_STATS2 293#ifdef CONFIG_CIFS_STATS2
294 atomic_t inSend; /* requests trying to send */ 294 atomic_t in_send; /* requests trying to send */
295 atomic_t num_waiters; /* blocked waiting to get in sendrecv */ 295 atomic_t num_waiters; /* blocked waiting to get in sendrecv */
296#endif 296#endif
297}; 297};
@@ -501,7 +501,7 @@ struct cifs_search_info {
501 char *ntwrk_buf_start; 501 char *ntwrk_buf_start;
502 char *srch_entries_start; 502 char *srch_entries_start;
503 char *last_entry; 503 char *last_entry;
504 char *presume_name; 504 const char *presume_name;
505 unsigned int resume_name_len; 505 unsigned int resume_name_len;
506 bool endOfSearch:1; 506 bool endOfSearch:1;
507 bool emptyDir:1; 507 bool emptyDir:1;
@@ -672,12 +672,54 @@ struct mid_q_entry {
672 bool multiEnd:1; /* both received */ 672 bool multiEnd:1; /* both received */
673}; 673};
674 674
675struct oplock_q_entry { 675/* Make code in transport.c a little cleaner by moving
676 struct list_head qhead; 676 update of optional stats into function below */
677 struct inode *pinode; 677#ifdef CONFIG_CIFS_STATS2
678 struct cifs_tcon *tcon; 678
679 __u16 netfid; 679static inline void cifs_in_send_inc(struct TCP_Server_Info *server)
680}; 680{
681 atomic_inc(&server->in_send);
682}
683
684static inline void cifs_in_send_dec(struct TCP_Server_Info *server)
685{
686 atomic_dec(&server->in_send);
687}
688
689static inline void cifs_num_waiters_inc(struct TCP_Server_Info *server)
690{
691 atomic_inc(&server->num_waiters);
692}
693
694static inline void cifs_num_waiters_dec(struct TCP_Server_Info *server)
695{
696 atomic_dec(&server->num_waiters);
697}
698
699static inline void cifs_save_when_sent(struct mid_q_entry *mid)
700{
701 mid->when_sent = jiffies;
702}
703#else
704static inline void cifs_in_send_inc(struct TCP_Server_Info *server)
705{
706}
707static inline void cifs_in_send_dec(struct TCP_Server_Info *server)
708{
709}
710
711static inline void cifs_num_waiters_inc(struct TCP_Server_Info *server)
712{
713}
714
715static inline void cifs_num_waiters_dec(struct TCP_Server_Info *server)
716{
717}
718
719static inline void cifs_save_when_sent(struct mid_q_entry *mid)
720{
721}
722#endif
681 723
682/* for pending dnotify requests */ 724/* for pending dnotify requests */
683struct dir_notify_req { 725struct dir_notify_req {
@@ -942,8 +984,6 @@ GLOBAL_EXTERN spinlock_t siduidlock;
942GLOBAL_EXTERN spinlock_t sidgidlock; 984GLOBAL_EXTERN spinlock_t sidgidlock;
943 985
944void cifs_oplock_break(struct work_struct *work); 986void cifs_oplock_break(struct work_struct *work);
945void cifs_oplock_break_get(struct cifsFileInfo *cfile);
946void cifs_oplock_break_put(struct cifsFileInfo *cfile);
947 987
948extern const struct slow_work_ops cifs_oplock_break_ops; 988extern const struct slow_work_ops cifs_oplock_break_ops;
949 989
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
index 1a9fe7f816d1..aac37d99a487 100644
--- a/fs/cifs/cifssmb.c
+++ b/fs/cifs/cifssmb.c
@@ -107,7 +107,7 @@ static void mark_open_files_invalid(struct cifs_tcon *pTcon)
107static int 107static int
108cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) 108cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)
109{ 109{
110 int rc = 0; 110 int rc;
111 struct cifs_ses *ses; 111 struct cifs_ses *ses;
112 struct TCP_Server_Info *server; 112 struct TCP_Server_Info *server;
113 struct nls_table *nls_codepage; 113 struct nls_table *nls_codepage;
@@ -5720,6 +5720,7 @@ CIFSSMBQAllEAs(const int xid, struct cifs_tcon *tcon,
5720 char *temp_ptr; 5720 char *temp_ptr;
5721 char *end_of_smb; 5721 char *end_of_smb;
5722 __u16 params, byte_count, data_offset; 5722 __u16 params, byte_count, data_offset;
5723 unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0;
5723 5724
5724 cFYI(1, "In Query All EAs path %s", searchName); 5725 cFYI(1, "In Query All EAs path %s", searchName);
5725QAllEAsRetry: 5726QAllEAsRetry:
@@ -5837,7 +5838,8 @@ QAllEAsRetry:
5837 } 5838 }
5838 5839
5839 if (ea_name) { 5840 if (ea_name) {
5840 if (strncmp(ea_name, temp_ptr, name_len) == 0) { 5841 if (ea_name_len == name_len &&
5842 strncmp(ea_name, temp_ptr, name_len) == 0) {
5841 temp_ptr += name_len + 1; 5843 temp_ptr += name_len + 1;
5842 rc = value_len; 5844 rc = value_len;
5843 if (buf_size == 0) 5845 if (buf_size == 0)
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index e66297bad412..633c246b6775 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -319,25 +319,328 @@ requeue_echo:
319 queue_delayed_work(system_nrt_wq, &server->echo, SMB_ECHO_INTERVAL); 319 queue_delayed_work(system_nrt_wq, &server->echo, SMB_ECHO_INTERVAL);
320} 320}
321 321
322static bool
323allocate_buffers(char **bigbuf, char **smallbuf, unsigned int size,
324 bool is_large_buf)
325{
326 char *bbuf = *bigbuf, *sbuf = *smallbuf;
327
328 if (bbuf == NULL) {
329 bbuf = (char *)cifs_buf_get();
330 if (!bbuf) {
331 cERROR(1, "No memory for large SMB response");
332 msleep(3000);
333 /* retry will check if exiting */
334 return false;
335 }
336 } else if (is_large_buf) {
337 /* we are reusing a dirty large buf, clear its start */
338 memset(bbuf, 0, size);
339 }
340
341 if (sbuf == NULL) {
342 sbuf = (char *)cifs_small_buf_get();
343 if (!sbuf) {
344 cERROR(1, "No memory for SMB response");
345 msleep(1000);
346 /* retry will check if exiting */
347 return false;
348 }
349 /* beginning of smb buffer is cleared in our buf_get */
350 } else {
351 /* if existing small buf clear beginning */
352 memset(sbuf, 0, size);
353 }
354
355 *bigbuf = bbuf;
356 *smallbuf = sbuf;
357
358 return true;
359}
360
361static int
362read_from_socket(struct TCP_Server_Info *server, struct msghdr *smb_msg,
363 struct kvec *iov, unsigned int to_read,
364 unsigned int *ptotal_read, bool is_header_read)
365{
366 int length, rc = 0;
367 unsigned int total_read;
368 char *buf = iov->iov_base;
369
370 for (total_read = 0; total_read < to_read; total_read += length) {
371 length = kernel_recvmsg(server->ssocket, smb_msg, iov, 1,
372 to_read - total_read, 0);
373 if (server->tcpStatus == CifsExiting) {
374 /* then will exit */
375 rc = 2;
376 break;
377 } else if (server->tcpStatus == CifsNeedReconnect) {
378 cifs_reconnect(server);
379 /* Reconnect wakes up rspns q */
380 /* Now we will reread sock */
381 rc = 1;
382 break;
383 } else if (length == -ERESTARTSYS ||
384 length == -EAGAIN ||
385 length == -EINTR) {
386 /*
387 * Minimum sleep to prevent looping, allowing socket
388 * to clear and app threads to set tcpStatus
389 * CifsNeedReconnect if server hung.
390 */
391 usleep_range(1000, 2000);
392 length = 0;
393 if (!is_header_read)
394 continue;
395 /* Special handling for header read */
396 if (total_read) {
397 iov->iov_base = (to_read - total_read) +
398 buf;
399 iov->iov_len = to_read - total_read;
400 smb_msg->msg_control = NULL;
401 smb_msg->msg_controllen = 0;
402 rc = 3;
403 } else
404 rc = 1;
405 break;
406 } else if (length <= 0) {
407 cERROR(1, "Received no data, expecting %d",
408 to_read - total_read);
409 cifs_reconnect(server);
410 rc = 1;
411 break;
412 }
413 }
414
415 *ptotal_read = total_read;
416 return rc;
417}
418
419static bool
420check_rfc1002_header(struct TCP_Server_Info *server, char *buf)
421{
422 char temp = *buf;
423 unsigned int pdu_length = be32_to_cpu(
424 ((struct smb_hdr *)buf)->smb_buf_length);
425
426 /*
427 * The first byte big endian of the length field,
428 * is actually not part of the length but the type
429 * with the most common, zero, as regular data.
430 */
431 if (temp == (char) RFC1002_SESSION_KEEP_ALIVE) {
432 return false;
433 } else if (temp == (char)RFC1002_POSITIVE_SESSION_RESPONSE) {
434 cFYI(1, "Good RFC 1002 session rsp");
435 return false;
436 } else if (temp == (char)RFC1002_NEGATIVE_SESSION_RESPONSE) {
437 /*
438 * We get this from Windows 98 instead of an error on
439 * SMB negprot response.
440 */
441 cFYI(1, "Negative RFC1002 Session Response Error 0x%x)",
442 pdu_length);
443 /* give server a second to clean up */
444 msleep(1000);
445 /*
446 * Always try 445 first on reconnect since we get NACK
447 * on some if we ever connected to port 139 (the NACK
448 * is since we do not begin with RFC1001 session
449 * initialize frame).
450 */
451 cifs_set_port((struct sockaddr *)
452 &server->dstaddr, CIFS_PORT);
453 cifs_reconnect(server);
454 wake_up(&server->response_q);
455 return false;
456 } else if (temp != (char) 0) {
457 cERROR(1, "Unknown RFC 1002 frame");
458 cifs_dump_mem(" Received Data: ", buf, 4);
459 cifs_reconnect(server);
460 return false;
461 }
462
463 /* else we have an SMB response */
464 if ((pdu_length > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) ||
465 (pdu_length < sizeof(struct smb_hdr) - 1 - 4)) {
466 cERROR(1, "Invalid size SMB length %d pdu_length %d",
467 4, pdu_length+4);
468 cifs_reconnect(server);
469 wake_up(&server->response_q);
470 return false;
471 }
472
473 return true;
474}
475
476static struct mid_q_entry *
477find_cifs_mid(struct TCP_Server_Info *server, struct smb_hdr *buf,
478 int *length, bool is_large_buf, bool *is_multi_rsp, char **bigbuf)
479{
480 struct mid_q_entry *mid = NULL, *tmp_mid, *ret = NULL;
481
482 spin_lock(&GlobalMid_Lock);
483 list_for_each_entry_safe(mid, tmp_mid, &server->pending_mid_q, qhead) {
484 if (mid->mid != buf->Mid ||
485 mid->midState != MID_REQUEST_SUBMITTED ||
486 mid->command != buf->Command)
487 continue;
488
489 if (*length == 0 && check2ndT2(buf, server->maxBuf) > 0) {
490 /* We have a multipart transact2 resp */
491 *is_multi_rsp = true;
492 if (mid->resp_buf) {
493 /* merge response - fix up 1st*/
494 *length = coalesce_t2(buf, mid->resp_buf);
495 if (*length > 0) {
496 *length = 0;
497 mid->multiRsp = true;
498 break;
499 }
500 /* All parts received or packet is malformed. */
501 mid->multiEnd = true;
502 goto multi_t2_fnd;
503 }
504 if (!is_large_buf) {
505 /*FIXME: switch to already allocated largebuf?*/
506 cERROR(1, "1st trans2 resp needs bigbuf");
507 } else {
508 /* Have first buffer */
509 mid->resp_buf = buf;
510 mid->largeBuf = true;
511 *bigbuf = NULL;
512 }
513 break;
514 }
515 mid->resp_buf = buf;
516 mid->largeBuf = is_large_buf;
517multi_t2_fnd:
518 if (*length == 0)
519 mid->midState = MID_RESPONSE_RECEIVED;
520 else
521 mid->midState = MID_RESPONSE_MALFORMED;
522#ifdef CONFIG_CIFS_STATS2
523 mid->when_received = jiffies;
524#endif
525 list_del_init(&mid->qhead);
526 ret = mid;
527 break;
528 }
529 spin_unlock(&GlobalMid_Lock);
530
531 return ret;
532}
533
534static void clean_demultiplex_info(struct TCP_Server_Info *server)
535{
536 int length;
537
538 /* take it off the list, if it's not already */
539 spin_lock(&cifs_tcp_ses_lock);
540 list_del_init(&server->tcp_ses_list);
541 spin_unlock(&cifs_tcp_ses_lock);
542
543 spin_lock(&GlobalMid_Lock);
544 server->tcpStatus = CifsExiting;
545 spin_unlock(&GlobalMid_Lock);
546 wake_up_all(&server->response_q);
547
548 /*
549 * Check if we have blocked requests that need to free. Note that
550 * cifs_max_pending is normally 50, but can be set at module install
551 * time to as little as two.
552 */
553 spin_lock(&GlobalMid_Lock);
554 if (atomic_read(&server->inFlight) >= cifs_max_pending)
555 atomic_set(&server->inFlight, cifs_max_pending - 1);
556 /*
557 * We do not want to set the max_pending too low or we could end up
558 * with the counter going negative.
559 */
560 spin_unlock(&GlobalMid_Lock);
561 /*
562 * Although there should not be any requests blocked on this queue it
563 * can not hurt to be paranoid and try to wake up requests that may
564 * haven been blocked when more than 50 at time were on the wire to the
565 * same server - they now will see the session is in exit state and get
566 * out of SendReceive.
567 */
568 wake_up_all(&server->request_q);
569 /* give those requests time to exit */
570 msleep(125);
571
572 if (server->ssocket) {
573 sock_release(server->ssocket);
574 server->ssocket = NULL;
575 }
576
577 if (!list_empty(&server->pending_mid_q)) {
578 struct list_head dispose_list;
579 struct mid_q_entry *mid_entry;
580 struct list_head *tmp, *tmp2;
581
582 INIT_LIST_HEAD(&dispose_list);
583 spin_lock(&GlobalMid_Lock);
584 list_for_each_safe(tmp, tmp2, &server->pending_mid_q) {
585 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
586 cFYI(1, "Clearing mid 0x%x", mid_entry->mid);
587 mid_entry->midState = MID_SHUTDOWN;
588 list_move(&mid_entry->qhead, &dispose_list);
589 }
590 spin_unlock(&GlobalMid_Lock);
591
592 /* now walk dispose list and issue callbacks */
593 list_for_each_safe(tmp, tmp2, &dispose_list) {
594 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
595 cFYI(1, "Callback mid 0x%x", mid_entry->mid);
596 list_del_init(&mid_entry->qhead);
597 mid_entry->callback(mid_entry);
598 }
599 /* 1/8th of sec is more than enough time for them to exit */
600 msleep(125);
601 }
602
603 if (!list_empty(&server->pending_mid_q)) {
604 /*
605 * mpx threads have not exited yet give them at least the smb
606 * send timeout time for long ops.
607 *
608 * Due to delays on oplock break requests, we need to wait at
609 * least 45 seconds before giving up on a request getting a
610 * response and going ahead and killing cifsd.
611 */
612 cFYI(1, "Wait for exit from demultiplex thread");
613 msleep(46000);
614 /*
615 * If threads still have not exited they are probably never
616 * coming home not much else we can do but free the memory.
617 */
618 }
619
620 kfree(server->hostname);
621 kfree(server);
622
623 length = atomic_dec_return(&tcpSesAllocCount);
624 if (length > 0)
625 mempool_resize(cifs_req_poolp, length + cifs_min_rcv,
626 GFP_KERNEL);
627}
628
322static int 629static int
323cifs_demultiplex_thread(void *p) 630cifs_demultiplex_thread(void *p)
324{ 631{
325 int length; 632 int length;
326 struct TCP_Server_Info *server = p; 633 struct TCP_Server_Info *server = p;
327 unsigned int pdu_length, total_read; 634 unsigned int pdu_length, total_read;
635 char *buf = NULL, *bigbuf = NULL, *smallbuf = NULL;
328 struct smb_hdr *smb_buffer = NULL; 636 struct smb_hdr *smb_buffer = NULL;
329 struct smb_hdr *bigbuf = NULL;
330 struct smb_hdr *smallbuf = NULL;
331 struct msghdr smb_msg; 637 struct msghdr smb_msg;
332 struct kvec iov; 638 struct kvec iov;
333 struct socket *csocket = server->ssocket;
334 struct list_head *tmp, *tmp2;
335 struct task_struct *task_to_wake = NULL; 639 struct task_struct *task_to_wake = NULL;
336 struct mid_q_entry *mid_entry; 640 struct mid_q_entry *mid_entry;
337 char temp;
338 bool isLargeBuf = false; 641 bool isLargeBuf = false;
339 bool isMultiRsp; 642 bool isMultiRsp = false;
340 int reconnect; 643 int rc;
341 644
342 current->flags |= PF_MEMALLOC; 645 current->flags |= PF_MEMALLOC;
343 cFYI(1, "Demultiplex PID: %d", task_pid_nr(current)); 646 cFYI(1, "Demultiplex PID: %d", task_pid_nr(current));
@@ -351,35 +654,16 @@ cifs_demultiplex_thread(void *p)
351 while (server->tcpStatus != CifsExiting) { 654 while (server->tcpStatus != CifsExiting) {
352 if (try_to_freeze()) 655 if (try_to_freeze())
353 continue; 656 continue;
354 if (bigbuf == NULL) {
355 bigbuf = cifs_buf_get();
356 if (!bigbuf) {
357 cERROR(1, "No memory for large SMB response");
358 msleep(3000);
359 /* retry will check if exiting */
360 continue;
361 }
362 } else if (isLargeBuf) {
363 /* we are reusing a dirty large buf, clear its start */
364 memset(bigbuf, 0, sizeof(struct smb_hdr));
365 }
366 657
367 if (smallbuf == NULL) { 658 if (!allocate_buffers(&bigbuf, &smallbuf,
368 smallbuf = cifs_small_buf_get(); 659 sizeof(struct smb_hdr), isLargeBuf))
369 if (!smallbuf) { 660 continue;
370 cERROR(1, "No memory for SMB response");
371 msleep(1000);
372 /* retry will check if exiting */
373 continue;
374 }
375 /* beginning of smb buffer is cleared in our buf_get */
376 } else /* if existing small buf clear beginning */
377 memset(smallbuf, 0, sizeof(struct smb_hdr));
378 661
379 isLargeBuf = false; 662 isLargeBuf = false;
380 isMultiRsp = false; 663 isMultiRsp = false;
381 smb_buffer = smallbuf; 664 smb_buffer = (struct smb_hdr *)smallbuf;
382 iov.iov_base = smb_buffer; 665 buf = smallbuf;
666 iov.iov_base = buf;
383 iov.iov_len = 4; 667 iov.iov_len = 4;
384 smb_msg.msg_control = NULL; 668 smb_msg.msg_control = NULL;
385 smb_msg.msg_controllen = 0; 669 smb_msg.msg_controllen = 0;
@@ -393,158 +677,50 @@ incomplete_rcv:
393 "Reconnecting...", server->hostname, 677 "Reconnecting...", server->hostname,
394 (echo_retries * SMB_ECHO_INTERVAL / HZ)); 678 (echo_retries * SMB_ECHO_INTERVAL / HZ));
395 cifs_reconnect(server); 679 cifs_reconnect(server);
396 csocket = server->ssocket;
397 wake_up(&server->response_q); 680 wake_up(&server->response_q);
398 continue; 681 continue;
399 } 682 }
400 683
401 length = 684 rc = read_from_socket(server, &smb_msg, &iov, pdu_length,
402 kernel_recvmsg(csocket, &smb_msg, 685 &total_read, true /* header read */);
403 &iov, 1, pdu_length, 0 /* BB other flags? */); 686 if (rc == 3)
404 687 goto incomplete_rcv;
405 if (server->tcpStatus == CifsExiting) { 688 else if (rc == 2)
406 break; 689 break;
407 } else if (server->tcpStatus == CifsNeedReconnect) { 690 else if (rc == 1)
408 cFYI(1, "Reconnect after server stopped responding");
409 cifs_reconnect(server);
410 cFYI(1, "call to reconnect done");
411 csocket = server->ssocket;
412 continue;
413 } else if (length == -ERESTARTSYS ||
414 length == -EAGAIN ||
415 length == -EINTR) {
416 msleep(1); /* minimum sleep to prevent looping
417 allowing socket to clear and app threads to set
418 tcpStatus CifsNeedReconnect if server hung */
419 if (pdu_length < 4) {
420 iov.iov_base = (4 - pdu_length) +
421 (char *)smb_buffer;
422 iov.iov_len = pdu_length;
423 smb_msg.msg_control = NULL;
424 smb_msg.msg_controllen = 0;
425 goto incomplete_rcv;
426 } else
427 continue;
428 } else if (length <= 0) {
429 cFYI(1, "Reconnect after unexpected peek error %d",
430 length);
431 cifs_reconnect(server);
432 csocket = server->ssocket;
433 wake_up(&server->response_q);
434 continue; 691 continue;
435 } else if (length < pdu_length) {
436 cFYI(1, "requested %d bytes but only got %d bytes",
437 pdu_length, length);
438 pdu_length -= length;
439 msleep(1);
440 goto incomplete_rcv;
441 }
442
443 /* The right amount was read from socket - 4 bytes */
444 /* so we can now interpret the length field */
445 692
446 /* the first byte big endian of the length field, 693 /*
447 is actually not part of the length but the type 694 * The right amount was read from socket - 4 bytes,
448 with the most common, zero, as regular data */ 695 * so we can now interpret the length field.
449 temp = *((char *) smb_buffer); 696 */
450 697
451 /* Note that FC 1001 length is big endian on the wire, 698 /*
452 but we convert it here so it is always manipulated 699 * Note that RFC 1001 length is big endian on the wire,
453 as host byte order */ 700 * but we convert it here so it is always manipulated
701 * as host byte order.
702 */
454 pdu_length = be32_to_cpu(smb_buffer->smb_buf_length); 703 pdu_length = be32_to_cpu(smb_buffer->smb_buf_length);
455 704
456 cFYI(1, "rfc1002 length 0x%x", pdu_length+4); 705 cFYI(1, "rfc1002 length 0x%x", pdu_length+4);
457 706 if (!check_rfc1002_header(server, buf))
458 if (temp == (char) RFC1002_SESSION_KEEP_ALIVE) {
459 continue;
460 } else if (temp == (char)RFC1002_POSITIVE_SESSION_RESPONSE) {
461 cFYI(1, "Good RFC 1002 session rsp");
462 continue;
463 } else if (temp == (char)RFC1002_NEGATIVE_SESSION_RESPONSE) {
464 /* we get this from Windows 98 instead of
465 an error on SMB negprot response */
466 cFYI(1, "Negative RFC1002 Session Response Error 0x%x)",
467 pdu_length);
468 /* give server a second to clean up */
469 msleep(1000);
470 /* always try 445 first on reconnect since we get NACK
471 * on some if we ever connected to port 139 (the NACK
472 * is since we do not begin with RFC1001 session
473 * initialize frame)
474 */
475 cifs_set_port((struct sockaddr *)
476 &server->dstaddr, CIFS_PORT);
477 cifs_reconnect(server);
478 csocket = server->ssocket;
479 wake_up(&server->response_q);
480 continue;
481 } else if (temp != (char) 0) {
482 cERROR(1, "Unknown RFC 1002 frame");
483 cifs_dump_mem(" Received Data: ", (char *)smb_buffer,
484 length);
485 cifs_reconnect(server);
486 csocket = server->ssocket;
487 continue; 707 continue;
488 }
489
490 /* else we have an SMB response */
491 if ((pdu_length > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) ||
492 (pdu_length < sizeof(struct smb_hdr) - 1 - 4)) {
493 cERROR(1, "Invalid size SMB length %d pdu_length %d",
494 length, pdu_length+4);
495 cifs_reconnect(server);
496 csocket = server->ssocket;
497 wake_up(&server->response_q);
498 continue;
499 }
500 708
501 /* else length ok */ 709 /* else length ok */
502 reconnect = 0;
503
504 if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE - 4) { 710 if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE - 4) {
505 isLargeBuf = true; 711 isLargeBuf = true;
506 memcpy(bigbuf, smallbuf, 4); 712 memcpy(bigbuf, smallbuf, 4);
507 smb_buffer = bigbuf; 713 smb_buffer = (struct smb_hdr *)bigbuf;
714 buf = bigbuf;
508 } 715 }
509 length = 0; 716
510 iov.iov_base = 4 + (char *)smb_buffer; 717 iov.iov_base = 4 + buf;
511 iov.iov_len = pdu_length; 718 iov.iov_len = pdu_length;
512 for (total_read = 0; total_read < pdu_length; 719 rc = read_from_socket(server, &smb_msg, &iov, pdu_length,
513 total_read += length) { 720 &total_read, false);
514 length = kernel_recvmsg(csocket, &smb_msg, &iov, 1, 721 if (rc == 2)
515 pdu_length - total_read, 0);
516 if (server->tcpStatus == CifsExiting) {
517 /* then will exit */
518 reconnect = 2;
519 break;
520 } else if (server->tcpStatus == CifsNeedReconnect) {
521 cifs_reconnect(server);
522 csocket = server->ssocket;
523 /* Reconnect wakes up rspns q */
524 /* Now we will reread sock */
525 reconnect = 1;
526 break;
527 } else if (length == -ERESTARTSYS ||
528 length == -EAGAIN ||
529 length == -EINTR) {
530 msleep(1); /* minimum sleep to prevent looping,
531 allowing socket to clear and app
532 threads to set tcpStatus
533 CifsNeedReconnect if server hung*/
534 length = 0;
535 continue;
536 } else if (length <= 0) {
537 cERROR(1, "Received no data, expecting %d",
538 pdu_length - total_read);
539 cifs_reconnect(server);
540 csocket = server->ssocket;
541 reconnect = 1;
542 break;
543 }
544 }
545 if (reconnect == 2)
546 break; 722 break;
547 else if (reconnect == 1) 723 else if (rc == 1)
548 continue; 724 continue;
549 725
550 total_read += 4; /* account for rfc1002 hdr */ 726 total_read += 4; /* account for rfc1002 hdr */
@@ -562,75 +738,13 @@ incomplete_rcv:
562 */ 738 */
563 length = checkSMB(smb_buffer, smb_buffer->Mid, total_read); 739 length = checkSMB(smb_buffer, smb_buffer->Mid, total_read);
564 if (length != 0) 740 if (length != 0)
565 cifs_dump_mem("Bad SMB: ", smb_buffer, 741 cifs_dump_mem("Bad SMB: ", buf,
566 min_t(unsigned int, total_read, 48)); 742 min_t(unsigned int, total_read, 48));
567 743
568 mid_entry = NULL;
569 server->lstrp = jiffies; 744 server->lstrp = jiffies;
570 745
571 spin_lock(&GlobalMid_Lock); 746 mid_entry = find_cifs_mid(server, smb_buffer, &length,
572 list_for_each_safe(tmp, tmp2, &server->pending_mid_q) { 747 isLargeBuf, &isMultiRsp, &bigbuf);
573 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
574
575 if (mid_entry->mid != smb_buffer->Mid ||
576 mid_entry->midState != MID_REQUEST_SUBMITTED ||
577 mid_entry->command != smb_buffer->Command) {
578 mid_entry = NULL;
579 continue;
580 }
581
582 if (length == 0 &&
583 check2ndT2(smb_buffer, server->maxBuf) > 0) {
584 /* We have a multipart transact2 resp */
585 isMultiRsp = true;
586 if (mid_entry->resp_buf) {
587 /* merge response - fix up 1st*/
588 length = coalesce_t2(smb_buffer,
589 mid_entry->resp_buf);
590 if (length > 0) {
591 length = 0;
592 mid_entry->multiRsp = true;
593 break;
594 } else {
595 /* all parts received or
596 * packet is malformed
597 */
598 mid_entry->multiEnd = true;
599 goto multi_t2_fnd;
600 }
601 } else {
602 if (!isLargeBuf) {
603 /*
604 * FIXME: switch to already
605 * allocated largebuf?
606 */
607 cERROR(1, "1st trans2 resp "
608 "needs bigbuf");
609 } else {
610 /* Have first buffer */
611 mid_entry->resp_buf =
612 smb_buffer;
613 mid_entry->largeBuf = true;
614 bigbuf = NULL;
615 }
616 }
617 break;
618 }
619 mid_entry->resp_buf = smb_buffer;
620 mid_entry->largeBuf = isLargeBuf;
621multi_t2_fnd:
622 if (length == 0)
623 mid_entry->midState = MID_RESPONSE_RECEIVED;
624 else
625 mid_entry->midState = MID_RESPONSE_MALFORMED;
626#ifdef CONFIG_CIFS_STATS2
627 mid_entry->when_received = jiffies;
628#endif
629 list_del_init(&mid_entry->qhead);
630 break;
631 }
632 spin_unlock(&GlobalMid_Lock);
633
634 if (mid_entry != NULL) { 748 if (mid_entry != NULL) {
635 mid_entry->callback(mid_entry); 749 mid_entry->callback(mid_entry);
636 /* Was previous buf put in mpx struct for multi-rsp? */ 750 /* Was previous buf put in mpx struct for multi-rsp? */
@@ -648,7 +762,7 @@ multi_t2_fnd:
648 !isMultiRsp) { 762 !isMultiRsp) {
649 cERROR(1, "No task to wake, unknown frame received! " 763 cERROR(1, "No task to wake, unknown frame received! "
650 "NumMids %d", atomic_read(&midCount)); 764 "NumMids %d", atomic_read(&midCount));
651 cifs_dump_mem("Received Data is: ", (char *)smb_buffer, 765 cifs_dump_mem("Received Data is: ", buf,
652 sizeof(struct smb_hdr)); 766 sizeof(struct smb_hdr));
653#ifdef CONFIG_CIFS_DEBUG2 767#ifdef CONFIG_CIFS_DEBUG2
654 cifs_dump_detail(smb_buffer); 768 cifs_dump_detail(smb_buffer);
@@ -658,88 +772,13 @@ multi_t2_fnd:
658 } 772 }
659 } /* end while !EXITING */ 773 } /* end while !EXITING */
660 774
661 /* take it off the list, if it's not already */
662 spin_lock(&cifs_tcp_ses_lock);
663 list_del_init(&server->tcp_ses_list);
664 spin_unlock(&cifs_tcp_ses_lock);
665
666 spin_lock(&GlobalMid_Lock);
667 server->tcpStatus = CifsExiting;
668 spin_unlock(&GlobalMid_Lock);
669 wake_up_all(&server->response_q);
670
671 /* check if we have blocked requests that need to free */
672 /* Note that cifs_max_pending is normally 50, but
673 can be set at module install time to as little as two */
674 spin_lock(&GlobalMid_Lock);
675 if (atomic_read(&server->inFlight) >= cifs_max_pending)
676 atomic_set(&server->inFlight, cifs_max_pending - 1);
677 /* We do not want to set the max_pending too low or we
678 could end up with the counter going negative */
679 spin_unlock(&GlobalMid_Lock);
680 /* Although there should not be any requests blocked on
681 this queue it can not hurt to be paranoid and try to wake up requests
682 that may haven been blocked when more than 50 at time were on the wire
683 to the same server - they now will see the session is in exit state
684 and get out of SendReceive. */
685 wake_up_all(&server->request_q);
686 /* give those requests time to exit */
687 msleep(125);
688
689 if (server->ssocket) {
690 sock_release(csocket);
691 server->ssocket = NULL;
692 }
693 /* buffer usually freed in free_mid - need to free it here on exit */ 775 /* buffer usually freed in free_mid - need to free it here on exit */
694 cifs_buf_release(bigbuf); 776 cifs_buf_release(bigbuf);
695 if (smallbuf) /* no sense logging a debug message if NULL */ 777 if (smallbuf) /* no sense logging a debug message if NULL */
696 cifs_small_buf_release(smallbuf); 778 cifs_small_buf_release(smallbuf);
697 779
698 if (!list_empty(&server->pending_mid_q)) {
699 struct list_head dispose_list;
700
701 INIT_LIST_HEAD(&dispose_list);
702 spin_lock(&GlobalMid_Lock);
703 list_for_each_safe(tmp, tmp2, &server->pending_mid_q) {
704 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
705 cFYI(1, "Clearing mid 0x%x", mid_entry->mid);
706 mid_entry->midState = MID_SHUTDOWN;
707 list_move(&mid_entry->qhead, &dispose_list);
708 }
709 spin_unlock(&GlobalMid_Lock);
710
711 /* now walk dispose list and issue callbacks */
712 list_for_each_safe(tmp, tmp2, &dispose_list) {
713 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
714 cFYI(1, "Callback mid 0x%x", mid_entry->mid);
715 list_del_init(&mid_entry->qhead);
716 mid_entry->callback(mid_entry);
717 }
718 /* 1/8th of sec is more than enough time for them to exit */
719 msleep(125);
720 }
721
722 if (!list_empty(&server->pending_mid_q)) {
723 /* mpx threads have not exited yet give them
724 at least the smb send timeout time for long ops */
725 /* due to delays on oplock break requests, we need
726 to wait at least 45 seconds before giving up
727 on a request getting a response and going ahead
728 and killing cifsd */
729 cFYI(1, "Wait for exit from demultiplex thread");
730 msleep(46000);
731 /* if threads still have not exited they are probably never
732 coming home not much else we can do but free the memory */
733 }
734
735 kfree(server->hostname);
736 task_to_wake = xchg(&server->tsk, NULL); 780 task_to_wake = xchg(&server->tsk, NULL);
737 kfree(server); 781 clean_demultiplex_info(server);
738
739 length = atomic_dec_return(&tcpSesAllocCount);
740 if (length > 0)
741 mempool_resize(cifs_req_poolp, length + cifs_min_rcv,
742 GFP_KERNEL);
743 782
744 /* if server->tsk was NULL then wait for a signal before exiting */ 783 /* if server->tsk was NULL then wait for a signal before exiting */
745 if (!task_to_wake) { 784 if (!task_to_wake) {
@@ -2839,7 +2878,8 @@ cleanup_volume_info_contents(struct smb_vol *volume_info)
2839 kfree(volume_info->username); 2878 kfree(volume_info->username);
2840 kzfree(volume_info->password); 2879 kzfree(volume_info->password);
2841 kfree(volume_info->UNC); 2880 kfree(volume_info->UNC);
2842 kfree(volume_info->UNCip); 2881 if (volume_info->UNCip != volume_info->UNC + 2)
2882 kfree(volume_info->UNCip);
2843 kfree(volume_info->domainname); 2883 kfree(volume_info->domainname);
2844 kfree(volume_info->iocharset); 2884 kfree(volume_info->iocharset);
2845 kfree(volume_info->prepath); 2885 kfree(volume_info->prepath);
@@ -3193,15 +3233,9 @@ mount_fail_check:
3193 else 3233 else
3194 cifs_put_tcp_session(srvTcp); 3234 cifs_put_tcp_session(srvTcp);
3195 bdi_destroy(&cifs_sb->bdi); 3235 bdi_destroy(&cifs_sb->bdi);
3196 goto out;
3197 } 3236 }
3198 3237
3199 /* volume_info->password is freed above when existing session found
3200 (in which case it is not needed anymore) but when new sesion is created
3201 the password ptr is put in the new session structure (in which case the
3202 password will be freed at unmount time) */
3203out: 3238out:
3204 /* zero out password before freeing */
3205 FreeXid(xid); 3239 FreeXid(xid);
3206 return rc; 3240 return rc;
3207} 3241}
diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c
index 499f27fc8576..72d448bf96ce 100644
--- a/fs/cifs/dir.c
+++ b/fs/cifs/dir.c
@@ -57,11 +57,6 @@ build_path_from_dentry(struct dentry *direntry)
57 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb); 57 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
58 unsigned seq; 58 unsigned seq;
59 59
60 if (direntry == NULL)
61 return NULL; /* not much we can do if dentry is freed and
62 we need to reopen the file after it was closed implicitly
63 when the server crashed */
64
65 dirsep = CIFS_DIR_SEP(cifs_sb); 60 dirsep = CIFS_DIR_SEP(cifs_sb);
66 if (tcon->Flags & SMB_SHARE_IS_IN_DFS) 61 if (tcon->Flags & SMB_SHARE_IS_IN_DFS)
67 dfsplen = strnlen(tcon->treeName, MAX_TREE_SIZE + 1); 62 dfsplen = strnlen(tcon->treeName, MAX_TREE_SIZE + 1);
@@ -110,8 +105,8 @@ cifs_bp_rename_retry:
110 } 105 }
111 rcu_read_unlock(); 106 rcu_read_unlock();
112 if (namelen != dfsplen || read_seqretry(&rename_lock, seq)) { 107 if (namelen != dfsplen || read_seqretry(&rename_lock, seq)) {
113 cERROR(1, "did not end path lookup where expected namelen is %d", 108 cFYI(1, "did not end path lookup where expected. namelen=%d "
114 namelen); 109 "dfsplen=%d", namelen, dfsplen);
115 /* presumably this is only possible if racing with a rename 110 /* presumably this is only possible if racing with a rename
116 of one of the parent directories (we can not lock the dentries 111 of one of the parent directories (we can not lock the dentries
117 above us to prevent this, but retrying should be harmless) */ 112 above us to prevent this, but retrying should be harmless) */
diff --git a/fs/cifs/dns_resolve.c b/fs/cifs/dns_resolve.c
index 548f06230a6d..1d2d91d9bf65 100644
--- a/fs/cifs/dns_resolve.c
+++ b/fs/cifs/dns_resolve.c
@@ -79,8 +79,8 @@ dns_resolve_server_name_to_ip(const char *unc, char **ip_addr)
79 /* Perform the upcall */ 79 /* Perform the upcall */
80 rc = dns_query(NULL, hostname, len, NULL, ip_addr, NULL); 80 rc = dns_query(NULL, hostname, len, NULL, ip_addr, NULL);
81 if (rc < 0) 81 if (rc < 0)
82 cERROR(1, "%s: unable to resolve: %*.*s", 82 cFYI(1, "%s: unable to resolve: %*.*s",
83 __func__, len, len, hostname); 83 __func__, len, len, hostname);
84 else 84 else
85 cFYI(1, "%s: resolved: %*.*s to %s", 85 cFYI(1, "%s: resolved: %*.*s to %s",
86 __func__, len, len, hostname, *ip_addr); 86 __func__, len, len, hostname, *ip_addr);
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index 378acdafa356..9f41a10523a1 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -314,6 +314,8 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file)
314 } 314 }
315 spin_unlock(&cifs_file_list_lock); 315 spin_unlock(&cifs_file_list_lock);
316 316
317 cancel_work_sync(&cifs_file->oplock_break);
318
317 if (!tcon->need_reconnect && !cifs_file->invalidHandle) { 319 if (!tcon->need_reconnect && !cifs_file->invalidHandle) {
318 int xid, rc; 320 int xid, rc;
319 321
@@ -2418,31 +2420,6 @@ void cifs_oplock_break(struct work_struct *work)
2418 cinode->clientCanCacheRead ? 1 : 0); 2420 cinode->clientCanCacheRead ? 1 : 0);
2419 cFYI(1, "Oplock release rc = %d", rc); 2421 cFYI(1, "Oplock release rc = %d", rc);
2420 } 2422 }
2421
2422 /*
2423 * We might have kicked in before is_valid_oplock_break()
2424 * finished grabbing reference for us. Make sure it's done by
2425 * waiting for cifs_file_list_lock.
2426 */
2427 spin_lock(&cifs_file_list_lock);
2428 spin_unlock(&cifs_file_list_lock);
2429
2430 cifs_oplock_break_put(cfile);
2431}
2432
2433/* must be called while holding cifs_file_list_lock */
2434void cifs_oplock_break_get(struct cifsFileInfo *cfile)
2435{
2436 cifs_sb_active(cfile->dentry->d_sb);
2437 cifsFileInfo_get(cfile);
2438}
2439
2440void cifs_oplock_break_put(struct cifsFileInfo *cfile)
2441{
2442 struct super_block *sb = cfile->dentry->d_sb;
2443
2444 cifsFileInfo_put(cfile);
2445 cifs_sb_deactive(sb);
2446} 2423}
2447 2424
2448const struct address_space_operations cifs_addr_ops = { 2425const struct address_space_operations cifs_addr_ops = {
diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c
index 9b018c8334fa..a7b2dcd4a53e 100644
--- a/fs/cifs/inode.c
+++ b/fs/cifs/inode.c
@@ -764,20 +764,10 @@ char *cifs_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
764 if (full_path == NULL) 764 if (full_path == NULL)
765 return full_path; 765 return full_path;
766 766
767 if (dfsplen) { 767 if (dfsplen)
768 strncpy(full_path, tcon->treeName, dfsplen); 768 strncpy(full_path, tcon->treeName, dfsplen);
769 /* switch slash direction in prepath depending on whether
770 * windows or posix style path names
771 */
772 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS) {
773 int i;
774 for (i = 0; i < dfsplen; i++) {
775 if (full_path[i] == '\\')
776 full_path[i] = '/';
777 }
778 }
779 }
780 strncpy(full_path + dfsplen, vol->prepath, pplen); 769 strncpy(full_path + dfsplen, vol->prepath, pplen);
770 convert_delimiter(full_path, CIFS_DIR_SEP(cifs_sb));
781 full_path[dfsplen + pplen] = 0; /* add trailing null */ 771 full_path[dfsplen + pplen] = 0; /* add trailing null */
782 return full_path; 772 return full_path;
783} 773}
diff --git a/fs/cifs/link.c b/fs/cifs/link.c
index 556b1a0b54de..db3f18cdf024 100644
--- a/fs/cifs/link.c
+++ b/fs/cifs/link.c
@@ -74,8 +74,14 @@ symlink_hash(unsigned int link_len, const char *link_str, u8 *md5_hash)
74 cERROR(1, "%s: Could not init md5 shash\n", __func__); 74 cERROR(1, "%s: Could not init md5 shash\n", __func__);
75 goto symlink_hash_err; 75 goto symlink_hash_err;
76 } 76 }
77 crypto_shash_update(&sdescmd5->shash, link_str, link_len); 77 rc = crypto_shash_update(&sdescmd5->shash, link_str, link_len);
78 if (rc) {
79 cERROR(1, "%s: Could not update iwth link_str\n", __func__);
80 goto symlink_hash_err;
81 }
78 rc = crypto_shash_final(&sdescmd5->shash, md5_hash); 82 rc = crypto_shash_final(&sdescmd5->shash, md5_hash);
83 if (rc)
84 cERROR(1, "%s: Could not generate md5 hash\n", __func__);
79 85
80symlink_hash_err: 86symlink_hash_err:
81 crypto_free_shash(md5); 87 crypto_free_shash(md5);
diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
index 03a1f491d39b..7c1693392598 100644
--- a/fs/cifs/misc.c
+++ b/fs/cifs/misc.c
@@ -585,15 +585,8 @@ is_valid_oplock_break(struct smb_hdr *buf, struct TCP_Server_Info *srv)
585 585
586 cifs_set_oplock_level(pCifsInode, 586 cifs_set_oplock_level(pCifsInode,
587 pSMB->OplockLevel ? OPLOCK_READ : 0); 587 pSMB->OplockLevel ? OPLOCK_READ : 0);
588 /* 588 queue_work(system_nrt_wq,
589 * cifs_oplock_break_put() can't be called 589 &netfile->oplock_break);
590 * from here. Get reference after queueing
591 * succeeded. cifs_oplock_break() will
592 * synchronize using cifs_file_list_lock.
593 */
594 if (queue_work(system_nrt_wq,
595 &netfile->oplock_break))
596 cifs_oplock_break_get(netfile);
597 netfile->oplock_break_cancelled = false; 590 netfile->oplock_break_cancelled = false;
598 591
599 spin_unlock(&cifs_file_list_lock); 592 spin_unlock(&cifs_file_list_lock);
diff --git a/fs/cifs/readdir.c b/fs/cifs/readdir.c
index 965a3af186a1..5de03ec20144 100644
--- a/fs/cifs/readdir.c
+++ b/fs/cifs/readdir.c
@@ -4,6 +4,7 @@
4 * Directory search handling 4 * Directory search handling
5 * 5 *
6 * Copyright (C) International Business Machines Corp., 2004, 2008 6 * Copyright (C) International Business Machines Corp., 2004, 2008
7 * Copyright (C) Red Hat, Inc., 2011
7 * Author(s): Steve French (sfrench@us.ibm.com) 8 * Author(s): Steve French (sfrench@us.ibm.com)
8 * 9 *
9 * This library is free software; you can redistribute it and/or modify 10 * This library is free software; you can redistribute it and/or modify
@@ -290,10 +291,10 @@ error_exit:
290} 291}
291 292
292/* return length of unicode string in bytes */ 293/* return length of unicode string in bytes */
293static int cifs_unicode_bytelen(char *str) 294static int cifs_unicode_bytelen(const char *str)
294{ 295{
295 int len; 296 int len;
296 __le16 *ustr = (__le16 *)str; 297 const __le16 *ustr = (const __le16 *)str;
297 298
298 for (len = 0; len <= PATH_MAX; len++) { 299 for (len = 0; len <= PATH_MAX; len++) {
299 if (ustr[len] == 0) 300 if (ustr[len] == 0)
@@ -334,78 +335,128 @@ static char *nxt_dir_entry(char *old_entry, char *end_of_smb, int level)
334 335
335} 336}
336 337
338struct cifs_dirent {
339 const char *name;
340 size_t namelen;
341 u32 resume_key;
342 u64 ino;
343};
344
345static void cifs_fill_dirent_unix(struct cifs_dirent *de,
346 const FILE_UNIX_INFO *info, bool is_unicode)
347{
348 de->name = &info->FileName[0];
349 if (is_unicode)
350 de->namelen = cifs_unicode_bytelen(de->name);
351 else
352 de->namelen = strnlen(de->name, PATH_MAX);
353 de->resume_key = info->ResumeKey;
354 de->ino = le64_to_cpu(info->basic.UniqueId);
355}
356
357static void cifs_fill_dirent_dir(struct cifs_dirent *de,
358 const FILE_DIRECTORY_INFO *info)
359{
360 de->name = &info->FileName[0];
361 de->namelen = le32_to_cpu(info->FileNameLength);
362 de->resume_key = info->FileIndex;
363}
364
365static void cifs_fill_dirent_full(struct cifs_dirent *de,
366 const FILE_FULL_DIRECTORY_INFO *info)
367{
368 de->name = &info->FileName[0];
369 de->namelen = le32_to_cpu(info->FileNameLength);
370 de->resume_key = info->FileIndex;
371}
372
373static void cifs_fill_dirent_search(struct cifs_dirent *de,
374 const SEARCH_ID_FULL_DIR_INFO *info)
375{
376 de->name = &info->FileName[0];
377 de->namelen = le32_to_cpu(info->FileNameLength);
378 de->resume_key = info->FileIndex;
379 de->ino = le64_to_cpu(info->UniqueId);
380}
381
382static void cifs_fill_dirent_both(struct cifs_dirent *de,
383 const FILE_BOTH_DIRECTORY_INFO *info)
384{
385 de->name = &info->FileName[0];
386 de->namelen = le32_to_cpu(info->FileNameLength);
387 de->resume_key = info->FileIndex;
388}
389
390static void cifs_fill_dirent_std(struct cifs_dirent *de,
391 const FIND_FILE_STANDARD_INFO *info)
392{
393 de->name = &info->FileName[0];
394 /* one byte length, no endianess conversion */
395 de->namelen = info->FileNameLength;
396 de->resume_key = info->ResumeKey;
397}
398
399static int cifs_fill_dirent(struct cifs_dirent *de, const void *info,
400 u16 level, bool is_unicode)
401{
402 memset(de, 0, sizeof(*de));
403
404 switch (level) {
405 case SMB_FIND_FILE_UNIX:
406 cifs_fill_dirent_unix(de, info, is_unicode);
407 break;
408 case SMB_FIND_FILE_DIRECTORY_INFO:
409 cifs_fill_dirent_dir(de, info);
410 break;
411 case SMB_FIND_FILE_FULL_DIRECTORY_INFO:
412 cifs_fill_dirent_full(de, info);
413 break;
414 case SMB_FIND_FILE_ID_FULL_DIR_INFO:
415 cifs_fill_dirent_search(de, info);
416 break;
417 case SMB_FIND_FILE_BOTH_DIRECTORY_INFO:
418 cifs_fill_dirent_both(de, info);
419 break;
420 case SMB_FIND_FILE_INFO_STANDARD:
421 cifs_fill_dirent_std(de, info);
422 break;
423 default:
424 cFYI(1, "Unknown findfirst level %d", level);
425 return -EINVAL;
426 }
427
428 return 0;
429}
430
337#define UNICODE_DOT cpu_to_le16(0x2e) 431#define UNICODE_DOT cpu_to_le16(0x2e)
338 432
339/* return 0 if no match and 1 for . (current directory) and 2 for .. (parent) */ 433/* return 0 if no match and 1 for . (current directory) and 2 for .. (parent) */
340static int cifs_entry_is_dot(char *current_entry, struct cifsFileInfo *cfile) 434static int cifs_entry_is_dot(struct cifs_dirent *de, bool is_unicode)
341{ 435{
342 int rc = 0; 436 int rc = 0;
343 char *filename = NULL;
344 int len = 0;
345
346 if (cfile->srch_inf.info_level == SMB_FIND_FILE_UNIX) {
347 FILE_UNIX_INFO *pFindData = (FILE_UNIX_INFO *)current_entry;
348 filename = &pFindData->FileName[0];
349 if (cfile->srch_inf.unicode) {
350 len = cifs_unicode_bytelen(filename);
351 } else {
352 /* BB should we make this strnlen of PATH_MAX? */
353 len = strnlen(filename, 5);
354 }
355 } else if (cfile->srch_inf.info_level == SMB_FIND_FILE_DIRECTORY_INFO) {
356 FILE_DIRECTORY_INFO *pFindData =
357 (FILE_DIRECTORY_INFO *)current_entry;
358 filename = &pFindData->FileName[0];
359 len = le32_to_cpu(pFindData->FileNameLength);
360 } else if (cfile->srch_inf.info_level ==
361 SMB_FIND_FILE_FULL_DIRECTORY_INFO) {
362 FILE_FULL_DIRECTORY_INFO *pFindData =
363 (FILE_FULL_DIRECTORY_INFO *)current_entry;
364 filename = &pFindData->FileName[0];
365 len = le32_to_cpu(pFindData->FileNameLength);
366 } else if (cfile->srch_inf.info_level ==
367 SMB_FIND_FILE_ID_FULL_DIR_INFO) {
368 SEARCH_ID_FULL_DIR_INFO *pFindData =
369 (SEARCH_ID_FULL_DIR_INFO *)current_entry;
370 filename = &pFindData->FileName[0];
371 len = le32_to_cpu(pFindData->FileNameLength);
372 } else if (cfile->srch_inf.info_level ==
373 SMB_FIND_FILE_BOTH_DIRECTORY_INFO) {
374 FILE_BOTH_DIRECTORY_INFO *pFindData =
375 (FILE_BOTH_DIRECTORY_INFO *)current_entry;
376 filename = &pFindData->FileName[0];
377 len = le32_to_cpu(pFindData->FileNameLength);
378 } else if (cfile->srch_inf.info_level == SMB_FIND_FILE_INFO_STANDARD) {
379 FIND_FILE_STANDARD_INFO *pFindData =
380 (FIND_FILE_STANDARD_INFO *)current_entry;
381 filename = &pFindData->FileName[0];
382 len = pFindData->FileNameLength;
383 } else {
384 cFYI(1, "Unknown findfirst level %d",
385 cfile->srch_inf.info_level);
386 }
387 437
388 if (filename) { 438 if (!de->name)
389 if (cfile->srch_inf.unicode) { 439 return 0;
390 __le16 *ufilename = (__le16 *)filename; 440
391 if (len == 2) { 441 if (is_unicode) {
392 /* check for . */ 442 __le16 *ufilename = (__le16 *)de->name;
393 if (ufilename[0] == UNICODE_DOT) 443 if (de->namelen == 2) {
394 rc = 1; 444 /* check for . */
395 } else if (len == 4) { 445 if (ufilename[0] == UNICODE_DOT)
396 /* check for .. */ 446 rc = 1;
397 if ((ufilename[0] == UNICODE_DOT) 447 } else if (de->namelen == 4) {
398 && (ufilename[1] == UNICODE_DOT)) 448 /* check for .. */
399 rc = 2; 449 if (ufilename[0] == UNICODE_DOT &&
400 } 450 ufilename[1] == UNICODE_DOT)
401 } else /* ASCII */ { 451 rc = 2;
402 if (len == 1) { 452 }
403 if (filename[0] == '.') 453 } else /* ASCII */ {
404 rc = 1; 454 if (de->namelen == 1) {
405 } else if (len == 2) { 455 if (de->name[0] == '.')
406 if ((filename[0] == '.') && (filename[1] == '.')) 456 rc = 1;
407 rc = 2; 457 } else if (de->namelen == 2) {
408 } 458 if (de->name[0] == '.' && de->name[1] == '.')
459 rc = 2;
409 } 460 }
410 } 461 }
411 462
@@ -427,66 +478,18 @@ static int is_dir_changed(struct file *file)
427} 478}
428 479
429static int cifs_save_resume_key(const char *current_entry, 480static int cifs_save_resume_key(const char *current_entry,
430 struct cifsFileInfo *cifsFile) 481 struct cifsFileInfo *file_info)
431{ 482{
432 int rc = 0; 483 struct cifs_dirent de;
433 unsigned int len = 0; 484 int rc;
434 __u16 level;
435 char *filename;
436
437 if ((cifsFile == NULL) || (current_entry == NULL))
438 return -EINVAL;
439
440 level = cifsFile->srch_inf.info_level;
441
442 if (level == SMB_FIND_FILE_UNIX) {
443 FILE_UNIX_INFO *pFindData = (FILE_UNIX_INFO *)current_entry;
444 485
445 filename = &pFindData->FileName[0]; 486 rc = cifs_fill_dirent(&de, current_entry, file_info->srch_inf.info_level,
446 if (cifsFile->srch_inf.unicode) { 487 file_info->srch_inf.unicode);
447 len = cifs_unicode_bytelen(filename); 488 if (!rc) {
448 } else { 489 file_info->srch_inf.presume_name = de.name;
449 /* BB should we make this strnlen of PATH_MAX? */ 490 file_info->srch_inf.resume_name_len = de.namelen;
450 len = strnlen(filename, PATH_MAX); 491 file_info->srch_inf.resume_key = de.resume_key;
451 }
452 cifsFile->srch_inf.resume_key = pFindData->ResumeKey;
453 } else if (level == SMB_FIND_FILE_DIRECTORY_INFO) {
454 FILE_DIRECTORY_INFO *pFindData =
455 (FILE_DIRECTORY_INFO *)current_entry;
456 filename = &pFindData->FileName[0];
457 len = le32_to_cpu(pFindData->FileNameLength);
458 cifsFile->srch_inf.resume_key = pFindData->FileIndex;
459 } else if (level == SMB_FIND_FILE_FULL_DIRECTORY_INFO) {
460 FILE_FULL_DIRECTORY_INFO *pFindData =
461 (FILE_FULL_DIRECTORY_INFO *)current_entry;
462 filename = &pFindData->FileName[0];
463 len = le32_to_cpu(pFindData->FileNameLength);
464 cifsFile->srch_inf.resume_key = pFindData->FileIndex;
465 } else if (level == SMB_FIND_FILE_ID_FULL_DIR_INFO) {
466 SEARCH_ID_FULL_DIR_INFO *pFindData =
467 (SEARCH_ID_FULL_DIR_INFO *)current_entry;
468 filename = &pFindData->FileName[0];
469 len = le32_to_cpu(pFindData->FileNameLength);
470 cifsFile->srch_inf.resume_key = pFindData->FileIndex;
471 } else if (level == SMB_FIND_FILE_BOTH_DIRECTORY_INFO) {
472 FILE_BOTH_DIRECTORY_INFO *pFindData =
473 (FILE_BOTH_DIRECTORY_INFO *)current_entry;
474 filename = &pFindData->FileName[0];
475 len = le32_to_cpu(pFindData->FileNameLength);
476 cifsFile->srch_inf.resume_key = pFindData->FileIndex;
477 } else if (level == SMB_FIND_FILE_INFO_STANDARD) {
478 FIND_FILE_STANDARD_INFO *pFindData =
479 (FIND_FILE_STANDARD_INFO *)current_entry;
480 filename = &pFindData->FileName[0];
481 /* one byte length, no name conversion */
482 len = (unsigned int)pFindData->FileNameLength;
483 cifsFile->srch_inf.resume_key = pFindData->ResumeKey;
484 } else {
485 cFYI(1, "Unknown findfirst level %d", level);
486 return -EINVAL;
487 } 492 }
488 cifsFile->srch_inf.resume_name_len = len;
489 cifsFile->srch_inf.presume_name = filename;
490 return rc; 493 return rc;
491} 494}
492 495
@@ -605,136 +608,70 @@ static int find_cifs_entry(const int xid, struct cifs_tcon *pTcon,
605 return rc; 608 return rc;
606} 609}
607 610
608/* inode num, inode type and filename returned */ 611static int cifs_filldir(char *find_entry, struct file *file, filldir_t filldir,
609static int cifs_get_name_from_search_buf(struct qstr *pqst, 612 void *dirent, char *scratch_buf, unsigned int max_len)
610 char *current_entry, __u16 level, unsigned int unicode,
611 struct cifs_sb_info *cifs_sb, unsigned int max_len, __u64 *pinum)
612{ 613{
614 struct cifsFileInfo *file_info = file->private_data;
615 struct super_block *sb = file->f_path.dentry->d_sb;
616 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
617 struct cifs_dirent de = { NULL, };
618 struct cifs_fattr fattr;
619 struct dentry *dentry;
620 struct qstr name;
613 int rc = 0; 621 int rc = 0;
614 unsigned int len = 0; 622 ino_t ino;
615 char *filename;
616 struct nls_table *nlt = cifs_sb->local_nls;
617
618 *pinum = 0;
619
620 if (level == SMB_FIND_FILE_UNIX) {
621 FILE_UNIX_INFO *pFindData = (FILE_UNIX_INFO *)current_entry;
622
623 filename = &pFindData->FileName[0];
624 if (unicode) {
625 len = cifs_unicode_bytelen(filename);
626 } else {
627 /* BB should we make this strnlen of PATH_MAX? */
628 len = strnlen(filename, PATH_MAX);
629 }
630 623
631 *pinum = le64_to_cpu(pFindData->basic.UniqueId); 624 rc = cifs_fill_dirent(&de, find_entry, file_info->srch_inf.info_level,
632 } else if (level == SMB_FIND_FILE_DIRECTORY_INFO) { 625 file_info->srch_inf.unicode);
633 FILE_DIRECTORY_INFO *pFindData = 626 if (rc)
634 (FILE_DIRECTORY_INFO *)current_entry; 627 return rc;
635 filename = &pFindData->FileName[0];
636 len = le32_to_cpu(pFindData->FileNameLength);
637 } else if (level == SMB_FIND_FILE_FULL_DIRECTORY_INFO) {
638 FILE_FULL_DIRECTORY_INFO *pFindData =
639 (FILE_FULL_DIRECTORY_INFO *)current_entry;
640 filename = &pFindData->FileName[0];
641 len = le32_to_cpu(pFindData->FileNameLength);
642 } else if (level == SMB_FIND_FILE_ID_FULL_DIR_INFO) {
643 SEARCH_ID_FULL_DIR_INFO *pFindData =
644 (SEARCH_ID_FULL_DIR_INFO *)current_entry;
645 filename = &pFindData->FileName[0];
646 len = le32_to_cpu(pFindData->FileNameLength);
647 *pinum = le64_to_cpu(pFindData->UniqueId);
648 } else if (level == SMB_FIND_FILE_BOTH_DIRECTORY_INFO) {
649 FILE_BOTH_DIRECTORY_INFO *pFindData =
650 (FILE_BOTH_DIRECTORY_INFO *)current_entry;
651 filename = &pFindData->FileName[0];
652 len = le32_to_cpu(pFindData->FileNameLength);
653 } else if (level == SMB_FIND_FILE_INFO_STANDARD) {
654 FIND_FILE_STANDARD_INFO *pFindData =
655 (FIND_FILE_STANDARD_INFO *)current_entry;
656 filename = &pFindData->FileName[0];
657 /* one byte length, no name conversion */
658 len = (unsigned int)pFindData->FileNameLength;
659 } else {
660 cFYI(1, "Unknown findfirst level %d", level);
661 return -EINVAL;
662 }
663 628
664 if (len > max_len) { 629 if (de.namelen > max_len) {
665 cERROR(1, "bad search response length %d past smb end", len); 630 cERROR(1, "bad search response length %zd past smb end",
631 de.namelen);
666 return -EINVAL; 632 return -EINVAL;
667 } 633 }
668 634
669 if (unicode) {
670 pqst->len = cifs_from_ucs2((char *) pqst->name,
671 (__le16 *) filename,
672 UNICODE_NAME_MAX,
673 min(len, max_len), nlt,
674 cifs_sb->mnt_cifs_flags &
675 CIFS_MOUNT_MAP_SPECIAL_CHR);
676 pqst->len -= nls_nullsize(nlt);
677 } else {
678 pqst->name = filename;
679 pqst->len = len;
680 }
681 return rc;
682}
683
684static int cifs_filldir(char *pfindEntry, struct file *file, filldir_t filldir,
685 void *direntry, char *scratch_buf, unsigned int max_len)
686{
687 int rc = 0;
688 struct qstr qstring;
689 struct cifsFileInfo *pCifsF;
690 u64 inum;
691 ino_t ino;
692 struct super_block *sb;
693 struct cifs_sb_info *cifs_sb;
694 struct dentry *tmp_dentry;
695 struct cifs_fattr fattr;
696
697 /* get filename and len into qstring */
698 /* get dentry */
699 /* decide whether to create and populate ionde */
700 if ((direntry == NULL) || (file == NULL))
701 return -EINVAL;
702
703 pCifsF = file->private_data;
704
705 if ((scratch_buf == NULL) || (pfindEntry == NULL) || (pCifsF == NULL))
706 return -ENOENT;
707
708 rc = cifs_entry_is_dot(pfindEntry, pCifsF);
709 /* skip . and .. since we added them first */ 635 /* skip . and .. since we added them first */
710 if (rc != 0) 636 if (cifs_entry_is_dot(&de, file_info->srch_inf.unicode))
711 return 0; 637 return 0;
712 638
713 sb = file->f_path.dentry->d_sb; 639 if (file_info->srch_inf.unicode) {
714 cifs_sb = CIFS_SB(sb); 640 struct nls_table *nlt = cifs_sb->local_nls;
715
716 qstring.name = scratch_buf;
717 rc = cifs_get_name_from_search_buf(&qstring, pfindEntry,
718 pCifsF->srch_inf.info_level,
719 pCifsF->srch_inf.unicode, cifs_sb,
720 max_len, &inum /* returned */);
721 641
722 if (rc) 642 name.name = scratch_buf;
723 return rc; 643 name.len =
644 cifs_from_ucs2((char *)name.name, (__le16 *)de.name,
645 UNICODE_NAME_MAX,
646 min(de.namelen, (size_t)max_len), nlt,
647 cifs_sb->mnt_cifs_flags &
648 CIFS_MOUNT_MAP_SPECIAL_CHR);
649 name.len -= nls_nullsize(nlt);
650 } else {
651 name.name = de.name;
652 name.len = de.namelen;
653 }
724 654
725 if (pCifsF->srch_inf.info_level == SMB_FIND_FILE_UNIX) 655 switch (file_info->srch_inf.info_level) {
656 case SMB_FIND_FILE_UNIX:
726 cifs_unix_basic_to_fattr(&fattr, 657 cifs_unix_basic_to_fattr(&fattr,
727 &((FILE_UNIX_INFO *) pfindEntry)->basic, 658 &((FILE_UNIX_INFO *)find_entry)->basic,
728 cifs_sb); 659 cifs_sb);
729 else if (pCifsF->srch_inf.info_level == SMB_FIND_FILE_INFO_STANDARD) 660 break;
730 cifs_std_info_to_fattr(&fattr, (FIND_FILE_STANDARD_INFO *) 661 case SMB_FIND_FILE_INFO_STANDARD:
731 pfindEntry, cifs_sb); 662 cifs_std_info_to_fattr(&fattr,
732 else 663 (FIND_FILE_STANDARD_INFO *)find_entry,
733 cifs_dir_info_to_fattr(&fattr, (FILE_DIRECTORY_INFO *) 664 cifs_sb);
734 pfindEntry, cifs_sb); 665 break;
666 default:
667 cifs_dir_info_to_fattr(&fattr,
668 (FILE_DIRECTORY_INFO *)find_entry,
669 cifs_sb);
670 break;
671 }
735 672
736 if (inum && (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)) { 673 if (de.ino && (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)) {
737 fattr.cf_uniqueid = inum; 674 fattr.cf_uniqueid = de.ino;
738 } else { 675 } else {
739 fattr.cf_uniqueid = iunique(sb, ROOT_I); 676 fattr.cf_uniqueid = iunique(sb, ROOT_I);
740 cifs_autodisable_serverino(cifs_sb); 677 cifs_autodisable_serverino(cifs_sb);
@@ -750,12 +687,12 @@ static int cifs_filldir(char *pfindEntry, struct file *file, filldir_t filldir,
750 fattr.cf_flags |= CIFS_FATTR_NEED_REVAL; 687 fattr.cf_flags |= CIFS_FATTR_NEED_REVAL;
751 688
752 ino = cifs_uniqueid_to_ino_t(fattr.cf_uniqueid); 689 ino = cifs_uniqueid_to_ino_t(fattr.cf_uniqueid);
753 tmp_dentry = cifs_readdir_lookup(file->f_dentry, &qstring, &fattr); 690 dentry = cifs_readdir_lookup(file->f_dentry, &name, &fattr);
754 691
755 rc = filldir(direntry, qstring.name, qstring.len, file->f_pos, 692 rc = filldir(dirent, name.name, name.len, file->f_pos, ino,
756 ino, fattr.cf_dtype); 693 fattr.cf_dtype);
757 694
758 dput(tmp_dentry); 695 dput(dentry);
759 return rc; 696 return rc;
760} 697}
761 698
diff --git a/fs/cifs/smbencrypt.c b/fs/cifs/smbencrypt.c
index 1c5b770c3141..42b9fff48751 100644
--- a/fs/cifs/smbencrypt.c
+++ b/fs/cifs/smbencrypt.c
@@ -157,8 +157,14 @@ mdfour(unsigned char *md4_hash, unsigned char *link_str, int link_len)
157 cERROR(1, "%s: Could not init md4 shash\n", __func__); 157 cERROR(1, "%s: Could not init md4 shash\n", __func__);
158 goto mdfour_err; 158 goto mdfour_err;
159 } 159 }
160 crypto_shash_update(&sdescmd4->shash, link_str, link_len); 160 rc = crypto_shash_update(&sdescmd4->shash, link_str, link_len);
161 if (rc) {
162 cERROR(1, "%s: Could not update with link_str\n", __func__);
163 goto mdfour_err;
164 }
161 rc = crypto_shash_final(&sdescmd4->shash, md4_hash); 165 rc = crypto_shash_final(&sdescmd4->shash, md4_hash);
166 if (rc)
167 cERROR(1, "%s: Could not genereate md4 hash\n", __func__);
162 168
163mdfour_err: 169mdfour_err:
164 crypto_free_shash(md4); 170 crypto_free_shash(md4);
diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c
index 147aa22c3c3a..10ca6b2c26b7 100644
--- a/fs/cifs/transport.c
+++ b/fs/cifs/transport.c
@@ -266,15 +266,11 @@ static int wait_for_free_request(struct TCP_Server_Info *server,
266 while (1) { 266 while (1) {
267 if (atomic_read(&server->inFlight) >= cifs_max_pending) { 267 if (atomic_read(&server->inFlight) >= cifs_max_pending) {
268 spin_unlock(&GlobalMid_Lock); 268 spin_unlock(&GlobalMid_Lock);
269#ifdef CONFIG_CIFS_STATS2 269 cifs_num_waiters_inc(server);
270 atomic_inc(&server->num_waiters);
271#endif
272 wait_event(server->request_q, 270 wait_event(server->request_q,
273 atomic_read(&server->inFlight) 271 atomic_read(&server->inFlight)
274 < cifs_max_pending); 272 < cifs_max_pending);
275#ifdef CONFIG_CIFS_STATS2 273 cifs_num_waiters_dec(server);
276 atomic_dec(&server->num_waiters);
277#endif
278 spin_lock(&GlobalMid_Lock); 274 spin_lock(&GlobalMid_Lock);
279 } else { 275 } else {
280 if (server->tcpStatus == CifsExiting) { 276 if (server->tcpStatus == CifsExiting) {
@@ -362,6 +358,8 @@ cifs_call_async(struct TCP_Server_Info *server, struct kvec *iov,
362 mid = AllocMidQEntry(hdr, server); 358 mid = AllocMidQEntry(hdr, server);
363 if (mid == NULL) { 359 if (mid == NULL) {
364 mutex_unlock(&server->srv_mutex); 360 mutex_unlock(&server->srv_mutex);
361 atomic_dec(&server->inFlight);
362 wake_up(&server->request_q);
365 return -ENOMEM; 363 return -ENOMEM;
366 } 364 }
367 365
@@ -379,15 +377,13 @@ cifs_call_async(struct TCP_Server_Info *server, struct kvec *iov,
379 mid->callback = callback; 377 mid->callback = callback;
380 mid->callback_data = cbdata; 378 mid->callback_data = cbdata;
381 mid->midState = MID_REQUEST_SUBMITTED; 379 mid->midState = MID_REQUEST_SUBMITTED;
382#ifdef CONFIG_CIFS_STATS2 380
383 atomic_inc(&server->inSend); 381 cifs_in_send_inc(server);
384#endif
385 rc = smb_sendv(server, iov, nvec); 382 rc = smb_sendv(server, iov, nvec);
386#ifdef CONFIG_CIFS_STATS2 383 cifs_in_send_dec(server);
387 atomic_dec(&server->inSend); 384 cifs_save_when_sent(mid);
388 mid->when_sent = jiffies;
389#endif
390 mutex_unlock(&server->srv_mutex); 385 mutex_unlock(&server->srv_mutex);
386
391 if (rc) 387 if (rc)
392 goto out_err; 388 goto out_err;
393 389
@@ -573,14 +569,10 @@ SendReceive2(const unsigned int xid, struct cifs_ses *ses,
573 } 569 }
574 570
575 midQ->midState = MID_REQUEST_SUBMITTED; 571 midQ->midState = MID_REQUEST_SUBMITTED;
576#ifdef CONFIG_CIFS_STATS2 572 cifs_in_send_inc(ses->server);
577 atomic_inc(&ses->server->inSend);
578#endif
579 rc = smb_sendv(ses->server, iov, n_vec); 573 rc = smb_sendv(ses->server, iov, n_vec);
580#ifdef CONFIG_CIFS_STATS2 574 cifs_in_send_dec(ses->server);
581 atomic_dec(&ses->server->inSend); 575 cifs_save_when_sent(midQ);
582 midQ->when_sent = jiffies;
583#endif
584 576
585 mutex_unlock(&ses->server->srv_mutex); 577 mutex_unlock(&ses->server->srv_mutex);
586 578
@@ -701,14 +693,11 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses,
701 } 693 }
702 694
703 midQ->midState = MID_REQUEST_SUBMITTED; 695 midQ->midState = MID_REQUEST_SUBMITTED;
704#ifdef CONFIG_CIFS_STATS2 696
705 atomic_inc(&ses->server->inSend); 697 cifs_in_send_inc(ses->server);
706#endif
707 rc = smb_send(ses->server, in_buf, be32_to_cpu(in_buf->smb_buf_length)); 698 rc = smb_send(ses->server, in_buf, be32_to_cpu(in_buf->smb_buf_length));
708#ifdef CONFIG_CIFS_STATS2 699 cifs_in_send_dec(ses->server);
709 atomic_dec(&ses->server->inSend); 700 cifs_save_when_sent(midQ);
710 midQ->when_sent = jiffies;
711#endif
712 mutex_unlock(&ses->server->srv_mutex); 701 mutex_unlock(&ses->server->srv_mutex);
713 702
714 if (rc < 0) 703 if (rc < 0)
@@ -841,14 +830,10 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon,
841 } 830 }
842 831
843 midQ->midState = MID_REQUEST_SUBMITTED; 832 midQ->midState = MID_REQUEST_SUBMITTED;
844#ifdef CONFIG_CIFS_STATS2 833 cifs_in_send_inc(ses->server);
845 atomic_inc(&ses->server->inSend);
846#endif
847 rc = smb_send(ses->server, in_buf, be32_to_cpu(in_buf->smb_buf_length)); 834 rc = smb_send(ses->server, in_buf, be32_to_cpu(in_buf->smb_buf_length));
848#ifdef CONFIG_CIFS_STATS2 835 cifs_in_send_dec(ses->server);
849 atomic_dec(&ses->server->inSend); 836 cifs_save_when_sent(midQ);
850 midQ->when_sent = jiffies;
851#endif
852 mutex_unlock(&ses->server->srv_mutex); 837 mutex_unlock(&ses->server->srv_mutex);
853 838
854 if (rc < 0) { 839 if (rc < 0) {