Skip to content

Commit a4f2590

Browse files
authored
Merge pull request kubernetes#75371 from andyzhangx/smb-mount-win-lock
fix race condition issue for smb mount on windows
2 parents cd9f18b + 4b4b6cd commit a4f2590

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

pkg/util/mount/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ go_library(
5959
"//vendor/k8s.io/utils/nsenter:go_default_library",
6060
],
6161
"@io_bazel_rules_go//go/platform:windows": [
62+
"//vendor/k8s.io/utils/keymutex:go_default_library",
6263
"//vendor/k8s.io/utils/nsenter:go_default_library",
6364
"//vendor/k8s.io/utils/path:go_default_library",
6465
],

pkg/util/mount/mount_windows.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"strings"
2929

3030
"k8s.io/klog"
31+
"k8s.io/utils/keymutex"
3132

3233
utilpath "k8s.io/utils/path"
3334
)
@@ -48,6 +49,9 @@ func New(mounterPath string) Interface {
4849
}
4950
}
5051

52+
// acquire lock for smb mount
53+
var getSMBMountMutex = keymutex.NewHashed(0)
54+
5155
// Mount : mounts source to target with given options.
5256
// currently only supports cifs(smb), bind mount(for disk)
5357
func (mounter *Mounter) Mount(source string, target string, fstype string, options []string) error {
@@ -83,6 +87,10 @@ func (mounter *Mounter) Mount(source string, target string, fstype string, optio
8387
return fmt.Errorf("only cifs mount is supported now, fstype: %q, mounting source (%q), target (%q), with options (%q)", fstype, source, target, options)
8488
}
8589

90+
// lock smb mount for the same source
91+
getSMBMountMutex.LockKey(source)
92+
defer getSMBMountMutex.UnlockKey(source)
93+
8694
if output, err := newSMBMapping(options[0], options[1], source); err != nil {
8795
if isSMBMappingExist(source) {
8896
klog.V(2).Infof("SMB Mapping(%s) already exists, now begin to remove and remount", source)

0 commit comments

Comments
 (0)