@@ -3159,9 +3159,7 @@ protected void migrate(final VMInstanceVO vm, final long srcHostId, final Deploy
31593159
31603160 final VirtualMachineTO to = toVmTO (profile );
31613161
3162- if (vm .getHypervisorType () == HypervisorType .KVM && hasClvmVolumes (vm .getId ())) {
3163- executePreMigrationCommand (to , vm .getInstanceName (), srcHostId );
3164- }
3162+ executePreMigrationCommand (vm , to , srcHostId );
31653163
31663164 final PrepareForMigrationCommand pfmc = new PrepareForMigrationCommand (to );
31673165 setVmNetworkDetails (vm , to );
@@ -3335,25 +3333,26 @@ protected void migrate(final VMInstanceVO vm, final long srcHostId, final Deploy
33353333 }
33363334
33373335 private void executePostMigrationCommand (VMInstanceVO vm , VirtualMachineTO to , long dstHostId ) {
3338- if (vm .getHypervisorType () == HypervisorType .KVM && hasClvmVolumes (vm .getId ())) {
3339- try {
3340- logger .info ("Executing post-migration tasks for VM {} with CLVM volumes on destination host {}" , vm .getInstanceName (), dstHostId );
3341- final PostMigrationCommand postMigrationCommand = new PostMigrationCommand (to , vm .getInstanceName ());
3342- final Answer postMigrationAnswer = _agentMgr .send (dstHostId , postMigrationCommand );
3343-
3344- if (postMigrationAnswer == null || !postMigrationAnswer .getResult ()) {
3345- final String details = postMigrationAnswer != null ? postMigrationAnswer .getDetails () : "null answer returned" ;
3346- logger .warn ("Post-migration tasks failed for VM {} on destination host {}: {}. Migration completed but some cleanup may be needed." ,
3347- vm .getInstanceName (), dstHostId , details );
3348- } else {
3349- logger .info ("Successfully completed post-migration tasks for VM {} on destination host {}" , vm .getInstanceName (), dstHostId );
3350- }
3351- } catch (Exception e ) {
3352- logger .warn ("Exception during post-migration tasks for VM {} on destination host {}: {}. Migration completed but some cleanup may be needed." ,
3353- vm .getInstanceName (), dstHostId , e .getMessage (), e );
3336+ if (!(vm .getHypervisorType () == HypervisorType .KVM && hasClvmVolumes (vm .getId ()))) {
3337+ return ;
3338+ }
3339+ final String dstHostUuid = _hostDao .findById (dstHostId ).getUuid ();
3340+ try {
3341+ logger .info ("Executing post-migration tasks for VM {} with CLVM volumes on destination host {}" , vm .getInstanceName (), dstHostUuid );
3342+ final PostMigrationCommand postMigrationCommand = new PostMigrationCommand (to , vm .getInstanceName ());
3343+ final Answer postMigrationAnswer = _agentMgr .send (dstHostId , postMigrationCommand );
3344+
3345+ if (postMigrationAnswer == null || !postMigrationAnswer .getResult ()) {
3346+ final String details = postMigrationAnswer != null ? postMigrationAnswer .getDetails () : "null answer returned" ;
3347+ logger .warn ("Post-migration tasks failed for VM {} on destination host {}: {}. Migration completed but some cleanup may be needed." ,
3348+ vm .getInstanceName (), dstHostUuid , details );
3349+ } else {
3350+ logger .info ("Successfully completed post-migration tasks for VM {} on destination host {}" , vm .getInstanceName (), dstHostUuid );
33543351 }
3352+ } catch (Exception e ) {
3353+ logger .warn ("Exception during post-migration tasks for VM {} on destination host {}: {}. Migration completed but some cleanup may be needed." ,
3354+ vm .getInstanceName (), dstHostUuid , e .getMessage (), e );
33553355 }
3356-
33573356 updateClvmLockHostForVmVolumes (vm .getId (), dstHostId );
33583357 }
33593358
@@ -4983,9 +4982,7 @@ private void orchestrateMigrateForScale(final String vmUuid, final long srcHostI
49834982
49844983 // Step 1: Send PreMigrationCommand to source host to convert CLVM volumes to shared mode
49854984 // This must happen BEFORE PrepareForMigrationCommand on destination to avoid lock conflicts
4986- if (vm .getHypervisorType () == HypervisorType .KVM && hasClvmVolumes (vm .getId ())) {
4987- executePreMigrationCommand (to , vm .getInstanceName (), srcHostId );
4988- }
4985+ executePreMigrationCommand (vm , to , srcHostId );
49894986
49904987 // Step 2: Send PrepareForMigrationCommand to destination host
49914988 final PrepareForMigrationCommand pfmc = new PrepareForMigrationCommand (to );
@@ -5072,6 +5069,7 @@ private void orchestrateMigrateForScale(final String vmUuid, final long srcHostI
50725069 }
50735070
50745071 migrated = true ;
5072+ executePostMigrationCommand (vm , to , dstHostId );
50755073 } finally {
50765074 if (!migrated ) {
50775075 logger .info ("Migration was unsuccessful. Cleaning up: {}" , vm );
@@ -6514,21 +6512,26 @@ private boolean hasClvmVolumes(long vmId) {
65146512 .anyMatch (pool -> pool != null && ClvmPoolManager .isClvmPoolType (pool .getPoolType ()));
65156513 }
65166514
6517- private void executePreMigrationCommand (VirtualMachineTO to , String vmInstanceName , long srcHostId ) {
6518- logger .info ("Sending PreMigrationCommand to source host {} for VM {} with CLVM volumes" , srcHostId , vmInstanceName );
6515+ private void executePreMigrationCommand (VMInstanceVO vm , VirtualMachineTO to , long srcHostId ) {
6516+ if (!(vm .getHypervisorType () == HypervisorType .KVM && hasClvmVolumes (vm .getId ()))) {
6517+ return ;
6518+ }
6519+ final String vmInstanceName = vm .getInstanceName ();
6520+ final String srcHostUuid = _hostDao .findById (srcHostId ).getUuid ();
6521+ logger .info ("Sending PreMigrationCommand to source host {} for VM {} with CLVM volumes" , srcHostUuid , vmInstanceName );
65196522 final PreMigrationCommand preMigCmd = new PreMigrationCommand (to , vmInstanceName );
65206523 Answer preMigAnswer = null ;
65216524 try {
65226525 preMigAnswer = _agentMgr .send (srcHostId , preMigCmd );
65236526 if (preMigAnswer == null || !preMigAnswer .getResult ()) {
65246527 final String details = preMigAnswer != null ? preMigAnswer .getDetails () : "null answer returned" ;
65256528 final String msg = "Failed to prepare source host for migration: " + details ;
6526- logger .error ("Failed to prepare source host {} for migration of VM {}: {}" , srcHostId , vmInstanceName , details );
6529+ logger .error ("Failed to prepare source host {} for migration of VM {}: {}" , srcHostUuid , vmInstanceName , details );
65276530 throw new CloudRuntimeException (msg );
65286531 }
6529- logger .info ("Successfully prepared source host {} for migration of VM {}" , srcHostId , vmInstanceName );
6532+ logger .info ("Successfully prepared source host {} for migration of VM {}" , srcHostUuid , vmInstanceName );
65306533 } catch (final AgentUnavailableException | OperationTimedoutException e ) {
6531- logger .error ("Failed to send PreMigrationCommand to source host {}: {}" , srcHostId , e .getMessage (), e );
6534+ logger .error ("Failed to send PreMigrationCommand to source host {}: {}" , srcHostUuid , e .getMessage (), e );
65326535 throw new CloudRuntimeException ("Failed to prepare source host for migration: " + e .getMessage (), e );
65336536 }
65346537 }
0 commit comments