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:
Rene Peinthor 2024-04-22 10:04:05 +02:00 committed by GitHub
parent 5a52ca78ae
commit 405aac38bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 42 additions and 10 deletions

View File

@ -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
public boolean connectPhysicalDisk(String volumePath, KVMStoragePool pool, Map<String, String> details)
{
@ -286,16 +308,7 @@ public class LinstorStorageAdaptor implements StorageAdaptor {
try
{
// 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
}
allow2PrimariesIfInUse(api, rscName);
} catch (ApiException apiEx) {
s_logger.error(apiEx);
// do not fail here as adding allow-two-primaries property is only a problem while live migrating

View File

@ -23,6 +23,7 @@ import com.linbit.linstor.api.DevelopersApi;
import com.linbit.linstor.api.model.ApiCallRc;
import com.linbit.linstor.api.model.ApiCallRcList;
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.StoragePool;
@ -90,4 +91,22 @@ public class LinstorUtil {
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;
}
}