@@ -369,11 +369,17 @@ func cleanupCache(volumeId string, nodeId string) error {
369
369
370
370
volumeGroupName := getVolumeGroupName (nodeId )
371
371
if ! checkVgExists (volumeGroupName ) {
372
+ klog .V (4 ).Infof ("Volume group %s not found, no cache clean up needed" , volumeGroupName )
372
373
// If volume group doesn't exist then there's nothing to uncache
373
374
return nil
374
375
}
375
376
reduceVolumeGroup (volumeGroupName , true )
376
377
mainLvName := getLvName (mainLvSuffix , volumeId )
378
+ if ! checkLvExists (mainLvName ) {
379
+ klog .V (4 ).Infof ("Logical volume %s not found, assuming caching wasn't setup for the PVC %s or is cleaned up" , mainLvName , volumeId )
380
+ // If logical volume doesn't exist then there's nothing to uncache
381
+ return nil
382
+ }
377
383
args := []string {
378
384
"-an" ,
379
385
"/dev/" + volumeGroupName + "/" + mainLvName ,
@@ -394,6 +400,17 @@ func cleanupCache(volumeId string, nodeId string) error {
394
400
return nil
395
401
}
396
402
403
+ func checkLvExists (lvName string ) bool {
404
+ args := []string {}
405
+ info , err := common .RunCommand ("" /* pipedCmd */ , "" /* pipedCmdArg */ , "lvscan" , args ... )
406
+ if err != nil {
407
+ klog .Errorf ("Errored while checking if logical volume exists for %s %v: %s" , lvName , err , info )
408
+ return false
409
+ }
410
+ // Check if the required logical volume already exists
411
+ return strings .Contains (string (info ), lvName )
412
+ }
413
+
397
414
func getVolumeGroupName (nodePath string ) string {
398
415
nodeSlice := strings .Split (nodePath , "/" )
399
416
nodeId := nodeSlice [len (nodeSlice )- 1 ]
0 commit comments