Skip to content

Commit e289502

Browse files
Merge branch 'main' into ui-improv
2 parents 320b7f0 + f7b7339 commit e289502

File tree

16 files changed

+276
-57
lines changed

16 files changed

+276
-57
lines changed

engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,8 +2078,8 @@ public void copyAsync(Map<VolumeInfo, DataStore> volumeDataStoreMap, VirtualMach
20782078
migrateDiskInfo = configureMigrateDiskInfo(srcVolumeInfo, destPath, backingPath);
20792079
migrateDiskInfo.setSourceDiskOnStorageFileSystem(isStoragePoolTypeOfFile(sourceStoragePool));
20802080
migrateDiskInfoList.add(migrateDiskInfo);
2081-
prepareDiskWithSecretConsumerDetail(vmTO, srcVolumeInfo, destVolumeInfo.getPath());
20822081
}
2082+
prepareDiskWithSecretConsumerDetail(vmTO, srcVolumeInfo, destVolumeInfo.getPath());
20832083

20842084
migrateStorage.put(srcVolumeInfo.getPath(), migrateDiskInfo);
20852085

@@ -2479,7 +2479,8 @@ protected void verifyLiveMigrationForKVM(Map<VolumeInfo, DataStore> volumeDataSt
24792479
throw new CloudRuntimeException("Destination storage pool with ID " + dataStore.getId() + " was not located.");
24802480
}
24812481

2482-
if (srcStoragePoolVO.isManaged() && srcStoragePoolVO.getId() != destStoragePoolVO.getId()) {
2482+
boolean isSrcAndDestPoolPowerFlexStorage = srcStoragePoolVO.getPoolType().equals(Storage.StoragePoolType.PowerFlex) && destStoragePoolVO.getPoolType().equals(Storage.StoragePoolType.PowerFlex);
2483+
if (srcStoragePoolVO.isManaged() && !isSrcAndDestPoolPowerFlexStorage && srcStoragePoolVO.getId() != destStoragePoolVO.getId()) {
24832484
throw new CloudRuntimeException("Migrating a volume online with KVM from managed storage is not currently supported.");
24842485
}
24852486

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
381381
protected static final String DEFAULT_TUNGSTEN_VIF_DRIVER_CLASS_NAME = "com.cloud.hypervisor.kvm.resource.VRouterVifDriver";
382382
private final static long HYPERVISOR_LIBVIRT_VERSION_SUPPORTS_IO_URING = 6003000;
383383
private final static long HYPERVISOR_QEMU_VERSION_SUPPORTS_IO_URING = 5000000;
384+
private final static long HYPERVISOR_QEMU_VERSION_IDE_DISCARD_FIXED = 7000000;
384385

385386
protected HypervisorType hypervisorType;
386387
protected String hypervisorURI;
@@ -3050,7 +3051,7 @@ public int compare(final DiskTO arg0, final DiskTO arg1) {
30503051
}
30513052
} else if (volume.getType() != Volume.Type.ISO) {
30523053
final PrimaryDataStoreTO store = (PrimaryDataStoreTO)data.getDataStore();
3053-
physicalDisk = storagePoolManager.getPhysicalDisk(store.getPoolType(), store.getUuid(), data.getPath());
3054+
physicalDisk = getStoragePoolMgr().getPhysicalDisk(store.getPoolType(), store.getUuid(), data.getPath());
30543055
pool = physicalDisk.getPool();
30553056
}
30563057

