mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
linstor: Only set allow-two-primaries if resource is already in use (#8802)
For live migrate we need the allow-two-primaries option, but we don't know exactly if we are called for a migration operation. Now also check if at least any of the resources is in use somewhere and only then set the option.
This commit is contained in:
parent
5a52ca78ae
commit
405aac38bc
@ -260,6 +260,28 @@ public class LinstorStorageAdaptor implements StorageAdaptor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 {
|
||||||
|
if (LinstorUtil.isResourceInUse(api, rscName)) {
|
||||||
|
// allow 2 primaries for live migration, should be removed by disconnect on the other end
|
||||||
|
ResourceDefinitionModify rdm = new ResourceDefinitionModify();
|
||||||
|
Properties props = new Properties();
|
||||||
|
props.put("DrbdOptions/Net/allow-two-primaries", "yes");
|
||||||
|
rdm.setOverrideProps(props);
|
||||||
|
ApiCallRcList answers = api.resourceDefinitionModify(rscName, rdm);
|
||||||
|
if (answers.hasError()) {
|
||||||
|
s_logger.error("Unable to set 'allow-two-primaries' on " + rscName);
|
||||||
|
// do not fail here as adding allow-two-primaries property is only a problem while live migrating
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean connectPhysicalDisk(String volumePath, KVMStoragePool pool, Map<String, String> details)
|
public boolean connectPhysicalDisk(String volumePath, KVMStoragePool pool, Map<String, String> details)
|
||||||
{
|
{
|
||||||
@ -286,16 +308,7 @@ public class LinstorStorageAdaptor implements StorageAdaptor {
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// allow 2 primaries for live migration, should be removed by disconnect on the other end
|
allow2PrimariesIfInUse(api, rscName);
|
||||||
ResourceDefinitionModify rdm = new ResourceDefinitionModify();
|
|
||||||
Properties props = new Properties();
|
|
||||||
props.put("DrbdOptions/Net/allow-two-primaries", "yes");
|
|
||||||
rdm.setOverrideProps(props);
|
|
||||||
ApiCallRcList answers = api.resourceDefinitionModify(rscName, rdm);
|
|
||||||
if (answers.hasError()) {
|
|
||||||
s_logger.error("Unable to set 'allow-two-primaries' on " + rscName);
|
|
||||||
// do not fail here as adding allow-two-primaries property is only a problem while live migrating
|
|
||||||
}
|
|
||||||
} catch (ApiException apiEx) {
|
} catch (ApiException apiEx) {
|
||||||
s_logger.error(apiEx);
|
s_logger.error(apiEx);
|
||||||
// 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
|
||||||
|
|||||||
@ -23,6 +23,7 @@ import com.linbit.linstor.api.DevelopersApi;
|
|||||||
import com.linbit.linstor.api.model.ApiCallRc;
|
import com.linbit.linstor.api.model.ApiCallRc;
|
||||||
import com.linbit.linstor.api.model.ApiCallRcList;
|
import com.linbit.linstor.api.model.ApiCallRcList;
|
||||||
import com.linbit.linstor.api.model.ProviderKind;
|
import com.linbit.linstor.api.model.ProviderKind;
|
||||||
|
import com.linbit.linstor.api.model.Resource;
|
||||||
import com.linbit.linstor.api.model.ResourceGroup;
|
import com.linbit.linstor.api.model.ResourceGroup;
|
||||||
import com.linbit.linstor.api.model.StoragePool;
|
import com.linbit.linstor.api.model.StoragePool;
|
||||||
|
|
||||||
@ -90,4 +91,22 @@ public class LinstorUtil {
|
|||||||
throw new CloudRuntimeException(apiEx);
|
throw new CloudRuntimeException(apiEx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if any resource of the given name is InUse on any host.
|
||||||
|
*
|
||||||
|
* @param api developer api object to use
|
||||||
|
* @param rscName resource name to check in use state.
|
||||||
|
* @return True if a resource found that is in use(primary) state, else false.
|
||||||
|
* @throws ApiException forwards api errors
|
||||||
|
*/
|
||||||
|
public static boolean isResourceInUse(DevelopersApi api, String rscName) throws ApiException {
|
||||||
|
List<Resource> rscs = api.resourceList(rscName, null, null);
|
||||||
|
if (rscs != null) {
|
||||||
|
return rscs.stream()
|
||||||
|
.anyMatch(rsc -> rsc.getState() != null && Boolean.TRUE.equals(rsc.getState().isInUse()));
|
||||||
|
}
|
||||||
|
s_logger.error("isResourceInUse: null returned from resourceList");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user