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 27, 2024
1 parent 8c62365 commit 30d8328
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> details)
{
Expand All @@ -285,16 +307,7 @@ 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
}
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
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 30d8328

Please sign in to comment.