Skip to content

Commit 3ad0e8f

Browse files
CLOUDSTACK-5701: physical size is not getting updated in snapshot_store_ref table.
1 parent e5283e9 commit 3ad0e8f

5 files changed

Lines changed: 45 additions & 4 deletions

File tree

core/src/org/apache/cloudstack/storage/to/SnapshotObjectTO.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class SnapshotObjectTO implements DataTO {
3838
private long id;
3939
private boolean quiescevm;
4040
private String[] parents;
41+
private Long physicalSize = (long) 0;
4142

4243

4344
public SnapshotObjectTO() {
@@ -94,6 +95,14 @@ public void setPath(String path) {
9495
this.path = path;
9596
}
9697

98+
public Long getPhysicalSize() {
99+
return this.physicalSize;
100+
}
101+
102+
public void setPhysicalSize(Long physicalSize ) {
103+
this.physicalSize = physicalSize;
104+
}
105+
97106
public VolumeObjectTO getVolume() {
98107
return volume;
99108
}

engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ public void processEvent(ObjectInDataStoreStateMachine.Event event, Answer answe
278278
} else if (answer instanceof CopyCmdAnswer) {
279279
SnapshotObjectTO snapshotTO = (SnapshotObjectTO)((CopyCmdAnswer)answer).getNewData();
280280
snapshotStore.setInstallPath(snapshotTO.getPath());
281+
snapshotStore.setSize(snapshotTO.getPhysicalSize());
281282
if (snapshotTO.getParentSnapshotPath() == null) {
282283
snapshotStore.setParentSnapshotId(0L);
283284
}

engine/storage/src/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public DataObject create(DataObject obj, DataStore dataStore) {
115115
ss.setDataStoreId(dataStore.getId());
116116
ss.setRole(dataStore.getRole());
117117
ss.setVolumeId(snapshotInfo.getVolumeId());
118+
ss.setSize(snapshotInfo.getSize()); // this is the virtual size of snapshot in primary storage.
118119
SnapshotDataStoreVO snapshotDataStoreVO = snapshotDataStoreDao.findParent(dataStore.getRole(), dataStore.getId(), snapshotInfo.getVolumeId());
119120
if (snapshotDataStoreVO != null) {
120121
ss.setParentSnapshotId(snapshotDataStoreVO.getSnapshotId());

plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServerStorageProcessor.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,16 @@ protected String backupSnapshotToS3(final Connection connection, final S3TO s3,
11041104

11051105
}
11061106

1107+
protected Long getSnapshotSize(Connection conn, String primaryStorageSRUuid, String snapshotUuid, Boolean isISCSI, int wait) {
1108+
String physicalSize = hypervisorResource.callHostPluginAsync(conn, "vmopsSnapshot", "getSnapshotSize", wait,
1109+
"primaryStorageSRUuid", primaryStorageSRUuid, "snapshotUuid", snapshotUuid, "isISCSI", isISCSI.toString());
1110+
if (physicalSize == null || physicalSize.isEmpty()) {
1111+
return (long) 0;
1112+
} else {
1113+
return Long.parseLong(physicalSize);
1114+
}
1115+
}
1116+
11071117
protected String backupSnapshot(Connection conn, String primaryStorageSRUuid, String localMountPoint, String path, String secondaryStorageMountPath,
11081118
String snapshotUuid, String prevBackupUuid, Boolean isISCSI, int wait) {
11091119
String backupSnapshotUuid = null;
@@ -1134,7 +1144,7 @@ protected String backupSnapshot(Connection conn, String primaryStorageSRUuid, St
11341144
// indicator of success.
11351145
if (status != null && status.equalsIgnoreCase("1") && backupSnapshotUuid != null) {
11361146
s_logger.debug("Successfully copied backupUuid: " + backupSnapshotUuid + " to secondary storage");
1137-
return backupSnapshotUuid;
1147+
return results;
11381148
} else {
11391149
errMsg =
11401150
"Could not copy backupUuid: " + backupSnapshotUuid + " from primary storage " + primaryStorageSRUuid + " to secondary storage " +
@@ -1230,6 +1240,7 @@ public Answer backupSnapshot(CopyCommand cmd) {
12301240
String details = null;
12311241
String snapshotBackupUuid = null;
12321242
boolean fullbackup = true;
1243+
Long physicalSize = null;
12331244
try {
12341245
SR primaryStorageSR = hypervisorResource.getSRByNameLabelandHost(conn, primaryStorageNameLabel);
12351246
if (primaryStorageSR == null) {
@@ -1276,6 +1287,8 @@ public Answer backupSnapshot(CopyCommand cmd) {
12761287
snapshotSr = hypervisorResource.createNfsSRbyURI(conn, new URI(snapshotMountpoint), false);
12771288
VDI backedVdi = hypervisorResource.cloudVDIcopy(conn, snapshotVdi, snapshotSr, wait);
12781289
snapshotBackupUuid = backedVdi.getUuid(conn);
1290+
String primarySRuuid = snapshotSr.getUuid(conn);
1291+
physicalSize = getSnapshotSize(conn, primarySRuuid, snapshotBackupUuid, isISCSI, wait);
12791292

12801293
if (destStore instanceof SwiftTO) {
12811294
try {
@@ -1328,9 +1341,12 @@ public Answer backupSnapshot(CopyCommand cmd) {
13281341
throw new CloudRuntimeException("S3 upload of snapshots " + snapshotPaUuid + " failed");
13291342
}
13301343
} else {
1331-
snapshotBackupUuid =
1344+
String results =
13321345
backupSnapshot(conn, primaryStorageSRUuid, localMountPoint, folder, secondaryStorageMountPath, snapshotUuid, prevBackupUuid, isISCSI, wait);
13331346

1347+
String[] tmp = results.split("#");
1348+
snapshotBackupUuid = tmp[1];
1349+
physicalSize = Long.parseLong(tmp[2]);
13341350
finalPath = folder + File.separator + snapshotBackupUuid;
13351351
}
13361352
}
@@ -1339,6 +1355,7 @@ public Answer backupSnapshot(CopyCommand cmd) {
13391355

13401356
SnapshotObjectTO newSnapshot = new SnapshotObjectTO();
13411357
newSnapshot.setPath(finalPath);
1358+
newSnapshot.setPhysicalSize(physicalSize);
13421359
if (fullbackup) {
13431360
newSnapshot.setParentSnapshotPath(null);
13441361
} else {

scripts/vm/hypervisor/xenserver/vmopsSnapshot

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,18 @@ def getVhdParent(session, args):
487487

488488
return baseCopyUuid
489489

490+
def getSnapshotSize(session, args):
491+
primaryStorageSRUuid = args['primaryStorageSRUuid']
492+
snapshotUuid = args['snapshotUuid']
493+
isISCSI = getIsTrueString(args['isISCSI'])
494+
495+
primarySRPath = getPrimarySRPath(primaryStorageSRUuid, isISCSI)
496+
logging.debug("primarySRPath: " + primarySRPath)
497+
498+
snapshotVHD = getVHD(snapshotUuid, isISCSI)
499+
snapshotPath = os.path.join(primarySRPath, snapshotVHD)
500+
physicalSize = vhdutil.getSizePhys(snapshotPath)
501+
return str(physicalSize)
490502

491503
def backupSnapshot(session, args):
492504
logging.debug("Called backupSnapshot with " + str(args))
@@ -515,6 +527,7 @@ def backupSnapshot(session, args):
515527
prevBackupUuid = prevBackupUuid.split("/")[-1]
516528
# Check existence of snapshot on primary storage
517529
isfile(baseCopyPath, isISCSI)
530+
physicalSize = vhdutil.getSizePhys(baseCopyPath)
518531
if prevBackupUuid:
519532
# Check existence of prevBackupFile
520533
prevBackupVHD = getBackupVHD(prevBackupUuid)
@@ -535,7 +548,7 @@ def backupSnapshot(session, args):
535548
# If there was a previous snapshot
536549
setParent(prevBackupFile, backupFile)
537550

538-
txt = "1#" + backupUuid
551+
txt = "1#" + backupUuid + "#" + str(physicalSize)
539552
return txt
540553

541554
@echo
@@ -596,6 +609,6 @@ def revert_memory_snapshot(session, args):
596609
return "0"
597610

598611
if __name__ == "__main__":
599-
XenAPIPlugin.dispatch({"getVhdParent":getVhdParent, "create_secondary_storage_folder":create_secondary_storage_folder, "delete_secondary_storage_folder":delete_secondary_storage_folder, "post_create_private_template":post_create_private_template, "backupSnapshot": backupSnapshot, "deleteSnapshotBackup": deleteSnapshotBackup, "unmountSnapshotsDir": unmountSnapshotsDir, "revert_memory_snapshot":revert_memory_snapshot})
612+
XenAPIPlugin.dispatch({"getVhdParent":getVhdParent, "create_secondary_storage_folder":create_secondary_storage_folder, "delete_secondary_storage_folder":delete_secondary_storage_folder, "post_create_private_template":post_create_private_template, "backupSnapshot": backupSnapshot, "deleteSnapshotBackup": deleteSnapshotBackup, "unmountSnapshotsDir": unmountSnapshotsDir, "revert_memory_snapshot":revert_memory_snapshot, "getSnapshotSize":getSnapshotSize})
600613

601614

0 commit comments

Comments
 (0)