From 1c04d4630d7bc29f2e40de1a04def1899316dec9 Mon Sep 17 00:00:00 2001 From: Rene Peinthor Date: Wed, 14 Feb 2024 15:26:05 +0100 Subject: [PATCH] linstor: do not use hosts in maintenance for copy operations --- .../LinstorPrimaryDataStoreDriverImpl.java | 23 +++++------ .../storage/datastore/util/LinstorUtil.java | 38 ++++++++++++------- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/driver/LinstorPrimaryDataStoreDriverImpl.java b/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/driver/LinstorPrimaryDataStoreDriverImpl.java index 6f8246728b11..d375ead6bd52 100644 --- a/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/driver/LinstorPrimaryDataStoreDriverImpl.java +++ b/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/driver/LinstorPrimaryDataStoreDriverImpl.java @@ -865,7 +865,7 @@ private Optional getLinstorEP(DevelopersApi api, String rscN Host host = null; for (String nodeName : linstorNodeNames) { host = _hostDao.findByName(nodeName); - if (host != null) { + if (host != null && !host.isInMaintenanceStates()) { s_logger.info(String.format("Linstor: Make resource %s available on node %s ...", rscName, nodeName)); ApiCallRcList answers = api.resourceMakeAvailableOnNode(rscName, nodeName, new ResourceMakeAvailable()); if (!answers.hasError()) { @@ -892,21 +892,16 @@ private Optional getLinstorEP(DevelopersApi api, String rscN } private Optional getDiskfullEP(DevelopersApi api, String rscName) throws ApiException { - com.linbit.linstor.api.model.StoragePool linSP = - LinstorUtil.getDiskfulStoragePool(api, rscName); - if (linSP != null) - { - Host host = _hostDao.findByName(linSP.getNodeName()); - if (host == null) - { - s_logger.error("Linstor: Host '" + linSP.getNodeName() + "' not found."); - return Optional.empty(); - } - else - { - return Optional.of(RemoteHostEndPoint.getHypervisorHostEndPoint(host)); + List linSPs = LinstorUtil.getDiskfulStoragePools(api, rscName); + if (linSPs != null) { + for (com.linbit.linstor.api.model.StoragePool sp : linSPs) { + Host host = _hostDao.findByName(sp.getNodeName()); + if (host != null && !host.isInMaintenanceStates()) { + return Optional.of(RemoteHostEndPoint.getHypervisorHostEndPoint(host)); + } } } + s_logger.error("Linstor: No diskfull host found."); return Optional.empty(); } diff --git a/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/util/LinstorUtil.java b/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/util/LinstorUtil.java index e953c94db220..33cbea0996d5 100644 --- a/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/util/LinstorUtil.java +++ b/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/util/LinstorUtil.java @@ -77,16 +77,16 @@ public static List getLinstorNodeNames(@Nonnull DevelopersApi api) throw return nodes.stream().map(Node::getName).collect(Collectors.toList()); } - public static com.linbit.linstor.api.model.StoragePool - getDiskfulStoragePool(@Nonnull DevelopersApi api, @Nonnull String rscName) throws ApiException + public static List + getDiskfulStoragePools(@Nonnull DevelopersApi api, @Nonnull String rscName) throws ApiException { List resources = api.viewResources( - Collections.emptyList(), - Collections.singletonList(rscName), - Collections.emptyList(), - Collections.emptyList(), - null, - null); + Collections.emptyList(), + Collections.singletonList(rscName), + Collections.emptyList(), + Collections.emptyList(), + null, + null); String nodeName = null; String storagePoolName = null; @@ -107,13 +107,23 @@ public static List getLinstorNodeNames(@Nonnull DevelopersApi api) throw } List sps = api.viewStoragePools( - Collections.singletonList(nodeName), - Collections.singletonList(storagePoolName), - Collections.emptyList(), - null, - null + Collections.singletonList(nodeName), + Collections.singletonList(storagePoolName), + Collections.emptyList(), + null, + null ); - return !sps.isEmpty() ? sps.get(0) : null; + return sps != null ? sps : Collections.emptyList(); + } + + public static com.linbit.linstor.api.model.StoragePool + getDiskfulStoragePool(@Nonnull DevelopersApi api, @Nonnull String rscName) throws ApiException + { + List sps = getDiskfulStoragePools(api, rscName); + if (sps != null) { + return !sps.isEmpty() ? sps.get(0) : null; + } + return null; } public static String getSnapshotPath(com.linbit.linstor.api.model.StoragePool sp, String rscName, String snapshotName) {