@@ -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 .FormatFloat (maxChunkSize , 'g' , - 1 , 64 )
179
+ var chunkSize string
180
+ cachePvSize , err := fetchPvSize (raidedLocalSsdPath )
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 ... )
@@ -639,6 +647,21 @@ func watchDiskDetaches(watcher *fsnotify.Watcher, nodeName string, errorCh chan
639
647
errorCh <- fmt .Errorf ("disk update event errored: %v" , err )
640
648
// watch for events
641
649
case event := <- watcher .Events :
650
+ args := []string {
651
+ "--updatemetadata" ,
652
+ getVolumeGroupName (nodeName ),
653
+ }
654
+ _ , err := common .RunCommand ("" /* pipedCmd */ , nil /* pipedCmdArg */ , "vgck" , args ... )
655
+ if err != nil {
656
+ klog .Errorf ("Error updating volume group's metadata: %v" , err )
657
+ }
658
+ args = []string {}
659
+ info , _ := common .RunCommand ("" /* pipedCmd */ , nil /* pipedCmdArg */ , "pvs" , args ... )
660
+ args = []string {
661
+ getVolumeGroupName (nodeName ),
662
+ }
663
+ infoVG , _ := common .RunCommand ("" /* pipedCmd */ , nil /* pipedCmdArg */ , "vgdisplay" , args ... )
664
+ klog .Infof ("Got VG %s and PV %s" , infoVG , info )
642
665
// In case of an event i.e. creation or deletion of any new PV, we update the VG metadata.
643
666
// This might include some non-LVM changes, no harm in updating metadata multiple times.
644
667
reduceVolumeGroup (getVolumeGroupName (nodeName ), true )
@@ -674,3 +697,39 @@ func addRaidedLSSDToVg(vgName, lssdPath string) error {
674
697
}
675
698
return nil
676
699
}
700
+
701
+ func fetchPvSize (pvName string ) (string , error ) {
702
+ var pvSize string
703
+ args := []string {
704
+ "--select" ,
705
+ "pv_name=" + pvName ,
706
+ "-o" ,
707
+ "--noheadings" ,
708
+ "pv_size" ,
709
+ "--units=b" ,
710
+ }
711
+ info , err := common .RunCommand ("" /* pipedCmd */ , nil /* pipedCmdArg */ , "pvs" , args ... )
712
+ if err != nil {
713
+ return "" , fmt .Errorf ("errored while fetching PV size %v: %s" , err , info )
714
+ }
715
+ infoString := strings .TrimSpace (string (info ))
716
+ infoSlice := strings .Fields (infoString )
717
+ re , err := regexp .Compile ("^[0-9]+B$" )
718
+ if err != nil {
719
+ return "" , fmt .Errorf ("Errored while compiling regex for PV size" )
720
+ }
721
+ for _ , i := range infoSlice {
722
+ if re .MatchString (i ) {
723
+ pvSize = strings .TrimSuffix (i , "B" )
724
+ break
725
+ }
726
+ }
727
+ if pvSize != "" {
728
+ pvSizeInt , err := strconv .ParseFloat (pvSize , 64 )
729
+ if err != nil {
730
+ return "" , fmt .Errorf ("Error while fetching PV size for cache" )
731
+ }
732
+ return strconv .FormatInt (int64 (pvSizeInt / KiB ), 10 ) + "KiB" , nil
733
+ }
734
+ return "" , fmt .Errorf ("Error fetching PV size for cache" )
735
+ }
0 commit comments