@@ -260,7 +260,7 @@ public void copyAsync(DataObject srcData, DataObject destData, Host destHost, As
260260 } else {
261261 answer = agentMgr .sendTo (sourcePool .getDataCenterId (), HypervisorType .VMware , cmd );
262262 }
263- updateVolumeAfterMigration (answer , srcData , destData );
263+ handleAnswerAndUpdateVolumeAfterMigration (answer , srcData , destData );
264264 CopyCommandResult result = new CopyCommandResult (null , answer );
265265 callback .complete (result );
266266 }
@@ -286,21 +286,19 @@ private Long findSuitableHostIdForWorkerVmPlacement(Long clusterId) {
286286 return hostId ;
287287 }
288288
289- private void updateVolumeAfterMigration (Answer answer , DataObject srcData , DataObject destData ) {
289+ private void handleAnswerAndUpdateVolumeAfterMigration (Answer answer , DataObject srcData , DataObject destData ) {
290290 VolumeVO destinationVO = volDao .findById (destData .getId ());
291291 if (!(answer instanceof MigrateVolumeAnswer )) {
292292 // OfflineVmwareMigration: reset states and such
293- VolumeVO sourceVO = volDao .findById (srcData .getId ());
294- sourceVO .setState (Volume .State .Ready );
295- volDao .update (sourceVO .getId (), sourceVO );
296- if (destinationVO .getId () != sourceVO .getId ()) {
297- destinationVO .setState (Volume .State .Expunged );
298- destinationVO .setRemoved (new Date ());
299- volDao .update (destinationVO .getId (), destinationVO );
300- }
293+ resetVolumeState (srcData , destinationVO );
301294 throw new CloudRuntimeException ("unexpected answer from hypervisor agent: " + answer .getDetails ());
302295 }
303296 MigrateVolumeAnswer ans = (MigrateVolumeAnswer ) answer ;
297+ if (!answer .getResult ()) {
298+ String msg = "Unable to migrate volume: " + srcData .getName () + " due to " + answer .getDetails ();
299+ resetVolumeState (srcData , destinationVO );
300+ throw new CloudRuntimeException (msg );
301+ }
304302 if (logger .isDebugEnabled ()) {
305303 String format = "retrieved '%s' as new path for volume(%d)" ;
306304 logger .debug (String .format (format , ans .getVolumePath (), destData .getId ()));
@@ -311,6 +309,17 @@ private void updateVolumeAfterMigration(Answer answer, DataObject srcData, DataO
311309 volDao .update (destinationVO .getId (), destinationVO );
312310 }
313311
312+ private void resetVolumeState (DataObject srcData , VolumeVO destinationVO ) {
313+ VolumeVO sourceVO = volDao .findById (srcData .getId ());
314+ sourceVO .setState (Volume .State .Ready );
315+ volDao .update (sourceVO .getId (), sourceVO );
316+ if (destinationVO .getId () != sourceVO .getId ()) {
317+ destinationVO .setState (Volume .State .Expunged );
318+ destinationVO .setRemoved (new Date ());
319+ volDao .update (destinationVO .getId (), destinationVO );
320+ }
321+ }
322+
314323 @ Override
315324 public void copyAsync (Map <VolumeInfo , DataStore > volumeMap , VirtualMachineTO vmTo , Host srcHost , Host destHost , AsyncCompletionCallback <CopyCommandResult > callback ) {
316325 Answer answer = null ;
0 commit comments