@@ -175,10 +175,18 @@ func setupCaching(devicePath string, req *csi.NodeStageVolumeRequest, nodeId str
175
175
klog .V (4 ).Infof ("Assuming valid data cache size and mode, resizing cache is not supported" )
176
176
} else {
177
177
cacheSize := req .GetPublishContext ()[common .ContextDataCacheSize ]
178
- chunkSize , err := fetchChunkSizeKiB (cacheSize )
178
+ maxChunkSizeStr := strconv .FormatInt (int64 (maxChunkSize / KiB ), 10 )
179
+ var chunkSize string
180
+ cachePvSize , err := fetchPvSizeGiB ()
179
181
if err != nil {
180
- klog .Errorf ("Errored to fetch cache size, verify the data-cache-size is valid: got %v, error: %q" , cacheSize , err )
181
- return mainDevicePath , err
182
+ klog .Errorf ("Errored while fetching PV size, got %v, falling back to default chunkSize of %v" , err , maxChunkSize )
183
+ chunkSize = maxChunkSizeStr
184
+ } else {
185
+ chunkSize , err = fetchChunkSizeKiB (cachePvSize )
186
+ if err != nil {
187
+ klog .Errorf ("Errored to fetch cache size, verify the data-cache-size is valid: got %v, error: %q" , chunkSize , err )
188
+ chunkSize = maxChunkSizeStr
189
+ }
182
190
}
183
191
// Check if LV exists
184
192
info , err = common .RunCommand ("" /* pipedCmd */ , nil /* pipedCmdArg */ , "lvs" , args ... )
@@ -642,7 +650,7 @@ func watchDiskDetaches(watcher *fsnotify.Watcher, nodeName string, errorCh chan
642
650
// In case of an event i.e. creation or deletion of any new PV, we update the VG metadata.
643
651
// This might include some non-LVM changes, no harm in updating metadata multiple times.
644
652
reduceVolumeGroup (getVolumeGroupName (nodeName ), true )
645
- klog .V (2 ).Infof ("disk attach/detach event %#v\n " , event )
653
+ klog .V (6 ).Infof ("disk attach/detach event %#v\n " , event )
646
654
}
647
655
}
648
656
}
@@ -674,3 +682,48 @@ func addRaidedLSSDToVg(vgName, lssdPath string) error {
674
682
}
675
683
return nil
676
684
}
685
+
686
+ func fetchPvSizeGiB () (string , error ) {
687
+ args := []string {
688
+ "--select" ,
689
+ "-o" ,
690
+ "--noheadings" ,
691
+ "pv_size" ,
692
+ "--units=b" ,
693
+ }
694
+ // RAIDed device is always registered with its /dev/md127 equivalent in VG so cannot check it directly based on the RAIDed LSSD path which could be /dev/md/csi-driver-data-cache
695
+ info , err := common .RunCommand ("grep" /* pipedCmd */ , []string {"/dev/md" } /* pipedCmdArg */ , "pvs" , args ... )
696
+ if err != nil {
697
+ return "" , fmt .Errorf ("errored while fetching PV size %v: %s" , err , info )
698
+ }
699
+ infoString := strings .TrimSpace (string (info ))
700
+ infoSlice := strings .Fields (infoString )
701
+ pvSize , err := fetchNumberGiB (infoSlice )
702
+ if err != nil {
703
+ return "" , fmt .Errorf ("Error fetching PV size for cache %v" , err )
704
+ }
705
+ return pvSize , nil
706
+
707
+ }
708
+
709
+ func fetchNumberGiB (infoSlice []string ) (string , error ) {
710
+ re , err := regexp .Compile ("^[0-9]+B$" )
711
+ if err != nil {
712
+ return "" , fmt .Errorf ("Failed to compile regex match %v" , err )
713
+ }
714
+ var pvSize string
715
+ for _ , i := range infoSlice {
716
+ if re .MatchString (i ) {
717
+ pvSize , err = strings .TrimSuffix (i , "B" ), nil
718
+ if err != nil {
719
+ return "" , fmt .Errorf ("Failed to extract PV size %v" , err )
720
+ }
721
+ break
722
+ }
723
+ }
724
+ pvSizeInt , err := strconv .ParseFloat (pvSize , 64 )
725
+ if err != nil {
726
+ return "" , fmt .Errorf ("Error while fetching PV size for cache %v" , err )
727
+ }
728
+ return strconv .FormatInt (int64 (math .Ceil (pvSizeInt / GiB )), 10 ) + "GiB" , nil
729
+ }
0 commit comments