diff --git a/plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStorageAdaptor.java b/plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStorageAdaptor.java index 87746447188d..cdc61ec3e6fb 100644 --- a/plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStorageAdaptor.java +++ b/plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStorageAdaptor.java @@ -259,6 +259,28 @@ public KVMPhysicalDisk createPhysicalDisk(String name, KVMStoragePool pool, Qemu } } + /** + * 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 public boolean connectPhysicalDisk(String volumePath, KVMStoragePool pool, Map details) { @@ -285,16 +307,7 @@ public boolean connectPhysicalDisk(String volumePath, KVMStoragePool pool, Map rscs = api.resourceList(rscName, null, null); + return rscs.stream().anyMatch(rsc -> rsc.getState() != null ? rsc.getState().isInUse() : false); + } }