fixed NPE on calculating vm snasphot volume size

(cherry picked from commit 95c7ffbd46)
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
Anthony Xu 2014-10-13 10:29:58 -07:00 committed by Rohit Yadav
parent 86fe713ab9
commit 64e938b701
1 changed files with 10 additions and 6 deletions

View File

@ -6232,11 +6232,11 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
// add size of snapshot vdi node, usually this only contains meta data
size = size + vdi.getPhysicalUtilisation(conn);
// add size of snapshot vdi parent, this contains data
if (parentVDI != null)
if (!isRefNull(parentVDI))
size = size + parentVDI.getPhysicalUtilisation(conn).longValue();
}
} catch (Exception e) {
s_logger.debug("Exception occurs when calculate " + "snapshot capacity for volumes: " + e.getMessage());
s_logger.debug("Exception occurs when calculate snapshot capacity for volumes: due to " + e.toString());
continue;
}
}
@ -6248,13 +6248,17 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
try {
String vName = vmr.getNameLabel(conn);
if (vName != null && vName.contains(vmName) && vmr.getIsASnapshot(conn)) {
VDI memoryVDI = vmr.getSuspendVDI(conn);
size = size + memoryVDI.getParent(conn).getPhysicalUtilisation(conn);
size = size + memoryVDI.getPhysicalUtilisation(conn);
if (!isRefNull(memoryVDI)) {
size = size + memoryVDI.getPhysicalUtilisation(conn);
VDI pMemoryVDI = memoryVDI.getParent(conn);
if (!isRefNull(pMemoryVDI)) {
size = size + pMemoryVDI.getPhysicalUtilisation(conn);
}
}
}
} catch (Exception e) {
s_logger.debug("Exception occurs when calculate " + "snapshot capacity for memory: " + e.getMessage());
s_logger.debug("Exception occurs when calculate snapshot capacity for memory: due to " + e.toString());
continue;
}
}