Skip to content

Commit 8eb430f

Browse files
author
Mike Tutkowski
committed
CLOUDSTACK-5662: XenServer can't discover iSCSI targets with different credentials
1 parent dc303fd commit 8eb430f

6 files changed

Lines changed: 88 additions & 5 deletions

File tree

‎api/src/com/cloud/hypervisor/HypervisorGuru.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,6 @@ public interface HypervisorGuru extends Adapter {
7575
*
7676
*/
7777
List<Command> finalizeExpungeNics(VirtualMachine vm, List<NicProfile> nics);
78+
79+
List<Command> finalizeExpungeVolumes(VirtualMachine vm);
7880
}

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,34 @@ protected void advanceExpunge(VMInstanceVO vm) throws ResourceUnavailableExcepti
479479
List<Command> nicExpungeCommands = hvGuru.finalizeExpungeNics(vm, profile.getNics());
480480
_networkMgr.cleanupNics(profile);
481481

482+
s_logger.debug("Cleaning up hypervisor data structures (ex. SRs in XenServer) for managed storage");
483+
484+
List<Command> volumeExpungeCommands = hvGuru.finalizeExpungeVolumes(vm);
485+
486+
if (volumeExpungeCommands != null) {
487+
Long hostId = vm.getHostId() != null ? vm.getHostId() : vm.getLastHostId();
488+
489+
if (hostId != null) {
490+
Commands cmds = new Commands(Command.OnError.Stop);
491+
492+
for (Command volumeExpungeCommand : volumeExpungeCommands) {
493+
cmds.addCommand(volumeExpungeCommand);
494+
}
495+
496+
_agentMgr.send(hostId, cmds);
497+
498+
if (!cmds.isSuccessful()) {
499+
for (Answer answer : cmds.getAnswers()) {
500+
if (!answer.getResult()) {
501+
s_logger.warn("Failed to expunge vm due to: " + answer.getDetails());
502+
503+
throw new CloudRuntimeException("Unable to expunge " + vm + " due to " + answer.getDetails());
504+
}
505+
}
506+
}
507+
}
508+
}
509+
482510
// Clean up volumes based on the vm's instance id
483511
volumeMgr.cleanupVolumes(vm.getId());
484512

‎plugins/hypervisors/xen/src/com/cloud/hypervisor/XenServerGuru.java‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
// under the License.
1717
package com.cloud.hypervisor;
1818

19+
import java.util.ArrayList;
20+
import java.util.List;
21+
1922
import javax.ejb.Local;
2023
import javax.inject.Inject;
2124

@@ -26,14 +29,22 @@
2629
import com.cloud.host.dao.HostDao;
2730
import com.cloud.hypervisor.Hypervisor.HypervisorType;
2831
import com.cloud.storage.GuestOSVO;
32+
import com.cloud.storage.Volume;
33+
import com.cloud.storage.VolumeVO;
2934
import com.cloud.storage.dao.GuestOSDao;
35+
import com.cloud.storage.dao.VolumeDao;
3036
import com.cloud.template.VirtualMachineTemplate.BootloaderType;
3137
import com.cloud.utils.Pair;
38+
import com.cloud.vm.VirtualMachine;
3239
import com.cloud.vm.VirtualMachineProfile;
3340
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
3441
import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
42+
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
3543
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
3644
import org.apache.cloudstack.storage.command.CopyCommand;
45+
import org.apache.cloudstack.storage.command.DettachCommand;
46+
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
47+
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
3748

3849
@Local(value=HypervisorGuru.class)
3950
public class XenServerGuru extends HypervisorGuruBase implements HypervisorGuru {
@@ -42,6 +53,12 @@ public class XenServerGuru extends HypervisorGuruBase implements HypervisorGuru
4253
EndPointSelector endPointSelector;
4354
@Inject
4455
HostDao hostDao;
56+
@Inject
57+
VolumeDao _volumeDao;
58+
@Inject
59+
PrimaryDataStoreDao _storagePoolDao;
60+
@Inject
61+
VolumeDataFactory _volFactory;
4562

4663
protected XenServerGuru() {
4764
super();
@@ -73,6 +90,39 @@ public boolean trackVmHostChange() {
7390
return true;
7491
}
7592

93+
@Override
94+
public List<Command> finalizeExpungeVolumes(VirtualMachine vm) {
95+
List<Command> commands = new ArrayList<Command>();
96+
97+
List<VolumeVO> volumes = _volumeDao.findByInstance(vm.getId());
98+
99+
if (volumes != null) {
100+
for (VolumeVO volume : volumes) {
101+
if (volume.getVolumeType() == Volume.Type.DATADISK) {
102+
StoragePoolVO storagePool = _storagePoolDao.findById(volume.getPoolId());
103+
104+
if (storagePool.isManaged()) {
105+
DataTO volTO = _volFactory.getVolume(volume.getId()).getTO();
106+
DiskTO disk = new DiskTO(volTO, volume.getDeviceId(), volume.getPath(), volume.getVolumeType());
107+
108+
DettachCommand cmd = new DettachCommand(disk, vm.getInstanceName());
109+
110+
cmd.setManaged(true);
111+
112+
cmd.setStorageHost(storagePool.getHostAddress());
113+
cmd.setStoragePort(storagePool.getPort());
114+
115+
cmd.set_iScsiName(volume.get_iScsiName());
116+
117+
commands.add(cmd);
118+
}
119+
}
120+
}
121+
}
122+
123+
return commands;
124+
}
125+
76126
@Override
77127
public Pair<Boolean, Long> getCommandHostDelegation(long hostId, Command cmd) {
78128
if (cmd instanceof CopyCommand) {

‎plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6504,9 +6504,7 @@ protected VDI createVdi(SR sr, String vdiNameLabel, Long volumeSize) throws Type
65046504
return vdi;
65056505
}
65066506

6507-
protected void handleSrAndVdiDetach(String iqn) throws Exception {
6508-
Connection conn = getConnection();
6509-
6507+
protected void handleSrAndVdiDetach(String iqn, Connection conn) throws Exception {
65106508
SR sr = getStorageRepository(conn, iqn);
65116509

65126510
removeSR(conn, sr);
@@ -6614,7 +6612,7 @@ protected AttachVolumeAnswer execute(final AttachVolumeCommand cmd) {
66146612
vdi.setNameLabel(conn, "detached");
66156613

66166614
if (cmd.isManaged()) {
6617-
handleSrAndVdiDetach(cmd.get_iScsiName());
6615+
handleSrAndVdiDetach(cmd.get_iScsiName(), conn);
66186616
}
66196617

66206618
return new AttachVolumeAnswer(cmd);

‎plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServerStorageProcessor.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ public Answer dettachVolume(DettachCommand cmd) {
425425
}
426426

427427
if (cmd.isManaged()) {
428-
hypervisorResource.handleSrAndVdiDetach(cmd.get_iScsiName());
428+
hypervisorResource.handleSrAndVdiDetach(cmd.get_iScsiName(), conn);
429429
}
430430

431431
return new DettachAnswer(disk);

‎server/src/com/cloud/hypervisor/HypervisorGuruBase.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,9 @@ public List<Command> finalizeExpunge(VirtualMachine vm) {
144144
public List<Command> finalizeExpungeNics(VirtualMachine vm, List<NicProfile> nics) {
145145
return null;
146146
}
147+
148+
@Override
149+
public List<Command> finalizeExpungeVolumes(VirtualMachine vm) {
150+
return null;
151+
}
147152
}

0 commit comments

Comments
 (0)