Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
qemu: cleanup vm template path properly
Browse files Browse the repository at this point in the history
VM templates creates a symlink from `/run/vc/vm/sbid` to
`/run/vc/vm/vmid`. We need to clean up both of them.

Signed-off-by: Peng Tao <bergwolf@gmail.com>
  • Loading branch information
bergwolf committed Jan 21, 2019
1 parent 0c09d2b commit 36762c7
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions virtcontainers/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ package virtcontainers
import (
"context"
"fmt"
govmmQemu "github.com/intel/govmm/qemu"
"github.com/kata-containers/runtime/virtcontainers/pkg/uuid"
"github.com/opentracing/opentracing-go"
"github.com/sirupsen/logrus"
"math"
"os"
"path/filepath"
Expand All @@ -21,6 +17,11 @@ import (
"time"
"unsafe"

govmmQemu "github.com/intel/govmm/qemu"
"github.com/kata-containers/runtime/virtcontainers/pkg/uuid"
"github.com/opentracing/opentracing-go"
"github.com/sirupsen/logrus"

"github.com/kata-containers/runtime/virtcontainers/device/config"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/kata-containers/runtime/virtcontainers/utils"
Expand Down Expand Up @@ -653,9 +654,25 @@ func (q *qemu) stopSandbox() error {
return err
}

err = os.RemoveAll(filepath.Join(RunVMStoragePath, q.id))
// cleanup vm path
dir := filepath.Join(RunVMStoragePath, q.id)

// If it's a symlink, remove both dir and the target.
// This can happen when vm template links a sandbox to a vm.
link, err := filepath.EvalSymlinks(dir)
if err != nil {
q.Logger().WithError(err).Error("Fail to clean up vm directory")
// Well, it's just cleanup failure. Let's ignore it.
q.Logger().WithError(err).WithField("dir", dir).Warn("failed to resolve vm path")
}
q.Logger().WithField("link", link).WithField("dir", dir).Infof("cleanup vm path")

if err := os.RemoveAll(dir); err != nil {
q.Logger().WithError(err).Warnf("failed to remove vm path %s", dir)
}
if link != dir && link != "" {
if err := os.RemoveAll(link); err != nil {
q.Logger().WithError(err).WithField("link", link).Warn("failed to remove resolved vm path")
}
}

return nil
Expand Down

0 comments on commit 36762c7

Please sign in to comment.