mirror of https://github.com/k3s-io/k3s
Merge pull request #75371 from andyzhangx/smb-mount-win-lock
fix race condition issue for smb mount on windowspull/564/head
commit
a4f2590bd8
|
@ -59,6 +59,7 @@ go_library(
|
||||||
"//vendor/k8s.io/utils/nsenter:go_default_library",
|
"//vendor/k8s.io/utils/nsenter:go_default_library",
|
||||||
],
|
],
|
||||||
"@io_bazel_rules_go//go/platform:windows": [
|
"@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/nsenter:go_default_library",
|
||||||
"//vendor/k8s.io/utils/path:go_default_library",
|
"//vendor/k8s.io/utils/path:go_default_library",
|
||||||
],
|
],
|
||||||
|
|
|
@ -28,6 +28,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
|
"k8s.io/utils/keymutex"
|
||||||
|
|
||||||
utilpath "k8s.io/utils/path"
|
utilpath "k8s.io/utils/path"
|
||||||
)
|
)
|
||||||
|
@ -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.
|
// Mount : mounts source to target with given options.
|
||||||
// currently only supports cifs(smb), bind mount(for disk)
|
// currently only supports cifs(smb), bind mount(for disk)
|
||||||
func (mounter *Mounter) Mount(source string, target string, fstype string, options []string) error {
|
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
|
||||||
return fmt.Errorf("only cifs mount is supported now, fstype: %q, mounting source (%q), target (%q), with options (%q)", fstype, source, target, options)
|
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 output, err := newSMBMapping(options[0], options[1], source); err != nil {
|
||||||
if isSMBMappingExist(source) {
|
if isSMBMappingExist(source) {
|
||||||
klog.V(2).Infof("SMB Mapping(%s) already exists, now begin to remove and remount", source)
|
klog.V(2).Infof("SMB Mapping(%s) already exists, now begin to remove and remount", source)
|
||||||
|
|
Loading…
Reference in New Issue