@@ -121,19 +121,31 @@ const (
121121 fsTypeExt3 = "ext3"
122122 fsTypeBtrfs = "btrfs"
123123
124- readAheadKBMountFlagRegexPattern = "^read_ahead_kb=(.+)$"
125- btrfsReclaimDataRegexPattern = "^btrfs-allocation-data-bg_reclaim_threshold=(\\ d{1,2})$" // 0-99 are valid, incl. 00
126- btrfsReclaimMetadataRegexPattern = "^btrfs-allocation-metadata-bg_reclaim_threshold=(\\ d{1,2})$" // ditto ^
127- btrfsReadAheadKBRegexPattern = "^btrfs-bdi-read_ahead_kb=(\\ d+)$"
124+ readAheadKBMountFlagRegexPattern = "^read_ahead_kb=(.+)$"
125+ btrfsReclaimDataRegexPattern = "^btrfs-allocation-data-bg_reclaim_threshold=(\\ d{1,2})$" // 0-99 are valid, incl. 00
126+ btrfsReclaimMetadataRegexPattern = "^btrfs-allocation-metadata-bg_reclaim_threshold=(\\ d{1,2})$" // ditto ^
127+ btrfsDynamicReclaimDataRegexPattern = "^btrfs-allocation-data-dynamic_reclaim=(0|1)$" // boolean in kernel, so accepting 0 or 1
128+ btrfsDynamicReclaimMetadataRegexPattern = "^btrfs-allocation-metadata-dynamic_reclaim=(0|1)$" // ditto ^
129+ btrfsReadAheadKBRegexPattern = "^btrfs-bdi-read_ahead_kb=(\\ d+)$"
128130)
129131
130132var (
131- readAheadKBMountFlagRegex = regexp .MustCompile (readAheadKBMountFlagRegexPattern )
132- btrfsReclaimDataRegex = regexp .MustCompile (btrfsReclaimDataRegexPattern )
133- btrfsReclaimMetadataRegex = regexp .MustCompile (btrfsReclaimMetadataRegexPattern )
134- btrfsReadAheadKBRegex = regexp .MustCompile (btrfsReadAheadKBRegexPattern )
133+ readAheadKBMountFlagRegex = regexp .MustCompile (readAheadKBMountFlagRegexPattern )
134+ btrfsReclaimDataRegex = regexp .MustCompile (btrfsReclaimDataRegexPattern )
135+ btrfsReclaimMetadataRegex = regexp .MustCompile (btrfsReclaimMetadataRegexPattern )
136+ btrfsDynamicReclaimDataRegex = regexp .MustCompile (btrfsDynamicReclaimDataRegexPattern )
137+ btrfsDynamicReclaimMetadataRegex = regexp .MustCompile (btrfsDynamicReclaimMetadataRegexPattern )
138+ btrfsReadAheadKBRegex = regexp .MustCompile (btrfsReadAheadKBRegexPattern )
135139)
136140
141+ type btrfsFlags struct {
142+ reclaimData ,
143+ reclaimMetadata ,
144+ dynamicReclaimData ,
145+ dynamicReclaimMetadata ,
146+ readAheadKb string
147+ }
148+
137149func getDefaultFsType () string {
138150 if runtime .GOOS == "windows" {
139151 return defaultWindowsFsType
@@ -404,7 +416,7 @@ func (ns *GCENodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStage
404416 // Part 3: Mount device to stagingTargetPath
405417 fstype := getDefaultFsType ()
406418
407- var btrfsReclaimData , btrfsReclaimMetadata , btrfsReadAheadKb string
419+ var btrfsFlags btrfsFlags
408420 shouldUpdateReadAhead := false
409421 var readAheadKB int64
410422 options := []string {}
@@ -420,7 +432,7 @@ func (ns *GCENodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStage
420432 }
421433
422434 if mnt .FsType == fsTypeBtrfs {
423- btrfsReclaimData , btrfsReclaimMetadata , btrfsReadAheadKb = extractBtrfsFlags (mnt .MountFlags )
435+ btrfsFlags = extractBtrfsFlags (mnt .MountFlags )
424436 }
425437 } else if blk := volumeCapability .GetBlock (); blk != nil {
426438 // Noop for Block NodeStageVolume
@@ -476,16 +488,22 @@ func (ns *GCENodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStage
476488
477489 btrfsSysfs := map [string ]string {}
478490
479- if btrfsReadAheadKb != "" {
480- btrfsSysfs ["bdi/read_ahead_kb" ] = btrfsReadAheadKb
491+ if btrfsFlags . readAheadKb != "" {
492+ btrfsSysfs ["bdi/read_ahead_kb" ] = btrfsFlags . readAheadKb
481493 }
482494
483495 if ! readonly {
484- if btrfsReclaimData != "" {
485- btrfsSysfs ["allocation/data/bg_reclaim_threshold" ] = btrfsReclaimData
496+ if btrfsFlags .reclaimData != "" {
497+ btrfsSysfs ["allocation/data/bg_reclaim_threshold" ] = btrfsFlags .reclaimData
498+ }
499+ if btrfsFlags .reclaimMetadata != "" {
500+ btrfsSysfs ["allocation/metadata/bg_reclaim_threshold" ] = btrfsFlags .reclaimMetadata
501+ }
502+ if btrfsFlags .dynamicReclaimData != "" {
503+ btrfsSysfs ["allocation/data/dynamic_reclaim" ] = btrfsFlags .dynamicReclaimData
486504 }
487- if btrfsReclaimMetadata != "" {
488- btrfsSysfs ["allocation/metadata/bg_reclaim_threshold " ] = btrfsReclaimMetadata
505+ if btrfsFlags . dynamicReclaimMetadata != "" {
506+ btrfsSysfs ["allocation/metadata/dynamic_reclaim " ] = btrfsFlags . dynamicReclaimMetadata
489507 }
490508 }
491509
@@ -552,18 +570,22 @@ func (ns *GCENodeServer) updateReadAhead(devicePath string, readAheadKB int64) e
552570 return nil
553571}
554572
555- func extractBtrfsFlags (mountFlags []string ) ( string , string , string ) {
556- var reclaimData , reclaimMetadata , readAheadKb string
573+ func extractBtrfsFlags (mountFlags []string ) btrfsFlags {
574+ var flags btrfsFlags
557575 for _ , mountFlag := range mountFlags {
558576 if got := btrfsReclaimDataRegex .FindStringSubmatch (mountFlag ); len (got ) == 2 {
559- reclaimData = got [1 ]
577+ flags . reclaimData = got [1 ]
560578 } else if got := btrfsReclaimMetadataRegex .FindStringSubmatch (mountFlag ); len (got ) == 2 {
561- reclaimMetadata = got [1 ]
579+ flags . reclaimMetadata = got [1 ]
562580 } else if got := btrfsReadAheadKBRegex .FindStringSubmatch (mountFlag ); len (got ) == 2 {
563- readAheadKb = got [1 ]
581+ flags .readAheadKb = got [1 ]
582+ } else if got := btrfsDynamicReclaimDataRegex .FindStringSubmatch (mountFlag ); len (got ) == 2 {
583+ flags .dynamicReclaimData = got [1 ]
584+ } else if got := btrfsDynamicReclaimMetadataRegex .FindStringSubmatch (mountFlag ); len (got ) == 2 {
585+ flags .dynamicReclaimMetadata = got [1 ]
564586 }
565587 }
566- return reclaimData , reclaimMetadata , readAheadKb
588+ return flags
567589}
568590
569591func extractReadAheadKBMountFlag (mountFlags []string ) (int64 , bool , error ) {
0 commit comments