Skip to content

Commit 944b603

Browse files
committed
Merge remote-tracking branch 'apache/4.16'
2 parents 9162a9b + a69ab3b commit 944b603

File tree

4 files changed

+51
-34
lines changed

4 files changed

+51
-34
lines changed

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2756,25 +2756,25 @@ public String getVolumePath(final Connect conn, final DiskTO volume) throws Libv
27562756
public String getVolumePath(final Connect conn, final DiskTO volume, boolean diskOnHostCache) throws LibvirtException, URISyntaxException {
27572757
final DataTO data = volume.getData();
27582758
final DataStoreTO store = data.getDataStore();
2759+
final String dataPath = data.getPath();
27592760

2760-
if (volume.getType() == Volume.Type.ISO && data.getPath() != null && (store instanceof NfsTO ||
2761-
store instanceof PrimaryDataStoreTO && data instanceof TemplateObjectTO && !((TemplateObjectTO) data).isDirectDownload())) {
2762-
2763-
if (data.getPath().startsWith(ConfigDrive.CONFIGDRIVEDIR) && diskOnHostCache) {
2764-
String configDrivePath = getConfigPath() + "/" + data.getPath();
2765-
return configDrivePath;
2761+
if (volume.getType() == Volume.Type.ISO && dataPath != null) {
2762+
if (dataPath.startsWith(ConfigDrive.CONFIGDRIVEDIR) && diskOnHostCache) {
2763+
return getConfigPath() + "/" + data.getPath();
27662764
}
27672765

2768-
final String isoPath = store.getUrl().split("\\?")[0] + File.separator + data.getPath();
2769-
final int index = isoPath.lastIndexOf("/");
2770-
final String path = isoPath.substring(0, index);
2771-
final String name = isoPath.substring(index + 1);
2772-
final KVMStoragePool secondaryPool = _storagePoolMgr.getStoragePoolByURI(path);
2773-
final KVMPhysicalDisk isoVol = secondaryPool.getPhysicalDisk(name);
2774-
return isoVol.getPath();
2775-
} else {
2776-
return data.getPath();
2766+
if (store instanceof NfsTO || store instanceof PrimaryDataStoreTO && data instanceof TemplateObjectTO && !((TemplateObjectTO) data).isDirectDownload()) {
2767+
final String isoPath = store.getUrl().split("\\?")[0] + File.separator + dataPath;
2768+
final int index = isoPath.lastIndexOf("/");
2769+
final String path = isoPath.substring(0, index);
2770+
final String name = isoPath.substring(index + 1);
2771+
final KVMStoragePool secondaryPool = _storagePoolMgr.getStoragePoolByURI(path);
2772+
final KVMPhysicalDisk isoVol = secondaryPool.getPhysicalDisk(name);
2773+
return isoVol.getPath();
2774+
}
27772775
}
2776+
2777+
return dataPath;
27782778
}
27792779

27802780
public void createVbd(final Connect conn, final VirtualMachineTO vmSpec, final String vmName, final LibvirtVMDef vm) throws InternalErrorException, LibvirtException, URISyntaxException {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0.
153153
String oldIsoVolumePath = getOldVolumePath(disks, vmName);
154154
String newIsoVolumePath = getNewVolumePathIfDatastoreHasChanged(libvirtComputingResource, conn, to);
155155
if (newIsoVolumePath != null && !newIsoVolumePath.equals(oldIsoVolumePath)) {
156-
s_logger.debug("Editing mount path");
156+
s_logger.debug(String.format("Editing mount path of iso from %s to %s", oldIsoVolumePath, newIsoVolumePath));
157157
xmlDesc = replaceDiskSourceFile(xmlDesc, newIsoVolumePath, vmName);
158158
}
159159
// delete the metadata of vm snapshots before migration
@@ -568,7 +568,7 @@ private String getNewVolumePathIfDatastoreHasChanged(LibvirtComputingResource li
568568

569569
String newIsoVolumePath = null;
570570
if (newDisk != null) {
571-
newIsoVolumePath = libvirtComputingResource.getVolumePath(conn, newDisk);
571+
newIsoVolumePath = libvirtComputingResource.getVolumePath(conn, newDisk, to.isConfigDriveOnHostCache());
572572
}
573573
return newIsoVolumePath;
574574
}

server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -927,15 +927,26 @@ public Pair<Configuration, String> resetConfiguration(final ResetCfgCmd cmd) thr
927927
final Long accountId = cmd.getAccountId();
928928
final Long domainId = cmd.getDomainId();
929929
final Long imageStoreId = cmd.getImageStoreId();
930+
ConfigKey<?> configKey = null;
930931
Optional optionalValue;
931-
final ConfigKey<?> configKey = _configDepot.get(name);
932-
if (configKey == null) {
933-
s_logger.warn("Probably the component manager where configuration variable " + name + " is defined needs to implement Configurable interface");
934-
throw new InvalidParameterValueException("Config parameter with name " + name + " doesn't exist");
932+
String defaultValue;
933+
String category;
934+
String configScope;
935+
final ConfigurationVO config = _configDao.findByName(name);
936+
if (config == null) {
937+
configKey = _configDepot.get(name);
938+
if (configKey == null) {
939+
s_logger.warn("Probably the component manager where configuration variable " + name + " is defined needs to implement Configurable interface");
940+
throw new InvalidParameterValueException("Config parameter with name " + name + " doesn't exist");
941+
}
942+
defaultValue = configKey.defaultValue();
943+
category = configKey.category();
944+
configScope = configKey.scope().toString();
945+
} else {
946+
defaultValue = config.getDefaultValue();
947+
category = config.getCategory();
948+
configScope = config.getScope();
935949
}
936-
String defaultValue = configKey.defaultValue();
937-
String category = configKey.category();
938-
String configScope = configKey.scope().toString();
939950

940951
String scope = "";
941952
Map<String, Long> scopeMap = new LinkedHashMap<>();
@@ -971,7 +982,7 @@ public Pair<Configuration, String> resetConfiguration(final ResetCfgCmd cmd) thr
971982
throw new InvalidParameterValueException("unable to find zone by id " + id);
972983
}
973984
_dcDetailsDao.removeDetail(id, name);
974-
optionalValue = Optional.ofNullable(configKey.valueIn(id));
985+
optionalValue = Optional.ofNullable(configKey != null ? configKey.valueIn(id): config.getValue());
975986
newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue;
976987
break;
977988

@@ -981,13 +992,13 @@ public Pair<Configuration, String> resetConfiguration(final ResetCfgCmd cmd) thr
981992
throw new InvalidParameterValueException("unable to find cluster by id " + id);
982993
}
983994
ClusterDetailsVO clusterDetailsVO = _clusterDetailsDao.findDetail(id, name);
984-
newValue = configKey.value().toString();
995+
newValue = configKey != null ? configKey.value().toString() : config.getValue();
985996
if (name.equalsIgnoreCase("cpu.overprovisioning.factor") || name.equalsIgnoreCase("mem.overprovisioning.factor")) {
986997
_clusterDetailsDao.persist(id, name, newValue);
987998
} else if (clusterDetailsVO != null) {
988999
_clusterDetailsDao.remove(clusterDetailsVO.getId());
9891000
}
990-
optionalValue = Optional.ofNullable(configKey.valueIn(id));
1001+
optionalValue = Optional.ofNullable(configKey != null ? configKey.valueIn(id): config.getValue());
9911002
newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue;
9921003
break;
9931004

@@ -997,7 +1008,7 @@ public Pair<Configuration, String> resetConfiguration(final ResetCfgCmd cmd) thr
9971008
throw new InvalidParameterValueException("unable to find storage pool by id " + id);
9981009
}
9991010
_storagePoolDetailsDao.removeDetail(id, name);
1000-
optionalValue = Optional.ofNullable(configKey.valueIn(id));
1011+
optionalValue = Optional.ofNullable(configKey != null ? configKey.valueIn(id) : config.getValue());
10011012
newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue;
10021013
break;
10031014

@@ -1010,7 +1021,7 @@ public Pair<Configuration, String> resetConfiguration(final ResetCfgCmd cmd) thr
10101021
if (domainDetailVO != null) {
10111022
_domainDetailsDao.remove(domainDetailVO.getId());
10121023
}
1013-
optionalValue = Optional.ofNullable(configKey.valueIn(id));
1024+
optionalValue = Optional.ofNullable(configKey != null ? configKey.valueIn(id) : config.getValue());
10141025
newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue;
10151026
break;
10161027

@@ -1023,7 +1034,7 @@ public Pair<Configuration, String> resetConfiguration(final ResetCfgCmd cmd) thr
10231034
if (accountDetailVO != null) {
10241035
_accountDetailsDao.remove(accountDetailVO.getId());
10251036
}
1026-
optionalValue = Optional.ofNullable(configKey.valueIn(id));
1037+
optionalValue = Optional.ofNullable(configKey != null ? configKey.valueIn(id) : config.getValue());
10271038
newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue;
10281039
break;
10291040

@@ -1036,7 +1047,7 @@ public Pair<Configuration, String> resetConfiguration(final ResetCfgCmd cmd) thr
10361047
if (imageStoreDetailVO != null) {
10371048
_imageStoreDetailsDao.remove(imageStoreDetailVO.getId());
10381049
}
1039-
optionalValue = Optional.ofNullable(configKey.valueIn(id));
1050+
optionalValue = Optional.ofNullable(configKey != null ? configKey.valueIn(id) : config.getValue());
10401051
newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue;
10411052
break;
10421053

@@ -1045,7 +1056,7 @@ public Pair<Configuration, String> resetConfiguration(final ResetCfgCmd cmd) thr
10451056
s_logger.error("Failed to reset configuration option, name: " + name + ", defaultValue:" + defaultValue);
10461057
throw new CloudRuntimeException("Failed to reset configuration value. Please contact Cloud Support.");
10471058
}
1048-
optionalValue = Optional.ofNullable(configKey.value());
1059+
optionalValue = Optional.ofNullable(configKey != null ? configKey.value() : config.getValue());
10491060
newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue;
10501061
}
10511062

