Skip to content

Fix hv_ss_reserve value for volumes on migration #6078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions api/src/main/java/com/cloud/vm/DiskProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class DiskProfile {
private String cacheMode;
private Long minIops;
private Long maxIops;
private Long newDiskOfferingId;
private boolean requiresEncryption;

private HypervisorType hyperType;
Expand Down Expand Up @@ -254,6 +255,13 @@ public void setMaxIops(Long maxIops) {
this.maxIops = maxIops;
}

public Long getNewDiskOfferingId() {
return newDiskOfferingId;
}

public void setNewDiskOfferingId(Long newDiskOfferingId) {
this.newDiskOfferingId = newDiskOfferingId;
}
public boolean requiresEncryption() { return requiresEncryption; }

public void setEncryption(boolean encrypt) { this.requiresEncryption = encrypt; }
Expand Down
10 changes: 6 additions & 4 deletions server/src/main/java/com/cloud/storage/StorageManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2427,10 +2427,12 @@ public boolean storagePoolHasEnoughSpace(List<Pair<Volume, DiskProfile>> volumeD
Volume volume = volumeDiskProfilePair.first();
DiskProfile diskProfile = volumeDiskProfilePair.second();
VolumeVO volumeVO = _volumeDao.findById(volume.getId());
Long newDiskOfferingId = diskProfile.getNewDiskOfferingId();

if (volumeVO.getHypervisorSnapshotReserve() == null) {
if (volumeVO.getHypervisorSnapshotReserve() == null || volumeVO.getHypervisorSnapshotReserve() == 0) {
// update the volume's hv_ss_reserve (hypervisor snapshot reserve) from a disk offering (used for managed storage)
volService.updateHypervisorSnapshotReserveForVolume(getDiskOfferingVO(volumeVO), volumeVO.getId(), getHypervisorType(volumeVO));
volService.updateHypervisorSnapshotReserveForVolume(getDiskOfferingForSnapshotReserve(volumeVO, newDiskOfferingId),
volumeVO.getId(), getHypervisorType(volumeVO));

// hv_ss_reserve field might have been updated; refresh from DB to make use of it in getDataObjectSizeIncludingHypervisorSnapshotReserve
volumeVO = _volumeDao.findById(volume.getId());
Expand Down Expand Up @@ -2630,8 +2632,8 @@ private long getDataObjectSizeIncludingHypervisorSnapshotReserve(Volume volume,
return volume.getSize();
}

private DiskOfferingVO getDiskOfferingVO(Volume volume) {
Long diskOfferingId = volume.getDiskOfferingId();
private DiskOfferingVO getDiskOfferingForSnapshotReserve(Volume volume, Long newDiskOfferingId) {
Long diskOfferingId = newDiskOfferingId == null ? volume.getDiskOfferingId() : newDiskOfferingId;

return _diskOfferingDao.findById(diskOfferingId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3081,8 +3081,10 @@ public Volume migrateVolume(MigrateVolumeCmd cmd) {
throw new CloudRuntimeException("Storage pool " + destPool.getName() + " is not suitable to migrate volume " + vol.getName());
}

DiskOfferingVO newDiskOffering = retrieveAndValidateNewDiskOffering(cmd);
HypervisorType hypervisorType = _volsDao.getHypervisorType(volumeId);
DiskProfile diskProfile = new DiskProfile(vol, diskOffering, hypervisorType);
diskProfile.setNewDiskOfferingId(newDiskOffering.getId());
Pair<Volume, DiskProfile> volumeDiskProfilePair = new Pair<>(vol, diskProfile);
if (!storageMgr.storagePoolHasEnoughSpace(Collections.singletonList(volumeDiskProfilePair), destPool)) {
throw new CloudRuntimeException("Storage pool " + destPool.getName() + " does not have enough space to migrate volume " + vol.getName());
Expand Down Expand Up @@ -3127,7 +3129,6 @@ public Volume migrateVolume(MigrateVolumeCmd cmd) {
}
}

DiskOfferingVO newDiskOffering = retrieveAndValidateNewDiskOffering(cmd);
validateConditionsToReplaceDiskOfferingOfVolume(vol, newDiskOffering, destPool);

if (vm != null) {
Expand Down