diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2008-11-17 23:53:31 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-11-17 23:53:31 -0500 |
commit | 4e14e833ac3b97a4aa8803eea49f899adc5bb5f4 (patch) | |
tree | dd052898b27acff7f1e7d1cc41c98a17d6b9f0f1 /fs/cifs/cifssmb.c | |
parent | 65ecc14a30ad21bed9aabdfd6a2ae1a1aaaa6a00 (diff) | |
parent | b066a48c9532243894f93a06ca5a0ee2cc21a8dc (diff) |
Merge git://git.kernel.org/pub/scm/linux/kernel/git/sfrench/cifs-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/sfrench/cifs-2.6:
prevent cifs_writepages() from skipping unwritten pages
Fixed parsing of mount options when doing DFS submount
[CIFS] Fix check for tcon seal setting and fix oops on failed mount from earlier patch
[CIFS] Fix build break
cifs: reinstate sharing of tree connections
[CIFS] minor cleanup to cifs_mount
cifs: reinstate sharing of SMB sessions sans races
cifs: disable sharing session and tcon and add new TCP sharing code
[CIFS] clean up server protocol handling
[CIFS] remove unused list, add new cifs sock list to prepare for mount/umount fix
[CIFS] Fix cifs reconnection flags
[CIFS] Can't rely on iov length and base when kernel_recvmsg returns error
Diffstat (limited to 'fs/cifs/cifssmb.c')
-rw-r--r-- | fs/cifs/cifssmb.c | 136 |
1 files changed, 73 insertions, 63 deletions
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c index d5eac48fc415..bdda46dd435a 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c | |||
@@ -190,10 +190,10 @@ small_smb_init(int smb_command, int wct, struct cifsTconInfo *tcon, | |||
190 | /* need to prevent multiple threads trying to | 190 | /* need to prevent multiple threads trying to |
191 | simultaneously reconnect the same SMB session */ | 191 | simultaneously reconnect the same SMB session */ |
192 | down(&tcon->ses->sesSem); | 192 | down(&tcon->ses->sesSem); |
193 | if (tcon->ses->status == CifsNeedReconnect) | 193 | if (tcon->ses->need_reconnect) |
194 | rc = cifs_setup_session(0, tcon->ses, | 194 | rc = cifs_setup_session(0, tcon->ses, |
195 | nls_codepage); | 195 | nls_codepage); |
196 | if (!rc && (tcon->tidStatus == CifsNeedReconnect)) { | 196 | if (!rc && (tcon->need_reconnect)) { |
197 | mark_open_files_invalid(tcon); | 197 | mark_open_files_invalid(tcon); |
198 | rc = CIFSTCon(0, tcon->ses, tcon->treeName, | 198 | rc = CIFSTCon(0, tcon->ses, tcon->treeName, |
199 | tcon, nls_codepage); | 199 | tcon, nls_codepage); |
@@ -295,7 +295,7 @@ smb_init(int smb_command, int wct, struct cifsTconInfo *tcon, | |||
295 | check for tcp and smb session status done differently | 295 | check for tcp and smb session status done differently |
296 | for those three - in the calling routine */ | 296 | for those three - in the calling routine */ |
297 | if (tcon) { | 297 | if (tcon) { |
298 | if (tcon->tidStatus == CifsExiting) { | 298 | if (tcon->need_reconnect) { |
299 | /* only tree disconnect, open, and write, | 299 | /* only tree disconnect, open, and write, |
300 | (and ulogoff which does not have tcon) | 300 | (and ulogoff which does not have tcon) |
301 | are allowed as we start force umount */ | 301 | are allowed as we start force umount */ |
@@ -337,10 +337,10 @@ smb_init(int smb_command, int wct, struct cifsTconInfo *tcon, | |||
337 | /* need to prevent multiple threads trying to | 337 | /* need to prevent multiple threads trying to |
338 | simultaneously reconnect the same SMB session */ | 338 | simultaneously reconnect the same SMB session */ |
339 | down(&tcon->ses->sesSem); | 339 | down(&tcon->ses->sesSem); |
340 | if (tcon->ses->status == CifsNeedReconnect) | 340 | if (tcon->ses->need_reconnect) |
341 | rc = cifs_setup_session(0, tcon->ses, | 341 | rc = cifs_setup_session(0, tcon->ses, |
342 | nls_codepage); | 342 | nls_codepage); |
343 | if (!rc && (tcon->tidStatus == CifsNeedReconnect)) { | 343 | if (!rc && (tcon->need_reconnect)) { |
344 | mark_open_files_invalid(tcon); | 344 | mark_open_files_invalid(tcon); |
345 | rc = CIFSTCon(0, tcon->ses, tcon->treeName, | 345 | rc = CIFSTCon(0, tcon->ses, tcon->treeName, |
346 | tcon, nls_codepage); | 346 | tcon, nls_codepage); |
@@ -664,8 +664,9 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) | |||
664 | rc = -EIO; | 664 | rc = -EIO; |
665 | goto neg_err_exit; | 665 | goto neg_err_exit; |
666 | } | 666 | } |
667 | 667 | read_lock(&cifs_tcp_ses_lock); | |
668 | if (server->socketUseCount.counter > 1) { | 668 | if (server->srv_count > 1) { |
669 | read_unlock(&cifs_tcp_ses_lock); | ||
669 | if (memcmp(server->server_GUID, | 670 | if (memcmp(server->server_GUID, |
670 | pSMBr->u.extended_response. | 671 | pSMBr->u.extended_response. |
671 | GUID, 16) != 0) { | 672 | GUID, 16) != 0) { |
@@ -674,9 +675,11 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) | |||
674 | pSMBr->u.extended_response.GUID, | 675 | pSMBr->u.extended_response.GUID, |
675 | 16); | 676 | 16); |
676 | } | 677 | } |
677 | } else | 678 | } else { |
679 | read_unlock(&cifs_tcp_ses_lock); | ||
678 | memcpy(server->server_GUID, | 680 | memcpy(server->server_GUID, |
679 | pSMBr->u.extended_response.GUID, 16); | 681 | pSMBr->u.extended_response.GUID, 16); |
682 | } | ||
680 | 683 | ||
681 | if (count == 16) { | 684 | if (count == 16) { |
682 | server->secType = RawNTLMSSP; | 685 | server->secType = RawNTLMSSP; |
@@ -739,50 +742,31 @@ CIFSSMBTDis(const int xid, struct cifsTconInfo *tcon) | |||
739 | int rc = 0; | 742 | int rc = 0; |
740 | 743 | ||
741 | cFYI(1, ("In tree disconnect")); | 744 | cFYI(1, ("In tree disconnect")); |
742 | /* | ||
743 | * If last user of the connection and | ||
744 | * connection alive - disconnect it | ||
745 | * If this is the last connection on the server session disconnect it | ||
746 | * (and inside session disconnect we should check if tcp socket needs | ||
747 | * to be freed and kernel thread woken up). | ||
748 | */ | ||
749 | if (tcon) | ||
750 | down(&tcon->tconSem); | ||
751 | else | ||
752 | return -EIO; | ||
753 | 745 | ||
754 | atomic_dec(&tcon->useCount); | 746 | /* BB: do we need to check this? These should never be NULL. */ |
755 | if (atomic_read(&tcon->useCount) > 0) { | 747 | if ((tcon->ses == NULL) || (tcon->ses->server == NULL)) |
756 | up(&tcon->tconSem); | 748 | return -EIO; |
757 | return -EBUSY; | ||
758 | } | ||
759 | 749 | ||
760 | /* No need to return error on this operation if tid invalidated and | 750 | /* |
761 | closed on server already e.g. due to tcp session crashing */ | 751 | * No need to return error on this operation if tid invalidated and |
762 | if (tcon->tidStatus == CifsNeedReconnect) { | 752 | * closed on server already e.g. due to tcp session crashing. Also, |
763 | up(&tcon->tconSem); | 753 | * the tcon is no longer on the list, so no need to take lock before |
754 | * checking this. | ||
755 | */ | ||
756 | if (tcon->need_reconnect) | ||
764 | return 0; | 757 | return 0; |
765 | } | ||
766 | 758 | ||
767 | if ((tcon->ses == NULL) || (tcon->ses->server == NULL)) { | ||
768 | up(&tcon->tconSem); | ||
769 | return -EIO; | ||
770 | } | ||
771 | rc = small_smb_init(SMB_COM_TREE_DISCONNECT, 0, tcon, | 759 | rc = small_smb_init(SMB_COM_TREE_DISCONNECT, 0, tcon, |
772 | (void **)&smb_buffer); | 760 | (void **)&smb_buffer); |
773 | if (rc) { | 761 | if (rc) |
774 | up(&tcon->tconSem); | ||
775 | return rc; | 762 | return rc; |
776 | } | ||
777 | 763 | ||
778 | rc = SendReceiveNoRsp(xid, tcon->ses, smb_buffer, 0); | 764 | rc = SendReceiveNoRsp(xid, tcon->ses, smb_buffer, 0); |
779 | if (rc) | 765 | if (rc) |
780 | cFYI(1, ("Tree disconnect failed %d", rc)); | 766 | cFYI(1, ("Tree disconnect failed %d", rc)); |
781 | 767 | ||
782 | up(&tcon->tconSem); | ||
783 | |||
784 | /* No need to return error on this operation if tid invalidated and | 768 | /* No need to return error on this operation if tid invalidated and |
785 | closed on server already e.g. due to tcp session crashing */ | 769 | closed on server already e.g. due to tcp session crashing */ |
786 | if (rc == -EAGAIN) | 770 | if (rc == -EAGAIN) |
787 | rc = 0; | 771 | rc = 0; |
788 | 772 | ||
@@ -796,43 +780,36 @@ CIFSSMBLogoff(const int xid, struct cifsSesInfo *ses) | |||
796 | int rc = 0; | 780 | int rc = 0; |
797 | 781 | ||
798 | cFYI(1, ("In SMBLogoff for session disconnect")); | 782 | cFYI(1, ("In SMBLogoff for session disconnect")); |
799 | if (ses) | 783 | |
800 | down(&ses->sesSem); | 784 | /* |
801 | else | 785 | * BB: do we need to check validity of ses and server? They should |
786 | * always be valid since we have an active reference. If not, that | ||
787 | * should probably be a BUG() | ||
788 | */ | ||
789 | if (!ses || !ses->server) | ||
802 | return -EIO; | 790 | return -EIO; |
803 | 791 | ||
804 | atomic_dec(&ses->inUse); | 792 | down(&ses->sesSem); |
805 | if (atomic_read(&ses->inUse) > 0) { | 793 | if (ses->need_reconnect) |
806 | up(&ses->sesSem); | 794 | goto session_already_dead; /* no need to send SMBlogoff if uid |
807 | return -EBUSY; | 795 | already closed due to reconnect */ |
808 | } | ||
809 | rc = small_smb_init(SMB_COM_LOGOFF_ANDX, 2, NULL, (void **)&pSMB); | 796 | rc = small_smb_init(SMB_COM_LOGOFF_ANDX, 2, NULL, (void **)&pSMB); |
810 | if (rc) { | 797 | if (rc) { |
811 | up(&ses->sesSem); | 798 | up(&ses->sesSem); |
812 | return rc; | 799 | return rc; |
813 | } | 800 | } |
814 | 801 | ||
815 | if (ses->server) { | 802 | pSMB->hdr.Mid = GetNextMid(ses->server); |
816 | pSMB->hdr.Mid = GetNextMid(ses->server); | ||
817 | 803 | ||
818 | if (ses->server->secMode & | 804 | if (ses->server->secMode & |
819 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) | 805 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) |
820 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; | 806 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
821 | } | ||
822 | 807 | ||
823 | pSMB->hdr.Uid = ses->Suid; | 808 | pSMB->hdr.Uid = ses->Suid; |
824 | 809 | ||
825 | pSMB->AndXCommand = 0xFF; | 810 | pSMB->AndXCommand = 0xFF; |
826 | rc = SendReceiveNoRsp(xid, ses, (struct smb_hdr *) pSMB, 0); | 811 | rc = SendReceiveNoRsp(xid, ses, (struct smb_hdr *) pSMB, 0); |
827 | if (ses->server) { | 812 | session_already_dead: |
828 | atomic_dec(&ses->server->socketUseCount); | ||
829 | if (atomic_read(&ses->server->socketUseCount) == 0) { | ||
830 | spin_lock(&GlobalMid_Lock); | ||
831 | ses->server->tcpStatus = CifsExiting; | ||
832 | spin_unlock(&GlobalMid_Lock); | ||
833 | rc = -ESHUTDOWN; | ||
834 | } | ||
835 | } | ||
836 | up(&ses->sesSem); | 813 | up(&ses->sesSem); |
837 | 814 | ||
838 | /* if session dead then we do not need to do ulogoff, | 815 | /* if session dead then we do not need to do ulogoff, |
@@ -3922,6 +3899,27 @@ GetInodeNumOut: | |||
3922 | return rc; | 3899 | return rc; |
3923 | } | 3900 | } |
3924 | 3901 | ||
3902 | /* computes length of UCS string converted to host codepage | ||
3903 | * @src: UCS string | ||
3904 | * @maxlen: length of the input string in UCS characters | ||
3905 | * (not in bytes) | ||
3906 | * | ||
3907 | * return: size of input string in host codepage | ||
3908 | */ | ||
3909 | static int hostlen_fromUCS(const __le16 *src, const int maxlen, | ||
3910 | const struct nls_table *nls_codepage) { | ||
3911 | int i; | ||
3912 | int hostlen = 0; | ||
3913 | char to[4]; | ||
3914 | int charlen; | ||
3915 | for (i = 0; (i < maxlen) && src[i]; ++i) { | ||
3916 | charlen = nls_codepage->uni2char(le16_to_cpu(src[i]), | ||
3917 | to, NLS_MAX_CHARSET_SIZE); | ||
3918 | hostlen += charlen > 0 ? charlen : 1; | ||
3919 | } | ||
3920 | return hostlen; | ||
3921 | } | ||
3922 | |||
3925 | /* parses DFS refferal V3 structure | 3923 | /* parses DFS refferal V3 structure |
3926 | * caller is responsible for freeing target_nodes | 3924 | * caller is responsible for freeing target_nodes |
3927 | * returns: | 3925 | * returns: |
@@ -3932,7 +3930,8 @@ static int | |||
3932 | parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr, | 3930 | parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr, |
3933 | unsigned int *num_of_nodes, | 3931 | unsigned int *num_of_nodes, |
3934 | struct dfs_info3_param **target_nodes, | 3932 | struct dfs_info3_param **target_nodes, |
3935 | const struct nls_table *nls_codepage) | 3933 | const struct nls_table *nls_codepage, int remap, |
3934 | const char *searchName) | ||
3936 | { | 3935 | { |
3937 | int i, rc = 0; | 3936 | int i, rc = 0; |
3938 | char *data_end; | 3937 | char *data_end; |
@@ -3983,7 +3982,17 @@ parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr, | |||
3983 | struct dfs_info3_param *node = (*target_nodes)+i; | 3982 | struct dfs_info3_param *node = (*target_nodes)+i; |
3984 | 3983 | ||
3985 | node->flags = le16_to_cpu(pSMBr->DFSFlags); | 3984 | node->flags = le16_to_cpu(pSMBr->DFSFlags); |
3986 | node->path_consumed = le16_to_cpu(pSMBr->PathConsumed); | 3985 | if (is_unicode) { |
3986 | __le16 *tmp = kmalloc(strlen(searchName)*2, GFP_KERNEL); | ||
3987 | cifsConvertToUCS((__le16 *) tmp, searchName, | ||
3988 | PATH_MAX, nls_codepage, remap); | ||
3989 | node->path_consumed = hostlen_fromUCS(tmp, | ||
3990 | le16_to_cpu(pSMBr->PathConsumed)/2, | ||
3991 | nls_codepage); | ||
3992 | kfree(tmp); | ||
3993 | } else | ||
3994 | node->path_consumed = le16_to_cpu(pSMBr->PathConsumed); | ||
3995 | |||
3987 | node->server_type = le16_to_cpu(ref->ServerType); | 3996 | node->server_type = le16_to_cpu(ref->ServerType); |
3988 | node->ref_flag = le16_to_cpu(ref->ReferralEntryFlags); | 3997 | node->ref_flag = le16_to_cpu(ref->ReferralEntryFlags); |
3989 | 3998 | ||
@@ -4116,7 +4125,8 @@ getDFSRetry: | |||
4116 | 4125 | ||
4117 | /* parse returned result into more usable form */ | 4126 | /* parse returned result into more usable form */ |
4118 | rc = parse_DFS_referrals(pSMBr, num_of_nodes, | 4127 | rc = parse_DFS_referrals(pSMBr, num_of_nodes, |
4119 | target_nodes, nls_codepage); | 4128 | target_nodes, nls_codepage, remap, |
4129 | searchName); | ||
4120 | 4130 | ||
4121 | GetDFSRefExit: | 4131 | GetDFSRefExit: |
4122 | cifs_buf_release(pSMB); | 4132 | cifs_buf_release(pSMB); |