Skip to content

Commit e5bd83e

Browse files
committed
Merge branch '4.19'
2 parents 8925ac7 + 8d819ec commit e5bd83e

File tree

4 files changed

+97
-45
lines changed

4 files changed

+97
-45
lines changed

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

+41-32
Original file line numberDiff line numberDiff line change
@@ -1958,25 +1958,26 @@ protected MigrationOptions createFullCloneMigrationOptions(VolumeInfo srcVolumeI
19581958
* - Full clones (no backing file): Take snapshot of the VM prior disk creation
19591959
* Return this information
19601960
*/
1961-
protected void setVolumeMigrationOptions(VolumeInfo srcVolumeInfo, VolumeInfo destVolumeInfo,
1962-
VirtualMachineTO vmTO, Host srcHost, StoragePoolVO destStoragePool) {
1963-
if (!destStoragePool.isManaged()) {
1964-
String srcVolumeBackingFile = getVolumeBackingFile(srcVolumeInfo);
1965-
1966-
String srcPoolUuid = srcVolumeInfo.getDataStore().getUuid();
1967-
StoragePoolVO srcPool = _storagePoolDao.findById(srcVolumeInfo.getPoolId());
1968-
Storage.StoragePoolType srcPoolType = srcPool.getPoolType();
1969-
1970-
MigrationOptions migrationOptions;
1971-
if (StringUtils.isNotBlank(srcVolumeBackingFile)) {
1972-
migrationOptions = createLinkedCloneMigrationOptions(srcVolumeInfo, destVolumeInfo,
1973-
srcVolumeBackingFile, srcPoolUuid, srcPoolType);
1974-
} else {
1975-
migrationOptions = createFullCloneMigrationOptions(srcVolumeInfo, vmTO, srcHost, srcPoolUuid, srcPoolType);
1976-
}
1977-
migrationOptions.setTimeout(StorageManager.KvmStorageOnlineMigrationWait.value());
1978-
destVolumeInfo.setMigrationOptions(migrationOptions);
1961+
protected void setVolumeMigrationOptions(VolumeInfo srcVolumeInfo, VolumeInfo destVolumeInfo, VirtualMachineTO vmTO, Host srcHost, StoragePoolVO destStoragePool,
1962+
MigrationOptions.Type migrationType) {
1963+
if (destStoragePool.isManaged()) {
1964+
return;
1965+
}
1966+
1967+
String srcVolumeBackingFile = getVolumeBackingFile(srcVolumeInfo);
1968+
1969+
String srcPoolUuid = srcVolumeInfo.getDataStore().getUuid();
1970+
StoragePoolVO srcPool = _storagePoolDao.findById(srcVolumeInfo.getPoolId());
1971+
Storage.StoragePoolType srcPoolType = srcPool.getPoolType();
1972+
1973+
MigrationOptions migrationOptions;
1974+
if (MigrationOptions.Type.LinkedClone.equals(migrationType)) {
1975+
migrationOptions = createLinkedCloneMigrationOptions(srcVolumeInfo, destVolumeInfo, srcVolumeBackingFile, srcPoolUuid, srcPoolType);
1976+
} else {
1977+
migrationOptions = createFullCloneMigrationOptions(srcVolumeInfo, vmTO, srcHost, srcPoolUuid, srcPoolType);
19791978
}
1979+
migrationOptions.setTimeout(StorageManager.KvmStorageOnlineMigrationWait.value());
1980+
destVolumeInfo.setMigrationOptions(migrationOptions);
19801981
}
19811982

19821983
/**
@@ -2007,6 +2008,7 @@ public void copyAsync(Map<VolumeInfo, DataStore> volumeDataStoreMap, VirtualMach
20072008
Map<VolumeInfo, VolumeInfo> srcVolumeInfoToDestVolumeInfo = new HashMap<>();
20082009

20092010
boolean managedStorageDestination = false;
2011+
boolean migrateNonSharedInc = false;
20102012
for (Map.Entry<VolumeInfo, DataStore> entry : volumeDataStoreMap.entrySet()) {
20112013
VolumeInfo srcVolumeInfo = entry.getKey();
20122014
DataStore destDataStore = entry.getValue();
@@ -2024,15 +2026,8 @@ public void copyAsync(Map<VolumeInfo, DataStore> volumeDataStoreMap, VirtualMach
20242026
continue;
20252027
}
20262028

2027-
VMTemplateVO vmTemplate = _vmTemplateDao.findById(vmInstance.getTemplateId());
2028-
if (srcVolumeInfo.getTemplateId() != null &&
2029-
Objects.nonNull(vmTemplate) &&
2030-
!Arrays.asList(KVM_VM_IMPORT_DEFAULT_TEMPLATE_NAME, VM_IMPORT_DEFAULT_TEMPLATE_NAME).contains(vmTemplate.getName())) {
2031-
logger.debug(String.format("Copying template [%s] of volume [%s] from source storage pool [%s] to target storage pool [%s].", srcVolumeInfo.getTemplateId(), srcVolumeInfo.getId(), sourceStoragePool.getId(), destStoragePool.getId()));
2032-
copyTemplateToTargetFilesystemStorageIfNeeded(srcVolumeInfo, sourceStoragePool, destDataStore, destStoragePool, destHost);
2033-
} else {
2034-
logger.debug(String.format("Skipping copy template from source storage pool [%s] to target storage pool [%s] before migration due to volume [%s] does not have a template.", sourceStoragePool.getId(), destStoragePool.getId(), srcVolumeInfo.getId()));
2035-
}
2029+
MigrationOptions.Type migrationType = decideMigrationTypeAndCopyTemplateIfNeeded(destHost, vmInstance, srcVolumeInfo, sourceStoragePool, destStoragePool, destDataStore);
2030+
migrateNonSharedInc = migrateNonSharedInc || MigrationOptions.Type.LinkedClone.equals(migrationType);
20362031

20372032
VolumeVO destVolume = duplicateVolumeOnAnotherStorage(srcVolume, destStoragePool);
20382033
VolumeInfo destVolumeInfo = _volumeDataFactory.getVolume(destVolume.getId(), destDataStore);
@@ -2044,7 +2039,7 @@ public void copyAsync(Map<VolumeInfo, DataStore> volumeDataStoreMap, VirtualMach
20442039
// move the volume from Ready to Migrating
20452040
destVolumeInfo.processEvent(Event.MigrationRequested);
20462041

2047-
setVolumeMigrationOptions(srcVolumeInfo, destVolumeInfo, vmTO, srcHost, destStoragePool);
2042+
setVolumeMigrationOptions(srcVolumeInfo, destVolumeInfo, vmTO, srcHost, destStoragePool, migrationType);
20482043

20492044
// create a volume on the destination storage
20502045
destDataStore.getDriver().createAsync(destDataStore, destVolumeInfo, null);
@@ -2059,7 +2054,7 @@ public void copyAsync(Map<VolumeInfo, DataStore> volumeDataStoreMap, VirtualMach
20592054

20602055
_volumeDao.update(destVolume.getId(), destVolume);
20612056

2062-
postVolumeCreationActions(srcVolumeInfo, destVolumeInfo, vmTO, srcHost);
2057+
postVolumeCreationActions(srcVolumeInfo, destVolumeInfo);
20632058

20642059
destVolumeInfo = _volumeDataFactory.getVolume(destVolume.getId(), destDataStore);
20652060

@@ -2110,8 +2105,6 @@ public void copyAsync(Map<VolumeInfo, DataStore> volumeDataStoreMap, VirtualMach
21102105
VMInstanceVO vm = _vmDao.findById(vmTO.getId());
21112106
boolean isWindows = _guestOsCategoryDao.findById(_guestOsDao.findById(vm.getGuestOSId()).getCategoryId()).getName().equalsIgnoreCase("Windows");
21122107

2113-
boolean migrateNonSharedInc = isSourceAndDestinationPoolTypeOfNfs(volumeDataStoreMap);
2114-
21152108
MigrateCommand migrateCommand = new MigrateCommand(vmTO.getName(), destHost.getPrivateIpAddress(), isWindows, vmTO, true);
21162109
migrateCommand.setWait(StorageManager.KvmStorageOnlineMigrationWait.value());
21172110
migrateCommand.setMigrateStorage(migrateStorage);
@@ -2161,6 +2154,22 @@ public void copyAsync(Map<VolumeInfo, DataStore> volumeDataStoreMap, VirtualMach
21612154
}
21622155
}
21632156

2157+
private MigrationOptions.Type decideMigrationTypeAndCopyTemplateIfNeeded(Host destHost, VMInstanceVO vmInstance, VolumeInfo srcVolumeInfo, StoragePoolVO sourceStoragePool, StoragePoolVO destStoragePool, DataStore destDataStore) {
2158+
VMTemplateVO vmTemplate = _vmTemplateDao.findById(vmInstance.getTemplateId());
2159+
String srcVolumeBackingFile = getVolumeBackingFile(srcVolumeInfo);
2160+
if (StringUtils.isNotBlank(srcVolumeBackingFile) && supportStoragePoolType(destStoragePool.getPoolType(), StoragePoolType.Filesystem) &&
2161+
srcVolumeInfo.getTemplateId() != null &&
2162+
Objects.nonNull(vmTemplate) &&
2163+
!Arrays.asList(KVM_VM_IMPORT_DEFAULT_TEMPLATE_NAME, VM_IMPORT_DEFAULT_TEMPLATE_NAME).contains(vmTemplate.getName())) {
2164+
logger.debug(String.format("Copying template [%s] of volume [%s] from source storage pool [%s] to target storage pool [%s].", srcVolumeInfo.getTemplateId(), srcVolumeInfo.getId(), sourceStoragePool.getId(), destStoragePool.getId()));
2165+
copyTemplateToTargetFilesystemStorageIfNeeded(srcVolumeInfo, sourceStoragePool, destDataStore, destStoragePool, destHost);
2166+
return MigrationOptions.Type.LinkedClone;
2167+
}
2168+
logger.debug(String.format("Skipping copy template from source storage pool [%s] to target storage pool [%s] before migration due to volume [%s] does not have a " +
2169+
"template or we are doing full clone migration.", sourceStoragePool.getId(), destStoragePool.getId(), srcVolumeInfo.getId()));
2170+
return MigrationOptions.Type.FullClone;
2171+
}
2172+
21642173
protected String formatMigrationElementsAsJsonToDisplayOnLog(String objectName, Object object, Object from, Object to){
21652174
return String.format("{%s: \"%s\", from: \"%s\", to:\"%s\"}", objectName, object, from, to);
21662175
}
@@ -2422,7 +2431,7 @@ protected void updateCopiedTemplateReference(VolumeInfo srcVolumeInfo, VolumeInf
24222431
/**
24232432
* Handle post destination volume creation actions depending on the migrating volume type: full clone or linked clone
24242433
*/
2425-
protected void postVolumeCreationActions(VolumeInfo srcVolumeInfo, VolumeInfo destVolumeInfo, VirtualMachineTO vmTO, Host srcHost) {
2434+
protected void postVolumeCreationActions(VolumeInfo srcVolumeInfo, VolumeInfo destVolumeInfo) {
24262435
MigrationOptions migrationOptions = destVolumeInfo.getMigrationOptions();
24272436
if (migrationOptions != null) {
24282437
if (migrationOptions.getType() == MigrationOptions.Type.LinkedClone && migrationOptions.isCopySrcTemplate()) {

framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java

+29-12
Original file line numberDiff line numberDiff line change
@@ -1400,22 +1400,39 @@ protected List<Attribute> addJoins(StringBuilder str, Collection<JoinBuilder<Sea
14001400
onClause.append("?");
14011401
joinAttrList.add(join.getFirstAttributes()[i]);
14021402
} else {
1403-
onClause.append(joinedTableNames.getOrDefault(join.getFirstAttributes()[i].table, join.getFirstAttributes()[i].table))
1404-
.append(".")
1405-
.append(join.getFirstAttributes()[i].columnName);
1403+
if ((join.getFirstAttributes()[i].table == null && join.getFirstAttributes()[i].value == null) ||
1404+
(join.getSecondAttribute()[i].table == null && join.getSecondAttribute()[i].value == null)) {
1405+
onClause.append(joinedTableNames.getOrDefault(join.getSecondAttribute()[i].table, join.getFirstAttributes()[i].table))
1406+
.append(".");
1407+
if (join.getFirstAttributes()[i].table == null && join.getFirstAttributes()[i].value == null) {
1408+
onClause.append(join.getSecondAttribute()[i].columnName);
1409+
} else {
1410+
onClause.append(join.getFirstAttributes()[i].columnName);
1411+
}
1412+
1413+
} else {
1414+
onClause.append(joinedTableNames.getOrDefault(join.getFirstAttributes()[i].table, join.getFirstAttributes()[i].table))
1415+
.append(".")
1416+
.append(join.getFirstAttributes()[i].columnName);
1417+
}
14061418
}
1407-
onClause.append("=");
1408-
if (join.getSecondAttribute()[i].getValue() != null) {
1409-
onClause.append("?");
1410-
joinAttrList.add(join.getSecondAttribute()[i]);
1419+
if ((join.getFirstAttributes()[i].table == null && join.getFirstAttributes()[i].value == null) ||
1420+
(join.getSecondAttribute()[i].table == null && join.getSecondAttribute()[i].value == null)) {
1421+
onClause.append(" IS NULL");
14111422
} else {
1412-
if(!joinTableAlias.equals(joinTableName)) {
1413-
onClause.append(joinTableAlias);
1423+
onClause.append("=");
1424+
if (join.getSecondAttribute()[i].getValue() != null) {
1425+
onClause.append("?");
1426+
joinAttrList.add(join.getSecondAttribute()[i]);
14141427
} else {
1415-
onClause.append(joinTableName);
1428+
if (!joinTableAlias.equals(joinTableName)) {
1429+
onClause.append(joinTableAlias);
1430+
} else {
1431+
onClause.append(joinTableName);
1432+
}
1433+
onClause.append(".")
1434+
.append(join.getSecondAttribute()[i].columnName);
14161435
}
1417-
onClause.append(".")
1418-
.append(join.getSecondAttribute()[i].columnName);
14191436
}
14201437
}
14211438
onClause.append(" ");

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

+2
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,10 @@ public Domain call() throws LibvirtException {
123123
if (migrateNonSharedInc) {
124124
flags |= VIR_MIGRATE_PERSIST_DEST;
125125
flags |= VIR_MIGRATE_NON_SHARED_INC;
126+
logger.debug("Setting VIR_MIGRATE_NON_SHARED_INC for linked clone migration.");
126127
} else {
127128
flags |= VIR_MIGRATE_NON_SHARED_DISK;
129+
logger.debug("Setting VIR_MIGRATE_NON_SHARED_DISK for full clone migration.");
128130
}
129131
}
130132

server/src/main/java/com/cloud/api/query/QueryManagerImpl.java

+25-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
import javax.inject.Inject;
3838

39-
import com.cloud.cpu.CPU;
4039
import org.apache.cloudstack.acl.ControlledEntity;
4140
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
4241
import org.apache.cloudstack.acl.SecurityChecker;
@@ -216,6 +215,7 @@
216215
import com.cloud.api.query.vo.VolumeJoinVO;
217216
import com.cloud.cluster.ManagementServerHostVO;
218217
import com.cloud.cluster.dao.ManagementServerHostDao;
218+
import com.cloud.cpu.CPU;
219219
import com.cloud.dc.ClusterVO;
220220
import com.cloud.dc.DataCenter;
221221
import com.cloud.dc.DedicatedResourceVO;
@@ -245,6 +245,8 @@
245245
import com.cloud.network.as.AutoScaleVmGroupVmMapVO;
246246
import com.cloud.network.as.dao.AutoScaleVmGroupDao;
247247
import com.cloud.network.as.dao.AutoScaleVmGroupVmMapDao;
248+
import com.cloud.network.dao.IPAddressDao;
249+
import com.cloud.network.dao.IPAddressVO;
248250
import com.cloud.network.dao.NetworkDao;
249251
import com.cloud.network.dao.NetworkVO;
250252
import com.cloud.network.dao.PublicIpQuarantineDao;
@@ -551,6 +553,9 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
551553
@Inject
552554
private NetworkDao networkDao;
553555

556+
@Inject
557+
private IPAddressDao ipAddressDao;
558+
554559
@Inject
555560
private NicDao nicDao;
556561

@@ -1461,6 +1466,22 @@ private Pair<List<Long>, Integer> searchForUserVMIdsAndCount(ListVMsCmd cmd) {
14611466
if (isRootAdmin) {
14621467
userVmSearchBuilder.or("keywordInstanceName", userVmSearchBuilder.entity().getInstanceName(), Op.LIKE );
14631468
}
1469+
1470+
SearchBuilder<IPAddressVO> ipAddressSearch = ipAddressDao.createSearchBuilder();
1471+
userVmSearchBuilder.join("ipAddressSearch", ipAddressSearch,
1472+
ipAddressSearch.entity().getAssociatedWithVmId(), userVmSearchBuilder.entity().getId(), JoinBuilder.JoinType.LEFT);
1473+
1474+
SearchBuilder<NicVO> nicSearch = nicDao.createSearchBuilder();
1475+
userVmSearchBuilder.join("nicSearch", nicSearch, JoinBuilder.JoinType.LEFT,
1476+
JoinBuilder.JoinCondition.AND,
1477+
nicSearch.entity().getInstanceId(), userVmSearchBuilder.entity().getId(),
1478+
nicSearch.entity().getRemoved(), userVmSearchBuilder.entity().setLong(null));
1479+
1480+
userVmSearchBuilder.or("ipAddressSearch", "keywordPublicIpAddress", ipAddressSearch.entity().getAddress(), Op.LIKE);
1481+
1482+
userVmSearchBuilder.or("nicSearch", "keywordIpAddress", nicSearch.entity().getIPv4Address(), Op.LIKE);
1483+
userVmSearchBuilder.or("nicSearch", "keywordIp6Address", nicSearch.entity().getIPv6Address(), Op.LIKE);
1484+
14641485
userVmSearchBuilder.cp();
14651486
}
14661487

@@ -1554,6 +1575,9 @@ private Pair<List<Long>, Integer> searchForUserVMIdsAndCount(ListVMsCmd cmd) {
15541575
userVmSearchCriteria.setParameters("keywordDisplayName", keywordMatch);
15551576
userVmSearchCriteria.setParameters("keywordName", keywordMatch);
15561577
userVmSearchCriteria.setParameters("keywordState", keyword);
1578+
userVmSearchCriteria.setParameters("keywordIpAddress", keywordMatch);
1579+
userVmSearchCriteria.setParameters("keywordPublicIpAddress", keywordMatch);
1580+
userVmSearchCriteria.setParameters("keywordIp6Address", keywordMatch);
15571581
if (isRootAdmin) {
15581582
userVmSearchCriteria.setParameters("keywordInstanceName", keywordMatch);
15591583
}

0 commit comments

Comments
 (0)