Revert "cifs: reconnect work should have reference on server struct"
Subsystems (2)
PATCH 1/3 Revert "cifs: reconnect work should have reference on server struct"
From: Shyam Prasad N <[email protected]>
This reverts commit 19a4b9d6c372cab6a3b2c9a061a236136fe95274.
This earlier commit was making an assumption that each mod_delayed_work called for the reconnect work would result in smb2_reconnect_server being called twice. This assumption turns out to be untrue. So reverting this change for now.
I will submit a follow-up patch to fix the actual problem in a different way.
--- fs/smb/client/connect.c | 27 ++++++--------------------- fs/smb/client/smb2pdu.c | 23 ++++++++++------------- 2 files changed, 16 insertions(+), 34 deletions(-)
fs/smb/client/connect.c +6 -21
@@ -402,13 +402,7 @@ static int __cifs_reconnect(struct TCP_Server_Info *server,spin_unlock (&server->srv_lock);cifs_swn_reset_server_dstaddr (server);cifs_server_unlock (server); - -/* increase ref count which reconnect work will drop */ -spin_lock (&cifs_tcp_ses_lock); - server->srv_count++; -spin_unlock (&cifs_tcp_ses_lock); -if (mod_delayed_work (cifsiod_wq, &server->reconnect,0 )) -cifs_put_tcp_session (server, false); +mod_delayed_work (cifsiod_wq, &server->reconnect,0 ); } }while (server->tcpStatus == CifsNeedReconnect);
@@ -538,13 +532,7 @@ static int reconnect_dfs_server(struct TCP_Server_Info *server)spin_unlock (&server->srv_lock);cifs_swn_reset_server_dstaddr (server);cifs_server_unlock (server); - -/* increase ref count which reconnect work will drop */ -spin_lock (&cifs_tcp_ses_lock); - server->srv_count++; -spin_unlock (&cifs_tcp_ses_lock); -if (mod_delayed_work (cifsiod_wq, &server->reconnect,0 )) -cifs_put_tcp_session (server, false); +mod_delayed_work (cifsiod_wq, &server->reconnect,0 ); }while (server->tcpStatus == CifsNeedReconnect);mutex_lock (&server->refpath_lock);
@@ -1626,19 +1614,16 @@ cifs_put_tcp_session(struct TCP_Server_Info *server, int from_reconnect)cancel_delayed_work_sync (&server->echo); -if (from_reconnect) { +if (from_reconnect)/* * Avoid deadlock here: reconnect work calls * cifs_put_tcp_session() at its end. Need to be sure * that reconnect work does nothing with server pointer after * that step. */ -if (cancel_delayed_work (&server->reconnect)) -cifs_put_tcp_session (server, from_reconnect); - }else { -if (cancel_delayed_work_sync (&server->reconnect)) -cifs_put_tcp_session (server, from_reconnect); - } +cancel_delayed_work (&server->reconnect); +else +cancel_delayed_work_sync (&server->reconnect);spin_lock (&server->srv_lock); server->tcpStatus = CifsExiting;
fs/smb/client/smb2pdu.c +10 -13
@@ -3954,6 +3954,12 @@ void smb2_reconnect_server(struct work_struct *work) }spin_unlock (&ses->chan_lock); } +/* +* Get the reference to server struct to be sure that the last call of +* cifs_put_tcon() in the loop below won't release the server pointer. +*/ +if (tcon_exist || ses_exist) + server->srv_count++;spin_unlock (&cifs_tcp_ses_lock);
@@ -4001,17 +4007,13 @@ void smb2_reconnect_server(struct work_struct *work) done:cifs_dbg (FYI ,"Reconnecting tcons and channels finished\n" ); -if (resched) { +if (resched)queue_delayed_work (cifsiod_wq, &server->reconnect,2 *HZ ); -mutex_unlock (&pserver->reconnect_mutex); - -/* no need to put tcp session as we're retrying */ -return ; - }mutex_unlock (&pserver->reconnect_mutex);/* now we can safely release srv struct */ -cifs_put_tcp_session (server, true); +if (tcon_exist || ses_exist) +cifs_put_tcp_session (server,1 ); }int
@@ -4031,12 +4033,7 @@ SMB2_echo(struct TCP_Server_Info *server) server->ops->need_neg(server)) {spin_unlock (&server->srv_lock);/* No need to send echo on newly established connections */ -spin_lock (&cifs_tcp_ses_lock); - server->srv_count++; -spin_unlock (&cifs_tcp_ses_lock); -if (mod_delayed_work (cifsiod_wq, &server->reconnect,0 )) -cifs_put_tcp_session (server, false); - +mod_delayed_work (cifsiod_wq, &server->reconnect,0 );return rc; }spin_unlock (&server->srv_lock);
Signature · 1 line
2.34.1
PATCH 2/3 cifs: reconnect worker should take reference on server struct unconditionally
From: Shyam Prasad N <[email protected]>
Reconnect worker currently assumes that the server struct is alive and only takes reference on the server if it needs to call smb2_reconnect.
With the new ability to disable channels based on whether the server has multichannel disabled, this becomes a problem when we need to disable established channels. While disabling the channels and deallocating the server, there could be reconnect work that could not be cancelled (because it started).
This change forces the reconnect worker to unconditionally take a reference on the server when it runs.
Also, this change now allows smb2_reconnect to know if it was called by the reconnect worker. Based on this, the cifs_put_tcp_session can decide whether it can cancel the reconnect work synchronously or not.
--- fs/smb/client/connect.c | 8 ++++---- fs/smb/client/smb2pdu.c | 29 +++++++++++++++-------------- 2 files changed, 19 insertions(+), 18 deletions(-)
fs/smb/client/connect.c +4 -4
@@ -1608,10 +1608,6 @@ cifs_put_tcp_session(struct TCP_Server_Info *server, int from_reconnect)list_del_init (&server->tcp_ses_list);spin_unlock (&cifs_tcp_ses_lock); -/* For secondary channels, we pick up ref-count on the primary server */ -if (SERVER_IS_CHAN (server)) -cifs_put_tcp_session (server->primary_server, from_reconnect); -cancel_delayed_work_sync (&server->echo);if (from_reconnect)
@@ -1625,6 +1621,10 @@ cifs_put_tcp_session(struct TCP_Server_Info *server, int from_reconnect)else cancel_delayed_work_sync (&server->reconnect); +/* For secondary channels, we pick up ref-count on the primary server */ +if (SERVER_IS_CHAN (server)) +cifs_put_tcp_session (server->primary_server, from_reconnect); +spin_lock (&server->srv_lock); server->tcpStatus = CifsExiting;spin_unlock (&server->srv_lock);
fs/smb/client/smb2pdu.c +15 -14
@@ -158,7 +158,7 @@ smb2_hdr_assemble(struct smb2_hdr *shdr, __le16 smb2_cmd,static int smb2_reconnect (__le16 smb2_command,struct cifs_tcon *tcon, -struct TCP_Server_Info *server) +struct TCP_Server_Info *server,bool from_reconnect) {int rc =0 ;struct nls_table *nls_codepage =NULL ;
@@ -331,7 +331,7 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,* as cifs_put_tcp_session takes a higher lock * i.e. cifs_tcp_ses_lock */ -cifs_put_tcp_session (server,1 ); +cifs_put_tcp_session (server, from_reconnect); server->terminate = true;cifs_signal_cifsd_for_reconnect (server, false);
@@ -499,7 +499,7 @@ static int smb2_plain_req_init(__le16 smb2_command, struct cifs_tcon *tcon, {int rc; - rc =smb2_reconnect (smb2_command, tcon, server); + rc =smb2_reconnect (smb2_command, tcon, server, false);if (rc)return rc;
@@ -3897,6 +3897,15 @@ void smb2_reconnect_server(struct work_struct *work)int rc;bool resched = false; +/* first check if ref count has reached 0, if not inc ref count */ +spin_lock (&cifs_tcp_ses_lock); +if (!server->srv_count) { +spin_unlock (&cifs_tcp_ses_lock); +return ; + } + server->srv_count++; +spin_unlock (&cifs_tcp_ses_lock); +/* If server is a channel, select the primary channel */ pserver =SERVER_IS_CHAN (server) ? server->primary_server : server;
@@ -3954,17 +3963,10 @@ void smb2_reconnect_server(struct work_struct *work) }spin_unlock (&ses->chan_lock); } -/* -* Get the reference to server struct to be sure that the last call of -* cifs_put_tcon() in the loop below won't release the server pointer. -*/ -if (tcon_exist || ses_exist) - server->srv_count++; -spin_unlock (&cifs_tcp_ses_lock);list_for_each_entry_safe (tcon, tcon2, &tmp_list, rlist) { - rc =smb2_reconnect (SMB2_INTERNAL_CMD , tcon, server); + rc =smb2_reconnect (SMB2_INTERNAL_CMD , tcon, server, true);if (!rc)cifs_reopen_persistent_handles (tcon);else
@@ -3997,7 +3999,7 @@ void smb2_reconnect_server(struct work_struct *work)/* now reconnect sessions for necessary channels */ list_for_each_entry_safe (ses, ses2, &tmp_ses_list, rlist) { tcon->ses = ses; - rc =smb2_reconnect (SMB2_INTERNAL_CMD , tcon, server); + rc =smb2_reconnect (SMB2_INTERNAL_CMD , tcon, server, true);if (rc) resched = true;list_del_init (&ses->rlist);
@@ -4012,8 +4014,7 @@ void smb2_reconnect_server(struct work_struct *work)mutex_unlock (&pserver->reconnect_mutex);/* now we can safely release srv struct */ -if (tcon_exist || ses_exist) -cifs_put_tcp_session (server,1 ); +cifs_put_tcp_session (server, true); }int
Signature · 1 line
2.34.1