@@ -1030,32 +1030,26 @@ public Answer backupSnapshot(CopyCommand cmd) {
10301030 CopyCmdAnswer answer = null ;
10311031
10321032 try {
1033- vmMo = hyperHost .findVmOnHyperHost (vmName );
1034- if (vmMo == null ) {
1035- if (s_logger .isDebugEnabled ()) {
1036- s_logger .debug ("Unable to find owner VM for BackupSnapshotCommand on host " + hyperHost .getHyperHostName () + ", will try within datacenter" );
1037- }
1038-
1039- vmMo = hyperHost .findVmOnPeerHyperHost (vmName );
1040- if (vmMo == null ) {
1041- dsMo = new DatastoreMO (hyperHost .getContext (), morDs );
1042-
1043- workerVMName = hostService .getWorkerName (context , cmd , 0 );
1044-
1045- vmMo = HypervisorHostHelper .createWorkerVM (hyperHost , dsMo , workerVMName );
1046-
1047- if (vmMo == null ) {
1048- throw new Exception ("Failed to find the newly create or relocated VM. vmName: " + workerVMName );
1033+ if (vmName != null ) {
1034+ vmMo = hyperHost .findVmOnHyperHost (vmName );
1035+ if (vmMo == null ) {
1036+ if (s_logger .isDebugEnabled ()) {
1037+ s_logger .debug ("Unable to find owner VM for BackupSnapshotCommand on host " + hyperHost .getHyperHostName () + ", will try within datacenter" );
10491038 }
1050- workerVm = vmMo ;
1051-
1052- // attach volume to worker VM
1053- String datastoreVolumePath = dsMo .getDatastorePath (volumePath + ".vmdk" );
1054- vmMo .attachDisk (new String [] { datastoreVolumePath }, morDs );
1055- } else {
1056- s_logger .info ("Using owner VM " + vmName + " for snapshot operation" );
1057- hasOwnerVm = true ;
1039+ vmMo = hyperHost .findVmOnPeerHyperHost (vmName );
1040+ }
1041+ }
1042+ if (vmMo == null ) {
1043+ dsMo = new DatastoreMO (hyperHost .getContext (), morDs );
1044+ workerVMName = hostService .getWorkerName (context , cmd , 0 );
1045+ vmMo = HypervisorHostHelper .createWorkerVM (hyperHost , dsMo , workerVMName );
1046+ if (vmMo == null ) {
1047+ throw new Exception ("Failed to find the newly create or relocated VM. vmName: " + workerVMName );
10581048 }
1049+ workerVm = vmMo ;
1050+ // attach volume to worker VM
1051+ String datastoreVolumePath = dsMo .getDatastorePath (volumePath + ".vmdk" );
1052+ vmMo .attachDisk (new String [] { datastoreVolumePath }, morDs );
10591053 } else {
10601054 s_logger .info ("Using owner VM " + vmName + " for snapshot operation" );
10611055 hasOwnerVm = true ;
0 commit comments