Skip to content

Commit 006ac3f

Browse files
Srivastava, PiyushSrivastava, Piyush
authored andcommitted
vm instance creation test5
1 parent cb541f8 commit 006ac3f

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,26 +130,34 @@ private String createCloudStackVolumeForTypeVolume(DataStore dataStore, DataObje
130130
throw new CloudRuntimeException("createCloudStackVolume : Storage Pool not found for id: " + dataStore.getId());
131131
}
132132
Map<String, String> details = storagePoolDetailsDao.listDetailsKeyPairs(dataStore.getId());
133-
// For managed NFS: create subdirectory via ONTAP REST API, store path in DB, return null
134-
// KVM will mount this subdirectory separately as: storage-ip:/vol/volumename/subdir -> /mnt/{volume-uuid}
133+
// For managed NFS: create subdirectory via ONTAP REST API
134+
// Use readable name combining volume name and UUID for subdirectory
135135
if (ProtocolType.NFS.name().equalsIgnoreCase(details.get(Constants.PROTOCOL))) {
136136
StorageStrategy storageStrategy = getStrategyByStoragePoolDetails(details);
137137
String volumeName = ((VolumeInfo) dataObject).getName();
138-
s_logger.info("createCloudStackVolumeForTypeVolume: NFS - creating subdirectory on ONTAP for volume: {}", volumeName);
138+
String volumeUuid = ((VolumeInfo) dataObject).getUuid();
139+
// Create readable subdirectory name: "ROOT-15_9c2e59a8-ee14-4f80-9db4-e279a12e0d7b"
140+
String readableSubdirName = volumeName + "_" + volumeUuid;
141+
s_logger.info("createCloudStackVolumeForTypeVolume: NFS - creating subdirectory on ONTAP: {}", readableSubdirName);
139142
CloudStackVolume cloudStackVolumeRequest = Utility.createCloudStackVolumeRequestByProtocol(storagePool, details, (VolumeInfo) dataObject);
140143
CloudStackVolume cloudStackVolume = storageStrategy.createCloudStackVolume(cloudStackVolumeRequest); // Creates subdirectory on ONTAP via REST API
141144
String subdirectoryName = cloudStackVolume.getFile().getPath();
142145
String subdirectoryPath = "/" + subdirectoryName;
143-
// Store the subdirectory path for KVM to mount separately
146+
// Store metadata in CloudStack database
144147
VolumeVO volume = volumeDao.findById(((VolumeInfo) dataObject).getId());
145-
volume.set_iScsiName(subdirectoryPath); // Used as MOUNT_POINT for NFS managed storage
148+
volume.set_iScsiName(subdirectoryPath); // Subdirectory path for reference
146149
volume.setPoolType(Storage.StoragePoolType.NetworkFilesystem); // Set volume pool type for KVM adaptor selection
147-
volume.setFolder(((VolumeInfo) dataObject).getUuid());
150+
volume.setFolder(volumeUuid); // Store UUID in folder field
148151
volume.setPoolId(dataStore.getId());
149-
volume.setPath(null); // Path is null for managed storage - KVM creates files in mounted subdir
152+
// CRITICAL: Set path to point to file INSIDE the subdirectory, not the subdirectory itself
153+
// Subdirectory exists at: /mnt/{pool-uuid}/{volume-uuid}/
154+
// We want hypervisor to create file at: /mnt/{pool-uuid}/{volume-uuid}/{volume-uuid}.{format}
155+
// So path should be: /{volume-uuid}/{volume-uuid} (hypervisor adds extension)
156+
String volumePath = subdirectoryPath + "/" + volumeUuid; // e.g., /9c2e59a8.../9c2e59a8...
157+
volume.setPath(volumePath);
150158
volumeDao.update(volume.getId(), volume);
151-
s_logger.info("createCloudStackVolumeForTypeVolume: NFS subdirectory created on ONTAP: {}, path stored in DB: {}", subdirectoryName, subdirectoryPath);
152-
return null; // Return null - backend work done, KVM will handle file creation
159+
s_logger.info("createCloudStackVolumeForTypeVolume: NFS subdirectory '{}' created on ONTAP, volume will be created at path: {}", subdirectoryPath, volumePath);
160+
return null; // Return null - backend work done, hypervisor will handle file creation
153161
}
154162
// For iSCSI and other protocols, use ONTAP REST API
155163
StorageStrategy storageStrategy = getStrategyByStoragePoolDetails(details);

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/utils/Utility.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,22 @@ public static CloudStackVolume createCloudStackVolumeRequestByProtocol(StoragePo
6565
ProtocolType protocolType = ProtocolType.valueOf(protocol);
6666
switch (protocolType) {
6767
case NFS:
68-
// TODO add logic for NFS file creation
68+
// For managed NFS: create subdirectory with readable name combining volume name and UUID
69+
// Format: "ROOT-15_9c2e59a8-ee14-4f80-9db4-e279a12e0d7b"
70+
// Hypervisor will create volume files inside this subdirectory with format-specific extensions
6971
cloudStackVolumeRequest = new CloudStackVolume();
7072
FileInfo file = new FileInfo();
71-
//file.setName("test1"); // to be replaced with volume name // this should not be passed for dir
72-
// file.setName(volumeObject.getName()); // to check whether this needs to be sent or not
73-
//file.setSize(Long.parseLong("10000"));
74-
//file.setSize(volumeObject.getSize());
75-
file.setUnixPermissions(755); // check if it is needed only for dir ? it is needed for dir
76-
file.setType(FileInfo.TypeEnum.DIRECTORY); // We are creating file for a cloudstack volume . Should it be dir ? // TODO change once multipart is done
73+
file.setUnixPermissions(755);
74+
file.setType(FileInfo.TypeEnum.DIRECTORY);
7775

7876
Volume poolVolume = new Volume();
7977
poolVolume.setName(details.get(Constants.VOLUME_NAME));
8078
poolVolume.setUuid(details.get(Constants.VOLUME_UUID));
8179
cloudStackVolumeRequest.setVolume(poolVolume);
8280
cloudStackVolumeRequest.setFile(file);
83-
cloudStackVolumeRequest.setCloudstackVolName(volumeObject.getName());
81+
// Use "name_uuid" format for readable subdirectory name
82+
String readableSubdirName = volumeObject.getName() + "_" + volumeObject.getUuid();
83+
cloudStackVolumeRequest.setCloudstackVolName(readableSubdirName);
8484
cloudStackVolumeRequest.setCloudstackVolUUID(volumeObject.getUuid());
8585
break;
8686
case ISCSI:

0 commit comments

Comments
 (0)