Skip to content

Commit

Permalink
Merge pull request #1267 from kubernetes-sigs/append-nosharesock-option
Browse files Browse the repository at this point in the history
fix: append nosharesock mount option on Linux node by default
  • Loading branch information
andyzhangx authored May 19, 2023
2 parents 2c69d56 + a540843 commit 544b926
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
8 changes: 7 additions & 1 deletion pkg/azurefile/azurefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ type DriverOptions struct {
KubeAPIBurst int
EnableWindowsHostProcess bool
AppendClosetimeoOption bool
AppendNoShareSockOption bool
}

// Driver implements all interfaces of CSI drivers
Expand All @@ -223,6 +224,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)
Expand Down Expand Up @@ -271,6 +273,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()
Expand Down Expand Up @@ -429,7 +432,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,
Expand All @@ -440,6 +443,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)
Expand Down
31 changes: 27 additions & 4 deletions pkg/azurefile/azurefile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion pkg/azurefile/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/azurefileplugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,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() {
Expand Down Expand Up @@ -101,6 +102,7 @@ func handle() {
KubeAPIBurst: *kubeAPIBurst,
EnableWindowsHostProcess: *enableWindowsHostProcess,
AppendClosetimeoOption: *appendClosetimeoOption,
AppendNoShareSockOption: *appendNoShareSockOption,
}
driver := azurefile.NewDriver(&driverOptions)
if driver == nil {
Expand Down

0 comments on commit 544b926

Please sign in to comment.