Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
960b0d7
<fix>[kvm]: add VM edk tags
Jan 13, 2026
aedb011
<feature>[header]: add TPM depandency
Feb 3, 2026
b49144f
<feature>[compute]: support create VM with TPM
Feb 4, 2026
9dc0572
<feature>[compute]: add secure boot dependency
Feb 4, 2026
da8f115
<feature>[kms]: support kms
Feb 6, 2026
cd084cd
<fix>[kvm]: update KVMGlobalConfig default value to "None"
Feb 11, 2026
0f1a23c
<fix>[kvm]: continue to update KVMGlobalConfig default value to "None"
Feb 12, 2026
21c1014
<fix>[conf]: update default value of secure.boot global config to false
Feb 24, 2026
05c3bc8
<feature>[compute]: introduce NvRam type volume
Feb 13, 2026
84b4024
<feature>[localstorage]: support create empty volume in raw types
Feb 13, 2026
3821c6d
<fix>[localstorage]: remame CreateEmptyVolumeCmd.format to volumeFormat
Feb 26, 2026
6204533
<feature>[header]: introduce VmHostFileVO
Mar 3, 2026
51b34cb
<feature>[header]: merge TpmHostRefVO to VmHostFileVO
Mar 6, 2026
6ffd613
<fix>[sdk]: rekey API and root key synchronization
Mar 6, 2026
32803e7
<fix>[header]: Envelope wrapper dek to compute
Mar 6, 2026
74e85a6
<fix>[kvm]: Remove rotate public key in initial pingHook
Mar 6, 2026
c64e794
<fix>[header]: Hide dek in log
Mar 7, 2026
637ff5c
<fix>[kvm]: fix swtpm path error
Mar 10, 2026
1cf6a8d
<fix>[kvm]: Move some logic to premium
Mar 10, 2026
e92a56e
<fix>[kvm]: update condition write VM host file
Mar 11, 2026
a43134d
<fix>[kvm]: Remove unused envelopeDekBase64
Mar 11, 2026
28f4c3d
<feature>[kvm]: support clone for TPM VM
Mar 12, 2026
c6c189b
<feature>[kvm]: support to start VM with VmHostBackupFileVO
Mar 12, 2026
12a86fd
<feature>[kvm]: clean VmHostFileVO after VM destroy
Mar 12, 2026
7df8afa
<feature>[kvm]: introduce VmHostBackupFileVO
Mar 12, 2026
768078a
<feature>[compute]: persist resource key when creating VM
Mar 16, 2026
e3b2d3a
<fix>[header]: fix reference error in VmHostFileContentVO
Mar 16, 2026
82a00b6
<feature>[compute]: prepare DEK on instantiating VM resource
Mar 17, 2026
c7789c0
<fix>[kvm]: prepare nvram folder before migrate VM
Mar 18, 2026
398f63b
<fix>[conf]: move premium errors xml to premium module
Mar 18, 2026
e6e7921
<feature>[kvm]: support take snapshot on VM offline
Mar 23, 2026
07e8e14
<feature>[kvm]: introduce SyncVmHostFilesFromHostMsg
Mar 23, 2026
9f72347
<feature>[kvm]: reset TPM state after VM reimage
Mar 25, 2026
68a9f9d
<feature>[keyprovider]: Add DEK provisioning for TPM
Mar 23, 2026
a64f204
<feature>[kvm]: refactor VmHostFileTO to support different operations
Mar 25, 2026
608269c
<feature>[kvm]: sync VM host files when releasing VM resource
Mar 24, 2026
e4d8ad5
<feature>[kvm]: sync VM host files after migration
Mar 25, 2026
d8a90fd
<feature>[kvm]: reset TPM state on VM reimage
Mar 25, 2026
22de7bb
<refactor>[kvm]: batch query VM host file content
Mar 25, 2026
5c0425f
<feature>[kvm]: reset TPM state after VM clone
Mar 25, 2026
a4ed577
<feature>[kvm]: use SQLBatch for TPM state reset
Mar 26, 2026
6479d74
<feature>[kvm]: add VM host file periodic sync tracker
Mar 25, 2026
7348552
<feature>[kvm]: make VM host file sync configurable
Mar 26, 2026
6cb5d33
<feature>[kvm]: add lastSyncReason to track VM host file sync
Mar 26, 2026
244b5d9
<feature>[kvm]: add key provider binding to TPM operations
Mar 26, 2026
0721139
<refactor>[kvm]: move VM host file cleanup to new extension point
Mar 26, 2026
71ac0f1
<test>[kvm]: remove NvRam volume supports
Mar 27, 2026
67fdf88
<feature>[vm]: add TPM and NvRam restore support for snapshot group
Mar 26, 2026
8206383
<refactor>[kvm]: introduce VM host file base classes for backup tracking
Mar 27, 2026
db489a3
<feature>[kvm]: support TPM key provider restore from snapshot group
Mar 27, 2026
a9c94ff
<fix>[compute]: add opaque on check root disk settings failed
Jan 13, 2026
c833fcf
<chore>[storage]: improve error message in VolumeSnapshotApiInterceptor
Feb 11, 2026
c4b057b
<refactor>[header]: add APINoSee to backupFileUuid fields
Mar 27, 2026
0ea2d67
<feature>[kvm]: add online snapshot support for VM host files
Mar 27, 2026
2d0c250
<fix>[header]: remove invalid notes on VmHostFileBackupJob
Mar 30, 2026
ec4346d
<feature>[kvm]: register VolumeSnapshotCreationExtensionPoint
Mar 30, 2026
d77894e
<feature>[kvm]: add hostfile backup agent command
Mar 30, 2026
c13c24b
<fix>[kvm]: fix invalid edk version tag error
Mar 31, 2026
9deb209
<refactor>[kvm]: reorganize vm host file management packages
Mar 31, 2026
80301ad
<feature>[kvm]: add os spec machine type support
Mar 31, 2026
2ddb3cd
<feature>[kvm]: persist machine type to system tag
Apr 1, 2026
62a4505
<refactor>[vm]: move nvram to devices spec and add backup support
Apr 1, 2026
6b49d62
<fix>[compute]: add allowed.tpm.vm.without.kms global config
Apr 1, 2026
65dee6e
<fix>[kvm]: support secure boot for primary storage migration
Apr 2, 2026
acc71b8
<feature>[kvm]: add periodic cleanup for expired VM host files
Apr 2, 2026
ea17721
<refactor>[kvm]: improve TPM removal by cleaning host files before DB…
Apr 2, 2026
8e54fa4
<feature>[log]: add LongText type for logging long content safely
Apr 3, 2026
9b1894e
<fix>[kvm]: add null check for dstHostUuid in secure boot
Apr 3, 2026
524e6e7
<fix>[core]: enforce propagateExceptionTo before lambda handlers
Apr 3, 2026
02509d6
<refactor>[kvm]: reset TPM via data plane before DB cleanup
Apr 3, 2026
eb7c707
<fix>[kvm]: skip key provider attach when no KMS
Apr 3, 2026
66232d7
<refactor>[kvm]: use enum for vm host file sync reasons
Apr 4, 2026
a71678b
<refactor>[kvm]: prepare NvRam host-file before migration
Apr 5, 2026
d793e4c
<feature>[kvm]: sync VM host files before HA start
Apr 6, 2026
06fbd77
<fix>[crypto]: keep TPM key ref until VM removed from DB
Apr 7, 2026
393a445
<feature>[kvm]: periodic check and sync for VM host files
Apr 7, 2026
234ee58
<fix>[kvm]: remove TPM from VM individually instead of batch delete
Apr 7, 2026
28b349e
<feature>[kvm]: support TPM revert without KMS
Apr 7, 2026
5d95b73
<fix>[kvm]: fix NVRAM migration handler duplicate call
Apr 8, 2026
e0d8a11
<fix>[kvm]: clone resource ref when revert snapshot
Apr 8, 2026
0984367
<fix>[crypto]: secret get in vm pre instantiate
Apr 6, 2026
bbcb140
<fix>[kvm]: remove TPM when VM deleted from DB
Apr 9, 2026
06b6e15
<fix>[kms]: add delete secret for vm
zsphere-opensource Apr 8, 2026
38c4ab6
<fix>[kms]: add test case for delete secret
zsphere-opensource Apr 9, 2026
90b9b50
<fix>[crypto]: fix conflict and review
Apr 15, 2026
f43d587
<fix>[kvm]: fix NPE in VmHostFileTracker sync
Apr 10, 2026
7144190
<fix>[kvm]: disable host status check when syncing VM host files
Apr 10, 2026
fa7c72c
<fix>[kvm]: mark TPM VM host files changed on start/shutdown
Apr 11, 2026
f6c1e5b
<fix>[kvm]: define secret on migrate destination
Apr 11, 2026
004e22c
<fix>[kvm]: fail VM start when host file changed but sync fails
Apr 14, 2026
4ccdb71
<fix>[header]: add Tpm cascade extensions
Apr 13, 2026
6b0b439
<fix>[kvm]: revert block vm start if TPM is not latest
Apr 15, 2026
106cc39
<fix>[kvm]: add auto-completer for VM host file TPM reset config
Apr 16, 2026
d33279d
<feature>[kvm]: add allocator filter for VM with unsynchronized host …
Apr 16, 2026
71bc787
<fix>[kvm]: Fix vm start fail after nkp restore
zsphere-opensource Apr 16, 2026
1e23ed6
<fix>[kvm]: create key when attach tpm
Apr 16, 2026
b6c16b6
<fix>[kvm]: skip sync VM host file is not changed
Apr 17, 2026
964b435
<fix>[kvm]: remove bad check in KvmSecureBootManager syncing step
Apr 18, 2026
adfedfa
<fix>[kvm]: save EncryptedResourceKeyRefVO when sync VmHostFile to ba…
Apr 20, 2026
fb8f287
<fix>[kvm]: use domain XML secret UUID for vTPM migrate
Apr 20, 2026
65bb75d
<fix>[kvm]: rename RemoveTpmMsg to TpmDeletionMsg
Apr 21, 2026
115d61c
<fix>[kvm]: support to handle "/vm/hostfile/changed" event from kvmagent
Apr 22, 2026
22eba67
<fix>[kvm]: wrapper createBackupBase step by try...catch
Apr 22, 2026
8d1085b
<fix>[kvm]: add ignoreSyncError in CloneVmHostFileMsg
Apr 22, 2026
912b1ec
<fix>[kvm]: sync VM host files before migration based on changeDate
Apr 23, 2026
5fe5e00
<fix>[kvm]: simplify resetTpm checker in SnapshotGroupRevertTpmHelper
Apr 22, 2026
96f0722
<fix>[kvm]: sync dirty vm host files for stopped VMs
Apr 23, 2026
1b72062
<fix>[kvm]: reject stale vm host file in secure boot flow
Apr 23, 2026
77c95c0
<fix>[kvm]: support reset tpm to a new default key provider
Apr 23, 2026
59fcfc6
<fix>[kvm]: clean resource key before sync VmHostFile to backup
Apr 28, 2026
5a39c8a
<fix>[kvm]: KvmSecureBootExt no longer implement JustBeforeDeleteExte…
Apr 28, 2026
218838b
<feature>[compute]: introduce VmExpungeVmResourceCascadeFlow
Apr 29, 2026
9239eaf
<fix>[kvm]: clean VmHostFile by message in VmHostFileTracker
Apr 30, 2026
a379d81
<fix>[kvm]: detach resource key from VmHostBackupFileVO when remove T…
Apr 29, 2026
5001214
<fix>[storage]: clean VmHostBackupFileVO when VolumeSnapshot ungroup
Apr 30, 2026
1374b5c
<fix>[compute]: hard delete host file if created state vm destroyed
May 1, 2026
9818cff
<fix>[header]: backup resource key after taking memory snapshot group
May 8, 2026
de571b9
<feature>[storage]: support restore TPM when reverting snapshot group
May 9, 2026
f4762b0
<fix>[header]: rename BackupVmTpmMsg and RestoreVmTpmMsg
May 9, 2026
6abea6e
<feature>[header]: Add TPM key backup for snapshot revert and rollback
May 11, 2026
ef52edd
<fix>[generated]: collect vTPM and KMS schema and SDK artifacts
Aug 17, 2026
4ead394
<fix>[zstack]: adapt vTPM migration compile issues
Aug 17, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.zstack.compute.legacy;

