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"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/mitchellh/multistep"
|
||||
"io"
|
||||
"log"
|
||||
"os/exec"
|
||||
|
@ -14,6 +13,8 @@ import (
|
|||
"syscall"
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
"github.com/mitchellh/multistep"
|
||||
)
|
||||
|
||||
type DriverCancelCallback func(state multistep.StateBag) bool
|
||||
|
@ -188,8 +189,8 @@ func (d *QemuDriver) Version() (string, error) {
|
|||
|
||||
versionOutput := strings.TrimSpace(stdout.String())
|
||||
log.Printf("Qemu --version output: %s", versionOutput)
|
||||
versionRe := regexp.MustCompile("qemu-kvm-[0-9]\\.[0-9]")
|
||||
matches := versionRe.Split(versionOutput, 2)
|
||||
versionRe := regexp.MustCompile("[0-9]\\.[0-9]\\.[0-9]")
|
||||
matches := versionRe.FindStringSubmatch(versionOutput)
|
||||
if len(matches) == 0 {
|
||||
return "", fmt.Errorf("No version found: %s", versionOutput)
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/mitchellh/multistep"
|
||||
|
@ -62,6 +63,7 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error
|
|||
vncPort := state.Get("vnc_port").(uint)
|
||||
sshHostPort := state.Get("sshHostPort").(uint)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
driver := state.Get("driver").(Driver)
|
||||
|
||||
vnc := fmt.Sprintf("0.0.0.0:%d", vncPort-5900)
|
||||
vmName := config.VMName
|
||||
|
@ -82,7 +84,15 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error
|
|||
defaultArgs["-netdev"] = fmt.Sprintf(
|
||||
"user,id=user.0,hostfwd=tcp::%v-:%d", sshHostPort, config.Comm.Port())
|
||||
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 {
|
||||
defaultArgs["-cdrom"] = isoPath
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue