Skip to content

Commit 7ef78aa

Browse files
author
Mike Tutkowski
committed
Merge from 4.3: CLOUDSTACK-5662: XenServer can't discover iSCSI targets with different credentials
1 parent 6944bf9 commit 7ef78aa

3 files changed

Lines changed: 38 additions & 15 deletions

File tree

engine/api/src/org/apache/cloudstack/engine/orchestration/service/VolumeOrchestrationService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ VolumeInfo moveVolume(VolumeInfo volume, long destPoolDcId, Long destPoolPodId,
9494

9595
void cleanupVolumes(long vmId) throws ConcurrentOperationException;
9696

97+
void disconnectVolumesFromHost(long vmId, long hostId);
98+
9799
void migrateVolumes(VirtualMachine vm, VirtualMachineTO vmTo, Host srcHost, Host destHost, Map<Volume, StoragePool> volumeToPool);
98100

99101
boolean storageMigration(VirtualMachineProfile vm, StoragePool destPool) throws StorageUnavailableException;

engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -489,30 +489,32 @@ protected void advanceExpunge(VMInstanceVO vm) throws ResourceUnavailableExcepti
489489

490490
List<Command> volumeExpungeCommands = hvGuru.finalizeExpungeVolumes(vm);
491491

492-
if (volumeExpungeCommands != null) {
493-
Long hostId = vm.getHostId() != null ? vm.getHostId() : vm.getLastHostId();
492+
Long hostId = vm.getHostId() != null ? vm.getHostId() : vm.getLastHostId();
494493

495-
if (hostId != null) {
496-
Commands cmds = new Commands(Command.OnError.Stop);
494+
if (volumeExpungeCommands != null && hostId != null) {
495+
Commands cmds = new Commands(Command.OnError.Stop);
497496

498-
for (Command volumeExpungeCommand : volumeExpungeCommands) {
499-
cmds.addCommand(volumeExpungeCommand);
500-
}
497+
for (Command volumeExpungeCommand : volumeExpungeCommands) {
498+
cmds.addCommand(volumeExpungeCommand);
499+
}
501500

502-
_agentMgr.send(hostId, cmds);
501+
_agentMgr.send(hostId, cmds);
503502

504-
if (!cmds.isSuccessful()) {
505-
for (Answer answer : cmds.getAnswers()) {
506-
if (!answer.getResult()) {
507-
s_logger.warn("Failed to expunge vm due to: " + answer.getDetails());
503+
if (!cmds.isSuccessful()) {
504+
for (Answer answer : cmds.getAnswers()) {
505+
if (!answer.getResult()) {
506+
s_logger.warn("Failed to expunge vm due to: " + answer.getDetails());
508507

509-
throw new CloudRuntimeException("Unable to expunge " + vm + " due to " + answer.getDetails());
510-
}
508+
throw new CloudRuntimeException("Unable to expunge " + vm + " due to " + answer.getDetails());
511509
}
512510
}
513511
}
514512
}
515513

514+
if (hostId != null) {
515+
volumeMgr.disconnectVolumesFromHost(vm.getId(), hostId);
516+
}
517+
516518
// Clean up volumes based on the vm's instance id
517519
volumeMgr.cleanupVolumes(vm.getId());
518520

@@ -524,7 +526,6 @@ protected void advanceExpunge(VMInstanceVO vm) throws ResourceUnavailableExcepti
524526
// send hypervisor-dependent commands before removing
525527
List<Command> finalizeExpungeCommands = hvGuru.finalizeExpunge(vm);
526528
if (finalizeExpungeCommands != null && finalizeExpungeCommands.size() > 0) {
527-
Long hostId = vm.getHostId() != null ? vm.getHostId() : vm.getLastHostId();
528529
if (hostId != null) {
529530
Commands cmds = new Commands(Command.OnError.Stop);
530531
for (Command command : finalizeExpungeCommands) {

engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373
import com.cloud.exception.InvalidParameterValueException;
7474
import com.cloud.exception.StorageUnavailableException;
7575
import com.cloud.host.Host;
76+
import com.cloud.host.HostVO;
77+
import com.cloud.host.dao.HostDao;
7678
import com.cloud.hypervisor.Hypervisor.HypervisorType;
7779
import com.cloud.offering.DiskOffering;
7880
import com.cloud.offering.ServiceOffering;
@@ -143,6 +145,8 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati
143145
@Inject
144146
ConfigDepot _configDepot;
145147
@Inject
148+
HostDao _hostDao;
149+
@Inject
146150
SnapshotService _snapshotSrv;
147151

148152
private final StateMachine2<Volume.State, Volume.Event, Volume> _volStateMachine;
@@ -787,6 +791,22 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
787791
}
788792
}
789793

794+
@Override
795+
public void disconnectVolumesFromHost(long vmId, long hostId) {
796+
HostVO host = _hostDao.findById(hostId);
797+
798+
List<VolumeVO> volumesForVm = _volsDao.findByInstance(vmId);
799+
800+
if (volumesForVm != null) {
801+
for (VolumeVO volumeForVm : volumesForVm) {
802+
VolumeInfo volumeInfo = volFactory.getVolume(volumeForVm.getId());
803+
DataStore dataStore = dataStoreMgr.getDataStore(volumeForVm.getPoolId(), DataStoreRole.Primary);
804+
805+
volService.disconnectVolumeFromHost(volumeInfo, host, dataStore);
806+
}
807+
}
808+
}
809+
790810
@Override
791811
@DB
792812
public Volume migrateVolume(Volume volume, StoragePool destPool) throws StorageUnavailableException {

0 commit comments

Comments
 (0)