import org.zstack.core.GlobalProperty;
import org.zstack.core.GlobalPropertyDefinition;

@GlobalPropertyDefinition
public class ComputeLegacyGlobalProperty {
@GlobalProperty(name="enable.nv.ram.type.volume", defaultValue = "false")
public static boolean enableNvRamTypeVolume;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.zstack.header.vm.InstantiateNewCreatedVmInstanceMsg;
import org.zstack.header.vm.VmCreationStrategy;
import org.zstack.header.vm.VmNicSpec;
import org.zstack.header.vm.devices.VmDevicesSpec;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -31,6 +32,7 @@ public class InstantiateVmFromNewCreatedStruct {
private List<String> sshKeyPairUuids;
private final List<String> candidatePrimaryStorageUuidsForRootVolume = new ArrayList<>();
private final List<String> candidatePrimaryStorageUuidsForDataVolume = new ArrayList<>();
private VmDevicesSpec devicesSpec;

public List<String> getCandidatePrimaryStorageUuidsForRootVolume() {
return candidatePrimaryStorageUuidsForRootVolume;
Expand Down Expand Up @@ -64,6 +66,14 @@ public void setDiskAOs(List<APICreateVmInstanceMsg.DiskAO> diskAOs) {
this.diskAOs = diskAOs;
}

public VmDevicesSpec getDevicesSpec() {
return devicesSpec;
}

public void setDevicesSpec(VmDevicesSpec devicesSpec) {
this.devicesSpec = devicesSpec;
}

public List<String> getRootVolumeSystemTags() {
return rootVolumeSystemTags;
}
Expand Down Expand Up @@ -142,6 +152,7 @@ public static InstantiateVmFromNewCreatedStruct fromMessage(InstantiateNewCreate
struct.setDataVolumeSystemTagsOnIndex(msg.getDataVolumeSystemTagsOnIndex());
struct.setDisableL3Networks(msg.getDisableL3Networks());
struct.setDiskAOs(msg.getDiskAOs());
struct.setDevicesSpec(msg.getDevicesSpec());
return struct;
}

Expand All @@ -161,6 +172,7 @@ public static InstantiateVmFromNewCreatedStruct fromMessage(CreateVmInstanceMsg
struct.setDataVolumeSystemTagsOnIndex(msg.getDataVolumeSystemTagsOnIndex());
struct.setDisableL3Networks(msg.getDisableL3Networks());
struct.setDiskAOs(msg.getDiskAOs());
struct.setDevicesSpec(msg.getDevicesSpec());
return struct;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,11 @@ public void done(ErrorCodeList errorCodeList) {
.flatMap(List::stream).map(VmCdRomInventory::getUuid)
.collect(Collectors.toList());
dbf.removeByPrimaryKeys(cdRomUuids, VmCdRomVO.class);
dbf.removeByPrimaryKeys(vminvs.stream().map(p -> p.getInventory().getUuid())
.collect(Collectors.toList()),
VmInstanceVO.class);

List<String> vmUuidList = vminvs.stream()
.map(vm -> vm.getInventory().getUuid())
.collect(Collectors.toList());
dbf.removeByPrimaryKeys(vmUuidList, VmInstanceVO.class);
}

completion.success();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public void run(final FlowTrigger trigger, Map data) {
final boolean deleteDataDisk = VmGlobalConfig.DELETE_DATA_VOLUME_ON_VM_DESTROY.value(Boolean.class);

/* data volume must be detached anyway no matter if it is going to be deleted */
if (spec.getVmInventory().getAllVolumes().size() > 1) {
boolean anyDataVolume = spec.getVmInventory().getAllVolumes().stream()
.anyMatch(arg -> VolumeType.Data.toString().equals(arg.getType()));
if (anyDataVolume) {
detachDataVolumes(spec);
}

Expand All @@ -58,7 +60,11 @@ public void run(final FlowTrigger trigger, Map data) {
return;
}

List<String> volumeTypes = Arrays.asList(VolumeType.Root.toString(), VolumeType.Memory.toString(), VolumeType.Cache.toString());
List<String> volumeTypes = Arrays.asList(
VolumeType.Root.toString(),
VolumeType.Memory.toString(),
VolumeType.Cache.toString()
);
List<VolumeDeletionStruct> ctx = CollectionUtils.transformToList(spec.getVmInventory().getAllVolumes(), new Function<VolumeDeletionStruct, VolumeInventory>() {
@Override
public VolumeDeletionStruct call(VolumeInventory arg) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package org.zstack.compute.vm;

import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.zstack.compute.vm.devices.VmTpmManager;
import org.zstack.core.cascade.CascadeConstant;
import org.zstack.core.cascade.CascadeFacade;
import org.zstack.core.componentloader.PluginRegistry;
import org.zstack.header.core.Completion;
import org.zstack.header.core.workflow.FlowTrigger;
import org.zstack.header.core.workflow.NoRollbackFlow;
import org.zstack.header.errorcode.ErrorCode;
import org.zstack.header.vm.VmAfterExpungeExtensionPoint;
import org.zstack.header.vm.VmDeletionStruct;
import org.zstack.header.vm.VmInstanceConstant;
import org.zstack.header.vm.VmInstanceDeletionPolicyManager.VmInstanceDeletionPolicy;
import org.zstack.header.vm.VmInstanceInventory;
import org.zstack.header.vm.VmInstanceSpec;
import org.zstack.header.vm.VmInstanceVO;
import org.zstack.utils.CollectionUtils;
import org.zstack.utils.Utils;
import org.zstack.utils.logging.CLogger;

import java.util.Map;

import static org.zstack.utils.CollectionDSL.list;

/**
* Runs after volume/metadata expunge flows: fires {@link VmAfterExpungeExtensionPoint}, then
* {@link CascadeConstant#VM_INSTANCE_EXPUNGE_CODE} so TPM / VM host-file rows are removed before the VM row is deleted.
*/
@Configurable(preConstruction = true, autowire = Autowire.BY_TYPE)
public class VmExpungeVmResourceCascadeFlow extends NoRollbackFlow {
private static final CLogger logger = Utils.getLogger(VmExpungeVmResourceCascadeFlow.class);

/**
* Snapshot of TPM uuid before cascade deletes {@link org.zstack.header.tpm.entity.TpmVO};
* read by {@link VmInstanceBase} expunge done handler for {@code detachTpmKeyProviderBestEffort}.
*/
public static final String EXPUNGE_CASCADE_TPM_UUID_KEY =
VmExpungeVmResourceCascadeFlow.class.getSimpleName() + ".tpmUuidBeforeCascade";

@Autowired
private CascadeFacade casf;
@Autowired
private PluginRegistry pluginRgty;

@Override
public void run(FlowTrigger trigger, Map data) {
final VmInstanceSpec spec = (VmInstanceSpec) data.get(VmInstanceConstant.Params.VmInstanceSpec.toString());
if (spec == null || spec.getVmInventory() == null) {
logger.warn("[VmExpungeVmResourceCascadeFlow] missing VmInstanceSpec, skip cascade");
trigger.next();
return;
}

final VmInstanceInventory inv = spec.getVmInventory();

CollectionUtils.safeForEach(pluginRgty.getExtensionList(VmAfterExpungeExtensionPoint.class),
arg -> arg.vmAfterExpunge(inv));

final String tpmUuidBeforeCascade = VmTpmManager.findTpmUuidForVmOrNull(inv.getUuid());
data.put(EXPUNGE_CASCADE_TPM_UUID_KEY, tpmUuidBeforeCascade);

VmDeletionStruct expungeStruct = new VmDeletionStruct();
expungeStruct.setInventory(inv);
expungeStruct.setDeletionPolicy(VmInstanceDeletionPolicy.Direct);

casf.asyncCascade(CascadeConstant.VM_INSTANCE_EXPUNGE_CODE, VmInstanceVO.class.getSimpleName(),
list(expungeStruct), new Completion(trigger) {
@Override
public void success() {
trigger.next();
}

@Override
public void fail(ErrorCode errorCode) {
trigger.fail(errorCode);
}
});
}
}
10 changes: 10 additions & 0 deletions compute/src/main/java/org/zstack/compute/vm/VmGlobalConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public class VmGlobalConfig {
@GlobalConfigDef(defaultValue = "false", type = Boolean.class, description = "sync clock after vm resume")
public static GlobalConfig VM_CLOCK_SYNC_AFTER_VM_RESUME = new GlobalConfig(CATEGORY, "vm.clock.sync.after.vm.resume");

@BindResourceConfig(value = {VmInstanceVO.class, ClusterVO.class})
@GlobalConfigValidation(validValues = {"true", "false"})
public static GlobalConfig ENABLE_UEFI_SECURE_BOOT = new GlobalConfig(CATEGORY, "enable.uefi.secure.boot");

Expand All @@ -141,4 +142,13 @@ public class VmGlobalConfig {
@GlobalConfigValidation(validValues = {"true", "false", "auto"})
@GlobalConfigDef(defaultValue = "false", type = String.class, description = "generate config required for vhost primary storage")
public static GlobalConfig GENERATE_CONFIG_VHOST_REQUIRED = new GlobalConfig(CATEGORY, "generate.config.vhost.required");

@GlobalConfigDef(defaultValue = "true", type = Boolean.class, description = "whether reset TPM state after VM clone")
@GlobalConfigValidation(validValues = {"true", "false"})
@BindResourceConfig(value = {VmInstanceVO.class, ClusterVO.class})
public static GlobalConfig RESET_TPM_AFTER_VM_CLONE = new GlobalConfig(CATEGORY, "reset.tpm.after.vm.clone");

@GlobalConfigDef(defaultValue = "false", type = Boolean.class, description = "allowed TPM VM start without KMS")
@GlobalConfigValidation(validValues = {"true", "false"})
public static GlobalConfig ALLOWED_TPM_VM_WITHOUT_KMS = new GlobalConfig(CATEGORY, "allowed.tpm.vm.without.kms");
}
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,8 @@ private void validateRootDiskOffering(ImageMediaType imgFormat, APICreateVmInsta
}

if (msg.getRootDiskSize() <= 0) {
throw new ApiMessageInterceptionException(operr(ORG_ZSTACK_COMPUTE_VM_10182, "Unexpected root disk settings"));
throw new ApiMessageInterceptionException(operr(ORG_ZSTACK_COMPUTE_VM_10182,
"Unexpected root disk settings: DiskAO[0].size is mandatory when image format is ISO"));
}
}
}
Expand Down
59 changes: 44 additions & 15 deletions compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.transaction.annotation.Transactional;
import org.zstack.compute.allocator.HostAllocatorManager;
import org.zstack.compute.vm.devices.TpmEncryptedResourceKeyBackend;
import org.zstack.compute.vm.devices.VmTpmManager;
import org.zstack.core.Platform;
import org.zstack.core.asyncbatch.While;
import org.zstack.core.cascade.CascadeConstant;
Expand Down Expand Up @@ -145,11 +147,26 @@ public class VmInstanceBase extends AbstractVmInstance {
private TagManager tagMgr;
@Autowired
private VmInstanceDeviceManager vidm;
@Autowired
private TpmEncryptedResourceKeyBackend tpmKeyBackend;

protected VmInstanceVO self;
protected VmInstanceVO originalCopy;
protected String syncThreadName;

private void detachTpmKeyProviderBestEffort(String tpmUuid) {
if (tpmUuid == null) {
return;
}
try {
tpmKeyBackend.detachKeyProviderFromTpm(tpmUuid);
} catch (Throwable t) {
logger.warn(String.format(
"failed to detach key provider from TPM[uuid:%s]: %s",
tpmUuid, t.getMessage()), t);
}
}

protected void checkState(final String hostUuid, final NoErrorCompletion completion) {
CheckVmStateOnHypervisorMsg msg = new CheckVmStateOnHypervisorMsg();
msg.setVmInstanceUuids(list(self.getUuid()));
Expand Down Expand Up @@ -1439,21 +1456,9 @@ private void expunge(Message msg, final Completion completion) {
chain.done(new FlowDoneHandler(completion) {
@Override
public void handle(Map data) {
CollectionUtils.safeForEach(pluginRgty.getExtensionList(VmAfterExpungeExtensionPoint.class),
arg -> arg.vmAfterExpunge(inv));

callVmJustBeforeDeleteFromDbExtensionPoint();

dbf.reload(self);
dbf.removeCollection(self.getVmNics(), VmNicVO.class);
dbf.removeCollection(self.getVmCdRoms(), VmCdRomVO.class);
dbf.remove(self);
logger.debug(String.format("successfully expunged the vm[uuid:%s]", self.getUuid()));
dbf.eoCleanup(VmInstanceVO.class, self.getUuid());
if (inv.getRootVolumeUuid() != null) {
dbf.eoCleanup(VolumeVO.class, inv.getRootVolumeUuid());
}
completion.success();
final String tpmUuidForEncryptedKeyRef =
(String) data.get(VmExpungeVmResourceCascadeFlow.EXPUNGE_CASCADE_TPM_UUID_KEY);
finishExpungeAfterVmResourceCascade(inv, tpmUuidForEncryptedKeyRef, completion);
}
}).error(new FlowErrorHandler(completion) {
@Override
Expand All @@ -1463,6 +1468,23 @@ public void handle(final ErrorCode errCode, Map data) {
}).start();
}

private void finishExpungeAfterVmResourceCascade(VmInstanceInventory inv, String tpmUuidForEncryptedKeyRef,
Completion completion) {
callVmJustBeforeDeleteFromDbExtensionPoint();

self = dbf.reload(self);
dbf.removeCollection(self.getVmNics(), VmNicVO.class);
dbf.removeCollection(self.getVmCdRoms(), VmCdRomVO.class);
dbf.remove(self);
logger.debug(String.format("successfully expunged the vm[uuid:%s]", self.getUuid()));
dbf.eoCleanup(VmInstanceVO.class, self.getUuid());
if (inv.getRootVolumeUuid() != null) {
dbf.eoCleanup(VolumeVO.class, inv.getRootVolumeUuid());
}
detachTpmKeyProviderBestEffort(tpmUuidForEncryptedKeyRef);
completion.success();
}

private void handle(final VmCheckOwnStateMsg msg) {
thdf.chainSubmit(new ChainTask(msg) {
@Override
Expand Down Expand Up @@ -2803,12 +2825,15 @@ public void success() {
if (self.getState() != VmInstanceState.Destroyed) {
changeVmStateInDb(VmInstanceStateEvent.destroyed);
}
final String tpmUuidForEncryptedKeyRef = VmTpmManager.findTpmUuidForVmOrNull(self.getUuid());
callVmJustBeforeDeleteFromDbExtensionPoint();
dbf.removeCollection(self.getVmCdRoms(), VmCdRomVO.class);
dbf.remove(getSelf());
dbf.eoCleanup(VmInstanceVO.class, self.getUuid());
detachTpmKeyProviderBestEffort(tpmUuidForEncryptedKeyRef);
} else if (deletionPolicy == VmInstanceDeletionPolicy.DBOnly || deletionPolicy == VmInstanceDeletionPolicy.KeepVolume) {
String accountUuid = acntMgr.getOwnerAccountUuidOfResource(inv.getUuid());
final String tpmUuidForEncryptedKeyRef = VmTpmManager.findTpmUuidForVmOrNull(self.getUuid());
new SQLBatch() {
@Override
protected void scripts() {
Expand All @@ -2822,6 +2847,7 @@ protected void scripts() {
sql(VmInstanceVO.class).eq(VmInstanceVO_.uuid, self.getUuid()).hardDelete();
}
}.execute();
detachTpmKeyProviderBestEffort(tpmUuidForEncryptedKeyRef);
callVmJustAfterDeleteFromDbExtensionPoint(inv, accountUuid);
} else if (deletionPolicy == VmInstanceDeletionPolicy.Delay) {
changeVmStateInDb(VmInstanceStateEvent.destroyed);
Expand Down Expand Up @@ -7767,6 +7793,7 @@ public DiskOfferingVO call(DiskOfferingVO arg) {
}

spec.setDiskAOs(struct.getDiskAOs());
spec.setDevicesSpec(struct.getDevicesSpec());

List<CdRomSpec> cdRomSpecs = buildVmCdRomSpecsForNewCreated(spec);
spec.setCdRomSpecs(cdRomSpecs);
Expand Down Expand Up @@ -7952,6 +7979,7 @@ public void handle(final Map data) {
}).error(new FlowErrorHandler(completion) {
@Override
public void handle(final ErrorCode errCode, Map data) {
final String tpmUuidForEncryptedKeyRef = VmTpmManager.findTpmUuidForVmOrNull(self.getUuid());
extEmitter.failedToStartNewCreatedVm(VmInstanceInventory.valueOf(self), errCode);
dbf.remove(self);
// clean up EO, otherwise API-retry may cause conflict if
Expand All @@ -7962,6 +7990,7 @@ public void handle(final ErrorCode errCode, Map data) {
logger.warn(e.getMessage());
}

detachTpmKeyProviderBestEffort(tpmUuidForEncryptedKeyRef);
completion.fail(operr(ORG_ZSTACK_COMPUTE_VM_10289, errCode, errCode.getDetails()));
}
}).start();
Expand Down
Loading