Skip to content

Commit 001c769

Browse files
authored
Linstor 4.19 fix selecting non enabled hosts (#8653)
* linstor: cleanup resource if copy from template failed * linstor: do not use non enabled hosts for copy operations
1 parent d99b1b9 commit 001c769

File tree

2 files changed

+37
-28
lines changed

2 files changed

+37
-28
lines changed

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import com.cloud.configuration.Config;
6060
import com.cloud.host.Host;
6161
import com.cloud.host.dao.HostDao;
62+
import com.cloud.resource.ResourceState;
6263
import com.cloud.storage.DataStoreRole;
6364
import com.cloud.storage.ResizeVolumePayload;
6465
import com.cloud.storage.SnapshotVO;
@@ -214,6 +215,7 @@ private void deleteResourceDefinition(StoragePoolVO storagePoolVO, String rscDef
214215
}
215216
throw new CloudRuntimeException("Linstor: Unable to delete resource definition: " + rscDefName);
216217
}
218+
s_logger.info(String.format("Linstor: Deleted resource %s", rscDefName));
217219
} catch (ApiException apiEx)
218220
{
219221
s_logger.error("Linstor: ApiEx - " + apiEx.getMessage());
@@ -865,7 +867,7 @@ private Optional<RemoteHostEndPoint> getLinstorEP(DevelopersApi api, String rscN
865867
Host host = null;
866868
for (String nodeName : linstorNodeNames) {
867869
host = _hostDao.findByName(nodeName);
868-
if (host != null) {
870+
if (host != null && host.getResourceState() == ResourceState.Enabled) {
869871
s_logger.info(String.format("Linstor: Make resource %s available on node %s ...", rscName, nodeName));
870872
ApiCallRcList answers = api.resourceMakeAvailableOnNode(rscName, nodeName, new ResourceMakeAvailable());
871873
if (!answers.hasError()) {
@@ -892,21 +894,16 @@ private Optional<RemoteHostEndPoint> getLinstorEP(DevelopersApi api, String rscN
892894
}
893895

894896
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));
897+
List<com.linbit.linstor.api.model.StoragePool> linSPs = LinstorUtil.getDiskfulStoragePools(api, rscName);
898+
if (linSPs != null) {
899+
for (com.linbit.linstor.api.model.StoragePool sp : linSPs) {
900+
Host host = _hostDao.findByName(sp.getNodeName());
901+
if (host != null && host.getResourceState() == ResourceState.Enabled) {
902+
return Optional.of(RemoteHostEndPoint.getHypervisorHostEndPoint(host));
903+
}
908904
}
909905
}
906+
s_logger.error("Linstor: No diskfull host found.");
910907
return Optional.empty();
911908
}
912909

@@ -958,9 +955,11 @@ private Answer copyTemplate(DataObject srcData, DataObject dstData) {
958955
}
959956
else {
960957
answer = new Answer(cmd, false, "Unable to get matching Linstor endpoint.");
958+
deleteResourceDefinition(pool, rscName);
961959
}
962960
} catch (ApiException exc) {
963961
s_logger.error("copy template failed: ", exc);
962+
deleteResourceDefinition(pool, rscName);
964963
throw new CloudRuntimeException(exc.getBestMessage());
965964
}
966965
return answer;

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)