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