/** * If the underlying storage system needed to create a volume from a snapshot for createVolumeFromSnapshot(SnapshotInfo), then * this is its opportunity to delete that temporary volume and restore properties in snapshot_details to the way they were before the * invocation of createVolumeFromSnapshot(SnapshotInfo). */ private void deleteVolumeFromSnapshot(SnapshotInfo snapshotInfo) { SnapshotDetailsVO snapshotDetails = handleSnapshotDetails(snapshotInfo.getId(), "delete"); try { snapshotInfo.getDataStore().getDriver().createAsync(snapshotInfo.getDataStore(), snapshotInfo, null); } finally { _snapshotDetailsDao.remove(snapshotDetails.getId()); } }
/** * If the underlying storage system is making use of read-only snapshots, this gives the storage system the opportunity to * create a volume from the snapshot so that we can copy the VHD file that should be inside of the snapshot to secondary storage. * * The resultant volume must be writable because we need to resign the SR and the VDI that should be inside of it before we copy * the VHD file to secondary storage. * * If the storage system is using writable snapshots, then nothing need be done by that storage system here because we can just * resign the SR and the VDI that should be inside of the snapshot before copying the VHD file to secondary storage. */ private void createVolumeFromSnapshot(SnapshotInfo snapshotInfo) { SnapshotDetailsVO snapshotDetails = handleSnapshotDetails(snapshotInfo.getId(), "create"); try { snapshotInfo.getDataStore().getDriver().createAsync(snapshotInfo.getDataStore(), snapshotInfo, null); } finally { _snapshotDetailsDao.remove(snapshotDetails.getId()); } }
AsyncCallbackDispatcher<TemplateServiceImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this); caller.setCallback(caller.getTarget().copyTemplateCrossZoneCallBack(null, null)).setContext(context); destStore.getDriver().createAsync(destStore, templateOnStore, caller); } catch (CloudRuntimeException ex) {
destVolumeInfo.getDataStore().getDriver().createAsync(destVolumeInfo.getDataStore(), destVolumeInfo, null);
destVolumeInfo.getDataStore().getDriver().createAsync(destVolumeInfo.getDataStore(), destVolumeInfo, null);
caller.setCallback(caller.getTarget().createAsynCallback(null, null)).setContext(context); store.getDriver().createAsync(store, objInStore, caller); return;
store.getDriver().createAsync(store, templateOnStore, caller); } catch (CloudRuntimeException ex) {
destDataStore.getDriver().createAsync(destDataStore, destVolumeInfo, null);
@Override public AsyncCallFuture<VolumeApiResult> registerVolume(VolumeInfo volume, DataStore store) { AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<VolumeApiResult>(); DataObject volumeOnStore = store.create(volume); volumeOnStore.processEvent(Event.CreateOnlyRequested); try { CreateVolumeContext<VolumeApiResult> context = new CreateVolumeContext<VolumeApiResult>(null, volumeOnStore, future); AsyncCallbackDispatcher<VolumeServiceImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this); caller.setCallback(caller.getTarget().registerVolumeCallback(null, null)); caller.setContext(context); store.getDriver().createAsync(store, volumeOnStore, caller); } catch (CloudRuntimeException ex) { // clean up already persisted volume_store_ref entry in case of createVolumeCallback is never called VolumeDataStoreVO volStoreVO = _volumeStoreDao.findByStoreVolume(store.getId(), volume.getId()); if (volStoreVO != null) { VolumeInfo volObj = volFactory.getVolume(volume, store); volObj.processEvent(ObjectInDataStoreStateMachine.Event.OperationFailed); } VolumeApiResult res = new VolumeApiResult((VolumeObject)volumeOnStore); res.setResult(ex.getMessage()); future.complete(res); } return future; }
@Override public AsyncCallFuture<VolumeApiResult> createVolumeAsync(VolumeInfo volume, DataStore dataStore) { AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<VolumeApiResult>(); DataObject volumeOnStore = dataStore.create(volume); volumeOnStore.processEvent(Event.CreateOnlyRequested); try { CreateVolumeContext<VolumeApiResult> context = new CreateVolumeContext<VolumeApiResult>(null, volumeOnStore, future); AsyncCallbackDispatcher<VolumeServiceImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this); caller.setCallback(caller.getTarget().createVolumeCallback(null, null)).setContext(context); dataStore.getDriver().createAsync(dataStore, volumeOnStore, caller); } catch (CloudRuntimeException ex) { // clean up already persisted volume_store_ref entry in case of createVolumeCallback is never called VolumeDataStoreVO volStoreVO = _volumeStoreDao.findByStoreVolume(dataStore.getId(), volume.getId()); if (volStoreVO != null) { VolumeInfo volObj = volFactory.getVolume(volume, dataStore); volObj.processEvent(ObjectInDataStoreStateMachine.Event.OperationFailed); } VolumeApiResult volResult = new VolumeApiResult((VolumeObject)volumeOnStore); volResult.setResult(ex.getMessage()); future.complete(volResult); } return future; }
destPrimaryDataStore.getDriver().createAsync(destPrimaryDataStore, templateOnPrimary, createCaller);
private void handleVolumeMigrationForKVM(VolumeInfo srcVolumeInfo, VolumeInfo destVolumeInfo) { VirtualMachine vm = srcVolumeInfo.getAttachedVM(); if (vm != null && vm.getState() != VirtualMachine.State.Stopped) { throw new CloudRuntimeException("Currently, if a volume to migrate from non-managed storage to managed storage on KVM is attached to " + "a VM, the VM must be in the Stopped state."); } destVolumeInfo.getDataStore().getDriver().createAsync(destVolumeInfo.getDataStore(), destVolumeInfo, null); VolumeVO volumeVO = _volumeDao.findById(destVolumeInfo.getId()); volumeVO.setPath(volumeVO.get_iScsiName()); _volumeDao.update(volumeVO.getId(), volumeVO); destVolumeInfo = _volumeDataFactory.getVolume(destVolumeInfo.getId(), destVolumeInfo.getDataStore()); long srcStoragePoolId = srcVolumeInfo.getPoolId(); StoragePoolVO srcStoragePoolVO = _storagePoolDao.findById(srcStoragePoolId); HostVO hostVO; if (srcStoragePoolVO.getClusterId() != null) { hostVO = getHostInCluster(srcStoragePoolVO.getClusterId()); } else { hostVO = getHost(destVolumeInfo.getDataCenterId(), HypervisorType.KVM, false); } // migrate the volume via the hypervisor migrateVolumeForKVM(srcVolumeInfo, destVolumeInfo, hostVO, "Unable to migrate the volume from non-managed storage to managed storage"); volumeVO = _volumeDao.findById(destVolumeInfo.getId()); volumeVO.setFormat(ImageFormat.QCOW2); _volumeDao.update(volumeVO.getId(), volumeVO); }