Skip to content

feat: append default nfs mount options #1592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion pkg/azurefile/azurefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const (
fileMode = "file_mode"
dirMode = "dir_mode"
actimeo = "actimeo"
noResvPort = "noresvport"
mfsymlinks = "mfsymlinks"
defaultFileMode = "0777"
defaultDirMode = "0777"
Expand Down Expand Up @@ -213,6 +214,8 @@ type DriverOptions struct {
EnableWindowsHostProcess bool
AppendClosetimeoOption bool
AppendNoShareSockOption bool
AppendNoResvPortOption bool
AppendActimeoOption bool
SkipMatchingTagCacheExpireInMinutes int
VolStatsCacheExpireInMinutes int
PrintVolumeStatsCallLogs bool
Expand Down Expand Up @@ -240,6 +243,8 @@ type Driver struct {
enableWindowsHostProcess bool
appendClosetimeoOption bool
appendNoShareSockOption bool
appendNoResvPortOption bool
appendActimeoOption bool
printVolumeStatsCallLogs bool
fileClient *azureFileClient
mounter *mount.SafeFormatAndMount
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
50 changes: 47 additions & 3 deletions pkg/azurefile/azurefile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/azurefile/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/azurefileplugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -107,6 +109,8 @@ func handle() {
EnableWindowsHostProcess: *enableWindowsHostProcess,
AppendClosetimeoOption: *appendClosetimeoOption,
AppendNoShareSockOption: *appendNoShareSockOption,
AppendNoResvPortOption: *appendNoResvPortOption,
AppendActimeoOption: *appendActimeoOption,
SkipMatchingTagCacheExpireInMinutes: *skipMatchingTagCacheExpireInMinutes,
VolStatsCacheExpireInMinutes: *volStatsCacheExpireInMinutes,
PrintVolumeStatsCallLogs: *printVolumeStatsCallLogs,
Expand Down