cifs: get rid of cifs_mount_ctx::{origin,leaf}_fullpath
Subsystems (2)
PATCH 1/5 cifs: get rid of cifs_mount_ctx::{origin,leaf}_fullpath
leaf_fullpath is now part of smb3_fs_context structure, while origin_fullpath is just a variable in __dfs_mount_share() that is used when final tcon is available.
Get rid of those fields in cifs_mount_ctx structure and no-op kfree()'s.
--- fs/cifs/cifsglob.h | 1 - fs/cifs/connect.c | 2 -- 2 files changed, 3 deletions(-)
fs/cifs/cifsglob.h +0 -1
@@ -1750,7 +1750,6 @@ struct cifs_mount_ctx {struct TCP_Server_Info *server;struct cifs_ses *ses;struct cifs_tcon *tcon; -char *origin_fullpath, *leaf_fullpath;struct list_head dfs_ses_list; };
fs/cifs/connect.c +0 -2
@@ -3454,8 +3454,6 @@ int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx) error:dfs_put_root_smb_sessions (&mnt_ctx.dfs_ses_list); -kfree (mnt_ctx.origin_fullpath); -kfree (mnt_ctx.leaf_fullpath);cifs_mount_put_conns (&mnt_ctx);return rc; }
Signature · 1 line
2.40.0
PATCH 2/5 cifs: get rid of unnecessary ifdef
No need to ifdef around TCP_Server_Info::{origin,leaf}_fullpath as they're declared regardless CONFIG_CIFS_DFS_UPCALL.
--- fs/cifs/connect.c | 2 -- 1 file changed, 2 deletions(-)
fs/cifs/connect.c +0 -2
@@ -993,10 +993,8 @@ static void clean_demultiplex_info(struct TCP_Server_Info *server)*/ } -#ifdef CONFIG_CIFS_DFS_UPCALL kfree (server->origin_fullpath);kfree (server->leaf_fullpath); -#endif kfree (server); length =atomic_dec_return (&tcpSesAllocCount);
Signature · 1 line
2.40.0
ronnie sahlberg
reviewerRe: [PATCH 2/5] cifs: get rid of unnecessary ifdef
reviewed-by me
Quoted 27 lines · Paulo Alcantara
No need to ifdef around TCP_Server_Info::{origin,leaf}_fullpath as they're declared regardless
CONFIG_CIFS_DFS_UPCALL.Signed-off-by Paulo Alcantara (SUSE) <[email protected]>--- fs/cifs/connect.c | 2 -- 1 file changed, 2 deletions(-)fs/cifs/connect.c +0
-3@@ -993,10 +993,8 @@ static void clean_demultiplex_info(struct TCP_Server_Info *server)*/ } -#ifdef CONFIG_CIFS_DFS_UPCALL kfree (server->origin_fullpath);kfree (server->leaf_fullpath); -#endif kfree (server); length =atomic_dec_return (&tcpSesAllocCount); --2.40.0
PATCH 3/5 cifs: avoid races in parallel reconnects in smb1
In reply to Paulo AlcantaraPrevent multiple threads of doing negotiate, session setup and tree connect by holding @ses->session_mutex in cifs_reconnect_tcon() while reconnecting session and tcon.
--- fs/cifs/cifssmb.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
fs/cifs/cifssmb.c +15 -6
@@ -71,7 +71,7 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)int rc;struct cifs_ses *ses;struct TCP_Server_Info *server; -struct nls_table *nls_codepage; +struct nls_table *nls_codepage =NULL ;/* * SMBs NegProt, SessSetup, uLogoff do not have tcon yet so check for
@@ -99,6 +99,7 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) }spin_unlock (&tcon->tc_lock); +again: rc =cifs_wait_for_server_reconnect (server, tcon->retry);if (rc)return rc;
@@ -110,8 +111,7 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) }spin_unlock (&ses->chan_lock); - nls_codepage =load_nls_default (); - +mutex_lock (&ses->session_mutex);/* * Recheck after acquire mutex. If another thread is negotiating * and the server never sends an answer the socket will be closed
@@ -120,29 +120,38 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)spin_lock (&server->srv_lock);if (server->tcpStatus == CifsNeedReconnect) {spin_unlock (&server->srv_lock); +mutex_lock (&ses->session_mutex); + +if (tcon->retry) + goto again; rc = -EHOSTDOWN ; goto out; }spin_unlock (&server->srv_lock); + nls_codepage =load_nls_default (); +/* * need to prevent multiple threads trying to simultaneously * reconnect the same SMB session */ +spin_lock (&ses->ses_lock);spin_lock (&ses->chan_lock); -if (!cifs_chan_needs_reconnect (ses, server)) { +if (!cifs_chan_needs_reconnect (ses, server) && + ses->ses_status ==SES_GOOD ) {spin_unlock (&ses->chan_lock); +spin_unlock (&ses->ses_lock);/* this means that we only need to tree connect */ if (tcon->need_reconnect) goto skip_sess_setup; - rc = -EHOSTDOWN ; +mutex_unlock (&ses->session_mutex); goto out; }spin_unlock (&ses->chan_lock); +spin_unlock (&ses->ses_lock); -mutex_lock (&ses->session_mutex); rc =cifs_negotiate_protocol (0 , ses, server);if (!rc) rc =cifs_setup_session (0 , ses, server, nls_codepage);
Signature · 1 line
2.40.0
ronnie sahlberg
reviewerRe: [PATCH 3/5] cifs: avoid races in parallel reconnects in smb1
reviewed-by me
Quoted 86 lines · Paulo Alcantara
Prevent multiple threads of doing negotiate, session setup and tree connect by holding @ses->session_mutex in
cifs_reconnect_tcon()while reconnecting session and tcon.Signed-off-by Paulo Alcantara (SUSE) <[email protected]>--- fs/cifs/cifssmb.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)fs/cifs/cifssmb.c +15
-7@@ -71,7 +71,7 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)int rc;struct cifs_ses *ses;struct TCP_Server_Info *server; -struct nls_table *nls_codepage; +struct nls_table *nls_codepage =NULL ;/* * SMBs NegProt, SessSetup, uLogoff do not have tcon yet so check for @@ -99,6 +99,7 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) }spin_unlock (&tcon->tc_lock); +again: rc =cifs_wait_for_server_reconnect (server, tcon->retry);if (rc)return rc;@@ -110,8 +111,7 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) }spin_unlock (&ses->chan_lock); - nls_codepage =load_nls_default (); - +mutex_lock (&ses->session_mutex);/* * Recheck after acquire mutex. If another thread is negotiating * and the server never sends an answer the socket will be closed @@ -120,29 +120,38 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)spin_lock (&server->srv_lock);if (server->tcpStatus == CifsNeedReconnect) {spin_unlock (&server->srv_lock); +mutex_lock (&ses->session_mutex); + +if (tcon->retry) + goto again; rc = -EHOSTDOWN ; goto out; }spin_unlock (&server->srv_lock); + nls_codepage =load_nls_default (); +/* * need to prevent multiple threads trying to simultaneously * reconnect the same SMB session */ +spin_lock (&ses->ses_lock);spin_lock (&ses->chan_lock); -if (!cifs_chan_needs_reconnect (ses, server)) { +if (!cifs_chan_needs_reconnect (ses, server) && + ses->ses_status ==SES_GOOD ) {spin_unlock (&ses->chan_lock); +spin_unlock (&ses->ses_lock);/* this means that we only need to tree connect */ if (tcon->need_reconnect) goto skip_sess_setup; - rc = -EHOSTDOWN ; +mutex_unlock (&ses->session_mutex); goto out; }spin_unlock (&ses->chan_lock); +spin_unlock (&ses->ses_lock); -mutex_lock (&ses->session_mutex); rc =cifs_negotiate_protocol (0 , ses, server);if (!rc) rc =cifs_setup_session (0 , ses, server, nls_codepage); --2.40.0
Re: [PATCH 3/5] cifs: avoid races in parallel reconnects in smb1
In reply to Paulo Alcantaraadded ronnie's RB and merged into cifs-2.6.git for-next (I will hold off on patches 1 and 2 since they are cleanup until 6.4-rc)
Quoted 86 lines · Paulo Alcantara
Prevent multiple threads of doing negotiate, session setup and tree connect by holding @ses->session_mutex in
cifs_reconnect_tcon()while reconnecting session and tcon.Signed-off-by Paulo Alcantara (SUSE) <[email protected]>--- fs/cifs/cifssmb.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)fs/cifs/cifssmb.c +15
-7@@ -71,7 +71,7 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)int rc;struct cifs_ses *ses;struct TCP_Server_Info *server; -struct nls_table *nls_codepage; +struct nls_table *nls_codepage =NULL ;/* * SMBs NegProt, SessSetup, uLogoff do not have tcon yet so check for @@ -99,6 +99,7 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) }spin_unlock (&tcon->tc_lock); +again: rc =cifs_wait_for_server_reconnect (server, tcon->retry);if (rc)return rc;@@ -110,8 +111,7 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) }spin_unlock (&ses->chan_lock); - nls_codepage =load_nls_default (); - +mutex_lock (&ses->session_mutex);/* * Recheck after acquire mutex. If another thread is negotiating * and the server never sends an answer the socket will be closed @@ -120,29 +120,38 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)spin_lock (&server->srv_lock);if (server->tcpStatus == CifsNeedReconnect) {spin_unlock (&server->srv_lock); +mutex_lock (&ses->session_mutex); + +if (tcon->retry) + goto again; rc = -EHOSTDOWN ; goto out; }spin_unlock (&server->srv_lock); + nls_codepage =load_nls_default (); +/* * need to prevent multiple threads trying to simultaneously * reconnect the same SMB session */ +spin_lock (&ses->ses_lock);spin_lock (&ses->chan_lock); -if (!cifs_chan_needs_reconnect (ses, server)) { +if (!cifs_chan_needs_reconnect (ses, server) && + ses->ses_status ==SES_GOOD ) {spin_unlock (&ses->chan_lock); +spin_unlock (&ses->ses_lock);/* this means that we only need to tree connect */ if (tcon->need_reconnect) goto skip_sess_setup; - rc = -EHOSTDOWN ; +mutex_unlock (&ses->session_mutex); goto out; }spin_unlock (&ses->chan_lock); +spin_unlock (&ses->ses_lock); -mutex_lock (&ses->session_mutex); rc =cifs_negotiate_protocol (0 , ses, server);if (!rc) rc =cifs_setup_session (0 , ses, server, nls_codepage); --2.40.0
Signature · 3 lines
Thanks, Steve
PATCH 4/5 cifs: prevent infinite recursion in CIFSGetDFSRefer()
In reply to Paulo AlcantaraWe can't call smb_init() in CIFSGetDFSRefer() as cifs_reconnect_tcon() may end up calling CIFSGetDFSRefer() again to get new DFS referrals and thus causing an infinite recursion.
--- fs/cifs/cifssmb.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
fs/cifs/cifssmb.c +7 -2
@@ -4382,8 +4382,13 @@ CIFSGetDFSRefer(const unsigned int xid, struct cifs_ses *ses,return -ENODEV ; getDFSRetry: - rc =smb_init (SMB_COM_TRANSACTION2 ,15 , ses->tcon_ipc, (void **) &pSMB, - (void **) &pSMBr); +/* +* Use smb_init_no_reconnect() instead of smb_init() as +* CIFSGetDFSRefer() may be called from cifs_reconnect_tcon() and thus +* causing an infinite recursion. +*/ + rc =smb_init_no_reconnect (SMB_COM_TRANSACTION2 ,15 , ses->tcon_ipc, + (void **)&pSMB, (void **)&pSMBr);if (rc)return rc;
Signature · 1 line
2.40.0
ronnie sahlberg
reviewerRe: [PATCH 4/5] cifs: prevent infinite recursion in CIFSGetDFSRefer()
reviewed-by me
Quoted 33 lines · Paulo Alcantara
We can't call
smb_init()inCIFSGetDFSRefer()ascifs_reconnect_tcon()may end up callingCIFSGetDFSRefer()again to get new DFS referrals and thus causing an infinite recursion.Signed-off-by Paulo Alcantara (SUSE) <[email protected]>--- fs/cifs/cifssmb.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)fs/cifs/cifssmb.c +7
-3@@ -4382,8 +4382,13 @@ CIFSGetDFSRefer(const unsigned int xid, struct cifs_ses *ses,return -ENODEV ; getDFSRetry: - rc =smb_init (SMB_COM_TRANSACTION2 ,15 , ses->tcon_ipc, (void **) &pSMB, - (void **) &pSMBr); +/* +* Use smb_init_no_reconnect() instead of smb_init() as +* CIFSGetDFSRefer() may be called from cifs_reconnect_tcon() and thus +* causing an infinite recursion. +*/ + rc =smb_init_no_reconnect (SMB_COM_TRANSACTION2 ,15 , ses->tcon_ipc, + (void **)&pSMB, (void **)&pSMBr);if (rc)return rc; --2.40.0
Re: [PATCH 4/5] cifs: prevent infinite recursion in CIFSGetDFSRefer()
In reply to Paulo Alcantaraadded cc:stable and added ronnie's RB and merged into cifs-2.6.git for-next
Quoted 33 lines · Paulo Alcantara
We can't call
smb_init()inCIFSGetDFSRefer()ascifs_reconnect_tcon()may end up callingCIFSGetDFSRefer()again to get new DFS referrals and thus causing an infinite recursion.Signed-off-by Paulo Alcantara (SUSE) <[email protected]>--- fs/cifs/cifssmb.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)fs/cifs/cifssmb.c +7
-3@@ -4382,8 +4382,13 @@ CIFSGetDFSRefer(const unsigned int xid, struct cifs_ses *ses,return -ENODEV ; getDFSRetry: - rc =smb_init (SMB_COM_TRANSACTION2 ,15 , ses->tcon_ipc, (void **) &pSMB, - (void **) &pSMBr); +/* +* Use smb_init_no_reconnect() instead of smb_init() as +* CIFSGetDFSRefer() may be called from cifs_reconnect_tcon() and thus +* causing an infinite recursion. +*/ + rc =smb_init_no_reconnect (SMB_COM_TRANSACTION2 ,15 , ses->tcon_ipc, + (void **)&pSMB, (void **)&pSMBr);if (rc)return rc; --2.40.0
Signature · 3 lines
Thanks, Steve
PATCH 5/5 cifs: get rid of dead check in smb2_reconnect()
In reply to Paulo AlcantaraThe SMB2_IOCTL check in the switch statement will never be true as we return earlier from smb2_reconnect() if @smb2_command == SMB2_IOCTL.
--- fs/cifs/smb2pdu.c | 1 - 1 file changed, 1 deletion(-)
fs/cifs/smb2pdu.c +0 -1
@@ -310,7 +310,6 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,case SMB2_READ :case SMB2_WRITE :case SMB2_LOCK : -case SMB2_IOCTL :case SMB2_QUERY_DIRECTORY :case SMB2_CHANGE_NOTIFY :case SMB2_QUERY_INFO :
Signature · 1 line
2.40.0
ronnie sahlberg
reviewerRe: [PATCH 5/5] cifs: get rid of dead check in smb2_reconnect()
reviewed-by me
Quoted 24 lines · Paulo Alcantara
The
SMB2_IOCTLcheck in the switch statement will never be true as we return earlier fromsmb2_reconnect()if @smb2_command ==SMB2_IOCTL.Signed-off-by Paulo Alcantara (SUSE) <[email protected]>--- fs/cifs/smb2pdu.c | 1 - 1 file changed, 1 deletion(-)fs/cifs/smb2pdu.c +0
-2@@ -310,7 +310,6 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,case SMB2_READ :case SMB2_WRITE :case SMB2_LOCK : -case SMB2_IOCTL :case SMB2_QUERY_DIRECTORY :case SMB2_CHANGE_NOTIFY :case SMB2_QUERY_INFO : --2.40.0
Re: [PATCH 5/5] cifs: get rid of dead check in smb2_reconnect()
In reply to Paulo Alcantaraadded ronnie's RB and merged into cifs-2.6.git for-next
Quoted 24 lines · Paulo Alcantara
The
SMB2_IOCTLcheck in the switch statement will never be true as we return earlier fromsmb2_reconnect()if @smb2_command ==SMB2_IOCTL.Signed-off-by Paulo Alcantara (SUSE) <[email protected]>--- fs/cifs/smb2pdu.c | 1 - 1 file changed, 1 deletion(-)fs/cifs/smb2pdu.c +0
-2@@ -310,7 +310,6 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,case SMB2_READ :case SMB2_WRITE :case SMB2_LOCK : -case SMB2_IOCTL :case SMB2_QUERY_DIRECTORY :case SMB2_CHANGE_NOTIFY :case SMB2_QUERY_INFO : --2.40.0
Signature · 3 lines
Thanks, Steve
ronnie sahlberg
reviewerReviewed-by me
Quoted 42 lines · Paulo Alcantara
leaf_fullpathis now part ofsmb3_fs_contextstructure, whileorigin_fullpathis just a variable in__dfs_mount_share()that is used when final tcon is available.Get rid of those fields in
cifs_mount_ctxstructure and no-op kfree()'s.Signed-off-by Paulo Alcantara (SUSE) <[email protected]>--- fs/cifs/cifsglob.h | 1 - fs/cifs/connect.c | 2 -- 2 files changed, 3 deletions(-)fs/cifs/cifsglob.h +0
-1@@ -1750,7 +1750,6 @@ struct cifs_mount_ctx {struct TCP_Server_Info *server;struct cifs_ses *ses;struct cifs_tcon *tcon; -char *origin_fullpath, *leaf_fullpath;struct list_head dfs_ses_list; };fs/cifs/connect.c +0
-3@@ -3454,8 +3454,6 @@ int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx) error:dfs_put_root_smb_sessions (&mnt_ctx.dfs_ses_list); -kfree (mnt_ctx.origin_fullpath); -kfree (mnt_ctx.leaf_fullpath);cifs_mount_put_conns (&mnt_ctx);return rc; } --2.40.0