Skip to content

Commit d1cb48b

Browse files
committed
linstor: do not use non enabled hosts for copy operations
1 parent 83a00ff commit d1cb48b

2 files changed

Lines changed: 33 additions & 28 deletions

File tree

plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/driver/LinstorPrimaryDataStoreDriverImpl.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ private Optional<RemoteHostEndPoint> getLinstorEP(DevelopersApi api, String rscN
865865
Host host = null;
866866
for (String nodeName : linstorNodeNames) {
867867
host = _hostDao.findByName(nodeName);
868-
if (host != null) {
868+
if (host != null && !host.isInMaintenanceStates()) {
869869
s_logger.info(String.format("Linstor: Make resource %s available on node %s ...", rscName, nodeName));
870870
ApiCallRcList answers = api.resourceMakeAvailableOnNode(rscName, nodeName, new ResourceMakeAvailable());
871871
if (!answers.hasError()) {
@@ -892,21 +892,16 @@ private Optional<RemoteHostEndPoint> getLinstorEP(DevelopersApi api, String rscN
892892
}
893893

894894
private Optional<RemoteHostEndPoint> getDiskfullEP(DevelopersApi api, String rscName) throws ApiException {
895-
com.linbit.linstor.api.model.StoragePool linSP =
896-
LinstorUtil.getDiskfulStoragePool(api, rscName);
897-
if (linSP != null)
898-
{
899-
Host host = _hostDao.findByName(linSP.getNodeName());
900-
if (host == null)
901-
{
902-
s_logger.error("Linstor: Host '" + linSP.getNodeName() + "' not found.");
903-
return Optional.empty();
904-
}
905-
else
906-
{
907-
return Optional.of(RemoteHostEndPoint.getHypervisorHostEndPoint(host));
895+
List<com.linbit.linstor.api.model.StoragePool> linSPs = LinstorUtil.getDiskfulStoragePools(api, rscName);
896+
if (linSPs != null) {
897+
for (com.linbit.linstor.api.model.StoragePool sp : linSPs) {
898+
Host host = _hostDao.findByName(sp.getNodeName());
899+
if (host != null && !host.isInMaintenanceStates()) {
900+
return Optional.of(RemoteHostEndPoint.getHypervisorHostEndPoint(host));
901+
}
908902
}
909903
}
904+
s_logger.error("Linstor: No diskfull host found.");
910905
return Optional.empty();
911906
}
912907

plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/util/LinstorUtil.java

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,16 @@ public static List<String> getLinstorNodeNames(@Nonnull DevelopersApi api) throw
7777
return nodes.stream().map(Node::getName).collect(Collectors.toList());
7878
}
7979

80-
public static com.linbit.linstor.api.model.StoragePool
81-
getDiskfulStoragePool(@Nonnull DevelopersApi api, @Nonnull String rscName) throws ApiException
80+
public static List<com.linbit.linstor.api.model.StoragePool>
81+
getDiskfulStoragePools(@Nonnull DevelopersApi api, @Nonnull String rscName) throws ApiException
8282
{
8383
List<ResourceWithVolumes> resources = api.viewResources(
84-
Collections.emptyList(),
85-
Collections.singletonList(rscName),
86-
Collections.emptyList(),
87-
Collections.emptyList(),
88-
null,
89-
null);
84+
Collections.emptyList(),
85+
Collections.singletonList(rscName),
86+
Collections.emptyList(),
87+
Collections.emptyList(),
88+
null,
89+
null);
9090

9191
String nodeName = null;
9292
String storagePoolName = null;
@@ -107,13 +107,23 @@ public static List<String> getLinstorNodeNames(@Nonnull DevelopersApi api) throw
107107
}
108108

109109
List<com.linbit.linstor.api.model.StoragePool> sps = api.viewStoragePools(
110-
Collections.singletonList(nodeName),
111-
Collections.singletonList(storagePoolName),
112-
Collections.emptyList(),
113-
null,
114-
null
110+
Collections.singletonList(nodeName),
111+
Collections.singletonList(storagePoolName),
112+
Collections.emptyList(),
113+
null,
114+
null
115115
);
116-
return !sps.isEmpty() ? sps.get(0) : null;
116+
return sps != null ? sps : Collections.emptyList();
117+
}
118+
119+
public static com.linbit.linstor.api.model.StoragePool
120+
getDiskfulStoragePool(@Nonnull DevelopersApi api, @Nonnull String rscName) throws ApiException
121+
{
122+
List<com.linbit.linstor.api.model.StoragePool> sps = getDiskfulStoragePools(api, rscName);
123+
if (sps != null) {
124+
return !sps.isEmpty() ? sps.get(0) : null;
125+
}
126+
return null;
117127
}
118128

119129
public static String getSnapshotPath(com.linbit.linstor.api.model.StoragePool sp, String rscName, String snapshotName) {

0 commit comments

Comments
 (0)