@@ -121,19 +121,31 @@ const (
121
121
fsTypeExt3 = "ext3"
122
122
fsTypeBtrfs = "btrfs"
123
123
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+)$"
128
130
)
129
131
130
132
var (
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 )
135
139
)
136
140
141
+ type btrfsFlags struct {
142
+ reclaimData ,
143
+ reclaimMetadata ,
144
+ dynamicReclaimData ,
145
+ dynamicReclaimMetadata ,
146
+ readAheadKb string
147
+ }
148
+
137
149
func getDefaultFsType () string {
138
150
if runtime .GOOS == "windows" {
139
151
return defaultWindowsFsType
@@ -404,7 +416,7 @@ func (ns *GCENodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStage
404
416
// Part 3: Mount device to stagingTargetPath
405
417
fstype := getDefaultFsType ()
406
418
407
- var btrfsReclaimData , btrfsReclaimMetadata , btrfsReadAheadKb string
419
+ var btrfsFlags btrfsFlags
408
420
shouldUpdateReadAhead := false
409
421
var readAheadKB int64
410
422
options := []string {}
@@ -420,7 +432,7 @@ func (ns *GCENodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStage
420
432
}
421
433
422
434
if mnt .FsType == fsTypeBtrfs {
423
- btrfsReclaimData , btrfsReclaimMetadata , btrfsReadAheadKb = extractBtrfsFlags (mnt .MountFlags )
435
+ btrfsFlags = extractBtrfsFlags (mnt .MountFlags )
424
436
}
425
437
} else if blk := volumeCapability .GetBlock (); blk != nil {
426
438
// Noop for Block NodeStageVolume
@@ -476,16 +488,22 @@ func (ns *GCENodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStage
476
488
477
489
btrfsSysfs := map [string ]string {}
478
490
479
- if btrfsReadAheadKb != "" {
480
- btrfsSysfs ["bdi/read_ahead_kb" ] = btrfsReadAheadKb
491
+ if btrfsFlags . readAheadKb != "" {
492
+ btrfsSysfs ["bdi/read_ahead_kb" ] = btrfsFlags . readAheadKb
481
493
}
482
494
483
495
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
486
504
}
487
- if btrfsReclaimMetadata != "" {
488
- btrfsSysfs ["allocation/metadata/bg_reclaim_threshold " ] = btrfsReclaimMetadata
505
+ if btrfsFlags . dynamicReclaimMetadata != "" {
506
+ btrfsSysfs ["allocation/metadata/dynamic_reclaim " ] = btrfsFlags . dynamicReclaimMetadata
489
507
}
490
508
}
491
509
@@ -552,18 +570,22 @@ func (ns *GCENodeServer) updateReadAhead(devicePath string, readAheadKB int64) e
552
570
return nil
553
571
}
554
572
555
- func extractBtrfsFlags (mountFlags []string ) ( string , string , string ) {
556
- var reclaimData , reclaimMetadata , readAheadKb string
573
+ func extractBtrfsFlags (mountFlags []string ) btrfsFlags {
574
+ var flags btrfsFlags
557
575
for _ , mountFlag := range mountFlags {
558
576
if got := btrfsReclaimDataRegex .FindStringSubmatch (mountFlag ); len (got ) == 2 {
559
- reclaimData = got [1 ]
577
+ flags . reclaimData = got [1 ]
560
578
} else if got := btrfsReclaimMetadataRegex .FindStringSubmatch (mountFlag ); len (got ) == 2 {
561
- reclaimMetadata = got [1 ]
579
+ flags . reclaimMetadata = got [1 ]
562
580
} 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 ]
564
586
}
565
587
}
566
- return reclaimData , reclaimMetadata , readAheadKb
588
+ return flags
567
589
}
568
590
569
591
func extractReadAheadKBMountFlag (mountFlags []string ) (int64 , bool , error ) {
0 commit comments