Skip to contentSkip to conversation

cifs: serialize all mount attempts

PATCH In review Ronnie Sahlberg 2 participants 3 messages Jan 18, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cifs: serialize all mount attempts

RHBZ: 2008434

Some servers, such as Windows2016 have a very low number of concurrent mounts that they allow from each client.
This can be a problem if you have a more than a handful (==3 in this case) of cifs entries in your fstab and cause a number of the mounts there to randomly fail.

Add a global mutex and use it to serialize all mount attempts.

---
 fs/cifs/fs_context.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
fs/cifs/fs_context.c +7 -1
index e3ed25dc6f3f..7ec35f3f0a5f 100644
@@ -37,6 +37,8 @@
 #include "rfc1002pdu.h"
 #include "fs_context.h"
 
+static DEFINE_MUTEX(cifs_mount_mutex);
+
 static const match_table_t cifs_smb_version_tokens = {
 	{ Smb_1, SMB1_VERSION_STRING },
 	{ Smb_20, SMB20_VERSION_STRING},
@@ -707,10 +709,14 @@ static int smb3_get_tree_common(struct fs_context *fc)
 static int smb3_get_tree(struct fs_context *fc)
 {
 	int err = smb3_fs_context_validate(fc);
+	int ret;
 
 	if (err)
 		return err;
-	return smb3_get_tree_common(fc);
+	mutex_lock(&cifs_mount_mutex);
+	ret = smb3_get_tree_common(fc);
+	mutex_unlock(&cifs_mount_mutex);
+	return ret;
 }
 
 static void smb3_fs_context_free(struct fs_context *fc)
Signature · 1 line
2.30.2
#1 lore raw

Would this slow things down much at boot time when you do have e.g. 3 mounts ... would end up serializing a bit more?

Quoted 47 lines · Ronnie Sahlberg

RHBZ: 2008434

Some servers, such as Windows2016 have a very low number of concurrent mounts that they allow from each client.
This can be a problem if you have a more than a handful (==3 in this case) of cifs entries in your fstab and cause a number of the mounts there to randomly fail.

Add a global mutex and use it to serialize all mount attempts.

---
 fs/cifs/fs_context.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
fs/cifs/fs_context.c +7 -2
index e3ed25dc6f3f..7ec35f3f0a5f 100644
@@ -37,6 +37,8 @@
 #include "rfc1002pdu.h"
 #include "fs_context.h"
 
+static DEFINE_MUTEX(cifs_mount_mutex);
+
 static const match_table_t cifs_smb_version_tokens = {
        { Smb_1, SMB1_VERSION_STRING },
        { Smb_20, SMB20_VERSION_STRING},
@@ -707,10 +709,14 @@ static int smb3_get_tree_common(struct fs_context *fc)
 static int smb3_get_tree(struct fs_context *fc)
 {
        int err = smb3_fs_context_validate(fc);
+       int ret;
 
        if (err)
                return err;
-       return smb3_get_tree_common(fc);
+       mutex_lock(&cifs_mount_mutex);
+       ret = smb3_get_tree_common(fc);
+       mutex_unlock(&cifs_mount_mutex);
+       return ret;
 }
 
 static void smb3_fs_context_free(struct fs_context *fc)
--

2.30.2

Signature · 3 lines
Thanks,

Steve
#2 lore raw
In reply to Ronnie Sahlberg

What would happen if on boot you had 3 servers in fstab, the first two of which time out due to bad address (or in my case port 445 blocked for the internet but not for local servers in the house), does it slow down bootup? Does it slow down the mount to the 3rd server (which is reachable)?

Would it slow things down too much in some cases?

Quoted 47 lines · Ronnie Sahlberg

RHBZ: 2008434

Some servers, such as Windows2016 have a very low number of concurrent mounts that they allow from each client.
This can be a problem if you have a more than a handful (==3 in this case) of cifs entries in your fstab and cause a number of the mounts there to randomly fail.

Add a global mutex and use it to serialize all mount attempts.

---
 fs/cifs/fs_context.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
fs/cifs/fs_context.c +7 -2
index e3ed25dc6f3f..7ec35f3f0a5f 100644
@@ -37,6 +37,8 @@
 #include "rfc1002pdu.h"
 #include "fs_context.h"
 
+static DEFINE_MUTEX(cifs_mount_mutex);
+
 static const match_table_t cifs_smb_version_tokens = {
        { Smb_1, SMB1_VERSION_STRING },
        { Smb_20, SMB20_VERSION_STRING},
@@ -707,10 +709,14 @@ static int smb3_get_tree_common(struct fs_context *fc)
 static int smb3_get_tree(struct fs_context *fc)
 {
        int err = smb3_fs_context_validate(fc);
+       int ret;
 
        if (err)
                return err;
-       return smb3_get_tree_common(fc);
+       mutex_lock(&cifs_mount_mutex);
+       ret = smb3_get_tree_common(fc);
+       mutex_unlock(&cifs_mount_mutex);
+       return ret;
 }
 
 static void smb3_fs_context_free(struct fs_context *fc)
--

2.30.2

Signature · 3 lines
Thanks,

Steve