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