Skip to content

Commit

Permalink
linstor: Only set allow-two-primaries if resource is already in use
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rp- committed Mar 19, 2024
1 parent 024f8d3 commit 51d050d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,15 +285,17 @@ public boolean connectPhysicalDisk(String volumePath, KVMStoragePool pool, Map<S

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
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
}
}
} catch (ApiException apiEx) {
s_logger.error(apiEx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
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;

Expand Down Expand Up @@ -90,4 +91,17 @@ public static long getCapacityBytes(String linstorUrl, String rscGroupName) {
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);
return rscs.stream().anyMatch(rsc -> rsc.getState() != null ? rsc.getState().isInUse() : false);
}
}

0 comments on commit 51d050d

Please sign in to comment.