From 69e70dec2272f99c8dddd5bfa818da12ccaa4dc4 Mon Sep 17 00:00:00 2001 From: Tomas Hozza Date: Wed, 6 Apr 2022 10:29:49 +0200 Subject: [PATCH] osbuild2: support VMDK subformat in the QEMU stage Support setting a specific VMDK subformat in the type format options. The required osbuild version in the SPEC file is not bumped, since the new functionality is currently not used by any image type. Related to https://github.com/osbuild/osbuild/pull/999 --- internal/osbuild2/qemu_stage.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/internal/osbuild2/qemu_stage.go b/internal/osbuild2/qemu_stage.go index 2a2c8c416..0b7d2ba60 100644 --- a/internal/osbuild2/qemu_stage.go +++ b/internal/osbuild2/qemu_stage.go @@ -21,6 +21,7 @@ type QEMUStageOptions struct { func (QEMUStageOptions) isStageOptions() {} type QEMUFormat string +type VMDKSubformat string const ( QEMUFormatQCOW2 QEMUFormat = "qcow2" @@ -28,6 +29,12 @@ const ( QEMUFormatVMDK QEMUFormat = "vmdk" QEMUFormatVPC QEMUFormat = "vpc" QEMUFormatVHDX QEMUFormat = "vhdx" + + VMDKSubformatMonolithicSparse VMDKSubformat = "monolithicSparse" + VMDKSubformatMonolithicFlat VMDKSubformat = "monolithicFlat" + VMDKSubformatTwoGbMaxExtentSparse VMDKSubformat = "twoGbMaxExtentSparse" + VMDKSubformatTwoGbMaxExtentFlat VMDKSubformat = "twoGbMaxExtentFlat" + VMDKSubformatStreamOptimized VMDKSubformat = "streamOptimized" ) type QEMUFormatOptions interface { @@ -83,6 +90,8 @@ func (o VPCOptions) validate() error { type VMDKOptions struct { // The type of the format must be 'vpc' Type QEMUFormat `json:"type"` + + Subformat VMDKSubformat `json:"subformat,omitempty"` } func (VMDKOptions) isQEMUFormatOptions() {} @@ -91,6 +100,27 @@ func (o VMDKOptions) validate() error { if o.Type != QEMUFormatVMDK { return fmt.Errorf("invalid format type %q for %q options", o.Type, QEMUFormatVMDK) } + + if o.Subformat != "" { + allowedVMDKSubformats := []VMDKSubformat{ + VMDKSubformatMonolithicFlat, + VMDKSubformatMonolithicSparse, + VMDKSubformatTwoGbMaxExtentFlat, + VMDKSubformatTwoGbMaxExtentSparse, + VMDKSubformatStreamOptimized, + } + valid := false + for _, value := range allowedVMDKSubformats { + if o.Subformat == value { + valid = true + break + } + } + if !valid { + return fmt.Errorf("'subformat' option does not allow %q as a value", o.Subformat) + } + } + return nil }