Commit 3b795210 authored by Steve French's avatar Steve French

[CIFS] Fix cifs reconnection flags

In preparation for Jeff's big umount/mount fixes to remove the possibility of
various races in cifs mount and linked list handling of sessions, sockets and
tree connections, this patch cleans up some repetitive code in cifs_mount,
and addresses a problem with ses->status and tcon->tidStatus in which we
were overloading the "need_reconnect" state with other status in that
field.  So the "need_reconnect" flag has been broken out from those
two state fields (need reconnect was not mutually exclusive from some of the
other possible tid and ses states).  In addition, a few exit cases in
cifs_mount were cleaned up, and a problem with a tcon flag (for lease support)
was not being set consistently for the 2nd mount of the same share

CC: Jeff Layton <jlayton@redhat.com>
CC: Shirish Pargaonkar <shirishp@us.ibm.com>
Signed-off-by: default avatarSteve French <sfrench@us.ibm.com>
parent c527c8a7
...@@ -1013,7 +1013,7 @@ static int cifs_oplock_thread(void *dummyarg) ...@@ -1013,7 +1013,7 @@ static int cifs_oplock_thread(void *dummyarg)
not bother sending an oplock release if session not bother sending an oplock release if session
to server still is disconnected since oplock to server still is disconnected since oplock
already released by the server in that case */ already released by the server in that case */
if (pTcon->tidStatus != CifsNeedReconnect) { if (!pTcon->need_reconnect) {
rc = CIFSSMBLock(0, pTcon, netfid, rc = CIFSSMBLock(0, pTcon, netfid,
0 /* len */ , 0 /* offset */, 0, 0 /* len */ , 0 /* offset */, 0,
0, LOCKING_ANDX_OPLOCK_RELEASE, 0, LOCKING_ANDX_OPLOCK_RELEASE,
......
...@@ -122,6 +122,8 @@ struct cifs_cred { ...@@ -122,6 +122,8 @@ struct cifs_cred {
*/ */
struct TCP_Server_Info { struct TCP_Server_Info {
struct list_head tcp_ses_list;
struct list_head smb_ses_list;
/* 15 character server name + 0x20 16th byte indicating type = srv */ /* 15 character server name + 0x20 16th byte indicating type = srv */
char server_RFC1001_name[SERVER_NAME_LEN_WITH_NULL]; char server_RFC1001_name[SERVER_NAME_LEN_WITH_NULL];
char unicode_server_Name[SERVER_NAME_LEN_WITH_NULL * 2]; char unicode_server_Name[SERVER_NAME_LEN_WITH_NULL * 2];
...@@ -195,6 +197,7 @@ struct cifsUidInfo { ...@@ -195,6 +197,7 @@ struct cifsUidInfo {
*/ */
struct cifsSesInfo { struct cifsSesInfo {
struct list_head cifsSessionList; struct list_head cifsSessionList;
struct list_head tcon_list;
struct semaphore sesSem; struct semaphore sesSem;
#if 0 #if 0
struct cifsUidInfo *uidInfo; /* pointer to user info */ struct cifsUidInfo *uidInfo; /* pointer to user info */
...@@ -216,6 +219,7 @@ struct cifsSesInfo { ...@@ -216,6 +219,7 @@ struct cifsSesInfo {
char userName[MAX_USERNAME_SIZE + 1]; char userName[MAX_USERNAME_SIZE + 1];
char *domainName; char *domainName;
char *password; char *password;
bool need_reconnect:1; /* connection reset, uid now invalid */
}; };
/* no more than one of the following three session flags may be set */ /* no more than one of the following three session flags may be set */
#define CIFS_SES_NT4 1 #define CIFS_SES_NT4 1
...@@ -288,6 +292,7 @@ struct cifsTconInfo { ...@@ -288,6 +292,7 @@ struct cifsTconInfo {
bool unix_ext:1; /* if false disable Linux extensions to CIFS protocol bool unix_ext:1; /* if false disable Linux extensions to CIFS protocol
for this mount even if server would support */ for this mount even if server would support */
bool local_lease:1; /* check leases (only) on local system not remote */ bool local_lease:1; /* check leases (only) on local system not remote */
bool need_reconnect:1; /* connection reset, tid now invalid */
/* BB add field for back pointer to sb struct(s)? */ /* BB add field for back pointer to sb struct(s)? */
}; };
......
...@@ -190,10 +190,10 @@ small_smb_init(int smb_command, int wct, struct cifsTconInfo *tcon, ...@@ -190,10 +190,10 @@ small_smb_init(int smb_command, int wct, struct cifsTconInfo *tcon,
/* need to prevent multiple threads trying to /* need to prevent multiple threads trying to
simultaneously reconnect the same SMB session */ simultaneously reconnect the same SMB session */
down(&tcon->ses->sesSem); down(&tcon->ses->sesSem);
if (tcon->ses->status == CifsNeedReconnect) if (tcon->ses->need_reconnect)
rc = cifs_setup_session(0, tcon->ses, rc = cifs_setup_session(0, tcon->ses,
nls_codepage); nls_codepage);
if (!rc && (tcon->tidStatus == CifsNeedReconnect)) { if (!rc && (tcon->need_reconnect)) {
mark_open_files_invalid(tcon); mark_open_files_invalid(tcon);
rc = CIFSTCon(0, tcon->ses, tcon->treeName, rc = CIFSTCon(0, tcon->ses, tcon->treeName,
tcon, nls_codepage); tcon, nls_codepage);
...@@ -295,7 +295,7 @@ smb_init(int smb_command, int wct, struct cifsTconInfo *tcon, ...@@ -295,7 +295,7 @@ smb_init(int smb_command, int wct, struct cifsTconInfo *tcon,
check for tcp and smb session status done differently check for tcp and smb session status done differently
for those three - in the calling routine */ for those three - in the calling routine */
if (tcon) { if (tcon) {
if (tcon->tidStatus == CifsExiting) { if (tcon->need_reconnect) {
/* only tree disconnect, open, and write, /* only tree disconnect, open, and write,
(and ulogoff which does not have tcon) (and ulogoff which does not have tcon)
are allowed as we start force umount */ are allowed as we start force umount */
...@@ -337,10 +337,10 @@ smb_init(int smb_command, int wct, struct cifsTconInfo *tcon, ...@@ -337,10 +337,10 @@ smb_init(int smb_command, int wct, struct cifsTconInfo *tcon,
/* need to prevent multiple threads trying to /* need to prevent multiple threads trying to
simultaneously reconnect the same SMB session */ simultaneously reconnect the same SMB session */
down(&tcon->ses->sesSem); down(&tcon->ses->sesSem);
if (tcon->ses->status == CifsNeedReconnect) if (tcon->ses->need_reconnect)
rc = cifs_setup_session(0, tcon->ses, rc = cifs_setup_session(0, tcon->ses,
nls_codepage); nls_codepage);
if (!rc && (tcon->tidStatus == CifsNeedReconnect)) { if (!rc && (tcon->need_reconnect)) {
mark_open_files_invalid(tcon); mark_open_files_invalid(tcon);
rc = CIFSTCon(0, tcon->ses, tcon->treeName, rc = CIFSTCon(0, tcon->ses, tcon->treeName,
tcon, nls_codepage); tcon, nls_codepage);
...@@ -759,7 +759,7 @@ CIFSSMBTDis(const int xid, struct cifsTconInfo *tcon) ...@@ -759,7 +759,7 @@ CIFSSMBTDis(const int xid, struct cifsTconInfo *tcon)
/* No need to return error on this operation if tid invalidated and /* No need to return error on this operation if tid invalidated and
closed on server already e.g. due to tcp session crashing */ closed on server already e.g. due to tcp session crashing */
if (tcon->tidStatus == CifsNeedReconnect) { if (tcon->need_reconnect) {
up(&tcon->tconSem); up(&tcon->tconSem);
return 0; return 0;
} }
...@@ -806,32 +806,36 @@ CIFSSMBLogoff(const int xid, struct cifsSesInfo *ses) ...@@ -806,32 +806,36 @@ CIFSSMBLogoff(const int xid, struct cifsSesInfo *ses)
up(&ses->sesSem); up(&ses->sesSem);
return -EBUSY; return -EBUSY;
} }
if (ses->server == NULL)
return -EIO;
if (ses->need_reconnect)
goto session_already_dead; /* no need to send SMBlogoff if uid
already closed due to reconnect */
rc = small_smb_init(SMB_COM_LOGOFF_ANDX, 2, NULL, (void **)&pSMB); rc = small_smb_init(SMB_COM_LOGOFF_ANDX, 2, NULL, (void **)&pSMB);
if (rc) { if (rc) {
up(&ses->sesSem); up(&ses->sesSem);
return rc; return rc;
} }
if (ses->server) { pSMB->hdr.Mid = GetNextMid(ses->server);
pSMB->hdr.Mid = GetNextMid(ses->server);
if (ses->server->secMode & if (ses->server->secMode &
(SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE;
}
pSMB->hdr.Uid = ses->Suid; pSMB->hdr.Uid = ses->Suid;
pSMB->AndXCommand = 0xFF; pSMB->AndXCommand = 0xFF;
rc = SendReceiveNoRsp(xid, ses, (struct smb_hdr *) pSMB, 0); rc = SendReceiveNoRsp(xid, ses, (struct smb_hdr *) pSMB, 0);
if (ses->server) { session_already_dead:
atomic_dec(&ses->server->socketUseCount); atomic_dec(&ses->server->socketUseCount);
if (atomic_read(&ses->server->socketUseCount) == 0) { if (atomic_read(&ses->server->socketUseCount) == 0) {
spin_lock(&GlobalMid_Lock); spin_lock(&GlobalMid_Lock);
ses->server->tcpStatus = CifsExiting; ses->server->tcpStatus = CifsExiting;
spin_unlock(&GlobalMid_Lock); spin_unlock(&GlobalMid_Lock);
rc = -ESHUTDOWN; rc = -ESHUTDOWN;
}
} }
up(&ses->sesSem); up(&ses->sesSem);
......
This diff is collapsed.
...@@ -493,7 +493,7 @@ int cifs_close(struct inode *inode, struct file *file) ...@@ -493,7 +493,7 @@ int cifs_close(struct inode *inode, struct file *file)
if (pTcon) { if (pTcon) {
/* no sense reconnecting to close a file that is /* no sense reconnecting to close a file that is
already closed */ already closed */
if (pTcon->tidStatus != CifsNeedReconnect) { if (!pTcon->need_reconnect) {
timeout = 2; timeout = 2;
while ((atomic_read(&pSMBFile->wrtPending) != 0) while ((atomic_read(&pSMBFile->wrtPending) != 0)
&& (timeout <= 2048)) { && (timeout <= 2048)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment