diff --git a/pkg/azurefile/azurefile.go b/pkg/azurefile/azurefile.go index ef7370c891..93349e5b79 100644 --- a/pkg/azurefile/azurefile.go +++ b/pkg/azurefile/azurefile.go @@ -64,6 +64,7 @@ const ( fileMode = "file_mode" dirMode = "dir_mode" actimeo = "actimeo" + noResvPort = "noresvport" mfsymlinks = "mfsymlinks" defaultFileMode = "0777" defaultDirMode = "0777" @@ -213,6 +214,8 @@ type DriverOptions struct { EnableWindowsHostProcess bool AppendClosetimeoOption bool AppendNoShareSockOption bool + AppendNoResvPortOption bool + AppendActimeoOption bool SkipMatchingTagCacheExpireInMinutes int VolStatsCacheExpireInMinutes int PrintVolumeStatsCallLogs bool @@ -240,6 +243,8 @@ type Driver struct { enableWindowsHostProcess bool appendClosetimeoOption bool appendNoShareSockOption bool + appendNoResvPortOption bool + appendActimeoOption bool printVolumeStatsCallLogs bool fileClient *azureFileClient mounter *mount.SafeFormatAndMount @@ -298,6 +303,8 @@ func NewDriver(options *DriverOptions) *Driver { driver.enableWindowsHostProcess = options.EnableWindowsHostProcess driver.appendClosetimeoOption = options.AppendClosetimeoOption driver.appendNoShareSockOption = options.AppendNoShareSockOption + driver.appendNoResvPortOption = options.AppendNoResvPortOption + driver.appendActimeoOption = options.AppendActimeoOption driver.printVolumeStatsCallLogs = options.PrintVolumeStatsCallLogs driver.sasTokenExpirationMinutes = options.SasTokenExpirationMinutes driver.volLockMap = newLockMap() @@ -473,7 +480,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, appendNoShareSockOption, appendClosetimeoOption bool) []string { +func appendDefaultCifsMountOptions(mountOptions []string, appendNoShareSockOption, appendClosetimeoOption bool) []string { var defaultMountOptions = map[string]string{ fileMode: defaultFileMode, dirMode: defaultDirMode, @@ -518,6 +525,46 @@ func appendDefaultMountOptions(mountOptions []string, appendNoShareSockOption, a return allMountOptions } +// check whether mountOptions contains actimeo, if not, append default mode +func appendDefaultNfsMountOptions(mountOptions []string, appendNoResvPortOption, appendActimeoOption bool) []string { + var defaultMountOptions = map[string]string{} + if appendNoResvPortOption { + defaultMountOptions[noResvPort] = "" + } + if appendActimeoOption { + defaultMountOptions[actimeo] = defaultActimeo + } + + if len(defaultMountOptions) == 0 { + return mountOptions + } + + // stores the mount options already included in mountOptions + included := make(map[string]bool) + + for _, mountOption := range mountOptions { + for k := range defaultMountOptions { + if strings.HasPrefix(mountOption, k) { + included[k] = true + } + } + } + + allMountOptions := mountOptions + + for k, v := range defaultMountOptions { + if _, isIncluded := included[k]; !isIncluded { + if v != "" { + allMountOptions = append(allMountOptions, fmt.Sprintf("%s=%s", k, v)) + } else { + allMountOptions = append(allMountOptions, k) + } + } + } + + return allMountOptions +} + // get storage account from secrets map func getStorageAccount(secrets map[string]string) (string, string, error) { if secrets == nil { diff --git a/pkg/azurefile/azurefile_test.go b/pkg/azurefile/azurefile_test.go index 25ad82b414..a81f945787 100644 --- a/pkg/azurefile/azurefile_test.go +++ b/pkg/azurefile/azurefile_test.go @@ -101,7 +101,7 @@ func TestNewFakeDriver(t *testing.T) { assert.NotNil(t, d) } -func TestAppendDefaultMountOptions(t *testing.T) { +func TestAppendDefaultCifsMountOptions(t *testing.T) { tests := []struct { options []string appendClosetimeoOption bool @@ -231,12 +231,56 @@ func TestAppendDefaultMountOptions(t *testing.T) { } for _, test := range tests { - result := appendDefaultMountOptions(test.options, test.appendNoShareSockOption, test.appendClosetimeoOption) + result := appendDefaultCifsMountOptions(test.options, test.appendNoShareSockOption, test.appendClosetimeoOption) sort.Strings(result) sort.Strings(test.expected) if !reflect.DeepEqual(result, test.expected) { - t.Errorf("input: %q, appendDefaultMountOptions result: %q, expected: %q", test.options, result, test.expected) + t.Errorf("input: %q, appendDefaultCifsMountOptions result: %q, expected: %q", test.options, result, test.expected) + } + } +} + +func TestAppendDefaultNfsMountOptions(t *testing.T) { + tests := []struct { + options []string + appendNoResvPortOption bool + appendActimeoOption bool + expected []string + }{ + { + options: []string{""}, + appendNoResvPortOption: false, + appendActimeoOption: false, + expected: []string{""}, + }, + { + options: []string{}, + appendNoResvPortOption: true, + appendActimeoOption: true, + expected: []string{fmt.Sprintf("%s=%s", actimeo, defaultActimeo), noResvPort}, + }, + { + options: []string{noResvPort}, + appendNoResvPortOption: true, + appendActimeoOption: true, + expected: []string{fmt.Sprintf("%s=%s", actimeo, defaultActimeo), noResvPort}, + }, + { + options: []string{fmt.Sprintf("%s=%s", actimeo, "60")}, + appendNoResvPortOption: true, + appendActimeoOption: true, + expected: []string{fmt.Sprintf("%s=%s", actimeo, "60"), noResvPort}, + }, + } + + for _, test := range tests { + result := appendDefaultNfsMountOptions(test.options, test.appendNoResvPortOption, test.appendActimeoOption) + sort.Strings(result) + sort.Strings(test.expected) + + if !reflect.DeepEqual(result, test.expected) { + t.Errorf("input: %q, appendDefaultNfsMountOptions result: %q, expected: %q", test.options, result, test.expected) } } } diff --git a/pkg/azurefile/nodeserver.go b/pkg/azurefile/nodeserver.go index fad80f0f8c..28d4618b96 100644 --- a/pkg/azurefile/nodeserver.go +++ b/pkg/azurefile/nodeserver.go @@ -286,6 +286,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe var mountOptions, sensitiveMountOptions []string if protocol == nfs { mountOptions = util.JoinMountOptions(mountFlags, []string{"vers=4,minorversion=1,sec=sys"}) + mountOptions = appendDefaultNfsMountOptions(mountOptions, d.appendNoResvPortOption, d.appendActimeoOption) } else { if accountName == "" || accountKey == "" { return nil, status.Errorf(codes.Internal, "accountName(%s) or accountKey is empty", accountName) @@ -302,7 +303,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe if ephemeralVol { cifsMountFlags = util.JoinMountOptions(cifsMountFlags, strings.Split(ephemeralVolMountOptions, ",")) } - mountOptions = appendDefaultMountOptions(cifsMountFlags, d.appendNoShareSockOption, d.appendClosetimeoOption) + mountOptions = appendDefaultCifsMountOptions(cifsMountFlags, d.appendNoShareSockOption, d.appendClosetimeoOption) } } diff --git a/pkg/azurefileplugin/main.go b/pkg/azurefileplugin/main.go index c262911ef0..94d59e4a78 100644 --- a/pkg/azurefileplugin/main.go +++ b/pkg/azurefileplugin/main.go @@ -59,6 +59,8 @@ var ( 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") + appendNoResvPortOption = flag.Bool("append-noresvport-option", true, "Whether appending noresvport option to nfs mount command") + appendActimeoOption = flag.Bool("append-actimeo-option", true, "Whether appending actimeo=0 option to nfs mount command") skipMatchingTagCacheExpireInMinutes = flag.Int("skip-matching-tag-cache-expire-in-minutes", 30, "The cache expire time in minutes for skipMatchingTagCache") volStatsCacheExpireInMinutes = flag.Int("vol-stats-cache-expire-in-minutes", 10, "The cache expire time in minutes for volume stats cache") printVolumeStatsCallLogs = flag.Bool("print-volume-stats-call-logs", false, "Whether to print volume statfs call logs with log level 2") @@ -107,6 +109,8 @@ func handle() { EnableWindowsHostProcess: *enableWindowsHostProcess, AppendClosetimeoOption: *appendClosetimeoOption, AppendNoShareSockOption: *appendNoShareSockOption, + AppendNoResvPortOption: *appendNoResvPortOption, + AppendActimeoOption: *appendActimeoOption, SkipMatchingTagCacheExpireInMinutes: *skipMatchingTagCacheExpireInMinutes, VolStatsCacheExpireInMinutes: *volStatsCacheExpireInMinutes, PrintVolumeStatsCallLogs: *printVolumeStatsCallLogs,