diff --git a/virtcontainers/hypervisor.go b/virtcontainers/hypervisor.go index 5dd008c7b7..5546794455 100644 --- a/virtcontainers/hypervisor.go +++ b/virtcontainers/hypervisor.go @@ -279,6 +279,10 @@ type HypervisorConfig struct { // GuestHookPath is the path within the VM that will be used for 'drop-in' hooks GuestHookPath string + + // VMid is the id of the VM that create the hypervisor if the VM is created by the factory. + // VMid is "" if the hypervisor is not created by the factory. + VMid string } // vcpu mapping from vcpu number to thread number diff --git a/virtcontainers/qemu.go b/virtcontainers/qemu.go index 157c25f86e..cde61e20a6 100644 --- a/virtcontainers/qemu.go +++ b/virtcontainers/qemu.go @@ -690,6 +690,17 @@ func (q *qemu) cleanupVM() error { } } + if q.config.VMid != "" { + dir = store.SandboxConfigurationRootPath(q.config.VMid) + if err := os.RemoveAll(dir); err != nil { + q.Logger().WithError(err).WithField("path", dir).Warnf("failed to remove vm path") + } + dir = store.SandboxRuntimeRootPath(q.config.VMid) + if err := os.RemoveAll(dir); err != nil { + q.Logger().WithError(err).WithField("path", dir).Warnf("failed to remove vm path") + } + } + return nil } diff --git a/virtcontainers/vm.go b/virtcontainers/vm.go index b621830bf1..a6e6e12a35 100644 --- a/virtcontainers/vm.go +++ b/virtcontainers/vm.go @@ -461,6 +461,7 @@ func (v *VM) assignSandbox(s *Sandbox) error { } s.hypervisor = v.hypervisor + s.config.HypervisorConfig.VMid = v.id return nil }