From 1ec4782fc93548b4188eacb516fa72edb3370cf6 Mon Sep 17 00:00:00 2001 From: andyzhangx Date: Thu, 18 May 2023 16:33:56 +0000 Subject: [PATCH] fix: append nosharesock mount option on Linux node by default --- pkg/azurefile/azurefile.go | 8 +++++++- pkg/azurefile/azurefile_test.go | 31 +++++++++++++++++++++++++++---- pkg/azurefile/nodeserver.go | 2 +- pkg/azurefileplugin/main.go | 2 ++ 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/pkg/azurefile/azurefile.go b/pkg/azurefile/azurefile.go index 99cbc952aa..d8de55f9f9 100644 --- a/pkg/azurefile/azurefile.go +++ b/pkg/azurefile/azurefile.go @@ -200,6 +200,7 @@ type DriverOptions struct { KubeAPIBurst int EnableWindowsHostProcess bool AppendClosetimeoOption bool + AppendNoShareSockOption bool } // Driver implements all interfaces of CSI drivers @@ -221,6 +222,7 @@ type Driver struct { kubeAPIBurst int enableWindowsHostProcess bool appendClosetimeoOption bool + appendNoShareSockOption bool fileClient *azureFileClient mounter *mount.SafeFormatAndMount // lock per volume attach (only for vhd disk feature) @@ -268,6 +270,7 @@ func NewDriver(options *DriverOptions) *Driver { driver.kubeAPIBurst = options.KubeAPIBurst driver.enableWindowsHostProcess = options.EnableWindowsHostProcess driver.appendClosetimeoOption = options.AppendClosetimeoOption + driver.appendNoShareSockOption = options.AppendNoShareSockOption driver.volLockMap = newLockMap() driver.subnetLockMap = newLockMap() driver.volumeLocks = newVolumeLocks() @@ -425,7 +428,7 @@ func GetFileShareInfo(id string) (string, string, string, string, string, string } // check whether mountOptions contains file_mode, dir_mode, vers, if not, append default mode -func appendDefaultMountOptions(mountOptions []string, appendClosetimeoOption bool) []string { +func appendDefaultMountOptions(mountOptions []string, appendNoShareSockOption, appendClosetimeoOption bool) []string { var defaultMountOptions = map[string]string{ fileMode: defaultFileMode, dirMode: defaultDirMode, @@ -436,6 +439,9 @@ func appendDefaultMountOptions(mountOptions []string, appendClosetimeoOption boo if appendClosetimeoOption { defaultMountOptions["sloppy,closetimeo=0"] = "" } + if appendNoShareSockOption { + defaultMountOptions["nosharesock"] = "" + } // stores the mount options already included in mountOptions included := make(map[string]bool) diff --git a/pkg/azurefile/azurefile_test.go b/pkg/azurefile/azurefile_test.go index 0291afd676..1e71e9211b 100644 --- a/pkg/azurefile/azurefile_test.go +++ b/pkg/azurefile/azurefile_test.go @@ -92,9 +92,10 @@ func TestNewFakeDriver(t *testing.T) { func TestAppendDefaultMountOptions(t *testing.T) { tests := []struct { - options []string - appendClosetimeoOption bool - expected []string + options []string + appendClosetimeoOption bool + appendNoShareSockOption bool + expected []string }{ { options: []string{"dir_mode=0777"}, @@ -194,10 +195,32 @@ func TestAppendDefaultMountOptions(t *testing.T) { "sloppy,closetimeo=0", }, }, + { + options: []string{""}, + appendNoShareSockOption: true, + expected: []string{"", fmt.Sprintf("%s=%s", + fileMode, defaultFileMode), + fmt.Sprintf("%s=%s", dirMode, defaultDirMode), + fmt.Sprintf("%s=%s", actimeo, defaultActimeo), + mfsymlinks, + "nosharesock", + }, + }, + { + options: []string{"nosharesock"}, + appendNoShareSockOption: true, + expected: []string{fmt.Sprintf("%s=%s", + fileMode, defaultFileMode), + fmt.Sprintf("%s=%s", dirMode, defaultDirMode), + fmt.Sprintf("%s=%s", actimeo, defaultActimeo), + mfsymlinks, + "nosharesock", + }, + }, } for _, test := range tests { - result := appendDefaultMountOptions(test.options, test.appendClosetimeoOption) + result := appendDefaultMountOptions(test.options, test.appendNoShareSockOption, test.appendClosetimeoOption) sort.Strings(result) sort.Strings(test.expected) diff --git a/pkg/azurefile/nodeserver.go b/pkg/azurefile/nodeserver.go index cc1809bee4..5588be4b3d 100644 --- a/pkg/azurefile/nodeserver.go +++ b/pkg/azurefile/nodeserver.go @@ -294,7 +294,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe if ephemeralVol { cifsMountFlags = util.JoinMountOptions(cifsMountFlags, strings.Split(ephemeralVolMountOptions, ",")) } - mountOptions = appendDefaultMountOptions(cifsMountFlags, d.appendClosetimeoOption) + mountOptions = appendDefaultMountOptions(cifsMountFlags, d.appendNoShareSockOption, d.appendClosetimeoOption) } } diff --git a/pkg/azurefileplugin/main.go b/pkg/azurefileplugin/main.go index 7a1ae44287..e57300710e 100644 --- a/pkg/azurefileplugin/main.go +++ b/pkg/azurefileplugin/main.go @@ -57,6 +57,7 @@ var ( appendMountErrorHelpLink = flag.Bool("append-mount-error-help-link", true, "Whether to include a link for help with mount errors when a mount error occurs.") enableWindowsHostProcess = flag.Bool("enable-windows-host-process", false, "enable windows host process") appendClosetimeoOption = flag.Bool("append-closetimeo-option", false, "Whether appending closetimeo=0 option to smb mount command") + appendNoShareSockOption = flag.Bool("append-nosharesock-option", true, "Whether appending nosharesock option to smb mount command") ) func main() { @@ -99,6 +100,7 @@ func handle() { KubeAPIBurst: *kubeAPIBurst, EnableWindowsHostProcess: *enableWindowsHostProcess, AppendClosetimeoOption: *appendClosetimeoOption, + AppendNoShareSockOption: *appendNoShareSockOption, } driver := azurefile.NewDriver(&driverOptions) if driver == nil {