|
24 | 24 | import com.cloud.agent.api.to.DataTO; |
25 | 25 | import com.cloud.exception.InvalidParameterValueException; |
26 | 26 | import com.cloud.host.Host; |
| 27 | +import com.cloud.host.HostVO; |
27 | 28 | import com.cloud.storage.Storage; |
28 | 29 | import com.cloud.storage.StoragePool; |
29 | 30 | import com.cloud.storage.Volume; |
|
50 | 51 | import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; |
51 | 52 | import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao; |
52 | 53 | import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; |
| 54 | +import org.apache.cloudstack.storage.feign.model.Igroup; |
53 | 55 | import org.apache.cloudstack.storage.feign.model.Lun; |
54 | 56 | import org.apache.cloudstack.storage.service.SANStrategy; |
55 | 57 | import org.apache.cloudstack.storage.service.StorageStrategy; |
|
63 | 65 | import org.apache.logging.log4j.Logger; |
64 | 66 |
|
65 | 67 | import javax.inject.Inject; |
| 68 | +import java.util.ArrayList; |
66 | 69 | import java.util.Arrays; |
67 | 70 | import java.util.HashMap; |
| 71 | +import java.util.List; |
68 | 72 | import java.util.Map; |
69 | 73 |
|
70 | 74 | /** |
@@ -158,17 +162,26 @@ public void createAsync(DataStore dataStore, DataObject dataObject, AsyncComplet |
158 | 162 | volumeVO.setFolder(created.getLun().getUuid()); |
159 | 163 | } |
160 | 164 |
|
161 | | - // Create LUN-to-igroup mapping and retrieve the assigned LUN ID |
162 | | - UnifiedSANStrategy sanStrategy = (UnifiedSANStrategy) Utility.getStrategyByStoragePoolDetails(details); |
163 | | - String accessGroupName = Utility.getIgroupName(svmName, storagePoolUuid); |
164 | | - String lunNumber = sanStrategy.ensureLunMapped(svmName, lunName, accessGroupName); |
165 | | - |
166 | | - // Construct iSCSI path: /<iqn>/<lun_id> format for KVM/libvirt attachment |
167 | | - String iscsiPath = Constants.SLASH + storagePool.getPath() + Constants.SLASH + lunNumber; |
168 | | - volumeVO.set_iScsiName(iscsiPath); |
169 | | - volumeVO.setPath(iscsiPath); |
170 | | - s_logger.info("createAsync: Volume [{}] iSCSI path set to {}", volumeVO.getId(), iscsiPath); |
171 | | - createCmdResult = new CreateCmdResult(null, new Answer(null, true, null)); |
| 165 | + s_logger.info("createAsync: Created LUN [{}] for volume [{}]. LUN mapping will occur during grantAccess() to per-host igroup.", |
| 166 | + lunName, volumeVO.getId()); |
| 167 | + |
| 168 | + // Path will be set during grantAccess when LUN is mapped and we get the LUN ID |
| 169 | + // Return LUN name as identifier for CloudStack tracking |
| 170 | + volumeVO.set_iScsiName(null); |
| 171 | + volumeVO.setPath(null); |
| 172 | + createCmdResult = new CreateCmdResult(lunName, new Answer(null, true, null)); |
| 173 | + |
| 174 | +// // Create LUN-to-igroup mapping and retrieve the assigned LUN ID |
| 175 | +// UnifiedSANStrategy sanStrategy = (UnifiedSANStrategy) Utility.getStrategyByStoragePoolDetails(details); |
| 176 | +// String accessGroupName = Utility.getIgroupName(svmName, storagePoolUuid); |
| 177 | +// String lunNumber = sanStrategy.ensureLunMapped(svmName, lunName, accessGroupName); |
| 178 | +// |
| 179 | +// // Construct iSCSI path: /<iqn>/<lun_id> format for KVM/libvirt attachment |
| 180 | +// String iscsiPath = Constants.SLASH + storagePool.getPath() + Constants.SLASH + lunNumber; |
| 181 | +// volumeVO.set_iScsiName(iscsiPath); |
| 182 | +// volumeVO.setPath(iscsiPath); |
| 183 | +// s_logger.info("createAsync: Volume [{}] iSCSI path set to {}", volumeVO.getId(), iscsiPath); |
| 184 | +// createCmdResult = new CreateCmdResult(null, new Answer(null, true, null)); |
172 | 185 |
|
173 | 186 | } else if (ProtocolType.NFS3.name().equalsIgnoreCase(details.get(Constants.PROTOCOL))) { |
174 | 187 | createCmdResult = new CreateCmdResult(volInfo.getUuid(), new Answer(null, true, null)); |
@@ -319,12 +332,32 @@ public boolean grantAccess(DataObject dataObject, Host host, DataStore dataStore |
319 | 332 | // Only retrieve LUN name for iSCSI volumes |
320 | 333 | String cloudStackVolumeName = volumeDetailsDao.findDetail(volumeVO.getId(), Constants.LUN_DOT_NAME).getValue(); |
321 | 334 | UnifiedSANStrategy sanStrategy = (UnifiedSANStrategy) Utility.getStrategyByStoragePoolDetails(details); |
322 | | - String accessGroupName = Utility.getIgroupName(svmName, storagePoolUuid); |
323 | | - |
324 | | - // Verify host initiator is registered in the igroup before allowing access |
325 | | - if (!sanStrategy.validateInitiatorInAccessGroup(host.getStorageUrl(), svmName, accessGroupName)) { |
326 | | - throw new CloudRuntimeException("grantAccess: Host initiator [" + host.getStorageUrl() + |
327 | | - "] is not present in iGroup [" + accessGroupName + "]"); |
| 335 | + String accessGroupName = Utility.getIgroupName(svmName, host.getName()); |
| 336 | + |
| 337 | + // Validate if Igroup exist ONTAP for this host as we may be using delete_on_unmap= true and igroup may be deleted by ONTAP automatically |
| 338 | + Map<String, String> getAccessGroupMap = Map.of( |
| 339 | + Constants.NAME, accessGroupName, |
| 340 | + Constants.SVM_DOT_NAME, svmName |
| 341 | + ); |
| 342 | + Igroup igroup = new Igroup(); |
| 343 | + AccessGroup accessGroup = sanStrategy.getAccessGroup(getAccessGroupMap); |
| 344 | + if(accessGroup == null || accessGroup.getIgroup() == null) { |
| 345 | + s_logger.info("grantAccess: Igroup does not exist for the host: Need to create Igroup " + host.getName()); |
| 346 | + // create the igroup for the host and perform lun-mapping |
| 347 | + accessGroup = new AccessGroup(); |
| 348 | + List<HostVO> hosts = new ArrayList<>(); |
| 349 | + hosts.add((HostVO) host); |
| 350 | + accessGroup.setHostsToConnect(hosts); |
| 351 | + accessGroup.setStoragePoolId(storagePool.getId()); |
| 352 | + accessGroup = sanStrategy.createAccessGroup(accessGroup); |
| 353 | + }else{ |
| 354 | + s_logger.info("grantAccess: Igroup {} already exist for the host {}: ", accessGroup.getIgroup().getName() ,host.getName()); |
| 355 | + igroup = accessGroup.getIgroup(); |
| 356 | + // Verify host initiator is registered in the igroup before allowing access |
| 357 | +// if (sanStrategy.validateInitiatorInAccessGroup(host.getStorageUrl(), svmName, accessGroup.getIgroup())) { |
| 358 | +// // add host initiator to the igroup ? or fail here ? |
| 359 | +// } |
| 360 | + // Use the existing igroup and perform lun-mapping |
328 | 361 | } |
329 | 362 |
|
330 | 363 | // Create or retrieve existing LUN mapping |
@@ -453,7 +486,7 @@ private void revokeAccessForVolume(StoragePoolVO storagePool, VolumeVO volumeVO, |
453 | 486 |
|
454 | 487 | // Verify host initiator is in the igroup before attempting to remove mapping |
455 | 488 | SANStrategy sanStrategy = (UnifiedSANStrategy) storageStrategy; |
456 | | - if (!sanStrategy.validateInitiatorInAccessGroup(host.getStorageUrl(), svmName, accessGroup.getIgroup().getName())) { |
| 489 | + if (!sanStrategy.validateInitiatorInAccessGroup(host.getStorageUrl(), svmName, accessGroup.getIgroup())) { |
457 | 490 | s_logger.warn("revokeAccessForVolume: Initiator [{}] is not in iGroup [{}], skipping revoke", |
458 | 491 | host.getStorageUrl(), accessGroupName); |
459 | 492 | return; |
@@ -524,7 +557,6 @@ public long getUsedIops(StoragePool storagePool) { |
524 | 557 |
|
525 | 558 | @Override |
526 | 559 | public void takeSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback<CreateCmdResult> callback) { |
527 | | - |
528 | 560 | } |
529 | 561 |
|
530 | 562 | @Override |
@@ -569,7 +601,6 @@ public boolean isVmInfoNeeded() { |
569 | 601 |
|
570 | 602 | @Override |
571 | 603 | public void provideVmInfo(long vmId, long volumeId) { |
572 | | - |
573 | 604 | } |
574 | 605 |
|
575 | 606 | @Override |
|
0 commit comments