fileMap.put(fileInfo.getKey(), fileInfo);
}
}
sizeDetail = new HashMap<DeviceId, DiskSize>();
size = new DiskSize(0);
if (fileLayout.getSnapshot() == null) {
logger.info("missing snapshot layout in " + vm);
return;
}
// search for the snapshot's files
for (SnapshotLayout snapshotLayout : fileLayout.getSnapshot()) {
if (getMoRef().equals(snapshotLayout.getKey())) {
// loop through each disk and count the last diskunit in the chain only
// because the previous ones are shared with the other snapshots so don't double counting
VirtualDevice[] devices = getConfig().getHardware().getDevice();
for(DiskLayout disk : snapshotLayout.getDisk()) {
VirtualDisk vdisk = (VirtualDisk)findDevice(devices, disk.getKey());
String diskMode = ((VirtualDisk.FlatVer2BackingInfo)vdisk.getBacking()).getDiskMode();
// independent disks are not included in snapshot
if (!diskMode.equals(DiskMode.independent_nonpersistent.name()) &&
!diskMode.equals(DiskMode.independent_persistent.name())) {
DiskUnit[] diskUnits = disk.getChain();
int[] fileKeys = diskUnits[diskUnits.length - 1].getFileKey();
// count the total of each file's size
long total = 0;
for (int fileKey : fileKeys) {
FileInfo fileInfo = fileMap.get(fileKey);
if (fileInfo != null) {
total += fileInfo.getSize();
}
}
// add up
size.add(total);
DeviceId deviceId =
new DeviceId(findDevice(devices, vdisk.getControllerKey()), vdisk);
sizeDetail.put(deviceId, new DiskSize(total));
}
}
// add vmsn file size which is always on data storage
FileInfo fileInfo = fileMap.get(snapshotLayout.getDataKey());
if (fileInfo != null) {
size.add(fileInfo.getSize());
vmsnFileSize = new DiskSize(fileInfo.getSize());
}
return;
}
}
// no matching file layout for this snapshot?