Skip to content

Commit 3936f7c

Browse files
vm-import: kvm import and fix volume size when lesser than 1GiB (apache#8500)
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> Co-authored-by: Daan Hoogland <daan@onecht.net>
1 parent a3a4833 commit 3936f7c

3 files changed

Lines changed: 10 additions & 12 deletions

File tree

engine/api/src/main/java/org/apache/cloudstack/engine/orchestration/service/VolumeOrchestrationService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ List<DiskProfile> allocateTemplatedVolumes(Type type, String name, DiskOffering
153153
* @param type Type of the volume - ROOT, DATADISK, etc
154154
* @param name Name of the volume
155155
* @param offering DiskOffering for the volume
156-
* @param size DiskOffering for the volume
156+
* @param sizeInBytes size of the volume in bytes
157157
* @param minIops minimum IOPS for the disk, if not passed DiskOffering value will be used
158158
* @param maxIops maximum IOPS for the disk, if not passed DiskOffering value will be used
159159
* @param vm VirtualMachine this volume is attached to
@@ -165,7 +165,7 @@ List<DiskProfile> allocateTemplatedVolumes(Type type, String name, DiskOffering
165165
* @param chainInfo chain info for the volume. Hypervisor specific.
166166
* @return DiskProfile of imported volume
167167
*/
168-
DiskProfile importVolume(Type type, String name, DiskOffering offering, Long size, Long minIops, Long maxIops, VirtualMachine vm, VirtualMachineTemplate template,
168+
DiskProfile importVolume(Type type, String name, DiskOffering offering, Long sizeInBytes, Long minIops, Long maxIops, VirtualMachine vm, VirtualMachineTemplate template,
169169
Account owner, Long deviceId, Long poolId, String path, String chainInfo);
170170

171171
DiskProfile updateImportedVolume(Type type, DiskOffering offering, VirtualMachine vm, VirtualMachineTemplate template,

engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,19 +2172,17 @@ public void updateVolumeDiskChain(long volumeId, String path, String chainInfo,
21722172
}
21732173

21742174
@Override
2175-
public DiskProfile importVolume(Type type, String name, DiskOffering offering, Long size, Long minIops, Long maxIops,
2175+
public DiskProfile importVolume(Type type, String name, DiskOffering offering, Long sizeInBytes, Long minIops, Long maxIops,
21762176
VirtualMachine vm, VirtualMachineTemplate template, Account owner,
21772177
Long deviceId, Long poolId, String path, String chainInfo) {
2178-
if (size == null) {
2179-
size = offering.getDiskSize();
2180-
} else {
2181-
size = (size * 1024 * 1024 * 1024);
2178+
if (sizeInBytes == null) {
2179+
sizeInBytes = offering.getDiskSize();
21822180
}
21832181

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

2187-
VolumeVO vol = new VolumeVO(type, name, vm.getDataCenterId(), owner.getDomainId(), owner.getId(), offering.getId(), offering.getProvisioningType(), size, minIops, maxIops, null);
2185+
VolumeVO vol = new VolumeVO(type, name, vm.getDataCenterId(), owner.getDomainId(), owner.getId(), offering.getId(), offering.getProvisioningType(), sizeInBytes, minIops, maxIops, null);
21882186
if (vm != null) {
21892187
vol.setInstanceId(vm.getId());
21902188
}

server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,8 @@ private UserVm importVirtualMachineInternal(final UnmanagedInstanceTO unmanagedI
11131113
}
11141114
allDetails.put(VmDetailConstants.ROOT_DISK_CONTROLLER, rootDisk.getController());
11151115
if (cluster.getHypervisorType() == Hypervisor.HypervisorType.KVM && isImportUnmanagedFromSameHypervisor) {
1116-
allDetails.put(VmDetailConstants.ROOT_DISK_SIZE, String.valueOf(rootDisk.getCapacity() / Resource.ResourceType.bytesToGiB));
1116+
long size = Double.valueOf(Math.ceil((double)rootDisk.getCapacity() / Resource.ResourceType.bytesToGiB)).longValue();
1117+
allDetails.put(VmDetailConstants.ROOT_DISK_SIZE, String.valueOf(size));
11171118
}
11181119

11191120
try {
@@ -1172,16 +1173,15 @@ private UserVm importVirtualMachineInternal(final UnmanagedInstanceTO unmanagedI
11721173
}
11731174
DiskOfferingVO diskOffering = diskOfferingDao.findById(serviceOffering.getDiskOfferingId());
11741175
diskProfileStoragePoolList.add(importDisk(rootDisk, userVm, cluster, diskOffering, Volume.Type.ROOT, String.format("ROOT-%d", userVm.getId()),
1175-
(rootDisk.getCapacity() / Resource.ResourceType.bytesToGiB), minIops, maxIops,
1176-
template, owner, null));
1176+
rootDisk.getCapacity(), minIops, maxIops, template, owner, null));
11771177
long deviceId = 1L;
11781178
for (UnmanagedInstanceTO.Disk disk : dataDisks) {
11791179
if (disk.getCapacity() == null || disk.getCapacity() == 0) {
11801180
throw new InvalidParameterValueException(String.format("Disk ID: %s size is invalid", rootDisk.getDiskId()));
11811181
}
11821182
DiskOffering offering = diskOfferingDao.findById(dataDiskOfferingMap.get(disk.getDiskId()));
11831183
diskProfileStoragePoolList.add(importDisk(disk, userVm, cluster, offering, Volume.Type.DATADISK, String.format("DATA-%d-%s", userVm.getId(), disk.getDiskId()),
1184-
(disk.getCapacity() / Resource.ResourceType.bytesToGiB), offering.getMinIops(), offering.getMaxIops(),
1184+
disk.getCapacity(), offering.getMinIops(), offering.getMaxIops(),
11851185
template, owner, deviceId));
11861186
deviceId++;
11871187
}

0 commit comments

Comments
 (0)