|
31 | 31 | import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector; |
32 | 32 | import org.apache.cloudstack.storage.command.CreateObjectCommand; |
33 | 33 | import org.apache.cloudstack.storage.command.DeleteCommand; |
| 34 | +import com.cloud.agent.api.to.DataTO; |
| 35 | +import org.apache.cloudstack.storage.to.VolumeObjectTO; |
34 | 36 | import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao; |
35 | 37 | import org.apache.cloudstack.storage.feign.FeignClientFactory; |
36 | 38 | import org.apache.cloudstack.storage.feign.client.JobFeignClient; |
@@ -87,10 +89,10 @@ public void setOntapStorage(OntapStorage ontapStorage) { |
87 | 89 | public CloudStackVolume createCloudStackVolume(CloudStackVolume cloudstackVolume) { |
88 | 90 | s_logger.info("createCloudStackVolume: Create cloudstack volume " + cloudstackVolume); |
89 | 91 | try { |
90 | | - // Step 1: set cloudstack volume metadata |
| 92 | + // Step 1: set cloudstack volume metadata and get the volumeUuid |
91 | 93 | String volumeUuid = updateCloudStackVolumeMetadata(cloudstackVolume.getDatastoreId(), cloudstackVolume.getVolumeInfo()); |
92 | | - // Step 2: Send command to KVM host to create qcow2 file using qemu-img |
93 | | - Answer answer = createVolumeOnKVMHost(cloudstackVolume.getVolumeInfo()); |
| 94 | + // Step 2: Send command to KVM host with explicit volumeUuid to avoid stale cached path |
| 95 | + Answer answer = createVolumeOnKVMHost(cloudstackVolume.getVolumeInfo(), volumeUuid); |
94 | 96 | if (answer == null || !answer.getResult()) { |
95 | 97 | String errMsg = answer != null ? answer.getDetails() : "Failed to create qcow2 on KVM host"; |
96 | 98 | s_logger.error("createCloudStackVolume: " + errMsg); |
@@ -480,21 +482,29 @@ private String updateCloudStackVolumeMetadata(String dataStoreId, DataObject vol |
480 | 482 | String volumeUuid = volumeInfo.getUuid(); |
481 | 483 | volume.setPoolType(Storage.StoragePoolType.NetworkFilesystem); |
482 | 484 | volume.setPoolId(Long.parseLong(dataStoreId)); |
483 | | - volume.setPath(volumeUuid); // Filename for qcow2 file |
| 485 | + volume.setPath(volumeUuid); // Filename for qcow2 file - unique per volume |
484 | 486 | volumeDao.update(volume.getId(), volume); |
| 487 | + s_logger.info("Updated volume path to {} for volume ID {}", volumeUuid, volumeId); |
485 | 488 | return volumeUuid; |
486 | 489 | }catch (Exception e){ |
487 | 490 | s_logger.error("Exception while updating volumeInfo: {} in volume: {}", dataStoreId, volumeInfo.getUuid(), e); |
488 | 491 | throw new CloudRuntimeException("Exception while updating volumeInfo: " + e.getMessage()); |
489 | 492 | } |
490 | 493 | } |
491 | 494 |
|
492 | | - private Answer createVolumeOnKVMHost(DataObject volumeInfo) { |
493 | | - s_logger.info("createVolumeOnKVMHost called with volumeInfo: {} ", volumeInfo); |
| 495 | + private Answer createVolumeOnKVMHost(DataObject volumeInfo, String correctPath) { |
| 496 | + s_logger.info("createVolumeOnKVMHost called with volumeInfo: {}, correctPath: {}", volumeInfo, correctPath); |
494 | 497 |
|
495 | 498 | try { |
| 499 | + // Get the base TO and override the path with correct value to avoid stale cached path |
| 500 | + DataTO dataTO = volumeInfo.getTO(); |
| 501 | + if (dataTO instanceof VolumeObjectTO) { |
| 502 | + VolumeObjectTO volumeTO = (VolumeObjectTO) dataTO; |
| 503 | + s_logger.info("createVolumeOnKVMHost: Original TO path: {}, overriding with correct path: {}", volumeTO.getPath(), correctPath); |
| 504 | + volumeTO.setPath(correctPath); // Override stale path with correct UUID |
| 505 | + } |
496 | 506 | s_logger.info("createVolumeOnKVMHost: Sending CreateObjectCommand to KVM agent for volume: {}", volumeInfo.getUuid()); |
497 | | - CreateObjectCommand cmd = new CreateObjectCommand(volumeInfo.getTO()); |
| 507 | + CreateObjectCommand cmd = new CreateObjectCommand(dataTO); |
498 | 508 | EndPoint ep = epSelector.select(volumeInfo); |
499 | 509 | if (ep == null) { |
500 | 510 | String errMsg = "No remote endpoint to send CreateObjectCommand, check if host is up"; |
|
0 commit comments