Skip to content

Commit

Permalink
fix race condition issue for smb mount on windows
Browse files Browse the repository at this point in the history
change var name
  • Loading branch information
andyzhangx committed Mar 14, 2019
1 parent 897d62a commit 4b4b6cd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/util/mount/BUILD
Expand Up @@ -59,6 +59,7 @@ go_library(
"//vendor/k8s.io/utils/nsenter:go_default_library",
],
"@io_bazel_rules_go//go/platform:windows": [
"//vendor/k8s.io/utils/keymutex:go_default_library",
"//vendor/k8s.io/utils/nsenter:go_default_library",
"//vendor/k8s.io/utils/path:go_default_library",
],
Expand Down
8 changes: 8 additions & 0 deletions pkg/util/mount/mount_windows.go
Expand Up @@ -28,6 +28,7 @@ import (
"strings"

"k8s.io/klog"
"k8s.io/utils/keymutex"

utilpath "k8s.io/utils/path"
)
Expand All @@ -48,6 +49,9 @@ func New(mounterPath string) Interface {
}
}

// acquire lock for smb mount
var getSMBMountMutex = keymutex.NewHashed(0)

// Mount : mounts source to target with given options.
// currently only supports cifs(smb), bind mount(for disk)
func (mounter *Mounter) Mount(source string, target string, fstype string, options []string) error {
Expand Down Expand Up @@ -83,6 +87,10 @@ func (mounter *Mounter) Mount(source string, target string, fstype string, optio
return fmt.Errorf("only cifs mount is supported now, fstype: %q, mounting source (%q), target (%q), with options (%q)", fstype, source, target, options)
}

// lock smb mount for the same source
getSMBMountMutex.LockKey(source)
defer getSMBMountMutex.UnlockKey(source)

if output, err := newSMBMapping(options[0], options[1], source); err != nil {
if isSMBMappingExist(source) {
klog.V(2).Infof("SMB Mapping(%s) already exists, now begin to remove and remount", source)
Expand Down

0 comments on commit 4b4b6cd

Please sign in to comment.