Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

fix possible dm snapshot leaks #381

Merged
merged 2 commits into from
Sep 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 4 additions & 3 deletions pkg/dmlegacy/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,17 @@ func AllocateAndPopulateOverlay(vm *api.VM) error {
}

func copyToOverlay(vm *api.VM) error {
if err := ActivateSnapshot(vm); err != nil {
err := ActivateSnapshot(vm)
defer cleanup.DeactivateSnapshot(vm)
if err != nil {
return err
}
defer cleanup.DeactivateSnapshot(vm)

mp, err := util.Mount(vm.SnapshotDev())
defer mp.Umount()
if err != nil {
return err
}
defer mp.Umount()

// Copy the kernel files to the VM. TODO: Use snapshot overlaying instead.
if err := copyKernelToOverlay(vm, mp.Path); err != nil {
Expand Down
11 changes: 9 additions & 2 deletions pkg/operations/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
log "github.com/sirupsen/logrus"
api "github.com/weaveworks/ignite/pkg/apis/ignite"
"github.com/weaveworks/ignite/pkg/client"
"github.com/weaveworks/ignite/pkg/dmlegacy/cleanup"
"github.com/weaveworks/ignite/pkg/logs"
"github.com/weaveworks/ignite/pkg/providers"
"github.com/weaveworks/ignite/pkg/runtime"
Expand All @@ -28,7 +29,7 @@ func DeleteVM(c *client.Client, vm *api.VM) error {
// CleanupVM removes the resources of the given VM
func CleanupVM(vm *api.VM) error {
// Inspect the container before trying to stop it and it gets auto-removed
result, _ := providers.Runtime.InspectContainer(util.NewPrefixer().Prefix(vm.GetUID()))
inspectResult, _ := providers.Runtime.InspectContainer(util.NewPrefixer().Prefix(vm.GetUID()))

// If the VM is running, try to kill it first so we don't leave dangling containers
if vm.Running() {
Expand All @@ -38,7 +39,13 @@ func CleanupVM(vm *api.VM) error {
}

// Remove the VM container if it exists
RemoveVMContainer(result)
// TODO should this function return a proper error?
RemoveVMContainer(inspectResult)

// After removal is successful, remove the dm snapshots
if err := cleanup.DeactivateSnapshot(vm); err != nil {
return err
}

if logs.Quiet {
fmt.Println(vm.GetUID())
Expand Down