Skip to content

Commit 574fc3a

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

13 files changed

Lines changed: 646 additions & 158 deletions

File tree

api/src/com/cloud/host/Host.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ public static String[] toStrings(Host.Type... types) {
9191
*/
9292
String getPrivateIpAddress();
9393

94+
/**
95+
* @return the ip address of the host.
96+
*/
97+
String getStorageUrl();
98+
9499
/**
95100
* @return the ip address of the host attached to the storage network.
96101
*/

core/test/org/apache/cloudstack/api/agent/test/CheckOnHostCommandTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ public String getPrivateIpAddress() {
7676
return "10.1.1.1";
7777
};
7878

79+
public String getStorageUrl() {
80+
return null;
81+
}
82+
7983
public String getStorageIpAddress() {
8084
return "10.1.1.2";
8185
};

engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreDriver.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,19 @@
1818
*/
1919
package org.apache.cloudstack.engine.subsystem.api.storage;
2020

21+
import java.util.List;
22+
2123
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
2224
import org.apache.cloudstack.storage.command.CommandResult;
2325

26+
import com.cloud.host.Host;
2427
import com.cloud.storage.StoragePool;
2528
import com.cloud.storage.Volume;
2629

2730
public interface PrimaryDataStoreDriver extends DataStoreDriver {
2831
public ChapInfo getChapInfo(VolumeInfo volumeInfo);
32+
public boolean connectVolumeToHost(VolumeInfo volumeInfo, Host host, DataStore dataStore);
33+
public void disconnectVolumeFromHost(VolumeInfo volumeInfo, Host host, DataStore dataStore);
2934
public long getVolumeSizeIncludingHypervisorSnapshotReserve(Volume volume, StoragePool pool);
3035
public void takeSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback<CreateCmdResult> callback);
3136
public void revertSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback<CommandResult> callback);

engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.apache.cloudstack.engine.subsystem.api.storage;
2020

2121
import java.util.Map;
22+
import java.util.List;
2223

