Merge remote-tracking branch 'origin/4.18' into 4.19

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
Rohit Yadav 2024-11-07 14:51:43 +05:30
commit 5b7c86aa45
3 changed files with 87 additions and 17 deletions

View File

@ -17,6 +17,7 @@
package com.cloud.hypervisor.kvm.storage; package com.cloud.hypervisor.kvm.storage;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -47,6 +48,7 @@ import com.linbit.linstor.api.model.ProviderKind;
import com.linbit.linstor.api.model.Resource; import com.linbit.linstor.api.model.Resource;
import com.linbit.linstor.api.model.ResourceConnectionModify; import com.linbit.linstor.api.model.ResourceConnectionModify;
import com.linbit.linstor.api.model.ResourceDefinition; import com.linbit.linstor.api.model.ResourceDefinition;
import com.linbit.linstor.api.model.ResourceDefinitionModify;
import com.linbit.linstor.api.model.ResourceGroupSpawn; import com.linbit.linstor.api.model.ResourceGroupSpawn;
import com.linbit.linstor.api.model.ResourceMakeAvailable; import com.linbit.linstor.api.model.ResourceMakeAvailable;
import com.linbit.linstor.api.model.ResourceWithVolumes; import com.linbit.linstor.api.model.ResourceWithVolumes;
@ -231,17 +233,20 @@ public class LinstorStorageAdaptor implements StorageAdaptor {
} }
} }
/** private void setAllowTwoPrimariesOnRD(DevelopersApi api, String rscName) throws ApiException {
* Checks if the given resource is in use by drbd on any host and ResourceDefinitionModify rdm = new ResourceDefinitionModify();
* if so set the drbd option allow-two-primaries Properties props = new Properties();
* @param api linstor api object props.put("DrbdOptions/Net/allow-two-primaries", "yes");
* @param rscName resource name to set allow-two-primaries if in use props.put("DrbdOptions/Net/protocol", "C");
* @throws ApiException if any problem connecting to the Linstor controller rdm.setOverrideProps(props);
*/ ApiCallRcList answers = api.resourceDefinitionModify(rscName, rdm);
private void allow2PrimariesIfInUse(DevelopersApi api, String rscName) throws ApiException { if (answers.hasError()) {
String inUseNode = LinstorUtil.isResourceInUse(api, rscName); s_logger.error(String.format("Unable to set protocol C and 'allow-two-primaries' on %s", rscName));
if (inUseNode != null && !inUseNode.equalsIgnoreCase(localNodeName)) { // do not fail here as adding allow-two-primaries property is only a problem while live migrating
// allow 2 primaries for live migration, should be removed by disconnect on the other end }
}
private void setAllowTwoPrimariesOnRc(DevelopersApi api, String rscName, String inUseNode) throws ApiException {
ResourceConnectionModify rcm = new ResourceConnectionModify(); ResourceConnectionModify rcm = new ResourceConnectionModify();
Properties props = new Properties(); Properties props = new Properties();
props.put("DrbdOptions/Net/allow-two-primaries", "yes"); props.put("DrbdOptions/Net/allow-two-primaries", "yes");
@ -255,6 +260,27 @@ public class LinstorStorageAdaptor implements StorageAdaptor {
// do not fail here as adding allow-two-primaries property is only a problem while live migrating // do not fail here as adding allow-two-primaries property is only a problem while live migrating
} }
} }
/**
* Checks if the given resource is in use by drbd on any host and
* if so set the drbd option allow-two-primaries
* @param api linstor api object
* @param rscName resource name to set allow-two-primaries if in use
* @throws ApiException if any problem connecting to the Linstor controller
*/
private void allow2PrimariesIfInUse(DevelopersApi api, String rscName) throws ApiException {
String inUseNode = LinstorUtil.isResourceInUse(api, rscName);
if (inUseNode != null && !inUseNode.equalsIgnoreCase(localNodeName)) {
// allow 2 primaries for live migration, should be removed by disconnect on the other end
// if non hyperconverged setup, we have to set allow-two-primaries on the resource-definition
// as there is no resource connection between diskless nodes.
if (LinstorUtil.areResourcesDiskless(api, rscName, Arrays.asList(inUseNode, localNodeName))) {
setAllowTwoPrimariesOnRD(api, rscName);
} else {
setAllowTwoPrimariesOnRc(api, rscName, inUseNode);
}
}
} }
@Override @Override
@ -291,11 +317,22 @@ public class LinstorStorageAdaptor implements StorageAdaptor {
return true; return true;
} }
private void removeTwoPrimariesRcProps(DevelopersApi api, String inUseNode, String rscName) throws ApiException { private void removeTwoPrimariesRDProps(DevelopersApi api, String rscName, List<String> deleteProps)
throws ApiException {
ResourceDefinitionModify rdm = new ResourceDefinitionModify();
rdm.deleteProps(deleteProps);
ApiCallRcList answers = api.resourceDefinitionModify(rscName, rdm);
if (answers.hasError()) {
s_logger.error(
String.format("Failed to remove 'protocol' and 'allow-two-primaries' on %s: %s",
rscName, LinstorUtil.getBestErrorMessage(answers)));
// do not fail here as removing allow-two-primaries property isn't fatal
}
}
private void removeTwoPrimariesRcProps(DevelopersApi api, String rscName, String inUseNode, List<String> deleteProps)
throws ApiException {
ResourceConnectionModify rcm = new ResourceConnectionModify(); ResourceConnectionModify rcm = new ResourceConnectionModify();
List<String> deleteProps = new ArrayList<>();
deleteProps.add("DrbdOptions/Net/allow-two-primaries");
deleteProps.add("DrbdOptions/Net/protocol");
rcm.deleteProps(deleteProps); rcm.deleteProps(deleteProps);
ApiCallRcList answers = api.resourceConnectionModify(rscName, localNodeName, inUseNode, rcm); ApiCallRcList answers = api.resourceConnectionModify(rscName, localNodeName, inUseNode, rcm);
if (answers.hasError()) { if (answers.hasError()) {
@ -308,6 +345,15 @@ public class LinstorStorageAdaptor implements StorageAdaptor {
} }
} }
private void removeTwoPrimariesProps(DevelopersApi api, String inUseNode, String rscName) throws ApiException {
List<String> deleteProps = new ArrayList<>();
deleteProps.add("DrbdOptions/Net/allow-two-primaries");
deleteProps.add("DrbdOptions/Net/protocol");
removeTwoPrimariesRDProps(api, rscName, deleteProps);
removeTwoPrimariesRcProps(api, rscName, inUseNode, deleteProps);
}
private boolean tryDisconnectLinstor(String volumePath, KVMStoragePool pool) private boolean tryDisconnectLinstor(String volumePath, KVMStoragePool pool)
{ {
if (volumePath == null) { if (volumePath == null) {
@ -341,7 +387,7 @@ public class LinstorStorageAdaptor implements StorageAdaptor {
try { try {
String inUseNode = LinstorUtil.isResourceInUse(api, rsc.getName()); String inUseNode = LinstorUtil.isResourceInUse(api, rsc.getName());
if (inUseNode != null && !inUseNode.equalsIgnoreCase(localNodeName)) { if (inUseNode != null && !inUseNode.equalsIgnoreCase(localNodeName)) {
removeTwoPrimariesRcProps(api, inUseNode, rsc.getName()); removeTwoPrimariesProps(api, inUseNode, rsc.getName());
} }
} catch (ApiException apiEx) { } catch (ApiException apiEx) {
s_logger.error(apiEx.getBestMessage()); s_logger.error(apiEx.getBestMessage());

View File

@ -17,6 +17,7 @@
package org.apache.cloudstack.storage.datastore.util; package org.apache.cloudstack.storage.datastore.util;
import com.linbit.linstor.api.ApiClient; import com.linbit.linstor.api.ApiClient;
import com.linbit.linstor.api.ApiConsts;
import com.linbit.linstor.api.ApiException; import com.linbit.linstor.api.ApiException;
import com.linbit.linstor.api.DevelopersApi; import com.linbit.linstor.api.DevelopersApi;
import com.linbit.linstor.api.model.ApiCallRc; import com.linbit.linstor.api.model.ApiCallRc;
@ -33,6 +34,7 @@ import com.linbit.linstor.api.model.Volume;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -209,6 +211,28 @@ public class LinstorUtil {
return null; return null;
} }
/**
* Check if the given resources are diskless.
*
* @param api developer api object to use
* @param rscName resource name to check in use state.
* @return NodeName where the resource is inUse, if not in use `null`
* @throws ApiException forwards api errors
*/
public static boolean areResourcesDiskless(DevelopersApi api, String rscName, Collection<String> nodeNames)
throws ApiException {
List<Resource> rscs = api.resourceList(rscName, null, null);
if (rscs != null) {
Collection<String> disklessNodes = rscs.stream()
.filter(rsc -> rsc.getFlags() != null && (rsc.getFlags().contains(ApiConsts.FLAG_DISKLESS) ||
rsc.getFlags().contains(ApiConsts.FLAG_DRBD_DISKLESS)))
.map(rsc -> rsc.getNodeName().toLowerCase())
.collect(Collectors.toList());
return disklessNodes.containsAll(nodeNames.stream().map(String::toLowerCase).collect(Collectors.toList()));
}
return false;
}
/** /**
* Try to get the device path for the given resource name. * Try to get the device path for the given resource name.
* This could be made a bit more direct after java-linstor api is fixed for layer data subtypes. * This could be made a bit more direct after java-linstor api is fixed for layer data subtypes.

View File

@ -174,6 +174,6 @@ class CsFile:
self.new_config = list(temp_config) self.new_config = list(temp_config)
def compare(self, o): def compare(self, o):
result = (isinstance(o, self.__class__) and set(self.config) == set(o.config)) result = (isinstance(o, self.__class__) and self.config == o.config)
logging.debug("Comparison of CsFiles content is ==> %s" % result) logging.debug("Comparison of CsFiles content is ==> %s" % result)
return result return result