Skip to content

Commit

Permalink
qemu: create vm directory before launching qemu
Browse files Browse the repository at this point in the history
Right now we create it in `createsandbox` and it would
create the vm dir unnecessarily for fetchsandbox() and
it ends up leaving an empty vm dir behind even after
DeleteSandbox.

Fixes: clearcontainers#547

Signed-off-by: Peng Tao <[email protected]>
  • Loading branch information
bergwolf committed Aug 3, 2018
1 parent 568b65c commit bd50761
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions virtcontainers/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,6 @@ func (q *qemu) createQmpSocket() ([]govmmQemu.QMPSocket, error) {
path: monitorSockPath,
}

err = os.MkdirAll(filepath.Dir(monitorSockPath), dirMode)
if err != nil {
return nil, err
}

return []govmmQemu.QMPSocket{
{
Type: "unix",
Expand Down Expand Up @@ -489,7 +484,21 @@ func (q *qemu) startSandbox() error {
}
}()

strErr, err := govmmQemu.LaunchQemu(q.qemuConfig, newQMPLogger())
vmPath := filepath.Join(RunVMStoragePath, q.id)
err := os.MkdirAll(vmPath, dirMode)
if err != nil {
return err
}
defer func() {
if err != nil {
if err := os.RemoveAll(vmPath); err != nil {
q.Logger().WithError(err).Error("Fail to clean up vm directory")
}
}
}()

var strErr string
strErr, err = govmmQemu.LaunchQemu(q.qemuConfig, newQMPLogger())
if err != nil {
return fmt.Errorf("%s", strErr)
}
Expand Down

0 comments on commit bd50761

Please sign in to comment.