Skip to content

Commit c409c33

Browse files
authored
Merge pull request #1594 from k8s-infra-cherrypick-robot/cherry-pick-1592-to-release-1.29
[release-1.29] feat: append default nfs mount options
2 parents 71040fd + 48825c9 commit c409c33

File tree

4 files changed

+101
-5
lines changed

4 files changed

+101
-5
lines changed

pkg/azurefile/azurefile.go

+48-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ const (
6464
fileMode = "file_mode"
6565
dirMode = "dir_mode"
6666
actimeo = "actimeo"
67+
noResvPort = "noresvport"
6768
mfsymlinks = "mfsymlinks"
6869
defaultFileMode = "0777"
6970
defaultDirMode = "0777"
@@ -213,6 +214,8 @@ type DriverOptions struct {
213214
EnableWindowsHostProcess bool
214215
AppendClosetimeoOption bool
215216
AppendNoShareSockOption bool
217+
AppendNoResvPortOption bool
218+
AppendActimeoOption bool
216219
SkipMatchingTagCacheExpireInMinutes int
217220
VolStatsCacheExpireInMinutes int
218221
PrintVolumeStatsCallLogs bool
@@ -240,6 +243,8 @@ type Driver struct {
240243
enableWindowsHostProcess bool
241244
appendClosetimeoOption bool
242245
appendNoShareSockOption bool
246+
appendNoResvPortOption bool
247+
appendActimeoOption bool
243248
printVolumeStatsCallLogs bool
244249
fileClient *azureFileClient
245250
mounter *mount.SafeFormatAndMount
@@ -298,6 +303,8 @@ func NewDriver(options *DriverOptions) *Driver {
298303
driver.enableWindowsHostProcess = options.EnableWindowsHostProcess
299304
driver.appendClosetimeoOption = options.AppendClosetimeoOption
300305
driver.appendNoShareSockOption = options.AppendNoShareSockOption
306+
driver.appendNoResvPortOption = options.AppendNoResvPortOption
307+
driver.appendActimeoOption = options.AppendActimeoOption
301308
driver.printVolumeStatsCallLogs = options.PrintVolumeStatsCallLogs
302309
driver.sasTokenExpirationMinutes = options.SasTokenExpirationMinutes
303310
driver.volLockMap = newLockMap()
@@ -473,7 +480,7 @@ func GetFileShareInfo(id string) (string, string, string, string, string, string
473480
}
474481

475482
// check whether mountOptions contains file_mode, dir_mode, vers, if not, append default mode
476-
func appendDefaultMountOptions(mountOptions []string, appendNoShareSockOption, appendClosetimeoOption bool) []string {
483+
func appendDefaultCifsMountOptions(mountOptions []string, appendNoShareSockOption, appendClosetimeoOption bool) []string {
477484
var defaultMountOptions = map[string]string{
478485
fileMode: defaultFileMode,
479486
dirMode: defaultDirMode,
@@ -518,6 +525,46 @@ func appendDefaultMountOptions(mountOptions []string, appendNoShareSockOption, a
518525
return allMountOptions
519526
}
520527

528+
// check whether mountOptions contains actimeo, if not, append default mode
529+
func appendDefaultNfsMountOptions(mountOptions []string, appendNoResvPortOption, appendActimeoOption bool) []string {
530+
var defaultMountOptions = map[string]string{}
531+
if appendNoResvPortOption {
532+
defaultMountOptions[noResvPort] = ""
533+
}
534+
if appendActimeoOption {
535+
defaultMountOptions[actimeo] = defaultActimeo
536+
}
537+
538+
if len(defaultMountOptions) == 0 {
539+
return mountOptions
540+
}
541+
542+
// stores the mount options already included in mountOptions
543+
included := make(map[string]bool)
544+
545+
for _, mountOption := range mountOptions {
546+
for k := range defaultMountOptions {
547+
if strings.HasPrefix(mountOption, k) {
548+
included[k] = true
549+
}
550+
}
551+
}
552+
553+
allMountOptions := mountOptions
554+
555+
for k, v := range defaultMountOptions {
556+
if _, isIncluded := included[k]; !isIncluded {
557+
if v != "" {
558+
allMountOptions = append(allMountOptions, fmt.Sprintf("%s=%s", k, v))
559+
} else {
560+
allMountOptions = append(allMountOptions, k)
561+
}
562+
}
563+
}
564+
565+
return allMountOptions
566+
}
567+
521568
// get storage account from secrets map
522569
func getStorageAccount(secrets map[string]string) (string, string, error) {
523570
if secrets == nil {

pkg/azurefile/azurefile_test.go

+47-3
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func TestNewFakeDriver(t *testing.T) {
101101
assert.NotNil(t, d)
102102
}
103103

104-
func TestAppendDefaultMountOptions(t *testing.T) {
104+
func TestAppendDefaultCifsMountOptions(t *testing.T) {
105105
tests := []struct {
106106
options []string
107107
appendClosetimeoOption bool
@@ -231,12 +231,56 @@ func TestAppendDefaultMountOptions(t *testing.T) {
231231
}
232232

233233
for _, test := range tests {
234-
result := appendDefaultMountOptions(test.options, test.appendNoShareSockOption, test.appendClosetimeoOption)
234+
result := appendDefaultCifsMountOptions(test.options, test.appendNoShareSockOption, test.appendClosetimeoOption)
235235
sort.Strings(result)
236236
sort.Strings(test.expected)
237237

238238
if !reflect.DeepEqual(result, test.expected) {
239-
t.Errorf("input: %q, appendDefaultMountOptions result: %q, expected: %q", test.options, result, test.expected)
239+
t.Errorf("input: %q, appendDefaultCifsMountOptions result: %q, expected: %q", test.options, result, test.expected)
240+
}
241+
}
242+
}
243+
244+
func TestAppendDefaultNfsMountOptions(t *testing.T) {
245+
tests := []struct {
246+
options []string
247+
appendNoResvPortOption bool
248+
appendActimeoOption bool
249+
expected []string
250+
}{
251+
{
252+
options: []string{""},
253+
appendNoResvPortOption: false,
254+
appendActimeoOption: false,
255+
expected: []string{""},
256+
},
257+
{
258+
options: []string{},
259+
appendNoResvPortOption: true,
260+
appendActimeoOption: true,
261+
expected: []string{fmt.Sprintf("%s=%s", actimeo, defaultActimeo), noResvPort},
262+
},
263+
{
264+
options: []string{noResvPort},
265+
appendNoResvPortOption: true,
266+
appendActimeoOption: true,
267+
expected: []string{fmt.Sprintf("%s=%s", actimeo, defaultActimeo), noResvPort},
268+
},
269+
{
270+
options: []string{fmt.Sprintf("%s=%s", actimeo, "60")},
271+
appendNoResvPortOption: true,
272+
appendActimeoOption: true,
273+
expected: []string{fmt.Sprintf("%s=%s", actimeo, "60"), noResvPort},
274+
},
275+
}
276+
277+
for _, test := range tests {
278+
result := appendDefaultNfsMountOptions(test.options, test.appendNoResvPortOption, test.appendActimeoOption)
279+
sort.Strings(result)
280+
sort.Strings(test.expected)
281+
282+
if !reflect.DeepEqual(result, test.expected) {
283+
t.Errorf("input: %q, appendDefaultNfsMountOptions result: %q, expected: %q", test.options, result, test.expected)
240284
}
241285
}
242286
}

pkg/azurefile/nodeserver.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
286286
var mountOptions, sensitiveMountOptions []string
287287
if protocol == nfs {
288288
mountOptions = util.JoinMountOptions(mountFlags, []string{"vers=4,minorversion=1,sec=sys"})
289+
mountOptions = appendDefaultNfsMountOptions(mountOptions, d.appendNoResvPortOption, d.appendActimeoOption)
289290
} else {
290291
if accountName == "" || accountKey == "" {
291292
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
302303
if ephemeralVol {
303304
cifsMountFlags = util.JoinMountOptions(cifsMountFlags, strings.Split(ephemeralVolMountOptions, ","))
304305
}
305-
mountOptions = appendDefaultMountOptions(cifsMountFlags, d.appendNoShareSockOption, d.appendClosetimeoOption)
306+
mountOptions = appendDefaultCifsMountOptions(cifsMountFlags, d.appendNoShareSockOption, d.appendClosetimeoOption)
306307
}
307308
}
308309

pkg/azurefileplugin/main.go

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ var (
5959
enableWindowsHostProcess = flag.Bool("enable-windows-host-process", false, "enable windows host process")
6060
appendClosetimeoOption = flag.Bool("append-closetimeo-option", false, "Whether appending closetimeo=0 option to smb mount command")
6161
appendNoShareSockOption = flag.Bool("append-nosharesock-option", true, "Whether appending nosharesock option to smb mount command")
62+
appendNoResvPortOption = flag.Bool("append-noresvport-option", true, "Whether appending noresvport option to nfs mount command")
63+
appendActimeoOption = flag.Bool("append-actimeo-option", true, "Whether appending actimeo=0 option to nfs mount command")
6264
skipMatchingTagCacheExpireInMinutes = flag.Int("skip-matching-tag-cache-expire-in-minutes", 30, "The cache expire time in minutes for skipMatchingTagCache")
6365
volStatsCacheExpireInMinutes = flag.Int("vol-stats-cache-expire-in-minutes", 10, "The cache expire time in minutes for volume stats cache")
6466
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() {
107109
EnableWindowsHostProcess: *enableWindowsHostProcess,
108110
AppendClosetimeoOption: *appendClosetimeoOption,
109111
AppendNoShareSockOption: *appendNoShareSockOption,
112+
AppendNoResvPortOption: *appendNoResvPortOption,
113+
AppendActimeoOption: *appendActimeoOption,
110114
SkipMatchingTagCacheExpireInMinutes: *skipMatchingTagCacheExpireInMinutes,
111115
VolStatsCacheExpireInMinutes: *volStatsCacheExpireInMinutes,
112116
PrintVolumeStatsCallLogs: *printVolumeStatsCallLogs,

0 commit comments

Comments
 (0)