Skip to content

Commit 405aac3

Browse files
authored
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.
1 parent 5a52ca7 commit 405aac3

File tree

2 files changed

+42
-10
lines changed

2 files changed

+42
-10
lines changed

plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStorageAdaptor.java

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,28 @@ public KVMPhysicalDisk createPhysicalDisk(String name, KVMStoragePool pool, Qemu
260260
}
261261
}
262262

263+
/**
264+
* Checks if the given resource is in use by drbd on any host and
265+
* if so set the drbd option allow-two-primaries
266+
* @param api linstor api object
267+
* @param rscName resource name to set allow-two-primaries if in use
268+
* @throws ApiException if any problem connecting to the Linstor controller
269+
*/
270+
private void allow2PrimariesIfInUse(DevelopersApi api, String rscName) throws ApiException {
271+
if (LinstorUtil.isResourceInUse(api, rscName)) {
272+
// allow 2 primaries for live migration, should be removed by disconnect on the other end
273+
ResourceDefinitionModify rdm = new ResourceDefinitionModify();
274+
Properties props = new Properties();
275+
props.put("DrbdOptions/Net/allow-two-primaries", "yes");
276+
rdm.setOverrideProps(props);
277+
ApiCallRcList answers = api.resourceDefinitionModify(rscName, rdm);
278+
if (answers.hasError()) {
279+
s_logger.error("Unable to set 'allow-two-primaries' on " + rscName);
280+
// do not fail here as adding allow-two-primaries property is only a problem while live migrating
281+
}
282+
}
283+
}
284+
263285
@Override
264286
public boolean connectPhysicalDisk(String volumePath, KVMStoragePool pool, Map<String, String> details)
265287
{
@@ -286,16 +308,7 @@ public boolean connectPhysicalDisk(String volumePath, KVMStoragePool pool, Map<S
286308

287309
try
288310
{
289-
// allow 2 primaries for live migration, should be removed by disconnect on the other end
290-
ResourceDefinitionModify rdm = new ResourceDefinitionModify();
291-
Properties props = new Properties();
292-
props.put("DrbdOptions/Net/allow-two-primaries", "yes");
293-
rdm.setOverrideProps(props);
294-
ApiCallRcList answers = api.resourceDefinitionModify(rscName, rdm);
295-
if (answers.hasError()) {
296-
s_logger.error("Unable to set 'allow-two-primaries' on " + rscName);
297-
// do not fail here as adding allow-two-primaries property is only a problem while live migrating
298-
}
311+
allow2PrimariesIfInUse(api, rscName);
299312
} catch (ApiException apiEx) {
300313
s_logger.error(apiEx);
301314
// do not fail here as adding allow-two-primaries property is only a problem while live migrating

plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/util/LinstorUtil.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.linbit.linstor.api.model.ApiCallRc;
2424
import com.linbit.linstor.api.model.ApiCallRcList;
2525
import com.linbit.linstor.api.model.ProviderKind;
26+
import com.linbit.linstor.api.model.Resource;
2627
import com.linbit.linstor.api.model.ResourceGroup;
2728
import com.linbit.linstor.api.model.StoragePool;
2829

@@ -90,4 +91,22 @@ public static long getCapacityBytes(String linstorUrl, String rscGroupName) {
9091
throw new CloudRuntimeException(apiEx);
9192
}
9293
}
94+
95+
/**
96+
* Check if any resource of the given name is InUse on any host.
97+
*
98+
* @param api developer api object to use
99+
* @param rscName resource name to check in use state.
100+
* @return True if a resource found that is in use(primary) state, else false.
101+
* @throws ApiException forwards api errors
102+
*/
103+
public static boolean isResourceInUse(DevelopersApi api, String rscName) throws ApiException {
104+
List<Resource> rscs = api.resourceList(rscName, null, null);
105+
if (rscs != null) {
106+
return rscs.stream()
107+
.anyMatch(rsc -> rsc.getState() != null && Boolean.TRUE.equals(rsc.getState().isInUse()));
108+
}
109+
s_logger.error("isResourceInUse: null returned from resourceList");
110+
return false;
111+
}
93112
}

0 commit comments

Comments
 (0)