Merge pull request #548 from bergwolf/cleanup

qemu: create vm directory before launching qemu
This commit is contained in:
Julio Montes 2018-08-03 07:12:51 -05:00 committed by GitHub
commit dec385abd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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",
@ -416,21 +411,6 @@ func (q *qemu) createSandbox() error {
return fmt.Errorf("UUID should not be empty")
}
monitorSockPath, err := q.qmpSocketPath(q.id)
if err != nil {
return err
}
q.qmpMonitorCh = qmpChannel{
ctx: context.Background(),
path: monitorSockPath,
}
err = os.MkdirAll(filepath.Dir(monitorSockPath), dirMode)
if err != nil {
return err
}
qmpSockets, err := q.createQmpSocket()
if err != nil {
return err
@ -504,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)
}