Commit 77af5f83 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

Merge pull request #2120 from vtolstov/discard

add discard option to qemu builder
parents 44008c32 3984f5e6
...@@ -66,6 +66,11 @@ var diskCache = map[string]bool{ ...@@ -66,6 +66,11 @@ var diskCache = map[string]bool{
"directsync": true, "directsync": true,
} }
var diskDiscard = map[string]bool{
"unmap": true,
"ignore": true,
}
type Builder struct { type Builder struct {
config Config config Config
runner multistep.Runner runner multistep.Runner
...@@ -79,6 +84,7 @@ type Config struct { ...@@ -79,6 +84,7 @@ type Config struct {
DiskInterface string `mapstructure:"disk_interface"` DiskInterface string `mapstructure:"disk_interface"`
DiskSize uint `mapstructure:"disk_size"` DiskSize uint `mapstructure:"disk_size"`
DiskCache string `mapstructure:"disk_cache"` DiskCache string `mapstructure:"disk_cache"`
DiskDiscard string `mapstructure:"disk_discard"`
FloppyFiles []string `mapstructure:"floppy_files"` FloppyFiles []string `mapstructure:"floppy_files"`
Format string `mapstructure:"format"` Format string `mapstructure:"format"`
Headless bool `mapstructure:"headless"` Headless bool `mapstructure:"headless"`
...@@ -144,6 +150,10 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { ...@@ -144,6 +150,10 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
b.config.DiskCache = "writeback" b.config.DiskCache = "writeback"
} }
if b.config.DiskDiscard == "" {
b.config.DiskDiscard = "ignore"
}
if b.config.Accelerator == "" { if b.config.Accelerator == "" {
b.config.Accelerator = "kvm" b.config.Accelerator = "kvm"
} }
...@@ -237,6 +247,11 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { ...@@ -237,6 +247,11 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
errs, errors.New("unrecognized disk cache type")) errs, errors.New("unrecognized disk cache type"))
} }
if _, ok := diskDiscard[b.config.DiskDiscard]; !ok {
errs = packer.MultiErrorAppend(
errs, errors.New("unrecognized disk cache type"))
}
if b.config.HTTPPortMin > b.config.HTTPPortMax { if b.config.HTTPPortMin > b.config.HTTPPortMax {
errs = packer.MultiErrorAppend( errs = packer.MultiErrorAppend(
errs, errors.New("http_port_min must be less than http_port_max")) errs, errors.New("http_port_min must be less than http_port_max"))
......
...@@ -82,7 +82,7 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error ...@@ -82,7 +82,7 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error
defaultArgs["-machine"] = fmt.Sprintf("type=%s", config.MachineType) defaultArgs["-machine"] = fmt.Sprintf("type=%s", config.MachineType)
defaultArgs["-netdev"] = fmt.Sprintf("user,id=user.0,hostfwd=tcp::%v-:22", sshHostPort) defaultArgs["-netdev"] = fmt.Sprintf("user,id=user.0,hostfwd=tcp::%v-:22", sshHostPort)
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", imgPath, config.DiskInterface, config.DiskCache) defaultArgs["-drive"] = fmt.Sprintf("file=%s,if=%s,cache=%s,discard=%s", imgPath, config.DiskInterface, config.DiskCache, config.DiskDiscard)
if !config.DiskImage { if !config.DiskImage {
defaultArgs["-cdrom"] = isoPath defaultArgs["-cdrom"] = isoPath
} }
......
...@@ -115,6 +115,9 @@ each category, the available options are alphabetized and described. ...@@ -115,6 +115,9 @@ each category, the available options are alphabetized and described.
values include any of "writethrough", "writeback", "none", "unsafe" or values include any of "writethrough", "writeback", "none", "unsafe" or
"directsync". "directsync".
* `disk_discard` (string) - The discard mode to use for disk. Allowed values
include any of "unmap" or "ignore".
* `disk_image` (boolean) - Packer defaults to building from an ISO file, * `disk_image` (boolean) - Packer defaults to building from an ISO file,
this parameter controls whether the ISO URL supplied is actually a bootable this parameter controls whether the ISO URL supplied is actually a bootable
QEMU image. When this value is set to true, the machine will clone the QEMU image. When this value is set to true, the machine will clone the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment