Skip to content

Commit 93cee45

Browse files
Paulo AlcantaraSteve French
authored andcommitted
smb: client: serialise cifs_construct_tcon() with cifs_mount_mutex
Serialise cifs_construct_tcon() with cifs_mount_mutex to handle parallel mounts that may end up reusing the session and tcon created by it. Cc: [email protected] # 6.4+ Signed-off-by: Paulo Alcantara (Red Hat) <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 4a5ba0e commit 93cee45

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

fs/smb/client/connect.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3988,7 +3988,7 @@ cifs_set_vol_auth(struct smb3_fs_context *ctx, struct cifs_ses *ses)
39883988
}
39893989

39903990
static struct cifs_tcon *
3991-
cifs_construct_tcon(struct cifs_sb_info *cifs_sb, kuid_t fsuid)
3991+
__cifs_construct_tcon(struct cifs_sb_info *cifs_sb, kuid_t fsuid)
39923992
{
39933993
int rc;
39943994
struct cifs_tcon *master_tcon = cifs_sb_master_tcon(cifs_sb);
@@ -4086,6 +4086,17 @@ cifs_construct_tcon(struct cifs_sb_info *cifs_sb, kuid_t fsuid)
40864086
return tcon;
40874087
}
40884088

4089+
static struct cifs_tcon *
4090+
cifs_construct_tcon(struct cifs_sb_info *cifs_sb, kuid_t fsuid)
4091+
{
4092+
struct cifs_tcon *ret;
4093+
4094+
cifs_mount_lock();
4095+
ret = __cifs_construct_tcon(cifs_sb, fsuid);
4096+
cifs_mount_unlock();
4097+
return ret;
4098+
}
4099+
40894100
struct cifs_tcon *
40904101
cifs_sb_master_tcon(struct cifs_sb_info *cifs_sb)
40914102
{

fs/smb/client/fs_context.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#include "rfc1002pdu.h"
3838
#include "fs_context.h"
3939

40-
static DEFINE_MUTEX(cifs_mount_mutex);
40+
DEFINE_MUTEX(cifs_mount_mutex);
4141

4242
static const match_table_t cifs_smb_version_tokens = {
4343
{ Smb_1, SMB1_VERSION_STRING },
@@ -783,9 +783,9 @@ static int smb3_get_tree(struct fs_context *fc)
783783

784784
if (err)
785785
return err;
786-
mutex_lock(&cifs_mount_mutex);
786+
cifs_mount_lock();
787787
ret = smb3_get_tree_common(fc);
788-
mutex_unlock(&cifs_mount_mutex);
788+
cifs_mount_unlock();
789789
return ret;
790790
}
791791

fs/smb/client/fs_context.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,4 +304,16 @@ extern void smb3_update_mnt_flags(struct cifs_sb_info *cifs_sb);
304304
#define MAX_CACHED_FIDS 16
305305
extern char *cifs_sanitize_prepath(char *prepath, gfp_t gfp);
306306

307+
extern struct mutex cifs_mount_mutex;
308+
309+
static inline void cifs_mount_lock(void)
310+
{
311+
mutex_lock(&cifs_mount_mutex);
312+
}
313+
314+
static inline void cifs_mount_unlock(void)
315+
{
316+
mutex_unlock(&cifs_mount_mutex);
317+
}
318+
307319
#endif

0 commit comments

Comments
 (0)