Skip to content

Commit e61f3ba

Browse files
committed
Merge branch '4.19'
2 parents 54926c3 + 3de1f8b commit e61f3ba

File tree

18 files changed

+487
-278
lines changed

18 files changed

+487
-278
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ jobs:
5454
smoke/test_deploy_vm_with_userdata
5555
smoke/test_deploy_vms_in_parallel
5656
smoke/test_deploy_vms_with_varied_deploymentplanners
57+
smoke/test_restore_vm
5758
smoke/test_diagnostics
5859
smoke/test_direct_download
5960
smoke/test_disk_offerings

engine/api/src/main/java/org/apache/cloudstack/engine/orchestration/service/VolumeOrchestrationService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public interface VolumeOrchestrationService {
8585
VolumeInfo moveVolume(VolumeInfo volume, long destPoolDcId, Long destPoolPodId, Long destPoolClusterId, HypervisorType dataDiskHyperType)
8686
throws ConcurrentOperationException, StorageUnavailableException;
8787

88-
Volume allocateDuplicateVolume(Volume oldVol, Long templateId);
88+
Volume allocateDuplicateVolume(Volume oldVol, DiskOffering diskOffering, Long templateId);
8989

9090
boolean volumeOnSharedStoragePool(Volume volume);
9191

engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,11 @@ public VolumeInfo moveVolume(VolumeInfo volumeInfo, long destPoolDcId, Long dest
306306
}
307307

308308
@Override
309-
public Volume allocateDuplicateVolume(Volume oldVol, Long templateId) {
310-
return allocateDuplicateVolumeVO(oldVol, templateId);
309+
public Volume allocateDuplicateVolume(Volume oldVol, DiskOffering diskOffering, Long templateId) {
310+
return allocateDuplicateVolumeVO(oldVol, diskOffering, templateId);
311311
}
312312

313-
public VolumeVO allocateDuplicateVolumeVO(Volume oldVol, Long templateId) {
313+
public VolumeVO allocateDuplicateVolumeVO(Volume oldVol, DiskOffering diskOffering, Long templateId) {
314314
VolumeVO newVol = new VolumeVO(oldVol.getVolumeType(), oldVol.getName(), oldVol.getDataCenterId(), oldVol.getDomainId(), oldVol.getAccountId(), oldVol.getDiskOfferingId(),
315315
oldVol.getProvisioningType(), oldVol.getSize(), oldVol.getMinIops(), oldVol.getMaxIops(), oldVol.get_iScsiName());
316316
if (templateId != null) {
@@ -322,8 +322,7 @@ public VolumeVO allocateDuplicateVolumeVO(Volume oldVol, Long templateId) {
322322
newVol.setInstanceId(oldVol.getInstanceId());
323323
newVol.setRecreatable(oldVol.isRecreatable());
324324
newVol.setFormat(oldVol.getFormat());
325-
326-
if (oldVol.getPassphraseId() != null) {
325+
if ((diskOffering == null || diskOffering.getEncrypt()) && oldVol.getPassphraseId() != null) {
327326
PassphraseVO passphrase = passphraseDao.persist(new PassphraseVO(true));
328327
newVol.setPassphraseId(passphrase.getId());
329328
}
@@ -1170,7 +1169,7 @@ protected VolumeVO switchVolume(final VolumeVO existingVolume, final VirtualMach
11701169
return Transaction.execute(new TransactionCallback<VolumeVO>() {
11711170
@Override
11721171
public VolumeVO doInTransaction(TransactionStatus status) {
1173-
VolumeVO newVolume = allocateDuplicateVolumeVO(existingVolume, templateIdToUseFinal);
1172+
VolumeVO newVolume = allocateDuplicateVolumeVO(existingVolume, null, templateIdToUseFinal);
11741173
try {
11751174
stateTransitTo(existingVolume, Volume.Event.DestroyRequested);
11761175
} catch (NoTransitionException e) {

engine/schema/src/main/java/com/cloud/upgrade/SystemVmTemplateRegistration.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -483,19 +483,19 @@ private VMTemplateZoneVO createOrUpdateTemplateZoneEntry(long zoneId, long templ
483483
templateZoneVO = vmTemplateZoneDao.persist(templateZoneVO);
484484
} else {
485485
templateZoneVO.setLastUpdated(new java.util.Date());
486-
if (vmTemplateZoneDao.update(templateZoneVO.getId(), templateZoneVO)) {
486+
if (!vmTemplateZoneDao.update(templateZoneVO.getId(), templateZoneVO)) {
487487
templateZoneVO = null;
488488
}
489489
}
490490
return templateZoneVO;
491491
}
492492

493-
private void createCrossZonesTemplateZoneRefEntries(VMTemplateVO template) {
493+
private void createCrossZonesTemplateZoneRefEntries(Long templateId) {
494494
List<DataCenterVO> dcs = dataCenterDao.listAll();
495495
for (DataCenterVO dc : dcs) {
496-
VMTemplateZoneVO templateZoneVO = createOrUpdateTemplateZoneEntry(dc.getId(), template.getId());
496+
VMTemplateZoneVO templateZoneVO = createOrUpdateTemplateZoneEntry(dc.getId(), templateId);
497497
if (templateZoneVO == null) {
498-
throw new CloudRuntimeException(String.format("Failed to create template_zone_ref record for the systemVM template for hypervisor: %s and zone: %s", template.getHypervisorType().name(), dc));
498+
throw new CloudRuntimeException(String.format("Failed to create template_zone_ref record for the systemVM template (id: %s) and zone: %s", templateId, dc));
499499
}
500500
}
501501
}
@@ -625,8 +625,9 @@ private Long performTemplateRegistrationOperations(Pair<Hypervisor.HypervisorTyp
625625
throw new CloudRuntimeException(String.format("Failed to register template for hypervisor: %s", hypervisor.name()));
626626
}
627627
templateId = template.getId();
628-
createCrossZonesTemplateZoneRefEntries(template);
629628
}
629+
createCrossZonesTemplateZoneRefEntries(templateId);
630+
630631
details.setId(templateId);
631632
String destTempFolderName = String.valueOf(templateId);
632633
String destTempFolder = filePath + PARTIAL_TEMPLATE_FOLDER + destTempFolderName;

engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,7 @@ private void destroyAndReallocateManagedVolume(VolumeInfo volumeInfo) {
12401240

12411241
volumeInfo.processEvent(Event.DestroyRequested);
12421242

1243-
Volume newVol = _volumeMgr.allocateDuplicateVolume(volume, null);
1243+
Volume newVol = _volumeMgr.allocateDuplicateVolume(volume, null, null);
12441244
VolumeVO newVolume = (VolumeVO) newVol;
12451245
newVolume.set_iScsiName(null);
12461246
volDao.update(newVolume.getId(), newVolume);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,10 @@ public String getDiskLabel() {
10081008
return _diskLabel;
10091009
}
10101010

1011+
public void setDiskLabel(String label) {
1012+
_diskLabel = label;
1013+
}
1014+
10111015
public DiskType getDiskType() {
10121016
return _diskType;
10131017
}

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

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,20 @@
1818
*/
1919
package com.cloud.hypervisor.kvm.resource;
2020

21+
import java.util.Iterator;
22+
import java.util.Set;
2123
import java.util.concurrent.Callable;
2224

25+
import org.apache.log4j.Logger;
2326
import org.libvirt.Connect;
2427
import org.libvirt.Domain;
2528
import org.libvirt.LibvirtException;
29+
import org.libvirt.TypedParameter;
30+
import org.libvirt.TypedStringParameter;
31+
import org.libvirt.TypedUlongParameter;
2632

2733
public class MigrateKVMAsync implements Callable<Domain> {
34+
protected Logger logger = Logger.getLogger(getClass());
2835

2936
private final LibvirtComputingResource libvirtComputingResource;
3037

@@ -37,6 +44,8 @@ public class MigrateKVMAsync implements Callable<Domain> {
3744
private boolean migrateNonSharedInc;
3845
private boolean autoConvergence;
3946

47+
protected Set<String> migrateDiskLabels;
48+
4049
// Libvirt Migrate Flags reference:
4150
// https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainMigrateFlags
4251

@@ -87,7 +96,7 @@ public class MigrateKVMAsync implements Callable<Domain> {
8796
private static final int LIBVIRT_VERSION_SUPPORTS_AUTO_CONVERGE = 1002003;
8897

8998
public MigrateKVMAsync(final LibvirtComputingResource libvirtComputingResource, final Domain dm, final Connect dconn, final String dxml,
90-
final boolean migrateStorage, final boolean migrateNonSharedInc, final boolean autoConvergence, final String vmName, final String destIp) {
99+
final boolean migrateStorage, final boolean migrateNonSharedInc, final boolean autoConvergence, final String vmName, final String destIp, Set<String> migrateDiskLabels) {
91100
this.libvirtComputingResource = libvirtComputingResource;
92101

93102
this.dm = dm;
@@ -98,6 +107,7 @@ public MigrateKVMAsync(final LibvirtComputingResource libvirtComputingResource,
98107
this.autoConvergence = autoConvergence;
99108
this.vmName = vmName;
100109
this.destIp = destIp;
110+
this.migrateDiskLabels = migrateDiskLabels;
101111
}
102112

103113
@Override
@@ -121,6 +131,37 @@ public Domain call() throws LibvirtException {
121131
flags |= VIR_MIGRATE_AUTO_CONVERGE;
122132
}
123133

124-
return dm.migrate(dconn, flags, dxml, vmName, "tcp:" + destIp, libvirtComputingResource.getMigrateSpeed());
134+
TypedParameter [] parameters = createTypedParameterList();
135+
136+
logger.debug(String.format("Migrating [%s] with flags [%s], destination [%s] and speed [%s]. The disks with the following labels will be migrated [%s].", vmName, flags,
137+
destIp, libvirtComputingResource.getMigrateSpeed(), migrateDiskLabels));
138+
139+
return dm.migrate(dconn, parameters, flags);
140+
141+
}
142+
143+
protected TypedParameter[] createTypedParameterList() {
144+
int sizeOfMigrateDiskLabels = 0;
145+
if (migrateDiskLabels != null) {
146+
sizeOfMigrateDiskLabels = migrateDiskLabels.size();
147+
}
148+
149+
TypedParameter[] parameters = new TypedParameter[4 + sizeOfMigrateDiskLabels];
150+
parameters[0] = new TypedStringParameter(Domain.DomainMigrateParameters.VIR_MIGRATE_PARAM_DEST_NAME, vmName);
151+
parameters[1] = new TypedStringParameter(Domain.DomainMigrateParameters.VIR_MIGRATE_PARAM_DEST_XML, dxml);
152+
parameters[2] = new TypedStringParameter(Domain.DomainMigrateParameters.VIR_MIGRATE_PARAM_URI, "tcp:" + destIp);
153+
parameters[3] = new TypedUlongParameter(Domain.DomainMigrateParameters.VIR_MIGRATE_PARAM_BANDWIDTH, libvirtComputingResource.getMigrateSpeed());
154+
155+
if (sizeOfMigrateDiskLabels == 0) {
156+
return parameters;
157+
}
158+
159+
Iterator<String> iterator = migrateDiskLabels.iterator();
160+
for (int i = 0; i < sizeOfMigrateDiskLabels; i++) {
161+
parameters[4 + i] = new TypedStringParameter(Domain.DomainMigrateParameters.VIR_MIGRATE_PARAM_MIGRATE_DISKS, iterator.next());
162+
}
163+
164+
return parameters;
125165
}
166+
126167
}

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.io.InputStream;
2525
import java.net.URISyntaxException;
2626
import java.nio.charset.StandardCharsets;
27+
import java.util.HashSet;
2728
import java.util.List;
2829
import java.util.Map;
2930
import java.util.Set;
@@ -188,6 +189,7 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0.
188189
// migrateStorage's value should always only be associated with the initial state of mapMigrateStorage.
189190
final boolean migrateStorage = MapUtils.isNotEmpty(mapMigrateStorage);
190191
final boolean migrateStorageManaged = command.isMigrateStorageManaged();
192+
Set<String> migrateDiskLabels = null;
191193

192194
if (migrateStorage) {
193195
if (logger.isDebugEnabled()) {
@@ -197,6 +199,7 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0.
197199
if (logger.isDebugEnabled()) {
198200
logger.debug(String.format("Changed VM [%s] XML configuration of used storage. New XML configuration is [%s].", vmName, xmlDesc));
199201
}
202+
migrateDiskLabels = getMigrateStorageDeviceLabels(disks, mapMigrateStorage);
200203
}
201204

202205
Map<String, DpdkTO> dpdkPortsMapping = command.getDpdkInterfaceMapping();
@@ -225,7 +228,7 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0.
225228

226229
final Callable<Domain> worker = new MigrateKVMAsync(libvirtComputingResource, dm, dconn, xmlDesc,
227230
migrateStorage, migrateNonSharedInc,
228-
command.isAutoConvergence(), vmName, command.getDestinationIp());
231+
command.isAutoConvergence(), vmName, command.getDestinationIp(), migrateDiskLabels);
229232
final Future<Domain> migrateThread = executor.submit(worker);
230233
executor.shutdown();
231234
long sleeptime = 0;
@@ -364,6 +367,30 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0.
364367
return new MigrateAnswer(command, result == null, result, null);
365368
}
366369

370+
/**
371+
* Gets the disk labels (vda, vdb...) of the disks mapped for migration on mapMigrateStorage.
372+
* @param diskDefinitions list of all the disksDefinitions of the VM.
373+
* @param mapMigrateStorage map of the disks that should be migrated.
374+
* @return set with the labels of the disks that should be migrated.
375+
* */
376+
protected Set<String> getMigrateStorageDeviceLabels(List<DiskDef> diskDefinitions, Map<String, MigrateCommand.MigrateDiskInfo> mapMigrateStorage) {
377+
HashSet<String> setOfLabels = new HashSet<>();
378+
logger.debug("Searching for disk labels of disks [{}].", mapMigrateStorage.keySet());
379+
for (String fileName : mapMigrateStorage.keySet()) {
380+
for (DiskDef diskDef : diskDefinitions) {
381+
String diskPath = diskDef.getDiskPath();
382+
if (diskPath != null && diskPath.contains(fileName)) {
383+
setOfLabels.add(diskDef.getDiskLabel());
384+
logger.debug("Found label [{}] for disk [{}].", diskDef.getDiskLabel(), fileName);
385+
break;
386+
}
387+
}
388+
}
389+
390+
return setOfLabels;
391+
}
392+
393+
367394
/**
368395
* Checks if the CPU shares are equal in the source host and destination host.
369396
* <ul>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
20+
package com.cloud.hypervisor.kvm.resource;
21+
22+
import org.junit.Assert;
23+
import org.junit.Test;
24+
import org.junit.runner.RunWith;
25+
import org.libvirt.Connect;
26+
import org.libvirt.Domain;
27+
import org.libvirt.TypedParameter;
28+
import org.mockito.Mock;
29+
import org.mockito.Mockito;
30+
import org.mockito.junit.MockitoJUnitRunner;
31+
32+
import java.util.Set;
33+
34+
@RunWith(MockitoJUnitRunner.class)
35+
public class MigrateKVMAsyncTest {
36+
37+
@Mock
38+
private LibvirtComputingResource libvirtComputingResource;
39+
@Mock
40+
private Connect connect;
41+
@Mock
42+
private Domain domain;
43+
44+
45+
@Test
46+
public void createTypedParameterListTestNoMigrateDiskLabels() {
47+
MigrateKVMAsync migrateKVMAsync = new MigrateKVMAsync(libvirtComputingResource, domain, connect, "testxml",
48+
false, false, false, "tst", "1.1.1.1", null);
49+
50+
Mockito.doReturn(10).when(libvirtComputingResource).getMigrateSpeed();
51+
52+
TypedParameter[] result = migrateKVMAsync.createTypedParameterList();
53+
54+
Assert.assertEquals(4, result.length);
55+
56+
Assert.assertEquals("tst", result[0].getValueAsString());
57+
Assert.assertEquals("testxml", result[1].getValueAsString());
58+
Assert.assertEquals("tcp:1.1.1.1", result[2].getValueAsString());
59+
Assert.assertEquals("10", result[3].getValueAsString());
60+
61+
}
62+
63+
@Test
64+
public void createTypedParameterListTestWithMigrateDiskLabels() {
65+
Set<String> labels = Set.of("vda", "vdb");
66+
MigrateKVMAsync migrateKVMAsync = new MigrateKVMAsync(libvirtComputingResource, domain, connect, "testxml",
67+
false, false, false, "tst", "1.1.1.1", labels);
68+
69+
Mockito.doReturn(10).when(libvirtComputingResource).getMigrateSpeed();
70+
71+
TypedParameter[] result = migrateKVMAsync.createTypedParameterList();
72+
73+
Assert.assertEquals(6, result.length);
74+
75+
Assert.assertEquals("tst", result[0].getValueAsString());
76+
Assert.assertEquals("testxml", result[1].getValueAsString());
77+
Assert.assertEquals("tcp:1.1.1.1", result[2].getValueAsString());
78+
Assert.assertEquals("10", result[3].getValueAsString());
79+
80+
Assert.assertEquals(labels, Set.of(result[4].getValueAsString(), result[5].getValueAsString()));
81+
}
82+
83+
}

0 commit comments

Comments
 (0)