enable discards only on qemu >= 2
older qemu versions does not have discard option, so not enable it Signed-off-by: Vasiliy Tolstov <v.tolstov@selfip.ru>
This commit is contained in:
parent
17cea4fa95
commit
3fae902bc3
|
@ -4,7 +4,6 @@ import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/mitchellh/multistep"
|
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
@ -14,6 +13,8 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
|
"github.com/mitchellh/multistep"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DriverCancelCallback func(state multistep.StateBag) bool
|
type DriverCancelCallback func(state multistep.StateBag) bool
|
||||||
|
@ -188,8 +189,8 @@ func (d *QemuDriver) Version() (string, error) {
|
||||||
|
|
||||||
versionOutput := strings.TrimSpace(stdout.String())
|
versionOutput := strings.TrimSpace(stdout.String())
|
||||||
log.Printf("Qemu --version output: %s", versionOutput)
|
log.Printf("Qemu --version output: %s", versionOutput)
|
||||||
versionRe := regexp.MustCompile("qemu-kvm-[0-9]\\.[0-9]")
|
versionRe := regexp.MustCompile("[0-9]\\.[0-9]\\.[0-9]")
|
||||||
matches := versionRe.Split(versionOutput, 2)
|
matches := versionRe.FindStringSubmatch(versionOutput)
|
||||||
if len(matches) == 0 {
|
if len(matches) == 0 {
|
||||||
return "", fmt.Errorf("No version found: %s", versionOutput)
|
return "", fmt.Errorf("No version found: %s", versionOutput)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/mitchellh/multistep"
|
"github.com/mitchellh/multistep"
|
||||||
|
@ -62,6 +63,7 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error
|
||||||
vncPort := state.Get("vnc_port").(uint)
|
vncPort := state.Get("vnc_port").(uint)
|
||||||
sshHostPort := state.Get("sshHostPort").(uint)
|
sshHostPort := state.Get("sshHostPort").(uint)
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
driver := state.Get("driver").(Driver)
|
||||||
|
|
||||||
vnc := fmt.Sprintf("0.0.0.0:%d", vncPort-5900)
|
vnc := fmt.Sprintf("0.0.0.0:%d", vncPort-5900)
|
||||||
vmName := config.VMName
|
vmName := config.VMName
|
||||||
|
@ -82,7 +84,15 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error
|
||||||
defaultArgs["-netdev"] = fmt.Sprintf(
|
defaultArgs["-netdev"] = fmt.Sprintf(
|
||||||
"user,id=user.0,hostfwd=tcp::%v-:%d", sshHostPort, config.Comm.Port())
|
"user,id=user.0,hostfwd=tcp::%v-:%d", sshHostPort, config.Comm.Port())
|
||||||
defaultArgs["-device"] = fmt.Sprintf("%s,netdev=user.0", config.NetDevice)
|
defaultArgs["-device"] = fmt.Sprintf("%s,netdev=user.0", config.NetDevice)
|
||||||
defaultArgs["-drive"] = fmt.Sprintf("file=%s,if=%s,cache=%s,discard=%s", imgPath, config.DiskInterface, config.DiskCache, config.DiskDiscard)
|
qemuVersion, err := driver.Version()
|
||||||
|
if err == nil {
|
||||||
|
parts := strings.Split(qemuVersion, ".")
|
||||||
|
if strconv.Atoi(parts[0]) >= 2 {
|
||||||
|
defaultArgs["-drive"] = fmt.Sprintf("file=%s,if=%s,cache=%s,discard=%s", imgPath, config.DiskInterface, config.DiskCache, config.DiskDiscard)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
defaultArgs["-drive"] = fmt.Sprintf("file=%s,if=%s,cache=%s", imgPath, config.DiskInterface, config.DiskCache)
|
||||||
|
}
|
||||||
if !config.DiskImage {
|
if !config.DiskImage {
|
||||||
defaultArgs["-cdrom"] = isoPath
|
defaultArgs["-cdrom"] = isoPath
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue