@@ -370,11 +370,17 @@ func cleanupCache(volumeId string, nodeId string) error {
370370
371371 volumeGroupName := getVolumeGroupName (nodeId )
372372 if ! checkVgExists (volumeGroupName ) {
373+ klog .V (4 ).Infof ("Volume group %s not found, no cache clean up needed" , volumeGroupName )
373374 // If volume group doesn't exist then there's nothing to uncache
374375 return nil
375376 }
376377 reduceVolumeGroup (volumeGroupName , true )
377378 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+ }
378384 args := []string {
379385 "-an" ,
380386 "/dev/" + volumeGroupName + "/" + mainLvName ,
@@ -395,6 +401,17 @@ func cleanupCache(volumeId string, nodeId string) error {
395401 return nil
396402}
397403
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+
398415func getVolumeGroupName (nodePath string ) string {
399416 nodeSlice := strings .Split (nodePath , "/" )
400417 nodeId := nodeSlice [len (nodeSlice )- 1 ]
0 commit comments