@@ -217,10 +217,16 @@ func cleanupCache(volumeId string, nodeId string) error {
217
217
218
218
volumeGroupName := getVolumeGroupName (nodeId )
219
219
if ! checkVgExists (volumeGroupName ) {
220
+ klog .V (4 ).Infof ("Volume group %s not found, no cache clean up needed" , volumeGroupName )
220
221
// If volume group doesn't exist then there's nothing to uncache
221
222
return nil
222
223
}
223
224
mainLvName := getLvName (mainLvSuffix , volumeId )
225
+ if ! checkLvExists (mainLvName ) {
226
+ klog .V (4 ).Infof ("Logical volume %s not found, assuming caching wasn't setup for the PVC %s or is cleaned up" , mainLvName , volumeId )
227
+ // If logical volume doesn't exist then there's nothing to uncache
228
+ return nil
229
+ }
224
230
args := []string {
225
231
"-an" ,
226
232
"/dev/" + volumeGroupName + "/" + mainLvName ,
@@ -241,6 +247,17 @@ func cleanupCache(volumeId string, nodeId string) error {
241
247
return nil
242
248
}
243
249
250
+ func checkLvExists (lvName string ) bool {
251
+ args := []string {}
252
+ info , err := common .RunCommand ("" /* pipedCmd */ , "" /* pipedCmdArg */ , "lvscan" , args ... )
253
+ if err != nil {
254
+ klog .Errorf ("Errored while checking if logical volume exists for %s %v: %s" , lvName , err , info )
255
+ return false
256
+ }
257
+ // Check if the required logical volume already exists
258
+ return strings .Contains (string (info ), lvName )
259
+ }
260
+
244
261
func getVolumeGroupName (nodePath string ) string {
245
262
nodeSlice := strings .Split (nodePath , "/" )
246
263
nodeId := nodeSlice [len (nodeSlice )- 1 ]
0 commit comments