Merge pull request #6827 from skish/qemuDiskZero

builder/qemu add drive detect-zeroes option
This commit is contained in:
Megan Marsh 2018-10-17 19:12:38 -07:00 committed by GitHub
commit fd89d4f020
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 2 deletions

View File

@ -75,6 +75,12 @@ var diskDiscard = map[string]bool{
"ignore": true, "ignore": true,
} }
var diskDZeroes = map[string]bool{
"unmap": true,
"on": true,
"off": true,
}
type Builder struct { type Builder struct {
config Config config Config
runner multistep.Runner runner multistep.Runner
@ -94,6 +100,7 @@ type Config struct {
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"` DiskDiscard string `mapstructure:"disk_discard"`
DetectZeroes string `mapstructure:"disk_detect_zeroes"`
SkipCompaction bool `mapstructure:"skip_compaction"` SkipCompaction bool `mapstructure:"skip_compaction"`
DiskCompression bool `mapstructure:"disk_compression"` DiskCompression bool `mapstructure:"disk_compression"`
Format string `mapstructure:"format"` Format string `mapstructure:"format"`
@ -157,6 +164,10 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
b.config.DiskDiscard = "ignore" b.config.DiskDiscard = "ignore"
} }
if b.config.DetectZeroes == "" {
b.config.DetectZeroes = "off"
}
if b.config.Accelerator == "" { if b.config.Accelerator == "" {
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
b.config.Accelerator = "tcg" b.config.Accelerator = "tcg"
@ -286,6 +297,11 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
errs, errors.New("unrecognized disk discard type")) errs, errors.New("unrecognized disk discard type"))
} }
if _, ok := diskDZeroes[b.config.DetectZeroes]; !ok {
errs = packer.MultiErrorAppend(
errs, errors.New("unrecognized disk detect zeroes setting"))
}
if !b.config.PackerForce { if !b.config.PackerForce {
if _, err := os.Stat(b.config.OutputDir); err == nil { if _, err := os.Stat(b.config.OutputDir); err == nil {
errs = packer.MultiErrorAppend( errs = packer.MultiErrorAppend(

View File

@ -97,9 +97,9 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error
if qemuMajor >= 2 { if qemuMajor >= 2 {
if config.DiskInterface == "virtio-scsi" { if config.DiskInterface == "virtio-scsi" {
deviceArgs = append(deviceArgs, "virtio-scsi-pci,id=scsi0", "scsi-hd,bus=scsi0.0,drive=drive0") deviceArgs = append(deviceArgs, "virtio-scsi-pci,id=scsi0", "scsi-hd,bus=scsi0.0,drive=drive0")
driveArgs = append(driveArgs, fmt.Sprintf("if=none,file=%s,id=drive0,cache=%s,discard=%s,format=%s", imgPath, config.DiskCache, config.DiskDiscard, config.Format)) driveArgs = append(driveArgs, fmt.Sprintf("if=none,file=%s,id=drive0,cache=%s,discard=%s,format=%s,detect-zeroes=%s", imgPath, config.DiskCache, config.DiskDiscard, config.Format, config.DetectZeroes))
} else { } else {
driveArgs = append(driveArgs, fmt.Sprintf("file=%s,if=%s,cache=%s,discard=%s,format=%s", imgPath, config.DiskInterface, config.DiskCache, config.DiskDiscard, config.Format)) driveArgs = append(driveArgs, fmt.Sprintf("file=%s,if=%s,cache=%s,discard=%s,format=%s,detect-zeroes=%s", imgPath, config.DiskInterface, config.DiskCache, config.DiskDiscard, config.Format, config.DetectZeroes))
} }
} else { } else {
driveArgs = append(driveArgs, fmt.Sprintf("file=%s,if=%s,cache=%s,format=%s", imgPath, config.DiskInterface, config.DiskCache, config.Format)) driveArgs = append(driveArgs, fmt.Sprintf("file=%s,if=%s,cache=%s,format=%s", imgPath, config.DiskInterface, config.DiskCache, config.Format))

View File

@ -145,6 +145,9 @@ Linux server and have not enabled X11 forwarding (`ssh -X`).
- `disk_discard` (string) - The discard mode to use for disk. Allowed values - `disk_discard` (string) - The discard mode to use for disk. Allowed values
include any of `unmap` or `ignore`. By default, this is set to `ignore`. include any of `unmap` or `ignore`. By default, this is set to `ignore`.
- `disk_detect_zeroes` (string) - The detect-zeroes mode to use for disk.
Allowed values include any of `unmap`, `on` or `off`. Defaults to `off`.
- `disk_image` (boolean) - Packer defaults to building from an ISO file, this - `disk_image` (boolean) - Packer defaults to building from an ISO file, this
parameter controls whether the ISO URL supplied is actually a bootable parameter controls whether the ISO URL supplied is actually a bootable
QEMU image. When this value is set to `true`, the machine will either clone QEMU image. When this value is set to `true`, the machine will either clone