|
27 | 27 | import com.cloud.storage.Storage; |
28 | 28 | import com.cloud.storage.StoragePool; |
29 | 29 | import com.cloud.storage.Volume; |
| 30 | +import com.cloud.storage.VolumeVO; |
30 | 31 | import com.cloud.utils.Pair; |
31 | 32 | import com.cloud.utils.exception.CloudRuntimeException; |
32 | 33 | import org.apache.cloudstack.engine.subsystem.api.storage.ChapInfo; |
@@ -64,6 +65,7 @@ public class OntapPrimaryDatastoreDriver implements PrimaryDataStoreDriver { |
64 | 65 |
|
65 | 66 | @Inject private StoragePoolDetailsDao storagePoolDetailsDao; |
66 | 67 | @Inject private PrimaryDataStoreDao storagePoolDao; |
| 68 | + @Inject private com.cloud.storage.dao.VolumeDao volumeDao; |
67 | 69 | @Override |
68 | 70 | public Map<String, String> getCapabilities() { |
69 | 71 | s_logger.trace("OntapPrimaryDatastoreDriver: getCapabilities: Called"); |
@@ -128,11 +130,23 @@ private String createCloudStackVolumeForTypeVolume(DataStore dataStore, DataObje |
128 | 130 | throw new CloudRuntimeException("createCloudStackVolume : Storage Pool not found for id: " + dataStore.getId()); |
129 | 131 | } |
130 | 132 | Map<String, String> details = storagePoolDetailsDao.listDetailsKeyPairs(dataStore.getId()); |
131 | | - // For NFS, skip ONTAP REST API operations - CloudStack manages files natively |
| 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} |
132 | 135 | if (ProtocolType.NFS.name().equalsIgnoreCase(details.get(Constants.PROTOCOL))) { |
133 | | - String volumeUuid = ((VolumeInfo) dataObject).getUuid(); |
134 | | - s_logger.info("createCloudStackVolumeForTypeVolume: NFS protocol detected - returning volume UUID for native file management: {}", volumeUuid); |
135 | | - return volumeUuid; |
| 136 | + StorageStrategy storageStrategy = getStrategyByStoragePoolDetails(details); |
| 137 | + s_logger.info("createCloudStackVolumeForTypeVolume: NFS - creating subdirectory on ONTAP for volume: {}", ((VolumeInfo) dataObject).getName()); |
| 138 | + CloudStackVolume cloudStackVolumeRequest = Utility.createCloudStackVolumeRequestByProtocol(storagePool, details, (VolumeInfo) dataObject); |
| 139 | + storageStrategy.createCloudStackVolume(cloudStackVolumeRequest); // Creates subdirectory on ONTAP via REST API |
| 140 | + // Store the subdirectory path for KVM to mount separately |
| 141 | + String subdirectoryPath = "/" + ((VolumeInfo) dataObject).getName(); |
| 142 | + VolumeVO volume = volumeDao.findById(((VolumeInfo) dataObject).getId()); |
| 143 | + volume.set_iScsiName(subdirectoryPath); // Used as MOUNT_POINT for NFS managed storage |
| 144 | + volume.setFolder(((VolumeInfo) dataObject).getUuid()); |
| 145 | + volume.setPoolId(dataStore.getId()); |
| 146 | + volume.setPath(null); // Path is null for managed storage - KVM creates files in mounted subdir |
| 147 | + volumeDao.update(volume.getId(), volume); |
| 148 | + s_logger.info("createCloudStackVolumeForTypeVolume: NFS subdirectory created, path stored: {}", subdirectoryPath); |
| 149 | + return null; // Return null - backend work done, KVM will handle file creation |
136 | 150 | } |
137 | 151 | // For iSCSI and other protocols, use ONTAP REST API |
138 | 152 | StorageStrategy storageStrategy = getStrategyByStoragePoolDetails(details); |
|
0 commit comments