Skip to content

Commit cddf38e

Browse files
OVF export tool parallel threads code improvements
1 parent d0e45b4 commit cddf38e

5 files changed

Lines changed: 42 additions & 8 deletions

File tree

api/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManager.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ public interface UnmanagedVMsManager extends VmImportService, UnmanageVMService,
4949
"threads.on.kvm.host.to.transfer.vmware.vm.files",
5050
"Advanced",
5151
"0",
52-
"Number of threads to use on the KVM host (by ovftool) to transfer VMware VM files, zero (or less than zero) would use total disks count. Default (0)",
52+
"Threads to use on the KVM host (by OVF Tool, supported from version >= 4.4.0) to transfer VMware VM files," +
53+
" less than zero - disabled, zero - uses total disks count, value should be less than 100 which is approximated to the number" +
54+
" of CPU cores minus one. Default: 0.",
5355
true,
5456
ConfigKey.Scope.Global,
5557
null);

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,11 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
307307
public static final String TUNGSTEN_PATH = "scripts/vm/network/tungsten";
308308

309309
public static final String INSTANCE_CONVERSION_SUPPORTED_CHECK_CMD = "virt-v2v --version";
310+
// virt-v2v --version => sample output: virt-v2v 1.42.0rhel=8,release=22.module+el8.10.0+1590+a67ab969
310311
public static final String OVF_EXPORT_SUPPORTED_CHECK_CMD = "ovftool --version";
312+
// ovftool --version => sample output: VMware ovftool 4.6.0 (build-21452615)
313+
public static final String OVF_EXPORT_TOOl_GET_VERSION_CMD = "ovftool --version | awk '{print $3}'";
314+
311315
public static final String WINDOWS_GUEST_CONVERSION_SUPPORTED_CHECK_CMD = "rpm -qa | grep -i virtio-win";
312316
public static final String UBUNTU_WINDOWS_GUEST_CONVERSION_SUPPORTED_CHECK_CMD = "dpkg -l virtio-win";
313317
public static final String UBUNTU_NBDKIT_PKG_CHECK_CMD = "dpkg -l nbdkit";
@@ -5167,6 +5171,26 @@ public boolean hostSupportsOvfExport() {
51675171
return exitValue == 0;
51685172
}
51695173

5174+
public boolean ovfExportToolSupportsParallelThreads() {
5175+
String ovfExportToolVersion = Script.runSimpleBashScript(OVF_EXPORT_TOOl_GET_VERSION_CMD);
5176+
if (StringUtils.isBlank(ovfExportToolVersion)) {
5177+
return false;
5178+
}
5179+
String[] ovfExportToolVersions = ovfExportToolVersion.trim().split("\\.");
5180+
if (ovfExportToolVersions.length > 1) {
5181+
try {
5182+
int majorVersion = Integer.parseInt(ovfExportToolVersions[0]);
5183+
int minorVersion = Integer.parseInt(ovfExportToolVersions[1]);
5184+
//ovftool version >= 4.4 supports parallel threads
5185+
if (majorVersion > 4 || (majorVersion == 4 && minorVersion >= 4)) {
5186+
return true;
5187+
}
5188+
} catch (NumberFormatException ignored) {
5189+
}
5190+
}
5191+
return false;
5192+
}
5193+
51705194
private void setCpuTopology(CpuModeDef cmd, int vCpusInDef, Map<String, String> details) {
51715195
if (!enableManuallySettingCpuTopologyOnKvmVm) {
51725196
s_logger.debug(String.format("Skipping manually setting CPU topology on VM's XML due to it is disabled in agent.properties {\"property\": \"%s\", \"value\": %s}.",

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtConvertInstanceCommandWrapper.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ public Answer execute(ConvertInstanceCommand cmd, LibvirtComputingResource serve
106106
}
107107

108108
int noOfThreads = cmd.getThreadsCountToExportOvf();
109+
if (noOfThreads > 1 && !serverResource.ovfExportToolSupportsParallelThreads()) {
110+
noOfThreads = 0;
111+
}
109112
ovfTemplateDirOnConversionLocation = UUID.randomUUID().toString();
110113
temporaryStoragePool.createFolder(ovfTemplateDirOnConversionLocation);
111114
sourceOVFDirPath = String.format("%s/%s/", temporaryConvertPath, ovfTemplateDirOnConversionLocation);
@@ -370,13 +373,11 @@ private boolean exportOVAFromVMOnVcenter(String vmExportUrl,
370373
String targetOvfDir,
371374
int noOfThreads,
372375
long timeout) {
373-
if (noOfThreads <= 0) {
374-
// '--parallelThreads': Value must be greater than zero
375-
noOfThreads = 1;
376-
}
377376
Script script = new Script("ovftool", timeout, s_logger);
378377
script.add("--noSSLVerify");
379-
script.add(String.format("--parallelThreads=%s", noOfThreads));
378+
if (noOfThreads > 1) {
379+
script.add(String.format("--parallelThreads=%s", noOfThreads));
380+
}
380381
script.add(vmExportUrl);
381382
script.add(targetOvfDir);
382383

server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ private void populateConfigValuesForValidationSet() {
559559
configValuesForValidation.add(StorageManager.STORAGE_POOL_CLIENT_MAX_CONNECTIONS.key());
560560
configValuesForValidation.add(UserDataManager.VM_USERDATA_MAX_LENGTH_STRING);
561561
configValuesForValidation.add(UnmanagedVMsManager.RemoteKvmInstanceDisksCopyTimeout.key());
562+
configValuesForValidation.add(UnmanagedVMsManager.ThreadsOnKVMHostToTransferVMwareVMFiles.key());
562563
}
563564

564565
private void weightBasedParametersForValidation() {
@@ -1292,6 +1293,12 @@ private String validateConfigurationValue(final String name, String value, final
12921293
throw new InvalidParameterValueException("Please enter a value less than 1048576 for the configuration parameter:" + name);
12931294
}
12941295
}
1296+
1297+
if (UnmanagedVMsManager.ThreadsOnKVMHostToTransferVMwareVMFiles.key().equalsIgnoreCase(name)) {
1298+
if (val >= 100) {
1299+
throw new InvalidParameterValueException("Please enter a value less than 100 for the configuration parameter:" + name);
1300+
}
1301+
}
12951302
} catch (final NumberFormatException e) {
12961303
s_logger.error("There was an error trying to parse the integer value for:" + name);
12971304
throw new InvalidParameterValueException("There was an error trying to parse the integer value for:" + name);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,8 +1881,8 @@ private UnmanagedInstanceTO convertVmwareInstanceToKVMAfterExportingOVFToConvert
18811881
int timeoutSeconds = UnmanagedVMsManager.ConvertVmwareInstanceToKvmTimeout.value() * 60 * 60;
18821882
cmd.setWait(timeoutSeconds);
18831883
int noOfThreads = UnmanagedVMsManager.ThreadsOnKVMHostToTransferVMwareVMFiles.value();
1884-
if (noOfThreads <= 0) {
1885-
// Use threads as the disks count
1884+
if (noOfThreads == 0) {
1885+
// Use no. of threads as the disks count
18861886
noOfThreads = clonedInstance.getDisks().size();
18871887
}
18881888
cmd.setThreadsCountToExportOvf(noOfThreads);

0 commit comments

Comments
 (0)