Skip to content

Commit f128819

Browse files
Srivastava, PiyushSrivastava, Piyush
authored andcommitted
Commit 28
1 parent 38f54b0 commit f128819

File tree

2 files changed

+49
-51
lines changed

2 files changed

+49
-51
lines changed

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/OntapNfsStorageAdaptor.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -476,10 +476,17 @@ public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk srcDisk, String name, KV
476476
try {
477477
// Get mount point for destination volume (handles junction path properly)
478478
String destMountPoint = getMountPointForVolume(name);
479-
// Extract volume UUID from name (remove leading slash if present)
480-
String volumeUuid = name.startsWith("/") ? name.substring(name.lastIndexOf('_') + 1).replace("_", "-") : name;
481-
String destPath = destMountPoint + "/" + volumeUuid + ".qcow2";
482-
logger.info("Destination mount point: " + destMountPoint + ", file: " + volumeUuid + ".qcow2");
479+
// Extract volume UUID from name (junction path format: /cs_vol_c392abfc_d209_4190_b7ea_e64d3e8b16a0)
480+
String volumeUuid;
481+
if (name.startsWith("/cs_vol_")) {
482+
// Extract UUID from junction path: /cs_vol_<uuid_with_underscores> -> <uuid-with-hyphens>
483+
volumeUuid = name.substring("/cs_vol_".length()).replace("_", "-");
484+
} else {
485+
// Already a UUID
486+
volumeUuid = name;
487+
}
488+
String destPath = destMountPoint + "/" + volumeUuid;
489+
logger.info("Destination mount point: " + destMountPoint + ", file: " + volumeUuid);
483490
// Ensure destination volume is mounted
484491
if (!isMounted(destMountPoint)) {
485492
throw new CloudRuntimeException("Destination ONTAP volume not mounted: " + name);

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

Lines changed: 38 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.cloud.agent.api.to.DataObjectType;
2323
import com.cloud.agent.api.to.DataStoreTO;
2424
import com.cloud.agent.api.to.DataTO;
25+
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
2526
import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
2627
import com.cloud.exception.InvalidParameterValueException;
2728
import com.cloud.host.Host;
@@ -43,6 +44,7 @@
4344
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
4445
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
4546
import org.apache.cloudstack.storage.command.CommandResult;
47+
import org.apache.cloudstack.storage.command.CreateObjectCommand;
4648
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
4749
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
4850
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
@@ -138,42 +140,34 @@ public void createAsync(DataStore dataStore, DataObject dataObject, AsyncComplet
138140
* @param volumeInfo Volume information with size, format, uuid
139141
* @return Answer from KVM agent indicating success/failure
140142
*/
141-
// private Answer createVolumeOnKVMHost(VolumeInfo volumeInfo) {
142-
// try {
143-
// s_logger.info("createVolumeOnKVMHost: Sending CreateObjectCommand to KVM agent for volume: {}", volumeInfo.getUuid());
144-
//
145-
// // Create command with volume TO (Transfer Object)
146-
// CreateObjectCommand cmd = new CreateObjectCommand(volumeInfo.getTO());
147-
//
148-
// // Select endpoint (KVM agent) to send command
149-
// // epSelector will find an appropriate KVM host in the cluster/pod
150-
// EndPoint ep = epSelector.select(volumeInfo);
151-
//
152-
// if (ep == null) {
153-
// String errMsg = "No remote endpoint to send CreateObjectCommand, check if host is up";
154-
// s_logger.error(errMsg);
155-
// return new Answer(cmd, false, errMsg);
156-
// }
157-
//
158-
// s_logger.info("createVolumeOnKVMHost: Sending command to endpoint: {}", ep.getHostAddr());
159-
//
160-
// // Send command to KVM agent and wait for response
161-
// Answer answer = ep.sendMessage(cmd);
162-
//
163-
// if (answer != null && answer.getResult()) {
164-
// s_logger.info("createVolumeOnKVMHost: Successfully created qcow2 file on KVM host");
165-
// } else {
166-
// s_logger.error("createVolumeOnKVMHost: Failed to create qcow2 file: {}",
167-
// answer != null ? answer.getDetails() : "null answer");
168-
// }
169-
//
170-
// return answer;
171-
//
172-
// } catch (Exception e) {
173-
// s_logger.error("createVolumeOnKVMHost: Exception sending CreateObjectCommand", e);
174-
// return new Answer(null, false, e.toString());
175-
// }
176-
// }
143+
private Answer createVolumeOnKVMHost(VolumeInfo volumeInfo) {
144+
try {
145+
s_logger.info("createVolumeOnKVMHost: Sending CreateObjectCommand to KVM agent for volume: {}", volumeInfo.getUuid());
146+
// Create command with volume TO (Transfer Object)
147+
CreateObjectCommand cmd = new CreateObjectCommand(volumeInfo.getTO());
148+
// Select endpoint (KVM agent) to send command
149+
// epSelector will find an appropriate KVM host in the cluster/pod
150+
EndPoint ep = epSelector.select(volumeInfo);
151+
if (ep == null) {
152+
String errMsg = "No remote endpoint to send CreateObjectCommand, check if host is up";
153+
s_logger.error(errMsg);
154+
return new Answer(cmd, false, errMsg);
155+
}
156+
s_logger.info("createVolumeOnKVMHost: Sending command to endpoint: {}", ep.getHostAddr());
157+
// Send command to KVM agent and wait for response
158+
Answer answer = ep.sendMessage(cmd);
159+
if (answer != null && answer.getResult()) {
160+
s_logger.info("createVolumeOnKVMHost: Successfully created qcow2 file on KVM host");
161+
} else {
162+
s_logger.error("createVolumeOnKVMHost: Failed to create qcow2 file: {}",
163+
answer != null ? answer.getDetails() : "null answer");
164+
}
165+
return answer;
166+
} catch (Exception e) {
167+
s_logger.error("createVolumeOnKVMHost: Exception sending CreateObjectCommand", e);
168+
return new Answer(null, false, e.toString());
169+
}
170+
}
177171

178172
/**
179173
* Creates CloudStack volume based on storage protocol type (NFS or iSCSI).
@@ -201,17 +195,7 @@ private String createCloudStackVolumeForTypeVolume(DataStore dataStore, DataObje
201195
// Step 1: Create ONTAP volume and set metadata
202196
String volumeUuid = createManagedNfsVolume(dataStore, dataObject, storagePool);
203197

204-
// Step 2: Send command to KVM host to create qcow2 file using qemu-img
205-
// VolumeInfo volumeInfo = (VolumeInfo) dataObject;
206-
// Answer answer = createVolumeOnKVMHost(volumeInfo);
207-
208-
// if (answer == null || !answer.getResult()) {
209-
// String errMsg = answer != null ? answer.getDetails() : "Failed to create qcow2 on KVM host";
210-
// s_logger.error("createCloudStackVolumeForTypeVolume: " + errMsg);
211-
// throw new CloudRuntimeException(errMsg);
212-
// }
213-
214-
// create export olicy and attach it to new volume created
198+
// Step 2: Create export policy and attach it to new volume (MUST be before KVM mount)
215199
VolumeInfo volumeInfo = (VolumeInfo) dataObject;
216200
Map<String, String> volumeDetails = new HashMap<>();
217201
volumeDetails.put(Constants.VOLUME_UUID, volumeInfo.getUuid());
@@ -223,6 +207,13 @@ private String createCloudStackVolumeForTypeVolume(DataStore dataStore, DataObje
223207
accessGroup.setVolumedetails(volumeDetails);
224208
storageStrategy.createAccessGroup(accessGroup);
225209

210+
// Step 3: Send command to KVM host to create qcow2 file using qemu-img
211+
Answer answer = createVolumeOnKVMHost(volumeInfo);
212+
if (answer == null || !answer.getResult()) {
213+
String errMsg = answer != null ? answer.getDetails() : "Failed to create qcow2 on KVM host";
214+
s_logger.error("createCloudStackVolumeForTypeVolume: " + errMsg);
215+
throw new CloudRuntimeException(errMsg);
216+
}
226217
// create export policy
227218
// VolumeInfo volumeInfo = (VolumeInfo) dataObject;
228219
// String svmName = details.get(Constants.SVM_NAME);

0 commit comments

Comments
 (0)