Skip to content

Commit 0fbf500

Browse files
nvazquezrohityadavcloud
authored andcommitted
kvm: live storage migration intra cluster from NFS source and destination (#2983)
Feature Specification: https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=95653548 Live storage migration on KVM under these conditions: From source and destination hosts within the same cluster From NFS primary storage to NFS cluster-wide primary storage Source NFS and destination NFS storage mounted on hosts In order to enable this functionality, database should be updated in order to enable live storage capacibilty for KVM, if previous conditions are met. This is due to existing conflicts between qemu and libvirt versions. This has been tested on CentOS 6 hosts. Additional notes: To use this feature set the storage_motion_supported=1 in the hypervisor_capability table for KVM. This is done by default as the feature may not work in some environments, read below. This feature of online storage+VM migration for KVM will only work with CentOS6 and possible Ubuntu as KVM hosts but not with CentOS7 due to: https://bugs.centos.org/view.php?id=14026 https://bugzilla.redhat.com/show_bug.cgi?id=1219541 On CentOS7 the error we see is: " error: unable to execute QEMU command 'migrate': this feature or command is not currently supported" (reference https://ask.openstack.org/en/question/94186/live-migration-unable-to-execute-qemu-command-migrate/). Reading through various lists looks like the migrate feature with qemu may be available with paid versions of RHEL-EV but not centos7 however this works with CentOS6. Fix for CentOS 7: Create repo file on /etc/yum.repos.d/: [qemu-kvm-rhev] name=oVirt rebuilds of qemu-kvm-rhev baseurl=http://resources.ovirt.org/pub/ovirt-3.5/rpm/el7Server/ mirrorlist=http://resources.ovirt.org/pub/yum-repo/mirrorlist-ovirt-3.5-el7Server enabled=1 skip_if_unavailable=1 gpgcheck=0 yum install qemu-kvm-common-ev-2.3.0-29.1.el7.x86_64 qemu-kvm-ev-2.3.0-29.1.el7.x86_64 qemu-img-ev-2.3.0-29.1.el7.x86_64 Reboot host Signed-off-by: Rohit Yadav <[email protected]>
1 parent 6323aac commit 0fbf500

File tree

31 files changed

+1309
-195
lines changed

31 files changed

+1309
-195
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
package com.cloud.storage;
20+
21+
import java.io.Serializable;
22+
23+
public class MigrationOptions implements Serializable {
24+
25+
private String srcPoolUuid;
26+
private Storage.StoragePoolType srcPoolType;
27+
private Type type;
28+
private String srcBackingFilePath;
29+
private boolean copySrcTemplate;
30+
private String srcVolumeUuid;
31+
private int timeout;
32+
33+
public enum Type {
34+
LinkedClone, FullClone
35+
}
36+
37+
public MigrationOptions() {
38+
}
39+
40+
public MigrationOptions(String srcPoolUuid, Storage.StoragePoolType srcPoolType, String srcBackingFilePath, boolean copySrcTemplate) {
41+
this.srcPoolUuid = srcPoolUuid;
42+
this.srcPoolType = srcPoolType;
43+
this.type = Type.LinkedClone;
44+
this.srcBackingFilePath = srcBackingFilePath;
45+
this.copySrcTemplate = copySrcTemplate;
46+
}
47+
48+
public MigrationOptions(String srcPoolUuid, Storage.StoragePoolType srcPoolType, String srcVolumeUuid) {
49+
this.srcPoolUuid = srcPoolUuid;
50+
this.srcPoolType = srcPoolType;
51+
this.type = Type.FullClone;
52+
this.srcVolumeUuid = srcVolumeUuid;
53+
}
54+
55+
public String getSrcPoolUuid() {
56+
return srcPoolUuid;
57+
}
58+
59+
public Storage.StoragePoolType getSrcPoolType() {
60+
return srcPoolType;
61+
}
62+
63+
public String getSrcBackingFilePath() {
64+
return srcBackingFilePath;
65+
}
66+
67+
public boolean isCopySrcTemplate() {
68+
return copySrcTemplate;
69+
}
70+
71+
public String getSrcVolumeUuid() {
72+
return srcVolumeUuid;
73+
}
74+
75+
public Type getType() {
76+
return type;
77+
}
78+
79+
public int getTimeout() {
80+
return timeout;
81+
}
82+
83+
public void setTimeout(int timeout) {
84+
this.timeout = timeout;
85+
}
86+
}

core/src/main/java/com/cloud/agent/api/CreateVMSnapshotCommand.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ public CreateVMSnapshotCommand(String vmName, String vmUuid, VMSnapshotTO snapsh
3232
this.vmUuid = vmUuid;
3333
}
3434

35+
public CreateVMSnapshotCommand(String vmName, VMSnapshotTO snapshot) {
36+
super(vmName, snapshot, null, null);
37+
}
38+
3539
public String getVmUuid() {
3640
return vmUuid;
3741
}

core/src/main/java/com/cloud/agent/api/DeleteVMSnapshotCommand.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ public class DeleteVMSnapshotCommand extends VMSnapshotBaseCommand {
2727
public DeleteVMSnapshotCommand(String vmName, VMSnapshotTO snapshot, List<VolumeObjectTO> volumeTOs, String guestOSType) {
2828
super(vmName, snapshot, volumeTOs, guestOSType);
2929
}
30+
31+
public DeleteVMSnapshotCommand(String vmName, VMSnapshotTO snapshot) {
32+
super(vmName, snapshot, null, null);
33+
}
3034
}

core/src/main/java/com/cloud/agent/api/MigrateCommand.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class MigrateCommand extends Command {
3030
private String vmName;
3131
private String destIp;
3232
private Map<String, MigrateDiskInfo> migrateStorage;
33+
private boolean migrateStorageManaged;
3334
private boolean autoConvergence;
3435
private String hostGuid;
3536
private boolean isWindows;
@@ -56,6 +57,14 @@ public Map<String, MigrateDiskInfo> getMigrateStorage() {
5657
return migrateStorage != null ? new HashMap<>(migrateStorage) : new HashMap<String, MigrateDiskInfo>();
5758
}
5859

60+
public boolean isMigrateStorageManaged() {
61+
return migrateStorageManaged;
62+
}
63+
64+
public void setMigrateStorageManaged(boolean migrateStorageManaged) {
65+
this.migrateStorageManaged = migrateStorageManaged;
66+
}
67+
5968
public void setAutoConvergence(boolean autoConvergence) {
6069
this.autoConvergence = autoConvergence;
6170
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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.agent.api.storage;
21+
22+
import com.cloud.agent.api.Command;
23+
import com.cloud.storage.Storage;
24+
25+
import java.util.Map;
26+
27+
public class CheckStorageAvailabilityCommand extends Command {
28+
29+
private Map<String, Storage.StoragePoolType> poolsMap;
30+
31+
public CheckStorageAvailabilityCommand(Map<String, Storage.StoragePoolType> poolsMap) {
32+
this.poolsMap = poolsMap;
33+
}
34+
35+
public Map<String, Storage.StoragePoolType> getPoolsMap() {
36+
return poolsMap;
37+
}
38+
39+
@Override
40+
public boolean executeInSequence() {
41+
return false;
42+
}
43+
}

core/src/main/java/org/apache/cloudstack/storage/to/VolumeObjectTO.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.apache.cloudstack.storage.to;
2121

22+
import com.cloud.storage.MigrationOptions;
2223
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
2324

2425
import com.cloud.agent.api.to.DataObjectType;
@@ -59,6 +60,7 @@ public class VolumeObjectTO implements DataTO {
5960
private Long iopsWriteRateMaxLength;
6061
private DiskCacheMode cacheMode;
6162
private Hypervisor.HypervisorType hypervisorType;
63+
private MigrationOptions migrationOptions;
6264

6365
public VolumeObjectTO() {
6466

@@ -97,6 +99,7 @@ public VolumeObjectTO(VolumeInfo volume) {
9799
cacheMode = volume.getCacheMode();
98100
hypervisorType = volume.getHypervisorType();
99101
setDeviceId(volume.getDeviceId());
102+
this.migrationOptions = volume.getMigrationOptions();
100103
}
101104

102105
public String getUuid() {
@@ -300,4 +303,8 @@ public void setCacheMode(DiskCacheMode cacheMode) {
300303
public DiskCacheMode getCacheMode() {
301304
return cacheMode;
302305
}
306+
307+
public MigrationOptions getMigrationOptions() {
308+
return migrationOptions;
309+
}
303310
}

engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/VolumeInfo.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.cloud.agent.api.Answer;
2222
import com.cloud.hypervisor.Hypervisor.HypervisorType;
2323
import com.cloud.offering.DiskOffering.DiskCacheMode;
24+
import com.cloud.storage.MigrationOptions;
2425
import com.cloud.storage.Volume;
2526
import com.cloud.vm.VirtualMachine;
2627

@@ -71,4 +72,11 @@ public interface VolumeInfo extends DataObject, Volume {
7172
Long getIopsWriteRateMaxLength();
7273

7374
DiskCacheMode getCacheMode();
75+
76+
/**
77+
* Currently available for KVM volumes
78+
*/
79+
MigrationOptions getMigrationOptions();
80+
81+
void setMigrationOptions(MigrationOptions migrationOptions);
7482
}

engine/components-api/src/main/java/com/cloud/storage/StorageManager.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,19 @@ public interface StorageManager extends StorageService {
8787
ConfigKey<Integer> KvmStorageOnlineMigrationWait = new ConfigKey<>(Integer.class,
8888
"kvm.storage.online.migration.wait",
8989
"Storage",
90-
"10800",
90+
"86400",
9191
"Timeout in seconds for online (live) storage migration to complete on KVM (migrateVirtualMachineWithVolume)",
9292
true,
9393
ConfigKey.Scope.Global,
9494
null);
95+
ConfigKey<Boolean> KvmAutoConvergence = new ConfigKey<>(Boolean.class,
96+
"kvm.auto.convergence",
97+
"Storage",
98+
"false",
99+
"Setting this to 'true' allows KVM to use auto convergence to complete VM migration (libvirt version 1.2.3+ and QEMU version 1.6+)",
100+
true,
101+
ConfigKey.Scope.Global,
102+
null);
95103
ConfigKey<Integer> MaxNumberOfManagedClusteredFileSystems = new ConfigKey<>(Integer.class,
96104
"max.number.managed.clustered.file.systems",
97105
"Storage",

engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@
120120
import com.cloud.agent.manager.allocator.HostAllocator;
121121
import com.cloud.alert.AlertManager;
122122
import com.cloud.capacity.CapacityManager;
123-
import com.cloud.configuration.Config;
124123
import com.cloud.dc.ClusterDetailsDao;
125124
import com.cloud.dc.ClusterDetailsVO;
126125
import com.cloud.dc.DataCenter;
@@ -2367,11 +2366,8 @@ protected void migrate(final VMInstanceVO vm, final long srcHostId, final Deploy
23672366
final boolean isWindows = _guestOsCategoryDao.findById(_guestOsDao.findById(vm.getGuestOSId()).getCategoryId()).getName().equalsIgnoreCase("Windows");
23682367
final MigrateCommand mc = new MigrateCommand(vm.getInstanceName(), dest.getHost().getPrivateIpAddress(), isWindows, to, getExecuteInSequence(vm.getHypervisorType()));
23692368

2370-
String autoConvergence = _configDao.getValue(Config.KvmAutoConvergence.toString());
2371-
boolean kvmAutoConvergence = Boolean.parseBoolean(autoConvergence);
2372-
2369+
boolean kvmAutoConvergence = StorageManager.KvmAutoConvergence.value();
23732370
mc.setAutoConvergence(kvmAutoConvergence);
2374-
23752371
mc.setHostGuid(dest.getHost().getGuid());
23762372

23772373
try {
@@ -3897,11 +3893,8 @@ private void orchestrateMigrateForScale(final String vmUuid, final long srcHostI
38973893
final boolean isWindows = _guestOsCategoryDao.findById(_guestOsDao.findById(vm.getGuestOSId()).getCategoryId()).getName().equalsIgnoreCase("Windows");
38983894
final MigrateCommand mc = new MigrateCommand(vm.getInstanceName(), dest.getHost().getPrivateIpAddress(), isWindows, to, getExecuteInSequence(vm.getHypervisorType()));
38993895

3900-
String autoConvergence = _configDao.getValue(Config.KvmAutoConvergence.toString());
3901-
boolean kvmAutoConvergence = Boolean.parseBoolean(autoConvergence);
3902-
3896+
boolean kvmAutoConvergence = StorageManager.KvmAutoConvergence.value();
39033897
mc.setAutoConvergence(kvmAutoConvergence);
3904-
39053898
mc.setHostGuid(dest.getHost().getGuid());
39063899

39073900
try {

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

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
import javax.inject.Inject;
2626

27+
import com.cloud.storage.ScopeType;
28+
import com.cloud.storage.Storage;
2729
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
2830
import org.apache.cloudstack.engine.subsystem.api.storage.StrategyPriority;
2931
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateDataFactory;
@@ -54,6 +56,7 @@
5456
import com.cloud.storage.dao.VMTemplatePoolDao;
5557
import com.cloud.utils.exception.CloudRuntimeException;
5658
import com.cloud.vm.VirtualMachineManager;
59+
import org.apache.commons.collections.MapUtils;
5760

5861
/**
5962
* Extends {@link StorageSystemDataMotionStrategy}, allowing KVM hosts to migrate VMs with the ROOT volume on a non managed local storage pool.
@@ -77,21 +80,69 @@ public class KvmNonManagedStorageDataMotionStrategy extends StorageSystemDataMot
7780
* Note that the super implementation (override) is called by {@link #canHandle(Map, Host, Host)} which ensures that {@link #internalCanHandle(Map)} will be executed only if the source host is KVM.
7881
*/
7982
@Override
80-
protected StrategyPriority internalCanHandle(Map<VolumeInfo, DataStore> volumeMap) {
81-
if (super.internalCanHandle(volumeMap) == StrategyPriority.CANT_HANDLE) {
82-
Set<VolumeInfo> volumeInfoSet = volumeMap.keySet();
83+
protected StrategyPriority internalCanHandle(Map<VolumeInfo, DataStore> volumeMap, Host srcHost, Host destHost) {
84+
if (super.internalCanHandle(volumeMap, srcHost, destHost) == StrategyPriority.CANT_HANDLE) {
85+
if (canHandleKVMNonManagedLiveNFSStorageMigration(volumeMap, srcHost, destHost) == StrategyPriority.CANT_HANDLE) {
86+
Set<VolumeInfo> volumeInfoSet = volumeMap.keySet();
8387

84-
for (VolumeInfo volumeInfo : volumeInfoSet) {
85-
StoragePoolVO storagePoolVO = _storagePoolDao.findById(volumeInfo.getPoolId());
86-
if (storagePoolVO.getPoolType() != StoragePoolType.Filesystem && storagePoolVO.getPoolType() != StoragePoolType.NetworkFilesystem) {
87-
return StrategyPriority.CANT_HANDLE;
88+
for (VolumeInfo volumeInfo : volumeInfoSet) {
89+
StoragePoolVO storagePoolVO = _storagePoolDao.findById(volumeInfo.getPoolId());
90+
if (storagePoolVO.getPoolType() != StoragePoolType.Filesystem && storagePoolVO.getPoolType() != StoragePoolType.NetworkFilesystem) {
91+
return StrategyPriority.CANT_HANDLE;
92+
}
8893
}
8994
}
9095
return StrategyPriority.HYPERVISOR;
9196
}
9297
return StrategyPriority.CANT_HANDLE;
9398
}
9499

100+
/**
101+
* Allow KVM live storage migration for non managed storage when:
102+
* - Source host and destination host are different, and are on the same cluster
103+
* - Source and destination storage are NFS
104+
* - Destination storage is cluster-wide
105+
*/
106+
protected StrategyPriority canHandleKVMNonManagedLiveNFSStorageMigration(Map<VolumeInfo, DataStore> volumeMap,
107+
Host srcHost, Host destHost) {
108+
if (srcHost.getId() != destHost.getId() &&
109+
srcHost.getClusterId().equals(destHost.getClusterId()) &&
110+
isSourceNfsPrimaryStorage(volumeMap) &&
111+
isDestinationNfsPrimaryStorageClusterWide(volumeMap)) {
112+
return StrategyPriority.HYPERVISOR;
113+
}
114+
return StrategyPriority.CANT_HANDLE;
115+
}
116+
117+
/**
118+
* True if volumes source storage are NFS
119+
*/
120+
protected boolean isSourceNfsPrimaryStorage(Map<VolumeInfo, DataStore> volumeMap) {
121+
if (MapUtils.isNotEmpty(volumeMap)) {
122+
for (VolumeInfo volumeInfo : volumeMap.keySet()) {
123+
StoragePoolVO storagePoolVO = _storagePoolDao.findById(volumeInfo.getPoolId());
124+
return storagePoolVO != null &&
125+
storagePoolVO.getPoolType() == Storage.StoragePoolType.NetworkFilesystem;
126+
}
127+
}
128+
return false;
129+
}
130+
131+
/**
132+
* True if destination storage is cluster-wide NFS
133+
*/
134+
protected boolean isDestinationNfsPrimaryStorageClusterWide(Map<VolumeInfo, DataStore> volumeMap) {
135+
if (MapUtils.isNotEmpty(volumeMap)) {
136+
for (DataStore dataStore : volumeMap.values()) {
137+
StoragePoolVO storagePoolVO = _storagePoolDao.findById(dataStore.getId());
138+
return storagePoolVO != null &&
139+
storagePoolVO.getPoolType() == Storage.StoragePoolType.NetworkFilesystem &&
140+
storagePoolVO.getScope() == ScopeType.CLUSTER;
141+
}
142+
}
143+
return false;
144+
}
145+
95146
/**
96147
* Configures a {@link MigrateDiskInfo} object configured for migrating a File System volume and calls rootImageProvisioning.
97148
*/
@@ -135,7 +186,7 @@ protected void setVolumePath(VolumeVO volume) {
135186
*/
136187
@Override
137188
protected boolean shouldMigrateVolume(StoragePoolVO sourceStoragePool, Host destHost, StoragePoolVO destStoragePool) {
138-
return sourceStoragePool.getPoolType() == StoragePoolType.Filesystem;
189+
return sourceStoragePool.getPoolType() == StoragePoolType.Filesystem || sourceStoragePool.getPoolType() == StoragePoolType.NetworkFilesystem;
139190
}
140191

141192
/**

0 commit comments

Comments
 (0)