@@ -124,12 +124,14 @@ const (
124
124
readAheadKBMountFlagRegexPattern = "^read_ahead_kb=(.+)$"
125
125
btrfsReclaimDataRegexPattern = "^btrfs-allocation-data-bg_reclaim_threshold=(\\ d{1,2})$" // 0-99 are valid, incl. 00
126
126
btrfsReclaimMetadataRegexPattern = "^btrfs-allocation-metadata-bg_reclaim_threshold=(\\ d{1,2})$" // ditto ^
127
+ btrfsReadAheadKBRegexPattern = "^btrfs-bdi-read_ahead_kb=(\\ d+)$"
127
128
)
128
129
129
130
var (
130
131
readAheadKBMountFlagRegex = regexp .MustCompile (readAheadKBMountFlagRegexPattern )
131
132
btrfsReclaimDataRegex = regexp .MustCompile (btrfsReclaimDataRegexPattern )
132
133
btrfsReclaimMetadataRegex = regexp .MustCompile (btrfsReclaimMetadataRegexPattern )
134
+ btrfsReadAheadKBRegex = regexp .MustCompile (btrfsReadAheadKBRegexPattern )
133
135
)
134
136
135
137
func getDefaultFsType () string {
@@ -402,7 +404,7 @@ func (ns *GCENodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStage
402
404
// Part 3: Mount device to stagingTargetPath
403
405
fstype := getDefaultFsType ()
404
406
405
- var btrfsReclaimData , btrfsReclaimMetadata string
407
+ var btrfsReclaimData , btrfsReclaimMetadata , btrfsReadAheadKb string
406
408
shouldUpdateReadAhead := false
407
409
var readAheadKB int64
408
410
options := []string {}
@@ -418,7 +420,7 @@ func (ns *GCENodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStage
418
420
}
419
421
420
422
if mnt .FsType == fsTypeBtrfs {
421
- btrfsReclaimData , btrfsReclaimMetadata = extractBtrfsReclaimFlags (mnt .MountFlags )
423
+ btrfsReclaimData , btrfsReclaimMetadata , btrfsReadAheadKb = extractBtrfsFlags (mnt .MountFlags )
422
424
}
423
425
} else if blk := volumeCapability .GetBlock (); blk != nil {
424
426
// Noop for Block NodeStageVolume
@@ -465,47 +467,52 @@ func (ns *GCENodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStage
465
467
}
466
468
}
467
469
468
- // Part 5: Update read_ahead
470
+ // Part 5: Update read_ahead for the block device
469
471
if shouldUpdateReadAhead {
470
472
if err := ns .updateReadAhead (devicePath , readAheadKB ); err != nil {
471
473
return nil , status .Errorf (codes .Internal , "failure updating readahead for %s to %dKB: %v" , devicePath , readAheadKB , err .Error ())
472
474
}
473
475
}
474
476
475
- // Part 6: if configured, write sysfs values
477
+ btrfsSysfs := map [string ]string {}
478
+
479
+ if btrfsReadAheadKb != "" {
480
+ btrfsSysfs ["bdi/read_ahead_kb" ] = btrfsReadAheadKb
481
+ }
482
+
476
483
if ! readonly {
477
- sysfs := map [string ]string {}
478
484
if btrfsReclaimData != "" {
479
- sysfs ["allocation/data/bg_reclaim_threshold" ] = btrfsReclaimData
485
+ btrfsSysfs ["allocation/data/bg_reclaim_threshold" ] = btrfsReclaimData
480
486
}
481
487
if btrfsReclaimMetadata != "" {
482
- sysfs ["allocation/metadata/bg_reclaim_threshold" ] = btrfsReclaimMetadata
483
- }
484
-
485
- if len (sysfs ) > 0 {
486
- args := []string {"--match-tag" , "UUID" , "--output" , "value" , stagingTargetPath }
487
- cmd := ns .Mounter .Exec .Command ("blkid" , args ... )
488
- var stderr bytes.Buffer
489
- cmd .SetStderr (& stderr )
490
- klog .V (4 ).Infof (
491
- "running %q for volume %s" ,
492
- strings .Join (append ([]string {"blkid" }, args ... ), " " ),
493
- volumeID ,
494
- )
495
- uuid , err := cmd .Output ()
496
- if err != nil {
497
- klog .Errorf ("blkid failed for %s. stderr:\n %s" , volumeID , stderr .String ())
498
- return nil , status .Errorf (codes .Internal , "blkid failed: %v" , err )
499
- }
500
- uuid = bytes .TrimRight (uuid , "\n " )
488
+ btrfsSysfs ["allocation/metadata/bg_reclaim_threshold" ] = btrfsReclaimMetadata
489
+ }
490
+ }
501
491
502
- for key , value := range sysfs {
503
- path := fmt .Sprintf ("%s/fs/btrfs/%s/%s" , ns .SysfsPath , uuid , key )
504
- if err := writeSysfs (path , value ); err != nil {
505
- return nil , status .Error (codes .Internal , err .Error ())
506
- }
507
- klog .V (4 ).Infof ("NodeStageVolume set %s %s=%s" , volumeID , key , value )
492
+ // Part 6: if configured, write sysfs values
493
+ if len (btrfsSysfs ) > 0 {
494
+ args := []string {"--match-tag" , "UUID" , "--output" , "value" , stagingTargetPath }
495
+ cmd := ns .Mounter .Exec .Command ("blkid" , args ... )
496
+ var stderr bytes.Buffer
497
+ cmd .SetStderr (& stderr )
498
+ klog .V (4 ).Infof (
499
+ "running %q for volume %s" ,
500
+ strings .Join (append ([]string {"blkid" }, args ... ), " " ),
501
+ volumeID ,
502
+ )
503
+ uuid , err := cmd .Output ()
504
+ if err != nil {
505
+ klog .Errorf ("blkid failed for %s. stderr:\n %s" , volumeID , stderr .String ())
506
+ return nil , status .Errorf (codes .Internal , "blkid failed: %v" , err )
507
+ }
508
+ uuid = bytes .TrimRight (uuid , "\n " )
509
+
510
+ for key , value := range btrfsSysfs {
511
+ path := fmt .Sprintf ("%s/fs/btrfs/%s/%s" , ns .SysfsPath , uuid , key )
512
+ if err := writeSysfs (path , value ); err != nil {
513
+ return nil , status .Error (codes .Internal , err .Error ())
508
514
}
515
+ klog .V (4 ).Infof ("NodeStageVolume set %s %s=%s" , volumeID , key , value )
509
516
}
510
517
}
511
518
@@ -526,7 +533,6 @@ func writeSysfs(path, value string) (_err error) {
526
533
if _ , err := f .Write ([]byte (value )); err != nil {
527
534
return err
528
535
}
529
-
530
536
return nil
531
537
}
532
538
@@ -546,16 +552,18 @@ func (ns *GCENodeServer) updateReadAhead(devicePath string, readAheadKB int64) e
546
552
return nil
547
553
}
548
554
549
- func extractBtrfsReclaimFlags (mountFlags []string ) (string , string ) {
550
- var reclaimData , reclaimMetadata string
555
+ func extractBtrfsFlags (mountFlags []string ) (string , string , string ) {
556
+ var reclaimData , reclaimMetadata , readAheadKb string
551
557
for _ , mountFlag := range mountFlags {
552
558
if got := btrfsReclaimDataRegex .FindStringSubmatch (mountFlag ); len (got ) == 2 {
553
559
reclaimData = got [1 ]
554
560
} else if got := btrfsReclaimMetadataRegex .FindStringSubmatch (mountFlag ); len (got ) == 2 {
555
561
reclaimMetadata = got [1 ]
562
+ } else if got := btrfsReadAheadKBRegex .FindStringSubmatch (mountFlag ); len (got ) == 2 {
563
+ readAheadKb = got [1 ]
556
564
}
557
565
}
558
- return reclaimData , reclaimMetadata
566
+ return reclaimData , reclaimMetadata , readAheadKb
559
567
}
560
568
561
569
func extractReadAheadKBMountFlag (mountFlags []string ) (int64 , bool , error ) {
0 commit comments