Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change save/restore nvram data logic #887

Merged
merged 7 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.ovirt.engine.core.common.action.ExternalDataStatus;
import org.ovirt.engine.core.common.action.SaveVmExternalDataParameters;
import org.ovirt.engine.core.common.action.VmExternalDataKind;
import org.ovirt.engine.core.common.businessentities.BiosType;
import org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType;
import org.ovirt.engine.core.common.errors.EngineError;
import org.ovirt.engine.core.common.errors.EngineException;
Expand Down Expand Up @@ -47,8 +46,8 @@ private boolean hasTpmDevice() {
return !vmDeviceDao.getVmDeviceByVmIdAndType(getParameters().getVmId(), VmDeviceGeneralType.TPM).isEmpty();
}

private boolean hasSecureBoot() {
return getVm().getBiosType() == BiosType.Q35_SECURE_BOOT
private boolean isUefi() {
return getVm().getBiosType().isOvmf()
&& FeatureSupported.isNvramPersistenceSupported(getVm().getCompatibilityVersion());
}

Expand Down Expand Up @@ -80,7 +79,7 @@ protected void executeCommand() {
if (hasTpmDevice()) {
dataToRetrieve.add(VmExternalDataKind.TPM);
}
if (hasSecureBoot()) {
if (isUefi()) {
dataToRetrieve.add(VmExternalDataKind.NVRAM);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.ovirt.engine.core.bll.utils.VmDeviceUtils;
import org.ovirt.engine.core.common.AuditLogType;
import org.ovirt.engine.core.common.action.VmExternalDataKind;
import org.ovirt.engine.core.common.businessentities.BiosType;
import org.ovirt.engine.core.common.businessentities.Cluster;
import org.ovirt.engine.core.common.businessentities.Quota;
import org.ovirt.engine.core.common.businessentities.Snapshot;
Expand Down Expand Up @@ -352,7 +351,7 @@ private void addVmExternalData(Map<VmExternalDataKind, SecretValue<String>> vmEx
vmExternalData.put(VmExternalDataKind.TPM, tpmData);
}
}
if (vm.getBiosType() == BiosType.Q35_SECURE_BOOT) {
if (vm.getBiosType().isOvmf()) {
SecretValue<String> nvramData = vmDao.getNvramData(vm.getId()).getFirst();
if (!SecretValue.isNull(nvramData) && !nvramData.getValue().equals("")) {
vmExternalData.put(VmExternalDataKind.NVRAM, nvramData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.ovirt.engine.core.common.action.VmExternalDataKind;
import org.ovirt.engine.core.common.action.VmManagementParametersBase;
import org.ovirt.engine.core.common.businessentities.ArchitectureType;
import org.ovirt.engine.core.common.businessentities.BiosType;
import org.ovirt.engine.core.common.businessentities.ChipsetType;
import org.ovirt.engine.core.common.businessentities.Cluster;
import org.ovirt.engine.core.common.businessentities.ConsoleTargetType;
Expand Down Expand Up @@ -2287,7 +2286,7 @@ public void copyVmExternalData(Guid sourceVmId, Guid targetVmId) {
if (hasTpmDevice(targetVmId)) {
vmDao.copyTpmData(sourceVmId, targetVmId);
}
if (getVmBase(targetVmId).getBiosType() == BiosType.Q35_SECURE_BOOT) {
if (getVmBase(targetVmId).getBiosType().isOvmf()) {
vmDao.copyNvramData(sourceVmId, targetVmId);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import javax.inject.Inject;

import org.ovirt.engine.core.common.businessentities.BiosType;
import org.ovirt.engine.core.common.businessentities.VM;
import org.ovirt.engine.core.common.businessentities.VmDevice;
import org.ovirt.engine.core.common.businessentities.storage.DiskImage;
Expand Down Expand Up @@ -78,7 +77,7 @@ private Map<String, Object> createInfo() {
if (!SecretValue.isNull(tpmData)) {
createInfo.put(VdsProperties.tpmData, tpmData.getValue());
}
if (vm.getBiosType() == BiosType.Q35_SECURE_BOOT) {
if (vm.getBiosType().isOvmf()) {
SecretValue<String> nvramData = vmInfoBuildUtils.nvramData(vm.getId());
if (!SecretValue.isNull(nvramData)) {
createInfo.put(VdsProperties.nvramData, nvramData.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.ovirt.engine.core.common.action.VmInterfacesModifyParameters;
import org.ovirt.engine.core.common.action.VmManagementParametersBase;
import org.ovirt.engine.core.common.action.VmOperationParameterBase;
import org.ovirt.engine.core.common.businessentities.BiosType;
import org.ovirt.engine.core.common.businessentities.DisplayType;
import org.ovirt.engine.core.common.businessentities.MigrationSupport;
import org.ovirt.engine.core.common.businessentities.OriginType;
Expand Down Expand Up @@ -787,6 +788,28 @@ private void edit() {

}

private void confirmBiosTypeUpdate(){
VM vm = getSelectedItem();
UnitVmModel model = (UnitVmModel) getWindow();
if (vm == null || model.getIsNew()) {
preSave();
} else {
BiosType newBiosType = model.getBiosType().getSelectedItem();
BiosType oldBiosType = vm.getBiosType();
if (oldBiosType.equals(BiosType.Q35_SECURE_BOOT) && !newBiosType.equals(BiosType.Q35_SECURE_BOOT) ||
oldBiosType.equals(BiosType.Q35_OVMF) && newBiosType.getValue() < BiosType.Q35_OVMF.getValue()) {
smelamud marked this conversation as resolved.
Show resolved Hide resolved
ConfirmationModel confirmModel = new ConfirmationModel();
confirmModel.setTitle(ConstantsManager.getInstance().getConstants().confirmBiosUpdateTitle());
confirmModel.setMessage(ConstantsManager.getInstance().getConstants().confirmBiosUpdateMessage());
confirmModel.getCommands().add(UICommand.createDefaultOkUiCommand("PreSave", VmListModel.this)); //$NON-NLS-1$
confirmModel.getCommands().add(UICommand.createCancelUiCommand("Cancel", VmListModel.this)); //$NON-NLS-1$
setConfirmWindow(confirmModel);
} else {
preSave();
}
}
}

private void vmInitLoaded(VM vm) {
UnitVmModel model = new UnitVmModel(new ExistingVmModelBehavior(vm), this);
model.setVmAttachedToPool(vm.getVmPoolId() != null);
Expand Down Expand Up @@ -2128,6 +2151,8 @@ public void executeCommand(UICommand command) {
} else if ("Cancel".equals(command.getName())) { //$NON-NLS-1$
cancel();
} else if ("OnSave".equals(command.getName())) { //$NON-NLS-1$
confirmBiosTypeUpdate();
} else if ("PreSave".equals(command.getName())) { //$NON-NLS-1$
preSave();
} else if ("OnRemove".equals(command.getName())) { //$NON-NLS-1$
onRemove();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2258,4 +2258,8 @@ public interface UIConstants extends Constants {
String homePageCustom();

String statelessVmFieldDisabledReason();

String confirmBiosUpdateTitle();

String confirmBiosUpdateMessage();
}
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,8 @@ vmRoleTree=VM
vmUnknownPriority=Unknown
vmUnsupportedCpuMessage=The selected CPU type is not supported by the VM cluster, this may cause scheduling limitations and prevent this vm from running on certain hosts. Are you sure you want to proceed?
vmUnsupportedCpuTitle=Unsupported CPU type for current cluster
confirmBiosUpdateTitle=Update BIOS type
confirmBiosUpdateMessage=Updating BIOS type, the current NVRAM data will be irrecoverably deleted. Are you sure you want to proceed?
vmCpuPinningClearMessage=The current configuration of the VM does not allow cpu pinning.\nThe pinning topology will be lost when the VM is saved.\n\nAre you sure you want to continue?
vmCpuPinningClearTitle=CPU pinning topology will be lost
vmsAttachedToInstanceTypeNote=There are VMs attached to this instance type-this will make them attached to 'Custom'
Expand Down
2 changes: 1 addition & 1 deletion packaging/dbscripts/vms_sp.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2503,7 +2503,7 @@ IF EXISTS remove_nvram_data_on_update
CREATE OR REPLACE FUNCTION remove_nvram_data ()
RETURNS TRIGGER AS $$
BEGIN
IF OLD.bios_type = 4 AND NEW.bios_type != 4 THEN
IF (OLD.bios_type = 4 AND NEW.bios_type != 4) OR (OLD.bios_type = 3 AND NEW.bios_type < 3) THEN
DELETE FROM vm_nvram_data
WHERE vm_id = OLD.vm_guid;
END IF;
Expand Down