mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-09-19 15:58:25 +00:00
qemu: cleanup vm template path properly
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>
This commit is contained in:
@@ -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"
|
||||
@@ -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"
|
||||
@@ -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
|
||||
|
Reference in New Issue
Block a user