|
39 | 39 | import com.cloud.storage.DiskOfferingVO; |
40 | 40 | import com.cloud.storage.SnapshotVO; |
41 | 41 | import com.cloud.storage.Storage.ImageFormat; |
| 42 | +import com.cloud.storage.Volume; |
42 | 43 | import com.cloud.storage.VolumeDetailVO; |
43 | 44 | import com.cloud.storage.VolumeVO; |
44 | 45 | import com.cloud.storage.dao.DiskOfferingDao; |
|
86 | 87 | import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; |
87 | 88 | import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; |
88 | 89 | import org.apache.cloudstack.storage.to.PrimaryDataStoreTO; |
| 90 | +import org.apache.cloudstack.storage.to.SnapshotObjectTO; |
89 | 91 | import org.apache.cloudstack.storage.to.VolumeObjectTO; |
90 | 92 | import org.apache.commons.lang.StringUtils; |
91 | 93 | import org.apache.log4j.Logger; |
@@ -445,6 +447,29 @@ private void handleCopyDataToSecondaryStorage(SnapshotInfo snapshotInfo, DataObj |
445 | 447 | throw new CloudRuntimeException(msg + ex.getMessage()); |
446 | 448 |
|
447 | 449 | } finally { |
| 450 | + |
| 451 | + // detach and remove access after the volume is created |
| 452 | + SnapshotObjectTO snapshotObjectTO = (SnapshotObjectTO) snapshotInfo.getTO(); |
| 453 | + DiskTO disk = new DiskTO(snapshotObjectTO, null, snapshotInfo.getPath(), Volume.Type.UNKNOWN); |
| 454 | + DettachCommand cmd = new DettachCommand(disk, null); |
| 455 | + StoragePoolVO storagePool = _storagePoolDao.findById(srcDataStore.getId()); |
| 456 | + |
| 457 | + cmd.setManaged(true); |
| 458 | + cmd.setStorageHost(storagePool.getHostAddress()); |
| 459 | + cmd.setStoragePort(storagePool.getPort()); |
| 460 | + cmd.set_iScsiName(getProperty(snapshotInfo.getId(), DiskTO.IQN)); |
| 461 | + |
| 462 | + try { |
| 463 | + DettachAnswer dettachAnswer = (DettachAnswer) _agentMgr.send(hostVO.getId(), cmd); |
| 464 | + |
| 465 | + if (!dettachAnswer.getResult()) { |
| 466 | + throw new CloudRuntimeException("Error detaching volume:" + dettachAnswer.getDetails()); |
| 467 | + } |
| 468 | + |
| 469 | + } catch (Exception e) { |
| 470 | + LOGGER.warn("Error detaching volume for snapshot " + snapshotInfo.getId() + " Error: " + e.getMessage()); |
| 471 | + } |
| 472 | + |
448 | 473 | try { |
449 | 474 | _volumeService.revokeAccess(snapshotInfo, hostVO, srcDataStore); |
450 | 475 | } |
|
0 commit comments