Skip to content

Commit 0ac967d

Browse files
rp-dhslove
authored andcommitted
linstor: fix live migrate on non-hyperconverged setups (apache#9832)
In non-hyperconverged setups, diskless nodes don't have a connection to each other, so setting properties there had no effect. Now it is checked if a connection exists, between the live migration nodes and if not, it will set the allow-two-primaries on resource-definition level.
1 parent 214fe2d commit 0ac967d

File tree

2 files changed

+87
-16
lines changed

2 files changed

+87
-16
lines changed

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

Lines changed: 63 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.cloud.hypervisor.kvm.storage;
1818

1919
import java.util.ArrayList;
20+
import java.util.Arrays;
2021
import java.util.Collections;
2122
import java.util.HashMap;
2223
import java.util.List;
@@ -48,6 +49,7 @@
4849
import com.linbit.linstor.api.model.Resource;
4950
import com.linbit.linstor.api.model.ResourceConnectionModify;
5051
import com.linbit.linstor.api.model.ResourceDefinition;
52+
import com.linbit.linstor.api.model.ResourceDefinitionModify;
5153
import com.linbit.linstor.api.model.ResourceGroupSpawn;
5254
import com.linbit.linstor.api.model.ResourceMakeAvailable;
5355
import com.linbit.linstor.api.model.ResourceWithVolumes;
@@ -152,7 +154,7 @@ public KVMPhysicalDisk getPhysicalDisk(String name, KVMStoragePool pool)
152154

153155
@Override
154156
public KVMStoragePool createStoragePool(String name, String host, int port, String path, String userInfo,
155-
Storage.StoragePoolType type, Map<String, String> details)
157+
Storage.StoragePoolType type, Map<String, String> details, boolean isPrimaryStorage)
156158
{
157159
logger.debug("Linstor createStoragePool: name: '{}', host: '{}', path: {}, userinfo: {}", name, host, path, userInfo);
158160
LinstorStoragePool storagePool = new LinstorStoragePool(name, host, port, userInfo, type, this);
@@ -235,6 +237,34 @@ public KVMPhysicalDisk createPhysicalDisk(String name, KVMStoragePool pool, Qemu
235237
}
236238
}
237239