2324
import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
2425
import org.apache.cloudstack.framework.async.AsyncCallFuture;
@@ -44,6 +45,10 @@ public VolumeInfo getVolume() {
4445

4546
ChapInfo getChapInfo(VolumeInfo volumeInfo, DataStore dataStore);
4647

48+
boolean connectVolumeToHost(VolumeInfo volumeInfo, Host host, DataStore dataStore);
49+
50+
void disconnectVolumeFromHost(VolumeInfo volumeInfo, Host host, DataStore dataStore);
51+
4752
/**
4853
* Creates the volume based on the given criteria
4954
*

engine/storage/integration-test/test/org/apache/cloudstack/storage/test/FakePrimaryDataStoreDriver.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919
package org.apache.cloudstack.storage.test;
2020

21+
import java.util.List;
22+
import java.util.Map;
2123
import java.util.UUID;
2224

2325
import org.apache.cloudstack.engine.subsystem.api.storage.ChapInfo;
@@ -35,16 +37,29 @@
3537

3638
import com.cloud.agent.api.to.DataStoreTO;
3739
import com.cloud.agent.api.to.DataTO;
40+
import com.cloud.host.Host;
3841
import com.cloud.storage.StoragePool;
3942
import com.cloud.storage.Volume;
4043

4144
public class FakePrimaryDataStoreDriver implements PrimaryDataStoreDriver {
4245
boolean snapshotResult = true;
46+
47+
@Override
48+
public Map<String, String> getCapabilities() {
49+
return null;
50+
}
51+
4352
@Override
4453
public ChapInfo getChapInfo(VolumeInfo volumeInfo) {
45-
return null; //To change body of implemented methods use File | Settings | File Templates.
54+
return null; // To change body of implemented methods, use File | Settings | File Templates.
4655
}
4756

57+
@Override
58+
public boolean connectVolumeToHost(VolumeInfo volumeInfo, Host host, DataStore dataStore) { return false; }
59+
60+
@Override
61+
public void disconnectVolumeFromHost(VolumeInfo volumeInfo, Host host, DataStore dataStore) {}
62+
4863
@Override
4964
public long getVolumeSizeIncludingHypervisorSnapshotReserve(Volume volume, StoragePool pool) {
5065
return volume.getSize();

engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,24 @@ public ChapInfo getChapInfo(VolumeInfo volumeInfo, DataStore dataStore) {
159159
return null;
160160
}
161161

162+
public boolean connectVolumeToHost(VolumeInfo volumeInfo, Host host, DataStore dataStore) {
163+
DataStoreDriver dataStoreDriver = dataStore.getDriver();
164+
165+
if (dataStoreDriver instanceof PrimaryDataStoreDriver) {
166+
return ((PrimaryDataStoreDriver)dataStoreDriver).connectVolumeToHost(volumeInfo, host, dataStore);
167+
}
168+
169+
return false;
170+
}
171+
172+
public void disconnectVolumeFromHost(VolumeInfo volumeInfo, Host host, DataStore dataStore) {
173+
DataStoreDriver dataStoreDriver = dataStore.getDriver();
174+
175+
if (dataStoreDriver instanceof PrimaryDataStoreDriver) {
176+
((PrimaryDataStoreDriver)dataStoreDriver).disconnectVolumeFromHost(volumeInfo, host, dataStore);
177+
}
178+
}
179+
162180
@Override
163181
public AsyncCallFuture<VolumeApiResult> createVolumeAsync(VolumeInfo volume, DataStore dataStore) {
164182
AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<VolumeApiResult>();

plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4808,22 +4808,26 @@ public ManagedObjectReference getVmfsDatastore(VmwareHypervisorHost hyperHost, S
48084808
target.setPort(storagePortNumber);
48094809
target.setIScsiName(iqn);
48104810

4811-
HostInternetScsiHbaAuthenticationProperties auth = new HostInternetScsiHbaAuthenticationProperties();
4811+
if (StringUtils.isNotBlank(chapName) && StringUtils.isNotBlank(chapSecret)) {
4812+
HostInternetScsiHbaAuthenticationProperties auth = new HostInternetScsiHbaAuthenticationProperties();
48124813

4813-
String strAuthType = "chapRequired";
4814+
String strAuthType = "chapRequired";
48144815

4815-
auth.setChapAuthEnabled(true);
4816-
auth.setChapInherited(false);
4817-
auth.setChapAuthenticationType(strAuthType);
4818-
auth.setChapName(chapName);
4819-
auth.setChapSecret(chapSecret);
4816+
auth.setChapAuthEnabled(true);
4817+
auth.setChapInherited(false);
4818+
auth.setChapAuthenticationType(strAuthType);
4819+
auth.setChapName(chapName);
4820+
auth.setChapSecret(chapSecret);
48204821

4821-
auth.setMutualChapInherited(false);
4822-
auth.setMutualChapAuthenticationType(strAuthType);
4823-
auth.setMutualChapName(mutualChapName);
4824-
auth.setMutualChapSecret(mutualChapSecret);
4822+
if (StringUtils.isNotBlank(mutualChapName) && StringUtils.isNotBlank(mutualChapSecret)) {
4823+
auth.setMutualChapInherited(false);
4824+
auth.setMutualChapAuthenticationType(strAuthType);
4825+
auth.setMutualChapName(mutualChapName);
4826+
auth.setMutualChapSecret(mutualChapSecret);
4827+
}
48254828

4826-
target.setAuthenticationProperties(auth);
4829+
target.setAuthenticationProperties(auth);
4830+
}
48274831

48284832
final List<HostInternetScsiHbaStaticTarget> lstTargets = new ArrayList<HostInternetScsiHbaStaticTarget>();
48294833

@@ -6062,11 +6066,34 @@ protected void fillHostInfo(StartupRoutingCommand cmd) {
60626066
cmd.setName(_url);
60636067
cmd.setGuid(_guid);
60646068
cmd.setDataCenter(_dcId);
6069+
cmd.setIqn(getIqn());
60656070
cmd.setPod(_pod);
60666071
cmd.setCluster(_cluster);
60676072
cmd.setVersion(VmwareResource.class.getPackage().getImplementationVersion());
60686073
}
60696074

6075+
private String getIqn() {
6076+
try {
6077+
VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
6078+
6079+
if (hyperHost instanceof HostMO) {
6080+
HostMO host = (HostMO)hyperHost;
6081+
HostStorageSystemMO hostStorageSystem = host.getHostStorageSystemMO();
6082+
6083+
for (HostHostBusAdapter hba : hostStorageSystem.getStorageDeviceInfo().getHostBusAdapter()) {
6084+
if (hba instanceof HostInternetScsiHba) {
6085+
return ((HostInternetScsiHba)hba).getIScsiName();
6086+
}
6087+
}
6088+
}
6089+
}
6090+
catch (Exception ex) {
6091+
s_logger.info("Could not locate an IQN for this host.");
6092+
}
6093+
6094+
return null;
6095+
}
6096+
60706097
private void fillHostHardwareInfo(VmwareContext serviceContext, StartupRoutingCommand cmd) throws RuntimeFaultFaultMsg, RemoteException, Exception {
60716098

60726099
VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());

plugins/storage/volume/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackPrimaryDataStoreDriverImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.apache.cloudstack.storage.datastore.driver;
2020

2121
import java.util.HashMap;
22+
import java.util.List;
2223
import java.util.Map;
2324
import java.util.UUID;
2425

@@ -52,6 +53,7 @@
5253
import com.cloud.agent.api.to.StorageFilerTO;
5354
import com.cloud.configuration.Config;
5455
import com.cloud.exception.StorageUnavailableException;
56+
import com.cloud.host.Host;
5557
import com.cloud.host.dao.HostDao;
5658
import com.cloud.storage.dao.DiskOfferingDao;
5759
import com.cloud.storage.dao.SnapshotDao;
@@ -130,6 +132,12 @@ public ChapInfo getChapInfo(VolumeInfo volumeInfo) {
130132
return null;
131133
}
132134

135+
@Override
136+
public boolean connectVolumeToHost(VolumeInfo volumeInfo, Host host, DataStore dataStore) { return false; }
137+
138+
@Override
139+
public void disconnectVolumeFromHost(VolumeInfo volumeInfo, Host host, DataStore dataStore) {}
140+
133141
@Override
134142
public long getVolumeSizeIncludingHypervisorSnapshotReserve(Volume volume, StoragePool pool) {
135143
return volume.getSize();

plugins/storage/volume/sample/src/org/apache/cloudstack/storage/datastore/driver/SamplePrimaryDataStoreDriverImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@
4040
import com.cloud.agent.api.Answer;
4141
import com.cloud.agent.api.to.DataStoreTO;
4242
import com.cloud.agent.api.to.DataTO;
43+
import com.cloud.host.Host;
4344
import com.cloud.storage.StoragePool;
4445
import com.cloud.storage.Volume;
4546
import com.cloud.storage.dao.StoragePoolHostDao;
4647
import com.cloud.utils.exception.CloudRuntimeException;
4748

4849
import java.util.HashMap;
50+
import java.util.List;
4951
import java.util.Map;
5052

5153
public class SamplePrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver {
@@ -81,6 +83,12 @@ public ChapInfo getChapInfo(VolumeInfo volumeInfo) {
8183
return null;
8284
}
8385

86+
@Override
87+
public boolean connectVolumeToHost(VolumeInfo volumeInfo, Host host, DataStore dataStore) { return false; }
88+
89+
@Override
90+
public void disconnectVolumeFromHost(VolumeInfo volumeInfo, Host host, DataStore dataStore) {}
91+
8492
@Override
8593
public long getVolumeSizeIncludingHypervisorSnapshotReserve(Volume volume, StoragePool pool) {
8694
return volume.getSize();

0 commit comments

Comments
 (0)