@@ -3152,7 +3153,7 @@ public int compare(final DiskTO arg0, final DiskTO arg1) {
31523153
else {
31533154
disk.defBlockBasedDisk(physicalDisk.getPath(), devId, diskBusType);
31543155
}
3155-
if (pool.getType() == StoragePoolType.Linstor) {
3156+
if (pool.getType() == StoragePoolType.Linstor && isQemuDiscardBugFree(diskBusType)) {
31563157
disk.setDiscard(DiscardType.UNMAP);
31573158
}
31583159
} else {
@@ -3299,6 +3300,16 @@ private boolean isIoUringEnabled() {
32993300
return isUbuntuHost() || isIoUringSupportedByQemu();
33003301
}
33013302

3303+
/**
3304+
* Qemu has a bug with discard enabled on IDE bus devices if qemu version < 7.0.
3305+
* <a href="https://bugzilla.redhat.com/show_bug.cgi?id=2029980">redhat bug entry</a>
3306+
* @param diskBus used for the disk
3307+
* @return true if it is safe to enable discard, otherwise false.
3308+
*/
3309+
public boolean isQemuDiscardBugFree(DiskDef.DiskBus diskBus) {
3310+
return diskBus != DiskDef.DiskBus.IDE || getHypervisorQemuVersion() >= HYPERVISOR_QEMU_VERSION_IDE_DISCARD_FIXED;
3311+
}
3312+
33023313
public boolean isUbuntuHost() {
33033314
Map<String, String> versionString = getVersionStrings();
33043315
String hostKey = "Host.OS";

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsFetchInterfaceCommandWrapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public Ternary<String, String, String> getInterfaceDetails(String interfaceName)
8989

9090
@Override
9191
public Answer execute(final OvsFetchInterfaceCommand command, final LibvirtComputingResource libvirtComputingResource) {
92-
final String label = "'" + command.getLabel() + "'";
92+
final String label = command.getLabel();
9393

9494
logger.debug("Will look for network with name-label:" + label);
9595
try {

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1447,7 +1447,7 @@ protected synchronized void attachOrDetachDisk(final Connect conn, final boolean
14471447
diskdef.defFileBasedDisk(attachingDisk.getPath(), devId, busT, DiskDef.DiskFmtType.QCOW2);
14481448
} else if (attachingDisk.getFormat() == PhysicalDiskFormat.RAW) {
14491449
diskdef.defBlockBasedDisk(attachingDisk.getPath(), devId, busT);
1450-
if (attachingPool.getType() == StoragePoolType.Linstor) {
1450+
if (attachingPool.getType() == StoragePoolType.Linstor && resource.isQemuDiscardBugFree(busT)) {
14511451
diskdef.setDiscard(DiscardType.UNMAP);
14521452
}
14531453
}

plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,12 @@
5858

5959
import com.cloud.utils.net.NetUtils;
6060

61+
import com.cloud.vm.VmDetailConstants;
6162
import org.apache.cloudstack.api.ApiConstants.IoDriverPolicy;
6263
import org.apache.cloudstack.storage.command.AttachAnswer;
6364
import org.apache.cloudstack.storage.command.AttachCommand;
65+
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
66+
import org.apache.cloudstack.storage.to.VolumeObjectTO;
6467
import org.apache.cloudstack.utils.bytescale.ByteScaleUtils;
6568
import org.apache.cloudstack.utils.linux.CPUStat;
6669
import org.apache.cloudstack.utils.linux.MemStat;
@@ -6415,4 +6418,114 @@ public void calculateVmMetricsTestOldStatsIsNotNullCalculatesUtilization() throw
64156418
Assert.assertEquals(newStats.getDiskReadKBs() - oldStats.getDiskReadKBs(), metrics.getDiskReadKBs(), 0);
64166419
Assert.assertEquals(newStats.getDiskWriteKBs() - oldStats.getDiskWriteKBs(), metrics.getDiskWriteKBs(), 0);
64176420
}
6421+
6422+
@Test
6423+
public void createLinstorVdb() throws LibvirtException, InternalErrorException, URISyntaxException {
6424+
final Connect connect = Mockito.mock(Connect.class);
6425+
6426+
final int id = random.nextInt(65534);
6427+
final String name = "test-instance-1";
6428+
6429+
final int cpus = 2;
6430+
final int speed = 1024;
6431+
final int minRam = 256 * 1024;
6432+
final int maxRam = 512 * 1024;
6433+
final String os = "Ubuntu";
6434+
final String vncPassword = "mySuperSecretPassword";
6435+
6436+
final VirtualMachineTO to = new VirtualMachineTO(id, name, VirtualMachine.Type.User, cpus, speed, minRam,
6437+
maxRam, BootloaderType.HVM, os, false, false, vncPassword);
6438+
to.setVncAddr("");
6439+
to.setArch("x86_64");
6440+
to.setUuid("b0f0a72d-7efb-3cad-a8ff-70ebf30b3af9");
6441+
to.setVcpuMaxLimit(cpus + 1);
6442+
final HashMap<String, String> vmToDetails = new HashMap<>();
6443+
to.setDetails(vmToDetails);
6444+
6445+
String diskLinPath = "9ebe53c1-3d35-46e5-b7aa-6fc223ba0fcf";
6446+
final DiskTO diskTO = new DiskTO();
6447+
diskTO.setDiskSeq(1L);
6448+
diskTO.setType(Volume.Type.ROOT);
6449+
diskTO.setDetails(new HashMap<>());
6450+
diskTO.setPath(diskLinPath);
6451+
6452+
final PrimaryDataStoreTO primaryDataStoreTO = Mockito.mock(PrimaryDataStoreTO.class);
6453+
String pDSTOUUID = "9ebe53c1-3d35-46e5-b7aa-6fc223ac4fcf";
6454+
when(primaryDataStoreTO.getPoolType()).thenReturn(StoragePoolType.Linstor);
6455+
when(primaryDataStoreTO.getUuid()).thenReturn(pDSTOUUID);
6456+
6457+
VolumeObjectTO dataTO = new VolumeObjectTO();
6458+
6459+
dataTO.setUuid("12be53c1-3d35-46e5-b7aa-6fc223ba0f34");
6460+
dataTO.setPath(diskTO.getPath());
6461+
dataTO.setDataStore(primaryDataStoreTO);
6462+
diskTO.setData(dataTO);
6463+
to.setDisks(new DiskTO[]{diskTO});
6464+
6465+
String path = "/dev/drbd1020";
6466+
final KVMStoragePoolManager storagePoolMgr = Mockito.mock(KVMStoragePoolManager.class);
6467+
final KVMStoragePool storagePool = Mockito.mock(KVMStoragePool.class);
6468+
final KVMPhysicalDisk vol = Mockito.mock(KVMPhysicalDisk.class);
6469+
6470+
when(libvirtComputingResourceSpy.getStoragePoolMgr()).thenReturn(storagePoolMgr);
6471+
when(storagePool.getType()).thenReturn(StoragePoolType.Linstor);
6472+
when(storagePoolMgr.getPhysicalDisk(StoragePoolType.Linstor, pDSTOUUID, diskLinPath)).thenReturn(vol);
6473+
when(vol.getPath()).thenReturn(path);
6474+
when(vol.getPool()).thenReturn(storagePool);
6475+
when(vol.getFormat()).thenReturn(PhysicalDiskFormat.RAW);
6476+
6477+
// 1. test Bus: IDE and broken qemu version -> NO discard
6478+
when(libvirtComputingResourceSpy.getHypervisorQemuVersion()).thenReturn(6000000L);
6479+
vmToDetails.put(VmDetailConstants.ROOT_DISK_CONTROLLER, DiskDef.DiskBus.IDE.name());
6480+
{
6481+
LibvirtVMDef vm = new LibvirtVMDef();
6482+
vm.addComp(new DevicesDef());
6483+
libvirtComputingResourceSpy.createVbd(connect, to, name, vm);
6484+
6485+
DiskDef rootDisk = vm.getDevices().getDisks().get(0);
6486+
assertEquals(DiskDef.DiskType.BLOCK, rootDisk.getDiskType());
6487+
assertEquals(DiskDef.DiskBus.IDE, rootDisk.getBusType());
6488+
assertEquals(DiskDef.DiscardType.IGNORE, rootDisk.getDiscard());
6489+
}
6490+
6491+
// 2. test Bus: VIRTIO and broken qemu version -> discard unmap
6492+
vmToDetails.put(VmDetailConstants.ROOT_DISK_CONTROLLER, DiskDef.DiskBus.VIRTIO.name());
6493+
{
6494+
LibvirtVMDef vm = new LibvirtVMDef();
6495+
vm.addComp(new DevicesDef());
6496+
libvirtComputingResourceSpy.createVbd(connect, to, name, vm);
6497+
6498+
DiskDef rootDisk = vm.getDevices().getDisks().get(0);
6499+
assertEquals(DiskDef.DiskType.BLOCK, rootDisk.getDiskType());
6500+
assertEquals(DiskDef.DiskBus.VIRTIO, rootDisk.getBusType());
6501+
assertEquals(DiskDef.DiscardType.UNMAP, rootDisk.getDiscard());
6502+
}
6503+
6504+
// 3. test Bus; IDE and "good" qemu version -> discard unmap
6505+
vmToDetails.put(VmDetailConstants.ROOT_DISK_CONTROLLER, DiskDef.DiskBus.IDE.name());
6506+
when(libvirtComputingResourceSpy.getHypervisorQemuVersion()).thenReturn(7000000L);
6507+
{
6508+
LibvirtVMDef vm = new LibvirtVMDef();
6509+
vm.addComp(new DevicesDef());
6510+
libvirtComputingResourceSpy.createVbd(connect, to, name, vm);
6511+
6512+
DiskDef rootDisk = vm.getDevices().getDisks().get(0);
6513+
assertEquals(DiskDef.DiskType.BLOCK, rootDisk.getDiskType());
6514+
assertEquals(DiskDef.DiskBus.IDE, rootDisk.getBusType());
6515+
assertEquals(DiskDef.DiscardType.UNMAP, rootDisk.getDiscard());
6516+
}
6517+
6518+
// 4. test Bus: VIRTIO and "good" qemu version -> discard unmap
6519+
vmToDetails.put(VmDetailConstants.ROOT_DISK_CONTROLLER, DiskDef.DiskBus.VIRTIO.name());
6520+
{
6521+
LibvirtVMDef vm = new LibvirtVMDef();
6522+
vm.addComp(new DevicesDef());
6523+
libvirtComputingResourceSpy.createVbd(connect, to, name, vm);
6524+
6525+
DiskDef rootDisk = vm.getDevices().getDisks().get(0);
6526+
assertEquals(DiskDef.DiskType.BLOCK, rootDisk.getDiskType());
6527+
assertEquals(DiskDef.DiskBus.VIRTIO, rootDisk.getBusType());
6528+
assertEquals(DiskDef.DiscardType.UNMAP, rootDisk.getDiscard());
6529+
}
6530+
}
64186531
}

plugins/storage/volume/linstor/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to Linstor CloudStack plugin will be documented in this file
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [2024-10-28]
9+
10+
### Fixed
11+
12+
- Disable discard="unmap" for ide devices and qemu < 7.0
13+
https://bugzilla.redhat.com/show_bug.cgi?id=2029980
14+
815
## [2024-10-04]
916

1017
### Added

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

Lines changed: 62 additions & 15 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;
@@ -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());

0 commit comments

Comments
 (0)