slavkap commented on code in PR #14389:
URL: https://github.com/apache/cloudstack/pull/14389#discussion_r4323459291
##########
server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java:
##########
@@ -2976,27 +2997,51 @@ private UserVm importKvmVirtualMachineFromDisk(final
ImportSource importSource,
Map<Volume, StoragePool> storage = dest.getStorageForDisks();
Volume volume = volumeDao.findById(diskProfile.getVolumeId());
StoragePool storagePool = storage.get(volume);
- CheckVolumeCommand checkVolumeCommand = new CheckVolumeCommand();
- checkVolumeCommand.setSrcFile(diskPath);
- StorageFilerTO storageTO = new StorageFilerTO(storagePool);
- checkVolumeCommand.setStorageFilerTO(storageTO);
- Answer answer = agentManager.easySend(dest.getHost().getId(),
checkVolumeCommand);
- if (!(answer instanceof CheckVolumeAnswer)) {
- cleanupFailedImportVM(userVm);
- throw new CloudRuntimeException("Disk not found or is
invalid");
- }
- CheckVolumeAnswer checkVolumeAnswer = (CheckVolumeAnswer) answer;
- try {
- checkVolume(checkVolumeAnswer.getVolumeDetails());
- } catch (CloudRuntimeException e) {
- cleanupFailedImportVM(userVm);
- throw e;
- }
- if (!checkVolumeAnswer.getResult()) {
- cleanupFailedImportVM(userVm);
- throw new CloudRuntimeException("Disk not found or is
invalid");
+
+ Map<VolumeOnStorageTO.Detail, String> volumeDetails;
+ long volumeSize;
+ List<VolumeOnStorageTO> volumesFromDriver =
listVolumesForImportFromDriver(storagePool, diskPath);
+ if (volumesFromDriver != null) {
+ // The storage driver can enumerate its own volumes (e.g.
StorPool, via its
+ // management API), so there is no need to reach the host
agent just to read size.
+ if (CollectionUtils.isEmpty(volumesFromDriver)) {
+ cleanupFailedImportVM(userVm);
+ throw new CloudRuntimeException("Disk not found or is
invalid");
+ }
+ VolumeOnStorageTO volumeOnStorage = volumesFromDriver.get(0);
+ volumeDetails = volumeOnStorage.getDetails();
+ try {
+ checkVolume(volumeDetails);
+ } catch (CloudRuntimeException e) {
+ cleanupFailedImportVM(userVm);
+ throw e;
+ }
+ volumeSize = volumeOnStorage.getVirtualSize();
+ } else {
+ CheckVolumeCommand checkVolumeCommand = new
CheckVolumeCommand();
+ checkVolumeCommand.setSrcFile(diskPath);
+ StorageFilerTO storageTO = new StorageFilerTO(storagePool);
+ checkVolumeCommand.setStorageFilerTO(storageTO);
+ Answer answer = agentManager.easySend(dest.getHost().getId(),
checkVolumeCommand);
+ if (!(answer instanceof CheckVolumeAnswer)) {
+ cleanupFailedImportVM(userVm);
+ throw new CloudRuntimeException("Disk not found or is
invalid");
+ }
+ CheckVolumeAnswer checkVolumeAnswer = (CheckVolumeAnswer)
answer;
+ volumeDetails = checkVolumeAnswer.getVolumeDetails();
+ try {
+ checkVolume(volumeDetails);
+ } catch (CloudRuntimeException e) {
+ cleanupFailedImportVM(userVm);
+ throw e;
+ }
+ if (!checkVolumeAnswer.getResult()) {
+ cleanupFailedImportVM(userVm);
+ throw new CloudRuntimeException("Disk not found or is
invalid");
+ }
+ volumeSize = checkVolumeAnswer.getSize();
Review Comment:
thank! I extracted it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]