diff --git a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java index da8d341e49b..c64f78fd01c 100644 --- a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java +++ b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java @@ -288,7 +288,7 @@ public class SnapshotObject implements SnapshotInfo { snapshotStore.setInstallPath(snapshotTO.getPath()); if (snapshotTO.getPhysicalSize() != null) { // For S3 delta snapshot, physical size is currently not set - snapshotStore.setSize(snapshotTO.getPhysicalSize()); + snapshotStore.setPhysicalSize(snapshotTO.getPhysicalSize()); } if (snapshotTO.getParentSnapshotPath() == null) { snapshotStore.setParentSnapshotId(0L); diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java index 82164ee06d8..fbce8609e6d 100644 --- a/engine/storage/src/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java @@ -116,6 +116,7 @@ public class ObjectInDataStoreManagerImpl implements ObjectInDataStoreManager { ss.setRole(dataStore.getRole()); ss.setVolumeId(snapshotInfo.getVolumeId()); ss.setSize(snapshotInfo.getSize()); // this is the virtual size of snapshot in primary storage. + ss.setPhysicalSize(snapshotInfo.getSize()); // this physical size will get updated with actual size once the snapshot backup is done. SnapshotDataStoreVO snapshotDataStoreVO = snapshotDataStoreDao.findParent(dataStore.getRole(), dataStore.getId(), snapshotInfo.getVolumeId()); if (snapshotDataStoreVO != null) { ss.setParentSnapshotId(snapshotDataStoreVO.getSnapshotId()); @@ -156,7 +157,7 @@ public class ObjectInDataStoreManagerImpl implements ObjectInDataStoreManager { ss.setSnapshotId(obj.getId()); ss.setDataStoreId(dataStore.getId()); ss.setRole(dataStore.getRole()); - ss.setRole(dataStore.getRole()); + ss.setSize(snapshot.getSize()); ss.setVolumeId(snapshot.getVolumeId()); SnapshotDataStoreVO snapshotDataStoreVO = snapshotDataStoreDao.findParent(dataStore.getRole(), dataStore.getId(), snapshot.getVolumeId()); if (snapshotDataStoreVO != null) { diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/Xenserver625StorageProcessor.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/Xenserver625StorageProcessor.java index f5310944a4e..20baffd6bf4 100644 --- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/Xenserver625StorageProcessor.java +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/Xenserver625StorageProcessor.java @@ -329,8 +329,8 @@ public class Xenserver625StorageProcessor extends XenServerStorageProcessor { } } } - String backupUuid = dvdi.getUuid(conn); - return backupUuid; + String result = dvdi.getUuid(conn).concat("#").concat(dvdi.getPhysicalUtilisation(conn).toString()); + return result; } catch (Exception e) { String msg = "Exception in backupsnapshot stage due to " + e.toString(); s_logger.debug(msg); @@ -392,6 +392,7 @@ public class Xenserver625StorageProcessor extends XenServerStorageProcessor { String details = null; String snapshotBackupUuid = null; boolean fullbackup = Boolean.parseBoolean(options.get("fullSnapshot")); + Long physicalSize = null; try { SR primaryStorageSR = hypervisorResource.getSRByNameLabelandHost(conn, primaryStorageNameLabel); if (primaryStorageSR == null) { @@ -431,6 +432,7 @@ public class Xenserver625StorageProcessor extends XenServerStorageProcessor { hypervisorResource.checkForSuccess(conn, task); VDI backedVdi = Types.toVDI(task, conn); snapshotBackupUuid = backedVdi.getUuid(conn); + physicalSize = backedVdi.getPhysicalUtilisation(conn); if( destStore instanceof SwiftTO) { try { @@ -488,9 +490,11 @@ public class Xenserver625StorageProcessor extends XenServerStorageProcessor { throw new CloudRuntimeException("S3 upload of snapshots " + snapshotPaUuid + " failed"); } } else { - snapshotBackupUuid = backupSnapshot(conn, primaryStorageSRUuid, localMountPoint, folder, + String result = backupSnapshot(conn, primaryStorageSRUuid, localMountPoint, folder, secondaryStorageMountPath, snapshotUuid, prevBackupUuid, prevSnapshotUuid, isISCSI, wait); - + String[] tmp = result.split("#"); + snapshotBackupUuid = tmp[0]; + physicalSize = Long.parseLong(tmp[1]); finalPath = folder + File.separator + snapshotBackupUuid; } } @@ -499,6 +503,7 @@ public class Xenserver625StorageProcessor extends XenServerStorageProcessor { SnapshotObjectTO newSnapshot = new SnapshotObjectTO(); newSnapshot.setPath(finalPath); + newSnapshot.setPhysicalSize(physicalSize); if (fullbackup) { newSnapshot.setParentSnapshotPath(null); } else { diff --git a/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java b/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java index d15b68a4560..fd348af7496 100755 --- a/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java +++ b/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java @@ -198,7 +198,7 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim templateSizeSearch.done(); snapshotSizeSearch = _snapshotDataStoreDao.createSearchBuilder(SumCount.class); - snapshotSizeSearch.select("sum", Func.SUM, snapshotSizeSearch.entity().getSize()); + snapshotSizeSearch.select("sum", Func.SUM, snapshotSizeSearch.entity().getPhysicalSize()); snapshotSizeSearch.and("state", snapshotSizeSearch.entity().getState(), Op.EQ); snapshotSizeSearch.and("storeRole", snapshotSizeSearch.entity().getRole(), Op.EQ); SearchBuilder join2 = _snapshotDao.createSearchBuilder(); diff --git a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java index 6d74636895e..369b42c8b41 100755 --- a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java +++ b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java @@ -434,7 +434,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager, if (snapshotCheck.getState() != Snapshot.State.Error && snapshotCheck.getState() != Snapshot.State.Destroyed) _resourceLimitMgr.decrementResourceCount(snapshotCheck.getAccountId(), ResourceType.snapshot); if (snapshotCheck.getState() == Snapshot.State.BackedUp) - _resourceLimitMgr.decrementResourceCount(snapshotCheck.getAccountId(), ResourceType.secondary_storage, new Long(snapshotStoreRef.getSize())); + _resourceLimitMgr.decrementResourceCount(snapshotCheck.getAccountId(), ResourceType.secondary_storage, new Long(snapshotStoreRef.getPhysicalSize())); } return result; } catch (Exception e) { @@ -624,7 +624,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager, if (Type.MANUAL == snapshot.getRecurringType()) { _resourceLimitMgr.decrementResourceCount(accountId, ResourceType.snapshot); if (snapshotStoreRef != null) { - _resourceLimitMgr.decrementResourceCount(accountId, ResourceType.secondary_storage, new Long(snapshotStoreRef.getSize())); + _resourceLimitMgr.decrementResourceCount(accountId, ResourceType.secondary_storage, new Long(snapshotStoreRef.getPhysicalSize())); } } @@ -973,11 +973,10 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager, try { postCreateSnapshot(volume.getId(), snapshotId, payload.getSnapshotPolicyId()); SnapshotDataStoreVO snapshotStoreRef = _snapshotStoreDao.findBySnapshot(snapshotId, DataStoreRole.Image); - // FIXME - snapshotStoreRef.getSize() refers to physical size, correct that UsageEventUtils.publishUsageEvent(EventTypes.EVENT_SNAPSHOT_CREATE, snapshot.getAccountId(), snapshot.getDataCenterId(), snapshotId, snapshot.getName(), - null, null, snapshotStoreRef.getSize(), volume.getSize(), snapshot.getClass().getName(), snapshot.getUuid()); + null, null, snapshotStoreRef.getPhysicalSize(), volume.getSize(), snapshot.getClass().getName(), snapshot.getUuid()); // Correct the resource count of snapshot in case of delta snapshots. - _resourceLimitMgr.decrementResourceCount(snapshotOwner.getId(), ResourceType.secondary_storage, new Long(volume.getSize() - snapshotStoreRef.getSize())); + _resourceLimitMgr.decrementResourceCount(snapshotOwner.getId(), ResourceType.secondary_storage, new Long(volume.getSize() - snapshotStoreRef.getPhysicalSize())); } catch (Exception e) { s_logger.debug("post process snapshot failed", e); }