|
33 | 33 | import org.zstack.header.tpm.entity.TpmVO; |
34 | 34 | import org.zstack.header.tpm.entity.TpmVO_; |
35 | 35 | import org.zstack.header.secret.SecretHostDefineReply; |
| 36 | +import org.zstack.header.tpm.message.RemoveTpmMsg; |
36 | 37 | import org.zstack.header.vm.PreVmInstantiateResourceExtensionPoint; |
| 38 | +import org.zstack.header.vm.VmInstanceInventory; |
37 | 39 | import org.zstack.header.vm.VmInstanceSpec; |
38 | 40 | import org.zstack.header.vm.VmInstantiateResourceException; |
| 41 | +import org.zstack.header.vm.VmJustBeforeDeleteFromDbExtensionPoint; |
39 | 42 | import org.zstack.header.vm.additions.VmHostBackupFileVO; |
40 | 43 | import org.zstack.header.vm.additions.VmHostBackupFileVO_; |
41 | 44 | import org.zstack.header.vm.additions.VmHostFileType; |
|
54 | 57 | import java.time.Instant; |
55 | 58 | import java.util.Map; |
56 | 59 |
|
| 60 | +import static org.zstack.header.tpm.TpmConstants.SERVICE_ID; |
57 | 61 | import static org.zstack.kvm.KVMConstant.*; |
58 | 62 | import static org.zstack.core.Platform.operr; |
59 | 63 |
|
60 | 64 | public class KvmTpmExtensions implements KVMStartVmExtensionPoint, |
61 | | - PreVmInstantiateResourceExtensionPoint { |
| 65 | + PreVmInstantiateResourceExtensionPoint, |
| 66 | + VmJustBeforeDeleteFromDbExtensionPoint { |
62 | 67 | private static final CLogger logger = Utils.getLogger(KvmTpmExtensions.class); |
63 | 68 |
|
64 | 69 | @Autowired |
@@ -373,6 +378,27 @@ public void fail(ErrorCode errorCode) { |
373 | 378 | }); |
374 | 379 | } |
375 | 380 |
|
| 381 | + @Override |
| 382 | + public void vmJustBeforeDeleteFromDb(VmInstanceInventory inv) { |
| 383 | + String tpmUuid = Q.New(TpmVO.class) |
| 384 | + .eq(TpmVO_.vmInstanceUuid, inv.getUuid()) |
| 385 | + .select(TpmVO_.uuid) |
| 386 | + .findValue(); |
| 387 | + if (tpmUuid == null) { |
| 388 | + return; |
| 389 | + } |
| 390 | + |
| 391 | + RemoveTpmMsg removeMsg = new RemoveTpmMsg(); |
| 392 | + removeMsg.setVmInstanceUuid(inv.getUuid()); |
| 393 | + removeMsg.setTpmUuid(tpmUuid); |
| 394 | + bus.makeTargetServiceIdByResourceUuid(removeMsg, SERVICE_ID, removeMsg.getTpmUuid()); |
| 395 | + MessageReply reply = bus.call(removeMsg); |
| 396 | + if (!reply.isSuccess()) { |
| 397 | + logger.warn(String.format("failed to remove TPM[uuid:%s] of VM[uuid:%s], error: %s", |
| 398 | + tpmUuid, inv.getUuid(), reply.getError())); |
| 399 | + } |
| 400 | + } |
| 401 | + |
376 | 402 | private void clearRollbackInfo(VmInstanceSpec spec) { |
377 | 403 | if (spec.getDevicesSpec() == null || spec.getDevicesSpec().getTpm() == null) { |
378 | 404 | return; |
|
0 commit comments