Skip to content

Commit 4e1cdf2

Browse files
committed
skip cache clean up for non-data cache PVCs
1 parent d35496c commit 4e1cdf2

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pkg/gce-pd-csi-driver/cache.go

+17
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,16 @@ func cleanupCache(volumeId string, nodeId string) error {
217217

218218
volumeGroupName := getVolumeGroupName(nodeId)
219219
if !checkVgExists(volumeGroupName) {
220+
klog.V(4).Infof("Volume group %s not found, no cache clean up needed", volumeGroupName)
220221
// If volume group doesn't exist then there's nothing to uncache
221222
return nil
222223
}
223224
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+
}
224230
args := []string{
225231
"-an",
226232
"/dev/" + volumeGroupName + "/" + mainLvName,
@@ -241,6 +247,17 @@ func cleanupCache(volumeId string, nodeId string) error {
241247
return nil
242248
}
243249

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+
244261
func getVolumeGroupName(nodePath string) string {
245262
nodeSlice := strings.Split(nodePath, "/")
246263
nodeId := nodeSlice[len(nodeSlice)-1]

0 commit comments

Comments
 (0)