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

Commit

Permalink
Merge pull request #381 from chanwit/fix_possible_dm_leak
Browse files Browse the repository at this point in the history
fix possible dm snapshot leaks
  • Loading branch information
stealthybox authored Sep 3, 2019
2 parents 0693997 + 6704273 commit 70fb4a8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
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

0 comments on commit 70fb4a8

Please sign in to comment.