240+
private void setAllowTwoPrimariesOnRD(DevelopersApi api, String rscName) throws ApiException {
241+
ResourceDefinitionModify rdm = new ResourceDefinitionModify();
242+
Properties props = new Properties();
243+
props.put("DrbdOptions/Net/allow-two-primaries", "yes");
244+
props.put("DrbdOptions/Net/protocol", "C");
245+
rdm.setOverrideProps(props);
246+
ApiCallRcList answers = api.resourceDefinitionModify(rscName, rdm);
247+
if (answers.hasError()) {
248+
logger.error(String.format("Unable to set protocol C and 'allow-two-primaries' on %s", rscName));
249+
// do not fail here as adding allow-two-primaries property is only a problem while live migrating
250+
}
251+
}
252+
253+
private void setAllowTwoPrimariesOnRc(DevelopersApi api, String rscName, String inUseNode) throws ApiException {
254+
ResourceConnectionModify rcm = new ResourceConnectionModify();
255+
Properties props = new Properties();
256+
props.put("DrbdOptions/Net/allow-two-primaries", "yes");
257+
props.put("DrbdOptions/Net/protocol", "C");
258+
rcm.setOverrideProps(props);
259+
ApiCallRcList answers = api.resourceConnectionModify(rscName, inUseNode, localNodeName, rcm);
260+
if (answers.hasError()) {
261+
logger.error(String.format(
262+
"Unable to set protocol C and 'allow-two-primaries' on %s/%s/%s",
263+
inUseNode, localNodeName, rscName));
264+
// do not fail here as adding allow-two-primaries property is only a problem while live migrating
265+
}
266+
}
267+
238268
/**
239269
* Checks if the given resource is in use by drbd on any host and
240270
* if so set the drbd option allow-two-primaries
@@ -246,16 +276,13 @@ private void allow2PrimariesIfInUse(DevelopersApi api, String rscName) throws Ap
246276
String inUseNode = LinstorUtil.isResourceInUse(api, rscName);
247277
if (inUseNode != null && !inUseNode.equalsIgnoreCase(localNodeName)) {
248278
// allow 2 primaries for live migration, should be removed by disconnect on the other end
249-
ResourceConnectionModify rcm = new ResourceConnectionModify();
250-
Properties props = new Properties();
251-
props.put("DrbdOptions/Net/allow-two-primaries", "yes");
252-
props.put("DrbdOptions/Net/protocol", "C");
253-
rcm.setOverrideProps(props);
254-
ApiCallRcList answers = api.resourceConnectionModify(rscName, inUseNode, localNodeName, rcm);
255-
if (answers.hasError()) {
256-
logger.error("Unable to set protocol C and 'allow-two-primaries' on {}/{}/{}",
257-
inUseNode, localNodeName, rscName);
258-
// do not fail here as adding allow-two-primaries property is only a problem while live migrating
279+
280+
// if non hyperconverged setup, we have to set allow-two-primaries on the resource-definition
281+
// as there is no resource connection between diskless nodes.
282+
if (LinstorUtil.areResourcesDiskless(api, rscName, Arrays.asList(inUseNode, localNodeName))) {
283+
setAllowTwoPrimariesOnRD(api, rscName);
284+
} else {
285+
setAllowTwoPrimariesOnRc(api, rscName, inUseNode);
259286
}
260287
}
261288
}
@@ -294,11 +321,22 @@ public boolean connectPhysicalDisk(String volumePath, KVMStoragePool pool, Map<S
294321
return true;
295322
}
296323

297-
private void removeTwoPrimariesRcProps(DevelopersApi api, String inUseNode, String rscName) throws ApiException {
324+
private void removeTwoPrimariesRDProps(DevelopersApi api, String rscName, List<String> deleteProps)
325+
throws ApiException {
326+
ResourceDefinitionModify rdm = new ResourceDefinitionModify();
327+
rdm.deleteProps(deleteProps);
328+
ApiCallRcList answers = api.resourceDefinitionModify(rscName, rdm);
329+
if (answers.hasError()) {
330+
logger.error(
331+
String.format("Failed to remove 'protocol' and 'allow-two-primaries' on %s: %s",
332+
rscName, LinstorUtil.getBestErrorMessage(answers)));
333+
// do not fail here as removing allow-two-primaries property isn't fatal
334+
}
335+
}
336+
337+
private void removeTwoPrimariesRcProps(DevelopersApi api, String rscName, String inUseNode, List<String> deleteProps)
338+
throws ApiException {
298339
ResourceConnectionModify rcm = new ResourceConnectionModify();
299-
List<String> deleteProps = new ArrayList<>();
300-
deleteProps.add("DrbdOptions/Net/allow-two-primaries");
301-
deleteProps.add("DrbdOptions/Net/protocol");
302340
rcm.deleteProps(deleteProps);
303341
ApiCallRcList answers = api.resourceConnectionModify(rscName, localNodeName, inUseNode, rcm);
304342
if (answers.hasError()) {
@@ -310,6 +348,15 @@ private void removeTwoPrimariesRcProps(DevelopersApi api, String inUseNode, Stri
310348
}
311349
}
312350

351+
private void removeTwoPrimariesProps(DevelopersApi api, String inUseNode, String rscName) throws ApiException {
352+
List<String> deleteProps = new ArrayList<>();
353+
deleteProps.add("DrbdOptions/Net/allow-two-primaries");
354+
deleteProps.add("DrbdOptions/Net/protocol");
355+
356+
removeTwoPrimariesRDProps(api, rscName, deleteProps);
357+
removeTwoPrimariesRcProps(api, rscName, inUseNode, deleteProps);
358+
}
359+
313360
private boolean tryDisconnectLinstor(String volumePath, KVMStoragePool pool)
314361
{
315362
if (volumePath == null) {
@@ -343,7 +390,7 @@ private boolean tryDisconnectLinstor(String volumePath, KVMStoragePool pool)
343390
try {
344391
String inUseNode = LinstorUtil.isResourceInUse(api, rsc.getName());
345392
if (inUseNode != null && !inUseNode.equalsIgnoreCase(localNodeName)) {
346-
removeTwoPrimariesRcProps(api, inUseNode, rsc.getName());
393+
removeTwoPrimariesProps(api, inUseNode, rsc.getName());
347394
}
348395
} catch (ApiException apiEx) {
349396
logger.error(apiEx.getBestMessage());

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.apache.cloudstack.storage.datastore.util;
1818

1919
import com.linbit.linstor.api.ApiClient;
20+
import com.linbit.linstor.api.ApiConsts;
2021
import com.linbit.linstor.api.ApiException;
2122
import com.linbit.linstor.api.DevelopersApi;
2223
import com.linbit.linstor.api.model.ApiCallRc;
@@ -33,6 +34,7 @@
3334

3435
import javax.annotation.Nonnull;
3536

37+
import java.util.Collection;
3638
import java.util.Collections;
3739
import java.util.List;
3840
import java.util.stream.Collectors;
@@ -210,6 +212,28 @@ public static String isResourceInUse(DevelopersApi api, String rscName) throws A
210212
return null;
211213
}
212214

215+
/**
216+
* Check if the given resources are diskless.
217+
*
218+
* @param api developer api object to use
219+
* @param rscName resource name to check in use state.
220+
* @return NodeName where the resource is inUse, if not in use `null`
221+
* @throws ApiException forwards api errors
222+
*/
223+
public static boolean areResourcesDiskless(DevelopersApi api, String rscName, Collection<String> nodeNames)
224+
throws ApiException {
225+
List<Resource> rscs = api.resourceList(rscName, null, null);
226+
if (rscs != null) {
227+
Collection<String> disklessNodes = rscs.stream()
228+
.filter(rsc -> rsc.getFlags() != null && (rsc.getFlags().contains(ApiConsts.FLAG_DISKLESS) ||
229+
rsc.getFlags().contains(ApiConsts.FLAG_DRBD_DISKLESS)))
230+
.map(rsc -> rsc.getNodeName().toLowerCase())
231+
.collect(Collectors.toList());
232+
return disklessNodes.containsAll(nodeNames.stream().map(String::toLowerCase).collect(Collectors.toList()));
233+
}
234+
return false;
235+
}
236+
213237
/**
214238
* Try to get the device path for the given resource name.
215239
* This could be made a bit more direct after java-linstor api is fixed for layer data subtypes.

0 commit comments

Comments
 (0)