From d0ccea04045e9b154970a92f8eafa0c76cb0f2e2 Mon Sep 17 00:00:00 2001 From: Simon Frei Date: Tue, 3 Nov 2020 19:09:32 +0100 Subject: [PATCH] lib/config: Sanity checks on MaxConcurrentWrites (ref #7064) (#7069) --- lib/config/config_test.go | 1 + lib/config/folderconfiguration.go | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/config/config_test.go b/lib/config/config_test.go index 0008d5c83..3d73912e4 100644 --- a/lib/config/config_test.go +++ b/lib/config/config_test.go @@ -129,6 +129,7 @@ func TestDeviceConfig(t *testing.T) { WeakHashThresholdPct: 25, MarkerName: DefaultMarkerName, JunctionsAsDirs: true, + MaxConcurrentWrites: maxConcurrentWritesDefault, }, } diff --git a/lib/config/folderconfiguration.go b/lib/config/folderconfiguration.go index 4c08b9d12..d92dd67f8 100644 --- a/lib/config/folderconfiguration.go +++ b/lib/config/folderconfiguration.go @@ -26,7 +26,11 @@ var ( ErrMarkerMissing = errors.New("folder marker missing (this indicates potential data loss, search docs/forum to get information about how to proceed)") ) -const DefaultMarkerName = ".stfolder" +const ( + DefaultMarkerName = ".stfolder" + maxConcurrentWritesDefault = 2 + maxConcurrentWritesLimit = 64 +) func NewFolderConfiguration(myID protocol.DeviceID, id, label string, fsType fs.FilesystemType, path string) FolderConfiguration { f := FolderConfiguration{ @@ -206,6 +210,12 @@ func (f *FolderConfiguration) prepare() { if f.MarkerName == "" { f.MarkerName = DefaultMarkerName } + + if f.MaxConcurrentWrites <= 0 { + f.MaxConcurrentWrites = maxConcurrentWritesDefault + } else if f.MaxConcurrentWrites > maxConcurrentWritesLimit { + f.MaxConcurrentWrites = maxConcurrentWritesLimit + } } // RequiresRestartOnly returns a copy with only the attributes that require