Skip to content

Commit 075028d

Browse files
author
gitlab
committed
Merge branch 'zsv-ldap-9' into 'feature-zsv-5.0.0-vm-support-vtpm-and-secuceboot'
<feature>[kvm]: support TPM revert without KMS See merge request zstackio/zstack!9558
2 parents 064b889 + 866fc0f commit 075028d

1 file changed

Lines changed: 19 additions & 15 deletions

File tree

plugin/kvm/src/main/java/org/zstack/kvm/tpm/SnapshotGroupRevertTpmHelper.java

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
import java.util.List;
2525

26+
import static org.zstack.compute.vm.VmGlobalConfig.ALLOWED_TPM_VM_WITHOUT_KMS;
27+
2628
@Configurable(preConstruction = true, autowire = Autowire.BY_TYPE)
2729
public class SnapshotGroupRevertTpmHelper {
2830
private static final CLogger logger = Utils.getLogger(SnapshotGroupRevertTpmHelper.class);
@@ -98,23 +100,25 @@ public void setupFromApi(APICreateVmInstanceFromVolumeSnapshotGroupMsg apiMsg, C
98100
tpmSpec.setBackupFileUuid(tpmBackupFile.getUuid());
99101
}
100102

101-
String keyProviderName = KVMSystemTags.TPM_KEY_PROVIDER_NAME
102-
.getTokenByResourceUuid(tpmBackupFile.getUuid(), KVMSystemTags.TPM_KEY_PROVIDER_NAME_TOKEN);
103-
if (keyProviderName == null) {
104-
logger.warn(String.format(
105-
"failed to find keyProvider from snapshotGroup[uuid:%s] by tpmBackupFile[uuid:%s]",
106-
snapshotGroupUuid, tpmBackupFile.getUuid()));
107-
if (tpmSpec.getKeyProviderUuid() == null) {
108-
tpmSpec.setKeyProviderUuid(tpmKeyBackend.defaultKeyProviderUuid()); // maybe null
109-
}
110-
} else {
111-
String keyProviderUuid = tpmKeyBackend.findKeyProviderUuidByName(keyProviderName);
112-
if (keyProviderUuid == null) {
103+
if (ALLOWED_TPM_VM_WITHOUT_KMS.value(Boolean.class) != Boolean.TRUE) {
104+
String keyProviderName = KVMSystemTags.TPM_KEY_PROVIDER_NAME
105+
.getTokenByResourceUuid(tpmBackupFile.getUuid(), KVMSystemTags.TPM_KEY_PROVIDER_NAME_TOKEN);
106+
if (keyProviderName == null) {
113107
logger.warn(String.format(
114-
"failed to resolve keyProvider[name:%s] from snapshotGroup[uuid:%s] by tpmBackupFile[uuid:%s], keep keyProviderUuid unset",
115-
keyProviderName, snapshotGroupUuid, tpmBackupFile.getUuid()));
108+
"failed to find keyProvider from snapshotGroup[uuid:%s] by tpmBackupFile[uuid:%s]",
109+
snapshotGroupUuid, tpmBackupFile.getUuid()));
110+
if (tpmSpec.getKeyProviderUuid() == null) {
111+
tpmSpec.setKeyProviderUuid(tpmKeyBackend.defaultKeyProviderUuid()); // maybe null
112+
}
116113
} else {
117-
tpmSpec.setKeyProviderUuid(keyProviderUuid);
114+
String keyProviderUuid = tpmKeyBackend.findKeyProviderUuidByName(keyProviderName);
115+
if (keyProviderUuid == null) {
116+
logger.warn(String.format(
117+
"failed to resolve keyProvider[name:%s] from snapshotGroup[uuid:%s] by tpmBackupFile[uuid:%s], keep keyProviderUuid unset",
118+
keyProviderName, snapshotGroupUuid, tpmBackupFile.getUuid()));
119+
} else {
120+
tpmSpec.setKeyProviderUuid(keyProviderUuid);
121+
}
118122
}
119123
}
120124
}

0 commit comments

Comments
 (0)