server/src/main/java/com/cloud/network/element/ConfigDriveNetworkElement.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ private Long findAgentId(VirtualMachineProfile profile, DeployDestination dest,
497497
agentId = dest.getHost().getId();
498498
}
499499
if (!VirtualMachineManager.VmConfigDriveOnPrimaryPool.valueIn(dest.getDataCenter().getId()) &&
500-
!VirtualMachineManager.VmConfigDriveForceHostCacheUse.valueIn(dest.getDataCenter().getId())) {
500+
!VirtualMachineManager.VmConfigDriveForceHostCacheUse.valueIn(dest.getDataCenter().getId()) && dataStore != null) {
501501
agentId = findAgentIdForImageStore(dataStore);
502502
}
503503
return agentId;
@@ -630,6 +630,10 @@ private DataStore getDatastoreForConfigDriveIso(DiskTO disk, VirtualMachineProfi
630630
private boolean deleteConfigDriveIso(final VirtualMachine vm) throws ResourceUnavailableException {
631631
Long hostId = (vm.getHostId() != null) ? vm.getHostId() : vm.getLastHostId();
632632
Location location = getConfigDriveLocation(vm.getId());
633+
if (hostId == null) {
634+
LOG.info(String.format("The VM was never booted; no config-drive ISO created for VM %s", vm.getName()));
635+
return true;
636+
}
633637
if (location == Location.HOST) {
634638
return deleteConfigDriveIsoOnHostCache(vm, hostId);
635639
}
@@ -639,7 +643,9 @@ private boolean deleteConfigDriveIso(final VirtualMachine vm) throws ResourceUna
639643

640644
if (location == Location.SECONDARY) {
641645
dataStore = _dataStoreMgr.getImageStoreWithFreeCapacity(vm.getDataCenterId());
642-
agentId = findAgentIdForImageStore(dataStore);
646+
if (dataStore != null) {
647+
agentId = findAgentIdForImageStore(dataStore);
648+
}
643649
} else if (location == Location.PRIMARY) {
644650
List<VolumeVO> volumes = _volumeDao.findByInstanceAndType(vm.getId(), Volume.Type.ROOT);
645651
if (volumes != null && volumes.size() > 0) {

0 commit comments

Comments
 (0)