Skip to content

Commit c1535f3

Browse files
Srivastava, PiyushSrivastava, Piyush
authored andcommitted
feature/CSTACKEX-122: Per host Igroup changes 3
1 parent 7f470fd commit c1535f3

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriver.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ public void createAsync(DataStore dataStore, DataObject dataObject, AsyncComplet
149149
volumeVO.setPoolId(storagePool.getId());
150150

151151
if (ProtocolType.ISCSI.name().equalsIgnoreCase(details.get(Constants.PROTOCOL))) {
152-
String svmName = details.get(Constants.SVM_NAME);
153152
String lunName = created != null && created.getLun() != null ? created.getLun().getName() : null;
154153
if (lunName == null) {
155154
throw new CloudRuntimeException("createAsync: Missing LUN name for volume " + volInfo.getId());
@@ -171,9 +170,12 @@ public void createAsync(DataStore dataStore, DataObject dataObject, AsyncComplet
171170
volumeVO.setPath(null);
172171
createCmdResult = new CreateCmdResult(lunName, new Answer(null, true, null));
173172
} else if (ProtocolType.NFS3.name().equalsIgnoreCase(details.get(Constants.PROTOCOL))) {
173+
// For NFS, set path to volume UUID to ensure uniqueness
174+
// This prevents multiple VMs from using the same template file path
175+
volumeVO.setPath(volInfo.getUuid());
174176
createCmdResult = new CreateCmdResult(volInfo.getUuid(), new Answer(null, true, null));
175-
s_logger.info("createAsync: Managed NFS volume [{}] associated with pool {}",
176-
volumeVO.getId(), storagePool.getId());
177+
s_logger.info("createAsync: Managed NFS volume [{}] with path [{}] associated with pool {}",
178+
volumeVO.getId(), volInfo.getUuid(), storagePool.getId());
177179
}
178180
volumeDao.update(volumeVO.getId(), volumeVO);
179181
}
@@ -340,6 +342,7 @@ public boolean grantAccess(DataObject dataObject, Host host, DataStore dataStore
340342
}else{
341343
s_logger.info("grantAccess: Igroup {} already exist for the host {}: ", accessGroup.getIgroup().getName() ,host.getName());
342344
igroup = accessGroup.getIgroup();
345+
// TODO
343346
// Verify host initiator is registered in the igroup before allowing access
344347
// if (sanStrategy.validateInitiatorInAccessGroup(host.getStorageUrl(), svmName, accessGroup.getIgroup())) {
345348
// // add host initiator to the igroup ? or fail here ?

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/UnifiedNASStrategy.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
3232
import org.apache.cloudstack.storage.command.CreateObjectCommand;
3333
import org.apache.cloudstack.storage.command.DeleteCommand;
34+
import com.cloud.agent.api.to.DataTO;
35+
import org.apache.cloudstack.storage.to.VolumeObjectTO;
3436
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
3537
import org.apache.cloudstack.storage.feign.FeignClientFactory;
3638
import org.apache.cloudstack.storage.feign.client.JobFeignClient;
@@ -87,10 +89,10 @@ public void setOntapStorage(OntapStorage ontapStorage) {
8789
public CloudStackVolume createCloudStackVolume(CloudStackVolume cloudstackVolume) {
8890
s_logger.info("createCloudStackVolume: Create cloudstack volume " + cloudstackVolume);
8991
try {
90-
// Step 1: set cloudstack volume metadata
92+
// Step 1: set cloudstack volume metadata and get the volumeUuid
9193
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);
9496
if (answer == null || !answer.getResult()) {
9597
String errMsg = answer != null ? answer.getDetails() : "Failed to create qcow2 on KVM host";
9698
s_logger.error("createCloudStackVolume: " + errMsg);
@@ -480,21 +482,29 @@ private String updateCloudStackVolumeMetadata(String dataStoreId, DataObject vol
480482
String volumeUuid = volumeInfo.getUuid();
481483
volume.setPoolType(Storage.StoragePoolType.NetworkFilesystem);
482484
volume.setPoolId(Long.parseLong(dataStoreId));
483-
volume.setPath(volumeUuid); // Filename for qcow2 file
485+
volume.setPath(volumeUuid); // Filename for qcow2 file - unique per volume
484486
volumeDao.update(volume.getId(), volume);
487+
s_logger.info("Updated volume path to {} for volume ID {}", volumeUuid, volumeId);
485488
return volumeUuid;
486489
}catch (Exception e){
487490
s_logger.error("Exception while updating volumeInfo: {} in volume: {}", dataStoreId, volumeInfo.getUuid(), e);
488491
throw new CloudRuntimeException("Exception while updating volumeInfo: " + e.getMessage());
489492
}
490493
}
491494

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);
494497

495498
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+
}
496506
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);
498508
EndPoint ep = epSelector.select(volumeInfo);
499509
if (ep == null) {
500510
String errMsg = "No remote endpoint to send CreateObjectCommand, check if host is up";

0 commit comments

Comments
 (0)