Skip to content

Commit

Permalink
vm-import: fix volume size when lesser than 1GiB
Browse files Browse the repository at this point in the history
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
  • Loading branch information
shwstppr committed Jan 12, 2024
1 parent a3a4833 commit 31ff6ed
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ List<DiskProfile> allocateTemplatedVolumes(Type type, String name, DiskOffering
* @param type Type of the volume - ROOT, DATADISK, etc
* @param name Name of the volume
* @param offering DiskOffering for the volume
* @param size DiskOffering for the volume
* @param sizeInBytes size of the volume in bytes
* @param minIops minimum IOPS for the disk, if not passed DiskOffering value will be used
* @param maxIops maximum IOPS for the disk, if not passed DiskOffering value will be used
* @param vm VirtualMachine this volume is attached to
Expand All @@ -165,7 +165,7 @@ List<DiskProfile> allocateTemplatedVolumes(Type type, String name, DiskOffering
* @param chainInfo chain info for the volume. Hypervisor specific.
* @return DiskProfile of imported volume
*/
DiskProfile importVolume(Type type, String name, DiskOffering offering, Long size, Long minIops, Long maxIops, VirtualMachine vm, VirtualMachineTemplate template,
DiskProfile importVolume(Type type, String name, DiskOffering offering, Long sizeInBytes, Long minIops, Long maxIops, VirtualMachine vm, VirtualMachineTemplate template,
Account owner, Long deviceId, Long poolId, String path, String chainInfo);

DiskProfile updateImportedVolume(Type type, DiskOffering offering, VirtualMachine vm, VirtualMachineTemplate template,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2172,19 +2172,17 @@ public void updateVolumeDiskChain(long volumeId, String path, String chainInfo,
}

@Override
public DiskProfile importVolume(Type type, String name, DiskOffering offering, Long size, Long minIops, Long maxIops,
public DiskProfile importVolume(Type type, String name, DiskOffering offering, Long sizeInBytes, Long minIops, Long maxIops,
VirtualMachine vm, VirtualMachineTemplate template, Account owner,
Long deviceId, Long poolId, String path, String chainInfo) {
if (size == null) {
size = offering.getDiskSize();
} else {
size = (size * 1024 * 1024 * 1024);
if (sizeInBytes == null) {
sizeInBytes = offering.getDiskSize();
}

minIops = minIops != null ? minIops : offering.getMinIops();
maxIops = maxIops != null ? maxIops : offering.getMaxIops();

VolumeVO vol = new VolumeVO(type, name, vm.getDataCenterId(), owner.getDomainId(), owner.getId(), offering.getId(), offering.getProvisioningType(), size, minIops, maxIops, null);
VolumeVO vol = new VolumeVO(type, name, vm.getDataCenterId(), owner.getDomainId(), owner.getId(), offering.getId(), offering.getProvisioningType(), sizeInBytes, minIops, maxIops, null);
if (vm != null) {
vol.setInstanceId(vm.getId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@ private UserVm importVirtualMachineInternal(final UnmanagedInstanceTO unmanagedI
}
DiskOfferingVO diskOffering = diskOfferingDao.findById(serviceOffering.getDiskOfferingId());
diskProfileStoragePoolList.add(importDisk(rootDisk, userVm, cluster, diskOffering, Volume.Type.ROOT, String.format("ROOT-%d", userVm.getId()),
(rootDisk.getCapacity() / Resource.ResourceType.bytesToGiB), minIops, maxIops,
rootDisk.getCapacity(), minIops, maxIops,
template, owner, null));
long deviceId = 1L;
for (UnmanagedInstanceTO.Disk disk : dataDisks) {
Expand All @@ -1181,7 +1181,7 @@ private UserVm importVirtualMachineInternal(final UnmanagedInstanceTO unmanagedI
}
DiskOffering offering = diskOfferingDao.findById(dataDiskOfferingMap.get(disk.getDiskId()));
diskProfileStoragePoolList.add(importDisk(disk, userVm, cluster, offering, Volume.Type.DATADISK, String.format("DATA-%d-%s", userVm.getId(), disk.getDiskId()),
(disk.getCapacity() / Resource.ResourceType.bytesToGiB), offering.getMinIops(), offering.getMaxIops(),
disk.getCapacity(), offering.getMinIops(), offering.getMaxIops(),
template, owner, deviceId));
deviceId++;
}
Expand Down

0 comments on commit 31ff6ed

Please sign in to comment.