vishesh92 commented on code in PR #11071:
URL: https://github.com/apache/cloudstack/pull/11071#discussion_r2332355218
##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java:
##########
@@ -187,17 +207,79 @@ public boolean
connectPhysicalDisksViaVmSpec(VirtualMachineTO vmSpec, boolean is
KVMStoragePool pool = getStoragePool(store.getPoolType(),
store.getUuid());
StorageAdaptor adaptor = getStorageAdaptor(pool.getType());
- result = adaptor.connectPhysicalDisk(vol.getPath(), pool,
disk.getDetails(), isVMMigrate);
+ if (adaptor instanceof AsyncPhysicalDiskConnectorDecorator) {
+ // If the adaptor supports async disk connection, we can start
the connection
+ // and return immediately, allowing the connection to complete
in the background.
+ result = ((AsyncPhysicalDiskConnectorDecorator)
adaptor).startConnectPhysicalDisk(vol.getPath(), pool, disk.getDetails());
+ if (!result) {
+ logger.error("Failed to start connecting disks via vm spec
for vm: " + vmName + " volume:" + vol.toString());
+ return false;
+ }
- if (!result) {
- logger.error("Failed to connect disks via vm spec for vm: " +
vmName + " volume:" + vol.toString());
- return result;
+ // add disk to list of disks to check later
+ connectingDisks.add(new ConnectingDiskInfo(vol, adaptor, pool,
disk.getDetails()));
+ } else {
+ result = adaptor.connectPhysicalDisk(vol.getPath(), pool,
disk.getDetails(), isVMMigrate);
+
+ if (!result) {
+ logger.error("Failed to connect disks via vm spec for vm:
" + vmName + " volume:" + vol.toString());
+ return result;
+ }
+ }
+ }
+
+ // if we have any connecting disks to check, wait for them to connect
or timeout
+ if (!connectingDisks.isEmpty()) {
+ for (ConnectingDiskInfo connectingDisk : connectingDisks) {
+ StorageAdaptor adaptor = connectingDisk.adapter;
+ KVMStoragePool pool = connectingDisk.pool;
+ VolumeObjectTO volume = connectingDisk.volume;
+ Map<String, String> details = connectingDisk.details;
+ long diskWaitTimeMillis = getDiskWaitTimeMillis(details);
+
+ // wait for the disk to connect
+ long startTime = System.currentTimeMillis();
+ while (System.currentTimeMillis() - startTime <
diskWaitTimeMillis) {
+ if (((AsyncPhysicalDiskConnectorDecorator)
adaptor).isConnected(volume.getPath(), pool, details)) {
+ logger.debug(String.format("Disk %s connected
successfully for VM %s", volume.getPath(), vmName));
+ break;
+ }
+
+ sleep(1000); // wait for 1 second before checking again
+ }
}
}
return result;
}
+ private long getDiskWaitTimeMillis(Map<String,String> details) {
Review Comment:
```suggestion
private long getDiskWaitTimeMillis(Map<String,String> details) {
```
--
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]